Skip to content

Commit

Permalink
Bunch of stuffs!
Browse files Browse the repository at this point in the history
Fixes Jebbs#118 fixes Jebbs#124 fixes Jebbs#147 fixes Jebbs#95 fixes Jebbs#42 fixes Jebbs#162
  • Loading branch information
Jebbs committed Mar 30, 2015
1 parent 0cc87d6 commit 9bae375
Show file tree
Hide file tree
Showing 36 changed files with 738 additions and 447 deletions.
10 changes: 5 additions & 5 deletions build.d
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void initialize()
prefix = "";
extension = ".lib";

unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" dsfml-graphics-2.lib dsfml-window-2.lib dsfml-audio-2.lib dsfml-network-2.lib dsfml-system-2.lib dsfml-graphics.lib dsfml-window.lib dsfml-audio.lib dsfml-network.lib dsfml-system.lib ";
unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" dsfml-graphics.lib dsfml-window.lib dsfml-audio.lib dsfml-network.lib dsfml-system.lib dsfmlc-graphics.lib dsfmlc-window.lib dsfmlc-audio.lib dsfmlc-network.lib dsfmlc-system.lib ";

if(!force64Build)
{
Expand All @@ -257,14 +257,14 @@ void initialize()
writeln("Building for Linux");
prefix = "lib";
extension = ".a";
unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" -L-ldsfml-graphics-2 -L-ldsfml-window-2 -L-ldsfml-audio-2 -L-ldsfml-network-2 -L-ldsfml-system-2 -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-audio -L-ldsfml-network -L-ldsfml-system -L-L"~libDirectory;
unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" -L-ldsfml-graphics -L-ldsfml-window -L-ldsfml-audio -L-ldsfml-network -L-ldsfml-system -L-ldsfmlc-graphics -L-ldsfmlc-window -L-ldsfmlc-audio -L-ldsfmlc-network -L-ldsfmlc-system -L-L"~libDirectory;
}
else
{
writeln("Building for OSX");
prefix = "lib";
extension = ".a";
unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" -ldsfml-graphics-2 -ldsfml-window-2 -ldsfml-audio-2 -ldsfml-network-2 -ldsfml-system-2 -ldsfml-graphics -ldsfml-window -ldsfml-audio -ldsfml-network -ldsfml-system -L-L"~libDirectory;
unittestCompilerSwitches = "-main -unittest -cov -I"~impDirectory~" -ldsfml-graphics -ldsfml-window -ldsfml-audio -ldsfml-network -ldsfml-system -ldsfmlc-graphics -ldsfmlc-window -ldsfmlc-audio -ldsfmlc-network -ldsfmlc-system -L-L"~libDirectory;
}

libCompilerSwitches = "-lib -O -release -inline -I"~impDirectory;
Expand Down Expand Up @@ -301,7 +301,7 @@ bool buildLibs()
fileList~= name ~ " ";
}

string buildCommand = "dmd "~ fileList ~ libCompilerSwitches ~ " -of"~libDirectory~prefix~"dsfml-"~theModule~"-2"~extension;
string buildCommand = "dmd "~ fileList ~ libCompilerSwitches ~ " -of"~libDirectory~prefix~"dsfml-"~theModule~extension;

writeln("Building " ~ theModule~ " module.");

Expand Down Expand Up @@ -418,7 +418,7 @@ void showHelp()
writeln("-unittest : Build static libs and unittests");
writeln("-all : Build everything");
writeln("-unittest:sharedDir : Build static libs and unittests, sharedDir is the location of DSFML-C shared libraries");
writeln("-all:sharedDir : Build everything, sharedDir is the location of DSFML-C shared libraries");
writeln("-all:sharedDir : Build everything, sharedDir is the location of DSFMLC shared libraries");
writeln();
writeln("Modifier switches:");
writeln("-m32 : force a 32 bit build");
Expand Down
2 changes: 1 addition & 1 deletion src/dsfml/audio/music.d
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ unittest
auto music = new Music();

