This commit is contained in:
Jack Andersen 2016-06-27 12:56:43 -10:00
commit 9d62e7d9f1
34 changed files with 511 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
version.h
*.user
.DS_Store
*.autosave

View File

@ -65,7 +65,7 @@ static const std::vector<FourCC> DecalTypes =
SBIG('NCDL'),SBIG('DDCL'),SBIG('CODL'),SBIG('MEDL'),
SBIG('GRDL'),SBIG('ICDL'),SBIG('GODL'),SBIG('WODL'),
SBIG('WTDL'),SBIG('3MUD'),SBIG('3LAV'),SBIG('3SAN'),
SBIG('CHDL')
SBIG('CHDL'),SBIG('ENDL')
};

View File

@ -14,7 +14,7 @@ class CGameState
{
int m_stateFlag = -1;
CPlayerState m_playerState;
CWorldTransManager m_transManager;
CWorldTransManager x9c_transManager;
float m_gameTime = 0.0;
CGameOptions m_gameOpts;
double xa0_playTime;
@ -22,7 +22,7 @@ public:
CGameState() {}
CGameState(CBitStreamReader& stream);
void SetCurrentWorldId(unsigned int id, const std::string& name);
CWorldTransManager& WorldTransitionManager() {return m_transManager;}
CWorldTransManager& WorldTransitionManager() {return x9c_transManager;}
void SetTotalPlayTime(float time);
};

View File

@ -47,6 +47,7 @@ add_library(RuntimeCommon
${WORLD_SOURCES}
#CMemory.hpp CMemory.cpp
CMemoryCardSys.hpp
CSaveWorld.hpp CSaveWorld.cpp
IAllocator.hpp IAllocator.cpp
CGameAllocator.hpp CGameAllocator.cpp
CDependencyGroup.hpp CDependencyGroup.cpp

0
Runtime/CSaveWorld.cpp Normal file
View File

12
Runtime/CSaveWorld.hpp Normal file
View File

@ -0,0 +1,12 @@
#ifndef __URDE_CSAVEWORLD_HPP__
#define __URDE_CSAVEWORLD_HPP__
namespace urde
{
class CSaveWorld
{
CSaveWorld(CInputStream& in);
};
}
#endif // __URDE_CSAVEWORLD_HPP__

View File

@ -1,6 +1,51 @@
#include "CCollidableAABox.hpp"
namespace urde
{
const CCollisionPrimitive::Type CCollidableAABox::sType(CCollidableAABox::SetStaticTableIndex, "CCollidableAABox");
u32 CCollidableAABox::sTableIndex = -1;
CCollidableAABox::CCollidableAABox()
{
}
zeus::CAABox CCollidableAABox::Transform(const zeus::CTransform& xf) const
{
return {xf.origin + x10_aabox.min, xf.origin + x10_aabox.max};
}
u32 CCollidableAABox::GetTableIndex() const
{
return sTableIndex;
}
zeus::CAABox CCollidableAABox::CalculateAABox(const zeus::CTransform& xf) const
{
return Transform(xf);
}
zeus::CAABox CCollidableAABox::CalculateLocalAABox() const
{
return x10_aabox;
}
FourCC CCollidableAABox::GetPrimType() const
{
return SBIG('AABX');
}
CRayCastResult CCollidableAABox::CastRayInternal(const CInternalRayCastStructure &) const
{
return {};
}
const CCollisionPrimitive::Type& CCollidableAABox::GetType()
{
return sType;
}
void CCollidableAABox::SetStaticTableIndex(u32 index)
{
sTableIndex = index;
}
}

View File

@ -1,11 +1,35 @@
#ifndef CCOLLIDABLEAABOX_HPP
#define CCOLLIDABLEAABOX_HPP
#ifndef __URDE_CCOLLIDABLEAABOX_HPP__
#define __URDE_CCOLLIDABLEAABOX_HPP__
#include "CCollisionPrimitive.hpp"
class CCollidableAABox
namespace urde
{
namespace Collide
{
bool AABox_AABox(const CInternalCollisionStructure&, CCollisionInfoList&);
bool AABox_AABox_Bool(const CInternalCollisionStructure&, CCollisionInfoList&);
}
class CCollidableAABox : public CCollisionPrimitive
{
static const Type sType;
static u32 sTableIndex;
zeus::CAABox x10_aabox;
public:
CCollidableAABox();
};
#endif // CCOLLIDABLEAABOX_HPP
zeus::CAABox Transform(const zeus::CTransform&) const;
virtual u32 GetTableIndex() const;
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const;
virtual zeus::CAABox CalculateLocalAABox() const;
virtual FourCC GetPrimType() const;
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
static const CCollisionPrimitive::Type& GetType();
static void SetStaticTableIndex(u32 index);
};
}
#endif // __URDE_CCOLLIDABLEAABOX_HPP__

