metaforce/Runtime/AutoMapper/CAutoMapper.cpp

1627 lines
70 KiB
C++
Raw Normal View History

2016-07-29 17:00:23 +00:00
#include "CAutoMapper.hpp"
2017-03-20 05:09:53 +00:00
#include "CSimplePool.hpp"
#include "GameGlobalObjects.hpp"
#include "Camera/CGameCamera.hpp"
#include "AutoMapper/CMapUniverse.hpp"
#include "AutoMapper/CMapArea.hpp"
#include "zeus/CEulerAngles.hpp"
#include "World/CPlayer.hpp"
2017-03-20 06:59:46 +00:00
#include "Particle/CGenDescription.hpp"
2017-04-15 05:32:25 +00:00
#include "MP1/MP1.hpp"
#include "Input/ControlMapper.hpp"
2017-04-16 05:52:43 +00:00
#include "GuiSys/CGuiFrame.hpp"
#include "GuiSys/CGuiTextPane.hpp"
#include "GuiSys/CGuiWidgetDrawParms.hpp"
2016-07-29 17:00:23 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
2016-07-29 17:00:23 +00:00
2017-04-15 05:32:25 +00:00
void CAutoMapper::SAutoMapperRenderState::InterpolateWithClamp(const SAutoMapperRenderState& a,
SAutoMapperRenderState& out,
2018-12-08 05:30:43 +00:00
const SAutoMapperRenderState& b, float t) {
t = zeus::clamp(0.f, t, 1.f);
float easeIn = zeus::clamp(0.f, t * t * t, 1.f);
float omt = 1.f - t;
float easeOut = zeus::clamp(0.f, 1.f - omt * omt * omt, 1.f);
float easeInOut;
if (t >= 0.5f)
easeInOut = zeus::clamp(0.f, 0.5f * std::sqrt(2.f * t - 1.f) + 0.5f, 1.f);
else
easeInOut = zeus::clamp(0.f, 1.f - (0.5f * std::sqrt(2.f * omt - 1.f) + 0.5f), 1.f);
float eases[5] = {};
eases[1] = t;
eases[2] = easeOut;
eases[3] = easeIn;
eases[4] = easeInOut;
if (b.x44_viewportEase != Ease::None) {
float easeB = eases[int(b.x44_viewportEase)];
float easeA = 1.f - easeB;
zeus::CVector2i vpA = a.GetViewportSize();
zeus::CVector2i vpB = b.GetViewportSize();
out.x0_viewportSize = zeus::CVector2i(vpB.x * easeB + vpA.x * easeA, vpB.y * easeB + vpA.y * easeA);
}
if (t == 1.f)
out.m_getViewportSize = b.m_getViewportSize;
else
out.m_getViewportSize = nullptr;
if (b.x48_camEase != Ease::None) {
float easeB = eases[int(b.x48_camEase)];
float easeA = 1.f - easeB;
out.x8_camOrientation = zeus::CQuaternion::slerp(a.x8_camOrientation, b.x8_camOrientation, easeB);
out.x18_camDist = b.x18_camDist * easeB + a.x18_camDist * easeA;
out.x1c_camAngle = b.x1c_camAngle * easeB + a.x1c_camAngle * easeA;
}
if (b.x4c_pointEase != Ease::None) {
float easeB = eases[int(b.x4c_pointEase)];
float easeA = 1.f - easeB;
out.x20_areaPoint = b.x20_areaPoint * easeB + a.x20_areaPoint * easeA;
}
if (b.x50_depth1Ease != Ease::None) {
float easeB = eases[int(b.x50_depth1Ease)];
float easeA = 1.f - easeB;
out.x2c_drawDepth1 = b.x2c_drawDepth1 * easeB + a.x2c_drawDepth1 * easeA;
}
if (b.x54_depth2Ease != Ease::None) {
float easeB = eases[int(b.x54_depth2Ease)];
float easeA = 1.f - easeB;
out.x30_drawDepth2 = b.x30_drawDepth2 * easeB + a.x30_drawDepth2 * easeA;
}
if (b.x58_alphaEase != Ease::None) {
float easeB = eases[int(b.x58_alphaEase)];
float easeA = 1.f - easeB;
out.x34_alphaSurfaceVisited = b.x34_alphaSurfaceVisited * easeB + a.x34_alphaSurfaceVisited * easeA;
out.x38_alphaOutlineVisited = b.x38_alphaOutlineVisited * easeB + a.x38_alphaOutlineVisited * easeA;
out.x3c_alphaSurfaceUnvisited = b.x3c_alphaSurfaceUnvisited * easeB + a.x3c_alphaSurfaceUnvisited * easeA;
out.x40_alphaOutlineUnvisited = b.x40_alphaOutlineUnvisited * easeB + a.x40_alphaOutlineUnvisited * easeA;
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
CAutoMapper::CAutoMapper(CStateManager& stateMgr) : x24_world(stateMgr.GetWorld()) {
x8_mapu = g_SimplePool->GetObj("MAPU_MapUniverse");
x30_miniMapSamus = g_SimplePool->GetObj("CMDL_MiniMapSamus");
x3c_hintBeacon = g_SimplePool->GetObj("TXTR_HintBeacon");
xa0_curAreaId = xa4_otherAreaId = stateMgr.GetWorld()->IGetCurrentAreaId();
zeus::CMatrix3f camRot = stateMgr.GetCameraManager()->GetCurrentCamera(stateMgr)->GetTransform().buildMatrix3f();
xa8_renderStates[0] = xa8_renderStates[1] = xa8_renderStates[2] =
BuildMiniMapWorldRenderState(stateMgr, camRot, xa0_curAreaId);
x48_mapIcons.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x4_saveStationIcon}));
x48_mapIcons.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x8_missileStationIcon}));
x48_mapIcons.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->xc_elevatorIcon}));
x48_mapIcons.push_back(
g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x10_minesBreakFirstTopIcon}));
x48_mapIcons.push_back(
g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x14_minesBreakFirstBottomIcon}));
for (u32 i = 0; i < 9; ++i) {
x210_lstick.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x24_lStick[i]}));
x25c_cstick.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x4c_cStick[i]}));
}
for (u32 i = 0; i < 2; ++i) {
x2a8_ltrigger.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x74_lTrigger[i]}));
x2bc_rtrigger.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x80_rTrigger[i]}));
x2d0_abutton.push_back(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), g_tweakPlayerRes->x98_aButton[i]}));
}
2017-02-12 03:17:18 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAutoMapper::CheckLoadComplete() {
switch (x4_loadPhase) {
case ELoadPhase::LoadResources:
for (TLockedToken<CTexture>& tex : x48_mapIcons)
if (!tex.IsLoaded())
return false;
if (!x30_miniMapSamus.IsLoaded())
return false;
if (!x3c_hintBeacon.IsLoaded())
return false;
x4_loadPhase = ELoadPhase::LoadUniverse;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case ELoadPhase::LoadUniverse:
if (!x8_mapu.IsLoaded())
return false;
x14_dummyWorlds.resize(x8_mapu->GetNumMapWorldDatas());
SetCurWorldAssetId(x24_world->IGetWorldAssetId());
x4_loadPhase = ELoadPhase::Done;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case ELoadPhase::Done:
return true;
default:
break;
}
return false;
2017-02-12 03:17:18 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAutoMapper::NotHintNavigating() const { return x1e0_hintSteps.empty(); }
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
bool CAutoMapper::CanLeaveMapScreenInternal(const CStateManager& mgr) const {
if (!NotHintNavigating())
return false;
if (IsRenderStateInterpolating())
2017-04-15 05:32:25 +00:00
return false;
2018-12-08 05:30:43 +00:00
if (IsInMapperState(EAutoMapperState::MapScreenUniverse))
return true;
if (x24_world != mgr.GetWorld())
return false;
if (IsInMapperState(EAutoMapperState::MapScreen))
return true;
return false;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::LeaveMapScreen(const CStateManager& mgr) {
if (x1c0_nextState == EAutoMapperState::MapScreenUniverse) {
xa8_renderStates[1].x2c_drawDepth1 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[1].x30_drawDepth2 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[0].x2c_drawDepth1 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[0].x30_drawDepth2 = GetMapAreaMiniMapDrawDepth();
SetupMiniMapWorld(mgr);
} else {
x328_ = 2;
xa8_renderStates[1] = xa8_renderStates[0];
xa8_renderStates[2] = xa8_renderStates[1];
xa0_curAreaId = x24_world->IGetCurrentAreaId();
xa8_renderStates[1].x20_areaPoint = GetAreaPointOfInterest(mgr, xa0_curAreaId);
xa8_renderStates[1].x4c_pointEase = SAutoMapperRenderState::Ease::Linear;
xa8_renderStates[1].x2c_drawDepth1 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[1].x30_drawDepth2 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[1].x50_depth1Ease = SAutoMapperRenderState::Ease::Linear;
xa8_renderStates[1].x54_depth2Ease = SAutoMapperRenderState::Ease::Linear;
ResetInterpolationTimer(0.25f);
}
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetupMiniMapWorld(const CStateManager& mgr) {
const CWorld& wld = *mgr.GetWorld();
const_cast<CMapWorld*>(wld.GetMapWorld())->SetWhichMapAreasLoaded(wld, wld.GetCurrentAreaId(), 3);
x328_ = 3;
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAutoMapper::HasCurrentMapUniverseWorld() const {
CAssetId mlvlId = x24_world->IGetWorldAssetId();
for (const CMapUniverse::CMapWorldData& wld : *x8_mapu)
if (wld.GetWorldAssetId() == mlvlId)
return true;
return false;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAutoMapper::CheckDummyWorldLoad(const CStateManager& mgr) {
const CMapUniverse::CMapWorldData& mapuWld = x8_mapu->GetMapWorldData(x9c_worldIdx);
auto& dummyWorld = x14_dummyWorlds[x9c_worldIdx];
if (!dummyWorld) {
x32c_loadingDummyWorld = false;
return false;
}
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
if (!dummyWorld->ICheckWorldComplete())
return true;
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
CWorldState& worldState = g_GameState->StateForWorld(dummyWorld->IGetWorldAssetId());
CMapWorldInfo& mwInfo = *worldState.MapWorldInfo();
zeus::CVector3f localPoint = mapuWld.GetWorldTransform().inverse() * xa8_renderStates[0].x20_areaPoint;
zeus::CMatrix3f camRot = xa8_renderStates[0].x8_camOrientation.toTransform().buildMatrix3f();
TAreaId aid = FindClosestVisibleArea(localPoint, zeus::CUnitVector3f(camRot[1]), mgr, *dummyWorld, mwInfo);
if (aid == -1) {
2017-04-15 05:32:25 +00:00
x32c_loadingDummyWorld = false;
2018-12-08 05:30:43 +00:00
return false;
}
xa0_curAreaId = aid;
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
dummyWorld->IMapWorld()->RecalculateWorldSphere(mwInfo, *dummyWorld);
BeginMapperStateTransition(EAutoMapperState::MapScreen, mgr);
x32c_loadingDummyWorld = false;
return true;
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::UpdateHintNavigation(float dt, const CStateManager& mgr) {
SAutoMapperHintStep& nextStep = x1e0_hintSteps.front();
bool oldProcessing = nextStep.x8_processing;
nextStep.x8_processing = true;
switch (nextStep.x0_type) {
case SAutoMapperHintStep::Type::PanToArea: {
if (x24_world->IGetMapWorld()->GetMapArea(nextStep.x4_areaId)) {
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1].x20_areaPoint = GetAreaPointOfInterest(mgr, nextStep.x4_areaId);
xa8_renderStates[1].ResetInterpolation();
2018-12-31 05:01:42 +00:00
xa8_renderStates[1].x4c_pointEase = SAutoMapperRenderState::Ease::Linear;
2018-12-08 05:30:43 +00:00
ResetInterpolationTimer(2.f * g_tweakAutoMapper->GetHintPanTime());
x1e0_hintSteps.pop_front();
}
break;
}
case SAutoMapperHintStep::Type::PanToWorld: {
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldDataByWorldId(nextStep.x4_worldId);
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1].x20_areaPoint = mwData.GetWorldCenterPoint();
xa8_renderStates[1].ResetInterpolation();
2018-12-31 05:01:42 +00:00
xa8_renderStates[1].x4c_pointEase = SAutoMapperRenderState::Ease::Linear;
2018-12-08 05:30:43 +00:00
ResetInterpolationTimer(2.f * g_tweakAutoMapper->GetHintPanTime());
x1e0_hintSteps.pop_front();
break;
}
case SAutoMapperHintStep::Type::SwitchToUniverse: {
if (HasCurrentMapUniverseWorld()) {
BeginMapperStateTransition(EAutoMapperState::MapScreenUniverse, mgr);
x1e0_hintSteps.pop_front();
} else {
x1e0_hintSteps.clear();
}
break;
}
case SAutoMapperHintStep::Type::SwitchToWorld: {
x1e0_hintSteps.pop_front();
x32c_loadingDummyWorld = true;
if (CheckDummyWorldLoad(mgr))
break;
x1e0_hintSteps.clear();
break;
}
case SAutoMapperHintStep::Type::ShowBeacon: {
if (!oldProcessing) {
if (xa0_curAreaId == mgr.GetNextAreaId() && x24_world == mgr.GetWorld())
CSfxManager::SfxStart(SFXui_show_local_beacon, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
else
CSfxManager::SfxStart(SFXui_show_remote_beacon, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
}
nextStep.x4_float = std::max(0.f, nextStep.x4_float - dt);
for (SAutoMapperHintLocation& loc : x1f8_hintLocations) {
if (x24_world->IGetWorldAssetId() == loc.x8_worldId && xa0_curAreaId == loc.xc_areaId) {
2018-12-31 05:01:42 +00:00
loc.x0_showBeacon = 1;
loc.x4_beaconAlpha = 1.f - std::min(nextStep.x4_float / 0.5f, 1.f);
2018-12-08 05:30:43 +00:00
break;
}
}
if (nextStep.x4_float != 0.f)
break;
x1e0_hintSteps.pop_front();
break;
}
case SAutoMapperHintStep::Type::ZoomOut: {
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1].x18_camDist = g_tweakAutoMapper->GetMaxCamDist();
xa8_renderStates[1].ResetInterpolation();
xa8_renderStates[1].x48_camEase = SAutoMapperRenderState::Ease::Linear;
ResetInterpolationTimer(0.5f);
x1e0_hintSteps.pop_front();
break;
}
case SAutoMapperHintStep::Type::ZoomIn: {
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1].x18_camDist = g_tweakAutoMapper->GetCamDist();
xa8_renderStates[1].ResetInterpolation();
xa8_renderStates[1].x48_camEase = SAutoMapperRenderState::Ease::Linear;
ResetInterpolationTimer(0.5f);
x1e0_hintSteps.pop_front();
break;
}
default:
break;
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
bool CAutoMapper::CanLeaveMapScreen(const CStateManager& mgr) const {
return x328_ == 3 && CanLeaveMapScreenInternal(mgr);
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetCurWorldAssetId(CAssetId mlvlId) {
u32 numWorlds = x8_mapu->GetNumMapWorldDatas();
for (u32 i = 0; i < numWorlds; ++i)
if (x8_mapu->GetMapWorldData(i).GetWorldAssetId() == mlvlId) {
x9c_worldIdx = i;
break;
2017-04-15 05:32:25 +00:00
}
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::BeginMapperStateTransition(EAutoMapperState state, const CStateManager& mgr) {
if (state == x1c0_nextState)
return;
if ((state == EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) ||
(state != EAutoMapperState::MiniMap && x1c0_nextState == EAutoMapperState::MiniMap))
CSfxManager::KillAll(CSfxManager::ESfxChannels::PauseScreen);
x1bc_state = x1c0_nextState;
x1c0_nextState = state;
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1] = xa8_renderStates[0];
if (x1bc_state == EAutoMapperState::MiniMap && state == EAutoMapperState::MapScreen) {
xa8_renderStates[1] =
BuildMapScreenWorldRenderState(mgr, xa8_renderStates[0].x8_camOrientation, xa0_curAreaId, false);
ResetInterpolationTimer(g_tweakAutoMapper->GetOpenMapScreenTime());
} else if (x1bc_state == EAutoMapperState::MapScreen && state == EAutoMapperState::MiniMap) {
xa0_curAreaId = x24_world->IGetCurrentAreaId();
xa8_renderStates[1] = BuildMiniMapWorldRenderState(mgr, xa8_renderStates[0].x8_camOrientation, xa0_curAreaId);
ResetInterpolationTimer(g_tweakAutoMapper->GetCloseMapScreenTime());
x1f8_hintLocations.clear();
} else if (x1bc_state == EAutoMapperState::MapScreen && state == EAutoMapperState::MapScreenUniverse) {
CSfxManager::SfxStart(SFXui_map_to_universe, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
xa8_renderStates[1] = BuildMapScreenUniverseRenderState(mgr, xa8_renderStates[0].x8_camOrientation, xa0_curAreaId);
TransformRenderStatesWorldToUniverse();
ResetInterpolationTimer(g_tweakAutoMapper->GetSwitchToFromUniverseTime());
} else if (x1bc_state == EAutoMapperState::MapScreenUniverse && state == EAutoMapperState::MapScreen) {
CSfxManager::SfxStart(SFXui_map_from_universe, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
xa8_renderStates[1] = BuildMapScreenWorldRenderState(mgr, xa8_renderStates[0].x8_camOrientation, xa0_curAreaId,
x1e0_hintSteps.size());
TransformRenderStateWorldToUniverse(xa8_renderStates[1]);
ResetInterpolationTimer(g_tweakAutoMapper->GetSwitchToFromUniverseTime());
for (auto& wld : x14_dummyWorlds) {
if (wld.get() != x24_world || x24_world == mgr.GetWorld())
wld.reset();
}
} else if (x1bc_state == EAutoMapperState::MapScreenUniverse && state == EAutoMapperState::MiniMap) {
x24_world = mgr.GetWorld();
xa0_curAreaId = x24_world->IGetCurrentAreaId();
xa8_renderStates[1] = BuildMiniMapWorldRenderState(mgr, xa8_renderStates[0].x8_camOrientation, xa0_curAreaId);
SetCurWorldAssetId(x24_world->IGetWorldAssetId());
TransformRenderStateWorldToUniverse(xa8_renderStates[1]);
ResetInterpolationTimer(g_tweakAutoMapper->GetCloseMapScreenTime());
x1f8_hintLocations.clear();
for (auto& wld : x14_dummyWorlds) {
if (wld.get() != x24_world || x24_world == mgr.GetWorld())
wld.reset();
2017-11-16 08:05:10 +00:00
}
2018-12-08 05:30:43 +00:00
}
}
2017-11-16 08:05:10 +00:00
2018-12-08 05:30:43 +00:00
void CAutoMapper::CompleteMapperStateTransition(const CStateManager& mgr) {
if (x1bc_state == EAutoMapperState::MapScreenUniverse)
TransformRenderStatesUniverseToWorld();
2017-11-16 08:05:10 +00:00
2018-12-08 05:30:43 +00:00
if (x1c0_nextState == EAutoMapperState::MapScreen) {
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
x24_world->IGetMapWorld()->RecalculateWorldSphere(mwInfo, *x24_world);
x1d8_flashTimer = 0.f;
x1dc_playerFlashPulse = 0.f;
}
if (x1c0_nextState == EAutoMapperState::MiniMap) {
x28_frmeMapScreen = TLockedToken<CGuiFrame>();
m_frmeInitialized = false;
x2fc_textpane_hint = nullptr;
x300_textpane_instructions = nullptr;
x304_textpane_instructions1 = nullptr;
x308_textpane_instructions2 = nullptr;
x2f8_textpane_areaname = nullptr;
x30c_basewidget_leftPane = nullptr;
x310_basewidget_yButtonPane = nullptr;
x314_basewidget_bottomPane = nullptr;
SetResLockState(x210_lstick, false);
SetResLockState(x25c_cstick, false);
SetResLockState(x2a8_ltrigger, false);
SetResLockState(x2bc_rtrigger, false);
SetResLockState(x2d0_abutton, false);
}
if (x1c0_nextState == EAutoMapperState::MapScreenUniverse && x328_ == 1)
LeaveMapScreen(mgr);
x1bc_state = x1c0_nextState;
}
2017-11-16 08:05:10 +00:00
2018-12-08 05:30:43 +00:00
void CAutoMapper::ResetInterpolationTimer(float t) {
x1c4_interpDur = t;
x1c8_interpTime = 0.f;
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
CAutoMapper::SAutoMapperRenderState CAutoMapper::BuildMiniMapWorldRenderState(const CStateManager& stateMgr,
const zeus::CQuaternion& rot,
TAreaId area) const {
zeus::CQuaternion camOrient = GetMiniMapCameraOrientation(stateMgr);
zeus::CQuaternion useOrient = (camOrient.dot(rot) >= 0.f) ? camOrient : camOrient.buildEquivalent();
SAutoMapperRenderState ret(
GetMiniMapViewportSize, useOrient, g_tweakAutoMapper->GetMiniCamDist(), g_tweakAutoMapper->GetMiniCamAngle(),
GetAreaPointOfInterest(stateMgr, area), GetMapAreaMiniMapDrawDepth(), GetMapAreaMiniMapDrawDepth(),
GetMapAreaMiniMapDrawAlphaSurfaceVisited(stateMgr), GetMapAreaMiniMapDrawAlphaOutlineVisited(stateMgr),
GetMapAreaMiniMapDrawAlphaSurfaceUnvisited(stateMgr), GetMapAreaMiniMapDrawAlphaOutlineUnvisited(stateMgr));
ret.x44_viewportEase = SAutoMapperRenderState::Ease::Out;
ret.x48_camEase = SAutoMapperRenderState::Ease::Out;
ret.x4c_pointEase = SAutoMapperRenderState::Ease::Out;
ret.x50_depth1Ease = SAutoMapperRenderState::Ease::Linear;
ret.x54_depth2Ease = SAutoMapperRenderState::Ease::In;
ret.x58_alphaEase = SAutoMapperRenderState::Ease::Linear;
return ret;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
CAutoMapper::SAutoMapperRenderState CAutoMapper::BuildMapScreenWorldRenderState(const CStateManager& mgr,
const zeus::CQuaternion& rot,
TAreaId area, bool doingHint) const {
float camDist = doingHint ? g_tweakAutoMapper->GetMaxCamDist() : g_tweakAutoMapper->GetCamDist();
SAutoMapperRenderState ret(GetMapScreenViewportSize, rot, camDist, g_tweakAutoMapper->GetCamAngle(),
GetAreaPointOfInterest(mgr, area), GetMapAreaMaxDrawDepth(mgr, area),
GetMapAreaMaxDrawDepth(mgr, area), g_tweakAutoMapper->GetAlphaSurfaceVisited(),
g_tweakAutoMapper->GetAlphaOutlineVisited(), g_tweakAutoMapper->GetAlphaSurfaceUnvisited(),
g_tweakAutoMapper->GetAlphaOutlineUnvisited());
ret.x44_viewportEase = SAutoMapperRenderState::Ease::Out;
ret.x48_camEase = SAutoMapperRenderState::Ease::Linear;
ret.x4c_pointEase = SAutoMapperRenderState::Ease::Out;
ret.x50_depth1Ease = SAutoMapperRenderState::Ease::Linear;
ret.x54_depth2Ease = SAutoMapperRenderState::Ease::Out;
ret.x58_alphaEase = SAutoMapperRenderState::Ease::Linear;
return ret;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
CAutoMapper::SAutoMapperRenderState CAutoMapper::BuildMapScreenUniverseRenderState(const CStateManager& mgr,
const zeus::CQuaternion& rot,
TAreaId area) const {
SAutoMapperRenderState ret(GetMapScreenViewportSize, rot, g_tweakAutoMapper->GetUniverseCamDist(),
g_tweakAutoMapper->GetCamAngle(), GetAreaPointOfInterest(mgr, area),
GetMapAreaMaxDrawDepth(mgr, area), GetMapAreaMaxDrawDepth(mgr, area), 0.f, 0.f, 0.f, 0.f);
ret.x44_viewportEase = SAutoMapperRenderState::Ease::Out;
ret.x48_camEase = SAutoMapperRenderState::Ease::Linear;
ret.x4c_pointEase = SAutoMapperRenderState::Ease::Out;
ret.x50_depth1Ease = SAutoMapperRenderState::Ease::Linear;
ret.x54_depth2Ease = SAutoMapperRenderState::Ease::Out;
ret.x58_alphaEase = SAutoMapperRenderState::Ease::Linear;
return ret;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::LeaveMapScreenState() {
SetShouldPanningSoundBePlaying(false);
SetShouldZoomingSoundBePlaying(false);
SetShouldRotatingSoundBePlaying(false);
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetBaseMapScreenCameraMoveSpeed() { return g_tweakAutoMapper->GetBaseMapScreenCameraMoveSpeed(); }
float CAutoMapper::GetFinalMapScreenCameraMoveSpeed() const {
float ret = GetBaseMapScreenCameraMoveSpeed();
if (g_tweakAutoMapper->GetScaleMoveSpeedWithCamDist())
ret = ret * xa8_renderStates[0].x18_camDist / g_tweakAutoMapper->GetCamDist();
return ret;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::ProcessMapRotateInput(const CFinalInput& input, const CStateManager& mgr) {
float up = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleUp, input);
float down = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleDown, input);
float left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleLeft, input);
float right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapCircleRight, input);
2019-01-23 07:52:19 +00:00
2019-01-31 07:52:21 +00:00
float dirs[4] = {};
2019-01-23 07:52:19 +00:00
bool mouseHeld = false;
if (const auto& kbm = input.GetKBM()) {
2019-01-31 07:52:21 +00:00
if (kbm->m_mouseButtons[int(boo::EMouseButton::Primary)]) {
2019-01-23 07:52:19 +00:00
mouseHeld = true;
if (float(m_mouseDelta.x()) < 0.f)
2019-01-31 07:52:21 +00:00
dirs[3] = -m_mouseDelta.x();
2019-01-23 07:52:19 +00:00
else if (float(m_mouseDelta.x()) > 0.f)
2019-01-31 07:52:21 +00:00
dirs[2] = m_mouseDelta.x();
2019-01-23 07:52:19 +00:00
if (float(m_mouseDelta.y()) < 0.f)
2019-01-31 07:52:21 +00:00
dirs[0] = -m_mouseDelta.y();
2019-01-23 07:52:19 +00:00
else if (float(m_mouseDelta.y()) > 0.f)
2019-01-31 07:52:21 +00:00
dirs[1] = m_mouseDelta.y();
2019-01-23 07:52:19 +00:00
}
2018-12-08 05:30:43 +00:00
}
float maxMag = up;
int dirSlot = 0;
if (down > up) {
maxMag = down;
dirSlot = 1;
}
if (left > maxMag) {
maxMag = left;
dirSlot = 2;
}
if (right > maxMag) {
maxMag = right;
dirSlot = 3;
}
2019-01-31 07:52:21 +00:00
dirs[dirSlot] += maxMag;
2018-12-08 05:30:43 +00:00
2019-01-23 07:52:19 +00:00
if (dirs[0] > 0.f || dirs[1] > 0.f || dirs[2] > 0.f || dirs[3] > 0.f || mouseHeld) {
int flags = 0x0;
if (up > 0.f)
flags |= 0x2;
if (down > 0.f)
flags |= 0x1;
if (left > 0.f)
flags |= 0x4;
if (right > 0.f)
flags |= 0x8;
switch (flags) {
case 1: // Down
x2e4_lStickPos = 1;
break;
case 2: // Up
x2e4_lStickPos = 5;
break;
case 4: // Left
x2e4_lStickPos = 3;
break;
case 5: // Down-Left
x2e4_lStickPos = 2;
break;
case 6: // Up-Left
x2e4_lStickPos = 4;
break;
case 8: // Right
x2e4_lStickPos = 7;
break;
case 9: // Down-Right
x2e4_lStickPos = 8;
break;
case 10: // Up-Right
x2e4_lStickPos = 6;
break;
default:
break;
}
2018-12-08 05:30:43 +00:00
float deltaFrames = input.DeltaTime() * 60.f;
2019-01-23 07:52:19 +00:00
SetShouldRotatingSoundBePlaying(dirs[0] > 0.f || dirs[1] > 0.f || dirs[2] > 0.f || dirs[3] > 0.f);
2018-12-08 05:30:43 +00:00
zeus::CEulerAngles eulers(xa8_renderStates[0].x8_camOrientation);
zeus::CRelAngle angX(eulers.x());
2018-12-17 03:52:51 +00:00
angX.makeRel();
2018-12-08 05:30:43 +00:00
zeus::CRelAngle angZ(eulers.z());
2018-12-17 03:52:51 +00:00
angZ.makeRel();
2018-12-08 05:30:43 +00:00
float dt = deltaFrames * g_tweakAutoMapper->GetCamRotateDegreesPerFrame();
angZ -= zeus::degToRad(dt * dirs[2]);
2018-12-17 03:52:51 +00:00
angZ.makeRel();
2018-12-08 05:30:43 +00:00
angZ += zeus::degToRad(dt * dirs[3]);
2018-12-17 03:52:51 +00:00
angZ.makeRel();
2018-12-08 05:30:43 +00:00
angX -= zeus::degToRad(dt * dirs[0]);
2018-12-17 03:52:51 +00:00
angX.makeRel();
2018-12-08 05:30:43 +00:00
angX += zeus::degToRad(dt * dirs[1]);
2018-12-17 03:52:51 +00:00
angX.makeRel();
2018-12-08 05:30:43 +00:00
float angXDeg = angX.asDegrees();
if (angXDeg > 180.f)
angXDeg -= 360.f;
angX = zeus::degToRad(
zeus::clamp(g_tweakAutoMapper->GetMinCamRotateX(), angXDeg, g_tweakAutoMapper->GetMaxCamRotateX()));
2018-12-17 03:52:51 +00:00
angX.makeRel();
2018-12-08 05:30:43 +00:00
zeus::CQuaternion quat;
quat.rotateZ(angZ);
quat.rotateX(angX);
quat.rotateY(0.f);
xa8_renderStates[0].x8_camOrientation = quat;
} else {
2019-01-23 07:52:19 +00:00
x2e4_lStickPos = 0;
2018-12-08 05:30:43 +00:00
SetShouldRotatingSoundBePlaying(false);
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::ProcessMapZoomInput(const CFinalInput& input, const CStateManager& mgr) {
bool in = ControlMapper::GetDigitalInput(ControlMapper::ECommands::MapZoomIn, input);
bool out = ControlMapper::GetDigitalInput(ControlMapper::ECommands::MapZoomOut, input);
2019-01-31 07:52:21 +00:00
float zoomSpeed = 1.f;
2019-01-23 07:52:19 +00:00
if (const auto& kbm = input.GetKBM()) {
m_mapScroll += kbm->m_accumScroll - m_lastAccumScroll;
m_lastAccumScroll = kbm->m_accumScroll;
if (m_mapScroll.delta[1] > 0.0) {
in = true;
2019-01-31 07:52:21 +00:00
zoomSpeed = std::max(1.f, float(m_mapScroll.delta[1]));
2019-01-23 07:52:19 +00:00
m_mapScroll.delta[1] = std::max(0.0, m_mapScroll.delta[1] - (15.0 / 60.0));
} else if (m_mapScroll.delta[1] < 0.0) {
out = true;
2019-01-31 07:52:21 +00:00
zoomSpeed = std::max(1.f, float(-m_mapScroll.delta[1]));
2019-01-23 07:52:19 +00:00
m_mapScroll.delta[1] = std::min(0.0, m_mapScroll.delta[1] + (15.0 / 60.0));
}
}
2018-12-08 05:30:43 +00:00
EZoomState nextZoomState = EZoomState::None;
switch (x324_zoomState) {
case EZoomState::None:
if (in)
nextZoomState = EZoomState::In;
else if (out)
nextZoomState = EZoomState::Out;
break;
case EZoomState::In:
if (in)
nextZoomState = EZoomState::In;
else if (out)
nextZoomState = EZoomState::Out;
break;
case EZoomState::Out:
if (in)
nextZoomState = EZoomState::In;
else if (out)
nextZoomState = EZoomState::Out;
break;
default:
break;
}
x324_zoomState = nextZoomState;
float delta = input.DeltaTime() * 60.f * (x1bc_state == EAutoMapperState::MapScreen ? 1.f : 4.f) *
2019-01-31 07:52:21 +00:00
g_tweakAutoMapper->GetCamZoomUnitsPerFrame() * zoomSpeed;
2018-12-08 05:30:43 +00:00
float oldDist = xa8_renderStates[0].x18_camDist;
if (x324_zoomState == EZoomState::In) {
xa8_renderStates[0].x18_camDist = GetClampedMapScreenCameraDistance(xa8_renderStates[0].x18_camDist - delta);
x2f0_rTriggerPos = 1;
x324_zoomState = EZoomState::In;
} else if (x324_zoomState == EZoomState::Out) {
xa8_renderStates[0].x18_camDist = GetClampedMapScreenCameraDistance(xa8_renderStates[0].x18_camDist + delta);
x2ec_lTriggerPos = 1;
x324_zoomState = EZoomState::Out;
}
2019-01-31 07:52:21 +00:00
if (oldDist == xa8_renderStates[0].x18_camDist)
m_mapScroll.delta[1] = 0.0;
2019-01-23 07:52:19 +00:00
SetShouldZoomingSoundBePlaying(oldDist != xa8_renderStates[0].x18_camDist);
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::ProcessMapPanInput(const CFinalInput& input, const CStateManager& mgr) {
float forward = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapMoveForward, input);
float back = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapMoveBack, input);
float left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapMoveLeft, input);
float right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::MapMoveRight, input);
2019-01-23 07:52:19 +00:00
bool mouseHeld = false;
if (const auto& kbm = input.GetKBM()) {
2019-01-31 07:52:21 +00:00
if (kbm->m_mouseButtons[int(boo::EMouseButton::Middle)] ||
kbm->m_mouseButtons[int(boo::EMouseButton::Secondary)]) {
2019-01-23 07:52:19 +00:00
mouseHeld = true;
if (float(m_mouseDelta.x()) < 0.f)
right += -m_mouseDelta.x();
else if (float(m_mouseDelta.x()) > 0.f)
left += m_mouseDelta.x();
if (float(m_mouseDelta.y()) < 0.f)
forward += -m_mouseDelta.y();
else if (float(m_mouseDelta.y()) > 0.f)
back += m_mouseDelta.y();
}
}
2018-12-08 05:30:43 +00:00
zeus::CTransform camRot = xa8_renderStates[0].x8_camOrientation.toTransform();
2019-01-23 07:52:19 +00:00
if (forward > 0.f || back > 0.f || left > 0.f || right > 0.f || mouseHeld) {
2018-12-08 05:30:43 +00:00
float deltaFrames = 60.f * input.DeltaTime();
float speed = GetFinalMapScreenCameraMoveSpeed();
2017-04-15 05:32:25 +00:00
int flags = 0x0;
2018-12-08 05:30:43 +00:00
if (forward > 0.f)
flags |= 0x1;
if (back > 0.f)
flags |= 0x2;
2017-04-15 05:32:25 +00:00
if (left > 0.f)
2018-12-08 05:30:43 +00:00
flags |= 0x4;
2017-04-15 05:32:25 +00:00
if (right > 0.f)
2018-12-08 05:30:43 +00:00
flags |= 0x8;
switch (flags) {
case 1: // Forward
x2e8_rStickPos = 1;
break;
case 2: // Back
x2e8_rStickPos = 5;
break;
2017-04-15 05:32:25 +00:00
case 4: // Left
2018-12-08 05:30:43 +00:00
x2e8_rStickPos = 3;
break;
case 5: // Forward-Left
x2e8_rStickPos = 2;
break;
case 6: // Back-Left
x2e8_rStickPos = 4;
break;
2017-04-15 05:32:25 +00:00
case 8: // Right
2018-12-08 05:30:43 +00:00
x2e8_rStickPos = 7;
break;
case 9: // Forward-Right
x2e8_rStickPos = 8;
break;
case 10: // Back-Right
x2e8_rStickPos = 6;
break;
default:
break;
}
zeus::CVector3f dirVec(right - left, 0.f, forward - back);
zeus::CVector3f deltaVec = camRot * (dirVec * deltaFrames * speed);
zeus::CVector3f newPoint = xa8_renderStates[0].x20_areaPoint + deltaVec;
2019-01-23 07:52:19 +00:00
SetShouldPanningSoundBePlaying(deltaVec.magnitude() > input.DeltaTime());
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
if (x1bc_state == EAutoMapperState::MapScreen) {
xa8_renderStates[0].x20_areaPoint = x24_world->IGetMapWorld()->ConstrainToWorldVolume(newPoint, camRot.basis[1]);
} else {
zeus::CVector3f localPoint = newPoint - x8_mapu->GetMapUniverseCenterPoint();
if (localPoint.magnitude() > x8_mapu->GetMapUniverseRadius())
newPoint = x8_mapu->GetMapUniverseCenterPoint() + localPoint.normalized() * x8_mapu->GetMapUniverseRadius();
xa8_renderStates[0].x20_areaPoint = newPoint;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
} else {
2019-01-23 07:52:19 +00:00
x2e8_rStickPos = 0;
2018-12-08 05:30:43 +00:00
SetShouldPanningSoundBePlaying(false);
float speed = g_tweakAutoMapper->GetCamPanUnitsPerFrame() * GetBaseMapScreenCameraMoveSpeed();
if (x1bc_state == EAutoMapperState::MapScreen) {
const CMapArea* area = x24_world->IGetMapWorld()->GetMapArea(xa0_curAreaId);
zeus::CVector3f worldPoint = area->GetAreaPostTransform(*x24_world, xa0_curAreaId) * area->GetAreaCenterPoint();
zeus::CVector3f viewPoint = worldPoint - xa8_renderStates[0].x20_areaPoint;
if (viewPoint.magnitude() < speed)
xa8_renderStates[0].x20_areaPoint = worldPoint;
else
xa8_renderStates[0].x20_areaPoint += viewPoint.normalized() * speed;
} else {
std::pair<int, int> areas = FindClosestVisibleWorld(xa8_renderStates[0].x20_areaPoint, camRot.basis[1], mgr);
const zeus::CTransform& hex = x8_mapu->GetMapWorldData(areas.first).GetMapAreaData(areas.second);
zeus::CVector3f areaToHex = hex.origin - xa8_renderStates[0].x20_areaPoint;
if (areaToHex.magnitude() < speed)
xa8_renderStates[0].x20_areaPoint = hex.origin;
else
xa8_renderStates[0].x20_areaPoint += areaToHex.normalized() * speed;
}
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetShouldPanningSoundBePlaying(bool b) {
if (b) {
if (!x1cc_panningSfx)
x1cc_panningSfx = CSfxManager::SfxStart(SFXui_map_pan, 1.f, 0.f, false, 0x7f, true, kInvalidAreaId);
} else {
CSfxManager::SfxStop(x1cc_panningSfx);
x1cc_panningSfx.reset();
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetShouldZoomingSoundBePlaying(bool b) {
if (b) {
if (!x1d4_zoomingSfx)
x1d4_zoomingSfx = CSfxManager::SfxStart(SFXui_map_zoom, 1.f, 0.f, false, 0x7f, true, kInvalidAreaId);
} else {
CSfxManager::SfxStop(x1d4_zoomingSfx);
x1d4_zoomingSfx.reset();
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetShouldRotatingSoundBePlaying(bool b) {
if (b) {
if (!x1d0_rotatingSfx)
x1d0_rotatingSfx = CSfxManager::SfxStart(SFXui_map_rotate, 1.f, 0.f, false, 0x7f, true, kInvalidAreaId);
} else {
CSfxManager::SfxStop(x1d0_rotatingSfx);
x1d0_rotatingSfx.reset();
}
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::ProcessMapScreenInput(const CFinalInput& input, const CStateManager& mgr) {
zeus::CMatrix3f camRot = xa8_renderStates[0].x8_camOrientation.toTransform().buildMatrix3f();
if (x1bc_state == EAutoMapperState::MapScreen) {
2019-01-21 04:10:34 +00:00
if ((input.PA() || input.PSpecialKey(boo::ESpecialKey::Enter)) && x328_ == 0 && HasCurrentMapUniverseWorld())
2018-12-08 05:30:43 +00:00
BeginMapperStateTransition(EAutoMapperState::MapScreenUniverse, mgr);
2019-01-21 04:10:34 +00:00
} else if (x1bc_state == EAutoMapperState::MapScreenUniverse &&
(input.PA() || input.PSpecialKey(boo::ESpecialKey::Enter))) {
2018-12-08 05:30:43 +00:00
const CMapUniverse::CMapWorldData& mapuWld = x8_mapu->GetMapWorldData(x9c_worldIdx);
zeus::CVector3f pointLocal = mapuWld.GetWorldTransform().inverse() * xa8_renderStates[0].x20_areaPoint;
if (mapuWld.GetWorldAssetId() != g_GameState->CurrentWorldAssetId()) {
x32c_loadingDummyWorld = true;
CheckDummyWorldLoad(mgr);
} else {
x24_world = mgr.GetWorld();
CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
xa0_curAreaId = FindClosestVisibleArea(pointLocal, zeus::CUnitVector3f(camRot[1]), mgr, *x24_world, mwInfo);
BeginMapperStateTransition(EAutoMapperState::MapScreen, mgr);
}
}
x2f4_aButtonPos = 0;
2019-01-21 04:10:34 +00:00
if (input.PA() || input.PSpecialKey(boo::ESpecialKey::Enter))
2018-12-08 05:30:43 +00:00
x2f4_aButtonPos = 1;
2019-01-23 07:52:19 +00:00
if (IsInPlayerControlState()) {
2018-12-08 05:30:43 +00:00
x2ec_lTriggerPos = 0;
x2f0_rTriggerPos = 0;
2019-01-23 07:52:19 +00:00
if (const auto& kbm = input.GetKBM()) {
zeus::CVector2f mouseCoord = zeus::CVector2f(kbm->m_mouseCoord.norm[0], kbm->m_mouseCoord.norm[1]);
if (!m_lastMouseCoord) {
m_lastMouseCoord.emplace(mouseCoord);
} else {
m_mouseDelta = mouseCoord - *m_lastMouseCoord;
m_lastMouseCoord.emplace(mouseCoord);
m_mouseDelta.x() *= g_Viewport.aspect;
m_mouseDelta *= 100.f;
}
}
2018-12-08 05:30:43 +00:00
ProcessMapRotateInput(input, mgr);
ProcessMapZoomInput(input, mgr);
ProcessMapPanInput(input, mgr);
}
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
zeus::CQuaternion CAutoMapper::GetMiniMapCameraOrientation(const CStateManager& stateMgr) const {
const CGameCamera* cam = stateMgr.GetCameraManager()->GetCurrentCamera(stateMgr);
zeus::CEulerAngles camAngles(zeus::CQuaternion(cam->GetTransform().buildMatrix3f()));
2018-12-17 03:52:51 +00:00
zeus::CRelAngle angle(camAngles.z());
angle.makeRel();
2018-12-08 05:30:43 +00:00
zeus::CQuaternion ret;
2018-12-17 03:52:51 +00:00
ret.rotateZ(angle);
2018-12-08 05:30:43 +00:00
ret.rotateX(zeus::degToRad(g_tweakAutoMapper->GetMiniCamXAngle()));
return ret;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f CAutoMapper::GetAreaPointOfInterest(const CStateManager&, TAreaId aid) const {
const CMapArea* mapa = x24_world->IGetMapWorld()->GetMapArea(aid);
return mapa->GetAreaPostTransform(*x24_world, aid) * mapa->GetAreaCenterPoint();
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
TAreaId CAutoMapper::FindClosestVisibleArea(const zeus::CVector3f& point, const zeus::CUnitVector3f& camDir,
const CStateManager& mgr, const IWorld& wld,
const CMapWorldInfo& mwInfo) const {
float minDist = 9999.f;
TAreaId closestArea = xa0_curAreaId;
const CMapWorld* mw = wld.IGetMapWorld();
std::vector<TAreaId> areas = mw->GetVisibleAreas(wld, mwInfo);
for (TAreaId areaId : areas) {
const CMapArea* mapa = mw->GetMapArea(areaId);
zeus::CVector3f xfPoint = mapa->GetAreaPostTransform(wld, areaId) * mapa->GetAreaCenterPoint();
zeus::CVector3f pointToArea = xfPoint - point;
pointToArea = pointToArea.canBeNormalized()
? point + (pointToArea.normalized().dot(camDir) * pointToArea.magnitude()) * camDir
: point;
pointToArea -= xfPoint;
float dist = pointToArea.magnitude();
if (dist < minDist) {
minDist = dist;
closestArea = areaId;
}
}
return closestArea;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
std::pair<int, int> CAutoMapper::FindClosestVisibleWorld(const zeus::CVector3f& point,
const zeus::CUnitVector3f& camDir,
const CStateManager& mgr) const {
float minDist = 29999.f;
std::pair<int, int> closestWorld = {x9c_worldIdx, xa0_curAreaId};
for (u32 w = 0; w < x8_mapu->GetNumMapWorldDatas(); ++w) {
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldData(w);
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(mwData.GetWorldAssetId()).MapWorldInfo();
if (!mwInfo.IsAnythingSet())
continue;
for (u32 i = 0; i < mwData.GetNumMapAreaDatas(); ++i) {
const zeus::CVector3f& mwOrigin = mwData.GetMapAreaData(i).origin;
zeus::CVector3f pointToArea = mwOrigin - point;
pointToArea = pointToArea.canBeNormalized()
? point + (pointToArea.normalized().dot(camDir) * pointToArea.magnitude()) * camDir
: point;
pointToArea -= mwOrigin;
float dist = pointToArea.magnitude();
if (dist < minDist) {
minDist = dist;
closestWorld.first = w;
closestWorld.second = i;
}
}
}
return closestWorld;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
zeus::CVector2i CAutoMapper::GetMiniMapViewportSize() {
float scaleX = g_Viewport.x8_width / 640.f;
float scaleY = g_Viewport.xc_height / 480.f;
return {int(scaleX * g_tweakAutoMapper->GetMiniMapViewportWidth()),
int(scaleY * g_tweakAutoMapper->GetMiniMapViewportHeight())};
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
zeus::CVector2i CAutoMapper::GetMapScreenViewportSize() {
return {int(g_Viewport.x8_width), int(g_Viewport.xc_height)};
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetMapAreaMaxDrawDepth(const CStateManager&, TAreaId aid) const {
return x24_world->IGetMapWorld()->GetCurrentMapAreaDepth(*x24_world, aid);
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetMapAreaMiniMapDrawAlphaSurfaceVisited(const CStateManager& stateMgr) {
float mapAlphaInterp = g_tweakGui->GetMapAlphaInterpolant();
return g_tweakAutoMapper->GetMiniAlphaSurfaceVisited() * (1.f - mapAlphaInterp) * stateMgr.Player()->GetGunAlpha() +
mapAlphaInterp;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetMapAreaMiniMapDrawAlphaOutlineVisited(const CStateManager& stateMgr) {
float mapAlphaInterp = g_tweakGui->GetMapAlphaInterpolant();
return g_tweakAutoMapper->GetMiniAlphaOutlineVisited() * (1.f - mapAlphaInterp) * stateMgr.Player()->GetGunAlpha() +
mapAlphaInterp;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetMapAreaMiniMapDrawAlphaSurfaceUnvisited(const CStateManager& stateMgr) {
float mapAlphaInterp = g_tweakGui->GetMapAlphaInterpolant();
return g_tweakAutoMapper->GetMiniAlphaSurfaceUnvisited() * (1.f - mapAlphaInterp) * stateMgr.Player()->GetGunAlpha() +
mapAlphaInterp;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetMapAreaMiniMapDrawAlphaOutlineUnvisited(const CStateManager& stateMgr) {
float mapAlphaInterp = g_tweakGui->GetMapAlphaInterpolant();
return g_tweakAutoMapper->GetMiniAlphaOutlineUnvisited() * (1.f - mapAlphaInterp) * stateMgr.Player()->GetGunAlpha() +
mapAlphaInterp;
2017-03-20 05:09:53 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetDesiredMiniMapCameraDistance(const CStateManager& mgr) const {
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
const CMapWorld* mw = x24_world->IGetMapWorld();
zeus::CAABox aabb;
const IGameArea* area = x24_world->IGetAreaAlways(xa0_curAreaId);
const CMapArea* mapa = mw->GetMapArea(xa0_curAreaId);
bool oneMiniMapArea = g_tweakAutoMapper->GetShowOneMiniMapArea();
for (int i = -1; i < (oneMiniMapArea ? 0 : int(area->IGetNumAttachedAreas())); ++i) {
TAreaId aid = i == -1 ? xa0_curAreaId : area->IGetAttachedAreaId(i);
const CMapArea* attMapa = mw->GetMapArea(aid);
if (attMapa->GetIsVisibleToAutoMapper(mwInfo.IsWorldVisible(aid), mwInfo.IsAreaVisible(aid))) {
zeus::CAABox areaAABB =
attMapa->GetBoundingBox().getTransformedAABox(attMapa->GetAreaPostTransform(*x24_world, aid));
aabb.accumulateBounds(areaAABB.min);
aabb.accumulateBounds(areaAABB.max);
}
}
zeus::CVector3f xfPoint = mapa->GetAreaPostTransform(*x24_world, xa0_curAreaId) * mapa->GetAreaCenterPoint();
zeus::CVector3f maxMargin;
maxMargin.x() = std::max(xfPoint.x() - aabb.min.x(), aabb.max.x() - xfPoint.x());
maxMargin.y() = std::max(xfPoint.y() - aabb.min.y(), aabb.max.y() - xfPoint.y());
maxMargin.z() = std::max(xfPoint.z() - aabb.min.z(), aabb.max.z() - xfPoint.z());
zeus::CVector3f extent = mapa->GetBoundingBox().max - mapa->GetBoundingBox().min;
return (0.5f * (0.5f * extent.magnitude()) + 0.5f * maxMargin.magnitude()) *
g_tweakAutoMapper->GetMiniMapCamDistScale() *
std::tan(M_PIF / 2.f - 0.5f * 2.f * M_PIF * (xa8_renderStates[0].x1c_camAngle / 360.f));
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
float CAutoMapper::GetClampedMapScreenCameraDistance(float v) {
if (x1bc_state == EAutoMapperState::MapScreenUniverse)
return zeus::clamp(g_tweakAutoMapper->GetMinUniverseCamDist(), v, g_tweakAutoMapper->GetMaxUniverseCamDist());
return zeus::clamp(g_tweakAutoMapper->GetMinCamDist(), v, g_tweakAutoMapper->GetMaxCamDist());
2017-04-15 05:32:25 +00:00
}
2019-01-23 07:52:19 +00:00
void CAutoMapper::MuteAllLoopedSounds() {
CSfxManager::SfxVolume(x1cc_panningSfx, 0.f);
CSfxManager::SfxVolume(x1d0_rotatingSfx, 0.f);
CSfxManager::SfxVolume(x1d4_zoomingSfx, 0.f);
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::UnmuteAllLoopedSounds() {
CSfxManager::SfxVolume(x1cc_panningSfx, 1.f);
CSfxManager::SfxVolume(x1d0_rotatingSfx, 1.f);
CSfxManager::SfxVolume(x1d4_zoomingSfx, 1.f);
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager& mgr) {
if (!IsRenderStateInterpolating()) {
2019-01-23 07:52:19 +00:00
if (IsInPlayerControlState()) {
2018-12-08 05:30:43 +00:00
if (x32c_loadingDummyWorld)
CheckDummyWorldLoad(mgr);
else if (x1e0_hintSteps.size())
UpdateHintNavigation(input.DeltaTime(), mgr);
else if (x328_ == 0)
ProcessMapScreenInput(input, mgr);
}
}
zeus::CMatrix3f camRot = xa8_renderStates[0].x8_camOrientation.toTransform().buildMatrix3f();
if (IsInMapperState(EAutoMapperState::MapScreen)) {
CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
TAreaId aid = FindClosestVisibleArea(xa8_renderStates[0].x20_areaPoint, camRot[1], mgr, *x24_world, mwInfo);
if (aid != xa0_curAreaId) {
xa0_curAreaId = aid;
xa8_renderStates[0].x2c_drawDepth1 = GetMapAreaMaxDrawDepth(mgr, xa0_curAreaId);
xa8_renderStates[0].x30_drawDepth2 = GetMapAreaMaxDrawDepth(mgr, xa0_curAreaId);
}
} else if (IsInMapperState(EAutoMapperState::MapScreenUniverse)) {
u32 oldWldIdx = x9c_worldIdx;
if (x1e0_hintSteps.size()) {
SAutoMapperHintStep& nextStep = x1e0_hintSteps.front();
if (nextStep.x0_type == SAutoMapperHintStep::Type::PanToWorld ||
nextStep.x0_type == SAutoMapperHintStep::Type::SwitchToWorld) {
SetCurWorldAssetId(nextStep.x4_worldId);
} else {
std::pair<int, int> wld = FindClosestVisibleWorld(xa8_renderStates[0].x20_areaPoint, camRot[1], mgr);
x9c_worldIdx = wld.first;
}
} else {
std::pair<int, int> wld = FindClosestVisibleWorld(xa8_renderStates[0].x20_areaPoint, camRot[1], mgr);
x9c_worldIdx = wld.first;
}
if (x9c_worldIdx != oldWldIdx) {
CAssetId curMlvl = g_GameState->CurrentWorldAssetId();
for (u32 i = 0; i < x14_dummyWorlds.size(); ++i) {
auto& wld = x14_dummyWorlds[i];
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldData(i);
if (i == x9c_worldIdx && curMlvl != mwData.GetWorldAssetId()) {
if (g_ResFactory->CanBuild(SObjectTag{FOURCC('MLVL'), mwData.GetWorldAssetId()}))
wld = std::make_unique<CDummyWorld>(mwData.GetWorldAssetId(), true);
} else {
wld.reset();
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
}
x24_world = (curMlvl == x8_mapu->GetMapWorldData(x9c_worldIdx).GetWorldAssetId()) ? mgr.GetWorld() : nullptr;
}
}
if (x300_textpane_instructions) {
if (x78_areaHintDesc.IsLoaded()) {
x2fc_textpane_hint->TextSupport().SetText(x78_areaHintDesc->GetString(0));
x304_textpane_instructions1->TextSupport().SetText(u"");
x300_textpane_instructions->TextSupport().SetText(u"");
x308_textpane_instructions2->TextSupport().SetText(u"");
} else {
x2fc_textpane_hint->TextSupport().SetText(u"");
2019-07-20 04:27:21 +00:00
std::u16string str = fmt::format(fmt(u"&image=SI,0.6,1.0,{};"), g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]);
2018-12-08 05:30:43 +00:00
str += g_MainStringTable->GetString(46); // Rotate
x300_textpane_instructions->TextSupport().SetText(str);
2019-07-20 04:27:21 +00:00
str = fmt::format(fmt(u"&image=SI,0.6,1.0,{};"), g_tweakPlayerRes->x4c_cStick[x2e8_rStickPos]);
2018-12-08 05:30:43 +00:00
str += g_MainStringTable->GetString(47); // Move
x304_textpane_instructions1->TextSupport().SetText(str);
2019-07-20 04:27:21 +00:00
str = fmt::format(fmt(u"&image={};"), g_tweakPlayerRes->x74_lTrigger[x2ec_lTriggerPos]);
2018-12-08 05:30:43 +00:00
str += g_MainStringTable->GetString(48); // Zoom
2019-07-20 04:27:21 +00:00
str += fmt::format(fmt(u"&image={};"), g_tweakPlayerRes->x80_rTrigger[x2f0_rTriggerPos]);
2018-12-08 05:30:43 +00:00
x308_textpane_instructions2->TextSupport().SetText(str);
}
}
2019-01-23 07:52:19 +00:00
if (input.PY() || input.PKey(' ')) {
2018-12-08 05:30:43 +00:00
CPersistentOptions& sysOpts = g_GameState->SystemOptions();
switch (sysOpts.GetAutoMapperKeyState()) {
case 0:
sysOpts.SetAutoMapperKeyState(1);
CSfxManager::SfxStart(SFXui_map_screen_key1, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
break;
case 1:
sysOpts.SetAutoMapperKeyState(2);
CSfxManager::SfxStart(SFXui_map_screen_key2, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
break;
case 2:
sysOpts.SetAutoMapperKeyState(0);
CSfxManager::SfxStart(SFXui_map_screen_key0, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
break;
default:
break;
}
}
2019-01-21 04:10:34 +00:00
if (input.PZ() || input.PKey('\t') || input.PB() || input.PSpecialKey(boo::ESpecialKey::Esc)) {
2018-12-08 05:30:43 +00:00
if (x328_ == 0) {
2018-12-31 05:01:42 +00:00
if (CanLeaveMapScreenInternal(mgr)) {
2018-12-08 05:30:43 +00:00
LeaveMapScreen(mgr);
2018-12-31 05:01:42 +00:00
} else if (NotHintNavigating()) {
2018-12-08 05:30:43 +00:00
BeginMapperStateTransition(EAutoMapperState::MapScreenUniverse, mgr);
x328_ = 1;
}
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-04-16 05:52:43 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::Update(float dt, const CStateManager& mgr) {
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
x1d8_flashTimer = std::fmod(x1d8_flashTimer + dt, 0.75f);
x1dc_playerFlashPulse = x1d8_flashTimer < 0.375f ? x1d8_flashTimer / 0.375f : (0.75f - x1d8_flashTimer) / 0.375f;
}
if (!m_frmeInitialized && x28_frmeMapScreen.IsLoaded()) {
x28_frmeMapScreen->SetMaxAspect(1.78f);
m_frmeInitialized = true;
static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_left"))
->TextSupport()
.SetText(g_MainStringTable->GetString(42));
static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_yicon"))
->TextSupport()
.SetText(g_MainStringTable->GetString(43));
x2fc_textpane_hint = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_hint"));
x300_textpane_instructions = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_instructions"));
x304_textpane_instructions1 = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_instructions1"));
x308_textpane_instructions2 = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_instructions2"));
CGuiTextPane* mapLegend = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_mapLegend"));
mapLegend->TextSupport().ClearRenderBuffer();
mapLegend->TextSupport().SetImageBaseline(true);
mapLegend->TextSupport().SetText(g_MainStringTable->GetString(49));
x30c_basewidget_leftPane = x28_frmeMapScreen->FindWidget("basewidget_leftPane");
x310_basewidget_yButtonPane = x28_frmeMapScreen->FindWidget("basewidget_yButtonPane");
x314_basewidget_bottomPane = x28_frmeMapScreen->FindWidget("basewidget_bottomPane");
x2f8_textpane_areaname = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_areaname"));
x2f8_textpane_areaname->SetDepthTest(false);
}
if (m_frmeInitialized) {
x28_frmeMapScreen->Update(dt);
CGuiTextPane* right1 = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_right1"));
std::u16string string;
if (x1bc_state == EAutoMapperState::MapScreenUniverse ||
(x1bc_state == EAutoMapperState::MapScreen && HasCurrentMapUniverseWorld()))
2019-07-20 04:27:21 +00:00
string = fmt::format(fmt(u"&image={};"), g_tweakPlayerRes->x98_aButton[x2f4_aButtonPos]);
2018-12-08 05:30:43 +00:00
right1->TextSupport().SetText(string);
CGuiTextPane* right = static_cast<CGuiTextPane*>(x28_frmeMapScreen->FindWidget("textpane_right"));
if (x1bc_state == EAutoMapperState::MapScreenUniverse)
string = g_MainStringTable->GetString(45);
else if (x1bc_state == EAutoMapperState::MapScreen && HasCurrentMapUniverseWorld())
string = g_MainStringTable->GetString(44);
2017-04-16 05:52:43 +00:00
else
2018-12-08 05:30:43 +00:00
string = std::u16string();
right->TextSupport().SetText(string);
}
float dt2 = 2.f * dt;
switch (g_GameState->SystemOptions().GetAutoMapperKeyState()) {
case 0: // All shown
x318_leftPanePos -= dt2;
x31c_yButtonPanePos -= dt2;
x320_bottomPanePos -= dt2;
break;
case 1: // Left shown
x318_leftPanePos += dt2;
x31c_yButtonPanePos -= dt2;
x320_bottomPanePos -= dt2;
break;
case 2: // All hidden
x318_leftPanePos += dt2;
x31c_yButtonPanePos += dt2;
x320_bottomPanePos += dt2;
break;
default:
break;
}
x318_leftPanePos = std::max(0.f, std::min(x318_leftPanePos, 1.f));
x31c_yButtonPanePos = std::max(0.f, std::min(x31c_yButtonPanePos, 1.f));
x320_bottomPanePos = std::max(0.f, std::min(x320_bottomPanePos, 1.f));
if (x30c_basewidget_leftPane) {
2019-01-23 07:52:19 +00:00
float vpAspectRatio = std::max(1.78f, g_Viewport.aspect);
2018-12-08 05:30:43 +00:00
x30c_basewidget_leftPane->SetLocalTransform(
zeus::CTransform::Translate(x318_leftPanePos * vpAspectRatio * -9.f, 0.f, 0.f) *
x30c_basewidget_leftPane->GetTransform());
}
if (x310_basewidget_yButtonPane) {
x310_basewidget_yButtonPane->SetLocalTransform(zeus::CTransform::Translate(0.f, 0.f, x31c_yButtonPanePos * -3.5f) *
x310_basewidget_yButtonPane->GetTransform());
}
if (x314_basewidget_bottomPane) {
x314_basewidget_bottomPane->SetLocalTransform(zeus::CTransform::Translate(0.f, 0.f, x320_bottomPanePos * -7.f) *
x314_basewidget_bottomPane->GetTransform());
}
if (IsInMapperState(EAutoMapperState::MiniMap)) {
xa8_renderStates[0].x8_camOrientation = GetMiniMapCameraOrientation(mgr);
float desiredDist = GetDesiredMiniMapCameraDistance(mgr);
if (std::fabs(xa8_renderStates[0].x18_camDist - desiredDist) < 3.f)
xa8_renderStates[0].x18_camDist = desiredDist;
else if (xa8_renderStates[0].x18_camDist < desiredDist)
xa8_renderStates[0].x18_camDist += 3.f;
else
xa8_renderStates[0].x18_camDist -= 3.f;
TAreaId curAid = x24_world->IGetCurrentAreaId();
if (curAid != xa0_curAreaId) {
xa8_renderStates[2] = xa8_renderStates[0];
xa8_renderStates[1] = xa8_renderStates[0];
xa4_otherAreaId = xa0_curAreaId;
xa0_curAreaId = curAid;
xa8_renderStates[1].x20_areaPoint = GetAreaPointOfInterest(mgr, xa0_curAreaId);
xa8_renderStates[1].x44_viewportEase = SAutoMapperRenderState::Ease::None;
xa8_renderStates[1].x48_camEase = SAutoMapperRenderState::Ease::None;
xa8_renderStates[1].x4c_pointEase = SAutoMapperRenderState::Ease::InOut;
xa8_renderStates[1].x50_depth1Ease = SAutoMapperRenderState::Ease::Linear;
xa8_renderStates[1].x54_depth2Ease = SAutoMapperRenderState::Ease::Linear;
xa8_renderStates[1].x58_alphaEase = SAutoMapperRenderState::Ease::None;
xa8_renderStates[1].x2c_drawDepth1 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[1].x30_drawDepth2 = GetMapAreaMiniMapDrawDepth();
xa8_renderStates[2].x2c_drawDepth1 = GetMapAreaMiniMapDrawDepth() - 1.f;
xa8_renderStates[2].x30_drawDepth2 = GetMapAreaMiniMapDrawDepth() - 1.f;
ResetInterpolationTimer(g_tweakAutoMapper->GetHintPanTime());
}
xa8_renderStates[1].x34_alphaSurfaceVisited = GetMapAreaMiniMapDrawAlphaSurfaceVisited(mgr);
xa8_renderStates[1].x38_alphaOutlineVisited = GetMapAreaMiniMapDrawAlphaOutlineVisited(mgr);
xa8_renderStates[1].x3c_alphaSurfaceUnvisited = GetMapAreaMiniMapDrawAlphaSurfaceUnvisited(mgr);
xa8_renderStates[1].x40_alphaOutlineUnvisited = GetMapAreaMiniMapDrawAlphaOutlineUnvisited(mgr);
} else {
if (x1c0_nextState == EAutoMapperState::MiniMap) {
float desiredDist = GetDesiredMiniMapCameraDistance(mgr);
if (std::fabs(xa8_renderStates[1].x18_camDist - desiredDist) < 3.f)
xa8_renderStates[0].x18_camDist = desiredDist;
else if (xa8_renderStates[1].x18_camDist < desiredDist)
xa8_renderStates[1].x18_camDist += 3.f;
else
xa8_renderStates[1].x18_camDist -= 3.f;
} else if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap && x24_world) {
x24_world->IGetMapWorld()->RecalculateWorldSphere(
*g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo(), *x24_world);
}
}
if (IsRenderStateInterpolating()) {
x1c8_interpTime = std::min(x1c8_interpTime + dt, x1c4_interpDur);
SAutoMapperRenderState::InterpolateWithClamp(xa8_renderStates[2], xa8_renderStates[0], xa8_renderStates[1],
x1c8_interpTime / x1c4_interpDur);
if (x1c8_interpTime == x1c4_interpDur && x328_ == 2)
SetupMiniMapWorld(mgr);
} else if (IsInMapperStateTransition()) {
CompleteMapperStateTransition(mgr);
}
CAssetId stringId = x88_mapAreaStringId;
if (IsInMapperState(EAutoMapperState::MapScreenUniverse)) {
IWorld* wld = x14_dummyWorlds[x9c_worldIdx].get();
if (wld && wld->ICheckWorldComplete())
stringId = wld->IGetStringTableAssetId();
2017-04-16 20:56:34 +00:00
else if (x24_world)
2018-12-08 05:30:43 +00:00
stringId = x24_world->IGetStringTableAssetId();
} else if (x24_world) {
const IGameArea* area = x24_world->IGetAreaAlways(xa0_curAreaId);
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
if (mwInfo.IsMapped(xa0_curAreaId) || mwInfo.IsAreaVisted(xa0_curAreaId))
stringId = area->IGetStringTableAssetId();
2017-04-16 05:52:43 +00:00
else
2018-12-08 05:30:43 +00:00
stringId = {};
}
2017-04-16 05:52:43 +00:00
2018-12-08 05:30:43 +00:00
if (x88_mapAreaStringId != stringId) {
x88_mapAreaStringId = stringId;
if (x88_mapAreaStringId.IsValid())
x8c_mapAreaString = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), x88_mapAreaStringId});
2017-04-16 20:56:34 +00:00
else
2018-12-08 05:30:43 +00:00
x8c_mapAreaString = TLockedToken<CStringTable>();
}
if (x2f8_textpane_areaname) {
if (x8c_mapAreaString) {
if (x8c_mapAreaString.IsLoaded())
x2f8_textpane_areaname->TextSupport().SetText(x8c_mapAreaString->GetString(0));
} else {
x2f8_textpane_areaname->TextSupport().SetText(u"");
}
}
if (IsInMapperState(EAutoMapperState::MapScreen)) {
CAssetId hintDesc = GetAreaHintDescriptionString(x24_world->IGetAreaAlways(xa0_curAreaId)->IGetAreaAssetId());
if (hintDesc != x74_areaHintDescId) {
x74_areaHintDescId = hintDesc;
if (x74_areaHintDescId.IsValid())
x78_areaHintDesc = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), x74_areaHintDescId});
else
x78_areaHintDesc = TLockedToken<CStringTable>();
}
}
for (auto& wld : x14_dummyWorlds)
if (wld)
wld->ICheckWorldComplete();
}
2017-04-16 20:56:34 +00:00
2018-12-08 05:30:43 +00:00
void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, float alpha) const {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CAutoMapper::Draw", zeus::skPurple);
2018-12-08 05:30:43 +00:00
alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f;
// Blend mode alpha
// Backface cull
float alphaInterp;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
alphaInterp = 1.f;
} else if (IsInMapperState(EAutoMapperState::MiniMap)) {
alphaInterp = alpha;
} else if (x1c0_nextState == EAutoMapperState::MiniMap) {
float t = GetInterp();
alphaInterp = alpha * t + (1.f - t);
} else if (x1bc_state == EAutoMapperState::MiniMap) {
float t = GetInterp();
alphaInterp = alpha * (1.f - t) + t;
} else {
alphaInterp = 1.f;
}
zeus::CVector2i vp = xa8_renderStates[0].GetViewportSize();
float aspect = vp.x / float(vp.y);
if (aspect > 1.78f)
aspect = 1.78f;
float yScale = xa8_renderStates[0].x18_camDist /
std::tan(M_PIF / 2.f - 0.5f * 2.f * M_PIF * (xa8_renderStates[0].x1c_camAngle / 360.f));
float xScale = yScale * aspect;
zeus::CTransform camXf(xa8_renderStates[0].x8_camOrientation, xa8_renderStates[0].x20_areaPoint);
zeus::CTransform distScale = zeus::CTransform::Scale(1.f / xScale, 0.001f, 1.f / yScale);
zeus::CTransform tweakScale =
zeus::CTransform::Scale(g_tweakAutoMapper->GetMapPlaneScaleX(), 0.f, g_tweakAutoMapper->GetMapPlaneScaleZ());
zeus::CTransform planeXf = xf * tweakScale * distScale * camXf.inverse();
float universeInterp = 0.f;
if (x1c0_nextState == EAutoMapperState::MapScreenUniverse) {
if (x1bc_state == EAutoMapperState::MapScreenUniverse)
universeInterp = 1.f;
else
universeInterp = GetInterp();
} else if (x1bc_state == EAutoMapperState::MapScreenUniverse) {
universeInterp = 1.f - GetInterp();
}
zeus::CTransform preXf;
if (x1bc_state == EAutoMapperState::MapScreenUniverse || x1c0_nextState == EAutoMapperState::MapScreenUniverse)
preXf = x8_mapu->GetMapWorldData(x9c_worldIdx).GetWorldTransform();
float objectScale = xa8_renderStates[0].x18_camDist / g_tweakAutoMapper->GetMinCamDist();
float mapAlpha = alphaInterp * (1.f - universeInterp);
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
if (universeInterp < 1.f && x24_world) {
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
const CMapWorld* mw = x24_world->IGetMapWorld();
float hintFlash = 0.f;
if (x1e0_hintSteps.size() && x1e0_hintSteps.front().x0_type == SAutoMapperHintStep::Type::ShowBeacon) {
if (xa0_curAreaId == mgr.GetNextAreaId() && x24_world == mgr.GetWorld()) {
float pulseTime = std::fmod(x1e0_hintSteps.front().x4_float * 8.f, 1.f);
hintFlash = 2.f * (pulseTime < 0.5f ? pulseTime : 1.f - pulseTime);
} else {
for (const SAutoMapperHintLocation& loc : x1f8_hintLocations) {
if (x24_world->IGetWorldAssetId() != loc.x8_worldId)
continue;
if (xa0_curAreaId != loc.xc_areaId)
continue;
float pulseTime =
std::fmod((1.f - std::max(0.f, (x1e0_hintSteps.front().x4_float - 0.5f) / 0.5f)) * 4.f, 1.f);
hintFlash = 2.f * (pulseTime < 0.5f ? pulseTime : 1.f - pulseTime);
break;
}
}
2018-12-08 05:30:43 +00:00
}
zeus::CTransform modelXf = planeXf * preXf;
CMapWorld::CMapWorldDrawParms parms(xa8_renderStates[0].x34_alphaSurfaceVisited * alphaInterp,
xa8_renderStates[0].x38_alphaOutlineVisited * alphaInterp,
xa8_renderStates[0].x3c_alphaSurfaceUnvisited * alphaInterp,
xa8_renderStates[0].x40_alphaOutlineUnvisited * alphaInterp, mapAlpha, 2.f,
mgr, modelXf, camXf, *x24_world, mwInfo, x1dc_playerFlashPulse, hintFlash,
objectScale, true);
mw->Draw(parms, xa0_curAreaId, xa0_curAreaId, xa8_renderStates[0].x2c_drawDepth1,
xa8_renderStates[0].x30_drawDepth2, true);
}
} else if (IsInMapperState(EAutoMapperState::MiniMap)) {
const CMapWorld* mw = x24_world->IGetMapWorld();
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
CMapWorld::CMapWorldDrawParms parms(xa8_renderStates[0].x34_alphaSurfaceVisited * alphaInterp,
xa8_renderStates[0].x38_alphaOutlineVisited * alphaInterp,
xa8_renderStates[0].x3c_alphaSurfaceUnvisited * alphaInterp,
xa8_renderStates[0].x40_alphaOutlineUnvisited * alphaInterp, mapAlpha, 1.f, mgr,
planeXf, camXf, *x24_world, mwInfo, 0.f, 0.f, objectScale, false);
mw->Draw(parms, xa0_curAreaId, xa4_otherAreaId, xa8_renderStates[0].x2c_drawDepth1,
xa8_renderStates[0].x30_drawDepth2, false);
} else {
const CMapWorld* mw = x24_world->IGetMapWorld();
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(x24_world->IGetWorldAssetId()).MapWorldInfo();
zeus::CTransform modelXf = planeXf * preXf;
CMapWorld::CMapWorldDrawParms parms(xa8_renderStates[0].x34_alphaSurfaceVisited * alphaInterp,
xa8_renderStates[0].x38_alphaOutlineVisited * alphaInterp,
xa8_renderStates[0].x3c_alphaSurfaceUnvisited * alphaInterp,
xa8_renderStates[0].x40_alphaOutlineUnvisited * alphaInterp, mapAlpha, 2.f, mgr,
modelXf, camXf, *x24_world, mwInfo, 0.f, 0.f, objectScale, true);
mw->Draw(parms, xa0_curAreaId, xa0_curAreaId, xa8_renderStates[0].x2c_drawDepth1,
xa8_renderStates[0].x30_drawDepth2, false);
}
if (universeInterp > 0.f) {
zeus::CTransform areaXf = mgr.GetWorld()
->GetMapWorld()
->GetMapArea(mgr.GetNextAreaId())
->GetAreaPostTransform(*mgr.GetWorld(), mgr.GetNextAreaId());
const CMapUniverse::CMapWorldData& mwData = x8_mapu->GetMapWorldDataByWorldId(g_GameState->CurrentWorldAssetId());
zeus::CTransform universeAreaXf = mwData.GetWorldTransform() * areaXf;
float minMag = FLT_MAX;
int hexIdx = -1;
for (u32 i = 0; i < mwData.GetNumMapAreaDatas(); ++i) {
float mag = (universeAreaXf.origin - mwData.GetMapAreaData(i).origin).magnitude();
if (mag < minMag) {
hexIdx = i;
minMag = mag;
}
}
CMapUniverse::CMapUniverseDrawParms parms(universeInterp, x9c_worldIdx, g_GameState->CurrentWorldAssetId(), hexIdx,
x1dc_playerFlashPulse, mgr, planeXf, camXf);
x8_mapu->Draw(parms, zeus::skZero3f, 0.f, 0.f);
2018-12-08 05:30:43 +00:00
}
if (!IsInMapperState(EAutoMapperState::MapScreenUniverse)) {
zeus::CTransform mapXf = planeXf * preXf;
if (x24_world == mgr.GetWorld()) {
float func = zeus::clamp(0.f, 0.5f * (1.f + std::sin(5.f * CGraphics::GetSecondsMod900() - (M_PIF / 2.f))), 1.f);
float scale =
std::min(0.6f * g_tweakAutoMapper->GetMaxCamDist() / g_tweakAutoMapper->GetMinCamDist(), objectScale);
zeus::CEulerAngles eulers(mgr.GetCameraManager()->GetCurrentCameraTransform(mgr));
zeus::CRelAngle angle(eulers.z());
2018-12-17 03:52:51 +00:00
angle.makeRel();
2018-12-08 05:30:43 +00:00
zeus::CTransform playerXf(zeus::CMatrix3f::RotateZ(angle),
CMapArea::GetAreaPostTranslate(*x24_world, mgr.GetNextAreaId()) +
mgr.GetPlayer().GetTranslation());
CGraphics::SetModelMatrix(mapXf * playerXf * zeus::CTransform::Scale(scale * (0.25f * func + 0.75f)));
float alpha;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap)
alpha = 1.f;
else
alpha = xa8_renderStates[0].x34_alphaSurfaceVisited;
alpha *= mapAlpha;
zeus::CColor modColor = g_tweakAutoMapper->GetMiniMapSamusModColor();
modColor.a() *= alpha;
CModelFlags flags(5, 0, 8 | 1, modColor); /* Depth GEqual */
flags.m_extendedShader = EExtendedShader::DepthGEqualNoZWrite;
x30_miniMapSamus->Draw(flags);
}
if (IsInMapperState(EAutoMapperState::MapScreen)) {
CAssetId wldMlvl = x24_world->IGetWorldAssetId();
const CMapWorld* mw = x24_world->IGetMapWorld();
std::vector<CTexturedQuadFilter>& hintBeaconFilters = const_cast<CAutoMapper&>(*this).m_hintBeaconFilters;
if (hintBeaconFilters.size() < x1f8_hintLocations.size()) {
hintBeaconFilters.reserve(x1f8_hintLocations.size());
for (u32 i = hintBeaconFilters.size(); i < x1f8_hintLocations.size(); ++i)
hintBeaconFilters.emplace_back(EFilterType::Add, x3c_hintBeacon);
}
auto locIt = x1f8_hintLocations.cbegin();
auto filterIt = hintBeaconFilters.begin();
for (; locIt != x1f8_hintLocations.cend(); ++locIt, ++filterIt) {
const SAutoMapperHintLocation& loc = *locIt;
CTexturedQuadFilter& filter = *filterIt;
if (loc.x8_worldId != wldMlvl)
continue;
const CMapArea* mapa = mw->GetMapArea(loc.xc_areaId);
if (!mapa)
continue;
zeus::CTransform camRot(camXf.buildMatrix3f(), zeus::skZero3f);
2018-12-08 05:30:43 +00:00
CGraphics::SetModelMatrix(
mapXf * zeus::CTransform::Translate(mapa->GetAreaPostTransform(*x24_world, loc.xc_areaId).origin) *
zeus::CTransform::Translate(mapa->GetAreaCenterPoint()) * zeus::CTransform::Scale(objectScale) * camRot);
float beaconAlpha = 0.f;
if (loc.x0_showBeacon == 1)
beaconAlpha = loc.x4_beaconAlpha;
if (beaconAlpha > 0.f) {
CTexturedQuadFilter::Vert verts[4] = {{{-4.f, -8.f, 8.f}, {0.f, 1.f}},
{{-4.f, -8.f, 0.f}, {0.f, 0.f}},
{{4.f, -8.f, 8.f}, {1.f, 1.f}},
{{4.f, -8.f, 0.f}, {1.f, 0.f}}};
float alpha = beaconAlpha;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
} else
alpha *= xa8_renderStates[0].x34_alphaSurfaceVisited;
alpha *= mapAlpha;
zeus::CColor color = zeus::skWhite;
2018-12-08 05:30:43 +00:00
color.a() = alpha;
filter.drawVerts(color, verts);
}
2018-12-08 05:30:43 +00:00
}
}
}
// No zread, no zwrite
// Ambient color white
// Disable all lights
if (m_frmeInitialized) {
float frmeAlpha = 0.f;
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
frmeAlpha = 1.f;
} else {
if (x1c0_nextState != EAutoMapperState::MiniMap) {
if (x1c4_interpDur > 0.f)
frmeAlpha = x1c8_interpTime / x1c4_interpDur;
} else {
if (x1c4_interpDur > 0.f)
frmeAlpha = x1c8_interpTime / x1c4_interpDur;
frmeAlpha = 1.f - frmeAlpha;
}
}
CGraphics::SetDepthRange(DEPTH_NEAR, DEPTH_NEAR);
CGuiWidgetDrawParms parms(frmeAlpha, zeus::skZero3f);
2018-12-08 05:30:43 +00:00
x28_frmeMapScreen->Draw(parms);
CGraphics::SetDepthRange(DEPTH_NEAR, DEPTH_HUD);
}
2017-04-15 05:32:25 +00:00
}
2017-02-18 02:19:50 +00:00
2018-12-08 05:30:43 +00:00
void CAutoMapper::TransformRenderStatesWorldToUniverse() {
const CMapUniverse::CMapWorldData& mapuWld = x8_mapu->GetMapWorldData(x9c_worldIdx);
zeus::CQuaternion rot = zeus::CQuaternion(mapuWld.GetWorldTransform().buildMatrix3f());
xa8_renderStates[2].x8_camOrientation *= rot;
xa8_renderStates[2].x20_areaPoint = mapuWld.GetWorldTransform() * xa8_renderStates[2].x20_areaPoint;
xa8_renderStates[0].x8_camOrientation *= rot;
xa8_renderStates[0].x20_areaPoint = mapuWld.GetWorldTransform() * xa8_renderStates[0].x20_areaPoint;
xa8_renderStates[1].x8_camOrientation *= rot;
xa8_renderStates[1].x20_areaPoint = mapuWld.GetWorldTransform() * xa8_renderStates[1].x20_areaPoint;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::TransformRenderStatesUniverseToWorld() {
const CMapUniverse::CMapWorldData& mapuWld = x8_mapu->GetMapWorldData(x9c_worldIdx);
zeus::CTransform inv = mapuWld.GetWorldTransform().inverse();
zeus::CQuaternion invRot = zeus::CQuaternion(inv.buildMatrix3f());
xa8_renderStates[2].x8_camOrientation *= invRot;
xa8_renderStates[2].x20_areaPoint = inv * xa8_renderStates[2].x20_areaPoint;
xa8_renderStates[0].x8_camOrientation *= invRot;
xa8_renderStates[0].x20_areaPoint = inv * xa8_renderStates[0].x20_areaPoint;
xa8_renderStates[1].x8_camOrientation *= invRot;
xa8_renderStates[1].x20_areaPoint = inv * xa8_renderStates[1].x20_areaPoint;
2017-04-15 05:32:25 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::TransformRenderStateWorldToUniverse(SAutoMapperRenderState& state) {
state.x20_areaPoint = x8_mapu->GetMapWorldData(x9c_worldIdx).GetWorldTransform() * xa8_renderStates[1].x20_areaPoint;
2017-02-18 02:19:50 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::SetupHintNavigation() {
if (!g_GameState->GameOptions().GetIsHintSystemEnabled())
return;
x1e0_hintSteps.clear();
x1f8_hintLocations.clear();
CHintOptions& hintOpts = g_GameState->HintOptions();
const CHintOptions::SHintState* curHint = hintOpts.GetCurrentDisplayedHint();
bool navigating = false;
if (curHint && curHint->CanContinue()) {
navigating = true;
x1e0_hintSteps.push_back({SAutoMapperHintStep::ShowBeacon{}, 0.75f});
const CGameHintInfo::CGameHint& nextHint = g_MemoryCardSys->GetHints()[hintOpts.GetNextHintIdx()];
CAssetId curMlvl = x24_world->IGetWorldAssetId();
for (const CGameHintInfo::SHintLocation& loc : nextHint.GetLocations()) {
if (loc.x0_mlvlId != curMlvl) {
x1e0_hintSteps.push_back({SAutoMapperHintStep::SwitchToUniverse{}});
x1e0_hintSteps.push_back({SAutoMapperHintStep::PanToWorld{}, curMlvl});
x1e0_hintSteps.push_back({SAutoMapperHintStep::SwitchToWorld{}, curMlvl});
} else {
x1e0_hintSteps.push_back({SAutoMapperHintStep::ZoomOut{}});
}
x1e0_hintSteps.push_back({SAutoMapperHintStep::PanToArea{}, loc.x8_areaId});
x1e0_hintSteps.push_back({SAutoMapperHintStep::ZoomIn{}});
x1e0_hintSteps.push_back({SAutoMapperHintStep::ShowBeacon{}, 1.f});
x1f8_hintLocations.push_back({0, 0.f, loc.x0_mlvlId, loc.x8_areaId});
}
}
for (u32 i = 0; i < hintOpts.GetHintStates().size(); ++i) {
const CHintOptions::SHintState& state = hintOpts.GetHintStates()[i];
if (navigating && hintOpts.GetNextHintIdx() == i)
continue;
if (state.x0_state != CHintOptions::EHintState::Displaying)
continue;
const CGameHintInfo::CGameHint& hint = g_MemoryCardSys->GetHints()[i];
for (const CGameHintInfo::SHintLocation& loc : hint.GetLocations())
x1f8_hintLocations.push_back({1, 1.f, loc.x0_mlvlId, loc.x8_areaId});
}
2017-04-15 05:32:25 +00:00
}
2017-02-18 02:19:50 +00:00
2018-12-08 05:30:43 +00:00
CAssetId CAutoMapper::GetAreaHintDescriptionString(CAssetId mreaId) {
const CHintOptions& hintOpts = g_GameState->HintOptions();
for (u32 i = 0; i < hintOpts.GetHintStates().size(); ++i) {
const CHintOptions::SHintState& state = hintOpts.GetHintStates()[i];
if (state.x0_state != CHintOptions::EHintState::Displaying)
continue;
const CGameHintInfo::CGameHint& memHint = g_MemoryCardSys->GetHints()[i];
for (const CGameHintInfo::SHintLocation& loc : memHint.GetLocations()) {
if (loc.x4_mreaId != mreaId)
continue;
for (const SAutoMapperHintLocation& hintLoc : x1f8_hintLocations) {
if (hintLoc.xc_areaId != loc.x8_areaId)
continue;
if (hintLoc.x4_beaconAlpha > 0.f)
return loc.xc_stringId;
}
}
}
return -1;
2017-04-16 20:56:34 +00:00
}
2018-12-08 05:30:43 +00:00
void CAutoMapper::OnNewInGameGuiState(EInGameGuiState state, const CStateManager& mgr) {
if (state == EInGameGuiState::MapScreen) {
MP1::CMain::EnsureWorldPaksReady();
const CWorld& wld = *mgr.GetWorld();
const_cast<CMapWorld*>(wld.GetMapWorld())->SetWhichMapAreasLoaded(wld, 0, 9999);
SetupHintNavigation();
BeginMapperStateTransition(EAutoMapperState::MapScreen, mgr);
x28_frmeMapScreen = g_SimplePool->GetObj("FRME_MapScreen");
SetResLockState(x210_lstick, true);
SetResLockState(x25c_cstick, true);
SetResLockState(x2a8_ltrigger, true);
SetResLockState(x2bc_rtrigger, true);
SetResLockState(x2d0_abutton, true);
} else {
MP1::CMain::EnsureWorldPakReady(g_GameState->CurrentWorldAssetId());
if (x1bc_state == EAutoMapperState::MapScreenUniverse || x24_world == mgr.GetWorld()) {
BeginMapperStateTransition(EAutoMapperState::MiniMap, mgr);
x328_ = 0;
}
LeaveMapScreenState();
}
2017-02-18 02:19:50 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde