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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
memory allocation
|
|
|
|
|
|
|
|
|
|
|
|
H_??? The hunk manages the entire memory block given to quake. It must be
|
|
|
|
contiguous. Memory can be allocated from either the low or high end in a
|
|
|
|
stack fashion. The only way memory is released is by resetting one of the
|
|
|
|
pointers.
|
|
|
|
|
|
|
|
Hunk allocations should be given a name, so the Hunk_Print () function
|
|
|
|
can display usage.
|
|
|
|
|
|
|
|
Hunk allocations are guaranteed to be 16 byte aligned.
|
|
|
|
|
|
|
|
The video buffers are allocated high to avoid leaving a hole underneath
|
|
|
|
server allocations when changing to a higher video mode.
|
|
|
|
|
|
|
|
|
|
|
|
Z_??? Zone memory functions used for small, dynamic allocations like text
|
|
|
|
strings from command input. There is only about 48K for it, allocated at
|
|
|
|
the very bottom of the hunk.
|
|
|
|
|
|
|
|
Cache_??? Cache memory is for objects that can be dynamically loaded and
|
|
|
|
can usefully stay persistant between levels. The size of the cache
|
|
|
|
fluctuates from level to level.
|
|
|
|
|
|
|
|
To allocate a cachable object
|
|
|
|
|
|
|
|
|
|
|
|
Temp_??? Temp memory is used for file loading and surface caching. The size
|
|
|
|
of the cache memory is adjusted so that there is a minimum of 512k remaining
|
|
|
|
for temp memory.
|
|
|
|
|
|
|
|
|
|
|
|
------ Top of Memory -------
|
|
|
|
|
|
|
|
high hunk allocations
|
|
|
|
|
|
|
|
<--- high hunk reset point held by vid
|
|
|
|
|
|
|
|
video buffer
|
|
|
|
|
|
|
|
z buffer
|
|
|
|
|
|
|
|
surface cache
|
|
|
|
|
|
|
|
<--- high hunk used
|
|
|
|
|
|
|
|
cachable memory
|
|
|
|
|
|
|
|
<--- low hunk used
|
|
|
|
|
|
|
|
client and server low hunk allocations
|
|
|
|
|
|
|
|
<-- low hunk reset point held by host
|
|
|
|
|
|
|
|
startup hunk allocations
|
|
|
|
|
|
|
|
Zone block
|
|
|
|
|
|
|
|
----- Bottom of Memory -----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2019-07-29 05:28:20 +00:00
|
|
|
#if 0//defined(_DEBUG) && defined(__linux__) && !defined(ANDROID)
|
|
|
|
#include <valgrind/memcheck.h>
|
|
|
|
#else
|
|
|
|
#define VALGRIND_MAKE_MEM_UNDEFINED(ptr,sz) //as an alternative to memzero..
|
|
|
|
#define VALGRIND_MAKE_MEM_NOACCESS(ptr,sz)
|
2021-05-09 13:02:49 +00:00
|
|
|
#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(ptr,sz) //undo VALGRIND_MAKE_MEM_UNDEFINED, to make sure we don't read past the end of buffers.
|
2019-07-29 05:28:20 +00:00
|
|
|
#endif
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
void Memory_Init (void);
|
2008-05-09 14:22:37 +00:00
|
|
|
void Memory_DeInit(void);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2020-03-25 21:29:30 +00:00
|
|
|
//Prefixes:
|
|
|
|
//Z - just general 'zone' memory.
|
|
|
|
//B - allocated memory is not zero-filled.
|
|
|
|
//F - allocation can return NULL (otherwise sys_errors)
|
|
|
|
//G - special set of functions with its own rules. Frees must not be mixed.
|
|
|
|
//Tag - additional special set of functions with their own rules. Frees must not be mixed.
|
2005-03-18 06:13:36 +00:00
|
|
|
void VARGS Z_Free (void *ptr);
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Z_Malloc (size_t size); // returns 0 filled memory
|
|
|
|
void *ZF_Malloc (size_t size); // allowed to fail
|
|
|
|
void *Z_MallocNamed (size_t size, char *file, int line); // returns 0 filled memory
|
|
|
|
void *ZF_MallocNamed (size_t size, char *file, int line); // allowed to fail
|
2004-08-21 01:25:48 +00:00
|
|
|
//#define Z_Malloc(x) Z_MallocNamed2(x, __FILE__, __LINE__ )
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Z_TagMalloc (size_t size, int tag);
|
2008-05-09 14:22:37 +00:00
|
|
|
void VARGS Z_TagFree(void *ptr);
|
2005-03-18 06:13:36 +00:00
|
|
|
void VARGS Z_FreeTags(int tag);
|
2015-04-14 23:12:17 +00:00
|
|
|
qboolean ZF_ReallocElements(void **ptr, size_t *elements, size_t newelements, size_t elementsize); //returns false on error
|
2017-04-18 11:12:17 +00:00
|
|
|
qboolean ZF_ReallocElementsNamed(void **ptr, size_t *elements, size_t newelements, size_t elementsize, const char *file, int line); //returns false on error
|
2015-04-14 23:12:17 +00:00
|
|
|
#define Z_ReallocElements(ptr,elements,newelements,elementsize) do{if (!ZF_ReallocElements(ptr,elements,newelements,elementsize))Sys_Error("Z_ReallocElements failed (%s %i)\n", __FILE__, __LINE__);}while(0) //returns false on error
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2014-03-30 08:55:06 +00:00
|
|
|
//Big Zone: allowed to fail, doesn't clear. The expectation is a large file, rather than sensitive data structures.
|
2004-08-21 01:25:48 +00:00
|
|
|
//(this is a nicer name for malloc)
|
2019-05-23 15:11:32 +00:00
|
|
|
void *BZ_Malloc(size_t size);
|
|
|
|
void *BZF_Malloc(size_t size);
|
|
|
|
void *BZ_MallocNamed (size_t size, const char *file, int line); // returns 0 filled memory
|
|
|
|
void *BZF_MallocNamed (size_t size, const char *file, int line); // allowed to fail
|
|
|
|
void *BZ_Realloc(void *ptr, size_t size);
|
|
|
|
void *BZ_ReallocNamed(void *data, size_t newsize, const char *file, int line);
|
|
|
|
void *BZF_Realloc(void *data, size_t newsize);
|
|
|
|
void *BZF_ReallocNamed(void *data, size_t newsize, const char *file, int line);
|
2004-08-21 01:25:48 +00:00
|
|
|
void BZ_Free(void *ptr);
|
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
//ctx should start off as void*ctx=NULL
|
|
|
|
typedef struct zonegroup_s
|
|
|
|
{
|
|
|
|
void *first;
|
2020-01-09 15:35:40 +00:00
|
|
|
int totalbytes; //combined size of all mallocs in this group
|
2013-07-14 12:22:51 +00:00
|
|
|
} zonegroup_t;
|
2019-05-23 15:11:32 +00:00
|
|
|
void *QDECL ZG_Malloc(zonegroup_t *ctx, size_t size);
|
|
|
|
void *ZG_MallocNamed(zonegroup_t *ctx, size_t size, char *file, int line);
|
2022-03-08 05:30:30 +00:00
|
|
|
void QDECL ZG_Free(zonegroup_t *ctx, void *ptr);
|
|
|
|
void QDECL ZG_FreeGroup(zonegroup_t *ctx);
|
2013-07-14 12:22:51 +00:00
|
|
|
|
2012-07-05 19:42:36 +00:00
|
|
|
#ifdef USE_MSVCRT_DEBUG
|
|
|
|
#define BZ_Malloc(size) BZ_MallocNamed(size, __FILE__, __LINE__)
|
2004-08-21 01:25:48 +00:00
|
|
|
#define Z_Malloc(size) Z_MallocNamed(size, __FILE__, __LINE__)
|
2012-07-05 19:42:36 +00:00
|
|
|
#define BZ_Realloc(ptr, size) BZ_ReallocNamed(ptr, size, __FILE__, __LINE__)
|
|
|
|
#define BZF_Malloc(size) BZF_MallocNamed(size, __FILE__, __LINE__)
|
|
|
|
#define ZF_Malloc(size) ZF_MallocNamed(size, __FILE__, __LINE__)
|
|
|
|
#define BZF_Realloc(ptr, size) BZF_ReallocNamed(ptr, size, __FILE__, __LINE__)
|
2013-07-14 12:22:51 +00:00
|
|
|
#define ZG_Malloc(ctx, size) ZG_MallocNamed(ctx, size, __FILE__, __LINE__)
|
2017-03-30 18:37:16 +00:00
|
|
|
#define ZF_ReallocElements(p,e,n,s) ZF_ReallocElementsNamed(p,e,n,s,__FILE__,__LINE__)
|
2004-08-21 01:25:48 +00:00
|
|
|
#endif
|
2013-06-23 02:17:02 +00:00
|
|
|
#define Z_StrDup(s) strcpy(Z_Malloc(strlen(s)+1), s)
|
2019-03-23 07:06:37 +00:00
|
|
|
#define Z_StrDupPtr(v,s) do{Z_Free(*v),*(v) = strcpy(Z_Malloc(strlen(s)+1), s);}while(0)
|
2013-06-23 02:17:02 +00:00
|
|
|
|
2021-07-17 15:11:15 +00:00
|
|
|
char *Z_StrDupf(const char *format, ...);
|
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
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
/*
|
2004-08-21 01:25:48 +00:00
|
|
|
void *Hunk_Alloc (int size); // returns 0 filled memory
|
|
|
|
void *Hunk_AllocName (int size, char *name);
|
2013-07-14 12:22:51 +00:00
|
|
|
*/
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2019-05-23 15:11:32 +00:00
|
|
|
void *Hunk_TempAlloc (size_t size);
|
|
|
|
void *Hunk_TempAllocMore (size_t size); //Don't clear old temp
|
2004-08-21 01:25:48 +00:00
|
|
|
|
2013-07-14 12:22:51 +00:00
|
|
|
/*
|
2004-08-21 01:25:48 +00:00
|
|
|
typedef struct cache_user_s
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
qboolean fake;
|
|
|
|
} cache_user_t;
|
2013-07-14 12:22:51 +00:00
|
|
|
*/
|
2004-08-21 01:25:48 +00:00
|
|
|
void Cache_Flush (void);
|
2013-07-14 12:22:51 +00:00
|
|
|
/*
|
2004-08-21 01:25:48 +00:00
|
|
|
void *Cache_Check (cache_user_t *c);
|
|
|
|
// returns the cached data, and moves to the head of the LRU list
|
|
|
|
// if present, otherwise returns NULL
|
|
|
|
|
|
|
|
void Cache_Free (cache_user_t *c);
|
|
|
|
|
|
|
|
void *Cache_Alloc (cache_user_t *c, int size, char *name);
|
|
|
|
// Returns NULL if all purgable data was tossed and there still
|
|
|
|
// wasn't enough room.
|
|
|
|
|
|
|
|
void Cache_Report (void);
|
2013-07-14 12:22:51 +00:00
|
|
|
*/
|