UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
win_main.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 1997-2001 Id Software, Inc.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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 
33 void 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 
74 static 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
90 int main(int argc, char *argv[])
91 #else
92 int 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 
101  Sys_ConsoleInit();
102 
103  /* always change to the current working dir */
105 
106  Qcommon_Init(__argc, __argv);
107 
108  /* main window message loop */
109  while (1)
110  Qcommon_Frame();
111 
112  /* never gets here */
113  return FALSE;
114 }
void Qcommon_Frame(void)
This is the function that is called directly from main()
Definition: common.cpp:1493
void Qcommon_Init(int argc, char **argv)
Init function.
Definition: common.cpp:1078
void Sys_Error(const char *error,...)
Definition: g_main.cpp:421
cvar_t * sys_affinity
Definition: common.cpp:60
void Sys_ConsoleInit(void)
Initialize the console input (tty mode if possible)
int main(int argc, char **argv)
The entry point for linux server and client. Initializes the program and calls Qcommon_Frame in an in...
Definition: linux_main.cpp:47
#define MAX_OSPATH
Definition: filesys.h:44
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
static void FixWorkingDirectory(void)
Definition: win_main.cpp:74
#define CVAR_ARCHIVE
Definition: cvar.h:40
HINSTANCE global_hInstance
Definition: win_shared.cpp:39
Win32-specific UFO header file.
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
void Sys_Init(void)
Definition: win_main.cpp:33
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
Definition: win_main.cpp:92
#define MAX_QPATH
Definition: filesys.h:40
cvar_t * sys_os
Definition: common.cpp:61
cvar_t * sys_priority
Definition: common.cpp:59
#define CVAR_SERVERINFO
Definition: cvar.h:42