Changeset - r16516:3e651c9d6713
[Not reviewed]
master
0 6 0
rubidium - 14 years ago 2010-11-19 10:35:59
rubidium@openttd.org
(svn r21252) -Codechange: introduce a constant for the number of milliseconds per game tick and use it
6 files changed with 13 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/gfx_type.h
Show inline comments
 
@@ -256,7 +256,10 @@ enum SpriteType {
 
	ST_MAPGEN   = 1,      ///< Special sprite for the map generator
 
	ST_FONT     = 2,      ///< A sprite used for fonts
 
	ST_RECOLOUR = 3,      ///< Recolour sprite
 
	ST_INVALID  = 4,      ///< Pseudosprite or other unusable sprite, used only internally
 
};
 

	
 
/** The number of milliseconds per game tick. */
 
static const uint MILLISECONDS_PER_TICK = 30;
 

	
 
#endif /* GFX_TYPE_H */
src/video/allegro_v.cpp
Show inline comments
 
@@ -471,13 +471,13 @@ static uint32 GetTime()
 

	
 

	
 
void VideoDriver_Allegro::MainLoop()
 
{
 
	uint32 cur_ticks = GetTime();
 
	uint32 last_cur_ticks = cur_ticks;
 
	uint32 next_tick = cur_ticks + 30;
 
	uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 
	uint32 pal_tick = 0;
 

	
 
	for (;;) {
 
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
 
		InteractiveRandom(); // randomness
 

	
 
@@ -498,13 +498,13 @@ void VideoDriver_Allegro::MainLoop()
 
		}
 

	
 
		cur_ticks = GetTime();
 
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
 
			_realtime_tick += cur_ticks - last_cur_ticks;
 
			last_cur_ticks = cur_ticks;
 
			next_tick = cur_ticks + 30;
 
			next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
			bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
			_ctrl_pressed  = !!(key_shifts & KB_CTRL_FLAG);
 
			_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG);
 

	
src/video/cocoa/event.mm
Show inline comments
 
@@ -603,13 +603,13 @@ static bool QZ_PollEvent()
 

	
 

	
 
void QZ_GameLoop()
 
{
 
	uint32 cur_ticks = GetTick();
 
	uint32 last_cur_ticks = cur_ticks;
 
	uint32 next_tick = cur_ticks + 30;
 
	uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 
	uint32 pal_tick = 0;
 

	
 
#ifdef _DEBUG
 
	uint32 et0 = GetTick();
 
	uint32 st = 0;
 
#endif
 
@@ -652,13 +652,13 @@ void QZ_GameLoop()
 
		}
 

	
 
		cur_ticks = GetTick();
 
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
 
			_realtime_tick += cur_ticks - last_cur_ticks;
 
			last_cur_ticks = cur_ticks;
 
			next_tick = cur_ticks + 30;
 
			next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
			bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
			_ctrl_pressed = !!(_current_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
 
			_shift_pressed = !!(_current_mods & NSShiftKeyMask);
 

	
src/video/dedicated_v.cpp
Show inline comments
 
@@ -253,13 +253,13 @@ static void DedicatedHandleKeyInput()
 
	IConsoleCmdExec(input_line); // execute command
 
}
 

	
 
void VideoDriver_Dedicated::MainLoop()
 
{
 
	uint32 cur_ticks = GetTime();
 
	uint32 next_tick = cur_ticks + 30;
 
	uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
	/* Signal handlers */
 
#if defined(UNIX) || defined(PSP)
 
	signal(SIGTERM, DedicatedSignalHandler);
 
	signal(SIGINT, DedicatedSignalHandler);
 
	signal(SIGQUIT, DedicatedSignalHandler);
 
@@ -302,13 +302,13 @@ void VideoDriver_Dedicated::MainLoop()
 

	
 
		if (!_dedicated_forks) DedicatedHandleKeyInput();
 

	
 
		cur_ticks = GetTime();
 
		_realtime_tick += cur_ticks - prev_cur_ticks;
 
		if (cur_ticks >= next_tick || cur_ticks < prev_cur_ticks || _ddc_fastforward) {
 
			next_tick = cur_ticks + 30;
 
			next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
			GameLoop();
 
			UpdateWindows();
 
		}
 

	
 
		/* Don't sleep when fast forwarding (for desync debugging) */
src/video/sdl_v.cpp
Show inline comments
 
@@ -494,13 +494,13 @@ void VideoDriver_SDL::Stop()
 
}
 

	
 
void VideoDriver_SDL::MainLoop()
 
{
 
	uint32 cur_ticks = SDL_CALL SDL_GetTicks();
 
	uint32 last_cur_ticks = cur_ticks;
 
	uint32 next_tick = cur_ticks + 30;
 
	uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 
	uint32 pal_tick = 0;
 
	uint32 mod;
 
	int numkeys;
 
	Uint8 *keys;
 

	
 
	if (_draw_threaded) {
 
@@ -551,13 +551,13 @@ void VideoDriver_SDL::MainLoop()
 
		}
 

	
 
		cur_ticks = SDL_CALL SDL_GetTicks();
 
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
 
			_realtime_tick += cur_ticks - last_cur_ticks;
 
			last_cur_ticks = cur_ticks;
 
			next_tick = cur_ticks + 30;
 
			next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
			bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
			_ctrl_pressed  = !!(mod & KMOD_CTRL);
 
			_shift_pressed = !!(mod & KMOD_SHIFT);
 

	
src/video/win32_v.cpp
Show inline comments
 
@@ -829,13 +829,13 @@ static void CheckPaletteAnim()
 

	
 
void VideoDriver_Win32::MainLoop()
 
{
 
	MSG mesg;
 
	uint32 cur_ticks = GetTickCount();
 
	uint32 last_cur_ticks = cur_ticks;
 
	uint32 next_tick = cur_ticks + 30;
 
	uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
	_wnd.running = true;
 

	
 
	for (;;) {
 
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
 

	
 
@@ -859,13 +859,13 @@ void VideoDriver_Win32::MainLoop()
 
		}
 

	
 
		cur_ticks = GetTickCount();
 
		if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
 
			_realtime_tick += cur_ticks - last_cur_ticks;
 
			last_cur_ticks = cur_ticks;
 
			next_tick = cur_ticks + 30;
 
			next_tick = cur_ticks + MILLISECONDS_PER_TICK;
 

	
 
			bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
 
			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
 

	
0 comments (0 inline, 0 general)