Compare commits

...

10 Commits

36 changed files with 697 additions and 715 deletions

View File

@ -27,7 +27,6 @@ set(srcs
source/bgmusic.c
source/bgmusic.h
source/bspfile.h
source/cd_sdl.c
source/cdaudio.h
source/cfgfile.c
source/cfgfile.h
@ -63,7 +62,6 @@ set(srcs
source/gl_sky.c
source/gl_texmgr.c
source/gl_texmgr.h
source/gl_vidsdl.c
source/gl_warp.c
source/gl_warp_sin.h
source/glquake.h
@ -71,12 +69,10 @@ set(srcs
source/host_cmd.c
source/image.c
source/image.h
source/in_sdl.c
source/input.h
source/keys.c
source/keys.h
source/lodepng.h
source/main_sdl.c
source/mathlib.c
source/mathlib.h
source/menu.c
@ -95,6 +91,8 @@ set(srcs
source/pr_comp.h
source/pr_edict.c
source/pr_exec.c
source/pr_load.c
source/pr_string.c
source/progdefs.h
source/progs.h
source/protocol.h
@ -127,7 +125,6 @@ set(srcs
source/snd_mpg123.c
source/snd_opus.c
source/snd_opus.h
source/snd_sdl.c
source/snd_umx.c
source/snd_umx.h
source/snd_vorbis.c
@ -176,6 +173,16 @@ set(srcs_windows
source/windows/sys_sdl_win.c
source/windows/wsaerror.h)
set(srcs_sdl
source/sdl/cd_sdl.c
source/sdl/endian_sdl.h
source/sdl/gl_vidsdl.c
source/sdl/in_sdl.c
source/sdl/main_sdl.c
source/sdl/snd_sdl.c)
list(APPEND srcs ${srcs_sdl})
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
list(APPEND srcs ${srcs_windows})
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")

View File

@ -693,7 +693,7 @@ void Cmd_AddCommand(const char *cmd_name, xcommand_t function)
}
}
cmd = (cmd_function_t *) Hunk_Alloc(sizeof(cmd_function_t));
cmd = Hunk_AllocName(sizeof(cmd_function_t), "cmd_functions");
cmd->name = cmd_name;
cmd->function = function;

View File

@ -508,125 +508,6 @@ float Q_atof(const char *str)
return val * sign;
}
/*
============================================================================
BYTE ORDER FUNCTIONS
============================================================================
*/
bool host_bigendian;
int16_t (*BigShort)(int16_t l);
int32_t (*BigLong)(int32_t l);
float (*BigFloat)(float l);
int16_t (*LittleShort)(int16_t l);
int32_t (*LittleLong)(int32_t l);
float (*LittleFloat)(float l);
static int16_t ShortSwap(int16_t l)
{
int32_t copy;
((byte *)&copy)[0] = ((byte *)&l)[1];
((byte *)&copy)[1] = ((byte *)&l)[0];
return copy;
}
static int16_t ShortNoSwap(int16_t l)
{
return l;
}
static int32_t LongSwap(int32_t l)
{
int32_t copy;
((byte *)&copy)[0] = ((byte *)&l)[3];
((byte *)&copy)[1] = ((byte *)&l)[2];
((byte *)&copy)[2] = ((byte *)&l)[1];
((byte *)&copy)[3] = ((byte *)&l)[0];
return copy;
}
static int32_t LongNoSwap(int32_t l)
{
return l;
}
static float FloatSwap(float f)
{
float copy;
((byte *)&copy)[0] = ((byte *)&f)[3];
((byte *)&copy)[1] = ((byte *)&f)[2];
((byte *)&copy)[2] = ((byte *)&f)[1];
((byte *)&copy)[3] = ((byte *)&f)[0];
return copy;
}
static float FloatNoSwap(float f)
{
return f;
}
int16_t ReadBigShort(byte *bytes)
{
int16_t v;
v = bytes[1];
v |= bytes[0] << 8;
return v;
}
int32_t ReadBigLong(byte *bytes)
{
int32_t v;
v = bytes[3];
v |= bytes[2] << 8;
v |= bytes[1] << 16;
v |= bytes[0] << 24;
return v;
}
float ReadBigFloat(byte *bytes)
{
union
{
float f;
uint32_t i;
} data;
data.i = ReadBigLong(bytes);
return data.f;
}
int16_t ReadLittleShort(byte *bytes)
{
int16_t v;
v = bytes[0];
v |= bytes[1] << 8;
return v;
}
int32_t ReadLittleLong(byte *bytes)
{
int32_t v;
v = bytes[0];
v |= bytes[1] << 8;
v |= bytes[2] << 16;
v |= bytes[3] << 24;
return v;
}
float ReadLittleFloat(byte *bytes)
{
union
{
float f;
uint32_t i;
} data;
data.i = ReadLittleLong(bytes);
return data.f;
}
/*
==============================================================================
@ -816,9 +697,7 @@ int32_t MSG_ReadShort(void)
return -1;
}
c = (int16_t)(net_message.data[msg_readcount]
+ (net_message.data[msg_readcount + 1] << 8));
c = LittleShort(BytesShort(&net_message.data[msg_readcount]));
msg_readcount += 2;
return c;
@ -834,11 +713,7 @@ int32_t MSG_ReadLong(void)
return -1;
}
c = net_message.data[msg_readcount]
+ (net_message.data[msg_readcount + 1] << 8)
+ (net_message.data[msg_readcount + 2] << 16)
+ (net_message.data[msg_readcount + 3] << 24);
c = LittleLong(BytesLong(&net_message.data[msg_readcount]));
msg_readcount += 4;
return c;
@ -1308,43 +1183,6 @@ void COM_InitArgv(int32_t argc, char **argv)
}
}
/*
================
COM_Init
================
*/
void COM_Init(void)
{
int32_t i = 0x12345678;
if(*(byte *)&i == 0x12)
host_bigendian = true;
else if(*(byte *)&i == 0x78)
host_bigendian = false;
else
Sys_Error("Unsupported endianness");
if(host_bigendian)
{
BigShort = ShortNoSwap;
BigLong = LongNoSwap;
BigFloat = FloatNoSwap;
LittleShort = ShortSwap;
LittleLong = LongSwap;
LittleFloat = FloatSwap;
}
else
{
BigShort = ShortSwap;
BigLong = LongSwap;
BigFloat = FloatSwap;
LittleShort = ShortNoSwap;
LittleLong = LongNoSwap;
LittleFloat = FloatNoSwap;
}
}
/*
============
va
@ -1753,10 +1591,14 @@ byte *COM_LoadTempFile(const char *path, uint32_t *path_id)
return COM_LoadFile(path, LOADFILE_TEMPHUNK, path_id);
}
void COM_LoadCacheFile(const char *path, struct cache_user_s *cu, uint32_t *path_id)
byte *COM_LoadCacheFile(const char *path, struct cache_user_s *cu, uint32_t *path_id)
{
byte *buf;
loadcache = cu;
COM_LoadFile(path, LOADFILE_CACHE, path_id);
buf = COM_LoadFile(path, LOADFILE_CACHE, path_id);
return buf;
}
// uses temp hunk if larger than bufsize

View File

@ -23,23 +23,55 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef spingle__common_h
#define spingle__common_h
// comndef.h -- general definitions
#include "sdl/endian_sdl.h"
#undef min
#undef max
#define q_min(a, b) (((a) < (b)) ? (a) : (b))
#define q_max(a, b) (((a) > (b)) ? (a) : (b))
#define CLAMP(_minval, x, _maxval) \
((x) < (_minval) ? (_minval) : \
(x) > (_maxval) ? (_maxval) : (x))
#define q_minfunc(typ, name) \
static inline typ name(typ a, typ b) {return a < b ? a : b;}
#define q_maxfunc(typ, name) \
static inline typ name(typ a, typ b) {return a > b ? a : b;}
#define CLAMPfunc(typ, name) \
static inline typ name(typ min, typ x, typ max) \
{ \
return x < min ? min : x > max ? max : x; \
}
#define GenericTypes(func, name) \
func(char, name##chr) \
func(byte, name##byt) \
func(int16_t, name##i16) \
func(int32_t, name##i32) \
func(int64_t, name##i64) \
func(uint16_t, name##u16) \
func(uint32_t, name##u32) \
func(uint64_t, name##u64) \
func(float, name##f) \
func(double, name##d)
#define GenericDecl(typ, name) , typ: name
GenericTypes(q_minfunc, q_min)
GenericTypes(q_maxfunc, q_max)
GenericTypes(CLAMPfunc, CLAMP)
#define CLAMP(minval, x, maxval) \
_Generic((x) GenericTypes(GenericDecl, CLAMP))(minval, x, maxval)
#define q_min(a, b) _Generic((a) GenericTypes(GenericDecl, q_min))(a, b)
#define q_max(a, b) _Generic((a) GenericTypes(GenericDecl, q_max))(a, b)
#undef q_minfunc
#undef q_maxfunc
#undef CLAMPfunc
typedef struct sizebuf_s
{
bool allowoverflow; // if false, do a Sys_Error
bool overflowed; // set to true if the buffer size failed
byte *data;
int32_t maxsize;
int32_t cursize;
bool allowoverflow; // if false, do a Sys_Error
bool overflowed; // set to true if the buffer size failed
byte *data;
int32_t maxsize;
int32_t cursize;
} sizebuf_t;
void SZ_Alloc(sizebuf_t *buf, int32_t startsize);
@ -64,23 +96,45 @@ void InsertLinkAfter(link_t *l, link_t *after);
//============================================================================
extern bool host_bigendian;
#define BytesX(typ, name) \
static inline typ Bytes##name(byte const *bytes) \
{ \
typ v; \
memcpy(&v, bytes, sizeof(typ)); \
return v; \
}
extern int16_t (*BigShort)(int16_t l);
extern int32_t (*BigLong)(int32_t l);
extern float (*BigFloat)(float l);
#define ReadXX(endian, typ, name) \
static inline typ Read##endian##name(byte const **bytes) \
{ \
typ v = endian##name(Bytes##name(*bytes)); \
*bytes += sizeof(typ); \
return v; \
}
extern int16_t (*LittleShort)(int16_t l);
extern int32_t (*LittleLong)(int32_t l);
extern float (*LittleFloat)(float l);
#define Reader(typ, name) \
BytesX(typ, name) \
ReadXX(Big, typ, name) \
ReadXX(Little, typ, name)
int16_t ReadBigShort(byte *bytes);
int32_t ReadBigLong(byte *bytes);
float ReadBigFloat(byte *bytes);
Reader(int16_t, Short)
Reader(int32_t, Long)
Reader(float, Float)
int16_t ReadLittleShort(byte *bytes);
int32_t ReadLittleLong(byte *bytes);
float ReadLittleFloat(byte *bytes);
static inline void ReadSkip(byte const **bytes, size_t n)
{
*bytes += n;
}
static inline void ReadCopy(void *out, byte const **bytes, size_t n)
{
memcpy(out, *bytes, n);
*bytes += n;
}
#undef BytesX
#undef ReadXX
#undef Reader
//============================================================================
@ -162,7 +216,6 @@ extern int32_t safemode;
int32_t COM_CheckParm(const char *parm);
void COM_Init(void);
void COM_InitArgv(int32_t argc, char **argv);
void COM_InitFilesystem(void);
@ -235,8 +288,8 @@ byte *COM_LoadHunkFile(const char *path, uint32_t *path_id);
// allocates the buffer on the hunk.
byte *COM_LoadZoneFile(const char *path, uint32_t *path_id);
// allocates the buffer on the zone.
void COM_LoadCacheFile(const char *path, struct cache_user_s *cu,
uint32_t *path_id);
byte *COM_LoadCacheFile(const char *path, struct cache_user_s *cu,
uint32_t *path_id);
// uses cache mem for allocating the buffer.
byte *COM_LoadMallocFile(const char *path, uint32_t *path_id);
// allocates the buffer on the system mem (malloc).

View File

@ -274,7 +274,7 @@ void Con_CheckResize(void)
numchars = con_linewidth;
mark = Hunk_LowMark(); //johnfitz
tbuf = (char *) Hunk_Alloc(con_buffersize); //johnfitz
tbuf = Hunk_AllocName(con_buffersize, __func__); //johnfitz
Q_memcpy(tbuf, con_text, con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
@ -314,7 +314,7 @@ void Con_Init(void)
con_buffersize = CON_TEXTSIZE;
//johnfitz
con_text = (char *) Hunk_AllocName(con_buffersize, "context"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
con_text = (char *)Hunk_AllocName(con_buffersize, "con_text"); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
Q_memset(con_text, ' ', con_buffersize); //johnfitz -- con_buffersize replaces CON_TEXTSIZE
con_linewidth = -1;
@ -771,7 +771,7 @@ void AddToTabList(const char *name, const char *type)
*i_bash = 0;
}
t = (tab_t *) Hunk_Alloc(sizeof(tab_t));
t = Hunk_AllocName(sizeof(tab_t), __func__);
t->name = name;
t->type = type;

View File

@ -63,16 +63,19 @@ interface from being ambiguous.
*/
#define CVAR_NONE 0
#define CVAR_ARCHIVE (1U << 0) // if set, causes it to be saved to config
#define CVAR_NOTIFY (1U << 1) // changes will be broadcasted to all players (q1)
#define CVAR_SERVERINFO (1U << 2) // added to serverinfo will be sent to clients (q1/net_dgrm.c and qwsv)
#define CVAR_USERINFO (1U << 3) // added to userinfo, will be sent to server (qwcl)
#define CVAR_CHANGED (1U << 4)
#define CVAR_ROM (1U << 6)
#define CVAR_LOCKED (1U << 8) // locked temporarily
#define CVAR_REGISTERED (1U << 10) // the var is added to the list of variables
#define CVAR_CALLBACK (1U << 16) // var has a callback
enum
{
CVAR_NONE = 0,
CVAR_ARCHIVE = 1 << 0, // if set, causes it to be saved to config
CVAR_NOTIFY = 1 << 1, // changes will be broadcasted to all players (q1)
CVAR_SERVERINFO = 1 << 2, // added to serverinfo will be sent to clients (q1/net_dgrm.c and qwsv)
CVAR_USERINFO = 1 << 3, // added to userinfo, will be sent to server (qwcl)
CVAR_CHANGED = 1 << 4,
CVAR_ROM = 1 << 6,
CVAR_LOCKED = 1 << 8, // locked temporarily
CVAR_REGISTERED = 1 << 10, // the var is added to the list of variables
CVAR_CALLBACK = 1 << 16, // var has a callback
};
typedef void (*cvarcallback_t)(struct cvar_s *);

View File

@ -326,7 +326,7 @@ qpic_t *Draw_MakePic(const char *name, int32_t width, int32_t height, byte *data
qpic_t *pic;
glpic_t gl;
pic = (qpic_t *) Hunk_Alloc(sizeof(qpic_t) - 4 + sizeof(glpic_t));
pic = Hunk_AllocName(sizeof(qpic_t) - 4 + sizeof(glpic_t), __func__);
pic->width = width;
pic->height = height;

View File

@ -320,7 +320,7 @@ void GL_MakeAliasModelDisplayLists(qmodel_t *m, aliashdr_t *hdr)
paliashdr->poseverts = numorder;
cmds = (int32_t *) Hunk_Alloc(numcommands * 4);
cmds = Hunk_AllocName(numcommands * 4, __func__);
paliashdr->commands = (byte *)cmds - (byte *)paliashdr;
//johnfitz -- precompute texcoords for padded skins
@ -344,7 +344,7 @@ void GL_MakeAliasModelDisplayLists(qmodel_t *m, aliashdr_t *hdr)
}
//johnfitz
verts = (trivertx_t *) Hunk_Alloc(paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t));
verts = Hunk_AllocName(paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t), __func__);
paliashdr->posedata = (byte *)verts - (byte *)paliashdr;
for(i = 0 ; i < paliashdr->numposes ; i++)
for(j = 0 ; j < numorder ; j++)
@ -379,7 +379,7 @@ void GL_MakeAliasModelDisplayLists_VBO(void)
return;
// first, copy the verts onto the hunk
verts = (trivertx_t *) Hunk_Alloc(paliashdr->numposes * paliashdr->numverts * sizeof(trivertx_t));
verts = Hunk_AllocName(paliashdr->numposes * paliashdr->numverts * sizeof(trivertx_t), __func__);
paliashdr->vertexes = (byte *)verts - (byte *)paliashdr;
for(i = 0 ; i < paliashdr->numposes ; i++)
for(j = 0 ; j < paliashdr->numverts ; j++)
@ -387,10 +387,10 @@ void GL_MakeAliasModelDisplayLists_VBO(void)
// there can never be more than this number of verts and we just put them all on the hunk
maxverts_vbo = pheader->numtris * 3;
desc = (aliasmesh_t *) Hunk_Alloc(sizeof(aliasmesh_t) * maxverts_vbo);
desc = Hunk_AllocName(sizeof(aliasmesh_t) * maxverts_vbo, __func__);
// there will always be this number of indexes
indexes = (uint16_t *) Hunk_Alloc(sizeof(uint16_t) * maxverts_vbo);
indexes = Hunk_AllocName(sizeof(uint16_t) * maxverts_vbo, __func__);
pheader->indexes = (intptr_t) indexes - (intptr_t) pheader;
pheader->meshdesc = (intptr_t) desc - (intptr_t) pheader;

