CCameraManager imps

This commit is contained in:
Jack Andersen 2016-04-16 16:50:45 -10:00
parent 7afdc556fd
commit 1817227465
29 changed files with 452 additions and 34 deletions

View File

@ -13,14 +13,14 @@ struct CameraShaker : IScriptObject
{
DECL_YAML
String<-1> name;
Value<float> unknown1;
Value<float> unknown2;
Value<float> unknown3;
Value<float> unknown4;
Value<float> unknown5;
Value<float> unknown6;
Value<float> unknown7;
Value<bool> unknown8;
Value<float> xA;
Value<float> xB;
Value<float> yA;
Value<float> yB;
Value<float> zA;
Value<float> zB;
Value<float> duration;
Value<bool> shakeY;
};
}
}

View File

@ -0,0 +1,19 @@
#include "CSfxManager.hpp"
namespace urde
{
void CSfxManager::AddListener(ESfxChannels,
const zeus::CVector3f& vec1, const zeus::CVector3f& vec2,
const zeus::CVector3f& right, const zeus::CVector3f& up,
float, float, float, u32, u8)
{
}
void CSfxManager::UpdateListener(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CVector3f& heading, const zeus::CVector3f& up,
u8 vol)
{
}
}

View File

@ -12,8 +12,11 @@ namespace urde
class CSfxManager
{
public:
enum class ESfxChannels
{
Zero,
One
};
enum class ESfxAudibility
@ -58,7 +61,7 @@ class CSfxManager
virtual void Play()=0;
virtual void Stop()=0;
virtual bool Ready()=0;
virtual ESfxAudibility GetAudible(const CVector3f&)=0;
virtual ESfxAudibility GetAudible(const zeus::CVector3f&)=0;
virtual u32 GetVoice() const=0;
void Release() {m_available = true;}
@ -78,7 +81,7 @@ class CSfxManager
void Play();
void Stop();
bool Ready();
ESfxAudibility GetAudible(const CVector3f&);
ESfxAudibility GetAudible(const zeus::CVector3f&);
u32 GetVoice() const;
u32 GetHandle() const {return m_emitterHandle;}
@ -99,7 +102,7 @@ class CSfxManager
void Play();
void Stop();
bool Ready();
ESfxAudibility GetAudible(const CVector3f&) {return Aud3;}
ESfxAudibility GetAudible(const zeus::CVector3f&) {return ESfxAudibility::Aud3;}
u32 GetVoice() const {return m_voiceHandle;}
void SetVolume(s16 vol) {m_vol = vol;}
@ -126,6 +129,14 @@ class CSfxManager
static u32 kAllAreas;
static ESfxChannels GetCurrentChannel() {return m_currentChannel;}
static void AddListener(ESfxChannels,
const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CVector3f& heading, const zeus::CVector3f& up,
float frontRadius, float surroundRadius, float soundSpeed,
u32 flags /* 0x1 for doppler */, u8 vol);
static void UpdateListener(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CVector3f& heading, const zeus::CVector3f& up,
u8 vol);
};
}

View File

View File

@ -0,0 +1,13 @@
#ifndef __URDE_CFLUIDPLANEMANAGER_HPP__
#define __URDE_CFLUIDPLANEMANAGER_HPP__
namespace urde
{
class CFluidPlaneManager
{
};
}
#endif // __URDE_CFLUIDPLANEMANAGER_HPP__

View File

