]> icculus.org git repositories - divverent/darkplaces.git/blob - sys_shared.c
added some SV_CheckVelocity calls to MOVETYPE_WALK code
[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
52 #define MAX_PRINT_MSG   16384
53 void Sys_Printf (const char *fmt, ...)
54 {
55         va_list         argptr;
56         char            start[MAX_PRINT_MSG];   // String we started with
57         char            stamp[MAX_PRINT_MSG];   // Time stamp
58         char            final[MAX_PRINT_MSG];   // String we print
59
60         time_t          mytime = 0;
61         struct tm       *local = NULL;
62
63         unsigned char           *p;
64
65         va_start (argptr, fmt);
66         vsnprintf (start, sizeof(start), fmt, argptr);
67         va_end (argptr);
68
69         if (sys_nostdout)
70                 return;
71
72         if (timestamps.integer)
73         {
74                 mytime = time (NULL);
75                 local = localtime (&mytime);
76                 strftime (stamp, sizeof (stamp), timeformat.string, local);
77
78                 snprintf (final, sizeof (final), "%s%s", stamp, start);
79         }
80         else
81                 snprintf (final, sizeof (final), "%s", start);
82
83         // LordHavoc: make sure the string is terminated
84         final[MAX_PRINT_MSG - 1] = 0;
85         for (p = (unsigned char *) final;*p; p++)
86                 *p = qfont_table[*p];
87         Sys_Print(final);
88 }
89
90
91 char engineversion[128];
92
93 void Sys_Shared_EarlyInit(void)
94 {
95         const char* os;
96
97         Memory_Init ();
98
99         COM_InitArgv();
100         COM_InitGameType();
101
102 #if defined(__linux__)
103         os = "Linux";
104 #elif defined(WIN32)
105         os = "Windows";
106 #else
107         os = "Unknown";
108 #endif
109         snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
110
111         if (COM_CheckParm("-nostdout"))
112                 sys_nostdout = 1;
113         else
114                 Con_Printf("%s\n", engineversion);
115 }
116
117 void Sys_Shared_LateInit(void)
118 {
119 }
120
121 /*
122 ===============================================================================
123
124 DLL MANAGEMENT
125
126 ===============================================================================
127 */
128
129 #ifndef WIN32
130 #include <dlfcn.h>
131 #endif
132
133 dllhandle_t Sys_LoadLibrary (const char* name)
134 {
135 #ifdef WIN32
136         return LoadLibrary (name);
137 #else
138         return dlopen (name, RTLD_LAZY);
139 #endif
140 }
141
142 void Sys_UnloadLibrary (dllhandle_t handle)
143 {
144 #ifdef WIN32
145         FreeLibrary (handle);
146 #else
147         dlclose (handle);
148 #endif
149 }
150
151 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
152 {
153 #ifdef WIN32
154         return (void *)GetProcAddress (handle, name);
155 #else
156         return (void *)dlsym (handle, name);
157 #endif
158 }
159