Skip to content

Commit

Permalink
Merge branch 'andrei-drexler:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
drHyperion451 authored Jul 18, 2024
2 parents c194946 + cdd2ff0 commit 99c94e2
Show file tree
Hide file tree
Showing 27 changed files with 461 additions and 375 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/mingw_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: MinGW CI

on: [push, pull_request]

jobs:
build-linux:
name: Build MinGW
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
config:
- target: win32
package: i686-win32

- target: win64
package: x86-64

steps:
- uses: actions/checkout@v4

- name: Install Dependencies
run: sudo apt update && sudo apt install gcc-mingw-w64-${{ matrix.config.package }}

- name: Build MinGW ${{ matrix.config.target }}
run: |
export MAKEFLAGS=--jobs=3\ --keep-going
cd Quake && ./build_cross_${{ matrix.config.target }}-sdl2.sh
2 changes: 2 additions & 0 deletions Quake/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,8 @@ cmd_function_t *Cmd_AddCommand2 (const char *cmd_name, xcommand_t function, cmd_
if (host_initialized)
{
cmd = (cmd_function_t *) malloc(sizeof(*cmd) + strlen(cmd_name)+1);
if (!cmd)
Sys_Error ("Cmd_AddCommand2: out of memory (%s)", cmd_name);
cmd->name = strcpy((char*)(cmd + 1), cmd_name);
cmd->dynamic = true;
}
Expand Down
55 changes: 2 additions & 53 deletions Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,16 +1992,8 @@ Filename are reletive to the quake directory.
Allways appends a 0 byte.
============
*/
#define LOADFILE_ZONE 0
#define LOADFILE_HUNK 1
#define LOADFILE_TEMPHUNK 2
#define LOADFILE_CACHE 3
#define LOADFILE_STACK 4
#define LOADFILE_MALLOC 5

static byte *loadbuf;
static cache_user_t *loadcache;
static int loadsize;
#define LOADFILE_HUNK 0
#define LOADFILE_MALLOC 1

byte *COM_LoadFile (const char *path, int usehunk, unsigned int *path_id)
{
Expand All @@ -2025,21 +2017,6 @@ byte *COM_LoadFile (const char *path, int usehunk, unsigned int *path_id)
case LOADFILE_HUNK:
buf = (byte *) Hunk_AllocName (len+1, base);
break;
case LOADFILE_TEMPHUNK:
buf = (byte *) Hunk_TempAlloc (len+1);
break;
case LOADFILE_ZONE:
buf = (byte *) Z_Malloc (len+1);
break;
case LOADFILE_CACHE:
buf = (byte *) Cache_Alloc (loadcache, len+1, base);
break;
case LOADFILE_STACK:
if (len < loadsize)
buf = loadbuf;
else
buf = (byte *) Hunk_TempAlloc (len+1);
break;
case LOADFILE_MALLOC:
buf = (byte *) malloc (len+1);
break;
Expand All @@ -2065,34 +2042,6 @@ byte *COM_LoadHunkFile (const char *path, unsigned int *path_id)
return COM_LoadFile (path, LOADFILE_HUNK, path_id);
}

byte *COM_LoadZoneFile (const char *path, unsigned int *path_id)
{
return COM_LoadFile (path, LOADFILE_ZONE, path_id);
}

byte *COM_LoadTempFile (const char *path, unsigned int *path_id)
{
return COM_LoadFile (path, LOADFILE_TEMPHUNK, path_id);
}

void COM_LoadCacheFile (const char *path, struct cache_user_s *cu, unsigned int *path_id)
{
loadcache = cu;
COM_LoadFile (path, LOADFILE_CACHE, path_id);
}

// uses temp hunk if larger than bufsize
byte *COM_LoadStackFile (const char *path, void *buffer, int bufsize, unsigned int *path_id)
{
byte *buf;

loadbuf = (byte *)buffer;
loadsize = bufsize;
buf = COM_LoadFile (path, LOADFILE_STACK, path_id);

return buf;
}

// returns malloc'd memory
byte *COM_LoadMallocFile (const char *path, unsigned int *path_id)
{
Expand Down
19 changes: 7 additions & 12 deletions Quake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ void InsertLinkAfter (link_t *l, link_t *after);

//============================================================================

#define PTR_IN_RANGE(ptr, begin, end) (((uintptr_t)(ptr)-(uintptr_t)(begin)) < ((uintptr_t)(end)-(uintptr_t)(begin)))

//============================================================================

typedef struct vec_header_t {
size_t capacity;
size_t size;
Expand All @@ -169,6 +173,9 @@ void MultiString_Append (char **pvec, const char *str);

//============================================================================

#define BITARRAY_DWORDS(bits) (((bits)+31)/32)
#define BITARRAY_MEM_SIZE(bits) (BITARRAY_DWORDS (bits) * sizeof (uint32_t))

static inline qboolean GetBit (const uint32_t *arr, uint32_t i)
{
return (arr[i/32u] & (1u<<(i%32u))) != 0u;
Expand Down Expand Up @@ -398,20 +405,8 @@ void COM_CloseFile (int h);
// these procedures open a file using COM_FindFile and loads it into a proper
// buffer. the buffer is allocated with a total size of com_filesize + 1. the
// procedures differ by their buffer allocation method.
byte *COM_LoadStackFile (const char *path, void *buffer, int bufsize,
unsigned int *path_id);
// uses the specified stack stack buffer with the specified size
// of bufsize. if bufsize is too short, uses temp hunk. the bufsize
// must include the +1
byte *COM_LoadTempFile (const char *path, unsigned int *path_id);
// allocates the buffer on the temp hunk.
byte *COM_LoadHunkFile (const char *path, unsigned int *path_id);
// allocates the buffer on the hunk.
byte *COM_LoadZoneFile (const char *path, unsigned int *path_id);
// allocates the buffer on the zone.
void COM_LoadCacheFile (const char *path, struct cache_user_s *cu,
unsigned int *path_id);
// uses cache mem for allocating the buffer.
byte *COM_LoadMallocFile (const char *path, unsigned int *path_id);
// allocates the buffer on the system mem (malloc).

Expand Down
4 changes: 3 additions & 1 deletion Quake/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ qboolean Con_CopySelectionToClipboard (void)
// Convert to UTF-8
maxsize = UTF8_FromQuake (NULL, 0, qtext);
utf8 = (char *) malloc (maxsize);
if (!utf8)
Sys_Error ("Con_CopySelectionToClipboard: out of memory on %" SDL_PRIu64 " bytes", (uint64_t)maxsize);
UTF8_FromQuake (utf8, maxsize, qtext);

// Copy the UTF-8 text to clipboard
Expand Down Expand Up @@ -1422,7 +1424,7 @@ void Con_LinkPrintf (const char *addr, const char *fmt, ...)
len = strlen (addr);
link = (conlink_t *) malloc (sizeof (conlink_t) + len + 1);
if (!link)
Sys_Error ("Con_LinkPrintf: out of memory on %" SDL_PRIu64 "u bytes", (uint64_t)(sizeof (conlink_t) + len + 1));
Sys_Error ("Con_LinkPrintf: out of memory on %" SDL_PRIu64 " bytes", (uint64_t)(sizeof (conlink_t) + len + 1));

memcpy (link + 1, addr, len + 1);
link->path = (const char *)(link + 1);
Expand Down
3 changes: 2 additions & 1 deletion Quake/gl_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ qpic_t *Draw_TryCachePic (const char *path, unsigned int texflags)
//
// load the pic from disk
//
dat = (qpic_t *)COM_LoadTempFile (path, NULL);
dat = (qpic_t *)COM_LoadMallocFile (path, NULL);
if (!dat)
return NULL;
SwapPic (dat);
Expand Down Expand Up @@ -404,6 +404,7 @@ qpic_t *Draw_TryCachePic (const char *path, unsigned int texflags)
gl.th = (float)dat->height/(float)TexMgr_PadConditional(dat->height); //johnfitz
}

free (dat);
memcpy (pic->pic.data, &gl, sizeof(glpic_t));

return &pic->pic;
Expand Down
93 changes: 61 additions & 32 deletions Quake/gl_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ static void Mod_LoadLighting (lump_t *l)
return;
}
Hunk_FreeToLowMark(mark);
Con_Printf("Outdated .lit file (%s should be %u bytes, not %lli)\n", litfilename, 8+l->filelen*3, com_filesize);
Con_Printf("Outdated .lit file (%s should be %u bytes, not %" SDL_PRIs64 "\n", litfilename, 8+l->filelen*3, com_filesize);
}
else
{
Expand Down Expand Up @@ -1783,23 +1783,24 @@ Mod_FindUsedTextures
*/
static void Mod_FindUsedTextures (qmodel_t *mod)
{
msurface_t *s;
int i, count, bit;
int ofs[TEXTYPE_COUNT];
int mark = Hunk_HighMark ();
byte *inuse = (byte *) Hunk_HighAllocName ((mod->numtextures + 7) >> 3, "used textures");
msurface_t *s;
int i, count;
int ofs[TEXTYPE_COUNT];
uint32_t *inuse;

inuse = (uint32_t *) calloc (BITARRAY_DWORDS (mod->numtextures), sizeof (uint32_t));
if (!inuse)
Sys_Error ("Mod_FindUsedTextures: out of memory (%d bits)", mod->numtextures);

memset (ofs, 0, sizeof(ofs));
for (i = 0, s = mod->surfaces + mod->firstmodelsurface; i < mod->nummodelsurfaces; i++, s++)
{
texture_t *t = mod->textures[s->texinfo->texnum];
byte *val = &inuse[s->texinfo->texnum >> 3];
if (!t)
continue;
bit = 1 << (s->texinfo->texnum & 7);
if (!(*val & bit))
if (!GetBit (inuse, s->texinfo->texnum))
{
*val |= bit;
SetBit (inuse, s->texinfo->texnum);
ofs[t->type]++;
}
}
Expand All @@ -1817,11 +1818,11 @@ static void Mod_FindUsedTextures (qmodel_t *mod)
for (i = 0; i < mod->numtextures; i++)
{
texture_t *t = mod->textures[i];
if (inuse[i >> 3] & (1 << (i & 7)))
if (GetBit (inuse, i))
mod->usedtextures[ofs[t->type]++] = i;
}

Hunk_FreeToHighMark (mark);
free (inuse);

//Con_Printf("%s: %d/%d textures\n", mod->name, count, mod->numtextures);
}
Expand Down Expand Up @@ -2468,6 +2469,48 @@ static void Mod_LoadBrushModel (qmodel_t *mod, void *buffer)
}
}

