Open source Star Ruler 2 source code!

This commit is contained in:
Lucas de Vries
2018-07-17 14:15:37 +02:00
commit cc307720ff
4342 changed files with 2365070 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#ifndef LIN_MODE
#ifdef SND_EXPORT
#define _export __declspec(dllexport)
#else
#define _export __declspec(dllimport)
#endif
#else
#define _export
#endif
namespace audio {
class IAudioReference {
mutable int references;
public:
virtual ~IAudioReference();
IAudioReference();
_export void grab() const;
_export void drop() const;
};
};
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include "IAudioReference.h"
#include "sound_vector.h"
namespace audio {
class ISoundSource;
class ISound : public IAudioReference {
public:
virtual ~ISound();
ISound();
//Returns true if the sound is stopped, and cannot be played again.
virtual bool isStopped() const = 0;
//Returns true if the sound is playing
virtual bool isPlaying() const = 0;
//For streaming sources, buffers additional sound data (if necessary)
virtual void streamData() = 0;
//Pauses the sound
virtual void pause() = 0;
//Resumes the sound
virtual void resume() = 0;
//Changes the sound's current time stamp
virtual void seek(int timeMS) = 0;
virtual void setLooped(bool loop) = 0;
virtual bool isLooped() const = 0;
//Ends the sound. The sound may not be resumed from this state.
virtual void stop() = 0;
//Sets the sound's 3D Position. For 2D Sounds, this is in camera space.
virtual void setPosition(float x, float y, float z) = 0;
inline void setPosition(const snd_vec& pos) {
setPosition(pos.x, pos.y, pos.z);
}
//Sets the sound's 3D Velocity. For 2D Sounds, this is in camera space.
virtual void setVelocity(float x, float y, float z) = 0;
inline void setVelocity(const snd_vec& vel) {
setVelocity(vel.x, vel.y, vel.z);
}
virtual void setVolume(float volume) = 0;
//Pitch is a factor from 0.5 to 2.0, defaulting to 1.0
virtual void setPitch(float pitch) = 0;
virtual void setRolloff(float factor) = 0;
//Applies a low pass filter with a strength from 0 to 1 (none to max)
virtual void setLowPass(float strength) = 0;
//Returns the sound's position in the file
virtual int getPlayPosition() = 0;
virtual int getPlayLength() = 0;
inline void setIsPaused(bool paused) {
if(paused)
pause();
else
resume();
}
virtual void setMinDistance(float minDist) = 0;
virtual void setMaxDistance(float maxDist) = 0;
virtual void setPlayPosition(int timeMs) = 0;
//Returns the sound source used to create this sound.
//This pointer should not be dropped.
virtual const ISoundSource* getSoundSource() = 0;
};
};
+57
View File
@@ -0,0 +1,57 @@
#pragma once
#include "IAudioReference.h"
#include "SoundTypes.h"
#include "sound_vector.h"
#include <string>
#include <list>
#include <vector>
#include <functional>
namespace audio {
class ISound;
class ISoundSource;
extern void checkError();
class ISoundDevice : public IAudioReference {
public:
virtual ISound* play2D(const ISoundSource* sound, bool loop = false, bool startPaused = false, bool priority = false) = 0;
virtual ISound* play3D(const ISoundSource* sound, const snd_vec& at, bool loop = false, bool startPaused = false, bool priority = false) = 0;
virtual void stopAllSounds() = 0;
virtual void setListenerData(const snd_vec& pos, const snd_vec& vel, const snd_vec& at, const snd_vec& up) = 0;
virtual void setVolume(float volume) = 0;
virtual float getVolume() const = 0;
virtual void setRolloffFactor(float rolloff) = 0;
virtual ISoundSource* loadSound(const std::string& fileName) = 0;
virtual ISoundSource* loadStreamingSound(const std::string& fileName) = 0;
//Returns a unique source ID. If this ID is valid, it should be passed to freeSource() when it is no longer used.
virtual sourceID getFreeSourceID(bool priority) = 0;
virtual void freeSource(sourceID id) = 0;
virtual bufferID getFreeBufferID() = 0;
virtual void freeBuffer(bufferID id) = 0;
virtual sourceID applyLowPassFilter(sourceID applyTo, float strength) = 0;
virtual void freeFilter(sourceID fromSource, sourceID id) = 0;
//Prevents alterations to the sound system until unlockSounds() is called
virtual void lock() = 0;
//Allows alterations to the sound system after a call to lockSounds()
virtual void unlock() = 0;
virtual ~ISoundDevice();
};
_export void enumerateDevices(std::function<void(const char*)> cb);
_export ISoundDevice* createAudioDevice(const char* useSoundDevice = 0);
_export ISoundDevice* createDummyAudioDevice();
};
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include "IAudioReference.h"
#include "SoundTypes.h"
namespace audio {
class ISoundDevice;
class ISoundSource : public IAudioReference {
protected:
ISoundDevice* device;
public:
ISoundSource(ISoundDevice* Device);
virtual ~ISoundSource();
virtual int getLength_ms() const = 0;
virtual bool isStreaming() const = 0;
virtual void setDefaultVolume(float volume) = 0;
virtual float getDefaultVolume() const = 0;
ISoundDevice* getDevice() const { return device; }
};
};
+18
View File
@@ -0,0 +1,18 @@
#pragma once
namespace audio {
template<class T>
struct SAutoDrop {
T* pRef;
void clear() { pRef = 0; }
SAutoDrop(T* object) : pRef(object) {}
~SAutoDrop() {
if(pRef) pRef->drop();
}
};
};
+11
View File
@@ -0,0 +1,11 @@
#pragma once
namespace audio {
template<class T>
struct SAutoLocker {
T* obj;
SAutoLocker(T* Object) { obj = Object; obj->lock(); }
~SAutoLocker() { obj->unlock(); }
};
};
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include <exception>
namespace audio {
class SLoadError : public std::exception {
bool badFile;
public:
#ifdef LIN_MODE
SLoadError(const char* msg, bool wasBadFile = false) : std::exception(), badFile(wasBadFile) {
#else
SLoadError(const char* msg, bool wasBadFile = false) : std::exception(msg, 0), badFile(wasBadFile) {
#endif
}
inline bool wasBadFile() const { return badFile; }
};
class NotThisType {
};
};
+9
View File
@@ -0,0 +1,9 @@
#pragma once
namespace audio {
typedef unsigned int bufferID;
const bufferID invalidBuffer = 0xffffffff;
typedef unsigned int sourceID;
const sourceID invalidSource = 0xffffffff;
};
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include "../../util/include/vec3.h"
typedef vec3f snd_vec;
//Correct the dimensions to be in the soundcard's space
static inline snd_vec sync(const snd_vec& v) {
//return snd_vec(-v.x, v.y, -v.z);
return v;
}
static inline void sync(float& x, float& y, float& z) {
//x = -x;
//z = -z;
}
static inline bool valid(const snd_vec& v) {
if(v.x != v.x || v.y != v.y || v.z != v.z)
return false;
if(v.x > 1e32f || v.y > 1e32f || v.z > 1e32f)
return false;
return true;
}
static inline bool valid(float x, float y, float z) {
if(x != x || y != y || z != z)
return false;
if(x > 1e32f || y > 1e32f || z > 1e32f)
return false;
return true;
}