1 /*
2 ===========================================================================
3 Copyright (C) 2005 - 2015, ioquake3 contributors
4 Copyright (C) 2013 - 2015, OpenJK contributors
5 
6 This file is part of the OpenJK source code.
7 
8 OpenJK is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
19 ===========================================================================
20 */
21 
22 #pragma once
23 
24 #include "qcommon/q_shared.h"
25 
26 #define MAXPRINTMSG 4096
27 
28 typedef enum netadrtype_s
29 {
30 	NA_BAD = 0,					// an address lookup failed
31 	NA_BOT,
32 	NA_LOOPBACK,
33 	NA_BROADCAST,
34 	NA_IP
35 } netadrtype_t;
36 
37 typedef struct netadr_s
38 {
39 	netadrtype_t	type;
40 	union {
41 		byte		ip[4];
42 		int32_t		ipi;
43 	};
44 	uint16_t	port;
45 } netadr_t;
46 
47 /*
48 ==============================================================
49 
50 NON-PORTABLE SYSTEM SERVICES
51 
52 ==============================================================
53 */
54 
55 typedef enum {
56 	AXIS_SIDE,
57 	AXIS_FORWARD,
58 	AXIS_UP,
59 	AXIS_ROLL,
60 	AXIS_YAW,
61 	AXIS_PITCH,
62 	MAX_JOYSTICK_AXIS
63 } joystickAxis_t;
64 
65 typedef enum {
66   // bk001129 - make sure SE_NONE is zero
67 	SE_NONE = 0,	// evTime is still valid
68 	SE_KEY,		// evValue is a key code, evValue2 is the down flag
69 	SE_CHAR,	// evValue is an ascii char
70 	SE_MOUSE,	// evValue and evValue2 are reletive signed x / y moves
71 	SE_JOYSTICK_AXIS,	// evValue is an axis number and evValue2 is the current state (-127 to 127)
72 	SE_CONSOLE,	// evPtr is a char*
73 	SE_MAX
74 } sysEventType_t;
75 
76 typedef struct sysEvent_s {
77 	int				evTime;
78 	sysEventType_t	evType;
79 	int				evValue, evValue2;
80 	int				evPtrLength;	// bytes of data pointed to by evPtr, for journaling
81 	void			*evPtr;			// this must be manually freed if not NULL
82 } sysEvent_t;
83 
84 extern cvar_t *com_minimized;
85 extern cvar_t *com_unfocused;
86 extern cvar_t *com_maxfps;
87 extern cvar_t *com_maxfpsMinimized;
88 extern cvar_t *com_maxfpsUnfocused;
89 
90 sysEvent_t	Sys_GetEvent( void );
91 
92 void	Sys_Init (void);
93 
94 // general development dll loading for virtual machine testing
95 typedef void *GetGameAPIProc( void  *);
96 typedef intptr_t QDECL VMMainProc( int, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t );
97 typedef intptr_t QDECL SystemCallProc( intptr_t, ... );
98 typedef void * QDECL GetModuleAPIProc( int, ... );
99 
100 void	*Sys_LoadSPGameDll( const char *name, GetGameAPIProc **GetGameAPI );
101 void	* QDECL Sys_LoadDll(const char *name, qboolean useSystemLib);
102 void	* QDECL Sys_LoadLegacyGameDll( const char *name, VMMainProc **vmMain, SystemCallProc *systemcalls );
103 void	* QDECL Sys_LoadGameDll( const char *name, GetModuleAPIProc **moduleAPI );
104 void	Sys_UnloadDll( void *dllHandle );
105 
106 char	*Sys_GetCurrentUser( void );
107 
108 void	NORETURN QDECL Sys_Error( const char *error, ... );
109 void	NORETURN Sys_Quit (void);
110 char	*Sys_GetClipboardData( void );	// note that this isn't journaled...
111 
112 void	Sys_Print( const char *msg );
113 
114 // Sys_Milliseconds should only be used for profiling purposes,
115 // any game related timing information should come from event timestamps
116 int		Sys_Milliseconds (bool baseTime = false);
117 int		Sys_Milliseconds2(void);
118 void	Sys_Sleep( int msec );
119 
120 extern "C" void	Sys_SnapVector( float *v );
121 
122 bool Sys_RandomBytes( byte *string, int len );
123 
124 void	Sys_SetErrorText( const char *text );
125 
126 void	Sys_SendPacket( int length, const void *data, netadr_t to );
127 
128 qboolean	Sys_StringToAdr( const char *s, netadr_t *a );
129 //Does NOT parse port numbers, only base addresses.
130 
131 qboolean	Sys_IsLANAddress (netadr_t adr);
132 void		Sys_ShowIP(void);
133 
134 qboolean	Sys_Mkdir( const char *path );
135 char	*Sys_Cwd( void );
136 void	Sys_SetDefaultInstallPath(const char *path);
137 char	*Sys_DefaultInstallPath(void);
138 
139 #ifdef MACOS_X
140 char    *Sys_DefaultAppPath(void);
141 #endif
142 
143 char	*Sys_DefaultHomePath(void);
144 const char *Sys_Dirname( char *path );
145 const char *Sys_Basename( char *path );
146 
147 bool Sys_PathCmp( const char *path1, const char *path2 );
148 
149 char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
150 void	Sys_FreeFileList( char **fileList );
151 //rwwRMG - changed to fileList to not conflict with list type
152 
153 time_t Sys_FileTime( const char *path );
154 
155 qboolean Sys_LowPhysicalMemory();
156 
157 void Sys_SetProcessorAffinity( void );
158 
159 typedef enum graphicsApi_e
160 {
161 	GRAPHICS_API_GENERIC,
162 
163 	// Only OpenGL needs special treatment..
164 	GRAPHICS_API_OPENGL,
165 } graphicsApi_t;
166 
167 // Graphics API
168 typedef struct window_s
169 {
170 	void *handle; // OS-dependent window handle
171 	graphicsApi_t api;
172 } window_t;
173 
174 typedef enum glProfile_e
175 {
176 	GLPROFILE_COMPATIBILITY,
177 	GLPROFILE_CORE,
178 	GLPROFILE_ES,
179 } glProfile_t;
180 
181 typedef enum glContextFlag_e
182 {
183 	GLCONTEXT_DEBUG = (1 << 1),
184 } glContextFlag_t;
185 
186 typedef struct windowDesc_s
187 {
188 	graphicsApi_t api;
189 
190 	// Only used if api == GRAPHICS_API_OPENGL
191 	struct gl_
192 	{
193 		int majorVersion;
194 		int minorVersion;
195 		glProfile_t profile;
196 		uint32_t contextFlags;
197 	} gl;
198 } windowDesc_t;
199 
200 typedef struct glconfig_s glconfig_t;
201 window_t	WIN_Init( const windowDesc_t *desc, glconfig_t *glConfig );
202 void		WIN_Present( window_t *window );
203 void		WIN_SetGamma( glconfig_t *glConfig, byte red[256], byte green[256], byte blue[256] );
204 void		WIN_Shutdown( void );
205 void *		WIN_GL_GetProcAddress( const char *proc );
206 qboolean	WIN_GL_ExtensionSupported( const char *extension );
207 
208 uint8_t ConvertUTF32ToExpectedCharset( uint32_t utf32 );
209