This commit is contained in:
Jack Andersen 2017-01-03 19:27:53 -10:00
commit 9109151bf9
49 changed files with 899 additions and 182 deletions

View File

@ -12,7 +12,6 @@ namespace DNAMP1
struct ControllerAction : IScriptObject
{
DECL_YAML
Value<atUint32> propertyCount;
String<-1> name;
Value<bool> unknown1;
Value<atUint32> unknown2;

View File

@ -18,7 +18,7 @@ struct Dock : IScriptObject
Value<atVec3f> volume;
Value<atUint32> dock;
Value<atUint32> room;
Value<bool> autoLoad;
Value<bool> loadConnected;
};
}
}

View File

@ -44,7 +44,7 @@ void CRelayTracker::RemoveRelay(TEditorId id)
void CRelayTracker::SendMsgs(const TAreaId& areaId, CStateManager& stateMgr)
{
const CWorld* world = stateMgr.GetWorld();
const CWorld* world = stateMgr.WorldNC();
u32 relayCount = world->GetRelayCount();
bool hasActiveRelays = false;

View File

@ -15,4 +15,14 @@ void CSortedListManager::Reset()
xb000_sortedLists[i].Reset();
}
void CSortedListManager::RemoveFromList(ESortedList list, s16 id)
{
SSortedList& sl = xb000_sortedLists[u32(list)];
}
void CSortedListManager::Remove(const CActor *)
{
}
}

View File

@ -6,14 +6,25 @@
namespace urde
{
enum ESortedList
{
Zero,
One,
Two,
Three,
Four,
Five
};
struct SSortedList
{
TUniqueId x0_ids[1024];
u32 x800_;
void Reset() {std::fill(std::begin(x0_ids), std::end(x0_ids), -1);}
SSortedList() {Reset();}
};
class CActor;
class CSortedListManager
{
struct SNode
@ -31,6 +42,8 @@ class CSortedListManager
public:
CSortedListManager();
void Reset();
void RemoveFromList(ESortedList, s16);
void Remove(const CActor*);
};
}

View File

@ -725,8 +725,27 @@ void CStateManager::ClearGraveyard()
{
}
void CStateManager::DeleteObjectRequest(TUniqueId)
void CStateManager::DeleteObjectRequest(TUniqueId id)
{
CEntity* entity = ObjectById(id);
if (!entity)
return;
if (entity->IsInGraveyard())
return;
entity->SetIsInGraveyard(true);
x858_objectGraveyard.push_back(entity->GetUniqueId());
entity->AcceptScriptMsg(EScriptObjectMessage::InternalMessage12, kInvalidUniqueId, *this);
entity->SetIsScriptingBlocked(true);
CActor* actor = static_cast<CActor*>(entity);
if (actor)
{
x874_sortedListManager->Remove(actor);
actor->SetUseInSortedList(false);
}
}
CEntity* CStateManager::ObjectById(TUniqueId uid)

View File

@ -251,6 +251,7 @@ public:
void RemoveObject(TUniqueId);
void RemoveActor(TUniqueId);
void UpdateRoomAcoustics(TAreaId);
TAreaId GetNextAreaId() const { return x8cc_nextAreaId; }
void SetCurrentAreaId(TAreaId);
void ClearGraveyard();
void DeleteObjectRequest(TUniqueId);
@ -285,7 +286,8 @@ public:
CCameraFilterPass& GetCameraFilterPass(int idx) {return xb84_camFilterPasses[idx];}
CEnvFxManager* GetEnvFxManager() { return x880_envFxManager; }
CWorld* GetWorld() {return x850_world.get();}
CWorld* WorldNC() {return x850_world.get();}
const CWorld* GetWorld() const { return x850_world.get(); }
CRelayTracker* GetRelayTracker() { return x8bc_relayTracker.get(); }
CCameraManager* GetCameraManager() const { return x870_cameraManager; }
@ -303,7 +305,6 @@ public:
CListeningAiList& GetListeningAiObjectList() const { return *x834_listenAiObjs; }
CAiWaypointList& GetAiWaypointObjectList() const { return *x83c_aiWaypointObjs; }
CPlatformAndDoorList& GetPlatformAndDoorObjectList() const { return *x844_platformAndDoorObjs; }
std::pair<u32, u32> CalculateScanCompletionRate() const;
};
}

View File

@ -140,6 +140,7 @@ public:
const CActorLights* lights, const CModelFlags& drawFlags);
CAnimData* AnimationData() { return x10_animData.get(); }
const CAnimData* GetAnimationData() const { return x10_animData.get(); }
const TLockedToken<CModel>& GetNormalModel() const { return x1c_normalModel; }
const TLockedToken<CModel>& GetXRayModel() const { return x2c_xrayModel; }
const TLockedToken<CModel>& GetThermalModel() const { return x3c_infraModel; }

View File

@ -54,4 +54,29 @@ void CCollidableAABox::SetStaticTableIndex(u32 index)
{
sTableIndex = index;
}
bool CCollidableAABox::CollideMovingAABox(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
bool CCollidableAABox::CollideMovingSphere(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
namespace Collide
{
bool AABox_AABox(const CInternalCollisionStructure &, CCollisionInfoList &)
{
return false;
}
bool AABox_AABox_Bool(const CInternalCollisionStructure &)
{
return false;
}
}
}

View File

@ -8,7 +8,7 @@ namespace urde
namespace Collide
{
bool AABox_AABox(const CInternalCollisionStructure&, CCollisionInfoList&);
bool AABox_AABox_Bool(const CInternalCollisionStructure&, CCollisionInfoList&);
bool AABox_AABox_Bool(const CInternalCollisionStructure&);
}
class CCollidableAABox : public CCollisionPrimitive
@ -17,6 +17,7 @@ class CCollidableAABox : public CCollisionPrimitive
static u32 sTableIndex;
zeus::CAABox x10_aabox;
public:
CCollidableAABox();
CCollidableAABox(const zeus::CAABox&, const CMaterialList&);
@ -30,6 +31,10 @@ public:
static const CCollisionPrimitive::Type& GetType();
static void SetStaticTableIndex(u32 index);
static bool CollideMovingAABox(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
};
}

View File

@ -64,6 +64,36 @@ void CCollidableOBBTreeGroup::SetStaticTableIndex(u32 index)
sTableIndex = index;
}
bool CCollidableOBBTreeGroup::SphereCollide(const CInternalCollisionStructure &, CCollisionInfoList &)
{
return false;
}
bool CCollidableOBBTreeGroup::SphereCollideBoolean(const CInternalCollisionStructure &)
{
return false;
}
bool CCollidableOBBTreeGroup::CollideMovingSphere(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
bool CCollidableOBBTreeGroup::AABoxCollide(const CInternalCollisionStructure &, CCollisionInfoList &)
{
return false;
}
bool CCollidableOBBTreeGroup::AABoxCollideBoolean(const CInternalCollisionStructure &)
{
return false;
}
bool CCollidableOBBTreeGroup::CollideMovingAABox(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream& in,
const CVParamTransfer& vparms,
CObjectReference* selfRef)

View File

@ -15,6 +15,7 @@ class CCollidableOBBTreeGroup : public CCollisionPrimitive
static u32 sTableIndex;
std::vector<std::unique_ptr<COBBTree>> x0_trees;
std::vector<zeus::CAABox> x10_aabbs;
public:
CCollidableOBBTreeGroup(CInputStream& in);
virtual ~CCollidableOBBTreeGroup() {}
@ -28,12 +29,20 @@ public:
static const Type& GetType();
static void SetStaticTableIndex(u32 index);
/* Sphere Collide */
static bool SphereCollide(const CInternalCollisionStructure&, CCollisionInfoList&);
static bool SphereCollideBoolean(const CInternalCollisionStructure&);
static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
/* AABox Collide */
static bool AABoxCollide(const CInternalCollisionStructure&, CCollisionInfoList&);
static bool AABoxCollideBoolean(const CInternalCollisionStructure&);
static bool CollideMovingAABox(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
};
CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag &tag, CInputStream& in,
const CVParamTransfer& vparms,
CFactoryFnReturn FCollidableOBBTreeGroupFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms,
CObjectReference* selfRef);
}
#endif // __URDE_CCOLLIDABLEOBBTREEGROUP_HPP__

