1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 
21 // com_public.h -- interfaces for common subsystems
22 
23 #ifndef _COM_PUBLIC_H_
24 #define _COM_PUBLIC_H_
25 
26 /*
27 ==============================================================
28 
29 CMD
30 
31 ==============================================================
32 */
33 
34 typedef enum cbufExecWhen_e {
35 	EXEC_NOW,		// don't return until completed
36 	EXEC_INSERT,	// insert at current position, but don't run yet
37 	EXEC_APPEND		// add to end of the command buffer
38 } cbufExecWhen_t;
39 
40 typedef void ( *xcommand_t )( void );
41 typedef void ( *xmacro_t )( char *, int );
42 typedef const char *( *xgenerator_t )( const char *, int );
43 
44 typedef struct cmdAPI_s {
45 	void 	(*ExecuteText)( cbufExecWhen_t exec_when, const char *text );
46 	int 	(*Argc)( void );
47 	char 	*(*Argv)( int arg );
48 	void 	(*ArgvBuffer)( int arg, char *buffer, int bufferSize );
49 	char 	*(*Args)( void );
50 	void 	(*ArgsBuffer)( char *buffer, int bufferSize );
51 	char 	*(*ArgsFrom)( int from );
52 	void 	(*AddCommand)( const char *cmd_name, xcommand_t function );
53 	void 	(*AddCommandEx)( const char *cmd_name, xcommand_t function, xgenerator_t generator );
54 	void 	(*RemoveCommand)( const char *cmd_name );
55 	xcommand_t	(*FindFunction)( const char *name );
56 	xmacro_t	(*FindMacroFunction)( const char *name );
57 	xgenerator_t	(*FindGenerator)( const char *name );
58 } cmdAPI_t;
59 
60 extern	cmdAPI_t	cmd;
61 
62 /*
63 ==============================================================
64 
65 CVAR
66 
67 ==============================================================
68 */
69 
70 typedef enum {
71 	CVAR_SYSTEM_GENERIC,
72 	CVAR_SYSTEM_GAME,
73 	CVAR_SYSTEM_VIDEO,
74 	CVAR_SYSTEM_SOUND,
75 	CVAR_SYSTEM_INPUT,
76 	CVAR_SYSTEM_NET,
77 	CVAR_SYSTEM_FILES,
78 
79 	CVAR_SYSTEM_MAX
80 } cvarSubsystem_t;
81 
82 #define CVAR_CHEAT			32
83 #define CVAR_PRIVATE		64
84 #define CVAR_ROM			128
85 #define CVAR_LATCHED		256
86 #define CVAR_USER_CREATED	512
87 #define CVAR_DEFAULTS_MIXED	1024
88 
89 #define CVAR_INFOMASK		(CVAR_USERINFO|CVAR_SERVERINFO)
90 #define CVAR_EXTENDED_MASK	(~31)
91 
92 typedef struct cvarAPI_s {
93 	float 	(*VariableValue)( const char *var_name );
94 	int 	(*VariableInteger)( const char *var_name );
95 	char 	*(*VariableString)( const char *var_name );
96 	void 	(*VariableStringBuffer)( const char *var_name, char *buffer, int bufferSize );
97 	cvar_t 	*(*Get)( const char *var_name, const char *var_value, int flags );
98 	cvar_t 	*(*Set)( const char *var_name, const char *value );
99 	void 	(*SetValue)( const char *var_name, float value );
100 	void 	(*SetInteger)( const char *var_name, int value );
101 	void	(*Subsystem)( cvarSubsystem_t subsystem );
102 } cvarAPI_t;
103 
104 extern	cvarAPI_t	cvar;
105 
106 /*
107 ==============================================================
108 
109 FILESYSTEM
110 
111 ==============================================================
112 */
113 
114 #define MAX_LISTED_FILES	4096
115 
116 typedef struct fsSearchInfo_s {
117 	int		fileSize;
118 	qtime_t		timeCreate;
119 	qtime_t		timeModify;
120 } fsFileInfo_t;
121 
122 
123 /* bits 0 - 1, enum */
124 #define		FS_MODE_APPEND			0x00000000
125 #define		FS_MODE_READ			0x00000001
126 #define		FS_MODE_WRITE			0x00000002
127 #define		FS_MODE_RDWR			0x00000003
128 #define		FS_MODE_MASK			0x00000003
129 
130 /* bits 0 - 1, enum */
131 #define		FS_SEARCHDIRS_NO			0x00000000
132 #define		FS_SEARCHDIRS_YES			0x00000001
133 #define		FS_SEARCHDIRS_ONLY			0x00000002
134 #define		FS_SEARCHDIRS_RESERVED		0x00000003
135 #define		FS_SEARCHDIRS_MASK			0x00000003
136 
137 /* bit 2, enum */
138 #define FS_FLUSH_NONE			0x00000000
139 #define FS_FLUSH_SYNC			0x00000004
140 #define	FS_FLUSH_MASK			0x00000004
141 
142 /* bits 3 - 4, enum */
143 #define	FS_TYPE_ANY			0x00000000
144 #define	FS_TYPE_REAL		0x00000008
145 #define	FS_TYPE_PAK			0x00000010
146 #define	FS_TYPE_RESERVED	0x00000018
147 #define	FS_TYPE_MASK		0x00000018
148 
149 /* bits 5 - 6, enum */
150 #define	FS_PATH_ANY			0x00000000
151 #define	FS_PATH_RESERVED	0x00000020
152 #define	FS_PATH_BASE		0x00000040
153 #define	FS_PATH_GAME		0x00000060
154 #define	FS_PATH_MASK		0x00000060
155 
156 /* bits 7 - 10, flag */
157 #define	FS_SEARCH_BYFILTER		0x00000080
158 #define	FS_SEARCH_SAVEPATH		0x00000100
159 #define	FS_SEARCH_EXTRAINFO		0x00000200
160 #define	FS_SEARCH_NOSORT		0x00000400
161 
162 /* bits 7 - 8, flag */
163 #define	FS_FLAG_RAW				0x00000080
164 #define	FS_FLAG_CACHE			0x00000100
165 
166 typedef struct fsAPI_s {
167 	void 	(*FCloseFile)( fileHandle_t f );
168 	int 	(*Read)( void *buffer, int len, fileHandle_t f );
169 	int 	(*Write)( const void *buffer, int len, fileHandle_t f );
170 	int 	(*FOpenFile)( const char *filename, fileHandle_t *f, uint32 mode );
171 	int 	(*Tell)( fileHandle_t f );
172 	int 	(*RawTell)( fileHandle_t f );
173 	int 	(*LoadFile)( const char *path, void **buffer );
174 	int 	(*LoadFileEx)( const char *path, void **buffer, uint32 flags );
175 	void 	(*FreeFile)( void *buffer );
176 	char 	**(*ListFiles)( const char *path, const char *extension, uint32 flags, int *numFiles );
177 	void 	(*FreeFileList)( char **list );
178 } fsAPI_t;
179 
180 extern	fsAPI_t		fs;
181 
182 /*
183 ==============================================================
184 
185 COMMON
186 
187 ==============================================================
188 */
189 
190 #define	MAXPRINTMSG		4096
191 
192 // memory tags to allow dynamic memory to be cleaned up
193 typedef enum memtag_e {
194 	TAG_FREE,				// should have never been set
195 	TAG_STATIC,
196 
197 	TAG_GENERAL,
198 	TAG_CMD,
199 	TAG_CVAR,
200 	TAG_FILESYSTEM,
201 	TAG_RENDERER,
202 	TAG_UI,
203 	TAG_CGAME,
204     TAG_SERVER,
205 	TAG_MVD,
206     TAG_SOUND,
207 	TAG_CMODEL,
208     TAG_LUA,
209 
210 	TAG_MAX,
211 
212 	TAG_GAME	= 765,		// clear when unloading the dll
213 	TAG_LEVEL	= 766		// clear when loading a new level
214 } memtag_t;
215 
216 typedef struct commonAPI_s {
217 	void	( * __attribute__(( noreturn )) Error)
218         ( comErrorType_t code, const char *str );
219 	void	(*Print)( comPrintType_t type, const char *str );
220 
221 	void	*(*TagMalloc)( size_t size, memtag_t tag );
222 	void	*(*Realloc)( void *ptr, size_t size );
223 	void	(*Free)( void *ptr );
224 } commonAPI_t;
225 
226 extern	commonAPI_t	com;
227 
228 /*
229 ==============================================================
230 
231 SYSTEM
232 
233 ==============================================================
234 */
235 
236 typedef struct {
237 	byte	*base;
238 	int		maxsize;
239 	int		cursize;
240     int     mapped;
241 } mempool_t;
242 
243 typedef struct sysAPI_s {
244 	int		(*Milliseconds)( void );
245 	char	*(*GetClipboardData)( void );
246 	void	(*SetClipboardData)( const char *data );
247 	void	(*HunkBegin)( mempool_t *pool, int maxsize );
248 	void	*(*HunkAlloc)( mempool_t *pool, int size );
249 	void	(*HunkEnd)( mempool_t *pool );
250 	void	(*HunkFree)( mempool_t *pool );
251 } sysAPI_t;
252 
253 extern sysAPI_t		sys;
254 
255 /*
256 ==============================================================
257 
258 MODULES
259 
260 ==============================================================
261 */
262 
263 #define MODULES_APIVERSION	311
264 
265 typedef enum moduleQuery_e {
266 	MQ_GETINFO,
267 	MQ_GETCAPS,
268 	MQ_SETUPAPI
269 } moduleQuery_t;
270 
271 typedef enum moduleCapability_e {
272 	MCP_EMPTY			= (0<<0),
273 	MCP_VIDEO_SOFTWARE	= (1<<0),
274 	MCP_VIDEO_OPENGL	= (1<<1),
275 	MCP_REFRESH			= (1<<2),
276 	MCP_SOUND			= (1<<3),
277 	MCP_INPUT			= (1<<4),
278 	MCP_UI				= (1<<5)
279 } moduleCapability_t;
280 
281 typedef struct moduleInfo_s {
282 	// if api_version is different, the dll cannot be used
283 	int		api_version;
284 	char	fullname[MAX_QPATH];
285 	char	author[MAX_QPATH];
286 } moduleInfo_t;
287 
288 // this is the only function actually exported at the linker level
289 typedef void	*(*moduleEntry_t)( int, void * );
290 
291 // API types used in MQ_SETUPAPI query
292 typedef enum api_type_e {
293 	API_CMD,
294 	API_CVAR,
295 	API_FS,
296 	API_COMMON,
297 	API_KEYS,
298 	API_SYSTEM,
299 	API_VIDEO_SOFTWARE,
300 	API_VIDEO_OPENGL,
301 	API_REFRESH,
302 	API_INPUT,
303 	API_UI,
304 	API_CLIENT
305 } api_type_t;
306 
307 // passed along with MQ_SETUPAPI query
308 typedef void	(*APISetupCallback_t)( int, void * );
309 
310 #endif // _COM_PUBLIC_H_
311