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{
28
29private:
30 void NSIO(void);
31
32 virtual void Init(void);
33
34#ifdef SERVER
35 string m_strOnTrigger;
36 string m_strOnUser1;
37 string m_strOnUser2;
38 string m_strOnUser3;
39 string m_strOnUser4;
40
41 /* entityDef powered modelevent callbacks */
42 string m_strModelEventCB;
43#endif
44
45public:
50 virtual void Spawned(void);
51
54 virtual void Respawn(void);
55
59 virtual void SpawnKey(string,string);
60
61#ifdef SERVER
65 virtual void Save(float);
66
70 virtual void Restore(string,string);
71
73 virtual void RestoreComplete(void);
74
76 virtual void TransitionComplete(void);
77
79 virtual void Input(entity,string,string);
80
81 /* helper functions to allocate outputs */
83 nonvirtual void UseOutput(entity,string);
89 nonvirtual string PrepareOutput(string,string);
90
96 nonvirtual string CreateOutput(string);
97
100 nonvirtual bool CheckOutput(string);
101
103 virtual void ParentUpdate(void);
104
105 /* save game related methods */
107 nonvirtual void SaveFloat(float,string,float);
109 nonvirtual void SaveInt(float,string,int);
111 nonvirtual void SaveString(float,string,string);
113 nonvirtual void SaveVector(float,string,vector);
115 nonvirtual void SaveBool(float,string,bool);
117 nonvirtual void SaveEntity(float,string,entity);
118#endif
119
120 /* load game/spawn helper functions */
122 nonvirtual float ReadFloat(string);
124 nonvirtual int ReadInt(string);
126 nonvirtual string ReadString(string);
128 nonvirtual vector ReadVector(string);
130 nonvirtual bool ReadBool(string);
132 nonvirtual entity ReadEntity(string);
133
139 nonvirtual float GetTime(void);
140};
141
143
144void
145_NSEntLog(string className, string functionName, float edictNum, string warnMessage)
146{
148 print(sprintf("^9%f ^7%s (%d)^7: %s\n", time, className, edictNum, warnMessage));
149 else
150 print(sprintf("^7%s (%d)^7: %s\n", className, edictNum, warnMessage));
151}
152
153void
154_NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
155{
157 print(sprintf("^9%f ^3%s (%d)^7: %s\n", time, functionName, edictNum, warnMessage));
158 else
159 print(sprintf("^3%s (%d)^7: %s\n", functionName, edictNum, warnMessage));
160}
161
162void
163_NSEntError(string className, string functionName, float edictNum, string warnMessage)
164{
166 print(sprintf("^9%f ^1%s (id: %d)^7: %s\n", time, functionName, edictNum, warnMessage));
167 else
168 print(sprintf("^1%s (id: %d)^7: %s\n", functionName, edictNum, warnMessage));
169}
174#define EntLog(...) if (autocvar_g_developer) _NSEntLog(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
175
180#define EntWarning(...) _NSEntWarning(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
181
186#define EntError(...) _NSEntError(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
void _NSEntWarning(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:154
void _NSEntError(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:163
void _NSEntLog(string className, string functionName, float edictNum, string warnMessage)
Definition: NSIO.h:145
bool _mapspawned
Definition: NSIO.h:142
This class is responsible for handling core entity functionality.
Definition: NSIO.h:27
nonvirtual void SaveFloat(float, string, float)
Saves a floating point key/value pair to a filehandle.
Definition: NSIO.qc:271
nonvirtual void SaveEntity(float, string, entity)
Saves an entity id key/value pair to a filehandle.
Definition: NSIO.qc:295
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:45
nonvirtual void SaveInt(float, string, int)
Saves a integer key/value pair to a filehandle.
Definition: NSIO.qc:277
nonvirtual vector ReadVector(string)
reads a vector from a string
Definition: NSIO.qc:128
nonvirtual float GetTime(void)
Get the level time the entity finds itself in.
Definition: NSIO.qc:762
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition: NSIO.qc:238
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition: NSIO.qc:85
virtual void Restore(string, string)
Similar to ::SpawnKey but for save-game fields.
Definition: NSIO.qc:406
nonvirtual int ReadInt(string)
reads an integer value from a string
Definition: NSIO.qc:114
nonvirtual string CreateOutput(string)
Called at the end of setting up an entity's output field.
Definition: NSIO.qc:170
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition: NSIO.qc:304
nonvirtual void SaveBool(float, string, bool)
Saves a boolean key/value pair to a filehandle.
Definition: NSIO.qc:265
nonvirtual void UseOutput(entity, string)
Triggers an output field that has been created beforehand.
Definition: NSIO.qc:149
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition: NSIO.qc:700
nonvirtual string PrepareOutput(string, string)
Prepares an output field.
Definition: NSIO.qc:228
nonvirtual float ReadFloat(string)
reads a floating point value from a string
Definition: NSIO.qc:107
nonvirtual void SaveVector(float, string, vector)
Saves a vector key/value pair to a filehandle.
Definition: NSIO.qc:289
nonvirtual bool CheckOutput(string)
Returns whether the Output is ready, or has done firing - not currently scheduled to fire,...
Definition: NSIO.qc:215
nonvirtual string ReadString(string)
reads a string value from a string (with error checking)
Definition: NSIO.qc:121
nonvirtual entity ReadEntity(string)
read an entity id, converted to entity, from a string
Definition: NSIO.qc:135
virtual void TransitionComplete(void)
Called when the entity has successfully completed a level transition.
Definition: NSIO.qc:705
nonvirtual void SaveString(float, string, string)
Saves a string key/value pair to a filehandle.
Definition: NSIO.qc:283
nonvirtual bool ReadBool(string)
reads a boolean value from a string
Definition: NSIO.qc:100
virtual void ParentUpdate(void)
Called when we need to re-align the entity to our parent entity.
Definition: NSIO.qc:710
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition: NSIO.qc:717
float time
Definition: fteextensions.qc:509
vector(vector) normalize
entity() spawn
var bool autocvar_g_developerTimestamps
Definition: global.h:18