mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-29 08:17:59 +03:00
First commit of assetDir command line option.
This commit is contained in:
parent
c4202101b7
commit
a2d985b4c5
12 changed files with 77 additions and 28 deletions
|
@ -51,20 +51,21 @@ GameStats Statistics;
|
||||||
SaveGameHeader SavegameInfos[SAVEGAME_MAX];
|
SaveGameHeader SavegameInfos[SAVEGAME_MAX];
|
||||||
|
|
||||||
FileStream* SaveGame::m_stream;
|
FileStream* SaveGame::m_stream;
|
||||||
|
std::string SaveGame::m_fullSaveDir;
|
||||||
int SaveGame::LastSaveGame;
|
int SaveGame::LastSaveGame;
|
||||||
|
|
||||||
void LoadSavegameInfos()
|
void SaveGame::LoadSavegameInfos()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SAVEGAME_MAX; i++)
|
for (int i = 0; i < SAVEGAME_MAX; i++)
|
||||||
SavegameInfos[i].Present = false;
|
SavegameInfos[i].Present = false;
|
||||||
|
|
||||||
if (!std::filesystem::exists(SAVEGAME_PATH))
|
if (!std::filesystem::exists(m_fullSaveDir))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// try to load the savegame
|
// try to load the savegame
|
||||||
for (int i = 0; i < SAVEGAME_MAX; i++)
|
for (int i = 0; i < SAVEGAME_MAX; i++)
|
||||||
{
|
{
|
||||||
auto fileName = SAVEGAME_PATH + "savegame." + std::to_string(i);
|
auto fileName = m_fullSaveDir + "savegame." + std::to_string(i);
|
||||||
auto savegamePtr = fopen(fileName.c_str(), "rb");
|
auto savegamePtr = fopen(fileName.c_str(), "rb");
|
||||||
|
|
||||||
if (savegamePtr == NULL)
|
if (savegamePtr == NULL)
|
||||||
|
@ -169,7 +170,7 @@ Vector4 ToVector4(const Save::Vector4* vec)
|
||||||
|
|
||||||
bool SaveGame::Save(int slot)
|
bool SaveGame::Save(int slot)
|
||||||
{
|
{
|
||||||
auto fileName = std::string(SAVEGAME_PATH) + "savegame." + std::to_string(slot);
|
auto fileName = m_fullSaveDir + "savegame." + std::to_string(slot);
|
||||||
TENLog("Saving to savegame: " + fileName, LogLevel::Info);
|
TENLog("Saving to savegame: " + fileName, LogLevel::Info);
|
||||||
|
|
||||||
ItemInfo itemToSerialize{};
|
ItemInfo itemToSerialize{};
|
||||||
|
@ -1315,8 +1316,8 @@ bool SaveGame::Save(int slot)
|
||||||
auto bufferToSerialize = fbb.GetBufferPointer();
|
auto bufferToSerialize = fbb.GetBufferPointer();
|
||||||
auto bufferSize = fbb.GetSize();
|
auto bufferSize = fbb.GetSize();
|
||||||
|
|
||||||
if (!std::filesystem::exists(SAVEGAME_PATH))
|
if (!std::filesystem::exists(m_fullSaveDir))
|
||||||
std::filesystem::create_directory(SAVEGAME_PATH);
|
std::filesystem::create_directory(m_fullSaveDir);
|
||||||
|
|
||||||
std::ofstream fileOut{};
|
std::ofstream fileOut{};
|
||||||
fileOut.open(fileName, std::ios_base::binary | std::ios_base::out);
|
fileOut.open(fileName, std::ios_base::binary | std::ios_base::out);
|
||||||
|
@ -1326,9 +1327,14 @@ bool SaveGame::Save(int slot)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SaveGame::SetSaveDirLocation(std::string_view dirLocation)
|
||||||
|
{
|
||||||
|
m_fullSaveDir = std::string{ dirLocation } + SAVEGAME_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
bool SaveGame::Load(int slot)
|
bool SaveGame::Load(int slot)
|
||||||
{
|
{
|
||||||
auto fileName = SAVEGAME_PATH + "savegame." + std::to_string(slot);
|
auto fileName = m_fullSaveDir + "savegame." + std::to_string(slot);
|
||||||
TENLog("Loading from savegame: " + fileName, LogLevel::Info);
|
TENLog("Loading from savegame: " + fileName, LogLevel::Info);
|
||||||
|
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
|
@ -2158,7 +2164,7 @@ bool SaveGame::Load(int slot)
|
||||||
|
|
||||||
bool SaveGame::LoadHeader(int slot, SaveGameHeader* header)
|
bool SaveGame::LoadHeader(int slot, SaveGameHeader* header)
|
||||||
{
|
{
|
||||||
auto fileName = SAVEGAME_PATH + "savegame." + std::to_string(slot);
|
auto fileName = m_fullSaveDir + "savegame." + std::to_string(slot);
|
||||||
|
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
file.open(fileName, std::ios_base::app | std::ios_base::binary);
|
file.open(fileName, std::ios_base::app | std::ios_base::binary);
|
||||||
|
|
|
@ -45,13 +45,14 @@ class SaveGame
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static FileStream* m_stream;
|
static FileStream* m_stream;
|
||||||
|
static std::string m_fullSaveDir;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static int LastSaveGame;
|
static int LastSaveGame;
|
||||||
|
static void SetSaveDirLocation(std::string_view dir);
|
||||||
|
|
||||||
static bool Load(int slot);
|
static bool Load(int slot);
|
||||||
static bool LoadHeader(int slot, SaveGameHeader* header);
|
static bool LoadHeader(int slot, SaveGameHeader* header);
|
||||||
static bool Save(int slot);
|
static bool Save(int slot);
|
||||||
|
static void LoadSavegameInfos();
|
||||||
};
|
};
|
||||||
|
|
||||||
void LoadSavegameInfos();
|
|
||||||
|
|
|
@ -402,7 +402,7 @@ namespace TEN::Renderer
|
||||||
int y = MenuVerticalLineSpacing;
|
int y = MenuVerticalLineSpacing;
|
||||||
short selection = g_Gui.GetLoadSaveSelection();
|
short selection = g_Gui.GetLoadSaveSelection();
|
||||||
char stringBuffer[255];
|
char stringBuffer[255];
|
||||||
LoadSavegameInfos();
|
SaveGame::LoadSavegameInfos();
|
||||||
|
|
||||||
// Title
|
// Title
|
||||||
AddString(MenuCenterEntry, MenuVerticalNarrowLineSpacing, Str_LoadSave(g_Gui.GetInventoryMode() == InventoryMode::Save),
|
AddString(MenuCenterEntry, MenuVerticalNarrowLineSpacing, Str_LoadSave(g_Gui.GetInventoryMode() == InventoryMode::Save),
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
|
|
||||||
virtual ~ScriptInterfaceFlowHandler() = default;
|
virtual ~ScriptInterfaceFlowHandler() = default;
|
||||||
virtual void LoadFlowScript() = 0;
|
virtual void LoadFlowScript() = 0;
|
||||||
|
virtual void SetAssetDir(std::string_view assetDir) = 0;
|
||||||
|
virtual std::string_view GetAssetDir() = 0;
|
||||||
virtual int GetNumLevels() const = 0;
|
virtual int GetNumLevels() const = 0;
|
||||||
virtual char const* GetString(const char* id) const = 0;
|
virtual char const* GetString(const char* id) const = 0;
|
||||||
virtual bool IsFlyCheatEnabled() const = 0;
|
virtual bool IsFlyCheatEnabled() const = 0;
|
||||||
|
|
|
@ -11,5 +11,5 @@ public:
|
||||||
static ScriptInterfaceFlowHandler* CreateFlow();
|
static ScriptInterfaceFlowHandler* CreateFlow();
|
||||||
static ScriptInterfaceObjectsHandler* CreateObjectsHandler();
|
static ScriptInterfaceObjectsHandler* CreateObjectsHandler();
|
||||||
static ScriptInterfaceStringsHandler* CreateStringsHandler();
|
static ScriptInterfaceStringsHandler* CreateStringsHandler();
|
||||||
static void ScriptInterfaceState::Init();
|
static void ScriptInterfaceState::Init(std::string_view assetsDir);
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,10 +37,11 @@ ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
||||||
return new StringsHandler(&s_solState, s_rootTable);
|
return new StringsHandler(&s_solState, s_rootTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptInterfaceState::Init()
|
void ScriptInterfaceState::Init(std::string_view assetsDir)
|
||||||
{
|
{
|
||||||
s_solState.open_libraries(sol::lib::base, sol::lib::math, sol::lib::package, sol::lib::coroutine, sol::lib::table, sol::lib::string, sol::lib::debug);
|
s_solState.open_libraries(sol::lib::base, sol::lib::math, sol::lib::package, sol::lib::coroutine, sol::lib::table, sol::lib::string, sol::lib::debug);
|
||||||
s_solState.script("package.path=\"Scripts/?.lua\"");
|
|
||||||
|
s_solState.script("package.path=\"" + std::string{assetsDir} + "Scripts/?.lua\"");
|
||||||
s_solState.set_exception_handler(lua_exception_handler);
|
s_solState.set_exception_handler(lua_exception_handler);
|
||||||
|
|
||||||
s_rootTable = sol::table{ s_solState.lua_state(), sol::create };
|
s_rootTable = sol::table{ s_solState.lua_state(), sol::create };
|
||||||
|
|
|
@ -215,6 +215,16 @@ FlowHandler::~FlowHandler()
|
||||||
delete lev;
|
delete lev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view FlowHandler::GetAssetDir()
|
||||||
|
{
|
||||||
|
return m_assetDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlowHandler::SetAssetDir(std::string_view assetDir)
|
||||||
|
{
|
||||||
|
m_assetDir = assetDir;
|
||||||
|
}
|
||||||
|
|
||||||
void FlowHandler::SetLanguageNames(sol::as_table_t<std::vector<std::string>> && src)
|
void FlowHandler::SetLanguageNames(sol::as_table_t<std::vector<std::string>> && src)
|
||||||
{
|
{
|
||||||
m_languageNames = std::move(src);
|
m_languageNames = std::move(src);
|
||||||
|
@ -257,9 +267,9 @@ void FlowHandler::SetTotalSecretCount(int secretsNumber)
|
||||||
|
|
||||||
void FlowHandler::LoadFlowScript()
|
void FlowHandler::LoadFlowScript()
|
||||||
{
|
{
|
||||||
m_handler.ExecuteScript("Scripts/Gameflow.lua");
|
m_handler.ExecuteScript(m_assetDir + "Scripts/Gameflow.lua");
|
||||||
m_handler.ExecuteScript("Scripts/Strings.lua");
|
m_handler.ExecuteScript(m_assetDir + "Scripts/Strings.lua");
|
||||||
m_handler.ExecuteScript("Scripts/Settings.lua");
|
m_handler.ExecuteScript(m_assetDir + "Scripts/Settings.lua");
|
||||||
|
|
||||||
SetScriptErrorMode(GetSettings()->ErrorMode);
|
SetScriptErrorMode(GetSettings()->ErrorMode);
|
||||||
|
|
||||||
|
@ -316,7 +326,7 @@ int FlowHandler::GetLevelNumber(std::string const& fileName)
|
||||||
for (int i = 0; i < Levels.size(); i++)
|
for (int i = 0; i < Levels.size(); i++)
|
||||||
{
|
{
|
||||||
auto level = TEN::Utils::ToLower(this->GetLevel(i)->FileName);
|
auto level = TEN::Utils::ToLower(this->GetLevel(i)->FileName);
|
||||||
if (level == lcFilename && std::filesystem::exists(fileName))
|
if (level == lcFilename && std::filesystem::exists(std::string{ GetAssetDir() } + fileName))
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "LuaHandler.h"
|
#include "LuaHandler.h"
|
||||||
#include "Logic/LogicHandler.h"
|
#include "Logic/LogicHandler.h"
|
||||||
#include "Color/Color.h"
|
#include "Color/Color.h"
|
||||||
|
#include <string_view>
|
||||||
#include "Flow/Level/FlowLevel.h"
|
#include "Flow/Level/FlowLevel.h"
|
||||||
#include "Settings/Settings.h"
|
#include "Settings/Settings.h"
|
||||||
#include "Flow/Animations/Animations.h"
|
#include "Flow/Animations/Animations.h"
|
||||||
|
@ -19,6 +20,8 @@ private:
|
||||||
|
|
||||||
std::map<short, short> m_itemsMap;
|
std::map<short, short> m_itemsMap;
|
||||||
|
|
||||||
|
std::string m_assetDir;
|
||||||
|
|
||||||
LuaHandler m_handler;
|
LuaHandler m_handler;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -38,6 +41,8 @@ public:
|
||||||
FlowHandler(sol::state* lua, sol::table & parent);
|
FlowHandler(sol::state* lua, sol::table & parent);
|
||||||
~FlowHandler() override;
|
~FlowHandler() override;
|
||||||
|
|
||||||
|
std::string_view GetAssetDir() override;
|
||||||
|
void SetAssetDir(std::string_view assetDir) override;
|
||||||
void AddLevel(Level const& level);
|
void AddLevel(Level const& level);
|
||||||
void LoadFlowScript();
|
void LoadFlowScript();
|
||||||
char const* GetString(const char* id) const;
|
char const* GetString(const char* id) const;
|
||||||
|
|
|
@ -37,9 +37,15 @@ int SecretSoundIndex = 5;
|
||||||
constexpr int LegacyLoopingTrackMin = 98;
|
constexpr int LegacyLoopingTrackMin = 98;
|
||||||
constexpr int LegacyLoopingTrackMax = 111;
|
constexpr int LegacyLoopingTrackMax = 111;
|
||||||
|
|
||||||
|
static std::string AudioFullDir;
|
||||||
static int GlobalMusicVolume;
|
static int GlobalMusicVolume;
|
||||||
static int GlobalFXVolume;
|
static int GlobalFXVolume;
|
||||||
|
|
||||||
|
void SetAudioDirLocation(std::string_view dirLocation)
|
||||||
|
{
|
||||||
|
AudioFullDir = std::string{ dirLocation } + TRACKS_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
void SetVolumeMusic(int vol)
|
void SetVolumeMusic(int vol)
|
||||||
{
|
{
|
||||||
GlobalMusicVolume = vol;
|
GlobalMusicVolume = vol;
|
||||||
|
@ -338,7 +344,7 @@ void FreeSamples()
|
||||||
|
|
||||||
void EnumerateLegacyTracks()
|
void EnumerateLegacyTracks()
|
||||||
{
|
{
|
||||||
auto dir = std::filesystem::path(TRACKS_PATH);
|
auto dir = std::filesystem::path{ AudioFullDir };
|
||||||
if (std::filesystem::exists(dir))
|
if (std::filesystem::exists(dir))
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
@ -408,13 +414,13 @@ void PlaySoundTrack(std::string track, SoundTrackType mode, QWORD position)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fullTrackName = TRACKS_PATH + track + ".ogg";
|
auto fullTrackName = AudioFullDir + track + ".ogg";
|
||||||
if (!std::filesystem::exists(fullTrackName))
|
if (!std::filesystem::exists(fullTrackName))
|
||||||
{
|
{
|
||||||
fullTrackName = TRACKS_PATH + track + ".mp3";
|
fullTrackName = AudioFullDir + track + ".mp3";
|
||||||
if (!std::filesystem::exists(fullTrackName))
|
if (!std::filesystem::exists(fullTrackName))
|
||||||
{
|
{
|
||||||
fullTrackName = TRACKS_PATH + track + ".wav";
|
fullTrackName = AudioFullDir + track + ".wav";
|
||||||
if (!std::filesystem::exists(fullTrackName))
|
if (!std::filesystem::exists(fullTrackName))
|
||||||
{
|
{
|
||||||
TENLog("No soundtrack files with name '" + track + "' were found", LogLevel::Warning);
|
TENLog("No soundtrack files with name '" + track + "' were found", LogLevel::Warning);
|
||||||
|
|
|
@ -144,6 +144,7 @@ extern std::map<std::string, int> SoundTrackMap;
|
||||||
extern std::unordered_map<int, SoundTrackInfo> SoundTracks;
|
extern std::unordered_map<int, SoundTrackInfo> SoundTracks;
|
||||||
extern int SecretSoundIndex;
|
extern int SecretSoundIndex;
|
||||||
|
|
||||||
|
void SetAudioDirLocation(std::string_view dirLocation);
|
||||||
bool SoundEffect(int effectID, Pose* position, SoundEnvironment condition = SoundEnvironment::Land, float pitchMultiplier = 1.0f, float gainMultiplier = 1.0f);
|
bool SoundEffect(int effectID, Pose* position, SoundEnvironment condition = SoundEnvironment::Land, float pitchMultiplier = 1.0f, float gainMultiplier = 1.0f);
|
||||||
void StopSoundEffect(short effectID);
|
void StopSoundEffect(short effectID);
|
||||||
bool LoadSample(char *buffer, int compSize, int uncompSize, int currentIndex);
|
bool LoadSample(char *buffer, int compSize, int uncompSize, int currentIndex);
|
||||||
|
|
|
@ -1031,23 +1031,26 @@ unsigned int _stdcall LoadLevel(void* data)
|
||||||
|
|
||||||
auto* level = g_GameFlow->GetLevel(levelIndex);
|
auto* level = g_GameFlow->GetLevel(levelIndex);
|
||||||
|
|
||||||
TENLog("Loading level file: " + level->FileName, LogLevel::Info);
|
auto assetDir = std::string{ g_GameFlow->GetAssetDir() };
|
||||||
|
auto levelPath = assetDir + level->FileName;
|
||||||
|
TENLog("Loading level file: " + levelPath, LogLevel::Info);
|
||||||
|
|
||||||
LevelDataPtr = nullptr;
|
LevelDataPtr = nullptr;
|
||||||
FILE* filePtr = nullptr;
|
FILE* filePtr = nullptr;
|
||||||
char* dataPtr = nullptr;
|
char* dataPtr = nullptr;
|
||||||
|
|
||||||
g_Renderer.SetLoadingScreen(TEN::Utils::ToWString(level->LoadScreenFileName.c_str()));
|
auto loadingScreenPath = TEN::Utils::ToWString(assetDir + level->LoadScreenFileName);
|
||||||
|
g_Renderer.SetLoadingScreen(loadingScreenPath);
|
||||||
|
|
||||||
SetScreenFadeIn(FADE_SCREEN_SPEED);
|
SetScreenFadeIn(FADE_SCREEN_SPEED);
|
||||||
g_Renderer.UpdateProgress(0);
|
g_Renderer.UpdateProgress(0);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
filePtr = FileOpen(level->FileName.c_str());
|
filePtr = FileOpen(levelPath.c_str());
|
||||||
|
|
||||||
if (!filePtr)
|
if (!filePtr)
|
||||||
throw std::exception((std::string("Unable to read level file: ") + level->FileName).c_str());
|
throw std::exception{ (std::string{ "Unable to read level file: " } + levelPath).c_str() };
|
||||||
|
|
||||||
char header[4];
|
char header[4];
|
||||||
unsigned char version[4];
|
unsigned char version[4];
|
||||||
|
|
|
@ -245,6 +245,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
LPWSTR* argv;
|
LPWSTR* argv;
|
||||||
int argc;
|
int argc;
|
||||||
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||||
|
std::string assetDir{};
|
||||||
|
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
for (int i = 1; i < argc; i++)
|
for (int i = 1; i < argc; i++)
|
||||||
|
@ -265,6 +266,15 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
{
|
{
|
||||||
SystemNameHash = std::stoul(std::wstring(argv[i + 1]));
|
SystemNameHash = std::stoul(std::wstring(argv[i + 1]));
|
||||||
}
|
}
|
||||||
|
else if (ArgEquals(argv[i], "assetdir") && argc > (i + 1))
|
||||||
|
{
|
||||||
|
assetDir = TEN::Utils::ToString(argv[i + 1]);
|
||||||
|
//replace all backslashes with forward slashes:
|
||||||
|
std::replace(assetDir.begin(), assetDir.end(), '\\', '/');
|
||||||
|
//add a trailing slash if it's not there:
|
||||||
|
if (assetDir.back() != '/')
|
||||||
|
assetDir += '/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LocalFree(argv);
|
LocalFree(argv);
|
||||||
|
|
||||||
|
@ -288,11 +298,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
std::to_string(ver[2]));
|
std::to_string(ver[2]));
|
||||||
TENLog(windowName, LogLevel::Info);
|
TENLog(windowName, LogLevel::Info);
|
||||||
|
|
||||||
|
SaveGame::SetSaveDirLocation(assetDir);
|
||||||
|
SetAudioDirLocation(assetDir);
|
||||||
|
|
||||||
// Collect numbered tracks
|
// Collect numbered tracks
|
||||||
EnumerateLegacyTracks();
|
EnumerateLegacyTracks();
|
||||||
|
|
||||||
// Initialize the new scripting system
|
// Initialize the scripting system
|
||||||
ScriptInterfaceState::Init();
|
ScriptInterfaceState::Init(assetDir);
|
||||||
|
|
||||||
// Initialize scripting
|
// Initialize scripting
|
||||||
try
|
try
|
||||||
|
@ -314,6 +327,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
//should be moved to LogicHandler or vice versa to make this stuff
|
//should be moved to LogicHandler or vice versa to make this stuff
|
||||||
//less fragile (squidshire, 16/09/22)
|
//less fragile (squidshire, 16/09/22)
|
||||||
g_GameScript->ShortenTENCalls();
|
g_GameScript->ShortenTENCalls();
|
||||||
|
g_GameFlow->SetAssetDir(assetDir);
|
||||||
g_GameFlow->LoadFlowScript();
|
g_GameFlow->LoadFlowScript();
|
||||||
}
|
}
|
||||||
catch (TENScriptException const& e)
|
catch (TENScriptException const& e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue