Implement --warp command-line arguments

This commit is contained in:
Jack Andersen 2018-10-17 18:51:59 -10:00
parent 8d839d8a17
commit f433821320
10 changed files with 115 additions and 36 deletions

View File

@ -116,6 +116,7 @@ public:
void ExportPersistentOptions(CPersistentOptions& opts) const; void ExportPersistentOptions(CPersistentOptions& opts) const;
void SetGameOptions(const CGameOptions& opts) { x17c_gameOptions = opts; } void SetGameOptions(const CGameOptions& opts) { x17c_gameOptions = opts; }
void WriteBackupBuf(); void WriteBackupBuf();
std::vector<u8>& BackupBuf() { return x218_backupBuf; }
u32 GetFileIdx() const { return x20c_saveFileIdx; } u32 GetFileIdx() const { return x20c_saveFileIdx; }
void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; } void SetFileIdx(u32 idx) { x20c_saveFileIdx = idx; }
void SetCardSerial(u64 serial) { x210_cardSerial = serial; } void SetCardSerial(u64 serial) { x210_cardSerial = serial; }

View File

@ -43,6 +43,8 @@ void CPakFile::LoadResourceTable(athena::io::MemoryReader& r)
CAssetId id = r.readUint32Big(); CAssetId id = r.readUint32Big();
u32 size = r.readUint32Big(); u32 size = r.readUint32Big();
u32 offset = r.readUint32Big(); u32 offset = r.readUint32Big();
if (fcc == FOURCC('MLVL'))
m_mlvlId = id;
x74_resList.emplace_back(id, fcc, offset, size, flags); x74_resList.emplace_back(id, fcc, offset, size, flags);
if (x28_24_buildDepList) if (x28_24_buildDepList)
x64_depList.push_back(id); x64_depList.push_back(id);

View File

@ -63,6 +63,7 @@ private:
std::vector<CAssetId> x64_depList; std::vector<CAssetId> x64_depList;
std::vector<SResInfo> x74_resList; std::vector<SResInfo> x74_resList;
mutable s32 x84_currentSeek = -1; mutable s32 x84_currentSeek = -1;
CAssetId m_mlvlId;
void LoadResourceTable(athena::io::MemoryReader& r); void LoadResourceTable(athena::io::MemoryReader& r);
void DataLoad(); void DataLoad();
void InitialHeaderLoad(); void InitialHeaderLoad();
@ -79,6 +80,7 @@ public:
bool IsWorldPak() const { return x28_26_worldPak; } bool IsWorldPak() const { return x28_26_worldPak; }
u32 GetFakeStaticSize() const { return 0; } u32 GetFakeStaticSize() const { return 0; }
void AsyncIdle(); void AsyncIdle();
CAssetId GetMLVLId() const { return m_mlvlId; }
}; };
} }

View File

@ -373,12 +373,12 @@ void CBooRenderer::CalcDrawFogFan(const zeus::CPlane* planes, int numPlanes, con
const zeus::CPlane& plane = planes[level]; const zeus::CPlane& plane = planes[level];
u32 insidePlaneCount = 0; u32 insidePlaneCount = 0;
bool outsidePlane[4]; bool outsidePlane[20];
for (int i=0 ; i<numVerts ; ++i) for (int i=0 ; i<numVerts ; ++i)
outsidePlane[insidePlaneCount++] = plane.normal().dot(verts[i]) < plane.d; outsidePlane[insidePlaneCount++] = plane.normal().dot(verts[i]) < plane.d;
u32 numUseVerts = 0; u32 numUseVerts = 0;
zeus::CVector3f useVerts[4]; zeus::CVector3f useVerts[20];
for (int i=0 ; i<numVerts ; ++i) for (int i=0 ; i<numVerts ; ++i)
{ {
int nextIdx = (i + 1) % numVerts; int nextIdx = (i + 1) % numVerts;

View File

@ -39,34 +39,19 @@ void CFogVolumePlaneShader::CommitResources(size_t capacity)
void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts) void CFogVolumePlaneShader::addFan(const zeus::CVector3f* verts, int numVerts)
{ {
if (numVerts == 3)
{
zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true); zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true);
zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]); zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]);
if (m_verts.size()) if (m_verts.size())
{ {
m_verts.push_back(m_verts.back()); m_verts.push_back(m_verts.back());
m_verts.push_back(vert0); m_verts.push_back(vert0);
} if (m_verts.size() & 1)
m_verts.push_back(vert0);
m_verts.push_back(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[1]));
m_verts.push_back(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[2]));
m_verts.push_back(m_verts.back());
}
else if (numVerts == 4)
{
zeus::CMatrix4f proj = CGraphics::GetPerspectiveProjectionMatrix(true);
zeus::CVector4f vert0 = proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[0]);
if (m_verts.size())
{
m_verts.push_back(m_verts.back());
m_verts.push_back(vert0); m_verts.push_back(vert0);
} }
m_verts.push_back(vert0); TriFanToStrip<zeus::CVector4f> fanToStrip(m_verts);
m_verts.push_back(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[1])); fanToStrip.AddVert(vert0);
m_verts.push_back(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[3])); for (int i = 1; i < numVerts; ++i)
m_verts.push_back(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[2])); fanToStrip.AddVert(proj * zeus::CVector4f(CGraphics::g_GXModelView * verts[i]));
}
} }
void CFogVolumePlaneShader::draw(int pass) void CFogVolumePlaneShader::draw(int pass)

View File

@ -2007,7 +2007,6 @@ CFrontEndUI::CFrontEndUI()
m->ResetGameState(); m->ResetGameState();
g_GameState->SetCurrentWorldId(g_ResFactory->TranslateOriginalToNew(g_DefaultWorldTag.id)); g_GameState->SetCurrentWorldId(g_ResFactory->TranslateOriginalToNew(g_DefaultWorldTag.id));
g_GameState->CurrentWorldState().SetAreaId(7);
g_GameState->GameOptions().ResetToDefaults(); g_GameState->GameOptions().ResetToDefaults();
g_GameState->WriteBackupBuf(); g_GameState->WriteBackupBuf();
@ -2016,8 +2015,6 @@ CFrontEndUI::CFrontEndUI()
m_touchBar = NewFrontEndUITouchBar(); m_touchBar = NewFrontEndUITouchBar();
m_touchBar->SetPhase(CFrontEndUITouchBar::EPhase::None); m_touchBar->SetPhase(CFrontEndUITouchBar::EPhase::None);
x14_phase = EPhase::ExitFrontEnd;
} }
void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue) void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue)

View File

@ -1,20 +1,54 @@
#include "CStateSetterFlow.hpp" #include "CStateSetterFlow.hpp"
#include "CArchitectureMessage.hpp" #include "CArchitectureMessage.hpp"
#include "GameGlobalObjects.hpp" #include "GameGlobalObjects.hpp"
#include "MP1.hpp"
namespace urde::MP1 namespace urde::MP1
{ {
CStateSetterFlow::CStateSetterFlow() CStateSetterFlow::CStateSetterFlow()
: CIOWin("") : CIOWin("") {}
{
}
CIOWin::EMessageReturn CStateSetterFlow::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue) CIOWin::EMessageReturn CStateSetterFlow::OnMessage(const CArchitectureMessage& msg, CArchitectureQueue& queue)
{ {
if (msg.GetType() == EArchMsgType::TimerTick) if (msg.GetType() == EArchMsgType::TimerTick)
{ {
//g_Main->sub80004590(); MP1::CMain* m = static_cast<MP1::CMain*>(g_Main);
if (m->m_warpWorldIdx > -1)
{
CResLoader* loader = g_ResFactory->GetResLoader();
CAssetId worldId;
for (const auto& pak : loader->GetPaks())
{
if (*(pak->GetPath().end() - 6) == '0' + m->m_warpWorldIdx)
{
worldId = pak->GetMLVLId();
break;
}
}
if (worldId.IsValid())
{
m->ResetGameState();
g_GameState->SetCurrentWorldId(worldId);
CWorldLayerState& layers = *g_GameState->StateForWorld(worldId).GetLayerState();
if (m->m_warpAreaId < layers.GetAreaCount())
{
g_GameState->StateForWorld(worldId).SetAreaId(m->m_warpAreaId);
if (m->m_warpLayerBits)
{
for (u32 i = 0; i < layers.GetAreaLayerCount(m->m_warpAreaId); ++i)
layers.SetLayerActive(m->m_warpAreaId, i, ((m->m_warpLayerBits >> i) & 1) != 0);
}
}
g_GameState->GameOptions().ResetToDefaults();
g_GameState->WriteBackupBuf();
return EMessageReturn::RemoveIOWinAndExit;
}
}
m->RefreshGameState();
return EMessageReturn::RemoveIOWinAndExit; return EMessageReturn::RemoveIOWinAndExit;
} }
return EMessageReturn::Exit; return EMessageReturn::Exit;

View File

@ -622,6 +622,22 @@ void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx)
g_GameState->HintOptions().SetNextHintTime(); g_GameState->HintOptions().SetNextHintTime();
} }
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());
}
static logvisor::Module DiscordLog("Discord"); static logvisor::Module DiscordLog("Discord");
static const char* DISCORD_APPLICATION_ID = "402571593815031819"; static const char* DISCORD_APPLICATION_ID = "402571593815031819";
static int64_t DiscordStartTime; static int64_t DiscordStartTime;
@ -720,6 +736,35 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr,
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); 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);
m_console->registerCommand("WarpTo"sv, "Warps to a given area and world"sv, "[worldname] areaId"sv, std::bind(&CMain::WarpTo, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Normal); m_console->registerCommand("WarpTo"sv, "Warps to a given area and world"sv, "[worldname] areaId"sv, std::bind(&CMain::WarpTo, this, std::placeholders::_1, std::placeholders::_2), hecl::SConsoleCommand::ECommandFlags::Normal);
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;
m_warpWorldIdx = hecl::StrToUl(worldIdxStr, &endptr, 0);
if (endptr == worldIdxStr)
m_warpWorldIdx = 0;
m_warpAreaId = hecl::StrToUl(areaIdxStr, &endptr, 0);
if (endptr == areaIdxStr)
m_warpAreaId = 0;
if (args.end() - it >= 4)
{
const hecl::SystemChar* layerStr = (*(it + 3)).c_str();
if (layerStr[0] == _SYS_STR('0') || layerStr[0] == _SYS_STR('1'))
for (const auto* cur = layerStr; *cur != _SYS_STR('\0'); ++cur)
if (*cur == _SYS_STR('1'))
m_warpLayerBits |= 1 << (cur - layerStr);
}
SetFlowState(EFlowState::StateSetter);
}
}
InitializeSubsystems(); InitializeSubsystems();
x128_globalObjects.PostInitialize(); x128_globalObjects.PostInitialize();
x70_tweaks.RegisterTweaks(m_cvarMgr); x70_tweaks.RegisterTweaks(m_cvarMgr);
@ -730,8 +775,6 @@ void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr,
g_archSupport = x164_archSupport.get(); g_archSupport = x164_archSupport.get();
x164_archSupport->PreloadAudio(); x164_archSupport->PreloadAudio();
//g_TweakManager->ReadFromMemoryCard("AudioTweaks"); //g_TweakManager->ReadFromMemoryCard("AudioTweaks");
//CStreamAudioManager::Start(false, "Audio/rui_samusL.dsp|Audio/rui_samusR.dsp", 0x7f, true, 1.f, 1.f);
} }
static logvisor::Module WarmupLog("ShaderWarmup"); static logvisor::Module WarmupLog("ShaderWarmup");

