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);
114 nonvirtual ncSoundDict GetDefSound(string);
115
117 nonvirtual float GetSubDefAct(string, string);
119 nonvirtual string GetSubDefString(string, string);
121 nonvirtual float GetSubDefFloat(string, string);
123 nonvirtual bool GetSubDefBool(string, string);
125 nonvirtual int GetSubDefInt(string, string);
127 nonvirtual vector GetSubDefVector(string, string);
129 nonvirtual ncSoundDict GetSubDefSound(string, string);
130
132 nonvirtual void Destroy(void);
134 virtual void OnRemoveEntity(void);
135
137 nonvirtual void Relink(void);
138
141 nonvirtual float GetNextThinkTime(void);
143 nonvirtual bool IsThinking(void);
145 nonvirtual void ReleaseThink(void);
147 nonvirtual void ThinkBusy(float);
148
151 nonvirtual void SetThink(void());
155 nonvirtual void SetNextThink(float);
160 nonvirtual void ScheduleThink(void(void),float);
161
162#ifdef SERVER
166 virtual void Save(float);
167
171 virtual void Restore(string,string);
172
174 virtual void RestoreComplete(void);
175
177 virtual void TransitionComplete(void);
178
180 virtual void Input(entity,string,string);
181
182 /* helper functions to allocate outputs */
184 nonvirtual void UseOutput(entity,string);
190 nonvirtual string PrepareOutput(string,string);
191
197 nonvirtual string CreateOutput(string);
198
201 nonvirtual bool CheckOutput(string);
202
204 virtual void ParentUpdate(void);
205
206 /* save game related methods */
208 nonvirtual void SaveFloat(float,string,float);
210 nonvirtual void SaveInt(float,string,int);
212 nonvirtual void SaveString(float,string,string);
214 nonvirtual void SaveVector(float,string,vector);
216 nonvirtual void SaveBool(float,string,bool);
218 nonvirtual void SaveEntity(float,string,entity);
220 nonvirtual void SetSendFlags(float);
221#endif
222
223#ifdef CLIENT
225 virtual void _ReceiveComplete(float, float);
226#endif
227
229 nonvirtual float GetSpawnFloat(string);
231 nonvirtual int GetSpawnInt(string);
233 nonvirtual string GetSpawnString(string);
235 nonvirtual vector GetSpawnVector(string);
237 nonvirtual bool GetSpawnBool(string);
241 nonvirtual entity GetSpawnEntity(string, entity);
242
243 nonvirtual ncSoundDict GetSpawnSound(string keyName);
244
245 /* load game/spawn helper functions */
247 nonvirtual float ReadFloat(string);
249 nonvirtual int ReadInt(string);
251 nonvirtual string ReadString(string);
253 nonvirtual vector ReadVector(string);
255 nonvirtual bool ReadBool(string);
257 nonvirtual entity ReadEntity(string);
258
264 nonvirtual float GetTime(void);
265
266 /* save game related methods */
268 nonvirtual void DebugFloat(string,float);
270 nonvirtual void DebugInt(string,int);
272 nonvirtual void DebugString(string,string);
274 nonvirtual void DebugVector(string,vector);
276 nonvirtual void DebugBool(string,bool);
278 nonvirtual void DebugEntity(string,entity);
279
280private:
281 string m_rawSpawnData;
282#ifdef SERVER
283 string m_outputOnSpawn;
284 string m_outputOnKilled;
285 string m_outputOnTrigger;
286 string m_outputOnUser1;
287 string m_outputOnUser2;
288 string m_outputOnUser3;
289 string m_outputOnUser4;
290
291 /* entityDef powered modelevent callbacks */
292 string m_modelEventCallbacks;
293 string m_gameModeFilter;
294#endif
295};
296
297#define CREATE_OUTPUT(x) if (STRING_SET(x)) { \
298 x = CreateOutput(x); \
299 }
300
301.bool _mapspawned;
302
303#define CGENT_LOG imageToConsole("gfx/icon16/brick", ICN_SIZE, "Client Entity Log")
304#define CGENT_WARNING imageToConsole("gfx/icon16/brick_error", ICN_SIZE, "Client Entity Warning")
305#define CGENT_ERROR imageToConsole("gfx/icon16/brick_delete", ICN_SIZE, "Client Entity Error")
306
307#define SVENT_LOG imageToConsole("gfx/icon16/brick", ICN_SIZE, "Server Entity Log")
308#define SVENT_WARNING imageToConsole("gfx/icon16/brick_error", ICN_SIZE, "Server Entity Warning")
309#define SVENT_ERROR imageToConsole("gfx/icon16/brick_delete", ICN_SIZE, "Server Entity Error")
310
311void
312_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
313{
314#ifdef SERVER
315 if (autocvar_g_logTimestamps)
316 print(sprintf("%s ^9%f ^7%s (%d)^7: %s\n", SVENT_LOG, time, className, edictNum, warnMessage));
317 else
318 print(sprintf("%s ^7%s (%d)^7: %s\n", SVENT_LOG, className, edictNum, warnMessage));
319#endif
320#ifdef CLIENT
321 if (autocvar_g_logTimestamps)
322 print(sprintf("%s ^9%f ^7%s (%d)^7: %s\n", CGENT_LOG, time, className, edictNum, warnMessage));
323 else
324 print(sprintf("%s ^7%s (%d)^7: %s\n", CGENT_LOG, className, edictNum, warnMessage));
325#endif
326}
327
328void
329_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
330{
331#ifdef SERVER
332 if (autocvar_g_logTimestamps)
333 print(sprintf("%s ^9%f ^3%s (%d)^1: %s\n", SVENT_WARNING, time, functionName, edictNum, warnMessage));
334 else
335 print(sprintf("%s ^3%s (%d)^1: %s\n", SVENT_WARNING, functionName, edictNum, warnMessage));
336#endif
337#ifdef CLIENT
338 if (autocvar_g_logTimestamps)
339 print(sprintf("%s ^9%f ^3%s (%d)^1: %s\n", CGENT_WARNING, time, functionName, edictNum, warnMessage));
340 else
341 print(sprintf("%s ^3%s (%d)^1: %s\n", CGENT_WARNING, functionName, edictNum, warnMessage));
342#endif
343}
344
345void
346_NSEntError(string className, string functionName, float edictNum, string warnMessage)
347{
348#ifdef SERVER
349 if (autocvar_g_logTimestamps)
350 print(sprintf("%s ^9%f ^1%s (id: %d)^1: %s\n", SVENT_ERROR, time, functionName, edictNum, warnMessage));
351 else
352 print(sprintf("%s ^1%s (id: %d)^1: %s\n", SVENT_ERROR, functionName, edictNum, warnMessage));
353#endif
354#ifdef CLIENT
355 if (autocvar_g_logTimestamps)
356 print(sprintf("%s ^9%f ^1%s (id: %d)^1: %s\n", CGENT_ERROR, time, functionName, edictNum, warnMessage));
357 else
358 print(sprintf("%s ^1%s (id: %d)^1: %s\n", CGENT_ERROR, functionName, edictNum, warnMessage));
359#endif
360}
361
366#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
367
372#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
373
378#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:102
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:205
nonvirtual bool ReadBool(string)
Returns a boolean value from a string.
Definition: IO.qc:235
nonvirtual float GetDefAct(string)
Looks up a sequence from an act of a key within this entity's declaration.
Definition: IO.qc:179
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: IO.qc:419
nonvirtual void DebugEntity(string, entity)
Debug print for a given entity.
Definition: IO.qc:701
nonvirtual void ScheduleThink(void(void), float)
Schedules a think timer.
Definition: IO.qc:758
nonvirtual void DebugString(string, string)
Debug print for a given string.
Definition: IO.qc:691
nonvirtual int GetDefInt(string)
Looks up the integer value of a key within this entity's declaration.
Definition: IO.qc:166
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: IO.qc:364
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:56
nonvirtual string GetDefString(string)
Looks up the string value of a key within this entity's declaration.
Definition: IO.qc:142
nonvirtual void DebugBool(string, bool)
Debug print for a given boolean.
Definition: IO.qc:676
nonvirtual string ReadString(string)
Returns a string value from a string (with error checking).
Definition: IO.qc:256
nonvirtual void SetThink(void())
Overrides the Think function of the entity.
Definition: IO.qc:735
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: IO.qc:604
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:173
nonvirtual float GetSpawnFloat(string)
Returns the floating-point value of a named key in the entity's spawn data.
Definition: IO.qc:290
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: IO.qc:573
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: IO.qc:67
nonvirtual float GetDefFloat(string)
Looks up the floating-point value of a key within this entity's declaration.
Definition: IO.qc:154
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: IO.qc:509
nonvirtual void Relink(void)
Relink the entity against the world.
Definition: IO.qc:597
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: IO.qc:485
nonvirtual bool GetSpawnBool(string)
Returns the boolean value of a named key in the entity's spawn data.
Definition: IO.qc:284
nonvirtual void SetSendFlags(float)
Overrides the field that's used to determine which information should be networked.
Definition: IO.qc:579
virtual void _ReceiveComplete(float, float)
Called once ReceiveEntity has done its job.
Definition: IO.qc:590
nonvirtual vector GetSpawnVector(string)
Returns the vector value of a named key in the entity's spawn data.
Definition: IO.qc:323
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: IO.qc:491
nonvirtual void SetNextThink(float)
Sets the next think timer of the entity.
Definition: IO.qc:741
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: IO.qc:669
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: IO.qc:503
nonvirtual bool GetDefBool(string)
Looks up the boolean value of a key within this entity's declaration.
Definition: IO.qc:160
nonvirtual void DebugFloat(string, float)
Debug print for a given float.
Definition: IO.qc:681
virtual void ReloadCachedAttributes(void)
Shared: Called on launch/reload to read variables from defaults.
Definition: IO.qc:62
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:217
nonvirtual ncSoundDict GetSubDefSound(string, string)
Like GetDefSound, but queries a specified def, falling back to reading from our own if it's not defin...
Definition: IO.qc:223
nonvirtual void ThinkBusy(float)
When called, will make the entity think busy for the specified amount of time.
Definition: IO.qc:726
nonvirtual vector ReadVector(string)
Returns a vector from a string.
Definition: IO.qc:265
nonvirtual void DebugVector(string, vector)
Debug print for a given vector.
Definition: IO.qc:696
nonvirtual ncSoundDict GetSpawnSound(string keyName)
Definition: IO.qc:317
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: IO.qc:479
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:199
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:185
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: IO.qc:442
nonvirtual ncSoundDict GetDefSound(string)
Looks up the sound dictionary of a key within this entity's declaration.
Definition: IO.qc:229
nonvirtual float GetNextThinkTime(void)
Returns an absolute value of when the entity will be think again.
Definition: IO.qc:707
nonvirtual entity GetSpawnEntity(string, entity)
Returns an entity of a named key in the entity's spawn data.
Definition: IO.qc:329
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: IO.qc:432
nonvirtual entity ReadEntity(string)
Reads an entity id from a string and returns the entity.
Definition: IO.qc:272
nonvirtual void Destroy(void)
When called, will remove the entity from the game entirely.
Definition: IO.qc:107
nonvirtual vector GetDefVector(string)
Looks up the vector value of a key within this entity's declaration.
Definition: IO.qc:148
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:713
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: IO.qc:563
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: IO.qc:568
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: IO.qc:497
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: IO.qc:518
nonvirtual string GetSpawnString(string)
Returns the string value of a named key in the entity's spawn data.
Definition: IO.qc:302
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:211
nonvirtual void ReleaseThink(void)
When called, will unset anything related to ongoing think operations.
Definition: IO.qc:719
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: IO.qc:338
nonvirtual void DebugInt(string, int)
Debug print for a given integer.
Definition: IO.qc:686
nonvirtual int ReadInt(string)
Returns an integer value from a string.
Definition: IO.qc:249
nonvirtual float ReadFloat(string)
Returns a floating point value from a string value.
Definition: IO.qc:242
nonvirtual int GetSpawnInt(string)
Returns the integer value of a named key in the entity's spawn data.
Definition: IO.qc:296
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition: IO.qc:532
Dictionary for sound effect definition.
Definition: SoundDict.h:39