View File

@ -0,0 +1,17 @@
#include "CCollidableCollisionSurface.hpp"
namespace urde
{
const CCollisionPrimitive::Type CCollidableCollisionSurface::sType(CCollidableCollisionSurface::SetStaticTableIndex, "CCollidableCollisionSurface");
u32 CCollidableCollisionSurface::sTableIndex = -1;
const CCollisionPrimitive::Type& CCollidableCollisionSurface::GetType()
{
return sType;
}
void CCollidableCollisionSurface::SetStaticTableIndex(u32 index)
{
sTableIndex = index;
}
}

View File

@ -0,0 +1,17 @@
#ifndef __URDE_COLLIDABLECOLLISIONSURFACE_HPP__
#define __URDE_COLLIDABLECOLLISIONSURFACE_HPP__
#include "CCollisionPrimitive.hpp"
namespace urde
{
class CCollidableCollisionSurface
{
static const CCollisionPrimitive::Type sType;
static u32 sTableIndex;
public:
static const CCollisionPrimitive::Type& GetType();
static void SetStaticTableIndex(u32 index);
};
}
#endif // __URDE_COLLIDABLECOLLISIONSURFACE_HPP__

View File

@ -11,7 +11,7 @@ namespace urde
{
class CCollidableOBBTreeGroup : public CCollisionPrimitive
{
static const CCollisionPrimitive::Type sType;
static const Type sType;
static u32 sTableIndex;
std::vector<std::unique_ptr<COBBTree>> x0_trees;
std::vector<zeus::CAABox> x10_aabbs;
@ -26,7 +26,7 @@ public:
virtual FourCC GetPrimType() const;
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
static const CCollisionPrimitive::Type& GetType();
static const Type& GetType();
static void SetStaticTableIndex(u32 index);
};

View File

@ -0,0 +1,43 @@
#include "CCollidableSphere.hpp"
namespace urde
{
const CCollisionPrimitive::Type CCollidableSphere::sType(CCollidableSphere::SetStaticTableIndex, "CCollidableSphere");
u32 CCollidableSphere::sTableIndex = -1;
u32 CCollidableSphere::GetTableIndex() const
{
return sTableIndex;
}
zeus::CAABox CCollidableSphere::CalculateAABox(const zeus::CTransform &) const
{
return {};
}
zeus::CAABox CCollidableSphere::CalculateLocalAABox() const
{
return {};
}
FourCC CCollidableSphere::GetPrimType() const
{
return SBIG('SPHR');
}
CRayCastResult CCollidableSphere::CastRayInternal(const CInternalRayCastStructure &) const
{
return {};
}
const CCollisionPrimitive::Type& CCollidableSphere::GetType()
{
return sType;
}
void CCollidableSphere::SetStaticTableIndex(u32 index)
{
sTableIndex = index;
}
}

View File

@ -0,0 +1,25 @@
#ifndef __URDE_CCOLLIDALBESPHERE_HPP
#define __URDE_CCOLLIDALBESPHERE_HPP
#include "CCollisionPrimitive.hpp"
namespace urde
{
class CCollidableSphere : public CCollisionPrimitive
{
static const Type sType;
static u32 sTableIndex;
public:
virtual u32 GetTableIndex() const;
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const;
virtual zeus::CAABox CalculateLocalAABox() const;
virtual FourCC GetPrimType() const;
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const;
static const Type& GetType();
static void SetStaticTableIndex(u32 index);
};
}
#endif // __URDE_CCOLLIDALBESPHERE_HPP

View File

@ -0,0 +1,6 @@
#include "CCollisionInfo.hpp"
namespace urde
{
}

View File

@ -1,11 +1,14 @@
#ifndef __URDE_CCOLLISIONINFO_HPP__
#define __URDE_CCOLLISIONINFO_HPP__
#include "zeus/CAABox.hpp"
namespace urde
{
class CMaterialList;
class CCollisionInfo
{
public:
};
}

View File

View File

@ -0,0 +1,30 @@
#ifndef __URDE_CCOLLISIONINFOLIST_HPP__
#define __URDE_CCOLLISIONINFOLIST_HPP__
#include "RetroTypes.hpp"
namespace urde
{
class CCollisionInfo;
class CCollisionInfoList
{
rstl::reserved_vector<CCollisionInfo, 32> x0_list;
public:
CCollisionInfoList() = default;
void GetAverageLeftNormal() const;
void GetAveragePoint() const;
void GetUnionOfAllLeftMaterials() const;
s32 GetCount() const;
void Swap(s32);
void Add(const CCollisionInfo&, bool);
void Clear();
void End();
void End() const;
void Begin();
void Begin() const;
};
}
#endif // __URDE_CCOLLISIONINFOLIST_HPP__

View File

@ -1,9 +1,12 @@
#include "CCollisionPrimitive.hpp"
#include "CInternalRayCastStructure.hpp"
#include "CMaterialFilter.hpp"
#include "InternalColliders.hpp"
namespace urde
{
std::unique_ptr<std::vector<CCollisionPrimitive::Type>> CCollisionPrimitive::sCollisionTypeList;
bool CCollisionPrimitive::sTypesAdding = false;
CCollisionPrimitive::CCollisionPrimitive(const CMaterialList& list)
: x8_material(list)
{
@ -14,7 +17,7 @@ void CCollisionPrimitive::SetMaterial(const CMaterialList& material)
x8_material = material;
}
const CMaterialList&CCollisionPrimitive::GetMaterial() const
const CMaterialList& CCollisionPrimitive::GetMaterial() const
{
return x8_material;
@ -26,4 +29,41 @@ CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const
return CastRayInternal(CInternalRayCastStructure(start, end, d, xf, filter));
}
void CCollisionPrimitive::InitBeginTypes()
{
sCollisionTypeList.reset(new std::vector<CCollisionPrimitive::Type>());
sCollisionTypeList->reserve(3);
sTypesAdding = true;
InternalColliders::AddTypes();
}
void CCollisionPrimitive::InitAddType(const CCollisionPrimitive::Type& tp)
{
tp.GetSetter()(sCollisionTypeList->size());
sCollisionTypeList->reserve(sCollisionTypeList->size() + 1);
sCollisionTypeList->push_back(tp);
}
void CCollisionPrimitive::InitEndTypes()
{
sTypesAdding = false;
}
CCollisionPrimitive::Type::Type(const std::function<void(u32)>& setter, const char *info)
: x0_setter(setter),
x4_info(info)
{
}
const char *CCollisionPrimitive::Type::GetInfo() const
{
return x4_info;
}
std::function<void (u32)> CCollisionPrimitive::Type::GetSetter() const
{
return x0_setter;
}
}

View File

@ -11,11 +11,20 @@ namespace urde
{
class COBBTree;
class CInternalCollisionStructure;
class CCollisionInfo;
class CCollisionInfoList;
class CInternalRayCastStructure;
class CMaterialFilter;
class CCollisionPrimitive
{
public:
class Type;
private:
CMaterialList x8_material;
static std::unique_ptr<std::vector<Type>> sCollisionTypeList;
static bool sTypesAdding;
public:
class Type
{
@ -23,21 +32,71 @@ public:
const char* x4_info;
public:
Type() = default;
Type(std::function<void(unsigned int)> setter, const char * info)
: x0_setter(setter),
x4_info(info)
Type(const std::function<void(u32)>& setter, const char * info);
const char* GetInfo() const;
std::function<void(u32)> GetSetter() const;
};
class Comparison
{
std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)> x0_collider;
const char* x4_type1;
const char* x8_type2;
public:
Comparison(const std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)>& collider,
const char* type1, const char* type2)
: x0_collider(collider),
x4_type1(type1),
x8_type2(type2)
{
}
const char* GetInfo() const
std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)> GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
};
class MovingComparison
{
std::function<bool(const CInternalCollisionStructure&, const zeus::CVector2f&, double&,
CCollisionInfo&)> x0_collider;
const char* x4_type1;
const char* x8_type2;
public:
MovingComparison(const std::function<bool(const CInternalCollisionStructure&, const zeus::CVector2f&, double&,
CCollisionInfo&)>& collider, const char* type1, const char* type2)
: x0_collider(collider),
x4_type1(type1),
x8_type2(type2)
{
return x4_info;
}
std::function<void(u32)> GetSetter() const
std::function<bool(const CInternalCollisionStructure&, const zeus::CVector2f&, double&,
CCollisionInfo&)> GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
};
class BooleanComparison
{
std::function<bool(const CInternalCollisionStructure&)> x0_collider;
const char* x4_type1;
const char* x8_type2;
public:
BooleanComparison(const std::function<bool(const CInternalCollisionStructure&)>& collider, const char* type1,
const char* type2)
: x0_collider(collider),
x4_type1(type1),
x8_type2(type2)
{
return x0_setter;
}
std::function<bool(const CInternalCollisionStructure&)> GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
};
CCollisionPrimitive()=default;
@ -59,7 +118,10 @@ public:
static void InitEndTypes();
static void InitBeginColliders();
static void InitAddCollider(const Type& tp);
static void InitAddBooleanCollider(const BooleanComparison& cmp);
static void InitAddMovingCollider(const MovingComparison& cmp);
static void InitAddCollider(const Comparison& cmp);
static void InitEndColliders();
};
}

