Nuclide
Software Development Kit for id Tech
NSPhysicsEntity.h
Go to the documentation of this file.
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;
29
30#ifdef CLIENT
32#endif
33
37
38enum
39{
45};
46
48{
49 BPHY_NODMGPUSH,
50 BPHY_SHARP
51};
52
53
54typedef enumflags
55{
56 PHYENT_CHANGED_ORIGIN_X,
57 PHYENT_CHANGED_ORIGIN_Y,
58 PHYENT_CHANGED_ORIGIN_Z,
59 PHYENT_CHANGED_ANGLES_X,
60 PHYENT_CHANGED_ANGLES_Y,
61 PHYENT_CHANGED_ANGLES_Z,
62 PHYENT_CHANGED_MODELINDEX,
63 PHYENT_CHANGED_SIZE,
64 PHYENT_CHANGED_FLAGS,
65 PHYENT_CHANGED_SOLID,
66 PHYENT_CHANGED_FRAME,
67 PHYENT_CHANGED_SKIN,
68 PHYENT_CHANGED_MOVETYPE,
69 PHYENT_CHANGED_EFFECTS,
70 PHYENT_CHANGED_BODY,
71 PHYENT_CHANGED_SCALE,
72 PHYENT_CHANGED_VELOCITY,
73 PHYENT_CHANGED_RENDERCOLOR,
74 PHYENT_CHANGED_RENDERAMT,
75 PHYENT_CHANGED_RENDERMODE,
76} nsphyricsentity_changed_t;
77
86{
87private:
88 int m_iEnabled;
89 int m_iShape;
90 int m_iMaterial;
91 int m_iFlags;
92 float m_flInertiaScale;
93 float m_flBuoyancyRatio;
94 bool m_bInvincible;
95 float m_flVolume;
96
97 /* performance sanity checks */
98 vector m_vecPrevOrigin;
99 vector m_vecPrevAngles;
100 float m_flCheckTime;
101 PREDICTED_FLOAT(m_flMass)
102
103 virtual void _TouchThink(void);
104
105#ifdef SERVER
106 PREDICTED_VECTOR(m_vecNetAngles)
107
108 string m_strOnDamaged;
109#endif
110
111public:
112 void NSPhysicsEntity(void);
113
114 /* overrides */
115 virtual void Respawn(void);
116 virtual void SpawnKey(string,string);
117#ifdef SERVER
118 virtual void Spawned(void);
119 virtual void Pain(void);
120 virtual void Death(void);
121 virtual void EvaluateEntity(void);
122 virtual float SendEntity(entity,float);
123 virtual void Save(float);
124 virtual void Restore(string,string);
125 virtual void Touch(entity);
126#endif
127#ifdef CLIENT
128 virtual void ReceiveEntity(float,float);
129 virtual void postdraw(void);
130#endif
131
132 nonvirtual void _UpdateBuoyancy(void);
133 nonvirtual void _UpdateMass(void);
134
136 nonvirtual void SetFriction(float);
138 nonvirtual float GetFriction(void);
139
141 nonvirtual float CalculateImpactDamage(int,int);
142
143 /* this merely mirrors the GMod API: https://wiki.facepunch.com/gmod/PhysObj */
144
146 nonvirtual vector AlignAngles(vector, vector);
148 nonvirtual void ApplyForceCenter(vector);
150 nonvirtual void ApplyForceOffset(vector,vector);
152 nonvirtual void ApplyTorqueCenter(vector);
154 nonvirtual void EnableDrag(bool);
156 nonvirtual void EnableGravity(bool);
158 nonvirtual void EnableMotion(bool);
160 nonvirtual float GetLinearDamping(void);
162 nonvirtual float GetAngularDamping(void);
164 nonvirtual float GetEnergy(void);
166 nonvirtual float GetInertia(void);
168 nonvirtual float GetInvInertia(void);
170 nonvirtual float GetInvMass(void);
172 nonvirtual float GetMass(void);
174 nonvirtual vector GetMassCenter(void);
176 nonvirtual float GetRotDamping(void);
178 nonvirtual float GetSpeedDamping(void);
180 nonvirtual float GetSurfaceArea(void);
182 nonvirtual float GetVolume(void);
184 nonvirtual bool IsAsleep(void);
186 nonvirtual bool IsCollisionEnabled(void);
188 nonvirtual bool IsDragEnabled(void);
190 nonvirtual bool IsGravityEnabled(void);
192 nonvirtual bool IsMotionEnabled(void);
194 nonvirtual bool IsMoveable(void);
196 nonvirtual bool IsPenetrating(void);
197
199 nonvirtual void SetAngleDragCoefficient(float);
201 nonvirtual void SetBuoyancyRatio(float);
203 nonvirtual void SetDamping(float, float);
205 nonvirtual void SetDragCoefficient(float);
206
208 nonvirtual void SetInertia(float);
210 nonvirtual void SetMass(float);
211
213 nonvirtual void Wake(void);
215 nonvirtual void Sleep(void);
216};
217
218noref .bool isPhysics;
var float autocvar_phys_impactforcescale
Definition: NSPhysicsEntity.h:28
var bool autocvar_r_showPhysicsInfo
Definition: NSPhysicsEntity.h:31
var bool autocvar_phys_developer
Definition: NSPhysicsEntity.h:17
void _NSPhysics_Log(string msg)
Definition: NSPhysicsEntity.h:19
float damp_angular
Definition: NSPhysicsEntity.h:35
float damp_linear
Definition: NSPhysicsEntity.h:34
var float autocvar_phys_pushscale
Definition: NSPhysicsEntity.h:27
@ PHYSM_BOX
Definition: NSPhysicsEntity.h:40
@ PHYSM_SPHERE
Definition: NSPhysicsEntity.h:41
@ PHYSM_CYLINDER
Definition: NSPhysicsEntity.h:44
@ PHYSM_TRIMESH
Definition: NSPhysicsEntity.h:43
@ PHYSM_CAPSULE
Definition: NSPhysicsEntity.h:42
float jointgroup
Definition: NSPhysicsEntity.h:36
noref bool isPhysics
Definition: NSPhysicsEntity.h:218
enumflags
Definition: NSPhysicsEntity.h:48
This entity class represents physically-simulated entities.
Definition: NSPhysicsEntity.h:86
virtual float SendEntity(entity, float)
Called by the engine whenever we need to send a client an update about this entity.
Definition: NSPhysicsEntity.qc:192
virtual void Touch(entity)
Called whenever we're touching another entity.
Definition: NSPhysicsEntity.qc:422
nonvirtual bool IsDragEnabled(void)
Returns whether the entity is affected by drag.
Definition: NSPhysicsEntity.qc:868
nonvirtual float GetVolume(void)
Returns the volume of the entity.
Definition: NSPhysicsEntity.qc:850
nonvirtual vector AlignAngles(vector, vector)
Call to align angles of the object to the ones passed.
Definition: NSPhysicsEntity.qc:682
nonvirtual float GetRotDamping(void)
Returns the rotational damping of the entity.
Definition: NSPhysicsEntity.qc:832
nonvirtual void SetFriction(float)
Sets the friction multiplier for this entity.
Definition: NSPhysicsEntity.qc:376
virtual void Pain(void)
Called whenever the entity receives damage.
Definition: NSPhysicsEntity.qc:517
nonvirtual bool IsPenetrating(void)
Returns whether the entity is penetrating another object.
Definition: NSPhysicsEntity.qc:892
nonvirtual bool IsGravityEnabled(void)
Returns whether the entity is affected by gravity.
Definition: NSPhysicsEntity.qc:874
nonvirtual void ApplyTorqueCenter(vector)
Call to apply torque (angular velocity vector) to the center of the entity.
Definition: NSPhysicsEntity.qc:735
virtual void postdraw(void)
Client: Run after the rendering of 3D world is complete.
nonvirtual float GetInertia(void)
Returns the inertia modifier of this entity.
Definition: NSPhysicsEntity.qc:802
nonvirtual bool IsMoveable(void)
Returns whether the entity is able to move.
Definition: NSPhysicsEntity.qc:886
nonvirtual float GetInvInertia(void)
Returns 1 divided by the angular inertia of this entity.
Definition: NSPhysicsEntity.qc:808
nonvirtual float GetSurfaceArea(void)
Returns the surface area of the entity.
Definition: NSPhysicsEntity.qc:844
nonvirtual float GetMass(void)
Returns the mass of the entity.
Definition: NSPhysicsEntity.qc:820
nonvirtual bool IsMotionEnabled(void)
Returns whether the entity is able to move by itself.
Definition: NSPhysicsEntity.qc:880
virtual void ReceiveEntity(float, float)
Client: Handles network updates from the server for the associated entity.
nonvirtual float GetEnergy(void)
Returns the linear and rotational kinetic energy combined.
Definition: NSPhysicsEntity.qc:787
nonvirtual void SetAngleDragCoefficient(float)
Call to set the amount of rotational drag the entity experiences.
Definition: NSPhysicsEntity.qc:898
nonvirtual float GetSpeedDamping(void)
Returns the speed damping of the entity.
Definition: NSPhysicsEntity.qc:838
nonvirtual void EnableGravity(bool)
Call to set whether the entity should be affected by gravity.
Definition: NSPhysicsEntity.qc:762
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: NSPhysicsEntity.qc:566
nonvirtual float GetAngularDamping(void)
Returns the angular damping of the entity.
Definition: NSPhysicsEntity.qc:781
nonvirtual void SetMass(float)
Sets the mass of the entity in kilograms.
Definition: NSPhysicsEntity.qc:957
nonvirtual bool IsCollisionEnabled(void)
Returns whether the entity is able to collide with anything.
Definition: NSPhysicsEntity.qc:862
nonvirtual void _UpdateBuoyancy(void)
Definition: NSPhysicsEntity.qc:940
nonvirtual void SetDragCoefficient(float)
Call to set how much drag affects the entity.
Definition: NSPhysicsEntity.qc:917
nonvirtual float GetFriction(void)
Returns the friction multiplayer for this entity.
Definition: NSPhysicsEntity.qc:381
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: NSPhysicsEntity.qc:82
nonvirtual void EnableMotion(bool)
Call to set whether the entity should be able to move.
Definition: NSPhysicsEntity.qc:769
nonvirtual void SetInertia(float)
Sets the angular inertia for this entity.
Definition: NSPhysicsEntity.qc:923
nonvirtual float GetLinearDamping(void)
Returns the linear damping of the entity.
Definition: NSPhysicsEntity.qc:775
nonvirtual vector GetMassCenter(void)
Returns the center of mass of the entity.
Definition: NSPhysicsEntity.qc:826
virtual void Death(void)
Called when the health is equal or below 0.
Definition: NSPhysicsEntity.qc:546
nonvirtual void ApplyForceCenter(vector)
Call to apply a force (absolute velocity vector) to the center of the entity.
Definition: NSPhysicsEntity.qc:689
virtual void Restore(string, string)
Similar to ::SpawnKey but for save-game fields.
Definition: NSPhysicsEntity.qc:94
nonvirtual float GetInvMass(void)
Returns 1 divided by the mass of this entity.
Definition: NSPhysicsEntity.qc:814
nonvirtual void SetDamping(float, float)
Call to set the linear and angular damping of the entity.
Definition: NSPhysicsEntity.qc:910
nonvirtual void Wake(void)
Call to enable physics simulation on this entity.
Definition: NSPhysicsEntity.qc:964
nonvirtual float CalculateImpactDamage(int, int)
Called by the physics routine to figure out the impact damage.
Definition: NSPhysicsEntity.qc:388
void NSPhysicsEntity(void)
Definition: NSPhysicsEntity.qc:25
nonvirtual void ApplyForceOffset(vector, vector)
Call to apply force (absolute velocity vector) to an absolute position on the entity.
Definition: NSPhysicsEntity.qc:710
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: NSPhysicsEntity.qc:72
nonvirtual void Sleep(void)
Call to freeze physics simulation on this entity.
Definition: NSPhysicsEntity.qc:978
virtual void EvaluateEntity(void)
Run each tic after physics are run to determine if we need to send updates over the network.
Definition: NSPhysicsEntity.qc:139
nonvirtual void SetBuoyancyRatio(float)
Call to set the buoyancy ratio of the entity.
Definition: NSPhysicsEntity.qc:904
nonvirtual void EnableDrag(bool)
Call to set whether the entity should be affected by drag.
Definition: NSPhysicsEntity.qc:756
nonvirtual bool IsAsleep(void)
Returns whether the entity is at rest and not moving.
Definition: NSPhysicsEntity.qc:856
nonvirtual void _UpdateMass(void)
Definition: NSPhysicsEntity.qc:929
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: NSPhysicsEntity.qc:635
This entity represents an NSRenderableEntity with interactive surface properties.
Definition: NSSurfacePropEntity.h:49
float time
Definition: fteextensions.qc:509
vector(vector) normalize
entity() spawn
#define PREDICTED_FLOAT(x)
Definition: defs.h:31
#define PREDICTED_VECTOR(x)
Definition: defs.h:32