mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-09 03:58:19 +03:00
Take vanilla/TRNG stuff out of Tracks.lua (which is now no longer needed) and partially replicate it in the C++ side of things.
This commit is contained in:
parent
4d8fbe279c
commit
14f0b710fb
6 changed files with 44 additions and 35 deletions
|
@ -101,13 +101,14 @@ struct SampleInfo
|
||||||
|
|
||||||
struct SoundTrackInfo
|
struct SoundTrackInfo
|
||||||
{
|
{
|
||||||
std::string Name;
|
std::string Name{};
|
||||||
SOUNDTRACK_PLAYTYPE Mode;
|
SOUNDTRACK_PLAYTYPE Mode{ SOUNDTRACK_PLAYTYPE::OneShot };
|
||||||
int Mask;
|
int Mask{ 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
extern std::map<std::string, int> SoundTrackMap;
|
extern std::map<std::string, int> SoundTrackMap;
|
||||||
extern std::vector<SoundTrackInfo> SoundTracks;
|
extern std::unordered_map<int, SoundTrackInfo> SoundTracks;
|
||||||
|
extern int SecretSoundIndex;
|
||||||
|
|
||||||
long SoundEffect(int effectID, PHD_3DPOS* position, int env_flags, float pitchMultiplier = 1.0f, float gainMultiplier = 1.0f);
|
long SoundEffect(int effectID, PHD_3DPOS* position, int env_flags, float pitchMultiplier = 1.0f, float gainMultiplier = 1.0f);
|
||||||
void StopSoundEffect(short effectID);
|
void StopSoundEffect(short effectID);
|
||||||
|
@ -124,6 +125,7 @@ void PlaySecretTrack();
|
||||||
void SayNo();
|
void SayNo();
|
||||||
void PlaySoundSources();
|
void PlaySoundSources();
|
||||||
int GetShatterSound(int shatterID);
|
int GetShatterSound(int shatterID);
|
||||||
|
void EnumerateLegacyTracks();
|
||||||
|
|
||||||
std::pair<std::string, QWORD> GetSoundTrackNameAndPosition(SOUNDTRACK_PLAYTYPE type);
|
std::pair<std::string, QWORD> GetSoundTrackNameAndPosition(SOUNDTRACK_PLAYTYPE type);
|
||||||
|
|
||||||
|
|
|
@ -85,17 +85,6 @@ settings.lua shouldn't be bundled with any finished levels/games.
|
||||||
*/
|
*/
|
||||||
m_lua->set_function("SetAnimations", &GameFlow::SetAnimations, this);
|
m_lua->set_function("SetAnimations", &GameFlow::SetAnimations, this);
|
||||||
|
|
||||||
/*** tracks.lua.
|
|
||||||
__TODO CONFIRM PROPER BEHAVIOUR__
|
|
||||||
@section trackslua
|
|
||||||
*/
|
|
||||||
/***
|
|
||||||
@function SetAudioTracks
|
|
||||||
@tparam table table array-style table with @{AudioTrack} objects
|
|
||||||
*/
|
|
||||||
//TODO confirm proper behaviour
|
|
||||||
m_lua->set_function("SetAudioTracks", &GameFlow::SetAudioTracks, this);
|
|
||||||
|
|
||||||
/*** strings.lua.
|
/*** strings.lua.
|
||||||
These functions used in strings.lua, which is generated by TombIDE.
|
These functions used in strings.lua, which is generated by TombIDE.
|
||||||
You will not need to call them manually.
|
You will not need to call them manually.
|
||||||
|
@ -181,24 +170,9 @@ void GameFlow::SetGameFarView(byte val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameFlow::SetAudioTracks(sol::as_table_t<std::vector<GameScriptAudioTrack>>&& src)
|
|
||||||
{
|
|
||||||
std::vector<GameScriptAudioTrack> tracks = std::move(src);
|
|
||||||
SoundTracks.clear();
|
|
||||||
|
|
||||||
for (auto t : tracks) {
|
|
||||||
SoundTrackInfo track;
|
|
||||||
track.Name = t.trackName;
|
|
||||||
track.Mask = 0;
|
|
||||||
track.Mode = t.looped ? SOUNDTRACK_PLAYTYPE::BGM : SOUNDTRACK_PLAYTYPE::OneShot;
|
|
||||||
SoundTracks.push_back(track);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GameFlow::LoadGameFlowScript()
|
void GameFlow::LoadGameFlowScript()
|
||||||
{
|
{
|
||||||
ExecuteScript("Scripts/Enums.lua");
|
ExecuteScript("Scripts/Enums.lua");
|
||||||
ExecuteScript("Scripts/Tracks.lua");
|
|
||||||
ExecuteScript("Scripts/Gameflow.lua");
|
ExecuteScript("Scripts/Gameflow.lua");
|
||||||
ExecuteScript("Scripts/Strings.lua");
|
ExecuteScript("Scripts/Strings.lua");
|
||||||
ExecuteScript("Scripts/Settings.lua");
|
ExecuteScript("Scripts/Settings.lua");
|
||||||
|
|
|
@ -38,7 +38,6 @@ public:
|
||||||
~GameFlow();
|
~GameFlow();
|
||||||
|
|
||||||
void AddLevel(GameScriptLevel const& level);
|
void AddLevel(GameScriptLevel const& level);
|
||||||
void SetAudioTracks(sol::as_table_t<std::vector<GameScriptAudioTrack>>&& src);
|
|
||||||
void LoadGameFlowScript();
|
void LoadGameFlowScript();
|
||||||
char const * GetString(const char* id) const;
|
char const * GetString(const char* id) const;
|
||||||
void SetStrings(sol::nested<std::unordered_map<std::string, std::vector<std::string>>> && src);
|
void SetStrings(sol::nested<std::unordered_map<std::string, std::vector<std::string>>> && src);
|
||||||
|
|
|
@ -474,7 +474,7 @@ bool SaveGame::Save(int slot)
|
||||||
|
|
||||||
// Legacy soundtrack map
|
// Legacy soundtrack map
|
||||||
std::vector<int> soundTrackMap;
|
std::vector<int> soundTrackMap;
|
||||||
for (auto& track : SoundTracks) { soundTrackMap.push_back(track.Mask); }
|
for (auto& track : SoundTracks) { soundTrackMap.push_back(track.second.Mask); }
|
||||||
auto soundtrackMapOffset = fbb.CreateVector(soundTrackMap);
|
auto soundtrackMapOffset = fbb.CreateVector(soundTrackMap);
|
||||||
|
|
||||||
// Flipmaps
|
// Flipmaps
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "Sound/sound.h"
|
#include "Sound/sound.h"
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <regex>
|
||||||
#include "Game/camera.h"
|
#include "Game/camera.h"
|
||||||
#include "Game/Lara/lara.h"
|
#include "Game/Lara/lara.h"
|
||||||
#include "Game/room.h"
|
#include "Game/room.h"
|
||||||
|
@ -29,7 +30,8 @@ const BASS_BFX_FREEVERB BASS_ReverbTypes[(int)REVERB_TYPE::Count] = // Reverb
|
||||||
const std::string TRACKS_PATH = "Audio\\";
|
const std::string TRACKS_PATH = "Audio\\";
|
||||||
|
|
||||||
std::map<std::string, int> SoundTrackMap;
|
std::map<std::string, int> SoundTrackMap;
|
||||||
std::vector<SoundTrackInfo> SoundTracks;
|
std::unordered_map<int, SoundTrackInfo> SoundTracks;
|
||||||
|
int SecretSoundIndex;
|
||||||
|
|
||||||
static int GlobalMusicVolume;
|
static int GlobalMusicVolume;
|
||||||
static int GlobalFXVolume;
|
static int GlobalFXVolume;
|
||||||
|
@ -310,6 +312,35 @@ void FreeSamples()
|
||||||
Sound_FreeSample(i);
|
Sound_FreeSample(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EnumerateLegacyTracks()
|
||||||
|
{
|
||||||
|
auto dir = std::filesystem::path(TRACKS_PATH);
|
||||||
|
// capture three-digit filenames, or those which start with three digits.
|
||||||
|
std::regex upToThreeDigits("\\\\((\\d{1,3})[^\\.]*)");
|
||||||
|
std::smatch result;
|
||||||
|
for (const auto& file : std::filesystem::directory_iterator{ dir })
|
||||||
|
{
|
||||||
|
std::string fileName = file.path().string();
|
||||||
|
auto bResult = std::regex_search(fileName, result, upToThreeDigits);
|
||||||
|
if (!result.empty())
|
||||||
|
{
|
||||||
|
// result[0] is the whole match including the leading backslash, so ignore it
|
||||||
|
// result[1] is the full file name, not including the extension
|
||||||
|
int index = std::stoi(result[2].str());
|
||||||
|
SoundTrackInfo s;
|
||||||
|
|
||||||
|
// TRLE default looping tracks
|
||||||
|
if (index >= 98 && index <= 111)
|
||||||
|
{
|
||||||
|
s.Mode = SOUNDTRACK_PLAYTYPE::BGM;
|
||||||
|
}
|
||||||
|
s.Name = result[1];
|
||||||
|
SoundTracks.insert(std::make_pair(index, s));
|
||||||
|
SecretSoundIndex = std::max(SecretSoundIndex, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PlaySoundTrack(std::string track, SOUNDTRACK_PLAYTYPE mode, QWORD position)
|
void PlaySoundTrack(std::string track, SOUNDTRACK_PLAYTYPE mode, QWORD position)
|
||||||
{
|
{
|
||||||
if (track.empty())
|
if (track.empty())
|
||||||
|
@ -456,7 +487,7 @@ void StopSoundTracks()
|
||||||
|
|
||||||
void ClearSoundTrackMasks()
|
void ClearSoundTrackMasks()
|
||||||
{
|
{
|
||||||
for (auto& track : SoundTracks) { track.Mask = 0; }
|
for (auto& track : SoundTracks) { track.second.Mask = 0; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns specified soundtrack type's stem name and playhead position.
|
// Returns specified soundtrack type's stem name and playhead position.
|
||||||
|
@ -801,7 +832,7 @@ void SayNo()
|
||||||
void PlaySecretTrack()
|
void PlaySecretTrack()
|
||||||
{
|
{
|
||||||
// Secret soundtrack should be always last one on a list.
|
// Secret soundtrack should be always last one on a list.
|
||||||
PlaySoundTrack(SoundTracks.back().Name, SOUNDTRACK_PLAYTYPE::OneShot);
|
PlaySoundTrack(SoundTracks.at(SecretSoundIndex).Name, SOUNDTRACK_PLAYTYPE::OneShot);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetShatterSound(int shatterID)
|
int GetShatterSound(int shatterID)
|
||||||
|
|
|
@ -157,6 +157,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||||
|
|
||||||
InitTENLog();
|
InitTENLog();
|
||||||
|
|
||||||
|
// Collect numbered tracks
|
||||||
|
EnumerateLegacyTracks();
|
||||||
|
|
||||||
// Initialise the new scripting system
|
// Initialise the new scripting system
|
||||||
ScriptInterfaceState::Init();
|
ScriptInterfaceState::Init();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue