ref: 854729a4c1cd2db5a27628af9f77ed907251f875
parent: 8d1771774944a92cfd9650ba36007889e9b3e861
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Oct 10 12:07:47 EDT 2023
clean up dynamic reallocation of arrays; fix nonsensical MAXEDGES value
--- a/cl_parse.c
+++ b/cl_parse.c
@@ -720,7 +720,7 @@
switch (cmd)
{
default:
- Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+ Host_Error ("CL_ParseServerMessage: Illegible server message (cmd %d)\n", cmd);
break;
case svc_nop:
--- a/common.c
+++ b/common.c
@@ -306,6 +306,16 @@
//===========================================================================
void
+Arr_AllocExtra(void **arr, int *nel, int needextra)
+{
+ while(needextra > 0){
+ *arr = Hunk_Double(*arr);
+ needextra -= *nel;
+ *nel *= 2;
+ }
+}
+
+void
SZ_Alloc(sizebuf_t *buf, int startsize)
{
if(startsize < 256)
@@ -313,6 +323,7 @@
buf->data = Hunk_Alloc(startsize);
buf->maxsize = startsize;
buf->cursize = 0;
+ setmalloctag(buf->data, getcallerpc(&buf));
}
--- a/common.h
+++ b/common.h
@@ -1,3 +1,5 @@
+void Arr_AllocExtra(void **arr, int *nel, int needextra);
+
typedef struct sizebuf_s
{
qboolean allowoverflow; // if false, do a fatal
--- a/model.c
+++ b/model.c
@@ -47,7 +47,7 @@
Mod_LoadModel (mod, true);
if (!mod->cache.data)
- fatal ("Mod_Extradata: caching failed");
+ fatal ("Mod_Extradata: caching failed: %s", mod->name);
return mod->cache.data;
}
@@ -229,7 +229,7 @@
model_t *Mod_LoadModel (model_t *mod, qboolean crash)
{
unsigned *buf;
- byte stackbuf[1024]; // avoid dirtying the cache heap
+ byte stackbuf[1024]; // avoid dirtying the cache heap
if (mod->type == mod_alias)
{
@@ -241,8 +241,9 @@
}
else
{
- if (mod->needload == NL_PRESENT)
+ if (mod->needload == NL_PRESENT){
return mod;
+ }
}
//
@@ -253,6 +254,7 @@
if(buf == nil){
if(crash)
fatal("Mod_LoadModel: %r");
+ fprint(2, "loadstklmp failed: %s\n", mod->name);
return nil;
}
--- a/net_main.c
+++ b/net_main.c
@@ -390,7 +390,7 @@
if (sock->disconnected)
{
- Con_Printf("NET_SendMessage: disconnected socket\n");
+ Con_Printf("NET_SendUnreliableMessage: disconnected socket\n");
return -1;
}
--- a/r_edge.c
+++ b/r_edge.c
@@ -51,44 +51,8 @@
void R_LeadingEdgeBackwards (edge_t *edge);
void R_TrailingEdge (surf_t *surf, edge_t *edge);
-void R_SetupEdges(void)
-{
- while(r_outofedges > 0){
- r_edges = Hunk_Double(r_edges);
- r_outofedges -= r_numallocatededges;
- r_numallocatededges *= 2;
- }
- r_outofedges = 0;
- edge_p = r_edges;
- edge_max = &r_edges[r_numallocatededges];
-}
-
-void R_SetupSurfaces(void)
-{
- while(r_outofsurfaces > 0){
- surfaces = Hunk_Double(surfaces);
- r_outofsurfaces -= r_cnumsurfs;
- r_cnumsurfs *= 2;
- }
- r_outofsurfaces = 0;
- surface_p = surfaces;
- surf_max = &surfaces[r_cnumsurfs];
-}
-
-void R_SetupSpans(void)
-{
- while(r_outofspans > 0){
- r_basespans = Hunk_Double(r_basespans);
- r_outofspans -= r_numallocatedbasespans;
- r_numallocatedbasespans *= 2;
- }
- r_outofspans = 0;
-}
-
-
//=============================================================================
-
/*
==============
R_DrawCulledPolys
@@ -140,9 +104,15 @@
{
int v;
- R_SetupEdges();
- R_SetupSurfaces();
+ Arr_AllocExtra(&r_edges, &r_numallocatededges, r_outofedges);
+ edge_p = r_edges;
+ edge_max = &r_edges[r_numallocatededges];
+ r_outofedges = 0;
+ Arr_AllocExtra(&surfaces, &r_cnumsurfs, r_outofsurfaces);
+ surf_max = &surfaces[r_cnumsurfs];
+ r_outofsurfaces = 0;
+
surface_p = &surfaces[2]; // background is surface 1,
// surface 0 is a dummy
surfaces[1].spans = nil; // no background spans yet
@@ -661,11 +631,12 @@
espan_t *basespan_p;
surf_t *s;
- R_SetupSpans();
+ Arr_AllocExtra(&r_basespans, &r_numallocatedbasespans, r_outofspans);
basespan_p = (espan_t *)
((uintptr)(r_basespans + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
max_span_p = &basespan_p[r_numallocatedbasespans - r_refdef.vrect.width];
span_p = basespan_p;
+ r_outofspans = 0;
// clear active edges to just the background edges around the whole screen
// FIXME: most of this only needs to be set up once
--- a/r_main.c
+++ b/r_main.c
@@ -224,19 +224,15 @@
r_numallocatedbasespans = MAXSPANS;
r_basespans = Hunk_Alloc(r_numallocatedbasespans * sizeof(espan_t) + CACHE_SIZE);
- r_viewleaf = nil;
- R_ClearParticles ();
-
r_cnumsurfs = MAXSURFACES;
surfaces = Hunk_Alloc(r_cnumsurfs * sizeof *surfaces);
- R_SetupSurfaces();
-
- r_maxedgesseen = 0;
- r_maxsurfsseen = 0;
-
r_numallocatededges = MAXEDGES;
r_edges = Hunk_Alloc(r_numallocatededges * sizeof *r_edges);
+ r_viewleaf = nil;
+ R_ClearParticles ();
+ r_maxedgesseen = 0;
+ r_maxsurfsseen = 0;
r_dowarpold = false;
r_viewchanged = false;
#ifdef PASSAGES
--- a/r_shared.h
+++ b/r_shared.h
@@ -36,7 +36,7 @@
extern entity_t *currententity;
// NOTE: these are only initial values. limits are supposed to scale up dynamically
-#define MAXEDGES 32
+#define MAXEDGES 2400
#define MAXSURFACES 800
#define MAXSPANS 3000