metaforce/Runtime/AutoMapper/CAutoMapper.hpp

278 lines
12 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2016-07-29 17:00:23 +00:00
#include <array>
#include <list>
#include <memory>
#include <optional>
#include <vector>
#include "Runtime/rstl.hpp"
#include "Runtime/RetroTypes.hpp"
#include "Runtime/MP1/CInGameGuiManager.hpp"
#include <zeus/CQuaternion.hpp>
#include <zeus/CTransform.hpp>
#include <zeus/CVector2f.hpp>
#include <zeus/CVector2i.hpp>
#include <zeus/CVector3f.hpp>
2016-07-29 17:00:23 +00:00
2018-12-08 05:30:43 +00:00
namespace urde {
class CMapUniverse;
2016-07-29 17:00:23 +00:00
class CMapWorldInfo;
class CStateManager;
class IWorld;
struct CFinalInput;
2017-03-20 05:09:53 +00:00
2018-12-08 05:30:43 +00:00
class CAutoMapper {
2016-07-29 17:00:23 +00:00
public:
2018-12-08 05:30:43 +00:00
using EInGameGuiState = MP1::EInGameGuiState;
enum class ELoadPhase { LoadResources, LoadUniverse, Done };
enum class EAutoMapperState { MiniMap, MapScreen, MapScreenUniverse };
struct SAutoMapperRenderState {
enum class Ease { None, Linear, Out, In, InOut };
using FGetViewportSize = zeus::CVector2i (*)();
FGetViewportSize m_getViewportSize = nullptr;
2018-12-08 05:30:43 +00:00
zeus::CVector2i x0_viewportSize;
zeus::CQuaternion x8_camOrientation;
float x18_camDist = 0.0f;
float x1c_camAngle = 0.0f;
2018-12-08 05:30:43 +00:00
zeus::CVector3f x20_areaPoint;
float x2c_drawDepth1 = 0.0f;
float x30_drawDepth2 = 0.0f;
float x34_alphaSurfaceVisited = 0.0f;
float x38_alphaOutlineVisited = 0.0f;
float x3c_alphaSurfaceUnvisited = 0.0f;
float x40_alphaOutlineUnvisited = 0.0f;
Ease x44_viewportEase = Ease::None;
Ease x48_camEase = Ease::None;
Ease x4c_pointEase = Ease::None;
Ease x50_depth1Ease = Ease::None;
Ease x54_depth2Ease = Ease::None;
Ease x58_alphaEase = Ease::None;
2018-12-08 05:30:43 +00:00
SAutoMapperRenderState() = default;
SAutoMapperRenderState(FGetViewportSize getViewportSize, const zeus::CQuaternion& camOrientation, float camDist,
float camAngle, const zeus::CVector3f& areaPoint, float drawDepth1, float drawDepth2,
float alphaSurfaceVisited, float alphaOutlineVisited, float alphaSurfaceUnvisited,
float alphaOutlineUnvisited)
: m_getViewportSize(getViewportSize)
, x0_viewportSize(getViewportSize())
, x8_camOrientation(camOrientation)
, x18_camDist(camDist)
, x1c_camAngle(camAngle)
, x20_areaPoint(areaPoint)
, x2c_drawDepth1(drawDepth1)
, x30_drawDepth2(drawDepth2)
, x34_alphaSurfaceVisited(alphaSurfaceVisited)
, x38_alphaOutlineVisited(alphaOutlineVisited)
, x3c_alphaSurfaceUnvisited(alphaSurfaceUnvisited)
, x40_alphaOutlineUnvisited(alphaOutlineUnvisited) {}
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
static void InterpolateWithClamp(const SAutoMapperRenderState& a, SAutoMapperRenderState& out,
const SAutoMapperRenderState& b, float t);
void ResetInterpolation() {
x44_viewportEase = Ease::None;
x48_camEase = Ease::None;
x4c_pointEase = Ease::None;
x50_depth1Ease = Ease::None;
x54_depth2Ease = Ease::None;
x58_alphaEase = Ease::None;
}
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector2i GetViewportSize() const {
if (m_getViewportSize)
return m_getViewportSize();
else
return x0_viewportSize;
}
};
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
struct SAutoMapperHintStep {
enum class Type { PanToArea, PanToWorld, SwitchToUniverse, SwitchToWorld, ShowBeacon, ZoomIn, ZoomOut };
struct PanToArea {};
struct PanToWorld {};
struct SwitchToUniverse {};
struct SwitchToWorld {};
struct ShowBeacon {};
struct ZoomIn {};
struct ZoomOut {};
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
Type x0_type;
union {
CAssetId x4_worldId;
TAreaId x4_areaId;
float x4_float;
2017-04-15 05:32:25 +00:00
};
2018-12-08 05:30:43 +00:00
bool x8_processing = false;
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
SAutoMapperHintStep(PanToArea, TAreaId areaId) : x0_type(Type::PanToArea), x4_areaId(areaId) {}
SAutoMapperHintStep(PanToWorld, CAssetId worldId) : x0_type(Type::PanToWorld), x4_worldId(worldId) {}
SAutoMapperHintStep(SwitchToUniverse) : x0_type(Type::SwitchToUniverse), x4_worldId(0) {}
SAutoMapperHintStep(SwitchToWorld, CAssetId worldId) : x0_type(Type::SwitchToWorld), x4_worldId(worldId) {}
SAutoMapperHintStep(ShowBeacon, float val) : x0_type(Type::ShowBeacon), x4_float(val) {}
SAutoMapperHintStep(ZoomIn) : x0_type(Type::ZoomIn), x4_worldId(0) {}
SAutoMapperHintStep(ZoomOut) : x0_type(Type::ZoomOut), x4_worldId(0) {}
};
struct SAutoMapperHintLocation {
u32 x0_showBeacon;
float x4_beaconAlpha;
CAssetId x8_worldId;
TAreaId xc_areaId;
};
2016-07-29 17:00:23 +00:00
private:
2018-12-08 05:30:43 +00:00
enum class EZoomState { None, In, Out };
2017-04-15 05:32:25 +00:00
2018-12-08 05:30:43 +00:00
ELoadPhase x4_loadPhase = ELoadPhase::LoadResources;
TLockedToken<CMapUniverse> x8_mapu;
std::vector<std::unique_ptr<IWorld>> x14_dummyWorlds;
CWorld* x24_world;
2018-12-08 05:30:43 +00:00
TLockedToken<CGuiFrame> x28_frmeMapScreen; // Used to be ptr
bool m_frmeInitialized = false;
TLockedToken<CModel> x30_miniMapSamus;
TLockedToken<CTexture> x3c_hintBeacon;
std::vector<CTexturedQuadFilter> m_hintBeaconFilters;
rstl::reserved_vector<TLockedToken<CTexture>, 5> x48_mapIcons;
CAssetId x74_areaHintDescId;
TLockedToken<CStringTable> x78_areaHintDesc;
CAssetId x88_mapAreaStringId;
TLockedToken<CStringTable> x8c_mapAreaString; // Used to be optional
u32 x9c_worldIdx = 0;
TAreaId xa0_curAreaId;
TAreaId xa4_otherAreaId;
std::array<SAutoMapperRenderState, 3> xa8_renderStates; // xa8, x104, x160; current, next, prev
2018-12-08 05:30:43 +00:00
EAutoMapperState x1bc_state = EAutoMapperState::MiniMap;
EAutoMapperState x1c0_nextState = EAutoMapperState::MiniMap;
float x1c4_interpDur = 0.f;
float x1c8_interpTime = 0.f;
CSfxHandle x1cc_panningSfx;
CSfxHandle x1d0_rotatingSfx;
CSfxHandle x1d4_zoomingSfx;
float x1d8_flashTimer = 0.f;
float x1dc_playerFlashPulse = 0.f;
std::list<SAutoMapperHintStep> x1e0_hintSteps;
std::list<SAutoMapperHintLocation> x1f8_hintLocations;
rstl::reserved_vector<TLockedToken<CTexture>, 9> x210_lstick;
rstl::reserved_vector<TLockedToken<CTexture>, 9> x25c_cstick;
rstl::reserved_vector<TLockedToken<CTexture>, 2> x2a8_ltrigger;
rstl::reserved_vector<TLockedToken<CTexture>, 2> x2bc_rtrigger;
rstl::reserved_vector<TLockedToken<CTexture>, 2> x2d0_abutton;
u32 x2e4_lStickPos = 0;
u32 x2e8_rStickPos = 0;
u32 x2ec_lTriggerPos = 0;
u32 x2f0_rTriggerPos = 0;
u32 x2f4_aButtonPos = 0;
CGuiTextPane* x2f8_textpane_areaname = nullptr;
CGuiTextPane* x2fc_textpane_hint = nullptr;
CGuiTextPane* x300_textpane_instructions = nullptr;
CGuiTextPane* x304_textpane_instructions1 = nullptr;
CGuiTextPane* x308_textpane_instructions2 = nullptr;
CGuiWidget* x30c_basewidget_leftPane = nullptr;
CGuiWidget* x310_basewidget_yButtonPane = nullptr;
CGuiWidget* x314_basewidget_bottomPane = nullptr;
float x318_leftPanePos = 0.f;
float x31c_yButtonPanePos = 0.f;
float x320_bottomPanePos = 0.f;
EZoomState x324_zoomState = EZoomState::None;
u32 x328_ = 0;
bool x32c_loadingDummyWorld = false;
2017-04-15 05:32:25 +00:00
std::optional<zeus::CVector2f> m_lastMouseCoord;
2019-01-23 07:52:19 +00:00
zeus::CVector2f m_mouseDelta;
boo::SScrollDelta m_lastAccumScroll;
boo::SScrollDelta m_mapScroll;
2018-12-08 05:30:43 +00:00
template <class T>
static void SetResLockState(T& list, bool lock) {
for (auto& res : list)
if (lock)
res.Lock();
else
res.Unlock();
}
bool NotHintNavigating() const;
bool CanLeaveMapScreenInternal(const CStateManager& mgr) const;
void LeaveMapScreen(const CStateManager& mgr);
void SetupMiniMapWorld(const CStateManager& mgr);
bool HasCurrentMapUniverseWorld() const;
bool CheckDummyWorldLoad(CStateManager& mgr);
void UpdateHintNavigation(float dt, CStateManager& mgr);
2018-12-08 05:30:43 +00:00
static zeus::CVector2i GetMiniMapViewportSize();
static zeus::CVector2i GetMapScreenViewportSize();
static float GetMapAreaMiniMapDrawDepth() { return 2.f; }
float GetMapAreaMaxDrawDepth(const CStateManager&, TAreaId) const;
static float GetMapAreaMiniMapDrawAlphaSurfaceVisited(const CStateManager&);
static float GetMapAreaMiniMapDrawAlphaOutlineVisited(const CStateManager&);
static float GetMapAreaMiniMapDrawAlphaSurfaceUnvisited(const CStateManager&);
static float GetMapAreaMiniMapDrawAlphaOutlineUnvisited(const CStateManager&);
float GetDesiredMiniMapCameraDistance(const CStateManager&) const;
static float GetBaseMapScreenCameraMoveSpeed();
float GetClampedMapScreenCameraDistance(float) const;
2018-12-08 05:30:43 +00:00
float GetFinalMapScreenCameraMoveSpeed() const;
void ProcessMapRotateInput(const CFinalInput& input, const CStateManager& mgr);
void ProcessMapZoomInput(const CFinalInput& input, const CStateManager& mgr);
void ProcessMapPanInput(const CFinalInput& input, const CStateManager& mgr);
void SetShouldPanningSoundBePlaying(bool);
void SetShouldZoomingSoundBePlaying(bool);
void SetShouldRotatingSoundBePlaying(bool);
void TransformRenderStatesWorldToUniverse();
void TransformRenderStatesUniverseToWorld();
void TransformRenderStateWorldToUniverse(SAutoMapperRenderState&);
void SetupHintNavigation();
CAssetId GetAreaHintDescriptionString(CAssetId mreaId);
2017-03-20 05:09:53 +00:00
2016-07-29 17:00:23 +00:00
public:
2018-12-08 05:30:43 +00:00
CAutoMapper(CStateManager& stateMgr);
bool CheckLoadComplete();
bool CanLeaveMapScreen(const CStateManager&) const;
2019-01-23 07:52:19 +00:00
float GetMapRotationX() const { return xa8_renderStates[0].x1c_camAngle; }
float GetMapRotationZ() const { return xa8_renderStates[0].x8_camOrientation.yaw(); }
TAreaId GetFocusAreaIndex() const { return xa0_curAreaId; }
CAssetId GetCurrWorldAssetId() const { return x24_world->IGetWorldAssetId(); }
2018-12-08 05:30:43 +00:00
void SetCurWorldAssetId(CAssetId mlvlId);
void MuteAllLoopedSounds();
void UnmuteAllLoopedSounds();
void ProcessControllerInput(const CFinalInput&, CStateManager&);
2019-01-23 07:52:19 +00:00
bool IsInPlayerControlState() const {
return IsInMapperState(EAutoMapperState::MapScreen) || IsInMapperState(EAutoMapperState::MapScreenUniverse);
}
2018-12-08 05:30:43 +00:00
void Update(float dt, const CStateManager& mgr);
void Draw(const CStateManager&, const zeus::CTransform&, float) const;
2019-01-23 07:52:19 +00:00
float GetTimeIntoInterpolation() const { return x1c8_interpTime; }
void BeginMapperStateTransition(EAutoMapperState, CStateManager&);
2018-12-08 05:30:43 +00:00
void CompleteMapperStateTransition(const CStateManager&);
void ResetInterpolationTimer(float);
SAutoMapperRenderState BuildMiniMapWorldRenderState(const CStateManager&, const zeus::CQuaternion&, TAreaId) const;
SAutoMapperRenderState BuildMapScreenWorldRenderState(const CStateManager&, const zeus::CQuaternion&, TAreaId,
bool) const;
SAutoMapperRenderState BuildMapScreenUniverseRenderState(const CStateManager&, const zeus::CQuaternion&,
TAreaId) const;
void LeaveMapScreenState();
void ProcessMapScreenInput(const CFinalInput& input, CStateManager& mgr);
2018-12-08 05:30:43 +00:00
zeus::CQuaternion GetMiniMapCameraOrientation(const CStateManager&) const;
zeus::CVector3f GetAreaPointOfInterest(const CStateManager&, TAreaId) const;
TAreaId FindClosestVisibleArea(const zeus::CVector3f&, const zeus::CUnitVector3f&, const CStateManager&,
const IWorld&, const CMapWorldInfo&) const;
std::pair<int, int> FindClosestVisibleWorld(const zeus::CVector3f&, const zeus::CUnitVector3f&,
const CStateManager&) const;
2017-03-20 05:09:53 +00:00
2018-12-08 05:30:43 +00:00
EAutoMapperState GetNextState() const { return x1c0_nextState; }
bool IsInMapperState(EAutoMapperState state) const { return state == x1bc_state && state == x1c0_nextState; }
bool IsInMapperStateTransition() const { return x1c0_nextState != x1bc_state; }
bool IsRenderStateInterpolating() const { return x1c8_interpTime < x1c4_interpDur; }
bool IsStateTransitioning() const { return x1bc_state != x1c0_nextState; }
bool IsFullyInMiniMapState() const { return IsInMapperState(EAutoMapperState::MiniMap); }
bool IsFullyOutOfMiniMapState() const {
return x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap;
}
void OnNewInGameGuiState(EInGameGuiState, CStateManager&);
2018-12-08 05:30:43 +00:00
float GetInterp() const {
if (x1c4_interpDur > 0.f)
return x1c8_interpTime / x1c4_interpDur;
return 0.f;
}
2016-07-29 17:00:23 +00:00
};
2018-12-08 05:30:43 +00:00
} // namespace urde