2016-03-04 05:28:20 +00:00
|
|
|
#include "MP1.hpp"
|
2016-07-21 05:21:45 +00:00
|
|
|
#include "Graphics/Shaders/CModelShaders.hpp"
|
2016-07-22 19:46:30 +00:00
|
|
|
#include "Graphics/Shaders/CThermalColdFilter.hpp"
|
2016-08-03 21:53:03 +00:00
|
|
|
#include "Graphics/Shaders/CThermalHotFilter.hpp"
|
2016-07-29 17:38:44 +00:00
|
|
|
#include "Graphics/Shaders/CSpaceWarpFilter.hpp"
|
2016-08-17 06:18:18 +00:00
|
|
|
#include "Graphics/Shaders/CColoredQuadFilter.hpp"
|
2019-01-03 03:47:28 +00:00
|
|
|
#include "Graphics/Shaders/CColoredStripShader.hpp"
|
2016-08-17 06:18:18 +00:00
|
|
|
#include "Graphics/Shaders/CTexturedQuadFilter.hpp"
|
2016-08-20 18:18:44 +00:00
|
|
|
#include "Graphics/Shaders/CCameraBlurFilter.hpp"
|
2016-08-20 04:22:13 +00:00
|
|
|
#include "Graphics/Shaders/CXRayBlurFilter.hpp"
|
2017-01-29 03:58:16 +00:00
|
|
|
#include "Graphics/Shaders/CTextSupportShader.hpp"
|
2017-04-02 03:03:37 +00:00
|
|
|
#include "Graphics/Shaders/CEnergyBarShader.hpp"
|
2017-04-07 05:35:09 +00:00
|
|
|
#include "Graphics/Shaders/CRadarPaintShader.hpp"
|
2017-04-22 06:42:32 +00:00
|
|
|
#include "Graphics/Shaders/CMapSurfaceShader.hpp"
|
2017-05-06 05:21:42 +00:00
|
|
|
#include "Graphics/Shaders/CPhazonSuitFilter.hpp"
|
2017-06-01 05:34:24 +00:00
|
|
|
#include "Graphics/Shaders/CScanLinesFilter.hpp"
|
|
|
|
#include "Graphics/Shaders/CRandomStaticFilter.hpp"
|
2017-08-14 03:55:06 +00:00
|
|
|
#include "Graphics/Shaders/CFluidPlaneShader.hpp"
|
2017-09-03 05:53:38 +00:00
|
|
|
#include "Graphics/Shaders/CAABoxShader.hpp"
|
2017-10-01 04:26:46 +00:00
|
|
|
#include "Graphics/Shaders/CWorldShadowShader.hpp"
|
2017-10-17 05:51:53 +00:00
|
|
|
#include "Graphics/Shaders/CParticleSwooshShaders.hpp"
|
2018-11-02 08:16:16 +00:00
|
|
|
#include "Graphics/Shaders/CEnvFxShaders.hpp"
|
2018-02-01 23:19:34 +00:00
|
|
|
#include "NESEmulator/CNESShader.hpp"
|
2017-01-16 09:14:54 +00:00
|
|
|
#include "Audio/CStreamAudioManager.hpp"
|
2017-01-08 02:52:49 +00:00
|
|
|
#include "CGBASupport.hpp"
|
2017-10-26 05:37:46 +00:00
|
|
|
|
|
|
|
#include "CGameHintInfo.hpp"
|
|
|
|
#include "Particle/CParticleDataFactory.hpp"
|
|
|
|
#include "Particle/CGenDescription.hpp"
|
|
|
|
#include "Particle/CElectricDescription.hpp"
|
|
|
|
#include "Particle/CSwooshDescription.hpp"
|
|
|
|
#include "Particle/CParticleElectricDataFactory.hpp"
|
|
|
|
#include "Particle/CParticleSwooshDataFactory.hpp"
|
|
|
|
#include "Particle/CWeaponDescription.hpp"
|
|
|
|
#include "Particle/CProjectileWeaponDataFactory.hpp"
|
|
|
|
#include "Particle/CDecalDataFactory.hpp"
|
|
|
|
#include "GuiSys/CGuiFrame.hpp"
|
|
|
|
#include "GuiSys/CRasterFont.hpp"
|
|
|
|
#include "GuiSys/CStringTable.hpp"
|
|
|
|
#include "Graphics/CModel.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
|
|
|
#include "Character/CCharLayoutInfo.hpp"
|
|
|
|
#include "Character/CSkinRules.hpp"
|
|
|
|
#include "Character/CAnimCharacterSet.hpp"
|
|
|
|
#include "Character/CAllFormatsAnimSource.hpp"
|
|
|
|
#include "Character/CAnimPOIData.hpp"
|
|
|
|
#include "Collision/CCollidableOBBTreeGroup.hpp"
|
|
|
|
#include "Collision/CCollisionResponseData.hpp"
|
|
|
|
#include "CSaveWorld.hpp"
|
|
|
|
#include "AutoMapper/CMapWorld.hpp"
|
|
|
|
#include "AutoMapper/CMapArea.hpp"
|
|
|
|
#include "AutoMapper/CMapUniverse.hpp"
|
2018-05-02 00:43:31 +00:00
|
|
|
#include "World/CStateMachine.hpp"
|
2017-10-26 05:37:46 +00:00
|
|
|
#include "CScannableObjectInfo.hpp"
|
2017-01-20 03:53:32 +00:00
|
|
|
#include "Audio/CAudioGroupSet.hpp"
|
2017-10-26 05:37:46 +00:00
|
|
|
#include "Audio/CSfxManager.hpp"
|
|
|
|
#include "Audio/CMidiManager.hpp"
|
|
|
|
#include "CDependencyGroup.hpp"
|
|
|
|
#include "MP1OriginalIDs.hpp"
|
2018-04-30 03:12:41 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "World/CPlayer.hpp"
|
2018-10-07 02:59:17 +00:00
|
|
|
#include "CStopwatch.hpp"
|
2018-05-25 06:39:38 +00:00
|
|
|
#include <discord_rpc.h>
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace hecl {
|
|
|
|
extern CVar* com_enableCheats;
|
|
|
|
extern CVar* com_developer;
|
2019-06-06 00:07:50 +00:00
|
|
|
extern CVar* com_cubemaps;
|
2018-12-08 05:30:43 +00:00
|
|
|
}; // namespace hecl
|
2018-04-26 21:12:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
|
|
|
namespace MP1 {
|
2015-08-17 22:05:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameArchitectureSupport::CGameArchitectureSupport(CMain& parent, boo::IAudioVoiceEngine* voiceEngine,
|
2016-12-14 22:56:59 +00:00
|
|
|
amuse::IBackendVoiceAllocator& backend)
|
2018-12-08 05:30:43 +00:00
|
|
|
: m_parent(parent)
|
|
|
|
, x0_audioSys(voiceEngine, backend, 0, 0, 0, 0, 0)
|
|
|
|
, x30_inputGenerator(g_tweakPlayer->GetLeftLogicalThreshold(), g_tweakPlayer->GetRightLogicalThreshold())
|
|
|
|
, x44_guiSys(*g_ResFactory, *g_SimplePool, CGuiSys::EUsageMode::Zero) {
|
|
|
|
CMain* m = static_cast<CMain*>(g_Main);
|
2016-09-14 05:54:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x30_inputGenerator.startScanning();
|
|
|
|
g_InputGenerator = &x30_inputGenerator;
|
2016-09-14 05:54:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CAudioSys::SysSetVolume(0x7f);
|
|
|
|
CAudioSys::SetDefaultVolumeScale(0x75);
|
|
|
|
CAudioSys::SetVolumeScale(CAudioSys::GetDefaultVolumeScale());
|
|
|
|
CStreamAudioManager::Initialize();
|
|
|
|
CStreamAudioManager::SetMusicVolume(0x7f);
|
|
|
|
m->ResetGameState();
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2019-04-16 08:00:46 +00:00
|
|
|
if (!g_tweakGame->GetSplashScreensDisabled()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CIOWin> splash = std::make_shared<CSplashScreen>(CSplashScreen::ESplashScreen::Nintendo);
|
|
|
|
x58_ioWinManager.AddIOWin(splash, 1000, 10000);
|
|
|
|
}
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CIOWin> mf = std::make_shared<CMainFlow>();
|
|
|
|
x58_ioWinManager.AddIOWin(mf, 0, 0);
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CIOWin> console = std::make_shared<CConsoleOutputWindow>(8, 5.f, 0.75f);
|
|
|
|
x58_ioWinManager.AddIOWin(console, 100, 0);
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CIOWin> audState = std::make_shared<CAudioStateWin>();
|
|
|
|
x58_ioWinManager.AddIOWin(audState, 100, -1);
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::shared_ptr<CIOWin> errWin = std::make_shared<CErrorOutputWindow>(false);
|
|
|
|
x58_ioWinManager.AddIOWin(errWin, 10000, 100000);
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_GuiSys = &x44_guiSys;
|
|
|
|
g_GameState->GameOptions().EnsureSettings();
|
2017-01-20 03:53:32 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameArchitectureSupport::UpdateTicks() {
|
|
|
|
x4_archQueue.Push(MakeMsg::CreateFrameBegin(EArchMsgTarget::Game, x78_gameFrameCount));
|
|
|
|
x4_archQueue.Push(MakeMsg::CreateTimerTick(EArchMsgTarget::Game, 1.f / 60.f));
|
2016-09-14 05:54:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameArchitectureSupport::Update() {
|
|
|
|
g_GameState->GetWorldTransitionManager()->TouchModels();
|
|
|
|
x30_inputGenerator.Update(1 / 60.f, x4_archQueue);
|
|
|
|
x4_archQueue.Push(MakeMsg::CreateFrameEnd(EArchMsgTarget::Game, x78_gameFrameCount));
|
|
|
|
x58_ioWinManager.PumpMessages(x4_archQueue);
|
|
|
|
}
|
2017-01-22 01:40:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
struct AudioGroupInfo {
|
|
|
|
const char* name;
|
|
|
|
u32 id;
|
|
|
|
};
|
2017-01-22 01:40:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static const AudioGroupInfo StaticAudioGroups[] = {
|
|
|
|
{"Misc_AGSC", 39}, {"MiscSamus_AGSC", 41}, {"UI_AGSC", 40}, {"Weapons_AGSC", 43}, {"ZZZ_AGSC", 65}};
|
2017-01-22 01:40:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CGameArchitectureSupport::LoadAudio() {
|
|
|
|
if (x88_audioLoadStatus == EAudioLoadStatus::Loaded)
|
|
|
|
return true;
|
2016-09-14 05:54:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
TToken<CAudioGroupSet>& tok = x8c_pendingAudioGroups[i];
|
|
|
|
if (tok.IsLocked()) {
|
|
|
|
if (tok.IsLoaded()) {
|
|
|
|
CAudioGroupSet* set = tok.GetObj();
|
|
|
|
if (!CAudioSys::SysIsGroupSetLoaded(set->GetName())) {
|
|
|
|
CAudioSys::SysLoadGroupSet(tok, set->GetName(), tok.GetObjectTag()->id);
|
|
|
|
CAudioSys::SysAddGroupIntoAmuse(set->GetName());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Lock next pending group */
|
|
|
|
tok.Lock();
|
|
|
|
return false;
|
2017-10-26 05:37:46 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSfxManager::LoadTranslationTable(g_SimplePool, g_ResFactory->GetResourceIdByName("sound_lookup"));
|
|
|
|
x8c_pendingAudioGroups = std::vector<TToken<CAudioGroupSet>>();
|
|
|
|
x88_audioLoadStatus = EAudioLoadStatus::Loaded;
|
2017-10-26 05:37:46 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return true;
|
2017-10-26 05:37:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CGameArchitectureSupport::PreloadAudio() {
|
|
|
|
if (x88_audioLoadStatus != EAudioLoadStatus::Uninitialized)
|
|
|
|
return;
|
|
|
|
x8c_pendingAudioGroups.clear();
|
|
|
|
x8c_pendingAudioGroups.reserve(5);
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
const AudioGroupInfo& info = StaticAudioGroups[i];
|
|
|
|
CToken grp = g_SimplePool->GetObj(info.name);
|
|
|
|
if (i == 0) /* Lock first group in sequence */
|
|
|
|
grp.Lock();
|
|
|
|
x8c_pendingAudioGroups.push_back(std::move(grp));
|
|
|
|
}
|
|
|
|
|
|
|
|
x88_audioLoadStatus = EAudioLoadStatus::Loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArchitectureSupport::UnloadAudio() {
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
const AudioGroupInfo& info = StaticAudioGroups[i];
|
|
|
|
const SObjectTag* tag = g_ResFactory->GetResourceIdByName(info.name);
|
|
|
|
auto name = CAudioSys::SysGetGroupSetName(tag->id);
|
|
|
|
CAudioSys::SysRemoveGroupFromAmuse(name);
|
|
|
|
CAudioSys::SysUnloadAudioGroupSet(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
x8c_pendingAudioGroups = std::vector<TToken<CAudioGroupSet>>();
|
|
|
|
x88_audioLoadStatus = EAudioLoadStatus::Uninitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArchitectureSupport::Draw() {
|
|
|
|
x58_ioWinManager.Draw();
|
|
|
|
if (m_parent.x161_24_gameFrameDrawn) {
|
|
|
|
++x78_gameFrameCount;
|
|
|
|
m_parent.x161_24_gameFrameDrawn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CGameArchitectureSupport::~CGameArchitectureSupport() {
|
|
|
|
x58_ioWinManager.RemoveAllIOWins();
|
|
|
|
UnloadAudio();
|
|
|
|
CSfxManager::Shutdown();
|
|
|
|
CStreamAudioManager::Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArchitectureSupport::charKeyDown(unsigned long charCode, boo::EModifierKey mods, bool isRepeat) {
|
|
|
|
x30_inputGenerator.charKeyDown(charCode, mods, isRepeat);
|
|
|
|
m_parent.m_console->handleCharCode(charCode, mods, isRepeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArchitectureSupport::specialKeyDown(boo::ESpecialKey key, boo::EModifierKey mods, bool isRepeat) {
|
|
|
|
x30_inputGenerator.specialKeyDown(key, mods, isRepeat);
|
|
|
|
m_parent.m_console->handleSpecialKeyDown(key, mods, isRepeat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGameArchitectureSupport::specialKeyUp(boo::ESpecialKey key, boo::EModifierKey mods) {
|
|
|
|
x30_inputGenerator.specialKeyUp(key, mods);
|
|
|
|
m_parent.m_console->handleSpecialKeyUp(key, mods);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMain::CMain(IFactory* resFactory, CSimplePool* resStore, boo::IGraphicsDataFactory* gfxFactory,
|
|
|
|
boo::IGraphicsCommandQueue* cmdQ, const boo::ObjToken<boo::ITextureR>& spareTex)
|
|
|
|
: m_booSetter(gfxFactory, cmdQ, spareTex), x128_globalObjects(resFactory, resStore) {
|
|
|
|
xe4_gameplayResult = EGameplayResult::Playing;
|
|
|
|
g_Main = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory, boo::IGraphicsCommandQueue* cmdQ,
|
|
|
|
const boo::ObjToken<boo::ITextureR>& spareTex) {
|
|
|
|
CGraphics::InitializeBoo(factory, cmdQ, spareTex);
|
|
|
|
CParticleSwooshShaders::Initialize();
|
|
|
|
CThermalColdFilter::Initialize();
|
|
|
|
CThermalHotFilter::Initialize();
|
|
|
|
CSpaceWarpFilter::Initialize();
|
|
|
|
CCameraBlurFilter::Initialize();
|
|
|
|
CXRayBlurFilter::Initialize();
|
|
|
|
CFogVolumePlaneShader::Initialize();
|
|
|
|
CFogVolumeFilter::Initialize();
|
|
|
|
CEnergyBarShader::Initialize();
|
|
|
|
CRadarPaintShader::Initialize();
|
|
|
|
CMapSurfaceShader::Initialize();
|
|
|
|
CPhazonSuitFilter::Initialize();
|
|
|
|
CAABoxShader::Initialize();
|
|
|
|
CWorldShadowShader::Initialize();
|
|
|
|
CColoredQuadFilter::Initialize();
|
2019-01-03 03:47:28 +00:00
|
|
|
CColoredStripShader::Initialize();
|
2018-12-08 05:30:43 +00:00
|
|
|
CTexturedQuadFilter::Initialize();
|
|
|
|
CTexturedQuadFilterAlpha::Initialize();
|
|
|
|
CTextSupportShader::Initialize();
|
|
|
|
CScanLinesFilter::Initialize();
|
|
|
|
CRandomStaticFilter::Initialize();
|
|
|
|
CEnvFxShaders::Initialize();
|
|
|
|
CNESShader::Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::RegisterResourceTweaks() {}
|
|
|
|
|
|
|
|
void CGameGlobalObjects::AddPaksAndFactories() {
|
2019-02-24 07:15:54 +00:00
|
|
|
CGraphics::SetViewPointMatrix(zeus::CTransform());
|
|
|
|
CGraphics::SetModelMatrix(zeus::CTransform());
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CResLoader* loader = g_ResFactory->GetResLoader()) {
|
|
|
|
loader->AddPakFileAsync("Tweaks", false, false);
|
|
|
|
loader->AddPakFileAsync("NoARAM", false, false);
|
|
|
|
loader->AddPakFileAsync("AudioGrp", false, false);
|
|
|
|
loader->AddPakFileAsync("MiscData", false, false);
|
|
|
|
loader->AddPakFileAsync("SamusGun", true, false);
|
|
|
|
loader->AddPakFileAsync("TestAnim", true, false);
|
|
|
|
loader->AddPakFileAsync("SamGunFx", true, false);
|
|
|
|
loader->AddPakFileAsync("MidiData", false, false);
|
|
|
|
loader->AddPakFileAsync("GGuiSys", false, false);
|
|
|
|
loader->AddPakFileAsync("!original_ids", false, false);
|
2017-10-27 10:10:32 +00:00
|
|
|
loader->WaitForPakFileLoadingComplete();
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CFactoryMgr* fmgr = g_ResFactory->GetFactoryMgr()) {
|
|
|
|
fmgr->AddFactory(FOURCC('TXTR'), FMemFactoryFunc(FTextureFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('PART'), FFactoryFunc(FParticleFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('FRME'), FFactoryFunc(RGuiFrameFactoryInGame));
|
|
|
|
fmgr->AddFactory(FOURCC('FONT'), FFactoryFunc(FRasterFontFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('CMDL'), FMemFactoryFunc(FModelFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('CINF'), FFactoryFunc(FCharLayoutInfo));
|
|
|
|
fmgr->AddFactory(FOURCC('CSKR'), FFactoryFunc(FSkinRulesFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('ANCS'), FFactoryFunc(FAnimCharacterSet));
|
|
|
|
fmgr->AddFactory(FOURCC('ANIM'), FFactoryFunc(AnimSourceFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('EVNT'), FFactoryFunc(AnimPOIDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('DCLN'), FFactoryFunc(FCollidableOBBTreeGroupFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('DGRP'), FFactoryFunc(FDependencyGroupFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('AGSC'), FMemFactoryFunc(FAudioGroupSetDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('CSNG'), FFactoryFunc(FMidiDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('ATBL'), FFactoryFunc(FAudioTranslationTableFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('STRG'), FFactoryFunc(FStringTableFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('HINT'), FFactoryFunc(FHintFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('SAVW'), FFactoryFunc(FSaveWorldFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('MAPW'), FFactoryFunc(FMapWorldFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('OIDS'), FFactoryFunc(FMP1OriginalIDsFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('SCAN'), FFactoryFunc(FScannableObjectInfoFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('CRSC'), FFactoryFunc(FCollisionResponseDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('SWHC'), FFactoryFunc(FParticleSwooshDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('ELSC'), FFactoryFunc(FParticleElectricDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('WPSC'), FFactoryFunc(FProjectileWeaponDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('DPSC'), FFactoryFunc(FDecalDataFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('MAPA'), FFactoryFunc(FMapAreaFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('MAPU'), FFactoryFunc(FMapUniverseFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('AFSM'), FFactoryFunc(FAiFiniteStateMachineFactory));
|
|
|
|
fmgr->AddFactory(FOURCC('PATH'), FMemFactoryFunc(FPathFindAreaFactory));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CGameGlobalObjects::~CGameGlobalObjects() {
|
|
|
|
g_ResFactory = nullptr;
|
|
|
|
g_SimplePool = nullptr;
|
|
|
|
g_CharFactoryBuilder = nullptr;
|
|
|
|
g_AiFuncMap = nullptr;
|
|
|
|
g_GameState = nullptr;
|
|
|
|
g_TweakManager = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::AddWorldPaks() {
|
|
|
|
CResLoader* loader = g_ResFactory->GetResLoader();
|
|
|
|
if (!loader)
|
|
|
|
return;
|
|
|
|
auto pakPrefix = g_tweakGame->GetWorldPrefix();
|
|
|
|
for (int i = 0; i < 9; ++i) {
|
|
|
|
std::string path(pakPrefix);
|
|
|
|
|
|
|
|
if (i != 0)
|
|
|
|
path += '0' + i;
|
|
|
|
|
|
|
|
std::string lowerPath(path);
|
|
|
|
athena::utility::tolower(lowerPath);
|
|
|
|
if (CDvdFile::FileExists((path + ".upak").c_str()))
|
|
|
|
loader->AddPakFileAsync(path, false, true);
|
|
|
|
else if (CDvdFile::FileExists((lowerPath + ".upak").c_str()))
|
|
|
|
loader->AddPakFileAsync(lowerPath, false, true);
|
|
|
|
}
|
|
|
|
loader->WaitForPakFileLoadingComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::ResetGameState() {
|
|
|
|
CPersistentOptions sysOpts = g_GameState->SystemOptions();
|
|
|
|
CGameOptions gameOpts = g_GameState->GameOptions();
|
|
|
|
x128_globalObjects.ResetGameState();
|
|
|
|
g_GameState->ImportPersistentOptions(sysOpts);
|
|
|
|
g_GameState->SetGameOptions(gameOpts);
|
|
|
|
g_GameState->GetPlayerState()->SetIsFusionEnabled(g_GameState->SystemOptions().GetPlayerFusionSuitActive());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::InitializeSubsystems() {
|
|
|
|
CBasics::Initialize();
|
|
|
|
CModelShaders::Initialize();
|
|
|
|
CMoviePlayer::Initialize();
|
|
|
|
CLineRenderer::Initialize();
|
|
|
|
CElementGen::Initialize();
|
|
|
|
CAnimData::InitializeCache();
|
|
|
|
CDecalManager::Initialize();
|
|
|
|
CGBASupport::Initialize();
|
2019-06-16 06:25:29 +00:00
|
|
|
CGraphics::g_BooFactory->waitUntilShadersReady();
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::MemoryCardInitializePump() {
|
|
|
|
if (!g_MemoryCardSys) {
|
|
|
|
std::unique_ptr<CMemoryCardSys>& memSys = x128_globalObjects.x0_memoryCardSys;
|
|
|
|
if (!memSys)
|
|
|
|
memSys.reset(new CMemoryCardSys());
|
|
|
|
if (memSys->InitializePump()) {
|
|
|
|
g_MemoryCardSys = memSys.get();
|
|
|
|
g_GameState->InitializeMemoryStates();
|
2017-10-22 06:11:22 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-22 06:11:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::FillInAssetIDs() {}
|
2017-01-20 03:53:32 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMain::LoadAudio() {
|
|
|
|
if (x164_archSupport)
|
|
|
|
return x164_archSupport->LoadAudio();
|
|
|
|
return true;
|
2015-08-27 00:23:46 +00:00
|
|
|
}
|
2015-11-02 18:45:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::EnsureWorldPaksReady() {}
|
2017-04-15 05:32:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::EnsureWorldPakReady(CAssetId mlvl) { /* TODO: Schedule resource list load for World Pak containing mlvl */ }
|
2017-04-15 05:32:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::Give(hecl::Console* console, const std::vector<std::string>& args) {
|
|
|
|
if (args.size() < 1 || (!g_GameState || !g_GameState->GetPlayerState()))
|
|
|
|
return;
|
2018-04-26 21:12:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::string type = args[0];
|
|
|
|
athena::utility::tolower(type);
|
|
|
|
std::shared_ptr<CPlayerState> pState = g_GameState->GetPlayerState();
|
|
|
|
if (type == "all") {
|
|
|
|
for (u32 item = 0; item < u32(CPlayerState::EItemType::Max); ++item) {
|
|
|
|
pState->ReInitalizePowerUp(CPlayerState::EItemType(item),
|
|
|
|
CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item)));
|
|
|
|
pState->IncrPickup(CPlayerState::EItemType(item),
|
|
|
|
CPlayerState::GetPowerUpMaxValue(CPlayerState::EItemType(item)));
|
2018-04-26 21:12:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
pState->IncrPickup(CPlayerState::EItemType::HealthRefill, 99999);
|
|
|
|
} else {
|
|
|
|
CPlayerState::EItemType eType = CPlayerState::ItemNameToType(type);
|
|
|
|
if (eType == CPlayerState::EItemType::Invalid) {
|
|
|
|
console->report(hecl::Console::Level::Info, "Invalid item %s", type.c_str());
|
|
|
|
return;
|
2018-04-26 21:12:20 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (eType == CPlayerState::EItemType::HealthRefill) {
|
|
|
|
pState->IncrPickup(eType, 9999);
|
|
|
|
console->report(hecl::Console::Level::Info, "Cheater....., Greatly increasing Metroid encounters, have fun!");
|
|
|
|
if (g_StateManager)
|
2018-10-11 22:57:05 +00:00
|
|
|
g_StateManager->Player()->AsyncLoadSuit(*g_StateManager);
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2018-06-13 19:36:11 +00:00
|
|
|
}
|
2018-04-30 03:12:41 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
s32 itemAmt = CPlayerState::GetPowerUpMaxValue(eType);
|
|
|
|
if (args.size() == 2) {
|
|
|
|
s32 itemMax = CPlayerState::GetPowerUpMaxValue(eType);
|
|
|
|
itemAmt = s32(strtol(args[1].c_str(), nullptr, 10));
|
|
|
|
itemAmt = zeus::clamp(-itemMax, itemAmt, itemMax);
|
2018-04-30 03:12:41 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
u32 curCap = pState->GetItemCapacity(eType);
|
|
|
|
if (itemAmt > 0 && curCap < u32(itemAmt)) {
|
|
|
|
/* Handle special case with Missiles */
|
|
|
|
if (eType == CPlayerState::EItemType::Missiles) {
|
|
|
|
u32 tmp = ((u32(itemAmt) / 5) + (itemAmt % 5)) * 5;
|
|
|
|
pState->ReInitalizePowerUp(eType, tmp);
|
|
|
|
} else
|
|
|
|
pState->ReInitalizePowerUp(eType, itemAmt);
|
2018-06-13 02:07:13 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (itemAmt > 0)
|
|
|
|
pState->IncrPickup(eType, u32(itemAmt));
|
|
|
|
else
|
|
|
|
pState->DecrPickup(eType, zeus::clamp(0u, u32(abs(itemAmt)), pState->GetItemAmount(eType)));
|
|
|
|
}
|
|
|
|
if (g_StateManager)
|
|
|
|
g_StateManager->Player()->AsyncLoadSuit(*g_StateManager);
|
|
|
|
console->report(hecl::Console::Level::Info, "Cheater....., Greatly increasing Metroid encounters, have fun!");
|
|
|
|
}
|
|
|
|
|
2019-02-07 01:26:53 +00:00
|
|
|
void CMain::Remove(hecl::Console*, const std::vector<std::string>& args) {
|
|
|
|
if (args.size() < 1 || (!g_GameState || !g_GameState->GetPlayerState()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string type = args[0];
|
|
|
|
athena::utility::tolower(type);
|
|
|
|
std::shared_ptr<CPlayerState> pState = g_GameState->GetPlayerState();
|
|
|
|
CPlayerState::EItemType eType = CPlayerState::ItemNameToType(type);
|
|
|
|
if (eType != CPlayerState::EItemType::Invalid) {
|
|
|
|
pState->ReInitalizePowerUp(eType, 0);
|
|
|
|
if (g_StateManager)
|
|
|
|
g_StateManager->Player()->AsyncLoadSuit(*g_StateManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::God(hecl::Console* con, const std::vector<std::string>&) {
|
|
|
|
if (g_GameState && g_GameState->GetPlayerState()) {
|
|
|
|
g_GameState->GetPlayerState()->SetCanTakeDamage(!g_GameState->GetPlayerState()->CanTakeDamage());
|
|
|
|
if (!g_GameState->GetPlayerState()->CanTakeDamage())
|
|
|
|
con->report(hecl::Console::Level::Info, "God Mode Enabled");
|
|
|
|
else
|
|
|
|
con->report(hecl::Console::Level::Info, "God Mode Disabled");
|
|
|
|
}
|
2018-06-13 02:07:13 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::Teleport(hecl::Console*, const std::vector<std::string>& args) {
|
|
|
|
if (!g_StateManager || args.size() < 3)
|
|
|
|
return;
|
2018-09-21 03:41:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f loc;
|
|
|
|
for (u32 i = 0; i < 3; ++i)
|
|
|
|
loc[i] = strtof(args[i].c_str(), nullptr);
|
2018-09-21 03:41:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform xf = g_StateManager->Player()->GetTransform();
|
|
|
|
xf.origin = loc;
|
|
|
|
|
2019-02-10 04:41:35 +00:00
|
|
|
if (args.size() >= 6) {
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f angle;
|
|
|
|
for (u32 i = 0; i < 3; ++i)
|
|
|
|
angle[i] = zeus::degToRad(strtof(args[i + 3].c_str(), nullptr));
|
|
|
|
xf.setRotation(zeus::CMatrix3f(zeus::CQuaternion(angle)));
|
|
|
|
}
|
|
|
|
g_StateManager->Player()->Teleport(xf, *g_StateManager, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::ListWorlds(hecl::Console* con, const std::vector<std::string>&) {
|
|
|
|
|
|
|
|
if (g_ResFactory && g_ResFactory->GetResLoader()) {
|
|
|
|
for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks())
|
|
|
|
if (pak->IsWorldPak()) {
|
|
|
|
for (const auto& named : pak->GetNameList())
|
|
|
|
if (named.second.type == SBIG('MLVL')) {
|
|
|
|
con->report(hecl::Console::Level::Info, "%s '%08X'", named.first.c_str(), named.second.id.Value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-07 01:55:28 +00:00
|
|
|
void CMain::Warp(hecl::Console* con, const std::vector<std::string>& args) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!g_StateManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (args.size() < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
TAreaId aId;
|
|
|
|
std::string worldName;
|
|
|
|
if (args.size() == 2) {
|
|
|
|
worldName = args[0];
|
|
|
|
athena::utility::tolower(worldName);
|
|
|
|
aId = strtol(args[1].c_str(), nullptr, 10);
|
|
|
|
} else
|
|
|
|
aId = strtol(args[0].c_str(), nullptr, 10);
|
|
|
|
|
|
|
|
if (!worldName.empty() && g_ResFactory && g_ResFactory->GetResLoader()) {
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) {
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
if (pak->IsWorldPak()) {
|
|
|
|
for (const auto& named : pak->GetNameList())
|
|
|
|
if (named.second.type == SBIG('MLVL')) {
|
|
|
|
std::string name = named.first;
|
|
|
|
athena::utility::tolower(name);
|
|
|
|
if (name.find(worldName) != std::string::npos) {
|
|
|
|
g_GameState->SetCurrentWorldId(named.second.id);
|
|
|
|
found = true;
|
|
|
|
break;
|
2018-09-21 03:41:57 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-21 03:41:57 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-09-21 03:41:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_GameState->GetWorldTransitionManager()->DisableTransition();
|
2018-09-21 03:41:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (aId >= g_GameState->CurrentWorldState().GetLayerState()->GetAreaCount())
|
|
|
|
aId = 0;
|
2018-09-21 03:41:57 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_GameState->CurrentWorldState().SetAreaId(aId);
|
|
|
|
g_Main->SetFlowState(EFlowState::None);
|
|
|
|
g_StateManager->SetWarping(true);
|
|
|
|
g_StateManager->SetShouldQuitGame(true);
|
2018-09-21 03:41:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx) {
|
|
|
|
bool fusionBackup = g_GameState->SystemOptions().GetPlayerFusionSuitActive();
|
|
|
|
x128_globalObjects.x134_gameState = std::make_unique<CGameState>(r, idx);
|
|
|
|
g_GameState = x128_globalObjects.x134_gameState.get();
|
|
|
|
g_GameState->SystemOptions().SetPlayerFusionSuitActive(fusionBackup);
|
|
|
|
g_GameState->GetPlayerState()->SetIsFusionEnabled(fusionBackup);
|
|
|
|
g_GameState->HintOptions().SetNextHintTime();
|
2016-12-30 06:37:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::RefreshGameState() {
|
|
|
|
CPersistentOptions sysOpts = g_GameState->SystemOptions();
|
|
|
|
u64 cardSerial = g_GameState->GetCardSerial();
|
|
|
|
std::vector<u8> saveData = g_GameState->BackupBuf();
|
|
|
|
CGameOptions gameOpts = g_GameState->GameOptions();
|
|
|
|
CBitStreamReader r(saveData.data(), saveData.size());
|
|
|
|
x128_globalObjects.StreamInGameState(r, g_GameState->GetFileIdx());
|
|
|
|
g_GameState->SetPersistentOptions(sysOpts);
|
|
|
|
g_GameState->SetGameOptions(gameOpts);
|
|
|
|
g_GameState->GameOptions().EnsureSettings();
|
|
|
|
g_GameState->SetCardSerial(cardSerial);
|
|
|
|
g_GameState->GetPlayerState()->SetIsFusionEnabled(g_GameState->SystemOptions().GetPlayerFusionSuitActive());
|
2018-10-18 04:51:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 06:42:28 +00:00
|
|
|
static logvisor::Module DiscordLog("Discord");
|
|
|
|
static const char* DISCORD_APPLICATION_ID = "402571593815031819";
|
|
|
|
static int64_t DiscordStartTime;
|
|
|
|
static CAssetId DiscordWorldSTRG;
|
|
|
|
static TLockedToken<CStringTable> DiscordWorldSTRGObj;
|
|
|
|
static std::string DiscordWorldName;
|
|
|
|
static u32 DiscordItemPercent = 0xffffffff;
|
|
|
|
static std::string DiscordState;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::InitializeDiscord() {
|
|
|
|
DiscordStartTime = time(0);
|
|
|
|
DiscordEventHandlers handlers = {};
|
|
|
|
handlers.ready = HandleDiscordReady;
|
|
|
|
handlers.disconnected = HandleDiscordDisconnected;
|
|
|
|
handlers.errored = HandleDiscordErrored;
|
|
|
|
Discord_Initialize(DISCORD_APPLICATION_ID, &handlers, 1, nullptr);
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::ShutdownDiscord() {
|
|
|
|
DiscordWorldSTRGObj = TLockedToken<CStringTable>();
|
|
|
|
Discord_Shutdown();
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::UpdateDiscordPresence(CAssetId worldSTRG) {
|
|
|
|
bool updated = false;
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (worldSTRG != DiscordWorldSTRG) {
|
|
|
|
DiscordWorldSTRG = worldSTRG;
|
|
|
|
DiscordWorldSTRGObj = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), worldSTRG});
|
|
|
|
}
|
|
|
|
if (DiscordWorldSTRGObj.IsLoaded()) {
|
|
|
|
DiscordWorldName = hecl::Char16ToUTF8(DiscordWorldSTRGObj->GetString(0));
|
|
|
|
DiscordWorldSTRGObj = TLockedToken<CStringTable>();
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_GameState) {
|
|
|
|
if (CPlayerState* pState = g_GameState->GetPlayerState().get()) {
|
|
|
|
u32 itemPercent = pState->CalculateItemCollectionRate() * 100 / pState->GetPickupTotal();
|
|
|
|
if (DiscordItemPercent != itemPercent) {
|
|
|
|
DiscordItemPercent = itemPercent;
|
|
|
|
DiscordState = hecl::Format("%d%%", itemPercent);
|
2018-01-16 06:42:28 +00:00
|
|
|
updated = true;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (updated) {
|
|
|
|
DiscordRichPresence discordPresence = {};
|
|
|
|
discordPresence.state = DiscordState.c_str();
|
|
|
|
discordPresence.details = DiscordWorldName.c_str();
|
|
|
|
discordPresence.largeImageKey = "default";
|
|
|
|
discordPresence.startTimestamp = DiscordStartTime;
|
|
|
|
Discord_UpdatePresence(&discordPresence);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::HandleDiscordReady(const DiscordUser* request) { DiscordLog.report(logvisor::Info, "Discord Ready"); }
|
|
|
|
|
|
|
|
void CMain::HandleDiscordDisconnected(int errorCode, const char* message) {
|
|
|
|
DiscordLog.report(logvisor::Warning, "Discord Disconnected: %s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::HandleDiscordErrored(int errorCode, const char* message) {
|
|
|
|
DiscordLog.report(logvisor::Error, "Discord Error: %s", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IWindow* window,
|
|
|
|
boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) {
|
|
|
|
InitializeDiscord();
|
|
|
|
m_mainWindow = window;
|
|
|
|
m_cvarMgr = cvarMgr;
|
|
|
|
m_console = std::make_unique<hecl::Console>(m_cvarMgr);
|
2018-12-10 05:12:55 +00:00
|
|
|
m_console->init(window);
|
2018-12-08 05:30:43 +00:00
|
|
|
m_console->registerCommand("Quit"sv, "Quits the game immediately"sv, ""sv,
|
|
|
|
std::bind(&CMain::quit, this, std::placeholders::_1, std::placeholders::_2));
|
|
|
|
m_console->registerCommand("Give"sv, "Gives the player the specified item, maxing it out"sv, ""sv,
|
|
|
|
std::bind(&CMain::Give, this, std::placeholders::_1, std::placeholders::_2),
|
|
|
|
hecl::SConsoleCommand::ECommandFlags::Cheat);
|
2019-02-07 01:26:53 +00:00
|
|
|
m_console->registerCommand("Remove"sv, "Removes the specified item from the player"sv, ""sv,
|
|
|
|
std::bind(&CMain::Remove, this, std::placeholders::_1, std::placeholders::_2),
|
|
|
|
hecl::SConsoleCommand::ECommandFlags::Cheat);
|
2018-12-08 05:30:43 +00:00
|
|
|
m_console->registerCommand(
|
|
|
|
"Teleport"sv, "Teleports the player to the specified coordinates in worldspace"sv, "x y z [dX dY dZ]"sv,
|
|
|
|
std::bind(&CMain::Teleport, this, std::placeholders::_1, std::placeholders::_2),
|
|
|
|
(hecl::SConsoleCommand::ECommandFlags::Cheat | hecl::SConsoleCommand::ECommandFlags::Developer));
|
|
|
|
m_console->registerCommand("God"sv, "Disables damage given by enemies and objects"sv, ""sv,
|
|
|
|
std::bind(&CMain::God, this, std::placeholders::_1, std::placeholders::_2),
|
|
|
|
hecl::SConsoleCommand::ECommandFlags::Cheat);
|
|
|
|
m_console->registerCommand("ListWorlds"sv, "Lists loaded worlds"sv, ""sv,
|
|
|
|
std::bind(&CMain::ListWorlds, this, std::placeholders::_1, std::placeholders::_2),
|
|
|
|
hecl::SConsoleCommand::ECommandFlags::Normal);
|
2019-02-07 01:55:28 +00:00
|
|
|
m_console->registerCommand("Warp"sv, "Warps to a given area and world"sv, "[worldname] areaId"sv,
|
|
|
|
std::bind(&CMain::Warp, this, std::placeholders::_1, std::placeholders::_2),
|
2018-12-08 05:30:43 +00:00
|
|
|
hecl::SConsoleCommand::ECommandFlags::Normal);
|
|
|
|
|
|
|
|
InitializeSubsystems();
|
|
|
|
x128_globalObjects.PostInitialize();
|
|
|
|
x70_tweaks.RegisterTweaks(m_cvarMgr);
|
|
|
|
x70_tweaks.RegisterResourceTweaks(m_cvarMgr);
|
|
|
|
AddWorldPaks();
|
|
|
|
|
|
|
|
const auto& args = boo::APP->getArgs();
|
|
|
|
for (auto it = args.begin(); it != args.end(); ++it) {
|
|
|
|
if (*it == _SYS_STR("--warp") && args.end() - it >= 3) {
|
|
|
|
const hecl::SystemChar* worldIdxStr = (*(it + 1)).c_str();
|
|
|
|
const hecl::SystemChar* areaIdxStr = (*(it + 2)).c_str();
|
|
|
|
|
|
|
|
hecl::SystemChar* endptr;
|
2019-02-10 04:41:35 +00:00
|
|
|
m_warpWorldIdx = TAreaId(hecl::StrToUl(worldIdxStr, &endptr, 0));
|
2018-12-08 05:30:43 +00:00
|
|
|
if (endptr == worldIdxStr)
|
|
|
|
m_warpWorldIdx = 0;
|
2019-02-10 04:41:35 +00:00
|
|
|
m_warpAreaId = TAreaId(hecl::StrToUl(areaIdxStr, &endptr, 0));
|
2018-12-08 05:30:43 +00:00
|
|
|
if (endptr == areaIdxStr)
|
|
|
|
m_warpAreaId = 0;
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) {
|
|
|
|
if (*(pak->GetPath().end() - 6) == '0' + m_warpWorldIdx) {
|
|
|
|
found = true;
|
|
|
|
break;
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
m_warpWorldIdx = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-10 04:41:35 +00:00
|
|
|
while (args.end() - it >= 4) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const hecl::SystemChar* layerStr = (*(it + 3)).c_str();
|
2019-02-10 04:41:35 +00:00
|
|
|
if (!(layerStr[0] == _SYS_STR('0') && layerStr[1] == _SYS_STR('x')) &&
|
|
|
|
(layerStr[0] == _SYS_STR('0') || layerStr[0] == _SYS_STR('1'))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const auto* cur = layerStr; *cur != _SYS_STR('\0'); ++cur)
|
|
|
|
if (*cur == _SYS_STR('1'))
|
2019-01-29 08:28:35 +00:00
|
|
|
m_warpLayerBits |= u64(1) << (cur - layerStr);
|
2019-02-10 04:41:35 +00:00
|
|
|
} else if (layerStr[0] == _SYS_STR('0') && layerStr[1] == _SYS_STR('x')) {
|
|
|
|
m_warpMemoryRelays.push_back(TAreaId(hecl::StrToUl(layerStr + 2, nullptr, 16)));
|
|
|
|
}
|
|
|
|
++it;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SetFlowState(EFlowState::StateSetter);
|
2019-02-10 04:41:35 +00:00
|
|
|
break;
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
FillInAssetIDs();
|
|
|
|
x164_archSupport.reset(new CGameArchitectureSupport(*this, voiceEngine, backend));
|
|
|
|
g_archSupport = x164_archSupport.get();
|
|
|
|
x164_archSupport->PreloadAudio();
|
2019-02-10 04:41:35 +00:00
|
|
|
std::srand(static_cast<unsigned int>(std::time(nullptr)));
|
2018-12-08 05:30:43 +00:00
|
|
|
// g_TweakManager->ReadFromMemoryCard("AudioTweaks");
|
2018-01-16 06:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
static logvisor::Module WarmupLog("ShaderWarmup");
|
2018-10-18 04:51:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::WarmupShaders() {
|
|
|
|
if (m_warmupTags.size())
|
|
|
|
return;
|
2018-10-18 04:51:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_needsWarmupClear = true;
|
|
|
|
size_t modelCount = 0;
|
|
|
|
g_ResFactory->EnumerateResources([&](const SObjectTag& tag) {
|
|
|
|
if (tag.type == FOURCC('CMDL') || tag.type == FOURCC('MREA'))
|
|
|
|
++modelCount;
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
m_warmupTags.reserve(modelCount);
|
2016-04-15 20:42:40 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::unordered_set<SObjectTag> addedTags;
|
|
|
|
addedTags.reserve(modelCount);
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_ResFactory->EnumerateResources([&](const SObjectTag& tag) {
|
|
|
|
if (tag.type == FOURCC('CMDL') || tag.type == FOURCC('MREA')) {
|
|
|
|
if (addedTags.find(tag) != addedTags.end())
|
2017-10-17 05:51:53 +00:00
|
|
|
return true;
|
2018-12-08 05:30:43 +00:00
|
|
|
addedTags.insert(tag);
|
|
|
|
m_warmupTags.push_back(tag);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_warmupIt = m_warmupTags.begin();
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
WarmupLog.report(logvisor::Info, "Began warmup of %" PRISize " objects", m_warmupTags.size());
|
2017-10-17 05:51:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CMain::Proc() {
|
|
|
|
// Warmup cycle overrides update
|
|
|
|
if (m_warmupTags.size())
|
|
|
|
return false;
|
2019-03-09 08:58:27 +00:00
|
|
|
if (!m_loadedPersistentResources) {
|
|
|
|
x128_globalObjects.m_gameResFactory->LoadPersistentResources(*g_SimplePool);
|
|
|
|
m_loadedPersistentResources = true;
|
|
|
|
}
|
2017-10-17 05:51:53 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_console->proc();
|
|
|
|
if (!m_console->isOpen()) {
|
|
|
|
CGBASupport::GlobalPoll();
|
|
|
|
x164_archSupport->UpdateTicks();
|
|
|
|
x164_archSupport->Update();
|
|
|
|
CSfxManager::Update(1.f / 60.f);
|
|
|
|
CStreamAudioManager::Update(1.f / 60.f);
|
|
|
|
}
|
2018-01-15 16:00:20 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x164_archSupport->GetIOWinManager().IsEmpty() || CheckReset()) {
|
|
|
|
CStreamAudioManager::StopAll();
|
|
|
|
/*
|
|
|
|
x164_archSupport.reset();
|
|
|
|
g_archSupport = x164_archSupport.get();
|
|
|
|
x164_archSupport->PreloadAudio();
|
|
|
|
*/
|
|
|
|
x160_24_finished = true;
|
|
|
|
}
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
Discord_RunCallbacks();
|
2018-01-16 06:42:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return x160_24_finished;
|
2016-04-15 20:42:40 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CMain::Draw() {
|
|
|
|
// Warmup cycle overrides draw
|
|
|
|
if (m_warmupTags.size()) {
|
|
|
|
if (m_needsWarmupClear) {
|
|
|
|
CGraphics::g_BooMainCommandQueue->clearTarget(true, true);
|
|
|
|
m_needsWarmupClear = false;
|
2017-10-17 05:51:53 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
auto startTime = std::chrono::steady_clock::now();
|
|
|
|
while (m_warmupIt != m_warmupTags.end()) {
|
|
|
|
WarmupLog.report(logvisor::Info, "[%d / %d] Warming %.4s %08X", int(m_warmupIt - m_warmupTags.begin() + 1),
|
|
|
|
int(m_warmupTags.size()), m_warmupIt->type.getChars(), m_warmupIt->id.Value());
|
|
|
|
|
|
|
|
if (m_warmupIt->type == FOURCC('CMDL'))
|
|
|
|
CModel::WarmupShaders(*m_warmupIt);
|
|
|
|
else if (m_warmupIt->type == FOURCC('MREA'))
|
|
|
|
CGameArea::WarmupShaders(*m_warmupIt);
|
|
|
|
++m_warmupIt;
|
|
|
|
|
|
|
|
// Approximately 3/4 frame of warmups
|
|
|
|
auto curTime = std::chrono::steady_clock::now();
|
|
|
|
if (std::chrono::duration_cast<std::chrono::milliseconds>(curTime - startTime).count() > 12)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (m_warmupIt == m_warmupTags.end()) {
|
|
|
|
m_warmupTags = std::vector<SObjectTag>();
|
|
|
|
WarmupLog.report(logvisor::Info, "Finished warmup");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGraphics::g_BooMainCommandQueue->clearTarget(true, true);
|
|
|
|
x164_archSupport->Draw();
|
|
|
|
m_console->draw(CGraphics::g_BooMainCommandQueue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::ShutdownSubsystems() {
|
|
|
|
CMoviePlayer::Shutdown();
|
|
|
|
CLineRenderer::Shutdown();
|
|
|
|
CDecalManager::Shutdown();
|
|
|
|
CElementGen::Shutdown();
|
|
|
|
CAnimData::FreeCache();
|
|
|
|
CMemoryCardSys::Shutdown();
|
|
|
|
CModelShaders::Shutdown();
|
|
|
|
CMappableObject::Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMain::Shutdown() {
|
|
|
|
m_console->unregisterCommand("Give");
|
2019-03-09 08:58:27 +00:00
|
|
|
x128_globalObjects.m_gameResFactory->UnloadPersistentResources();
|
2018-12-08 05:30:43 +00:00
|
|
|
x164_archSupport.reset();
|
|
|
|
ShutdownSubsystems();
|
|
|
|
CParticleSwooshShaders::Shutdown();
|
|
|
|
CThermalColdFilter::Shutdown();
|
|
|
|
CThermalHotFilter::Shutdown();
|
|
|
|
CSpaceWarpFilter::Shutdown();
|
|
|
|
CCameraBlurFilter::Shutdown();
|
|
|
|
CXRayBlurFilter::Shutdown();
|
|
|
|
CFogVolumePlaneShader::Shutdown();
|
|
|
|
CFogVolumeFilter::Shutdown();
|
|
|
|
CEnergyBarShader::Shutdown();
|
|
|
|
CRadarPaintShader::Shutdown();
|
|
|
|
CMapSurfaceShader::Shutdown();
|
|
|
|
CPhazonSuitFilter::Shutdown();
|
|
|
|
CAABoxShader::Shutdown();
|
|
|
|
CWorldShadowShader::Shutdown();
|
|
|
|
CColoredQuadFilter::Shutdown();
|
2019-01-03 03:47:28 +00:00
|
|
|
CColoredStripShader::Shutdown();
|
2018-12-08 05:30:43 +00:00
|
|
|
CTexturedQuadFilter::Shutdown();
|
|
|
|
CTexturedQuadFilterAlpha::Shutdown();
|
|
|
|
CTextSupportShader::Shutdown();
|
|
|
|
CScanLinesFilter::Shutdown();
|
|
|
|
CRandomStaticFilter::Shutdown();
|
|
|
|
CEnvFxShaders::Shutdown();
|
|
|
|
CFluidPlaneShader::Shutdown();
|
|
|
|
CFluidPlaneManager::RippleMapTex.reset();
|
|
|
|
CNESShader::Shutdown();
|
2019-06-01 03:41:01 +00:00
|
|
|
CBooModel::Shutdown();
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::ShutdownBoo();
|
|
|
|
ShutdownDiscord();
|
|
|
|
}
|
|
|
|
|
|
|
|
boo::IWindow* CMain::GetMainWindow() const { return m_mainWindow; }
|
2017-02-09 09:23:17 +00:00
|
|
|
|
2016-04-15 20:42:40 +00:00
|
|
|
#if MP1_USE_BOO
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int CMain::appMain(boo::IApplication* app) {
|
|
|
|
zeus::detectCPU();
|
|
|
|
mainWindow = app->newWindow(_SYS_STR("Metroid Prime 1 Reimplementation vZygote"), 1);
|
|
|
|
mainWindow->showWindow();
|
|
|
|
TOneStatic<CGameGlobalObjects> globalObjs;
|
|
|
|
InitializeSubsystems();
|
|
|
|
globalObjs->PostInitialize();
|
|
|
|
x70_tweaks.RegisterTweaks();
|
|
|
|
AddWorldPaks();
|
|
|
|
g_TweakManager->ReadFromMemoryCard("AudioTweaks");
|
|
|
|
FillInAssetIDs();
|
|
|
|
TOneStatic<CGameArchitectureSupport> archSupport;
|
|
|
|
mainWindow->setCallback(archSupport.GetAllocSpace());
|
|
|
|
|
|
|
|
boo::IGraphicsCommandQueue* gfxQ = mainWindow->getCommandQueue();
|
|
|
|
boo::SWindowRect windowRect = mainWindow->getWindowFrame();
|
|
|
|
boo::ITextureR* renderTex;
|
|
|
|
boo::GraphicsDataToken data =
|
|
|
|
mainWindow->getMainContextDataFactory()->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool {
|
2016-03-30 19:16:01 +00:00
|
|
|
renderTex = ctx.newRenderTexture(windowRect.size[0], windowRect.size[1], true, true);
|
|
|
|
return true;
|
2018-12-08 05:30:43 +00:00
|
|
|
});
|
|
|
|
float rgba[4] = {0.2f, 0.2f, 0.2f, 1.0f};
|
|
|
|
gfxQ->setClearColor(rgba);
|
|
|
|
|
|
|
|
while (!xe8_b24_finished) {
|
|
|
|
xe8_b24_finished = archSupport->Update();
|
2016-02-20 10:26:43 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (archSupport->isRectDirty()) {
|
|
|
|
const boo::SWindowRect& windowRect = archSupport->getWindowRect();
|
|
|
|
gfxQ->resizeRenderTexture(renderTex, windowRect.size[0], windowRect.size[1]);
|
2015-08-17 05:26:58 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
gfxQ->setRenderTarget(renderTex);
|
|
|
|
gfxQ->clearTarget();
|
|
|
|
gfxQ->resolveDisplay(renderTex);
|
|
|
|
gfxQ->execute();
|
|
|
|
mainWindow->waitForRetrace();
|
|
|
|
}
|
|
|
|
return 0;
|
2015-08-27 00:23:46 +00:00
|
|
|
}
|
2015-08-17 05:26:58 +00:00
|
|
|
|
2016-04-15 20:42:40 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace MP1
|
|
|
|
} // namespace urde
|