UFO: Alien Invasion
Loading...
Searching...
No Matches
win_main.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "../../common/common.h"
27#include "win_local.h"
28#include <fcntl.h>
29#include <direct.h>
30#include <io.h>
31#include <mmsystem.h>
32
33void Sys_Init (void)
34{
35 OSVERSIONINFO vinfo;
36#if 0
37 MEMORYSTATUS mem;
38#endif
39
40 sys_affinity = Cvar_Get("sys_affinity", "0", CVAR_ARCHIVE, "Which core to use - 0 = all cores, 1 = two cores, 2 = one core");
41 sys_priority = Cvar_Get("sys_priority", "0", CVAR_ARCHIVE, "Process priority - 0 = normal, 1 = high, 2 = realtime");
42
43 timeBeginPeriod(1);
44
45 vinfo.dwOSVersionInfoSize = sizeof(vinfo);
46
47 if (!GetVersionEx(&vinfo))
48 Sys_Error("Couldn't get OS info");
49
50 char const* detected = "win";
51 if (vinfo.dwMajorVersion < 4) /* at least win nt 4 */
52 Sys_Error("UFO: AI requires windows version 4 or greater");
53 if (vinfo.dwPlatformId == VER_PLATFORM_WIN32s) /* win3.x with win32 extensions */
54 Sys_Error("UFO: AI doesn't run on Win32s");
55 else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) /* win95, 98, me */
56 detected = "win95";
57 else if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) { /* win nt, xp */
58 if (vinfo.dwMajorVersion == 5 && vinfo.dwMinorVersion == 0)
59 detected = "win2K";
60 else if (vinfo.dwMajorVersion == 5)
61 detected = "winXP";
62 else if (vinfo.dwMajorVersion == 6)
63 detected = "winVista";
64 }
65
66 sys_os = Cvar_Get("sys_os", detected, CVAR_SERVERINFO);
67
68#if 0
69 GlobalMemoryStatus(&mem);
70 Com_Printf("Memory: %u MB\n", mem.dwTotalPhys >> 20);
71#endif
72}
73
74static void FixWorkingDirectory (void)
75{
76 char curDir[MAX_PATH];
77
78 GetModuleFileName(nullptr, curDir, sizeof(curDir)-1);
79
80 char* p = strrchr(curDir, '\\');
81 p[0] = 0;
82
83 if (strlen(curDir) > (MAX_OSPATH - MAX_QPATH))
84 Sys_Error("Current path is too long. Please move your installation to a shorter path.");
85
86 SetCurrentDirectory(curDir);
87}
88
89#ifdef _MSC_VER
90int main(int argc, char *argv[])
91#else
92int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE, LPSTR, int)
93#endif
94{
95#ifdef _MSC_VER
96 global_hInstance = GetModuleHandle(NULL);
97#else
98 global_hInstance = hInstance;
99#endif
100
102
103 /* always change to the current working dir */
105
106 Qcommon_Init(__argc, __argv);
107
108 /* main window message loop */
109 while (1)
111
112 /* never gets here */
113 return FALSE;
114}
void Sys_ConsoleInit(void)
Initialize the console input (tty mode if possible).
void Qcommon_Frame(void)
This is the function that is called directly from main().
Definition common.cpp:1511
cvar_t * sys_os
Definition common.cpp:61
cvar_t * sys_priority
Definition common.cpp:59
cvar_t * sys_affinity
Definition common.cpp:60
void Qcommon_Init(int argc, char **argv)
Init function.
Definition common.cpp:1095
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
definitions common between client and server, but not game lib
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
#define CVAR_SERVERINFO
Definition cvar.h:42
#define CVAR_ARCHIVE
Definition cvar.h:40
#define MAX_OSPATH
Definition filesys.h:44
#define MAX_QPATH
Definition filesys.h:40
void Sys_Error(const char *error,...)
Definition g_main.cpp:421
int main(int argc, char **argv)
The entry point for linux server and client. Initializes the program and calls Qcommon_Frame in an in...
Win32-specific UFO header file.
HINSTANCE global_hInstance
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
Definition win_main.cpp:92
static void FixWorkingDirectory(void)
Definition win_main.cpp:74
void Sys_Init(void)
Definition win_main.cpp:33