Nuclide
Software Development Kit for id Technology (BETA)
IO.h
1/*
2 * Copyright (c) 2016-2024 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
77class ncIO
78{
79public:
80 void ncIO(void);
81
86 virtual void Spawned(void);
87
90 virtual void Respawn(void);
91
93 virtual void ReloadCachedAttributes(void);
94
98 virtual void SpawnKey(string,string);
99
100 /* EntityDef interactions */
102 nonvirtual float GetDefAct(string);
104 nonvirtual string GetDefString(string);
106 nonvirtual float GetDefFloat(string);
108 nonvirtual bool GetDefBool(string);
110 nonvirtual int GetDefInt(string);
112 nonvirtual vector GetDefVector(string);
113
115 nonvirtual float GetSubDefAct(string, string);
117 nonvirtual string GetSubDefString(string, string);
119 nonvirtual float GetSubDefFloat(string, string);
121 nonvirtual bool GetSubDefBool(string, string);
123 nonvirtual int GetSubDefInt(string, string);
125 nonvirtual vector GetSubDefVector(string, string);
126
128 nonvirtual void Destroy(void);
130 virtual void OnRemoveEntity(void);
131
133 nonvirtual void Relink(void);
134
137 nonvirtual float GetNextThinkTime(void);
139 nonvirtual bool IsThinking(void);
141 nonvirtual void ReleaseThink(void);
143 nonvirtual void ThinkBusy(float);
144
147 nonvirtual void SetThink(void());
151 nonvirtual void SetNextThink(float);
156 nonvirtual void ScheduleThink(void(void),float);
157
158#ifdef SERVER
162 virtual void Save(float);
163
167 virtual void Restore(string,string);
168
170 virtual void RestoreComplete(void);
171
173 virtual void TransitionComplete(void);
174
176 virtual void Input(entity,string,string);
177
178 /* helper functions to allocate outputs */
180 nonvirtual void UseOutput(entity,string);
186 nonvirtual string PrepareOutput(string,string);
187
193 nonvirtual string CreateOutput(string);
194
197 nonvirtual bool CheckOutput(string);
198
200 virtual void ParentUpdate(void);
201
202 /* save game related methods */
204 nonvirtual void SaveFloat(float,string,float);
206 nonvirtual void SaveInt(float,string,int);
208 nonvirtual void SaveString(float,string,string);
210 nonvirtual void SaveVector(float,string,vector);
212 nonvirtual void SaveBool(float,string,bool);
214 nonvirtual void SaveEntity(float,string,entity);
216 nonvirtual void SetSendFlags(float);
217#endif
218
219#ifdef CLIENT
221 virtual void _ReceiveComplete(float, float);
222#endif
223
225 nonvirtual float GetSpawnFloat(string);
227 nonvirtual int GetSpawnInt(string);
229 nonvirtual string GetSpawnString(string);
231 nonvirtual vector GetSpawnVector(string);
233 nonvirtual bool GetSpawnBool(string);
237 nonvirtual entity GetSpawnEntity(string, entity);
238
239 /* load game/spawn helper functions */
241 nonvirtual float ReadFloat(string);
243 nonvirtual int ReadInt(string);
245 nonvirtual string ReadString(string);
247 nonvirtual vector ReadVector(string);
249 nonvirtual bool ReadBool(string);
251 nonvirtual entity ReadEntity(string);
252
258 nonvirtual float GetTime(void);
259
260 /* save game related methods */
262 nonvirtual void DebugFloat(string,float);
264 nonvirtual void DebugInt(string,int);
266 nonvirtual void DebugString(string,string);
268 nonvirtual void DebugVector(string,vector);
270 nonvirtual void DebugBool(string,bool);
272 nonvirtual void DebugEntity(string,entity);
273
274private:
275 string m_rawSpawnData;
276#ifdef SERVER
277 string m_outputOnSpawn;
278 string m_outputOnKilled;
279 string m_outputOnTrigger;
280 string m_outputOnUser1;
281 string m_outputOnUser2;
282 string m_outputOnUser3;
283 string m_outputOnUser4;
284
285 /* entityDef powered modelevent callbacks */
286 string m_modelEventCallbacks;
287#endif
288};
289
290#define CREATE_OUTPUT(x) if (STRING_SET(x)) { \
291 x = CreateOutput(x); \
292 }
293
294.bool _mapspawned;
295
296#define CGENT_LOG imageToConsole("gfx/icon16/brick", ICN_SIZE, "Client Entity Log")
297#define CGENT_WARNING imageToConsole("gfx/icon16/brick_error", ICN_SIZE, "Client Entity Warning")
298#define CGENT_ERROR imageToConsole("gfx/icon16/brick_delete", ICN_SIZE, "Client Entity Error")
299
300#define SVENT_LOG imageToConsole("gfx/icon16/brick", ICN_SIZE, "Server Entity Log")
301#define SVENT_WARNING imageToConsole("gfx/icon16/brick_error", ICN_SIZE, "Server Entity Warning")
302#define SVENT_ERROR imageToConsole("gfx/icon16/brick_delete", ICN_SIZE, "Server Entity Error")
303
304void
305_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
306{
307#ifdef SERVER
308 if (autocvar_g_logTimestamps)
309 print(sprintf("%s ^9%f ^7%s (%d)^7: %s\n", SVENT_LOG, time, className, edictNum, warnMessage));
310 else
311 print(sprintf("%s ^7%s (%d)^7: %s\n", SVENT_LOG, className, edictNum, warnMessage));
312#endif
313#ifdef CLIENT
314 if (autocvar_g_logTimestamps)
315 print(sprintf("%s ^9%f ^7%s (%d)^7: %s\n", CGENT_LOG, time, className, edictNum, warnMessage));
316 else
317 print(sprintf("%s ^7%s (%d)^7: %s\n", CGENT_LOG, className, edictNum, warnMessage));
318#endif
319}
320
321void
322_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
323{
324#ifdef SERVER
325 if (autocvar_g_logTimestamps)
326 print(sprintf("%s ^9%f ^3%s (%d)^7: %s\n", SVENT_WARNING, time, functionName, edictNum, warnMessage));
327 else
328 print(sprintf("%s ^3%s (%d)^7: %s\n", SVENT_WARNING, functionName, edictNum, warnMessage));
329#endif
330#ifdef CLIENT
331 if (autocvar_g_logTimestamps)
332 print(sprintf("%s ^9%f ^3%s (%d)^7: %s\n", CGENT_WARNING, time, functionName, edictNum, warnMessage));
333 else
334 print(sprintf("%s ^3%s (%d)^7: %s\n", CGENT_WARNING, functionName, edictNum, warnMessage));
335#endif
336}
337
338void
339_NSEntError(string className, string functionName, float edictNum, string warnMessage)
340{
341#ifdef SERVER
342 if (autocvar_g_logTimestamps)
343 print(sprintf("%s ^9%f ^1%s (id: %d)^7: %s\n", SVENT_ERROR, time, functionName, edictNum, warnMessage));
344 else
345 print(sprintf("%s ^1%s (id: %d)^7: %s\n", SVENT_ERROR, functionName, edictNum, warnMessage));
346#endif
347#ifdef CLIENT
348 if (autocvar_g_logTimestamps)
349 print(sprintf("%s ^9%f ^1%s (id: %d)^7: %s\n", CGENT_ERROR, time, functionName, edictNum, warnMessage));
350 else
351 print(sprintf("%s ^1%s (id: %d)^7: %s\n", CGENT_ERROR, functionName, edictNum, warnMessage));
352#endif
353}
354
359#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
360
365#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
366
371#define EntError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
This class is responsible for handling core entity functionality.
Definition: IO.h:78
virtual void OnRemoveEntity(void)
Handles what happens before the entity gets removed from the client game.
Definition: IO.qc:89
nonvirtual float GetSubDefFloat(string, string)
Like GetDefFloat, but queries a specified def, falling back to reading from our own if it's not defin...
Definition: IO.qc:192
nonvirtual bool ReadBool(string)
Returns a boolean value from a string.
Definition: IO.qc:211
nonvirtual float GetDefAct(string)
Looks up a sequence from an act of a key within this entity's declaration.
Definition: IO.qc:166
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: IO.qc:388
nonvirtual void DebugEntity(string, entity)
Debug print for a given entity.
Definition: IO.qc:668
nonvirtual void ScheduleThink(void(void), float)
Schedules a think timer.
Definition: IO.qc:725
nonvirtual void DebugString(string, string)
Debug print for a given string.
Definition: IO.qc:658
nonvirtual int GetDefInt(string)
Looks up the integer value of a key within this entity's declaration.
Definition: IO.qc:153
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: IO.qc:333
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: IO.qc:52
nonvirtual string GetDefString(string)
Looks up the string value of a key within this entity's declaration.
Definition: IO.qc:129
nonvirtual void DebugBool(string, bool)
Debug print for a given boolean.
Definition: IO.qc:643
nonvirtual string ReadString(string)
Returns a string value from a string (with error checking).
Definition: IO.qc:232
nonvirtual void SetThink(void())
Overrides the Think function of the entity.
Definition: IO.qc:702
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: IO.qc:574
nonvirtual float GetSubDefAct(string, string)
Like GetDefAct, but queries a specified def, falling back to reading from our own if it's not defined...
Definition: IO.qc:160
nonvirtual float GetSpawnFloat(string)
Returns the floating-point value of a named key in the entity's spawn data.
Definition: IO.qc:266
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: IO.qc:542
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: IO.qc:63
nonvirtual float GetDefFloat(string)
Looks up the floating-point value of a key within this entity's declaration.
Definition: IO.qc:141
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: IO.qc:478
nonvirtual void Relink(void)
Relink the entity against the world.
Definition: IO.qc:567
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: IO.qc:454
nonvirtual bool GetSpawnBool(string)
Returns the boolean value of a named key in the entity's spawn data.
Definition: IO.qc:260
nonvirtual void SetSendFlags(float)
Overrides the field that's used to determine which information should be networked.
Definition: IO.qc:548
virtual void _ReceiveComplete(float, float)
Called once ReceiveEntity has done its job.
Definition: IO.qc:559
nonvirtual vector GetSpawnVector(string)
Returns the vector value of a named key in the entity's spawn data.
Definition: IO.qc:293
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: IO.qc:460
nonvirtual void SetNextThink(float)
Sets the next think timer of the entity.
Definition: IO.qc:708
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: IO.qc:636
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: IO.qc:472
nonvirtual bool GetDefBool(string)
Looks up the boolean value of a key within this entity's declaration.
Definition: IO.qc:147
nonvirtual void DebugFloat(string, float)
Debug print for a given float.
Definition: IO.qc:648
virtual void ReloadCachedAttributes(void)
Shared: Called on launch/reload to read variables from defaults.
Definition: IO.qc:58
nonvirtual int GetSubDefInt(string, string)
Like GetDefInt, but queries a specified def, falling back to reading from our own if it's not defined...
Definition: IO.qc:204
nonvirtual void ThinkBusy(float)
When called, will make the entity think busy for the specified amount of time.
Definition: IO.qc:693
nonvirtual vector ReadVector(string)
Returns a vector from a string.
Definition: IO.qc:241
nonvirtual void DebugVector(string, vector)
Debug print for a given vector.
Definition: IO.qc:663
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: IO.qc:448
nonvirtual vector GetSubDefVector(string, string)
Like GetDefVector, but queries a specified def, falling back to reading from our own if it's not defi...
Definition: IO.qc:186
nonvirtual string GetSubDefString(string, string)
Like GetDefString, but queries a specified def, falling back to reading from our own if it's not defi...
Definition: IO.qc:172
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: IO.qc:411
nonvirtual float GetNextThinkTime(void)
Returns an absolute value of when the entity will be think again.
Definition: IO.qc:674
nonvirtual entity GetSpawnEntity(string, entity)
Returns an entity of a named key in the entity's spawn data.
Definition: IO.qc:299
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: IO.qc:401
nonvirtual entity ReadEntity(string)
Reads an entity id from a string and returns the entity.
Definition: IO.qc:248
nonvirtual void Destroy(void)
When called, will remove the entity from the game entirely.
Definition: IO.qc:94
nonvirtual vector GetDefVector(string)
Looks up the integer value of a key within this entity's declaration.
Definition: IO.qc:135
void ncIO(void)
Definition: IO.qc:18
nonvirtual bool IsThinking(void)
Returns whether or not we're currently expecting to think any time soon.
Definition: IO.qc:680
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: IO.qc:532
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: IO.qc:537
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: IO.qc:466
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: IO.qc:487
nonvirtual string GetSpawnString(string)
Returns the string value of a named key in the entity's spawn data.
Definition: IO.qc:278
nonvirtual bool GetSubDefBool(string, string)
Like GetDefBool, but queries a specified def, falling back to reading from our own if it's not define...
Definition: IO.qc:198
nonvirtual void ReleaseThink(void)
When called, will unset anything related to ongoing think operations.
Definition: IO.qc:686
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: IO.qc:308
nonvirtual void DebugInt(string, int)
Debug print for a given integer.
Definition: IO.qc:653
nonvirtual int ReadInt(string)
Returns an integer value from a string.
Definition: IO.qc:225
nonvirtual float ReadFloat(string)
Returns a floating point value from a string value.
Definition: IO.qc:218
nonvirtual int GetSpawnInt(string)
Returns the integer value of a named key in the entity's spawn data.
Definition: IO.qc:272
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: IO.qc:501