From 290c8f40d773a268e1d177415e89c2021f99e076 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 21 Jan 2011 00:04:39 +0000 Subject: [PATCH] Skeleton for sample entity and sampler manager classes. --- src/Makefile.am | 1 + src/core.h | 2 ++ src/sample.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++ src/sample.h | 46 ++++++++++++++++++++++++++++++ src/sampler.cpp | 59 +++++++++++++++++++++++++++++++++++++++ src/sampler.h | 32 +++++++++++++++++++++ win32/deushax.vcxproj | 4 +++ win32/monsterz.vcxproj | 4 +++ 8 files changed, 211 insertions(+) create mode 100644 src/sample.cpp create mode 100644 src/sample.h create mode 100644 src/sampler.cpp create mode 100644 src/sampler.h diff --git a/src/Makefile.am b/src/Makefile.am index ce38adeb..44895639 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ \ diff --git a/src/core.h b/src/core.h index a46a7e4a..7845eb15 100644 --- a/src/core.h +++ b/src/core.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__ diff --git a/src/sample.cpp b/src/sample.cpp new file mode 100644 index 00000000..1b7380e8 --- /dev/null +++ b/src/sample.cpp @@ -0,0 +1,63 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// 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 +#include + +#include + +#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() +{ +} + diff --git a/src/sample.h b/src/sample.h new file mode 100644 index 00000000..05aba1b0 --- /dev/null +++ b/src/sample.h @@ -0,0 +1,46 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// 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 + +#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__ + diff --git a/src/sampler.cpp b/src/sampler.cpp new file mode 100644 index 00000000..a6d5a005 --- /dev/null +++ b/src/sampler.cpp @@ -0,0 +1,59 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// 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(); +} + diff --git a/src/sampler.h b/src/sampler.h new file mode 100644 index 00000000..c2b6a6dc --- /dev/null +++ b/src/sampler.h @@ -0,0 +1,32 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// 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 + +class Sampler +{ +public: + static int Register(char const *path); + static void Deregister(int id); + + static void PlaySample(int id); +}; + +#endif // __DH_SAMPLER_H__ + diff --git a/win32/deushax.vcxproj b/win32/deushax.vcxproj index 57668700..56ed6fa2 100644 --- a/win32/deushax.vcxproj +++ b/win32/deushax.vcxproj @@ -28,6 +28,8 @@ + + @@ -53,6 +55,8 @@ + + diff --git a/win32/monsterz.vcxproj b/win32/monsterz.vcxproj index dad8bbea..30cdaf68 100644 --- a/win32/monsterz.vcxproj +++ b/win32/monsterz.vcxproj @@ -29,6 +29,8 @@ + + @@ -55,6 +57,8 @@ + +