| @@ -7,6 +7,7 @@ liblol_a_SOURCES = \ | |||
| entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ | |||
| forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ | |||
| profiler.cpp profiler.h input.h input.cpp world.cpp world.h \ | |||
| sample.cpp sample.h sampler.cpp sampler.h \ | |||
| \ | |||
| sdlinput.cpp sdlinput.h \ | |||
| \ | |||
| @@ -30,6 +30,7 @@ | |||
| #include "entity.h" | |||
| #include "font.h" | |||
| #include "tileset.h" | |||
| #include "sample.h" | |||
| #include "world.h" | |||
| // Other objects | |||
| @@ -41,6 +42,7 @@ | |||
| #include "ticker.h" | |||
| #include "forge.h" | |||
| #include "tiler.h" | |||
| #include "sampler.h" | |||
| #endif // __DH_CORE_H__ | |||
| @@ -0,0 +1,63 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include <cstdlib> | |||
| #include <cmath> | |||
| #include <SDL.h> | |||
| #include "core.h" | |||
| /* | |||
| * Sample implementation class | |||
| */ | |||
| class SampleData | |||
| { | |||
| friend class Sample; | |||
| private: | |||
| char *name; | |||
| }; | |||
| /* | |||
| * Public Sample class | |||
| */ | |||
| Sample::Sample(char const *path) | |||
| { | |||
| data = new SampleData(); | |||
| data->name = strdup(path); | |||
| } | |||
| Sample::~Sample() | |||
| { | |||
| free(data->name); | |||
| delete data; | |||
| } | |||
| void Sample::TickGame(float deltams) | |||
| { | |||
| Entity::TickGame(deltams); | |||
| } | |||
| char const *Sample::GetName() | |||
| { | |||
| return data->name; | |||
| } | |||
| void Sample::Play() | |||
| { | |||
| } | |||
| @@ -0,0 +1,46 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| // | |||
| // The Sample class | |||
| // ---------------- | |||
| // A Sample is a unique sound sample. | |||
| // | |||
| #if !defined __DH_SAMPLE_H__ | |||
| #define __DH_SAMPLE_H__ | |||
| #include <stdint.h> | |||
| #include "entity.h" | |||
| class SampleData; | |||
| class Sample : public Entity | |||
| { | |||
| public: | |||
| Sample(char const *path); | |||
| virtual ~Sample(); | |||
| protected: | |||
| /* Inherited from Entity */ | |||
| virtual char const *GetName(); | |||
| virtual void TickGame(float deltams); | |||
| public: | |||
| /* New methods */ | |||
| void Play(); | |||
| private: | |||
| SampleData *data; | |||
| }; | |||
| #endif // __DH_SAMPLE_H__ | |||
| @@ -0,0 +1,59 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| #if defined HAVE_CONFIG_H | |||
| # include "config.h" | |||
| #endif | |||
| #include "core.h" | |||
| /* | |||
| * Sampler implementation class | |||
| */ | |||
| static class SamplerData | |||
| { | |||
| friend class Sampler; | |||
| public: | |||
| Dict samples; | |||
| } | |||
| samplerdata; | |||
| static SamplerData * const data = &samplerdata; | |||
| /* | |||
| * Public Sampler class | |||
| */ | |||
| int Sampler::Register(char const *path) | |||
| { | |||
| int id = data->samples.MakeSlot(path); | |||
| if (!data->samples.GetEntity(id)) | |||
| { | |||
| Sample *sample = new Sample(path); | |||
| data->samples.SetEntity(id, sample); | |||
| } | |||
| return id + 1; /* ID 0 is for the empty sample */ | |||
| } | |||
| void Sampler::Deregister(int id) | |||
| { | |||
| data->samples.RemoveSlot(id - 1); /* ID 0 is for the empty sample */ | |||
| } | |||
| void Sampler::PlaySample(int id) | |||
| { | |||
| Sample *sample = (Sample *)data->samples.GetEntity(id); | |||
| sample->Play(); | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> | |||
| // This program is free software; you can redistribute it and/or | |||
| // modify it under the terms of the Do What The Fuck You Want To | |||
| // Public License, Version 2, as published by Sam Hocevar. See | |||
| // http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
| // | |||
| // | |||
| // The Sampler class | |||
| // ----------------- | |||
| // The Sampler is a static class that manages samples. | |||
| // | |||
| #if !defined __DH_SAMPLER_H__ | |||
| #define __DH_SAMPLER_H__ | |||
| #include <stdint.h> | |||
| class Sampler | |||
| { | |||
| public: | |||
| static int Register(char const *path); | |||
| static void Deregister(int id); | |||
| static void PlaySample(int id); | |||
| }; | |||
| #endif // __DH_SAMPLER_H__ | |||
| @@ -28,6 +28,8 @@ | |||
| <ClInclude Include="..\src\map.h" /> | |||
| <ClInclude Include="..\src\matrix.h" /> | |||
| <ClInclude Include="..\src\profiler.h" /> | |||
| <ClInclude Include="..\src\sample.h" /> | |||
| <ClInclude Include="..\src\sampler.h" /> | |||
| <ClInclude Include="..\src\scene.h" /> | |||
| <ClInclude Include="..\src\sdlinput.h" /> | |||
| <ClInclude Include="..\src\ticker.h" /> | |||
| @@ -53,6 +55,8 @@ | |||
| <ClCompile Include="..\src\layer.cpp" /> | |||
| <ClCompile Include="..\src\map.cpp" /> | |||
| <ClCompile Include="..\src\profiler.cpp" /> | |||
| <ClCompile Include="..\src\sample.cpp" /> | |||
| <ClCompile Include="..\src\sampler.cpp" /> | |||
| <ClCompile Include="..\src\scene.cpp" /> | |||
| <ClCompile Include="..\src\sdlinput.cpp" /> | |||
| <ClCompile Include="..\src\ticker.cpp" /> | |||
| @@ -29,6 +29,8 @@ | |||
| <ClInclude Include="..\src\map.h" /> | |||
| <ClInclude Include="..\src\matrix.h" /> | |||
| <ClInclude Include="..\src\profiler.h" /> | |||
| <ClInclude Include="..\src\sample.h" /> | |||
| <ClInclude Include="..\src\sampler.h" /> | |||
| <ClInclude Include="..\src\scene.h" /> | |||
| <ClInclude Include="..\src\sdlinput.h" /> | |||
| <ClInclude Include="..\src\ticker.h" /> | |||
| @@ -55,6 +57,8 @@ | |||
| <ClCompile Include="..\src\layer.cpp" /> | |||
| <ClCompile Include="..\src\map.cpp" /> | |||
| <ClCompile Include="..\src\profiler.cpp" /> | |||
| <ClInclude Include="..\src\sample.cpp" /> | |||
| <ClInclude Include="..\src\sampler.cpp" /> | |||
| <ClCompile Include="..\src\scene.cpp" /> | |||
| <ClCompile Include="..\src\sdlinput.cpp" /> | |||
| <ClCompile Include="..\src\ticker.cpp" /> | |||