View File

@ -355,7 +355,7 @@ qmodel_t *Mod_LoadModel(qmodel_t *mod, bool crash)
// call the apropriate loader
mod->needload = false;
mod_type = (buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24));
mod_type = LittleLong(BytesLong(buf));
switch(mod_type)
{
case IDPOLYHEADER:
@ -529,7 +529,7 @@ void Mod_LoadTextures(lump_t *l)
}
//now create the warpimage, using dummy data from the hunk to create the initial image
Hunk_Alloc(gl_warpimagesize * gl_warpimagesize * 4); //make sure hunk is big enough so we don't reach an illegal address
Hunk_AllocName(gl_warpimagesize * gl_warpimagesize * 4, "temporary check"); //make sure hunk is big enough so we don't reach an illegal address
Hunk_FreeToLowMark(mark);
q_snprintf(texturename, sizeof(texturename), "%s_warp", texturename);
tx->warpimage = TexMgr_LoadImage(loadmodel, texturename, gl_warpimagesize,
@ -1083,7 +1083,7 @@ void Mod_PolyForUnlitSurface(msurface_t *fa)
}
//create the poly
poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float));
poly = Hunk_AllocName(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float), __func__);
poly->next = NULL;
fa->polys = poly;
poly->numverts = numverts;

View File

