Skip to content

Commit cbb2726

Browse files
committed
Merge branch 'development' into walkpath-auto-crouch
2 parents c031177 + ff0497c commit cbb2726

File tree

9 files changed

+94
-43
lines changed

9 files changed

+94
-43
lines changed

Activities/GAScripted.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "BuyMenuGUI.h"
3636
#include "SceneEditorGUI.h"
3737

38+
#include "tracy/Tracy.hpp"
39+
3840
namespace RTE {
3941

4042
ConcreteClassInfo(GAScripted, GameActivity, 0);
@@ -294,8 +296,8 @@ void GAScripted::HandleCraftEnteringOrbit(ACraft *orbitedCraft) {
294296

295297
if (orbitedCraft && g_MovableMan.IsActor(orbitedCraft)) {
296298
g_LuaMan.GetMasterScriptState().RunScriptFunctionString(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit"}, {orbitedCraft});
297-
for (const GlobalScript *globalScript : m_GlobalScriptsList) {
298-
if (globalScript->IsActive()) { globalScript->HandleCraftEnteringOrbit(orbitedCraft); }
299+
for (GlobalScript *globalScript : m_GlobalScriptsList) {
300+
globalScript->HandleCraftEnteringOrbit(orbitedCraft);
299301
}
300302
}
301303
}
@@ -346,18 +348,11 @@ int GAScripted::Start() {
346348
g_PresetMan.GetAllOfType(globalScripts, "GlobalScript");
347349

348350
for (std::list<Entity *>::iterator sItr = globalScripts.begin(); sItr != globalScripts.end(); ++sItr) {
349-
GlobalScript * script = dynamic_cast<GlobalScript *>(*sItr);
350-
if (script && g_SettingsMan.IsGlobalScriptEnabled(script->GetModuleAndPresetName())) {
351-
m_GlobalScriptsList.push_back(dynamic_cast<GlobalScript*>(script->Clone()));
352-
}
351+
m_GlobalScriptsList.push_back(dynamic_cast<GlobalScript*>((*sItr)->Clone()));
353352
}
354353

355354
// Start all global scripts
356355
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
357-
if (g_SettingsMan.PrintDebugInfo()) {
358-
g_ConsoleMan.PrintString("DEBUG: Start Global Script: " + (*sItr)->GetPresetName());
359-
}
360-
361356
(*sItr)->Start();
362357
}
363358

@@ -377,9 +372,7 @@ void GAScripted::SetPaused(bool pause) {
377372

378373
// Pause all global scripts
379374
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
380-
if ((*sItr)->IsActive()) {
381-
(*sItr)->Pause(pause);
382-
}
375+
(*sItr)->Pause(pause);
383376
}
384377
}
385378

@@ -396,12 +389,7 @@ void GAScripted::End() {
396389

397390
// End all global scripts
398391
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
399-
if ((*sItr)->IsActive()) {
400-
if (g_SettingsMan.PrintDebugInfo()) {
401-
g_ConsoleMan.PrintString("DEBUG: End Global Script: " + (*sItr)->GetPresetName());
402-
}
403-
(*sItr)->End();
404-
}
392+
(*sItr)->End();
405393
}
406394

407395
// Delete all global scripts, in case destructor is not called when activity restarts
@@ -462,9 +450,11 @@ void GAScripted::Update() {
462450
// Description: Updates globals scripts loaded with this activity.
463451

464452
void GAScripted::UpdateGlobalScripts(bool lateUpdate) {
453+
ZoneScoped;
454+
465455
// Update all global scripts
466456
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
467-
if ((*sItr)->IsActive() && (*sItr)->ShouldLateUpdate() == lateUpdate) {
457+
if ((*sItr)->ShouldLateUpdate() == lateUpdate) {
468458
(*sItr)->Update();
469459
}
470460
}
@@ -580,10 +570,8 @@ void GAScripted::AddPieSlicesToActiveActorPieMenus() {
580570
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), this, true);
581571
}
582572
for (const GlobalScript *globalScript : m_GlobalScriptsList) {
583-
if (globalScript->IsActive()) {
584-
for (const std::unique_ptr<PieSlice> &pieSlice : globalScript->GetPieSlicesToAdd()) {
585-
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), globalScript, true);
586-
}
573+
for (const std::unique_ptr<PieSlice> &pieSlice : globalScript->GetPieSlicesToAdd()) {
574+
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), globalScript, true);
587575
}
588576
}
589577
}

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
7272

