Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ADD_DEBUG(world,id,name) \
- world->debug->events.push_back(new DebugEvent(id,name));
- struct DebugEvent : public Shared
- {
- int id;
- std::string name;
- std::string dtime;
- DebugEvent();
- DebugEvent(int id_,std::string name_) : id(id_), name(name_), dtime(SetTime()) {}
- void SetId(int id)
- {
- this->id = id;
- }
- void SetName(std::string name)
- {
- this->name = name;
- }
- std::string SetTime()
- {
- time_t rawtime;
- struct tm * timeinfo;
- char buffer[80];
- time (&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo);
- std::string str(buffer);
- return str;
- }
- };
- struct Debug : public Shared
- {
- PtrVector<DebugEvent> events;
- double dump_timer;
- int next_event_id;
- Debug()
- {
- this->next_event_id = -1;
- this->dump_timer = 5;
- this->events.clear();
- }
- void FlushEvents()
- {
- this->next_event_id = -1;
- this->dump_timer = 5;
- this->events.clear();
- }
- void LogEvents(std::string file_name = "Debug.txt")
- {
- bool f_bool = false;
- std::ofstream file;
- file.open(file_name.c_str(),std::ios::out | std::ios::trunc);
- if (file.is_open())
- {
- UTIL_PTR_VECTOR_FOREACH(this->events,DebugEvent,event)
- {
- file << event->dtime + ": " << "ID: [" + event->id << "] Event Name: [" + event->name+"] \n";
- f_bool = true;
- }
- file.close();
- }
- }
- };
- //Timed action set to 1 second interval
- void handle_debug_dump(void *world_void)
- {
- World *world = static_cast<World *>(world_void);
- if(world->debug->dump_timer > 0)
- {
- --world->debug->dump_timer;
- }
- else
- {
- world->debug->LogEvents("Debug.txt");
- world->debug->FlushEvents();
- world->debug->dump_timer = 5;//NeeD CONFIG VALUE
- }
- }
- //Usage
- void MyClass::Function()
- {
- ADD_DEBUG(this->world,this->world->debug->next_event_id,"Function Name")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement