Builtin module private data management.
More...
|
These macros can be used to create functions for mapping C resources to QuakeC integer handles.
Valid handles are always negative.
- Note
map is the resource map itself, not a pointer to the resource map.
|
#define | PR_RESMAP(type) struct { type *_free; type **_map; unsigned _size; } |
| Type delcaration for the resource map. More...
|
|
#define | PR_RESNEW(type, map) |
| Allocate a new resource from the resource map. More...
|
|
#define | PR_RESFREE(type, map, t) |
| Free a resource returning it to the resource map. More...
|
|
#define | PR_RESRESET(type, map) |
| Free all resources in the resource map. More...
|
|
#define | PR_RESGET(map, col) |
| Retrieve a resource from the resource map using a handle. More...
|
|
#define | PR_RESINDEX(map, ptr) |
| Convert a resource pointer to a handle. More...
|
|
Builtin module private data management.
#define PR_RESFREE |
( |
|
type, |
|
|
|
map, |
|
|
|
t |
|
) |
| |
Value:memset (t, 0,
sizeof (
type)); \
*(
type **) t = map._free; \
map._free = t
int type
Definition: net_wins.c:85
Free a resource returning it to the resource map.
- Parameters
-
type | The type of the resource. Must match the type parameter used for PR_RESMAP. |
map | The resource map. |
t | Pointer to the resource to be freed. |
#define PR_RESGET |
( |
|
map, |
|
|
|
col |
|
) |
| |
Value:unsigned row = ~col / 1024; \
return 0; \
return &map._map[row][col]
if(!(yy_init))
Definition: qp-lex.c:893
Retrieve a resource from the resource map using a handle.
- Parameters
-
map | The resource map. |
col | The handle. |
- Returns
- A pointer to the resource, or NULL if the handle is invalid.
#define PR_RESINDEX |
( |
|
map, |
|
|
|
ptr |
|
) |
| |
Value:unsigned i; \
for (i = 0; i < map._size; i++) { \
long d = ptr - map._map[i];
\
if (d >= 0 && d < 1024) \
return ~(i * 1024 + d); \
} \
return 0
if(!(yy_init))
Definition: qp-lex.c:893
Convert a resource pointer to a handle.
- Parameters
-
map | The resource map. |
ptr | The resource pointer. |
- Returns
- The handle or 0 if the pointer is invalid.
#define PR_RESMAP |
( |
|
type | ) |
struct { type *_free; type **_map; unsigned _size; } |
Type delcaration for the resource map.
- Parameters
-
type | The type of the resource. The size must be at least as large as sizeof(type *) . |
#define PR_RESNEW |
( |
|
type, |
|
|
|
map |
|
) |
| |
Value:
map._size++; \
size = map._size *
sizeof (
type *); \
return 0; \
map._free = calloc (1024,
sizeof (
type));
\
return 0; \
map._map[map._size - 1] = map._free; \
for (i = 0; i < 1023; i++) \
*(
type **) &map._free[i] = &map._free[i + 1]; \
*(
type **) &map._free[i] = 0; \
} \
t = map._free; \
map._free = *(
type **) t; \
memset (t, 0,
sizeof (
type)); \
return t
int(PASCAL FAR *pWSAStartup)(WORD wVersionRequired
if(!(yy_init))
Definition: qp-lex.c:893
int type
Definition: net_wins.c:85
Allocate a new resource from the resource map.
- Parameters
-
type | The type of the resource. Must match the type parameter used for PR_RESMAP. |
map | The resource map. |
- Returns
- A pointer to the new resource, or null if no more could be allocated.
#define PR_RESRESET |
( |
|
type, |
|
|
|
map |
|
) |
| |
Value:
return; \
for (i = 0; i < map._size; i++) { \
map._free = map._map[i]; \
for (j = 0; j < 1023; j++) \
*(
type **) &map._free[j] = &map._free[j + 1];
\
*(
type **) &map._free[j] = &map._map[i + 1][0]; \
} \
map._free = map._map[0];
if(!(yy_init))
Definition: qp-lex.c:893
int type
Definition: net_wins.c:85
Free all resources in the resource map.
Any memory allocated to the resource must be freed before freeing the resource.
- Parameters
-
type | The type of the resource. Must match the type parameter used for PR_RESMAP. |
map | The resource map. |
void PR_Resources_Clear |
( |
progs_t * |
pr | ) |
|
Clear all resources before loading a new progs.
Calls the clear() callback of all registered resources.
- Parameters
-
pr | The VM of which the resources will be cleared. |
Retrieve a resource registered with the VM.
- Parameters
-
pr | The VM from which the resource will be retrieved. |
name | The name of the resource. |
- Returns
- The resource, or NULL if
name
does not match any resource registered with the VM.
void PR_Resources_Init |
( |
progs_t * |
pr | ) |
|
Initialize the resource management fields.
- Parameters
-
pr | The VM of which the resource fields will be initialized. |
void PR_Resources_Register |
( |
progs_t * |
pr, |
|
|
const char * |
name, |
|
|
void * |
data, |
|
|
void(*)(progs_t *, void *) |
clear |
|
) |
| |
Register a resource with a VM.
- Parameters
-
pr | The VM to which the resource will be associated. |
name | The name of the resource. Used for retrieving the resource. |
data | The resource data. callback. |
clear | Callback for performing any necessary cleanup. Called by PR_Resources_Clear(). The parameters are the current VM (pr ) and data . |
- Note
- The name should be unique to the VM, but no checking is done. If the name is not unique, the previous registered resource will break. The name of the sub-system registering the resource is a suitable name, and will probably be unique.