mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 08:27:39 +00:00
[gamecode] Make PR_RESMAP macros usable in void functions
This commit is contained in:
parent
5d1e515e9e
commit
065d0f3818
1 changed files with 35 additions and 26 deletions
|
@ -1550,28 +1550,33 @@ void *PR_Resources_Find (progs_t *pr, const char *name);
|
||||||
*/
|
*/
|
||||||
#define PR_RESNEW_NC(map) \
|
#define PR_RESNEW_NC(map) \
|
||||||
({ \
|
({ \
|
||||||
if (!(map)._free) { \
|
__auto_type ret = (map)._free; \
|
||||||
int i, size; \
|
do { \
|
||||||
(map)._size++; \
|
|
||||||
size = (map)._size * sizeof ((map)._free); \
|
|
||||||
(map)._map = realloc ((map)._map, size); \
|
|
||||||
if (!(map)._map) { \
|
|
||||||
return 0; \
|
|
||||||
} \
|
|
||||||
(map)._free = malloc (1024 * sizeof (*(map)._free)); \
|
|
||||||
if (!(map)._free) { \
|
if (!(map)._free) { \
|
||||||
return 0; \
|
int i, size; \
|
||||||
|
(map)._size++; \
|
||||||
|
size = (map)._size * sizeof ((map)._free); \
|
||||||
|
(map)._map = realloc ((map)._map, size); \
|
||||||
|
if (!(map)._map) { \
|
||||||
|
ret = 0; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
(map)._free = malloc (1024 * sizeof (*(map)._free)); \
|
||||||
|
if (!(map)._free) { \
|
||||||
|
ret = 0; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
(map)._map[(map)._size - 1] = (map)._free; \
|
||||||
|
for (i = 0; i < 1023; i++) { \
|
||||||
|
*(typeof ((map)._free) *) &(map)._free[i] \
|
||||||
|
= &(map)._free[i + 1]; \
|
||||||
|
} \
|
||||||
|
*(typeof ((map)._free) *) &(map)._free[i] = 0; \
|
||||||
} \
|
} \
|
||||||
(map)._map[(map)._size - 1] = (map)._free; \
|
ret = (map)._free; \
|
||||||
for (i = 0; i < 1023; i++) { \
|
(map)._free = *(typeof ((map)._free) *) ret; \
|
||||||
*(typeof ((map)._free) *) &(map)._free[i] \
|
} while (0); \
|
||||||
= &(map)._free[i + 1]; \
|
ret; \
|
||||||
} \
|
|
||||||
*(typeof ((map)._free) *) &(map)._free[i] = 0; \
|
|
||||||
} \
|
|
||||||
__auto_type t = (map)._free; \
|
|
||||||
(map)._free = *(typeof ((map)._free) *) t; \
|
|
||||||
t; \
|
|
||||||
})
|
})
|
||||||
|
|
||||||
#define PR_RESNEW(map) \
|
#define PR_RESNEW(map) \
|
||||||
|
@ -1631,13 +1636,17 @@ void *PR_Resources_Find (progs_t *pr, const char *name);
|
||||||
\return A pointer to the resource, or NULL if the handle is
|
\return A pointer to the resource, or NULL if the handle is
|
||||||
invalid.
|
invalid.
|
||||||
*/
|
*/
|
||||||
#define PR_RESGET(map,col) \
|
#define PR_RESGET(map,ind) \
|
||||||
({ \
|
({ \
|
||||||
unsigned row = ~col / 1024; \
|
__auto_type ret = (map)._free; \
|
||||||
col = ~col % 1024; \
|
unsigned row = ~ind / 1024; \
|
||||||
if (row >= (map)._size) \
|
unsigned col = ~ind % 1024; \
|
||||||
return 0; \
|
if (row >= (map)._size) { \
|
||||||
&(map)._map[row][col]; \
|
ret = 0; \
|
||||||
|
} else { \
|
||||||
|
ret = &(map)._map[row][col]; \
|
||||||
|
} \
|
||||||
|
ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Convert a resource pointer to a handle.
|
/** Convert a resource pointer to a handle.
|
||||||
|
|
Loading…
Reference in a new issue