SDL_GetTicks() => GFX2_GetTicks()

Signed-off-by: Thomas Bernard <miniupnp@free.fr>
This commit is contained in:
Thomas Bernard 2018-05-28 12:31:42 +02:00
parent a6c948b27e
commit fb51c1bb1c
12 changed files with 80 additions and 49 deletions

View File

@ -355,7 +355,7 @@ void Button_Select_forecolor(int btn)
int color;
time_previous = time_click;
time_click = SDL_GetTicks();
time_click = GFX2_GetTicks();
color=Pick_color_in_palette();

View File

@ -3246,9 +3246,9 @@ short Window_clicked_button(void)
{
short clicked_button;
T_List_button * list;
static Uint32 time_last_click = 0;
static dword time_last_click = 0;
static int last_list_number = -1;
Uint32 time_now;
dword time_now;
// Check which controls was clicked (by rectangular area)
clicked_button = Window_get_clicked_button();
@ -3263,7 +3263,7 @@ short Window_clicked_button(void)
clicked_line = (((Mouse_Y-Window_pos_Y)/Menu_factor_Y)-list->Entry_button->Pos_Y)>>3;
if (clicked_line >= list->Scroller->Nb_elements) // Below last line
return 0;
time_now = SDL_GetTicks();
time_now = GFX2_GetTicks();
if (clicked_line == list->Cursor_position)
{
// Double click check
@ -3603,15 +3603,15 @@ void Remap_UI_in_window_backgrounds(const byte * conversion_table)
void Delay_with_active_mouse(int speed)
{
Uint32 end;
dword end;
byte original_mouse_k = Mouse_K;
end = SDL_GetTicks()+speed*10;
end = GFX2_GetTicks()+speed*10;
do
{
Get_input(20);
} while (Mouse_K == original_mouse_k && SDL_GetTicks()<end);
} while (Mouse_K == original_mouse_k && GFX2_GetTicks()<end);
}
///

View File

@ -1385,7 +1385,7 @@ int L_MessageBox(lua_State* L)
int L_Wait(lua_State* L)
{
float delay;
Uint32 end;
dword end;
int nb_args=lua_gettop(L);
LUA_ARG_LIMIT (1, "wait");
@ -1403,19 +1403,19 @@ int L_Wait(lua_State* L)
return 0;
}
// Wait specified time
end = SDL_GetTicks()+(int)(delay*1000.0);
end = GFX2_GetTicks()+(int)(delay*1000.0);
do
{
Get_input(20);
} while (SDL_GetTicks()<end);
} while (GFX2_GetTicks()<end);
return 0;
}
int L_WaitBreak(lua_State* L)
{
float delay;
Uint32 end;
dword end;
int nb_args=lua_gettop(L);
LUA_ARG_LIMIT (1, "waitbreak");
@ -1434,7 +1434,7 @@ int L_WaitBreak(lua_State* L)
return 1;
}
// Wait specified time
end = SDL_GetTicks()+(int)(delay*1000.0);
end = GFX2_GetTicks()+(int)(delay*1000.0);
do
{
@ -1444,7 +1444,7 @@ int L_WaitBreak(lua_State* L)
lua_pushinteger(L, 1);
return 1;
}
} while (SDL_GetTicks()<end);
} while (GFX2_GetTicks()<end);
lua_pushinteger(L, 0);
return 1;
@ -1453,7 +1453,7 @@ int L_WaitBreak(lua_State* L)
int L_WaitInput(lua_State* L)
{
float delay;
Uint32 end;
dword end;
int nb_args=lua_gettop(L);
int moved;
@ -1478,13 +1478,13 @@ int L_WaitInput(lua_State* L)
else
{
// Wait specified time
end = SDL_GetTicks()+(int)(delay*1000.0);
end = GFX2_GetTicks()+(int)(delay*1000.0);
moved=0;
do
{
moved=Get_input(20);
} while (!moved && SDL_GetTicks()<end);
} while (!moved && GFX2_GetTicks()<end);
}
lua_pushboolean(L, moved ? 1 : 0);

View File

