2004-08-21 01:25:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// Z_zone.c
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "winquake.h"
|
|
|
|
#endif
|
2021-07-18 01:28:34 +00:00
|
|
|
#ifdef __GLIBC__
|
|
|
|
#include <malloc.h>
|
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
#define NOZONE
|
|
|
|
|
2004-09-20 23:25:38 +00:00
|
|
|
#ifdef _DEBUG
|
2004-11-27 08:16:25 +00:00
|
|
|
//#define MEMDEBUG 8192 //Debugging adds sentinels (the number is the size - I have the ram)
|
2004-09-20 23:25:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-03 03:02:17 +00:00
|
|
|
//must be multiple of 4.
|
2018-10-11 10:31:23 +00:00
|
|
|
//#define TEMPDEBUG 4
|
|
|
|
//#define ZONEDEBUG 4
|
|
|
|
//#define HUNKDEBUG 4
|
2004-12-02 06:00:21 +00:00
|
|
|
|
|
|
|
//these need to be defined because it makes some bits of code simpler
|
|
|
|
#ifndef HUNKDEBUG
|
|
|
|
#define HUNKDEBUG 0
|
|
|
|
#endif
|
|
|
|
#ifndef ZONEDEBUG
|
|
|
|
#define ZONEDEBUG 0
|
|
|
|
#endif
|
|
|
|
#ifndef TEMPDEBUG
|
|
|
|
#define TEMPDEBUG 0
|
|
|
|
#endif
|
2004-09-20 23:25:38 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
#if ZONEDEBUG>0 || HUNKDEBUG>0 || TEMPDEBUG>0
|
2020-02-26 00:37:52 +00:00
|
|
|
qbyte sentinelkey;
|
2004-09-20 23:25:38 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#define TAGLESS 1
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2019-05-23 15:11:32 +00:00
|
|
|
size_t zmemtotal;
|
|
|
|
size_t zmemdelta;
|
2012-05-09 15:30:53 +00:00
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
typedef struct memheader_s {
|
2019-05-23 15:11:32 +00:00
|
|
|
size_t size;
|
2008-05-09 14:22:37 +00:00
|
|
|
int tag;
|
|
|
|
} memheader_t;
|
|
|
|
|
|
|
|
typedef struct zone_s {
|
|
|
|
struct zone_s *next;
|
|
|
|
struct zone_s *pvdn; // down if first, previous if not
|
|
|
|
memheader_t mh;
|
|
|
|
} zone_t;
|
|
|
|
zone_t *zone_head;
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
void *zonelock;
|
|
|
|
#endif
|
|
|
|
|
2009-04-02 22:25:54 +00:00
|
|
|
#if 0
|
2008-11-09 22:29:28 +00:00
|
|
|
static void Z_DumpTree(void)
|
2008-09-12 00:17:32 +00:00
|
|
|
{
|
|
|
|
zone_t *zone;
|
|
|
|
zone_t *nextlist;
|
|
|
|
zone_t *t;
|
|
|
|
zone_t *prev;
|
|
|
|
|
|
|
|
zone = zone_head;
|
|
|
|
while(zone)
|
|
|
|
{
|
|
|
|
nextlist = zone->pvdn;
|
|
|
|
|
|
|
|
fprintf(stderr, " +-+ %016x (tag: %08x)\n", zone, zone->mh.tag);
|
|
|
|
|
|
|
|
prev = zone;
|
|
|
|
t = zone->next;
|
|
|
|
while(t)
|
|
|
|
{
|
|
|
|
if (t->pvdn != prev)
|
|
|
|
fprintf(stderr, "Previous link failure\n");
|
|
|
|
|
|
|
|
prev = t;
|
|
|
|
t = t->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(zone)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " +-- %016x\n", zone);
|
|
|
|
|
|
|
|
zone = zone->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
zone = nextlist;
|
|
|
|
}
|
|
|
|
}
|
2009-04-02 22:25:54 +00:00
|
|
|
#endif
|
2008-09-12 00:17:32 +00:00
|
|
|
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Z_TagMalloc(size_t size, int tag)
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
|
|
|
zone_t *zone;
|
|
|
|
|
|
|
|
zone = (zone_t *)malloc(size + sizeof(zone_t));
|
|
|
|
if (!zone)
|
2019-05-23 15:11:32 +00:00
|
|
|
Sys_Error("Z_Malloc: Failed on allocation of %"PRIuSIZE" bytes", size);
|
2008-05-09 14:22:37 +00:00
|
|
|
Q_memset(zone, 0, size + sizeof(zone_t));
|
|
|
|
zone->mh.tag = tag;
|
|
|
|
zone->mh.size = size;
|
|
|
|
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_LockMutex(zonelock);
|
|
|
|
#endif
|
2008-09-12 00:17:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "Before alloc:\n");
|
|
|
|
Z_DumpTree();
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
if (zone_head == NULL)
|
|
|
|
zone_head = zone;
|
|
|
|
else
|
|
|
|
{
|
2008-09-12 00:17:32 +00:00
|
|
|
zone_t *s = zone_head;
|
2008-05-09 14:22:37 +00:00
|
|
|
|
|
|
|
while (s && s->mh.tag != tag)
|
|
|
|
s = s->pvdn;
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
{ // tag match
|
|
|
|
zone->next = s->next;
|
2008-09-12 00:17:32 +00:00
|
|
|
if (s->next)
|
|
|
|
s->next->pvdn = zone;
|
|
|
|
zone->pvdn = s;
|
2008-05-09 14:22:37 +00:00
|
|
|
s->next = zone;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->pvdn = zone_head;
|
2009-04-01 22:03:56 +00:00
|
|
|
// if (s->next)
|
|
|
|
// s->next->pvdn = zone;
|
2008-05-09 14:22:37 +00:00
|
|
|
zone_head = zone;
|
|
|
|
}
|
|
|
|
}
|
2008-09-12 00:17:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "After alloc:\n");
|
|
|
|
Z_DumpTree();
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_UnlockMutex(zonelock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (void *)(zone + 1);
|
|
|
|
}
|
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
|
|
|
void *ZF_MallocNamed(int size, char *file, int line)
|
|
|
|
{
|
|
|
|
return _calloc_dbg(size, 1, _NORMAL_BLOCK, file, line);
|
|
|
|
}
|
|
|
|
void *Z_MallocNamed(int size, char *file, int line)
|
|
|
|
{
|
|
|
|
void *mem = ZF_MallocNamed(size, file, line);
|
|
|
|
if (!mem)
|
|
|
|
Sys_Error("Z_Malloc: Failed on allocation of %i bytes", size);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
#else
|
2019-05-23 15:11:32 +00:00
|
|
|
void *ZF_Malloc(size_t size)
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
2013-10-09 01:00:24 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
void *ret = NULL;
|
|
|
|
//android is linux, but not gnu and thus not posix...
|
|
|
|
ret = memalign(max(sizeof(float)*4, sizeof(void*)), size);
|
|
|
|
if (ret)
|
|
|
|
memset(ret, 0, size);
|
|
|
|
return ret;
|
|
|
|
#elif defined(__linux__)
|
2013-07-31 00:17:51 +00:00
|
|
|
void *ret = NULL;
|
2020-02-11 18:06:10 +00:00
|
|
|
|
2013-07-31 00:17:51 +00:00
|
|
|
if (!posix_memalign(&ret, max(sizeof(float)*4, sizeof(void*)), size))
|
|
|
|
memset(ret, 0, size);
|
|
|
|
return ret;
|
|
|
|
#else
|
2008-05-09 14:22:37 +00:00
|
|
|
return calloc(size, 1);
|
2013-07-31 00:17:51 +00:00
|
|
|
#endif
|
2008-05-09 14:22:37 +00:00
|
|
|
}
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Z_Malloc(size_t size)
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
|
|
|
void *mem = ZF_Malloc(size);
|
|
|
|
if (!mem)
|
2019-05-23 15:11:32 +00:00
|
|
|
Sys_Error("Z_Malloc: Failed on allocation of %"PRIuSIZE" bytes", size);
|
2008-05-09 14:22:37 +00:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
#endif
|
2008-05-09 14:22:37 +00:00
|
|
|
|
2021-07-17 15:11:15 +00:00
|
|
|
char *Z_StrDupf(const char *format, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char *string;
|
|
|
|
int n;
|
|
|
|
|
2021-08-04 21:17:31 +00:00
|
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
int try;
|
|
|
|
//msvc is shitty shit shit and doesn't even do c99. sadly mingw uses the same libraries.
|
|
|
|
try = 256;
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
string = Z_Malloc(try+1);
|
|
|
|
va_start (argptr, format);
|
|
|
|
n = _vsnprintf (string,try, format,argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
if (n >= 0 && n < try)
|
|
|
|
break;
|
|
|
|
Z_Free(string);
|
|
|
|
try *= 2;
|
|
|
|
}
|
|
|
|
string[n] = 0;
|
|
|
|
#else
|
2021-07-17 15:11:15 +00:00
|
|
|
va_start (argptr, format);
|
|
|
|
n = vsnprintf (NULL,0, format,argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
if (n < 0)
|
|
|
|
n = 1024; //windows bullshit. whatever. good luck with that.
|
|
|
|
|
|
|
|
string = Z_Malloc(n+1);
|
|
|
|
va_start (argptr, format);
|
2021-07-23 21:06:52 +00:00
|
|
|
vsnprintf (string,n+1, format,argptr);
|
2021-07-17 15:11:15 +00:00
|
|
|
va_end (argptr);
|
|
|
|
string[n] = 0;
|
2021-08-04 21:17:31 +00:00
|
|
|
#endif
|
2021-07-17 15:11:15 +00:00
|
|
|
|
|
|
|
return string;
|
|
|
|
}
|
2023-03-15 17:57:31 +00:00
|
|
|
void Z_StrCatLen(char **ptr, const char *append, size_t newlen)
|
|
|
|
{
|
|
|
|
size_t oldlen = *ptr?strlen(*ptr):0;
|
|
|
|
char *newptr = BZ_Malloc(oldlen+newlen+1);
|
|
|
|
memcpy(newptr, *ptr, oldlen);
|
|
|
|
memcpy(newptr+oldlen, append, newlen);
|
|
|
|
newptr[oldlen+newlen] = 0;
|
|
|
|
BZ_Free(*ptr);
|
|
|
|
*ptr = newptr;
|
|
|
|
}
|
2019-03-12 05:04:27 +00:00
|
|
|
void Z_StrCat(char **ptr, const char *append)
|
playdemo accepts https urls now. will start playing before the file has finished downloading, to avoid unnecessary delays.
reworked network addresses to separate address family and connection type. this should make banning people more reliable, as well as simplifying a whole load of logic (no need to check for ipv4 AND ipv6).
tcpconnect will keep trying to connect even if the connection wasn't instant, instead of giving up instantly.
rewrote tcp connections quite a bit. sv_port_tcp now handles qtv+qizmo+http+ws+rtcbroker+tls equivalents.
qtv_streamport is now a legacy cvar and now acts equivalently to sv_port_tcp (but still separate).
rewrote screenshot and video capture code to use strides. this solves image-is-upside down issues with vulkan.
ignore alt key in browser port. oh no! no more red text! oh no! no more alt-being-wrongly-down-and-being-unable-to-type-anything-without-forcing-alt-released!
reworked audio decoder interface. now has clearly defined success/unavailable/end-of-file results. this should solve a whole load of issues with audio streaming.
fixed various openal audio streaming issues too. openal also got some workarounds for emscripten's poor emulation.
fixed ogg decoder to retain sync properly if seeked.
updated menu_media a bit. now reads vorbis comments/id3v1 tags to get proper track names. also saves the playlist so you don't have to manually repopulate the list so it might actually be usable now (after how many years?)
r_stains now defaults to 0, and is no longer enabled by presets. use decals if you want that sort of thing.
added fs_noreexec cvar, so configs will not be reexeced on gamedir change. this also means defaults won't be reapplied, etc.
added 'nvvk' renderer on windows, using nvidia's vulkan-inside-opengl gl extension. mostly just to see how much slower it is.
fixed up the ftp server quite a lot. more complete, more compliant, and should do ipv6 properly to-boot. file transfers also threaded.
fixed potential crash inside runclientphys.
experimental sv_antilag=3 setting. totally untested. the aim is to avoid missing due to lagged knockbacks. may be expensive for the server.
browser port's websockets support fixed. experimental support for webrtc ('works for me', requires a broker server).
updated avplug(renamed to ffmpeg so people know what it is) to use ffmpeg 3.2.4 properly, with its new encoder api. should be much more robust... also added experimental audio decoder for game music etc (currently doesn't resample, so playback rates are screwed, disabled by cvar).
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5097 fc73d0e0-1445-4013-8a0c-d673dee63da5
2017-05-10 02:08:58 +00:00
|
|
|
{
|
|
|
|
size_t oldlen = *ptr?strlen(*ptr):0;
|
|
|
|
size_t newlen = strlen(append);
|
|
|
|
char *newptr = BZ_Malloc(oldlen+newlen+1);
|
|
|
|
memcpy(newptr, *ptr, oldlen);
|
|
|
|
memcpy(newptr+oldlen, append, newlen);
|
|
|
|
newptr[oldlen+newlen] = 0;
|
|
|
|
BZ_Free(*ptr);
|
|
|
|
*ptr = newptr;
|
|
|
|
}
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
void VARGS Z_TagFree(void *mem)
|
|
|
|
{
|
|
|
|
zone_t *zone = ((zone_t *)mem) - 1;
|
|
|
|
|
2008-09-12 00:17:32 +00:00
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "Before free:\n");
|
|
|
|
Z_DumpTree();
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_LockMutex(zonelock);
|
|
|
|
#endif
|
|
|
|
if (zone->next)
|
|
|
|
zone->next->pvdn = zone->pvdn;
|
2008-09-12 00:17:32 +00:00
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
if (zone->pvdn && zone->pvdn->mh.tag == zone->mh.tag)
|
|
|
|
zone->pvdn->next = zone->next;
|
|
|
|
else
|
|
|
|
{ // zone is first entry in a tag list
|
|
|
|
zone_t *s = zone_head;
|
|
|
|
|
|
|
|
if (zone != s)
|
|
|
|
{ // traverse and update down list
|
|
|
|
while (s->pvdn != zone)
|
2008-09-12 00:17:32 +00:00
|
|
|
s = s->pvdn;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2008-09-12 00:17:32 +00:00
|
|
|
if (zone->next)
|
|
|
|
s->pvdn = zone->next;
|
|
|
|
else
|
|
|
|
s->pvdn = zone->pvdn;
|
2008-05-09 14:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zone == zone_head)
|
|
|
|
{ // freeing head node so update head pointer
|
|
|
|
if (zone->next) // move to next, pvdn should be maintained properly
|
|
|
|
zone_head = zone->next;
|
|
|
|
else // no more entries with this tag so move head down
|
|
|
|
zone_head = zone->pvdn;
|
|
|
|
}
|
2008-09-12 00:17:32 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
fprintf(stderr, "After free:\n");
|
|
|
|
Z_DumpTree();
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
#endif
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_UnlockMutex(zonelock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
free(zone);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VARGS Z_Free(void *mem)
|
|
|
|
{
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VARGS Z_FreeTags(int tag)
|
|
|
|
{
|
|
|
|
zone_t *taglist;
|
|
|
|
zone_t *t;
|
|
|
|
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_LockMutex(zonelock);
|
|
|
|
#endif
|
|
|
|
if (zone_head)
|
|
|
|
{
|
|
|
|
if (zone_head->mh.tag == tag)
|
|
|
|
{ // just pull off the head
|
|
|
|
taglist = zone_head;
|
|
|
|
zone_head = zone_head->pvdn;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // search for tag list and isolate it
|
|
|
|
zone_t *z;
|
|
|
|
z = zone_head;
|
2008-09-18 18:25:39 +00:00
|
|
|
while (z->pvdn != NULL && z->pvdn->mh.tag != tag)
|
|
|
|
z = z->pvdn;
|
2008-05-09 14:22:37 +00:00
|
|
|
|
2008-10-08 19:18:12 +00:00
|
|
|
if (z->pvdn == NULL)
|
2008-05-09 14:22:37 +00:00
|
|
|
taglist = NULL;
|
|
|
|
else
|
|
|
|
{
|
2008-09-18 18:25:39 +00:00
|
|
|
taglist = z->pvdn;
|
|
|
|
z->pvdn = z->pvdn->pvdn;
|
2008-05-09 14:22:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
taglist = NULL;
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
Sys_UnlockMutex(zonelock);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// actually free list
|
|
|
|
while (taglist != NULL)
|
|
|
|
{
|
|
|
|
t = taglist->next;
|
|
|
|
free(taglist);
|
|
|
|
taglist = t;
|
|
|
|
}
|
|
|
|
}
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2015-04-14 23:12:17 +00:00
|
|
|
//close enough
|
|
|
|
#ifndef SIZE_MAX
|
|
|
|
#define SIZE_MAX ((size_t)-1)
|
|
|
|
#endif
|
|
|
|
|
2017-03-30 18:37:16 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
|
|
|
qboolean ZF_ReallocElementsNamed(void **ptr, size_t *elements, size_t newelements, size_t elementsize, const char *file, int line)
|
|
|
|
#else
|
2015-04-14 23:12:17 +00:00
|
|
|
qboolean ZF_ReallocElements(void **ptr, size_t *elements, size_t newelements, size_t elementsize)
|
2017-03-30 18:37:16 +00:00
|
|
|
#endif
|
2015-04-14 23:12:17 +00:00
|
|
|
{
|
|
|
|
void *n;
|
|
|
|
size_t oldsize;
|
|
|
|
size_t newsize;
|
|
|
|
|
|
|
|
//protect against malicious overflows
|
|
|
|
if (newelements > SIZE_MAX / elementsize)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
oldsize = *elements * elementsize;
|
|
|
|
newsize = newelements * elementsize;
|
|
|
|
|
2017-03-30 18:37:16 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
|
|
|
n = BZ_ReallocNamed(*ptr, newsize, file, line);
|
|
|
|
#else
|
2015-04-14 23:12:17 +00:00
|
|
|
n = BZ_Realloc(*ptr, newsize);
|
2017-03-30 18:37:16 +00:00
|
|
|
#endif
|
2015-04-14 23:12:17 +00:00
|
|
|
if (!n)
|
|
|
|
return false;
|
|
|
|
if (newsize > oldsize)
|
|
|
|
memset((char*)n+oldsize, 0, newsize - oldsize);
|
|
|
|
*elements = newelements;
|
|
|
|
*ptr = n;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
/*
|
|
|
|
void *Z_Realloc(void *data, int newsize)
|
|
|
|
{
|
|
|
|
memheader_t *memref;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return Z_Malloc(newsize);
|
|
|
|
|
|
|
|
memref = ((memheader_t *)data) - 1;
|
|
|
|
|
|
|
|
if (memref[0].tag != TAGLESS)
|
|
|
|
{ // allocate a new block and copy since we need to maintain the lists
|
|
|
|
zone_t *zone = ((zone_t *)data) - 1;
|
|
|
|
int size = zone->mh.size;
|
|
|
|
if (size != newsize)
|
|
|
|
{
|
|
|
|
void *newdata = Z_Malloc(newsize);
|
|
|
|
|
|
|
|
if (size > newsize)
|
|
|
|
size = newsize;
|
|
|
|
memcpy(newdata, data, size);
|
|
|
|
|
|
|
|
Z_Free(data);
|
|
|
|
data = newdata;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int oldsize = memref[0].size;
|
|
|
|
memref = realloc(memref, newsize + sizeof(memheader_t));
|
|
|
|
memref->size = newsize;
|
|
|
|
if (newsize > oldsize)
|
|
|
|
memset((qbyte *)memref + sizeof(memheader_t) + oldsize, 0, newsize - oldsize);
|
|
|
|
data = ((memheader_t *)memref) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
2017-04-18 11:12:17 +00:00
|
|
|
void *BZF_MallocNamed(int size, const char *file, int line) //BZ_MallocNamed but allowed to fail - like straight malloc.
|
2012-07-05 19:42:36 +00:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
mem = _malloc_dbg(size, _NORMAL_BLOCK, file, line);
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
zmemdelta += size;
|
|
|
|
zmemtotal += size;
|
|
|
|
}
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
#else
|
2019-05-23 15:11:32 +00:00
|
|
|
void *BZF_Malloc(size_t size) //BZ_Malloc but allowed to fail - like straight malloc.
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
2012-05-09 15:30:53 +00:00
|
|
|
void *mem;
|
|
|
|
mem = malloc(size);
|
|
|
|
if (mem)
|
|
|
|
{
|
|
|
|
zmemdelta += size;
|
|
|
|
zmemtotal += size;
|
|
|
|
}
|
|
|
|
return mem;
|
2008-05-09 14:22:37 +00:00
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
#endif
|
2008-05-09 14:22:37 +00:00
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
2017-04-18 11:12:17 +00:00
|
|
|
void *BZ_MallocNamed(int size, const char *file, int line) //BZ_MallocNamed but allowed to fail - like straight malloc.
|
2012-07-05 19:42:36 +00:00
|
|
|
{
|
|
|
|
void *mem = BZF_MallocNamed(size, file, line);
|
|
|
|
if (!mem)
|
|
|
|
Sys_Error("BZ_Malloc: Failed on allocation of %i bytes", size);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
#else
|
2019-05-23 15:11:32 +00:00
|
|
|
void *BZ_Malloc(size_t size) //Doesn't clear. The expectation is a large file, rather than sensitive data structures.
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
|
|
|
void *mem = BZF_Malloc(size);
|
|
|
|
if (!mem)
|
2019-05-23 15:11:32 +00:00
|
|
|
Sys_Error("BZ_Malloc: Failed on allocation of %"PRIuSIZE" bytes", size);
|
2008-05-09 14:22:37 +00:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
2017-04-18 11:12:17 +00:00
|
|
|
void *BZF_ReallocNamed(void *data, int newsize, const char *file, int line)
|
2012-07-05 19:42:36 +00:00
|
|
|
{
|
|
|
|
return _realloc_dbg(data, newsize, _NORMAL_BLOCK, file, line);
|
|
|
|
}
|
2008-05-09 14:22:37 +00:00
|
|
|
|
2017-04-18 11:12:17 +00:00
|
|
|
void *BZ_ReallocNamed(void *data, int newsize, const char *file, int line)
|
2012-07-05 19:42:36 +00:00
|
|
|
{
|
|
|
|
void *mem = BZF_ReallocNamed(data, newsize, file, line);
|
|
|
|
|
|
|
|
if (!mem)
|
|
|
|
Sys_Error("BZ_Realloc: Failed on reallocation of %i bytes", newsize);
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
#else
|
2019-05-23 15:11:32 +00:00
|
|
|
void *BZF_Realloc(void *data, size_t newsize)
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
|
|
|
return realloc(data, newsize);
|
|
|
|
}
|
|
|
|
|
2019-05-23 15:11:32 +00:00
|
|
|
void *BZ_Realloc(void *data, size_t newsize)
|
2008-05-09 14:22:37 +00:00
|
|
|
{
|
|
|
|
void *mem = BZF_Realloc(data, newsize);
|
|
|
|
|
|
|
|
if (!mem)
|
2019-05-23 15:11:32 +00:00
|
|
|
Sys_Error("BZ_Realloc: Failed on reallocation of %"PRIuSIZE" bytes", newsize);
|
2008-05-09 14:22:37 +00:00
|
|
|
|
|
|
|
return mem;
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
#endif
|
2008-05-09 14:22:37 +00:00
|
|
|
|
|
|
|
void BZ_Free(void *data)
|
|
|
|
{
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
typedef struct zonegroupblock_s
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-31 00:17:51 +00:00
|
|
|
union
|
|
|
|
{
|
2022-03-08 05:30:30 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
struct zonegroupblock_s *next;
|
|
|
|
struct zonegroupblock_s *prev;
|
|
|
|
#ifdef _DEBUG
|
|
|
|
#define ZONEGROUP_SENTINAL 0x709ef00d
|
|
|
|
unsigned int sentinal;
|
|
|
|
unsigned int size;
|
|
|
|
#endif
|
|
|
|
};
|
2013-07-31 00:17:51 +00:00
|
|
|
vec4_t align16;
|
|
|
|
};
|
2013-07-14 12:22:51 +00:00
|
|
|
} zonegroupblock_t;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
2014-03-30 10:43:05 +00:00
|
|
|
#undef ZG_Malloc
|
2014-04-24 01:53:01 +00:00
|
|
|
void *QDECL ZG_Malloc(zonegroup_t *ctx, int size){return ZG_MallocNamed(ctx, size, "ZG_Malloc", size);}
|
2013-07-14 12:22:51 +00:00
|
|
|
void *ZG_MallocNamed(zonegroup_t *ctx, int size, char *file, int line)
|
|
|
|
#else
|
2019-05-23 15:11:32 +00:00
|
|
|
void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size)
|
2013-07-14 12:22:51 +00:00
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
zonegroupblock_t *newm;
|
|
|
|
size += sizeof(zonegroupblock_t); //well, at least the memory will be pointer aligned...
|
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
|
|
|
newm = Z_MallocNamed(size, file, line);
|
|
|
|
#else
|
|
|
|
newm = Z_Malloc(size);
|
|
|
|
#endif
|
2021-04-14 05:21:04 +00:00
|
|
|
|
2022-03-08 05:30:30 +00:00
|
|
|
newm->prev = NULL;
|
|
|
|
if (ctx->first)
|
|
|
|
((zonegroupblock_t*)ctx->first)->prev = newm;
|
2013-07-14 12:22:51 +00:00
|
|
|
newm->next = ctx->first;
|
|
|
|
ctx->first = newm;
|
2020-01-09 15:35:40 +00:00
|
|
|
ctx->totalbytes += size;
|
2022-03-08 05:30:30 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
newm->sentinal = ZONEGROUP_SENTINAL;
|
|
|
|
newm->size = size;
|
|
|
|
#endif
|
2013-07-14 12:22:51 +00:00
|
|
|
return(void*)(newm+1);
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
2022-03-08 05:30:30 +00:00
|
|
|
void ZG_Free(zonegroup_t *ctx, void *ptr)
|
|
|
|
{
|
|
|
|
zonegroupblock_t *mem = (zonegroupblock_t*)ptr-1;
|
|
|
|
if (mem->prev)
|
|
|
|
mem->prev->next = mem->next;
|
|
|
|
else
|
|
|
|
ctx->first = mem->next;
|
|
|
|
if (mem->next)
|
|
|
|
mem->next->prev = mem->prev;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
if (mem->sentinal != ZONEGROUP_SENTINAL)
|
|
|
|
Sys_Error("Corrupt memory");
|
|
|
|
ctx->totalbytes -= mem->size;
|
|
|
|
#endif
|
|
|
|
BZ_Free(mem);
|
|
|
|
}
|
2013-07-14 12:22:51 +00:00
|
|
|
void ZG_FreeGroup(zonegroup_t *ctx)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
zonegroupblock_t *old;
|
|
|
|
while(ctx->first)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
old = ctx->first;
|
|
|
|
ctx->first = old->next;
|
|
|
|
BZ_Free(old);
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
2020-01-09 15:35:40 +00:00
|
|
|
ctx->totalbytes = 0;
|
2013-07-14 12:22:51 +00:00
|
|
|
}
|
2005-09-08 22:52:46 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
//============================================================================
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Hunk_TempAlloc
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
Return space from the top of the hunk
|
|
|
|
clears old temp.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
typedef struct hnktemps_s {
|
|
|
|
struct hnktemps_s *next;
|
|
|
|
#if TEMPDEBUG>0
|
|
|
|
int len;
|
2004-09-20 23:25:38 +00:00
|
|
|
#endif
|
2013-07-14 12:22:51 +00:00
|
|
|
} hnktemps_t;
|
|
|
|
hnktemps_t *hnktemps;
|
2004-09-20 23:25:38 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
void Hunk_TempFree(void)
|
2004-11-23 00:31:46 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
hnktemps_t *nt;
|
2004-11-23 00:31:46 +00:00
|
|
|
|
2014-10-05 20:04:11 +00:00
|
|
|
COM_AssertMainThread("Hunk_TempFree");
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
while (hnktemps)
|
2004-11-23 00:31:46 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
#if TEMPDEBUG>0
|
2004-11-23 00:31:46 +00:00
|
|
|
int i;
|
|
|
|
qbyte *buf;
|
2013-07-14 12:22:51 +00:00
|
|
|
buf = (qbyte *)(hnktemps+1);
|
|
|
|
for (i = 0; i < TEMPDEBUG; i++)
|
2004-11-23 00:31:46 +00:00
|
|
|
{
|
2020-02-26 00:37:52 +00:00
|
|
|
if (buf[i] != sentinelkey)
|
|
|
|
Sys_Error ("Hunk_Check: corrupt sentinel");
|
2004-11-23 00:31:46 +00:00
|
|
|
}
|
2013-07-14 12:22:51 +00:00
|
|
|
buf+=TEMPDEBUG;
|
2004-11-23 00:31:46 +00:00
|
|
|
//app data
|
2013-07-14 12:22:51 +00:00
|
|
|
buf += hnktemps->len;
|
|
|
|
for (i = 0; i < TEMPDEBUG; i++)
|
2004-11-23 00:31:46 +00:00
|
|
|
{
|
2020-02-26 00:37:52 +00:00
|
|
|
if (buf[i] != sentinelkey)
|
|
|
|
Sys_Error ("Hunk_Check: corrupt sentinel");
|
2004-11-23 00:31:46 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
nt = hnktemps->next;
|
2004-11-23 00:31:46 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
free(hnktemps);
|
|
|
|
hnktemps = nt;
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
|
|
|
|
//allocates without clearing previous temp.
|
|
|
|
//safer than my hack that fuh moaned about...
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Hunk_TempAllocMore (size_t size)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
|
|
|
void *buf;
|
2014-10-05 20:04:11 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
#if TEMPDEBUG>0
|
|
|
|
hnktemps_t *nt;
|
2014-10-05 20:04:11 +00:00
|
|
|
COM_AssertMainThread("Hunk_TempAllocMore");
|
2013-07-14 12:22:51 +00:00
|
|
|
nt = (hnktemps_t*)malloc(size + sizeof(hnktemps_t) + TEMPDEBUG*2);
|
2004-08-21 01:25:48 +00:00
|
|
|
if (!nt)
|
2013-07-14 12:22:51 +00:00
|
|
|
return NULL;
|
|
|
|
nt->next = hnktemps;
|
|
|
|
nt->len = size;
|
|
|
|
hnktemps = nt;
|
2004-08-21 01:25:48 +00:00
|
|
|
buf = (void *)(nt+1);
|
2020-02-26 00:37:52 +00:00
|
|
|
memset(buf, sentinelkey, TEMPDEBUG);
|
2013-07-14 12:22:51 +00:00
|
|
|
buf = (char *)buf + TEMPDEBUG;
|
|
|
|
memset(buf, 0, size);
|
2020-02-26 00:37:52 +00:00
|
|
|
memset((char *)buf + size, sentinelkey, TEMPDEBUG);
|
2004-08-21 01:25:48 +00:00
|
|
|
return buf;
|
|
|
|
#else
|
2013-07-14 12:22:51 +00:00
|
|
|
hnktemps_t *nt;
|
2014-10-05 20:04:11 +00:00
|
|
|
COM_AssertMainThread("Hunk_TempAllocMore");
|
2013-07-14 12:22:51 +00:00
|
|
|
nt = (hnktemps_t*)malloc(size + sizeof(hnktemps_t));
|
|
|
|
if (!nt)
|
|
|
|
return NULL;
|
|
|
|
nt->next = hnktemps;
|
|
|
|
hnktemps = nt;
|
|
|
|
buf = (void *)(nt+1);
|
|
|
|
memset(buf, 0, size);
|
2004-08-21 01:25:48 +00:00
|
|
|
return buf;
|
2013-07-14 12:22:51 +00:00
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Hunk_TempAlloc (size_t size)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
Hunk_TempFree();
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
return Hunk_TempAllocMore(size);
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
/*
|
|
|
|
===============================================================================
|
2004-10-03 22:52:02 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
CACHE MEMORY
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
===============================================================================
|
|
|
|
*/
|
|
|
|
void Cache_Flush(void)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
//this generically named function is hyjacked to flush models and sounds, as well as ragdolls etc
|
2018-12-28 00:04:36 +00:00
|
|
|
#ifdef HAVE_CLIENT
|
|
|
|
S_Purge(false);
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_CLIENT) || defined(HAVE_SERVER)
|
2013-07-14 12:22:51 +00:00
|
|
|
#ifdef RAGDOLL
|
|
|
|
rag_flushdolls(true);
|
|
|
|
#endif
|
2013-10-29 17:38:22 +00:00
|
|
|
Mod_Purge(MP_FLUSH);
|
2018-12-28 00:04:36 +00:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_CLIENT
|
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
|
|
|
Image_Purge();
|
|
|
|
#endif
|
2021-07-18 01:28:34 +00:00
|
|
|
|
|
|
|
#ifdef __GLIBC__
|
|
|
|
malloc_trim(0);
|
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
static void Hunk_Print_f (void)
|
2005-09-21 01:14:04 +00:00
|
|
|
{
|
2019-05-23 15:11:32 +00:00
|
|
|
Con_Printf("Z Delta: %"PRIuSIZE"KB\n", zmemdelta/1024); zmemdelta = 0;
|
|
|
|
Con_Printf("Z Total: %"PRIuSIZE"KB\n", zmemtotal/1024);
|
2013-07-14 12:22:51 +00:00
|
|
|
//note: Zone memory isn't tracked reliably. we don't track the mem that is freed, so it'll just climb and climb
|
|
|
|
//we don't track reallocs either.
|
2005-09-21 01:14:04 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
#if 0
|
2005-09-21 01:14:04 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
zone_t *zone;
|
|
|
|
int zoneused = 0;
|
|
|
|
int zoneblocks = 0;
|
2005-09-21 01:14:04 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
for(zone = zone_head; zone; zone=zone->next)
|
2005-09-21 01:14:04 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
zoneused += zone->size + sizeof(zone_t);
|
|
|
|
zoneblocks++;
|
2005-09-21 01:14:04 +00:00
|
|
|
}
|
2013-07-14 12:22:51 +00:00
|
|
|
Con_Printf("Zone: %i containing %iKB\n", zoneblocks, zoneused/1024);
|
2005-09-21 01:14:04 +00:00
|
|
|
}
|
2013-07-14 12:22:51 +00:00
|
|
|
#endif
|
2005-09-21 01:14:04 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
2005-09-21 01:14:04 +00:00
|
|
|
{
|
2013-07-14 12:22:51 +00:00
|
|
|
static struct _CrtMemState savedstate;
|
|
|
|
static qboolean statesaved;
|
2005-09-21 01:14:04 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
_CrtMemDumpAllObjectsSince(statesaved?&savedstate:NULL);
|
|
|
|
_CrtMemCheckpoint(&savedstate);
|
|
|
|
statesaved = true;
|
|
|
|
}
|
2012-07-05 19:42:36 +00:00
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
void Cache_Init(void)
|
|
|
|
{
|
|
|
|
Cmd_AddCommand ("flush", Cache_Flush);
|
|
|
|
Cmd_AddCommand ("hunkprint", Hunk_Print_f);
|
2008-05-09 14:22:37 +00:00
|
|
|
#if 0
|
2004-08-21 01:25:48 +00:00
|
|
|
Cmd_AddCommand ("zoneprint", Zone_Print_f);
|
2008-05-09 14:22:37 +00:00
|
|
|
#endif
|
2005-09-21 01:14:04 +00:00
|
|
|
#ifdef NAMEDMALLOCS
|
|
|
|
Cmd_AddCommand ("zonegroups", Zone_Groups_f);
|
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
Memory_Init
|
|
|
|
========================
|
|
|
|
*/
|
2013-07-14 12:22:51 +00:00
|
|
|
void Memory_Init (void)
|
2004-08-21 01:25:48 +00:00
|
|
|
{
|
2008-05-09 14:22:37 +00:00
|
|
|
#if 0 //ndef NOZONE
|
2004-08-21 01:25:48 +00:00
|
|
|
int p;
|
|
|
|
int zonesize = DYNAMIC_SIZE;
|
|
|
|
#endif
|
|
|
|
|
2004-12-02 06:00:21 +00:00
|
|
|
#if ZONEDEBUG>0 || HUNKDEBUG>0 || TEMPDEBUG>0||CACHEDEBUG>0
|
|
|
|
srand(time(0));
|
2020-02-26 00:37:52 +00:00
|
|
|
sentinelkey = rand() & 0xff;
|
2004-09-20 23:25:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
Cache_Init ();
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (!zonelock)
|
|
|
|
zonelock = Sys_CreateMutex(); // this can fail!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if 0 //ndef NOZONE
|
2004-08-21 01:25:48 +00:00
|
|
|
p = COM_CheckParm ("-zone");
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
if (p < com_argc-1)
|
|
|
|
zonesize = Q_atoi (com_argv[p+1]) * 1024;
|
|
|
|
else
|
|
|
|
Sys_Error ("Memory_Init: you must specify a size in KB after -zone");
|
|
|
|
}
|
|
|
|
mainzone = Hunk_AllocName ( zonesize, "zone" );
|
|
|
|
Z_ClearZone (mainzone, zonesize);
|
|
|
|
#endif
|
Added sys_openfile console command(and menu option) to web and flatpak(via cmake+dbus) builds, to 'install' packages on sandboxed systems a bit more easily.
Cmake: Add FTE_WERROR option, defaults to true in debug builds and off in release builds (in case future compilers have issues).
Cmake: Pull in libXscreensaver so we don't get interrupted by screensavers when playing demos.
Make: Added `make webcl-rel` for a web build without server bloat (eg for sites focused on demo playback. Yes, this means you XantoM).
fteqcc: Include the decompiler in fteqcc (non-gui) builds ('-d' arg).
fteqcc: Decompiler can now mostly handle hexen2 mods without any unknown opcodes.
Allow ezHud and OpenSSL to be compiled as in-engine plugins, potentially for web and windows ports respectively.
Web: Fix support for ogg vorbis. Add support for voip.
Web: Added basic support for WebXR.
QTV: Don't try seeking on unseekable qtv streams. Don't spam when developer 1 is set.
QTV: add support for some eztv extensions.
MVD: added hack to use ktx's vweps in mvd where mvdsv doesn't bother to record the info.
qwfwd: hack around a hack in qwfwd, allowing it to work again.
recording: favour qwd in single player, instead of mvd.
Protocol: reduce client memory used for precache names. Bump maximum precache counts - some people are just abusive, yes you Orl.
hexen2: add enough clientside protocol compat to play the demo included with h2mp. lacks effects.
in_xflip: restored this setting.
fs_hidesyspaths: new cvar, defaults to enabled so you won't find your username or whatever turning up in screenshots or the like. change it to 0 before debuging stuff eg via 'path'.
gl_overbright_models: Added cvar to match QS.
netchan: Added MTU determination, we'll no longer fail to connect when routers stupidly drop icmp packets.
Win: try a few other versions of xinput too.
CSQC: Added a CSQC_GenerateMaterial function, to give the csqc a chance to generate custom materials.
MenuQC: Added support for the skeletal objects API.
2024-04-09 17:13:59 +00:00
|
|
|
|
|
|
|
#ifdef MULTITHREAD
|
|
|
|
Sys_ThreadsInit();
|
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
void Memory_DeInit(void)
|
|
|
|
{
|
2009-04-01 22:03:56 +00:00
|
|
|
Hunk_TempFree();
|
|
|
|
Cache_Flush();
|
|
|
|
|
2008-05-09 14:22:37 +00:00
|
|
|
#ifdef MULTITHREAD
|
|
|
|
if (zonelock)
|
|
|
|
{
|
|
|
|
Sys_DestroyMutex(zonelock);
|
|
|
|
zonelock = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2008-05-14 14:55:25 +00:00
|
|
|
}
|
|
|
|
|