]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_shared.c
added texmatrix[] to rmeshstate_t and removed R_Mesh_TextureMatrix function
[divverent/darkplaces.git] / sys_shared.c
1
2 #include "quakedef.h"
3 #include <time.h>
4 #ifndef WIN32
5 #include <unistd.h>
6 #include <fcntl.h>
7 #endif
8
9 extern cvar_t   timestamps;
10 extern cvar_t   timeformat;
11
12 static int sys_nostdout = false;
13
14 /* The translation table between the graphical font and plain ASCII  --KB */
15 static char qfont_table[256] = {
16         '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
17         '#',  9,    10,   '#',  ' ',  13,   '.',  '.',
18         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
19         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
20         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
21         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
22         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
23         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
24         '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
25         'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
26         'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
27         'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
28         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
29         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
30         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
31         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<',
32
33         '<',  '=',  '>',  '#',  '#',  '.',  '#',  '#',
34         '#',  '#',  ' ',  '#',  ' ',  '>',  '.',  '.',
35         '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
36         '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
37         ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
38         '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
39         '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
40         '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
41         '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
42         'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
43         'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
44         'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
45         '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
46         'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
47         'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
48         'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
49 };
50
51 static char sys_timestring[128];
52 char *Sys_TimeString(const char *timeformat)
53 {
54         time_t mytime = time(NULL);
55         strftime(sys_timestring, sizeof(sys_timestring), timeformat, localtime(&mytime));
56         return sys_timestring;
57 }
58
59
60 #define MAXPRINTMSG 16384
61
62 void Sys_Print(const char *msg)
63 {
64         unsigned char *p;
65         // String we print
66         char final[MAXPRINTMSG];
67
68         if (sys_nostdout)
69                 return;
70
71         if (timestamps.integer)
72                 snprintf(final, sizeof(final), "%s%s", Sys_TimeString(timeformat.string), msg);
73         else
74                 strncpy(final, msg, sizeof(final));
75
76         // LordHavoc: make sure the string is terminated
77         final[MAXPRINTMSG-1] = 0;
78         for (p = (unsigned char *) final;*p; p++)
79                 *p = qfont_table[*p];
80         Sys_PrintToTerminal(final);
81 }
82
83 void Sys_Printf(const char *fmt, ...)
84 {
85         va_list argptr;
86         char msg[MAXPRINTMSG];  // String we started with
87
88         va_start(argptr,fmt);
89         vsnprintf(msg,sizeof(msg),fmt,argptr);
90         va_end(argptr);
91
92         Sys_Print(msg);
93 }
94
95
96 char engineversion[128];
97
98 void Sys_Shared_EarlyInit(void)
99 {
100         const char* os;
101
102         Memory_Init ();
103
104         COM_InitArgv();
105         COM_InitGameType();
106
107 #if defined(__linux__)
108         os = "Linux";
109 #elif defined(WIN32)
110         os = "Windows";
111 #elif defined(__NetBSD__)
112         os = "NetBSD";
113 #elif defined(__OpenBSD__)
114         os = "OpenBSD";
115 #else
116         os = "Unknown";
117 #endif
118         snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
119
120         if (COM_CheckParm("-nostdout"))
121                 sys_nostdout = 1;
122         else
123                 Con_Printf("%s\n", engineversion);
124 }
125
126 void Sys_Shared_LateInit(void)
127 {
128 }
129
130 /*
131 ===============================================================================
132
133 DLL MANAGEMENT
134
135 ===============================================================================
136 */
137
138 #ifndef WIN32
139 #include <dlfcn.h>
140 #endif
141
142 dllhandle_t Sys_LoadLibrary (const char* name)
143 {
144 #ifdef WIN32
145         return LoadLibrary (name);
146 #else
147         return dlopen (name, RTLD_LAZY);
148 #endif
149 }
150
151 void Sys_UnloadLibrary (dllhandle_t handle)
152 {
153 #ifdef WIN32
154         FreeLibrary (handle);
155 #else
156         dlclose (handle);
157 #endif
158 }
159
160 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
161 {
162 #ifdef WIN32
163         return (void *)GetProcAddress (handle, name);
164 #else
165         return (void *)dlsym (handle, name);
166 #endif
167 }
168