@ -29,6 +29,8 @@ add_library(RuntimeCommon
CIOWin.hpp
CIOWinManager.hpp CIOWinManager.cpp
CStateManager.hpp CStateManager.cpp
CWeaponMgr.hpp CWeaponMgr.cpp
CFluidPlaneManager.hpp CFluidPlaneManager.cpp
CGameState.hpp CGameState.cpp
CScriptMailbox.hpp CScriptMailbox.cpp
CPlayerState.hpp CPlayerState.cpp

View File

@ -1,4 +1,12 @@
#include "CStateManager.hpp"
#include "Camera/CCameraShakeData.hpp"
#include "CSortedLists.hpp"
#include "CWeaponMgr.hpp"
#include "CFluidPlaneManager.hpp"
#include "World/CEnvFxManager.hpp"
#include "World/CActorModelParticles.hpp"
#include "World/CTeamAiTypes.hpp"
#include "Input/CRumbleManager.hpp"
namespace urde
{

View File

@ -6,6 +6,8 @@
#include "ScriptObjectSupport.hpp"
#include "GameObjectLists.hpp"
#include "Camera/CCameraManager.hpp"
#include "Camera/CCameraFilter.hpp"
#include "CRandom16.hpp"
namespace urde
{
@ -14,26 +16,45 @@ class CMapWorldInfo;
class CPlayerState;
class CWorldTransManager;
class CObjectList;
class CSortedListManager;
class CWeaponMgr;
class CFluidPlaneManager;
class CEnvFxManager;
class CActorModelParticles;
class CTeamAiTypes;
class CRumbleManager;
class CStateManager
{
TUniqueId x8_idArr[1024] = {};
std::unique_ptr<CObjectList> x80c_allObjs;
std::unique_ptr<CActorList> x814_allObjs;
std::unique_ptr<CPhysicsActorList> x81c_allObjs;
std::unique_ptr<CGameCameraList> x824_allObjs;
std::unique_ptr<CGameLightList> x82c_allObjs;
std::unique_ptr<CListeningAiList> x834_allObjs;
std::unique_ptr<CAiWaypointList> x83c_allObjs;
std::unique_ptr<CPlatformAndDoorList> x844_allObjs;
std::unique_ptr<CActorList> x814_actorObjs;
std::unique_ptr<CPhysicsActorList> x81c_physActorObjs;
std::unique_ptr<CGameCameraList> x824_cameraObjs;
std::unique_ptr<CGameLightList> x82c_lightObjs;
std::unique_ptr<CListeningAiList> x834_listenAiObjs;
std::unique_ptr<CAiWaypointList> x83c_aiWaypointObjs;
std::unique_ptr<CPlatformAndDoorList> x844_platformAndDoorObjs;
std::list<u32> x858_;
// x86c_stateManagerContainer;
std::unique_ptr<CCameraManager> x870_cameraManager;
std::unique_ptr<CSortedListManager> x874_sortedListManager;
std::unique_ptr<CWeaponMgr> x878_weaponManager;
std::unique_ptr<CFluidPlaneManager> x87c_fluidPlaneManager;
std::unique_ptr<CEnvFxManager> x880_envFxManager;
std::unique_ptr<CActorModelParticles> x884_actorModelParticles;
std::unique_ptr<CTeamAiTypes> x888_teamAiTypes;
std::unique_ptr<CRumbleManager> x88c_rumbleManager;
CRandom16 x8f8_random;
CRandom16* x8fc_activeRandom = nullptr;
std::shared_ptr<CPlayerState> x8b8_playerState;
CCameraFilterPass xaf8_camFilterPasses[9];
CCameraBlurPass xc88_camBlurPasses[9];
public:
CStateManager(const std::weak_ptr<CScriptMailbox>&,
const std::weak_ptr<CMapWorldInfo>&,
@ -42,15 +63,27 @@ public:
const std::shared_ptr<CPlayerState>& GetPlayerState() const {return x8b8_playerState;}
void GetObjectListById() const
const CObjectList* GetObjectListById(EGameObjectList type) const
{
const std::unique_ptr<CObjectList>* lists = &x80c_allObjs;
return lists[int(type)].get();
}
void GetObjectById(TUniqueId uid) const
CObjectList* GetObjectListById(EGameObjectList type)
{
std::unique_ptr<CObjectList>* lists = &x80c_allObjs;
return lists[int(type)].get();
}
CEntity* GetObjectById(TUniqueId uid)
{
return x80c_allObjs->GetObjectById(uid);
}
void SendScriptMsg(TUniqueId uid, TEditorId eid, EScriptObjectMessage msg, EScriptObjectState state);
TUniqueId AllocateUniqueId();
CRandom16* GetActiveRandom() {return x8fc_activeRandom;}
CRumbleManager& GetRumbleManager() {return *x88c_rumbleManager;}
CCameraFilterPass& GetCameraFilterPass(int idx) {return xaf8_camFilterPasses[idx];}
};
}

0
Runtime/CWeaponMgr.cpp Normal file
View File

13
Runtime/CWeaponMgr.hpp Normal file
View File

@ -0,0 +1,13 @@
#ifndef __URDE_CWEAPONMGR_HPP__
#define __URDE_CWEAPONMGR_HPP__
namespace urde
{
class CWeaponMgr
{
};
}
#endif // __URDE_CWEAPONMGR_HPP__

View File

View File

@ -0,0 +1,35 @@
#ifndef __URDE_CCAMERAFILTER_HPP__
#define __URDE_CCAMERAFILTER_HPP__
#include "zeus/CColor.hpp"
#include "RetroTypes.hpp"
namespace urde
{
class CCameraFilterPass
{
public:
enum class EFilterType
{
Zero,
One
};
enum class EFilterShape
{
Zero,
One
};
private:
public:
void SetFilter(EFilterType type, EFilterShape shape, float, const zeus::CColor& color, u32);
void DisableFilter(float);
};
class CCameraBlurPass
{
};
}
#endif // __URDE_CCAMERAFILTER_HPP__

View File

@ -1,5 +1,10 @@
#include "CCameraManager.hpp"
#include "CCameraShakeData.hpp"
#include "Audio/CSfxManager.hpp"
#include "CGameCamera.hpp"
#include "CStateManager.hpp"
#include "Input/CRumbleManager.hpp"
#include "World/CScriptWater.hpp"
namespace urde
{
@ -7,6 +12,128 @@ namespace urde
CCameraManager::CCameraManager(TUniqueId curCameraId)
: x0_curCameraId(curCameraId)
{
CSfxManager::AddListener(CSfxManager::ESfxChannels::One,
zeus::CVector3f::skZero, zeus::CVector3f::skZero,
{1.f, 0.f, 0.f}, {0.f, 0.f, 1.f}, 50.f, 50.f, 1000.f, 1, 0x7f);
}
zeus::CVector3f CCameraManager::GetGlobalCameraTranslation(const CStateManager& stateMgr) const
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
return camera->GetTransform() * x30_shakeOffset;
}
zeus::CTransform CCameraManager::GetCurrentCameraTransform(const CStateManager& stateMgr) const
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
return camera->GetTransform() * zeus::CTransform::Translate(x30_shakeOffset);
}
void CCameraManager::RemoveCameraShaker(int id)
{
for (auto it=x18_shakers.begin() ; it != x18_shakers.end() ; ++it)
if (it->x20_shakerId == id)
{
x18_shakers.erase(it);
break;
}
}
int CCameraManager::AddCameraShaker(const CCameraShakeData& data)
{
x18_shakers.emplace_back(data);
x18_shakers.back().x20_shakerId = ++x2c_lastShakeId;
return x2c_lastShakeId;
}
void CCameraManager::AddCinemaCamera(TUniqueId id, CStateManager& stateMgr)
{
x4_cineCameras.push_back(id);
}
void CCameraManager::SetInsideFluid(bool val, TUniqueId fluidId)
{
if (val)
{
++x74_fluidCounter;
x78_fluidId = fluidId;
}
else
--x74_fluidCounter;
}
void CCameraManager::Update(float dt, CStateManager& stateMgr)
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
zeus::CVector3f heading = camera->GetTransform().m_basis * zeus::CVector3f{0.f, 1.f, 0.f};
CSfxManager::UpdateListener(camera->GetTransform().m_origin, zeus::CVector3f::skZero,
heading, {0.f, 0.f, 1.f}, 0x7f);
x30_shakeOffset = zeus::CVector3f::skZero;
for (auto it=x18_shakers.begin() ; it != x18_shakers.end() ;)
{
if (it->x1c_curTime >= it->x18_duration)
{
it = x18_shakers.erase(it);
continue;
}
x30_shakeOffset += it->GeneratePoint(dt, *stateMgr.GetActiveRandom());
++it;
}
if (x18_shakers.size())
{
if (!x86_25_rumbling || x86_24_)
{
stateMgr.GetRumbleManager().Rumble(ERumbleFxId::Seven, stateMgr, ERumblePriority::Two);
x86_25_rumbling = true;
}
}
else
{
x86_25_rumbling = false;
if (x84_rumbleId != -1)
{
stateMgr.GetRumbleManager().StopRumble(x84_rumbleId);
x84_rumbleId = -1;
}
}
if (x74_fluidCounter)
{
CScriptWater* water = dynamic_cast<CScriptWater*>(stateMgr.GetObjectById(x78_fluidId));
if (water)
{
// TODO: Finish
zeus::CColor tmpColor; // Get from water
zeus::CVector2f tmpVector; // Get from camera
x3c_fog.SetFogExplicit(ERglFogMode::Four, tmpColor, tmpVector);
stateMgr.GetCameraFilterPass(4).SetFilter(CCameraFilterPass::EFilterType::One,
CCameraFilterPass::EFilterShape::Zero,
0.f, tmpColor, -1);
}
x86_26_inWater = true;
}
else
{
x86_26_inWater = false;
x3c_fog.DisableFog();
stateMgr.GetCameraFilterPass(4).DisableFilter(dt);
}
x3c_fog.Update(dt);
}
CGameCamera* CCameraManager::GetCurrentCamera(CStateManager& stateMgr) const
{
CObjectList* camList = stateMgr.GetObjectListById(EGameObjectList::GameCamera);
return static_cast<CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
}
const CGameCamera* CCameraManager::GetCurrentCamera(const CStateManager& stateMgr) const
{
const CObjectList* camList = stateMgr.GetObjectListById(EGameObjectList::GameCamera);
return static_cast<const CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
}
}

