Skip to content

Commit c19436d

Browse files
committed
Detour interface improved, detours can be attached and detached at runtime.
1 parent 5524823 commit c19436d

11 files changed

Lines changed: 802 additions & 411 deletions

File tree

Spore LuaAPI/LuaSpore/LuaSpore.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ LUAAPI void lua_deepcopyx(lua_State* source, lua_State* dest, int arg);
3131
LUAAPI void lua_deepcopy_args(lua_State* source, lua_State* dest, int offset, int num_values);
3232
LUAAPI void lua_deepcopy_upvalues(lua_State* source, int source_function, lua_State* dest, int dest_function);
3333

34-
class LuaSpore : App::DefaultMessageListener
34+
class LuaSpore : public App::IUnmanagedMessageListener
3535
{
3636
public:
3737
LUAAPI static bool IsMainThread();
@@ -94,9 +94,6 @@ class LuaSpore : App::DefaultMessageListener
9494

9595
void PostInit();
9696

97-
void StartUpdating();
98-
void StopUpdating();
99-
10097
virtual bool HandleMessage(uint32_t messageID, void* pMessage) override;
10198
public:
10299
LuaSpore(const LuaSpore&) = delete;
@@ -166,4 +163,5 @@ class LuaSpore : App::DefaultMessageListener
166163
eastl::hash_set<eastl::string16, case_insensitive_hash, case_insensitive_equals> mLuaFolders;
167164
};
168165

169-
extern LUAAPI LuaSpore& GetLuaSpore();
166+
extern LUAAPI LuaSpore& GetLuaSpore();
167+
extern LUAAPI bool LuaSporeExists();

Spore LuaAPI/LuaSpore/TracyUtil.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/****************************************************************************
2+
* Copyright (C) 2023-2025 Zarklord
3+
*
4+
* This file is part of Spore LuaAPI.
5+
*
6+
* Spore LuaAPI is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with Spore LuaAPI. If not, see <http://www.gnu.org/licenses/>.
18+
****************************************************************************/
19+
20+
#pragma once
21+
22+
#include <tracy/Tracy.hpp>
23+
24+
namespace TracyUtil
25+
{
26+
#ifdef TRACY_ON_DEMAND
27+
inline thread_local uint32_t tracy_counter = 0;
28+
inline thread_local bool tracy_active = false;
29+
#endif
30+
31+
inline void TracyZonePush(const tracy::SourceLocationData* srcloc)
32+
{
33+
using namespace tracy;
34+
#ifdef TRACY_ENABLE
35+
#ifdef TRACY_ON_DEMAND
36+
const auto zone_count = tracy_counter++;
37+
if(zone_count != 0 && !tracy_active) return;
38+
tracy_active = TracyIsConnected;
39+
if(!tracy_active) return;
40+
#endif
41+
TracyQueuePrepare(QueueType::ZoneBegin)
42+
MemWrite(&item->zoneBegin.time, Profiler::GetTime());
43+
MemWrite(&item->zoneBegin.srcloc, srcloc);
44+
TracyQueueCommit(zoneBeginThread);
45+
#endif
46+
}
47+
48+
inline void TracyZonePop()
49+
{
50+
using namespace tracy;
51+
#ifdef TRACY_ENABLE
52+
#ifdef TRACY_ON_DEMAND
53+
assert(tracy_counter != 0);
54+
tracy_counter--;
55+
if(!tracy_active) return;
56+
if(!TracyIsConnected)
57+
{
58+
tracy_active = false;
59+
return;
60+
}
61+
#endif
62+
TracyQueuePrepare(QueueType::ZoneEnd);
63+
MemWrite(&item->zoneEnd.time, Profiler::GetTime());
64+
TracyQueueCommit(zoneEndThread);
65+
#endif
66+
}
67+
}
68+
69+
#define ZonePush static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,TracyLine) { nullptr, TracyFunction, TracyFile, (uint32_t)TracyLine, 0 }; TracyUtil::TracyZonePush(&TracyConcat(__tracy_source_location,TracyLine))
70+
#define ZonePushN(name) static constexpr tracy::SourceLocationData TracyConcat(__tracy_source_location,TracyLine) { name, TracyFunction, TracyFile, (uint32_t)TracyLine, 0 }; TracyUtil::TracyZonePush(&TracyConcat(__tracy_source_location,TracyLine))
71+
#define ZonePop TracyUtil::TracyZonePop()

0 commit comments

Comments
 (0)