From 3b0aa43aed85e02e8c57f2a7fa404b7a7f25bfda Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Tue, 1 Aug 2023 11:11:58 +0200 Subject: [PATCH 01/11] "Clean up and simplify zone memory allocation" more like, port zone memory stuff from srb2, idk may fix some stutter issues and give better performance in some cases still, see: https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2059 --- src/z_zone.c | 513 ++++++++++++++++++++++++++------------------------- src/z_zone.h | 136 ++++++++------ 2 files changed, 340 insertions(+), 309 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index 2214fb21f..740c28ac8 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -1,7 +1,7 @@ // SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // Copyright (C) 2006 by Graue. -// Copyright (C) 2006-2018 by Sonic Team Junior. +// Copyright (C) 2006-2023 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. @@ -27,6 +27,7 @@ #include "doomdef.h" #include "doomstat.h" +#include "r_patch.h" #include "i_system.h" // I_GetFreeMem #include "i_video.h" // rendermode #include "z_zone.h" @@ -49,27 +50,11 @@ static boolean Z_calloc = false; //#define ZDEBUG2 #endif -struct memblock_s; - -typedef struct -{ - struct memblock_s *block; // Describing this memory - UINT32 id; // Should be ZONEID -} ATTRPACK memhdr_t; - -// Some code might want aligned memory. Assume it wants memory n bytes -// aligned -- then we allocate n-1 extra bytes and return a pointer to -// the first byte aligned as requested. -// Thus, "real" is the pointer we get from malloc() and will free() -// later, but "hdr" is where the memhdr_t starts. -// For non-aligned allocations they will be the same. typedef struct memblock_s { - void *real; - memhdr_t *hdr; - void **user; INT32 tag; // purgelevel + UINT32 id; // Should be ZONEID size_t size; // including the header and blocks size_t realsize; // size of real data only @@ -80,74 +65,41 @@ typedef struct memblock_s #endif struct memblock_s *next, *prev; -} ATTRPACK memblock_t; +} memblock_t; -#ifdef ZDEBUG -#define Ptr2Memblock(s, f) Ptr2Memblock2(s, f, __FILE__, __LINE__) -static memblock_t *Ptr2Memblock2(void *ptr, const char* func, const char *file, INT32 line) -#else -static memblock_t *Ptr2Memblock(void *ptr, const char* func) -#endif -{ - memhdr_t *hdr; - memblock_t *block; - - if (ptr == NULL) - return NULL; - -#ifdef ZDEBUG2 - CONS_Printf("%s %s:%d\n", func, file, line); -#endif - - hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); - -#ifdef VALGRIND_MAKE_MEM_DEFINED - VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); -#endif - -#ifdef VALGRIND_MEMPOOL_EXISTS - if (!VALGRIND_MEMPOOL_EXISTS(hdr->block)) - { -#ifdef ZDEBUG - I_Error("%s: bad memblock from %s:%d", func, file, line); -#else - I_Error("%s: bad memblock", func); -#endif - } -#endif - if (hdr->id != ZONEID) - { -#ifdef ZDEBUG - I_Error("%s: wrong id from %s:%d", func, file, line); -#else - I_Error("%s: wrong id", func); -#endif - } - block = hdr->block; -#ifdef VALGRIND_MAKE_MEM_NOACCESS - VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); -#endif - return block; - -} +#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t)) +#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - sizeof(memblock_t)) +// both the head and tail of the zone memory block list static memblock_t head; +// +// Function prototypes +// static void Command_Memfree_f(void); #ifdef ZDEBUG static void Command_Memdump_f(void); #endif +// -------------------------- +// Zone memory initialisation +// -------------------------- + +/** Initialises zone memory. + * Used at game startup. + * + * \sa I_GetFreeMem, Command_Memfree_f, Command_Memdump_f + */ void Z_Init(void) { - UINT32 total, memfree; + size_t total, memfree; memset(&head, 0x00, sizeof(head)); head.next = head.prev = &head; memfree = I_GetFreeMem(&total)>>20; - CONS_Printf("System memory: %uMB - Free: %uMB\n", total>>20, memfree); + CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree)); // Note: This allocates memory. Watch out. COM_AddCommand("memfree", Command_Memfree_f); @@ -157,6 +109,17 @@ void Z_Init(void) #endif } + +// ---------------------- +// Zone memory allocation +// ---------------------- + +/** Frees allocated memory. + * + * \param ptr A pointer to allocated memory, + * assumed to have been allocated with Z_Malloc/Z_Calloc. + * \sa Z_FreeTags + */ #ifdef ZDEBUG void Z_Free2(void *ptr, const char *file, INT32 line) #else @@ -172,10 +135,14 @@ void Z_Free(void *ptr) CONS_Debug(DBG_MEMORY, "Z_Free %s:%d\n", file, line); #endif + block = MEMBLOCK(ptr); +#ifdef PARANOIA + if (block->id != ZONEID) #ifdef ZDEBUG - block = Ptr2Memblock2(ptr, "Z_Free", file, line); + I_Error("Z_Free at %s:%d: wrong id", file, line); #else - block = Ptr2Memblock(ptr, "Z_Free"); + I_Error("Z_Free: wrong id"); +#endif #endif #ifdef ZDEBUG @@ -183,11 +150,9 @@ void Z_Free(void *ptr) CONS_Debug(DBG_MEMORY, "Z_Free at %s:%d\n", file, line); #endif -#ifdef HAVE_BLUA // anything that isn't by lua gets passed to lua just in case. if (block->tag != PU_LUA) LUA_InvalidateUserdata(ptr); -#endif // TODO: if zdebugging, make sure no other block has a user // that is about to be freed. @@ -196,21 +161,27 @@ void Z_Free(void *ptr) if (block->user != NULL) *block->user = NULL; - // Free the memory and get rid of the block. - free(block->real); - block->prev->next = block->next; - block->next->prev = block->prev; - free(block); #ifdef VALGRIND_DESTROY_MEMPOOL VALGRIND_DESTROY_MEMPOOL(block); #endif + block->prev->next = block->next; + block->next->prev = block->prev; + free(block); } -// malloc() that doesn't accept failure. +/** malloc() that doesn't accept failure. + * + * \param size Amount of memory to be allocated, in bytes. + * \return A pointer to the allocated memory. + */ static void *xm(size_t size) { const size_t padedsize = size+sizeof (size_t); - void *p = malloc(padedsize); + void *p; + + if (padedsize < size)/* overflow check */ + I_Error("You are allocating memory too large!"); + p = malloc(padedsize); if (p == NULL) { @@ -220,10 +191,6 @@ static void *xm(size_t size) if (p == NULL) { -#if defined (_NDS) | defined (_PSP) - // Temporary-ish debugging measure - Command_Memfree_f(); -#endif I_Error("Out of memory allocating %s bytes", sizeu1(size)); } } @@ -231,10 +198,18 @@ static void *xm(size_t size) return p; } -// Z_Malloc -// You can pass Z_Malloc() a NULL user if the tag is less than -// PU_PURGELEVEL. - +/** The Z_MallocAlign function. + * Allocates a block of memory, adds it to a linked list so we can keep track of it. + * + * \param size Amount of memory to be allocated, in bytes. + * \param tag Purge tag. + * \param user The address of a pointer to the memory to be allocated. + * When the memory is freed by Z_Free later, + * the pointer at this address will then be automatically set to NULL. + * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. + * \note You can pass Z_Malloc() a NULL user if the tag is less than PU_PURGELEVEL. + * \sa Z_CallocAlign, Z_ReallocAlign + */ #ifdef ZDEBUG void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) @@ -242,81 +217,67 @@ void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) #endif { - // I have 0 knowledge about memory alignment but maybe if alignbits is - // something like 32 that would require too much BYTES, so bits amount - // should be divided by 8? Idk, maybe this would break alignment, but at - // least game wouldn't crash with "error allocating 2^32-1 bytes" - INT32 alignbytes = alignbits/8; - I_Assert(alignbytes >= 0 && alignbytes < (INT32)(sizeof(size_t) * 8)); - size_t extrabytes = ((size_t)1<<(alignbytes)) - 1; - size_t padsize = 0; memblock_t *block; void *ptr; - memhdr_t *hdr; - void *given; - size_t blocksize = extrabytes + sizeof *hdr + size; + (void)(alignbits); // no longer used, so silence warnings. #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line); #endif - block = xm(sizeof *block); + block = xm(sizeof (memblock_t) + size); + ptr = MEMORY(block); + I_Assert((intptr_t)ptr % sizeof (void *) == 0); + #ifdef HAVE_VALGRIND - padsize += (1<next = head.next; block->prev = &head; head.next = block; block->next->prev = block; - block->real = ptr; - block->hdr = hdr; block->tag = tag; block->user = NULL; #ifdef ZDEBUG block->ownerline = line; block->ownerfile = file; #endif - block->size = blocksize; + block->size = sizeof (memblock_t) + size; block->realsize = size; - hdr->id = ZONEID; - hdr->block = block; - -#ifdef VALGRIND_MAKE_MEM_NOACCESS - VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); +#ifdef VALGRIND_CREATE_MEMPOOL + VALGRIND_CREATE_MEMPOOL(block, size, Z_calloc); #endif + block->id = ZONEID; + if (user != NULL) { block->user = user; - *(void **)user = given; + *(void **)user = ptr; } else if (tag >= PU_PURGELEVEL) I_Error("Z_Malloc: attempted to allocate purgable block " "(size %s) with no user", sizeu1(size)); - return given; + return ptr; } +/** The Z_CallocAlign function. + * Allocates a block of memory, adds it to a linked list so we can keep track of it. + * Unlike Z_MallocAlign, this also initialises the bytes to zero. + * + * \param size Amount of memory to be allocated, in bytes. + * \param tag Purge tag. + * \param user The address of a pointer to the memory to be allocated. + * When the memory is freed by Z_Free later, + * the pointer at this address will then be automatically set to NULL. + * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. + * \note You can pass Z_Calloc() a NULL user if the tag is less than PU_PURGELEVEL. + * \sa Z_MallocAlign, Z_ReallocAlign + */ #ifdef ZDEBUG void *Z_Calloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) #else @@ -333,10 +294,26 @@ void *Z_CallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) #endif } +/** The Z_ReallocAlign function. + * Reallocates a block of memory with a new size. + * + * \param ptr A pointer to allocated memory, + * assumed to have been allocated with Z_Malloc/Z_Calloc. + * If NULL, this function instead acts as a wrapper for Z_CallocAlign. + * \param size New size of memory block, in bytes. + * If zero, then the memory is freed and NULL is returned. + * \param tag New purge tag. + * \param user The address of a pointer to the memory to be reallocated. + * This can be a different user to the one originally assigned to the memory block. + * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. + * \return A pointer to the reallocated memory. Can be NULL if memory was freed. + * \note You can pass Z_Realloc() a NULL user if the tag is less than PU_PURGELEVEL. + * \sa Z_MallocAlign, Z_CallocAlign + */ #ifdef ZDEBUG void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) #else -void *Z_ReallocAlign(void *ptr, size_t size,INT32 tag, void *user, INT32 alignbits) +void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) #endif { void *rez; @@ -362,10 +339,14 @@ void *Z_ReallocAlign(void *ptr, size_t size,INT32 tag, void *user, INT32 alignb #endif } + block = MEMBLOCK(ptr); +#ifdef PARANOIA + if (block->id != ZONEID) #ifdef ZDEBUG - block = Ptr2Memblock2(ptr, "Z_Realloc", file, line); + I_Error("Z_ReallocAlign at %s:%d: wrong id", file, line); #else - block = Ptr2Memblock(ptr, "Z_Realloc"); + I_Error("Z_ReallocAlign: wrong id"); +#endif #endif if (block == NULL) @@ -403,6 +384,11 @@ void *Z_ReallocAlign(void *ptr, size_t size,INT32 tag, void *user, INT32 alignb return rez; } +/** Frees all memory for a given set of tags. + * + * \param lowtag The lowest tag to consider. + * \param hightag The highest tag to consider. + */ void Z_FreeTags(INT32 lowtag, INT32 hightag) { memblock_t *block, *next; @@ -411,28 +397,57 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag) for (block = head.next; block != &head; block = next) { next = block->next; // get link before freeing - if (block->tag >= lowtag && block->tag <= hightag) - Z_Free((UINT8 *)block->hdr + sizeof *block->hdr); + Z_Free(MEMORY(block)); } } -// -// Z_CheckMemCleanup -// -// TODO: Currently blocks >= PU_PURGELEVEL are freed every -// CLEANUPCOUNT. It might be better to keep track of -// the total size of all purgable memory and free it when the -// size exceeds some value. -// -// This was in Z_Malloc, but was freeing data at -// unsafe times. Now it is only called when it is safe -// to cleanup memory. +/** Iterates through all memory for a given set of tags. + * + * \param lowtag The lowest tag to consider. + * \param hightag The highest tag to consider. + * \param iterfunc The iterator function. + */ +void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)) +{ + memblock_t *block, *next; + if (!iterfunc) + I_Error("Z_IterateTags: no iterator function was given"); + + for (block = head.next; block != &head; block = next) + { + next = block->next; // get link before possibly freeing + + if (block->tag >= lowtag && block->tag <= hightag) + { + void *mem = MEMORY(block); + boolean free = iterfunc(mem); + if (free) + Z_Free(mem); + } + } +} + +// ----------------- +// Utility functions +// ----------------- + +// starting value of nextcleanup #define CLEANUPCOUNT 2000 +// number of function calls left before next cleanup static INT32 nextcleanup = CLEANUPCOUNT; +/** This was in Z_Malloc, but was freeing data at + * unsafe times. Now it is only called when it is safe + * to cleanup memory. + * + * \todo Currently blocks >= PU_PURGELEVEL are freed every + * CLEANUPCOUNT. It might be better to keep track of + * the total size of all purgable memory and free it when the + * size exceeds some value. + */ void Z_CheckMemCleanup(void) { if (nextcleanup-- == 0) @@ -451,15 +466,13 @@ void Z_CheckMemCleanup(void) void Z_CheckHeap(INT32 i) { memblock_t *block; - memhdr_t *hdr; UINT32 blocknumon = 0; void *given; for (block = head.next; block != &head; block = block->next) { blocknumon++; - hdr = block->hdr; - given = (UINT8 *)hdr + sizeof *hdr; + given = MEMORY(block); #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "block %u owned by %s:%d\n", blocknumon, block->ownerfile, block->ownerline); @@ -475,7 +488,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } #endif if (block->user != NULL && *(block->user) != given) @@ -488,7 +501,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } if (block->next->prev != block) { @@ -500,7 +513,7 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } if (block->prev->next != block) { @@ -512,25 +525,9 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } -#ifdef VALGRIND_MAKE_MEM_DEFINED - VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); -#endif - if (hdr->block != block) - { - I_Error("Z_CheckHeap %d: block %u" -#ifdef ZDEBUG - "(owned by %s:%d)" -#endif - " doesn't have linkback from allocated memory", - i, blocknumon -#ifdef ZDEBUG - , block->ownerfile, block->ownerline -#endif - ); - } - if (hdr->id != ZONEID) + if (block->id != ZONEID) { I_Error("Z_CheckHeap %d: block %u" #ifdef ZDEBUG @@ -540,50 +537,37 @@ void Z_CheckHeap(INT32 i) #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif - ); + ); } -#ifdef VALGRIND_MAKE_MEM_NOACCESS - VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); -#endif } } +// ------------------------ +// Zone memory modification +// ------------------------ + +/** Changes a memory block's purge tag. + * + * \param ptr A pointer to allocated memory, + * assumed to have been allocated with Z_Malloc/Z_Calloc. + * \param tag The new tag. + * \sa Z_SetUser + */ #ifdef PARANOIA void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line) #else -void Z_ChangeTag2(void *ptr, INT32 tag) +void Z_ChangeTag(void *ptr, INT32 tag) #endif { memblock_t *block; - memhdr_t *hdr; if (ptr == NULL) return; - hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); + block = MEMBLOCK(ptr); -#ifdef VALGRIND_MAKE_MEM_DEFINED - VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); -#endif - -#ifdef VALGRIND_MEMPOOL_EXISTS - if (!VALGRIND_MEMPOOL_EXISTS(hdr->block)) - { #ifdef PARANOIA - I_Error("Z_CT at %s:%d: bad memblock", file, line); -#else - I_Error("Z_CT: bad memblock"); -#endif - } -#endif -#ifdef PARANOIA - if (hdr->id != ZONEID) I_Error("Z_CT at %s:%d: wrong id", file, line); -#endif - - block = hdr->block; - -#ifdef VALGRIND_MAKE_MEM_NOACCESS - VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); + if (block->id != ZONEID) I_Error("Z_ChangeTag at %s:%d: wrong id", file, line); #endif if (tag >= PU_PURGELEVEL && block->user == NULL) @@ -593,12 +577,48 @@ void Z_ChangeTag2(void *ptr, INT32 tag) block->tag = tag; } +/** Changes a memory block's user. + * + * \param ptr A pointer to allocated memory, + * assumed to have been allocated with Z_Malloc/Z_Calloc. + * \param newuser The new user for the memory block. + * \sa Z_ChangeTag + */ +#ifdef PARANOIA +void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line) +#else +void Z_SetUser(void *ptr, void **newuser) +#endif +{ + memblock_t *block; + + if (ptr == NULL) + return; + + block = MEMBLOCK(ptr); + +#ifdef PARANOIA + if (block->id != ZONEID) I_Error("Z_SetUser at %s:%d: wrong id", file, line); +#endif + + if (block->tag >= PU_PURGELEVEL && newuser == NULL) + I_Error("Internal memory management error: " + "tried to make block purgable but it has no owner"); + + block->user = (void*)newuser; + *newuser = ptr; +} + +// ----------------- +// Zone memory usage +// ----------------- + /** Calculates memory usage for a given set of tags. + * * \param lowtag The lowest tag to consider. * \param hightag The highest tag to consider. * \return Number of bytes currently allocated in the heap for the * given tags. - * \sa Z_TagUsage */ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) { @@ -615,44 +635,60 @@ size_t Z_TagsUsage(INT32 lowtag, INT32 hightag) return cnt; } -size_t Z_TagUsage(INT32 tagnum) -{ - return Z_TagsUsage(tagnum, tagnum); -} +// ----------------------- +// Miscellaneous functions +// ----------------------- -void Command_Memfree_f(void) +/** The function called by the "memfree" console command. + * Prints the memory being used by each part of the game to the console. + */ +static void Command_Memfree_f(void) { - UINT32 freebytes, totalbytes; + size_t freebytes, totalbytes; Z_CheckHeap(-1); CONS_Printf("\x82%s", M_GetText("Memory Info\n")); - CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TagsUsage(0, INT32_MAX)>>10)); - CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); - CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); - CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); - CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); - CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); - CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); - CONS_Printf(M_GetText("All purgable : %7s KB\n"), + CONS_Printf(M_GetText("Total heap used : %7s KB\n"), sizeu1(Z_TotalUsage()>>10)); + CONS_Printf(M_GetText("Static : %7s KB\n"), sizeu1(Z_TagUsage(PU_STATIC)>>10)); + CONS_Printf(M_GetText("Static (sound) : %7s KB\n"), sizeu1(Z_TagUsage(PU_SOUND)>>10)); + CONS_Printf(M_GetText("Static (music) : %7s KB\n"), sizeu1(Z_TagUsage(PU_MUSIC)>>10)); + CONS_Printf(M_GetText("Patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH)>>10)); + CONS_Printf(M_GetText("Patches (low priority) : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH_LOWPRIORITY)>>10)); + CONS_Printf(M_GetText("Patches (rotated) : %7s KB\n"), sizeu1(Z_TagUsage(PU_PATCH_ROTATED)>>10)); + CONS_Printf(M_GetText("Sprites : %7s KB\n"), sizeu1(Z_TagUsage(PU_SPRITE)>>10)); + CONS_Printf(M_GetText("HUD graphics : %7s KB\n"), sizeu1(Z_TagUsage(PU_HUDGFX)>>10)); + CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); + CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); + CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); + CONS_Printf(M_GetText("All purgable : %7s KB\n"), sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); #ifdef HWRENDER - if (rendermode != render_soft && rendermode != render_none) + if (rendermode == render_opengl) { - CONS_Printf(M_GetText("Patch info headers: %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); - CONS_Printf(M_GetText("Mipmap patches : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); - CONS_Printf(M_GetText("HW Texture cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); - CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); + CONS_Printf(M_GetText("Patch info headers : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHINFO)>>10)); + CONS_Printf(M_GetText("Cached textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRCACHE)>>10)); + CONS_Printf(M_GetText("Texture colormaps : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPATCHCOLMIPMAP)>>10)); + CONS_Printf(M_GetText("Model textures : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRMODELTEXTURE)>>10)); + CONS_Printf(M_GetText("Plane polygons : %7s KB\n"), sizeu1(Z_TagUsage(PU_HWRPLANE)>>10)); + //CONS_Printf(M_GetText("All GPU textures : %7d KB\n"), HWR_GetTextureUsed()>>10); } #endif CONS_Printf("\x82%s", M_GetText("System Memory Info\n")); freebytes = I_GetFreeMem(&totalbytes); - CONS_Printf(M_GetText(" Total physical memory: %7u KB\n"), totalbytes>>10); - CONS_Printf(M_GetText("Available physical memory: %7u KB\n"), freebytes>>10); + CONS_Printf(M_GetText(" Total physical memory: %s KB\n"), sizeu1(totalbytes>>10)); + CONS_Printf(M_GetText("Available physical memory: %s KB\n"), sizeu1(freebytes>>10)); } + + #ifdef ZDEBUG +/** The function called by the "memdump" console command. + * Prints zone memory debugging information (i.e. tag, size, location in code allocated). + * Can be all memory allocated in game, or between a set of tags (if -min/-max args used). + * This command is available only if ZDEBUG is enabled. + */ static void Command_Memdump_f(void) { memblock_t *block; @@ -674,45 +710,12 @@ static void Command_Memdump_f(void) } #endif -// Creates a copy of a string. +/** Creates a copy of a string. + * + * \param s The string to be copied. + * \return A copy of the string, allocated in zone memory. + */ char *Z_StrDup(const char *s) { return strcpy(ZZ_Alloc(strlen(s) + 1), s); } - - -#ifdef PARANOIA -void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line) -#else -void Z_SetUser2(void *ptr, void **newuser) -#endif -{ - memblock_t *block; - memhdr_t *hdr; - - if (ptr == NULL) - return; - - hdr = (memhdr_t *)((UINT8 *)ptr - sizeof *hdr); - -#ifdef VALGRIND_MAKE_MEM_DEFINED - VALGRIND_MAKE_MEM_DEFINED(hdr, sizeof *hdr); -#endif - -#ifdef PARANOIA - if (hdr->id != ZONEID) I_Error("Z_CT at %s:%d: wrong id", file, line); -#endif - - block = hdr->block; - -#ifdef VALGRIND_MAKE_MEM_NOACCESS - VALGRIND_MAKE_MEM_NOACCESS(hdr, sizeof *hdr); -#endif - - if (block->tag >= PU_PURGELEVEL && newuser == NULL) - I_Error("Internal memory management error: " - "tried to make block purgable but it has no owner"); - - block->user = (void*)newuser; - *newuser = ptr; -} diff --git a/src/z_zone.h b/src/z_zone.h index 9466f0338..36894e996 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -2,7 +2,7 @@ //----------------------------------------------------------------------------- // Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1998-2000 by DooM Legacy Team. -// Copyright (C) 1999-2018 by Sonic Team Junior. +// Copyright (C) 1999-2023 by Sonic Team Junior. // // This program is free software distributed under the // terms of the GNU General Public License, version 2. @@ -15,6 +15,7 @@ #define __Z_ZONE__ #include +#include "doomdef.h" #include "doomtype.h" #ifdef __GNUC__ // __attribute__ ((X)) @@ -30,52 +31,59 @@ //#define ZDEBUG // -// ZONE MEMORY -// PU - purge tags. -// Tags < PU_LEVEL are not purged until freed explicitly. -#define PU_STATIC 1 // static entire execution time -#define PU_LUA 2 // static entire execution time -- used by lua so it doesn't get caught in loops forever +// Purge tags +// +// Now they are an enum! -- Monster Iestyn 15/02/18 +// +enum +{ + // Tags < PU_LEVEL are not purged until freed explicitly. + PU_STATIC = 1, // static entire execution time + PU_LUA = 2, // static entire execution time -- used by lua so it doesn't get caught in loops forever + PU_PERFSTATS = 3, // static between changes to ps_samplesize cvar -#define PU_PERFSTATS 3 // static between changes to ps_samplesize cvar + PU_SOUND = 11, // static while playing + PU_MUSIC = 12, // static while playing -#define PU_SOUND 11 // static while playing -#define PU_MUSIC 12 // static while playing -#define PU_HUDGFX 13 // static until WAD added + PU_PATCH = 14, // static entire execution time + PU_PATCH_LOWPRIORITY = 15, // lower priority patch, static until level exited + PU_PATCH_ROTATED = 16, // rotated patch, static until level exited or WAD added + PU_PATCH_DATA = 17, // patch data, lifetime depends on the patch that owns it + PU_SPRITE = 18, // sprite patch, static until WAD added + PU_HUDGFX = 19, // HUD patch, static until WAD added -#define PU_HWRPATCHINFO 21 // Hardware GLPatch_t struct for OpenGL texture cache -#define PU_HWRPATCHCOLMIPMAP 22 // Hardware GLMipmap_t struct colromap variation of patch + PU_HWRPATCHINFO = 21, // Hardware GLPatch_t struct for OpenGL texture cache + PU_HWRPATCHCOLMIPMAP = 22, // Hardware GLMipmap_t struct colormap variation of patch + PU_HWRMODELTEXTURE = 23, // Hardware model texture -#define PU_HWRCACHE 48 // static until unlocked -#define PU_CACHE 49 // static until unlocked + PU_HWRCACHE = 48, // static until unlocked + PU_CACHE = 49, // static until unlocked -// Tags s.t. PU_LEVEL <= tag < PU_PURGELEVEL are purged at level start -#define PU_LEVEL 50 // static until level exited -#define PU_LEVSPEC 51 // a special thinker in a level -#define PU_HWRPLANE 52 + // Tags s.t. PU_LEVEL <= tag < PU_PURGELEVEL are purged at level start + PU_LEVEL = 50, // static until level exited + PU_LEVSPEC = 51, // a special thinker in a level + PU_HWRPLANE = 52, // if ZPLANALLOC is enabled in hw_bsp.c, this is used to alloc polygons for OpenGL -// Tags >= PU_PURGELEVEL are purgable whenever needed -#define PU_PURGELEVEL 100 -#define PU_CACHE_UNLOCKED 101 -#define PU_HWRCACHE_UNLOCKED 102 // 'second-level' cache for graphics - // stored in hardware format and downloaded as needed -#define PU_HWRPATCHINFO_UNLOCKED 103 + // Tags >= PU_PURGELEVEL are purgable whenever needed + PU_PURGELEVEL = 100, // Note: this is never actually used as a tag + PU_CACHE_UNLOCKED = 101, // Note: unused + PU_HWRCACHE_UNLOCKED = 102, // 'unlocked' PU_HWRCACHE memory: + // 'second-level' cache for graphics + // stored in hardware format and downloaded as needed + PU_HWRPATCHINFO_UNLOCKED = 103, // 'unlocked' PU_HWRMODELTEXTURE memory +}; +// +// Zone memory initialisation +// void Z_Init(void); -void Z_FreeTags(INT32 lowtag, INT32 hightag); -void Z_CheckMemCleanup(void); -void Z_CheckHeap(INT32 i); -#ifdef PARANOIA -void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line); -#else -void Z_ChangeTag2(void *ptr, INT32 tag); -#endif - -#ifdef PARANOIA -void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line); -#else -void Z_SetUser2(void *ptr, void **newuser); -#endif +// +// Zone memory allocation +// +// enable ZDEBUG to get the file + line the functions were called from +// for ZZ_Alloc, see doomdef.h +// // Z_Free and alloc with alignment #ifdef ZDEBUG @@ -99,31 +107,51 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb #define Z_Calloc(s,t,u) Z_CallocAlign(s, t, u, sizeof(void *)) #define Z_Realloc(p,s,t,u) Z_ReallocAlign(p, s, t, u, sizeof(void *)) +// Free all memory by tag +// these don't give line numbers for ZDEBUG currently though +// (perhaps this should be changed in future?) +#define Z_FreeTag(tagnum) Z_FreeTags(tagnum, tagnum) +void Z_FreeTags(INT32 lowtag, INT32 hightag); -size_t Z_TagUsage(INT32 tagnum); -size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); +// Iterate memory by tag +#define Z_IterateTag(tagnum, func) Z_IterateTags(tagnum, tagnum, func) +void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)); -char *Z_StrDup(const char *in); +// +// Utility functions +// +void Z_CheckMemCleanup(void); +void Z_CheckHeap(INT32 i); -// This is used to get the local FILE : LINE info from CPP -// prior to really call the function in question. +// +// Zone memory modification +// +// enable PARANOIA to get the file + line the functions were called from // #ifdef PARANOIA #define Z_ChangeTag(p,t) Z_ChangeTag2(p, t, __FILE__, __LINE__) +#define Z_SetUser(p,u) Z_SetUser2(p, u, __FILE__, __LINE__) +void Z_ChangeTag2(void *ptr, INT32 tag, const char *file, INT32 line); +void Z_SetUser2(void *ptr, void **newuser, const char *file, INT32 line); #else -#define Z_ChangeTag(p,t) Z_ChangeTag2(p, t) +void Z_ChangeTag(void *ptr, INT32 tag); +void Z_SetUser(void *ptr, void **newuser); #endif -#ifdef PARANOIA -#define Z_SetUser(p,u) Z_SetUser2(p, u, __FILE__, __LINE__) -#else -#define Z_SetUser(p,u) Z_SetUser2(p, u) -#endif +// +// Zone memory usage +// +// Note: These give the memory used in bytes, +// shift down by 10 to convert to KB +// +#define Z_TagUsage(tagnum) Z_TagsUsage(tagnum, tagnum) +size_t Z_TagsUsage(INT32 lowtag, INT32 hightag); +#define Z_TotalUsage() Z_TagsUsage(0, INT32_MAX) -#ifdef _NDS ///TODO: need a lock reference system -#define Z_Unlock(p) Z_ChangeTag(p, PU_CACHE_UNLOCKED) -#else -#define Z_Unlock(p) (void)p -#endif +// +// Miscellaneous functions +// +char *Z_StrDup(const char *in); +#define Z_Unlock(p) (void)p // TODO: remove this now that NDS code has been removed #endif -- 2.54.0 From 16effb5666fa65c0e0d2309db4eb41b628b3149e Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Mon, 31 Jul 2023 19:40:30 +0200 Subject: [PATCH 02/11] MSAA support, Alpha to coverage support Port from Birdhouse - msaa is enabled with command line parameter -msaa - alpha to coverage is enabled with parameter -a2c - note: a2c has issues with transparent surfaces becoming less opaque Need to find a way to make it toggable from cvar/menu somehow See: https://git.do.srb2.org/bird/Kart-Public/-/commit/6de9344875ff5d1b140cc4345cf155a15cc1102f --- src/hardware/hw_defs.h | 2 ++ src/hardware/hw_main.c | 9 +++++++++ src/hardware/r_opengl/r_opengl.c | 9 +++++++++ src/sdl/i_video.c | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index f242576cd..294e4e791 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -234,6 +234,8 @@ enum hwdsetspecialstate HWD_SET_TEXTUREFILTERMODE, HWD_SET_TEXTUREANISOTROPICMODE, + + HWD_SET_MSAA, HWD_SET_SCREEN_TEXTURES, diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a4e257117..2065b20f8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -41,6 +41,7 @@ #include "../st_stuff.h" #include "../i_system.h" #include "../m_cheat.h" +#include "../m_argv.h" // parm functions for msaa #ifdef ESLOPE #include "../p_slopes.h" @@ -6025,6 +6026,14 @@ void HWR_Startup(void) HWD.pfnKillShaders(); if (!HWD.pfnLoadShaders()) gr_shadersavailable = false; + + if (M_CheckParm("-msaa")) + { + if (M_CheckParm("-a2c")) + HWD.pfnSetSpecialState(HWD_SET_MSAA, 2); + else + HWD.pfnSetSpecialState(HWD_SET_MSAA, 1); + } } diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index a12962008..9c8074f56 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2735,6 +2735,15 @@ EXPORT void HWRAPI(SetSpecialState) (hwdspecialstate_t IdState, INT32 Value) } Flush(); //??? if we want to change filter mode by texture, remove this break; + + case HWD_SET_MSAA: + if (Value) + { + pglEnable(GL_MULTISAMPLE); + if (Value == 2) + pglEnable(GL_SAMPLE_ALPHA_TO_COVERAGE); + } + break; case HWD_SET_TEXTUREANISOTROPICMODE: anisotropic_filter = min(Value,maximumAnisotropy); diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index d18d6652e..712b4da4e 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -107,6 +107,10 @@ static void Impl_SetVsync(void); consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +// these cant be used since config is read after window creation, so need to use command line parameter instead +//static CV_PossibleValue_t msaa_cons_t[] = {{0, "Off"}, {2, "2X"}, {4, "4X"}, {8, "8X"}, {16, "16X"}, {0, NULL}}; +//consvar_t cv_msaa = {"msaa", "Off", CV_SAVE, msaa_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + UINT8 graphics_started = 0; // Is used in console.c and screen.c // To disable fullscreen at startup; is set in VID_PrepareModeList @@ -1772,7 +1776,19 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) #ifdef HWRENDER if (rendermode == render_opengl) + { flags |= SDL_WINDOW_OPENGL; + if (M_CheckParm("-msaa") && M_IsNextParm()) + { + unsigned int value; + const char* str = M_GetNextParm(); + if (sscanf(str, "%u", &value)) + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, value); + } + } + } // Without a 24-bit depth buffer many visuals are ruined by z-fighting. // Some GPU drivers may give us a 16-bit depth buffer since the -- 2.54.0 From 6de791b8c7c600ea60040d83fea7029382fc68df Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Aug 2023 13:31:50 +0300 Subject: [PATCH 03/11] Make MSAA and A2C configurable in renderer.txt --- src/hardware/hw_main.c | 98 ++++++++++++++++---------------- src/hardware/hw_main.h | 3 + src/sdl/i_video.c | 126 ++++++++++++++++++++++++++++++----------- 3 files changed, 146 insertions(+), 81 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 2065b20f8..0221aa4d4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -110,7 +110,7 @@ static INT32 current_bsp_culling_distance = 0; // - full screen scaling (use native resolution or windowed mode to avoid this) consvar_t cv_grscreentextures = {"gr_screentextures", "On", CV_CALL, CV_OnOff, CV_screentextures_ONChange, 0, NULL, NULL, 0, 0, NULL}; - + consvar_t cv_grusecustomshaders = {"gr_usecustomshaders", "Yes", CV_CALL|CV_SAVE, CV_OnOff, CV_useCustomShaders_ONChange, 0, NULL, NULL, 0, 0, NULL}; static void CV_filtermode_ONChange(void) @@ -439,7 +439,7 @@ void HWR_Lighting(FSurfaceInfo *Surface, INT32 light_level, extracolormap_t *col poly_color.s.green = (UINT8)green; poly_color.s.blue = (UINT8)blue; } - + // Clamp the light level, since it can sometimes go out of the 0-255 range from animations light_level = min(max(light_level, 0), 255); @@ -821,14 +821,14 @@ void HWR_ProjectWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend HWR_Lighting(pSurf, lightlevel, wallcolormap); HWD.pfnSetShader(2); // wall shader - + // don't draw to color buffer when drawing to stencil if (gl_drawing_stencil) { blendmode |= PF_Invisible|PF_NoAlphaTest; // TODO not sure if any others than PF_Invisible are needed?? blendmode &= ~PF_Masked; } - + HWD.pfnDrawPolygon(pSurf, wallVerts, 4, blendmode|PF_Modulated|PF_Occlude); #ifdef WALLSPLATS @@ -875,7 +875,7 @@ void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, FSurfa pegt = wallVerts[3].t; pegb = wallVerts[0].t; pegmul = (pegb - pegt) / (top - bot); - + if (fpclassify(pegmul) == FP_NAN) pegmul = 0.0; @@ -1631,7 +1631,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } else repeats = 1; - + fixed_t midtexheight = textureheight[gr_midtexture] * repeats; fixed_t popentop, popenbottom, polytop, polybottom, lowcut, highcut; fixed_t popentopslope, popenbottomslope, polytopslope, polybottomslope, lowcutslope, highcutslope; @@ -1658,7 +1658,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom #ifdef ESLOPE popentop = min(worldtop, worldhigh); popenbottom = max(worldbottom, worldlow); - + popentopslope = min(worldtopslope, worldhighslope); popenbottomslope = max(worldbottomslope, worldlowslope); } @@ -1699,7 +1699,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom polytopslope = popentopslope + gr_sidedef->rowoffset; polybottomslope = polytopslope - midtexheight; } - + // CB #ifdef POLYOBJECTS // NOTE: With polyobjects, whenever you need to check the properties of the polyobject sector it belongs to, @@ -1725,7 +1725,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom l = max(polybottom, lowcut); hS = min(highcutslope, polytopslope); lS = max(polybottomslope, lowcutslope); - + // PEGGING fixed_t texturevpeg, texturevpegslope; @@ -1760,7 +1760,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // set alpha for transparent walls (new boom and legacy linedef types) FBITFIELD blendmode; - + switch (gr_linedef->special) { case 900: @@ -1966,7 +1966,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!gl_drawing_stencil && gr_frontsector && gr_backsector && gr_frontsector->tag != gr_backsector->tag && (gr_backsector->ffloors || gr_frontsector->ffloors)) { ffloor_t * rover; - fixed_t highcut = 0, lowcut = 0; + fixed_t highcut = 0, lowcut = 0; fixed_t lowcutslope, highcutslope; // Used for height comparisons and etc across FOFs and slopes @@ -1979,14 +1979,14 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom highcut = min(worldtop, worldhigh); lowcutslope = max(worldbottomslope, worldlowslope); highcutslope = min(worldtopslope, worldhighslope); - + if (gr_backsector->ffloors) { for (rover = gr_backsector->ffloors; rover; rover = rover->next) { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || (rover->flags & FF_INVERTSIDES)) continue; - + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) @@ -2156,7 +2156,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom { if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERSIDES) || !(rover->flags & FF_ALLSIDES)) continue; - + SLOPEPARAMS(*rover->t_slope, high1, highslope1, *rover->topheight) SLOPEPARAMS(*rover->b_slope, low1, lowslope1, *rover->bottomheight) @@ -2427,7 +2427,7 @@ void HWR_AddLine(seg_t *line) static sector_t tempsec; fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - + boolean dont_draw = false; #ifdef POLYOBJECTS if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) @@ -2444,7 +2444,7 @@ void HWR_AddLine(seg_t *line) // OPTIMIZE: quickly reject orthogonal back sides. angle1 = R_PointToAngle64(v1x, v1y); angle2 = R_PointToAngle64(v2x, v2y); - + // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line // if not, the line can be culled. @@ -2515,7 +2515,7 @@ void HWR_AddLine(seg_t *line) checkforemptylines = true; gr_backsector = line->backsector; - + // Portal line /* if (cv_grportals.value && line->linedef->special == 40 && line->side == 0) @@ -3069,7 +3069,7 @@ void HWR_Subsector(size_t num) gr_frontsector = R_FakeFlat(gr_frontsector, &tempsec, &floorlightlevel, &ceilinglightlevel, false); //FIXME: Use floorlightlevel and ceilinglightlevel insted of lightlevel. - + if (gr_portal == GRPORTAL_SEARCH) { skipSprites = true; @@ -3326,7 +3326,7 @@ void HWR_Subsector(size_t num) ++numpolys; po = (polyobj_t *)(po->link.next); } - + // for performance stats ps_numpolyobjects.value.i += numpolys; @@ -3449,7 +3449,7 @@ void HWR_RenderBSPNode(INT32 bspnum) // Decide which side the view point is on INT32 side; - + ps_numbspcalls.value.i++; // Found a subsector? @@ -3470,7 +3470,7 @@ void HWR_RenderBSPNode(INT32 bspnum) HWR_Subsector(bspnum&(~NF_SUBSECTOR)); return; } - + // in portal checking phase we can stop after one is found //if (gr_portal == GRPORTAL_FOUND) // return; @@ -4420,10 +4420,10 @@ static int CompareVisSprites(const void *p1, const void *p2) gr_vissprite_t* spr2 = *(gr_vissprite_t*const*)p2; int idiff; float fdiff; - + // make transparent sprites last // "boolean to int" - + int transparency1 = (spr1->mobj->flags2 & MF2_SHADOW) || (spr1->mobj->frame & FF_TRANSMASK); int transparency2 = (spr2->mobj->flags2 & MF2_SHADOW) || (spr2->mobj->frame & FF_TRANSMASK); idiff = transparency1 - transparency2; @@ -4630,7 +4630,7 @@ void HWR_RenderDrawNodes(void) // However, in reality we shouldn't be re-copying and shifting all this information // that is already lying around. This should all be in some sort of linked list or lists. sortindex = Z_Calloc(sizeof(size_t) * (numplanes + numpolyplanes + numwalls), PU_STATIC, NULL); - + PS_START_TIMING(ps_hw_nodesorttime); for (i = 0; i < numplanes; i++, p++) @@ -4650,7 +4650,7 @@ void HWR_RenderDrawNodes(void) sortnode[p].wall = &wallinfo[i]; sortindex[p] = p; } - + ps_numdrawnodes.value.i = p; // p is the number of stuff to sort @@ -4694,7 +4694,7 @@ void HWR_RenderDrawNodes(void) run_start++; } } - + PS_STOP_TIMING(ps_hw_nodesorttime); PS_START_TIMING(ps_hw_nodedrawtime); @@ -4733,7 +4733,7 @@ void HWR_RenderDrawNodes(void) sortnode[sortindex[i]].wall->lightlevel, sortnode[sortindex[i]].wall->wallcolormap); } } - + PS_STOP_TIMING(ps_hw_nodedrawtime); numwalls = 0; @@ -4944,7 +4944,7 @@ void HWR_ProjectSprite(mobj_t *thing) const boolean papersprite = (thing->frame & FF_PAPERSPRITE); INT32 heightsec, phs; vector3_t pos; - + fixed_t spr_width, spr_height; fixed_t spr_offset, spr_topoffset; #ifdef ROTSPRITE @@ -4954,7 +4954,7 @@ void HWR_ProjectSprite(mobj_t *thing) angle_t sliptiderollangle = 0; #endif - + // uncapped/interpolation interpmobjstate_t interp = {0}; @@ -4970,7 +4970,7 @@ void HWR_ProjectSprite(mobj_t *thing) { R_InterpolateMobjState(thing, FRACUNIT, &interp); } - + if (interp.spritexscale < 1 || interp.spriteyscale < 1) return; @@ -5079,7 +5079,7 @@ void HWR_ProjectSprite(mobj_t *thing) if (thing->skin && ((skin_t *)thing->skin)->flags & SF_HIRES) this_scale = this_scale * FIXED_TO_FLOAT(((skin_t *)thing->skin)->highresscale); - + spr_width = spritecachedinfo[lumpoff].width; spr_height = spritecachedinfo[lumpoff].height; spr_offset = spritecachedinfo[lumpoff].offset; @@ -5095,7 +5095,7 @@ void HWR_ProjectSprite(mobj_t *thing) } else rollsum = (thing->rollangle)+(thing->sloperoll); - + rollangle = R_GetRollAngle(rollsum); rotsprite = Patch_GetRotatedSprite(sprframe, (thing->frame & FF_FRAMEMASK), rot, flip, sprinfo, rollangle); @@ -5105,7 +5105,7 @@ void HWR_ProjectSprite(mobj_t *thing) spr_height = rotsprite->height << FRACBITS; spr_offset = rotsprite->leftoffset << FRACBITS; spr_topoffset = rotsprite->topoffset << FRACBITS; - spr_topoffset += FEETADJUST; + spr_topoffset += FEETADJUST; // flip -> rotate, not rotate -> flip flip = 0; } @@ -5203,7 +5203,7 @@ void HWR_ProjectSprite(mobj_t *thing) vis->tz = tz; // Keep tz for the simple sprite sorting that happens vis->dispoffset = thing->info->dispoffset; // Monster Iestyn: 23/11/15: HARDWARE SUPPORT AT LAST vis->flip = flip; - + vis->scale = this_scale; vis->spritexscale = spritexscale; vis->spriteyscale = spriteyscale; @@ -5216,7 +5216,7 @@ void HWR_ProjectSprite(mobj_t *thing) else #endif vis->gpatch = (GLPatch_t *)W_CachePatchNum(sprframe->lumppat[rot], PU_CACHE); - + vis->mobj = thing; @@ -5254,7 +5254,7 @@ void HWR_ProjectSprite(mobj_t *thing) // set top/bottom coords vis->ty = gzt; - + vis->gzt = gzt; vis->gz = gz; @@ -5391,7 +5391,7 @@ void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) // set top/bottom coords vis->ty = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset); - + vis->gzt = FIXED_TO_FLOAT(thing->z + spritecachedinfo[lumpoff].topoffset); vis->gz = vis->gzt - FIXED_TO_FLOAT(spritecachedinfo[lumpoff].height); @@ -5484,7 +5484,7 @@ void HWR_SetTransform(float fpov, player_t *player) { postimg_t *postprocessor = &postimgtype[0]; INT32 i; - + // copy view cam position for local use dup_viewx = viewx; dup_viewy = viewy; @@ -5575,7 +5575,7 @@ void HWR_PortalClipping(portal_t *portal) v1y = FLOAT_TO_FIXED(((polyvertex_t *)seg->pv1)->y); v2x = FLOAT_TO_FIXED(((polyvertex_t *)seg->pv2)->x); v2y = FLOAT_TO_FIXED(((polyvertex_t *)seg->pv2)->y); - + angle1 = R_PointToAngleEx(viewx, viewy, v1x, v1y); angle2 = R_PointToAngleEx(viewx, viewy, v2x, v2y); */ @@ -5705,19 +5705,19 @@ void RecursivePortalRendering(portal_t *rootportal, const float fpov, player_t * validcount++; if (cv_grbatching.value) HWD.pfnStartBatching(); - + ps_numbspcalls.value.i = 0; ps_numpolyobjects.value.i = 0; PS_START_TIMING(ps_bsptime); if (!rootportal && portallist.base && !skybox)// if portals have been drawn in the main view, then render skywalls differently gr_collect_skywalls = true; - - // Recursively "render" the BSP tree. + + // Recursively "render" the BSP tree. HWR_RenderBSPNode((INT32)numnodes-1); - + PS_STOP_TIMING(ps_bsptime); - + if (cv_grbatching.value) { HWD.pfnRenderBatches(&ps_hw_batchsorttime.value.p, &ps_hw_batchdrawtime.value.p, @@ -5913,7 +5913,7 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play // Render the BSP from the new viewpoint. portalcullsector = gr_portalcullsectors[portalnum]; HWR_RenderBSPNode((INT32)numnodes - 1); - + // Draw MD2 and sprites ps_numsprites.value.i = gr_visspritecount; PS_START_TIMING(ps_hw_spritesorttime); @@ -5922,7 +5922,7 @@ void HWR_RenderSinglePortal(portal_t *portal, size_t portalnum, float fpov, play PS_START_TIMING(ps_hw_spritedrawtime); HWR_DrawSprites(); PS_STOP_TIMING(ps_hw_spritedrawtime); - + ps_numdrawnodes.value.i = 0; ps_hw_nodesorttime.value.p = 0; ps_hw_nodedrawtime.value.p = 0; @@ -6026,10 +6026,10 @@ void HWR_Startup(void) HWD.pfnKillShaders(); if (!HWD.pfnLoadShaders()) gr_shadersavailable = false; - - if (M_CheckParm("-msaa")) + + if (msaa) { - if (M_CheckParm("-a2c")) + if (a2c) HWD.pfnSetSpecialState(HWD_SET_MSAA, 2); else HWD.pfnSetSpecialState(HWD_SET_MSAA, 1); diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index c49e384b2..ef461a094 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -41,6 +41,9 @@ extern float gr_viewwidth, gr_viewheight, gr_baseviewwindowx, gr_baseviewwindowy extern float gr_basewindowcenterx, gr_basewindowcentery; +extern unsigned msaa; +extern boolean a2c; + extern FTransform atransform; // Performance stats diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 712b4da4e..30eab8711 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -99,6 +99,14 @@ static char vidModeName[33][32]; // allow 33 different modes rendermode_t rendermode = render_none; +#ifdef HWRENDER +unsigned msaa = 0; + +// Eee probably the way i organize it isn't best >< +// Just don't know where do i put declaration and "implementation" +boolean a2c = false; +#endif + boolean highcolor = false; static void Impl_SetVsync(void); @@ -1778,18 +1786,14 @@ static SDL_bool Impl_CreateWindow(SDL_bool fullscreen) if (rendermode == render_opengl) { flags |= SDL_WINDOW_OPENGL; - if (M_CheckParm("-msaa") && M_IsNextParm()) - { - unsigned int value; - const char* str = M_GetNextParm(); - if (sscanf(str, "%u", &value)) - { - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, value); - } - } + } + + if (msaa) + { + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa); } - + // Without a 24-bit depth buffer many visuals are ruined by z-fighting. // Some GPU drivers may give us a 16-bit depth buffer since the // default value for SDL_GL_DEPTH_SIZE is 16. @@ -1972,32 +1976,84 @@ void I_StartupGraphics(void) rendermode = render_opengl; #endif - if (rendermode == render_none) - { -#ifdef HWRENDER + msaa = 0; boolean msaa_set = false; + a2c = false; boolean a2c_set = false; + + if (M_CheckParm("-msaa") && M_IsNextParm()) + { + const char* str = M_GetNextParm(); + if (sscanf(str, "%u", &msaa)) + { + msaa_set = true; + } + } + + if (M_CheckParm("-a2c")) + { + a2c = true; + a2c_set = true; + } + else if (M_CheckParm("-noa2c")) + { + a2c_set = true; + } + + { char line[16]; char * word; FILE * file = OpenRendererFile("r"); if (file != NULL) { - if (fgets(line, sizeof line, file) != NULL) +#ifdef HWRENDER + while (fgets(line, sizeof line, file) != NULL) { - word = strtok(line, "\n"); + word = strtok(line, " \n"); - if (strcasecmp(word, "software") == 0) - { - rendermode = render_soft; - } - else if (strcasecmp(word, "opengl") == 0) - { - rendermode = render_opengl; - } + if (rendermode == render_none) + { + if (strcasecmp(word, "software") == 0) + { + rendermode = render_soft; + } + else if (strcasecmp(word, "opengl") == 0) + { + rendermode = render_opengl; + } + + if (rendermode != render_none) + { + CONS_Printf("Using last known renderer: %s\n", line); + } + } + + if (!msaa_set) + { + if (strcasecmp(word, "msaa") == 0) + { + const char *nextword = strtok(NULL, " \n"); + + if (!nextword || !sscanf(nextword, "%u", &msaa)) + { + CONS_Alert(CONS_ERROR, "Malformed MSAA entry in renderer.txt\n"); + } + else + { + CONS_Printf("Using last know MSAA value: %u\n", msaa); + } + } + } + + if (!a2c_set) + { + if (strcasecmp(word, "a2c") == 0) + { + a2c = true; + + CONS_Printf("Using a2c because it was specified to be used earlier\n"); + } + } + } - if (rendermode != render_none) - { - CONS_Printf("Using last known renderer: %s\n", line); - } - } fclose(file); } #endif @@ -2006,8 +2062,8 @@ void I_StartupGraphics(void) rendermode = render_soft; CONS_Printf("Using default software renderer.\n"); } - } - else + } + { FILE * file = OpenRendererFile("w"); if (file != NULL) @@ -2020,7 +2076,13 @@ void I_StartupGraphics(void) { fputs("opengl\n", file); } - fclose(file); + + fprintf(file, "msaa %u\n", msaa); + + if (a2c) + fputs("a2c\n", file); + + fclose(file); } else { -- 2.54.0 From f2ac6d6799c107e4f9e2441b267eb629271a64c4 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 2 Aug 2023 14:33:19 +0300 Subject: [PATCH 04/11] Add intermission hud hook --- src/dehacked.c | 3 +++ src/lua_hud.h | 1 + src/lua_hudlib.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/y_inter.c | 20 ++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 09ada89e0..52b2785c3 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8732,6 +8732,9 @@ struct { {"TC_ALLWHITE",TC_ALLWHITE}, {"TC_RAINBOW",TC_RAINBOW}, {"TC_BLINK",TC_BLINK}, + + // Custom client features exposed to lua + {"FEATURE_INTERMISSIONHUD",1}, #endif {NULL,0} diff --git a/src/lua_hud.h b/src/lua_hud.h index 07ac577de..06ba0169b 100644 --- a/src/lua_hud.h +++ b/src/lua_hud.h @@ -43,5 +43,6 @@ boolean LUA_HudEnabled(enum hud option); void LUAh_GameHUD(player_t *stplyr, huddrawlist_h list); void LUAh_ScoresHUD(huddrawlist_h list); +void LUAh_IntermissionHUD(huddrawlist_h list); #endif // __LUA_HUD_H__ diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 854721b2a..f2eeae4c9 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -84,11 +84,13 @@ static const char *const patch_opt[] = { enum hudhook { hudhook_game = 0, - hudhook_scores + hudhook_scores = 1, + hudhook_intermission = 2, }; static const char *const hudhook_opt[] = { "game", "scores", + "intermission", NULL}; // alignment types for v.drawString @@ -987,7 +989,10 @@ int LUA_HudLib(lua_State *L) lua_rawseti(L, -2, 2); // HUD[2] = game rendering functions array lua_newtable(L); - lua_rawseti(L, -2, 3); // HUD[2] = scores rendering functions array + lua_rawseti(L, -2, 3); // HUD[3] = scores rendering functions array + + lua_newtable(L); + lua_rawseti(L, -2, 4); // HUD[4] = intermission rendering functions array lua_setfield(L, LUA_REGISTRYINDEX, "HUD"); luaL_newmetatable(L, META_HUDINFO); @@ -1132,4 +1137,37 @@ void LUAh_ScoresHUD(huddrawlist_h list) lua_setfield(gL, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); } +void LUAh_IntermissionHUD(huddrawlist_h list) +{ + if (!gL || !(hudAvailable & (1< Date: Wed, 2 Aug 2023 12:52:56 +0300 Subject: [PATCH 05/11] Make amount of messages saved in log configurable via cvar --- src/d_netcmd.c | 1 + src/g_game.h | 4 ++++ src/hu_stuff.c | 43 +++++++++++++++++++++++++++++++++++-------- src/hu_stuff.h | 3 ++- src/m_menu.c | 3 ++- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 45055276e..9866de479 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -743,6 +743,7 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_httpsource); #ifndef NONET CV_RegisterVar(&cv_allownewplayer); + CV_RegisterVar(&cv_chatlogsize); #ifdef VANILLAJOINNEXTROUND CV_RegisterVar(&cv_joinnextround); #endif diff --git a/src/g_game.h b/src/g_game.h index 688ce3d5b..0f55724c0 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -163,6 +163,10 @@ extern consvar_t cv_resetspecialmusic; extern consvar_t cv_resume; extern consvar_t cv_fading; +#ifndef NONET +extern consvar_t cv_chatlogsize; +#endif + typedef enum { AXISNONE = 0, diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 60b1d14da..97ac3c3a0 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -378,6 +378,11 @@ void HU_Start(void) // EVERY CHANGE IN THIS SCRIPT IS LOL XD! BY VINCYTM +static void Chatlogsize_OnChange(void); + +static CV_PossibleValue_t chatlogsize_cons_t[] = {{8, "MIN"}, {MAX_CHAT_BUFSIZE, "MAX"}, {0, NULL}}; +consvar_t cv_chatlogsize = {"chatlogsize", "64", CV_CALL|CV_SAVE, chatlogsize_cons_t, Chatlogsize_OnChange, 0, NULL, NULL, 0, 0, NULL}; + static UINT32 chat_nummsg_log = 0; static UINT32 chat_nummsg_min = 0; static UINT32 chat_scroll = 0; @@ -385,10 +390,7 @@ static tic_t chat_scrolltime = 0; static UINT32 chat_maxscroll = 0; // how far can we scroll? -//static chatmsg_t chat_mini[CHAT_BUFSIZE]; // Display the last few messages sent. -//static chatmsg_t chat_log[CHAT_BUFSIZE]; // Keep every message sent to us in memory so we can scroll n shit, it's cool. - -static char chat_log[CHAT_BUFSIZE][255]; // hold the last 48 or so messages in that log. +static char **chat_log = NULL; static char chat_mini[8][255]; // display up to 8 messages that will fade away / get overwritten static tic_t chat_timers[8]; @@ -416,13 +418,30 @@ static void HU_removeChatText_Mini(void) // same but w the log. TODO: optimize this and maybe merge in a single func? im bad at C. static void HU_removeChatText_Log(void) { - // MPC: Don't create new arrays, just iterate through an existing one + // We don't have any messages, idiot! + if (!chat_nummsg_log) + return; + + free(chat_log[0]); size_t i; for(i=0;i (UINT32)cv_chatlogsize.value) + { + HU_removeChatText_Log(); + } + + // TODO - use z_zone allocators? + chat_log = reallocarray(chat_log, cv_chatlogsize.value, sizeof(char*)); + chat_nummsg_log = min(chat_nummsg_log, (UINT32)cv_chatlogsize.value); +} #endif void HU_AddChatText(const char *text, boolean playsound) @@ -432,11 +451,19 @@ void HU_AddChatText(const char *text, boolean playsound) S_StartSound(NULL, sfx_radio); // reguardless of our preferences, put all of this in the chat buffer in case we decide to change from oldchat mid-game. - if (chat_nummsg_log >= CHAT_BUFSIZE) // too many messages! + // Uuuh dunno how that can happen but a bit of paranoia is never too bad + if (!chat_log) + { + //I_Error("Chat log is not allocated what the fuck"); // uwu + Chatlogsize_OnChange(); // Lets hope that will surely allocate some memory for us + } + + if (chat_nummsg_log >= (UINT32)cv_chatlogsize.value) // too many messages! HU_removeChatText_Log(); + chat_log[chat_nummsg_log] = malloc(HU_MSGBUFSIZE); strcpy(chat_log[chat_nummsg_log], text); - chat_nummsg_log++; + ++chat_nummsg_log; if (chat_nummsg_min >= 8) HU_removeChatText_Mini(); diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 6842a17aa..f0ef731b6 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -62,7 +62,8 @@ typedef struct // chat stuff //------------------------------------ #define HU_MAXMSGLEN 223 -#define CHAT_BUFSIZE 64 // that's enough messages, right? We'll delete the older ones when that gets out of hand. +#define HU_MSGBUFSIZE 255 +#define MAX_CHAT_BUFSIZE 256 // that's enough messages, right? We'll delete the older ones when that gets out of hand. #define NETSPLITSCREEN // why the hell WOULDN'T we want this? #ifdef NETSPLITSCREEN #define OLDCHAT (cv_consolechat.value == 1 || dedicated || vid.width < 640) diff --git a/src/m_menu.c b/src/m_menu.c index bb19230c0..ac3bc3d41 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1533,8 +1533,9 @@ static menuitem_t OP_ChatOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "Chat Background Tint", &cv_chatbacktint, 50}, {IT_STRING | IT_CVAR, NULL, "Message Fadeout Time", &cv_chattime, 60}, {IT_STRING | IT_CVAR, NULL, "Spam Protection", &cv_chatspamprotection, 70}, + {IT_STRING | IT_CVAR, NULL, "Max Chat Messages", &cv_chatlogsize, 80}, - {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 90}, // shows ping next to framerate if we want to. + {IT_STRING | IT_CVAR, NULL, "Local ping display", &cv_showping, 100}, // shows ping next to framerate if we want to. }; static menuitem_t OP_GameOptionsMenu[] = -- 2.54.0 From fd10853f3ae87f5ee8ec63d41f2daedf1161fe4f Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 3 Aug 2023 11:17:04 +0300 Subject: [PATCH 06/11] Use realloc because reallocarray doesn't exist for some versions of C ;-; --- src/hu_stuff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 97ac3c3a0..effb24837 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -438,8 +438,13 @@ static void Chatlogsize_OnChange(void) HU_removeChatText_Log(); } +// Some versons of C don't have reallocarray sadly +#define reallocarray(ptr, nmemb, size) realloc(ptr, (nmemb)*(size)) + // TODO - use z_zone allocators? chat_log = reallocarray(chat_log, cv_chatlogsize.value, sizeof(char*)); + +#undef reallocarray chat_nummsg_log = min(chat_nummsg_log, (UINT32)cv_chatlogsize.value); } #endif -- 2.54.0 From 8ef29f8a76d0f295c0d25c1da6a67309e2752482 Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Sat, 5 Aug 2023 13:52:41 +0200 Subject: [PATCH 07/11] Lets make it v7 so much shit was added since initial v6 so lets just go straight to v7 c: --- src/doomdef.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 43048ae00..09d00aba8 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -149,8 +149,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#define VERSIONSTRING "Saturn v6.0 " -#define VERSIONSTRINGW L"Saturn v6.0" +#define VERSIONSTRING "Saturn v7.0 " +#define VERSIONSTRINGW L"Saturn v7.0" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! -- 2.54.0 From 0a25eeb1add21b1da6c6a13c3019578c4b963229 Mon Sep 17 00:00:00 2001 From: xyzzy Date: Sun, 27 Aug 2023 12:06:52 +0300 Subject: [PATCH 08/11] Make `alias` print a list of all defined aliases. * Alias with no args not only prints out the help text but all command aliases. * Alias with just one argument prints all commands that begin with the first argument. --- src/command.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index ff2ff7b13..16c8ad596 100644 --- a/src/command.c +++ b/src/command.c @@ -635,10 +635,44 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; + const char *alias_format = "\x87%-8s:\x80 %s\n"; + int argc = COM_Argc(); - if (COM_Argc() < 3) + if (argc == 2) { + const char *begin = COM_Argv(1); + size_t szBegin = strlen(begin); + + /* Display all aliases that start with `begin`. */ + CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); + + int count = 0; + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + if (strncmp(begin, head->name, szBegin) == 0) + { + CONS_Printf(alias_format, head->name, head->value); + count++; + } + } + + if (count == 0) + { + CONS_Printf(M_GetText("There are none.\n")); + } + + return; + } + else if (argc < 3) + { + /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); + + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + CONS_Printf(alias_format, head->name, head->value); + } + return; } -- 2.54.0 From 39d4cb4b3657c29e0650adf53072a0d3e0208b85 Mon Sep 17 00:00:00 2001 From: xyzzy Date: Sun, 27 Aug 2023 12:21:04 +0300 Subject: [PATCH 09/11] Patch in listskins for Saturn :3 * Listskins lists all loaded skins. * It's fun * Paginated display. --- src/d_netcmd.c | 105 +++++++++++++++++++ src/hu_stuff.c | 268 ++++++++++++++++++++++++------------------------- src/hu_stuff.h | 1 + 3 files changed, 235 insertions(+), 139 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9866de479..82face3f7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -190,6 +190,9 @@ static void Command_ShowTime_f(void); static void Command_Isgamemodified_f(void); static void Command_Cheats_f(void); + +static void Command_ListSkins(void); + #ifdef _DEBUG static void Command_Togglemodified_f(void); #ifdef HAVE_BLUA @@ -1126,8 +1129,34 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_discordstreamer); CV_RegisterVar(&cv_discordasks); #endif + + COM_AddCommand("listskins", Command_ListSkins); } +/** + * Searches the skins list for a skin of the "realname", if found, changes + * the CVAR value to be the "name" of the skin. + * \sa cv_skin, Skin_OnChange, Skin2_OnChange + * \author karen + */ +static void Skin_FindRealNameSkin(consvar_t *cvar) +{ + // Not the best way to implements this but it will do. + + int i; + const char *value = cvar->string; + for (i = 0; i < numskins; i++) + { + if (strncmp(value, skins[i].realname, sizeof skins[i].realname) == 0) + { + // Change the cvar to be the value of the name. + CV_StealthSet(cvar, skins[i].name); + return; + } + } +} + + /** Checks if a name (as received from another player) is okay. * A name is okay if it is no fewer than 1 and no more than ::MAXPLAYERNAME * chars long (not including NUL), it does not begin or end with a space, @@ -5705,6 +5734,8 @@ static void Name4_OnChange(void) */ static void Skin_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin); + if (!Playing()) return; // do whatever you want @@ -5731,6 +5762,8 @@ static void Skin_OnChange(void) */ static void Skin2_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin2); + if (!Playing() || !splitscreen) return; // do whatever you want @@ -5745,6 +5778,8 @@ static void Skin2_OnChange(void) static void Skin3_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin3); + if (!Playing() || splitscreen < 2) return; // do whatever you want @@ -5759,6 +5794,8 @@ static void Skin3_OnChange(void) static void Skin4_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin4); + if (!Playing() || splitscreen < 3) return; // do whatever you want @@ -5771,6 +5808,74 @@ static void Skin4_OnChange(void) } } +static void Command_ListSkins(void) +{ + int i; + int page = 0; + int numpages = numskins / 10 + (numskins % 10 ? 1 : 0); + int longest_name = 0; + + if (COM_Argc() > 1) + { + if (sscanf(COM_Argv(1), " %d", &page) == 0) + { + CONS_Printf("Expected a number.\n"); + return; + } + else if (page > numpages) + { + CONS_Printf("There are only %d pages.\n", numpages); + return; + } + else if (page < 0) + { + CONS_Printf("Page number cannot be negative.\n"); + return; + } + else if (page == 0) + { + CONS_Printf("There is no 0th page. (What are you a programmer?)\n"); + return; + } + + --page; + } + + CONS_Printf("Total %d skins. Page (%d/%d)\n", numskins, page + 1, numpages); + + // Find the longest name and realname in the skins list. (used for alignment) + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + int length; + skin_t *skin = &skins[i]; + + if ((length = strlen(skin->name)) > longest_name) + longest_name = length; + } + + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + skin_t *skin = &skins[i]; + + CONS_Printf( + "%s[%-*s]\x80 %s\n", + HU_SkinColorToConsoleColor(skin->prefcolor), + longest_name, + skin->name, + skin->realname); + } + + if (page + 1 != numpages) + { + CONS_Printf("Use \"listskins %d\" to see the next page.\n", page + 2); + } + else + { + CONS_Printf("There are no more pages.\n"); + } +} + + /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange * \author Graue diff --git a/src/hu_stuff.c b/src/hu_stuff.c index effb24837..3d5017961 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -682,6 +682,134 @@ static void Command_CSay_f(void) } static tic_t stop_spamming[MAXPLAYERS]; +const char *HU_SkinColorToConsoleColor(skincolors_t color) +{ + // Move this ugly switch into a function you can collapse. + switch (color) + { + case SKINCOLOR_WHITE: + case SKINCOLOR_SILVER: + case SKINCOLOR_SLATE: + return "\x80"; // White + case SKINCOLOR_GREY: + case SKINCOLOR_NICKEL: + case SKINCOLOR_BLACK: + case SKINCOLOR_SKUNK: + case SKINCOLOR_JET: + return "\x86"; // V_GRAYMAP + case SKINCOLOR_SEPIA: + case SKINCOLOR_BEIGE: + case SKINCOLOR_WALNUT: + case SKINCOLOR_BROWN: + case SKINCOLOR_LEATHER: + case SKINCOLOR_RUST: + case SKINCOLOR_WRISTWATCH: + return "\x8e"; // V_BROWNMAP + case SKINCOLOR_FAIRY: + case SKINCOLOR_SALMON: + case SKINCOLOR_PINK: + case SKINCOLOR_ROSE: + case SKINCOLOR_BRICK: + case SKINCOLOR_LEMONADE: + case SKINCOLOR_BUBBLEGUM: + case SKINCOLOR_LILAC: + return "\x8d"; // V_PINKMAP + case SKINCOLOR_CINNAMON: + case SKINCOLOR_RUBY: + case SKINCOLOR_RASPBERRY: + case SKINCOLOR_CHERRY: + case SKINCOLOR_RED: + case SKINCOLOR_CRIMSON: + case SKINCOLOR_MAROON: + case SKINCOLOR_FLAME: + case SKINCOLOR_SCARLET: + case SKINCOLOR_KETCHUP: + return "\x85"; // V_REDMAP + case SKINCOLOR_DAWN: + case SKINCOLOR_SUNSET: + case SKINCOLOR_CREAMSICLE: + case SKINCOLOR_ORANGE: + case SKINCOLOR_PUMPKIN: + case SKINCOLOR_ROSEWOOD: + case SKINCOLOR_BURGUNDY: + case SKINCOLOR_TANGERINE: + return "\x87"; // V_ORANGEMAP + case SKINCOLOR_PEACH: + case SKINCOLOR_CARAMEL: + case SKINCOLOR_CREAM: + return "\x8f"; // V_PEACHMAP + case SKINCOLOR_GOLD: + case SKINCOLOR_ROYAL: + case SKINCOLOR_BRONZE: + case SKINCOLOR_COPPER: + case SKINCOLOR_THUNDER: + return "\x8A"; // V_GOLDMAP + case SKINCOLOR_POPCORN: + case SKINCOLOR_QUARRY: + case SKINCOLOR_YELLOW: + case SKINCOLOR_MUSTARD: + case SKINCOLOR_CROCODILE: + case SKINCOLOR_OLIVE: + return "\x82"; // V_YELLOWMAP + case SKINCOLOR_ARTICHOKE: + case SKINCOLOR_VOMIT: + case SKINCOLOR_GARDEN: + case SKINCOLOR_TEA: + case SKINCOLOR_PISTACHIO: + return "\x8b"; // V_TEAMAP + case SKINCOLOR_LIME: + case SKINCOLOR_HANDHELD: + case SKINCOLOR_MOSS: + case SKINCOLOR_CAMOUFLAGE: + case SKINCOLOR_ROBOHOOD: + case SKINCOLOR_MINT: + case SKINCOLOR_GREEN: + case SKINCOLOR_PINETREE: + case SKINCOLOR_EMERALD: + case SKINCOLOR_SWAMP: + case SKINCOLOR_DREAM: + case SKINCOLOR_PLAGUE: + case SKINCOLOR_ALGAE: + return "\x83"; // V_GREENMAP + case SKINCOLOR_CARIBBEAN: + case SKINCOLOR_AZURE: + case SKINCOLOR_AQUA: + case SKINCOLOR_TEAL: + case SKINCOLOR_CYAN: + case SKINCOLOR_JAWZ: + case SKINCOLOR_CERULEAN: + case SKINCOLOR_NAVY: + case SKINCOLOR_SAPPHIRE: + return "\x88"; // V_SKYMAP + case SKINCOLOR_PIGEON: + case SKINCOLOR_PLATINUM: + case SKINCOLOR_STEEL: + return "\x8c"; // V_STEELMAP + case SKINCOLOR_PERIWINKLE: + case SKINCOLOR_BLUE: + case SKINCOLOR_BLUEBERRY: + case SKINCOLOR_NOVA: + return "\x84"; // V_BLUEMAP + case SKINCOLOR_ULTRAVIOLET: + case SKINCOLOR_PURPLE: + case SKINCOLOR_FUCHSIA: + return "\x81"; // V_PURPLEMAP + case SKINCOLOR_PASTEL: + case SKINCOLOR_MOONSLAM: + case SKINCOLOR_DUSK: + case SKINCOLOR_TOXIC: + case SKINCOLOR_MAUVE: + case SKINCOLOR_LAVENDER: + case SKINCOLOR_BYZANTIUM: + case SKINCOLOR_POMEGRANATE: + return "\x89"; // V_LAVENDERMAP + + default: + return "\x83"; + } +} + + /** Receives a message, processing an ::XD_SAY command. * \sa DoSayCommand * \author Graue @@ -828,145 +956,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) { const UINT8 color = players[playernum].skincolor; - cstart = "\x83"; - - switch (color) - { - case SKINCOLOR_WHITE: - case SKINCOLOR_SILVER: - case SKINCOLOR_SLATE: - cstart = "\x80"; // White - break; - case SKINCOLOR_GREY: - case SKINCOLOR_NICKEL: - case SKINCOLOR_BLACK: - case SKINCOLOR_SKUNK: - case SKINCOLOR_JET: - cstart = "\x86"; // V_GRAYMAP - break; - case SKINCOLOR_SEPIA: - case SKINCOLOR_BEIGE: - case SKINCOLOR_WALNUT: - case SKINCOLOR_BROWN: - case SKINCOLOR_LEATHER: - case SKINCOLOR_RUST: - case SKINCOLOR_WRISTWATCH: - cstart = "\x8e"; // V_BROWNMAP - break; - case SKINCOLOR_FAIRY: - case SKINCOLOR_SALMON: - case SKINCOLOR_PINK: - case SKINCOLOR_ROSE: - case SKINCOLOR_BRICK: - case SKINCOLOR_LEMONADE: - case SKINCOLOR_BUBBLEGUM: - case SKINCOLOR_LILAC: - cstart = "\x8d"; // V_PINKMAP - break; - case SKINCOLOR_CINNAMON: - case SKINCOLOR_RUBY: - case SKINCOLOR_RASPBERRY: - case SKINCOLOR_CHERRY: - case SKINCOLOR_RED: - case SKINCOLOR_CRIMSON: - case SKINCOLOR_MAROON: - case SKINCOLOR_FLAME: - case SKINCOLOR_SCARLET: - case SKINCOLOR_KETCHUP: - cstart = "\x85"; // V_REDMAP - break; - case SKINCOLOR_DAWN: - case SKINCOLOR_SUNSET: - case SKINCOLOR_CREAMSICLE: - case SKINCOLOR_ORANGE: - case SKINCOLOR_PUMPKIN: - case SKINCOLOR_ROSEWOOD: - case SKINCOLOR_BURGUNDY: - case SKINCOLOR_TANGERINE: - cstart = "\x87"; // V_ORANGEMAP - break; - case SKINCOLOR_PEACH: - case SKINCOLOR_CARAMEL: - case SKINCOLOR_CREAM: - cstart = "\x8f"; // V_PEACHMAP - break; - case SKINCOLOR_GOLD: - case SKINCOLOR_ROYAL: - case SKINCOLOR_BRONZE: - case SKINCOLOR_COPPER: - case SKINCOLOR_THUNDER: - cstart = "\x8A"; // V_GOLDMAP - break; - case SKINCOLOR_POPCORN: - case SKINCOLOR_QUARRY: - case SKINCOLOR_YELLOW: - case SKINCOLOR_MUSTARD: - case SKINCOLOR_CROCODILE: - case SKINCOLOR_OLIVE: - cstart = "\x82"; // V_YELLOWMAP - break; - case SKINCOLOR_ARTICHOKE: - case SKINCOLOR_VOMIT: - case SKINCOLOR_GARDEN: - case SKINCOLOR_TEA: - case SKINCOLOR_PISTACHIO: - cstart = "\x8b"; // V_TEAMAP - break; - case SKINCOLOR_LIME: - case SKINCOLOR_HANDHELD: - case SKINCOLOR_MOSS: - case SKINCOLOR_CAMOUFLAGE: - case SKINCOLOR_ROBOHOOD: - case SKINCOLOR_MINT: - case SKINCOLOR_GREEN: - case SKINCOLOR_PINETREE: - case SKINCOLOR_EMERALD: - case SKINCOLOR_SWAMP: - case SKINCOLOR_DREAM: - case SKINCOLOR_PLAGUE: - case SKINCOLOR_ALGAE: - cstart = "\x83"; // V_GREENMAP - break; - case SKINCOLOR_CARIBBEAN: - case SKINCOLOR_AZURE: - case SKINCOLOR_AQUA: - case SKINCOLOR_TEAL: - case SKINCOLOR_CYAN: - case SKINCOLOR_JAWZ: - case SKINCOLOR_CERULEAN: - case SKINCOLOR_NAVY: - case SKINCOLOR_SAPPHIRE: - cstart = "\x88"; // V_SKYMAP - break; - case SKINCOLOR_PIGEON: - case SKINCOLOR_PLATINUM: - case SKINCOLOR_STEEL: - cstart = "\x8c"; // V_STEELMAP - break; - case SKINCOLOR_PERIWINKLE: - case SKINCOLOR_BLUE: - case SKINCOLOR_BLUEBERRY: - case SKINCOLOR_NOVA: - cstart = "\x84"; // V_BLUEMAP - break; - case SKINCOLOR_ULTRAVIOLET: - case SKINCOLOR_PURPLE: - case SKINCOLOR_FUCHSIA: - cstart = "\x81"; // V_PURPLEMAP - break; - case SKINCOLOR_PASTEL: - case SKINCOLOR_MOONSLAM: - case SKINCOLOR_DUSK: - case SKINCOLOR_TOXIC: - case SKINCOLOR_MAUVE: - case SKINCOLOR_LAVENDER: - case SKINCOLOR_BYZANTIUM: - case SKINCOLOR_POMEGRANATE: - cstart = "\x89"; // V_LAVENDERMAP - break; - default: - break; - } + cstart = HU_SkinColorToConsoleColor(color); } prefix = cstart; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index f0ef731b6..9979427cf 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -121,6 +121,7 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags); // Lat': Ping draw //void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer); void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer, INT32 hilicol); void HU_DrawEmeralds(INT32 x, INT32 y, INT32 pemeralds); +const char *HU_SkinColorToConsoleColor(skincolors_t color); INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]); -- 2.54.0 From 9fddf3241fec7aae2ad14f77ac3181162ed01218 Mon Sep 17 00:00:00 2001 From: xyzzy Date: Sun, 27 Aug 2023 12:06:52 +0300 Subject: [PATCH 10/11] Make `alias` print a list of all defined aliases. * Alias with no args not only prints out the help text but all command aliases. * Alias with just one argument prints all commands that begin with the first argument. --- src/command.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 49bba34e7..46709fc67 100644 --- a/src/command.c +++ b/src/command.c @@ -634,10 +634,44 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; + const char *alias_format = "\x87%-8s:\x80 %s\n"; + int argc = COM_Argc(); - if (COM_Argc() < 3) + if (argc == 2) { + const char *begin = COM_Argv(1); + size_t szBegin = strlen(begin); + + /* Display all aliases that start with `begin`. */ + CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); + + int count = 0; + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + if (strncmp(begin, head->name, szBegin) == 0) + { + CONS_Printf(alias_format, head->name, head->value); + count++; + } + } + + if (count == 0) + { + CONS_Printf(M_GetText("There are none.\n")); + } + + return; + } + else if (argc < 3) + { + /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); + + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + CONS_Printf(alias_format, head->name, head->value); + } + return; } -- 2.54.0 From 259c180767d040974eb697ff6d8113552e691ce8 Mon Sep 17 00:00:00 2001 From: xyzzy Date: Sun, 27 Aug 2023 12:21:04 +0300 Subject: [PATCH 11/11] Patch in listskins for Saturn :3 * Listskins lists all loaded skins. * It's fun * Paginated display. --- src/d_netcmd.c | 105 +++++++++++++++++++ src/hu_stuff.c | 268 ++++++++++++++++++++++++------------------------- src/hu_stuff.h | 1 + 3 files changed, 235 insertions(+), 139 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 84bfc364c..859e396b7 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -190,6 +190,9 @@ static void Command_ShowTime_f(void); static void Command_Isgamemodified_f(void); static void Command_Cheats_f(void); + +static void Command_ListSkins(void); + #ifdef _DEBUG static void Command_Togglemodified_f(void); #ifdef HAVE_BLUA @@ -1142,8 +1145,34 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_discordstreamer); CV_RegisterVar(&cv_discordasks); #endif + + COM_AddCommand("listskins", Command_ListSkins); } +/** + * Searches the skins list for a skin of the "realname", if found, changes + * the CVAR value to be the "name" of the skin. + * \sa cv_skin, Skin_OnChange, Skin2_OnChange + * \author karen + */ +static void Skin_FindRealNameSkin(consvar_t *cvar) +{ + // Not the best way to implements this but it will do. + + int i; + const char *value = cvar->string; + for (i = 0; i < numskins; i++) + { + if (strncmp(value, skins[i].realname, sizeof skins[i].realname) == 0) + { + // Change the cvar to be the value of the name. + CV_StealthSet(cvar, skins[i].name); + return; + } + } +} + + /** Checks if a name (as received from another player) is okay. * A name is okay if it is no fewer than 1 and no more than ::MAXPLAYERNAME * chars long (not including NUL), it does not begin or end with a space, @@ -5736,6 +5765,8 @@ static void Name4_OnChange(void) */ static void Skin_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin); + if (!Playing()) return; // do whatever you want @@ -5762,6 +5793,8 @@ static void Skin_OnChange(void) */ static void Skin2_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin2); + if (!Playing() || !splitscreen) return; // do whatever you want @@ -5776,6 +5809,8 @@ static void Skin2_OnChange(void) static void Skin3_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin3); + if (!Playing() || splitscreen < 2) return; // do whatever you want @@ -5790,6 +5825,8 @@ static void Skin3_OnChange(void) static void Skin4_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin4); + if (!Playing() || splitscreen < 3) return; // do whatever you want @@ -5802,6 +5839,74 @@ static void Skin4_OnChange(void) } } +static void Command_ListSkins(void) +{ + int i; + int page = 0; + int numpages = numskins / 10 + (numskins % 10 ? 1 : 0); + int longest_name = 0; + + if (COM_Argc() > 1) + { + if (sscanf(COM_Argv(1), " %d", &page) == 0) + { + CONS_Printf("Expected a number.\n"); + return; + } + else if (page > numpages) + { + CONS_Printf("There are only %d pages.\n", numpages); + return; + } + else if (page < 0) + { + CONS_Printf("Page number cannot be negative.\n"); + return; + } + else if (page == 0) + { + CONS_Printf("There is no 0th page. (What are you a programmer?)\n"); + return; + } + + --page; + } + + CONS_Printf("Total %d skins. Page (%d/%d)\n", numskins, page + 1, numpages); + + // Find the longest name and realname in the skins list. (used for alignment) + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + int length; + skin_t *skin = &skins[i]; + + if ((length = strlen(skin->name)) > longest_name) + longest_name = length; + } + + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + skin_t *skin = &skins[i]; + + CONS_Printf( + "%s[%-*s]\x80 %s\n", + HU_SkinColorToConsoleColor(skin->prefcolor), + longest_name, + skin->name, + skin->realname); + } + + if (page + 1 != numpages) + { + CONS_Printf("Use \"listskins %d\" to see the next page.\n", page + 2); + } + else + { + CONS_Printf("There are no more pages.\n"); + } +} + + /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange * \author Graue diff --git a/src/hu_stuff.c b/src/hu_stuff.c index effb24837..3d5017961 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -682,6 +682,134 @@ static void Command_CSay_f(void) } static tic_t stop_spamming[MAXPLAYERS]; +const char *HU_SkinColorToConsoleColor(skincolors_t color) +{ + // Move this ugly switch into a function you can collapse. + switch (color) + { + case SKINCOLOR_WHITE: + case SKINCOLOR_SILVER: + case SKINCOLOR_SLATE: + return "\x80"; // White + case SKINCOLOR_GREY: + case SKINCOLOR_NICKEL: + case SKINCOLOR_BLACK: + case SKINCOLOR_SKUNK: + case SKINCOLOR_JET: + return "\x86"; // V_GRAYMAP + case SKINCOLOR_SEPIA: + case SKINCOLOR_BEIGE: + case SKINCOLOR_WALNUT: + case SKINCOLOR_BROWN: + case SKINCOLOR_LEATHER: + case SKINCOLOR_RUST: + case SKINCOLOR_WRISTWATCH: + return "\x8e"; // V_BROWNMAP + case SKINCOLOR_FAIRY: + case SKINCOLOR_SALMON: + case SKINCOLOR_PINK: + case SKINCOLOR_ROSE: + case SKINCOLOR_BRICK: + case SKINCOLOR_LEMONADE: + case SKINCOLOR_BUBBLEGUM: + case SKINCOLOR_LILAC: + return "\x8d"; // V_PINKMAP + case SKINCOLOR_CINNAMON: + case SKINCOLOR_RUBY: + case SKINCOLOR_RASPBERRY: + case SKINCOLOR_CHERRY: + case SKINCOLOR_RED: + case SKINCOLOR_CRIMSON: + case SKINCOLOR_MAROON: + case SKINCOLOR_FLAME: + case SKINCOLOR_SCARLET: + case SKINCOLOR_KETCHUP: + return "\x85"; // V_REDMAP + case SKINCOLOR_DAWN: + case SKINCOLOR_SUNSET: + case SKINCOLOR_CREAMSICLE: + case SKINCOLOR_ORANGE: + case SKINCOLOR_PUMPKIN: + case SKINCOLOR_ROSEWOOD: + case SKINCOLOR_BURGUNDY: + case SKINCOLOR_TANGERINE: + return "\x87"; // V_ORANGEMAP + case SKINCOLOR_PEACH: + case SKINCOLOR_CARAMEL: + case SKINCOLOR_CREAM: + return "\x8f"; // V_PEACHMAP + case SKINCOLOR_GOLD: + case SKINCOLOR_ROYAL: + case SKINCOLOR_BRONZE: + case SKINCOLOR_COPPER: + case SKINCOLOR_THUNDER: + return "\x8A"; // V_GOLDMAP + case SKINCOLOR_POPCORN: + case SKINCOLOR_QUARRY: + case SKINCOLOR_YELLOW: + case SKINCOLOR_MUSTARD: + case SKINCOLOR_CROCODILE: + case SKINCOLOR_OLIVE: + return "\x82"; // V_YELLOWMAP + case SKINCOLOR_ARTICHOKE: + case SKINCOLOR_VOMIT: + case SKINCOLOR_GARDEN: + case SKINCOLOR_TEA: + case SKINCOLOR_PISTACHIO: + return "\x8b"; // V_TEAMAP + case SKINCOLOR_LIME: + case SKINCOLOR_HANDHELD: + case SKINCOLOR_MOSS: + case SKINCOLOR_CAMOUFLAGE: + case SKINCOLOR_ROBOHOOD: + case SKINCOLOR_MINT: + case SKINCOLOR_GREEN: + case SKINCOLOR_PINETREE: + case SKINCOLOR_EMERALD: + case SKINCOLOR_SWAMP: + case SKINCOLOR_DREAM: + case SKINCOLOR_PLAGUE: + case SKINCOLOR_ALGAE: + return "\x83"; // V_GREENMAP + case SKINCOLOR_CARIBBEAN: + case SKINCOLOR_AZURE: + case SKINCOLOR_AQUA: + case SKINCOLOR_TEAL: + case SKINCOLOR_CYAN: + case SKINCOLOR_JAWZ: + case SKINCOLOR_CERULEAN: + case SKINCOLOR_NAVY: + case SKINCOLOR_SAPPHIRE: + return "\x88"; // V_SKYMAP + case SKINCOLOR_PIGEON: + case SKINCOLOR_PLATINUM: + case SKINCOLOR_STEEL: + return "\x8c"; // V_STEELMAP + case SKINCOLOR_PERIWINKLE: + case SKINCOLOR_BLUE: + case SKINCOLOR_BLUEBERRY: + case SKINCOLOR_NOVA: + return "\x84"; // V_BLUEMAP + case SKINCOLOR_ULTRAVIOLET: + case SKINCOLOR_PURPLE: + case SKINCOLOR_FUCHSIA: + return "\x81"; // V_PURPLEMAP + case SKINCOLOR_PASTEL: + case SKINCOLOR_MOONSLAM: + case SKINCOLOR_DUSK: + case SKINCOLOR_TOXIC: + case SKINCOLOR_MAUVE: + case SKINCOLOR_LAVENDER: + case SKINCOLOR_BYZANTIUM: + case SKINCOLOR_POMEGRANATE: + return "\x89"; // V_LAVENDERMAP + + default: + return "\x83"; + } +} + + /** Receives a message, processing an ::XD_SAY command. * \sa DoSayCommand * \author Graue @@ -828,145 +956,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) { const UINT8 color = players[playernum].skincolor; - cstart = "\x83"; - - switch (color) - { - case SKINCOLOR_WHITE: - case SKINCOLOR_SILVER: - case SKINCOLOR_SLATE: - cstart = "\x80"; // White - break; - case SKINCOLOR_GREY: - case SKINCOLOR_NICKEL: - case SKINCOLOR_BLACK: - case SKINCOLOR_SKUNK: - case SKINCOLOR_JET: - cstart = "\x86"; // V_GRAYMAP - break; - case SKINCOLOR_SEPIA: - case SKINCOLOR_BEIGE: - case SKINCOLOR_WALNUT: - case SKINCOLOR_BROWN: - case SKINCOLOR_LEATHER: - case SKINCOLOR_RUST: - case SKINCOLOR_WRISTWATCH: - cstart = "\x8e"; // V_BROWNMAP - break; - case SKINCOLOR_FAIRY: - case SKINCOLOR_SALMON: - case SKINCOLOR_PINK: - case SKINCOLOR_ROSE: - case SKINCOLOR_BRICK: - case SKINCOLOR_LEMONADE: - case SKINCOLOR_BUBBLEGUM: - case SKINCOLOR_LILAC: - cstart = "\x8d"; // V_PINKMAP - break; - case SKINCOLOR_CINNAMON: - case SKINCOLOR_RUBY: - case SKINCOLOR_RASPBERRY: - case SKINCOLOR_CHERRY: - case SKINCOLOR_RED: - case SKINCOLOR_CRIMSON: - case SKINCOLOR_MAROON: - case SKINCOLOR_FLAME: - case SKINCOLOR_SCARLET: - case SKINCOLOR_KETCHUP: - cstart = "\x85"; // V_REDMAP - break; - case SKINCOLOR_DAWN: - case SKINCOLOR_SUNSET: - case SKINCOLOR_CREAMSICLE: - case SKINCOLOR_ORANGE: - case SKINCOLOR_PUMPKIN: - case SKINCOLOR_ROSEWOOD: - case SKINCOLOR_BURGUNDY: - case SKINCOLOR_TANGERINE: - cstart = "\x87"; // V_ORANGEMAP - break; - case SKINCOLOR_PEACH: - case SKINCOLOR_CARAMEL: - case SKINCOLOR_CREAM: - cstart = "\x8f"; // V_PEACHMAP - break; - case SKINCOLOR_GOLD: - case SKINCOLOR_ROYAL: - case SKINCOLOR_BRONZE: - case SKINCOLOR_COPPER: - case SKINCOLOR_THUNDER: - cstart = "\x8A"; // V_GOLDMAP - break; - case SKINCOLOR_POPCORN: - case SKINCOLOR_QUARRY: - case SKINCOLOR_YELLOW: - case SKINCOLOR_MUSTARD: - case SKINCOLOR_CROCODILE: - case SKINCOLOR_OLIVE: - cstart = "\x82"; // V_YELLOWMAP - break; - case SKINCOLOR_ARTICHOKE: - case SKINCOLOR_VOMIT: - case SKINCOLOR_GARDEN: - case SKINCOLOR_TEA: - case SKINCOLOR_PISTACHIO: - cstart = "\x8b"; // V_TEAMAP - break; - case SKINCOLOR_LIME: - case SKINCOLOR_HANDHELD: - case SKINCOLOR_MOSS: - case SKINCOLOR_CAMOUFLAGE: - case SKINCOLOR_ROBOHOOD: - case SKINCOLOR_MINT: - case SKINCOLOR_GREEN: - case SKINCOLOR_PINETREE: - case SKINCOLOR_EMERALD: - case SKINCOLOR_SWAMP: - case SKINCOLOR_DREAM: - case SKINCOLOR_PLAGUE: - case SKINCOLOR_ALGAE: - cstart = "\x83"; // V_GREENMAP - break; - case SKINCOLOR_CARIBBEAN: - case SKINCOLOR_AZURE: - case SKINCOLOR_AQUA: - case SKINCOLOR_TEAL: - case SKINCOLOR_CYAN: - case SKINCOLOR_JAWZ: - case SKINCOLOR_CERULEAN: - case SKINCOLOR_NAVY: - case SKINCOLOR_SAPPHIRE: - cstart = "\x88"; // V_SKYMAP - break; - case SKINCOLOR_PIGEON: - case SKINCOLOR_PLATINUM: - case SKINCOLOR_STEEL: - cstart = "\x8c"; // V_STEELMAP - break; - case SKINCOLOR_PERIWINKLE: - case SKINCOLOR_BLUE: - case SKINCOLOR_BLUEBERRY: - case SKINCOLOR_NOVA: - cstart = "\x84"; // V_BLUEMAP - break; - case SKINCOLOR_ULTRAVIOLET: - case SKINCOLOR_PURPLE: - case SKINCOLOR_FUCHSIA: - cstart = "\x81"; // V_PURPLEMAP - break; - case SKINCOLOR_PASTEL: - case SKINCOLOR_MOONSLAM: - case SKINCOLOR_DUSK: - case SKINCOLOR_TOXIC: - case SKINCOLOR_MAUVE: - case SKINCOLOR_LAVENDER: - case SKINCOLOR_BYZANTIUM: - case SKINCOLOR_POMEGRANATE: - cstart = "\x89"; // V_LAVENDERMAP - break; - default: - break; - } + cstart = HU_SkinColorToConsoleColor(color); } prefix = cstart; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index f0ef731b6..9979427cf 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -121,6 +121,7 @@ void HU_drawPing(INT32 x, INT32 y, UINT32 ping, INT32 flags); // Lat': Ping draw //void HU_DrawDualTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer); void HU_DrawTabRankings(INT32 x, INT32 y, playersort_t *tab, INT32 scorelines, INT32 whiteplayer, INT32 hilicol); void HU_DrawEmeralds(INT32 x, INT32 y, INT32 pemeralds); +const char *HU_SkinColorToConsoleColor(skincolors_t color); INT32 HU_CreateTeamScoresTbl(playersort_t *tab, UINT32 dmtotals[]); -- 2.54.0