View File

@ -0,0 +1,12 @@
#include "CCollisionSurface.hpp"
namespace urde
{
CCollisionSurface::CCollisionSurface(const zeus::CVector3f& a, const zeus::CVector3f& b, const zeus::CVector3f& c, u32 flags)
: x0_a(a),
xc_b(b),
x18_c(c),
x24_flags(flags)
{
}
}

View File

@ -0,0 +1,22 @@
#ifndef __URDE_CCOLLISIONSURFACE_HPP__
#define __URDE_CCOLLISIONSURFACE_HPP__
#include "zeus/zeus.hpp"
#include "RetroTypes.hpp"
namespace urde
{
class CCollisionSurface
{
zeus::CVector3f x0_a;
zeus::CVector3f xc_b;
zeus::CVector3f x18_c;
u32 x24_flags;
public:
CCollisionSurface(const zeus::CVector3f&, const zeus::CVector3f&, const zeus::CVector3f&, u32);
zeus::CVector3f GetPoint(u32) const;
};
}
#endif // __URDE_CCOLLISIONSURFACE_HPP__

View File

@ -1 +1,13 @@
#include "CMaterialFilter.hpp"
#include "CGameCollision.hpp"
#include "CCollidableOBBTreeGroup.hpp"
namespace urde
{
void CGameCollision::InitCollision()
{
CCollisionPrimitive::InitBeginTypes();
}
}

