1
0
Fork 0

(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on

-Codechange: renamed _timer_counter to _palette_animation_counter, as that is what it is
release/0.6
truelight 2007-06-22 20:04:21 +00:00
parent e90b072c11
commit 2e19d3cf78
9 changed files with 26 additions and 17 deletions

View File

@ -875,14 +875,12 @@ static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total
_tp.percent = percent_table[cls]; _tp.percent = percent_table[cls];
} }
/* Don't update the screen too often. So update it once in every 200ms. /* Don't update the screen too often. So update it once in every 200ms */
* However, the _tick_counter increases by 8 every 30ms, so compensate if (!_network_dedicated && _tp.timer != 0 && _realtime_tick - _tp.timer < 200) return;
* for that. */
if (!_network_dedicated && _tp.timer != 0 && _timer_counter - _tp.timer < (200 * 8 / 30)) return;
/* Percentage is about the number of completed tasks, so 'current - 1' */ /* Percentage is about the number of completed tasks, so 'current - 1' */
_tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total; _tp.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_tp.current == 0 ? 0 : _tp.current - 1) / _tp.total;
_tp.timer = _timer_counter; _tp.timer = _realtime_tick;
if (_network_dedicated) { if (_network_dedicated) {
static uint last_percent = 0; static uint last_percent = 0;

View File

@ -665,8 +665,8 @@ void GfxInitPalettes()
_pal_count_dirty = 255; _pal_count_dirty = 255;
} }
#define EXTR(p, q) (((uint16)(_timer_counter * (p)) * (q)) >> 16) #define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16)
#define EXTR2(p, q) (((uint16)(~_timer_counter * (p)) * (q)) >> 16) #define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16)
void DoPaletteAnimations() void DoPaletteAnimations()
{ {
@ -681,10 +681,10 @@ void DoPaletteAnimations()
Colour old_val[38]; Colour old_val[38];
uint i; uint i;
uint j; uint j;
uint old_tc = _timer_counter; uint old_tc = _palette_animation_counter;
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
_timer_counter = 0; _palette_animation_counter = 0;
} }
d = &_cur_palette[217]; d = &_cur_palette[217];
@ -727,7 +727,7 @@ void DoPaletteAnimations()
/* Radio tower blinking */ /* Radio tower blinking */
{ {
byte i = (_timer_counter >> 1) & 0x7F; byte i = (_palette_animation_counter >> 1) & 0x7F;
byte v; byte v;
(v = 255, i < 0x3f) || (v = 255, i < 0x3f) ||
@ -779,7 +779,7 @@ void DoPaletteAnimations()
} }
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
_timer_counter = old_tc; _palette_animation_counter = old_tc;
} else { } else {
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) { if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) {
_pal_first_dirty = 217; _pal_first_dirty = 217;

View File

@ -110,6 +110,7 @@ void InitializeGame(int mode, uint size_x, uint size_y)
_pause_game = 0; _pause_game = 0;
_fast_forward = 0; _fast_forward = 0;
_tick_counter = 0; _tick_counter = 0;
_realtime_tick = 0;
_date_fract = 0; _date_fract = 0;
_cur_tileloop_tile = 0; _cur_tileloop_tile = 0;

View File

@ -1099,7 +1099,7 @@ void GameLoop()
} }
_caret_timer += 3; _caret_timer += 3;
_timer_counter += 8; _palette_animation_counter += 8;
CursorTick(); CursorTick();
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK

View File

