GS-Entbase: More work done on CBasePhysics
This commit is contained in:
parent
2b1e23a2fe
commit
770426e82c
5 changed files with 162 additions and 64 deletions
|
@ -55,6 +55,7 @@ server/func_wall_toggle.cpp
|
||||||
server/func_conveyor.cpp
|
server/func_conveyor.cpp
|
||||||
server/func_rotating.cpp
|
server/func_rotating.cpp
|
||||||
server/func_rot_button.cpp
|
server/func_rot_button.cpp
|
||||||
|
server/func_physbox.cpp
|
||||||
server/func_plat.cpp
|
server/func_plat.cpp
|
||||||
server/func_pendulum.cpp
|
server/func_pendulum.cpp
|
||||||
server/func_vehicle.cpp
|
server/func_vehicle.cpp
|
||||||
|
|
|
@ -14,10 +14,110 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::PhysicsEnable(void)
|
||||||
|
{
|
||||||
|
#ifdef GS_PHYSICS
|
||||||
|
physics_enable(this, TRUE);
|
||||||
|
#else
|
||||||
|
print("^1CBasePhysics::PhysicsEnable: ");
|
||||||
|
print("^7Physics simulator not enabled.\n");
|
||||||
|
#endif
|
||||||
|
m_iEnabled = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::PhysicsDisable(void)
|
||||||
|
{
|
||||||
|
#ifdef GS_PHYSICS
|
||||||
|
physics_enable(this, FALSE);
|
||||||
|
#else
|
||||||
|
print("^1CBasePhysics::PhysicsDisable: ");
|
||||||
|
print("^7Physics simulator not enabled.\n");
|
||||||
|
#endif
|
||||||
|
m_iEnabled = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::SetMass(float val)
|
||||||
|
{
|
||||||
|
mass = val;
|
||||||
|
}
|
||||||
|
float
|
||||||
|
CBasePhysics::GetMass(void)
|
||||||
|
{
|
||||||
|
return mass;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::SetFriction(float val)
|
||||||
|
{
|
||||||
|
friction = val;
|
||||||
|
}
|
||||||
|
float
|
||||||
|
CBasePhysics::GetFriction(void)
|
||||||
|
{
|
||||||
|
return friction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::SetBounceFactor(float val)
|
||||||
|
{
|
||||||
|
bouncefactor = val;
|
||||||
|
}
|
||||||
|
float
|
||||||
|
CBasePhysics::GetBounceFactor(void)
|
||||||
|
{
|
||||||
|
return bouncefactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::SetInertia(float val)
|
||||||
|
{
|
||||||
|
m_flInertiaScale = val;
|
||||||
|
}
|
||||||
|
float
|
||||||
|
CBasePhysics::GetInertia(void)
|
||||||
|
{
|
||||||
|
return m_flInertiaScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::ApplyForceCenter(vector vecForce)
|
||||||
|
{
|
||||||
|
#ifdef GS_PHYSICS
|
||||||
|
physics_addforce(this, vecForce, [0,0,0]);
|
||||||
|
#else
|
||||||
|
print("^1CBasePhysics::ApplyForceCenter: ");
|
||||||
|
print("^7Physics simulator not enabled.\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::ApplyForceOffset(vector vecForce, vector vecOffset)
|
||||||
|
{
|
||||||
|
#ifdef GS_PHYSICS
|
||||||
|
physics_addforce(this, vecForce, vecOffset);
|
||||||
|
#else
|
||||||
|
print("^1CBasePhysics::ApplyForceOffset: ");
|
||||||
|
print("^7Physics simulator not enabled.\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CBasePhysics::ApplyTorqueCenter(vector vecTorque)
|
||||||
|
{
|
||||||
|
#ifdef GS_PHYSICS
|
||||||
|
physics_addtorque(this, vecTorque * m_flInertia);
|
||||||
|
#else
|
||||||
|
print("^1CBasePhysics::ApplyTorqueCenter: ");
|
||||||
|
print("^7Physics simulator not enabled.\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CBasePhysics::TouchThink(void)
|
CBasePhysics::TouchThink(void)
|
||||||
{
|
{
|
||||||
#ifdef GS_BULLET_PHYSICS
|
|
||||||
/* let players collide */
|
/* let players collide */
|
||||||
dimension_solid = 255;
|
dimension_solid = 255;
|
||||||
dimension_hit = 255;
|
dimension_hit = 255;
|
||||||
|
@ -27,15 +127,15 @@ CBasePhysics::TouchThink(void)
|
||||||
/* stuck */
|
/* stuck */
|
||||||
if (trace_startsolid) {
|
if (trace_startsolid) {
|
||||||
if (trace_ent.flags & FL_CLIENT) {
|
if (trace_ent.flags & FL_CLIENT) {
|
||||||
physics_enable(this, TRUE);
|
PhysicsEnable();
|
||||||
makevectors(vectoangles(origin - trace_ent.origin));
|
makevectors(vectoangles(origin - trace_ent.origin));
|
||||||
velocity = v_forward * 256;
|
ApplyTorqueCenter([25,0,0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we barely move, disable the physics simulator */
|
/* If we barely move, disable the physics simulator */
|
||||||
if (vlen(velocity) <= 1) {
|
if (vlen(velocity) <= 1 && m_iEnabled) {
|
||||||
physics_enable(this, FALSE);
|
PhysicsDisable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* don't let players collide */
|
/* don't let players collide */
|
||||||
|
@ -45,43 +145,41 @@ CBasePhysics::TouchThink(void)
|
||||||
/* continue testing next frame */
|
/* continue testing next frame */
|
||||||
nextthink = time;
|
nextthink = time;
|
||||||
effects &= ~EF_NOSHADOW;
|
effects &= ~EF_NOSHADOW;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CBasePhysics::touch(void)
|
CBasePhysics::touch(void)
|
||||||
{
|
{
|
||||||
#ifdef GS_BULLET_PHYSICS
|
PhysicsEnable();
|
||||||
makevectors(vectoangles(origin - other.origin));
|
makevectors(vectoangles(origin - other.origin));
|
||||||
physics_addforce(this, v_forward, other.origin);
|
ApplyForceOffset(v_forward, origin - other.origin);
|
||||||
physics_enable(this, TRUE);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CBasePhysics::Pain(void)
|
CBasePhysics::Pain(void)
|
||||||
{
|
{
|
||||||
#ifdef GS_BULLET_PHYSICS
|
if (m_iFlags & BPHY_NODMGPUSH)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PhysicsEnable();
|
||||||
makevectors(vectoangles(origin - trace_endpos));
|
makevectors(vectoangles(origin - trace_endpos));
|
||||||
physics_addforce(this, v_forward * 20, trace_endpos);
|
ApplyForceOffset(v_forward * 20, origin - trace_endpos);
|
||||||
health = 100000;
|
health = 100000;
|
||||||
physics_enable(this, TRUE);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CBasePhysics::Respawn(void)
|
CBasePhysics::Respawn(void)
|
||||||
{
|
{
|
||||||
#ifdef GS_BULLET_PHYSICS
|
SetMovetype(MOVETYPE_PHYSICS);
|
||||||
movetype = MOVETYPE_PHYSICS;
|
SetSolid(SOLID_PHYSICS_BOX + m_iShape);
|
||||||
solid = SOLID_PHYSICS_BOX + m_iShape;
|
|
||||||
geomtype = GEOMTYPE_BOX;
|
geomtype = GEOMTYPE_BOX;
|
||||||
SetModel(m_oldModel);
|
SetModel(m_oldModel);
|
||||||
SetOrigin(m_oldOrigin);
|
SetOrigin(m_oldOrigin);
|
||||||
physics_enable(this, TRUE);
|
|
||||||
takedamage = DAMAGE_YES;
|
takedamage = DAMAGE_YES;
|
||||||
health = 100000;
|
health = 100000;
|
||||||
mass = m_flMass;
|
PhysicsDisable();
|
||||||
|
SetFriction(2.0f);
|
||||||
|
SetBounceFactor(0.25f);
|
||||||
|
|
||||||
/* don't let players collide */
|
/* don't let players collide */
|
||||||
dimension_solid = 1;
|
dimension_solid = 1;
|
||||||
|
@ -89,12 +187,6 @@ CBasePhysics::Respawn(void)
|
||||||
|
|
||||||
think = TouchThink;
|
think = TouchThink;
|
||||||
nextthink = time + 0.1f;
|
nextthink = time + 0.1f;
|
||||||
#else
|
|
||||||
movetype = MOVETYPE_NONE;
|
|
||||||
solid = SOLID_BBOX;
|
|
||||||
SetModel(m_oldModel);
|
|
||||||
SetOrigin(m_oldOrigin);
|
|
||||||
#endif
|
|
||||||
effects &= ~EF_NOSHADOW;
|
effects &= ~EF_NOSHADOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,13 +202,24 @@ CBasePhysics::SpawnKey(string strKey, string strValue)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "massscale":
|
case "massscale":
|
||||||
m_flMass = stof(strValue);
|
mass = stof(strValue);
|
||||||
|
break;
|
||||||
|
case "inertiascale":
|
||||||
|
m_flInertiaScale = stof(strValue);
|
||||||
break;
|
break;
|
||||||
case "physdamagescale":
|
case "physdamagescale":
|
||||||
break;
|
break;
|
||||||
case "material":
|
case "material":
|
||||||
m_iMaterial = stof(strValue);
|
m_iMaterial = stof(strValue);
|
||||||
break;
|
break;
|
||||||
|
case "nodamageforces":
|
||||||
|
if (strValue == "1")
|
||||||
|
m_iFlags |= BPHY_NODMGPUSH;
|
||||||
|
break;
|
||||||
|
case "Damagetype":
|
||||||
|
if (strValue == "1")
|
||||||
|
m_iFlags |= BPHY_SHARP;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
CBaseEntity::SpawnKey(strKey, strValue);
|
CBaseEntity::SpawnKey(strKey, strValue);
|
||||||
break;
|
break;
|
||||||
|
@ -126,6 +229,8 @@ CBasePhysics::SpawnKey(string strKey, string strValue)
|
||||||
void
|
void
|
||||||
CBasePhysics::CBasePhysics(void)
|
CBasePhysics::CBasePhysics(void)
|
||||||
{
|
{
|
||||||
|
mass = 1.0f;
|
||||||
|
m_flInertiaScale = 1.0f;
|
||||||
|
|
||||||
CBaseEntity::CBaseEntity();
|
CBaseEntity::CBaseEntity();
|
||||||
m_flMass = 1.0f;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,37 @@ enum
|
||||||
PHYSM_CYLINDER
|
PHYSM_CYLINDER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enumflags
|
||||||
|
{
|
||||||
|
BPHY_NODMGPUSH,
|
||||||
|
BPHY_SHARP
|
||||||
|
};
|
||||||
|
|
||||||
class CBasePhysics:CBaseEntity
|
class CBasePhysics:CBaseEntity
|
||||||
{
|
{
|
||||||
|
int m_iEnabled;
|
||||||
int m_iShape;
|
int m_iShape;
|
||||||
int m_iMaterial;
|
int m_iMaterial;
|
||||||
float m_flMass;
|
int m_iFlags;
|
||||||
|
float m_flInertiaScale;
|
||||||
|
|
||||||
void(void) CBasePhysics;
|
void(void) CBasePhysics;
|
||||||
virtual void(void) Respawn;
|
virtual void(void) Respawn;
|
||||||
virtual void(void) touch;
|
virtual void(void) touch;
|
||||||
virtual void(void) TouchThink;
|
virtual void(void) TouchThink;
|
||||||
virtual void(void) Pain;
|
virtual void(void) Pain;
|
||||||
|
|
||||||
|
virtual void(float) SetMass;
|
||||||
|
virtual float(void) GetMass;
|
||||||
|
virtual void(float) SetFriction;
|
||||||
|
virtual float(void) GetFriction;
|
||||||
|
virtual void(float) SetBounceFactor;
|
||||||
|
virtual float(void) GetBounceFactor;
|
||||||
|
virtual void(void) PhysicsEnable;
|
||||||
|
virtual void(void) PhysicsDisable;
|
||||||
|
virtual void(vector) ApplyForceCenter;
|
||||||
|
virtual void(vector, vector) ApplyForceOffset;
|
||||||
|
virtual void(vector) ApplyTorqueCenter;
|
||||||
|
|
||||||
virtual void(string, string) SpawnKey;
|
virtual void(string, string) SpawnKey;
|
||||||
};
|
};
|
||||||
|
|
|
@ -71,12 +71,12 @@ class func_door_rotating:CBaseTrigger
|
||||||
virtual void(vector angle, void(void) func) RotToDest;
|
virtual void(vector angle, void(void) func) RotToDest;
|
||||||
virtual void(string, string) SpawnKey;
|
virtual void(string, string) SpawnKey;
|
||||||
|
|
||||||
#ifdef GS_BULLET_PHYSICS
|
#ifdef GS_PHYSICS
|
||||||
virtual void(void) Unhinge;
|
virtual void(void) Unhinge;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef GS_BULLET_PHYSICS
|
#ifdef GS_PHYSICS
|
||||||
void func_door_rotating::Unhinge(void)
|
void func_door_rotating::Unhinge(void)
|
||||||
{
|
{
|
||||||
takedamage = DAMAGE_NO;
|
takedamage = DAMAGE_NO;
|
||||||
|
@ -297,7 +297,7 @@ void func_door_rotating::Respawn(void)
|
||||||
{
|
{
|
||||||
func_door_rotating::SetMovementDirection();
|
func_door_rotating::SetMovementDirection();
|
||||||
|
|
||||||
#ifdef GS_BULLET_PHYSICS
|
#ifdef GS_PHYSICS
|
||||||
takedamage = DAMAGE_YES;
|
takedamage = DAMAGE_YES;
|
||||||
health = 100;
|
health = 100;
|
||||||
Death = func_door_rotating::Unhinge;
|
Death = func_door_rotating::Unhinge;
|
||||||
|
|
|
@ -14,64 +14,35 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*QUAKED func_physbox_multiplayer (0 .5 .8) ?
|
|
||||||
"targetname" Name
|
|
||||||
|
|
||||||
Physics brush (server) - same for all player on server
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*QUAKED func_physbox (0 .5 .8) ?
|
/*QUAKED func_physbox (0 .5 .8) ?
|
||||||
"targetname" Name
|
"targetname" Name
|
||||||
|
|
||||||
Physics brush (client)
|
Physics brush (client)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class func_physbox:CBaseEntity
|
class func_physbox:CBasePhysics
|
||||||
{
|
{
|
||||||
int m_iShape;
|
int m_iShape;
|
||||||
|
|
||||||
void(void) func_physbox;
|
void(void) func_physbox;
|
||||||
virtual void(void) Respawn;
|
|
||||||
virtual void(void) touch;
|
|
||||||
virtual void(string, string) SpawnKey;
|
virtual void(string, string) SpawnKey;
|
||||||
};
|
};
|
||||||
|
|
||||||
void func_physbox::touch(void)
|
|
||||||
{
|
|
||||||
//physics_addforce(this, other.velocity, other.origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
void func_physbox::Respawn(void)
|
void func_physbox::Respawn(void)
|
||||||
{
|
{
|
||||||
SetMovetype(MOVETYPE_PHYSICS);
|
CBasePhysics::Respawn();
|
||||||
SetSolid(SOLID_PHYSICS_BOX); // SOLID_PHYSICS_TRIMESH
|
|
||||||
SetModel(m_oldModel);
|
|
||||||
SetOrigin(m_oldOrigin);
|
|
||||||
physics_enable(this, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
func_physbox::SpawnKey(string strKey, string strValue)
|
func_physbox::SpawnKey(string strKey, string strValue)
|
||||||
{
|
{
|
||||||
switch (strKey) {
|
switch (strKey) {
|
||||||
case "material":
|
|
||||||
//m_iMaterial = stof(strValue);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
CBaseEntity::SpawnKey(strKey, strValue);
|
CBasePhysics::SpawnKey(strKey, strValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void func_physbox::func_physbox(void)
|
void func_physbox::func_physbox(void)
|
||||||
{
|
{
|
||||||
if (!model) {
|
CBasePhysics::CBasePhysics();
|
||||||
remove(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CBaseEntity::CBaseEntity();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CLASSEXPORT(func_physbox, func_physbox)
|
|
||||||
CLASSEXPORT(func_physbox_multiplayer, func_physbox)
|
|
Loading…
Reference in a new issue