From 3d3ec36548beb6e7db2eab482919b8d90e28c731 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 5 Dec 2011 08:24:04 +0000 Subject: [PATCH] core: start working on the Emcee class. --- src/Makefile.am | 2 +- src/application/application.cpp | 2 + src/core.h | 1 + src/emcee.cpp | 82 +++++++++++++++++++++++++++++++++ src/emcee.h | 41 +++++++++++++++++ src/entity.cpp | 11 +++++ src/entity.h | 13 ++++++ src/thread/threadbase.h | 1 - test/debug/sandbox.cpp | 7 +++ 9 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/emcee.cpp create mode 100644 src/emcee.h diff --git a/src/Makefile.am b/src/Makefile.am index 38789e6b..9a9cedd2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,7 @@ liblol_a_SOURCES = \ text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \ worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \ platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \ - real.cpp real.h \ + real.cpp real.h emcee.cpp emcee.h \ \ lol/unit.h \ \ diff --git a/src/application/application.cpp b/src/application/application.cpp index cbb59346..9afa2e55 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -59,6 +59,7 @@ class ApplicationData Application::Application(char const *name, ivec2 resolution, float framerate) { + Emcee::Setup(); data = new ApplicationData(name, resolution, framerate); } @@ -75,6 +76,7 @@ void Application::Run() Application::~Application() { delete data; + Emcee::Shutdown(); } } /* namespace lol */ diff --git a/src/core.h b/src/core.h index 4db4d973..5149d58b 100644 --- a/src/core.h +++ b/src/core.h @@ -103,6 +103,7 @@ static inline int isnan(float f) #include "application/application.h" // Managers +#include "emcee.h" #include "ticker.h" #include "forge.h" #include "tiler.h" diff --git a/src/emcee.cpp b/src/emcee.cpp new file mode 100644 index 00000000..0838291d --- /dev/null +++ b/src/emcee.cpp @@ -0,0 +1,82 @@ +// +// 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 "core.h" + +namespace lol +{ + +/* + * Emcee implementation class + */ + +static Thread *GameThread, *DrawThread; + +static Queue gametick, drawtick; + +static void *GameThreadMain(void *data) +{ + while (!Ticker::Finished()) + for (;;) + { + int tick = gametick.Pop(); + if (!tick) + break; + + Ticker::TickGame(); + + drawtick.Push(1); + } + + drawtick.Push(0); +} + +static void *DrawThreadMain(void *data) +{ + for (;;) + { + int tick = drawtick.Pop(); + if (!tick) + break; + + Ticker::TickDraw(); + } +} + +void Emcee::Setup() +{ + GameThread = new Thread(GameThreadMain, NULL); + DrawThread = new Thread(DrawThreadMain, NULL); +} + +void Emcee::Shutdown() +{ +} + +void Emcee::SetState(Entity *entity, uint32_t state) +{ + +} + +void Emcee::SetStateWhenMatch(Entity *entity, uint32_t state, + Entity *other_entity, uint32_t other_state) +{ + +} + +} /* namespace lol */ + diff --git a/src/emcee.h b/src/emcee.h new file mode 100644 index 00000000..28b3c1bf --- /dev/null +++ b/src/emcee.h @@ -0,0 +1,41 @@ +// +// 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 Emcee class +// --------------- +// The Emcee manages tasks and their dependencies +// + +#if !defined __LOL_EMCEE_H__ +#define __LOL_EMCEE_H__ + +#include + +#include "entity.h" + +namespace lol +{ + +class Emcee +{ +public: + static void Setup(); + static void Shutdown(); + + static void SetState(Entity *entity, uint32_t state); + static void SetStateWhenMatch(Entity *entity, uint32_t state, + Entity *other_entity, uint32_t other_state); +}; + +} /* namespace lol */ + +#endif // __LOL_EMCEE_H__ + diff --git a/src/entity.cpp b/src/entity.cpp index eb09e388..6ea9f071 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -68,5 +68,16 @@ void Entity::TickDraw(float deltams) #endif } +void Entity::SetState(uint32_t state) +{ + Emcee::SetState(this, state); +} + +void Entity::SetStateWhenMatch(uint32_t state, + Entity *other_entity, uint32_t other_state) +{ + Emcee::SetStateWhenMatch(this, state, other_entity, other_state); +} + } /* namespace lol */ diff --git a/src/entity.h b/src/entity.h index bb50cbd0..0256a4eb 100644 --- a/src/entity.h +++ b/src/entity.h @@ -77,6 +77,19 @@ protected: state; #endif + // Emcee begin +private: + void SetState(uint32_t newstate); + void SetStateWhenMatch(uint32_t newstate, + Entity *other_entity, uint32_t other_state); + virtual uint32_t OnStateChanged(uint32_t newstate) + { + return m_state = newstate; + } + + uint32_t m_state; + // Emcee end + private: Entity *gamenext, *drawnext, *autonext; int ref, autorelease, destroy; diff --git a/src/thread/threadbase.h b/src/thread/threadbase.h index df992f70..3e5d1d31 100644 --- a/src/thread/threadbase.h +++ b/src/thread/threadbase.h @@ -17,7 +17,6 @@ #define __LOL_THREADBASE_H__ #if defined __linux__ || defined __native_client__ -# include # include #elif defined _WIN32 # include diff --git a/test/debug/sandbox.cpp b/test/debug/sandbox.cpp index a1d0c4f6..48f7b1a9 100644 --- a/test/debug/sandbox.cpp +++ b/test/debug/sandbox.cpp @@ -18,6 +18,13 @@ #include "core.h" +class Moo +{ + Moo() {} + + virtual int SetState(int state) { return state; } +}; + using namespace std; using namespace lol;