View File

@ -118,6 +118,12 @@ public:
x134_gameState.reset(new CGameState()); x134_gameState.reset(new CGameState());
g_GameState = x134_gameState.get(); g_GameState = x134_gameState.get();
} }
void StreamInGameState(CBitStreamReader& stream, u32 saveIdx)
{
x134_gameState.reset(new CGameState(stream, saveIdx));
g_GameState = x134_gameState.get();
}
}; };
#if MP1_USE_BOO #if MP1_USE_BOO
@ -281,6 +287,7 @@ public:
void AddWorldPaks(); void AddWorldPaks();
void ResetGameState(); void ResetGameState();
void StreamNewGameState(CBitStreamReader&, u32 idx); void StreamNewGameState(CBitStreamReader&, u32 idx);
void RefreshGameState();
void CheckTweakManagerDebugOptions() {} void CheckTweakManagerDebugOptions() {}
void SetMFGameBuilt(bool b) { x160_25_mfGameBuilt = b; } void SetMFGameBuilt(bool b) { x160_25_mfGameBuilt = b; }
void SetScreenFading(bool b) { x160_26_screenFading = b; } void SetScreenFading(bool b) { x160_26_screenFading = b; }
@ -336,6 +343,10 @@ public:
void ListWorlds(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>&); void WarpTo(hecl::Console*, const std::vector<std::string>&);
hecl::Console* Console() const { return m_console.get(); } hecl::Console* Console() const { return m_console.get(); }
int m_warpWorldIdx = -1;
TAreaId m_warpAreaId = 0;
u64 m_warpLayerBits = 0;
}; };
} }

View File

@ -6,6 +6,7 @@
#depthtest lequal #depthtest lequal
#depthwrite true #depthwrite true
#colorwrite false #colorwrite false
#alphawrite true
#culling frontface #culling frontface
#vertex glsl #vertex glsl
@ -72,16 +73,19 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]])
#depthtest none #depthtest none
#depthwrite false #depthwrite false
#colorwrite false #colorwrite false
#alphawrite true
#culling frontface #culling frontface
#shader CFogVolumePlaneShader2 : CFogVolumePlaneShader0 #shader CFogVolumePlaneShader2 : CFogVolumePlaneShader0
#depthtest lequal #depthtest lequal
#depthwrite true #depthwrite true
#colorwrite false #colorwrite false
#alphawrite true
#culling backface #culling backface
#shader CFogVolumePlaneShader3 : CFogVolumePlaneShader0 #shader CFogVolumePlaneShader3 : CFogVolumePlaneShader0
#depthtest greater #depthtest greater
#depthwrite false #depthwrite false
#colorwrite false #colorwrite false
#alphawrite true
#culling backface #culling backface