View File

@ -18,9 +18,26 @@ class CCameraManager
TUniqueId x0_curCameraId;
std::vector<TUniqueId> x4_cineCameras;
std::list<CCameraShakeData> x18_shakers;
zeus::CVector3f x30_;
CFirstPersonCamera* x7c_fpCamera;
CBallCamera* x80_ballCamera;
u32 x2c_lastShakeId = 0;
zeus::CVector3f x30_shakeOffset;
CGameArea::CAreaFog x3c_fog;
int x74_fluidCounter = 0;
TUniqueId x78_fluidId = kInvalidUniqueId;
CFirstPersonCamera* x7c_fpCamera = nullptr;
CBallCamera* x80_ballCamera = nullptr;
s16 x84_rumbleId = -1;
union
{
struct
{
bool x86_24_ : 1;
bool x86_25_rumbling : 1;
bool x86_26_inWater : 1;
};
u8 _dummy = 0;
};
public:
CCameraManager(TUniqueId curCameraId);
@ -31,14 +48,15 @@ public:
}
bool IsInCinematicCamera() const {return x4_cineCameras.size() != 0;}
zeus::CVector3f GetGlobalCameraTranslation(const CStateManager& stateMgr) const;
zeus::CTransform GetGlobalCameraTransform(const CStateManager& stateMgr) const;
void RemoveCameraShaker(int);
zeus::CTransform GetCurrentCameraTransform(const CStateManager& stateMgr) const;
void RemoveCameraShaker(int id);
int AddCameraShaker(const CCameraShakeData& data);
void AddCinemaCamera(TUniqueId, CStateManager& stateMgr);
void SetInsideFluid(bool, TUniqueId);
void Update(float dt, CStateManager& stateMgr);
CGameCamera* GetCurrentCamera(CStateManager& stateMgr) const;
const CGameCamera* GetCurrentCamera(const CStateManager& stateMgr) const;
void SetCurrentCameraId(TUniqueId id, CStateManager& stateMgr);
void SetCurrentCameraId(TUniqueId id, CStateManager& stateMgr) {x0_curCameraId = id;}
TUniqueId GetCurrentCameraId() const
{
if (x4_cineCameras.size())

View File

@ -0,0 +1,37 @@
#include "CCameraShakeData.hpp"
#include "CRandom16.hpp"
namespace urde
{
CCameraShakeData::CCameraShakeData(float xA, float xB, float yA, float yB,
float zA, float zB, float duration, bool shakeY)
: x0_pointA(xA, yA, zA), xc_pointB(xB, yB, zB), x18_duration(duration), x40_shakeY(shakeY) {}
zeus::CVector3f CCameraShakeData::GeneratePoint(float dt, CRandom16& r)
{
x3c_cycleTimeLeft -= dt;
if (x3c_cycleTimeLeft <= 0.f)
{
x3c_cycleTimeLeft = r.Range(1.f / 60.f, 0.1f);
float zVal = r.Range(-1.f, 1.f);
float yVal = 0.f;
if (x40_shakeY)
yVal = r.Range(-1.f, 1.f);
float xVal = r.Range(-1.f, 1.f);
zeus::CVector3f shakeVec(xVal, yVal, zVal);
if (!shakeVec.canBeNormalized())
shakeVec = {0.f, 0.f, 1.f};
else
shakeVec.normalize();
x30_velocity = (shakeVec - x24_position) / x3c_cycleTimeLeft;
}
x24_position += x30_velocity * dt;
float interp = zeus::clamp(0.f, 1.f - (x18_duration - x1c_curTime) / x18_duration, 1.f);
x1c_curTime += dt;
return x24_position * zeus::CVector3f::lerp(x0_pointA, xc_pointB, interp);
}
}

View File

@ -1,13 +1,29 @@
#ifndef __URDE_CCAMERASHAKEDATA_HPP__
#define __URDE_CCAMERASHAKEDATA_HPP__
#include "zeus/CVector3f.hpp"
#include "RetroTypes.hpp"
namespace urde
{
class CRandom16;
class CCameraShakeData
{
friend class CCameraManager;
zeus::CVector3f x0_pointA;
zeus::CVector3f xc_pointB;
float x18_duration;
float x1c_curTime = 0.f;
u32 x20_shakerId = 0;
zeus::CVector3f x24_position;
zeus::CVector3f x30_velocity;
float x3c_cycleTimeLeft;
bool x40_shakeY;
public:
CCameraShakeData(float, float, float, float, float, float, float, bool);
CCameraShakeData(float xA, float xB, float yA, float yB,
float zA, float zB, float duration, bool shakeY);
zeus::CVector3f GeneratePoint(float dt, CRandom16& r);
};
}

View File

@ -1,14 +1,17 @@
#ifndef __URDE_CGAMECAMERA_HPP__
#define __URDE_CGAMECAMERA_HPP__
#include "CActor.hpp"
#include "World/CActor.hpp"
#include "zeus/CTransform.hpp"
namespace urde
{
class CGameCamera : public CActor
{
zeus::CTransform x34_;
public:
const zeus::CTransform& GetTransform() const {return x34_;}
};
}

View File

@ -5,4 +5,5 @@ add_library(RuntimeCommonCamera
CBallCamera.hpp CBallCamera.cpp
CPathCamera.hpp CPathCamera.cpp
CCinematicCamera.hpp CCinematicCamera.cpp
CCameraShakeData.hpp CCameraShakeData.cpp)
CCameraShakeData.hpp CCameraShakeData.cpp
CCameraFilter.hpp CCameraFilter.cpp)

