Esempio n. 1
0
/*
================
idThread::WaitMS
================
*/
void idThread::WaitMS( int time ) {
	if ( time <= 0 ) {
		WaitFrame();
		return;
	}

	Pause();
	int now = gameLocal.time;
	if ( guiThread ) {
		now = gameLocal.ToGuiTime( now );
	}
	waitingUntil = now + time;
}
Esempio n. 2
0
void MainLoop()
{
	for (;;)
	{
		MSG msg;
		if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				return;
			}
			GetMessage(&msg, NULL, 0, 0);
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// Move an effect
			// エフェクトを移動させる
			g_manager->AddLocation(g_handle, ::Effekseer::Vector3D(0.2f, 0.0f, 0.0f));

			// Update effects
			// エフェクトを更新する
			g_manager->Update();

			wglMakeCurrent(g_hDC, g_hGLRC);

			glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			// Begin to draw effects
			// エフェクトの描画を開始する
			g_renderer->BeginRendering();

			// Draw effects
			// エフェクトを描画する
			g_manager->Draw();

			// Finish to draw effects
			// エフェクトの描画を終了する
			g_renderer->EndRendering();

			glFlush();
			wglMakeCurrent(0, 0);
			WaitFrame();
			SwapBuffers(g_hDC);
		}
	}
}
Esempio n. 3
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void MainLoop()
{
	for(;;)
	{ 
		MSG msg;
		if (PeekMessage (&msg,NULL,0,0,PM_NOREMOVE)) 
		{
			if( msg.message == WM_QUIT )
			{
				return ;
			}
			GetMessage (&msg,NULL,0,0);
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// エフェクトの移動処理を行う
			g_manager->AddLocation( g_handle, ::Effekseer::Vector3D( 0.2f, 0.0f, 0.0f ) );

			// エフェクトの更新処理を行う
			g_manager->Update();
			
			
			wglMakeCurrent( g_hDC, g_hGLRC );
			wglSwapIntervalEXT( 1 );

			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f);
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			// エフェクトの描画開始処理を行う。
			g_renderer->BeginRendering();

			// エフェクトの描画を行う。
			g_manager->Draw();

			// エフェクトの描画終了処理を行う。
			g_renderer->EndRendering();

			glFlush();
			wglMakeCurrent( 0, 0 );
			WaitFrame();
			SwapBuffers( g_hDC );
		}
	}
}
Esempio n. 4
0
/*
================
idThread::Event_WaitFrame
================
*/
void idThread::Event_WaitFrame( void ) {
	WaitFrame();
}
Esempio n. 5
0
void GameState::WaitFrames(int n) {
    for (int i = 0; i < n; i++) {
        WaitFrame();
    }
}
Esempio n. 6
0
/* This of course can be optimized :-) */
void RunGame(void)
{
	int i, j;
	SDL_Event event;
	Uint8 *keys;

	/* Paint the background */
	numupdates = 0;
	for ( i=0; i<screen->w; i += background->w ) {
		SDL_Rect dst;

		dst.x = i;
		dst.y = 0;
		dst.w = background->w;
		dst.h = background->h;
		SDL_BlitSurface(background, NULL, screen, &dst);
	}
	SDL_UpdateRect(screen, 0, 0, 0, 0);

	/* Initialize the objects */
	player.alive = 1;
	player.x = (screen->w - player.image->w)/2;
	player.y = (screen->h - player.image->h) - 1;
	player.facing = 0;
	DrawObject(&player);

	for ( i=0; i<MAX_SHOTS; ++i ) {
		shots[i].alive = 0;
	}
	for ( i=0; i<MAX_ALIENS; ++i ) {
		aliens[i].alive = 0;
	}
	CreateAlien();
	DrawObject(&aliens[0]);
	UpdateScreen();

	while ( player.alive ) {
		/* Wait for the next frame */
		WaitFrame();

		/* Poll input queue, run keyboard loop */
		while ( SDL_PollEvent(&event) ) {
			if ( event.type == SDL_QUIT )
				return;
		}
		keys = SDL_GetKeyState(NULL);

		/* Erase everything from the screen */
		for ( i=0; i<MAX_SHOTS; ++i ) {
			if ( shots[i].alive ) {
				EraseObject(&shots[i]);
			}
		}
		for ( i=0; i<MAX_ALIENS; ++i ) {
			if ( aliens[i].alive ) {
				EraseObject(&aliens[i]);
			}
		}
		EraseObject(&player);
		for ( i=0; i<MAX_ALIENS+1; ++i ) {
			if ( explosions[i].alive ) {
				EraseObject(&explosions[i]);
			}
		}

		/* Decrement the lifetime of the explosions */
		for ( i=0; i<MAX_ALIENS+1; ++i ) {
			if ( explosions[i].alive ) {
				--explosions[i].alive;
			}
		}

		/* Create new aliens */
		if ( (rand()%ALIEN_ODDS) == 0 ) {
			CreateAlien();
		}

		/* Create new shots */
		if ( ! reloading ) {
			if ( keys[SDLK_SPACE] == SDL_PRESSED ) {
				for ( i=0; i<MAX_SHOTS; ++i ) {
					if ( ! shots[i].alive ) {
						break;
					}
				}
				if ( i != MAX_SHOTS ) {
					shots[i].x = player.x +
					 (player.image->w-shots[i].image->w)/2;
					shots[i].y = player.y -
							  shots[i].image->h;
					shots[i].alive = 1;
					Mix_PlayChannel(SHOT_WAV,
							sounds[SHOT_WAV], 0);
				}
			}
		}
		reloading = (keys[SDLK_SPACE] == SDL_PRESSED);

		/* Move the player */
		player.facing = 0;
		if ( keys[SDLK_RIGHT] ) {
			++player.facing;
		}
		if ( keys[SDLK_LEFT] ) {
			--player.facing;
		}
		player.x += player.facing*PLAYER_SPEED;
		if ( player.x < 0 ) {
			player.x = 0;
		} else
		if ( player.x >= (screen->w-player.image->w) ) {
			player.x = (screen->w-player.image->w)-1;
		}

		/* Move the aliens */
		for ( i=0; i<MAX_ALIENS; ++i ) {
			if ( aliens[i].alive ) {
				aliens[i].x += aliens[i].facing*ALIEN_SPEED;
				if ( aliens[i].x < 0 ) {
					aliens[i].x = 0;
					aliens[i].y += aliens[i].image->h;
					aliens[i].facing = 1;
				} else
				if ( aliens[i].x >=
					   (screen->w-aliens[i].image->w) ) {
					aliens[i].x =
					   (screen->w-aliens[i].image->w)-1;
					aliens[i].y += aliens[i].image->h;
					aliens[i].facing = -1;
				}
			}
		}

		/* Move the shots */
		for ( i=0; i<MAX_SHOTS; ++i ) {
			if ( shots[i].alive ) {
				shots[i].y -= SHOT_SPEED;
				if ( shots[i].y < 0 ) {
					shots[i].alive = 0;
				}
			}
		}

		/* Detect collisions */
		for ( j=0; j<MAX_SHOTS; ++j ) {
			for ( i=0; i<MAX_ALIENS; ++i ) {
				if ( shots[j].alive && aliens[i].alive &&
					  Collide(&shots[j], &aliens[i]) ) {
					aliens[i].alive = 0;
					explosions[i].x = aliens[i].x;
					explosions[i].y = aliens[i].y;
					explosions[i].alive = EXPLODE_TIME;
					Mix_PlayChannel(EXPLODE_WAV,
							sounds[EXPLODE_WAV], 0);
					shots[j].alive = 0;
					break;
				}
			}
		}
		for ( i=0; i<MAX_ALIENS; ++i ) {
			if ( aliens[i].alive && Collide(&player, &aliens[i]) ) {
				aliens[i].alive = 0;
				explosions[i].x = aliens[i].x;
				explosions[i].y = aliens[i].y;
				explosions[i].alive = EXPLODE_TIME;
				player.alive = 0;
				explosions[MAX_ALIENS].x = player.x;
				explosions[MAX_ALIENS].y = player.y;
				explosions[MAX_ALIENS].alive = EXPLODE_TIME;
				Mix_PlayChannel(EXPLODE_WAV,
							sounds[EXPLODE_WAV], 0);
			}
		}

		/* Draw the aliens, shots, player, and explosions */
		for ( i=0; i<MAX_ALIENS; ++i ) {
			if ( aliens[i].alive ) {
				DrawObject(&aliens[i]);
			}
		}
		for ( i=0; i<MAX_SHOTS; ++i ) {
			if ( shots[i].alive ) {
				DrawObject(&shots[i]);
			}
		}
		if ( player.alive ) {
			DrawObject(&player);
		}
		for ( i=0; i<MAX_ALIENS+1; ++i ) {
			if ( explosions[i].alive ) {
				DrawObject(&explosions[i]);
			}
		}
		UpdateScreen();

		/* Loop the music */
#if defined(PLAY_MOD) || defined(PLAY_MID)
		if ( ! Mix_PlayingMusic() ) {
			Mix_PlayMusic(music, 0);
		}
#else
		if ( ! Mix_Playing(MUSIC_WAV) ) {
			Mix_PlayChannel(MUSIC_WAV, sounds[MUSIC_WAV], 0);
		}
#endif

		/* Check for keyboard abort */
		if ( keys[SDLK_ESCAPE] == SDL_PRESSED ) {
			player.alive = 0;
		}
	}

	/* Wait for the player to finish exploding */
	while ( Mix_Playing(EXPLODE_WAV) ) {
		WaitFrame();
	}
	Mix_HaltChannel(-1);
	return;
}