Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 0969893

Browse files
committed
Made OnPieMenu and CraftEnteredOrbit functions be called with parameters instead of using member variables to pass data to lua. Removed all references to these member variables, cleaned up the relevant methods and their comments.
1 parent 5e28692 commit 0969893

File tree

13 files changed

+85
-175
lines changed

13 files changed

+85
-175
lines changed

Activities/GAScripted.cpp

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -269,55 +269,34 @@ bool GAScripted::SceneIsCompatible(Scene *pScene, int teams)
269269
return g_LuaMan.GlobalIsDefined("TestScene");
270270
}
271271

272+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
272273

273-
//////////////////////////////////////////////////////////////////////////////////////////
274-
// Virtual Method: EnteredOrbit
275-
//////////////////////////////////////////////////////////////////////////////////////////
276-
// Description: Indicates an Actor as having left the game scene and entered orbit.
277-
// OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
278-
279-
void GAScripted::EnteredOrbit(Actor *pActor)
280-
{
281-
GameActivity::EnteredOrbit(pActor);
282-
283-
// Save the ACraft actor temporarily to member so the lua function can access it
284-
m_pOrbitedCraft = pActor;
274+
void GAScripted::EnteredOrbit(Actor *orbitedCraft) {
275+
GameActivity::EnteredOrbit(orbitedCraft);
285276

286-
if (m_pOrbitedCraft && g_MovableMan.IsActor(m_pOrbitedCraft))
287-
{
288-
// Call the defined function, but only after first checking if it exists
289-
g_LuaMan.RunScriptString("if " + m_LuaClassName + ".CraftEnteredOrbit then " + m_LuaClassName + ":CraftEnteredOrbit(); end");
290-
291-
// Trigger orbited craft for all global scripts
292-
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr)
293-
if ((*sItr)->IsActive())
294-
(*sItr)->EnteredOrbit(m_pOrbitedCraft);
277+
if (orbitedCraft && g_MovableMan.IsActor(orbitedCraft)) {
278+
g_LuaMan.RunScriptedFunction(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit"}, {orbitedCraft});
279+
for (GlobalScript *globalScript : m_GlobalScriptsList) {
280+
if (globalScript->IsActive()) { globalScript->EnteredOrbit(orbitedCraft); }
281+
}
295282
}
296-
297-
// Let go because it's about to be deleted later this frame
298-
m_pOrbitedCraft = 0;
299283
}
300284

301-
void GAScripted::OnPieMenu(Actor *pActor)
302-
{
303-
m_pPieMenuActor = pActor;
304-
if (pActor && g_MovableMan.IsActor(pActor))
305-
{
306-
m_pPieMenuActor->OnPieMenu(pActor);
307-
308-
g_MovableMan.OnPieMenu(pActor);
285+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
309286

310-
// Call the defined function, but only after first checking if it exists
311-
g_LuaMan.RunScriptString("if " + m_LuaClassName + ".OnPieMenu then " + m_LuaClassName + ":OnPieMenu(); end");
312-
313-
// Trigger pie menu for all global scripts
314-
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr)
315-
if ((*sItr)->IsActive())
316-
(*sItr)->OnPieMenu(m_pPieMenuActor);
287+
void GAScripted::OnPieMenu(Actor *pieMenuActor) {
288+
if (pieMenuActor && g_MovableMan.IsActor(pieMenuActor)) {
289+
pieMenuActor->OnPieMenu(pieMenuActor);
290+
g_MovableMan.OnPieMenu(pieMenuActor);
291+
g_LuaMan.RunScriptedFunction(m_LuaClassName + ".OnPieMenu", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".OnPieMenu"}, {pieMenuActor});
292+
for (GlobalScript *globalScript : m_GlobalScriptsList) {
293+
if (globalScript->IsActive()) { globalScript->OnPieMenu(pieMenuActor); }
294+
}
317295
}
318-
319296
}
320297

298+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
299+
321300
//////////////////////////////////////////////////////////////////////////////////////////
322301
// Virtual method: Start
323302
//////////////////////////////////////////////////////////////////////////////////////////

Activities/GAScripted.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,11 @@ ENTITYALLOCATION(GAScripted)
209209
virtual bool SceneIsCompatible(Scene *pScene, int teams = -1);
210210

211211

212-
//////////////////////////////////////////////////////////////////////////////////////////
213-
// Virtual method: EnteredOrbit
214-
//////////////////////////////////////////////////////////////////////////////////////////
215-
// Description: Indicates an Actor as having left the game scene and entered orbit.
216-
// OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
217-
// Arguments: The actor instance. Ownership IS NOT TRANSFERRED!
218-
// Return value: None.
219-
220-
virtual void EnteredOrbit(Actor *pActor);
212+
/// <summary>
213+
/// Indicates an Actor as having left the game scene and entered orbit. OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
214+
/// </summary>
215+
/// <param name="orbitedCraft">The actor instance that entered orbit. Ownership IS NOT TRANSFERRED!</param>
216+
virtual void EnteredOrbit(Actor *orbitedCraft);
221217

222218

223219
//////////////////////////////////////////////////////////////////////////////////////////
@@ -283,14 +279,11 @@ ENTITYALLOCATION(GAScripted)
283279
virtual void UpdateGlobalScripts(bool lateUpdate);
284280

285281

286-
//////////////////////////////////////////////////////////////////////////////////////////
287-
// Method: OnPieMenu
288-
//////////////////////////////////////////////////////////////////////////////////////////
289-
// Description: Calls this to be processed by derived classes to enable pie-menu dynamic change
290-
// Arguments: None.
291-
// Return value: None.
292-
293-
virtual void OnPieMenu(Actor *pActor);
282+
/// <summary>
283+
/// Calls this to be processed by derived classes to enable pie-menu dynamic change.
284+
/// </summary>
285+
/// <param name="pieMenuActor">The actor which triggered the pie menu event.</param>
286+
virtual void OnPieMenu(Actor *pieMenuActor);
294287

295288

296289
//////////////////////////////////////////////////////////////////////////////////////////

Activities/GameActivity.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ void GameActivity::Clear()
114114
m_GameOverTimer.Reset();
115115
m_GameOverPeriod = 5000;
116116
m_WinnerTeam = -1;
117-
m_pOrbitedCraft = 0;
118-
m_pPieMenuActor = 0;
119117
}
120118

121119

Activities/GameActivity.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -916,15 +916,7 @@ ENTITYALLOCATION(GameActivity)
916916

917917
void SetNetworkPlayerName(int player, std::string name);
918918

919-
920-
//////////////////////////////////////////////////////////////////////////////////////////
921-
// Method: OnPieMenu
922-
//////////////////////////////////////////////////////////////////////////////////////////
923-
// Description: Calls this to be processed by derived classes to enable pie-menu dynamic change
924-
// Arguments: None.
925-
// Return value: None.
926-
927-
virtual void OnPieMenu(Actor *pActor) { m_pPieMenuActor = pActor; };
919+
virtual void OnPieMenu(Actor *actor) { /* Does nothing, kept here for program control flow. Method is not pure virtual to avoid a bunch of junk implementations in non-scritped activities. */};
928920

929921
virtual void AddPieMenuSlice(std::string description, std::string functionName, PieMenuGUI::Slice::SliceDirection direction, bool isEnabled)
930922
{
@@ -1187,10 +1179,6 @@ ENTITYALLOCATION(GameActivity)
11871179
long m_GameOverPeriod;
11881180
// The winning team number, when the game is over
11891181
int m_WinnerTeam;
1190-
// Temporary member for whatever craft goes into orbit, so Lua can access it. Not owned by this
1191-
Actor *m_pOrbitedCraft;
1192-
// Temporary member for whatever actor has enabled the pie menu. Not owned by this
1193-
Actor *m_pPieMenuActor;
11941182

11951183
std::vector<PieMenuGUI::Slice *> m_CurrentPieMenuSlices;
11961184

Entities/AHuman.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,22 +3141,20 @@ void AHuman::UpdateAI()
31413141
}
31423142
}
31433143

