Added timer_update() to stop/start/reset_time() functions so resumed last_timer_value will be precise; Added new FPS counter which actually does count the frames rendered per second and is less irritating; Added timer_dleay2 call to console to not stress CPU too much; Imporoved placement for show_time(), multi messages

This commit is contained in:
zicodxx 2011-01-22 13:30:12 +01:00
parent 41a3d3971e
commit 13faad1855
5 changed files with 47 additions and 56 deletions

View file

@ -1,5 +1,9 @@
D1X-Rebirth Changelog
20110122
--------
main/console.c, main/game.c, main/gamerend.c, main/gauges.c: Added timer_update() to stop/start/reset_time() functions so resumed last_timer_value will be precise; Added new FPS counter which actually does count the frames rendered per second and is less irritating; Added timer_dleay2 call to console to not stress CPU too much; Imporoved placement for show_time(), multi messages
20110121
--------
main/render.c: Protection for negative array index in find_seg_side was accidentially checking for vv1 != -1 - fixed that

View file

@ -209,6 +209,7 @@ int con_handler(window *wind, d_event *event)
return 1;
case EVENT_WINDOW_DRAW:
timer_delay2(50);
if (con_state == CON_STATE_OPENING)
{
if (con_size < CON_LINES_ONSCREEN && timer_query() >= last_scroll_time+(F1_0/30))

View file

@ -366,6 +366,7 @@ void stop_time()
{
if (time_paused==0) {
fix64 time;
timer_update();
time = timer_query();
last_timer_value = time - last_timer_value;
if (last_timer_value < 0) {
@ -381,6 +382,7 @@ void start_time()
Assert(time_paused >= 0);
if (time_paused==0) {
fix64 time;
timer_update();
time = timer_query();
last_timer_value = time - last_timer_value;
}
@ -431,6 +433,7 @@ void FixedStepCalc()
void reset_time()
{
timer_update();
last_timer_value = timer_query();
}

View file

@ -20,7 +20,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "timer.h"
#include "pstypes.h"
#include "console.h"
#include "inferno.h"
@ -68,72 +68,55 @@ void game_draw_multi_message()
gr_set_curfont(GAME_FONT);
gr_set_fontcolor(BM_XRGB(0,63,0),-1);
sprintf( temp_string, "%s: %s_", TXT_MESSAGE, Network_message );
gr_printf(0x8000, (SHEIGHT/5.555), temp_string );
gr_printf(0x8000, (LINE_SPACING*5)+FSPACY(1), temp_string );
}
if ( (Game_mode&GM_MULTI) && (multi_defining_message)) {
gr_set_curfont(GAME_FONT);
gr_set_fontcolor(BM_XRGB(0,63,0),-1);
sprintf( temp_string, "%s #%d: %s_", TXT_MACRO, multi_defining_message, Network_message );
gr_printf(0x8000, (SHEIGHT/5.555), temp_string );
gr_printf(0x8000, (LINE_SPACING*5)+FSPACY(1), temp_string );
}
}
#endif
fix frame_time_list[8] = {0,0,0,0,0,0,0,0};
fix frame_time_total=0;
int frame_time_cntr=0;
void ftoa(char *string, fix f)
{
int decimal, fractional;
decimal = f2i(f);
fractional = ((f & 0xffff)*100)/65536;
if (fractional < 0 )
fractional *= -1;
if (fractional > 99 ) fractional = 99;
sprintf( string, "FPS: %d.%02d", decimal, fractional );
}
void show_framerate()
{
char temp[13];
fix rate;
int aw,w,h;
frame_time_total += FrameTime - frame_time_list[frame_time_cntr];
frame_time_list[frame_time_cntr] = FrameTime;
frame_time_cntr = (frame_time_cntr+1)%8;
if (frame_time_total) {
int y=GHEIGHT;
if (PlayerCfg.CockpitMode[1]==CM_FULL_SCREEN) {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode && GM_MULTI))
y -= LINE_SPACING * 10;
else
y -= LINE_SPACING * 4;
} else if (PlayerCfg.CockpitMode[1] == CM_STATUS_BAR) {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode && GM_MULTI))
y -= LINE_SPACING * 6;
else
y -= LINE_SPACING * 1;
} else {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode && GM_MULTI))
y -= LINE_SPACING * 7;
else
y -= LINE_SPACING * 2;
}
rate = fixdiv(f1_0*8,frame_time_total);
gr_set_curfont(GAME_FONT);
gr_set_fontcolor(BM_XRGB(0,31,0),-1);
ftoa( temp, rate );
gr_get_string_size("FPS: 000.00",&w,&h,&aw);
gr_printf(SWIDTH-w-FSPACX(1),y,"%s", temp );
static int fps_count = 0, fps_rate = 0, aw = 0, w = 0, h = 0;
int y = GHEIGHT;
static fix64 fps_time = 0;
if (w == 0) // w is static so size will only be calculated once
gr_get_string_size(GameArg.SysMaxFPS>999?"FPS: 0000":"FPS: 000",&w,&h,&aw);
gr_set_curfont(GAME_FONT);
gr_set_fontcolor(BM_XRGB(0,31,0),-1);
if (PlayerCfg.CockpitMode[1] == CM_FULL_SCREEN) {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI))
y -= LINE_SPACING * 10;
else
y -= LINE_SPACING * 4;
} else if (PlayerCfg.CockpitMode[1] == CM_STATUS_BAR) {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI))
y -= LINE_SPACING * 6;
else
y -= LINE_SPACING * 1;
} else {
if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI))
y -= LINE_SPACING * 7;
else
y -= LINE_SPACING * 2;
}
fps_count++;
if (timer_query() >= fps_time + F1_0)
{
fps_rate = fps_count;
fps_count = 0;
fps_time = timer_query();
}
gr_printf(SWIDTH-w-FSPACX(1),y,"FPS: %i",fps_rate);
}
#ifdef NETWORK
@ -282,7 +265,7 @@ void render_countdown_gauge()
if (!Endlevel_sequence && Control_center_destroyed && (Countdown_seconds_left>-1) && (Countdown_seconds_left<127)) {
gr_set_curfont(GAME_FONT);
gr_set_fontcolor(BM_XRGB(0,63,0),-1);
gr_printf(0x8000, (SHEIGHT/6.666), "T-%d s", Countdown_seconds_left );
gr_printf(0x8000, (LINE_SPACING*6)+FSPACY(1), "T-%d s", Countdown_seconds_left );
}
}

View file

@ -1313,7 +1313,7 @@ void show_time()
Color_0_31_0 = BM_XRGB(0,31,0);
gr_set_fontcolor(Color_0_31_0, -1 );
gr_printf(SWIDTH-FSPACX(25),(SHEIGHT/2),"%d:%02d", mins, secs);
gr_printf(SWIDTH-FSPACX(30),GHEIGHT-(LINE_SPACING*11),"%d:%02d", mins, secs);
}
#endif