//TODO: update this for a real unit test users can run themselves.
if(!music.openFromFile("res/hal1.ogg"))
if(!music.openFromFile("res/TestMusic.ogg"))
{
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/dsfml/audio/sound.d
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Sound : SoundSource

this()
{
sfPtr = sfSound_create();
sfPtr = sfSound_construct();
}

this(const(SoundBuffer) buffer)
Expand Down Expand Up @@ -310,7 +310,7 @@ unittest

auto soundbuffer = new SoundBuffer();

if(!soundbuffer.loadFromFile("res/cave1.ogg"))
if(!soundbuffer.loadFromFile("res/TestSound.ogg"))
{
//error
return;
Expand Down Expand Up @@ -346,7 +346,7 @@ private extern(C):

struct sfSound;

sfSound* sfSound_create();
sfSound* sfSound_construct();

sfSound* sfSound_copy(const sfSound* sound);

Expand Down
46 changes: 17 additions & 29 deletions src/dsfml/audio/soundbuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SoundBuffer
this()
{
import dsfml.system.string;
sfPtr = sfSoundBuffer_create();
sfPtr = sfSoundBuffer_construct();
err.write(toString(sfErr_getOutput()));
}

Expand Down Expand Up @@ -149,15 +149,13 @@ class SoundBuffer
*/
bool loadFromFile(string filename)
{
sfPtr = sfSoundBuffer_createFromFile(toStringz(filename));

if(sfPtr)
import dsfml.system.string;
if(sfSoundBuffer_loadFromFile(sfPtr, toStringz(filename)))
{
return true;
return true;
}
else
{
import dsfml.system.string;
err.write(toString(sfErr_getOutput()));
return false;
}
Expand All @@ -175,15 +173,13 @@ class SoundBuffer
*/
bool loadFromMemory(const(void)[] data)
{
sfPtr = sfSoundBuffer_createFromMemory(data.ptr, data.length);

if(sfPtr)
if(sfSoundBuffer_loadFromMemory(sfPtr, data.ptr, data.length))
{
return true;
return true;
}
else
{
import dsfml.system.string;
import dsfml.system.string;
err.write(toString(sfErr_getOutput()));
return false;
}
Expand All @@ -200,11 +196,8 @@ class SoundBuffer
* Returns: True if loading succeeded, false if it failed
*/
bool loadFromStream(InputStream stream)
{

sfPtr = sfSoundBuffer_createFromStream(new SoundBufferStream(stream));

if(sfPtr)
{
if(sfSoundBuffer_loadFromStream(sfPtr, new SoundBufferStream(stream)))
{
return true;
}
Expand All @@ -230,10 +223,7 @@ class SoundBuffer
*/
bool loadFromSamples(const(short[]) samples, uint channelCount, uint sampleRate)
{

sfPtr = sfSoundBuffer_createFromSamples(samples.ptr, samples.length, channelCount, sampleRate);

if(sfPtr)
if(sfSoundBuffer_loadFromSamples(sfPtr, samples.ptr, samples.length, channelCount, sampleRate))
{
return true;
}
Expand All @@ -258,9 +248,7 @@ class SoundBuffer
bool saveToFile(string filename)
{
import dsfml.system.string;
sfSoundBuffer_saveToFile(sfPtr, toStringz(filename));

if(sfPtr)
if(sfSoundBuffer_saveToFile(sfPtr, toStringz(filename)))
{
return true;
}
Expand All @@ -285,7 +273,7 @@ unittest

auto soundbuffer = new SoundBuffer();

if(!soundbuffer.loadFromFile("res/cave1.ogg"))
if(!soundbuffer.loadFromFile("res/TestSound.ogg"))
{
//error
return;
Expand Down Expand Up @@ -352,15 +340,15 @@ package struct sfSoundBuffer;

private extern(C):

sfSoundBuffer* sfSoundBuffer_create();
sfSoundBuffer* sfSoundBuffer_construct();

sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename);
bool sfSoundBuffer_loadFromFile(sfSoundBuffer* soundBuffer, const char* filename);

sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes);
bool sfSoundBuffer_loadFromMemory(sfSoundBuffer* soundBuffer, const void* data, size_t sizeInBytes);

sfSoundBuffer* sfSoundBuffer_createFromStream(sfmlInputStream stream);
bool sfSoundBuffer_loadFromStream(sfSoundBuffer* soundBuffer, sfmlInputStream stream);

sfSoundBuffer* sfSoundBuffer_createFromSamples(const short* samples, size_t sampleCount, uint channelCount, uint sampleRate);
bool sfSoundBuffer_loadFromSamples(sfSoundBuffer* soundBuffer, const short* samples, size_t sampleCount, uint channelCount, uint sampleRate);

sfSoundBuffer* sfSoundBuffer_copy(const sfSoundBuffer* soundBuffer);

Expand Down
62 changes: 37 additions & 25 deletions src/dsfml/audio/soundbufferrecorder.d
Original file line number Diff line number Diff line change
Expand Up @@ -134,41 +134,53 @@ unittest

writeln("Unit test for SoundBufferRecorder.");

assert(SoundRecorder.isAvailable());


auto recorder = new SoundBufferRecorder();

assert(SoundRecorder.isAvailable());

auto clock = new Clock();

writeln("Recording for 5 seconds in...");
writeln("3");
clock.restart();

while(clock.getElapsedTime().asSeconds() <1)
{
//wait for a second
}
writeln("2");

writeln("Press Enter to start recording.");
while(!Keyboard.isKeyPressed(Keyboard.Key.Return))
clock.restart();

while(clock.getElapsedTime().asSeconds() <1)
{
//wait for the user to press enter
if(Keyboard.isKeyPressed(Keyboard.Key.Return))
{

recorder.start();
}
//wait for a second
}
writeln("1");

clock.restart();

while(clock.getElapsedTime().asSeconds() <1)
{
//wait for a second
}
//make sure the next one diesn't trigger immediately
if(Keyboard.isKeyPressed(Keyboard.Key.Return))
writeln("Recording!");

recorder.start();
clock.restart();

while(clock.getElapsedTime().asSeconds() <5)
{
//wait until they release the key
while(Keyboard.isKeyPressed(Keyboard.Key.Return))
{
//writeln(true);
}
//wait for a second
}

writeln("Done!");

writeln("Press Enter to stop recording.");

while(!Keyboard.isKeyPressed(Keyboard.Key.Return))
{
if(Keyboard.isKeyPressed(Keyboard.Key.Return))
{
recorder.stop();
}
}
recorder.stop();




Expand All @@ -178,7 +190,7 @@ unittest

auto recorderSound = new Sound(buffer);

auto clock = new Clock();
clock.restart();

recorderSound.play();
while(clock.getElapsedTime() < recorderDuration)
Expand Down
4 changes: 2 additions & 2 deletions src/dsfml/audio/soundrecorder.d
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SoundRecorder
{
import dsfml.system.string;
callBacks = new SoundRecorderCallBacks(this);
sfPtr = sfSoundRecorder_create(callBacks);
sfPtr = sfSoundRecorder_construct(callBacks);

err.write(toString(sfErr_getOutput()));

Expand Down Expand Up @@ -214,7 +214,7 @@ private extern(C):

struct sfSoundRecorder;

sfSoundRecorder* sfSoundRecorder_create(sfmlSoundRecorderCallBacks newCallBacks);
sfSoundRecorder* sfSoundRecorder_construct(sfmlSoundRecorderCallBacks newCallBacks);

void sfSoundRecorder_destroy(sfSoundRecorder* soundRecorder);

Expand Down
16 changes: 6 additions & 10 deletions src/dsfml/audio/soundstream.d
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,8 @@ class SoundStream:SoundSource

protected this()
{
//create a blank pointer in case functions might be called before it is initialized (eg, stop() in Music's openFromFile)
sfPtr = sfSoundStream_create(0, 0, null);

callBacks = new SoundStreamCallBacks(this);

callBacks = new SoundStreamCallBacks(this);
sfPtr = sfSoundStream_construct(callBacks);
}

~this()
Expand All @@ -91,10 +88,7 @@ class SoundStream:SoundSource
{
import dsfml.system.string;

//destroy the blank pointer so we can create the real instance
sfSoundStream_destroy(sfPtr);

sfPtr = sfSoundStream_create(channelCount, sampleRate, callBacks);
sfSoundStream_initialize(sfPtr, channelCount, sampleRate);

err.write(toString(sfErr_getOutput()));
}
Expand Down Expand Up @@ -367,10 +361,12 @@ private extern(C):
struct sfSoundStream;


sfSoundStream* sfSoundStream_create( uint channelCount, uint sampleRate, sfmlSoundStreamCallBacks callBacks);
sfSoundStream* sfSoundStream_construct(sfmlSoundStreamCallBacks callBacks);

void sfSoundStream_destroy(sfSoundStream* soundStream);

void sfSoundStream_initialize(sfSoundStream* soundStream, uint channelCount, uint sampleRate);

void sfSoundStream_play(sfSoundStream* soundStream);

void sfSoundStream_pause(sfSoundStream* soundStream);
Expand Down
2 changes: 1 addition & 1 deletion src/dsfml/graphics/circleshape.d
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CircleShape : Shape

unittest
{
version(DSFML_Unittest_Graphics)
version(DSFML_Unittest_Graphicss)
{
import std.stdio;
import dsfml.graphics;
Expand Down
2 changes: 1 addition & 1 deletion src/dsfml/graphics/color.d
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct Color

unittest
{
version(DSFML_Unittest_Graphics)
version(DSFML_Unittest_Graphicss)
{
import std.stdio;

Expand Down
2 changes: 1 addition & 1 deletion src/dsfml/graphics/convexshape.d
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ConvexShape : Shape

unittest
{
version(DSFML_Unittest_Graphics)
version(DSFML_Unittest_Graphicss)
{
import std.stdio;
import dsfml.graphics;
Expand Down
Loading

0 comments on commit 9bae375

Please sign in to comment.