metaforce/Runtime/MP1/MP1.hpp

355 lines
11 KiB
C++
Raw Normal View History

2018-10-06 20:42:33 -07:00
#pragma once
2015-08-26 17:23:46 -07:00
2016-04-15 13:42:40 -07:00
#define MP1_USE_BOO 0
2016-09-16 23:40:45 -07:00
#include "IMain.hpp"
2015-08-26 17:23:46 -07:00
#include "CTweaks.hpp"
#include "CPlayMovie.hpp"
#include "IOStreams.hpp"
2016-04-15 13:42:40 -07:00
#include "CBasics.hpp"
#include "CMemoryCardSys.hpp"
#include "CResFactory.hpp"
#include "CSimplePool.hpp"
#include "Character/CAssetFactory.hpp"
2016-04-16 16:48:29 -07:00
#include "World/CAi.hpp"
2016-04-15 13:42:40 -07:00
#include "CGameState.hpp"
#include "CInGameTweakManager.hpp"
#include "Particle/CElementGen.hpp"
#include "Character/CAnimData.hpp"
#include "Particle/CDecalManager.hpp"
#include "Particle/CGenDescription.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "Audio/CAudioSys.hpp"
#include "Input/CInputGenerator.hpp"
#include "GuiSys/CGuiSys.hpp"
#include "CIOWinManager.hpp"
#include "GuiSys/CSplashScreen.hpp"
#include "CMainFlow.hpp"
#include "GuiSys/CConsoleOutputWindow.hpp"
2016-09-13 22:54:09 -07:00
#include "GuiSys/CErrorOutputWindow.hpp"
2016-04-15 13:42:40 -07:00
#include "GuiSys/CTextParser.hpp"
#include "CAudioStateWin.hpp"
2016-04-15 13:42:40 -07:00
#include "GameGlobalObjects.hpp"
#include "CArchitectureQueue.hpp"
#include "CTimeProvider.hpp"
#include "GuiSys/CTextExecuteBuffer.hpp"
#include "DataSpec/DNAMP1/Tweaks/CTweakPlayer.hpp"
#include "DataSpec/DNAMP1/Tweaks/CTweakGame.hpp"
#include "World/CScriptMazeNode.hpp"
2018-01-15 08:00:20 -08:00
#include "hecl/Console.hpp"
2015-08-26 17:23:46 -07:00
struct DiscordUser;
2016-03-04 15:04:53 -08:00
namespace urde
2015-08-26 17:23:46 -07:00
{
2016-04-15 13:42:40 -07:00
class IFactory;
class IObjectStore;
2015-08-26 17:23:46 -07:00
namespace MP1
{
class CMain;
2016-04-15 13:42:40 -07:00
class CGameGlobalObjects
{
2016-12-29 22:37:01 -08:00
friend class CMain;
2017-10-28 00:08:48 -07:00
std::unique_ptr<CSimplePool> m_gameSimplePool;
std::unique_ptr<CResFactory> m_gameResFactory;
std::unique_ptr<CMemoryCardSys> x0_memoryCardSys;
IFactory* x4_resFactory;
CSimplePool* xcc_simplePool;
CCharacterFactoryBuilder xec_charFactoryBuilder;
CAiFuncMap x110_aiFuncMap;
2016-12-29 13:38:59 -08:00
std::unique_ptr<CGameState> x134_gameState;
2016-12-14 14:56:59 -08:00
TLockedToken<CStringTable> x13c_mainStringTable;
CInGameTweakManager x150_tweakManager;
2017-01-20 22:03:37 -08:00
std::unique_ptr<IRenderer> m_renderer;
2016-04-15 13:42:40 -07:00
void LoadStringTable()
{
2016-12-14 14:56:59 -08:00
x13c_mainStringTable = g_SimplePool->GetObj("STRG_Main");
g_MainStringTable = x13c_mainStringTable.GetObj();
2016-04-15 13:42:40 -07:00
}
2017-10-25 22:37:46 -07:00
void AddPaksAndFactories();
2017-01-20 22:03:37 -08:00
static IRenderer*
2016-04-15 13:42:40 -07:00
AllocateRenderer(IObjectStore& store, IFactory& resFactory)
{
g_Renderer = new CBooRenderer(store, resFactory);
return g_Renderer;
}
public:
CGameGlobalObjects(IFactory* resFactory,
CSimplePool* objStore)
: x4_resFactory(resFactory), xcc_simplePool(objStore)
2016-04-15 13:42:40 -07:00
{
if (!x4_resFactory)
{
2017-10-28 00:08:48 -07:00
m_gameResFactory.reset(new CResFactory());
x4_resFactory = m_gameResFactory.get();
}
if (!xcc_simplePool)
{
2017-10-28 00:08:48 -07:00
m_gameSimplePool.reset(new CSimplePool(*x4_resFactory));
xcc_simplePool = m_gameSimplePool.get();
}
g_ResFactory = x4_resFactory;
g_SimplePool = xcc_simplePool;
g_CharFactoryBuilder = &xec_charFactoryBuilder;
g_AiFuncMap = &x110_aiFuncMap;
2016-12-29 13:38:59 -08:00
x134_gameState.reset(new CGameState());
g_GameState = x134_gameState.get();
g_TweakManager = &x150_tweakManager;
2016-04-15 13:42:40 -07:00
}
~CGameGlobalObjects();
2016-04-15 13:42:40 -07:00
void PostInitialize()
{
2017-10-25 22:37:46 -07:00
AddPaksAndFactories();
x4_resFactory->LoadOriginalIDs(*xcc_simplePool);
2016-04-15 13:42:40 -07:00
LoadStringTable();
m_renderer.reset(AllocateRenderer(*xcc_simplePool, *x4_resFactory));
CScriptMazeNode::LoadMazeSeeds();
2016-04-15 13:42:40 -07:00
}
2016-12-29 13:38:59 -08:00
void ResetGameState()
{
x134_gameState.reset(new CGameState());
g_GameState = x134_gameState.get();
}
void StreamInGameState(CBitStreamReader& stream, u32 saveIdx)
{
x134_gameState.reset(new CGameState(stream, saveIdx));
g_GameState = x134_gameState.get();
}
};
2016-04-15 13:42:40 -07:00
#if MP1_USE_BOO
class CGameArchitectureSupport : public boo::IWindowCallback
#else
class CGameArchitectureSupport
#endif
{
2018-01-15 08:00:20 -08:00
friend class CMain;
CMain& m_parent;
2016-12-29 13:38:59 -08:00
CArchitectureQueue x4_archQueue;
CAudioSys x0_audioSys;
CInputGenerator x30_inputGenerator;
CGuiSys x44_guiSys;
CIOWinManager x58_ioWinManager;
2017-02-17 18:19:50 -08:00
s32 x78_gameFrameCount;
2017-01-19 19:53:32 -08:00
enum class EAudioLoadStatus
{
Loading,
Loaded,
Uninitialized
};
EAudioLoadStatus x88_audioLoadStatus = EAudioLoadStatus::Uninitialized;
std::vector<TToken<CAudioGroupSet>> x8c_pendingAudioGroups;
2016-04-15 13:42:40 -07:00
boo::SWindowRect m_windowRect;
bool m_rectIsDirty;
2018-01-15 08:00:20 -08:00
void destroyed() { x4_archQueue.Push(MakeMsg::CreateRemoveAllIOWins(EArchMsgTarget::IOWinManager)); }
2017-01-22 13:26:58 -08:00
void resized(const boo::SWindowRect &rect)
{
m_windowRect = rect;
m_rectIsDirty = true;
}
public:
CGameArchitectureSupport(CMain& parent,
boo::IAudioVoiceEngine* voiceEngine,
2017-01-22 13:26:58 -08:00
amuse::IBackendVoiceAllocator& backend);
~CGameArchitectureSupport();
2016-04-15 13:42:40 -07:00
void mouseDown(const boo::SWindowCoord &coord, boo::EMouseButton button, boo::EModifierKey mods)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.mouseDown(coord, button, mods); }
2016-04-15 13:42:40 -07:00
void mouseUp(const boo::SWindowCoord &coord, boo::EMouseButton button, boo::EModifierKey mods)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.mouseUp(coord, button, mods); }
2016-04-15 13:42:40 -07:00
void mouseMove(const boo::SWindowCoord &coord)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.mouseMove(coord); }
2016-04-15 13:42:40 -07:00
void scroll(const boo::SWindowCoord &coord, const boo::SScrollDelta &scroll)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.scroll(coord, scroll); }
2018-01-15 08:00:20 -08:00
void charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat);
void charKeyUp(unsigned long charCode, boo::EModifierKey mods) { x30_inputGenerator.charKeyUp(charCode, mods); }
void specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat);
void specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods);
2016-04-15 13:42:40 -07:00
void modKeyDown(boo::EModifierKey mod, bool isRepeat)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.modKeyDown(mod, isRepeat);}
2016-04-15 13:42:40 -07:00
void modKeyUp(boo::EModifierKey mod)
2016-12-29 13:38:59 -08:00
{ x30_inputGenerator.modKeyUp(mod); }
2016-04-15 13:42:40 -07:00
void PreloadAudio();
2017-01-19 19:53:32 -08:00
bool LoadAudio();
void UnloadAudio();
2017-01-19 19:53:32 -08:00
void UpdateTicks();
void Update();
2016-09-13 22:54:09 -07:00
void Draw();
2016-04-15 13:42:40 -07:00
bool isRectDirty() { return m_rectIsDirty; }
const boo::SWindowRect& getWindowRect()
{
m_rectIsDirty = false;
return m_windowRect;
}
2017-02-05 19:21:58 -08:00
CIOWinManager& GetIOWinManager() { return x58_ioWinManager; }
2016-04-15 13:42:40 -07:00
};
#if MP1_USE_BOO
2016-09-16 23:40:45 -07:00
class CMain : public boo::IApplicationCallback, public IMain
2016-04-15 13:42:40 -07:00
#else
2016-09-16 23:40:45 -07:00
class CMain : public IMain
2016-04-15 13:42:40 -07:00
#endif
{
friend class CGameArchitectureSupport;
2016-04-15 13:42:40 -07:00
#if MP1_USE_BOO
boo::IWindow* mainWindow;
int appMain(boo::IApplication* app);
2015-08-27 17:11:31 -07:00
void appQuitting(boo::IApplication*)
{ xe8_b24_finished = true; }
2015-08-27 17:11:31 -07:00
void appFilesOpen(boo::IApplication*, const std::vector<std::string>& paths)
{
fprintf(stderr, "OPENING: ");
for (const std::string& path : paths)
fprintf(stderr, "%s ", path.c_str());
fprintf(stderr, "\n");
}
2016-04-15 13:42:40 -07:00
#endif
2016-08-15 13:58:07 -07:00
private:
2015-08-27 17:11:31 -07:00
struct BooSetter
{
BooSetter(boo::IGraphicsDataFactory* factory,
boo::IGraphicsCommandQueue* cmdQ,
const boo::ObjToken<boo::ITextureR>& spareTex);
} m_booSetter;
2016-04-15 13:42:40 -07:00
//CMemorySys x6c_memSys;
2015-08-26 17:23:46 -07:00
CTweaks x70_tweaks;
EGameplayResult xe4_gameplayResult;
2015-08-27 17:11:31 -07:00
2016-04-15 13:42:40 -07:00
/* urde addition: these are simply initialized along with everything else */
2016-08-15 13:58:07 -07:00
CGameGlobalObjects x128_globalObjects;
2016-04-15 13:42:40 -07:00
EFlowState x12c_flowState = EFlowState::Default;
2016-08-15 13:58:07 -07:00
u32 x130_[10] = { 1000000 };
union
{
struct
{
2017-01-19 19:53:32 -08:00
bool x160_24_finished : 1;
2017-02-17 18:19:50 -08:00
bool x160_25_mfGameBuilt : 1;
bool x160_26_screenFading : 1;
2016-08-15 13:58:07 -07:00
bool x160_27_ : 1;
2016-12-29 22:37:01 -08:00
bool x160_28_manageCard : 1;
2016-08-15 13:58:07 -07:00
bool x160_29_ : 1;
bool x160_30_ : 1;
2016-12-23 21:23:50 -08:00
bool x160_31_cardBusy : 1;
2017-02-17 18:19:50 -08:00
bool x161_24_gameFrameDrawn : 1;
2016-08-15 13:58:07 -07:00
};
u16 _dummy = 0;
};
2017-01-19 19:53:32 -08:00
std::unique_ptr<CGameArchitectureSupport> x164_archSupport;
2016-08-15 13:58:07 -07:00
boo::IWindow* m_mainWindow = nullptr;
2018-01-15 08:00:20 -08:00
hecl::CVarManager* m_cvarMgr = nullptr;
std::unique_ptr<hecl::Console> m_console;
2017-10-16 22:51:53 -07:00
// Warmup state
std::vector<SObjectTag> m_warmupTags;
std::vector<SObjectTag>::iterator m_warmupIt;
bool m_needsWarmupClear = false;
bool m_doQuit = false;
2017-10-16 22:51:53 -07:00
2018-10-06 19:59:17 -07:00
void InitializeSubsystems();
static void InitializeDiscord();
static void ShutdownDiscord();
static void HandleDiscordReady(const DiscordUser* request);
static void HandleDiscordDisconnected(int errorCode, const char* message);
static void HandleDiscordErrored(int errorCode, const char* message);
2016-04-15 13:42:40 -07:00
2015-08-26 17:23:46 -07:00
public:
CMain(IFactory* resFactory, CSimplePool* resStore,
boo::IGraphicsDataFactory* gfxFactory,
boo::IGraphicsCommandQueue* cmdQ,
const boo::ObjToken<boo::ITextureR>& spareTex);
2015-08-26 17:23:46 -07:00
void RegisterResourceTweaks();
2017-10-25 22:37:46 -07:00
void AddWorldPaks();
2015-08-26 17:23:46 -07:00
void ResetGameState();
2016-12-29 22:37:01 -08:00
void StreamNewGameState(CBitStreamReader&, u32 idx);
void RefreshGameState();
2015-08-26 17:23:46 -07:00
void CheckTweakManagerDebugOptions() {}
2017-02-17 18:19:50 -08:00
void SetMFGameBuilt(bool b) { x160_25_mfGameBuilt = b; }
void SetScreenFading(bool b) { x160_26_screenFading = b; }
2018-05-13 21:38:58 -07:00
bool GetScreenFading() const { return x160_26_screenFading; }
2016-04-15 13:42:40 -07:00
static void UpdateDiscordPresence(CAssetId worldSTRG = {});
2016-04-15 13:42:40 -07:00
//int RsMain(int argc, const boo::SystemChar* argv[]);
void Init(const hecl::Runtime::FileStoreManager& storeMgr,
2018-01-15 08:00:20 -08:00
hecl::CVarManager* cvarManager,
boo::IWindow* window,
boo::IAudioVoiceEngine* voiceEngine,
amuse::IBackendVoiceAllocator& backend);
2017-10-16 22:51:53 -07:00
void WarmupShaders();
2016-04-15 13:42:40 -07:00
bool Proc();
2016-09-13 22:54:09 -07:00
void Draw();
2016-04-15 13:42:40 -07:00
void Shutdown();
boo::IWindow* GetMainWindow() const;
2016-04-15 13:42:40 -07:00
void MemoryCardInitializePump();
2017-01-19 19:53:32 -08:00
bool CheckReset() { return m_doQuit; }
bool CheckTerminate() { return m_doQuit; }
2018-10-06 19:59:17 -07:00
void DrawDebugMetrics(double, CStopwatch&) {}
2015-08-26 17:23:46 -07:00
void DoPredrawMetrics() {}
void FillInAssetIDs();
2017-01-19 19:53:32 -08:00
bool LoadAudio();
void ShutdownSubsystems();
2016-12-29 22:37:01 -08:00
EGameplayResult GetGameplayResult() const { return xe4_gameplayResult; }
void SetGameplayResult(EGameplayResult wl) { xe4_gameplayResult = wl; }
void SetManageCard(bool v) { x160_28_manageCard = v; }
2017-01-08 19:44:00 -08:00
bool GetCardBusy() const { return x160_31_cardBusy; }
2016-12-29 22:37:01 -08:00
void SetCardBusy(bool v) { x160_31_cardBusy = v; }
2017-02-17 18:19:50 -08:00
void SetGameFrameDrawn() { x161_24_gameFrameDrawn = true; }
2017-04-14 22:32:25 -07:00
static void EnsureWorldPaksReady();
2017-08-12 22:26:14 -07:00
static void EnsureWorldPakReady(CAssetId mlvl);
2016-08-15 13:58:07 -07:00
2016-09-16 23:40:45 -07:00
EFlowState GetFlowState() const { return x12c_flowState; }
void SetFlowState(EFlowState s) { x12c_flowState = s; }
void SetX30(bool v) { x160_30_ = v; }
2017-01-22 13:26:58 -08:00
CGameArchitectureSupport* GetArchSupport() const { return x164_archSupport.get(); }
2017-08-12 22:26:14 -07:00
size_t GetExpectedIdSize() const { return sizeof(u32); }
2018-01-15 08:00:20 -08:00
void quit(hecl::Console*, const std::vector<std::string>&)
{
m_doQuit = true;
2018-01-15 08:00:20 -08:00
}
void Give(hecl::Console*, const std::vector<std::string>&);
2018-06-13 12:36:11 -07:00
void God(hecl::Console*, const std::vector<std::string>&);
void Teleport(hecl::Console*, const std::vector<std::string>&);
void ListWorlds(hecl::Console*, const std::vector<std::string>&);
void WarpTo(hecl::Console*, const std::vector<std::string>&);
hecl::Console* Console() const { return m_console.get(); }
int m_warpWorldIdx = -1;
TAreaId m_warpAreaId = 0;
u64 m_warpLayerBits = 0;
2015-08-26 17:23:46 -07:00
};
}
}