/*
=================
Mod_SanitizeMapDescription
Cleans up map descriptions:
- removes colors
- replaces newlines with spaces
- replaces consecutive spaces with single one
- removes leading/trailing spaces
Returns dst string length (excluding NUL terminator)
=================
*/
size_t Mod_SanitizeMapDescription (char *dst, size_t dstsize, const char *src)
{
int srcpos, dstpos;

if (!dstsize)
return 0;

for (srcpos = dstpos = 0; src[srcpos] && (size_t)dstpos + 1 < dstsize; srcpos++)
{
char c = src[srcpos] & 0x7f; // remove color
if (c == '\n' || c == '\r') // replace newlines with spaces
c = ' ';
else if (c == '\\' && src[srcpos + 1] == 'n') // replace '\\' followed by 'n' with space
{
c = ' ';
srcpos++;
}
// remove leading spaces, replace consecutive spaces with single one
if (c != ' ' || (dstpos > 0 && dst[dstpos - 1] != c))
dst[dstpos++] = c;
}
// remove trailing space, if any
if (dstpos > 0 && dst[dstpos - 1] == ' ')
--dstpos;

dst[dstpos] = '\0';
return dstpos;
}

/*
=================
Mod_LoadMapDescription
Expand All @@ -2485,7 +2528,7 @@ qboolean Mod_LoadMapDescription (char *desc, size_t maxchars, const char *map)
FILE *f;
lump_t *entlump;
dheader_t header;
int i, j, k, filesize;
int i, filesize;
qboolean ret = false;

if (!maxchars)
Expand Down Expand Up @@ -2578,25 +2621,7 @@ qboolean Mod_LoadMapDescription (char *desc, size_t maxchars, const char *map)

if (is_message)
{
// copy map title and clean it up a bit
for (j = k = 0; com_token[j] && (size_t)k + 1 < maxchars; j++)
{
char c = com_token[j] & 0x7f;
if (c == '\n' || c == '\r') // replace newlines with spaces
c = ' ';
else if (c == '\\' && com_token[j + 1] == 'n') // replace '\\' followed by 'n' with space
{
c = ' ';
j++;
}
// remove leading spaces, replace consecutive spaces with single one
if (c != ' ' || (k > 0 && desc[k - 1] != c))
desc[k++] = c;
}
// remove trailing space, if any
if (k > 0 && desc[k - 1] == ' ')
--k;
desc[k++] = '\0';
Mod_SanitizeMapDescription (desc, maxchars, com_token);
if (ret)
return true;
}
Expand Down Expand Up @@ -3718,6 +3743,8 @@ static void MD5_ComputeNormals(iqmvert_t *vert, size_t numverts, unsigned short
hashmap = (int *) calloc (hashsize, sizeof (*hashmap));
weld = (unsigned short *) malloc (numverts * sizeof (*weld));
normals = (vec3_t *) calloc (numverts, sizeof (vec3_t));
if (!hashmap || !weld || !normals)
Sys_Error ("MD5_ComputeNormals: out of memory (%u verts/%u tris)", (unsigned int)numverts, (unsigned int)(numindexes/3));

for (v = 0; v < numverts; v++)
{
Expand Down Expand Up @@ -3870,6 +3897,8 @@ static void MD5Anim_Load(md5animctx_t *ctx, boneinfo_t *bones, size_t numbones)

ctx->posedata = outposes = (bonepose_t *) Hunk_Alloc(sizeof(*outposes)*ctx->numjoints*ctx->numposes);
frameposes = (bonepose_t *) malloc (sizeof (*frameposes) * ctx->numjoints);
if (!frameposes)
Sys_Error ("MD5Anim_Load: out of memory (%u joints)", (unsigned int)ctx->numjoints);


MD5EXPECT("hierarchy");
Expand Down
1 change: 1 addition & 0 deletions Quake/gl_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ byte *Mod_LeafPVS (mleaf_t *leaf, qmodel_t *model);
byte *Mod_NoVisPVS (qmodel_t *model);

void Mod_SetExtraFlags (qmodel_t *mod);
size_t Mod_SanitizeMapDescription (char *dst, size_t dstsize, const char *src);
qboolean Mod_LoadMapDescription (char *desc, size_t maxchars, const char *map);

#endif /* GL_MODEL_H */
4 changes: 2 additions & 2 deletions Quake/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1797,8 +1797,8 @@ void R_WarpScaleView (void)
else
GL_Uniform4fFunc (1, 0.f, 0.f, 0.f, 0.f);
GL_BindNative (GL_TEXTURE0, GL_TEXTURE_2D, msaa ? framebufs.resolved_scene.color_tex : framebufs.scene.color_tex);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, water_warp ? GL_LINEAR : GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, water_warp ? GL_LINEAR : GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, water_warp && msaa ? GL_LINEAR : GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, water_warp && msaa ? GL_LINEAR : GL_NEAREST);

glDrawArrays (GL_TRIANGLES, 0, 3);

Expand Down
8 changes: 6 additions & 2 deletions Quake/gl_shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GL_InitError
*/
static void GL_InitError (const char *message, ...)
{
const char *fmt;
char buf[4096];
size_t len;
va_list argptr;
Expand All @@ -49,7 +50,7 @@ static void GL_InitError (const char *message, ...)
while (len && q_isspace (buf[len - 1]))
buf[--len] = '\0';

Sys_Error (
fmt =
"Your system appears to meet the minimum requirements,\n"
"however an error was encountered during OpenGL initialization.\n"
"This could be caused by a driver or an engine bug.\n"
Expand All @@ -65,7 +66,10 @@ static void GL_InitError (const char *message, ...)
"\n"
"(Note: you can press Ctrl+C to copy this text to clipboard)"
#endif
,
;

Sys_Error (
fmt,
buf,
(int) sizeof (void *) * 8,
gl_version,
Expand Down
Loading

0 comments on commit 99c94e2

Please sign in to comment.