コード例 #1
0
ファイル: win8game.cpp プロジェクト: Teile/monkey
void BBWin8Game::Run(){

	if( CFG_WIN8_SCREEN_ORIENTATION & 1 ){
		_deviceRotation=0;
	}else if( CFG_WIN8_SCREEN_ORIENTATION & 2 ){
		_deviceRotation=1;		
	}else if( CFG_WIN8_SCREEN_ORIENTATION & 4 ){
		_deviceRotation=2;		
	}else if( CFG_WIN8_SCREEN_ORIENTATION & 8 ){
		_deviceRotation=3;
	}else{
		_deviceRotation=0;
	}

	ValidateOrientation();

	StartGame();
	
	for(;;){
	
		if( _updateRate==60 ){
			PollEvents();
			UpdateGame();
			RenderGame();
			continue;
		}
	
		if( !_updateRate || _suspended ){
			RenderGame();
			WaitEvents();
			continue;
		}
		
		double time=GetTime();
		if( time<_nextUpdate ){
			Sleep( _nextUpdate-time );
			continue;
		}
		
		PollEvents();
				
		int updates=0;
		for(;;){
			_nextUpdate+=_updatePeriod;
			
			UpdateGame();
			if( !_updateRate ) break;
			
			if( _nextUpdate>GetTime() ){
				break;
			}
			
			if( ++updates==8 ) break;
		}
		RenderGame();
		if( updates==8 ) _nextUpdate=GetTime();
	}
}
コード例 #2
0
ファイル: main.cpp プロジェクト: geoff-wode/strumpfaffen
int main(int argc, char* argv[])
{
	SDL_Init(SDL_INIT_EVERYTHING);
	atexit(SDL_Quit);

	debugLogFile = fopen("stderr.txt", "wb");
	{
		char buffer[128];
		const time_t raw(time(NULL));
		const struct tm* local(localtime(&raw));
		strftime(buffer, sizeof(buffer)-1, "%c\n", local);
		LOG("%s", buffer);
	}

	if (!Initialise()) { exit(EXIT_FAILURE); }

	unsigned int lastUpdate = 0;
	while (!quit)
	{
		HandleEvents();

		unsigned int now = SDL_GetTicks();
		unsigned int elapsedMS = now - lastUpdate;
		lastUpdate = now;
		UpdateGame(elapsedMS);

		RenderFrame();

		Device::SwapBuffers();
	}

	return 0;
}
コード例 #3
0
ファイル: Game.cpp プロジェクト: dexter1986/unli
void Game::Go(){
	//pWnd->ShowMouseCursor(false);

	//objeto para recibir eventos
	Event evt;

	//Inicializa los objetos del juego
	Init();
	
	if(pWnd->IsOpened())
	{
		Intro();
		ShowMenu();		
	}
	while(pWnd->IsOpened()){
		//procesar eventos
		while (pWnd->GetEvent(evt))
			ProcessEvent(evt);

		//procesar colisiones
		ProcessCollisions();
		
		//actualizar estados de objetos
		UpdateGame();
		
		pWnd->Clear();
		
		DrawGame();
		
		pWnd->Display();
	}
	StopMusic();	
}
コード例 #4
0
ファイル: main.cpp プロジェクト: Arikado/Wii-Homebrew
int main( int argc, char *argv[] )
{
    fatInitDefault();

	if( argc >= 2 )
	{
		if( strcmp( argv[1], "--help" ) == 0 || strcmp( argv[1], "-h" ) == 0 )
		{
			printf( "%s V.%s\n\n", CAPTION, VERSION );
			printf( "Usage: %s [OPTIONS] [LEVELFILE]\n", argv[0] );
			printf( "Where LEVELFILE is the name of the level to play or OPTIONS is one of the following.\n" );
			printf( "-h, --help\tDisplay this message\n" );
			printf( "-v, --version\tShow the version of this binary\n" );
			return 0;
		}
		else if( strcmp( argv[1], "--version" ) == 0 || strcmp( argv[1], "-v" ) == 0 )
		{
			printf( "%s %s\n", CAPTION, VERSION );
			return 0;
		}
		else
		{
			printf( "Unknown argument %s\n", argv[1] );
		}
	}
	
	Leveleditor_Mode = 0;
	Game_debug = 0;
	cameraposx = 0;
	cameraposy = 0;

	MassiveObjects.reserve( 1000 );
	PassiveObjects.reserve( 1000 );
	ActiveObjects.reserve( 500 );
	EnemyObjects.reserve( 500 );
	
	srand( time( NULL ) );
	atexit( ExitGame );

	if( argc == 2 )
	{
		StartGame( argv[1] );
	}
	else
	{
		StartGame();
	}
	
	while( !done )
	{
		ProcessEvents();
		ProcessInput();
		UpdateGame();
		Framerate.Update();
	}

	ExitGame();

	return 0; // Successful
}
コード例 #5
0
ファイル: Game.cpp プロジェクト: Allanis/LibD
void Game::ProcessEvents(float dt) {
  if(_inTitleScreen) {
    UpdateTitle(dt);
  } else {
    UpdateGame(dt);
  }
  _slot->ProcessEvents();
}
コード例 #6
0
ファイル: Main.cpp プロジェクト: m1h4/Xetrix
bool Update(void)
{
	if(!UpdateTimer())
		return false;

	if(!UpdateGame())
		return false;

	return true;
}
コード例 #7
0
/*
=============================
idGameBustOutWindow::Draw
=============================
*/
void idGameBustOutWindow::Draw(int time, float x, float y) {
	int i;

	//Update the game every frame before drawing
	UpdateGame();

	for( i = entities.Num()-1; i >= 0; i-- ) {
		entities[i]->Draw(dc);
	}
}
コード例 #8
0
ファイル: Model_Level4.cpp プロジェクト: barryHub20/SP3
void Model_Level4::Update(double dt, bool* myKeys, Vector3 mousePos, StateManager::STATES currentState)
{
	/* parent class update */
	Model_Level::Update(dt, myKeys, mousePos, currentState);

	if (keyPressedTimer < delayTime)
		keyPressedTimer += dt;

	/* Update game */
	UpdateGame(dt, myKeys);
}
コード例 #9
0
void AppStateGameServer::Update() {
    // Insert game logic in UpdateGame()

    //////////////////////////////////////////////////////////////////////////////////
    // Server Stuff
    time_t now;
    time(&now);

    if (debugLevel > DL_LOW)
    {
        if (now - lastSpeedDisplay >= 1)
        {
            time(&lastSpeedDisplay);
            if (clientCount > 0)
                std::cout << "[ Server Speed ] " << CurrentDateTime() << " >>> Clients: " << clientCount << "; Frames Per Second: " << Clock::Frame_Control.Get_FPS() << std::endl;
        }
    }

    // Have we contacted the main server yet?
    if (!networkMainServer->IsInited())
    {
        if (tryMainAgain-- <= 0)
        {
            // std::cout << "Trying main again\n";
            if (networkMainServer->Init() != 1)
                tryMainAgain = 100;
            else
                UpdateMainServer();
        }
    }
    else
    {
        int receiveId = networkMainServer->ReceiveData();
        if (receiveId == -2) // Server hung up
        {
            std::cout << "MainServer hung up.\n";
            networkMainServer->Close();
            tryMainAgain = 100;
        }
    }

    if (inLobby)
        UpdateLobby();
    else
        UpdateGame();

    if (now - lastActivity > TimeoutInSeconds && clientCount == 0)
    {
        std::cout << "[ Server Timed Out ] " << CurrentDateTime() << " >>> No activity for " << TimeoutInSeconds << " seconds." << std::endl;

        AppStateEvent::New_Event(APPSTATE_NONE);
    }
    //////////////////////////////////////////////////////////////////////////////////
}
コード例 #10
0
ファイル: exp.cpp プロジェクト: Tee3D/EXPRemake
void CGameControllerEXP::StopClient(int ID)
{
	UpdateGame(ID);
	int min = GameServer()->m_apPlayers[ID]->m_GameExp.m_Time / 60;
	int sec = GameServer()->m_apPlayers[ID]->m_GameExp.m_Time % 60;
	char buf[512];
	str_format(buf, sizeof(buf), "'%s' finished in %d minutes %d seconds with %d kills. Good Game!", Server()->ClientName(ID), min, sec, GameServer()->m_apPlayers[ID]->m_GameExp.m_Kills);
	GameServer()->SendChatTarget(-1, buf);
	
	bool GotFreezer = false;
	if(GameServer()->m_apPlayers[ID]->m_GameExp.m_Weapons & (int)pow(2, WEAPON_FREEZER))
		GotFreezer = true;
	
	RestartClient(ID);
	
	if(GotFreezer)
		GameServer()->m_apPlayers[ID]->GetWeapon(WEAPON_FREEZER);
}
コード例 #11
0
ファイル: missile_commander.c プロジェクト: AdanBB/raylib
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    InitWindow(screenWidth, screenHeight, "sample game: missile commander");

    InitGame();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else

    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------
    
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        UpdateGame();
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        DrawGame();
        //----------------------------------------------------------------------------------
    }
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadGame();         // Unload loaded data (textures, sounds, models...)
    
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
コード例 #12
0
ファイル: GameApp.cpp プロジェクト: Rinirihiriro/SmallPlanet
int GameApp::Run()
{
	MSG message;
	ZeroMemory(&message, sizeof(message));

	static int fps_calculating_counter = 0;
	static DWORD fps_calculating_tick = timeGetTime();

	while (message.message != WM_QUIT)
	{
		dwNowTick = timeGetTime();
		if (dwOldTick==0) dwOldTick = dwNowTick;

		if ( PeekMessage(&message, NULL, 0, 0, PM_REMOVE) )
		{
			TranslateMessage(&message);
			DispatchMessage(&message);
		}
		else 
		{
			if ( dwNowTick >= dwOldTick + SPF )
			{
				fps_calculating_counter++;
				JInput::Update();
				if( !UpdateGame() ) break;
				dwOldTick += SPF;
				if (fps_calculating_counter >= 10)
				{
					fRealFPS = 1000.0f * fps_calculating_counter / ( dwNowTick - fps_calculating_tick );
					fps_calculating_tick = dwNowTick;
					fps_calculating_counter = 0;
				}
			}
		}
	}
	return (int)message.wParam;
}
コード例 #13
0
ファイル: missile_commander.c プロジェクト: AdanBB/raylib
// Update and Draw (one frame)
void UpdateDrawFrame(void)
{
    UpdateGame();
    DrawGame();
}
コード例 #14
0
ファイル: GameEngine.cpp プロジェクト: TimLiszak/Midi
void	CGameEngine::Run( CGameMode* pGameMode )
{
	m_nPreviousTime = 0;

	m_pCurrentGameMode = pGameMode;
	m_pCurrentGameMode->Init();

	while( !m_bQuit )					
	{
		// Switch game mode
		if ( m_pNextGameMode )
		{
			m_pCurrentGameMode->Term();
			delete m_pCurrentGameMode;

			m_pCurrentGameMode = m_pNextGameMode;
			m_pCurrentGameMode->Init();
			m_pNextGameMode = NULL;
		}


		// Calculate frame time
		INT nTime = clock();
		FLOAT fFrameTime = (FLOAT)(nTime - m_nPreviousTime) / 1000.0f;
		
		if ( fFrameTime == 0.0f ) continue; // too fast, busy wait

		fFrameTime = Math::Min( fFrameTime, 0.080f );
		GetDebugPrint()->Printf( "FPS %0.2f\n", 1.0f / fFrameTime );
		m_nPreviousTime = nTime;

		m_StoredFrameTimes[m_nStoredFrameTimeCnt++] = fFrameTime;
		if ( m_nStoredFrameTimeCnt >= NUM_FRAME_TIMES )
		{
			m_nStoredFrameTimeCnt = 0;
		}

		// Calculate average frame time over past few frames
		FLOAT fAvg = 0.0f;
		for ( INT i = 0; i < NUM_FRAME_TIMES; i++ )
		{
			fAvg += m_StoredFrameTimes[i];
		}
		fAvg /= NUM_FRAME_TIMES;
		m_fFrameTime = fAvg;

		if ( m_bDebugPause )
		{
			CKeyboard* pKey = GetInput()->GetKeyboard();
			if ( pKey->IsKeyTriggered( EKbKey_RIGHT ) )
			{
				m_fFrameTime = 1.0f / 60.0f;
			}
			else
			{
				m_fFrameTime = 0.0f;
			}
		}

		m_fTotalTime += m_fFrameTime;

		UpdateGame( m_pCurrentGameMode );
		RenderGame( m_pCurrentGameMode );

		m_pView->Sync();
	}

	m_pCurrentGameMode->Term();
	delete m_pCurrentGameMode;
}
コード例 #15
0
ファイル: Game.cpp プロジェクト: Allanis/Unuk
gameNavVal_t Game::Run(void) {
  _player->LoadSprites("../Data/Media/Images/Characters/Reniesta.png", 40, 45);

  int fps = 0;
  int frame = 0;
  int nextGameTick = SDL_GetTicks();

  Timer frameTimer;
  frameTimer.Start();

  Timer fpsCalc;
  fpsCalc.Start();

  Timer renderTimer;
  Timer updateTimer;

  stringstream playerHealth;
  _playerHealth.SetXY(15, 27);
  _playerHealth.SetTextBlended("Player Health - XX", vsmall, COLOUR_WHITE);

  stringstream playerExp;
  _playerExp.SetXY(15, 57);
  _playerExp.SetTextBlended("Player Level XX (XX/XX)", vsmall, COLOUR_WHITE);

  _gameRenderTime.SetXY(10, 90);
  _gameRenderTime.SetTextBlended("Render - XX", vsmall, COLOUR_BLACK);

  _gameUpdateTime.SetXY(10, 110);
  _gameUpdateTime.SetTextBlended("Update - XX", vsmall, COLOUR_BLACK);

  stringstream playerXYString;
  _playerXY.SetXY(10, 130);
  _playerXY.SetTextBlended("Player coords - XX XX", vsmall, COLOUR_BLACK);

  _playerHealthBar.SetBackgroundRGB(0, 0, 0);
  _playerHealthBar.SetForegroundRGB(255, 0, 0);
  _playerHealthBar.SetXY(10, 20);
  _playerHealthBar.SetWidthHeight(200, 25);

  _playerExpBar.SetBackgroundRGB(0, 0, 0);
  _playerExpBar.SetForegroundRGB(0, 0, 255);
  _playerExpBar.SetXY(10, 50);
  _playerExpBar.SetWidthHeight(200, 25);
  _playerExpBar.SetProgress(0.0f);

  eventHistory = scNew(EventHistory,);

  _gameRunning = true;
  while(_gameRunning) {
    bool stillRunning = true;

    updateTimer.Start();
    while((int)SDL_GetTicks() > nextGameTick) {
      HandleInput();
      if (!_gameRunning) {
        stillRunning = false;
        break;
      }

      UpdateGame();

      nextGameTick += SKIP_TICKS;
    }
    updateTimer.Pause();

    if (!stillRunning) {
      break;
    }

    renderTimer.Start();
    Render();
    renderTimer.Pause();

    // Calculate and display our FPS.
    if(fpsCalc.GetTicks() >= 1000) {
      fps = frame / (fpsCalc.GetTicks() / 1000);

      stringstream caption;
      caption << "Unuk - FPS: " << fps;

      SDL_WM_SetCaption(caption.str().c_str(), NULL);

      fpsCalc.Start();
      frame = 0;

      playerHealth.str("");
      playerHealth << "Player Health - " << _player->GetHealth();
      _playerHealth.SetTextBlended(playerHealth.str(), vsmall, COLOUR_WHITE);

      _playerHealthBar.SetProgress((float)_player->GetHealth() / 100.0f);

      playerExp.str("");
      playerExp << "Player Level " << _player->GetLevel() <<  "  (" << _player->GetExp() << "/" << Player::EXP_TABLE[_player->GetLevel() - 1] << ")";
      _playerExp.SetTextBlended(playerExp.str(), vsmall, COLOUR_WHITE);

      _playerExpBar.SetProgress((float)_player->GetExp() / (float)Player::EXP_TABLE[_player->GetLevel() - 1]);

      // Check to see if we are allowed to display debug info.
      if(debugEnabled) {
        _gameUpdateTime.SetTextBlended("Update - " + updateTimer.GetTicksStr(), vsmall, COLOUR_BLACK);
        _gameRenderTime.SetTextBlended("Render - " + renderTimer.GetTicksStr(), vsmall, COLOUR_BLACK);

        playerXYString.str("");
        playerXYString << "Player coords: x" << _player->GetX() << ", y" << _player->GetY();
        _playerXY.SetTextBlended(playerXYString.str(), vsmall, COLOUR_BLACK);
      }
    }
    // Restrict the fps.
    if(1000 / MAX_FPS > frameTimer.GetTicks()) {
      // SDL_Delay does not accept a float so for higher framerate
      // limits there's an innacuracy. This is as much as 3fps
      // at a limit of 60fps.
      SDL_Delay((1000 / MAX_FPS) - frameTimer.GetTicks());
    }
    frameTimer.Start();
    frame++;
  }

  delete eventHistory;

  return _runGameReturnValue;
}
コード例 #16
0
ファイル: win8game.cpp プロジェクト: Alshurafa/monkey
void BBWin8Game::Run(){

	DisplayOrientations prefs=DisplayOrientations::None;
	if( CFG_WIN8_SCREEN_ORIENTATION & 1 ) prefs=prefs|DisplayOrientations::Portrait;
	if( CFG_WIN8_SCREEN_ORIENTATION & 2 ) prefs=prefs|DisplayOrientations::Landscape;
	if( CFG_WIN8_SCREEN_ORIENTATION & 4 ) prefs=prefs|DisplayOrientations::PortraitFlipped;
	if( CFG_WIN8_SCREEN_ORIENTATION & 8 ) prefs=prefs|DisplayOrientations::LandscapeFlipped;
	if( prefs==DisplayOrientations::None ) prefs=DisplayProperties::CurrentOrientation;
	
	Windows::Graphics::Display::DisplayProperties::AutoRotationPreferences=prefs;

	int orientation;
	for( orientation=0;orientation<4 && !(CFG_WIN8_SCREEN_ORIENTATION & (1<<orientation));++orientation ) {}
	if( orientation==4 ) orientation=DeviceOrientation();

#if WINDOWS_8
	_deviceRotation=(orientation-1)&3;
#elif WINDOWS_PHONE_8
	_deviceRotation=orientation;
#endif	

	ValidateOrientation();
	
	StartGame();
	
	for(;;){
	
		if( _updateRate==60 ){
			PollEvents();
			UpdateGame();
			RenderGame();
			continue;
		}
	
		if( !_updateRate || _suspended ){
			RenderGame();
			WaitEvents();
			continue;
		}
		
		double time=GetTime();
		if( time<_nextUpdate ){
			Sleep( _nextUpdate-time );
			continue;
		}
		
		PollEvents();
				
		int updates=0;
		for(;;){
			_nextUpdate+=_updatePeriod;
			
			UpdateGame();
			if( !_updateRate ) break;
			
			if( _nextUpdate>GetTime() ){
				break;
			}
			
			if( ++updates==8 ) break;
		}
		RenderGame();
		if( updates==8 ) _nextUpdate=GetTime();
	}
}
コード例 #17
0
STDMETHODIMP CGNetUpdater::UpdateAborted(IGame *Game)
{
	UpdateGame(Game, false);
	return S_OK;
}
コード例 #18
0
STDMETHODIMP CGNetUpdater::UpdateComplete(IGame *Game)
{
	UpdateGame(Game, true);
	return S_OK;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: Dingf/Paper-TD
void UpdateStates()
{
	UpdateGame();
	HandleSpecialKeyPressed();
	HandleNormalKeyPressed();
}