Nuclide
Software Development Kit for id Technology (BETA)
PhysicsEntity.h
1/*
2 * Copyright (c) 2016-2022 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17var bool autocvar_phys_developer = false;
18void
19_NSPhysics_Log(string msg)
20{
21 if (autocvar_phys_developer == true)
22 print(sprintf("%f %s\n", time, msg));
23}
24#define NSPhysics_Log(...) _NSPhysics_Log(sprintf(__VA_ARGS__))
25
26
27var float autocvar_phys_pushscale = 1.0f;
28var float autocvar_phys_impactforcescale = 1.0f;
29
30#ifdef CLIENT
31var bool autocvar_r_showPhysicsInfo = false;
32#endif
33
34.float damp_linear;
35.float damp_angular;
36.float jointgroup;
37
38
40{
41 BPHY_NODMGPUSH,
42 BPHY_SHARP
43};
44
45
46typedef enumflags
47{
48 PHYENT_CHANGED_ORIGIN_X,
49 PHYENT_CHANGED_ORIGIN_Y,
50 PHYENT_CHANGED_ORIGIN_Z,
51 PHYENT_CHANGED_ANGLES_X,
52 PHYENT_CHANGED_ANGLES_Y,
53 PHYENT_CHANGED_ANGLES_Z,
54 PHYENT_CHANGED_MODELINDEX,
55 PHYENT_CHANGED_SIZE,
56 PHYENT_CHANGED_FLAGS,
57 PHYENT_CHANGED_SOLID,
58 PHYENT_CHANGED_FRAME,
59 PHYENT_CHANGED_SKIN,
60 PHYENT_CHANGED_MOVETYPE,
61 PHYENT_CHANGED_EFFECTS,
62 PHYENT_CHANGED_BODY,
63 PHYENT_CHANGED_SCALE,
64 PHYENT_CHANGED_VELOCITY,
65 PHYENT_CHANGED_RENDERCOLOR,
66 PHYENT_CHANGED_RENDERAMT,
67 PHYENT_CHANGED_RENDERMODE,
68} nsphyricsentity_changed_t;
69
70
88enum
89{
95};
96
106{
107public:
108 void ncPhysicsEntity(void);
109
110 /* overrides */
111 virtual void Respawn(void);
112 virtual void SpawnKey(string,string);
113 virtual void SetModel(string);
114
115#ifdef SERVER
116 virtual void Spawned(void);
117 virtual void Pain(entity, entity, int, vector, vector, int);
118 virtual void Death(entity, entity, int, vector, vector, int);
119 virtual void EvaluateEntity(void);
120 virtual float SendEntity(entity,float);
121 virtual void Save(float);
122 virtual void Restore(string,string);
123 virtual void Touch(entity);
124#endif
125#ifdef CLIENT
126 virtual void ReceiveEntity(float,float);
127 virtual void postdraw(void);
128#endif
129
130 nonvirtual void _UpdateBuoyancy(void);
131 nonvirtual void _UpdateMass(void);
132
134 nonvirtual void SetFriction(float);
136 nonvirtual float GetFriction(void);
137
139 nonvirtual float CalculateImpactDamage(int,int);
140
141 /* this merely mirrors the GMod API: https://wiki.facepunch.com/gmod/PhysObj */
143 nonvirtual vector AlignAngles(vector, vector);
145 nonvirtual void ApplyForceCenter(vector);
147 nonvirtual void ApplyForceOffset(vector,vector);
149 nonvirtual void ApplyTorqueCenter(vector);
151 nonvirtual void EnableDrag(bool);
153 nonvirtual void EnableGravity(bool);
155 nonvirtual void EnableMotion(bool);
157 nonvirtual float GetLinearDamping(void);
159 nonvirtual float GetAngularDamping(void);
161 nonvirtual float GetEnergy(void);
163 nonvirtual float GetInertia(void);
165 nonvirtual float GetInvInertia(void);
167 nonvirtual float GetInvMass(void);
169 nonvirtual float GetMass(void);
171 nonvirtual vector GetMassCenter(void);
173 nonvirtual float GetRotDamping(void);
175 nonvirtual float GetSpeedDamping(void);
177 nonvirtual float GetSurfaceArea(void);
179 nonvirtual float GetVolume(void);
181 nonvirtual bool IsAsleep(void);
183 nonvirtual bool IsCollisionEnabled(void);
185 nonvirtual bool IsDragEnabled(void);
187 nonvirtual bool IsGravityEnabled(void);
189 nonvirtual bool IsMotionEnabled(void);
191 nonvirtual bool IsMoveable(void);
193 nonvirtual bool IsPenetrating(void);
194
196 nonvirtual void SetAngleDragCoefficient(float);
198 nonvirtual void SetBuoyancyRatio(float);
200 nonvirtual void SetDamping(float, float);
202 nonvirtual void SetDragCoefficient(float);
203
205 nonvirtual void SetInertia(float);
207 nonvirtual void SetMass(float);
208
210 nonvirtual void Wake(void);
212 nonvirtual void Sleep(void);
213
214private:
215 int m_iEnabled;
216 int m_desiredGeomtype;
217 int m_surfdataID;
218 int m_physicsFlags;
219 float m_inertiaScale;
220 float m_buoyancyRatio;
221 bool m_physicsGod;
222 float m_overrideVolume;
223 float m_lastTouchTime;
224
225 /* performance sanity checks */
226 vector m_vecPrevOrigin;
227 vector m_vecPrevAngles;
228 float m_timeSincePhysicsCheck;
229 PREDICTED_FLOAT(m_overrideMass)
230 float m_spawnPhysTime;
231 bool m_playingFeedbackSound;
232
233#ifdef SERVER
234 string m_outputOnDamaged;
235 bool m_pvsSleep;
236 nonvirtual void PVSCheck(void);
237#endif
238};
239
240noref .bool isPhysics;
241 // end of pmove
This entity class represents physically-simulated entities.
Definition: PhysicsEntity.h:106
nonvirtual void ApplyForceCenter(vector)
Call to apply a force (absolute velocity vector) to the center of the entity.
Definition: PhysicsEntity.qc:896
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: PhysicsEntity.qc:105
nonvirtual bool IsCollisionEnabled(void)
Returns whether the entity is able to collide with anything.
Definition: PhysicsEntity.qc:1063
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: PhysicsEntity.qc:709
nonvirtual float GetSpeedDamping(void)
Returns the speed damping of the entity.
Definition: PhysicsEntity.qc:1039
nonvirtual float GetFriction(void)
Returns the friction multiplayer for this entity.
Definition: PhysicsEntity.qc:409
nonvirtual float GetLinearDamping(void)
Returns the linear damping of the entity.
Definition: PhysicsEntity.qc:975
nonvirtual vector AlignAngles(vector, vector)
Call to align angles of the object to the ones passed.
Definition: PhysicsEntity.qc:889
nonvirtual float GetInvMass(void)
Returns 1 divided by the mass of this entity.
Definition: PhysicsEntity.qc:1015
nonvirtual float GetMass(void)
Returns the mass of the entity.
Definition: PhysicsEntity.qc:1021
nonvirtual float GetRotDamping(void)
Returns the rotational damping of the entity.
Definition: PhysicsEntity.qc:1033
nonvirtual float GetSurfaceArea(void)
Returns the surface area of the entity.
Definition: PhysicsEntity.qc:1045
nonvirtual float GetEnergy(void)
Returns the linear and rotational kinetic energy combined.
Definition: PhysicsEntity.qc:987
nonvirtual void _UpdateMass(void)
Definition: PhysicsEntity.qc:1130
nonvirtual void SetMass(float)
Sets the mass of the entity in kilograms.
Definition: PhysicsEntity.qc:1158
nonvirtual void SetBuoyancyRatio(float)
Call to set the buoyancy ratio of the entity.
Definition: PhysicsEntity.qc:1105
nonvirtual float GetVolume(void)
Returns the volume of the entity.
Definition: PhysicsEntity.qc:1051
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: PhysicsEntity.qc:220
nonvirtual void Sleep(void)
Call to freeze physics simulation on this entity.
Definition: PhysicsEntity.qc:1196
virtual void postdraw(void)
Client: Run after the rendering of 3D world is complete.
nonvirtual void SetFriction(float)
Sets the friction multiplier for this entity.
Definition: PhysicsEntity.qc:404
nonvirtual void _UpdateBuoyancy(void)
Definition: PhysicsEntity.qc:1141
nonvirtual vector GetMassCenter(void)
Returns the center of mass of the entity.
Definition: PhysicsEntity.qc:1027
nonvirtual bool IsPenetrating(void)
Returns whether the entity is penetrating another object.
Definition: PhysicsEntity.qc:1093
void ncPhysicsEntity(void)
Definition: PhysicsEntity.qc:58
nonvirtual void SetDamping(float, float)
Call to set the linear and angular damping of the entity.
Definition: PhysicsEntity.qc:1111
virtual void SetModel(string)
Sets the 3D model representation of the entity from a file path and name.
Definition: PhysicsEntity.qc:77
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: PhysicsEntity.qc:95
virtual void ReceiveEntity(float, float)
Client: Handles network updates from the server for the associated entity.
nonvirtual void SetInertia(float)
Sets the angular inertia for this entity.
Definition: PhysicsEntity.qc:1124
nonvirtual bool IsMotionEnabled(void)
Returns whether the entity is able to move by itself.
Definition: PhysicsEntity.qc:1081
nonvirtual bool IsDragEnabled(void)
Returns whether the entity is affected by drag.
Definition: PhysicsEntity.qc:1069
nonvirtual void SetDragCoefficient(float)
Call to set how much drag affects the entity.
Definition: PhysicsEntity.qc:1118
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: PhysicsEntity.qc:116
nonvirtual void ApplyTorqueCenter(vector)
Call to apply torque (angular velocity vector) to the center of the entity.
Definition: PhysicsEntity.qc:934
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: PhysicsEntity.qc:448
nonvirtual float GetAngularDamping(void)
Returns the angular damping of the entity.
Definition: PhysicsEntity.qc:981
nonvirtual float GetInertia(void)
Returns the inertia modifier of this entity.
Definition: PhysicsEntity.qc:1003
nonvirtual void SetAngleDragCoefficient(float)
Call to set the amount of rotational drag the entity experiences.
Definition: PhysicsEntity.qc:1099
nonvirtual float GetInvInertia(void)
Returns 1 divided by the angular inertia of this entity.
Definition: PhysicsEntity.qc:1009
virtual void Death(entity, entity, int, vector, vector, int)
Called when the health is equal or below 0.
Definition: PhysicsEntity.qc:732
nonvirtual float CalculateImpactDamage(int, int)
Called by the physics routine to figure out the impact damage.
Definition: PhysicsEntity.qc:416
nonvirtual void EnableGravity(bool)
Call to set whether the entity should be affected by gravity.
Definition: PhysicsEntity.qc:958
nonvirtual void Wake(void)
Call to enable physics simulation on this entity.
Definition: PhysicsEntity.qc:1165
nonvirtual void EnableMotion(bool)
Call to set whether the entity should be able to move.
Definition: PhysicsEntity.qc:965
nonvirtual void ApplyForceOffset(vector, vector)
Call to apply force (absolute velocity vector) to an absolute position on the entity.
Definition: PhysicsEntity.qc:915
virtual void EvaluateEntity(void)
Run each tic after physics are run to determine if we need to send updates over the network.
Definition: PhysicsEntity.qc:150
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: PhysicsEntity.qc:842
nonvirtual void EnableDrag(bool)
Call to set whether the entity should be affected by drag.
Definition: PhysicsEntity.qc:952
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: PhysicsEntity.qc:756
nonvirtual bool IsGravityEnabled(void)
Returns whether the entity is affected by gravity.
Definition: PhysicsEntity.qc:1075
nonvirtual bool IsAsleep(void)
Returns whether the entity is at rest and not moving.
Definition: PhysicsEntity.qc:1057
nonvirtual bool IsMoveable(void)
Returns whether the entity is able to move.
Definition: PhysicsEntity.qc:1087
This entity represents an ncRenderableEntity with interactive surface properties.
Definition: SurfacePropEntity.h:70
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37
noref bool isPhysics
Definition: PhysicsEntity.h:240
@ PHYSM_BOX
Definition: PhysicsEntity.h:90
@ PHYSM_SPHERE
Definition: PhysicsEntity.h:91
@ PHYSM_CYLINDER
Definition: PhysicsEntity.h:94
@ PHYSM_TRIMESH
Definition: PhysicsEntity.h:93
@ PHYSM_CAPSULE
Definition: PhysicsEntity.h:92