View File

@ -40,4 +40,39 @@ void CCollidableSphere::SetStaticTableIndex(u32 index)
sTableIndex = index;
}
bool CCollidableSphere::CollideMovingAABox(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
bool CCollidableSphere::CollideMovingSphere(const CInternalCollisionStructure &, const zeus::CVector3f &, double &, CCollisionInfo &)
{
return false;
}
namespace Collide
{
bool Sphere_AABox(const CInternalCollisionStructure &, CCollisionInfoList &)
{
return false;
}
bool Sphere_AABox_Bool(const CInternalCollisionStructure &)
{
return false;
}
bool Sphere_Sphere(const CInternalCollisionStructure &, CCollisionInfoList &)
{
return false;
}
bool Sphere_Sphere_Bool(const CInternalCollisionStructure &)
{
return false;
}
}
}

View File

@ -5,12 +5,19 @@
namespace urde
{
namespace Collide
{
bool Sphere_AABox(const CInternalCollisionStructure&, CCollisionInfoList&);
bool Sphere_AABox_Bool(const CInternalCollisionStructure&);
bool Sphere_Sphere(const CInternalCollisionStructure&, CCollisionInfoList&);
bool Sphere_Sphere_Bool(const CInternalCollisionStructure&);
}
class CCollidableSphere : public CCollisionPrimitive
{
static const Type sType;
static u32 sTableIndex;
public:
public:
virtual u32 GetTableIndex() const;
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const;
virtual zeus::CAABox CalculateLocalAABox() const;
@ -19,6 +26,10 @@ public:
static const Type& GetType();
static void SetStaticTableIndex(u32 index);
static bool CollideMovingAABox(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
static bool CollideMovingSphere(const CInternalCollisionStructure&, const zeus::CVector3f&, double&,
CCollisionInfo&);
};
}

View File

@ -3,4 +3,9 @@
namespace urde
{
zeus::CVector3f CCollisionInfo::GetExtreme() const
{
return (x18_ + (x0_aabox.min + x0_aabox.max) + x24_);
}
}

View File

@ -33,7 +33,7 @@ public:
bool IsValid() const;
void GetMaterialLeft() const;
void GetMaterialRight() const;
void GetExtreme() const;
zeus::CVector3f GetExtreme() const;
void Swap();
void Transform(const zeus::CTransform&);
zeus::CVector3f GetNormalLeft() const;

View File

@ -6,25 +6,21 @@
namespace urde
{
std::unique_ptr<std::vector<CCollisionPrimitive::Type>> CCollisionPrimitive::sCollisionTypeList;
std::unique_ptr<std::vector<ComparisonFunc>> CCollisionPrimitive::sTableOfCollidables;
std::unique_ptr<std::vector<BooleanComparisonFunc>> CCollisionPrimitive::sTableOfBooleanCollidables;
std::unique_ptr<std::vector<MovingComparisonFunc>> CCollisionPrimitive::sTableOfMovingCollidables;
bool CCollisionPrimitive::sTypesAdded = false;
bool CCollisionPrimitive::sTypesAdding = false;
CCollisionPrimitive::CCollisionPrimitive(const CMaterialList& list)
: x8_material(list)
{
}
bool CCollisionPrimitive::sCollidersAdded = false;
bool CCollisionPrimitive::sCollidersAdding = false;
CCollisionPrimitive::CCollisionPrimitive(const CMaterialList& list) : x8_material(list) {}
void CCollisionPrimitive::SetMaterial(const CMaterialList& material)
{
x8_material = material;
}
void CCollisionPrimitive::SetMaterial(const CMaterialList& material) { x8_material = material; }
const CMaterialList& CCollisionPrimitive::GetMaterial() const
{
return x8_material;
const CMaterialList& CCollisionPrimitive::GetMaterial() const { return x8_material; }
}
CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const zeus::CVector3f& end, float d, const
CMaterialFilter& filter, const zeus::CTransform& xf) const
CRayCastResult CCollisionPrimitive::CastRay(const zeus::CVector3f& start, const zeus::CVector3f& end, float d,
const CMaterialFilter& filter, const zeus::CTransform& xf) const
{
return CastRayInternal(CInternalRayCastStructure(start, end, d, xf, filter));
}
@ -45,25 +41,46 @@ void CCollisionPrimitive::InitAddType(const CCollisionPrimitive::Type& tp)
sCollisionTypeList->push_back(tp);
}
void CCollisionPrimitive::InitEndTypes()
void CCollisionPrimitive::InitEndTypes() { sTypesAdding = false; }
void CCollisionPrimitive::InitBeginColliders()
{
sTypesAdding = false;
sTableOfCollidables.reset(new std::vector<ComparisonFunc>());
sTableOfBooleanCollidables.reset(new std::vector<BooleanComparisonFunc>());
sTableOfMovingCollidables.reset(new std::vector<MovingComparisonFunc>());
sCollidersAdding = true;
InternalColliders::AddColliders();
}
CCollisionPrimitive::Type::Type(const std::function<void(u32)>& setter, const char *info)
: x0_setter(setter),
x4_info(info)
void CCollisionPrimitive::InitAddBooleanCollider(const CCollisionPrimitive::BooleanComparison& cmp)
{
}
const char *CCollisionPrimitive::Type::GetInfo() const
void CCollisionPrimitive::InitAddBooleanCollider(const BooleanComparisonFunc& cmp, const char* a, const char* b)
{
return x4_info;
InitAddBooleanCollider({std::move(cmp), a, b});
}
std::function<void (u32)> CCollisionPrimitive::Type::GetSetter() const
void CCollisionPrimitive::InitAddMovingCollider(const CCollisionPrimitive::MovingComparison& cmp) {}
void CCollisionPrimitive::InitAddMovingCollider(const MovingComparisonFunc& cmp, const char* a, const char* b)
{
return x0_setter;
InitAddMovingCollider({std::move(cmp), a, b});
}
void CCollisionPrimitive::InitAddCollider(const CCollisionPrimitive::Comparison& cmp) {}
void CCollisionPrimitive::InitAddCollider(const ComparisonFunc& cmp, const char* a, const char* b)
{
InitAddCollider({std::move(cmp), a, b});
}
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

