- Timestamp:
- Dec 7, 2011, 2:06:19 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/deushax/gtk/glmapview.cpp
r863 r1106 111 111 ticking = TRUE; 112 112 113 /* FIXME: shouldn't this be protected by a mutex? */ 113 114 if (mapviewer) 114 115 mapviewer->SetPOV(gtk_adjustment_get_value(hadj), 115 116 mapviewer->GetHeight() - glarea->allocation.height 116 117 - gtk_adjustment_get_value(vadj)); 117 118 /* Tick the game */119 Ticker::TickGame();120 118 } 121 119 … … 183 181 while (g_main_context_iteration(NULL, FALSE)) 184 182 ; 185 186 /* FIXME: do some GTK stuff instead of waiting for so long */187 Ticker::ClampFps();188 183 } 189 184 -
trunk/src/Makefile.am
r1105 r1106 12 12 worldentity.cpp worldentity.h gradient.cpp gradient.h half.cpp half.h \ 13 13 platform.cpp platform.h sprite.cpp sprite.h trig.cpp trig.h \ 14 real.cpp real.h emcee.cpp emcee.h\14 real.cpp real.h \ 15 15 \ 16 16 lol/unit.h \ -
trunk/src/application/application.cpp
r1105 r1106 60 60 Application::Application(char const *name, ivec2 resolution, float framerate) 61 61 { 62 Emcee::Setup();63 62 data = new ApplicationData(name, resolution, framerate); 64 63 } … … 77 76 { 78 77 delete data; 79 Emcee::Shutdown();80 78 } 81 79 -
trunk/src/core.h
r1105 r1106 104 104 105 105 // Managers 106 #include "emcee.h"107 106 #include "ticker.h" 108 107 #include "forge.h" -
trunk/src/eglapp.cpp
r863 r1106 159 159 while (!Ticker::Finished()) 160 160 { 161 /* Tick the game */162 Ticker::TickGame();163 164 161 /* Tick the renderer, show the frame and clamp to desired framerate. */ 165 162 Ticker::TickDraw(); … … 167 164 eglSwapBuffers(data->egl_dpy, data->egl_surf); 168 165 #endif 169 170 Ticker::ClampFps();171 166 } 172 167 } -
trunk/src/entity.cpp
r1105 r1106 71 71 void Entity::SetState(uint32_t state) 72 72 { 73 Emcee::SetState(this, state);73 Ticker::SetState(this, state); 74 74 } 75 75 … … 77 77 Entity *other_entity, uint32_t other_state) 78 78 { 79 Emcee::SetStateWhenMatch(this, state, other_entity, other_state);79 Ticker::SetStateWhenMatch(this, state, other_entity, other_state); 80 80 } 81 81 -
trunk/src/entity.h
r1105 r1106 30 30 friend class TickerData; 31 31 friend class Dict; 32 friend class Emcee; 32 33 33 34 protected: -
trunk/src/platform/android/androidapp.cpp
r966 r1106 97 97 Java_org_zoy_LolEngine_LolRenderer_nativeRender(JNIEnv* env) 98 98 { 99 Ticker::ClampFps();100 Ticker::TickGame();101 99 Ticker::TickDraw(); 102 100 } -
trunk/src/platform/nacl/nacl_instance.cpp
r1087 r1106 127 127 return; 128 128 129 Ticker::ClampFps();130 Ticker::TickGame();131 132 129 opengl_context_->MakeContextCurrent(this); 133 130 Ticker::TickDraw(); -
trunk/src/platform/nacl/naclapp.cpp
r1084 r1106 59 59 while (!Ticker::Finished()) 60 60 { 61 /* Tick the game */62 Ticker::TickGame();63 64 61 /* Tick the renderer, show the frame and clamp to desired framerate. */ 65 62 Ticker::TickDraw(); … … 67 64 #if defined __native_client__ 68 65 #endif 69 70 Ticker::ClampFps();71 66 } 72 67 } -
trunk/src/platform/ps3/ps3app.cpp
r1063 r1106 119 119 while (!Ticker::Finished()) 120 120 { 121 /* Tick the game */122 Ticker::TickGame();123 124 121 /* Tick the renderer, show the frame and clamp to desired framerate. */ 125 122 Ticker::TickDraw(); … … 131 128 cellSysutilCheckCallback(); 132 129 #endif 133 134 Ticker::ClampFps();135 130 } 136 131 } -
trunk/src/platform/sdl/sdlapp.cpp
r1069 r1106 85 85 while (!Ticker::Finished()) 86 86 { 87 /* Tick the game */88 Ticker::TickGame();89 90 87 /* Tick the renderer, show the frame and clamp to desired framerate. */ 91 88 Ticker::TickDraw(); … … 93 90 SDL_GL_SwapBuffers(); 94 91 #endif 95 Ticker::ClampFps();96 92 } 97 93 } -
trunk/src/ticker.cpp
r735 r1106 67 67 Timer timer; 68 68 float deltams, bias, fps; 69 70 /* Background threads */ 71 static void *GameThreadMain(void *p); 72 static void *DrawThreadMain(void *p); /* unused */ 73 Thread *gamethread, *drawthread; 74 Queue gametick, drawtick; 69 75 70 76 /* Shutdown management */ … … 142 148 } 143 149 144 void Ticker::Setup(float fps) 145 { 146 data->fps = fps; 147 } 148 149 void Ticker::TickGame() 150 { 151 Profiler::Stop(Profiler::STAT_TICK_FRAME); 152 Profiler::Start(Profiler::STAT_TICK_FRAME); 153 154 Profiler::Start(Profiler::STAT_TICK_GAME); 150 void *TickerData::GameThreadMain(void *p) 151 { 152 for (;;) 153 { 154 int tick = data->gametick.Pop(); 155 if (!tick) 156 break; 157 158 Profiler::Stop(Profiler::STAT_TICK_FRAME); 159 Profiler::Start(Profiler::STAT_TICK_FRAME); 160 161 Profiler::Start(Profiler::STAT_TICK_GAME); 155 162 156 163 #if 0 157 Log::Debug("-------------------------------------\n"); 158 for (int i = 0; i < Entity::ALLGROUP_END; i++) 159 { 160 Log::Debug("%s Group %i\n", 161 (i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i); 162 163 for (Entity *e = data->list[i]; e; ) 164 { 165 Log::Debug(" \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy); 166 e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext; 167 } 168 } 169 #endif 170 171 data->frame++; 172 173 /* If recording with fixed framerate, set deltams to a fixed value */ 174 if (data->recording && data->fps) 175 { 176 data->deltams = 1000.0f / data->fps; 177 } 178 else 179 { 180 data->deltams = data->timer.GetMs(); 181 data->bias += data->deltams; 182 } 183 184 /* If shutdown is stuck, kick the first entity we meet and see 185 * whether it makes things better. Note that it is always a bug to 186 * have referenced entities after 20 frames, but at least this 187 * safeguard makes it possible to exit the program cleanly. */ 188 if (data->quit && !((data->frame - data->quitframe) % data->quitdelay)) 189 { 190 int n = 0; 191 data->panic = 2 * (data->panic + 1); 192 193 for (int i = 0; i < Entity::ALLGROUP_END && n < data->panic; i++) 194 for (Entity *e = data->list[i]; e && n < data->panic; e = e->gamenext) 195 if (e->ref) 164 Log::Debug("-------------------------------------\n"); 165 for (int i = 0; i < Entity::ALLGROUP_END; i++) 166 { 167 Log::Debug("%s Group %i\n", 168 (i < Entity::GAMEGROUP_END) ? "Game" : "Draw", i); 169 170 for (Entity *e = data->list[i]; e; ) 196 171 { 197 #if !LOL_RELEASE 198 Log::Error("poking %s\n", e->GetName()); 199 #endif 200 e->ref--; 201 n++; 202 } 203 204 #if !LOL_RELEASE 205 if (n) 206 Log::Error("%i entities stuck after %i frames, poked %i\n", 207 data->nentities, data->quitdelay, n); 208 #endif 209 210 data->quitdelay = data->quitdelay > 1 ? data->quitdelay / 2 : 1; 211 } 212 213 /* Garbage collect objects that can be destroyed. We can do this 214 * before inserting awaiting objects, because only objects already in 215 * the tick lists can be marked for destruction. */ 216 for (int i = 0; i < Entity::ALLGROUP_END; i++) 217 for (Entity *e = data->list[i], *prev = NULL; e; ) 218 { 219 if (e->destroy && i < Entity::GAMEGROUP_END) 220 { 221 /* If entity is to be destroyed, remove it from the 222 * game tick list. */ 223 (prev ? prev->gamenext : data->list[i]) = e->gamenext; 224 225 e = e->gamenext; 226 } 227 else if (e->destroy) 228 { 229 /* If entity is to be destroyed, remove it from the 230 * draw tick list and destroy it. */ 231 (prev ? prev->drawnext : data->list[i]) = e->drawnext; 232 233 Entity *tmp = e; 234 e = e->drawnext; /* Can only be in a draw group list */ 235 delete tmp; 236 237 data->nentities--; 238 } 239 else 240 { 241 if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN) 242 e->destroy = 1; 243 prev = e; 172 Log::Debug(" \\-- %s (ref %i, destroy %i)\n", e->GetName(), e->ref, e->destroy); 244 173 e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext; 245 174 } 246 175 } 247 248 /* Insert waiting objects into the appropriate lists */ 249 while (data->todolist) 250 { 251 Entity *e = data->todolist; 252 data->todolist = e->gamenext; 253 254 e->gamenext = data->list[e->gamegroup]; 255 data->list[e->gamegroup] = e; 256 e->drawnext = data->list[e->drawgroup]; 257 data->list[e->drawgroup] = e; 258 } 259 260 /* Tick objects for the game loop */ 261 for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++) 262 for (Entity *e = data->list[i]; e; e = e->gamenext) 263 if (!e->destroy) 176 #endif 177 178 data->frame++; 179 180 /* If recording with fixed framerate, set deltams to a fixed value */ 181 if (data->recording && data->fps) 182 { 183 data->deltams = 1000.0f / data->fps; 184 } 185 else 186 { 187 data->deltams = data->timer.GetMs(); 188 data->bias += data->deltams; 189 } 190 191 /* If shutdown is stuck, kick the first entity we meet and see 192 * whether it makes things better. Note that it is always a bug to 193 * have referenced entities after 20 frames, but at least this 194 * safeguard makes it possible to exit the program cleanly. */ 195 if (data->quit && !((data->frame - data->quitframe) % data->quitdelay)) 196 { 197 int n = 0; 198 data->panic = 2 * (data->panic + 1); 199 200 for (int i = 0; i < Entity::ALLGROUP_END && n < data->panic; i++) 201 for (Entity *e = data->list[i]; e && n < data->panic; e = e->gamenext) 202 if (e->ref) 203 { 204 #if !LOL_RELEASE 205 Log::Error("poking %s\n", e->GetName()); 206 #endif 207 e->ref--; 208 n++; 209 } 210 211 #if !LOL_RELEASE 212 if (n) 213 Log::Error("%i entities stuck after %i frames, poked %i\n", 214 data->nentities, data->quitdelay, n); 215 #endif 216 217 data->quitdelay = data->quitdelay > 1 ? data->quitdelay / 2 : 1; 218 } 219 220 /* Garbage collect objects that can be destroyed. We can do this 221 * before inserting awaiting objects, because only objects already 222 * inthe tick lists can be marked for destruction. */ 223 for (int i = 0; i < Entity::ALLGROUP_END; i++) 224 for (Entity *e = data->list[i], *prev = NULL; e; ) 264 225 { 265 #if !LOL_RELEASE 266 if (e->state != Entity::STATE_IDLE) 267 Log::Error("entity not idle for game tick\n"); 268 e->state = Entity::STATE_PRETICK_GAME; 269 #endif 270 e->TickGame(data->deltams); 271 #if !LOL_RELEASE 272 if (e->state != Entity::STATE_POSTTICK_GAME) 273 Log::Error("entity missed super game tick\n"); 274 e->state = Entity::STATE_IDLE; 275 #endif 226 if (e->destroy && i < Entity::GAMEGROUP_END) 227 { 228 /* If entity is to be destroyed, remove it from the 229 * game tick list. */ 230 (prev ? prev->gamenext : data->list[i]) = e->gamenext; 231 232 e = e->gamenext; 233 } 234 else if (e->destroy) 235 { 236 /* If entity is to be destroyed, remove it from the 237 * draw tick list and destroy it. */ 238 (prev ? prev->drawnext : data->list[i]) = e->drawnext; 239 240 Entity *tmp = e; 241 e = e->drawnext; /* Can only be in a draw group list */ 242 delete tmp; 243 244 data->nentities--; 245 } 246 else 247 { 248 if (e->ref <= 0 && i >= Entity::DRAWGROUP_BEGIN) 249 e->destroy = 1; 250 prev = e; 251 e = (i < Entity::GAMEGROUP_END) ? e->gamenext : e->drawnext; 252 } 276 253 } 277 254 278 Profiler::Stop(Profiler::STAT_TICK_GAME); 255 /* Insert waiting objects into the appropriate lists */ 256 while (data->todolist) 257 { 258 Entity *e = data->todolist; 259 data->todolist = e->gamenext; 260 261 e->gamenext = data->list[e->gamegroup]; 262 data->list[e->gamegroup] = e; 263 e->drawnext = data->list[e->drawgroup]; 264 data->list[e->drawgroup] = e; 265 } 266 267 /* Tick objects for the game loop */ 268 for (int i = Entity::GAMEGROUP_BEGIN; i < Entity::GAMEGROUP_END; i++) 269 for (Entity *e = data->list[i]; e; e = e->gamenext) 270 if (!e->destroy) 271 { 272 #if !LOL_RELEASE 273 if (e->state != Entity::STATE_IDLE) 274 Log::Error("entity not idle for game tick\n"); 275 e->state = Entity::STATE_PRETICK_GAME; 276 #endif 277 e->TickGame(data->deltams); 278 #if !LOL_RELEASE 279 if (e->state != Entity::STATE_POSTTICK_GAME) 280 Log::Error("entity missed super game tick\n"); 281 e->state = Entity::STATE_IDLE; 282 #endif 283 } 284 285 Profiler::Stop(Profiler::STAT_TICK_GAME); 286 287 data->drawtick.Push(1); 288 } 289 290 data->drawtick.Push(0); 291 292 return NULL; 293 } 294 295 void *TickerData::DrawThreadMain(void *p) 296 { 297 for (;;) 298 { 299 int tick = data->drawtick.Pop(); 300 if (!tick) 301 break; 302 303 data->gametick.Push(1); 304 } 305 306 return NULL; 307 } 308 309 void Ticker::SetState(Entity *entity, uint32_t state) 310 { 311 312 } 313 314 void Ticker::SetStateWhenMatch(Entity *entity, uint32_t state, 315 Entity *other_entity, uint32_t other_state) 316 { 317 318 } 319 320 void Ticker::Setup(float fps) 321 { 322 data->fps = fps; 323 324 data->gamethread = new Thread(TickerData::GameThreadMain, NULL); 325 data->gametick.Push(1); 279 326 } 280 327 281 328 void Ticker::TickDraw() 282 329 { 330 data->drawtick.Pop(); 331 283 332 Profiler::Start(Profiler::STAT_TICK_DRAW); 284 333 … … 323 372 Profiler::Stop(Profiler::STAT_TICK_DRAW); 324 373 Profiler::Start(Profiler::STAT_TICK_BLIT); 325 } 326 327 void Ticker::ClampFps() 328 { 374 375 /* Signal game thread that it can carry on */ 376 data->gametick.Push(1); 377 378 /* Clamp FPS */ 329 379 Profiler::Stop(Profiler::STAT_TICK_BLIT); 330 380 … … 369 419 data->quit = 1; 370 420 data->quitframe = data->frame; 421 422 data->gametick.Push(0); 423 delete data->gamethread; 371 424 } 372 425 -
trunk/src/ticker.h
r748 r1106 33 33 34 34 static void Setup(float fps); 35 static void TickGame();36 35 static void TickDraw(); 37 static void ClampFps();38 36 static void StartBenchmark(); 39 37 static void StopBenchmark(); … … 41 39 static void StopRecording(); 42 40 static int GetFrameNum(); 41 42 static void SetState(Entity *entity, uint32_t state); 43 static void SetStateWhenMatch(Entity *entity, uint32_t state, 44 Entity *other_entity, uint32_t other_state); 43 45 44 46 static void Shutdown();
Note: See TracChangeset
for help on using the changeset viewer.