mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-06 19:01:06 +03:00
Begin to split GameLogicScript. First up is Entity.
This commit is contained in:
parent
6cc329f43f
commit
8bcc41ef77
13 changed files with 196 additions and 117 deletions
|
@ -41,6 +41,7 @@
|
||||||
<ClInclude Include="include\ReservedScriptNames.h" />
|
<ClInclude Include="include\ReservedScriptNames.h" />
|
||||||
<ClInclude Include="include\ScriptAssert.h" />
|
<ClInclude Include="include\ScriptAssert.h" />
|
||||||
<ClInclude Include="include\Scripting\AudioTracks.h" />
|
<ClInclude Include="include\Scripting\AudioTracks.h" />
|
||||||
|
<ClInclude Include="include\Scripting\Entity\ScriptInterfaceEntity.h" />
|
||||||
<ClInclude Include="include\Scripting\GameFlowScript.h" />
|
<ClInclude Include="include\Scripting\GameFlowScript.h" />
|
||||||
<ClInclude Include="include\Scripting\GameLogicScript.h" />
|
<ClInclude Include="include\Scripting\GameLogicScript.h" />
|
||||||
<ClInclude Include="include\Scripting\GameScriptAIObject.h" />
|
<ClInclude Include="include\Scripting\GameScriptAIObject.h" />
|
||||||
|
@ -77,6 +78,7 @@
|
||||||
<ClInclude Include="include\ScriptInterfaceLevel.h" />
|
<ClInclude Include="include\ScriptInterfaceLevel.h" />
|
||||||
<ClInclude Include="include\ScriptUtil.h" />
|
<ClInclude Include="include\ScriptUtil.h" />
|
||||||
<ClInclude Include="src\AudioTracks.h" />
|
<ClInclude Include="src\AudioTracks.h" />
|
||||||
|
<ClInclude Include="src\Entity\Entity.h" />
|
||||||
<ClInclude Include="src\Entity\Static\GameScriptMeshInfo.h" />
|
<ClInclude Include="src\Entity\Static\GameScriptMeshInfo.h" />
|
||||||
<ClInclude Include="src\GameFlowScript.h" />
|
<ClInclude Include="src\GameFlowScript.h" />
|
||||||
<ClInclude Include="src\GameLogicScript.h" />
|
<ClInclude Include="src\GameLogicScript.h" />
|
||||||
|
@ -113,6 +115,7 @@
|
||||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">frameworkandsol.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">frameworkandsol.h</PrecompiledHeaderFile>
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Entity\Entity.cpp" />
|
||||||
<ClCompile Include="src\Entity\Static\GameScriptMeshInfo.cpp" />
|
<ClCompile Include="src\Entity\Static\GameScriptMeshInfo.cpp" />
|
||||||
<ClCompile Include="src\GameFlowScript.cpp" />
|
<ClCompile Include="src\GameFlowScript.cpp" />
|
||||||
<ClCompile Include="src\ScriptInterfaceState.cpp" />
|
<ClCompile Include="src\ScriptInterfaceState.cpp" />
|
||||||
|
|
|
@ -276,6 +276,12 @@
|
||||||
<ClInclude Include="src\Entity\Static\GameScriptMeshInfo.h">
|
<ClInclude Include="src\Entity\Static\GameScriptMeshInfo.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\Entity\Entity.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\Scripting\Entity\ScriptInterfaceEntity.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="frameworkandsol.cpp">
|
<ClCompile Include="frameworkandsol.cpp">
|
||||||
|
@ -350,6 +356,9 @@
|
||||||
<ClCompile Include="src\Entity\Static\GameScriptMeshInfo.cpp">
|
<ClCompile Include="src\Entity\Static\GameScriptMeshInfo.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\Entity\Entity.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|
25
Scripting/include/Scripting/Entity/ScriptInterfaceEntity.h
Normal file
25
Scripting/include/Scripting/Entity/ScriptInterfaceEntity.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <functional>
|
||||||
|
#include "Specific/level.h"
|
||||||
|
|
||||||
|
typedef DWORD D3DCOLOR;
|
||||||
|
using VarMapVal = std::variant< short,
|
||||||
|
std::reference_wrapper<MESH_INFO>,
|
||||||
|
std::reference_wrapper<LEVEL_CAMERA_INFO>,
|
||||||
|
std::reference_wrapper<SINK_INFO>,
|
||||||
|
std::reference_wrapper<SOUND_SOURCE_INFO>,
|
||||||
|
std::reference_wrapper<AI_OBJECT>>;
|
||||||
|
|
||||||
|
using CallbackDrawString = std::function<void(std::string const&, D3DCOLOR, int, int, int)>;
|
||||||
|
|
||||||
|
class ScriptInterfaceEntity {
|
||||||
|
public:
|
||||||
|
virtual ~ScriptInterfaceEntity() = default;
|
||||||
|
|
||||||
|
virtual bool AddName(std::string const& key, VarMapVal val) = 0;
|
||||||
|
virtual void FreeEntities() = 0;
|
||||||
|
virtual void AssignLara() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern ScriptInterfaceEntity* g_GameScriptEntities;
|
|
@ -29,11 +29,9 @@ public:
|
||||||
|
|
||||||
virtual void SetCallbackDrawString(CallbackDrawString) = 0;
|
virtual void SetCallbackDrawString(CallbackDrawString) = 0;
|
||||||
virtual void FreeLevelScripts() = 0;
|
virtual void FreeLevelScripts() = 0;
|
||||||
virtual bool AddName(std::string const& key, VarMapVal val) = 0;
|
|
||||||
virtual void ExecuteScriptFile(std::string const& luaFileName) = 0;
|
virtual void ExecuteScriptFile(std::string const& luaFileName) = 0;
|
||||||
virtual void ExecuteFunction(std::string const& luaFileName) = 0;
|
virtual void ExecuteFunction(std::string const& luaFileName) = 0;
|
||||||
|
|
||||||
virtual void AssignItemsAndLara() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ScriptInterfaceGame* g_GameScript;
|
extern ScriptInterfaceGame* g_GameScript;
|
|
@ -1,12 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "ScriptInterfaceGame.h"
|
#include "ScriptInterfaceGame.h"
|
||||||
#include "ScriptInterfaceFlow.h"
|
#include "ScriptInterfaceFlow.h"
|
||||||
|
#include "Entity/ScriptInterfaceEntity.h"
|
||||||
|
|
||||||
class ScriptInterfaceState
|
class ScriptInterfaceState
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static ScriptInterfaceGame* CreateGame();
|
static ScriptInterfaceGame* CreateGame();
|
||||||
static ScriptInterfaceFlow* CreateFlow();
|
static ScriptInterfaceFlow* CreateFlow();
|
||||||
|
static ScriptInterfaceEntity* CreateEntities();
|
||||||
static void ScriptInterfaceState::Init();
|
static void ScriptInterfaceState::Init();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
90
Scripting/src/Entity/Entity.cpp
Normal file
90
Scripting/src/Entity/Entity.cpp
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
#include "frameworkandsol.h"
|
||||||
|
#include "ReservedScriptNames.h"
|
||||||
|
#include "Lara/lara.h"
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
GameEntities::GameEntities(sol::state* lua) : LuaHandler{ lua }
|
||||||
|
{
|
||||||
|
/***
|
||||||
|
Get an ItemInfo by its name.
|
||||||
|
@function GetItemByName
|
||||||
|
@tparam string name the unique name of the item as set in, or generated by, Tomb Editor
|
||||||
|
@treturn ItemInfo a non-owning ItemInfo referencing the item.
|
||||||
|
*/
|
||||||
|
m_lua->set_function(ScriptReserved_GetItemByName, &GameEntities::GetByName<GameScriptItemInfo, ScriptReserved_ItemInfo>, this);
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get a MeshInfo by its name.
|
||||||
|
@function GetMeshByName
|
||||||
|
@tparam string name the unique name of the mesh as set in, or generated by, Tomb Editor
|
||||||
|
@treturn MeshInfo a non-owning MeshInfo referencing the mesh.
|
||||||
|
*/
|
||||||
|
m_lua->set_function(ScriptReserved_GetMeshByName, &GameEntities::GetByName<GameScriptMeshInfo, ScriptReserved_MeshInfo>, this);
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get a CameraInfo by its name.
|
||||||
|
@function GetCameraByName
|
||||||
|
@tparam string name the unique name of the camera as set in, or generated by, Tomb Editor
|
||||||
|
@treturn CameraInfo a non-owning CameraInfo referencing the camera.
|
||||||
|
*/
|
||||||
|
m_lua->set_function(ScriptReserved_GetCameraByName, &GameEntities::GetByName<GameScriptCameraInfo, ScriptReserved_CameraInfo>, this);
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get a SinkInfo by its name.
|
||||||
|
@function GetSinkByName
|
||||||
|
@tparam string name the unique name of the sink as set in, or generated by, Tomb Editor
|
||||||
|
@treturn SinkInfo a non-owning SinkInfo referencing the sink.
|
||||||
|
*/
|
||||||
|
m_lua->set_function(ScriptReserved_GetSinkByName, &GameEntities::GetByName<GameScriptSinkInfo, ScriptReserved_SinkInfo>, this);
|
||||||
|
|
||||||
|
/***
|
||||||
|
Get a SoundSourceInfo by its name.
|
||||||
|
@function GetSoundSourceByName
|
||||||
|
@tparam string name the unique name of the sink as set in, or generated by, Tomb Editor
|
||||||
|
@treturn SoundSourceInfo a non-owning SoundSourceInfo referencing the sink.
|
||||||
|
*/
|
||||||
|
m_lua->set_function(ScriptReserved_GetSoundSourceByName, &GameEntities::GetByName<GameScriptSoundSourceInfo, ScriptReserved_SoundSourceInfo>, this);
|
||||||
|
|
||||||
|
GameScriptItemInfo::Register(m_lua);
|
||||||
|
GameScriptItemInfo::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
GameScriptMeshInfo::Register(m_lua);
|
||||||
|
GameScriptMeshInfo::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
GameScriptCameraInfo::Register(m_lua);
|
||||||
|
GameScriptCameraInfo::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
GameScriptSinkInfo::Register(m_lua);
|
||||||
|
GameScriptSinkInfo::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
GameScriptAIObject::Register(m_lua);
|
||||||
|
GameScriptAIObject::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
GameScriptSoundSourceInfo::Register(m_lua);
|
||||||
|
GameScriptSoundSourceInfo::SetNameCallbacks(
|
||||||
|
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
||||||
|
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameEntities::AssignLara()
|
||||||
|
{
|
||||||
|
m_lua->set("Lara", GameScriptItemInfo(Lara.itemNumber, false));
|
||||||
|
}
|
||||||
|
|
49
Scripting/src/Entity/Entity.h
Normal file
49
Scripting/src/Entity/Entity.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#pragma once
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "LuaHandler.h"
|
||||||
|
#include "Scripting/Entity/ScriptInterfaceEntity.h"
|
||||||
|
#include "GameScriptItemInfo.h"
|
||||||
|
#include "Entity/Static/GameScriptMeshInfo.h"
|
||||||
|
#include "GameScriptSinkInfo.h"
|
||||||
|
#include "GameScriptAIObject.h"
|
||||||
|
#include "GameScriptSoundSourceInfo.h"
|
||||||
|
#include "GameScriptCameraInfo.h"
|
||||||
|
|
||||||
|
class GameEntities : public ScriptInterfaceEntity, public LuaHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
GameEntities::GameEntities(sol::state* lua);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_map<std::string, VarMapVal> m_nameMap{};
|
||||||
|
std::unordered_map<std::string, short> m_itemsMapName{};
|
||||||
|
|
||||||
|
|
||||||
|
void AssignLara() override;
|
||||||
|
|
||||||
|
template <typename R, char const* S>
|
||||||
|
std::unique_ptr<R> GetByName(std::string const& name)
|
||||||
|
{
|
||||||
|
ScriptAssertF(m_nameMap.find(name) != m_nameMap.end(), "{} name not found: {}", S, name);
|
||||||
|
return std::make_unique<R>(std::get<R::IdentifierType>(m_nameMap.at(name)), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AddName(std::string const& key, VarMapVal val) override
|
||||||
|
{
|
||||||
|
auto p = std::pair<std::string const&, VarMapVal>{ key, val };
|
||||||
|
return m_nameMap.insert(p).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RemoveName(std::string const& key)
|
||||||
|
{
|
||||||
|
return m_nameMap.erase(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreeEntities() override
|
||||||
|
{
|
||||||
|
m_nameMap.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ using std::unordered_map;
|
||||||
|
|
||||||
ScriptInterfaceFlow* g_GameFlow;
|
ScriptInterfaceFlow* g_GameFlow;
|
||||||
ScriptInterfaceGame* g_GameScript;
|
ScriptInterfaceGame* g_GameScript;
|
||||||
|
ScriptInterfaceEntity* g_GameScriptEntities;
|
||||||
|
|
||||||
GameFlow::GameFlow(sol::state* lua) : LuaHandler{ lua }
|
GameFlow::GameFlow(sol::state* lua) : LuaHandler{ lua }
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "GameScriptAnimations.h"
|
#include "GameScriptAnimations.h"
|
||||||
#include "ScriptInterfaceGame.h"
|
#include "ScriptInterfaceGame.h"
|
||||||
#include "ScriptInterfaceFlow.h"
|
#include "ScriptInterfaceFlow.h"
|
||||||
|
#include "Entity/Entity.h"
|
||||||
|
|
||||||
class GameFlow : public LuaHandler, public ScriptInterfaceFlow
|
class GameFlow : public LuaHandler, public ScriptInterfaceFlow
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,45 +46,6 @@ static void MakeSpecialTable(sol::state * state, std::string const & name, funcI
|
||||||
|
|
||||||
GameScript::GameScript(sol::state* lua) : LuaHandler{ lua }
|
GameScript::GameScript(sol::state* lua) : LuaHandler{ lua }
|
||||||
{
|
{
|
||||||
/***
|
|
||||||
Get an ItemInfo by its name.
|
|
||||||
@function GetItemByName
|
|
||||||
@tparam string name the unique name of the item as set in, or generated by, Tomb Editor
|
|
||||||
@treturn ItemInfo a non-owning ItemInfo referencing the item.
|
|
||||||
*/
|
|
||||||
m_lua->set_function(ScriptReserved_GetItemByName, &GameScript::GetByName<GameScriptItemInfo, ScriptReserved_ItemInfo>, this);
|
|
||||||
|
|
||||||
/***
|
|
||||||
Get a MeshInfo by its name.
|
|
||||||
@function GetMeshByName
|
|
||||||
@tparam string name the unique name of the mesh as set in, or generated by, Tomb Editor
|
|
||||||
@treturn MeshInfo a non-owning MeshInfo referencing the mesh.
|
|
||||||
*/
|
|
||||||
m_lua->set_function(ScriptReserved_GetMeshByName, &GameScript::GetByName<GameScriptMeshInfo, ScriptReserved_MeshInfo>, this);
|
|
||||||
|
|
||||||
/***
|
|
||||||
Get a CameraInfo by its name.
|
|
||||||
@function GetCameraByName
|
|
||||||
@tparam string name the unique name of the camera as set in, or generated by, Tomb Editor
|
|
||||||
@treturn CameraInfo a non-owning CameraInfo referencing the camera.
|
|
||||||
*/
|
|
||||||
m_lua->set_function(ScriptReserved_GetCameraByName, &GameScript::GetByName<GameScriptCameraInfo, ScriptReserved_CameraInfo>, this);
|
|
||||||
|
|
||||||
/***
|
|
||||||
Get a SinkInfo by its name.
|
|
||||||
@function GetSinkByName
|
|
||||||
@tparam string name the unique name of the sink as set in, or generated by, Tomb Editor
|
|
||||||
@treturn SinkInfo a non-owning SinkInfo referencing the sink.
|
|
||||||
*/
|
|
||||||
m_lua->set_function(ScriptReserved_GetSinkByName, &GameScript::GetByName<GameScriptSinkInfo, ScriptReserved_SinkInfo>, this);
|
|
||||||
|
|
||||||
/***
|
|
||||||
Get a SoundSourceInfo by its name.
|
|
||||||
@function GetSoundSourceByName
|
|
||||||
@tparam string name the unique name of the sink as set in, or generated by, Tomb Editor
|
|
||||||
@treturn SoundSourceInfo a non-owning SoundSourceInfo referencing the sink.
|
|
||||||
*/
|
|
||||||
m_lua->set_function(ScriptReserved_GetSoundSourceByName, &GameScript::GetByName<GameScriptSoundSourceInfo, ScriptReserved_SoundSourceInfo>, this);
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
Show some text on-screen.
|
Show some text on-screen.
|
||||||
|
@ -113,41 +74,6 @@ with a call to @{ShowString}, or this function will have no effect.
|
||||||
|
|
||||||
MakeSpecialTable(m_lua, ScriptReserved_GameVars, &LuaVariables::GetVariable, &LuaVariables::SetVariable, &m_globals);
|
MakeSpecialTable(m_lua, ScriptReserved_GameVars, &LuaVariables::GetVariable, &LuaVariables::SetVariable, &m_globals);
|
||||||
|
|
||||||
GameScriptItemInfo::Register(m_lua);
|
|
||||||
GameScriptItemInfo::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptMeshInfo::Register(m_lua);
|
|
||||||
GameScriptMeshInfo::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptCameraInfo::Register(m_lua);
|
|
||||||
GameScriptCameraInfo::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptSinkInfo::Register(m_lua);
|
|
||||||
GameScriptSinkInfo::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptAIObject::Register(m_lua);
|
|
||||||
GameScriptAIObject::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptSoundSourceInfo::Register(m_lua);
|
|
||||||
GameScriptSoundSourceInfo::SetNameCallbacks(
|
|
||||||
[this](auto && ... param) { return AddName(std::forward<decltype(param)>(param)...); },
|
|
||||||
[this](auto && ... param) { return RemoveName(std::forward<decltype(param)>(param)...); }
|
|
||||||
);
|
|
||||||
|
|
||||||
GameScriptDisplayString::Register(m_lua);
|
GameScriptDisplayString::Register(m_lua);
|
||||||
GameScriptDisplayString::SetCallbacks(
|
GameScriptDisplayString::SetCallbacks(
|
||||||
|
@ -230,7 +156,6 @@ void GameScript::SetCallbackDrawString(CallbackDrawString cb)
|
||||||
|
|
||||||
void GameScript::FreeLevelScripts()
|
void GameScript::FreeLevelScripts()
|
||||||
{
|
{
|
||||||
m_nameMap.clear();
|
|
||||||
m_levelFuncs.clear();
|
m_levelFuncs.clear();
|
||||||
m_locals = LuaVariables{};
|
m_locals = LuaVariables{};
|
||||||
ResetLevelTables();
|
ResetLevelTables();
|
||||||
|
@ -343,10 +268,6 @@ std::unique_ptr<R> GetByName(std::string const & type, std::string const & name,
|
||||||
return std::make_unique<R>(map.at(name), false);
|
return std::make_unique<R>(map.at(name), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScript::AssignItemsAndLara()
|
|
||||||
{
|
|
||||||
m_lua->set("Lara", GameScriptItemInfo(Lara.itemNumber, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** Special objects
|
/*** Special objects
|
||||||
@section specialobjects
|
@section specialobjects
|
||||||
|
|
|
@ -8,12 +8,6 @@
|
||||||
#include "GameScriptColor.h"
|
#include "GameScriptColor.h"
|
||||||
#include "GameScriptPosition.h"
|
#include "GameScriptPosition.h"
|
||||||
#include "GameScriptRotation.h"
|
#include "GameScriptRotation.h"
|
||||||
#include "GameScriptItemInfo.h"
|
|
||||||
#include "Entity/Static/GameScriptMeshInfo.h"
|
|
||||||
#include "GameScriptSinkInfo.h"
|
|
||||||
#include "GameScriptAIObject.h"
|
|
||||||
#include "GameScriptSoundSourceInfo.h"
|
|
||||||
#include "GameScriptCameraInfo.h"
|
|
||||||
#include "GameScriptDisplayString.h"
|
#include "GameScriptDisplayString.h"
|
||||||
|
|
||||||
struct LuaFunction {
|
struct LuaFunction {
|
||||||
|
@ -57,8 +51,6 @@ private:
|
||||||
LuaVariables m_globals{};
|
LuaVariables m_globals{};
|
||||||
LuaVariables m_locals{};
|
LuaVariables m_locals{};
|
||||||
DisplayStringMap m_userDisplayStrings{};
|
DisplayStringMap m_userDisplayStrings{};
|
||||||
std::unordered_map<std::string, VarMapVal> m_nameMap{};
|
|
||||||
std::unordered_map<std::string, short> m_itemsMapName{};
|
|
||||||
std::unordered_map<std::string, sol::protected_function> m_levelFuncs{};
|
std::unordered_map<std::string, sol::protected_function> m_levelFuncs{};
|
||||||
sol::protected_function m_onStart{};
|
sol::protected_function m_onStart{};
|
||||||
sol::protected_function m_onLoad{};
|
sol::protected_function m_onLoad{};
|
||||||
|
@ -82,30 +74,10 @@ std::optional<std::reference_wrapper<UserDisplayString>> GetDisplayString(Displa
|
||||||
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj);
|
bool SetLevelFunc(sol::table tab, std::string const& luaName, sol::object obj);
|
||||||
sol::protected_function GetLevelFunc(sol::table tab, std::string const& luaName);
|
sol::protected_function GetLevelFunc(sol::table tab, std::string const& luaName);
|
||||||
|
|
||||||
void AssignItemsAndLara() override;
|
|
||||||
|
|
||||||
|
|
||||||
void ExecuteScriptFile(const std::string& luaFilename) override;
|
void ExecuteScriptFile(const std::string& luaFilename) override;
|
||||||
void ExecuteFunction(std::string const & name) override;
|
void ExecuteFunction(std::string const & name) override;
|
||||||
void MakeItemInvisible(short id);
|
void MakeItemInvisible(short id);
|
||||||
|
|
||||||
template <typename R, char const* S>
|
|
||||||
std::unique_ptr<R> GetByName(std::string const& name)
|
|
||||||
{
|
|
||||||
ScriptAssertF(m_nameMap.find(name) != m_nameMap.end(), "{} name not found: {}", S, name);
|
|
||||||
return std::make_unique<R>(std::get<R::IdentifierType>(m_nameMap.at(name)), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AddName(std::string const& key, VarMapVal val) override
|
|
||||||
{
|
|
||||||
auto p = std::pair<std::string const&, VarMapVal>{ key, val };
|
|
||||||
return m_nameMap.insert(p).second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RemoveName(std::string const& key)
|
|
||||||
{
|
|
||||||
return m_nameMap.erase(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ScriptInterfaceState.h"
|
#include "ScriptInterfaceState.h"
|
||||||
#include "GameLogicScript.h"
|
#include "GameLogicScript.h"
|
||||||
#include "GameFlowScript.h"
|
#include "GameFlowScript.h"
|
||||||
|
#include "Entity/Entity.h"
|
||||||
|
|
||||||
sol::state g_solState;
|
sol::state g_solState;
|
||||||
|
|
||||||
|
@ -20,8 +21,14 @@ ScriptInterfaceFlow* ScriptInterfaceState::CreateFlow()
|
||||||
return new GameFlow(&g_solState);
|
return new GameFlow(&g_solState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScriptInterfaceEntity* CreateEntities()
|
||||||
|
{
|
||||||
|
return new GameEntities(&g_solState);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptInterfaceState::Init()
|
void ScriptInterfaceState::Init()
|
||||||
{
|
{
|
||||||
g_solState.open_libraries(sol::lib::base, sol::lib::math);
|
g_solState.open_libraries(sol::lib::base, sol::lib::math);
|
||||||
g_solState.set_exception_handler(lua_exception_handler);
|
g_solState.set_exception_handler(lua_exception_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "Scripting/ScriptInterfaceFlow.h"
|
#include "Scripting/ScriptInterfaceFlow.h"
|
||||||
#include "Scripting/ScriptInterfaceGame.h"
|
#include "Scripting/ScriptInterfaceGame.h"
|
||||||
#include "Scripting/ScriptInterfaceLevel.h"
|
#include "Scripting/ScriptInterfaceLevel.h"
|
||||||
|
#include "Scripting/Entity/ScriptInterfaceEntity.h"
|
||||||
#include "Sound/sound.h"
|
#include "Sound/sound.h"
|
||||||
#include "Specific/setup.h"
|
#include "Specific/setup.h"
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ void LoadItems()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
item->luaName = std::string(buffer, buffer + numBytes);
|
item->luaName = std::string(buffer, buffer + numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(item->luaName, i);
|
g_GameScriptEntities->AddName(item->luaName, i);
|
||||||
|
|
||||||
memcpy(&item->startPos, &item->pos, sizeof(PHD_3DPOS));
|
memcpy(&item->startPos, &item->pos, sizeof(PHD_3DPOS));
|
||||||
}
|
}
|
||||||
|
@ -374,7 +375,7 @@ void LoadCameras()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
camera.luaName = std::string(buffer, buffer + numBytes);
|
camera.luaName = std::string(buffer, buffer + numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(camera.luaName, camera);
|
g_GameScriptEntities->AddName(camera.luaName, camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberSpotcams = ReadInt32();
|
NumberSpotcams = ReadInt32();
|
||||||
|
@ -402,7 +403,7 @@ void LoadCameras()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
sink.luaName = std::string(buffer, buffer+numBytes);
|
sink.luaName = std::string(buffer, buffer+numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(sink.luaName, sink);
|
g_GameScriptEntities->AddName(sink.luaName, sink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,7 +741,7 @@ void ReadRooms()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
mesh.luaName = std::string(buffer, buffer + numBytes);
|
mesh.luaName = std::string(buffer, buffer + numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(mesh.luaName, mesh);
|
g_GameScriptEntities->AddName(mesh.luaName, mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
int numTriggerVolumes = ReadInt32();
|
int numTriggerVolumes = ReadInt32();
|
||||||
|
@ -881,7 +882,7 @@ void LoadSoundSources()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
source.luaName = std::string(buffer, buffer+numBytes);
|
source.luaName = std::string(buffer, buffer+numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(source.luaName, source);
|
g_GameScriptEntities->AddName(source.luaName, source);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +964,7 @@ void LoadAIObjects()
|
||||||
ReadBytes(buffer, numBytes);
|
ReadBytes(buffer, numBytes);
|
||||||
obj.luaName = std::string(buffer, buffer+numBytes);
|
obj.luaName = std::string(buffer, buffer+numBytes);
|
||||||
|
|
||||||
g_GameScript->AddName(obj.luaName, obj);
|
g_GameScriptEntities->AddName(obj.luaName, obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1096,7 +1097,7 @@ unsigned CALLBACK LoadLevel(void* data)
|
||||||
GetCarriedItems();
|
GetCarriedItems();
|
||||||
GetAIPickups();
|
GetAIPickups();
|
||||||
Lara.Vehicle = -1;
|
Lara.Vehicle = -1;
|
||||||
g_GameScript->AssignItemsAndLara();
|
g_GameScriptEntities->AssignLara();
|
||||||
|
|
||||||
// Level loaded
|
// Level loaded
|
||||||
IsLevelLoading = false;
|
IsLevelLoading = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue