Nuclide
Software Development Kit for id Tech
NSIO.h
Go to the documentation of this file.
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
26class NSIO
27{
28public:
29 void NSIO(void);
30
35 virtual void Spawned(void);
36
39 virtual void Respawn(void);
40
44 virtual void SpawnKey(string,string);
45
46 /* EntityDef interactions */
48 nonvirtual float GetDefAct(string);
50 nonvirtual string GetDefString(string);
52 nonvirtual float GetDefFloat(string);
54 nonvirtual bool GetDefBool(string);
56 nonvirtual int GetDefInt(string);
58 nonvirtual vector GetDefVector(string);
59
61 nonvirtual float GetSubDefAct(string, string);
63 nonvirtual string GetSubDefString(string, string);
65 nonvirtual float GetSubDefFloat(string, string);
67 nonvirtual bool GetSubDefBool(string, string);
69 nonvirtual int GetSubDefInt(string, string);
71 nonvirtual vector GetSubDefVector(string, string);
72
73#ifdef SERVER
77 virtual void Save(float);
78
82 virtual void Restore(string,string);
83
85 virtual void RestoreComplete(void);
86
88 virtual void TransitionComplete(void);
89
91 virtual void Input(entity,string,string);
92
93 /* helper functions to allocate outputs */
95 nonvirtual void UseOutput(entity,string);
101 nonvirtual string PrepareOutput(string,string);
102
108 nonvirtual string CreateOutput(string);
109
112 nonvirtual bool CheckOutput(string);
113
115 virtual void ParentUpdate(void);
116
117 /* save game related methods */
119 nonvirtual void SaveFloat(float,string,float);
121 nonvirtual void SaveInt(float,string,int);
123 nonvirtual void SaveString(float,string,string);
125 nonvirtual void SaveVector(float,string,vector);
127 nonvirtual void SaveBool(float,string,bool);
129 nonvirtual void SaveEntity(float,string,entity);
130
131#endif
132
134 nonvirtual float GetSpawnFloat(string);
136 nonvirtual int GetSpawnInt(string);
138 nonvirtual string GetSpawnString(string);
140 nonvirtual vector GetSpawnVector(string);
142 nonvirtual bool GetSpawnBool(string);
146 nonvirtual entity GetSpawnEntity(string, entity);
147
148 /* load game/spawn helper functions */
150 nonvirtual float ReadFloat(string);
152 nonvirtual int ReadInt(string);
154 nonvirtual string ReadString(string);
156 nonvirtual vector ReadVector(string);
158 nonvirtual bool ReadBool(string);
160 nonvirtual entity ReadEntity(string);
161
167 nonvirtual float GetTime(void);
168
169 /* save game related methods */
171 nonvirtual void DebugFloat(string,float);
173 nonvirtual void DebugInt(string,int);
175 nonvirtual void DebugString(string,string);
177 nonvirtual void DebugVector(string,vector);
179 nonvirtual void DebugBool(string,bool);
181 nonvirtual void DebugEntity(string,entity);
182
183private:
184 string m_strSpawnData;
185#ifdef SERVER
186 string m_strOnTrigger;
187 string m_strOnUser1;
188 string m_strOnUser2;
189 string m_strOnUser3;
190 string m_strOnUser4;
191
192 /* entityDef powered modelevent callbacks */
193 string m_strModelEventCB;
194#endif
195};
196
198
199void
200_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
201{
203 print(sprintf("^9%f ^7%s (%d)^7: %s\n", time, className, edictNum, warnMessage));
204 else
205 print(sprintf("^7%s (%d)^7: %s\n", className, edictNum, warnMessage));
206}
207
208void
209_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
210{
212 print(sprintf("^9%f ^3%s (%d)^7: %s\n", time, functionName, edictNum, warnMessage));
213 else
214 print(sprintf("^3%s (%d)^7: %s\n", functionName, edictNum, warnMessage));
215}
216
217void
218_NSEntError(string className, string functionName, float edictNum, string warnMessage)
219{
221 print(sprintf("^9%f ^1%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
222 else
223 print(sprintf("^1%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
224}
229#define EntLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
230
235#define EntWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
236
241#define EntError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
void _NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:209
void _NSEntError(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:218
void _NSEntLog(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:200
bool _mapspawned
Definition: NSIO.h:197
This class is responsible for handling core entity functionality.
Definition: NSIO.h:27
nonvirtual int GetDefInt(string)
Looks up the integer value of a key within this entity's declaration.
Definition: NSIO.qc:102
nonvirtual bool GetDefBool(string)
Looks up the boolean value of a key within this entity's declaration.
Definition: NSIO.qc:96
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: NSIO.qc:394
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: NSIO.qc:154
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: NSIO.qc:418
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: NSIO.qc:160
nonvirtual float GetDefAct(string)
Looks up a sequence from an act of a key within this entity's declaration.
Definition: NSIO.qc:63
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition: NSIO.qc:42
nonvirtual float GetDefFloat(string)
Looks up the floating-point value of a key within this entity's declaration.
Definition: NSIO.qc:90
nonvirtual void DebugVector(string, vector)
Debug print for a given vector.
Definition: NSIO.qc:918
void NSIO(void)
Definition: NSIO.qc:18
nonvirtual vector GetDefVector(string)
Looks up the integer value of a key within this entity's declaration.
Definition: NSIO.qc:84
nonvirtual bool GetSpawnBool(string)
Returns the boolean value of a named key in the entity's spawn data.
Definition: NSIO.qc:224
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: NSIO.qc:400
nonvirtual int GetSpawnInt(string)
Returns the integer value of a named key in the entity's spawn data.
Definition: NSIO.qc:236
nonvirtual float GetSpawnFloat(string)
Returns the floating-point value of a named key in the entity's spawn data.
Definition: NSIO.qc:230
nonvirtual vector ReadVector(string)
Returns a vector from a string.
Definition: NSIO.qc:205
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: NSIO.qc:891
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: NSIO.qc:361
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: NSIO.qc:129
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: NSIO.qc:48
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: NSIO.qc:142
virtual void Restore(string, string)
Similar to NSIO::SpawnKey but for save-game fields.
Definition: NSIO.qc:530
nonvirtual int ReadInt(string)
Returns an integer value from a string.
Definition: NSIO.qc:181
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: NSIO.qc:293
nonvirtual void DebugEntity(string, entity)
Debug print for a given entity.
Definition: NSIO.qc:923
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: NSIO.qc:427
nonvirtual void DebugBool(string, bool)
Debug print for a given boolean.
Definition: NSIO.qc:898
nonvirtual void DebugFloat(string, float)
Debug print for a given float.
Definition: NSIO.qc:903
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: NSIO.qc:388
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: NSIO.qc:272
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: NSIO.qc:827
nonvirtual void DebugString(string, string)
Debug print for a given string.
Definition: NSIO.qc:913
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: NSIO.qc:351
nonvirtual entity GetSpawnEntity(string, entity)
Returns an entity of a named key in the entity's spawn data.
Definition: NSIO.qc:263
nonvirtual float ReadFloat(string)
Returns a floating point value from a string value.
Definition: NSIO.qc:174
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: NSIO.qc:108
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: NSIO.qc:412
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: NSIO.qc:338
nonvirtual string GetDefString(string)
Looks up the string value of a key within this entity's declaration.
Definition: NSIO.qc:78
nonvirtual string ReadString(string)
Returns a string value from a string (with error checking).
Definition: NSIO.qc:188
nonvirtual vector GetSpawnVector(string)
Returns the vector value of a named key in the entity's spawn data.
Definition: NSIO.qc:257
nonvirtual entity ReadEntity(string)
Reads an entity id from a string and returns the entity.
Definition: NSIO.qc:212
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: NSIO.qc:832
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: NSIO.qc:406
nonvirtual void DebugInt(string, int)
Debug print for a given integer.
Definition: NSIO.qc:908
nonvirtual bool ReadBool(string)
Returns a boolean value from a string.
Definition: NSIO.qc:167
nonvirtual string GetSpawnString(string)
Returns the string value of a named key in the entity's spawn data.
Definition: NSIO.qc:242
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: NSIO.qc:148
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: NSIO.qc:837
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: NSIO.qc:844
var bool autocvar_g_logTimestamps
Definition: global.h:17