Skip to content

Commit

Permalink
Fix: refactor profiling IDs from statics to state members (#661)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Harrison <scottrules44@gmail.com>
  • Loading branch information
ggcrunchy and scottrules44 committed Jan 2, 2024
1 parent 0be9501 commit c151ca7
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 168 deletions.
6 changes: 3 additions & 3 deletions librtt/Display/Rtt_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Display::Restart( int newWidth, int newHeight )
void
Display::Update()
{
PROFILING_BEGIN( *GetProfilingState(), up, "update" );
PROFILING_BEGIN( *GetProfilingState(), up, Update );

up.Add( "Display::Update Begin" );

Expand Down Expand Up @@ -568,7 +568,7 @@ Display::Update()
void
Display::Render()
{
PROFILING_BEGIN( *GetProfilingState(), rp, "render" );
PROFILING_BEGIN( *GetProfilingState(), rp, Render );

rp.Add( "Display::Render Begin" );

Expand All @@ -585,7 +585,7 @@ Display::Render()
//fDeltaTimeInSeconds = ( 1.0f / 30.0f );
}

GetScene().Render( * fRenderer, * fTarget, rp.GetProfiling() );
GetScene().Render( * fRenderer, * fTarget, &rp );

rp.Add( "Display::Render End" );
}
Expand Down
37 changes: 10 additions & 27 deletions librtt/Display/Rtt_LuaLibDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2731,13 +2731,9 @@ int
DisplayLibrary::_allocateProfile( lua_State *L )
{
Self* lib = (Self *)lua_touserdata( L, lua_upvalueindex( 1 ) );
if ( lua_isstring( L, 1 ) && lua_isstring( L, 2 ) )
if ( lua_isstring( L, 1 ) )
{
char buf[128];

snprintf( buf, sizeof( buf ) - 1, "%s:%s", lua_tostring( L, 2 ), lua_tostring( L, 1 ) );

int profileID = lib->GetDisplay().GetProfilingState()->Create( buf );
int profileID = lib->GetDisplay().GetProfilingState()->Create( lua_tostring( L, 1 ) );

lua_pushinteger( L, profileID + 1 );
}
Expand Down Expand Up @@ -2861,30 +2857,17 @@ DisplayLibrary::_addProfileEntry( lua_State *L )
Self* lib = (Self *)lua_touserdata( L, lua_upvalueindex( 1 ) );
if ( lua_islightuserdata( L, 1 ) )
{
const char* str;
char buf[128];

switch ( lua_type( L, 2 ) )
{
case LUA_TSTRING:
str = lua_tostring( L, 2 );
break;

case LUA_TNUMBER:
snprintf( buf, sizeof( buf ) - 1, "%g", lua_tonumber( L, 2 ) );
str = buf;
break;
int type = lua_type( L, 2 );

case LUA_TBOOLEAN:
str = lua_toboolean( L, 2 ) ? "true" : "false";
break;

default:
snprintf( buf, sizeof( buf ) - 1, "%s:0x%p", luaL_typename( L, 2 ), lua_topointer( L, 2 ) );
str = buf;
if ( LUA_TTABLE == type || LUA_TFUNCTION == type )
{
lib->GetDisplay().GetProfilingState()->AddEntry( lua_touserdata( L, 1 ), Profiling::Payload( lua_topointer( L, 2 ), LUA_TTABLE == type ) );
}

lib->GetDisplay().GetProfilingState()->AddEntry( lua_touserdata( L, 1 ), str );
else
{
CoronaLuaError( L, "Profile entry expected to be function or table listener, got %s", lua_typename( L, type ) );
}
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions librtt/Display/Rtt_Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ Scene::Clear( Renderer& renderer )
renderer.Clear( c.rgba.r * inv255, c.rgba.g * inv255, c.rgba.b * inv255, c.rgba.a * inv255 );
}

#define ADD_ENTRY( what ) if ( profiling ) { profiling->AddEntry( what ); }
#define ADD_ENTRY( what ) if ( profiling ) PROFILING_ADD( *profiling, what )

void
Scene::Render( Renderer& renderer, PlatformSurface& rTarget, Profiling* profiling )
Scene::Render( Renderer& renderer, PlatformSurface& rTarget, ProfilingEntryRAII* profiling )
{
Rtt_ASSERT( fCurrentStage );

Expand Down
4 changes: 2 additions & 2 deletions librtt/Display/Rtt_Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Rtt

class Display;
class PlatformSurface;
class Profiling;
class ProfilingEntryRAII;
class Runtime;
class MUpdatable;

Expand Down Expand Up @@ -76,7 +76,7 @@ class Scene
bool IsValid() const;
void Invalidate();
void Clear( Renderer& renderer );
void Render( Renderer& renderer, PlatformSurface& rTarget, Profiling* profiling = NULL );
void Render( Renderer& renderer, PlatformSurface& rTarget, ProfilingEntryRAII* profiling = NULL );
void Render( Renderer& renderer, PlatformSurface& rTarget, DisplayObject& object );

public:
Expand Down
Loading

0 comments on commit c151ca7

Please sign in to comment.