Sylvain Rouquette avatar Sylvain Rouquette committed ec707d1

fixed debug compile (still not running in debug)

Comments (0)

Files changed (12)

game/inc/common/log.h

     char*   buffer_;
     int     context_length_;
 
-    typedef log_map_t   std::map<std::string, Log*>;
+    typedef std::map<std::string, Log*> log_map_t;
     static log_map_t    allocated_;
 };
 

game/inc/game/state/state_factory.h

 #define _GAME_STATE_FACTORY_
 
 #include "state/state_factory.h"
-#include "common/singleton.h"
+
+
+namespace common {
+class Log;
+}
 
 
 namespace state {
     bool register_state(const char* name, creator_t creator);
     state::State* create_state(const char* name);
 
+protected:
+#if defined(DEBUG)
+    static common::Log*    log_;
+#endif
+
 private:
     creator_map_t   creators_;
 };

game/inc/game/state/state_game.h

 #include "common/singleton.h"
 
 
+namespace common {
+class Log;
+}
+
 namespace renderer {
 class Renderer;
 }
 class StateGame: public state::State, public common::Singleton< StateGame >
 {
 public:
+    StateGame();
+
     void enter();
     void update(unsigned int);
     void render(renderer::Renderer* renderer) const;

game/inc/game/state/state_intro.h

 class StateIntro: public state::State, public common::Singleton< StateIntro >
 {
 public:
+    StateIntro();
+
     void enter();
     void update(unsigned int);
     void render(renderer::Renderer* renderer) const;

game/inc/platform/application.h

     Platform* platform_;
     GameLoop* game_loop_;
 
+    bool exit_requested_;
+
 #if defined(DEBUG)
     static common::Log*    log_;
 #endif
-
-    bool exit_requested_;
 };
 
 

game/inc/state/state_state.h

 class Renderer;
 }
 
+namespace common {
+class Log;
+}
 
 namespace state {
 
     virtual void render(renderer::Renderer* renderer) const = 0;
     virtual void enter() {}
     virtual void leave() {}
+
+protected:
+#if defined(DEBUG)
+    common::Log*    log_;
+#endif
 };
 
 

game/src/common/log.cpp

 
 
 #include <stdarg.h>
+#include <cstring>
 #include <cstdio>
 
 
 #define LOG_BUFFER_SIZE     256
 
 
+Log::log_map_t    Log::allocated_;
+
+
 Log::Log(const char* context) :
     context_length_(0)
 {
 }
 
 
-void Log::get(const char* context) {
+Log* Log::get(const char* context) {
     log_map_t::iterator it = allocated_.find(context);
-    if (it != allocated_.end)
-        return it;
+    if (it != allocated_.end())
+        return it->second;
 
     Log* log = new Log(context);
     allocated_[context] = log;

game/src/game/state/state_factory.cpp

 namespace game {
 
 
+#if defined(DEBUG)
+common::Log* StateFactory::log_ = NULL;
+#endif
+
+
 bool StateFactory::register_state(const char* name, creator_t creator)
 {
+#if defined(DEBUG)
+    if (!log_)
+        log_ = common::Log::get("StateFactory");
+#endif
+
     std::string str = std::string(name);
 
     LOG("Registering state %s\n", name);

game/src/game/state/state_game.cpp

 static bool registered = register_state< StateGame >("game");
 
 
+StateGame::StateGame() : state::State(), common::Singleton< StateGame >() {
+#if defined(DEBUG)
+    log_ = common::Log::get("StateGame");
+#endif
+}
+
+
 void StateGame::enter()
 {
     LOG("Entering state game\n");

game/src/game/state/state_intro.cpp

 static bool registered = register_state< StateIntro >("intro");
 
 
+StateIntro::StateIntro() : state::State(), common::Singleton< StateIntro >() {
+#if defined(DEBUG)
+    log_ = common::Log::get("StateIntro");
+#endif
+}
+
+
 void StateIntro::enter()
 {
     LOG("Entering state intro\n");

game/src/platform/application.cpp

 
 
 #if defined(DEBUG)
-Application::log_ = NULL;
+common::Log* Application::log_ = NULL;
 #endif
 
 
 {
 #if defined(DEBUG)
     if (!log_)
-        log_ = common::Log::get("platform");
+        log_ = common::Log::get("Application");
 #endif
 }
 
         if conf.options.debug:
             conf.env.cxxflags.append('-g')
 
+    if conf.options.debug:
+        conf.env.cxxflags.append('-DDEBUG')
+
     if Utils.unversioned_sys_platform() == 'win32':
         conf.env.cxxflags.extend(('-mwindows',
                                   '-DWINVER=0x0601',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.