@ -56,7 +56,7 @@ entity_t *r_addent;
// based on RMQEngine
static efrag_t *R_GetEfrag(void)
{
// we could just Hunk_Alloc a single efrag_t and return it, but since
// we could just allocate a single efrag_t and return it, but since
// the struct is so small (2 pointers) allocate groups of them
// to avoid wasting too much space on the hunk allocation headers.

View File

@ -98,8 +98,8 @@ void Sky_LoadTexture(texture_t *mt)
char texturename[64];
int32_t i, j, p, r, g, b, count;
byte *src;
static byte front_data[128 * 128]; //FIXME: Hunk_Alloc
static byte back_data[128 * 128]; //FIXME: Hunk_Alloc
static byte front_data[128 * 128]; //FIXME: dynamically allocate
static byte back_data[128 * 128]; //FIXME: dynamically allocate
unsigned *rgba;
src = (byte *)mt + mt->offsets[0];
@ -609,7 +609,7 @@ void Sky_ProcessEntities(void)
{
//copy the polygon and translate manually, since Sky_ProcessPoly needs it to be in world space
mark = Hunk_LowMark();
p = (glpoly_t *) Hunk_Alloc(sizeof(*s->polys)); //FIXME: don't allocate for each poly
p = Hunk_AllocName(sizeof(*s->polys), __func__); //FIXME: don't allocate for each poly
p->numverts = s->polys->numverts;
for(k = 0; k < p->numverts; k++)
{
@ -908,7 +908,7 @@ void Sky_DrawFace(int32_t axis)
Sky_SetBoxVert(1.0, -1.0, axis, verts[3]);
start = Hunk_LowMark();
p = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t));
p = Hunk_AllocName(sizeof(glpoly_t), __func__);
VectorSubtract(verts[2], verts[3], vup);
VectorSubtract(verts[2], verts[1], vright);

View File

@ -474,7 +474,7 @@ void TexMgr_LoadPalette(void)
Sys_Error("Couldn't load gfx/palette.lmp");
mark = Hunk_LowMark();
pal = (byte *) Hunk_Alloc(768);
pal = Hunk_AllocName(768, __func__);
fread(pal, 1, 768, f);
fclose(f);
@ -576,7 +576,7 @@ void TexMgr_RecalcWarpImageSize(void)
// resize the textures in opengl
mark = Hunk_LowMark();
dummy = (byte *) Hunk_Alloc(gl_warpimagesize * gl_warpimagesize * 4);
dummy = Hunk_AllocName(gl_warpimagesize * gl_warpimagesize * 4, __func__);
for(glt = active_gltextures; glt; glt = glt->next)
{
@ -760,7 +760,7 @@ static unsigned *TexMgr_ResampleTexture(unsigned *in, int32_t inwidth, int32_t i
outwidth = TexMgr_Pad(inwidth);
outheight = TexMgr_Pad(inheight);
out = (unsigned *) Hunk_Alloc(outwidth * outheight * 4);
out = Hunk_AllocName(outwidth * outheight * 4, __func__);
xfrac = ((inwidth - 1) << 16) / (outwidth - 1);
yfrac = ((inheight - 1) << 16) / (outheight - 1);
@ -998,7 +998,7 @@ static unsigned *TexMgr_8to32(byte *in, int32_t pixels, uint32_t *usepal)
int32_t i;
unsigned *out, *data;
out = data = (unsigned *) Hunk_Alloc(pixels * 4);
out = data = Hunk_AllocName(pixels * 4, __func__);
for(i = 0; i < pixels; i++)
*out++ = usepal[*in++];
@ -1021,7 +1021,7 @@ static byte *TexMgr_PadImageW(byte *in, int32_t width, int32_t height, byte padb
outwidth = TexMgr_Pad(width);
out = data = (byte *) Hunk_Alloc(outwidth * height);
out = data = Hunk_AllocName(outwidth * height, __func__);
for(i = 0; i < height; i++)
{
@ -1050,7 +1050,7 @@ static byte *TexMgr_PadImageH(byte *in, int32_t width, int32_t height, byte padb
srcpix = width * height;
dstpix = width * TexMgr_Pad(height);
out = data = (byte *) Hunk_Alloc(dstpix);
out = data = Hunk_AllocName(dstpix, __func__);
for(i = 0; i < srcpix; i++)
*out++ = *in++;
@ -1349,7 +1349,7 @@ void TexMgr_ReloadImage(gltexture_t *glt, int32_t shirt, int32_t pants)
size *= 4;
else if(glt->source_format == SRC_LIGHTMAP)
size *= lightmap_bytes;
data = (byte *) Hunk_Alloc(size);
data = Hunk_AllocName(size, __func__);
fread(data, 1, size, f);
fclose(f);
}
@ -1415,7 +1415,7 @@ invalid:
//translate texture
size = glt->width * glt->height;
dst = translated = (byte *) Hunk_Alloc(size);
dst = translated = Hunk_AllocName(size, __func__);
src = data;
for(i = 0; i < size; i++)

View File

@ -138,7 +138,7 @@ void SubdividePolygon(int32_t numverts, float *verts)
return;
}
poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float));
poly = Hunk_AllocName(sizeof(glpoly_t) + (numverts - 4) * VERTEXSIZE * sizeof(float), __func__);
poly->next = warpface->polys->next;
warpface->polys->next = poly;
poly->numverts = numverts;

View File

@ -826,7 +826,6 @@ void Host_Init(void)
Cmd_Init();
LOG_Init(host_parms);
Cvar_Init(); //johnfitz
COM_Init();
COM_InitFilesystem();
Host_InitLocal();
W_LoadWadFile(); //johnfitz -- filename is now hard-coded for honesty

View File

@ -113,28 +113,17 @@ typedef struct targaheader_s
#define TARGAHEADERSIZE 18 //size on disk
targaheader_t targa_header;
static targaheader_t targa_header;
int32_t fgetLittleShort(FILE *f)
static int32_t fgetLittleShort(FILE *f)
{
byte b1, b2;
size_t i;
byte b[2];
b1 = fgetc(f);
b2 = fgetc(f);
for(i = 0; i < sizeof(b); i++)
b[i] = fgetc(f);
return (int16_t)(b1 + b2 * 256);
}
int32_t fgetLittleLong(FILE *f)
{
byte b1, b2, b3, b4;
b1 = fgetc(f);
b2 = fgetc(f);
b3 = fgetc(f);
b4 = fgetc(f);
return b1 + (b2 << 8) + (b3 << 16) + (b4 << 24);
return LittleShort(BytesShort(b));
}
/*
@ -225,7 +214,7 @@ byte *Image_LoadTGA(FILE *fin, int32_t *width, int32_t *height)
numPixels = columns * rows;
upside_down = !(targa_header.attributes & 0x20); //johnfitz -- fix for upside-down targas
targa_rgba = (byte *) Hunk_Alloc(numPixels * 4);
targa_rgba = Hunk_AllocName(numPixels * 4, __func__);
if(targa_header.id_length != 0)
fseek(fin, targa_header.id_length, SEEK_CUR); // skip TARGA image comment
@ -435,7 +424,7 @@ byte *Image_LoadPCX(FILE *f, int32_t *width, int32_t *height)
w = pcx.xmax - pcx.xmin + 1;
h = pcx.ymax - pcx.ymin + 1;
data = (byte *) Hunk_Alloc((w * h + 1) * 4); //+1 to allow reading padding byte on last line
data = Hunk_AllocName((w * h + 1) * 4, __func__); //+1 to allow reading padding byte on last line
//load palette
fseek(f, start + com_filesize - 768, SEEK_SET);

View File

@ -139,7 +139,7 @@ int32_t Loop_GetMessage(qsocket_t *sock)
return 0;
ret = sock->receiveMessage[0];
length = sock->receiveMessage[1] + (sock->receiveMessage[2] << 8);
length = LittleShort(BytesShort(&sock->receiveMessage[1]));
// alignment byte skipped here
SZ_Clear(&net_message);
SZ_Write(&net_message, &sock->receiveMessage[4], length);

View File

@ -35,8 +35,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define DEF_SAVEGLOBAL (1 << 15)
#define MAX_PARMS 8
#define PROG_VERSION 6
typedef int32_t func_t;
@ -134,7 +132,7 @@ enum
OP_BITOR
};
typedef struct statement_s
typedef struct
{
uint16_t op;
int16_t a, b, c;
@ -159,7 +157,7 @@ typedef struct
int32_t s_file; // source file defined in
int32_t numparms;
byte parm_size[MAX_PARMS];
byte parm_size[8];
} dfunction_t;
typedef struct

View File

@ -26,13 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
dprograms_t progs;
dfunction_t *pr_functions;
static char *pr_strings;
static int32_t pr_stringssize;
static const char **pr_knownstrings;
static int32_t pr_maxknownstrings;
static int32_t pr_numknownstrings;
static ddef_t *pr_fielddefs;
static ddef_t *pr_globaldefs;
ddef_t *pr_fielddefs;
bool pr_alpha_supported; //johnfitz
@ -55,9 +49,6 @@ static int32_t type_size[] =
[ev_pointer] = 1,
};
static ddef_t *ED_FieldAtOfs(int32_t ofs);
static bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 2
@ -73,18 +64,6 @@ static gefv_cache gefvCache[GEFV_CACHESIZE] =
{ NULL, "" }
};
cvar_t nomonsters = {"nomonsters", "0", CVAR_NONE};
cvar_t gamecfg = {"gamecfg", "0", CVAR_NONE};
cvar_t scratch1 = {"scratch1", "0", CVAR_NONE};
cvar_t scratch2 = {"scratch2", "0", CVAR_NONE};
cvar_t scratch3 = {"scratch3", "0", CVAR_NONE};
cvar_t scratch4 = {"scratch4", "0", CVAR_NONE};
cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
/*
=================
ED_ClearEdict
@ -171,7 +150,7 @@ void ED_Free(edict_t *ed)
ED_GlobalAtOfs
============
*/
static ddef_t *ED_GlobalAtOfs(int32_t ofs)
ddef_t *ED_GlobalAtOfs(int32_t ofs)
{
ddef_t *def;
int32_t i;
@ -190,7 +169,7 @@ static ddef_t *ED_GlobalAtOfs(int32_t ofs)
ED_FieldAtOfs
============
*/
static ddef_t *ED_FieldAtOfs(int32_t ofs)
ddef_t *ED_FieldAtOfs(int32_t ofs)
{
ddef_t *def;
int32_t i;
@ -300,163 +279,6 @@ Done:
}
/*
============
PR_ValueString
(etype_t type, eval_t *val)
Returns a string describing *data in a type specific manner
=============
*/
static const char *PR_ValueString(int32_t type, eval_t *val)
{
static char line[512];
ddef_t *def;
dfunction_t *f;
type &= ~DEF_SAVEGLOBAL;
switch(type)
{
case ev_string:
sprintf(line, "%s", PR_GetString(val->string));
break;
case ev_entity:
sprintf(line, "entity %" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
break;
case ev_function:
f = pr_functions + val->function;
sprintf(line, "%s()", PR_GetString(f->s_name));
break;
case ev_field:
def = ED_FieldAtOfs(val->_int);
sprintf(line, ".%s", PR_GetString(def->s_name));
break;
case ev_void:
sprintf(line, "void");
break;
case ev_float:
sprintf(line, "%5.1f", val->_float);
break;
case ev_vector:
sprintf(line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]);
break;
case ev_pointer:
sprintf(line, "pointer");
break;
default:
sprintf(line, "bad type %" PRIi32 "", type);
break;
}
return line;
}
/*
============
PR_UglyValueString
(etype_t type, eval_t *val)
Returns a string describing *data in a type specific manner
Easier to parse than PR_ValueString
=============
*/
static const char *PR_UglyValueString(int32_t type, eval_t *val)
{
static char line[512];
ddef_t *def;
dfunction_t *f;
type &= ~DEF_SAVEGLOBAL;
switch(type)
{
case ev_string:
sprintf(line, "%s", PR_GetString(val->string));
break;
case ev_entity:
sprintf(line, "%" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
break;
case ev_function:
f = pr_functions + val->function;
sprintf(line, "%s", PR_GetString(f->s_name));
break;
case ev_field:
def = ED_FieldAtOfs(val->_int);
sprintf(line, "%s", PR_GetString(def->s_name));
break;
case ev_void:
sprintf(line, "void");
break;
case ev_float:
sprintf(line, "%f", val->_float);
break;
case ev_vector:
sprintf(line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
break;
default:
sprintf(line, "bad type %" PRIi32 "", type);
break;
}
return line;
}
/*
============
PR_GlobalString
Returns a string with a description and the contents of a global,
padded to 20 field width
============
*/
const char *PR_GlobalString(int32_t ofs)
{
static char line[512];
const char *s;
int32_t i;
ddef_t *def;
void *val;
val = &pr_globals[ofs];
def = ED_GlobalAtOfs(ofs);
if(!def)
sprintf(line, "%" PRIi32 "(?)", ofs);
else
{
s = PR_ValueString(def->type, (eval_t *)val);
sprintf(line, "%" PRIi32 "(%s)%s", ofs, PR_GetString(def->s_name), s);
}
i = strlen(line);
for(; i < 20; i++)
strcat(line, " ");
strcat(line, " ");
return line;
}
const char *PR_GlobalStringNoContents(int32_t ofs)
{
static char line[512];
int32_t i;
ddef_t *def;
def = ED_GlobalAtOfs(ofs);
if(!def)
sprintf(line, "%" PRIi32 "(?)", ofs);
else
sprintf(line, "%" PRIi32 "(%s)", ofs, PR_GetString(def->s_name));
i = strlen(line);
for(; i < 20; i++)
strcat(line, " ");
strcat(line, " ");
return line;
}
/*
=============
ED_Print
@ -773,7 +595,7 @@ Can parse either fields or globals
returns false if error
=============
*/
static bool ED_ParseEpair(void *base, ddef_t *key, const char *s)
bool ED_ParseEpair(void *base, ddef_t *key, const char *s)
{
int32_t i;
char string[128];
@ -1042,164 +864,22 @@ void ED_LoadFromFile(const char *data)
Con_DPrintf("%" PRIi32 " entities inhibited\n", inhibit);
}
static void PR_LoadProgHeader(byte *prog_data)
void ED_Load(void)
{
progs.version = ReadLittleLong(&prog_data[4 * 0]);
progs.crc = ReadLittleLong(&prog_data[4 * 1]);
progs.ofs_statements = ReadLittleLong(&prog_data[4 * 2]);
progs.numstatements = ReadLittleLong(&prog_data[4 * 3]);
progs.ofs_globaldefs = ReadLittleLong(&prog_data[4 * 4]);
progs.numglobaldefs = ReadLittleLong(&prog_data[4 * 5]);
progs.ofs_fielddefs = ReadLittleLong(&prog_data[4 * 6]);
progs.numfielddefs = ReadLittleLong(&prog_data[4 * 7]);
progs.ofs_functions = ReadLittleLong(&prog_data[4 * 8]);
progs.numfunctions = ReadLittleLong(&prog_data[4 * 9]);
progs.ofs_strings = ReadLittleLong(&prog_data[4 * 10]);
progs.numstrings = ReadLittleLong(&prog_data[4 * 11]);
progs.ofs_globals = ReadLittleLong(&prog_data[4 * 12]);
progs.numglobals = ReadLittleLong(&prog_data[4 * 13]);
progs.entityfields = ReadLittleLong(&prog_data[4 * 14]);
if(progs.version != PROG_VERSION)
Host_Error("progs.dat has wrong version number (%" PRIi32 " should be %" PRIi32 ")", progs.version, PROG_VERSION);
if(progs.crc != PROGHEADER_CRC)
Host_Error("progs.dat system vars have been modified, progdefs.h is out of date");
}
/*
===============
PR_LoadProgs
===============
*/
void PR_LoadProgs(void)
{
byte *prog_data;
int32_t i;
// flush the non-C variable lookup cache
for(i = 0; i < GEFV_CACHESIZE; i++)
gefvCache[i].field[0] = 0;
CRC_Init(&pr_crc);
prog_data = COM_LoadHunkFile("progs.dat", NULL);
if(!prog_data)
Host_Error("PR_LoadProgs: couldn't load progs.dat");
Con_DPrintf("Programs occupy %" PRIi32 "K.\n", com_filesize / 1024);
for(i = 0; i < com_filesize; i++)
CRC_ProcessByte(&pr_crc, prog_data[i]);
PR_LoadProgHeader(prog_data);
pr_functions = (dfunction_t *)&prog_data[progs.ofs_functions];
pr_strings = (char *)&prog_data[progs.ofs_strings];
if(progs.ofs_strings + progs.numstrings >= com_filesize)
Host_Error("progs.dat strings go past end of file\n");
// initialize the strings
pr_numknownstrings = 0;
pr_maxknownstrings = 0;
pr_stringssize = progs.numstrings;
if(pr_knownstrings)
Z_Free(pr_knownstrings);
pr_knownstrings = NULL;
PR_SetEngineString("");
pr_globaldefs = (ddef_t *)&prog_data[progs.ofs_globaldefs];
pr_fielddefs = (ddef_t *)&prog_data[progs.ofs_fielddefs];
pr_statements = (dstatement_t *)&prog_data[progs.ofs_statements];
pr_global_struct = (globalvars_t *)&prog_data[progs.ofs_globals];
pr_globals = (float *)pr_global_struct;
// byte swap the lumps
for(i = 0; i < progs.numstatements; i++)
{
pr_statements[i].op = LittleShort(pr_statements[i].op);
pr_statements[i].a = LittleShort(pr_statements[i].a);
pr_statements[i].b = LittleShort(pr_statements[i].b);
pr_statements[i].c = LittleShort(pr_statements[i].c);
}
for(i = 0; i < progs.numfunctions; i++)
{
pr_functions[i].first_statement = LittleLong(pr_functions[i].first_statement);
pr_functions[i].parm_start = LittleLong(pr_functions[i].parm_start);
pr_functions[i].s_name = LittleLong(pr_functions[i].s_name);
pr_functions[i].s_file = LittleLong(pr_functions[i].s_file);
pr_functions[i].numparms = LittleLong(pr_functions[i].numparms);
pr_functions[i].locals = LittleLong(pr_functions[i].locals);
}
for(i = 0; i < progs.numglobaldefs; i++)
{
pr_globaldefs[i].type = LittleShort(pr_globaldefs[i].type);
pr_globaldefs[i].ofs = LittleShort(pr_globaldefs[i].ofs);
pr_globaldefs[i].s_name = LittleLong(pr_globaldefs[i].s_name);
}
pr_alpha_supported = false; //johnfitz
for(i = 0; i < progs.numfielddefs; i++)
{
pr_fielddefs[i].type = LittleShort(pr_fielddefs[i].type);
if(pr_fielddefs[i].type & DEF_SAVEGLOBAL)
Host_Error("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
pr_fielddefs[i].ofs = LittleShort(pr_fielddefs[i].ofs);
pr_fielddefs[i].s_name = LittleLong(pr_fielddefs[i].s_name);
//johnfitz -- detect alpha support
if(!strcmp(pr_strings + pr_fielddefs[i].s_name, "alpha"))
pr_alpha_supported = true;
//johnfitz
}
for(i = 0; i < progs.numglobals; i++)
((int32_t *)pr_globals)[i] = LittleLong(((int32_t *)pr_globals)[i]);
pr_edict_size = progs.entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t);
// round off to next highest whole word address (esp for Alpha)
// this ensures that pointers in the engine data area are always
// properly aligned
pr_edict_size += sizeof(void *) - 1;
pr_edict_size &= ~(sizeof(void *) - 1);
}
/*
===============
PR_Init
===============
*/
void PR_Init(void)
void ED_Init(void)
{
Cmd_AddCommand("edict", ED_PrintEdict_f);
Cmd_AddCommand("edicts", ED_PrintEdicts);
Cmd_AddCommand("edictcount", ED_Count);
Cmd_AddCommand("profile", PR_Profile_f);
Cvar_RegisterVariable(&nomonsters);
Cvar_RegisterVariable(&gamecfg);
Cvar_RegisterVariable(&scratch1);
Cvar_RegisterVariable(&scratch2);
Cvar_RegisterVariable(&scratch3);
Cvar_RegisterVariable(&scratch4);
Cvar_RegisterVariable(&savedgamecfg);
Cvar_RegisterVariable(&saved1);
Cvar_RegisterVariable(&saved2);
Cvar_RegisterVariable(&saved3);
Cvar_RegisterVariable(&saved4);
}
edict_t *EDICT_NUM(int32_t n)
{
if(n < 0 || n >= sv.max_edicts)
@ -1218,79 +898,3 @@ int32_t NUM_FOR_EDICT(edict_t *e)
Host_Error("NUM_FOR_EDICT: bad pointer");
return b;
}
//===========================================================================
#define PR_STRING_ALLOCSLOTS 256
static void PR_AllocStringSlots(void)
{
pr_maxknownstrings += PR_STRING_ALLOCSLOTS;
Con_DPrintf2("PR_AllocStringSlots: realloc'ing for %" PRIi32 " slots\n", pr_maxknownstrings);
pr_knownstrings = (const char **) Z_Realloc(pr_knownstrings, pr_maxknownstrings * sizeof(char *));
}
const char *PR_GetString(int32_t num)
{
if(num >= 0 && num < pr_stringssize)
return pr_strings + num;
else if(num < 0 && num >= -pr_numknownstrings)
{
if(!pr_knownstrings[-1 - num])
{
Host_Error("PR_GetString: attempt to get a non-existant string %" PRIi32 "\n", num);
return "";
}
return pr_knownstrings[-1 - num];
}
else
{
Host_Error("PR_GetString: invalid string offset %" PRIi32 "\n", num);
return "";
}
}
int32_t PR_SetEngineString(const char *s)
{
int32_t i;
if(!s)
return 0;
if(s >= pr_strings && s <= pr_strings + pr_stringssize - 2)
return (int32_t)(s - pr_strings);
for(i = 0; i < pr_numknownstrings; i++)
{
if(pr_knownstrings[i] == s)
return -1 - i;
}
if(i >= pr_maxknownstrings)
PR_AllocStringSlots();
pr_numknownstrings++;
pr_knownstrings[i] = s;
return -1 - i;
}
int32_t PR_AllocString(int32_t size, char **ptr)
{
int32_t i;
if(!size)
return 0;
for(i = 0; i < pr_numknownstrings; i++)
{
if(!pr_knownstrings[i])
break;
}
// if (i >= pr_numknownstrings)
// {
if(i >= pr_maxknownstrings)
PR_AllocStringSlots();
pr_numknownstrings++;
// }
pr_knownstrings[i] = (char *)Hunk_AllocName(size, "string");
if(ptr)
*ptr = (char *) pr_knownstrings[i];
return -1 - i;
}

191
source/pr_load.c Normal file
View File

@ -0,0 +1,191 @@
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2010-2014 QuakeSpasm developers
Copyright (C) 2019 Alison G. Watson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "q_defs.h"
ddef_t *pr_globaldefs;
cvar_t nomonsters = {"nomonsters", "0", CVAR_NONE};
cvar_t gamecfg = {"gamecfg", "0", CVAR_NONE};
cvar_t scratch1 = {"scratch1", "0", CVAR_NONE};
cvar_t scratch2 = {"scratch2", "0", CVAR_NONE};
cvar_t scratch3 = {"scratch3", "0", CVAR_NONE};
cvar_t scratch4 = {"scratch4", "0", CVAR_NONE};
cvar_t savedgamecfg = {"savedgamecfg", "0", CVAR_ARCHIVE};
cvar_t saved1 = {"saved1", "0", CVAR_ARCHIVE};
cvar_t saved2 = {"saved2", "0", CVAR_ARCHIVE};
cvar_t saved3 = {"saved3", "0", CVAR_ARCHIVE};
cvar_t saved4 = {"saved4", "0", CVAR_ARCHIVE};
static void PR_LoadProgHeader(byte *prog_data)
{
progs.version = ReadLittleLong(&prog_data[4 * 0]);
progs.crc = ReadLittleLong(&prog_data[4 * 1]);
progs.ofs_statements = ReadLittleLong(&prog_data[4 * 2]);
progs.numstatements = ReadLittleLong(&prog_data[4 * 3]);
progs.ofs_globaldefs = ReadLittleLong(&prog_data[4 * 4]);
progs.numglobaldefs = ReadLittleLong(&prog_data[4 * 5]);
progs.ofs_fielddefs = ReadLittleLong(&prog_data[4 * 6]);
progs.numfielddefs = ReadLittleLong(&prog_data[4 * 7]);
progs.ofs_functions = ReadLittleLong(&prog_data[4 * 8]);
progs.numfunctions = ReadLittleLong(&prog_data[4 * 9]);
progs.ofs_strings = ReadLittleLong(&prog_data[4 * 10]);
progs.numstrings = ReadLittleLong(&prog_data[4 * 11]);
progs.ofs_globals = ReadLittleLong(&prog_data[4 * 12]);
progs.numglobals = ReadLittleLong(&prog_data[4 * 13]);
progs.entityfields = ReadLittleLong(&prog_data[4 * 14]);
if(progs.version != PROG_VERSION)
Host_Error("progs.dat has wrong version number (%" PRIi32 " should be %" PRIi32 ")", progs.version, PROG_VERSION);
if(progs.crc != PROGHEADER_CRC)
Host_Error("progs.dat system vars have been modified, progdefs.h is out of date");
}
/*
===============
PR_LoadProgs
===============
*/
void PR_LoadProgs(void)
{
byte *prog_data;
int32_t i;
ED_Load();
CRC_Init(&pr_crc);
prog_data = COM_LoadHunkFile("progs.dat", NULL);
if(!prog_data)
Host_Error("PR_LoadProgs: couldn't load progs.dat");
Con_DPrintf("Programs occupy %" PRIi32 "K.\n", com_filesize / 1024);
for(i = 0; i < com_filesize; i++)
CRC_ProcessByte(&pr_crc, prog_data[i]);
PR_LoadProgHeader(prog_data);
pr_functions = (dfunction_t *)&prog_data[progs.ofs_functions];
pr_strings = (char const *)&prog_data[progs.ofs_strings];
if(progs.ofs_strings + progs.numstrings >= com_filesize)
Host_Error("progs.dat strings go past end of file\n");
// initialize the strings
pr_numknownstrings = 0;
pr_maxknownstrings = 0;
if(pr_knownstrings)
Z_Free(pr_knownstrings);
pr_knownstrings = NULL;
PR_SetEngineString("");
pr_globaldefs = (ddef_t *)&prog_data[progs.ofs_globaldefs];
pr_fielddefs = (ddef_t *)&prog_data[progs.ofs_fielddefs];
pr_statements = (dstatement_t *)&prog_data[progs.ofs_statements];
pr_global_struct = (globalvars_t *)&prog_data[progs.ofs_globals];
pr_globals = (float *)pr_global_struct;
// byte swap the lumps
for(i = 0; i < progs.numstatements; i++)
{
pr_statements[i].op = LittleShort(pr_statements[i].op);
pr_statements[i].a = LittleShort(pr_statements[i].a);
pr_statements[i].b = LittleShort(pr_statements[i].b);
pr_statements[i].c = LittleShort(pr_statements[i].c);
}
for(i = 0; i < progs.numfunctions; i++)
{
pr_functions[i].first_statement = LittleLong(pr_functions[i].first_statement);
pr_functions[i].parm_start = LittleLong(pr_functions[i].parm_start);
pr_functions[i].s_name = LittleLong(pr_functions[i].s_name);
pr_functions[i].s_file = LittleLong(pr_functions[i].s_file);
pr_functions[i].numparms = LittleLong(pr_functions[i].numparms);
pr_functions[i].locals = LittleLong(pr_functions[i].locals);
}
for(i = 0; i < progs.numglobaldefs; i++)
{
pr_globaldefs[i].type = LittleShort(pr_globaldefs[i].type);
pr_globaldefs[i].ofs = LittleShort(pr_globaldefs[i].ofs);
pr_globaldefs[i].s_name = LittleLong(pr_globaldefs[i].s_name);
}
pr_alpha_supported = false; //johnfitz
for(i = 0; i < progs.numfielddefs; i++)
{
pr_fielddefs[i].type = LittleShort(pr_fielddefs[i].type);
if(pr_fielddefs[i].type & DEF_SAVEGLOBAL)
Host_Error("PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
pr_fielddefs[i].ofs = LittleShort(pr_fielddefs[i].ofs);
pr_fielddefs[i].s_name = LittleLong(pr_fielddefs[i].s_name);
//johnfitz -- detect alpha support
if(!strcmp(pr_strings + pr_fielddefs[i].s_name, "alpha"))
pr_alpha_supported = true;
//johnfitz
}
for(i = 0; i < progs.numglobals; i++)
((int32_t *)pr_globals)[i] = LittleLong(((int32_t *)pr_globals)[i]);
pr_edict_size = progs.entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t);
// round off to next highest whole word address (esp for Alpha)
// this ensures that pointers in the engine data area are always
// properly aligned
pr_edict_size += sizeof(void *) - 1;
pr_edict_size &= ~(sizeof(void *) - 1);
}
/*
===============
PR_Init
===============
*/
void PR_Init(void)
{
ED_Init();
Cmd_AddCommand("profile", PR_Profile_f);
Cvar_RegisterVariable(&nomonsters);
Cvar_RegisterVariable(&gamecfg);
Cvar_RegisterVariable(&scratch1);
Cvar_RegisterVariable(&scratch2);
Cvar_RegisterVariable(&scratch3);
Cvar_RegisterVariable(&scratch4);
Cvar_RegisterVariable(&savedgamecfg);
Cvar_RegisterVariable(&saved1);
Cvar_RegisterVariable(&saved2);
Cvar_RegisterVariable(&saved3);
Cvar_RegisterVariable(&saved4);
}

260
source/pr_string.c Normal file
View File

@ -0,0 +1,260 @@
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
Copyright (C) 2010-2014 QuakeSpasm developers
Copyright (C) 2019 Alison G. Watson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "q_defs.h"
char const *pr_strings;
char const **pr_knownstrings;
int32_t pr_maxknownstrings;
int32_t pr_numknownstrings;
/*
============
PR_ValueString
(etype_t type, eval_t *val)
Returns a string describing *data in a type specific manner
=============
*/
const char *PR_ValueString(int32_t type, eval_t *val)
{
static char line[512];
ddef_t *def;
dfunction_t *f;
type &= ~DEF_SAVEGLOBAL;
switch(type)
{
case ev_string:
sprintf(line, "%s", PR_GetString(val->string));
break;
case ev_entity:
sprintf(line, "entity %" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
break;
case ev_function:
f = pr_functions + val->function;
sprintf(line, "%s()", PR_GetString(f->s_name));
break;
case ev_field:
def = ED_FieldAtOfs(val->_int);
sprintf(line, ".%s", PR_GetString(def->s_name));
break;
case ev_void:
sprintf(line, "void");
break;
case ev_float:
sprintf(line, "%5.1f", val->_float);
break;
case ev_vector:
sprintf(line, "'%5.1f %5.1f %5.1f'", val->vector[0], val->vector[1], val->vector[2]);
break;
case ev_pointer:
sprintf(line, "pointer");
break;
default:
sprintf(line, "bad type %" PRIi32 "", type);
break;
}
return line;
}
/*
============
PR_UglyValueString
(etype_t type, eval_t *val)
Returns a string describing *data in a type specific manner
Easier to parse than PR_ValueString
=============
*/
const char *PR_UglyValueString(int32_t type, eval_t *val)
{
static char line[512];
ddef_t *def;
dfunction_t *f;
type &= ~DEF_SAVEGLOBAL;
switch(type)
{
case ev_string:
sprintf(line, "%s", PR_GetString(val->string));
break;
case ev_entity:
sprintf(line, "%" PRIi32 "", NUM_FOR_EDICT(PROG_TO_EDICT(val->edict)));
break;
case ev_function:
f = pr_functions + val->function;
sprintf(line, "%s", PR_GetString(f->s_name));
break;
case ev_field:
def = ED_FieldAtOfs(val->_int);
sprintf(line, "%s", PR_GetString(def->s_name));
break;
case ev_void:
sprintf(line, "void");
break;
case ev_float:
sprintf(line, "%f", val->_float);
break;
case ev_vector:
sprintf(line, "%f %f %f", val->vector[0], val->vector[1], val->vector[2]);
break;
default:
sprintf(line, "bad type %" PRIi32 "", type);
break;
}
return line;
}
/*
============
PR_GlobalString
Returns a string with a description and the contents of a global,
padded to 20 field width
============
*/
const char *PR_GlobalString(int32_t ofs)
{
static char line[512];
const char *s;
int32_t i;
ddef_t *def;
void *val;
val = &pr_globals[ofs];
def = ED_GlobalAtOfs(ofs);
if(!def)
sprintf(line, "%" PRIi32 "(?)", ofs);
else
{
s = PR_ValueString(def->type, (eval_t *)val);
sprintf(line, "%" PRIi32 "(%s)%s", ofs, PR_GetString(def->s_name), s);
}
i = strlen(line);
for(; i < 20; i++)
strcat(line, " ");
strcat(line, " ");
return line;
}
const char *PR_GlobalStringNoContents(int32_t ofs)
{
static char line[512];
int32_t i;
ddef_t *def;
def = ED_GlobalAtOfs(ofs);
if(!def)
sprintf(line, "%" PRIi32 "(?)", ofs);
else
sprintf(line, "%" PRIi32 "(%s)", ofs, PR_GetString(def->s_name));
i = strlen(line);
for(; i < 20; i++)
strcat(line, " ");
strcat(line, " ");
return line;
}
//===========================================================================
#define PR_STRING_ALLOCSLOTS 256
static void PR_AllocStringSlots(void)
{
pr_maxknownstrings += PR_STRING_ALLOCSLOTS;
Con_DPrintf2("PR_AllocStringSlots: realloc'ing for %" PRIi32 " slots\n", pr_maxknownstrings);
pr_knownstrings = (const char **) Z_Realloc(pr_knownstrings, pr_maxknownstrings * sizeof(char *));
}
const char *PR_GetString(int32_t num)
{
if(num >= 0 && num < progs.numstrings)
return pr_strings + num;
else if(num < 0 && num >= -pr_numknownstrings)
{
if(!pr_knownstrings[-1 - num])
{
Host_Error("PR_GetString: attempt to get a non-existant string %" PRIi32 "\n", num);
return "";
}
return pr_knownstrings[-1 - num];
}
else
{
Host_Error("PR_GetString: invalid string offset %" PRIi32 "\n", num);
return "";
}
}
int32_t PR_SetEngineString(const char *s)
{
int32_t i;
if(!s)
return 0;
if(s >= pr_strings && s <= pr_strings + progs.numstrings - 2)
return (int32_t)(s - pr_strings);
for(i = 0; i < pr_numknownstrings; i++)
{
if(pr_knownstrings[i] == s)
return -1 - i;
}
if(i >= pr_maxknownstrings)
PR_AllocStringSlots();
pr_numknownstrings++;
pr_knownstrings[i] = s;
return -1 - i;
}
int32_t PR_AllocString(int32_t size, char **ptr)
{
int32_t i;
if(!size)
return 0;
for(i = 0; i < pr_numknownstrings; i++)
{
if(!pr_knownstrings[i])
break;
}
if(i >= pr_maxknownstrings)
PR_AllocStringSlots();
pr_numknownstrings++;
pr_knownstrings[i] = (char *)Hunk_AllocName(size, "string");
if(ptr)
*ptr = (char *) pr_knownstrings[i];
return -1 - i;
}

View File

@ -65,8 +65,18 @@ extern dstatement_t *pr_statements;
extern globalvars_t *pr_global_struct;
extern float *pr_globals;
extern ddef_t *pr_fielddefs;
extern int32_t pr_edict_size;
extern char const *pr_strings;
extern char const **pr_knownstrings;
extern int32_t pr_maxknownstrings;
extern int32_t pr_numknownstrings;
extern ddef_t *pr_globaldefs;
const char *PR_ValueString(int32_t type, eval_t *val);
const char *PR_UglyValueString(int32_t type, eval_t *val);
void PR_Init(void);
@ -91,6 +101,13 @@ const char *ED_ParseGlobals(const char *data);
void ED_LoadFromFile(const char *data);
ddef_t *ED_GlobalAtOfs(int32_t ofs);
ddef_t *ED_FieldAtOfs(int32_t ofs);
bool ED_ParseEpair(void *base, ddef_t *key, const char *s);
void ED_Init(void);
void ED_Load(void);
edict_t *EDICT_NUM(int32_t n);
int32_t NUM_FOR_EDICT(edict_t *e);
@ -120,6 +137,8 @@ extern int32_t pr_xstatement;
extern uint16_t pr_crc;
extern bool pr_alpha_supported; //johnfitz
noreturn void PR_RunError(const char *error, ...) FUNC_PRINTF(1, 2);
void ED_PrintEdicts(void);

View File

@ -444,7 +444,7 @@ void BuildSurfaceDisplayList(msurface_t *fa)
//
// draw texture
//
poly = (glpoly_t *) Hunk_Alloc(sizeof(glpoly_t) + (lnumverts - 4) * VERTEXSIZE * sizeof(float));
poly = Hunk_AllocName(sizeof(glpoly_t) + (lnumverts - 4) * VERTEXSIZE * sizeof(float), __func__);
poly->next = fa->polys;
fa->polys = poly;
poly->numverts = lnumverts;

36
source/sdl/endian_sdl.h Normal file
View File

@ -0,0 +1,36 @@
/*
Copyright (C) 2019 Alison G. Watson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef spingle__endian_sdl_h
#define spingle__endian_sdl_h
#include <SDL_endian.h>
#define HOST_BIGENDIAN (SDL_BYTEORDER == SDL_BIG_ENDIAN)
#define BigShort SDL_SwapBE16
#define BigLong SDL_SwapBE32
#define BigFloat SDL_SwapFloatBE
#define LittleShort SDL_SwapLE16
#define LittleLong SDL_SwapLE32
#define LittleFloat SDL_SwapFloatLE
#endif

View File

@ -246,8 +246,7 @@ static void VID_Gamma_f(cvar_t *var)
for(i = 0; i < 256; i++)
{
vid_gamma_red[i] =
CLAMP(0, (int32_t)((255 * pow((i + 0.5) / 255.5, vid_gamma.value) + 0.5) * vid_contrast.value), 255) << 8;
vid_gamma_red[i] = CLAMP(0, (int32_t)((255 * pow((i + 0.5) / 255.5, vid_gamma.value) + 0.5) * vid_contrast.value), 255) << 8;
vid_gamma_green[i] = vid_gamma_red[i];
vid_gamma_blue[i] = vid_gamma_red[i];
}

View File

@ -100,8 +100,8 @@ static inline bool tag_is_apetag(const uint8_t *data, size_t length)
if(length < 32) return false;
if(memcmp(data, "APETAGEX", 8) != 0)
return false;
v = (data[11] << 24) | (data[10] << 16) | (data[9] << 8) | data[8];
if(v != 2000U/* && v != 1000U*/)
v = LittleLong(BytesLong(&data[8]));
if(v != 2000)
return false;
v = 0;
if(memcmp(&data[24], &v, 4) != 0 || memcmp(&data[28], &v, 4) != 0)
@ -129,7 +129,7 @@ static size_t mp3_tagsize(const uint8_t *data, size_t length)
if(tag_is_apetag(data, length))
{
size = (data[15] << 24) | (data[14] << 16) | (data[13] << 8) | data[12];
size = LittleLong(BytesLong(&data[12]));
size += 32;
return size;
}
@ -317,16 +317,13 @@ static int32_t mp3_decode(snd_stream_t *stream, byte *buf, int32_t len)
sample = 0x7FFF;
else
sample >>= (MAD_F_FRACBITS + 1 - 16);
if(host_bigendian)
{
*buf++ = (sample >> 8) & 0xFF;
*buf++ = sample & 0xFF;
}
else
{
*buf++ = sample & 0xFF;
*buf++ = (sample >> 8) & 0xFF;
}
#if HOST_BIGENDIAN
*buf++ = (sample >> 8) & 0xFF;
*buf++ = sample & 0xFF;
#else
*buf++ = sample & 0xFF;
*buf++ = (sample >> 8) & 0xFF;
#endif
i++;
}
p->cursamp++;

View File

@ -153,7 +153,7 @@ _retry:
if(type == UMUSIC_MP2)
{
uint8_t *p = (uint8_t *)sig;
uint16_t u = ((p[0] << 8) | p[1]) & 0xFFFE;
uint16_t u = BigShort(BytesShort(p)) & 0xFFFE;
if(u == 0xFFFC || u == 0xFFF4)
return UMUSIC_MP2;
return -1;
@ -304,7 +304,7 @@ static int32_t probe_header(void *header)
swp = (uint32_t *) header;
for(i = 0; i < UPKG_HDR_SIZE / 4; i++, p += 4)
{
swp[i] = p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
swp[i] = LittleLong(BytesLong(p));
}
hdr = (struct upkg_hdr *) header;

View File

@ -29,13 +29,7 @@
#include "snd_vorbis.h"
#define OV_EXCLUDE_STATIC_CALLBACKS
#if defined(VORBIS_USE_TREMOR)
/* for Tremor / Vorbisfile api differences,
* see doc/diff.html in the Tremor package. */
#include <tremor/ivorbisfile.h>
#else
#include <vorbis/vorbisfile.h>
#endif
/* Vorbis codec can return the samples in a number of different
* formats, we use the standard int16_t format. */
@ -161,11 +155,9 @@ static int32_t S_VORBIS_CodecReadStream(snd_stream_t *stream, int32_t bytes, voi
* the channels are interleaved in the output buffer.
*/
res = ov_read((OggVorbis_File *)stream->priv, ptr, rem,
#if !defined(VORBIS_USE_TREMOR)
host_bigendian,
HOST_BIGENDIAN,
VORBIS_SAMPLEWIDTH,
VORBIS_SIGNED_DATA,
#endif
& section);
if(res <= 0)
break;

View File

@ -30,8 +30,6 @@ static char localmodels[MAX_MODELS][8]; // inline model names for precac
int32_t sv_protocol = PROTOCOL_FITZQUAKE; //johnfitz
extern bool pr_alpha_supported; //johnfitz
//============================================================================
/*

View File

@ -482,8 +482,8 @@ void SV_PushMove(edict_t *pusher, float movetime)
//johnfitz -- dynamically allocate
mark = Hunk_LowMark();
moved_edict = (edict_t **) Hunk_Alloc(sv.num_edicts * sizeof(edict_t *));
moved_from = (vec3_t *) Hunk_Alloc(sv.num_edicts * sizeof(vec3_t));
moved_edict = Hunk_AllocName(sv.num_edicts * sizeof(edict_t *), "moved_edict");
moved_from = Hunk_AllocName(sv.num_edicts * sizeof(vec3_t), "moved_from");
//johnfitz
// see if any solid entities are inside the final position

View File

@ -343,7 +343,7 @@ void SV_TouchLinks(edict_t *ent)
int32_t mark;
mark = Hunk_LowMark();
list = (edict_t **) Hunk_Alloc(sv.num_edicts * sizeof(edict_t *));
list = Hunk_AllocName(sv.num_edicts * sizeof(edict_t *), __func__);
listcount = 0;
SV_AreaTriggerEdicts(ent, sv_areanodes, list, &listcount, sv.num_edicts);

View File

@ -438,12 +438,12 @@ void *Hunk_AllocName(int32_t size, const char *name)
#endif
if(size < 0)
Sys_Error("Hunk_Alloc: bad size: %" PRIi32 "", size);
Sys_Error("Hunk_AllocName: bad size: %" PRIi32 "", size);
size = sizeof(hunk_t) + ((size + 15) & ~15);
if(hunk_size - hunk_low_used - hunk_high_used < size)
Sys_Error("Hunk_Alloc: failed on %" PRIi32 " bytes", size);
Sys_Error("Hunk_AllocName: failed on %" PRIi32 " bytes", size);
h = (hunk_t *)(hunk_base + hunk_low_used);
hunk_low_used += size;
@ -459,16 +459,6 @@ void *Hunk_AllocName(int32_t size, const char *name)
return h + 1;
}
/*
===================
Hunk_Alloc
===================
*/
void *Hunk_Alloc(int32_t size)
{
return Hunk_AllocName(size, "unknown");
}
int32_t Hunk_LowMark(void)
{
return hunk_low_used;
@ -579,11 +569,15 @@ void *Hunk_TempAlloc(int32_t size)
return buf;
}
char *Hunk_Strdup(const char *s, const char *name)
void *Hunk_Strdup(void const *s, char const *name)
{
size_t sz = strlen(s) + 1;
char *ptr = (char *) Hunk_AllocName(sz, name);
memcpy(ptr, s, sz);
return Hunk_Memdup(s, strlen(s) + 1, name);
}
void *Hunk_Memdup(void const *mem, size_t n, char const *name)
{
void *ptr = Hunk_AllocName(n, name);
memcpy(ptr, mem, n);
return ptr;
}

View File

@ -96,10 +96,10 @@ void *Z_Malloc(int32_t size); // returns 0 filled memory
void *Z_Realloc(void *ptr, int32_t size);
char *Z_Strdup(const char *s);
void *Hunk_Alloc(int32_t size); // returns 0 filled memory
void *Hunk_AllocName(int32_t size, const char *name);
void *Hunk_HighAllocName(int32_t size, const char *name);
char *Hunk_Strdup(const char *s, const char *name);
void *Hunk_Strdup(void const *s, char const *name);
void *Hunk_Memdup(void const *mem, size_t n, char const *name);
int32_t Hunk_LowMark(void);
void Hunk_FreeToLowMark(int32_t mark);
@ -110,6 +110,7 @@ void Hunk_FreeToHighMark(int32_t mark);
void *Hunk_TempAlloc(int32_t size);
void Hunk_Check(void);
void Hunk_Print(bool all);
typedef struct cache_user_s
{