Commit 4f20a201 by Hannu Hanhi

Performance stats

parent 15008f31
......@@ -32,6 +32,7 @@ set(SRB2_CORE_SOURCES
m_fixed.c
m_menu.c
m_misc.c
m_perfstats.c
m_queue.c
m_random.c
md5.c
......@@ -97,6 +98,7 @@ set(SRB2_CORE_HEADERS
m_fixed.h
m_menu.h
m_misc.h
m_perfstats.h
m_queue.h
m_random.h
m_swap.h
......
......@@ -486,6 +486,7 @@ OBJS:=$(i_main_o) \
$(OBJDIR)/m_fixed.o \
$(OBJDIR)/m_menu.o \
$(OBJDIR)/m_misc.o \
$(OBJDIR)/m_perfstats.o \
$(OBJDIR)/m_random.o \
$(OBJDIR)/m_queue.o \
$(OBJDIR)/info.o \
......
......@@ -44,6 +44,7 @@
#include "lua_script.h"
#include "lua_hook.h"
#include "md5.h"
#include "m_perfstats.h"
#ifndef NONET
// cl loading screen
......@@ -5443,14 +5444,14 @@ void TryRunTics(tic_t realtics)
{
DEBFILE(va("============ Running tic %d (local %d)\n", gametic, localgametic));
rs_tictime = I_GetTimeMicros();
ps_tictime = I_GetTimeMicros();
G_Ticker((gametic % NEWTICRATERATIO) == 0);
ExtraDataTicker();
gametic++;
consistancy[gametic%BACKUPTICS] = Consistancy();
rs_tictime = I_GetTimeMicros() - rs_tictime;
ps_tictime = I_GetTimeMicros() - ps_tictime;
// Leave a certain amount of tics present in the net buffer as long as we've ran at least one tic this frame.
if (client && gamestate == GS_LEVEL && leveltime > 3 && neededtic <= gametic + cv_netticbuffer.value)
......
......@@ -67,6 +67,7 @@
#include "keys.h"
#include "filesrch.h" // refreshdirmenu, mainwadstally
#include "g_input.h" // tutorial mode control scheming
#include "m_perfstats.h"
#ifdef CMAKECONFIG
#include "config.h"
......@@ -435,7 +436,7 @@ static void D_Display(void)
if (!automapactive && !dedicated && cv_renderview.value)
{
rs_rendercalltime = I_GetTimeMicros();
ps_rendercalltime = I_GetTimeMicros();
if (players[displayplayer].mo || players[displayplayer].playerstate == PST_DEAD)
{
topleft = screens[0] + viewwindowy*vid.width + viewwindowx;
......@@ -482,7 +483,7 @@ static void D_Display(void)
if (postimgtype2)
V_DoPostProcessor(1, postimgtype2, postimgparam2);
}
rs_rendercalltime = I_GetTimeMicros() - rs_rendercalltime;
ps_rendercalltime = I_GetTimeMicros() - ps_rendercalltime;
}
if (lastdraw)
......@@ -496,7 +497,7 @@ static void D_Display(void)
lastdraw = false;
}
rs_uitime = I_GetTimeMicros();
ps_uitime = I_GetTimeMicros();
if (gamestate == GS_LEVEL)
{
......@@ -509,7 +510,7 @@ static void D_Display(void)
}
else
{
rs_uitime = I_GetTimeMicros();
ps_uitime = I_GetTimeMicros();
}
}
......@@ -551,7 +552,7 @@ static void D_Display(void)
CON_Drawer();
rs_uitime = I_GetTimeMicros() - rs_uitime;
ps_uitime = I_GetTimeMicros() - ps_uitime;
//
// wipe update
......@@ -632,90 +633,14 @@ static void D_Display(void)
V_DrawRightAlignedString(BASEVIDWIDTH, BASEVIDHEIGHT-ST_HEIGHT-10, V_YELLOWMAP, s);
}
if (cv_renderstats.value)
if (cv_perfstats.value)
{
char s[50];
int frametime = I_GetTimeMicros() - rs_prevframetime;
int divisor = 1;
rs_prevframetime = I_GetTimeMicros();
if (rs_rendercalltime > 10000) divisor = 1000;
snprintf(s, sizeof s - 1, "ft %d", frametime / divisor);
V_DrawThinString(30, 10, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "rtot %d", rs_rendercalltime / divisor);
V_DrawThinString(30, 20, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "bsp %d", rs_bsptime / divisor);
V_DrawThinString(30, 30, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "nbsp %d", rs_numbspcalls);
V_DrawThinString(80, 10, V_MONOSPACE | V_BLUEMAP, s);
snprintf(s, sizeof s - 1, "nspr %d", rs_numsprites);
V_DrawThinString(80, 20, V_MONOSPACE | V_BLUEMAP, s);
snprintf(s, sizeof s - 1, "nnod %d", rs_numdrawnodes);
V_DrawThinString(80, 30, V_MONOSPACE | V_BLUEMAP, s);
snprintf(s, sizeof s - 1, "npob %d", rs_numpolyobjects);
V_DrawThinString(80, 40, V_MONOSPACE | V_BLUEMAP, s);
if (rendermode == render_opengl) // OpenGL specific stats
{
#ifdef HWRENDER
snprintf(s, sizeof s - 1, "nsrt %d", rs_hw_nodesorttime / divisor);
V_DrawThinString(30, 40, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "ndrw %d", rs_hw_nodedrawtime / divisor);
V_DrawThinString(30, 50, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "ssrt %d", rs_hw_spritesorttime / divisor);
V_DrawThinString(30, 60, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "sdrw %d", rs_hw_spritedrawtime / divisor);
V_DrawThinString(30, 70, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "ui %d", rs_uitime / divisor);
V_DrawThinString(30, 80, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "fin %d", rs_swaptime / divisor);
V_DrawThinString(30, 90, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "tic %d", rs_tictime / divisor);
V_DrawThinString(30, 105, V_MONOSPACE | V_GRAYMAP, s);
if (cv_glbatching.value)
{
snprintf(s, sizeof s - 1, "bsrt %d", rs_hw_batchsorttime / divisor);
V_DrawThinString(80, 55, V_MONOSPACE | V_REDMAP, s);
snprintf(s, sizeof s - 1, "bdrw %d", rs_hw_batchdrawtime / divisor);
V_DrawThinString(80, 65, V_MONOSPACE | V_REDMAP, s);
snprintf(s, sizeof s - 1, "npol %d", rs_hw_numpolys);
V_DrawThinString(130, 10, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "ndc %d", rs_hw_numcalls);
V_DrawThinString(130, 20, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "nshd %d", rs_hw_numshaders);
V_DrawThinString(130, 30, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "nvrt %d", rs_hw_numverts);
V_DrawThinString(130, 40, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "ntex %d", rs_hw_numtextures);
V_DrawThinString(185, 10, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "npf %d", rs_hw_numpolyflags);
V_DrawThinString(185, 20, V_MONOSPACE | V_PURPLEMAP, s);
snprintf(s, sizeof s - 1, "ncol %d", rs_hw_numcolors);
V_DrawThinString(185, 30, V_MONOSPACE | V_PURPLEMAP, s);
}
#endif
}
else // software specific stats
{
snprintf(s, sizeof s - 1, "prtl %d", rs_sw_portaltime / divisor);
V_DrawThinString(30, 40, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "plns %d", rs_sw_planetime / divisor);
V_DrawThinString(30, 50, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "mskd %d", rs_sw_maskedtime / divisor);
V_DrawThinString(30, 60, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "ui %d", rs_uitime / divisor);
V_DrawThinString(30, 70, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "fin %d", rs_swaptime / divisor);
V_DrawThinString(30, 80, V_MONOSPACE | V_YELLOWMAP, s);
snprintf(s, sizeof s - 1, "tic %d", rs_tictime / divisor);
V_DrawThinString(30, 95, V_MONOSPACE | V_GRAYMAP, s);
}
M_DrawPerfStats();
}
rs_swaptime = I_GetTimeMicros();
ps_swaptime = I_GetTimeMicros();
I_FinishUpdate(); // page flip or blit buffer
rs_swaptime = I_GetTimeMicros() - rs_swaptime;
ps_swaptime = I_GetTimeMicros() - ps_swaptime;
}
needpatchflush = false;
......
......@@ -371,6 +371,10 @@ consvar_t cv_mute = CVAR_INIT ("mute", "Off", CV_NETVAR|CV_CALL, CV_OnOff, Mute_
consvar_t cv_sleep = CVAR_INIT ("cpusleep", "1", CV_SAVE, sleeping_cons_t, NULL);
static CV_PossibleValue_t perfstats_cons_t[] = {
{0, "Off"}, {1, "Rendering"}, {2, "Logic"}, {3, "ThinkFrame"}, {0, NULL}};
consvar_t cv_perfstats = CVAR_INIT ("perfstats", "Off", 0, perfstats_cons_t, NULL);
char timedemo_name[256];
boolean timedemo_csv;
char timedemo_csv_id[256];
......@@ -864,6 +868,8 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_soundtest);
CV_RegisterVar(&cv_perfstats);
// ingame object placing
COM_AddCommand("objectplace", Command_ObjectPlace_f);
COM_AddCommand("writethings", Command_Writethings_f);
......
......@@ -114,6 +114,8 @@ extern consvar_t cv_skipmapcheck;
extern consvar_t cv_sleep;
extern consvar_t cv_perfstats;
extern char timedemo_name[256];
extern boolean timedemo_csv;
extern char timedemo_csv_id[256];
......
......@@ -235,13 +235,13 @@ void HWR_RenderBatches(void)
currently_batching = false;// no longer collecting batches
if (!polygonArraySize)
{
rs_hw_numpolys = rs_hw_numcalls = rs_hw_numshaders = rs_hw_numtextures = rs_hw_numpolyflags = rs_hw_numcolors = 0;
ps_hw_numpolys = ps_hw_numcalls = ps_hw_numshaders = ps_hw_numtextures = ps_hw_numpolyflags = ps_hw_numcolors = 0;
return;// nothing to draw
}
// init stats vars
rs_hw_numpolys = polygonArraySize;
rs_hw_numcalls = rs_hw_numverts = 0;
rs_hw_numshaders = rs_hw_numtextures = rs_hw_numpolyflags = rs_hw_numcolors = 1;
ps_hw_numpolys = polygonArraySize;
ps_hw_numcalls = ps_hw_numverts = 0;
ps_hw_numshaders = ps_hw_numtextures = ps_hw_numpolyflags = ps_hw_numcolors = 1;
// init polygonIndexArray
for (i = 0; i < polygonArraySize; i++)
{
......@@ -249,12 +249,12 @@ void HWR_RenderBatches(void)
}
// sort polygons
rs_hw_batchsorttime = I_GetTimeMicros();
ps_hw_batchsorttime = I_GetTimeMicros();
if (cv_glshaders.value && gl_shadersavailable)
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons);
else
qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders);
rs_hw_batchsorttime = I_GetTimeMicros() - rs_hw_batchsorttime;
ps_hw_batchsorttime = I_GetTimeMicros() - ps_hw_batchsorttime;
// sort order
// 1. shader
// 2. texture
......@@ -262,7 +262,7 @@ void HWR_RenderBatches(void)
// 4. colors + light level
// not sure about what order of the last 2 should be, or if it even matters
rs_hw_batchdrawtime = I_GetTimeMicros();
ps_hw_batchdrawtime = I_GetTimeMicros();
currentShader = polygonArray[polygonIndexArray[0]].shader;
currentTexture = polygonArray[polygonIndexArray[0]].texture;
......@@ -398,8 +398,8 @@ void HWR_RenderBatches(void)
// execute draw call
HWD.pfnDrawIndexedTriangles(&currentSurfaceInfo, finalVertexArray, finalIndexWritePos, currentPolyFlags, finalVertexIndexArray);
// update stats
rs_hw_numcalls++;
rs_hw_numverts += finalIndexWritePos;
ps_hw_numcalls++;
ps_hw_numverts += finalIndexWritePos;
// reset write positions
finalVertexWritePos = 0;
finalIndexWritePos = 0;
......@@ -416,7 +416,7 @@ void HWR_RenderBatches(void)
currentShader = nextShader;
changeShader = false;
rs_hw_numshaders++;
ps_hw_numshaders++;
}
if (changeTexture)
{
......@@ -425,21 +425,21 @@ void HWR_RenderBatches(void)
currentTexture = nextTexture;
changeTexture = false;
rs_hw_numtextures++;
ps_hw_numtextures++;
}
if (changePolyFlags)
{
currentPolyFlags = nextPolyFlags;
changePolyFlags = false;
rs_hw_numpolyflags++;
ps_hw_numpolyflags++;
}
if (changeSurfaceInfo)
{
currentSurfaceInfo = nextSurfaceInfo;
changeSurfaceInfo = false;
rs_hw_numcolors++;
ps_hw_numcolors++;
}
// and that should be it?
}
......@@ -447,7 +447,7 @@ void HWR_RenderBatches(void)
polygonArraySize = 0;
unsortedVertexArraySize = 0;
rs_hw_batchdrawtime = I_GetTimeMicros() - rs_hw_batchdrawtime;
ps_hw_batchdrawtime = I_GetTimeMicros() - ps_hw_batchdrawtime;
}
......
......@@ -146,21 +146,22 @@ static angle_t gl_aimingangle;
static void HWR_SetTransformAiming(FTransform *trans, player_t *player, boolean skybox);
// Render stats
int rs_hw_nodesorttime = 0;
int rs_hw_nodedrawtime = 0;
int rs_hw_spritesorttime = 0;
int rs_hw_spritedrawtime = 0;
int ps_hw_skyboxtime = 0;
int ps_hw_nodesorttime = 0;
int ps_hw_nodedrawtime = 0;
int ps_hw_spritesorttime = 0;
int ps_hw_spritedrawtime = 0;
// Render stats for batching
int rs_hw_numpolys = 0;
int rs_hw_numverts = 0;
int rs_hw_numcalls = 0;
int rs_hw_numshaders = 0;
int rs_hw_numtextures = 0;
int rs_hw_numpolyflags = 0;
int rs_hw_numcolors = 0;
int rs_hw_batchsorttime = 0;
int rs_hw_batchdrawtime = 0;
int ps_hw_numpolys = 0;
int ps_hw_numverts = 0;
int ps_hw_numcalls = 0;
int ps_hw_numshaders = 0;
int ps_hw_numtextures = 0;
int ps_hw_numpolyflags = 0;
int ps_hw_numcolors = 0;
int ps_hw_batchsorttime = 0;
int ps_hw_batchdrawtime = 0;
boolean gl_shadersavailable = true;
......@@ -3188,7 +3189,7 @@ static void HWR_Subsector(size_t num)
}
// for render stats
rs_numpolyobjects += numpolys;
ps_numpolyobjects += numpolys;
// Sort polyobjects
R_SortPolyObjects(sub);
......@@ -3296,7 +3297,7 @@ static void HWR_RenderBSPNode(INT32 bspnum)
// Decide which side the view point is on
INT32 side;
rs_numbspcalls++;
ps_numbspcalls++;
// Found a subsector?
if (bspnum & NF_SUBSECTOR)
......@@ -4502,7 +4503,7 @@ static void HWR_CreateDrawNodes(void)
// that is already lying around. This should all be in some sort of linked list or lists.
sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL);
rs_hw_nodesorttime = I_GetTimeMicros();
ps_hw_nodesorttime = I_GetTimeMicros();
for (i = 0; i < numplanes; i++, p++)
{
......@@ -4522,7 +4523,7 @@ static void HWR_CreateDrawNodes(void)
sortindex[p] = p;
}
rs_numdrawnodes = p;
ps_numdrawnodes = p;
// p is the number of stuff to sort
......@@ -4557,9 +4558,9 @@ static void HWR_CreateDrawNodes(void)
}
}
rs_hw_nodesorttime = I_GetTimeMicros() - rs_hw_nodesorttime;
ps_hw_nodesorttime = I_GetTimeMicros() - ps_hw_nodesorttime;
rs_hw_nodedrawtime = I_GetTimeMicros();
ps_hw_nodedrawtime = I_GetTimeMicros();
// Okay! Let's draw it all! Woo!
HWD.pfnSetTransform(&atransform);
......@@ -4596,7 +4597,7 @@ static void HWR_CreateDrawNodes(void)
}
}
rs_hw_nodedrawtime = I_GetTimeMicros() - rs_hw_nodedrawtime;
ps_hw_nodedrawtime = I_GetTimeMicros() - ps_hw_nodedrawtime;
numwalls = 0;
numplanes = 0;
......@@ -5777,8 +5778,10 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
if (viewnumber == 0) // Only do it if it's the first screen being rendered
HWD.pfnClearBuffer(true, false, &ClearColor); // Clear the Color Buffer, stops HOMs. Also seems to fix the skybox issue on Intel GPUs.
ps_hw_skyboxtime = I_GetTimeMicros();
if (skybox && drawsky) // If there's a skybox and we should be drawing the sky, draw the skybox
HWR_RenderSkyboxView(viewnumber, player); // This is drawn before everything else so it is placed behind
ps_hw_skyboxtime = I_GetTimeMicros() - ps_hw_skyboxtime;
{
// do we really need to save player (is it not the same)?
......@@ -5889,9 +5892,9 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
HWD.pfnSetSpecialState(HWD_SET_SHADERS, cv_glshaders.value);
HWD.pfnSetShader(0);
rs_numbspcalls = 0;
rs_numpolyobjects = 0;
rs_bsptime = I_GetTimeMicros();
ps_numbspcalls = 0;
ps_numpolyobjects = 0;
ps_bsptime = I_GetTimeMicros();
validcount++;
......@@ -5929,7 +5932,7 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
}
#endif
rs_bsptime = I_GetTimeMicros() - rs_bsptime;
ps_bsptime = I_GetTimeMicros() - ps_bsptime;
if (cv_glbatching.value)
HWR_RenderBatches();
......@@ -5944,22 +5947,22 @@ void HWR_RenderPlayerView(INT32 viewnumber, player_t *player)
#endif
// Draw MD2 and sprites
rs_numsprites = gl_visspritecount;
rs_hw_spritesorttime = I_GetTimeMicros();
ps_numsprites = gl_visspritecount;
ps_hw_spritesorttime = I_GetTimeMicros();
HWR_SortVisSprites();
rs_hw_spritesorttime = I_GetTimeMicros() - rs_hw_spritesorttime;
rs_hw_spritedrawtime = I_GetTimeMicros();
ps_hw_spritesorttime = I_GetTimeMicros() - ps_hw_spritesorttime;
ps_hw_spritedrawtime = I_GetTimeMicros();
HWR_DrawSprites();
rs_hw_spritedrawtime = I_GetTimeMicros() - rs_hw_spritedrawtime;
ps_hw_spritedrawtime = I_GetTimeMicros() - ps_hw_spritedrawtime;
#ifdef NEWCORONAS
//Hurdler: they must be drawn before translucent planes, what about gl fog?
HWR_DrawCoronas();
#endif
rs_numdrawnodes = 0;
rs_hw_nodesorttime = 0;
rs_hw_nodedrawtime = 0;
ps_numdrawnodes = 0;
ps_hw_nodesorttime = 0;
ps_hw_nodedrawtime = 0;
if (numplanes || numpolyplanes || numwalls) //Hurdler: render 3D water and transparent walls after everything
{
HWR_CreateDrawNodes();
......@@ -6061,7 +6064,6 @@ void HWR_AddCommands(void)
CV_RegisterVar(&cv_glfiltermode);
CV_RegisterVar(&cv_glsolvetjoin);
CV_RegisterVar(&cv_renderstats);
CV_RegisterVar(&cv_glbatching);
#ifndef NEWCLIP
......
......@@ -108,21 +108,22 @@ extern FTransform atransform;
// Render stats
extern int rs_hw_nodesorttime;
extern int rs_hw_nodedrawtime;
extern int rs_hw_spritesorttime;
extern int rs_hw_spritedrawtime;
extern int ps_hw_skyboxtime;
extern int ps_hw_nodesorttime;
extern int ps_hw_nodedrawtime;
extern int ps_hw_spritesorttime;
extern int ps_hw_spritedrawtime;
// Render stats for batching
extern int rs_hw_numpolys;
extern int rs_hw_numverts;
extern int rs_hw_numcalls;
extern int rs_hw_numshaders;
extern int rs_hw_numtextures;
extern int rs_hw_numpolyflags;
extern int rs_hw_numcolors;
extern int rs_hw_batchsorttime;
extern int rs_hw_batchdrawtime;
extern int ps_hw_numpolys;
extern int ps_hw_numverts;
extern int ps_hw_numcalls;
extern int ps_hw_numshaders;
extern int ps_hw_numtextures;
extern int ps_hw_numpolyflags;
extern int ps_hw_numcolors;
extern int ps_hw_batchsorttime;
extern int ps_hw_batchdrawtime;
extern boolean gl_shadersavailable;
......
......@@ -23,6 +23,10 @@
#include "lua_hook.h"
#include "lua_hud.h" // hud_running errors
#include "m_perfstats.h"
#include "d_netcmd.h" // for cv_perfstats
#include "i_system.h" // I_GetTimeMicros
static UINT8 hooksAvailable[(hook_MAX/8)+1];
const char *const hookNames[hook_MAX+1] = {
......@@ -269,6 +273,7 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
LUA_PushUserdata(gL, mo, META_MOBJ);
PushHook(gL, hookp);
......@@ -290,6 +295,7 @@ boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
LUA_PushUserdata(gL, mo, META_MOBJ);
PushHook(gL, hookp);
......@@ -325,6 +331,7 @@ boolean LUAh_PlayerHook(player_t *plr, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
LUA_PushUserdata(gL, plr, META_PLAYER);
PushHook(gL, hookp);
......@@ -456,6 +463,9 @@ void LUAh_PreThinkFrame(void)
void LUAh_ThinkFrame(void)
{
hook_p hookp;
// variables used by perf stats
int hook_index = 0;
int time_taken = 0;
if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8))))
return;
......@@ -466,6 +476,8 @@ void LUAh_ThinkFrame(void)
if (hookp->type != hook_ThinkFrame)
continue;
if (cv_perfstats.value == 3)
time_taken = I_GetTimeMicros();
PushHook(gL, hookp);
if (lua_pcall(gL, 0, 0, 1)) {
if (!hookp->error || cv_debug & DBG_LUA)
......@@ -473,6 +485,16 @@ void LUAh_ThinkFrame(void)
lua_pop(gL, 1);
hookp->error = true;
}
if (cv_perfstats.value == 3)
{
lua_Debug ar;
time_taken = I_GetTimeMicros() - time_taken;
// we need the function, let's just retrieve it again
PushHook(gL, hookp);
lua_getinfo(gL, ">S", &ar);
PS_SetThinkFrameHookInfo(hook_index, time_taken, ar.short_src);
hook_index++;
}
}
lua_pop(gL, 1); // Pop error handler
......@@ -523,6 +545,7 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, thing1, META_MOBJ);
......@@ -553,6 +576,7 @@ UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, thing1, META_MOBJ);
......@@ -600,6 +624,7 @@ UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, thing, META_MOBJ);
......@@ -630,6 +655,7 @@ UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which)
if (hookp->type != which)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, thing, META_MOBJ);
......@@ -675,6 +701,7 @@ boolean LUAh_MobjThinker(mobj_t *mo)
// Look for all generic mobj thinker hooks
for (hookp = mobjthinkerhooks[MT_NULL]; hookp; hookp = hookp->next)
{
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
LUA_PushUserdata(gL, mo, META_MOBJ);
PushHook(gL, hookp);
......@@ -693,6 +720,7 @@ boolean LUAh_MobjThinker(mobj_t *mo)
for (hookp = mobjthinkerhooks[mo->type]; hookp; hookp = hookp->next)
{
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
LUA_PushUserdata(gL, mo, META_MOBJ);
PushHook(gL, hookp);
......@@ -732,6 +760,7 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
if (hookp->type != hook_TouchSpecial)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, special, META_MOBJ);
......@@ -757,6 +786,7 @@ boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
if (hookp->type != hook_TouchSpecial)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, special, META_MOBJ);
......@@ -800,6 +830,7 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
if (hookp->type != hook_ShouldDamage)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -835,6 +866,7 @@ UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
{
if (hookp->type != hook_ShouldDamage)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -889,6 +921,7 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
if (hookp->type != hook_MobjDamage)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -920,6 +953,7 @@ boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32
if (hookp->type != hook_MobjDamage)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -969,6 +1003,7 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8
if (hookp->type != hook_MobjDeath)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -998,6 +1033,7 @@ boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8
if (hookp->type != hook_MobjDeath)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, target, META_MOBJ);
......@@ -1190,6 +1226,7 @@ boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
if (strcmp(hookp->s.str, line->stringargs[0]))
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, line, META_LINE);
......@@ -1364,6 +1401,7 @@ boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
if (hookp->type != hook_MapThingSpawn)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, mo, META_MOBJ);
......@@ -1389,6 +1427,7 @@ boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
if (hookp->type != hook_MapThingSpawn)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, mo, META_MOBJ);
......@@ -1430,6 +1469,7 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
if (hookp->type != hook_FollowMobj)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, player, META_PLAYER);
......@@ -1455,6 +1495,7 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
if (hookp->type != hook_FollowMobj)
continue;
ps_lua_mobjhooks++;
if (lua_gettop(gL) == 1)
{
LUA_PushUserdata(gL, player, META_PLAYER);
......@@ -1495,6 +1536,7 @@ UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj)
if (hookp->type != hook_PlayerCanDamage)
continue;
ps_lua_mobjhooks++;