Skip to content

Commit

Permalink
Update BulletPhysicMnager.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hzqst committed Jan 18, 2024
1 parent 9ba29c6 commit 618fa95
Show file tree
Hide file tree
Showing 11 changed files with 849 additions and 132 deletions.
556 changes: 547 additions & 9 deletions Plugins/BulletPhysics/BasePhysicManager.cpp

Large diffs are not rendered by default.

110 changes: 107 additions & 3 deletions Plugins/BulletPhysics/BasePhysicManager.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,88 @@
#pragma once

#include <vector>
#include <unordered_map>

#include "PhysicManager.h"

class CPhysicBrushVertex
{
public:
CPhysicBrushVertex()
{
pos[0] = 0;
pos[1] = 0;
pos[2] = 0;
}

vec3_t pos;
};

class CPhysicBrushFace
{
public:
CPhysicBrushFace()
{
start_vertex = 0;
num_vertexes = 0;
}

int start_vertex;
int num_vertexes;
};

class CPhysicVertexArray
{
public:
CPhysicVertexArray()
{
bIsDynamic = false;
}
std::vector<CPhysicBrushVertex> vVertexBuffer;
std::vector<CPhysicBrushFace> vFaceBuffer;
bool bIsDynamic;
};

class CPhysicIndexArray
{
public:
CPhysicIndexArray()
{
bIsDynamic = false;
}
std::vector<int> vIndexBuffer;
bool bIsDynamic;
};

class CPhysicObjectCreationParameter
{
public:
CPhysicVertexArray* VertexArray;
CPhysicIndexArray* IndexArray;
};

class CPhysicStaticObjectCreationParameter : public CPhysicObjectCreationParameter
{
public:
bool IsKinematic;
};

class CBasePhysicManager : public IPhysicManager
{
protected:
CPhysicVertexArray* m_worldVertexArray;
CPhysicIndexArray* m_barnacleIndexArray;
CPhysicVertexArray* m_barnacleVertexArray;
CPhysicIndexArray* m_gargantuaIndexArray;
CPhysicVertexArray* m_gargantuaVertexArray;
float m_gravity;

std::unordered_map<int, IPhysicObject *> m_physicObjects;
std::vector<CRagdollConfig *> m_ragdollConfigs;
std::vector<CPhysicIndexArray *> m_brushIndexArray;
public:
CBasePhysicManager();

void Init(void) override;
void Shutdown() override;
void NewMap(void) override;
Expand All @@ -16,12 +94,38 @@ class CBasePhysicManager : public IPhysicManager
bool SetupJiggleBones(studiohdr_t* hdr, int entindex) override;
void MergeBarnacleBones(studiohdr_t* hdr, int entindex) override;
bool ChangeRagdollEntityIndex(int old_entindex, int new_entindex) override;
IRagdollObject* FindRagdollObject(int entindex) override;
IRagdollObject* CreateRagdollObject(model_t* mod, int entindex, const CRagdollConfig* config) override;
IStaticObject* CreateStaticObject(model_t* mod, int entindex) override;
IPhysicObject* GetPhysicObject(int entindex) override;
IRagdollObject* CreateRagdollObject(model_t* mod, int entindex, const CRagdollConfig& config) override;
void CreateBrushModel(cl_entity_t* ent) override;
void CreateBarnacle(cl_entity_t* ent) override;
void CreateGargantua(cl_entity_t* ent) override;
void RemovePhysicObject(int entindex) override;
void UpdateTempEntity(TEMPENTITY** ppTempEntFree, TEMPENTITY** ppTempEntActive, double frame_time, double client_time) override;

public:

virtual IStaticObject* CreateStaticObject(cl_entity_t* ent, const CPhysicStaticObjectCreationParameter& CreationParameter) = 0;

private:
//WorldVertexArray and WorldIndexArray
void GenerateWorldIndexVertexArray();
void FreeWorldVertexArray();
void GenerateBrushIndexArray();
void FreeAllBrushIndexArray();
void GenerateIndexArrayForBrushModel(model_t* mod, CPhysicVertexArray* vertexArray, CPhysicIndexArray* indexArray);
void GenerateIndexArrayRecursiveWorldNode(mnode_t* node, CPhysicVertexArray* vertexArray, CPhysicIndexArray* indexArray);
void GenerateIndexArrayForSurface(msurface_t* psurf, CPhysicVertexArray* vertexarray, CPhysicIndexArray* indexarray);
void GenerateIndexArrayForBrushface(CPhysicBrushFace* brushface, CPhysicIndexArray* indexArray);

CPhysicIndexArray* GetIndexArrayFromBrushModel(model_t* mod);

//Barnacle's VertexArray and IndexArray
void GenerateBarnacleIndexVertexArray();
void FreeBarnacleIndexVertexArray();

//Gargantua's VertexArray and IndexArray
void GenerateGargantuaIndexVertexArray();
void FreeGargantuaIndexVertexArray();

CRagdollConfig* GetRagdollConfigFromModel(model_t* mod);
};
17 changes: 4 additions & 13 deletions Plugins/BulletPhysics/BulletPhysicManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,8 @@ class CBulletPhysicManager : public CBasePhysicManager
void DebugDraw(void) override;
void SetGravity(float velocity) override;
void StepSimulation(double framerate) override;
void ReloadConfig(void) override;
bool SetupBones(studiohdr_t* hdr, int entindex) override;
bool SetupJiggleBones(studiohdr_t* hdr, int entindex) override;
void MergeBarnacleBones(studiohdr_t* hdr, int entindex) override;
bool ChangeRagdollEntityIndex(int old_entindex, int new_entindex) override;
IRagdollObject* FindRagdollObject(int entindex) override;
IRagdollObject* CreateRagdollObject(model_t* mod, int entindex, const CRagdollConfig* config) override;
IStaticObject* CreateStaticObject(model_t* mod, int entindex) override;
void CreateBrushModel(cl_entity_t* ent) override;
void CreateBarnacle(cl_entity_t* ent) override;
void CreateGargantua(cl_entity_t* ent) override;
void RemovePhysicObject(int entindex) override;
void UpdateTempEntity(TEMPENTITY** ppTempEntFree, TEMPENTITY** ppTempEntActive, double frame_time, double client_time) override;

public:
IStaticObject* CreateStaticObject(cl_entity_t* ent, const CPhysicStaticObjectCreationParameter& CreationParameter) override;

};
130 changes: 79 additions & 51 deletions Plugins/BulletPhysics/BulletPhysicMnager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,94 +16,122 @@ CBulletPhysicManager::CBulletPhysicManager() : CBasePhysicManager()
m_debugDraw = NULL;
}

void CBulletPhysicManager::Init(void)
ATTRIBUTE_ALIGNED16(class)
CBulletPhysicsDebugDraw : public btIDebugDraw
{
CBasePhysicManager::Init();
}
private:
int m_debugMode;
DefaultColors m_ourColors;

void CBulletPhysicManager::Shutdown()
{
CBasePhysicManager::Shutdown();
public:
BT_DECLARE_ALIGNED_ALLOCATOR();

}
CBulletPhysicsDebugDraw() : m_debugMode(btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawConstraints | btIDebugDraw::DBG_DrawConstraintLimits)
{

void CBulletPhysicManager::NewMap(void)
{
CBasePhysicManager::NewMap();
}

}
~CBulletPhysicsDebugDraw() override
{
}

void CBulletPhysicManager::DebugDraw(void)
{
DefaultColors getDefaultColors() const override
{
return m_ourColors;
}
///the default implementation for setDefaultColors has no effect. A derived class can implement it and store the colors.
void setDefaultColors(const DefaultColors& colors) override
{
m_ourColors = colors;
}

}
void CBulletPhysicManager::SetGravity(float velocity)
{
void drawLine(const btVector3& from1, const btVector3& to1, const btVector3& color1) override
{

}
void CBulletPhysicManager::StepSimulation(double framerate)
{
}

}
void CBulletPhysicManager::ReloadConfig(void)
{
void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color) override
{
drawLine(PointOnB, PointOnB + normalOnB * distance, color);
btVector3 nColor(0, 0, 0);
drawLine(PointOnB, PointOnB + normalOnB * 0.01, nColor);
}

}
void reportErrorWarning(const char* warningString) override
{

bool CBulletPhysicManager::SetupBones(studiohdr_t* hdr, int entindex)
{
return false;
}
}

bool CBulletPhysicManager::SetupJiggleBones(studiohdr_t* hdr, int entindex)
{
return false;
}
void draw3dText(const btVector3& location, const char* textString) override
{

void CBulletPhysicManager::MergeBarnacleBones(studiohdr_t* hdr, int entindex)
{
}

}
void setDebugMode(int debugMode) override
{
m_debugMode = debugMode;
}

bool CBulletPhysicManager::ChangeRagdollEntityIndex(int old_entindex, int new_entindex)
{
return false;
}
int getDebugMode() const override
{
return m_debugMode;
}
};

IRagdollObject* CBulletPhysicManager::FindRagdollObject(int entindex)
{
return NULL;
}

IRagdollObject* CBulletPhysicManager::CreateRagdollObject(model_t* mod, int entindex, const CRagdollConfig* config)
void CBulletPhysicManager::Init(void)
{
return NULL;
CBasePhysicManager::Init();

m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_overlappingPairCache = new btDbvtBroadphase();
m_solver = new btSequentialImpulseConstraintSolver;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_overlappingPairCache, m_solver, m_collisionConfiguration);

m_debugDraw = new CBulletPhysicsDebugDraw;
m_dynamicsWorld->setDebugDrawer(m_debugDraw);

//m_overlapFilterCallback = new GameFilterCallback();
m_dynamicsWorld->getPairCache()->setOverlapFilterCallback(m_overlapFilterCallback);

m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
}

IStaticObject* CBulletPhysicManager::CreateStaticObject(model_t* mod, int entindex)
void CBulletPhysicManager::Shutdown()
{
return NULL;
CBasePhysicManager::Shutdown();

}

void CBulletPhysicManager::CreateBrushModel(cl_entity_t* ent)
void CBulletPhysicManager::NewMap(void)
{
CBasePhysicManager::NewMap();

}
void CBulletPhysicManager::CreateBarnacle(cl_entity_t* ent)

void CBulletPhysicManager::DebugDraw(void)
{

}
void CBulletPhysicManager::CreateGargantua(cl_entity_t* ent)

void CBulletPhysicManager::SetGravity(float velocity)
{
CBasePhysicManager::SetGravity(velocity);

m_dynamicsWorld->setGravity(btVector3(0, 0, m_gravity));
}
void CBulletPhysicManager::RemovePhysicObject(int entindex)

void CBulletPhysicManager::StepSimulation(double framerate)
{

}
void CBulletPhysicManager::UpdateTempEntity(TEMPENTITY** ppTempEntFree, TEMPENTITY** ppTempEntActive, double frame_time, double client_time)

IStaticObject* CBulletPhysicManager::CreateStaticObject(cl_entity_t* ent, const CPhysicStaticObjectCreationParameter& CreationParameter)
{


return NULL;
}

static CBulletPhysicManager g_BulletPhysicManager;
Expand Down
Loading

0 comments on commit 618fa95

Please sign in to comment.