void MSpawnManager::Tick(unsigned long int nTime) { for(MSpawnList::iterator i=m_SpawnList.begin(); i!=m_SpawnList.end(); i++){ MSpawnData* pSpawn = (MSpawnData*)((*i).second); if ( (nTime - pSpawn->GetLastSpawnTime() >= pSpawn->GetRespawnTime()) && (pSpawn->GetCurrentCount() < pSpawn->GetMaxCount()) ) { if ((pSpawn->GetRespawnTime() == 0) && (pSpawn->GetLastSpawnTime()!=0)) continue; // Respawntime==0 이면 단 1회만 Spawn Spawn(pSpawn, nTime); } } UpdateTick(nTime); }
bool PerfMonitor::Update(float &fFPS) { struct timeval Time; gettimeofday(&Time, NULL); double time = Time.tv_sec + Time.tv_usec * 1.0 / 1000000.0; double tick = time - last_tick_; double d = UpdateTick(tick); last_tick_ = time; if (Time.tv_sec - tv_last_sec_ >= 1) { current_FPS_ = 1.f / d; tv_last_sec_ = Time.tv_sec; fFPS = current_FPS_; return true; } else { fFPS = current_FPS_; return false; } }
int globalwindowhandler::GetKey(truth EmptyBuffer) { if(EmptyBuffer) while(kbhit()) getkey(); int Key = 0; while(!Key) { while(!kbhit()) if(Controls && ControlLoopsEnabled) { static ulong LastTick = 0; UpdateTick(); if(LastTick != Tick) { LastTick = Tick; truth Draw = false; for(int c = 0; c < Controls; ++c) if(ControlLoop[c]()) Draw = true; if(Draw) graphics::BlitDBToScreen(); } } Key = getkey(); if(Key == K_Control_Print && !ScrshotDirectoryName.IsEmpty()) { mkdir(ScrshotDirectoryName.CStr(), S_IRUSR|S_IWUSR); DOUBLE_BUFFER->Save(ScrshotNameHandler()); Key = 0; } } return Key; }
int main(int argc, char *argv[]) { atexit(SDL_Quit); srand(time(NULL)); if(SDL_Init(SDL_INIT_EVERYTHING) == 1){ std::cerr << "Error initializing SDL\n"; return -1; } SDL_WM_SetCaption("SDL Puyo Puyo", NULL); SDL_Surface *screen = SDL_SetVideoMode(SCR_W, SCR_H, SCR_BPP, SDL_SWSURFACE ); if(screen == NULL){ std::cerr << "Error in SetVideoMode\n"; return -1; } SDL_Event event; Uint32 last_tick = SDL_GetTicks(); /* Holy f*****g sound initialization batman. */ int mix_flags = MIX_INIT_MP3; int init_mix = Mix_Init(mix_flags); int audio_rate = 22050; Uint16 audio_format = AUDIO_S16; /* 16-bit stereo */ int audio_channels = 2; int audio_buffers = 4096; if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) { std::cerr << "Unable to open audio\n"; mixer_on = false; } else { if(mix_flags & init_mix != mix_flags){ std::cerr << "Failed to init mp3 support, bg music disabled :(\n"; std::cerr << "mixer error: " << Mix_GetError() << std::endl; mixer_on = false; } else{ mixer_on = true; } } /* Init TTF */ if(TTF_Init() == -1){ std::cerr << "Could not initialize TTF subsystem :(\n"; font_on = false; } else { font_on = true; } GameState *gs = InitNewGame(); if(gs == NULL){ std::cerr << "Error initializing new game.\n"; return -1; } gameloop: while(gs->playing) { while(SDL_PollEvent(&event)) { if(event.type == SDL_QUIT) return 0; if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_ESCAPE) return 0; HandleInput(gs, event); } } if(SDL_GetTicks() - last_tick > 1000/60){ UpdateTick(gs); last_tick = SDL_GetTicks(); } RenderTick(screen, gs); SDL_Flip(screen); } RenderTick(screen, gs); SDL_Delay(5000); CleanGameState(gs); gs = InitNewGame(); goto gameloop; if(screen) SDL_FreeSurface(screen); TTF_Quit(); Mix_Quit(); return 0; }
// Monotonically increasing, not fussy about origin, but measured in ms: virtual double GetRuntimeMS() { return UpdateTick(RunTimeMSNow() - m_started); }
int globalwindowhandler::GetKey(truth EmptyBuffer) { SDL_Event Event; if(EmptyBuffer) { while(SDL_PollEvent(&Event)) ProcessMessage(&Event); KeyBuffer.clear(); } for(;;) if(!KeyBuffer.empty()) { int Key = KeyBuffer[0]; KeyBuffer.erase(KeyBuffer.begin()); if(Key > 0xE000) return Key - 0xE000; if(Key && Key < 0x81) return Key; } else { if(SDL_PollEvent(&Event)) ProcessMessage(&Event); else { #if SDL_MAJOR_VERSION == 1 if(SDL_GetAppState() & SDL_APPACTIVE #else if(SDL_GetWindowFlags(graphics::Window) & (SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_INPUT_FOCUS) #endif && Controls && ControlLoopsEnabled) { static ulong LastTick = 0; UpdateTick(); if(LastTick != Tick) { LastTick = Tick; truth Draw = false; for(int c = 0; c < Controls; ++c) if(ControlLoop[c]()) Draw = true; if(Draw) graphics::BlitDBToScreen(); } SDL_Delay(10); } else { SDL_WaitEvent(&Event); ProcessMessage(&Event); } } } }