@ -1111,13 +1111,13 @@ void Fill_general(byte fill_color)
//////////////////////////////////////////////////////////////////////////////
// Data used by ::Init_permanent_draw() and ::Pixel_figure_permanent()
static Uint32 Permanent_draw_next_refresh=0;
static dword Permanent_draw_next_refresh=0;
static int Permanent_draw_count=0;
void Init_permanent_draw(void)
{
Permanent_draw_count = 0;
Permanent_draw_next_refresh = SDL_GetTicks() + 100;
Permanent_draw_next_refresh = GFX2_GetTicks() + 100;
}
// Affichage d'un point de façon définitive (utilisation du pinceau)
@ -1129,7 +1129,7 @@ void Fill_general(byte fill_color)
// Check every 8 pixels
if (! (Permanent_draw_count&7))
{
Uint32 now = SDL_GetTicks();
dword now = GFX2_GetTicks();
SDL_PumpEvents();
if (now>= Permanent_draw_next_refresh)
{

View File

@ -989,7 +989,7 @@ int Get_input(int sleep_time)
long time_now;
int step=0;
time_now=SDL_GetTicks();
time_now=GFX2_GetTicks();
if (Directional_first_move==0)
{
@ -1081,14 +1081,14 @@ static int Color_cycling(void)
if (start==0)
{
// First run
start = SDL_GetTicks();
start = GFX2_GetTicks();
return 1;
}
if (!Allow_colorcycling || !Cycling_mode)
return 1;
now = SDL_GetTicks();
now = GFX2_GetTicks();
changed=0;
// Check all cycles for a change at this tick

View File

@ -630,10 +630,10 @@ void Button_Anim_last_frame(void)
void Button_Anim_continuous_next(void)
{
Uint32 time_start;
dword time_start;
int time_in_current_frame=0;
time_start = SDL_GetTicks();
time_start = GFX2_GetTicks();
do
{
@ -642,7 +642,7 @@ void Button_Anim_continuous_next(void)
Get_input(20);
time_now=SDL_GetTicks();
time_now=GFX2_GetTicks();
time_in_current_frame += time_now-time_start;
time_start=time_now;
target_frame = Main.current_layer;
@ -665,10 +665,10 @@ void Button_Anim_continuous_next(void)
void Button_Anim_continuous_prev(void)
{
Uint32 time_start;
dword time_start;
int time_in_current_frame=0;
time_start = SDL_GetTicks();
time_start = GFX2_GetTicks();
do
{
@ -677,7 +677,7 @@ void Button_Anim_continuous_prev(void)
Get_input(20);
time_now=SDL_GetTicks();
time_now=GFX2_GetTicks();
time_in_current_frame += time_now-time_start;
time_start=time_now;
target_frame = Main.current_layer;

View File

@ -1606,7 +1606,7 @@ if (Create_lock_file(Config_directory))
void Rotate_safety_backups(void)
{
Uint32 now;
dword now;
T_IO_Context context;
char file_name[12+1];
char deleted_file[MAX_PATH_CHARACTERS];
@ -1614,7 +1614,7 @@ void Rotate_safety_backups(void)
if (!Safety_backup_active)
return;
now = SDL_GetTicks();
now = GFX2_GetTicks();
// It's time to save if either:
// - Many edits have taken place
// - A minimum number of edits have taken place AND a minimum time has passed
@ -1630,7 +1630,7 @@ void Rotate_safety_backups(void)
sprintf(deleted_file, "%s%c%6.6d" BACKUP_FILE_EXTENSION,
Config_directory,
Main.safety_backup_prefix,
(Uint32)(Main.safety_number + 1000000l - Rotation_safety_backup) % (Uint32)1000000l);
(dword)(Main.safety_number + 1000000l - Rotation_safety_backup) % (dword)1000000l);
remove(deleted_file); // no matter if fail
// Reset counters
@ -1640,7 +1640,7 @@ void Rotate_safety_backups(void)
// Create a new file name and save
sprintf(file_name, "%c%6.6d" BACKUP_FILE_EXTENSION,
Main.safety_backup_prefix,
(Uint32)Main.safety_number);
(int)Main.safety_number);
Init_context_backup_image(&context, file_name, Config_directory);
context.Format=FORMAT_GIF;
// Provide original file data, to store as a GIF Application Extension

View File

@ -2,6 +2,7 @@
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2018 Thomas Bernard
Copyright 2011 Pawel Góralski
Copyright 2008 Yves Rizoud
Copyright 2008 Franck Charlet
@ -30,6 +31,13 @@
#endif
#include <stdlib.h>
#include <math.h>
#if !defined(USE_SDL) && !defined(USE_SDL2)
#if defined(WIN32)
#include <windows.h>
#else
#include <sys/time.h>
#endif
#endif
#include "struct.h"
#include "sdlscreen.h"
#include "global.h"
@ -233,7 +241,7 @@ void Init_chrono(dword delay)
// Démarrer le chrono
{
Timer_delay = delay;
Timer_start = SDL_GetTicks()/55;
Timer_start = GFX2_GetTicks()/55;
return;
}
@ -496,7 +504,7 @@ byte Effect_alpha_colorize (word x,word y,byte color)
void Check_timer(void)
{
if((SDL_GetTicks()/55)-Timer_delay>Timer_start) Timer_state=1;
if((GFX2_GetTicks()/55)-Timer_delay>Timer_start) Timer_state=1;
}
void Flip_Y_lowlevel(byte *src, short width, short height)
@ -882,3 +890,17 @@ int Convert_videomode_arg(const char *argument)
return -1;
}
dword GFX2_GetTicks(void)
{
#if defined(USE_SDL) || defined(USE_SDL2)
return SDL_GetTicks();
#elif defined(WIN32)
return GetTickCount();
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0)
return 0;
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
#endif
}

View File

@ -2,6 +2,7 @@
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2018 Thomas Bernard
Copyright 2007 Adrien Destugues
Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud)
@ -23,6 +24,9 @@
/// Miscellanous unsorted functions.
//////////////////////////////////////////////////////////////////////////////
#ifndef MISC_H__
#define MISC_H__
#include "struct.h"
#include "global.h"
@ -149,3 +153,8 @@ int Convert_videomode_arg(const char *argument);
int Popcount_word(word x);
int Popcount_dword(dword x);
/// Return a number of milliseconds
dword GFX2_GetTicks(void);
#endif

View File

@ -47,7 +47,7 @@
/// Time (in SDL ticks) when the next airbrush drawing should be done. Also used
/// for discontinuous freehand drawing.
Uint32 Airbrush_next_time;
dword Airbrush_next_time;
// Panning needs its own operation storage because it may interrupt another
// interrupting operation
@ -311,7 +311,7 @@ void Freehand_mode2_1_0(void)
Operation_push(Paintbrush_X);
Operation_push(Paintbrush_Y);
Print_coordinates();
Airbrush_next_time = SDL_GetTicks() + Airbrush_delay*10;
Airbrush_next_time = GFX2_GetTicks() + Airbrush_delay*10;
}
@ -331,7 +331,7 @@ void Freehand_mode2_1_2(void)
if ( (start_x!=Paintbrush_X) || (start_y!=Paintbrush_Y) )
{
Print_coordinates();
if (SDL_GetTicks()>Airbrush_next_time)
if (GFX2_GetTicks()>Airbrush_next_time)
{
Airbrush_next_time+=Airbrush_delay*10;
Hide_cursor();
@ -363,7 +363,7 @@ void Freehand_mode2_2_0(void)
Operation_push(Paintbrush_X);
Operation_push(Paintbrush_Y);
Print_coordinates();
Airbrush_next_time = SDL_GetTicks() + Airbrush_delay*10;
Airbrush_next_time = GFX2_GetTicks() + Airbrush_delay*10;
// On affiche définitivement le pinceau
Draw_paintbrush(Paintbrush_X,Paintbrush_Y,Back_color);
}
@ -385,7 +385,7 @@ void Freehand_mode2_2_2(void)
if ( (start_x!=Paintbrush_X) || (start_y!=Paintbrush_Y) )
{
Print_coordinates();
if (SDL_GetTicks()>Airbrush_next_time)
if (GFX2_GetTicks()>Airbrush_next_time)
{
Airbrush_next_time+=Airbrush_delay*10;
Hide_cursor();
@ -1983,10 +1983,10 @@ void Airbrush_1_0(void)
Backup();
Shade_table=Shade_table_left;
if (SDL_GetTicks()>Airbrush_next_time)
if (GFX2_GetTicks()>Airbrush_next_time)
{
Airbrush(LEFT_SIDE);
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
Airbrush_next_time = GFX2_GetTicks()+Airbrush_delay*10;
}
Operation_push(Paintbrush_X);
@ -2008,10 +2008,10 @@ void Airbrush_2_0(void)
Init_start_operation();
Backup();
Shade_table=Shade_table_right;
if (SDL_GetTicks()>Airbrush_next_time)
if (GFX2_GetTicks()>Airbrush_next_time)
{
Airbrush(RIGHT_SIDE);
Airbrush_next_time = SDL_GetTicks()+Airbrush_delay*10;
Airbrush_next_time = GFX2_GetTicks()+Airbrush_delay*10;
}
Operation_push(Paintbrush_X);
@ -2028,7 +2028,7 @@ void Airbrush_12_2(void)
//
{
short old_x,old_y;
Uint32 now;
dword now;
Operation_pop(&old_y);
Operation_pop(&old_x);
@ -2040,7 +2040,7 @@ void Airbrush_12_2(void)
Display_cursor();
}
now=SDL_GetTicks();
now=GFX2_GetTicks();
if (now>Airbrush_next_time)
{
//Airbrush_next_time+=Airbrush_delay*10;

View File

@ -429,7 +429,7 @@ void Transparency_set(byte amount)
}
time_previous = time_click;
time_click = SDL_GetTicks();
time_click = GFX2_GetTicks();
// Check if it's a quick re-press
if (time_click - time_previous < doubleclick_delay)

View File

@ -338,7 +338,7 @@ void Tilemap_update(void)
if (wait_window)
{
char str[8];
Uint32 end;
dword end;
if (Config.Tilemap_show_count)
{
@ -349,11 +349,11 @@ void Tilemap_update(void)
Display_cursor();
// Wait a moment to display count
end = SDL_GetTicks()+750;
end = GFX2_GetTicks()+750;
do
{
Get_input(20);
} while (SDL_GetTicks()<end);
} while (GFX2_GetTicks()<end);
}
Close_window();