vkQuake2 doxygen  1.0 dev
vk_model.h File Reference

Go to the source code of this file.

Classes

struct  mvertex_t
 
struct  mmodel_t
 
struct  medge_t
 
struct  mtexinfo_s
 
struct  vkpoly_s
 
struct  msurface_s
 
struct  mnode_s
 
struct  mleaf_s
 
struct  model_s
 

Macros

#define SIDE_FRONT   0
 
#define SIDE_BACK   1
 
#define SIDE_ON   2
 
#define SURF_PLANEBACK   2
 
#define SURF_DRAWSKY   4
 
#define SURF_DRAWTURB   0x10
 
#define SURF_DRAWBACKGROUND   0x40
 
#define SURF_UNDERWATER   0x80
 
#define VERTEXSIZE   7
 

Typedefs

typedef struct mtexinfo_s mtexinfo_t
 
typedef struct vkpoly_s vkpoly_t
 
typedef struct msurface_s msurface_t
 
typedef struct mnode_s mnode_t
 
typedef struct mleaf_s mleaf_t
 
typedef struct model_s model_t
 

Enumerations

enum  modtype_t {
  mod_bad, mod_brush, mod_sprite, mod_alias,
  mod_bad, mod_brush, mod_sprite, mod_alias,
  mod_bad, mod_brush, mod_sprite, mod_alias
}
 

Functions

void Mod_Init (void)
 
model_tMod_ForName (char *name, qboolean crash)
 
mleaf_tMod_PointInLeaf (float *p, model_t *model)
 
byteMod_ClusterPVS (int cluster, model_t *model)
 
void Mod_Modellist_f (void)
 
voidHunk_Begin (int maxsize)
 
voidHunk_Alloc (int size)
 
int Hunk_End (void)
 
void Hunk_Free (void *base)
 
void Mod_FreeAll (void)
 
void Mod_Free (model_t *mod)
 

Macro Definition Documentation

◆ SIDE_BACK

#define SIDE_BACK   1

Definition at line 59 of file vk_model.h.

◆ SIDE_FRONT

#define SIDE_FRONT   0

Definition at line 58 of file vk_model.h.

◆ SIDE_ON

#define SIDE_ON   2

Definition at line 60 of file vk_model.h.

◆ SURF_DRAWBACKGROUND

#define SURF_DRAWBACKGROUND   0x40

Definition at line 66 of file vk_model.h.

◆ SURF_DRAWSKY

#define SURF_DRAWSKY   4

Definition at line 64 of file vk_model.h.

◆ SURF_DRAWTURB

#define SURF_DRAWTURB   0x10

Definition at line 65 of file vk_model.h.

◆ SURF_PLANEBACK

#define SURF_PLANEBACK   2

Definition at line 63 of file vk_model.h.

◆ SURF_UNDERWATER

#define SURF_UNDERWATER   0x80

Definition at line 67 of file vk_model.h.

◆ VERTEXSIZE

#define VERTEXSIZE   7

Definition at line 85 of file vk_model.h.

Typedef Documentation

◆ mleaf_t

typedef struct mleaf_s mleaf_t

◆ mnode_t

typedef struct mnode_s mnode_t

◆ model_t

typedef struct model_s model_t

◆ msurface_t

typedef struct msurface_s msurface_t

◆ mtexinfo_t

typedef struct mtexinfo_s mtexinfo_t

◆ vkpoly_t

typedef struct vkpoly_s vkpoly_t

Enumeration Type Documentation

◆ modtype_t

enum modtype_t
Enumerator
mod_bad 
mod_brush 
mod_sprite 
mod_alias 
mod_bad 
mod_brush 
mod_sprite 
mod_alias 
mod_bad 
mod_brush 
mod_sprite 
mod_alias 

Definition at line 173 of file vk_model.h.

Function Documentation

◆ 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_LoadRighting(), Mod_LoadSpriteModel(), Mod_LoadSubmodels(), Mod_LoadSurfedges(), Mod_LoadTexinfo(), Mod_LoadVertexes(), Mod_LoadVisibility(), SubdividePolygon(), and Vk_BuildPolygonFromSurface().

◆ 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().

◆ Mod_ClusterPVS()

byte* Mod_ClusterPVS ( int  cluster,
model_t model 
)

Definition at line 268 of file r_model.c.

269 {
270  if (cluster == -1 || !model->vis)
271  return mod_novis;
272  return Mod_DecompressVis((byte *)model->vis + model->vis->bitofs[cluster][DVIS_PVS],
273  model);
274 }

Referenced by R_MarkLeaves().

◆ Mod_ForName()

model_t* Mod_ForName ( char *  name,
qboolean  crash 
)

Definition at line 90 of file r_model.c.

91 {
92  model_t *mod;
93  unsigned *buf;
94  int i;
95 
96  if (!name[0])
97  ri.Sys_Error(ERR_DROP, "Mod_ForName: NULL name");
98 
99  //
100  // inline models are grabbed only from worldmodel
101  //
102  if (name[0] == '*')
103  {
104  i = atoi(name + 1);
105  if (i < 1 || !r_worldmodel || i >= r_worldmodel->numsubmodels)
106  ri.Sys_Error(ERR_DROP, "bad inline model number");
107  return &mod_inline[i];
108  }
109 
110  //
111  // search the currently loaded models
112  //
113  for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
114  if (!strcmp(mod->name, name))
115  return mod;
116 
117  //
118  // find a free model slot spot
119  //
120  for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
121  {
122  if (!mod->name[0])
123  break; // free spot
124  }
125  if (i == mod_numknown)
126  {
128  ri.Sys_Error(ERR_DROP, "mod_numknown == MAX_MOD_KNOWN");
129  mod_numknown++;
130  }
131  strcpy(mod->name, name);
132 
133  //
134  // load the file
135  //
136  modfilelen = ri.FS_LoadFile(mod->name, (void **)&buf);
137  if (!buf)
138  {
139  if (crash)
140  ri.Sys_Error(ERR_DROP, "Mod_NumForName: %s not found", mod->name);
141  memset(mod->name, 0, sizeof(mod->name));
142  return NULL;
143  }
144 
145  loadmodel = mod;
146 
147  //
148  // fill it in
149  //
150 
151  // call the apropriate loader
152 
153  switch (LittleLong(*(unsigned *)buf))
154  {
155  case IDALIASHEADER:
156  loadmodel->extradata = Hunk_Begin(0x200000);
157  Mod_LoadAliasModel(mod, buf);
158  break;
159 
160  case IDSPRITEHEADER:
161  loadmodel->extradata = Hunk_Begin(0x10000);
162  Mod_LoadSpriteModel(mod, buf);
163  break;
164 
165  case IDBSPHEADER:
166  loadmodel->extradata = Hunk_Begin(0x1000000);
167  Mod_LoadBrushModel(mod, buf);
168  break;
169 
170  default:
171  ri.Sys_Error(ERR_DROP, "Mod_NumForName: unknown fileid for %s", mod->name);
172  break;
173  }
174 
176 
177  ri.FS_FreeFile(buf);
178 
179  return mod;
180 }

Referenced by R_BeginRegistration(), and R_RegisterModel().

◆ Mod_Free()

void Mod_Free ( model_t mod)

Definition at line 1313 of file r_model.c.

1314 {
1315  Hunk_Free(mod->extradata);
1316  memset(mod, 0, sizeof(*mod));
1317 }

Referenced by Mod_FreeAll(), R_BeginRegistration(), and R_EndRegistration().

◆ Mod_FreeAll()

void Mod_FreeAll ( void  )

Definition at line 1324 of file r_model.c.

1325 {
1326  int i;
1327 
1328  for (i = 0; i < mod_numknown; i++)
1329  {
1330  if (mod_known[i].extradatasize)
1331  Mod_Free(&mod_known[i]);
1332  }
1333 }

Referenced by R_Shutdown().

◆ Mod_Init()

void Mod_Init ( void  )

Definition at line 78 of file r_model.c.

79 {
80  memset(mod_novis, 0xff, sizeof(mod_novis));
81 }

Referenced by R_Init().

◆ Mod_Modellist_f()

void Mod_Modellist_f ( void  )

Definition at line 55 of file r_model.c.

56 {
57  int i;
58  model_t *mod;
59  int total;
60 
61  total = 0;
62  ri.Con_Printf(PRINT_ALL, "Loaded models:\n");
63  for (i = 0, mod = mod_known; i < mod_numknown; i++, mod++)
64  {
65  if (!mod->name[0])
66  continue;
67  ri.Con_Printf(PRINT_ALL, "%8i : %s\n", mod->extradatasize, mod->name);
68  total += mod->extradatasize;
69  }
70  ri.Con_Printf(PRINT_ALL, "Total resident: %i\n", total);
71 }

Referenced by R_Register().

◆ Mod_PointInLeaf()

mleaf_t* Mod_PointInLeaf ( float *  p,
model_t model 
)
hunkcount
int hunkcount
Definition: q_shwin.c:32
Mod_LoadSpriteModel
void Mod_LoadSpriteModel(model_t *mod, void *buffer)
Definition: r_model.c:1170
Hunk_Begin
void * Hunk_Begin(int maxsize)
Definition: q_shwin.c:41
model_s::vis
dvis_t * vis
Definition: r_model.h:229
hunkmaxsize
int hunkmaxsize
Definition: q_shwin.c:36
mod_known
model_t mod_known[MAX_MOD_KNOWN]
Definition: r_model.c:38
mod_brush
@ mod_brush
Definition: vk_model.h:173
mod_alias
@ mod_alias
Definition: vk_model.h:173
Hunk_Free
void Hunk_Free(void *base)
Definition: q_shwin.c:99
ri
refimport_t ri
Definition: r_main.c:25
IDSPRITEHEADER
#define IDSPRITEHEADER
Definition: qfiles.h:170
mod_bad
@ mod_bad
Definition: vk_model.h:173
Mod_DecompressVis
byte * Mod_DecompressVis(byte *in, model_t *model)
Definition: r_model.c:219
refimport_t::FS_LoadFile
int(* FS_LoadFile)(char *name, void **buf)
Definition: ref.h:209
Sys_Error
void Sys_Error(char *error,...)
Definition: sys_win.c:68
i
int i
Definition: q_shared.c:305
model_s
Definition: r_model.h:171
mod_novis
byte mod_novis[MAX_MAP_LEAFS/8]
Definition: r_model.c:35
DVIS_PVS
#define DVIS_PVS
Definition: qfiles.h:461
membase
byte * membase
Definition: q_shwin.c:35
model_s::extradata
void * extradata
Definition: r_model.h:235
refimport_t::FS_FreeFile
void(* FS_FreeFile)(void *buf)
Definition: ref.h:210
Mod_LoadBrushModel
void Mod_LoadBrushModel(model_t *mod, void *buffer)
Definition: r_model.c:962
IDBSPHEADER
#define IDBSPHEADER
Definition: qfiles.h:219
model_s::numsubmodels
int numsubmodels
Definition: r_model.h:198
mod_numknown
int mod_numknown
Definition: r_model.c:39
refimport_t::Con_Printf
void(* Con_Printf)(int print_level, char *str,...)
Definition: ref.h:202
PRINT_ALL
#define PRINT_ALL
Definition: qcommon.h:751
LittleLong
int LittleLong(int l)
Definition: q_shared.c:948
refimport_t::Sys_Error
void(* Sys_Error)(int err_level, char *str,...)
Definition: ref.h:194
r_worldmodel
model_t * r_worldmodel
Definition: r_main.c:41
Hunk_End
int Hunk_End(void)
Definition: q_shwin.c:81
NULL
#define NULL
Definition: q_shared.h:67
ERR_DROP
#define ERR_DROP
Definition: qcommon.h:744
modfilelen
int modfilelen
Definition: r_model.c:45
name
cvar_t * name
Definition: cl_main.c:79
dvis_t::bitofs
int bitofs[8][2]
Definition: qfiles.h:466
modtype_t
modtype_t
Definition: vk_model.h:173
mod_inline
model_t mod_inline[MAX_MOD_KNOWN]
Definition: r_model.c:42
model_s::name
char name[MAX_QPATH]
Definition: r_model.h:173
cursize
int cursize
Definition: q_shwin.c:37
MAX_MOD_KNOWN
#define MAX_MOD_KNOWN
Definition: r_model.c:37
mod_sprite
@ mod_sprite
Definition: vk_model.h:173
IDALIASHEADER
#define IDALIASHEADER
Definition: qfiles.h:86
Mod_Free
void Mod_Free(model_t *mod)
Definition: r_model.c:1313
Mod_LoadAliasModel
void Mod_LoadAliasModel(model_t *mod, void *buffer)
Definition: r_model.c:1046
loadmodel
model_t * loadmodel
Definition: r_model.c:27
model_s::extradatasize
int extradatasize
Definition: r_model.h:236