@ -16,23 +16,22 @@ class CCollisionInfo;
class CCollisionInfoList;
class CInternalRayCastStructure;
class CMaterialFilter;
using ComparisonFunc = std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)>;
using MovingComparisonFunc =
std::function<bool(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&)>;
using BooleanComparisonFunc = std::function<bool(const CInternalCollisionStructure&)>;
class CCollisionPrimitive
{
public:
class Type;
private:
CMaterialList x8_material;
static std::unique_ptr<std::vector<Type>> sCollisionTypeList;
static bool sTypesAdding;
public:
class Type
{
std::function<void(u32)> x0_setter;
const char* x4_info;
public:
Type() = default;
Type(const std::function<void(u32)>& setter, const char * info);
Type(const std::function<void(u32)>& setter, const char* info);
const char* GetInfo() const;
@ -41,89 +40,92 @@ public:
class Comparison
{
std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)> x0_collider;
ComparisonFunc 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)
Comparison(const ComparisonFunc& collider, const char* type1, const char* type2)
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
{
}
std::function<bool(const CInternalCollisionStructure&, CCollisionInfoList&)> GetCollider() const { return x0_collider; }
const ComparisonFunc& 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;
MovingComparisonFunc 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)
MovingComparison(const MovingComparisonFunc& collider, const char* type1, const char* type2)
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
{
}
std::function<bool(const CInternalCollisionStructure&, const zeus::CVector2f&, double&,
CCollisionInfo&)> GetCollider() const { return x0_collider; }
const MovingComparisonFunc& 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;
BooleanComparisonFunc 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)
BooleanComparison(const BooleanComparisonFunc& collider, const char* type1, const char* type2)
: x0_collider(collider), x4_type1(type1), x8_type2(type2)
{
}
std::function<bool(const CInternalCollisionStructure&)> GetCollider() const { return x0_collider; }
const BooleanComparisonFunc& GetCollider() const { return x0_collider; }
const char* GetType1() const { return x4_type1; }
const char* GetType2() const { return x8_type2; }
};
private:
CMaterialList x8_material;
static std::unique_ptr<std::vector<Type>> sCollisionTypeList;
static std::unique_ptr<std::vector<ComparisonFunc>> sTableOfCollidables;
static std::unique_ptr<std::vector<BooleanComparisonFunc>> sTableOfBooleanCollidables;
static std::unique_ptr<std::vector<MovingComparisonFunc>> sTableOfMovingCollidables;
static bool sTypesAdded;
static bool sTypesAdding;
static bool sCollidersAdded;
static bool sCollidersAdding;
CCollisionPrimitive()=default;
public:
CCollisionPrimitive() = default;
CCollisionPrimitive(const CMaterialList& list);
virtual u32 GetTableIndex() const=0;
virtual u32 GetTableIndex() const = 0;
virtual void SetMaterial(const CMaterialList&);
virtual const CMaterialList& GetMaterial() const;
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const=0;
virtual zeus::CAABox CalculateLocalAABox() const=0;
virtual FourCC GetPrimType() const=0;
virtual zeus::CAABox CalculateAABox(const zeus::CTransform&) const = 0;
virtual zeus::CAABox CalculateLocalAABox() const = 0;
virtual FourCC GetPrimType() const = 0;
virtual ~CCollisionPrimitive() {}
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const=0;
virtual CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const = 0;
CRayCastResult CastRay(const zeus::CVector3f&, const zeus::CVector3f&, float, const CMaterialFilter&,
const zeus::CTransform&) const;
static void InitBeginTypes();
static void InitAddType(const Type& tp);
static void InitEndTypes();
static void InitBeginColliders();
static void InitAddBooleanCollider(const BooleanComparison& cmp);
static void InitAddBooleanCollider(const BooleanComparisonFunc&, const char*, const char*);
static void InitAddMovingCollider(const MovingComparison& cmp);
static void InitAddMovingCollider(const MovingComparisonFunc&, const char*, const char*);
static void InitAddCollider(const Comparison& cmp);
static void InitAddCollider(const ComparisonFunc&, const char*, const char*);
static void InitEndColliders();
};
}
#endif // __URDE_CCOLLISIONPRIMITIVE_HPP__

View File

@ -1,13 +1,79 @@
#include "CMaterialFilter.hpp"
#include "CGameCollision.hpp"
#include "CCollidableOBBTreeGroup.hpp"
#include "CMaterialFilter.hpp"
#include "CMaterialList.hpp"
#include "World/CActor.hpp"
#include "CStateManager.hpp"
namespace urde
{
void CGameCollision::InitCollision()
float CollisionImpulseFiniteVsInfinite(float f1, float f2, float f3) { return f1 * ((1.f / f3) * f2); }
float CollisionImpulseFiniteVsFinite(float f1, float f2, float f3, float f4)
{
CCollisionPrimitive::InitBeginTypes();
return (-(1.f + f4) * f3) / ((1.f / f1) + (1.f / f2));
}
void CGameCollision::InitCollision()
{
/* Types */
CCollisionPrimitive::InitBeginTypes();
CCollisionPrimitive::InitAddType(CCollidableOBBTreeGroup::GetType());
CCollisionPrimitive::InitEndTypes();
/* Colliders */
CCollisionPrimitive::InitBeginColliders();
CCollisionPrimitive::InitAddCollider(CCollidableOBBTreeGroup::SphereCollide, "CCollidableSphere",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddCollider(CCollidableOBBTreeGroup::AABoxCollide, "CCollidableAABox",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddBooleanCollider(CCollidableOBBTreeGroup::SphereCollideBoolean, "CCollidableSphere",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddBooleanCollider(CCollidableOBBTreeGroup::AABoxCollideBoolean, "CCollidableAABox",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddMovingCollider(CCollidableOBBTreeGroup::CollideMovingAABox, "CCollidableAABox",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddMovingCollider(CCollidableOBBTreeGroup::CollideMovingSphere, "CCollidableSphere",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddCollider(CGameCollision::NullCollisionCollider, "CCollidableOBBTreeGroup",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddBooleanCollider(CGameCollision::NullBooleanCollider, "CCollidableOBBTreeGroup",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitAddMovingCollider(CGameCollision::NullMovingCollider, "CCollidableOBBTreeGroup",
"CCollidableOBBTreeGroup");
CCollisionPrimitive::InitEndColliders();
}
bool CGameCollision::CanBlock(const CMaterialList& mat, const zeus::CVector3f& v)
{
if ((mat.HasMaterial(EMaterialTypes::Character) && !mat.HasMaterial(EMaterialTypes::Scannable)) ||
mat.HasMaterial(EMaterialTypes::Occluder))
return false;
if (mat.HasMaterial(EMaterialTypes::Occluder) || mat.HasMaterial(EMaterialTypes::Floor))
return true;
return (v.z > 0.85f);
}
bool CGameCollision::IsFloor(const CMaterialList& mat, const zeus::CVector3f& v)
{
if (mat.HasMaterial(EMaterialTypes::Floor))
return true;
return (v.z > 0.85f);
}
void CGameCollision::SendMaterialMessage(CStateManager& mgr, const CMaterialList& mat, CActor& act)
{
EScriptObjectMessage msg;
if (mat.HasMaterial(EMaterialTypes::Ice))
msg = EScriptObjectMessage::InternalMessage05;
else if (mat.HasMaterial(EMaterialTypes::MudSlow))
msg = EScriptObjectMessage::InternalMessage06;
else
msg = EScriptObjectMessage::InternalMessage07;
mgr.SendScriptMsg(&act, kInvalidUniqueId, msg);
}
}

View File

@ -1,5 +1,6 @@
#ifndef __URDE_CGAMECOLLISION_HPP__
#define __URDE_CGAMECOLLISION_HPP__
#include "zeus/CVector3f.hpp"
namespace urde
{
@ -8,13 +9,26 @@ class CInternalCollisionStructure
{
};
class CActor;
class CCollisionInfo;
class CCollisionInfoList;
class CMaterialList;
class CStateManager;
class CGameCollision
{
public:
static bool NullMovingCollider(const CInternalCollisionStructure&, const zeus::CVector3f&, double&, CCollisionInfo&)
{
return false;
}
static bool NullBooleanCollider(const CInternalCollisionStructure&) { return false; }
static bool NullCollisionCollider(const CInternalCollisionStructure&, CCollisionInfoList&) { return false; }
static void InitCollision();
};
static bool CanBlock(const CMaterialList&, const zeus::CVector3f&);
static bool IsFloor(const CMaterialList&, const zeus::CVector3f&);
void SendMaterialMessage(CStateManager&, const CMaterialList&, CActor&);
};
}
#endif // __URDE_CGAMECOLLISION_HPP__

View File

@ -13,5 +13,23 @@ void AddTypes()
CCollisionPrimitive::InitAddType(CCollidableCollisionSurface::GetType());
CCollisionPrimitive::InitAddType(CCollidableSphere::GetType());
}
void AddColliders()
{
CCollisionPrimitive::InitAddCollider(Collide::AABox_AABox, "CCollidableAABox", "CCollidableAABox");
CCollisionPrimitive::InitAddCollider(Collide::Sphere_AABox, "CCollidableSphere", "CCollidableAABox");
CCollisionPrimitive::InitAddCollider(Collide::Sphere_Sphere, "CCollidableSphere", "CCollidableSphere");
CCollisionPrimitive::InitAddBooleanCollider(Collide::AABox_AABox_Bool, "CCollidableAABox", "CCollidableAABox");
CCollisionPrimitive::InitAddBooleanCollider(Collide::Sphere_AABox_Bool, "CCollidableSphere", "CCollidableAABox");
CCollisionPrimitive::InitAddBooleanCollider(Collide::Sphere_Sphere_Bool, "CCollidableSphere", "CCollidableSphere");
CCollisionPrimitive::InitAddMovingCollider(CCollidableAABox::CollideMovingAABox, "CCollidableAABox",
"CCollidableAABox");
CCollisionPrimitive::InitAddMovingCollider(CCollidableAABox::CollideMovingSphere, "CCollidableAABox",
"CCollidableSphere");
CCollisionPrimitive::InitAddMovingCollider(CCollidableSphere::CollideMovingAABox, "CCollidableSphere",
"CCollidableAABox");
CCollisionPrimitive::InitAddMovingCollider(CCollidableSphere::CollideMovingSphere, "CCollidableSphere",
"CCollidableSphere");
}
}
}

View File

@ -6,6 +6,7 @@ namespace urde
namespace InternalColliders
{
void AddTypes();
void AddColliders();
}
}
#endif // __URDE_INTERNALCOLLIDERS_HPP__

View File

@ -40,6 +40,7 @@ class CTexture
void BuildC8(const void* data, size_t length);
public:
CTexture(ETexelFormat, s16, s16, s32);
CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex);
enum class EClampMode
{

View File

@ -681,7 +681,20 @@ void CTexture::BuildC8(const void* data, size_t length)
m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::I8,
texels, texelCount);
return true;
});
});
}
CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips)
: x0_fmt(fmt)
, x4_w(w)
, x6_h(h)
, x8_mips(mips)
{
/*
x64_ = sMangleMipmaps;
InitBitmapBuffers(fmt, w, h, mips);
InitTextureObjs();
*/
}
CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex)