View File

@ -7,11 +7,12 @@ namespace urde
{
enum class ERumbleFxId
{
Seven = 7
};
enum class ERumblePriority
{
None
None,
Two = 2
};
struct SAdsrData;

View File

View File

@ -0,0 +1,13 @@
#ifndef __URDE_CACTORMODELPARTICLES_HPP__
#define __URDE_CACTORMODELPARTICLES_HPP__
namespace urde
{
class CActorModelParticles
{
};
}
#endif // __URDE_CACTORMODELPARTICLES_HPP__

View File

View File

@ -0,0 +1,13 @@
#ifndef __URDE_CENVFXMANAGER_HPP__
#define __URDE_CENVFXMANAGER_HPP__
namespace urde
{
class CEnvFxManager
{
};
}
#endif // __URDE_CENVFXMANAGER_HPP__

View File

@ -1,11 +1,34 @@
#ifndef __URDE_CGAMEAREA_HPP__
#define __URDE_CGAMEAREA_HPP__
#include "zeus/CVector2f.hpp"
#include "zeus/CColor.hpp"
#include "RetroTypes.hpp"
namespace urde
{
enum class ERglFogMode
{
Four = 4
};
class CGameArea
{
public:
class CAreaFog
{
zeus::CVector2f x4_ = {0.f, 1024.f};
zeus::CVector2f xc_ = {0.f, 1024.f};
zeus::CVector2f x14_;
zeus::CVector3f x1c_ = {0.5f};
zeus::CVector3f x28_ = {0.5f};
float x34_ = 0.f;
public:
void SetFogExplicit(ERglFogMode, const zeus::CColor& color, const zeus::CVector2f& vec);
void DisableFog();
void Update(float dt);
};
};
}

View File

@ -6,4 +6,8 @@ add_library(RuntimeCommonWorld
CAi.hpp CAi.cpp
CEntity.hpp CEntity.cpp
CPhysicsActor.hpp CPhysicsActor.cpp
CWorldTransManager.hpp CWorldTransManager.cpp)
CWorldTransManager.hpp CWorldTransManager.cpp
CEnvFxManager.hpp CEnvFxManager.cpp
CActorModelParticles.hpp CActorModelParticles.cpp
CTeamAiTypes.hpp CTeamAiTypes.cpp
CScriptWater.hpp CScriptWater.cpp)

View File

View File

@ -0,0 +1,15 @@
#ifndef __URDE_CSCRIPTWATER_HPP__
#define __URDE_CSCRIPTWATER_HPP__
#include "CActor.hpp"
namespace urde
{
class CScriptWater : public CActor
{
};
}
#endif // __URDE_CSCRIPTWATER_HPP__

View File

View File

@ -0,0 +1,13 @@
#ifndef __URDE_CTEAMAITYPES_HPP__
#define __URDE_CTEAMAITYPES_HPP__
namespace urde
{
class CTeamAiTypes
{
};
}
#endif // __URDE_CTEAMAITYPES_HPP__