View File

@ -24,7 +24,7 @@ public:
const zeus::CMRay& GetRay() const { return x0_ray; }
const zeus::CVector3f& GetStart() const { return x0_ray.start; }
const zeus::CVector3f& GetNormal() const { return x0_ray.normal; }
float GetMaxTime() const { return 0.f; }
float GetMaxTime() const { return x38_maxTime; }
const zeus::CTransform& GetTransform() const { return x3c_xf; }
const CMaterialFilter& GetFilter() const { return x6c_filter; }
};

View File

@ -1,8 +1,15 @@
set(COLLISION_SOURCES
CollisionUtil.hpp CollisionUtil.cpp
CGameCollision.hpp CGameCollision.cpp
CCollisionInfo.hpp CCollisionInfo.cpp
CCollisionInfoList.hpp CCollisionInfoList.cpp
CCollisionEdge.hpp CCollisionEdge.cpp
CCollisionSurface.hpp CCollisionSurface.cpp
InternalColliders.hpp InternalColliders.cpp
COBBTree.hpp COBBTree.cpp
CCollidableAABox.hpp CCollidableAABox.cpp
CCollidableCollisionSurface.hpp CCollidableCollisionSurface.cpp
CCollidableSphere.hpp CCollidableSphere.cpp
CCollidableOBBTree.hpp CCollidableOBBTree.cpp
CCollidableOBBTreeGroup.hpp CCollidableOBBTreeGroup.cpp
CCollisionPrimitive.hpp CCollisionPrimitive.cpp

View File

@ -15,7 +15,9 @@ u32 verify_version(CInputStream& in)
return in.readUint32Big();
}
COBBTree::COBBTree(const COBBTree::SIndexData&, const COBBTree::CNode*)
COBBTree::COBBTree(const SIndexData& indexData, const CNode* root)
: x18_indexData(indexData),
x88_root((CNode*)root)
{
}
@ -114,6 +116,25 @@ const zeus::COBBox& COBBTree::CNode::GetOBB() const
return x0_obb;
}
size_t COBBTree::CNode::GetMemoryUsage() const
{
size_t ret = 0;
if (x3c_isLeaf)
ret = x48_leaf->GetMemoryUsage() + 80;
else
{
if (x40_left)
ret = x40_left->GetMemoryUsage() + 80;
if (x44_right)
ret += x44_right->GetMemoryUsage();
}
if (!(ret & 3))
return ret;
return ret + ((ret & 3) - 4);
}
COBBTree::CLeafData::CLeafData(const std::vector<u16>& surface)
: x0_surface(surface)
{
@ -124,6 +145,14 @@ const std::vector<u16>& COBBTree::CLeafData::GetSurfaceVector() const
return x0_surface;
}
size_t COBBTree::CLeafData::GetMemoryUsage() const
{
size_t ret = (x0_surface.size() * 2) + 16;
if (!(ret & 3))
return ret;
return ret + ((ret & 3) - 4);
}
COBBTree::CLeafData::CLeafData(CInputStream& in)
{
u32 edgeCount = in.readUint32Big();

View File

@ -32,6 +32,7 @@ public:
CLeafData(CInputStream&);
const std::vector<u16>& GetSurfaceVector() const;
size_t GetMemoryUsage() const;
};
class CNode
@ -48,11 +49,12 @@ public:
CNode(CInputStream&);
bool WasHit() const;
void SetWasHit(bool) const;
void SetHit(bool) const;
CNode* GetLeft() const;
CNode* GetRight() const;
CLeafData* GetLeafData() const;
const zeus::COBBox& GetOBB() const;
size_t GetMemoryUsage() const;
};
private:

