Skip to content
Snippets Groups Projects
Commit 12073dda authored by dg's avatar dg
Browse files

Screen FPS will not go bonkers for a second after a long load/compute time

git-svn-id: http://svn.net-core.org/repos/t-engine4@4102 51575b47-30f0-44d4-a5cc-537603b46e54
parent b1db3179
No related branches found
No related tags found
No related merge requests found
......@@ -20,3 +20,4 @@ int luaopen_wait(lua_State *L);
void create_particles_thread();
void thread_particle_new_keyframes(int nb_keyframes);
bool draw_waiting(lua_State *L);
bool is_waiting();
......@@ -458,7 +458,7 @@ void on_redraw()
/* Gather our frames per second */
Frames++;
{
if (!is_waiting()) {
int t = SDL_GetTicks();
if (t - T0 >= 1000) {
float seconds = (t - T0) / 1000.0;
......@@ -472,6 +472,14 @@ void on_redraw()
count_keyframes = 0;
}
}
else
{
T0 = SDL_GetTicks();
Frames = 0;
last_keyframe = 0;
nb_keyframes = 0;
count_keyframes = 0;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
......
......@@ -35,6 +35,7 @@ extern SDL_Surface *screen;
static bool wait_hooked = FALSE;
static int waiting = 0;
static int waited_count = 0;
static long waited_ticks = 0;
static int bkg_realw, bkg_realh, bkg_w, bkg_h;
static GLuint bkg_t = 0;
static int wait_draw_ref = LUA_NOREF;
......@@ -81,6 +82,12 @@ bool draw_waiting(lua_State *L)
return TRUE;
}
bool is_waiting()
{
if (!waiting) return FALSE;
return TRUE;
}
extern void on_redraw();
static void hook_wait_display(lua_State *L, lua_Debug *ar)
{
......@@ -89,6 +96,7 @@ static void hook_wait_display(lua_State *L, lua_Debug *ar)
on_redraw();
}
extern long draw_tick_skip;
static int enable(lua_State *L)
{
waiting++;
......@@ -96,6 +104,9 @@ static int enable(lua_State *L)
// Grab currently displayed stuff
if (waiting == 1)
{
waited_count = 0;
waited_ticks = SDL_GetTicks();
int w, h;
SDL_GetWindowSize(window, &w, &h);
......@@ -117,8 +128,6 @@ static int enable(lua_State *L)
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, w, h);
printf("Make wait background texture %d : %dx%d (%d, %d)\n", bkg_t, w, h, bkg_realw, bkg_realh);
waited_count = 0;
int count = 300;
if (lua_isnumber(L, 1)) count = lua_tonumber(L, 1);
if (!lua_gethookmask(L))
......@@ -155,7 +164,8 @@ static int disable(lua_State *L)
}
if (wait_hooked) lua_sethook(L, NULL, 0, 0);
if (wait_draw_ref != LUA_NOREF) luaL_unref(L, LUA_REGISTRYINDEX, wait_draw_ref);
printf("Wait finished, counted %d\n", waited_count);
waited_ticks = SDL_GetTicks() - waited_ticks;
printf("Wait finished, counted %d, %ld ticks\n", waited_count, waited_ticks);
}
lua_pushboolean(L, waiting > 0);
lua_pushnumber(L, waiting);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment