icculus quake2 doxygen  1.0 dev
q_shwin.c File Reference
#include "../qcommon/qcommon.h"
#include "winquake.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <direct.h>
#include <io.h>
#include <conio.h>

Go to the source code of this file.

Macros

#define VIRTUAL_ALLOC
 

Functions

voidHunk_Begin (int maxsize)
 
voidHunk_Alloc (int size)
 
int Hunk_End (void)
 
void Hunk_Free (void *base)
 
int Sys_Milliseconds (void)
 
void Sys_Mkdir (char *path)
 
static qboolean CompareAttributes (unsigned found, unsigned musthave, unsigned canthave)
 
char * Sys_FindFirst (char *path, unsigned musthave, unsigned canthave)
 
char * Sys_FindNext (unsigned musthave, unsigned canthave)
 
void Sys_FindClose (void)
 

Variables

int hunkcount
 
bytemembase
 
int hunkmaxsize
 
int cursize
 
int curtime
 
char findbase [MAX_OSPATH]
 
char findpath [MAX_OSPATH]
 
int findhandle
 

Macro Definition Documentation

◆ VIRTUAL_ALLOC

#define VIRTUAL_ALLOC

Definition at line 39 of file q_shwin.c.

Function Documentation

◆ CompareAttributes()

static qboolean CompareAttributes ( unsigned  found,
unsigned  musthave,
unsigned  canthave 
)
static

Definition at line 146 of file q_shwin.c.

147 {
148  if ( ( found & _A_RDONLY ) && ( canthave & SFF_RDONLY ) )
149  return false;
150  if ( ( found & _A_HIDDEN ) && ( canthave & SFF_HIDDEN ) )
151  return false;
152  if ( ( found & _A_SYSTEM ) && ( canthave & SFF_SYSTEM ) )
153  return false;
154  if ( ( found & _A_SUBDIR ) && ( canthave & SFF_SUBDIR ) )
155  return false;
156  if ( ( found & _A_ARCH ) && ( canthave & SFF_ARCH ) )
157  return false;
158 
159  if ( ( musthave & SFF_RDONLY ) && !( found & _A_RDONLY ) )
160  return false;
161  if ( ( musthave & SFF_HIDDEN ) && !( found & _A_HIDDEN ) )
162  return false;
163  if ( ( musthave & SFF_SYSTEM ) && !( found & _A_SYSTEM ) )
164  return false;
165  if ( ( musthave & SFF_SUBDIR ) && !( found & _A_SUBDIR ) )
166  return false;
167  if ( ( musthave & SFF_ARCH ) && !( found & _A_ARCH ) )
168  return false;
169 
170  return true;
171 }

Referenced by Sys_FindFirst(), and Sys_FindNext().

◆ Hunk_Alloc()

void* Hunk_Alloc ( int  size)

Definition at line 57 of file q_shwin.c.

58 {
59  void *buf;
60 
61  // round to cacheline
62  size = (size+31)&~31;
63 
64 #ifdef VIRTUAL_ALLOC
65  // commit pages as needed
66 // buf = VirtualAlloc (membase+cursize, size, MEM_COMMIT, PAGE_READWRITE);
67  buf = VirtualAlloc (membase, cursize+size, MEM_COMMIT, PAGE_READWRITE);
68  if (!buf)
69  {
70  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buf, 0, NULL);
71  Sys_Error ("VirtualAlloc commit failed.\n%s", buf);
72  }
73 #endif
74  cursize += size;
75  if (cursize > hunkmaxsize)
76  Sys_Error ("Hunk_Alloc overflow");
77 
78  return (void *)(membase+cursize-size);
79 }

Referenced by GL_BuildPolygonFromSurface(), Mod_LoadAliasModel(), Mod_LoadEdges(), Mod_LoadFaces(), Mod_LoadLeafs(), Mod_LoadLighting(), Mod_LoadMarksurfaces(), Mod_LoadNodes(), Mod_LoadPlanes(), Mod_LoadSpriteModel(), Mod_LoadSubmodels(), Mod_LoadSurfedges(), Mod_LoadTexinfo(), Mod_LoadVertexes(), Mod_LoadVisibility(), and SubdividePolygon().

◆ Hunk_Begin()

void* Hunk_Begin ( int  maxsize)

Definition at line 41 of file q_shwin.c.

42 {
43  // reserve a huge chunk of memory, but don't commit any yet
44  cursize = 0;
45  hunkmaxsize = maxsize;
46 #ifdef VIRTUAL_ALLOC
47  membase = VirtualAlloc (NULL, maxsize, MEM_RESERVE, PAGE_NOACCESS);
48 #else
49  membase = malloc (maxsize);
50  memset (membase, 0, maxsize);
51 #endif
52  if (!membase)
53  Sys_Error ("VirtualAlloc reserve failed");
54  return (void *)membase;
55 }

Referenced by Mod_ForName().

◆ Hunk_End()

int Hunk_End ( void  )

Definition at line 81 of file q_shwin.c.

82 {
83 
84  // free the remaining unused virtual memory
85 #if 0
86  void *buf;
87 
88  // write protect it
89  buf = VirtualAlloc (membase, cursize, MEM_COMMIT, PAGE_READONLY);
90  if (!buf)
91  Sys_Error ("VirtualAlloc commit failed");
92 #endif
93 
94  hunkcount++;
95 //Com_Printf ("hunkcount: %i\n", hunkcount);
96  return cursize;
97 }

Referenced by Mod_ForName().

◆ Hunk_Free()

void Hunk_Free ( void base)

Definition at line 99 of file q_shwin.c.

100 {
101  if ( base )
102 #ifdef VIRTUAL_ALLOC
103  VirtualFree (base, 0, MEM_RELEASE);
104 #else
105  free (base);
106 #endif
107 
108  hunkcount--;
109 }

Referenced by Mod_Free(), and R_EndRegistration().

◆ Sys_FindClose()

void Sys_FindClose ( void  )

Definition at line 206 of file q_shwin.c.

207 {
208  if (findhandle != -1)
209  _findclose (findhandle);
210  findhandle = 0;
211 }

Referenced by FS_ExecAutoexec(), FS_ListFiles(), PlayerConfig_ScanDirectories(), SV_CopySaveGame(), and SV_WipeSavegame().

◆ Sys_FindFirst()

char* Sys_FindFirst ( char *  path,
unsigned  musthave,
unsigned  canthave 
)

Definition at line 173 of file q_shwin.c.

174 {
175  struct _finddata_t findinfo;
176 
177  if (findhandle)
178  Sys_Error ("Sys_BeginFind without close");
179  findhandle = 0;
180 
181  COM_FilePath (path, findbase);
182  findhandle = _findfirst (path, &findinfo);
183  if (findhandle == -1)
184  return NULL;
185  if ( !CompareAttributes( findinfo.attrib, musthave, canthave ) )
186  return NULL;
187  Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name);
188  return findpath;
189 }

Referenced by FS_ExecAutoexec(), FS_ListFiles(), PlayerConfig_ScanDirectories(), SV_CopySaveGame(), and SV_WipeSavegame().

◆ Sys_FindNext()

char* Sys_FindNext ( unsigned  musthave,
unsigned  canthave 
)

Definition at line 191 of file q_shwin.c.

192 {
193  struct _finddata_t findinfo;
194 
195  if (findhandle == -1)
196  return NULL;
197  if (_findnext (findhandle, &findinfo) == -1)
198  return NULL;
199  if ( !CompareAttributes( findinfo.attrib, musthave, canthave ) )
200  return NULL;
201 
202  Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name);
203  return findpath;
204 }

Referenced by FS_ListFiles(), SV_CopySaveGame(), and SV_WipeSavegame().

◆ Sys_Milliseconds()

int Sys_Milliseconds ( void  )

Definition at line 120 of file q_shwin.c.

121 {
122  static int base;
123  static qboolean initialized = false;
124 
125  if (!initialized)
126  { // let base retain 16 bits of effectively random data
127  base = timeGetTime() & 0xffff0000;
128  initialized = true;
129  }
130  curtime = timeGetTime() - base;
131 
132  return curtime;
133 }

Referenced by CL_Disconnect(), CL_Frame(), CL_InitLocal(), Field_Draw(), KeyCursorDrawFunc(), Menu_Draw(), Netchan_Init(), Qcommon_Frame(), R_EdgeDrawing(), R_PrintDSpeeds(), R_PrintTimes(), R_RenderFrame(), SCR_BeginLoadingPlaque(), SCR_PlayCinematic(), SCR_TimeRefresh_f(), SCR_UpdateScreen(), SV_RunGameFrame(), V_RenderView(), and WinMain().

◆ Sys_Mkdir()

void Sys_Mkdir ( char *  path)

Definition at line 135 of file q_shwin.c.

136 {
137  _mkdir (path);
138 }

Referenced by FS_CreatePath(), GL_ScreenShot_f(), and R_ScreenShot_f().

Variable Documentation

◆ cursize

int cursize

Definition at line 37 of file q_shwin.c.

Referenced by Hunk_Alloc(), Hunk_Begin(), and Hunk_End().

◆ curtime

◆ findbase

char findbase[MAX_OSPATH]

Definition at line 142 of file q_shwin.c.

Referenced by Sys_FindFirst(), and Sys_FindNext().

◆ findhandle

int findhandle

Definition at line 144 of file q_shwin.c.

Referenced by Sys_FindClose(), Sys_FindFirst(), and Sys_FindNext().

◆ findpath

char findpath[MAX_OSPATH]

Definition at line 143 of file q_shwin.c.

Referenced by Sys_FindFirst(), and Sys_FindNext().

◆ hunkcount

int hunkcount

Definition at line 32 of file q_shwin.c.

Referenced by Hunk_End(), and Hunk_Free().

◆ hunkmaxsize

int hunkmaxsize

Definition at line 36 of file q_shwin.c.

Referenced by Hunk_Alloc(), and Hunk_Begin().

◆ membase

byte* membase

Definition at line 35 of file q_shwin.c.

Referenced by Hunk_Alloc(), Hunk_Begin(), and Hunk_End().

curtime
int curtime
Definition: q_shwin.c:119
hunkcount
int hunkcount
Definition: q_shwin.c:32
COM_FilePath
void COM_FilePath(char *in, char *out)
Definition: q_shared.c:888
hunkmaxsize
int hunkmaxsize
Definition: q_shwin.c:36
SFF_ARCH
#define SFF_ARCH
Definition: q_shared.h:279
Sys_Error
void Sys_Error(char *error,...)
Definition: sys_win.c:67
qboolean
qboolean
Definition: q_shared.h:56
findhandle
int findhandle
Definition: q_shwin.c:144
membase
byte * membase
Definition: q_shwin.c:35
findbase
char findbase[MAX_OSPATH]
Definition: q_shwin.c:142
NULL
#define NULL
Definition: q_shared.h:60
cursize
int cursize
Definition: q_shwin.c:37
findpath
char findpath[MAX_OSPATH]
Definition: q_shwin.c:143
initialized
static qboolean initialized
Definition: cd_win.c:31
SFF_HIDDEN
#define SFF_HIDDEN
Definition: q_shared.h:280
SFF_RDONLY
#define SFF_RDONLY
Definition: q_shared.h:281
SFF_SUBDIR
#define SFF_SUBDIR
Definition: q_shared.h:282
CompareAttributes
static qboolean CompareAttributes(unsigned found, unsigned musthave, unsigned canthave)
Definition: q_shwin.c:146
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
SFF_SYSTEM
#define SFF_SYSTEM
Definition: q_shared.h:283