View File

@ -0,0 +1,25 @@
#include "CollisionUtil.hpp"
namespace urde
{
namespace CollisionUtil
{
bool LineIntersectsOBBox(const zeus::COBBox& obb, const zeus::CMRay& ray, float& d)
{
const zeus::CVector3f transXf = obb.transform.toMatrix4f().vec[0].toVec3f();
return RayAABoxIntersection(ray.getInvUnscaledTransformRay(obb.transform), {-obb.extents, obb.extents},
transXf, d);
}
u32 RayAABoxIntersection(const zeus::CMRay& ray, const zeus::CAABox& box, const zeus::CVector3f&, float& d)
{
return 0;
}
u32 RaySphereIntersection_Double(const zeus::CSphere&, const zeus::CVector3f &, const zeus::CVector3f &, double &)
{
return 0;
}
}
}

View File

@ -0,0 +1,16 @@
#ifndef __URDE_COLLISIONUTIL_HPP__
#define __URDE_COLLISIONUTIL_HPP__
#include "GCNTypes.hpp"
#include "zeus/zeus.hpp"
namespace urde
{
namespace CollisionUtil
{
bool LineIntersectsOBBox(const zeus::COBBox&, const zeus::CMRay&, float&);
u32 RayAABoxIntersection(const zeus::CMRay&, const zeus::CAABox&, const zeus::CVector3f&, float&);
u32 RaySphereIntersection_Double(const zeus::CSphere&, const zeus::CVector3f&, const zeus::CVector3f&, double&);
}
}
#endif // __URDE_COLLISIONUTIL_HPP__