View File

@ -19,8 +19,8 @@ static CMaterialList MakeActorMaterialList(const CMaterialList& materialList, co
CActor::CActor(TUniqueId uid, bool active, const std::string& name, const CEntityInfo& info, const zeus::CTransform&,
CModelData&& mData, const CMaterialList& list, const CActorParameters& params, TUniqueId otherUid)
: CEntity(uid, info, active, name)
, x60_material(MakeActorMaterialList(list, params))
, x70_(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::Unknown}))
, x68_material(MakeActorMaterialList(list, params))
, x70_materialFilter(CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {EMaterialTypes::Unknown}))
, xc6_(otherUid)
{
if (mData.x10_animData || mData.x1c_normalModel)
@ -163,52 +163,52 @@ void CActor::DoUserAnimEvent(CStateManager&, CInt32POINode&, EUserEventType) {}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4,
CStateManager& mgr)
{
x60_material.Remove(t1);
x68_material.Remove(t1);
RemoveMaterial(t2, t3, t4, mgr);
}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr)
{
x60_material.Remove(t1);
x68_material.Remove(t1);
RemoveMaterial(t2, t3, mgr);
}
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr) { x60_material.Remove(t1); }
void CActor::RemoveMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr) { x68_material.Remove(t1); }
void CActor::RemoveMaterial(EMaterialTypes t, CStateManager& mgr)
{
x60_material.Remove(t);
x68_material.Remove(t);
mgr.UpdateObjectInLists(*this);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4, EMaterialTypes t5,
CStateManager& mgr)
{
x60_material.Add(t1);
x68_material.Add(t1);
AddMaterial(t2, t3, t4, t5, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, EMaterialTypes t4, CStateManager& mgr)
{
x60_material.Add(t1);
x68_material.Add(t1);
AddMaterial(t2, t3, t4, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, EMaterialTypes t3, CStateManager& mgr)
{
x60_material.Add(t1);
x68_material.Add(t1);
AddMaterial(t2, t3, mgr);
}
void CActor::AddMaterial(EMaterialTypes t1, EMaterialTypes t2, CStateManager& mgr)
{
x60_material.Add(t1);
x68_material.Add(t1);
AddMaterial(t2, mgr);
}
void CActor::AddMaterial(EMaterialTypes type, CStateManager& mgr)
{
x60_material.Add(type);
x68_material.Add(type);
mgr.UpdateObjectInLists(*this);
}

View File

@ -29,8 +29,8 @@ class CActor : public CEntity
protected:
zeus::CTransform x34_transform;
std::unique_ptr<CModelData> x64_modelData;
CMaterialList x60_material;
CMaterialFilter x70_;
CMaterialList x68_material;
CMaterialFilter x70_materialFilter;
s16 x88_sfxId = -1;
std::unique_ptr<CSfxHandle> x8c_sfxHandle;
std::unique_ptr<CActorLights> x90_actorLights;
@ -133,8 +133,9 @@ public:
bool GetCallTouch() const;
void SetUseInSortedList(bool use);
bool GetUseInSortedLists() const;
const CMaterialFilter& GetMaterialFilter() const { return x70_; }
const CMaterialList& GetMaterialList() const { return x60_material; }
const CMaterialFilter& GetMaterialFilter() const { return x70_materialFilter; }
void SetMaterialFilter(const CMaterialFilter& filter) { x70_materialFilter = filter; }
const CMaterialList& GetMaterialList() const { return x68_material; }
void SetInFluid(bool in, TUniqueId uid);
bool HasModelData() const;
const CSfxHandle* GetSfxHandle() const;
@ -143,6 +144,7 @@ public:
void SetAddedToken(u32 tok);
float GetPitch() const;
float GetYaw() const;
const CModelData* GetModelData() const { return x64_modelData.get(); }
};
}

View File

@ -44,7 +44,7 @@ protected:
struct
{
bool x30_24_active : 1;
bool x30_25_ : 1;
bool x30_25_inGraveyard : 1;
bool x30_26_scriptingBlocked : 1;
bool x30_27_ : 1;
};
@ -66,6 +66,11 @@ public:
x30_24_active ^= 1;
}
bool IsInGraveyard() const { return x30_25_inGraveyard; }
void SetIsInGraveyard(bool in) { x30_25_inGraveyard = in; }
bool IsScriptingBlocked() const { return x30_26_scriptingBlocked; }
void SetIsScriptingBlocked(bool blocked) { x30_26_scriptingBlocked = blocked; }
TAreaId GetAreaId() const
{
if (x30_27_)

View File

@ -301,13 +301,16 @@ public:
const zeus::CAABox& GetAABB() const {return x6c_aabb;}
const std::vector<Dock> GetDocks() const {return xcc_docks;}
const Dock* GetDock(s32 dock) const { return &xcc_docks[dock]; }
s32 GetDockCount() const { return xcc_docks.size(); }
Dock* DockNC(s32 dock) { return &xcc_docks[dock]; }
bool IsPostConstructed() const {return xf0_24_postConstructed;}
const CPostConstructed* GetPostConstructed() const {return x12c_postConstructed.get();}
void SetAreaAttributes(const CScriptAreaAttributes* areaAttributes);
bool GetActive() const { return xf0_25_active; }
void SetActive(bool active) { xf0_25_active = active; }
};
}

View File