3144-
//////////////////////////////////////////////////////////////////////////////////////////
3145-
// Virtual method: OnPieMenu
3146-
//////////////////////////////////////////////////////////////////////////////////////////
3147-
// Description: Executes the Lua-defined OnPieMenu event handler.
3144+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31483145

3149-
int AHuman::OnPieMenu(Actor * pActor)
3150-
{
3151-
int error = Actor::OnPieMenu(pActor);
3146+
int AHuman::OnPieMenu(Actor *pieMenuActor) {
3147+
int status = Actor::OnPieMenu(pieMenuActor);
31523148

3153-
// Call OnPieMenu handlers for a currently held device if any
3154-
if (m_pFGArm && m_pFGArm->IsAttached() && m_pFGArm->HoldsDevice())
3155-
return m_pFGArm->GetHeldDevice()->OnPieMenu(pActor);
3149+
if (status >= 0 && m_pFGArm && m_pFGArm->IsAttached() && m_pFGArm->HoldsDevice()) {
3150+
return m_pFGArm->GetHeldDevice()->OnPieMenu(pieMenuActor);
3151+
}
31563152

3157-
return 0;
3153+
return status;
31583154
}
31593155

3156+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3157+
31603158
//////////////////////////////////////////////////////////////////////////////////////////
31613159
// Virtual method: Update
31623160
//////////////////////////////////////////////////////////////////////////////////////////

Entities/AHuman.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,12 @@ ENTITYALLOCATION(AHuman)
916916

917917
virtual void Update();
918918

919-
920-
//////////////////////////////////////////////////////////////////////////////////////////
921-
// Virtual method: OnPieMenu
922-
//////////////////////////////////////////////////////////////////////////////////////////
923-
// Description: Executes the Lua-defined OnPieMenu event handler.
924-
// Arguments: Actor which triggered the pie menu event
925-
// Return value: An error return value signaling sucess or any particular failure.
926-
// Anything below 0 is an error signal.
927-
928-
virtual int OnPieMenu(Actor * pActor);
919+
/// <summary>
920+
/// Executes the Lua-defined OnPieMenu event handler for this AHuman.
921+
/// </summary>
922+
/// <param name="pieMenuActor">The actor which triggered the pie menu event.</param>
923+
/// <returns>An error return value signaling sucess or any particular failure. Anything below 0 is an error signal.</returns>
924+
virtual int OnPieMenu(Actor *pieMenuActor);
929925

930926

931927
//////////////////////////////////////////////////////////////////////////////////////////

Entities/GlobalScript.cpp

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ void GlobalScript::Clear()
3030
{
3131
m_ScriptPath.clear();
3232
m_LuaClassName.clear();
33-
m_pOrbitedCraft = 0;
34-
m_pPieMenuActor = 0;
3533
m_IsActive = false;
3634
m_LateUpdate = false;
3735
}
@@ -47,8 +45,6 @@ int GlobalScript::Create(const GlobalScript &reference)
4745

4846
m_ScriptPath = reference.m_ScriptPath;
4947
m_LuaClassName = reference.m_LuaClassName;
50-
m_pOrbitedCraft = reference.m_pOrbitedCraft;
51-
m_pPieMenuActor = reference.m_pPieMenuActor;
5248
m_IsActive = reference.m_IsActive;
5349
m_LateUpdate = reference.m_LateUpdate;
5450

@@ -128,42 +124,24 @@ int GlobalScript::ReloadScripts()
128124
return error;
129125
}
130126

