From fb51c1bb1cb975c69cc4066811d25b4781df0dc7 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 28 May 2018 12:31:42 +0200 Subject: [PATCH] SDL_GetTicks() => GFX2_GetTicks() Signed-off-by: Thomas Bernard --- src/buttons.c | 2 +- src/engine.c | 12 ++++++------ src/factory.c | 18 +++++++++--------- src/graph.c | 6 +++--- src/input.c | 6 +++--- src/layers.c | 12 ++++++------ src/loadsave.c | 8 ++++---- src/misc.c | 26 ++++++++++++++++++++++++-- src/misc.h | 9 +++++++++ src/operatio.c | 22 +++++++++++----------- src/special.c | 2 +- src/tiles.c | 6 +++--- 12 files changed, 80 insertions(+), 49 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 9a6a8a7c..6c37d869 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -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(); diff --git a/src/engine.c b/src/engine.c index f78bee94..eeda4634 100644 --- a/src/engine.c +++ b/src/engine.c @@ -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()= Permanent_draw_next_refresh) { diff --git a/src/input.c b/src/input.c index 17e863fd..546e262b 100644 --- a/src/input.c +++ b/src/input.c @@ -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 diff --git a/src/layers.c b/src/layers.c index 4f8fd8bc..47e74389 100644 --- a/src/layers.c +++ b/src/layers.c @@ -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; diff --git a/src/loadsave.c b/src/loadsave.c index b951eb1b..db9fe882 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -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 diff --git a/src/misc.c b/src/misc.c index 5221d5bc..1ec6ed70 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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 #include +#if !defined(USE_SDL) && !defined(USE_SDL2) +#if defined(WIN32) +#include +#else +#include +#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 +} + diff --git a/src/misc.h b/src/misc.h index eedc11de..d99e9a01 100644 --- a/src/misc.h +++ b/src/misc.h @@ -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 diff --git a/src/operatio.c b/src/operatio.c index 95f8e020..a345db44 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -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; diff --git a/src/special.c b/src/special.c index a3202553..d6c6bb1a 100644 --- a/src/special.c +++ b/src/special.c @@ -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) diff --git a/src/tiles.c b/src/tiles.c index 90f165bf..05c758aa 100644 --- a/src/tiles.c +++ b/src/tiles.c @@ -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()