@ -70,6 +70,8 @@ set(WORLD_SOURCES
CScriptCameraPitchVolume.hpp CScriptCameraPitchVolume.cpp
CScriptCameraHintTrigger.hpp CScriptCameraHintTrigger.cpp
CScriptBeam.hpp CScriptBeam.cpp
CScriptMazeNode.hpp CScriptMazeNode.cpp
CScriptShadowProjector.hpp CScriptShadowProjector.cpp
CGrappleParameters.hpp
CActorParameters.hpp
CLightParameters.hpp
@ -84,6 +86,7 @@ set(WORLD_SOURCES
CPatterned.hpp CPatterned.cpp
CHUDMemoParms.hpp CHUDMemoParms.cpp
CWorldShadow.hpp CWorldShadow.cpp
CProjectedShadow.hpp CProjectedShadow.cpp
CGameLight.hpp CGameLight.cpp
CFluidPlane.hpp CFluidPlane.cpp
CFluidPlaneCPU.hpp CFluidPlaneCPU.cpp

View File

@ -0,0 +1,21 @@
#include "World/CProjectedShadow.hpp"
namespace urde
{
CProjectedShadow::CProjectedShadow(u32 w, u32 h, bool persistent)
: x0_texture(CTexture(ETexelFormat::I4, w, h, 1))
, x81_persistent(persistent)
{
}
zeus::CAABox CProjectedShadow::CalculateRenderBounds()
{
return {};
}
void CProjectedShadow::Render(CStateManager&, const CModelData&, const zeus::CTransform&, s32,
const zeus::CVector3f&, float, float)
{
}
}

View File

@ -0,0 +1,32 @@
#ifndef __URDE_CPROJECTEDSHADOW_HPP__
#define __URDE_CPROJECTEDSHADOW_HPP__
#include "Graphics/CTexture.hpp"
#include "zeus/CTransform.hpp"
#include "zeus/CAABox.hpp"
namespace urde
{
class CStateManager;
class CModelData;
class CProjectedShadow
{
CTexture x0_texture;
zeus::CAABox x68_ = zeus::CAABox::skInvertedBox;
bool x80_;
bool x81_persistent;
float x84_ = 1.f;
zeus::CVector3f x88_ = zeus::CVector3f::skZero;
float x94_zDistanceAdjust = 0.f;
float x98_ = 1.f;
public:
CProjectedShadow() = default;
CProjectedShadow(u32, u32, bool);
zeus::CAABox CalculateRenderBounds();
void Render(CStateManager&, const CModelData&, const zeus::CTransform&, s32, const zeus::CVector3f&, float,
float);
};
}
#endif // __URDE_CPROJECTEDSHADOW_HPP__

View File

@ -29,13 +29,13 @@ void CScriptAreaAttributes::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
if (msg == EScriptObjectMessage::InternalMessage13)
{
CGameArea* area = stateMgr.GetWorld()->GetArea(x4_areaId);
CGameArea* area = stateMgr.WorldNC()->GetArea(x4_areaId);
area->SetAreaAttributes(this);
stateMgr.GetEnvFxManager()->SetFxDensity(500, x3c_envFxDensity);
}
else if (msg >= EScriptObjectMessage::InternalMessage12)
{
CGameArea* area = stateMgr.GetWorld()->GetArea(x4_areaId);
CGameArea* area = stateMgr.WorldNC()->GetArea(x4_areaId);
if (!area->IsPostConstructed())
return;

View File

@ -120,7 +120,7 @@ void CScriptCoverPoint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid,
for (const SConnection& con : x20_conns)
if (con.x0_state == EScriptObjectState::Retreat)
{
xfc_ = mgr.GetIdForScript(con.x8_objId);
xfc_retreating = mgr.GetIdForScript(con.x8_objId);
break;
}
}

View File

@ -31,7 +31,7 @@ class CScriptCoverPoint : public CActor
u32 xf8_flags = 0;
};
TUniqueId xfa_occupant = kInvalidUniqueId;
TUniqueId xfc_ = kInvalidUniqueId;
TUniqueId xfc_retreating = kInvalidUniqueId;
std::experimental::optional<zeus::CAABox> x100_touchBounds;
float x11c_timeLeft = 0.f;
public:

View File

@ -39,7 +39,7 @@ void CScriptDistanceFog::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId obj
{
if (!x60_explicit)
return;
CGameArea::CAreaFog* fog = stateMgr.GetWorld()->GetArea(x4_areaId)->AreaFog();
CGameArea::CAreaFog* fog = stateMgr.WorldNC()->GetArea(x4_areaId)->AreaFog();
if (x34_mode == ERglFogMode::None)
fog->DisableFog();
else
@ -50,7 +50,7 @@ void CScriptDistanceFog::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId obj
if (!x61_nonZero)
return;
CGameArea::CAreaFog* fog = stateMgr.GetWorld()->GetArea(x4_areaId)->AreaFog();
CGameArea::CAreaFog* fog = stateMgr.WorldNC()->GetArea(x4_areaId)->AreaFog();
if (x34_mode == ERglFogMode::None)
fog->RollFogOut(x48_rangeDelta.x, x44_colorDelta, x38_color);
else
@ -58,13 +58,13 @@ void CScriptDistanceFog::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId obj
if (zeus::close_enough(x54_thermalSpeed, 0.f) && !zeus::close_enough(x5c_xraySpeed, 0.f))
{
CWorld* world = stateMgr.GetWorld();
CWorld* world = stateMgr.WorldNC();
CGameArea* area = world->GetArea(x4_areaId);
area->SetXRaySpeedAndTarget(x5c_xraySpeed, x58_xrayTarget);
}
else
{
CWorld* world = stateMgr.GetWorld();
CWorld* world = stateMgr.WorldNC();
CGameArea* area = world->GetArea(x4_areaId);
area->SetThermalSpeedAndTarget(x54_thermalSpeed, x50_thermalTarget);
}

View File

@ -4,6 +4,8 @@
#include "Collision/CMaterialList.hpp"
#include "CWorld.hpp"
#include "CStateManager.hpp"
#include "CScriptDoor.hpp"
#include "CPlayer.hpp"
namespace urde
{
@ -16,29 +18,204 @@ CMaterialList MakeDockMaterialList()
return list;
}
CScriptDock::CScriptDock(TUniqueId uid, const std::string &name, const CEntityInfo &info,
CScriptDock::CScriptDock(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CVector3f position, const zeus::CVector3f& extents, s32 dock, TAreaId area,
bool active, s32 w1, bool b1)
: CPhysicsActor(uid, active, name, info, zeus::CTransform(zeus::CMatrix3f::skIdentityMatrix3f, position),
CModelData::CModelDataNull(), MakeDockMaterialList(), zeus::CAABox(-extents * 0.5f, extents * 0.5f),
SMoverData(1.f), CActorParameters::None(), 0.3f, 0.1f),
x258_(w1),
x25c_dock(dock),
x260_area(area),
x264_(3)
bool active, s32 w1, bool loadConnected)
: CPhysicsActor(uid, active, name, info, zeus::CTransform(zeus::CMatrix3f::skIdentityMatrix3f, position),
CModelData::CModelDataNull(), MakeDockMaterialList(), zeus::CAABox(-extents * 0.5f, extents * 0.5f),
SMoverData(1.f), CActorParameters::None(), 0.3f, 0.1f)
, x258_dockReferenceCount(w1)
, x25c_dock(dock)
, x260_area(area)
, x268_25_loadConnected(loadConnected)
{
x268_24_ = false;
x268_25_ = b1;
x268_26_ = false;
}
void CScriptDock::AreaLoaded(CStateManager & mgr)
void CScriptDock::Think(float dt, CStateManager& mgr)
{
SetLoadConnected(mgr, x268_25_);
if (!GetActive())
{
UpdateAreaActivateFlags(mgr);
x268_24_dockReferenced = false;
}
CGameArea* area = mgr.WorldNC()->GetArea(x260_area);
if (x268_26_areaPostConstructed != area->IsPostConstructed())
{
if (area->IsPostConstructed())
CEntity::SendScriptMsgs(EScriptObjectState::MaxReached, mgr, EScriptObjectMessage::None);
}
}
void CScriptDock::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
switch (msg)
{
case EScriptObjectMessage::InternalMessage11:
{
CGameArea* area = mgr.WorldNC()->GetArea(x260_area);
if (area->GetDockCount() <= x25c_dock)
return;
IGameArea::Dock* dock = area->DockNC(x25c_dock);
if (!dock->IsReferenced())
dock->SetReferenceCount(x258_dockReferenceCount);
}
break;
case EScriptObjectMessage::InternalMessage12:
CleanUp();
break;
case EScriptObjectMessage::InternalMessage13:
AreaLoaded(mgr);
break;
case EScriptObjectMessage::InternalMessage14:
{
UpdateAreaActivateFlags(mgr);
CMaterialList exclude = GetMaterialFilter().GetExcludeList();
CMaterialList include = GetMaterialFilter().GetIncludeList();
include.Add(EMaterialTypes::AIBlock);
SetMaterialFilter({include, exclude, CMaterialFilter::EFilterType::Three});
}
break;
case EScriptObjectMessage::SetToZero:
{
if (mgr.GetNextAreaId() != x260_area)
return;
SetLoadConnected(mgr, false);
CGameArea* area = mgr.WorldNC()->GetArea(x260_area);
IGameArea::Dock* dock = area->DockNC(x25c_dock);
TAreaId aid = dock->GetConnectedAreaId(dock->GetReferenceCount());
CPlatformAndDoorList& lst = mgr.GetPlatformAndDoorObjectList();
for (CEntity* ent : lst)
{
CScriptDoor* door = static_cast<CScriptDoor*>(ent);
if (door && !door->IsConnectedToArea(mgr, aid))
door->ForceClosed(mgr);
}
}
break;
case EScriptObjectMessage::SetToMax:
if (mgr.GetNextAreaId() != x260_area)
return;
SetLoadConnected(mgr, true);
break;
case EScriptObjectMessage::Increment:
SetLoadConnected(mgr, true);
case EScriptObjectMessage::Decrement:
{
TAreaId aid = x260_area;
if (mgr.GetNextAreaId() == x260_area)
{
IGameArea::Dock* dock = mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock);
aid = dock->GetConnectedAreaId(dock->GetReferenceCount());
}
else
{
if (aid == 0 || mgr.GetWorld()->GetNumAreas() <= aid)
return;
if (!mgr.WorldNC()->GetArea(aid)->GetActive())
return;
}
#if 0
/* Propogate through area chain */
sub800C40DC((msg == EScriptObjectMessage::Increment), mgr.GetWorld()->GetAreaAlways(aid), mgr.WorldNC());
#endif
}
break;
default:
CPhysicsActor::AcceptScriptMsg(msg, uid, mgr);
break;
}
}
rstl::optional_object<zeus::CAABox> CScriptDock::GetTouchBounds() const
{
if (x264_dockState == EDockState::Three)
return {};
return GetBoundingBox();
}
void CScriptDock::Touch(CActor& act, CStateManager&)
{
if (x264_dockState == EDockState::Three)
return;
if (static_cast<CPlayer*>(&act) != nullptr)
x264_dockState = EDockState::PlayerTouched;
}
zeus::CPlane CScriptDock::GetPlane(const CStateManager& mgr) const
{
const IGameArea::Dock* dock = mgr.GetWorld()->GetAreaAlways(x260_area)->GetDock(x25c_dock);
return zeus::CPlane(dock->GetPoint(0), dock->GetPoint(1), dock->GetPoint(2));
}
void CScriptDock::SetDockReference(CStateManager& mgr, s32 ref)
{
mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock)->SetReferenceCount(ref);
x268_24_dockReferenced = true;
}
s32 CScriptDock::GetDockReference(CStateManager& mgr) const
{
return mgr.GetWorld()->GetAreaAlways(x260_area)->GetDock(x25c_dock)->GetReferenceCount();
}
TAreaId CScriptDock::GetCurrentConnectedAreaId(const CStateManager& mgr) const
{
if (mgr.GetWorld()->GetNumAreas() < x260_area)
return kInvalidAreaId;
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(x260_area);
if (area->GetDockCount() < x25c_dock)
return kInvalidAreaId;
const IGameArea::Dock* dock = area->GetDock(x25c_dock);
return dock->GetConnectedAreaId(dock->GetReferenceCount());
}
void CScriptDock::UpdateAreaActivateFlags(CStateManager& mgr)
{
CWorld* world = mgr.WorldNC();
if (x260_area >= world->GetNumAreas())
return;
CGameArea* area = world->GetArea(x260_area);
if (x25c_dock >= area->GetDockCount())
return;
IGameArea::Dock* dock = area->DockNC(x25c_dock);
for (s32 i = 0; i < dock->GetDockRefs().size(); ++i)
{
s32 dockRefCount = dock->GetReferenceCount();
TAreaId aid = dock->GetConnectedAreaId(i);
if (aid != kInvalidAreaId)
world->GetArea(aid)->SetActive(i == dockRefCount);
}
mgr.SetCurrentAreaId(mgr.GetNextAreaId());
}
void CScriptDock::AreaLoaded(CStateManager& mgr)
{
SetLoadConnected(mgr, x268_25_loadConnected);
}
void CScriptDock::SetLoadConnected(CStateManager& mgr, bool loadOther)
{
IGameArea::Dock* dock = mgr.GetWorld()->GetArea(x260_area)->DockNC(x25c_dock);
IGameArea::Dock* dock = mgr.WorldNC()->GetArea(x260_area)->DockNC(x25c_dock);
bool cur = dock->GetShouldLoadOther(dock->GetReferenceCount());
if (cur == loadOther)
return;
dock->SetShouldLoadOther(dock->GetReferenceCount(), loadOther);
}
}