View File

@ -0,0 +1,17 @@
#include "InternalColliders.hpp"
#include "CCollidableAABox.hpp"
#include "CCollidableCollisionSurface.hpp"
#include "CCollidableSphere.hpp"
namespace urde
{
namespace InternalColliders
{
void AddTypes()
{
CCollisionPrimitive::InitAddType(CCollidableAABox::GetType());
CCollisionPrimitive::InitAddType(CCollidableCollisionSurface::GetType());
CCollisionPrimitive::InitAddType(CCollidableSphere::GetType());
}
}
}

View File

@ -0,0 +1,11 @@
#ifndef __URDE_INTERNALCOLLIDERS_HPP__
#define __URDE_INTERNALCOLLIDERS_HPP__
namespace urde
{
namespace InternalColliders
{
void AddTypes();
}
}
#endif // __URDE_INTERNALCOLLIDERS_HPP__

View File

@ -38,7 +38,7 @@ zeus::CVector3f CGuiCamera::ConvertToScreenSpace(const zeus::CVector3f& vec) con
void CGuiCamera::Draw(const CGuiWidgetDrawParms& parms) const
{
if (xf8_proj == Projection::Perspective)
if (xf8_proj == EProjection::Perspective)
CGraphics::SetPerspective(xfc_fov, x100_aspect, x104_znear, x108_zfar);
else
CGraphics::SetOrtho(xfc_left, x100_right, x104_top, x108_bottom, x10c_znear, x110_zfar);
@ -49,11 +49,11 @@ void CGuiCamera::Draw(const CGuiWidgetDrawParms& parms) const
CGuiCamera* CGuiCamera::Create(CGuiFrame* frame, CInputStream& in, bool flag)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
Projection proj = Projection(in.readUint32Big());
EProjection proj = EProjection(in.readUint32Big());
CGuiCamera* ret = nullptr;
switch (proj)
{
case Projection::Perspective:
case EProjection::Perspective:
{
float fov = in.readFloatBig();
float aspect = in.readFloatBig();
@ -62,7 +62,7 @@ CGuiCamera* CGuiCamera::Create(CGuiFrame* frame, CInputStream& in, bool flag)
ret = new CGuiCamera(parms, fov, aspect, znear, zfar);
break;
}
case Projection::Orthographic:
case EProjection::Orthographic:
{
float left = in.readFloatBig();
float right = in.readFloatBig();

View File

@ -9,13 +9,13 @@ namespace urde
class CGuiCamera : public CGuiWidget
{
public:
enum class Projection
enum class EProjection
{
Perspective,
Orthographic
};
private:
Projection xf8_proj;
EProjection xf8_proj;
union
{
struct

View File

@ -69,7 +69,7 @@ static const std::vector<FourCC> DecalTypes =
SBIG('NCDL'),SBIG('DDCL'),SBIG('CODL'),SBIG('MEDL'),
SBIG('GRDL'),SBIG('ICDL'),SBIG('GODL'),SBIG('WODL'),
SBIG('WTDL'),SBIG('3MUD'),SBIG('3LAV'),SBIG('3SAN'),
SBIG('CHDL')
SBIG('CHDL'),SBIG('ENDL')
};
using CPF = CParticleDataFactory;

@ -1 +1 @@
Subproject commit 4dff27e3c69b11d7fa8232c4b32d28089e524b57
Subproject commit 47a6e28db624f100e8cbc6ef11f3feba2a575ec7