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

Commit

Permalink
Merge branch 'development' into interpolated-render
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Dec 31, 2023
2 parents 2cf663b + 70c4512 commit 16f16a1
Show file tree
Hide file tree
Showing 38 changed files with 523 additions and 154 deletions.
64 changes: 35 additions & 29 deletions Activities/GAScripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "BuyMenuGUI.h"
#include "SceneEditorGUI.h"

#include "tracy/Tracy.hpp"

namespace RTE {

ConcreteClassInfo(GAScripted, GameActivity, 0);
Expand Down Expand Up @@ -204,17 +206,30 @@ int GAScripted::ReloadScripts() {
}
}

std::unordered_map<std::string, LuabindObjectWrapper*> scriptFileFunctions;
if ((error = g_LuaMan.GetMasterScriptState().RunScriptFileAndRetrieveFunctions(m_ScriptPath, m_LuaClassName, GetSupportedScriptFunctionNames(), scriptFileFunctions, true)) < 0) {
if ((error = g_LuaMan.GetMasterScriptState().RunScriptFile(m_ScriptPath, true, false)) < 0) {
return error;
}

RefreshActivityFunctions();

return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void GAScripted::RefreshActivityFunctions() {
m_ScriptFunctions.clear();
if (m_ScriptPath.empty()) {
return;
}

// We use m_LuaClassName here, because we ran the script file in the global state instead of in an environment
std::unordered_map<std::string, LuabindObjectWrapper*> scriptFileFunctions;
g_LuaMan.GetMasterScriptState().RetrieveFunctions(m_LuaClassName, GetSupportedScriptFunctionNames(), scriptFileFunctions);

for (const auto& [functionName, functionObject] : scriptFileFunctions) {
m_ScriptFunctions[functionName] = std::unique_ptr<LuabindObjectWrapper>(functionObject);
}

return 0;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -281,8 +296,8 @@ void GAScripted::HandleCraftEnteringOrbit(ACraft *orbitedCraft) {

if (orbitedCraft && g_MovableMan.IsActor(orbitedCraft)) {
g_LuaMan.GetMasterScriptState().RunScriptFunctionString(m_LuaClassName + ".CraftEnteredOrbit", m_LuaClassName, {m_LuaClassName, m_LuaClassName + ".CraftEnteredOrbit"}, {orbitedCraft});
for (const GlobalScript *globalScript : m_GlobalScriptsList) {
if (globalScript->IsActive()) { globalScript->HandleCraftEnteringOrbit(orbitedCraft); }
for (GlobalScript *globalScript : m_GlobalScriptsList) {
globalScript->HandleCraftEnteringOrbit(orbitedCraft);
}
}
}
Expand Down Expand Up @@ -333,18 +348,11 @@ int GAScripted::Start() {
g_PresetMan.GetAllOfType(globalScripts, "GlobalScript");

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

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

(*sItr)->Start();
}

Expand All @@ -364,9 +372,7 @@ void GAScripted::SetPaused(bool pause) {

// Pause all global scripts
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
if ((*sItr)->IsActive()) {
(*sItr)->Pause(pause);
}
(*sItr)->Pause(pause);
}
}

Expand All @@ -383,12 +389,7 @@ void GAScripted::End() {

// End all global scripts
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
if ((*sItr)->IsActive()) {
if (g_SettingsMan.PrintDebugInfo()) {
g_ConsoleMan.PrintString("DEBUG: End Global Script: " + (*sItr)->GetPresetName());
}
(*sItr)->End();
}
(*sItr)->End();
}

// Delete all global scripts, in case destructor is not called when activity restarts
Expand Down Expand Up @@ -436,6 +437,9 @@ void GAScripted::Update() {
if (m_ActivityState != ActivityState::Over) {
AddPieSlicesToActiveActorPieMenus();

// Need to call this continually unfortunately, as something might change due to dofile()
RefreshActivityFunctions();

RunLuaFunction("UpdateActivity");

UpdateGlobalScripts(false);
Expand All @@ -449,9 +453,11 @@ void GAScripted::Update() {
// Description: Updates globals scripts loaded with this activity.

void GAScripted::UpdateGlobalScripts(bool lateUpdate) {
ZoneScoped;

// Update all global scripts
for (std::vector<GlobalScript *>::iterator sItr = m_GlobalScriptsList.begin(); sItr < m_GlobalScriptsList.end(); ++sItr) {
if ((*sItr)->IsActive() && (*sItr)->ShouldLateUpdate() == lateUpdate) {
if ((*sItr)->ShouldLateUpdate() == lateUpdate) {
(*sItr)->Update();
}
}
Expand Down Expand Up @@ -485,7 +491,9 @@ int GAScripted::RunLuaFunction(const std::string& functionName, const std::vecto
return 0;
}

return g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(funcItr->second.get(), "_G", m_LuaClassName, functionEntityArguments, functionLiteralArguments, functionObjectArguments);
int error = g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(funcItr->second.get(), "_G", m_LuaClassName, functionEntityArguments, functionLiteralArguments, functionObjectArguments);

return error;
}


Expand Down Expand Up @@ -562,10 +570,8 @@ void GAScripted::AddPieSlicesToActiveActorPieMenus() {
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), this, true);
}
for (const GlobalScript *globalScript : m_GlobalScriptsList) {
if (globalScript->IsActive()) {
for (const std::unique_ptr<PieSlice> &pieSlice : globalScript->GetPieSlicesToAdd()) {
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), globalScript, true);
}
for (const std::unique_ptr<PieSlice> &pieSlice : globalScript->GetPieSlicesToAdd()) {
controlledActorPieMenu->AddPieSliceIfPresetNameIsUnique(pieSlice.get(), globalScript, true);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Activities/GAScripted.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ ClassInfoGetters;

int ReloadScripts() override;

/// <summary>
/// Refreshes our activity functions to find any changes from script.
/// </summary>
void RefreshActivityFunctions();


//////////////////////////////////////////////////////////////////////////////////////////
// Virtual method: GetLuaClassName
Expand Down
24 changes: 21 additions & 3 deletions Activities/GameActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ void GameActivity::Clear()
m_InventoryMenuGUI[player] = nullptr;
m_pBuyGUI[player] = 0;
m_pEditorGUI[player] = 0;
m_LuaLockActor[player] = false;
m_LuaLockActorMode[player] = Controller::InputMode::CIM_AI;
m_pBannerRed[player] = 0;
m_pBannerYellow[player] = 0;
m_BannerRepeats[player] = 0;
Expand Down Expand Up @@ -174,6 +176,8 @@ int GameActivity::Create(const GameActivity &reference)
m_InventoryMenuGUI[player] = new InventoryMenuGUI;
m_pBuyGUI[player] = new BuyMenuGUI;
m_pEditorGUI[player] = new SceneEditorGUI;
m_LuaLockActor[player] = reference.m_LuaLockActor[player];
m_LuaLockActorMode[player] = reference.m_LuaLockActorMode[player];
m_pBannerRed[player] = new GUIBanner();
m_pBannerYellow[player] = new GUIBanner();
m_ReadyToStart[player] = reference.m_ReadyToStart[player];
Expand Down Expand Up @@ -396,6 +400,18 @@ bool GameActivity::IsBuyGUIVisible(int which) const {

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool GameActivity::LockControlledActor(Players player, bool lock, Controller::InputMode lockToMode) {
if (player >= Players::PlayerOne && player < Players::MaxPlayerCount) {
bool prevLock = m_LuaLockActor[player];
m_LuaLockActor[player] = lock;
m_LuaLockActorMode[player] = lockToMode;
return true;
}
return false;
}

//////////////////////////////////////////////////////////////////////////////////////////
// Virtual method: SwitchToActor
//////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1424,7 +1440,7 @@ void GameActivity::Update()
m_ViewState[player] = ViewState::Normal;
}
// Switch to next actor if the player wants to. Don't do it while the buy menu is open
else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible())
else if (m_PlayerController[player].IsState(ACTOR_NEXT) && m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && !m_LuaLockActor[player])
{
if (m_ControlledActor[player] && m_ControlledActor[player]->GetPieMenu()) {
m_ControlledActor[player]->GetPieMenu()->SetEnabled(false);
Expand All @@ -1444,7 +1460,7 @@ void GameActivity::Update()
g_FrameMan.ClearScreenText(ScreenOfPlayer(player));
}
// Go into manual actor select mode if either actor switch buttons are held for a duration
else if (m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && (m_PlayerController[player].IsState(ACTOR_NEXT_PREP) || m_PlayerController[player].IsState(ACTOR_PREV_PREP)))
else if (m_ViewState[player] != ViewState::ActorSelect && !m_pBuyGUI[player]->IsVisible() && !m_LuaLockActor[player] && (m_PlayerController[player].IsState(ACTOR_NEXT_PREP) || m_PlayerController[player].IsState(ACTOR_PREV_PREP)))
{
if (m_ActorSelectTimer[player].IsPastRealMS(250))
{
Expand Down Expand Up @@ -2006,6 +2022,8 @@ void GameActivity::Update()
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_AI);
} else if (m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel()) {
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_DISABLED);
} else if (m_LuaLockActor[player]) {
m_ControlledActor[player]->GetController()->SetInputMode(m_LuaLockActorMode[player]);
} else {
m_ControlledActor[player]->GetController()->SetInputMode(Controller::CIM_PLAYER);
}
Expand Down Expand Up @@ -2170,7 +2188,7 @@ void GameActivity::DrawGUI(BITMAP *pTargetBitmap, const Vector &targetPos, int w
//TODO_MULTITHREAD properly formalize this. Maybe an UpdateRender/UpdateRealTime function on things?
m_PlayerController[player].Update();
// Trap the mouse if we're in gameplay and not in menus
g_UInputMan.TrapMousePos(!m_pBuyGUI[player]->IsEnabled() && !m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel(), player);
g_UInputMan.TrapMousePos(!m_pBuyGUI[player]->IsEnabled() && !m_InventoryMenuGUI[player]->IsEnabledAndNotCarousel() && !m_LuaLockActor[player], player);
if (m_ViewState[player] == ViewState::ActorSelect)
{
// Get cursor input
Expand Down
11 changes: 11 additions & 0 deletions Activities/GameActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ class GameActivity : public Activity {

SceneEditorGUI * GetEditorGUI(unsigned int which = 0) const { return m_pEditorGUI[which]; }

/// <summary>
/// Locks a player controlled actor to a specific controller mode.
/// Locking the actor will disable player input, including switching actors.
/// </summary>
/// <param name="player">Which player to lock the actor for.</param>
/// <param name="lock">Whether to lock or unlock the actor. (Default: true)</param>
/// <param name="lockToMode">Which controller mode to lock the actor to. (Default: `CIM_AI`)</param>
/// <returns>Whether the (un)lock was performed.</returns>
bool LockControlledActor(Players player, bool lock = true, Controller::InputMode lockToMode = Controller::InputMode::CIM_AI);

//////////////////////////////////////////////////////////////////////////////////////////
// Virtual method: SwitchToActor
Expand Down Expand Up @@ -1035,6 +1044,8 @@ class GameActivity : public Activity {
BuyMenuGUI *m_pBuyGUI[Players::MaxPlayerCount];
// The in-game scene editor GUI for each player
SceneEditorGUI *m_pEditorGUI[Players::MaxPlayerCount];
bool m_LuaLockActor[Players::MaxPlayerCount]; //!< Whether or not to lock input for each player while lua has control.
Controller::InputMode m_LuaLockActorMode[Players::MaxPlayerCount]; //!< The input mode to lock to while lua has control.
// The in-game important message banners for each player
GUIBanner *m_pBannerRed[Players::MaxPlayerCount];
GUIBanner *m_pBannerYellow[Players::MaxPlayerCount];
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

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

- 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.
- 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.

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

Expand All @@ -84,6 +84,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- New `Actor` INI and Lua (R/W) property `PainThreshold`, which determines how much damage this actor must take in a frame to play their `PainSound`. This can be set to 0 to never manually play the sound. Defaults to 15.

- New `AHuman` INI and Lua (R/W) property `MaxWalkPathCrouchShift`, which determines how much the actor will automatically duck down to avoid low ceilings above them. This can be set to 0 to never duck. Defaults to 6.

- New `AHuman` INI and Lua (R/W) property `MaxCrouchRotation`, which determines how much the actor will rotate when ducking to avoid low ceilings above them. This can be set to 0 to never duck. Defaults to a quarter of Pi * 1.25 (roughly 56 degrees).

- New `AHuman` Lua (R/W) property `CrouchAmountOverride`, which enforces that the actor crouch a certain amount, where 0 means fully standing and 1 is fully crouching. This override can be disabled by setting it to -1.0.

- New `AHuman` Lua (R) property `CrouchAmount`, which returns how much the actor is crouching, where 0 means fully standing and 1 is fully crouching.

- New `MOPixel` INI and Lua (R/W) property `Staininess`, which defines how likely a pixel is to stain a surface when it collides with it. Staining a surface changes that surface's `Color` to that of this `MOPixel`, without changing the underlying material. Value can be between 0 and 1. Defaults to 0 (never stain).

- New `Activity` INI and Lua (R/W) property `AllowsUserSaving`, which can be used to enable/disable manual user saving/loading. This defaults to true for all `GAScripted` with an `OnSave()` function, but false otherwise. Lua `ActivityMan::SaveGame()` function now forces a save even if `AllowsUserSaving` is disabled. This allows mods and scripted gamemodes to handle saving in their own way (for example, only allowing saving at set points).
Expand All @@ -108,6 +116,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- `Enum` binding for `SceneObject.BuyableMode`: `NORESTRICTIONS = 0, BUYMENUONLY = 1, OBJECTPICKERONLY = 2, SCRIPTONLY = 3`.

- Exposed `UInputMan::AbsoluteMousePos` to Lua

- New `GameActivity::LockControlledActor` Lua function to allow grab player input in the way menus (buy menu/full inventorymenu) do.

</details>

<details><summary><b>Changed</b></summary>
Expand Down
2 changes: 1 addition & 1 deletion Entities/AEJetpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace RTE {
switch (m_JetpackType)
{
case JetpackType::Standard:
if (controller.IsState(BODY_JUMPSTART) && !IsOutOfFuel() && IsFullyFueled()) {
if (controller.IsState(BODY_JUMPSTART) && !IsOutOfFuel()) {
Burst(parentActor, fuelUseMultiplier);
} else if (controller.IsState(BODY_JUMP) && !IsOutOfFuel() && (GetJetTimeRatio() >= m_MinimumFuelRatio || wasEmittingLastFrame)) {
Thrust(parentActor, fuelUseMultiplier);
Expand Down
Loading

0 comments on commit 16f16a1

Please sign in to comment.