View File

@ -8,29 +8,43 @@ namespace urde
class CScriptDock : public CPhysicsActor
{
enum EDockState
{
Zero,
PlayerTouched,
Two,
Three
};
friend class CScriptDoor;
s32 x258_;
s32 x258_dockReferenceCount;
s32 x25c_dock;
TAreaId x260_area;
u32 x264_;
union
{
EDockState x264_dockState = EDockState::Three;
union {
struct
{
bool x268_24_ : 1;
bool x268_25_ : 1;
bool x268_26_ : 1;
bool x268_24_dockReferenced : 1;
bool x268_25_loadConnected : 1;
bool x268_26_areaPostConstructed : 1;
};
u8 dummy = 0;
};
public:
CScriptDock(TUniqueId uid, const std::string& name, const CEntityInfo& info, const zeus::CVector3f position,
const zeus::CVector3f& extent, s32, TAreaId, bool active, s32 w1, bool b1);
TAreaId GetAreaId() const { return x260_area; }
void Think(float, CStateManager&);
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&);
rstl::optional_object<zeus::CAABox> GetTouchBounds() const;
void Touch(CActor&, CStateManager&);
void CleanUp() {}
zeus::CPlane GetPlane(const CStateManager&) const;
TAreaId GetDestinationAreaId() const { return x260_area; }
s32 GetDockId() const { return x25c_dock; }
void SetDockReference(s32) {}
void GetDockReference(s32) {}
void SetDockReference(CStateManager& mgr, s32);
s32 GetDockReference(CStateManager& mgr) const;
TAreaId GetCurrentConnectedAreaId(const CStateManager&) const;
void UpdateAreaActivateFlags(CStateManager&);
bool HasPointCrossedDock(const CStateManager&, const zeus::CVector3f&) const;

View File

@ -25,7 +25,7 @@ void CScriptDockAreaChange::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
TUniqueId id = it->second;
CScriptDock* dock = dynamic_cast<CScriptDock*>(stateMgr.ObjectById(id));
if (dock)
dock->SetDockReference(x34_dockReference);
dock->SetDockReference(stateMgr, x34_dockReference);
}
}

View File

