Nuclide
Software Development Kit for id Technology (BETA)
Loading...
Searching...
No Matches
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;
18var float autocvar_phys_pushscale = 1.0f;
19var float autocvar_phys_impactforcescale = 1.0f;
20var bool autocvar_phys_lowspec = true;
21var float autocvar_phys_spinScale = 1.0f;
22var float autocvar_phys_forceScale = 1.0f;
23
24#ifdef CLIENT
25bool physics_supported(void)
26{
27 return true;
28}
29#endif
30
31#define CG_PHYSICS_LOG imageToConsole("gfx/icon16/hourglass", ICN_SIZE, "Client Physics Log")
32#define SV_PHYSICS_LOG imageToConsole("gfx/icon16/hourglass", ICN_SIZE, "Server Physics Log")
33
34void
35_LogPhysics(string msg)
36{
37#ifdef CLIENT
38 if (autocvar_g_logTimestamps)
39 print(sprintf("%s ^9%f ^7%s\n", CG_PHYSICS_LOG, time, msg));
40 else
41 print(sprintf("%s ^7%s\n", CG_PHYSICS_LOG, msg));
42#endif
43#ifdef SERVER
44 if (autocvar_g_logTimestamps)
45 print(sprintf("%s ^9%f ^7%s\n", SV_PHYSICS_LOG, time, msg));
46 else
47 print(sprintf("%s ^7%s\n", SV_PHYSICS_LOG, msg));
48#endif
49}
50
51#define LogPhysics(...) if (autocvar_phys_developer > 0) _ncLog(sprintf(__VA_ARGS__))
52
53
54#ifdef CLIENT
55var bool autocvar_r_showPhysicsInfo = false;
56#endif
57
58.float damp_linear;
59.float damp_angular;
60.float jointgroup;
61
62
63enumflags
64{
65 BPHY_NODMGPUSH,
66 BPHY_SHARP
67};
68
69
70typedef enumflags
71{
72 PHYENT_CHANGED_ORIGIN_X,
73 PHYENT_CHANGED_ORIGIN_Y,
74 PHYENT_CHANGED_ORIGIN_Z,
75 PHYENT_CHANGED_ANGLES_X,
76 PHYENT_CHANGED_ANGLES_Y,
77 PHYENT_CHANGED_ANGLES_Z,
78 PHYENT_CHANGED_MODELINDEX,
79 PHYENT_CHANGED_SIZE,
80 PHYENT_CHANGED_FLAGS,
81 PHYENT_CHANGED_SOLID,
82 PHYENT_CHANGED_FRAME,
83 PHYENT_CHANGED_SKIN,
84 PHYENT_CHANGED_MOVETYPE,
85 PHYENT_CHANGED_EFFECTS,
86 PHYENT_CHANGED_BODY,
87 PHYENT_CHANGED_SCALE,
88 PHYENT_CHANGED_VELOCITY,
89 PHYENT_CHANGED_RENDERCOLOR,
90 PHYENT_CHANGED_RENDERAMT,
91 PHYENT_CHANGED_RENDERMODE,
92} nsphyricsentity_changed_t;
93
94
111
113enum
114{
120};
121
131{
132public:
133 void ncPhysicsEntity(void);
134
135 /* overrides */
136 virtual void Respawn(void);
137 virtual void SpawnKey(string,string);
138 virtual void SetModel(string);
139
140#ifdef SERVER
141 virtual void Spawned(void);
142 virtual void Pain(entity, entity, int, vector, vector, int);
143 virtual void Death(entity, entity, int, vector, vector, int);
144 virtual void EvaluateEntity(void);
145 virtual float SendEntity(entity,float);
146 virtual void Save(float);
147 virtual void Restore(string,string);
148 virtual void Touch(entity);
149#endif
150
151#ifdef CLIENT
152 virtual void ReceiveEntity(float,float);
153 virtual void postdraw(void);
154#endif
155
156 nonvirtual void _UpdateBuoyancy(void);
157 nonvirtual void _UpdateMass(void);
158
160 nonvirtual void SetFriction(float);
162 nonvirtual float GetFriction(void);
163
165 nonvirtual float CalculateImpactDamage(int,int);
166
167 /* this merely mirrors the GMod API: https://wiki.facepunch.com/gmod/PhysObj */
169 nonvirtual vector AlignAngles(vector, vector);
171 nonvirtual void ApplyForceCenter(vector);
173 nonvirtual void ApplyForceOffset(vector,vector);
175 nonvirtual void ApplyTorqueCenter(vector);
177 nonvirtual void EnableDrag(bool);
179 nonvirtual void EnableGravity(bool);
181 nonvirtual void EnableMotion(bool);
183 nonvirtual float GetLinearDamping(void);
185 nonvirtual float GetAngularDamping(void);
187 nonvirtual float GetEnergy(void);
189 nonvirtual float GetInertia(void);
191 nonvirtual float GetInvInertia(void);
193 nonvirtual float GetInvMass(void);
195 nonvirtual float GetMass(void);
197 nonvirtual vector GetMassCenter(void);
199 nonvirtual float GetRotDamping(void);
201 nonvirtual float GetSpeedDamping(void);
203 nonvirtual float GetSurfaceArea(void);
205 nonvirtual float GetVolume(void);
207 nonvirtual bool IsAsleep(void);
209 nonvirtual bool IsCollisionEnabled(void);
211 nonvirtual bool IsDragEnabled(void);
213 nonvirtual bool IsGravityEnabled(void);
215 nonvirtual bool IsMotionEnabled(void);
217 nonvirtual bool IsMoveable(void);
219 nonvirtual bool IsPenetrating(void);
220
222 nonvirtual void SetAngleDragCoefficient(float);
224 nonvirtual void SetBuoyancyRatio(float);
226 nonvirtual void SetDamping(float, float);
228 nonvirtual void SetDragCoefficient(float);
229
231 nonvirtual void SetInertia(float);
233 nonvirtual void SetMass(float);
234
236 nonvirtual void Wake(void);
238 nonvirtual void Sleep(void);
239
240private:
241 int m_physicsEnabled;
242 int m_desiredGeomtype;
243 int m_surfdataID;
244 int m_physicsFlags;
245 float m_inertiaScale;
246 float m_buoyancyRatio;
247 bool m_physicsGod;
248 float m_overrideVolume;
249 float m_lastTouchTime;
250
251 NETWORKED_FLOAT(m_overrideMass)
252
253 /* performance sanity checks */
254 vector m_lastValidSimPos;
255 vector m_lastvalidSimAng;
256 float m_timeSincePhysicsCheck;
257 float m_spawnPhysTime;
258 bool m_playingFeedbackSound;
259
260 vector m_massCenter;
261
262#ifdef SERVER
263 string m_outputOnDamaged;
264 bool m_pvsSleep;
265 nonvirtual void PVSCheck(void);
266#endif
267};
268
269noref .bool isPhysics;
270 // end of pmove
nonvirtual void ApplyForceCenter(vector)
Call to apply a force (absolute velocity vector) to the center of the entity.
Definition PhysicsEntity.qc:911
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition PhysicsEntity.qc:104
nonvirtual bool IsCollisionEnabled(void)
Returns whether the entity is able to collide with anything.
Definition PhysicsEntity.qc:1078
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:1054
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:990
nonvirtual vector AlignAngles(vector, vector)
Call to align angles of the object to the ones passed.
Definition PhysicsEntity.qc:904
nonvirtual float GetInvMass(void)
Returns 1 divided by the mass of this entity.
Definition PhysicsEntity.qc:1030
nonvirtual float GetMass(void)
Returns the mass of the entity.
Definition PhysicsEntity.qc:1036
nonvirtual float GetRotDamping(void)
Returns the rotational damping of the entity.
Definition PhysicsEntity.qc:1048
nonvirtual float GetSurfaceArea(void)
Returns the surface area of the entity.
Definition PhysicsEntity.qc:1060
nonvirtual float GetEnergy(void)
Returns the linear and rotational kinetic energy combined.
Definition PhysicsEntity.qc:1002
nonvirtual void _UpdateMass(void)
Definition PhysicsEntity.qc:1145
nonvirtual void SetMass(float)
Sets the mass of the entity in kilograms.
Definition PhysicsEntity.qc:1173
nonvirtual void SetBuoyancyRatio(float)
Call to set the buoyancy ratio of the entity.
Definition PhysicsEntity.qc:1120
nonvirtual float GetVolume(void)
Returns the volume of the entity.
Definition PhysicsEntity.qc:1066
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition PhysicsEntity.qc:212
nonvirtual void Sleep(void)
Call to freeze physics simulation on this entity.
Definition PhysicsEntity.qc:1211
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:1156
nonvirtual vector GetMassCenter(void)
Returns the center of mass of the entity.
Definition PhysicsEntity.qc:1042
nonvirtual bool IsPenetrating(void)
Returns whether the entity is penetrating another object.
Definition PhysicsEntity.qc:1108
void ncPhysicsEntity(void)
Definition PhysicsEntity.qc:57
nonvirtual void SetDamping(float, float)
Call to set the linear and angular damping of the entity.
Definition PhysicsEntity.qc:1126
virtual void SetModel(string)
Sets the 3D model representation of the entity from a file path and name.
Definition PhysicsEntity.qc:76
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition PhysicsEntity.qc:94
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:1139
nonvirtual bool IsMotionEnabled(void)
Returns whether the entity is able to move by itself.
Definition PhysicsEntity.qc:1096
nonvirtual bool IsDragEnabled(void)
Returns whether the entity is affected by drag.
Definition PhysicsEntity.qc:1084
nonvirtual void SetDragCoefficient(float)
Call to set how much drag affects the entity.
Definition PhysicsEntity.qc:1133
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition PhysicsEntity.qc:115
nonvirtual void ApplyTorqueCenter(vector)
Call to apply torque (angular velocity vector) to the center of the entity.
Definition PhysicsEntity.qc:949
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:996
nonvirtual float GetInertia(void)
Returns the inertia modifier of this entity.
Definition PhysicsEntity.qc:1018
nonvirtual void SetAngleDragCoefficient(float)
Call to set the amount of rotational drag the entity experiences.
Definition PhysicsEntity.qc:1114
nonvirtual float GetInvInertia(void)
Returns 1 divided by the angular inertia of this entity.
Definition PhysicsEntity.qc:1024
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:973
nonvirtual void Wake(void)
Call to enable physics simulation on this entity.
Definition PhysicsEntity.qc:1180
nonvirtual void EnableMotion(bool)
Call to set whether the entity should be able to move.
Definition PhysicsEntity.qc:980
nonvirtual void ApplyForceOffset(vector, vector)
Call to apply force (absolute velocity vector) to an absolute position on the entity.
Definition PhysicsEntity.qc:930
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:141
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition PhysicsEntity.qc:857
nonvirtual void EnableDrag(bool)
Call to set whether the entity should be affected by drag.
Definition PhysicsEntity.qc:967
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:759
nonvirtual bool IsGravityEnabled(void)
Returns whether the entity is affected by gravity.
Definition PhysicsEntity.qc:1090
nonvirtual bool IsAsleep(void)
Returns whether the entity is at rest and not moving.
Definition PhysicsEntity.qc:1072
nonvirtual bool IsMoveable(void)
Returns whether the entity is able to move.
Definition PhysicsEntity.qc:1102
void ncSurfacePropEntity(void)
Definition SurfacePropEntity.qc:18
noref bool isPhysics
Definition PhysicsEntity.h:269
@ PHYSM_BOX
Entity will explicitly use a box for contact collision detection.
Definition PhysicsEntity.h:115
@ PHYSM_SPHERE
Entity will explicitly use a sphere for contact collision detection.
Definition PhysicsEntity.h:116
@ PHYSM_CYLINDER
Entity will explicitly use a cylinder for contact collision detection.
Definition PhysicsEntity.h:119
@ PHYSM_TRIMESH
Entity will explicitly use a per-poly checks (expensive) for contact collision detection.
Definition PhysicsEntity.h:118
@ PHYSM_CAPSULE
Entity will explicitly use a capsule for contact collision detection.
Definition PhysicsEntity.h:117