@ -270,10 +270,11 @@ struct Cheats {
VARDEF Cheats _cheats; VARDEF Cheats _cheats;
/* NOSAVE: Used in palette animations only, not really important. */ /* NOSAVE: Used in palette animations only, not really important. */
VARDEF int _timer_counter; VARDEF int _palette_animation_counter;
VARDEF uint32 _frame_counter; VARDEF uint32 _frame_counter;
VARDEF uint32 _realtime_tick;
VARDEF bool _is_old_ai_player; // current player is an oldAI player? (enables a lot of cheats..) VARDEF bool _is_old_ai_player; // current player is an oldAI player? (enables a lot of cheats..)

View File

@ -685,6 +685,7 @@ static bool QZ_PollEvent()
static void QZ_GameLoop() static void QZ_GameLoop()
{ {
uint32 cur_ticks = GetTick(); uint32 cur_ticks = GetTick();
uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + 30; uint32 next_tick = cur_ticks + 30;
uint32 pal_tick = 0; uint32 pal_tick = 0;
#ifdef _DEBUG #ifdef _DEBUG
@ -731,6 +732,8 @@ static void QZ_GameLoop()
} }
cur_ticks = GetTick(); cur_ticks = GetTick();
_realtime_tick += cur_ticks - last_cur_ticks;
last_cur_ticks = cur_ticks;
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
next_tick = cur_ticks + 30; next_tick = cur_ticks + 30;

View File

@ -442,6 +442,7 @@ static void SdlVideoStop()
static void SdlVideoMainLoop() static void SdlVideoMainLoop()
{ {
uint32 cur_ticks = SDL_CALL SDL_GetTicks(); uint32 cur_ticks = SDL_CALL SDL_GetTicks();
uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + 30; uint32 next_tick = cur_ticks + 30;
uint32 pal_tick = 0; uint32 pal_tick = 0;
uint32 mod; uint32 mod;
@ -471,6 +472,8 @@ static void SdlVideoMainLoop()
} }
cur_ticks = SDL_CALL SDL_GetTicks(); cur_ticks = SDL_CALL SDL_GetTicks();
_realtime_tick += cur_ticks - last_cur_ticks;
last_cur_ticks = cur_ticks;
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
next_tick = cur_ticks + 30; next_tick = cur_ticks + 30;

View File

@ -795,6 +795,7 @@ static void Win32GdiMainLoop()
{ {
MSG mesg; MSG mesg;
uint32 cur_ticks = GetTickCount(); uint32 cur_ticks = GetTickCount();
uint32 last_cur_ticks = cur_ticks;
uint32 next_tick = cur_ticks + 30; uint32 next_tick = cur_ticks + 30;
_wnd.running = true; _wnd.running = true;
@ -822,6 +823,8 @@ static void Win32GdiMainLoop()
} }
cur_ticks = GetTickCount(); cur_ticks = GetTickCount();
_realtime_tick += cur_ticks - last_cur_ticks;
last_cur_ticks = cur_ticks;
if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) { if (cur_ticks >= next_tick || (_fast_forward && !_pause_game) || cur_ticks < prev_cur_ticks) {
next_tick = cur_ticks + 30; next_tick = cur_ticks + 30;
_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0; _ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;

View File

@ -1639,8 +1639,8 @@ enum MouseClick {
MC_RIGHT, MC_RIGHT,
MC_DOUBLE_LEFT, MC_DOUBLE_LEFT,
MAX_OFFSET_DOUBLE_CLICK = 5, MAX_OFFSET_DOUBLE_CLICK = 5, ///< How much the mouse is allowed to move to call it a double click
TIME_BETWEEN_DOUBLE_CLICK = 50, TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
}; };
void MouseLoop(MouseClick click, int mousewheel) void MouseLoop(MouseClick click, int mousewheel)
@ -1759,12 +1759,12 @@ void HandleMouseEvents()
click = MC_NONE; click = MC_NONE;
if (_left_button_down && !_left_button_clicked) { if (_left_button_down && !_left_button_clicked) {
click = MC_LEFT; click = MC_LEFT;
if (double_click_time != 0 && _tick_counter - double_click_time < TIME_BETWEEN_DOUBLE_CLICK && if (double_click_time != 0 && _realtime_tick - double_click_time < TIME_BETWEEN_DOUBLE_CLICK &&
double_click_x != 0 && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK && double_click_x != 0 && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK &&
double_click_y != 0 && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) { double_click_y != 0 && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) {
click = MC_DOUBLE_LEFT; click = MC_DOUBLE_LEFT;
} }
double_click_time = _tick_counter; double_click_time = _realtime_tick;
double_click_x = _cursor.pos.x; double_click_x = _cursor.pos.x;
double_click_y = _cursor.pos.y; double_click_y = _cursor.pos.y;
_left_button_clicked = true; _left_button_clicked = true;