@ -111,7 +111,7 @@ bool CScriptDoor::IsConnectedToArea(const CStateManager& mgr, TAreaId area)
const CScriptDock* dock = dynamic_cast<const CScriptDock*>(mgr.GetObjectById(x282_dockId));
if (dock)
{
if (dock->x260_area == area)
if (dock->GetDestinationAreaId() == area)
return true;
/*
* TODO: Determine what's going on here

View File

@ -9,16 +9,25 @@ namespace urde
CScriptMazeNode::CScriptMazeNode(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, bool active, s32 w1, s32 w2, s32 w3,
const zeus::CVector3f& vec1, const zeus::CVector3f& vec2, const zeus::CVector3f& vec3)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
kInvalidUniqueId),
xe8_(w1), xec_(w1), xf0_(w2),
x100_(vec1), x110_(vec2), x120_(vec3)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
kInvalidUniqueId)
, xe8_(w1)
, xec_(w1)
, xf0_(w2)
, x100_(vec1)
, x110_(vec2)
, x120_(vec3)
{
x13c_24_ = true;
}
void CScriptMazeNode::LoadSeeds()
{
const SObjectTag* tag = g_ResFactory->GetResourceIdByName("DUMB_MazeSeeds");
u32 resSize = g_ResFactory->ResourceSize(*tag);
std::unique_ptr<u8[]> buf = g_ResFactory->LoadResourceSync(*tag);
CMemoryInStream in(buf.get(), resSize);
for (u32 i = 0; i<300 ; ++i)
sMazeSeeds[i] = in.readUint32Big();
}
}

View File

@ -7,6 +7,7 @@ namespace urde
{
class CScriptMazeNode : CActor
{
static u32 sMazeSeeds[300];
s32 xe8_;
s32 xec_;
s32 xf0_;

View File

@ -0,0 +1,91 @@
#include "World/CScriptShadowProjector.hpp"
#include "World/CActorParameters.hpp"
#include "World/CProjectedShadow.hpp"
#include "CStateManager.hpp"
namespace urde
{
CScriptShadowProjector::CScriptShadowProjector(TUniqueId uid, const std::string& name, const CEntityInfo& info,
const zeus::CTransform& xf, bool active, const zeus::CVector3f& offset,
bool b2, float scale, float f2, float opacity, float opacityQ,
s32 textureSize)
: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(), CActorParameters::None(),
kInvalidUniqueId)
, xe8_scale(scale)
, xec_offset(offset)
, xf8_zOffsetAdjust(f2)
, xfc_opacity(opacity)
, x100_opacityRecip(opacity < 0.00001 ? 1.f : opacityQ / opacity)
, x10c_textureSize(textureSize)
, x110_24_persistent(b2)
{
}
void CScriptShadowProjector::Think(float dt, CStateManager& mgr)
{
if (GetActive() && x110_25_shadowInvalidated)
{
xfc_opacity = (x100_opacityRecip * xfc_opacity) - dt;
if (dt > 0.f)
return;
x108_projectedShadow.reset();
x110_25_shadowInvalidated = false;
SendScriptMsgs(EScriptObjectState::Zero, mgr, EScriptObjectMessage::None);
}
}
void CScriptShadowProjector::CreateProjectedShadow()
{
if (!GetActive() || x104_target == kInvalidUniqueId || xfc_opacity <= 0.f)
x108_projectedShadow.reset();
else
x108_projectedShadow.reset(new CProjectedShadow(x10c_textureSize, x10c_textureSize, x110_24_persistent));
}
void CScriptShadowProjector::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
CActor::AcceptScriptMsg(msg, uid, mgr);
if (msg == EScriptObjectMessage::Decrement)
{
if (x110_24_persistent)
return;
if (xfc_opacity <= 0.f)
return;
x110_25_shadowInvalidated = true;
}
else if (msg == EScriptObjectMessage::InternalMessage13)
{
for (const SConnection& conn : x20_conns)
{
if (conn.x0_state != EScriptObjectState::Play)
continue;
const CActor* act = dynamic_cast<const CActor*>(mgr.GetObjectById(mgr.GetIdForScript(conn.x8_objId)));
if (!act)
continue;
const CModelData* mData = act->GetModelData();
if (!mData || (!mData->GetAnimationData() && !mData->GetNormalModel()))
continue;
x104_target = act->GetUniqueId();
}
if (x104_target == kInvalidUniqueId)
mgr.DeleteObjectRequest(GetUniqueId());
else
CreateProjectedShadow();
}
else if (msg == EScriptObjectMessage::Activate)
CreateProjectedShadow();
}
void CScriptShadowProjector::PreRender(const zeus::CFrustum &, const CStateManager &)
{
}
}

View File

@ -0,0 +1,41 @@
#ifndef __URDE_CSCRIPTSHADOWPROJECTOR_HPP__
#define __URDE_CSCRIPTSHADOWPROJECTOR_HPP__
#include "World/CActor.hpp"
namespace urde
{
class CProjectedShadow;
class CScriptShadowProjector : public CActor
{
float xe8_scale;
zeus::CVector3f xec_offset;
float xf8_zOffsetAdjust;
float xfc_opacity;
float x100_opacityRecip;
TUniqueId x104_target;
std::unique_ptr<CProjectedShadow> x108_projectedShadow;
u32 x10c_textureSize;
union {
struct
{
bool x110_24_persistent : 1;
bool x110_25_shadowInvalidated : 1;
};
u8 x110_dummy = 0;
};
public:
CScriptShadowProjector(TUniqueId, const std::string&, const CEntityInfo&, const zeus::CTransform&, bool,
const zeus::CVector3f&, bool, float, float, float, float, s32);
void Think(float, CStateManager &);
void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager &);
void PreRender(const zeus::CFrustum &, const CStateManager &);
void AddToRenderer(const zeus::CFrustum &, const CStateManager &) const {}
void CreateProjectedShadow();
};
}
#endif // __URDE_CSCRIPTSHADOWPROJECTOR_HPP__

View File

@ -10,7 +10,7 @@ CStateMachine::CStateMachine(CInputStream& in)
x0_states.reserve(stateCount);
for (u32 i = 0 ; i<stateCount ; ++i)
for (u32 i = 0; i < stateCount; ++i)
{
std::string name = in.readString(31);
CAiStateFunc func = CAi::GetStateFunc(name.c_str());
@ -19,31 +19,30 @@ CStateMachine::CStateMachine(CInputStream& in)
x10_triggers.reserve(in.readUint32Big());
for (u32 i = 0 ; i<stateCount ; ++i)
for (u32 i = 0; i < stateCount; ++i)
{
x0_states[i].SetNumTriggers(in.readUint32Big());
if (x0_states[i].GetNumTriggers() == 0)
continue;
for (u32 j = 0 ; j<x0_states[i].GetNumTriggers() ; ++j)
for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j)
x10_triggers.emplace_back();
for (u32 j = 0 ; j<x0_states[i].GetNumTriggers() ; ++j)
for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j)
{
u32 triggerCount = in.readUint32Big();
u32 r19 = triggerCount - 1;
for (u32 k = 0 ; k<triggerCount ; ++k)
for (u32 k = 0; k < triggerCount; ++k)
{
std::string name = in.readString(31);
CAiTriggerFunc func = CAi::GetTrigerFunc(name.c_str());
float f31 = in.readFloatBig();
}
}
}
#endif
}
s32 CStateMachine::GetStateIndex(const std::string& state)
s32 CStateMachine::GetStateIndex(const std::string& state) const
{
auto it = std::find_if(x0_states.begin(), x0_states.end(), [&state](const CAiState& st) -> bool {
return (strncmp(st.GetName(), state.c_str(), 31) == 0);
@ -54,14 +53,24 @@ s32 CStateMachine::GetStateIndex(const std::string& state)
return it - x0_states.begin();
}
const std::vector<CAiState>& CStateMachine::GetStateVector() const
const std::vector<CAiState>& CStateMachine::GetStateVector() const { return x0_states; }
float CStateMachineState::GetTime() const { return 0.f; }
void CStateMachineState::SetState(CStateManager &, CAi &, s32 idx)
{
return x0_states;
}
float CStateMachineState::GetTime() const
void CStateMachineState::SetState(CStateManager& mgr, CAi& ai, const CStateMachine* machine, const std::string& state)
{
return 0.f;
if (!machine)
return;
if (!x0_machine)
x0_machine = machine;
s32 idx = machine->GetStateIndex(state);
SetState(mgr, ai, idx);
}
const std::vector<CAiState>* CStateMachineState::GetStateVector() const
@ -72,18 +81,14 @@ const std::vector<CAiState>* CStateMachineState::GetStateVector() const
return &x0_machine->GetStateVector();
}
void CStateMachineState::Setup(const CStateMachine *machine)
void CStateMachineState::Setup(const CStateMachine* machine)
{
x0_machine = machine;
x4_state = nullptr;
x8_ = 0.f;
x8_time = 0.f;
xc_ = 0.f;
x10_= 0.f;
}
std::string CStateMachineState::GetName() const
{
return {};
x10_ = 0.f;
}
std::string CStateMachineState::GetName() const { return {}; }
}

View File

@ -68,7 +68,7 @@ class CStateMachine
public:
CStateMachine(CInputStream& in);
s32 GetStateIndex(const std::string& state);
s32 GetStateIndex(const std::string& state) const;
const std::vector<CAiState>& GetStateVector() const;
};
@ -76,9 +76,9 @@ class CStateMachineState
{
const CStateMachine* x0_machine = nullptr;
CAiState* x4_state = nullptr;
float x8_ = 0;
float xc_ = 0;
float x10_ = 0;
float x8_time = 0.f;
float xc_ = 0.f;
float x10_ = 0.f;
union
{
struct
@ -95,12 +95,12 @@ public:
void Update(CStateManager& mgr, CAi& ai, float delta)
{
x8_ += delta;
x8_time += delta;
if (x4_state)
x4_state->CallFunc(mgr, ai, EStateMsg::One, delta);
}
void SetState(CStateManager&, CAi&, s32);
void SetState(CStateManager &, CAi &, const std::string&);
void SetState(CStateManager&, CAi&, const CStateMachine*, const std::string&);
const std::vector<CAiState>* GetStateVector() const;
void Setup(const CStateMachine* machine);
std::string GetName() const;

View File

@ -170,6 +170,7 @@ public:
CMapWorld* IMapWorld();
const CGameArea* GetAreaAlways(TAreaId) const;
CGameArea* GetArea(TAreaId);
s32 GetNumAreas() const { return x18_areas.size(); }
const IGameArea* IGetAreaAlways(TAreaId id) const;
TAreaId IGetCurrentAreaId() const;
TAreaId IGetAreaId(ResId id) const;

View File

@ -45,16 +45,23 @@ bool IGameArea::Dock::GetShouldLoadOther(s32 other) const
if (other >= x4_dockReferences.size())
return false;
return false; //return x4_dockReferences[other].GetShouldLoad();
return x4_dockReferences[other].x6_loadOther;
}
void IGameArea::Dock::SetShouldLoadOther(s32 other, bool should)
{
if (other >= x4_dockReferences.size())
return;
x4_dockReferences[other].x6_loadOther = should;
}
bool IGameArea::Dock::ShouldLoadOtherArea(s32 other) const
{
return false;
if (x4_dockReferences.size() == 0)
return false;
return x4_dockReferences[other].x6_loadOther;
}
zeus::CVector3f IGameArea::Dock::GetPoint(s32 idx) const

View File

@ -16,23 +16,16 @@ public:
public:
struct SDockReference
{
u32 x0_area;
s16 x4_dock;
union
{
struct
{
bool x6_16_ : 1;
};
u16 x6_ = 0;
};
u32 x0_area = 0;
s16 x4_dock = 0;
bool x6_loadOther = false;
SDockReference() = default;
};
private:
u32 x0_referenceCount = 0;
std::vector<SDockReference> x4_dockReferences;
rstl::reserved_vector<zeus::CVector3f, 4> x14_planeVertices;
bool x48_;
bool x48_isReferenced;
public:
const rstl::reserved_vector<zeus::CVector3f, 4>& GetPlaneVertices() const {return x14_planeVertices;}
@ -45,6 +38,8 @@ public:
void SetShouldLoadOther(s32 other, bool should);
bool ShouldLoadOtherArea(s32 other) const;
zeus::CVector3f GetPoint(s32 idx) const;
bool IsReferenced() const { return x48_isReferenced; }
void SetReferenceCount(s32 v) { x0_referenceCount = v; x48_isReferenced = true; }
};
struct IAreaObjectList

View File

@ -59,6 +59,7 @@
#include "MP1/CBeetle.hpp"
#include "MP1/CWarWasp.hpp"
#include "MP1/CSpacePirate.hpp"
#include "CScriptShadowProjector.hpp"
#include "CPatternedInfo.hpp"
#include "CSimplePool.hpp"
#include "Collision/CCollidableOBBTreeGroup.hpp"
@ -140,7 +141,7 @@ static zeus::CAABox GetCollisionBox(CStateManager& stateMgr, TAreaId id, const z
const zeus::CVector3f& offset)
{
zeus::CAABox box(-extent * 0.5f + offset, extent * 0.5f + offset);
const zeus::CTransform& rot = stateMgr.GetWorld()->GetGameAreas()[id]->GetTransform().getRotation();
const zeus::CTransform& rot = stateMgr.WorldNC()->GetGameAreas()[id]->GetTransform().getRotation();
return box.getTransformedAABox(rot);
}
@ -520,7 +521,7 @@ CEntity* ScriptLoader::LoadTrigger(CStateManager& mgr, CInputStream& in, int pro
zeus::CAABox box(-extent * 0.5f, extent * 0.5f);
const zeus::CTransform& areaXf = mgr.GetWorld()->GetGameAreas()[info.GetAreaId()]->GetTransform();
const zeus::CTransform& areaXf = mgr.WorldNC()->GetGameAreas()[info.GetAreaId()]->GetTransform();
zeus::CVector3f orientedForce = areaXf.basis * forceVec;
return new CScriptTrigger(mgr.AllocateUniqueId(), *name, info, position, box, dInfo, orientedForce, flags, active,
@ -1074,7 +1075,7 @@ u32 ClassifyVector(const zeus::CVector3f& dir)
u32 TransformDamagableTriggerFlags(CStateManager& mgr, TAreaId aId, u32 flags)
{
CGameArea* area = mgr.GetWorld()->GetGameAreas().at(u32(aId)).get();
CGameArea* area = mgr.WorldNC()->GetGameAreas().at(u32(aId)).get();
zeus::CTransform rotation = area->GetTransform().getRotation();
u32 ret = 0;
@ -2010,8 +2011,8 @@ CEntity* ScriptLoader::LoadBeam(CStateManager& mgr, CInputStream& in, int propCo
CDamageInfo dInfo(in);
TToken<CWeaponDescription> weaponDesc = g_SimplePool->GetObj({SBIG('WPSC'), weaponDescId});
return new CScriptBeam(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active,
weaponDesc, beamInfo, dInfo);
return new CScriptBeam(mgr.AllocateUniqueId(), aHead.x0_name, info, aHead.x10_transform, active, weaponDesc,
beamInfo, dInfo);
}
CEntity* ScriptLoader::LoadWorldLightFader(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)
@ -2062,7 +2063,21 @@ CEntity* ScriptLoader::LoadNewCameraShaker(CStateManager& mgr, CInputStream& in,
CEntity* ScriptLoader::LoadShadowProjector(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)
{
return nullptr;
if (!EnsurePropertyCount(propCount, 10, "ShadowProjector"))
return nullptr;
const std::string* name = mgr.HashInstanceName(in);
zeus::CVector3f position(zeus::CVector3f::ReadBig(in));
bool b1 = in.readBool();
float f1 = in.readFloatBig();
zeus::CVector3f vec2(zeus::CVector3f::ReadBig(in));
float f2 = in.readFloatBig();
float f3 = in.readFloatBig();
float f4 = in.readFloatBig();
bool b2 = in.readBool();
u32 w1 = in.readUint32Big();
return new CScriptShadowProjector(mgr.AllocateUniqueId(), *name, info, zeus::CTransform::Translate(position), b1,
vec2, b2, f1, f2, f3, f4, w1);
}
CEntity* ScriptLoader::LoadEnergyBall(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info)