7373
- New `HeldDevice` Lua function `IsBeingHeld`, which returns whether or not the `HeldDevice` is currently being held.
7474

75-
- New `HeldDevice` INI and Lua (R/W) property `GetsHitByMOsWhenHeld`, which defines whether this `HeldDevice` can be hit by MOs while equipped and held by an actor. Defaults to true.
75+
- New `HeldDevice` INI and Lua (R/W) property `GetsHitByMOsWhenHeld`, which defines whether this `HeldDevice` can be hit by MOs while equipped and held by an actor. Defaults to false.
7676

7777
- New `MovableObject` INI and Lua (R/W) property `IgnoresActorHits`, which defines whether this `MovableObject` should ignore collisions with actors. Defaults to false.
7878

Entities/Activity.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ namespace RTE {
190190
int GetInCampaignStage() const { return m_InCampaignStage; }
191191

192192
/// <summary>
193+
///
193194
/// Sets in which stage of the Campaign this appears.
194195
/// </summary>
195196
/// <param name="newStage">The new stage to set. -1 means it doesn't appear in the campaign.</param>

Entities/GlobalScript.cpp

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "ACraft.h"
88
#include "PieSlice.h"
99

10+
#include "ConsoleMan.h"
11+
#include "SettingsMan.h"
12+
1013
namespace RTE {
1114

1215
ConcreteClassInfo(GlobalScript, Entity, 10);
@@ -16,7 +19,8 @@ namespace RTE {
1619
void GlobalScript::Clear() {
1720
m_ScriptPath.clear();
1821
m_LuaClassName.clear();
19-
m_IsActive = false;
22+
m_IsActive = true;
23+
m_HasStarted = false;
2024
m_LateUpdate = false;
2125
m_PieSlicesToAdd.clear();
2226
}
@@ -29,6 +33,7 @@ namespace RTE {
2933
m_ScriptPath = reference.m_ScriptPath;
3034
m_LuaClassName = reference.m_LuaClassName;
3135
m_IsActive = reference.m_IsActive;
36+
m_HasStarted = reference.m_HasStarted;
3237
m_LateUpdate = reference.m_LateUpdate;
3338

3439
for (const std::unique_ptr<PieSlice> &referencePieSliceToAdd : reference.m_PieSlicesToAdd) {
@@ -67,6 +72,17 @@ namespace RTE {
6772
return 0;
6873
}
6974

75+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76+
77+
const std::vector<std::unique_ptr<PieSlice>>& GlobalScript::GetPieSlicesToAdd() const {
78+
const std::vector<std::unique_ptr<PieSlice>> emptyVector;
79+
if (!m_HasStarted || !m_IsActive || !g_SettingsMan.IsGlobalScriptEnabled(GetModuleAndPresetName())) {
80+
return emptyVector;
81+
}
82+
83+
return m_PieSlicesToAdd;
84+
}
85+
7086
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7187

7288
int GlobalScript::ReloadScripts() {
@@ -86,37 +102,82 @@ namespace RTE {
86102
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87103

88104
int GlobalScript::Start() {
105+
if (!g_SettingsMan.IsGlobalScriptEnabled(GetModuleAndPresetName())) {
106+
return 0;
107+
}
108+
109+
if (g_SettingsMan.PrintDebugInfo()) {
110+
g_ConsoleMan.PrintString("DEBUG: Start Global Script: " + GetPresetName());
111+
}
112+
89113
int error = ReloadScripts();
90-
if (error == 0) { error = g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + ".StartScript then " + m_LuaClassName + ":StartScript(); end"); }
91-
m_IsActive = error == 0;
114+
if (error == 0) {
115+
error = g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + ".StartScript then " + m_LuaClassName + ":StartScript(); end");
116+
m_HasStarted = true;
117+
}
92118

119+
m_IsActive = error == 0;
93120
return error;
94121
}
95122

96123
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
97124

98125
int GlobalScript::Pause(bool pause) const {
126+
if (!m_IsActive || !m_HasStarted || !g_SettingsMan.IsGlobalScriptEnabled(GetModuleAndPresetName())) {
127+
return 0;
128+
}
129+
99130
return g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + ".PauseScript then " + m_LuaClassName + ":PauseScript(" + (pause ? "true" : "false") + "); end");
100131
}
101132

102133
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103134

104135
int GlobalScript::End() const {
136+
if (!m_HasStarted) {
137+
return 0;
138+
}
139+
140+
if (g_SettingsMan.PrintDebugInfo()) {
141+
g_ConsoleMan.PrintString("DEBUG: End Global Script: " + GetPresetName());
142+
}
143+
105144
return g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + ".EndScript then " + m_LuaClassName + ":EndScript(); end");
106145
}
107146

108147
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109148

110-
void GlobalScript::HandleCraftEnteringOrbit(const ACraft *orbitedCraft) const {
111-
if (orbitedCraft && g_MovableMan.IsActor(orbitedCraft)) {
112-
g_LuaMan.GetMasterScriptState().RunScriptFunctionString(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, { m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit" }, { orbitedCraft });
149+
void GlobalScript::HandleCraftEnteringOrbit(const ACraft *orbitedCraft) {
150+
if (!m_IsActive || !!m_HasStarted || orbitedCraft == nullptr || !g_MovableMan.IsActor(orbitedCraft) || !g_SettingsMan.IsGlobalScriptEnabled(GetModuleAndPresetName())) {
151+
return;
152+
}
153+
154+
int error = g_LuaMan.GetMasterScriptState().RunScriptFunctionString(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, { m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit" }, { orbitedCraft });
155+
if (error) {
156+
m_IsActive = false;
113157
}
114158
}
115159

116160
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117161

118162
void GlobalScript::Update() {
163+
if (!m_IsActive) {
164+
return;
165+
}
166+
167+
if (!g_SettingsMan.IsGlobalScriptEnabled(GetModuleAndPresetName())) {
168+
if (m_HasStarted) {
169+
End();
170+
}
171+
return;
172+
}
173+
174+
if (!m_HasStarted) {
175+
Start();
176+
}
177+
119178
int error = g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + ".UpdateScript then " + m_LuaClassName + ":UpdateScript(); end");
120-
if (error) { SetActive(false); }
179+
if (error) {
180+
m_IsActive = false;
181+
}
121182
}
122183
}

Entities/GlobalScript.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace RTE {
8080
/// Gets the list of PieSlices this GlobalScript adds to any active Actor PieMenus.
8181
/// </summary>
8282
/// <returns>The list of PieSilces this GlobalScript adds to any active Actor PieMenus</returns>
83-
const std::vector<std::unique_ptr<PieSlice>> & GetPieSlicesToAdd() const { return m_PieSlicesToAdd; }
83+
const std::vector<std::unique_ptr<PieSlice>>& GetPieSlicesToAdd() const;
8484
#pragma endregion
8585

8686
#pragma region Concrete Methods
@@ -113,7 +113,7 @@ namespace RTE {
113113
/// Handles when an ACraft has left the game scene and entered orbit by running the appropriate Lua function. Ownership is NOT transferred!
114114
/// </summary>
115115
/// <param name="orbitedCraft">The ACraft instance that entered orbit. Ownership is NOT transferred!</param>
116-
void HandleCraftEnteringOrbit(const ACraft *orbitedCraft) const;
116+
void HandleCraftEnteringOrbit(const ACraft *orbitedCraft);
117117

118118
/// <summary>
119119
/// Updates the state of this GlobalScript every frame.
@@ -128,6 +128,7 @@ namespace RTE {
128128
std::string m_ScriptPath; //!< The path to the Lua script file that defines this' behaviors in update.
129129
std::string m_LuaClassName; //!< The name of the class (table) defining the logic of this in Lua, as specified in the script file.
130130
bool m_IsActive; //!< Whether this GlobalScript is currently allowed to run.
131+
bool m_HasStarted; //!< Whether this script has already been started.
131132
bool m_LateUpdate; //!< Whether or not this GlobalScript should be updated late, i.e. after the standard MovableMan update.
132133

133134
std::vector<std::unique_ptr<PieSlice>> m_PieSlicesToAdd; //!< A vector of PieSlices that should be added to any PieMenus opened while this GlobalScript is active.

Managers/AudioMan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ namespace RTE {
127127

128128
float globalPitch = 1.0F;
129129

130-
float simSpeed = g_TimerMan.GetSimSpeed();
130+
float timeScale = g_TimerMan.GetTimeScale();
131131
// Soften the ratio of the pitch adjustment so it's not such an extreme effect on the audio.
132132
// TODO: This coefficient should probably move to SettingsMan and be loaded from ini. That way this effect can be lessened or even turned off entirely by users. 0.35 is a good default value though.
133-
globalPitch = simSpeed + (1.0F - simSpeed) * 0.35F;
133+
globalPitch = timeScale + (1.0F - timeScale) * 0.35F;
134134

135135
SetGlobalPitch(globalPitch);
136136

Managers/LuaMan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ namespace RTE {
11011101
g_ThreadMan.GetPriorityThreadPool().submit([luaState]() {
11021102
ZoneScopedN("Lua Garbage Collection");
11031103
std::lock_guard<std::recursive_mutex> lock(luaState->GetMutex());
1104-
lua_gc(luaState->GetLuaState(), LUA_GCSTEP, 100);
1104+
lua_gc(luaState->GetLuaState(), LUA_GCSTEP, 30);
11051105
lua_gc(luaState->GetLuaState(), LUA_GCSTOP, 0);
11061106
})
11071107
);

Managers/SettingsMan.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ namespace RTE {
375375
/// Gets the map of mods which are disabled.
376376
/// </summary>
377377
/// <returns>Map of mods which are disabled.</returns>
378-
std::map<std::string, bool> & GetDisabledModsMap() { return m_DisabledMods; }
378+
std::unordered_map<std::string, bool> & GetDisabledModsMap() { return m_DisabledMods; }
379379

380380
/// <summary>
381381
/// Gets whether the specified mod is disabled in the settings.
@@ -388,7 +388,7 @@ namespace RTE {
388388
/// Gets the map of global scripts which are enabled.
389389
/// </summary>
390390
/// <returns>Map of global scripts which are enabled.</returns>
391-
std::map<std::string, bool> & GetEnabledGlobalScriptMap() { return m_EnabledGlobalScripts; }
391+
std::unordered_map<std::string, bool> & GetEnabledGlobalScriptMap() { return m_EnabledGlobalScripts; }
392392

393393
/// <summary>
394394
/// Gets whether the specified global script is enabled in the settings.
@@ -563,8 +563,8 @@ namespace RTE {
563563
bool m_MeasureModuleLoadTime; //!< Whether to measure the duration of data module loading (extraction included). For benchmarking purposes.
564564

565565
std::list<std::string> m_VisibleAssemblyGroupsList; //!< List of assemblies groups always shown in editors.
566-
std::map<std::string, bool> m_DisabledMods; //!< Map of the module names we disabled.
567-
std::map<std::string, bool> m_EnabledGlobalScripts; //!< Map of the global script names we enabled.
566+
std::unordered_map<std::string, bool> m_DisabledMods; //!< Map of the module names we disabled.
567+
std::unordered_map<std::string, bool> m_EnabledGlobalScripts; //!< Map of the global script names we enabled.
568568

569569
private:
570570

Menus/ModManagerGUI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace RTE {
118118
void ModManagerGUI::ToggleMod() {
119119
int index = m_ModsListBox->GetSelectedIndex();
120120
if (index > -1) {
121-
std::map<std::string, bool> &disabledModsList = g_SettingsMan.GetDisabledModsMap();
121+
std::unordered_map<std::string, bool> &disabledModsList = g_SettingsMan.GetDisabledModsMap();
122122
GUIListPanel::Item *selectedItem = m_ModsListBox->GetSelected();
123123
ModRecord &modRecord = m_KnownMods.at(selectedItem->m_ExtraIndex);
124124

@@ -146,7 +146,7 @@ namespace RTE {
146146
void ModManagerGUI::ToggleScript() {
147147
int index = m_ScriptsListBox->GetSelectedIndex();
148148
if (index > -1) {
149-
std::map<std::string, bool> &enabledScriptList = g_SettingsMan.GetEnabledGlobalScriptMap();
149+
std::unordered_map<std::string, bool> &enabledScriptList = g_SettingsMan.GetEnabledGlobalScriptMap();
150150
GUIListPanel::Item *selectedItem = m_ScriptsListBox->GetSelected();
151151
ScriptRecord &scriptRecord = m_KnownScripts.at(selectedItem->m_ExtraIndex);
152152

0 commit comments

Comments
 (0)