131-
//////////////////////////////////////////////////////////////////////////////////////////
132-
// Virtual Method: EnteredOrbit
133-
//////////////////////////////////////////////////////////////////////////////////////////
134-
// Description: Indicates an Actor as having left the game scene and entered orbit.
135-
// OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
127+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136128

137-
void GlobalScript::EnteredOrbit(Actor *pActor)
138-
{
139-
// Save the ACraft actor temporarily to member so the lua function can access it
140-
m_pOrbitedCraft = pActor;
141-
142-
if (m_pOrbitedCraft && g_MovableMan.IsActor(m_pOrbitedCraft))
143-
{
144-
// Call the defined function, but only after first checking if it exists
145-
g_LuaMan.RunScriptString("if " + m_LuaClassName + ".CraftEnteredOrbit then " + m_LuaClassName + ":CraftEnteredOrbit(); end");
129+
void GlobalScript::EnteredOrbit(Actor *orbitedActor) {
130+
if (orbitedActor && g_MovableMan.IsActor(orbitedActor)) {
131+
g_LuaMan.RunScriptedFunction(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit"}, {orbitedActor});
146132
}
147-
148-
// Let go because it's about to be deleted later this frame
149-
m_pOrbitedCraft = 0;
150133
}
151134

152-
void GlobalScript::OnPieMenu(Actor *pActor)
153-
{
154-
// Save the actor temporarily to member so the lua function can access it
155-
m_pPieMenuActor = pActor;
135+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156136

157-
if (m_pPieMenuActor && g_MovableMan.IsActor(m_pPieMenuActor))
158-
{
159-
// Call the defined function, but only after first checking if it exists
160-
g_LuaMan.RunScriptString("if " + m_LuaClassName + ".OnPieMenu then " + m_LuaClassName + ":OnPieMenu(); end");
137+
void GlobalScript::OnPieMenu(Actor *pieMenuActor) {
138+
if (pieMenuActor && g_MovableMan.IsActor(pieMenuActor)) {
139+
g_LuaMan.RunScriptedFunction(m_LuaClassName + ".OnPieMenu", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".OnPieMenu"}, {pieMenuActor});
161140
}
162-
163-
// Let go because it's about to be deleted later this frame
164-
m_pPieMenuActor = 0;
165141
}
166142

143+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144+
167145
//////////////////////////////////////////////////////////////////////////////////////////
168146
// Virtual method: Start
169147
//////////////////////////////////////////////////////////////////////////////////////////

Entities/GlobalScript.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,19 +233,18 @@ ENTITYALLOCATION(GlobalScript)
233233

234234
virtual void Update();
235235

236+
/// <summary>
237+
/// Indicates an Actor as having left the game scene and entered orbit. OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
238+
/// </summary>
239+
/// <param name="orbitedActor">The actor instance that entered orbit. Ownership IS NOT TRANSFERRED!</param>
240+
virtual void EnteredOrbit(Actor *orbitedCraft);
236241

237-
//////////////////////////////////////////////////////////////////////////////////////////
238-
// Virtual method: EnteredOrbit
239-
//////////////////////////////////////////////////////////////////////////////////////////
240-
// Description: Indicates an Actor as having left the game scene and entered orbit.
241-
// OWNERSHIP IS NOT transferred, as the Actor's inventory is just 'unloaded'.
242-
// Arguments: The actor instance. Ownership IS NOT TRANSFERRED!
243-
// Return value: None.
244-
245-
virtual void EnteredOrbit(Actor *pActor);
246-
247-
248-
virtual void OnPieMenu(Actor *pActor);
242+
/// <summary>
243+
/// Executes the Lua-defined OnPieMenu event handler for this global script.
244+
/// </summary>
245+
/// <param name="pieMenuActor">The actor which triggered the pie menu event.</param>
246+
/// <returns>An error return value signaling sucess or any particular failure. Anything below 0 is an error signal.</returns>
247+
virtual void OnPieMenu(Actor *pieMenuActor);
249248

250249

251250
//////////////////////////////////////////////////////////////////////////////////////////
@@ -276,11 +275,6 @@ ENTITYALLOCATION(GlobalScript)
276275
std::string m_ScriptPath;
277276
// Whether this script allowed to run
278277
bool m_IsActive;
279-
// Orbited craft
280-
Actor * m_pOrbitedCraft;
281-
// Actor who opened pie menu
282-
Actor * m_pPieMenuActor;
283-
284278

285279
// Whether the script should Update before MovableMan or after
286280
bool m_LateUpdate;

Entities/MovableObject.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ void MovableObject::Clear()
100100
m_ParticleUniqueIDHit = 0;
101101

102102
m_ProvidesPieMenuContext = false;
103-
m_pPieMenuActor = 0;
104103
}
105104

106105

@@ -246,7 +245,6 @@ int MovableObject::Create(const MovableObject &reference)
246245
g_MovableMan.RegisterObject(this);
247246

248247
m_ProvidesPieMenuContext = reference.m_ProvidesPieMenuContext;
249-
m_pPieMenuActor = reference.m_pPieMenuActor;
250248

251249
return 0;
252250
}
@@ -968,13 +966,12 @@ int MovableObject::UpdateScripts() {
968966

969967
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
970968

971-
int MovableObject::OnPieMenu(Actor * pActor) {
972-
if (!pActor || m_LoadedScripts.empty() || m_ScriptPresetName.empty() || m_ScriptObjectName.empty()) {
969+
int MovableObject::OnPieMenu(Actor *pieMenuActor) {
970+
if (!pieMenuActor || m_LoadedScripts.empty() || m_ScriptPresetName.empty() || m_ScriptObjectName.empty()) {
973971
return -1;
974972
}
975-
m_pPieMenuActor = pActor;
976973

977-
return RunScriptedFunctionInAppropriateScripts("OnPieMenu"); //TODO try passing actor here, see if it works. If it does, maybe quietly refactor this whole thing
974+
return RunScriptedFunctionInAppropriateScripts("OnPieMenu", false, false, {pieMenuActor});
978975
}
979976

980977
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Entities/MovableObject.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,9 @@ ENTITYALLOCATION(MovableObject)
15351535
/// <summary>
15361536
/// Executes the Lua-defined OnPieMenu event handler for this MO.
15371537
/// </summary>
1538-
/// <param name="pActor">Actor which triggered the pie menu event.</param>
1538+
/// <param name="pieMenuActor">The actor which triggered the pie menu event.</param>
15391539
/// <returns>An error return value signaling sucess or any particular failure. Anything below 0 is an error signal.</returns>
1540-
virtual int OnPieMenu(Actor *pActor);
1540+
virtual int OnPieMenu(Actor *pieMenuActor);
15411541

15421542

15431543
//////////////////////////////////////////////////////////////////////////////////////////
@@ -1965,8 +1965,6 @@ ENTITYALLOCATION(MovableObject)
19651965
unsigned int m_LastCollisionSimFrameNumber;
19661966
// If true, the object will receive OnPieMenu event whenever someone activated a pie menu
19671967
bool m_ProvidesPieMenuContext;
1968-
// Temp variable to process OnPieMenu events
1969-
Actor * m_pPieMenuActor;
19701968

19711969
//////////////////////////////////////////////////////////////////////////////////////////
19721970
// Private member variable and method declarations

0 commit comments

Comments
 (0)