Compare commits

..
Author SHA1 Message Date
Alug f58772a570 z_zone: add asserts if zone memory functions are called from non main thread
also taken from srb2classic thanks!
2026-02-02 18:14:38 +01:00
Alug f7c065b22e refactor i_thread stuff
based on https://codeberg.org/srb2classic/srb2classic/commit/3670a7c1c193185cf4921de8955c96e63fbecc62
and other things from srb2classic
this also now allows to check if a thread failed to spawn and reduces duped stuff and such
2026-02-02 18:14:35 +01:00
69 changed files with 774 additions and 3262 deletions

No files matched your search

+2 -1
View File
@@ -54,7 +54,7 @@ set(SRB2_CORE_SOURCES
string.c string.c
tables.c tables.c
v_video.c v_video.c
w_wad.cpp w_wad.c
y_inter.c y_inter.c
z_zone.cpp z_zone.cpp
) )
@@ -191,6 +191,7 @@ set(SRB2_CORE_GAME_SOURCES
k_kart.c k_kart.c
k_stats.c k_stats.c
i_time.c i_time.c
i_threads.c
p_local.h p_local.h
p_maputl.h p_maputl.h
-1
View File
@@ -295,7 +295,6 @@ opts+=$(debug_opts)
opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v))) opts+=$(foreach v,$(passthru_opts),$(if $($(v)),-D$(v)))
CWFLAGS+=-std=gnu17
CXXFLAGS+=-std=c++17 # force c17 for c++ since most vpss run older ubuntu versions with old compilers CXXFLAGS+=-std=c++17 # force c17 for c++ since most vpss run older ubuntu versions with old compilers
opts+=$(WFLAGS) $(CFLAGS) opts+=$(WFLAGS) $(CFLAGS)
-5
View File
@@ -8,11 +8,6 @@ ifdef MINGW
libs+=-mconsole libs+=-mconsole
endif endif
ifndef NOTHREADS
opts+=-DHAVE_THREADS
sources+=dedicated/i_threads.c
endif
NOOPENMPT=1 NOOPENMPT=1
NOLIBGME=1 NOLIBGME=1
NOHW=1 NOHW=1
+5
View File
@@ -27,6 +27,11 @@ endif
sources+=$(call List,hardware/Sourcefile) sources+=$(call List,hardware/Sourcefile)
endif endif
ifndef NOTHREADS
opts+=-DHAVE_THREADS
sources+=i_threads.c
endif
ifndef NOMD5 ifndef NOMD5
sources+=md5.c sources+=md5.c
endif endif
-5
View File
@@ -40,11 +40,6 @@ sources+=sdl/mixer_sound.c
endif endif
endif endif
ifndef NOTHREADS
opts+=-DHAVE_THREADS
sources+=sdl/i_threads.c
endif
ifdef SDL_PKGCONFIG ifdef SDL_PKGCONFIG
$(eval $(call Use_pkg_config,SDL)) $(eval $(call Use_pkg_config,SDL))
else else
+1 -1
View File
@@ -434,7 +434,7 @@ LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) { LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
lua_lock(L); lua_lock(L);
luaC_checkGC(L); luaC_checkGC(L);
setsvalue2s(L, L->top, (len == 0) ? luaS_newlstr(L, "", 0) : luaS_newlstr(L, s, len)); setsvalue2s(L, L->top, (len == 0) ? luaS_new(L, "") : luaS_newlstr(L, s, len));
api_incr_top(L); api_incr_top(L);
lua_unlock(L); lua_unlock(L);
} }
+2 -2
View File
@@ -1178,7 +1178,7 @@ consvar_t *CV_FindVar(const char *name)
consvar_t *cvar; consvar_t *cvar;
for (cvar = consvar_vars; cvar; cvar = cvar->next) for (cvar = consvar_vars; cvar; cvar = cvar->next)
if (fasticmp(name, cvar->name)) if (fasticmp(name,cvar->name))
return cvar; return cvar;
return NULL; return NULL;
@@ -1793,7 +1793,7 @@ void CV_AddValue(consvar_t *var, INT32 increment)
if (newvalue == oldvalue) if (newvalue == oldvalue)
break; // don't loop forever if there's none of a certain gametype break; // don't loop forever if there's none of a certain gametype
if (newvalue >= 0 && newvalue < NUMMAPS && !mapheaderinfo[newvalue]) if (newvalue >= 0 && !mapheaderinfo[newvalue])
continue; // Don't allocate the header. That just makes memory usage skyrocket. continue; // Don't allocate the header. That just makes memory usage skyrocket.
} while (!M_CanShowLevelInList(newvalue, gt)); } while (!M_CanShowLevelInList(newvalue, gt));
+6 -6
View File
@@ -44,18 +44,18 @@
#define MAXHUDLINES 20 #define MAXHUDLINES 20
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex con_mutex; I_Mutex con_mutex;
// I_In_Exiting_Signal_Handler is an evil hack // g_in_exiting_signal_handler is an evil hack
// to avoid infinite SIGABRT recursion in the signal handler // to avoid infinite SIGABRT recursion in the signal handler
// due to poisoned locks or mach-o kernel not supporting locks in signals // due to poisoned locks or mach-o kernel not supporting locks in signals
// or something like that. idk // or something like that. idk
# define Lock_state() if (!I_In_Exiting_Signal_Handler()) { I_lock_mutex(&con_mutex); } # define Lock_state() if (!g_in_exiting_signal_handler) { I_LockMutex(&con_mutex); }
# define Unlock_state() if (!I_In_Exiting_Signal_Handler()) { I_unlock_mutex(con_mutex); } # define Unlock_state() if (!g_in_exiting_signal_handler) { I_UnlockMutex(con_mutex); }
#else /*HAVE_THREADS*/ #else/*HAVE_THREADS*/
# define Lock_state() # define Lock_state()
# define Unlock_state() # define Unlock_state()
#endif /*HAVE_THREADS*/ #endif/*HAVE_THREADS*/
static boolean con_started = false; // console has been initialised static boolean con_started = false; // console has been initialised
boolean con_startup = false; // true at game startup, screen need refreshing boolean con_startup = false; // true at game startup, screen need refreshing
+1 -9
View File
@@ -13,10 +13,6 @@
#ifndef __CONSOLE__ #ifndef __CONSOLE__
#define __CONSOLE__ #define __CONSOLE__
#ifdef __cplusplus
extern "C" {
#endif
#include "d_event.h" #include "d_event.h"
#include "command.h" #include "command.h"
#include "i_threads.h" #include "i_threads.h"
@@ -26,7 +22,7 @@ void CON_Init(void);
boolean CON_Responder(event_t *ev); boolean CON_Responder(event_t *ev);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
extern I_mutex con_mutex; extern I_Mutex con_mutex;
#endif #endif
// set true when screen size has changed, to adapt console // set true when screen size has changed, to adapt console
@@ -67,8 +63,4 @@ boolean CON_Ready(void);
void CON_LogMessage(const char *msg); void CON_LogMessage(const char *msg);
#ifdef __cplusplus
} // extern "C"
#endif
#endif #endif
+5 -12
View File
@@ -2782,11 +2782,6 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
{ {
INT32 key; INT32 key;
if (I_Interrupted())
{
I_Quit();
}
I_OsPolling(); I_OsPolling();
if (cl_mode == CL_CONFIRMCONNECT) if (cl_mode == CL_CONFIRMCONNECT)
@@ -2835,11 +2830,11 @@ static boolean CL_ServerConnectionTicker(const char *tmpsave, tic_t *oldtic, tic
F_TitleScreenDrawer(); F_TitleScreenDrawer();
CL_DrawConnectionStatus(); CL_DrawConnectionStatus();
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_Drawer(); //Needed for drawing messageboxes on the connection screen M_Drawer(); //Needed for drawing messageboxes on the connection screen
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
I_UpdateNoVsync(); // page flip or blit buffer I_UpdateNoVsync(); // page flip or blit buffer
if (moviemode) if (moviemode)
@@ -3355,7 +3350,7 @@ void CL_ClearPlayer(INT32 playernum)
if (players[playernum].mo) if (players[playernum].mo)
{ {
// Don't leave a NiGHTS ghost! // Don't leave a NiGHTS ghost!
if (UNLIKELY((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer)) if ((players[playernum].pflags & PF_NIGHTSMODE) && players[playernum].mo->tracer)
P_RemoveMobj(players[playernum].mo->tracer); P_RemoveMobj(players[playernum].mo->tracer);
P_RemoveMobj(players[playernum].mo); P_RemoveMobj(players[playernum].mo);
} }
@@ -3501,7 +3496,6 @@ static void Command_GetPlayerNum(void)
INT32 i; INT32 i;
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i]) if (playeringame[i])
{ {
if (serverplayer == i) if (serverplayer == i)
@@ -3509,7 +3503,6 @@ static void Command_GetPlayerNum(void)
else else
CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]); CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]);
} }
}
} }
SINT8 nametonum(const char *name) SINT8 nametonum(const char *name)
@@ -7194,12 +7187,12 @@ void NetUpdate(void)
{ {
resptime = nowtime; resptime = nowtime;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_Ticker(); M_Ticker();
refreshdirmenu = 0; refreshdirmenu = 0;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
CON_Ticker(); CON_Ticker();
} }
+40 -34
View File
@@ -223,13 +223,13 @@ void D_ProcessEvents(void)
// Menu input // Menu input
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
{ {
eaten = M_Responder(ev); eaten = M_Responder(ev);
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
if (eaten) if (eaten)
@@ -244,13 +244,13 @@ void D_ProcessEvents(void)
// console input // console input
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&con_mutex); I_LockMutex(&con_mutex);
#endif #endif
{ {
eaten = CON_Responder(ev); eaten = CON_Responder(ev);
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(con_mutex); I_UnlockMutex(con_mutex);
#endif #endif
if (eaten) if (eaten)
@@ -274,17 +274,21 @@ static void D_Renderview(void)
R_ApplyLevelInterpolators(R_GetTimeFrac(RTF_LEVEL)); R_ApplyLevelInterpolators(R_GetTimeFrac(RTF_LEVEL));
if (rendermode == render_soft && cv_homremoval.value) if (rendermode == render_soft)
{ {
if (cv_homremoval.value == 1) // if this is display player 1
if (cv_homremoval.value)
{ {
// Clear the software screen buffer to remove HOM if (cv_homremoval.value == 1)
memset(vid.screens[0], 31, vid.width * vid.height); {
} // Clear the software screen buffer to remove HOM
else if (cv_homremoval.value == 2) memset(vid.screens[0], 31, vid.width * vid.height);
{ }
//'development' HOM removal -- makes it blindingly obvious if HOM is spotted. else if (cv_homremoval.value == 2)
memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); {
//'development' HOM removal -- makes it blindingly obvious if HOM is spotted.
memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height);
}
} }
} }
@@ -318,6 +322,7 @@ static void D_Renderview(void)
break; break;
default: // Initialize for P1 default: // Initialize for P1
viewwindowy = viewwindowx = 0; viewwindowy = viewwindowx = 0;
objectsdrawn = 0;
break; break;
} }
@@ -328,17 +333,19 @@ static void D_Renderview(void)
} }
else if (rendermode == render_soft) else if (rendermode == render_soft)
#endif #endif
{
R_RenderPlayerView(&players[displayplayers[i]]); R_RenderPlayerView(&players[displayplayers[i]]);
}
if (rendermode == render_soft)
{
if (i == 0)
R_ApplyViewMorph();
if (i == 0)
R_ApplyViewMorph();
#ifdef MOTIONBLUR #ifdef MOTIONBLUR
V_DoPostProcessor(i, postimgparam[i]); V_DoPostProcessor(i, postimgparam[i]);
#else #else
V_DoPostProcessor(i, 0); V_DoPostProcessor(i, 0);
#endif #endif
}
} }
} }
@@ -570,11 +577,11 @@ static boolean D_Display(void)
vid.recalc = false; vid.recalc = false;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_Drawer(); // menu is drawn even on top of everything... M_Drawer(); // menu is drawn even on top of everything...
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
// focus lost moved to M_Drawer // focus lost moved to M_Drawer
@@ -697,11 +704,6 @@ void D_SRB2Loop(void)
for (;;) for (;;)
{ {
if (I_Interrupted())
{
I_Quit();
}
// capbudget is the minimum precise_t duration of a single loop iteration // capbudget is the minimum precise_t duration of a single loop iteration
precise_t capbudget; precise_t capbudget;
precise_t elapsed; precise_t elapsed;
@@ -781,6 +783,11 @@ void D_SRB2Loop(void)
doDisplay = true; doDisplay = true;
} }
if (!dedicated)
{
G_DeviceLEDTick();
}
} }
if (interp) if (interp)
@@ -822,13 +829,6 @@ void D_SRB2Loop(void)
if (takescreenshot) if (takescreenshot)
M_DoScreenShot(); M_DoScreenShot();
#ifndef DEDICATED
if (!dedicated && renderisnewtic)
{
G_DeviceLEDTick();
}
#endif
// consoleplayer -> displayplayers (hear sounds from viewpoint) // consoleplayer -> displayplayers (hear sounds from viewpoint)
S_UpdateSounds(); // move positional sounds S_UpdateSounds(); // move positional sounds
@@ -1643,6 +1643,12 @@ void D_SRB2Main(void)
strcpy(srb2, "SRB2Kart"); strcpy(srb2, "SRB2Kart");
D_MakeTitleString(srb2); D_MakeTitleString(srb2);
#if defined (__OS2__) && !defined (HAVE_SDL)
// set PM window title
snprintf(pmData->title, sizeof (pmData->title), "SRB2Kart" VERSIONSTRING ": %s", title);
pmData->title[sizeof (pmData->title) - 1] = '\0';
#endif
if (devparm) if (devparm)
CONS_Printf(M_GetText("Development mode ON.\n")); CONS_Printf(M_GetText("Development mode ON.\n"));
@@ -2023,7 +2029,7 @@ void D_SRB2Main(void)
if (M_CheckProtoParam("replay")) if (M_CheckProtoParam("replay"))
{ {
const char *replayurl = M_GetProtoParam(); const char *replayurl = M_GetProtoParam();
gconst char *replayname = strrchr(replayurl, '/'); char *replayname = strrchr(replayurl, '/');
if (!replayname || !replayurl) if (!replayname || !replayurl)
I_Error("REPLAY: Invalid URL."); I_Error("REPLAY: Invalid URL.");
+6 -6
View File
@@ -112,7 +112,7 @@ static fileused_t transferFiles[UINT8_MAX + 1];
INT32 fileneedednum = 0; // Number of files needed to join the server INT32 fileneedednum = 0; // Number of files needed to join the server
fileneeded_t fileneeded[MAX_WADFILES] = {}; // List of needed files fileneeded_t fileneeded[MAX_WADFILES] = {}; // List of needed files
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
static I_mutex downloadmutex; static I_Mutex downloadmutex;
#endif #endif
char downloaddir[512] = "DOWNLOAD"; char downloaddir[512] = "DOWNLOAD";
@@ -1427,7 +1427,7 @@ void CURLPrepareFile(const char* url, int dfilenum)
filedownload.http_running = true; filedownload.http_running = true;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread("http-download", (I_thread_fn)CURLGetFile, NULL); (void)!I_SpawnThread("http-download", (I_ThreadFn)CURLGetFile, NULL);
#endif #endif
} }
else else
@@ -1440,15 +1440,15 @@ void CURLAbortFile(void)
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
// lock and unlock to wait for the download thread to exit // lock and unlock to wait for the download thread to exit
I_lock_mutex(&downloadmutex); I_LockMutex(&downloadmutex);
I_unlock_mutex(downloadmutex); I_UnlockMutex(downloadmutex);
#endif #endif
} }
static void CURLGetFile(void) static void CURLGetFile(void)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&downloadmutex); I_LockMutex(&downloadmutex);
#endif #endif
CURLMcode mc; /* return code used by curl_multi_wait() */ CURLMcode mc; /* return code used by curl_multi_wait() */
CURLcode easyres; /* Return from easy interface */ CURLcode easyres; /* Return from easy interface */
@@ -1549,7 +1549,7 @@ static void CURLGetFile(void)
filedownload.http_running = false; filedownload.http_running = false;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(downloadmutex); I_UnlockMutex(downloadmutex);
#endif #endif
} }
-1
View File
@@ -2,6 +2,5 @@ i_system.c
i_main.c i_main.c
i_video.c i_video.c
i_sound.c i_sound.c
i_threads.c
dosstr.c dosstr.c
endtxt.c endtxt.c
+7 -19
View File
@@ -984,7 +984,7 @@ void I_SleepDuration(precise_t duration)
#endif #endif
} }
static volatile sig_atomic_t g_in_exiting_signal_handler = false; boolean g_in_exiting_signal_handler = false;
static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg) static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg)
{ {
@@ -1048,11 +1048,6 @@ static void I_ReportSignal(int num, int coredumped)
I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg);
} }
boolean I_In_Exiting_Signal_Handler(void)
{
return g_in_exiting_signal_handler;
}
#ifndef NEWSIGNALHANDLER #ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{ {
@@ -1072,17 +1067,11 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
} }
#endif #endif
static volatile sig_atomic_t interrupted = 0; FUNCNORETURN static ATTRNORETURN void quit_handler(int num)
boolean I_Interrupted(void)
{ {
return interrupted; signal(num, SIG_DFL); //default signal action
} raise(num);
I_Quit();
static void quit_handler(int num)
{
(void)num;
interrupted = 1;
} }
#ifdef HAVE_LIBBACKTRACE #ifdef HAVE_LIBBACKTRACE
@@ -1384,7 +1373,6 @@ static void I_Fork(void)
INT32 I_StartupSystem(void) INT32 I_StartupSystem(void)
{ {
W_Startup();
I_StartupConsole(); I_StartupConsole();
#ifdef NEWSIGNALHANDLER #ifdef NEWSIGNALHANDLER
// This is useful when debugging. It lets GDB attach to // This is useful when debugging. It lets GDB attach to
@@ -1393,8 +1381,8 @@ INT32 I_StartupSystem(void)
I_Fork(); I_Fork();
#endif #endif
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_start_threads(); I_StartThreads();
I_AddExitFunc(I_stop_threads); I_AddExitFunc(I_StopThreads);
#endif #endif
I_RegisterSignals(); I_RegisterSignals();
#ifndef NOMUMBLE #ifndef NOMUMBLE
+2 -2
View File
@@ -173,7 +173,7 @@ FUNCPRINTF static void deh_warning(const char *first, ...)
vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer. vsnprintf(buf, 1000, first, argptr); // sizeof only returned 4 here. it didn't like that pointer.
va_end(argptr); va_end(argptr);
if (dbg_line == -1) // Not in a SOC, line number unknown. if(dbg_line == -1) // Not in a SOC, line number unknown.
CONS_Alert(CONS_WARNING, "%s\n", buf); CONS_Alert(CONS_WARNING, "%s\n", buf);
else else
CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf); CONS_Alert(CONS_WARNING, "Line %u: %s\n", dbg_line, buf);
@@ -8545,7 +8545,7 @@ static inline int lib_action(lua_State *L)
// Hardcoded A_Action name to call for super() or NULL if super() would be invalid. // Hardcoded A_Action name to call for super() or NULL if super() would be invalid.
// Set in lua_infolib. // Set in lua_infolib.
const char *superactions[MAXRECURSION] = {}; const char *superactions[MAXRECURSION];
UINT8 superstack = 0; UINT8 superstack = 0;
static int lib_dummysuper(lua_State *L) static int lib_dummysuper(lua_State *L)
-9
View File
@@ -13,10 +13,6 @@
#ifndef __DEHACKED_H__ #ifndef __DEHACKED_H__
#define __DEHACKED_H__ #define __DEHACKED_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "m_fixed.h" // for get_number #include "m_fixed.h" // for get_number
#include "info.h" #include "info.h"
@@ -75,9 +71,4 @@ typedef struct
} MYFILE; } MYFILE;
#define myfeof(a) (a->data + a->size <= a->curpos) #define myfeof(a) (a->data + a->size <= a->curpos)
char *myfgets(char *buf, size_t bufsize, MYFILE *f); char *myfgets(char *buf, size_t bufsize, MYFILE *f);
#ifdef __cplusplus
} // extern "C"
#endif
#endif #endif
+16
View File
@@ -516,6 +516,22 @@ extern boolean capslock;
// i_system.c, replace getchar() once the keyboard has been appropriated // i_system.c, replace getchar() once the keyboard has been appropriated
INT32 I_GetKey(void); INT32 I_GetKey(void);
/* http://www.cse.yorku.ca/~oz/hash.html */
static inline
UINT32 quickncasehash (const char *p, size_t n)
{
size_t i = 0;
UINT32 x = 5381;
while (i < n && p[i])
{
x = (x * 33) ^ tolower(p[i]);
i++;
}
return x;
}
#ifndef __cplusplus #ifndef __cplusplus
#ifndef min // Double-Check with WATTCP-32's cdefs.h #ifndef min // Double-Check with WATTCP-32's cdefs.h
#define min(x, y) (((x) < (y)) ? (x) : (y)) #define min(x, y) (((x) < (y)) ? (x) : (y))
+10 -16
View File
@@ -68,21 +68,8 @@ extern "C" {
#define strnicmp(x,y,n) strncasecmp(x,y,n) #define strnicmp(x,y,n) strncasecmp(x,y,n)
#endif #endif
// glibc 2.43 made alot of standard lib functions propagate the constness of its input pointers
// to not cause warnings or compile issues on older glibc versions we do this silly thing
// to not have a gazillion glibc version checks
#if defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 43)
#define gconst const
#else
#define gconst
#endif
#else
#define gconst
#endif
#ifndef _GNU_SOURCE
char *nongnu_strcasestr(const char *in, const char *what); char *nongnu_strcasestr(const char *in, const char *what);
#ifndef _GNU_SOURCE
#define strcasestr nongnu_strcasestr #define strcasestr nongnu_strcasestr
#endif #endif
@@ -140,9 +127,9 @@ size_t strlcpy(char *dst, const char *src, size_t dsize);
#define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst) #define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst)
/* Boolean type definition */ /* Boolean type definition */
#include <stdbool.h>
#ifndef _WIN32 #ifndef _WIN32
#include <stdbool.h>
// dont use stdbools _BOOL type // dont use stdbools _BOOL type
// its smaller (1 byte) than the old interger bool (4 bytes) // its smaller (1 byte) than the old interger bool (4 bytes)
// which results in packed struct sizes being mismatched between vanilla and this // which results in packed struct sizes being mismatched between vanilla and this
@@ -150,7 +137,9 @@ size_t strlcpy(char *dst, const char *src, size_t dsize);
// which we cant use as enumeration constants // which we cant use as enumeration constants
typedef int32_t boolean; typedef int32_t boolean;
#else #else
#define boolean int32_t #define false FALSE
#define true TRUE
#define boolean BOOL
#endif #endif
/* 7.18.2.1 Limits of exact-width integer types */ /* 7.18.2.1 Limits of exact-width integer types */
@@ -234,6 +223,8 @@ typedef int32_t boolean;
#define FUNCNOINLINE __attribute__((noinline)) #define FUNCNOINLINE __attribute__((noinline))
#define FUNCWARNRV __attribute__((warn_unused_result))
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4
#ifdef __i386__ // i386 only #ifdef __i386__ // i386 only
#define FUNCTARGET(X) __attribute__ ((__target__ (X))) #define FUNCTARGET(X) __attribute__ ((__target__ (X)))
@@ -279,6 +270,9 @@ typedef int32_t boolean;
#ifndef FUNCTARGET #ifndef FUNCTARGET
#define FUNCTARGET(x) #define FUNCTARGET(x)
#endif #endif
#ifndef FUNCWARNRV
#define FUNCWARNRV
#endif
#ifndef ATTRPACK #ifndef ATTRPACK
#define ATTRPACK #define ATTRPACK
#endif #endif
+2 -7
View File
@@ -361,11 +361,6 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu)
// on for fade-to-black // on for fade-to-black
for (;;) for (;;)
{ {
if (I_Interrupted())
{
I_Quit();
}
// get fademask first so we can tell if it exists or not // get fademask first so we can tell if it exists or not
fmask = F_GetFadeMask(wipetype, wipeframe++); fmask = F_GetFadeMask(wipetype, wipeframe++);
@@ -393,11 +388,11 @@ void F_RunWipe(UINT8 wipetype, boolean drawMenu)
if (rendermode != render_none && drawMenu) if (rendermode != render_none && drawMenu)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_Drawer(); // menu is drawn even on top of wipes M_Drawer(); // menu is drawn even on top of wipes
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
} }
+1 -1
View File
@@ -2605,7 +2605,7 @@ void G_DoPlayDemo(char *defdemoname)
boolean skiperrors = false; boolean skiperrors = false;
#endif #endif
boolean spectator; boolean spectator;
UINT8 slots[MAXPLAYERS] = {}, kartspeed[MAXPLAYERS] = {}, kartweight[MAXPLAYERS] = {}, numslots = 0; UINT8 slots[MAXPLAYERS], kartspeed[MAXPLAYERS], kartweight[MAXPLAYERS], numslots = 0;
G_InitDemoRewind(); G_InitDemoRewind();
-3
View File
@@ -4153,7 +4153,6 @@ static void measurekeywords(mapsearchfreq_t *fr,
{ {
char *qp; char *qp;
char *sp; char *sp;
if (wanttable) if (wanttable)
(*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim), (*dimp) = Z_Realloc((*dimp), 255 * sizeof (struct searchdim),
PU_STATIC, NULL); PU_STATIC, NULL);
@@ -4168,12 +4167,10 @@ static void measurekeywords(mapsearchfreq_t *fr,
(*dimp)[(*cuntp)].pos = sp - s; (*dimp)[(*cuntp)].pos = sp - s;
(*dimp)[(*cuntp)].siz = strlen(qp); (*dimp)[(*cuntp)].siz = strlen(qp);
} }
(*cuntp)++; (*cuntp)++;
fr->total++; fr->total++;
} }
} }
if (wanttable) if (wanttable)
(*dimp) = Z_Realloc((*dimp), (*cuntp) * sizeof (struct searchdim), (*dimp) = Z_Realloc((*dimp), (*cuntp) * sizeof (struct searchdim),
PU_STATIC, NULL); PU_STATIC, NULL);
@@ -15,6 +15,8 @@
#ifdef HWRENDER #ifdef HWRENDER
#include <unordered_set>
#include "hw_main.h" #include "hw_main.h"
#include "hw_glob.h" #include "hw_glob.h"
#include "hw_gl.h" #include "hw_gl.h"
@@ -98,7 +100,7 @@ static void HWR_DrawColumnInCache(const column_t *patchcol, UINT8 *block, GLMipm
position = 0; position = 0;
} }
position = max(((position * scale_y) + (FRACUNIT/2)) >> FRACBITS, 0); position = std::max(((position * scale_y) + (FRACUNIT/2)) >> FRACBITS, 0);
if (position + count >= pblockheight) if (position + count >= pblockheight)
count = pblockheight - position; count = pblockheight - position;
@@ -162,7 +164,7 @@ static void HWR_DrawPatchInCache(GLMipmap_t *mipmap,
fixed_t xfrac, xfracstep; fixed_t xfrac, xfracstep;
fixed_t yfracstep, scale_y; fixed_t yfracstep, scale_y;
const column_t *patchcol; const column_t *patchcol;
UINT8 *block = (UINT8 *)(mipmap->data); UINT8 *block = static_cast<UINT8 *>(mipmap->data);
INT32 bpp; INT32 bpp;
INT32 blockmodulo; INT32 blockmodulo;
RGBA_t *palette; RGBA_t *palette;
@@ -212,7 +214,7 @@ static void HWR_DrawTexturePatchInCache(GLMipmap_t *mipmap,
fixed_t xfrac, xfracstep; fixed_t xfrac, xfracstep;
fixed_t yfracstep, scale_y; fixed_t yfracstep, scale_y;
const column_t *patchcol; const column_t *patchcol;
UINT8 *block = (UINT8 *)(mipmap->data); UINT8 *block = static_cast<UINT8 *>(mipmap->data);
INT32 bpp; INT32 bpp;
INT32 blockmodulo; INT32 blockmodulo;
INT32 width, height; INT32 width, height;
@@ -288,7 +290,7 @@ static UINT8 *MakeBlock(GLMipmap_t *glMipmap)
INT32 blocksize = (glMipmap->width * glMipmap->height); INT32 blocksize = (glMipmap->width * glMipmap->height);
bpp = format2bpp(glMipmap->format); bpp = format2bpp(glMipmap->format);
block = (UINT8 *)(Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data))); block = static_cast<UINT8 *>(Z_Malloc(blocksize*bpp, PU_HWRCACHE, &(glMipmap->data)));
switch (bpp) switch (bpp)
{ {
@@ -325,7 +327,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
texture = textures[texnum]; texture = textures[texnum];
gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY; gltex->mipmap.flags = TF_CHROMAKEYED | TF_WRAPXY;
gltex->mipmap.format = (GLTextureFormat_t)(textureformat); gltex->mipmap.format = static_cast<GLTextureFormat_t>(textureformat);
// hack the Legacy skies.. // hack the Legacy skies..
if (UNLIKELY(memcmp(texture->name, "SKY", 3) == 0 && if (UNLIKELY(memcmp(texture->name, "SKY", 3) == 0 &&
@@ -344,7 +346,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
colormap += COLORMAP_REMAPOFFSET; colormap += COLORMAP_REMAPOFFSET;
#endif #endif
gltex->mipmap.colormap = (GLColormap_t *)(Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL)); gltex->mipmap.colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*gltex->mipmap.colormap), PU_HWRPATCHCOLMIPMAP, NULL));
gltex->mipmap.colormap->source = colormap; gltex->mipmap.colormap->source = colormap;
memcpy(gltex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8)); memcpy(gltex->mipmap.colormap->data, colormap, 256 * sizeof(UINT8));
@@ -377,7 +379,7 @@ static void HWR_GenerateTexture(INT32 texnum, GLMapTexture_t *gltex, boolean noe
// Composite the columns together. // Composite the columns together.
for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++) for (i = 0, patch = texture->patches; i < texture->patchcount; i++, patch++)
{ {
pdata = (UINT8 *)(W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL)); pdata = static_cast<UINT8 *>(W_CacheLumpNumPwad(patch->wad, patch->lump, PU_LEVEL));
realpatch = (softwarepatch_t *)pdata; realpatch = (softwarepatch_t *)pdata;
HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch); HWR_DrawTexturePatchInCache(&gltex->mipmap, blockwidth, blockheight, texture, patch, realpatch);
@@ -413,7 +415,7 @@ void HWR_MakePatch(const patch_t *patch, GLPatch_t *glPatch, GLMipmap_t *glMipma
glMipmap->flags = 0; glMipmap->flags = 0;
// setup the texture info // setup the texture info
glMipmap->format = (GLTextureFormat_t)(patchformat); glMipmap->format = static_cast<GLTextureFormat_t>(patchformat);
glPatch->max_s = (float)patch->width / (float)glMipmap->width; glPatch->max_s = (float)patch->width / (float)glMipmap->width;
glPatch->max_t = (float)patch->height / (float)glMipmap->height; glPatch->max_t = (float)patch->height / (float)glMipmap->height;
@@ -455,7 +457,7 @@ static void HWR_FreeTextureData(patch_t *patch)
if (!patch || !patch->hardware) if (!patch || !patch->hardware)
return; return;
glPatch = (GLPatch_t *)(patch->hardware); glPatch = static_cast<GLPatch_t *>(patch->hardware);
if (vid.glstate == VID_GL_LIBRARY_LOADED) if (vid.glstate == VID_GL_LIBRARY_LOADED)
GL_DeleteTexture(glPatch->mipmap); GL_DeleteTexture(glPatch->mipmap);
@@ -471,7 +473,7 @@ void HWR_FreeTexture(patch_t *patch)
if (patch->hardware) if (patch->hardware)
{ {
GLPatch_t *glPatch = (GLPatch_t *)(patch->hardware); GLPatch_t *glPatch = static_cast<GLPatch_t *>(patch->hardware);
HWR_FreeTextureColormaps(patch); HWR_FreeTextureColormaps(patch);
@@ -497,7 +499,7 @@ static void HWR_FreeTextureColormaps(patch_t *patch)
if (!patch) if (!patch)
return; return;
pat = (GLPatch_t *)(patch->hardware); pat = static_cast<GLPatch_t *>(patch->hardware);
if (!pat) if (!pat)
return; return;
@@ -612,20 +614,24 @@ void HWR_FreeMapTextures(void)
gl_numtextures = 0; gl_numtextures = 0;
} }
#define NAME flatcheck
#define KEY_TY UINT32
#define HASH_FN vt_hash_integer
#define CMPR_FN vt_cmpr_integer
#include "../verstable.h"
static void HWR_PrecacheLevelFlats(void) static void HWR_PrecacheLevelFlats(void)
{ {
// lookup for flats that may´ve been already loaded // lookup for flats that may´ve been already loaded
flatcheck flatpresent; // too lazy to make a hashtable or smth so unordered set will do :carbuncle:
flatcheck_init(&flatpresent); std::unordered_set<UINT32> flatpresent;
size_t i, j; size_t i, j;
INT32 k; INT32 k;
auto load_flat = [&](lumpnum_t lump, boolean noencoremap)
{
// flat already loaded?
if (flatpresent.count(lump) == 0)
{
HWR_GetFlat(lump, noencoremap);
flatpresent.insert(lump);
}
};
// special case for encore // special case for encore
#ifdef GLENCORE #ifdef GLENCORE
if (encoremap) if (encoremap)
@@ -643,23 +649,14 @@ static void HWR_PrecacheLevelFlats(void)
const levelflat_t *levelflat = &levelflats[pic]; const levelflat_t *levelflat = &levelflats[pic];
if (flatcheck_is_end(flatcheck_get(&flatpresent, levelflat->lumpnum))) load_flat(levelflat->lumpnum, R_NoEncore(sec, ceiling));
{
HWR_GetFlat(levelflat->lumpnum, R_NoEncore(sec, ceiling));
flatcheck_insert(&flatpresent, levelflat->lumpnum);
}
if (levelflat->speed) // is it an animated flat ? if (levelflat->speed) // is it an animated flat ?
{ {
// start from 0, occasionally basenumlump != flat->lumpnum // start from 0, occasionally basenumlump != flat->lumpnum
for (k = 0; k < levelflat->numpics; k++) for (k = 0; k < levelflat->numpics; k++)
{ {
lumpnum_t lump = levelflat->baselumpnum + k; load_flat(levelflat->baselumpnum + k, R_NoEncore(sec, ceiling));
if (flatcheck_is_end(flatcheck_get(&flatpresent, lump)))
{
HWR_GetFlat(lump, R_NoEncore(sec, ceiling));
flatcheck_insert(&flatpresent, lump);
}
} }
} }
} }
@@ -674,29 +671,18 @@ static void HWR_PrecacheLevelFlats(void)
{ {
const levelflat_t *levelflat = &levelflats[i]; const levelflat_t *levelflat = &levelflats[i];
if (flatcheck_is_end(flatcheck_get(&flatpresent, levelflat->lumpnum))) load_flat(levelflat->lumpnum, false);
{
HWR_GetFlat(levelflat->lumpnum, false);
flatcheck_insert(&flatpresent, levelflat->lumpnum);
}
if (levelflat->speed) // is it an animated flat ? if (levelflat->speed) // is it an animated flat ?
{ {
// start from 0, occasionally basenumlump != flat->lumpnum // start from 0, occasionally basenumlump != flat->lumpnum
for (k = 0; k < levelflat->numpics; k++) for (k = 0; k < levelflat->numpics; k++)
{ {
lumpnum_t lump = levelflat->baselumpnum + k; load_flat(levelflat->baselumpnum + k, false);
if (flatcheck_is_end(flatcheck_get(&flatpresent, lump)))
{
HWR_GetFlat(lump, false);
flatcheck_insert(&flatpresent, lump);
}
} }
} }
} }
} }
flatcheck_cleanup(&flatpresent);
} }
static void HWR_PrecacheLevelTextures(void) static void HWR_PrecacheLevelTextures(void)
@@ -706,7 +692,7 @@ static void HWR_PrecacheLevelTextures(void)
size_t i, j, f; size_t i, j, f;
INT32 h; INT32 h;
texturepresent = (char *)(calloc(gl_numtextures, sizeof(*texturepresent))); texturepresent = static_cast<char *>(calloc(gl_numtextures, sizeof(*texturepresent)));
if (texturepresent == NULL) if (texturepresent == NULL)
I_Error("%s: Out of memory looking up textures", "HWR_PrecacheLevel"); I_Error("%s: Out of memory looking up textures", "HWR_PrecacheLevel");
@@ -881,7 +867,7 @@ void HWR_LoadMapTextures(size_t pnumtextures)
HWR_FreeMapTextures(); HWR_FreeMapTextures();
gl_numtextures = pnumtextures; gl_numtextures = pnumtextures;
gl_textures = (GLMapTextureSet_t *)(calloc(gl_numtextures, sizeof(*gl_textures))); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t gl_textures = static_cast<GLMapTextureSet_t *>(calloc(gl_numtextures, sizeof(*gl_textures))); // *2 - 1 for encore-remapped texture and another for noencore texture (unused when not in encore), see: GLMapTextureSet_t
if (gl_textures == NULL) if (gl_textures == NULL)
I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!"); I_Error("HWR_LoadMapTextures: ran out of memory for OpenGL textures. Sad!");
@@ -978,7 +964,7 @@ static void HWR_CacheFlat(GLMipmap_t *glMipmap, lumpnum_t flatlumpnum)
W_ReadLump(flatlumpnum, Z_Malloc(size, PU_HWRCACHE, &glMipmap->data)); W_ReadLump(flatlumpnum, Z_Malloc(size, PU_HWRCACHE, &glMipmap->data));
#ifdef GLENCORE #ifdef GLENCORE
flat = (UINT8 *)(glMipmap->data); flat = static_cast<UINT8 *>(glMipmap->data);
for (steppy = 0; steppy < size; steppy++) for (steppy = 0; steppy < size; steppy++)
{ {
if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX) if (flat[steppy] == HWR_PATCHES_CHROMAKEY_COLORINDEX)
@@ -1022,7 +1008,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
if (!noencoremap && encoremap) if (!noencoremap && encoremap)
colormap += COLORMAP_REMAPOFFSET; colormap += COLORMAP_REMAPOFFSET;
#endif #endif
glMipmap->colormap = (GLColormap_t *)(Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); glMipmap->colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*glMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL));
glMipmap->colormap->source = colormap; glMipmap->colormap->source = colormap;
memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); memcpy(glMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
} }
@@ -1046,7 +1032,7 @@ void HWR_GetFlat(lumpnum_t flatlumpnum, boolean noencoremap)
// --------------------+ // --------------------+
static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap)
{ {
GLPatch_t *glPatch = (GLPatch_t *)(patch->hardware); GLPatch_t *glPatch = static_cast<GLPatch_t *>(patch->hardware);
if (!glMipmap->downloaded) if (!glMipmap->downloaded)
{ {
@@ -1067,7 +1053,7 @@ static void HWR_LoadPatchMipmap(patch_t *patch, GLMipmap_t *glMipmap)
// ----------------------+ // ----------------------+
static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap) static void HWR_UpdatePatchMipmap(patch_t *patch, GLMipmap_t *glMipmap)
{ {
GLPatch_t *glPatch = (GLPatch_t *)(patch->hardware); GLPatch_t *glPatch = static_cast<GLPatch_t *>(patch->hardware);
HWR_MakePatch(patch, glPatch, glMipmap, true); HWR_MakePatch(patch, glPatch, glMipmap, true);
// If hardware does not have the texture, then call GL_SetTexture to upload it // If hardware does not have the texture, then call GL_SetTexture to upload it
@@ -1103,7 +1089,7 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
if (!patch->hardware) if (!patch->hardware)
Patch_CreateGL(patch); Patch_CreateGL(patch);
glPatch = (GLPatch_t *)(patch->hardware); glPatch = static_cast<GLPatch_t *>(patch->hardware);
// Blatant hack for encore colormapping aside... // Blatant hack for encore colormapping aside...
if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET)) if (colormap == colormaps || colormap == NULL || colormap == (const UINT8*)(COLORMAP_REMAPOFFSET))
@@ -1139,12 +1125,12 @@ void HWR_GetMappedPatch(patch_t *patch, const UINT8 *colormap)
// (it have a liste of mipmap) // (it have a liste of mipmap)
// this malloc is cleared in HWR_FreeColormapCache // this malloc is cleared in HWR_FreeColormapCache
// (...) unfortunately z_malloc fragment alot the memory :(so malloc is better // (...) unfortunately z_malloc fragment alot the memory :(so malloc is better
newMipmap = (GLMipmap_t *)(calloc(1, sizeof (*newMipmap))); newMipmap = static_cast<GLMipmap_t *>(calloc(1, sizeof (*newMipmap)));
if (newMipmap == NULL) if (newMipmap == NULL)
I_Error("%s: Out of memory", "HWR_GetMappedPatch"); I_Error("%s: Out of memory", "HWR_GetMappedPatch");
glMipmap->nextcolormap = newMipmap; glMipmap->nextcolormap = newMipmap;
newMipmap->colormap = (GLColormap_t *)(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL)); newMipmap->colormap = static_cast<GLColormap_t *>(Z_Calloc(sizeof(*newMipmap->colormap), PU_HWRPATCHCOLMIPMAP, NULL));
newMipmap->colormap->source = colormap; newMipmap->colormap->source = colormap;
memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8)); memcpy(newMipmap->colormap->data, colormap, 256 * sizeof(UINT8));
@@ -1167,7 +1153,7 @@ patch_t *HWR_GetCachedGLPatchPwad(UINT16 wadnum, UINT16 lumpnum)
{ {
void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]); void *ptr = Z_Calloc(sizeof(patch_t), PU_PATCH, &lumpcache[lumpnum]);
Patch_Create(NULL, 0, ptr); Patch_Create(NULL, 0, ptr);
Patch_AllocateHardwarePatch((patch_t *)(ptr)); Patch_AllocateHardwarePatch(static_cast<patch_t *>(ptr));
} }
return (patch_t *)(lumpcache[lumpnum]); return (patch_t *)(lumpcache[lumpnum]);
@@ -1184,7 +1170,7 @@ static void HWR_DrawFadeMaskInCache(GLMipmap_t *mipmap, INT32 pblockwidth, INT32
{ {
INT32 i,j; INT32 i,j;
fixed_t posx, posy, stepx, stepy; fixed_t posx, posy, stepx, stepy;
UINT8 *block = (UINT8 *)(mipmap->data); // places the data directly into here UINT8 *block = static_cast<UINT8 *>(mipmap->data); // places the data directly into here
UINT8 *flat; UINT8 *flat;
UINT8 *dest, *src, texel; UINT8 *dest, *src, texel;
RGBA_t col; RGBA_t col;
@@ -1340,7 +1326,7 @@ void HWR_SetPalette(RGBA_t *palette)
static void HWR_SetPaletteLookup(RGBA_t *palette) static void HWR_SetPaletteLookup(RGBA_t *palette)
{ {
int r, g, b; int r, g, b;
UINT8 *lut = (UINT8 *)(Z_Malloc( UINT8 *lut = static_cast<UINT8 *>(Z_Malloc(
HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8), HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*HWR_PALETTE_LUT_SIZE*sizeof(UINT8),
PU_STATIC, NULL)); PU_STATIC, NULL));
#define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE) #define STEP_SIZE (256/HWR_PALETTE_LUT_SIZE)
@@ -1385,7 +1371,7 @@ void HWR_SetMapPalette(void)
if (palsize < 768) // 256 * 3 if (palsize < 768) // 256 * 3
I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n"); I_Error("HWR_SetMapPalette: A programmer assumed palette lumps are at least 768 bytes long, but apparently this was a wrong assumption!\n");
RGB_data = (UINT8 *)(W_CacheLumpNum(lumpnum, PU_CACHE)); RGB_data = static_cast<UINT8 *>(W_CacheLumpNum(lumpnum, PU_CACHE));
// we got the RGB palette now, but we need it in RGBA format. // we got the RGB palette now, but we need it in RGBA format.
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
@@ -1420,7 +1406,7 @@ static UINT32 HWR_CreateLightTable(UINT8 *lighttable)
{ {
UINT32 i, id; UINT32 i, id;
RGBA_t *palette = HWR_GetTexturePalette(); RGBA_t *palette = HWR_GetTexturePalette();
RGBA_t *hw_lighttable = (RGBA_t *)(Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL)); RGBA_t *hw_lighttable = static_cast<RGBA_t *>(Z_Malloc(256 * 32 * sizeof(RGBA_t), PU_STATIC, NULL));
// To make the palette index -> RGBA mapping easier for the shader, // To make the palette index -> RGBA mapping easier for the shader,
// the hardware lighttable is composed of RGBA colors instead of palette indices. // the hardware lighttable is composed of RGBA colors instead of palette indices.
+1 -1
View File
@@ -54,7 +54,7 @@ struct GLMipmap_s
UINT16 width, height; UINT16 width, height;
UINT32 downloaded; // The GPU has this texture. UINT32 downloaded; // The GPU has this texture.
struct GLMipmap_s *nextcolormap; struct GLMipmap_s *nextcolormap;
struct GLColormap_s *colormap; struct GLColormap_s *colormap;
}; };
typedef struct GLMipmap_s GLMipmap_t; typedef struct GLMipmap_s GLMipmap_t;
+2 -1
View File
@@ -1378,7 +1378,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom
FSurfaceInfo Surf; FSurfaceInfo Surf;
Surf.PolyColor.s.alpha = 255; if (gl_frontsector)
Surf.PolyColor.s.alpha = 255;
const INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); const INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture);
GLMapTexture_t *glTex = NULL; GLMapTexture_t *glTex = NULL;
+16 -9
View File
@@ -693,15 +693,17 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi
GLPatch_t *hwrBlendPatch = blendgpatch->hardware; GLPatch_t *hwrBlendPatch = blendgpatch->hardware;
UINT16 w = gpatch->width, h = gpatch->height; UINT16 w = gpatch->width, h = gpatch->height;
UINT32 size = w*h; UINT32 size = w*h;
RGBA_t *image, *blendimage, *cur; RGBA_t *image, *blendimage, *cur, blendcolor;
RGBA_t blendcolor = {};
RGBA_t *palette = HWR_GetTexturePalette(); RGBA_t *palette = HWR_GetTexturePalette();
UINT8 translation[17] = {}; // First the color index UINT8 translation[17]; // First the color index
UINT8 cutoff[17] = {}; // Brightness cutoff before using the next color UINT8 cutoff[17]; // Brightness cutoff before using the next color
UINT8 translen = 0; UINT8 translen = 0;
UINT8 i; UINT8 i;
UINT8 colorbrightnesses[17] = {}; UINT8 colorbrightnesses[17];
UINT8 color_match_lookup[256] = {}; // optimization attempt UINT8 color_match_lookup[256]; // optimization attempt
memset(translation, 0, sizeof(translation));
memset(cutoff, 0, sizeof(cutoff));
if (glMipmap->width == 0) if (glMipmap->width == 0)
{ {
@@ -714,10 +716,14 @@ static void HWR_CreateBlendedTexture(patch_t *gpatch, patch_t *blendgpatch, GLMi
glMipmap->format = GL_TEXFMT_RGBA; glMipmap->format = GL_TEXFMT_RGBA;
} }
Z_Free(glMipmap->data); if (glMipmap->data)
glMipmap->data = NULL; {
Z_Free(glMipmap->data);
glMipmap->data = NULL;
}
cur = Z_Calloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data); cur = Z_Malloc(size*4, PU_HWRMODELTEXTURE, &glMipmap->data);
memset(cur, 0x00, size*4);
image = hwrPatch->mipmap->data; image = hwrPatch->mipmap->data;
blendimage = hwrBlendPatch->mipmap->data; blendimage = hwrBlendPatch->mipmap->data;
@@ -1031,6 +1037,7 @@ static void HWR_GetBlendedTexture(patch_t *patch, patch_t *blendgpatch, INT32 sk
GLPatch_t *glPatch = patch->hardware; GLPatch_t *glPatch = patch->hardware;
GLMipmap_t *glMipmap, *newMipmap; GLMipmap_t *glMipmap, *newMipmap;
if (blendgpatch == NULL || colormap == colormaps || colormap == NULL) if (blendgpatch == NULL || colormap == colormaps || colormap == NULL)
{ {
// Don't do any blending // Don't do any blending
+1 -1
View File
@@ -109,7 +109,7 @@ boolean HWR_InitShaders(void)
// returns INT32_MAX if not found // returns INT32_MAX if not found
static INT32 strstr_int(const char *str1, const char *str2) static INT32 strstr_int(const char *str1, const char *str2)
{ {
gconst char *location = strstr(str1, str2); char *location = strstr(str1, str2);
if (location) if (location)
return location - str1; return location - str1;
else else
+3 -3
View File
@@ -1383,19 +1383,19 @@ void GL_Flush(void)
// -----------------+ // -----------------+
INT32 GL_isExtAvailable(const char *extension, const GLubyte *start) INT32 GL_isExtAvailable(const char *extension, const GLubyte *start)
{ {
gconst GLubyte *where, *terminator; GLubyte *where, *terminator;
if (!extension || !start) if (!extension || !start)
return 0; return 0;
where = (gconst GLubyte *)strchr(extension, ' '); where = (GLubyte *) strchr(extension, ' ');
if (where || *extension == '\0') if (where || *extension == '\0')
return 0; return 0;
for (;;) for (;;)
{ {
where = (gconst GLubyte *)strstr((const char *)start, extension); where = (GLubyte *) strstr((const char *) start, extension);
if (!where) if (!where)
break; break;
+10 -12
View File
@@ -62,7 +62,7 @@ static int hms_started;
static char *hms_api; static char *hms_api;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
static I_mutex hms_api_mutex; static I_Mutex hms_api_mutex;
#endif #endif
static char *hms_server_token; static char *hms_server_token;
@@ -90,9 +90,9 @@ Printf_url (const char *url)
boolean startup; boolean startup;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&con_mutex); I_LockMutex(&con_mutex);
startup = con_startup; startup = con_startup;
I_unlock_mutex(con_mutex); I_UnlockMutex(con_mutex);
#else #else
startup = con_startup; startup = con_startup;
#endif #endif
@@ -183,7 +183,7 @@ HMS_connect (const char *format, ...)
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&hms_api_mutex); I_LockMutex(&hms_api_mutex);
#endif #endif
seek = strlen(hms_api) + 1;/* + '/' */ seek = strlen(hms_api) + 1;/* + '/' */
@@ -195,7 +195,7 @@ HMS_connect (const char *format, ...)
sprintf(url, "%s/", hms_api); sprintf(url, "%s/", hms_api);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(hms_api_mutex); I_UnlockMutex(hms_api_mutex);
#endif #endif
va_start (ap, format); va_start (ap, format);
@@ -225,10 +225,9 @@ HMS_connect (const char *format, ...)
{ {
cc = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); cc = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf); if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf);
#ifdef LOGMESSAGES
cc = curl_easy_setopt(curl, CURLOPT_STDERR, logstream); cc = curl_easy_setopt(curl, CURLOPT_STDERR, logstream);
if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf); if (cc != CURLE_OK) I_OutputMsg("libcurl: %s\n", buffer->errbuf);
#endif
} }
if (M_CheckParm("-bindaddr") && M_IsNextParm()) if (M_CheckParm("-bindaddr") && M_IsNextParm())
@@ -318,7 +317,6 @@ static void
HMS_end (struct HMS_buffer *buffer) HMS_end (struct HMS_buffer *buffer)
{ {
curl_easy_cleanup(buffer->curl); curl_easy_cleanup(buffer->curl);
free(buffer->errbuf);
free(buffer->buffer); free(buffer->buffer);
free(buffer); free(buffer);
} }
@@ -479,12 +477,12 @@ HMS_fetch_servers (msg_server_t *list, int query_id)
if (address && port) if (address && port)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&ms_QueryId_mutex); I_LockMutex(&ms_QueryId_mutex);
{ {
if (query_id != ms_QueryId) if (query_id != ms_QueryId)
doing_shit = 0; doing_shit = 0;
} }
I_unlock_mutex(ms_QueryId_mutex); I_UnlockMutex(ms_QueryId_mutex);
if (! doing_shit) if (! doing_shit)
break; break;
@@ -613,14 +611,14 @@ void
HMS_set_api (char *api) HMS_set_api (char *api)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&hms_api_mutex); I_LockMutex(&hms_api_mutex);
#endif #endif
{ {
free(hms_api); free(hms_api);
hms_api = Strip_trailing_slashes(api); hms_api = Strip_trailing_slashes(api);
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(hms_api_mutex); I_UnlockMutex(hms_api_mutex);
#endif #endif
} }
-3
View File
@@ -497,9 +497,7 @@ static void HU_removeChatText_Log(void)
{ {
chat_log[i] = chat_log[i+1]; chat_log[i] = chat_log[i+1];
} }
chat_nummsg_log--; // lost 1 msg. chat_nummsg_log--; // lost 1 msg.
chat_log[chat_nummsg_log] = NULL;
} }
static void Chatlogsize_OnChange(void) static void Chatlogsize_OnChange(void)
@@ -518,7 +516,6 @@ static void Chatlogsize_OnChange(void)
if (new_chat_log == NULL) if (new_chat_log == NULL)
{ {
free(chat_log); free(chat_log);
chat_log = NULL;
return; return;
} }
chat_log = new_chat_log; chat_log = new_chat_log;
+1 -5
View File
@@ -43,7 +43,7 @@ extern UINT8 graphics_started;
extern UINT8 keyboard_started; extern UINT8 keyboard_started;
/** \brief Set to true when inside a signal handler that will exit the program. */ /** \brief Set to true when inside a signal handler that will exit the program. */
boolean I_In_Exiting_Signal_Handler(void); extern boolean g_in_exiting_signal_handler;
/** \brief The I_GetFreeMem function /** \brief The I_GetFreeMem function
@@ -195,10 +195,6 @@ INT32 I_StartupSystem(void);
*/ */
void I_ShutdownSystem(void); void I_ShutdownSystem(void);
/** \brief To check if a Interrupt or Terminate Signal was fired
*/
boolean I_Interrupted(void);
/** \brief The I_GetDiskFreeSpace function /** \brief The I_GetDiskFreeSpace function
\param freespace a INT64 pointer to hold the free space amount \param freespace a INT64 pointer to hold the free space amount
+87 -59
View File
@@ -1,4 +1,4 @@
// SONIC ROBO BLAST 2 // SONIC ROBO BLAST 2 KART
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2020-2023 by James R. // Copyright (C) 2020-2023 by James R.
// //
@@ -9,12 +9,14 @@
/// \file i_threads.c /// \file i_threads.c
/// \brief Multithreading abstraction /// \brief Multithreading abstraction
#if defined (__unix__) || (!defined(__APPLE__) && defined (UNIXCOMMON)) #ifdef HAVE_THREADS
#if defined (__unix__) || defined(UNIXCOMMON)
#include <pthread.h> #include <pthread.h>
#include "../i_threads.h" #include "i_threads.h"
#include "../doomdef.h" #include "doomdef.h"
#include "doomtype.h"
typedef struct thread_s thread_t; typedef struct thread_s thread_t;
@@ -22,7 +24,7 @@ struct thread_s
{ {
thread_t *next; thread_t *next;
void *userdata; void *userdata;
I_thread_fn func; I_ThreadFn func;
pthread_t thread; pthread_t thread;
}; };
@@ -41,12 +43,8 @@ static void *HandleThread(void *data)
return NULL; return NULL;
} }
void FUNCWARNRV
I_spawn_thread ( int I_SpawnThread(const char *name, I_ThreadFn entry, void *userdata)
const char * name,
I_thread_fn entry,
void * userdata
)
{ {
thread_t *thread; thread_t *thread;
(void)name; (void)name;
@@ -66,17 +64,20 @@ I_spawn_thread (
if (thread == NULL) if (thread == NULL)
{ {
thread = malloc(sizeof(thread_t)); thread = malloc(sizeof(thread_t));
if (thread == NULL)
return false;
thread->next = thread_list; thread->next = thread_list;
thread_list = thread; thread_list = thread;
} }
thread->func = entry; thread->func = entry;
thread->userdata = userdata; thread->userdata = userdata;
pthread_create(&thread->thread, NULL, HandleThread, thread); int err = pthread_create(&thread->thread, NULL, HandleThread, thread);
pthread_mutex_unlock(&thread_lock); pthread_mutex_unlock(&thread_lock);
return err == 0;
} }
int I_thread_is_stopped(void) int I_ThreadIsStopped(void)
{ {
thread_t *thread; thread_t *thread;
pthread_mutex_lock(&thread_lock); pthread_mutex_lock(&thread_lock);
@@ -94,11 +95,11 @@ int I_thread_is_stopped(void)
return true; return true;
} }
void I_start_threads(void) void I_StartThreads(void)
{ {
} }
void I_stop_threads(void) void I_StopThreads(void)
{ {
thread_t *thread = thread_list; thread_t *thread = thread_list;
while (thread != NULL) while (thread != NULL)
@@ -109,7 +110,7 @@ void I_stop_threads(void)
} }
} }
void I_lock_mutex(I_mutex *anchor) void I_LockMutex(I_Mutex *anchor)
{ {
pthread_mutex_lock(&thread_lock); pthread_mutex_lock(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -127,25 +128,25 @@ void I_lock_mutex(I_mutex *anchor)
pthread_mutex_lock(*anchor); pthread_mutex_lock(*anchor);
} }
void I_unlock_mutex(I_mutex id) void I_UnlockMutex(I_Mutex id)
{ {
pthread_mutex_unlock(id); pthread_mutex_unlock(id);
} }
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) void I_HoldCond(I_Cond *condAnchor, I_Mutex mutexId)
{ {
I_Assert(mutex_id != NULL); I_Assert(mutexId != NULL);
pthread_mutex_lock(&thread_lock); pthread_mutex_lock(&thread_lock);
if (*cond_anchor == NULL) if (*condAnchor == NULL)
{ {
*cond_anchor = malloc(sizeof(pthread_cond_t)); *condAnchor = malloc(sizeof(pthread_cond_t));
pthread_cond_init(*cond_anchor, NULL); pthread_cond_init(*condAnchor, NULL);
} }
pthread_mutex_unlock(&thread_lock); pthread_mutex_unlock(&thread_lock);
pthread_cond_wait(*cond_anchor, mutex_id); pthread_cond_wait(*condAnchor, mutexId);
} }
void I_wake_one_cond(I_cond *anchor) void I_WakeOneCond(I_Cond *anchor)
{ {
pthread_mutex_lock(&thread_lock); pthread_mutex_lock(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -157,7 +158,7 @@ void I_wake_one_cond(I_cond *anchor)
pthread_cond_signal(*anchor); pthread_cond_signal(*anchor);
} }
void I_wake_all_cond(I_cond *anchor) void I_WakeAllCond(I_Cond *anchor)
{ {
pthread_mutex_lock(&thread_lock); pthread_mutex_lock(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -168,12 +169,17 @@ void I_wake_all_cond(I_cond *anchor)
pthread_mutex_unlock(&thread_lock); pthread_mutex_unlock(&thread_lock);
pthread_cond_broadcast(*anchor); pthread_cond_broadcast(*anchor);
} }
thread_handle_t I_GetCurrentThread(void)
{
return pthread_self();
}
#elif defined (_WIN32) #elif defined (_WIN32)
#include <windows.h> #include <windows.h>
#include "../i_threads.h" #include "i_threads.h"
#include "../doomdef.h" #include "doomdef.h"
#include "../doomtype.h" #include "doomtype.h"
typedef struct thread_s thread_t; typedef struct thread_s thread_t;
@@ -181,9 +187,9 @@ struct thread_s
{ {
thread_t *next; thread_t *next;
void *userdata; void *userdata;
I_thread_fn func; I_ThreadFn func;
HANDLE thread; HANDLE thread;
DWORD thread_id; DWORD threadId;
}; };
// we use a linked list to avoid moving memory blocks when allocating new threads. // we use a linked list to avoid moving memory blocks when allocating new threads.
@@ -201,7 +207,8 @@ static DWORD __stdcall HandleThread(void *data)
return 0; return 0;
} }
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata) FUNCWARNRV
int I_SpawnThread(const char *name, I_ThreadFn entry, void *userdata)
{ {
thread_t *thread; thread_t *thread;
(void)name; (void)name;
@@ -219,17 +226,20 @@ void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata)
if (thread == NULL) if (thread == NULL)
{ {
thread = malloc(sizeof(thread_t)); thread = malloc(sizeof(thread_t));
if (thread == NULL)
return false;
thread->next = thread_list; thread->next = thread_list;
thread_list = thread; thread_list = thread;
} }
thread->func = entry; thread->func = entry;
thread->userdata = userdata; thread->userdata = userdata;
thread->thread = CreateThread(NULL, 0, HandleThread, thread, 0, &thread->thread_id); thread->thread = CreateThread(NULL, 0, HandleThread, thread, 0, &thread->threadId);
LeaveCriticalSection(&thread_lock); LeaveCriticalSection(&thread_lock);
return thread->thread != NULL;
} }
int I_thread_is_stopped(void) int I_ThreadIsStopped(void)
{ {
thread_t *thread; thread_t *thread;
EnterCriticalSection(&thread_lock); EnterCriticalSection(&thread_lock);
@@ -247,12 +257,12 @@ int I_thread_is_stopped(void)
return true; return true;
} }
void I_start_threads(void) void I_StartThreads(void)
{ {
InitializeCriticalSection(&thread_lock); InitializeCriticalSection(&thread_lock);
} }
void I_stop_threads(void) void I_StopThreads(void)
{ {
thread_t *thread = thread_list; thread_t *thread = thread_list;
while (thread != NULL) while (thread != NULL)
@@ -264,7 +274,7 @@ void I_stop_threads(void)
DeleteCriticalSection(&thread_lock); DeleteCriticalSection(&thread_lock);
} }
void I_lock_mutex(I_mutex *anchor) void I_LockMutex(I_Mutex *anchor)
{ {
EnterCriticalSection(&thread_lock); EnterCriticalSection(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -276,25 +286,25 @@ void I_lock_mutex(I_mutex *anchor)
EnterCriticalSection(*anchor); EnterCriticalSection(*anchor);
} }
void I_unlock_mutex(I_mutex id) void I_UnlockMutex(I_Mutex id)
{ {
LeaveCriticalSection(id); LeaveCriticalSection(id);
} }
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) void I_HoldCond(I_Cond *condAnchor, I_Mutex mutexId)
{ {
I_Assert(mutex_id != NULL); I_Assert(mutexId != NULL);
EnterCriticalSection(&thread_lock); EnterCriticalSection(&thread_lock);
if (*cond_anchor == NULL) if (*condAnchor == NULL)
{ {
*cond_anchor = malloc(sizeof(CONDITION_VARIABLE)); *condAnchor = malloc(sizeof(CONDITION_VARIABLE));
InitializeConditionVariable(*cond_anchor); InitializeConditionVariable(*condAnchor);
} }
LeaveCriticalSection(&thread_lock); LeaveCriticalSection(&thread_lock);
SleepConditionVariableCS(*cond_anchor, mutex_id, INFINITE); SleepConditionVariableCS(*condAnchor, mutexId, INFINITE);
} }
void I_wake_one_cond(I_cond *anchor) void I_WakeOneCond(I_Cond *anchor)
{ {
EnterCriticalSection(&thread_lock); EnterCriticalSection(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -306,7 +316,7 @@ void I_wake_one_cond(I_cond *anchor)
WakeConditionVariable(*anchor); WakeConditionVariable(*anchor);
} }
void I_wake_all_cond(I_cond *anchor) void I_WakeAllCond(I_Cond *anchor)
{ {
EnterCriticalSection(&thread_lock); EnterCriticalSection(&thread_lock);
if (*anchor == NULL) if (*anchor == NULL)
@@ -317,48 +327,66 @@ void I_wake_all_cond(I_cond *anchor)
LeaveCriticalSection(&thread_lock); LeaveCriticalSection(&thread_lock);
WakeAllConditionVariable(*anchor); WakeAllConditionVariable(*anchor);
} }
void *I_GetCurrentThread(void)
{
return GetCurrentThread();
}
#else #else
void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata) #include "i_threads.h"
FUNCWARNRV
int I_SpawnThread(const char *name, I_ThreadFn entry, void *userdata)
{ {
(void)name; (void)name;
entry(userdata); entry(userdata);
return true;
} }
int I_thread_is_stopped(void) int I_ThreadIsStopped(void)
{
return true;
}
void I_StartThreads(void)
{ {
} }
void I_start_threads(void) void I_StopThreads(void)
{ {
} }
void I_stop_threads(void) void I_LockMutex(I_Mutex *anchor)
{
}
void I_lock_mutex(I_mutex *anchor)
{ {
(void)anchor; (void)anchor;
} }
void I_unlock_mutex(I_mutex id) void I_UnlockMutex(I_Mutex id)
{ {
(void)id; (void)id;
} }
void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) void I_HoldCond(I_Cond *condAnchor, I_Mutex mutexId)
{ {
(void)cond_anchor; (void)condAnchor;
(void)mutex_id; (void)mutexId;
} }
void I_wake_one_cond(I_cond *anchor) void I_WakeOneCond(I_Cond *anchor)
{ {
(void)anchor; (void)anchor;
} }
void I_wake_all_cond(I_cond *anchor) void I_WakeAllCond(I_Cond *anchor)
{ {
(void)anchor; (void)anchor;
} }
void *I_GetCurrentThread(void)
{
return NULL;
}
#endif #endif
#endif // HAVE_THREADS
+25 -13
View File
@@ -1,6 +1,6 @@
// SONIC ROBO BLAST 2 KART // SONIC ROBO BLAST 2 KART
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Copyright (C) 2020 by James R. // Copyright (C) 2020-2023 by James R.
// //
// This program is free software distributed under the // This program is free software distributed under the
// terms of the GNU General Public License, version 2. // terms of the GNU General Public License, version 2.
@@ -14,34 +14,46 @@
#ifndef I_THREADS_H #ifndef I_THREADS_H
#define I_THREADS_H #define I_THREADS_H
#include "doomtype.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
typedef void (*I_thread_fn)(void *userdata); typedef void (*I_ThreadFn)(void *userdata);
typedef void * I_mutex; typedef void * I_Mutex;
typedef void * I_cond; typedef void * I_Cond;
void I_start_threads (void); #ifdef __linux__
void I_stop_threads (void); typedef long unsigned int thread_handle_t;
#else
typedef void *thread_handle_t;
#endif
void I_spawn_thread (const char *name, I_thread_fn, void *userdata); void I_StartThreads (void);
void I_StopThreads (void);
FUNCWARNRV
int I_SpawnThread (const char *name, I_ThreadFn, void *userdata);
/* check in your thread whether to return early */ /* check in your thread whether to return early */
int I_thread_is_stopped (void); int I_ThreadIsStopped (void);
void I_lock_mutex (I_mutex *); void I_LockMutex (I_Mutex *);
void I_unlock_mutex (I_mutex); void I_UnlockMutex (I_Mutex);
void I_hold_cond (I_cond *, I_mutex); void I_HoldCond (I_Cond *, I_Mutex);
void I_wake_one_cond (I_cond *); void I_WakeOneCond (I_Cond *);
void I_wake_all_cond (I_cond *); void I_WakeAllCond (I_Cond *);
thread_handle_t I_GetCurrentThread(void);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
#endif/*I_THREADS_H*/ #endif/*I_THREADS_H*/
#endif/*HAVE_THREADS*/ #endif/*HAVE_THREADS*/
+20 -35
View File
@@ -931,21 +931,21 @@ const char *K_GetItemPatch(UINT8 item, boolean tiny)
//} //}
static INT32 ITEM_X, ITEM_Y; // Item Window INT32 ITEM_X, ITEM_Y; // Item Window
static INT32 TIME_X, TIME_Y; // Time Sticker INT32 TIME_X, TIME_Y; // Time Sticker
static INT32 LAPS_X, LAPS_Y; // Lap Sticker INT32 LAPS_X, LAPS_Y; // Lap Sticker
static INT32 SPDM_X, SPDM_Y; // Speedometer INT32 SPDM_X, SPDM_Y; // Speedometer
static INT32 POSI_X, POSI_Y; // Position Number INT32 POSI_X, POSI_Y; // Position Number
static INT32 FACE_X, FACE_Y; // Top-four Faces INT32 FACE_X, FACE_Y; // Top-four Faces
static INT32 STCD_X, STCD_Y; // Starting countdown INT32 STCD_X, STCD_Y; // Starting countdown
static INT32 CHEK_Y; // CHECK graphic INT32 CHEK_Y; // CHECK graphic
static INT32 MINI_X, MINI_Y; // Minimap INT32 MINI_X, MINI_Y; // Minimap
static INT32 WANT_X, WANT_Y; // Battle WANTED poster INT32 WANT_X, WANT_Y; // Battle WANTED poster
// This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN. // This is for the P2 and P4 side of splitscreen. Then we'll flip P1's and P2's to the bottom with V_SPLITSCREEN.
static INT32 ITEM2_X, ITEM2_Y; INT32 ITEM2_X, ITEM2_Y;
static INT32 LAPS2_X, LAPS2_Y; INT32 LAPS2_X, LAPS2_Y;
static INT32 POSI2_X, POSI2_Y; INT32 POSI2_X, POSI2_Y;
static void K_initKartHUD(void) static void K_initKartHUD(void)
{ {
@@ -1415,6 +1415,8 @@ static void K_drawKartStats(void)
break; break;
} }
} }
else
spdoffset = 0;
if (G_BattleGametype() && ((speedostyle != SPEEDO_DIAL) || splitscreen)) if (G_BattleGametype() && ((speedostyle != SPEEDO_DIAL) || splitscreen))
spdoffset += ((stplyr->kartstuff[k_bumper] ? -5 : -8)); spdoffset += ((stplyr->kartstuff[k_bumper] ? -5 : -8));
@@ -3816,7 +3818,7 @@ static void K_drawKartMinimap(void)
if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout) if (cv_showminimapangle.value && (minidoticon || minilighticon) && !playertimedout)
{ {
UINT8 *colormap = NULL; UINT8 *colormap;
drawinfo_t dims; drawinfo_t dims;
fixed_t interpx, interpy; fixed_t interpx, interpy;
fixed_t xoff = 0, yoff = 0; fixed_t xoff = 0, yoff = 0;
@@ -3827,27 +3829,10 @@ static void K_drawKartMinimap(void)
if (encoremode) if (encoremode)
ang = ANGLE_180 - ang; ang = ANGLE_180 - ang;
if (mobj->color) if (mobj->colorized)
{ colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE);
if (mobj->colorized) else
{ colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal);
colormap = R_GetTranslationColormap(TC_RAINBOW, mobj->color, GTC_CACHE);
}
else
{
const INT32 skinnum = K_GetMobjLocalSkinNum(mobj->skin, mobj->localskin, mobj->skinlocal);
// special case if startcolor is not the default (160 / Green)
if (skinnum && skins[skinnum].starttranscolor != skins[0].starttranscolor)
{
colormap = R_GetTranslationColormap(TC_DEFAULT, mobj->color, GTC_CACHE);
}
else
{
colormap = R_GetLocalTranslationColormap(mobj->skin, mobj->localskin, mobj->color, GTC_CACHE, mobj->skinlocal);
}
}
}
interpx = lerp(mobj->old_x, mobj->x); interpx = lerp(mobj->old_x, mobj->x);
interpy = lerp(mobj->old_y, mobj->y); interpy = lerp(mobj->old_y, mobj->y);
+2 -10
View File
@@ -660,22 +660,13 @@ INT32 K_GetSkinNum(player_t *player)
// //
// returns the mobj skinnumber // returns the mobj skinnumber
// accounts for localskins ? // accounts for localskins
// //
INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local) INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local)
{ {
return skin - K_GetSkinArray(local); return skin - K_GetSkinArray(local);
} }
//
// returns the mobj skinnumber
// accounts for localskins
//
INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local)
{
return localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins);
}
// //
// returns the players skinnumber // returns the players skinnumber
// accounts for localskins // accounts for localskins
@@ -1489,6 +1480,7 @@ void K_KartBouncing(mobj_t *mobj1, mobj_t *mobj2, boolean bounce, boolean solid)
fixed_t nx = FixedDiv(distx, dist); fixed_t nx = FixedDiv(distx, dist);
fixed_t ny = FixedDiv(disty, dist); fixed_t ny = FixedDiv(disty, dist);
dist = dist ? dist : 1;
distx = FixedMul(mobj1->radius+mobj2->radius, nx); distx = FixedMul(mobj1->radius+mobj2->radius, nx);
disty = FixedMul(mobj1->radius+mobj2->radius, ny); disty = FixedMul(mobj1->radius+mobj2->radius, ny);
+22 -22
View File
@@ -615,7 +615,7 @@ FUNCINLINE static ATTRINLINE void res_hud(Hook_State *hook)
int LUA_HookMobj(mobj_t *mobj, int hook_type) int LUA_HookMobj(mobj_t *mobj, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_mobj_hook(&hook, false, hook_type, mobj)) if (prepare_mobj_hook(&hook, false, hook_type, mobj))
{ {
LUA_PushUserdata(gL, mobj, META_MOBJ); LUA_PushUserdata(gL, mobj, META_MOBJ);
@@ -626,7 +626,7 @@ int LUA_HookMobj(mobj_t *mobj, int hook_type)
int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type) int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_mobj_hook(&hook, 0, hook_type, t1)) if (prepare_mobj_hook(&hook, 0, hook_type, t1))
{ {
LUA_PushUserdata(gL, t1, META_MOBJ); LUA_PushUserdata(gL, t1, META_MOBJ);
@@ -638,14 +638,14 @@ int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type)
void LUA_HookVoid(int type) void LUA_HookVoid(int type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, type)) if (prepare_hook(&hook, 0, type))
call_hooks(&hook, 0, res_none); call_hooks(&hook, 0, res_none);
} }
void LUA_HookInt(INT32 number, int hook_type) void LUA_HookInt(INT32 number, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, hook_type)) if (prepare_hook(&hook, 0, hook_type))
{ {
lua_pushinteger(gL, number); lua_pushinteger(gL, number);
@@ -655,7 +655,7 @@ void LUA_HookInt(INT32 number, int hook_type)
/*void LUA_HookBool(boolean value, int hook_type) /*void LUA_HookBool(boolean value, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, hook_type)) if (prepare_hook(&hook, 0, hook_type))
{ {
//lua_pushboolean(gL, value); //lua_pushboolean(gL, value);
@@ -665,7 +665,7 @@ void LUA_HookInt(INT32 number, int hook_type)
int LUA_HookPlayer(player_t *player, int hook_type) int LUA_HookPlayer(player_t *player, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, false, hook_type)) if (prepare_hook(&hook, false, hook_type))
{ {
LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, player, META_PLAYER);
@@ -676,7 +676,7 @@ int LUA_HookPlayer(player_t *player, int hook_type)
int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type) int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, false, hook_type)) if (prepare_hook(&hook, false, hook_type))
{ {
LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, player, META_PLAYER);
@@ -695,7 +695,7 @@ int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type)
void LUA_HookHUD(int hook_type, huddrawlist_h list) void LUA_HookHUD(int hook_type, huddrawlist_h list)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hud_hook(&hook, hook_type)) if (prepare_hud_hook(&hook, hook_type))
{ {
LUA_SetHudHook(hook_type, list); LUA_SetHudHook(hook_type, list);
@@ -723,7 +723,7 @@ static void hook_think_frame(int type)
int hook_index = 0; int hook_index = 0;
precise_t time_taken = 0; precise_t time_taken = 0;
Hook_State hook = {}; Hook_State hook;
const hook_t * map = &hookIds[type]; const hook_t * map = &hookIds[type];
int k; int k;
@@ -783,7 +783,7 @@ void LUA_HookPostThinkFrame(void)
int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher) int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special)) if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special))
{ {
LUA_PushUserdata(gL, special, META_MOBJ); LUA_PushUserdata(gL, special, META_MOBJ);
@@ -802,7 +802,7 @@ static int damage_hook
int hook_type, int hook_type,
Hook_Callback results_handler Hook_Callback results_handler
){ ){
Hook_State hook = {}; Hook_State hook;
if (prepare_mobj_hook(&hook, 0, hook_type, target)) if (prepare_mobj_hook(&hook, 0, hook_type, target))
{ {
LUA_PushUserdata(gL, target, META_MOBJ); LUA_PushUserdata(gL, target, META_MOBJ);
@@ -890,8 +890,8 @@ int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
{ {
const char *skin = ((skin_t *)tails->skin)->name; const char *skin = ((skin_t *)tails->skin)->name;
Hook_State hook = {}; Hook_State hook;
BotAI_State botai = {}; BotAI_State botai;
if (prepare_string_hook(&hook, false, STRING_HOOK(BotAI), skin)) if (prepare_string_hook(&hook, false, STRING_HOOK(BotAI), skin))
{ {
@@ -911,7 +911,7 @@ int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector) void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_string_hook if (prepare_string_hook
(&hook, 0, STRING_HOOK(LinedefExecute), line->text)) (&hook, 0, STRING_HOOK(LinedefExecute), line->text))
{ {
@@ -924,7 +924,7 @@ void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
int LUA_HookPlayerMsg(int source, int target, int flags, char *msg, int mute) int LUA_HookPlayerMsg(int source, int target, int flags, char *msg, int mute)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, false, HOOK(PlayerMsg))) if (prepare_hook(&hook, false, HOOK(PlayerMsg)))
{ {
LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player
@@ -953,7 +953,7 @@ int LUA_HookPlayerMsg(int source, int target, int flags, char *msg, int mute)
int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source) int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(HurtMsg), inflictor)) if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(HurtMsg), inflictor))
{ {
LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, player, META_PLAYER);
@@ -967,7 +967,7 @@ int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source)
void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save) void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save)
{ {
const hook_t * map = &hookIds[HOOK(NetVars)]; const hook_t * map = &hookIds[HOOK(NetVars)];
Hook_State hook = {}; Hook_State hook;
/* this is a remarkable case where the stack isn't reset */ /* this is a remarkable case where the stack isn't reset */
if (map->numHooks > 0) if (map->numHooks > 0)
{ {
@@ -997,7 +997,7 @@ void LUA_HookNetArchive(lua_CFunction archFunc, savebuffer_t *save)
void LUA_HookPlayerQuit(player_t *plr, int reason) void LUA_HookPlayerQuit(player_t *plr, int reason)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, HOOK(PlayerQuit))) if (prepare_hook(&hook, 0, HOOK(PlayerQuit)))
{ {
LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit
@@ -1060,7 +1060,7 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param)
const int type = HOOK(MusicChange); const int type = HOOK(MusicChange);
const hook_t * map = &hookIds[type]; const hook_t * map = &hookIds[type];
Hook_State hook = {}; Hook_State hook;
int k; int k;
@@ -1096,7 +1096,7 @@ int LUA_HookMusicChange(const char *oldname, struct MusicChange *param)
int LUA_HookMusicCredit(musicdef_t *musicdef) int LUA_HookMusicCredit(musicdef_t *musicdef)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, HOOK(MusicCredit))) if (prepare_hook(&hook, 0, HOOK(MusicCredit)))
{ {
LUA_PushUserdata(gL, musicdef, META_MUSICDEF); LUA_PushUserdata(gL, musicdef, META_MUSICDEF);
@@ -1114,7 +1114,7 @@ static int kartdamage_hook
int hook_type, int hook_type,
Hook_Callback results_handler Hook_Callback results_handler
){ ){
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, hook_type)) if (prepare_hook(&hook, 0, hook_type))
{ {
LUA_PushUserdata(gL, player, META_PLAYER); LUA_PushUserdata(gL, player, META_PLAYER);
@@ -1163,7 +1163,7 @@ boolean LUA_HookPlayerExplode(player_t *player, mobj_t *inflictor, mobj_t *sourc
void LUA_HookSetupVote(INT16 result[], INT16 maxresults, UINT8 gt, UINT8 secondgt) void LUA_HookSetupVote(INT16 result[], INT16 maxresults, UINT8 gt, UINT8 secondgt)
{ {
Hook_State hook = {}; Hook_State hook;
if (prepare_hook(&hook, 0, HOOK(SetupVote))) if (prepare_hook(&hook, 0, HOOK(SetupVote)))
{ {
// { 0, 0, 0, 0, } // { 0, 0, 0, 0, }
-8
View File
@@ -13,10 +13,6 @@
#define LZF_H #define LZF_H
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/*********************************************************************** /***********************************************************************
** **
** lzf -- an extremely fast/free compression/decompression-method ** lzf -- an extremely fast/free compression/decompression-method
@@ -75,9 +71,5 @@ size_t
lzf_decompress (const void *const in_data, size_t in_len, lzf_decompress (const void *const in_data, size_t in_len,
void *out_data, size_t out_len); void *out_data, size_t out_len);
#ifdef __cplusplus
} // extern "C"
#endif
#endif #endif
+1 -1
View File
@@ -556,7 +556,7 @@ static void GIF_framewrite(void)
} }
else if (gif_dynamicdelay ==(UINT8) 1) else if (gif_dynamicdelay ==(UINT8) 1)
{ {
float delayf = ceilf(100.0f/NEWTICRATE); float delayf = ceil(100.0f/NEWTICRATE);
delay = (UINT16)((I_GetPreciseTime() - gif_prevframetime)) / (I_GetPrecisePrecision() / 1000000) /10/1000; delay = (UINT16)((I_GetPreciseTime() - gif_prevframetime)) / (I_GetPrecisePrecision() / 1000000) /10/1000;
+45 -30
View File
@@ -142,7 +142,7 @@ typedef enum
} text_enum; } text_enum;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex m_menu_mutex; I_Mutex m_menu_mutex;
#endif #endif
M_waiting_mode_t m_waiting_mode = M_NOT_WAITING; M_waiting_mode_t m_waiting_mode = M_NOT_WAITING;
@@ -1967,7 +1967,7 @@ void M_Ticker(void)
} }
#if defined (MASTERSERVER) && defined (HAVE_THREADS) #if defined (MASTERSERVER) && defined (HAVE_THREADS)
I_lock_mutex(&ms_ServerList_mutex); I_LockMutex(&ms_ServerList_mutex);
{ {
if (ms_ServerList) if (ms_ServerList)
{ {
@@ -1976,7 +1976,7 @@ void M_Ticker(void)
ms_ServerList = NULL; ms_ServerList = NULL;
} }
} }
I_unlock_mutex(ms_ServerList_mutex); I_UnlockMutex(ms_ServerList_mutex);
#endif #endif
} }
@@ -2936,7 +2936,7 @@ static void M_PrepareLevelSelect(void)
boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt)
{ {
// invalid mapnum // invalid mapnum
if (mapnum < -1 || mapnum >= NUMMAPS) if (mapnum < -1)
return false; return false;
// Random map! // Random map!
@@ -4014,18 +4014,18 @@ size_t demolist_all_size = 0;
boolean replaynamesloaded = false; boolean replaynamesloaded = false;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_mutex replayquerymutex; I_Mutex replayquerymutex;
// I_In_Exiting_Signal_Handler is an evil hack // g_in_exiting_signal_handler is an evil hack
// to avoid infinite SIGABRT recursion in the signal handler // to avoid infinite SIGABRT recursion in the signal handler
// due to poisoned locks or mach-o kernel not supporting locks in signals // due to poisoned locks or mach-o kernel not supporting locks in signals
// or something like that. idk // or something like that. idk
# define Lock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_lock_mutex(&replayquerymutex); } # define Lock_search_state() if (!g_in_exiting_signal_handler) { I_LockMutex(&replayquerymutex); }
# define Unlock_search_state() if (!I_In_Exiting_Signal_Handler()) { I_unlock_mutex(replayquerymutex); } # define Unlock_search_state() if (!g_in_exiting_signal_handler) { I_UnlockMutex(replayquerymutex); }
#else /*HAVE_THREADS*/ #else/*HAVE_THREADS*/
# define Lock_search_state() # define Lock_search_state()
# define Unlock_search_state() # define Unlock_search_state()
#endif /*HAVE_THREADS*/ #endif/*HAVE_THREADS*/
#define MAXREPLAYQUERY 37 #define MAXREPLAYQUERY 37
@@ -4088,7 +4088,10 @@ static void LoadReplayNames(void)
Unlock_search_state(); Unlock_search_state();
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread("replay-names-load", ReplayNamesLoadThread, replaydirpath); if (!I_SpawnThread("replay-names-load", ReplayNamesLoadThread, replaydirpath))
{
free(replaydirpath);
}
#else #else
ReplayNamesLoadThread(replaydirpath); ReplayNamesLoadThread(replaydirpath);
#endif #endif
@@ -5522,6 +5525,7 @@ static void M_DrawChecklist(void)
if (conditionSets[unlockables[i].conditionset - 1].numconditions) if (conditionSets[unlockables[i].conditionset - 1].numconditions)
{ {
c = 0;
lastid = -1; lastid = -1;
for (c = 0; c < conditionSets[unlockables[i].conditionset - 1].numconditions; c++) for (c = 0; c < conditionSets[unlockables[i].conditionset - 1].numconditions; c++)
@@ -5681,6 +5685,9 @@ static void M_DrawMusicTest(void)
{ {
INT32 x, y, i; INT32 x, y, i;
x = 90<<FRACBITS;
y = (BASEVIDHEIGHT-32)<<FRACBITS;
y = (BASEVIDWIDTH-vid.scaledwidth)/2; y = (BASEVIDWIDTH-vid.scaledwidth)/2;
V_DrawFill(y-1, 20, vid.scaledwidth+1, 24, 239); V_DrawFill(y-1, 20, vid.scaledwidth+1, 24, 239);
@@ -6680,11 +6687,11 @@ static void M_EndGame(INT32 choice)
void M_SetWaitingMode(int mode) void M_SetWaitingMode(int mode)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
m_waiting_mode = mode; m_waiting_mode = mode;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
} }
@@ -6693,11 +6700,11 @@ int M_GetWaitingMode(void)
int mode; int mode;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
mode = m_waiting_mode; mode = m_waiting_mode;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
return mode; return mode;
@@ -6709,20 +6716,23 @@ static void Spawn_masterserver_thread(const char *name, void (*thread)(int*))
{ {
int *id = malloc(sizeof *id); int *id = malloc(sizeof *id);
I_lock_mutex(&ms_QueryId_mutex); I_LockMutex(&ms_QueryId_mutex);
*id = ms_QueryId; *id = ms_QueryId;
I_unlock_mutex(ms_QueryId_mutex); I_UnlockMutex(ms_QueryId_mutex);
I_spawn_thread(name, (I_thread_fn)thread, id); if (!I_SpawnThread(name, (I_ThreadFn)thread, id))
{
free(id);
}
} }
static int Same_instance(int id) static int Same_instance(int id)
{ {
int okay; int okay;
I_lock_mutex(&ms_QueryId_mutex); I_LockMutex(&ms_QueryId_mutex);
okay = ( id == ms_QueryId ); okay = ( id == ms_QueryId );
I_unlock_mutex(ms_QueryId_mutex); I_UnlockMutex(ms_QueryId_mutex);
return okay; return okay;
} }
@@ -6751,9 +6761,9 @@ static void Fetch_servers_thread(int *id)
M_SetWaitingMode(M_NOT_WAITING); M_SetWaitingMode(M_NOT_WAITING);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&ms_ServerList_mutex); I_LockMutex(&ms_ServerList_mutex);
ms_ServerList = server_list; ms_ServerList = server_list;
I_unlock_mutex(ms_ServerList_mutex); I_UnlockMutex(ms_ServerList_mutex);
#else #else
CL_QueryServerList(server_list); CL_QueryServerList(server_list);
free(server_list); free(server_list);
@@ -6786,7 +6796,7 @@ static void M_SearchServerList(void)
serverlistsearchedcount = 0; serverlistsearchedcount = 0;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&ms_ServerList_mutex); I_LockMutex(&ms_ServerList_mutex);
#endif #endif
for (UINT32 i = 0; i < serverlistcount; ++i) for (UINT32 i = 0; i < serverlistcount; ++i)
@@ -6797,7 +6807,7 @@ static void M_SearchServerList(void)
} }
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(ms_ServerList_mutex); I_UnlockMutex(ms_ServerList_mutex);
#endif #endif
if (menuinput.length > 0) if (menuinput.length > 0)
@@ -7163,11 +7173,11 @@ static void M_CheckMODVersion(int id)
{ {
sprintf(updatestring, UPDATE_ALERT_STRING, VERSIONSTRING, updatecheck); sprintf(updatestring, UPDATE_ALERT_STRING, VERSIONSTRING, updatecheck);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_StartMessage(updatestring, NULL, MM_NOTHING); M_StartMessage(updatestring, NULL, MM_NOTHING);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
} }
} }
@@ -7213,13 +7223,13 @@ static void M_ConnectMenu(INT32 choice)
itemOn = 0; itemOn = 0;
#if defined (MASTERSERVER) && defined (HAVE_THREADS) #if defined (MASTERSERVER) && defined (HAVE_THREADS)
I_lock_mutex(&ms_QueryId_mutex); I_LockMutex(&ms_QueryId_mutex);
{ {
ms_QueryId++; ms_QueryId++;
} }
I_unlock_mutex(ms_QueryId_mutex); I_UnlockMutex(ms_QueryId_mutex);
I_lock_mutex(&ms_ServerList_mutex); I_LockMutex(&ms_ServerList_mutex);
{ {
if (ms_ServerList) if (ms_ServerList)
{ {
@@ -7227,7 +7237,7 @@ static void M_ConnectMenu(INT32 choice)
ms_ServerList = NULL; ms_ServerList = NULL;
} }
} }
I_unlock_mutex(ms_ServerList_mutex); I_UnlockMutex(ms_ServerList_mutex);
#ifdef UPDATE_ALERT #ifdef UPDATE_ALERT
Spawn_masterserver_thread("check-new-version", Check_new_version_thread); Spawn_masterserver_thread("check-new-version", Check_new_version_thread);
@@ -7996,9 +8006,14 @@ static void M_DrawSetupMultiPlayerMenu(void)
#define GETSELECTEDSPEED (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartspeed : skins[setupm_fakeskin].kartspeed) #define GETSELECTEDSPEED (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartspeed : skins[setupm_fakeskin].kartspeed)
#define GETSELECTEDWEIGHT (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartweight : skins[setupm_fakeskin].kartweight) #define GETSELECTEDWEIGHT (itemOn == 1 && setupm_skinselect < numskins ? skins[skinsorted[setupm_skinselect]].kartweight : skins[setupm_fakeskin].kartweight)
statoffset = 0;
tw = V_StringWidth("Character", 0);//V_StringWidth(GETSELECTEDSKINNAME, 0); tw = V_StringWidth("Character", 0);//V_StringWidth(GETSELECTEDSKINNAME, 0);
st = V_StringWidth(GETSELECTEDSKINNAME, 0); st = V_StringWidth(GETSELECTEDSKINNAME, 0);
INT32 selectedskin = (itemOn == 1 && setupm_skinselect < numskins ? skinsorted[setupm_skinselect] : setupm_fakeskin);
speed = skins[selectedskin].kartspeed;
weight = skins[selectedskin].kartweight;
V_DrawString((mx+(tw/2)) - (st/2), my + 37, V_DrawString((mx+(tw/2)) - (st/2), my + 37,
((MP_PlayerSetupMenu[2].status & IT_TYPE) == IT_SPACE ? V_TRANSLUCENT : 0) | highlightflags | V_ALLOWLOWERCASE, ((MP_PlayerSetupMenu[2].status & IT_TYPE) == IT_SPACE ? V_TRANSLUCENT : 0) | highlightflags | V_ALLOWLOWERCASE,
GETSELECTEDSKINNAME); GETSELECTEDSKINNAME);
+1 -1
View File
@@ -215,7 +215,7 @@ void M_SetupNextMenu(menu_t *menudef);
void M_ClearMenus(boolean callexitmenufunc); void M_ClearMenus(boolean callexitmenufunc);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
extern I_mutex m_menu_mutex; extern I_Mutex m_menu_mutex;
#endif #endif
extern menu_t *currentMenu; extern menu_t *currentMenu;
+20 -13
View File
@@ -986,7 +986,7 @@ static const char* OP_ExpTooltips[] =
"Skips rendering frames if game logic takes too long\npreventing gameplay issues during performance drops.", // idk im shit as describing things "Skips rendering frames if game logic takes too long\npreventing gameplay issues during performance drops.", // idk im shit as describing things
"Different methods of scaling the votescreen backgrounds.", "Different methods of scaling the votescreen backgrounds.",
#ifdef HWRENDER #ifdef HWRENDER
"Disabling Screen Textures may result in a performance boost\nbut will break certain effects.\nScreen textures are required at resolutions lower than your desktop resolution!" "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.",
#ifdef USE_FBO_OGL #ifdef USE_FBO_OGL
"Allows the game to downsample from a higher resolution\nthan your display in OpenGL renderer mode.\nRequires a GPU with atleast OpenGL 2.1 support.", "Allows the game to downsample from a higher resolution\nthan your display in OpenGL renderer mode.\nRequires a GPU with atleast OpenGL 2.1 support.",
#endif #endif
@@ -1644,25 +1644,29 @@ static menuitem_t OP_AccessibilityMenu[] =
{IT_STRING|IT_CVAR, NULL, "Minimum Sector Brightness", &cv_secbright, 45}, {IT_STRING|IT_CVAR, NULL, "Minimum Sector Brightness", &cv_secbright, 45},
{IT_STRING|IT_CVAR, NULL, "Water Surface Ripples", &cv_ripplewater, 50}, #ifdef HWRENDER
{IT_STRING|IT_CVAR, NULL, "Screen Textures", &cv_glscreentextures, 50},
#endif
{IT_STRING|IT_CVAR, NULL, "Fade Players near Camera", &cv_playerfade, 55}, {IT_STRING|IT_CVAR, NULL, "Water Surface Ripples", &cv_ripplewater, 55},
{IT_STRING|IT_CVAR, NULL, "Quake Screenshakes", &cv_screenquake, 60}, {IT_STRING|IT_CVAR, NULL, "Fade Players near Camera", &cv_playerfade, 60},
{IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 65}, {IT_STRING|IT_CVAR, NULL, "Quake Screenshakes", &cv_screenquake, 65},
{IT_HEADER, NULL, "Audio", NULL, 75}, {IT_CALL|IT_STRING, NULL, "Camera Options...", M_CameraMenu, 70},
{IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 85}, {IT_HEADER, NULL, "Audio", NULL, 80},
{IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 90},
{IT_HEADER, NULL, "Controls", NULL, 100}, {IT_STRING|IT_CVAR, NULL, "Reverse L/R Channels", &stereoreverse, 90},
{IT_STRING|IT_CVAR, NULL, "Same Sound Limit", &cv_samesoundlimit, 95},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 110}, {IT_HEADER, NULL, "Controls", NULL, 105},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 115},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 120}, {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P1)", &cv_autoaccel[0], 115},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 125}, {IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P2)", &cv_autoaccel[1], 120},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P3)", &cv_autoaccel[2], 125},
{IT_STRING|IT_CVAR, NULL, "Automatic Acceleration (P4)", &cv_autoaccel[3], 130},
}; };
static const char* OP_AccessibilityTooltips[] = static const char* OP_AccessibilityTooltips[] =
@@ -1675,6 +1679,9 @@ static const char* OP_AccessibilityTooltips[] =
"Reduces or disables certain effects players might be sensitive to\nSuch as flashing, flickering, certain screen effects and more.", "Reduces or disables certain effects players might be sensitive to\nSuch as flashing, flickering, certain screen effects and more.",
"Disables the flicker effect on Midnight Channel.", "Disables the flicker effect on Midnight Channel.",
"Sets minimum sector brightness, useful for dark areas", "Sets minimum sector brightness, useful for dark areas",
#ifdef HWRENDER
"Disabling Screen Textures will disable the Underwater and Heat screen effects.",
#endif
"Toggles the ripple effect on water surfaces", "Toggles the ripple effect on water surfaces",
"Fades other Players that are close to the camera in and out", "Fades other Players that are close to the camera in and out",
"Toggles the screen shake effect during Earthquakes", "Toggles the screen shake effect during Earthquakes",
+3 -19
View File
@@ -1454,9 +1454,9 @@ INT32 axtoi(const char *hexStg)
void CopyCaretColors(char *p, const char *s, int n) void CopyCaretColors(char *p, const char *s, int n)
{ {
gconst char *t; char *t;
int m; int m;
int c; int c;
if (!n) if (!n)
return; return;
@@ -1956,22 +1956,6 @@ UINT32 FNV1a_Hash(const char *message, size_t size)
return hash; return hash;
} }
// Behaves like the old quickncasehash
// Stops either if it encounters null terminator
// or reaches size
UINT32 FNV1a_QuickCaseHash(const char *message, size_t size)
{
UINT32 hash = FNV1A_OFFSET_BASIS;
for (size_t i = 0; i < size && message[i]; i++)
{
hash ^= tolower(message[i]);
hash *= FNV1A_PRIME;
}
return hash;
}
UINT32 FNV1a_HashString(const char *message) UINT32 FNV1a_HashString(const char *message)
{ {
UINT32 hash = FNV1A_OFFSET_BASIS; UINT32 hash = FNV1A_OFFSET_BASIS;
-1
View File
@@ -123,7 +123,6 @@ FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size);
// Hashes some message using FNV-1a // Hashes some message using FNV-1a
UINT32 FNV1a_Hash(const char *message, size_t size); UINT32 FNV1a_Hash(const char *message, size_t size);
UINT32 FNV1a_QuickCaseHash(const char *message, size_t size);
UINT32 FNV1a_HashString(const char *message); UINT32 FNV1a_HashString(const char *message);
UINT32 FNV1a_HashLowercaseString(const char *message); UINT32 FNV1a_HashLowercaseString(const char *message);
-8
View File
@@ -16,10 +16,6 @@
#ifndef _MD5_H #ifndef _MD5_H
#define _MD5_H 1 #define _MD5_H 1
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h> #include <stdio.h>
#if defined (HAVE_LIMITS_H) || (defined (_LIBC) && _LIBC) || defined (_WIN32) #if defined (HAVE_LIMITS_H) || (defined (_LIBC) && _LIBC) || defined (_WIN32)
@@ -56,8 +52,4 @@ int md5_stream(FILE *stream, void *resblock) THROWFUNC;
digest. */ digest. */
extern void *md5_buffer(const char *buffer, size_t len, void *resblock) THROWFUNC; extern void *md5_buffer(const char *buffer, size_t len, void *resblock) THROWFUNC;
#ifdef __cplusplus
} // extern "C"
#endif
#endif /* md5.h */ #endif /* md5.h */
+33 -30
View File
@@ -41,11 +41,11 @@ static time_t MSLastPing;
static char *MSRules; static char *MSRules;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
static I_mutex MSMutex; static I_Mutex MSMutex;
static I_cond MSCond; static I_Cond MSCond;
# define Lock_state() I_lock_mutex (&MSMutex) # define Lock_state() I_LockMutex (&MSMutex)
# define Unlock_state() I_unlock_mutex (MSMutex) # define Unlock_state() I_UnlockMutex (MSMutex)
#else/*HAVE_THREADS*/ #else/*HAVE_THREADS*/
# define Lock_state() # define Lock_state()
# define Unlock_state() # define Unlock_state()
@@ -90,10 +90,10 @@ consvar_t cv_masterserver_nagattempts = {"masterserver_nagattempts", "5", CV_SAV
#if defined (MASTERSERVER) && defined (HAVE_THREADS) #if defined (MASTERSERVER) && defined (HAVE_THREADS)
int ms_QueryId = 0; int ms_QueryId = 0;
I_mutex ms_QueryId_mutex; I_Mutex ms_QueryId_mutex;
msg_server_t *ms_ServerList = NULL; msg_server_t *ms_ServerList = NULL;
I_mutex ms_ServerList_mutex; I_Mutex ms_ServerList_mutex;
#endif #endif
UINT16 current_port = 0; UINT16 current_port = 0;
@@ -129,11 +129,11 @@ void AddMServCommands(void)
static void WarnGUI (void) static void WarnGUI (void)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&m_menu_mutex); I_LockMutex(&m_menu_mutex);
#endif #endif
M_PopupMasterServerConnectError(); M_PopupMasterServerConnectError();
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_unlock_mutex(m_menu_mutex); I_UnlockMutex(m_menu_mutex);
#endif #endif
} }
@@ -168,12 +168,12 @@ char *GetMODVersion(int id)
c = HMS_compare_mod_version(buffer, 16); c = HMS_compare_mod_version(buffer, 16);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_lock_mutex(&ms_QueryId_mutex); I_LockMutex(&ms_QueryId_mutex);
{ {
if (id != ms_QueryId) if (id != ms_QueryId)
c = -1; c = -1;
} }
I_unlock_mutex(ms_QueryId_mutex); I_UnlockMutex(ms_QueryId_mutex);
#endif #endif
if (c > 0) if (c > 0)
@@ -262,7 +262,6 @@ Finish_registration (void)
{ {
CONS_Printf("\n"); CONS_Printf("\n");
CONS_Alert(CONS_NOTICE, "%s\n", rules); CONS_Alert(CONS_NOTICE, "%s\n", rules);
free(rules);
} }
if (registered) if (registered)
@@ -342,7 +341,7 @@ Finish_unlist (void)
Unlock_state(); Unlock_state();
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_wake_all_cond(&MSCond); I_WakeAllCond(&MSCond);
#endif #endif
} }
} }
@@ -378,7 +377,7 @@ New_server_id (void)
Lock_state(); Lock_state();
{ {
*id = ++MSId; *id = ++MSId;
I_wake_all_cond(&MSCond); I_WakeAllCond(&MSCond);
} }
Unlock_state(); Unlock_state();
return id; return id;
@@ -393,7 +392,7 @@ Register_server_thread (int *id)
{ {
/* wait for previous unlist to finish */ /* wait for previous unlist to finish */
while (*id == MSId && MSRegistered) while (*id == MSId && MSRegistered)
I_hold_cond(&MSCond, MSMutex); I_HoldCond(&MSCond, MSMutex);
same = ( *id == MSId );/* it could have been a while */ same = ( *id == MSId );/* it could have been a while */
} }
@@ -445,7 +444,7 @@ Change_masterserver_thread (char *api)
Lock_state(); Lock_state();
{ {
while (MSRegistered) while (MSRegistered)
I_hold_cond(&MSCond, MSMutex); I_HoldCond(&MSCond, MSMutex);
} }
Unlock_state(); Unlock_state();
@@ -465,9 +464,9 @@ void RegisterServer(void)
{ {
#ifdef MASTERSERVER #ifdef MASTERSERVER
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread( (void)!I_SpawnThread(
"register-server", "register-server",
(I_thread_fn)Register_server_thread, (I_ThreadFn)Register_server_thread,
New_server_id() New_server_id()
); );
#else #else
@@ -479,9 +478,9 @@ void RegisterServer(void)
static void UpdateServer(void) static void UpdateServer(void)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread( (void)!I_SpawnThread(
"update-server", "update-server",
(I_thread_fn)Update_server_thread, (I_ThreadFn)Update_server_thread,
Server_id() Server_id()
); );
#else #else
@@ -493,9 +492,9 @@ void UnregisterServer(void)
{ {
#ifdef MASTERSERVER #ifdef MASTERSERVER
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread( (void)!I_SpawnThread(
"unlist-server", "unlist-server",
(I_thread_fn)Unlist_server_thread, (I_ThreadFn)Unlist_server_thread,
Server_id() Server_id()
); );
#else #else
@@ -558,14 +557,18 @@ void MasterClient_Ticker(void)
static void static void
Set_api (const char *api) Set_api (const char *api)
{ {
char *dapi = strdup(api);
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread( if (!I_SpawnThread(
"change-masterserver", "change-masterserver",
(I_thread_fn)Change_masterserver_thread, (I_ThreadFn)Change_masterserver_thread,
strdup(api) dapi
); ))
{
free(dapi);
}
#else #else
Finish_masterserver_change(strdup(api)); Finish_masterserver_change(dapi);
#endif #endif
} }
@@ -573,9 +576,9 @@ void
Get_rules (void) Get_rules (void)
{ {
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_spawn_thread( (void)!I_SpawnThread(
"get-masterserver-rules", "get-masterserver-rules",
(I_thread_fn)Get_masterserver_rules_thread, (I_ThreadFn)Get_masterserver_rules_thread,
NULL NULL
); );
#else #else
+2 -2
View File
@@ -69,10 +69,10 @@ extern consvar_t cv_rendezvousserver;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
extern int ms_QueryId; extern int ms_QueryId;
extern I_mutex ms_QueryId_mutex; extern I_Mutex ms_QueryId_mutex;
extern msg_server_t *ms_ServerList; extern msg_server_t *ms_ServerList;
extern I_mutex ms_ServerList_mutex; extern I_Mutex ms_ServerList_mutex;
#endif #endif
#ifdef MASTERSERVER #ifdef MASTERSERVER
void RegisterServer(void); void RegisterServer(void);
+3 -2
View File
@@ -831,7 +831,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
{ {
S_StartSound(toucher, special->info->seesound); S_StartSound(toucher, special->info->seesound);
if (UNLIKELY(player->pflags & PF_NIGHTSMODE)) if (player->pflags & PF_NIGHTSMODE)
{ {
player->bumpertime = TICRATE/2; player->bumpertime = TICRATE/2;
if (special->threshold > 0) if (special->threshold > 0)
@@ -1131,7 +1131,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
S_StartSound(toucher, special->info->painsound); S_StartSound(toucher, special->info->painsound);
return; return;
} }
else if (UNLIKELY((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING)) else if (((player->pflags & PF_NIGHTSMODE) && (player->pflags & PF_DRILLING)) || (player->pflags & (PF_JUMPED|PF_SPINNING|PF_GLIDING))
|| player->powers[pw_invulnerability] || player->powers[pw_super]) // Do you possess the ability to subdue the object? || player->powers[pw_invulnerability] || player->powers[pw_super]) // Do you possess the ability to subdue the object?
{ {
// Shatter the shield! // Shatter the shield!
@@ -2420,6 +2420,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
{ {
player->kartstuff[k_sneakertimer] = 0; player->kartstuff[k_sneakertimer] = 0;
K_SpinPlayer(player, source, 1, inflictor, false); K_SpinPlayer(player, source, 1, inflictor, false);
damage = player->mo->health - 1;
P_RingDamage(player, inflictor, source); P_RingDamage(player, inflictor, source);
P_PlayerRingBurst(player, 5); P_PlayerRingBurst(player, 5);
+6
View File
@@ -30,6 +30,8 @@ extern "C" {
#define FLOATSPEED (FRACUNIT*4) #define FLOATSPEED (FRACUNIT*4)
//#define VIEWHEIGHTS "41"
// Maximum player score. // Maximum player score.
#define MAXSCORE 999999990 #define MAXSCORE 999999990
@@ -237,10 +239,14 @@ void P_InstaThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move);
boolean P_LookForEnemies(player_t *player); boolean P_LookForEnemies(player_t *player);
void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius); void P_NukeEnemies(mobj_t *inflictor, mobj_t *source, fixed_t radius);
void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user void P_HomingAttack(mobj_t *source, mobj_t *enemy); /// \todo doesn't belong in p_user
//boolean P_SuperReady(player_t *player);
boolean P_AnalogMove(player_t *player); boolean P_AnalogMove(player_t *player);
/*boolean P_TransferToNextMare(player_t *player);
UINT8 P_FindLowestMare(void);*/
UINT8 P_FindLowestLap(void); UINT8 P_FindLowestLap(void);
UINT8 P_FindHighestLap(void); UINT8 P_FindHighestLap(void);
void P_FindEmerald(void); void P_FindEmerald(void);
//void P_TransferToAxis(player_t *player, INT32 axisnum);
boolean P_PlayerMoving(INT32 pnum); boolean P_PlayerMoving(INT32 pnum);
void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range); void P_Telekinesis(player_t *player, fixed_t thrust, fixed_t range);
+14 -14
View File
@@ -335,7 +335,7 @@ static boolean P_SetPrecipMobjState(precipmobj_t *mobj, statenum_t state)
mobj->tics = st->tics; mobj->tics = st->tics;
mobj->sprite = st->sprite; mobj->sprite = st->sprite;
mobj->frame = st->frame; mobj->frame = st->frame;
//mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set
return true; return true;
} }
@@ -919,7 +919,12 @@ static void P_PlayerFlip(mobj_t *mo)
G_GhostAddFlip((INT32) (mo->player - players)); G_GhostAddFlip((INT32) (mo->player - players));
// Flip aiming to match! // Flip aiming to match!
if (mo->player->pflags & PF_FLIPCAM) if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam
{
if (mo->tracer)
mo->tracer->eflags ^= MFE_VERTICALFLIP;
}
else if (mo->player->pflags & PF_FLIPCAM)
{ {
UINT8 i; UINT8 i;
@@ -941,11 +946,6 @@ static void P_PlayerFlip(mobj_t *mo)
camera[i].z += FixedMul(20*FRACUNIT, mo->scale); camera[i].z += FixedMul(20*FRACUNIT, mo->scale);
} }
} }
else if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam
{
if (mo->tracer)
mo->tracer->eflags ^= MFE_VERTICALFLIP;
}
} }
// //
@@ -3252,7 +3252,7 @@ void P_CalcChasePostImg(player_t *player, camera_t *thiscam)
player_flipcam = cv_flipcam[pnum].value; player_flipcam = cv_flipcam[pnum].value;
} }
const boolean flipcam = (player_flipcam && player->mo->eflags & MFE_VERTICALFLIP && LIKELY(!(player->pflags & PF_NIGHTSMODE))); const boolean flipcam = (player_flipcam && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP);
UINT8 postimgtype = 0; UINT8 postimgtype = 0;
if (encoremode) if (encoremode)
@@ -3620,7 +3620,7 @@ boolean P_PrecipThinker(precipmobj_t *mobj)
mobj->lastThink = leveltime; mobj->lastThink = leveltime;
R_ResetPrecipitationMobjInterpolationState(mobj); R_ResetPrecipitationMobjInterpolationState(mobj);
//P_CycleStateAnimation((mobj_t *)mobj); // if we ever want animated precip, readd a specific function which does not need casting P_CycleStateAnimation((mobj_t *)mobj);
if (mobj->state == &states[S_RAINRETURN]) if (mobj->state == &states[S_RAINRETURN])
{ {
@@ -6986,7 +6986,7 @@ static boolean P_MobjDeadThink(mobj_t *mobj)
fixed_t ns; fixed_t ns;
mobj_t *mo2; mobj_t *mo2;
i = P_RandomByte(); // grrrrrr i = P_RandomByte();
z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT); z = mobj->subsector->sector->floorheight + ((P_RandomByte()&63)*FRACUNIT);
for (j = 0; j < 2; j++) for (j = 0; j < 2; j++)
@@ -8553,7 +8553,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
if (mobj->tracer && mobj->tracer->player) if (mobj->tracer && mobj->tracer->player)
{ {
if (LIKELY(!(mobj->tracer->player->pflags & PF_NIGHTSMODE))) if (!(mobj->tracer->player->pflags & PF_NIGHTSMODE))
{ {
mobj->flags &= ~MF_NOGRAVITY; mobj->flags &= ~MF_NOGRAVITY;
mobj->flags2 &= ~MF2_DONTDRAW; mobj->flags2 &= ~MF2_DONTDRAW;
@@ -8577,7 +8577,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
P_SetTarget(&mobj->target, NULL); P_SetTarget(&mobj->target, NULL);
} }
if (UNLIKELY(mobj->tracer->player->pflags & PF_NIGHTSMODE)) if (mobj->tracer->player->pflags & PF_NIGHTSMODE)
{ {
if (mobj->tracer->player->bonustime) if (mobj->tracer->player->bonustime)
{ {
@@ -10034,7 +10034,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype
mobj->x = x; mobj->x = x;
mobj->y = y; mobj->y = y;
//mobj->flags = info->flags; mobj->flags = info->flags;
// do not set the state with P_SetMobjState, // do not set the state with P_SetMobjState,
// because action routines can not be called yet // because action routines can not be called yet
@@ -10044,7 +10044,7 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype
mobj->tics = st->tics; mobj->tics = st->tics;
mobj->sprite = st->sprite; mobj->sprite = st->sprite;
mobj->frame = st->frame; // FF_FRAMEMASK for frame, and other bits.. mobj->frame = st->frame; // FF_FRAMEMASK for frame, and other bits..
//mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set mobj->anim_duration = (UINT16)st->var2; // only used if FF_ANIMATE is set
// set subsector and/or block links // set subsector and/or block links
P_SetPrecipitationThingPosition(mobj); P_SetPrecipitationThingPosition(mobj);
+5 -2
View File
@@ -444,10 +444,12 @@ typedef struct precipmobj_s
// More drawing info: to determine current sprite. // More drawing info: to determine current sprite.
spritenum_t sprite; // used to find patch_t and flip value spritenum_t sprite; // used to find patch_t and flip value
UINT32 frame; // frame number, plus bits see p_pspr.h UINT32 frame; // frame number, plus bits see p_pspr.h
//UINT16 anim_duration; // for FF_ANIMATE states UINT16 anim_duration; // for FF_ANIMATE states
INT16 lightlevel; // Add to sector lightlevel, -255 - 255 INT16 lightlevel; // Add to sector lightlevel, -255 - 255
struct mprecipsecnode_s *touching_sectorlist; // a linked list of sectors where this object appears
struct subsector_s *subsector; // Subsector the mobj resides in. struct subsector_s *subsector; // Subsector the mobj resides in.
// The closest interval over all contacted sectors (or things). // The closest interval over all contacted sectors (or things).
@@ -456,10 +458,11 @@ typedef struct precipmobj_s
// Momentums, used to update position. // Momentums, used to update position.
fixed_t momx, momy, momz; fixed_t momx, momy, momz;
precipflag_t precipflags; fixed_t precipflags; // fixed_t so it uses the same spot as "pmomz" even as we use precipflags_t for it
state_t *state; state_t *state;
INT32 tics; // state tic counter INT32 tics; // state tic counter
UINT32 flags; // flags from mobjinfo tables
tic_t lastThink; tic_t lastThink;
} precipmobj_t; } precipmobj_t;
+22 -19
View File
@@ -1702,7 +1702,7 @@ void P_SwitchWeather(INT32 weathernum)
precipmobj->type = type; // proper set the type precipmobj->type = type; // proper set the type
precipmobj->info = &mobjinfo[type]; precipmobj->info = &mobjinfo[type];
//precipmobj->flags = mobjinfo[type].flags; precipmobj->flags = mobjinfo[type].flags;
st = &states[mobjinfo[type].spawnstate+z]; st = &states[mobjinfo[type].spawnstate+z];
@@ -3161,6 +3161,11 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers
INT32 section1, section2, section3, section4; INT32 section1, section2, section3, section4;
INT32 special; INT32 special;
section1 = GETSECSPECIAL(sector->special, 1);
section2 = GETSECSPECIAL(sector->special, 2);
section3 = GETSECSPECIAL(sector->special, 3);
section4 = GETSECSPECIAL(sector->special, 4);
// Ignore spectators // Ignore spectators
if (player->spectator) if (player->spectator)
return; return;
@@ -3171,11 +3176,6 @@ void P_ProcessSpecialSector(player_t *player, sector_t *sector, sector_t *rovers
if (player->playerstate == PST_DEAD) if (player->playerstate == PST_DEAD)
return; return;
section1 = GETSECSPECIAL(sector->special, 1);
section2 = GETSECSPECIAL(sector->special, 2);
section3 = GETSECSPECIAL(sector->special, 3);
section4 = GETSECSPECIAL(sector->special, 4);
// Conveyor stuff // Conveyor stuff
if (section3 == 2 || section3 == 4) if (section3 == 2 || section3 == 4)
player->onconveyor = section3; player->onconveyor = section3;
@@ -4381,6 +4381,8 @@ static void P_PlayerOnSpecial3DFloor(player_t *player, sector_t *sector)
} }
} }
#define VDOORSPEED (FRACUNIT*2)
// //
// P_RunSpecialSectorCheck // P_RunSpecialSectorCheck
// //
@@ -4399,7 +4401,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
// The list of specials that activate without floor touch // The list of specials that activate without floor touch
// Check Section 1 // Check Section 1
switch (GETSECSPECIAL(sector->special, 1)) switch(GETSECSPECIAL(sector->special, 1))
{ {
//case 2: // Damage (water) //case 2: // Damage (water)
case 8: // Instant kill case 8: // Instant kill
@@ -4410,7 +4412,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
} }
// Check Section 2 // Check Section 2
switch (GETSECSPECIAL(sector->special, 2)) switch(GETSECSPECIAL(sector->special, 2))
{ {
case 2: // Linedef executor (All players needed) case 2: // Linedef executor (All players needed)
case 4: // Linedef executor case 4: // Linedef executor
@@ -4421,7 +4423,7 @@ static void P_RunSpecialSectorCheck(player_t *player, sector_t *sector)
} }
// Check Section 4 // Check Section 4
switch (GETSECSPECIAL(sector->special, 4)) switch(GETSECSPECIAL(sector->special, 4))
{ {
case 2: // Level Exit / GOAL Sector / Flag Return case 2: // Level Exit / GOAL Sector / Flag Return
case 1: // Starpost activator case 1: // Starpost activator
@@ -4510,7 +4512,9 @@ void P_UpdateSpecials(void)
{ {
anim_t *anim; anim_t *anim;
INT32 i; INT32 i;
INT32 pic;
size_t j; size_t j;
levelflat_t *foundflats; // for flat animation levelflat_t *foundflats; // for flat animation
// LEVEL TIMER // LEVEL TIMER
@@ -4528,11 +4532,9 @@ void P_UpdateSpecials(void)
{ {
for (i = 0; i < anim->numpics; i++) for (i = 0; i < anim->numpics; i++)
{ {
pic = anim->basepic + ((leveltime/anim->speed + i) % anim->numpics);
if (anim->istexture) if (anim->istexture)
{ texturetranslation[anim->basepic+i] = pic;
texturetranslation[anim->basepic+i] = anim->basepic +
((leveltime/anim->speed + i) % anim->numpics);
}
} }
} }
@@ -4627,8 +4629,8 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f
if (sec2->numattached == 0) if (sec2->numattached == 0)
{ {
sec2->attached = Z_Malloc(sizeof(*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); sec2->attached = Z_Malloc(sizeof (*sec2->attached) * sec2->maxattached, PU_STATIC, NULL);
sec2->attachedsolid = Z_Malloc(sizeof(*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); sec2->attachedsolid = Z_Malloc(sizeof (*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL);
sec2->attached[0] = sec - sectors; sec2->attached[0] = sec - sectors;
sec2->numattached = 1; sec2->numattached = 1;
sec2->attachedsolid[0] = (flags & FF_SOLID); sec2->attachedsolid[0] = (flags & FF_SOLID);
@@ -4642,8 +4644,8 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f
if (sec2->numattached >= sec2->maxattached) if (sec2->numattached >= sec2->maxattached)
{ {
sec2->maxattached *= 2; sec2->maxattached *= 2;
sec2->attached = Z_Realloc(sec2->attached, sizeof(*sec2->attached) * sec2->maxattached, PU_STATIC, NULL); sec2->attached = Z_Realloc(sec2->attached, sizeof (*sec2->attached) * sec2->maxattached, PU_STATIC, NULL);
sec2->attachedsolid = Z_Realloc(sec2->attachedsolid, sizeof(*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL); sec2->attachedsolid = Z_Realloc(sec2->attachedsolid, sizeof (*sec2->attachedsolid) * sec2->maxattached, PU_STATIC, NULL);
} }
sec2->attached[sec2->numattached] = sec - sectors; sec2->attached[sec2->numattached] = sec - sectors;
sec2->attachedsolid[sec2->numattached] = (flags & FF_SOLID); sec2->attachedsolid[sec2->numattached] = (flags & FF_SOLID);
@@ -4651,7 +4653,7 @@ static ffloor_t *P_AddFakeFloor(sector_t *sec, sector_t *sec2, line_t *master, f
} }
// Add the floor // Add the floor
ffloor = Z_Calloc(sizeof(*ffloor), PU_LEVEL, NULL); ffloor = Z_Calloc(sizeof (*ffloor), PU_LEVEL, NULL);
ffloor->secnum = sec2 - sectors; ffloor->secnum = sec2 - sectors;
ffloor->target = sec; ffloor->target = sec;
ffloor->bottomheight = &sec2->floorheight; ffloor->bottomheight = &sec2->floorheight;
@@ -5466,6 +5468,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate)
break; break;
case 10: // Vertical culling plane for sprites and FOFs case 10: // Vertical culling plane for sprites and FOFs
sec = sides[*lines[i].sidenum].sector - sectors;
for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;)
sectors[s].cullheight = &lines[i]; // This allows it to change in realtime! sectors[s].cullheight = &lines[i]; // This allows it to change in realtime!
break; break;
@@ -5986,7 +5989,7 @@ void P_SpawnSpecials(INT32 fromnetsave, boolean reloadinggamestate)
if (!virt) if (!virt)
virt = vres_GetMap(lastloadedmaplumpnum); virt = vres_GetMap(lastloadedmaplumpnum);
data = (UINT8*)vres_Find(virt, "SIDEDEFS")->data; data = (UINT8*) vres_Find(virt, "SIDEDEFS")->data;
for (b = 0; b < (INT16)numsides; b++) for (b = 0; b < (INT16)numsides; b++)
{ {
+3 -4
View File
@@ -728,12 +728,11 @@ void P_Ticker(boolean run)
if (cv_recordmultiplayerdemos.value) if (cv_recordmultiplayerdemos.value)
{ {
const INT32 axis = JoyAxis(AXISLOOKBACK, 1);
if (demo.savemode == DSM_NOTSAVING || demo.savemode == DSM_WILLAUTOSAVE) if (demo.savemode == DSM_NOTSAVING || demo.savemode == DSM_WILLAUTOSAVE)
{ if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && (InputDown(gc_lookback, 1) || (cv_usejoystick[0].value && axis > 0)))
const INT32 axis = cv_usejoystick[0].value ? JoyAxis(AXISLOOKBACK, 1) : -1;
if (demo.savebutton && demo.savebutton + 3*TICRATE < leveltime && (InputDown(gc_lookback, 1) || (axis > 0)))
demo.savemode = DSM_TITLEENTRY; demo.savemode = DSM_TITLEENTRY;
}
// if there are no players left at all, stop demo recording // if there are no players left at all, stop demo recording
// Demos that that dont have any players crash during playback, which can happen with dedicated servers // Demos that that dont have any players crash during playback, which can happen with dedicated servers
+13 -2
View File
@@ -1822,6 +1822,7 @@ void P_DoJumpShield(player_t *player)
player->pflags &= ~PF_JUMPED; player->pflags &= ~PF_JUMPED;
//P_DoJump(player, false); //P_DoJump(player, false);
player->pflags &= ~PF_JUMPED;
player->secondjump = 0; player->secondjump = 0;
player->jumping = 0; player->jumping = 0;
player->pflags |= PF_THOKKED; player->pflags |= PF_THOKKED;
@@ -1893,6 +1894,7 @@ static void P_3dMovement(player_t *player)
ticcmd_t *cmd; ticcmd_t *cmd;
angle_t movepushangle, movepushsideangle; // Analog angle_t movepushangle, movepushsideangle; // Analog
fixed_t movepushforward = 0, movepushside = 0; fixed_t movepushforward = 0, movepushside = 0;
angle_t dangle; // replaces old quadrants bits
boolean analogmove = false; boolean analogmove = false;
fixed_t oldMagnitude, newMagnitude; fixed_t oldMagnitude, newMagnitude;
vector3_t totalthrust; vector3_t totalthrust;
@@ -1950,6 +1952,15 @@ static void P_3dMovement(player_t *player)
// Calculates player's speed based on distance-of-a-line formula // Calculates player's speed based on distance-of-a-line formula
player->speed = R_PointToDist2(0, 0, player->rmomx, player->rmomy); player->speed = R_PointToDist2(0, 0, player->rmomx, player->rmomy);
// Monster Iestyn - 04-11-13
// Quadrants are stupid, excessive and broken, let's do this a much simpler way!
// Get delta angle from rmom angle and player angle first
dangle = R_PointToAngle2(0,0, player->rmomx, player->rmomy) - player->mo->angle;
if (dangle > ANGLE_180) //flip to keep to one side
{
dangle = InvAngle(dangle);
}
// When sliding, don't allow forward/back // When sliding, don't allow forward/back
if (player->pflags & PF_SLIDING) if (player->pflags & PF_SLIDING)
cmd->forwardmove = 0; cmd->forwardmove = 0;
@@ -4109,7 +4120,7 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
angle -= (angle - thiscam->pitch)/2; angle -= (angle - thiscam->pitch)/2;
} }
if (player->playerstate != PST_DEAD && LIKELY(!((player->pflags & PF_NIGHTSMODE) && player->exiting))) if (player->playerstate != PST_DEAD && !((player->pflags & PF_NIGHTSMODE) && player->exiting))
angle += (focusaiming < ANGLE_180 ? focusaiming/2 : InvAngle(InvAngle(focusaiming)/2)); // overcomplicated version of '((signed)focusaiming)/2;' angle += (focusaiming < ANGLE_180 ? focusaiming/2 : InvAngle(InvAngle(focusaiming)/2)); // overcomplicated version of '((signed)focusaiming)/2;'
if (!camstill && !timeover) // Keep the view still... if (!camstill && !timeover) // Keep the view still...
@@ -4453,7 +4464,7 @@ static INT32 Quaketilt(player_t *player)
lowb = FixedMul(lowb, player->mo->scale); lowb = FixedMul(lowb, player->mo->scale);
moma = FixedMul(FixedDiv(delta, ANGLE_90), tilt); moma = FixedMul(FixedDiv(delta, ANGLE_90), tilt);
speed = abs(player->mo->momx + player->mo->momy); speed = abs( player->mo->momx + player->mo->momy );
if (speed < lowb) if (speed < lowb)
{ {
+3 -3
View File
@@ -622,7 +622,7 @@ Rloadtextures (INT32 i, INT32 w)
// Set texture properties. // Set texture properties.
memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name)); memcpy(texture->name, W_CheckNameForNumPwad(wadnum, lumpnum), sizeof(texture->name));
texture->hash = FNV1a_QuickCaseHash(texture->name, 8); texture->hash = quickncasehash(texture->name, 8);
texture->width = SHORT(patchlump.width); texture->width = SHORT(patchlump.width);
texture->height = SHORT(patchlump.height); texture->height = SHORT(patchlump.height);
@@ -1066,7 +1066,7 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
// Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily. // Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily.
resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t), PU_STATIC, NULL); resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t), PU_STATIC, NULL);
memcpy(resultTexture->name, newTextureName, 8); memcpy(resultTexture->name, newTextureName, 8);
resultTexture->hash = FNV1a_QuickCaseHash(newTextureName, 8); resultTexture->hash = quickncasehash(newTextureName, 8);
resultTexture->width = newTextureWidth; resultTexture->width = newTextureWidth;
resultTexture->height = newTextureHeight; resultTexture->height = newTextureHeight;
resultTexture->type = TEXTURETYPE_COMPOSITE; resultTexture->type = TEXTURETYPE_COMPOSITE;
@@ -1755,7 +1755,7 @@ INT32 R_CheckTextureNumForName(const char *name)
if (name[0] == '-') if (name[0] == '-')
return 0; return 0;
hash = FNV1a_QuickCaseHash(name, 8); hash = quickncasehash(name, 8);
for (i = 0; i < tidcachelen; i++) for (i = 0; i < tidcachelen; i++)
if (tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8)) if (tidcache[i].hash == hash && !strncasecmp(tidcache[i].name, name, 8))
+10 -3
View File
@@ -289,8 +289,14 @@ void R_GenerateBlendTables(void)
state->LocalPalette = static_cast<RGBA_t *>(memcpy(malloc(palsize), pLocalPalette, palsize)); state->LocalPalette = static_cast<RGBA_t *>(memcpy(malloc(palsize), pLocalPalette, palsize));
state->gammaCorrectedPalette = static_cast<RGBA_t *>(memcpy(malloc(palsize), pGammaCorrectedPalette, palsize)); state->gammaCorrectedPalette = static_cast<RGBA_t *>(memcpy(malloc(palsize), pGammaCorrectedPalette, palsize));
I_spawn_thread("blend-tables", if (!I_SpawnThread("blend-tables",
R_GenerateBlendTables_Thread, state); R_GenerateBlendTables_Thread, state))
{
free(state->gammaCorrectedPalette);
free(state->LocalPalette);
free(state);
I_Error("R_GenerateBlendTables: Failed to generate BlendTables\n"); // should we just retry on main thread instead?
}
#else #else
struct GenerateBlendTables_State state = {pLocalPalette, pGammaCorrectedPalette}; struct GenerateBlendTables_State state = {pLocalPalette, pGammaCorrectedPalette};
R_GenerateBlendTables_Core(&state); R_GenerateBlendTables_Core(&state);
@@ -437,7 +443,8 @@ UINT8* R_GetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 flags)
UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local) UINT8* R_GetLocalTranslationColormap(skin_t *skin, skin_t *localskin, skincolors_t color, UINT8 flags, boolean local)
{ {
return RGetTranslationColormap(K_GetMobjLocalSkinNum(skin, localskin, local), color, flags, (localskin && local)); const INT32 skinnum = localskin ? (localskin - K_GetSkinArray(local)) : (skin - skins);
return RGetTranslationColormap(skinnum, color, flags, (localskin && local));
} }
patch_t* R_GetSkinFaceRank(player_t* ply) patch_t* R_GetSkinFaceRank(player_t* ply)
-1
View File
@@ -92,7 +92,6 @@ INT32 R_LocalSkinAvailable(const char *name, boolean local);
// had to move those here Zzz... // had to move those here Zzz...
INT32 K_GetSkinNum(player_t *player); INT32 K_GetSkinNum(player_t *player);
INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local); INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local);
INT32 K_GetMobjLocalSkinNum(const skin_t *skin, const skin_t *localskin, boolean local);
skin_t *K_GetPlayerSkin(player_t *player); skin_t *K_GetPlayerSkin(player_t *player);
skin_t *K_GetMobjSkin(const mobj_t *mobj); skin_t *K_GetMobjSkin(const mobj_t *mobj);
patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum); patch_t *K_GetFacePrefix(player_t *player, INT32 skinnum);
+4 -1
View File
@@ -1855,6 +1855,9 @@ static void R_ProjectSprite(mobj_t *thing)
if (thing->subsector->sector->numlights) if (thing->subsector->sector->numlights)
R_SplitSprite(vis); R_SplitSprite(vis);
// Debug
++objectsdrawn;
} }
static void R_ProjectPrecipitationSprite(precipmobj_t *thing) static void R_ProjectPrecipitationSprite(precipmobj_t *thing)
@@ -2960,7 +2963,7 @@ fixed_t R_DoPlayerFade(mobj_t *thing)
fixed_t fadealpha = FRACUNIT; fixed_t fadealpha = FRACUNIT;
static constexpr tic_t countdownstarttime = (15 * TICRATE) / 4; // starttime - (3*TICRATE) static constexpr tic_t countdownstarttime = (15 * TICRATE) / 4; // starttime - (3*TICRATE)
if (thing->player == viewplayer || viewplayer->exiting || viewplayer->spectator || camera[R_GetViewNumber()].freecam || leveltime < countdownstarttime) if (thing->player == viewplayer || viewplayer->exiting || camera[R_GetViewNumber()].freecam || leveltime < countdownstarttime)
return fadealpha; return fadealpha;
const INT32 playerdist = (FixedMul((thing->x - viewx), viewcos) + FixedMul((thing->y - viewy), viewsin)) >> FRACBITS; const INT32 playerdist = (FixedMul((thing->x - viewx), viewcos) + FixedMul((thing->y - viewy), viewsin)) >> FRACBITS;
+4 -3
View File
@@ -473,12 +473,13 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume)
return; return;
memset(listener, 0, sizeof(listener)); memset(listener, 0, sizeof(listener));
memset(listenmobj, 0, sizeof(listenmobj));
for (i = 0; i <= splitscreen; i++) for (i = 0; i <= splitscreen; i++)
{ {
player_t *player = &players[displayplayers[i]]; player_t *player = &players[displayplayers[i]];
listenmobj[i] = NULL;
if (player->awayviewtics) if (player->awayviewtics)
{ {
listenmobj[i] = player->awayviewmobj; listenmobj[i] = player->awayviewmobj;
@@ -1301,7 +1302,7 @@ static boolean ReadMusicDefFields(UINT16 wadnum, int line, char *stoken, musicde
STRBUFCPY(def->name, value); STRBUFCPY(def->name, value);
strlwr(def->name); strlwr(def->name);
def->hash = FNV1a_QuickCaseHash(def->name, 6); def->hash = quickncasehash (def->name, 6);
} }
(*defp) = def; (*defp) = def;
@@ -1483,7 +1484,7 @@ void S_InitMusicDefs(void)
// //
musicdef_t *S_FindMusicCredit(const char *musname) musicdef_t *S_FindMusicCredit(const char *musname)
{ {
UINT32 hash = FNV1a_QuickCaseHash(musname, 6); UINT32 hash = quickncasehash(musname, 6);
musicdef_t *def; musicdef_t *def;
for (INT32 i = 0; i < nummusicdefs; ++i) for (INT32 i = 0; i < nummusicdefs; ++i)
-1
View File
@@ -35,7 +35,6 @@ set(SRB2_SDL2_SOURCES
i_system.cpp i_system.cpp
i_ttf.c i_ttf.c
i_video.c i_video.c
i_threads.c
#IMG_xpm.c #IMG_xpm.c
ogl_sdl.c ogl_sdl.c
+21 -22
View File
@@ -1577,7 +1577,7 @@ static void write_backtrace(bt_crash_reason_t reason)
static std::thread::id g_main_thread_id; static std::thread::id g_main_thread_id;
#endif #endif
static volatile sig_atomic_t g_in_exiting_signal_handler = false; boolean g_in_exiting_signal_handler = false;
static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name) static void I_PrintSignal(INT32 signal_num, boolean core_dumped, char *signal_msg, char *signal_name)
{ {
@@ -1712,11 +1712,6 @@ static void I_ReportSignal(int num, int coredumped)
I_ShowErrorBox(sigttl, sigmsg); I_ShowErrorBox(sigttl, sigmsg);
} }
boolean I_In_Exiting_Signal_Handler(void)
{
return g_in_exiting_signal_handler;
}
#ifndef NEWSIGNALHANDLER #ifndef NEWSIGNALHANDLER
FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
{ {
@@ -1746,17 +1741,21 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num)
} }
#endif #endif
static volatile sig_atomic_t interrupted = false; FUNCNORETURN static ATTRNORETURN void quit_handler(int num)
boolean I_Interrupted(void)
{ {
return interrupted; #ifdef HAVE_THREADS
} if (g_main_thread_id != std::this_thread::get_id())
{
// Do not attempt any sort of recovery if this signal triggers off the main thread
signal(num, SIG_DFL);
raise(num);
exit(-2);
}
#endif
static void quit_handler(int num) signal(num, SIG_DFL); //default signal action
{ raise(num);
(void)num; I_Quit();
interrupted = true;
} }
static void I_RegisterSignals(void) static void I_RegisterSignals(void)
@@ -1842,15 +1841,18 @@ static void I_Fork(void)
I_RegisterChildSignals(); I_RegisterChildSignals();
break; break;
default: default:
#ifdef LOGMESSAGES
if (logstream) if (logstream)
fclose(logstream);/* the child has this */ fclose(logstream);/* the child has this */
#endif
c = wait(&status); c = wait(&status);
#ifdef LOGMESSAGES #ifdef LOGMESSAGES
/* By the way, exit closes files. */ /* By the way, exit closes files. */
logstream = fopen(logfilename, "at"); logstream = fopen(logfilename, "at");
#else
logstream = 0;
#endif #endif
if (c == -1) if (c == -1)
{ {
kill(child, SIGKILL); kill(child, SIGKILL);
@@ -1886,9 +1888,6 @@ INT32 I_StartupSystem(void)
SDL_version SDLlinked; SDL_version SDLlinked;
SDL_VERSION(&SDLcompiled) SDL_VERSION(&SDLcompiled)
SDL_GetVersion(&SDLlinked); SDL_GetVersion(&SDLlinked);
W_Startup();
I_StartupConsole(); I_StartupConsole();
#ifdef NEWSIGNALHANDLER #ifdef NEWSIGNALHANDLER
// This is useful when debugging. It lets GDB attach to // This is useful when debugging. It lets GDB attach to
@@ -1897,8 +1896,8 @@ INT32 I_StartupSystem(void)
I_Fork(); I_Fork();
#endif #endif
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
I_start_threads(); I_StartThreads();
I_AddExitFunc(I_stop_threads); I_AddExitFunc(I_StopThreads);
I_ThreadPoolInit(); I_ThreadPoolInit();
I_AddExitFunc(I_ThreadPoolShutdown); I_AddExitFunc(I_ThreadPoolShutdown);
#endif #endif
-360
View File
@@ -1,360 +0,0 @@
// SONIC ROBO BLAST 2 KART
//-----------------------------------------------------------------------------
// Copyright (C) 2020 by James R.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file i_threads.c
/// \brief Multithreading abstraction
#ifdef HAVE_THREADS
#include "../doomdef.h"
#include "../i_threads.h"
#include <SDL.h>
typedef void * (*Create_fn)(void);
struct Link;
struct Thread;
typedef struct Link * Link;
typedef struct Thread * Thread;
struct Link
{
void * data;
Link next;
Link prev;
};
struct Thread
{
I_thread_fn entry;
void * userdata;
SDL_Thread * thread;
};
static Link i_thread_pool;
static Link i_mutex_pool;
static Link i_cond_pool;
static I_mutex i_thread_pool_mutex;
static I_mutex i_mutex_pool_mutex;
static I_mutex i_cond_pool_mutex;
static SDL_atomic_t i_threads_running = {1};
static Link
Insert_link (
Link * head,
Link link
){
link->prev = NULL;
link->next = (*head);
if ((*head))
(*head)->prev = link;
(*head) = link;
return link;
}
static void
Free_link (
Link * head,
Link link
){
if (link->prev)
link->prev->next = link->next;
else
(*head) = link->next;
if (link->next)
link->next->prev = link->prev;
free(link->data);
free(link);
}
static Link
New_link (void *data)
{
Link link;
link = malloc(sizeof *link);
if (! link)
abort();
link->data = data;
return link;
}
static void *
Identity (
Link * pool_anchor,
I_mutex pool_mutex,
void ** anchor,
Create_fn create_fn
){
void * id;
id = SDL_AtomicGetPtr(anchor);
if (! id)
{
I_lock_mutex(&pool_mutex);
{
id = SDL_AtomicGetPtr(anchor);
if (! id)
{
id = (*create_fn)();
if (! id)
abort();
Insert_link(pool_anchor, New_link(id));
SDL_AtomicSetPtr(anchor, id);
}
}
I_unlock_mutex(pool_mutex);
}
return id;
}
static int
Worker (
Link link
){
Thread th;
th = link->data;
(*th->entry)(th->userdata);
if (SDL_AtomicGet(&i_threads_running))
{
I_lock_mutex(&i_thread_pool_mutex);
{
if (SDL_AtomicGet(&i_threads_running))
{
SDL_DetachThread(th->thread);
Free_link(&i_thread_pool, link);
}
}
I_unlock_mutex(i_thread_pool_mutex);
}
return 0;
}
void
I_spawn_thread (
const char * name,
I_thread_fn entry,
void * userdata
){
Link link;
Thread th;
th = malloc(sizeof *th);
if (! th)
abort();/* this is pretty GNU of me */
th->entry = entry;
th->userdata = userdata;
I_lock_mutex(&i_thread_pool_mutex);
{
link = Insert_link(&i_thread_pool, New_link(th));
if (SDL_AtomicGet(&i_threads_running))
{
th->thread = SDL_CreateThread(
(SDL_ThreadFunction)Worker,
name,
link
);
if (! th->thread)
abort();
}
}
I_unlock_mutex(i_thread_pool_mutex);
}
int
I_thread_is_stopped (void)
{
return ( ! SDL_AtomicGet(&i_threads_running) );
}
void
I_start_threads (void)
{
i_thread_pool_mutex = SDL_CreateMutex();
i_mutex_pool_mutex = SDL_CreateMutex();
i_cond_pool_mutex = SDL_CreateMutex();
if (!(
i_thread_pool_mutex &&
i_mutex_pool_mutex &&
i_cond_pool_mutex
)){
abort();
}
}
void
I_stop_threads (void)
{
Link link;
Link next;
Thread th;
SDL_mutex * mutex;
SDL_cond * cond;
if (i_threads_running.value)
{
/* rely on the good will of thread-san */
SDL_AtomicSet(&i_threads_running, 0);
I_lock_mutex(&i_thread_pool_mutex);
{
for (
link = i_thread_pool;
link;
link = next
){
next = link->next;
th = link->data;
SDL_WaitThread(th->thread, NULL);
free(th);
free(link);
}
}
I_unlock_mutex(i_thread_pool_mutex);
for (
link = i_mutex_pool;
link;
link = next
){
next = link->next;
mutex = link->data;
SDL_DestroyMutex(mutex);
free(link);
}
for (
link = i_cond_pool;
link;
link = next
){
next = link->next;
cond = link->data;
SDL_DestroyCond(cond);
free(link);
}
SDL_DestroyMutex(i_thread_pool_mutex);
SDL_DestroyMutex(i_mutex_pool_mutex);
SDL_DestroyMutex(i_cond_pool_mutex);
}
}
void
I_lock_mutex (
I_mutex * anchor
){
SDL_mutex * mutex;
mutex = Identity(
&i_mutex_pool,
i_mutex_pool_mutex,
anchor,
(Create_fn)SDL_CreateMutex
);
if (SDL_LockMutex(mutex) == -1)
abort();
}
void
I_unlock_mutex (
I_mutex id
){
if (SDL_UnlockMutex(id) == -1)
abort();
}
void
I_hold_cond (
I_cond * cond_anchor,
I_mutex mutex_id
){
SDL_cond * cond;
cond = Identity(
&i_cond_pool,
i_cond_pool_mutex,
cond_anchor,
(Create_fn)SDL_CreateCond
);
if (SDL_CondWait(cond, mutex_id) == -1)
abort();
}
void
I_wake_one_cond (
I_cond * anchor
){
SDL_cond * cond;
cond = Identity(
&i_cond_pool,
i_cond_pool_mutex,
anchor,
(Create_fn)SDL_CreateCond
);
if (SDL_CondSignal(cond) == -1)
abort();
}
void
I_wake_all_cond (
I_cond * anchor
){
SDL_cond * cond;
cond = Identity(
&i_cond_pool,
i_cond_pool_mutex,
anchor,
(Create_fn)SDL_CreateCond
);
if (SDL_CondBroadcast(cond) == -1)
abort();
}
#endif // HAVE_THREADS
+3 -4
View File
@@ -1164,8 +1164,8 @@ void I_GetEvent(void)
SDL_GetWindowSize(window, &wwidth, &wheight); SDL_GetWindowSize(window, &wwidth, &wheight);
event.type = ev_mouse; event.type = ev_mouse;
event.data1 = 0; event.data1 = 0;
event.data2 = (INT32)lroundf(mousemovex * ((float)wwidth / (float)realwidth)); event.data2 = (INT32)lround(mousemovex * ((float)wwidth / (float)realwidth));
event.data3 = (INT32)lroundf(mousemovey * ((float)wheight / (float)realheight)); event.data3 = (INT32)lround(mousemovey * ((float)wheight / (float)realheight));
D_PostEvent(&event); D_PostEvent(&event);
} }
@@ -2027,8 +2027,7 @@ void I_ShutdownGraphics(void)
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = NULL; window = NULL;
if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
framebuffer = SDL_FALSE; framebuffer = SDL_FALSE;
} }
+1 -2
View File
@@ -237,8 +237,7 @@ void I_ShutdownSound(void)
Mix_Quit(); Mix_Quit();
#endif #endif
if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDL_QuitSubSystem(SDL_INIT_AUDIO);
#ifdef HAVE_LIBGME #ifdef HAVE_LIBGME
if (gme) if (gme)
+2
View File
@@ -52,6 +52,8 @@
#include "r_fps.h" #include "r_fps.h"
UINT16 objectsdrawn = 0;
// dumb fade thing for director toggle // dumb fade thing for director toggle
tic_t directortoggletimer = 0; tic_t directortoggletimer = 0;
+2
View File
@@ -134,6 +134,8 @@ typedef enum
extern hudinfo_t hudinfo[NUMHUDITEMS]; extern hudinfo_t hudinfo[NUMHUDITEMS];
extern UINT16 objectsdrawn;
// variable to stop mayonaka static from flickering // variable to stop mayonaka static from flickering
extern consvar_t cv_lessflicker; extern consvar_t cv_lessflicker;
extern consvar_t cv_stagetitle; extern consvar_t cv_stagetitle;
+7 -10
View File
@@ -23,26 +23,24 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef _GNU_SOURCE
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stddef.h> #include <stddef.h>
static inline int trycmp(char **pp, char *cp, const char *q, size_t qn) static inline int
trycmp (char **pp, char *cp,
const char *q, size_t qn)
{ {
char *p; char *p;
p = (*pp); p = (*pp);
if (strncasecmp(p, q, qn) == 0) if (strncasecmp(p, q, qn) == 0)
return 0; return 0;
(*pp) = strchr(&p[1], (*cp)); (*pp) = strchr(&p[1], (*cp));
return 1; return 1;
} }
static inline void swapp(char ***ppap, char ***ppbp, char **cpap, char **cpbp) static inline void
swapp (char ***ppap, char ***ppbp, char **cpap, char **cpbp)
{ {
char **pp; char **pp;
char *p; char *p;
@@ -56,7 +54,8 @@ static inline void swapp(char ***ppap, char ***ppbp, char **cpap, char **cpbp)
*cpbp = p; *cpbp = p;
} }
char *nongnu_strcasestr(const char *s, const char *q) char *
nongnu_strcasestr (const char *s, const char *q)
{ {
size_t qn; size_t qn;
@@ -114,5 +113,3 @@ char *nongnu_strcasestr(const char *s, const char *q)
return NULL; return NULL;
} }
#endif
-2119
View File
File diff suppressed because it is too large. Load diff
+179 -195
View File
@@ -87,32 +87,18 @@ typedef struct
} lumpchecklist_t; } lumpchecklist_t;
// Must be a power of two // Must be a power of two
#define LUMPNUMCACHESIZE 2048 // should be reasonable ig #define LUMPNUMCACHESIZE 64
#define LUMPNUMCACHENAME 32 #define LUMPNUMCACHENAME 32
#define NAME lumpnum_map typedef struct lumpnum_cache_s
#define KEY_TY char * {
#define KEY_GET_CONST char lumpname[LUMPNUMCACHENAME];
#define VAL_TY lumpnum_t lumpnum_t lumpnum;
#define HASH_FN vt_hash_string UINT32 hash;
#define CMPR_FN vt_cmpr_string } lumpnum_cache_t;
#define KEY_DTOR_FN free
#include "verstable.h"
#define NAME folder_map static lumpnum_cache_t lumpnumcache[LUMPNUMCACHESIZE];
#define KEY_TY char * static UINT16 lumpnumcacheindex = 0;
#define KEY_GET_CONST
#define VAL_TY UINT16
#define HASH_FN vt_hash_string
#define CMPR_FN vt_cmpr_string
#define KEY_DTOR_FN free
#include "verstable.h"
static lumpnum_map lumpnumcache;
typedef struct FolderCache {
folder_map map;
} FolderCache;
static const char pat_central[] = {0x50, 0x4b, 0x01, 0x02, 0x00}; static const char pat_central[] = {0x50, 0x4b, 0x01, 0x02, 0x00};
static const char pat_end[] = {0x50, 0x4b, 0x05, 0x06, 0x00}; static const char pat_end[] = {0x50, 0x4b, 0x05, 0x06, 0x00};
@@ -130,8 +116,6 @@ wadfile_t *wadfiles[MAX_WADFILES] = {}; // 0 to numwadfiles-1 are valid
// being ejected // being ejected
void W_Shutdown(void) void W_Shutdown(void)
{ {
lumpnum_map_cleanup(&lumpnumcache);
while (numwadfiles--) while (numwadfiles--)
{ {
wadfile_t *wad = wadfiles[numwadfiles]; wadfile_t *wad = wadfiles[numwadfiles];
@@ -143,28 +127,18 @@ void W_Shutdown(void)
while (wad->numlumps--) while (wad->numlumps--)
{ {
//Z_Free(wad->lumpinfo[wad->numlumps].longname); Z_Free(wad->lumpinfo[wad->numlumps].longname);
Z_Free(wad->lumpinfo[wad->numlumps].fullname); Z_Free(wad->lumpinfo[wad->numlumps].fullname);
} }
folder_map_cleanup(&wad->startfolders->map); M_AATreeFree(wad->startfolders);
free(wad->startfolders); M_AATreeFree(wad->endfolders);
folder_map_cleanup(&wad->endfolders->map);
free(wad->endfolders);
Z_Free(wad->lumpinfo); Z_Free(wad->lumpinfo);
Z_Free(wad); Z_Free(wad);
} }
} }
// the lumpnum cache needs to be initialized before use
// call this as early as possible!
void W_Startup(void)
{
lumpnum_map_init(&lumpnumcache);
lumpnum_map_reserve(&lumpnumcache, LUMPNUMCACHESIZE);
}
//=========================================================================== //===========================================================================
// LUMP BASED ROUTINES // LUMP BASED ROUTINES
//=========================================================================== //===========================================================================
@@ -285,7 +259,7 @@ static inline void W_LoadDehackedLumpsPK3(UINT16 wadnum)
lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart]; lumpinfo_t *lump_p = &wadfiles[wadnum]->lumpinfo[posStart];
size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = (char *)(malloc(length + 1)); char *name = malloc(length + 1);
if (!name) if (!name)
I_Error("W_LoadDehackedLumpsPK3: Out of memory!\n"); I_Error("W_LoadDehackedLumpsPK3: Out of memory!\n");
@@ -321,7 +295,7 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum)
if (memcmp(lump_p->name, "SOC_", 4) == 0) // Check for generic SOC lump if (memcmp(lump_p->name, "SOC_", 4) == 0) // Check for generic SOC lump
{ // shameless copy+paste of code from LUA_LoadLump { // shameless copy+paste of code from LUA_LoadLump
size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name size_t length = len + 1 + strlen(lump_p->fullname); // length of file name, '|', and lump name
char *name = (char *)(malloc(length + 1)); char *name = malloc(length + 1);
if (!name) if (!name)
I_Error("W_LoadDehackedLumps: Out of memory!\n"); I_Error("W_LoadDehackedLumps: Out of memory!\n");
@@ -386,12 +360,12 @@ static inline INT32 W_MakeFileMD5(const char *filename, void *resblock)
} }
// Invalidates the cache of lump numbers. Call this whenever a wad is added. // Invalidates the cache of lump numbers. Call this whenever a wad is added.
FUNCINLINE static ATTRINLINE void W_InvalidateLumpnumCache(void) static void W_InvalidateLumpnumCache(void)
{ {
lumpnum_map_clear(&lumpnumcache); memset(lumpnumcache, 0, sizeof(lumpnumcache));
} }
FUNCINLINE static ATTRINLINE UINT32 W_HashLumpName(const char *name) UINT32 W_HashLumpName(const char *name)
{ {
return FNV1a_HashLowercaseString(name); return FNV1a_HashLowercaseString(name);
} }
@@ -417,28 +391,28 @@ static restype_t ResourceFileDetect(const char* filename)
*/ */
static lumpinfo_t* ResGetLumpsStandalone(FILE* handle, UINT16* numlumps, const char* lumpname) static lumpinfo_t* ResGetLumpsStandalone(FILE* handle, UINT16* numlumps, const char* lumpname)
{ {
lumpinfo_t* lumpinfo = (lumpinfo_t *)(Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL)); lumpinfo_t* lumpinfo = Z_Calloc(sizeof (*lumpinfo), PU_STATIC, NULL);
lumpinfo->position = 0; lumpinfo->position = 0;
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
lumpinfo->size = (size_t)(ftell(handle)); lumpinfo->size = ftell(handle);
fseek(handle, 0, SEEK_SET); fseek(handle, 0, SEEK_SET);
strlcpy(lumpinfo->name, lumpname, sizeof(lumpinfo->name)); strlcpy(lumpinfo->name, lumpname, sizeof(lumpinfo->name));
lumpinfo->namelength = strlen(lumpinfo->name); lumpinfo->namelength = strlen(lumpinfo->name);
lumpinfo->hash.name = W_HashLumpName(lumpname); lumpinfo->hash.name = W_HashLumpName(lumpname);
// Allocate the lump's long name. // Allocate the lump's long name.
/*lumpinfo->longname = (char *)(Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL)); lumpinfo->longname = Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->longname, lumpname); strcpy(lumpinfo->longname, lumpname);
lumpinfo->longname[lumpinfo->namelength] = '\0'; lumpinfo->longname[lumpinfo->namelength] = '\0';
lumpinfo->longnamelength = lumpinfo->namelength; lumpinfo->longnamelength = lumpinfo->namelength;
lumpinfo->hash.longname = lumpinfo->hash.name;*/ lumpinfo->hash.longname = lumpinfo->hash.name;
// Allocate the lump's full name. // Allocate the lump's full name.
lumpinfo->fullname = (char *)(Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL)); lumpinfo->fullname = Z_Malloc((lumpinfo->namelength + 1) * sizeof(char), PU_STATIC, NULL);
strcpy(lumpinfo->fullname, lumpname); strcpy(lumpinfo->fullname, lumpname);
lumpinfo->fullname[lumpinfo->namelength] = '\0'; lumpinfo->fullname[lumpinfo->namelength] = '\0';
lumpinfo->fullnamelength = lumpinfo->namelength; lumpinfo->fullnamelength = lumpinfo->namelength;
//lumpinfo->hash.fullname = lumpinfo->hash.name; lumpinfo->hash.fullname = lumpinfo->hash.name;
*numlumps = 1; *numlumps = 1;
return lumpinfo; return lumpinfo;
@@ -481,8 +455,8 @@ static lumpinfo_t* ResGetLumpsWad(FILE* handle, UINT16* nlmp, const char* filena
header.infotableofs = LONG(header.infotableofs); header.infotableofs = LONG(header.infotableofs);
// read wad file directory // read wad file directory
i = header.numlumps * sizeof(*fileinfo); i = header.numlumps * sizeof (*fileinfo);
fileinfov = fileinfo = (filelump_t *)(malloc(i)); fileinfov = fileinfo = malloc(i);
if (fseek(handle, header.infotableofs, SEEK_SET) == -1 if (fseek(handle, header.infotableofs, SEEK_SET) == -1
|| fread(fileinfo, 1, i, handle) < i) || fread(fileinfo, 1, i, handle) < i)
@@ -494,7 +468,7 @@ static lumpinfo_t* ResGetLumpsWad(FILE* handle, UINT16* nlmp, const char* filena
numlumps = header.numlumps; numlumps = header.numlumps;
// fill in lumpinfo for this wad // fill in lumpinfo for this wad
lump_p = lumpinfo = (lumpinfo_t *)(Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL)); lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
for (i = 0; i < numlumps; i++, lump_p++, fileinfo++) for (i = 0; i < numlumps; i++, lump_p++, fileinfo++)
{ {
@@ -538,18 +512,18 @@ static lumpinfo_t* ResGetLumpsWad(FILE* handle, UINT16* nlmp, const char* filena
lump_p->hash.name = W_HashLumpName(lump_p->name); lump_p->hash.name = W_HashLumpName(lump_p->name);
// Allocate the lump's long name. // Allocate the lump's long name.
/*lump_p->longname = (char *)(Z_Malloc(9 * sizeof(char), PU_STATIC, NULL)); lump_p->longname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->longname, fileinfo->name, 8); strncpy(lump_p->longname, fileinfo->name, 8);
lump_p->longname[8] = '\0'; lump_p->longname[8] = '\0';
lump_p->longnamelength = lump_p->namelength; lump_p->longnamelength = lump_p->namelength;
lump_p->hash.longname = lump_p->hash.name;*/ lump_p->hash.longname = lump_p->hash.name;
// Allocate the lump's full name. // Allocate the lump's full name.
lump_p->fullname = (char *)(Z_Malloc(9 * sizeof(char), PU_STATIC, NULL)); lump_p->fullname = Z_Malloc(9 * sizeof(char), PU_STATIC, NULL);
strncpy(lump_p->fullname, fileinfo->name, 8); strncpy(lump_p->fullname, fileinfo->name, 8);
lump_p->fullname[8] = '\0'; lump_p->fullname[8] = '\0';
lump_p->fullnamelength = lump_p->namelength; lump_p->fullnamelength = lump_p->namelength;
//lump_p->hash.fullname = lump_p->hash.name; lump_p->hash.fullname = lump_p->hash.name;
} }
*nlmp = numlumps; *nlmp = numlumps;
@@ -566,24 +540,24 @@ static boolean ResFindSignature(FILE* handle, const char endPat[], UINT32 startp
int c; int c;
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
size_t len = (size_t)(ftell(handle)); size_t len = ftell(handle);
fseek(handle, startpos, SEEK_SET); fseek(handle, startpos, SEEK_SET);
size_t remaining = (size_t)(len - startpos); size_t remaining = len - startpos;
size_t chunkpos = (size_t)(startpos); size_t chunkpos = startpos;
s = endPat; s = endPat;
//128k buffers //128k buffers
size_t buffer_size = min(128 * 1024 * sizeof(char), remaining); size_t buffer_size = min(128 * 1024 * sizeof(char), remaining);
CLEANUP(pfree) char* buffer = (char *)(malloc(buffer_size)); CLEANUP(pfree) char* buffer = (char*)(malloc(buffer_size));
size_t bytes_read = 0; size_t bytes_read = 0;
while ((bytes_read = fread(buffer, 1, buffer_size, handle)) > 0) while ((bytes_read = fread(buffer, 1, buffer_size, handle)) > 0)
{ {
for (size_t i = 0; i < bytes_read; i++) for (size_t i = 0; i < bytes_read; i++)
{ {
c = (int)(buffer[i]); c = (int)buffer[i];
if (*s != c && s > endPat) // No match? if (*s != c && s > endPat) // No match?
s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array. s = endPat; // We "reset" the counter by sending the s pointer back to the start of the array.
@@ -595,7 +569,7 @@ static boolean ResFindSignature(FILE* handle, const char endPat[], UINT32 startp
if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature. if (*s == 0x00) // The array pointer has reached the key char which marks the end. It means we have matched the signature.
{ {
//the original function would leave the FILE* seeked to the end of the match //the original function would leave the FILE* seeked to the end of the match
size_t foundpos = (size_t)(chunkpos + i + 1); size_t foundpos = chunkpos + i + 1;
fseek(handle, foundpos, SEEK_SET); fseek(handle, foundpos, SEEK_SET);
return true; return true;
} }
@@ -672,7 +646,7 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp)
// Contains entry number (number of lumps), and central directory start offset. // Contains entry number (number of lumps), and central directory start offset.
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
const long startpos = ftell(handle) - (22 + 65536); const long startpos = (ftell(handle) - (22 + 65536));
if (!ResFindSignature(handle, pat_end, max(0l, startpos))) if (!ResFindSignature(handle, pat_end, max(0l, startpos)))
{ {
CONS_Alert(CONS_ERROR, "Missing central directory\n"); CONS_Alert(CONS_ERROR, "Missing central directory\n");
@@ -688,11 +662,11 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp)
numlumps = SHORT(zend.entries); numlumps = SHORT(zend.entries);
lump_p = lumpinfo = (lumpinfo_t *)(Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL)); lump_p = lumpinfo = Z_Malloc(numlumps * sizeof (*lumpinfo), PU_STATIC, NULL);
fseek(handle, LONG(zend.cdiroffset), SEEK_SET); fseek(handle, LONG(zend.cdiroffset), SEEK_SET);
CLEANUP(Z_Pfree) char *cdir = (char *)(Z_Malloc(LONG(zend.cdirsize), PU_STATIC, &cdir)); CLEANUP(Z_Pfree) char *cdir = Z_Malloc(LONG(zend.cdirsize), PU_STATIC, &cdir);
if (fread(cdir, 1, LONG(zend.cdirsize), handle) < (UINT32)(LONG(zend.cdirsize))) if (fread(cdir, 1, LONG(zend.cdirsize), handle) < (UINT32)(LONG(zend.cdirsize)))
{ {
@@ -705,7 +679,7 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp)
for (i = 0; i < numlumps; i++, lump_p++) for (i = 0; i < numlumps; i++, lump_p++)
{ {
zentry_t *zentry = (zentry_t *)(cdir + offset); zentry_t *zentry = (zentry_t*)(cdir + offset);
char* fullname; char* fullname;
char* trimname; char* trimname;
char* dotpos; char* dotpos;
@@ -721,9 +695,8 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp)
lump_p->disksize = LONG(zentry->compsize); lump_p->disksize = LONG(zentry->compsize);
lump_p->size = LONG(zentry->size); lump_p->size = LONG(zentry->size);
fullname = (char *)(malloc(SHORT(zentry->namelen) + 1)); fullname = (char*)(malloc(SHORT(zentry->namelen) + 1));
strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1);
fullname[zentry->namelen] = 0;
// Strip away file address and extension for the 8char name. // Strip away file address and extension for the 8char name.
if ((trimname = strrchr(fullname, '/')) != NULL) if ((trimname = strrchr(fullname, '/')) != NULL)
@@ -739,15 +712,15 @@ static lumpinfo_t* ResGetLumpsZip(FILE* handle, UINT16* nlmp)
lump_p->namelength = strlen(lump_p->name); lump_p->namelength = strlen(lump_p->name);
lump_p->hash.name = W_HashLumpName(lump_p->name); lump_p->hash.name = W_HashLumpName(lump_p->name);
/*lump_p->longname = (char *)(Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL)); lump_p->longname = Z_Calloc(dotpos - trimname + 1, PU_STATIC, NULL);
strlcpy(lump_p->longname, trimname, dotpos - trimname + 1); strlcpy(lump_p->longname, trimname, dotpos - trimname + 1);
lump_p->longnamelength = strlen(lump_p->longname); lump_p->longnamelength = strlen(lump_p->longname);
lump_p->hash.longname = W_HashLumpName(lump_p->longname);*/ lump_p->hash.longname = W_HashLumpName(lump_p->longname);
lump_p->fullname = (char *)(Z_Calloc(SHORT(zentry->namelen) + 1, PU_STATIC, NULL)); lump_p->fullname = (char*)(Z_Calloc(SHORT(zentry->namelen) + 1, PU_STATIC, NULL));
strncpy(lump_p->fullname, fullname, SHORT(zentry->namelen)); strncpy(lump_p->fullname, fullname, SHORT(zentry->namelen));
lump_p->fullnamelength = zentry->namelen; lump_p->fullnamelength = zentry->namelen;
//lump_p->hash.fullname = W_HashLumpName(lump_p->fullname); lump_p->hash.fullname = W_HashLumpName(lump_p->fullname);
switch(SHORT(zentry->compression)) switch(SHORT(zentry->compression))
{ {
@@ -922,19 +895,17 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup)
// //
// link wad file to search files // link wad file to search files
// //
wadfile = (wadfile_t *)(Z_Calloc(sizeof (*wadfile), PU_STATIC, NULL)); wadfile = Z_Calloc(sizeof (*wadfile), PU_STATIC, NULL);
wadfile->filename = Z_StrDup(filename); wadfile->filename = Z_StrDup(filename);
wadfile->handle = handle; wadfile->handle = handle;
wadfile->numlumps = (UINT16)(numlumps); wadfile->numlumps = (UINT16)numlumps;
wadfile->lumpinfo = lumpinfo; wadfile->lumpinfo = lumpinfo;
wadfile->important = important; wadfile->important = important;
fseek(handle, 0, SEEK_END); fseek(handle, 0, SEEK_END);
wadfile->filesize = (unsigned)(ftell(handle)); wadfile->filesize = (unsigned)ftell(handle);
wadfile->type = type; wadfile->type = type;
wadfile->startfolders = (FolderCache *)malloc(sizeof(FolderCache)); wadfile->startfolders = M_AATreeAlloc(AATREE_STRING);
folder_map_init(&wadfile->startfolders->map); wadfile->endfolders = M_AATreeAlloc(AATREE_STRING);
wadfile->endfolders = (FolderCache *)malloc(sizeof(FolderCache));
folder_map_init(&wadfile->endfolders->map);
// already generated, just copy it over // already generated, just copy it over
memcpy(&wadfile->md5sum, &md5sum, 16); memcpy(&wadfile->md5sum, &md5sum, 16);
@@ -959,7 +930,7 @@ UINT16 W_InitFile(const char *filename, boolean local, boolean startup)
#ifdef HWRENDER #ifdef HWRENDER
// Read shaders from file // Read shaders from file
if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED))
HWR_LoadCustomShadersFromFile(numwadfiles - 1, (boolean)(type == RET_PK3)); HWR_LoadCustomShadersFromFile(numwadfiles - 1, (type == RET_PK3));
#endif #endif
// TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now. // TODO: HACK ALERT - Load Lua & SOC stuff right here. I feel like this should be out of this place, but... Let's stick with this for now.
@@ -1059,7 +1030,7 @@ INT32 W_AddAutoloadedLocalFiles(char **filenames)
/** Make sure a lump number is valid. /** Make sure a lump number is valid.
* Compiles away to nothing if PARANOIA is not defined. * Compiles away to nothing if PARANOIA is not defined.
*/ */
static inline boolean TestValidLump(UINT16 wad, UINT16 lump) static boolean TestValidLump(UINT16 wad, UINT16 lump)
{ {
I_Assert(wad < MAX_WADFILES); I_Assert(wad < MAX_WADFILES);
if (!wadfiles[wad]) // make sure the wad file exists if (!wadfiles[wad]) // make sure the wad file exists
@@ -1082,7 +1053,7 @@ const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump)
const char *W_CheckNameForNum(lumpnum_t lumpnum) const char *W_CheckNameForNum(lumpnum_t lumpnum)
{ {
return W_CheckNameForNumPwad(WADFILENUM(lumpnum), LUMPNUM(lumpnum)); return W_CheckNameForNumPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum));
} }
// //
@@ -1136,7 +1107,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
// Should be the only version, but that's not possible until we fix // Should be the only version, but that's not possible until we fix
// all the instances of non null-terminated strings in the codebase... // all the instances of non null-terminated strings in the codebase...
// //
/*UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; UINT16 i;
UINT32 hash; UINT32 hash;
@@ -1168,46 +1139,43 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
// not found. // not found.
return INT16_MAX; return INT16_MAX;
}*/ }
UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 marker; UINT16 marker;
marker = W_CheckNumForNamePwad(name, wad, startlump); marker = W_CheckNumForNamePwad(name, wad, startlump);
if (marker != INT16_MAX) if (marker != INT16_MAX)
marker++; // Do not count the first marker marker++; // Do not count the first marker
return marker; return marker;
} }
// Look for the first lump from a folder. // Look for the first lump from a folder.
UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; size_t name_length;
size_t namelen; INT32 i;
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
name_length = strlen(name);
folder_map_itr it = folder_map_get(&wadfiles[wad]->startfolders->map, name); void *val = M_AATreeGetString(wadfiles[wad]->startfolders, name);
if (!folder_map_is_end(it)) if (val != NULL)
return it.data->val; return (uintptr_t)val;
namelen = strlen(name);
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (strnicmp(name, lump_p->fullname, namelen) == 0) if (strnicmp(name, lump_p->fullname, name_length) == 0)
{ {
/* SLADE is special and puts a single directory entry. Skip that. */ /* SLADE is special and puts a single directory entry. Skip that. */
if (lump_p->fullnamelength == namelen) if (strlen(lump_p->fullname) == name_length)
i++; i++;
folder_map_insert(&wadfiles[wad]->startfolders->map, strdup(name), i); M_AATreeSetString(wadfiles[wad]->startfolders, name, (void *)(uintptr_t)i);
return i; return i;
} }
} }
folder_map_insert(&wadfiles[wad]->startfolders->map, strdup(name), INT16_MAX); M_AATreeSetString(wadfiles[wad]->startfolders, name, (void *)INT16_MAX);
return INT16_MAX; return INT16_MAX;
} }
@@ -1216,23 +1184,21 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum
// Returns the position of the lumpinfo entry. // Returns the position of the lumpinfo entry.
UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; INT32 i;
size_t namelen;
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
size_t name_length = strlen(name);
folder_map_itr it = folder_map_get(&wadfiles[wad]->endfolders->map, name); void *val = M_AATreeGetString(wadfiles[wad]->endfolders, name);
if (!folder_map_is_end(it)) if (val != NULL)
return it.data->val; return (uintptr_t)val;
namelen = strlen(name);
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (strnicmp(name, lump_p->fullname, namelen)) if (strnicmp(name, lump_p->fullname, name_length))
break; break;
} }
folder_map_insert(&wadfiles[wad]->endfolders->map, strdup(name), i); M_AATreeSetString(wadfiles[wad]->endfolders, name, (void *)(uintptr_t)i);
return i; return i;
} }
@@ -1240,15 +1206,13 @@ UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump)
// Returns lump position in PK3's lumpinfo, or INT16_MAX if not found. // Returns lump position in PK3's lumpinfo, or INT16_MAX if not found.
UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; INT32 i;
size_t namelen;
lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump; lumpinfo_t *lump_p = wadfiles[wad]->lumpinfo + startlump;
size_t name_length = strlen(name);
namelen = strlen(name);
for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++) for (i = startlump; i < wadfiles[wad]->numlumps; i++, lump_p++)
{ {
if (!strnicmp(name, lump_p->fullname, namelen)) if (!strnicmp(name, lump_p->fullname, name_length))
{ {
return i; return i;
} }
@@ -1258,19 +1222,61 @@ UINT16 W_CheckNumForFullNamePK3(const char *name, UINT16 wad, UINT16 startlump)
return INT16_MAX; return INT16_MAX;
} }
FUNCINLINE static ATTRINLINE lumpnum_t CheckLumpInCache(const char *name) static lumpnum_t CheckLumpInCache(const char *name, boolean longname)
{ {
lumpnum_map_itr it = lumpnum_map_get(&lumpnumcache, name); if (longname)
if (!lumpnum_map_is_end(it)) {
return it.data->val; UINT32 hash = quickncasehash(name, 32);
// Loop backwards so that we check most recent entries first
for (INT32 i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{
if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].hash == hash
&& fasticmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name))
{
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum;
}
}
}
else
{
UINT32 hash = quickncasehash(name, 8);
// Loop backwards so that we check most recent entries first
for (INT32 i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{
if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].hash == hash
&& lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname[8] == '\0'
&& strnicmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0)
{
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum;
}
}
}
return LUMPERROR; return LUMPERROR;
} }
FUNCINLINE static ATTRINLINE void AddLumpToCache(lumpnum_t lumpnum, const char *name) static void AddLumpToCache(lumpnum_t lumpnum, const char *name, boolean longname)
{ {
I_Assert(strlen(name) <= 8); // we dont have longnames, so assume this is a non terminated string if (longname && strlen(name) >= LUMPNUMCACHENAME)
lumpnum_map_insert(&lumpnumcache, strdup(name), lumpnum); return;
lumpnumcacheindex = (lumpnumcacheindex + 1) & (LUMPNUMCACHESIZE - 1);
memset(lumpnumcache[lumpnumcacheindex].lumpname, '\0', LUMPNUMCACHENAME);
if (longname)
{
strlcpy(lumpnumcache[lumpnumcacheindex].lumpname, name, LUMPNUMCACHENAME);
lumpnumcache[lumpnumcacheindex].hash = quickncasehash(name, LUMPNUMCACHENAME);
}
else
{
strncpy(lumpnumcache[lumpnumcacheindex].lumpname, name, 8);
lumpnumcache[lumpnumcacheindex].hash = quickncasehash(name, 8);
}
lumpnumcache[lumpnumcacheindex].lumpnum = lumpnum;
} }
// //
@@ -1286,14 +1292,14 @@ lumpnum_t W_CheckNumForName(const char *name)
return LUMPERROR; return LUMPERROR;
// Check the lumpnumcache first. // Check the lumpnumcache first.
lumpnum_t cachenum = CheckLumpInCache(name); lumpnum_t cachenum = CheckLumpInCache(name, false);
if (cachenum != LUMPERROR) if (cachenum != LUMPERROR)
return cachenum; return cachenum;
// scan wad files backwards so patch lump files take precedence // scan wad files backwards so patch lump files take precedence
for (i = numwadfiles - 1; i >= 0; i--) for (i = numwadfiles - 1; i >= 0; i--)
{ {
check = W_CheckNumForNamePwad(name, (UINT16)(i), 0); check = W_CheckNumForNamePwad(name, (UINT16)i, 0);
if (check != INT16_MAX) if (check != INT16_MAX)
break; //found it break; //found it
@@ -1307,7 +1313,7 @@ lumpnum_t W_CheckNumForName(const char *name)
{ {
// Update the cache. // Update the cache.
lumpnum_t lumpnum = (i << 16) | check; lumpnum_t lumpnum = (i << 16) | check;
AddLumpToCache(lumpnum, name); AddLumpToCache(lumpnum, name, false);
return lumpnum; return lumpnum;
} }
@@ -1319,7 +1325,7 @@ lumpnum_t W_CheckNumForName(const char *name)
// Should be the only version, but that's not possible until we fix // Should be the only version, but that's not possible until we fix
// all the instances of non null-terminated strings in the codebase... // all the instances of non null-terminated strings in the codebase...
// //
/*lumpnum_t W_CheckNumForLongName(const char *name) lumpnum_t W_CheckNumForLongName(const char *name)
{ {
INT32 i; INT32 i;
lumpnum_t check = INT16_MAX; lumpnum_t check = INT16_MAX;
@@ -1328,14 +1334,14 @@ lumpnum_t W_CheckNumForName(const char *name)
return LUMPERROR; return LUMPERROR;
// Check the lumpnumcache first. // Check the lumpnumcache first.
lumpnum_t cachenum = CheckLumpInCache(name); lumpnum_t cachenum = CheckLumpInCache(name, true);
if (cachenum != LUMPERROR) if (cachenum != LUMPERROR)
return cachenum; return cachenum;
// scan wad files backwards so patch lump files take precedence // scan wad files backwards so patch lump files take precedence
for (i = numwadfiles - 1; i >= 0; i--) for (i = numwadfiles - 1; i >= 0; i--)
{ {
check = W_CheckNumForLongNamePwad(name, (UINT16)(i), 0); check = W_CheckNumForLongNamePwad(name, (UINT16)i, 0);
if (check != INT16_MAX) if (check != INT16_MAX)
break; //found it break; //found it
@@ -1349,11 +1355,11 @@ lumpnum_t W_CheckNumForName(const char *name)
{ {
// Update the cache. // Update the cache.
lumpnum_t lumpnum = (i << 16) | check; lumpnum_t lumpnum = (i << 16) | check;
AddLumpToCache(lumpnum, name); AddLumpToCache(lumpnum, name, true);
return lumpnum; return lumpnum;
} }
}*/ }
// //
// W_GetNumForName // W_GetNumForName
@@ -1378,7 +1384,7 @@ lumpnum_t W_GetNumForName(const char *name)
// Should be the only version, but that's not possible until we fix // Should be the only version, but that's not possible until we fix
// all the instances of non null-terminated strings in the codebase... // all the instances of non null-terminated strings in the codebase...
// //
/*lumpnum_t W_GetNumForLongName(const char *name) lumpnum_t W_GetNumForLongName(const char *name)
{ {
lumpnum_t i; lumpnum_t i;
@@ -1388,7 +1394,7 @@ lumpnum_t W_GetNumForName(const char *name)
I_Error("W_GetNumForLongName: %s not found!\n", name); I_Error("W_GetNumForLongName: %s not found!\n", name);
return i; return i;
}*/ }
// //
// W_CheckNumForNameInBlock // W_CheckNumForNameInBlock
@@ -1405,49 +1411,32 @@ lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, con
{ {
if (wadfiles[i]->type == RET_WAD) if (wadfiles[i]->type == RET_WAD)
{ {
bsid = W_CheckNumForNamePwad(blockstart, (UINT16)(i), 0); bsid = W_CheckNumForNamePwad(blockstart, (UINT16)i, 0);
if (bsid == INT16_MAX) if (bsid == INT16_MAX)
continue; // Start block doesn't exist? continue; // Start block doesn't exist?
beid = W_CheckNumForNamePwad(blockend, (UINT16)(i), 0); beid = W_CheckNumForNamePwad(blockend, (UINT16)i, 0);
if (beid == INT16_MAX) if (beid == INT16_MAX)
continue; // End block doesn't exist? continue; // End block doesn't exist?
check = W_CheckNumForNamePwad(name, (UINT16)(i), bsid); check = W_CheckNumForNamePwad(name, (UINT16)i, bsid);
if (check < beid) if (check < beid)
return (i << 16)+check; // found it, in our constraints return (i<<16)+check; // found it, in our constraints
} }
} }
return LUMPERROR; return LUMPERROR;
} }
// Used by Lua. Case sensitive lump checking, quickly... // Used by Lua. Case sensitive lump checking, quickly...
UINT8 W_LumpExists(const char *name) UINT8 W_LumpExists(const char *name)
{ {
INT32 i, j; INT32 i,j;
UINT32 hash;
size_t namelen;
// Check the lumpnumcache first.
lumpnum_t cachenum = CheckLumpInCache(name);
if (cachenum != LUMPERROR)
return true;
namelen = strlen(name);
hash = W_HashLumpName(name);
for (i = numwadfiles - 1; i >= 0; i--) for (i = numwadfiles - 1; i >= 0; i--)
{ {
lumpinfo_t *lump_p = wadfiles[i]->lumpinfo; lumpinfo_t *lump_p = wadfiles[i]->lumpinfo;
for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p) for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p)
{ if (fastcmp(lump_p->name, name))
if (lump_p->namelength == namelen
&& lump_p->hash.name == hash
&& fastcmp(lump_p->name, name))
return true; return true;
}
} }
return false; return false;
} }
@@ -1607,13 +1596,13 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
fseek(handle, (long)(l->position + offset), SEEK_SET); fseek(handle, (long)(l->position + offset), SEEK_SET);
// But let's not copy it yet. We support different compression formats on lumps, so we need to take that into account. // But let's not copy it yet. We support different compression formats on lumps, so we need to take that into account.
switch (wadfiles[wad]->lumpinfo[lump].compression) switch(wadfiles[wad]->lumpinfo[lump].compression)
{ {
case CM_NOCOMPRESSION: // If it's uncompressed, we directly write the data into our destination, and return the bytes read. case CM_NOCOMPRESSION: // If it's uncompressed, we directly write the data into our destination, and return the bytes read.
#ifdef NO_PNG_LUMPS #ifdef NO_PNG_LUMPS
{ {
size_t bytesread = fread(dest, 1, size, handle); size_t bytesread = fread(dest, 1, size, handle);
ErrorIfPNG((UINT8 *)(dest), bytesread, wadfiles[wad]->filename, l->fullname); ErrorIfPNG((UINT8 *)dest, bytesread, wadfiles[wad]->filename, l->fullname);
return bytesread; return bytesread;
} }
#else #else
@@ -1626,8 +1615,8 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
char *decData; // Lump's decompressed real data. char *decData; // Lump's decompressed real data.
size_t retval; // Helper var, lzf_decompress returns 0 when an error occurs. size_t retval; // Helper var, lzf_decompress returns 0 when an error occurs.
rawData = (char *)(Z_Malloc(l->disksize, PU_STATIC, NULL)); rawData = Z_Malloc(l->disksize, PU_STATIC, NULL);
decData = (char *)(Z_Malloc(l->size, PU_STATIC, NULL)); decData = Z_Malloc(l->size, PU_STATIC, NULL);
if (fread(rawData, 1, l->disksize, handle) < l->disksize) if (fread(rawData, 1, l->disksize, handle) < l->disksize)
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
@@ -1654,7 +1643,7 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
Z_Free(rawData); Z_Free(rawData);
Z_Free(decData); Z_Free(decData);
#ifdef NO_PNG_LUMPS #ifdef NO_PNG_LUMPS
ErrorIfPNG((UINT8 *)(dest), size, wadfiles[wad]->filename, l->fullname); ErrorIfPNG((UINT8 *)dest, size, wadfiles[wad]->filename, l->fullname);
#endif #endif
return size; return size;
#else #else
@@ -1674,8 +1663,8 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
unsigned long rawSize = l->disksize; unsigned long rawSize = l->disksize;
unsigned long decSize = size; unsigned long decSize = size;
rawData = (UINT8 *)(Z_Malloc(rawSize, PU_STATIC, NULL)); rawData = Z_Malloc(rawSize, PU_STATIC, NULL);
decData = (UINT8 *)(dest); decData = dest;
if (fread(rawData, 1, rawSize, handle) < rawSize) if (fread(rawData, 1, rawSize, handle) < rawSize)
I_Error("wad %d, lump %d: cannot read compressed data", wad, lump); I_Error("wad %d, lump %d: cannot read compressed data", wad, lump);
@@ -1711,7 +1700,7 @@ size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, si
Z_Free(rawData); Z_Free(rawData);
#ifdef NO_PNG_LUMPS #ifdef NO_PNG_LUMPS
ErrorIfPNG((UINT8 *)(dest), size, wadfiles[wad]->filename, l->fullname); ErrorIfPNG((UINT8 *)dest, size, wadfiles[wad]->filename, l->fullname);
#endif #endif
return size; return size;
} }
@@ -1899,7 +1888,7 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0); W_ReadLumpHeaderPwad(wad, lump, lumpdata, 0, 0);
dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]); dest = Z_Calloc(sizeof(patch_t), tag, &lumpcache[lump]);
Patch_Create((softwarepatch_t *)(lumpdata), len, dest); Patch_Create((softwarepatch_t*)lumpdata, len, dest);
Z_Free(lumpdata); Z_Free(lumpdata);
} }
@@ -1921,7 +1910,7 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
if (!TestValidLump(wad, lump)) if (!TestValidLump(wad, lump))
return NULL; return NULL;
patch = (patch_t *)(W_CacheSoftwarePatchNumPwad(wad, lump, tag)); patch = (patch_t *)W_CacheSoftwarePatchNumPwad(wad, lump, tag);
if (patch == NULL) if (patch == NULL)
return NULL; return NULL;
@@ -1932,7 +1921,7 @@ void *W_CachePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag)
Patch_CreateGL(patch); Patch_CreateGL(patch);
#endif #endif
return (void*)(patch); return (void *)patch;
} }
void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag) void *W_CachePatchNum(lumpnum_t lumpnum, INT32 tag)
@@ -1950,20 +1939,17 @@ void *W_GetCachedPatchNumPwad(UINT16 wad, UINT16 lump)
#ifdef ROTSPRITE #ifdef ROTSPRITE
// Caches a rotsprite for patch rotation. // Caches a rotsprite for patch rotation.
void *W_GetCachedRotPatchPwad(UINT16 wad, UINT16 lump) void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum)
{ {
if (!TestValidLump(wad, lump)) lumpcache_t *rotcache = wadfiles[wadnum]->rotcache;
return NULL;
lumpcache_t *rotcache = wadfiles[wad]->rotcache; if (!rotcache[lumpnum])
if (!rotcache[lump])
{ {
rotsprite_t *rspr = RotatedPatch_Create(ROTANGLES); rotsprite_t *rspr = RotatedPatch_Create(ROTANGLES);
Z_SetUser(rspr, (void**)(&rotcache[lump])); Z_SetUser(rspr, (void **)(&rotcache[lumpnum]));
} }
return (void*)(rotcache[lump]); return (void *)(rotcache[lumpnum]);
} }
#endif // ROTSPRITE #endif // ROTSPRITE
@@ -1976,7 +1962,7 @@ void W_UnlockCachedPatch(void *patch)
// have different lifetimes from software's. // have different lifetimes from software's.
#ifdef HWRENDER #ifdef HWRENDER
if (rendermode == render_opengl) if (rendermode == render_opengl)
HWR_UnlockCachedPatch((GLPatch_t *)(((patch_t *)(patch))->hardware)); HWR_UnlockCachedPatch((GLPatch_t *)((patch_t *)patch)->hardware);
else else
#endif #endif
Z_ChangeTag(patch, PU_PATCH); Z_ChangeTag(patch, PU_PATCH);
@@ -2011,7 +1997,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
if (rotationangle < 1 || rotationangle >= ROTANGLES) if (rotationangle < 1 || rotationangle >= ROTANGLES)
return W_CachePatchNum(num, tag); return W_CachePatchNum(num, tag);
rspr = (rotsprite_t *)(W_GetCachedRotPatchPwad(WADFILENUM(num), LUMPNUM(num))); rspr = (rotsprite_t *)W_GetCachedRotPatchPwad(WADFILENUM(num),LUMPNUM(num));
if (rspr == NULL) if (rspr == NULL)
return W_CachePatchNum(W_GetNumForName("MISSING"), tag); return W_CachePatchNum(W_GetNumForName("MISSING"), tag);
@@ -2020,7 +2006,7 @@ void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag)
{ {
INT32 xpivot = 0, ypivot = 0; INT32 xpivot = 0, ypivot = 0;
ptr = (patch_t *)(W_CachePatchNum(num, PU_PATCH)); ptr = (patch_t *)W_CachePatchNum(num, PU_PATCH);
if (ptr == NULL) if (ptr == NULL)
return W_CachePatchNum(W_GetNumForName("MISSING"), tag); return W_CachePatchNum(W_GetNumForName("MISSING"), tag);
@@ -2213,7 +2199,7 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status)
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
file_size = ftell(fp); file_size = ftell(fp);
const long startpos = file_size - (22 + 65536); const long startpos = (file_size - (22 + 65536));
if (!ResFindSignature(fp, pat_end, max(0l, startpos))) if (!ResFindSignature(fp, pat_end, max(0l, startpos)))
return true; return true;
@@ -2227,7 +2213,7 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status)
fseek(fp, LONG(zend.cdiroffset), SEEK_SET); fseek(fp, LONG(zend.cdiroffset), SEEK_SET);
CLEANUP(pfree) char *cdir = (char *)(malloc(LONG(zend.cdirsize))); CLEANUP(pfree) char *cdir = (char*)(malloc(LONG(zend.cdirsize)));
if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize)))
{ {
@@ -2238,7 +2224,7 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status)
for (i = 0; i < numlumps; i++) for (i = 0; i < numlumps; i++)
{ {
zentry_t *zentry = (zentry_t *)(cdir + offset); zentry_t *zentry = (zentry_t*)(cdir + offset);
char* fullname; char* fullname;
char* trimname; char* trimname;
char* dotpos; char* dotpos;
@@ -2250,9 +2236,8 @@ static int W_VerifyPK3(FILE *fp, lumpchecklist_t *checklist, boolean status)
if (verified == true) if (verified == true)
{ {
fullname = (char *)(malloc(SHORT(zentry->namelen) + 1)); fullname = (char*)(malloc(SHORT(zentry->namelen) + 1));
strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1);
fullname[zentry->namelen] = 0;
// Strip away file address and extension for the 8char name. // Strip away file address and extension for the 8char name.
if ((trimname = strrchr(fullname, '/')) != NULL) if ((trimname = strrchr(fullname, '/')) != NULL)
@@ -2461,7 +2446,7 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
file_size = ftell(fp); file_size = ftell(fp);
const long startpos = file_size - (22 + 65536); const long startpos = (file_size - (22 + 65536));
if (!ResFindSignature(fp, pat_end, max(0l, startpos))) if (!ResFindSignature(fp, pat_end, max(0l, startpos)))
return true; return true;
@@ -2475,7 +2460,7 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
fseek(fp, LONG(zend.cdiroffset), SEEK_SET); fseek(fp, LONG(zend.cdiroffset), SEEK_SET);
CLEANUP(pfree) char *cdir = (char *)(malloc(LONG(zend.cdirsize))); CLEANUP(pfree) char *cdir = (char*)(malloc(LONG(zend.cdirsize)));
if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize))) if (fread(cdir, 1, LONG(zend.cdirsize), fp) < (UINT32)(LONG(zend.cdirsize)))
{ {
@@ -2486,7 +2471,7 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
for (i = 0; i < numlumps; i++) for (i = 0; i < numlumps; i++)
{ {
zentry_t *zentry = (zentry_t *)(cdir + offset); zentry_t *zentry = (zentry_t*)(cdir + offset);
CLEANUP(pfree) char* fullname = NULL; CLEANUP(pfree) char* fullname = NULL;
char* trimname; char* trimname;
char* dotpos; char* dotpos;
@@ -2496,9 +2481,8 @@ static int W_CheckPK3Contains(FILE *fp, lumpchecklist_t *checklist)
return false; return false;
} }
fullname = (char *)(malloc(SHORT(zentry->namelen) + 1)); fullname = (char*)(malloc(SHORT(zentry->namelen) + 1));
strncpy(fullname, (char *)(zentry + 1), SHORT(zentry->namelen)); strlcpy(fullname, (char*)(zentry + 1), SHORT(zentry->namelen) + 1);
fullname[zentry->namelen] = 0;
// Strip away file address and extension for the 8char name. // Strip away file address and extension for the 8char name.
if ((trimname = strrchr(fullname, '/')) != NULL) if ((trimname = strrchr(fullname, '/')) != NULL)
@@ -2634,14 +2618,14 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
size_t *vsizecache; size_t *vsizecache;
// Remember that we're assuming that the WAD will have a specific set of lumps in a specific order. // Remember that we're assuming that the WAD will have a specific set of lumps in a specific order.
UINT8 *wadData = (UINT8 *)(W_CacheLumpNum(lumpnum, PU_LEVEL)); UINT8 *wadData = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL));
if (wadData == NULL) if (wadData == NULL)
I_Error("vres_GetMap: Invalid WadData!\n"); I_Error("vres_GetMap: Invalid WadData!\n");
filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)(wadData))->infotableofs)); filelump_t *fileinfo = (filelump_t *)(wadData + LONG(((wadinfo_t *)wadData)->infotableofs));
i = LONG(((wadinfo_t *)(wadData))->numlumps); i = LONG(((wadinfo_t *)wadData)->numlumps);
vsizecache = (size_t *)(Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL)); vsizecache = (size_t*)(Z_Malloc(sizeof(size_t)*i, PU_LEVEL, NULL));
for (realentry = 0; realentry < i; realentry++) for (realentry = 0; realentry < i; realentry++)
{ {
@@ -2653,7 +2637,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
numlumps++; numlumps++;
} }
vlumps = (virtlump_t *)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL));
if (vlumps == NULL) if (vlumps == NULL)
I_Error("vres_GetMap: Out of memory!\n"); I_Error("vres_GetMap: Out of memory!\n");
@@ -2675,7 +2659,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
// Play it safe with the name in this case. // Play it safe with the name in this case.
memcpy(vlumps[i].name, name, 8); memcpy(vlumps[i].name, name, 8);
vlumps[i].name[8] = '\0'; vlumps[i].name[8] = '\0';
vlumps[i].data = (UINT8 *)( vlumps[i].data = (UINT8*)(
Z_Malloc(vlumps[i].size, PU_LEVEL, NULL) // This is memory inefficient, sorry about that. Z_Malloc(vlumps[i].size, PU_LEVEL, NULL) // This is memory inefficient, sorry about that.
); );
memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size);
@@ -2702,7 +2686,7 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
} }
numlumps++; numlumps++;
vlumps = (virtlump_t *)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL)); vlumps = (virtlump_t*)(Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL));
if (vlumps == NULL) if (vlumps == NULL)
I_Error("vres_GetMap: Out of memory!\n"); I_Error("vres_GetMap: Out of memory!\n");
@@ -2723,11 +2707,11 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum)
vlumps[i].size = W_LumpLength(lumpnum); vlumps[i].size = W_LumpLength(lumpnum);
memcpy(vlumps[i].name, name, 8); memcpy(vlumps[i].name, name, 8);
vlumps[i].name[8] = '\0'; vlumps[i].name[8] = '\0';
vlumps[i].data = (UINT8 *)(W_CacheLumpNum(lumpnum, PU_LEVEL)); vlumps[i].data = (UINT8*)(W_CacheLumpNum(lumpnum, PU_LEVEL));
} }
} }
vres = (virtres_t *)(Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL)); vres = (virtres_t*)(Z_Malloc(sizeof(virtres_t), PU_LEVEL, NULL));
vres->vlumps = vlumps; vres->vlumps = vlumps;
vres->numlumps = numlumps; vres->numlumps = numlumps;
+13 -11
View File
@@ -68,11 +68,11 @@ typedef struct
unsigned long position; // filelump_t filepos unsigned long position; // filelump_t filepos
unsigned long disksize; // filelump_t size unsigned long disksize; // filelump_t size
char name[9]; // filelump_t name[] e.g. "LongEntr" char name[9]; // filelump_t name[] e.g. "LongEntr"
//char *longname; // e.g. "LongEntryName" char *longname; // e.g. "LongEntryName"
char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension" char *fullname; // e.g. "Folder/Subfolder/LongEntryName.extension"
size_t namelength; // length of name size_t namelength; // length of name
//size_t longnamelength; // length of longname size_t longnamelength; // length of longname
size_t fullnamelength; // length of fullname size_t fullnamelength; // length of fullname
size_t size; // real (uncompressed) size size_t size; // real (uncompressed) size
@@ -80,8 +80,8 @@ typedef struct
struct { struct {
UINT32 name; // hash of name UINT32 name; // hash of name
//UINT32 longname; // hash of longname UINT32 longname; // hash of longname
//UINT32 fullname; // hash of fullname UINT32 fullname; // hash of fullname
} hash; } hash;
} lumpinfo_t; } lumpinfo_t;
@@ -126,6 +126,7 @@ typedef enum restype
RET_UNKNOWN, RET_UNKNOWN,
} restype_t; } restype_t;
typedef struct wadfile_s typedef struct wadfile_s
{ {
char *filename; char *filename;
@@ -136,8 +137,8 @@ typedef struct wadfile_s
#ifdef ROTSPRITE #ifdef ROTSPRITE
lumpcache_t *rotcache; // Cache rotsprites for rotating patches. lumpcache_t *rotcache; // Cache rotsprites for rotating patches.
#endif #endif
struct FolderCache *startfolders; aatree_t *startfolders;
struct FolderCache *endfolders; aatree_t *endfolders;
UINT16 numlumps; // this wad's number of resources UINT16 numlumps; // this wad's number of resources
FILE *handle; FILE *handle;
UINT32 filesize; // for network UINT32 filesize; // for network
@@ -154,7 +155,6 @@ extern wadfile_t *wadfiles[MAX_WADFILES];
// ========================================================================= // =========================================================================
void W_Startup(void);
void W_Shutdown(void); void W_Shutdown(void);
// Opens a WAD file. Returns the FILE * handle for the file, or NULL if not found or could not be opened // Opens a WAD file. Returns the FILE * handle for the file, or NULL if not found or could not be opened
@@ -174,11 +174,13 @@ INT32 W_AddAutoloadedLocalFiles(char **filenames);
#define W_FileHasFolders(wadfile) ((wadfile)->type == RET_PK3) #define W_FileHasFolders(wadfile) ((wadfile)->type == RET_PK3)
UINT32 W_HashLumpName(const char *name);
const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump); const char *W_CheckNameForNumPwad(UINT16 wad, UINT16 lump);
const char *W_CheckNameForNum(lumpnum_t lumpnum); const char *W_CheckNameForNum(lumpnum_t lumpnum);
UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump); // checks only in one pwad UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump); // checks only in one pwad
//UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump); UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump);
/* Find the first lump after F_START for instance. */ /* Find the first lump after F_START for instance. */
UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump); UINT16 W_CheckNumForMarkerStartPwad(const char *name, UINT16 wad, UINT16 startlump);
@@ -188,9 +190,9 @@ UINT16 W_CheckNumForFolderStartPK3(const char *name, UINT16 wad, UINT16 startlum
UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump); UINT16 W_CheckNumForFolderEndPK3(const char *name, UINT16 wad, UINT16 startlump);
lumpnum_t W_CheckNumForName(const char *name); lumpnum_t W_CheckNumForName(const char *name);
//lumpnum_t W_CheckNumForLongName(const char *name); lumpnum_t W_CheckNumForLongName(const char *name);
lumpnum_t W_GetNumForName(const char *name); // like W_CheckNumForName but I_Error on LUMPERROR lumpnum_t W_GetNumForName(const char *name); // like W_CheckNumForName but I_Error on LUMPERROR
//lumpnum_t W_GetNumForLongName(const char *name); lumpnum_t W_GetNumForLongName(const char *name);
lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, const char *blockend); lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, const char *blockend);
UINT8 W_LumpExists(const char *name); // Lua uses this. UINT8 W_LumpExists(const char *name); // Lua uses this.
UINT8 W_CheckMultipleLumps(const char* lump, ...); // variadic version of above lmao UINT8 W_CheckMultipleLumps(const char* lump, ...); // variadic version of above lmao
@@ -231,7 +233,7 @@ void *W_CacheSoftwarePatchNumPwad(UINT16 wad, UINT16 lump, INT32 tag);
void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag); void *W_CacheSoftwarePatchNum(lumpnum_t lumpnum, INT32 tag);
#ifdef ROTSPRITE #ifdef ROTSPRITE
void *W_GetCachedRotPatchPwad(UINT16 wad, UINT16 lump); // Get patch-based rotsprites from the cache. void *W_GetCachedRotPatchPwad(UINT16 wadnum, UINT16 lumpnum); // Get patch-based rotsprites from the cache.
void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag); void *W_CachePatchNameRotated(const char *name, INT32 rotationangle, INT32 tag);
#endif #endif
+15
View File
@@ -75,6 +75,8 @@ typedef struct memblock_s
#define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t) + ALIGNPAD) #define MEMORY(x) (void *)((uintptr_t)(x) + sizeof(memblock_t) + ALIGNPAD)
#define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - ALIGNPAD - sizeof(memblock_t)) #define MEMBLOCK(x) (memblock_t *)((uintptr_t)(x) - ALIGNPAD - sizeof(memblock_t))
static thread_handle_t main_thread;
// both the head and tail of the zone memory block list // both the head and tail of the zone memory block list
static memblock_t head; static memblock_t head;
@@ -108,6 +110,7 @@ static void Command_Memdump_f(void);
void Z_Init(void) void Z_Init(void)
{ {
size_t total, memfree; size_t total, memfree;
main_thread = I_GetCurrentThread();
memset(&head, 0x00, sizeof(head)); memset(&head, 0x00, sizeof(head));
@@ -143,6 +146,8 @@ void Z_Free(void *ptr)
{ {
memblock_t *block; memblock_t *block;
I_Assert(I_GetCurrentThread() == main_thread);
if (ptr == NULL) if (ptr == NULL)
return; return;
@@ -237,6 +242,8 @@ void *Z_Malloc(size_t size, INT32 tag, void *user)
memblock_t *block; memblock_t *block;
void *ptr; void *ptr;
I_Assert(I_GetCurrentThread() == main_thread);
#ifdef ZDEBUG2 #ifdef ZDEBUG2
CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line); CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line);
#endif #endif
@@ -300,6 +307,8 @@ void *Z_Calloc2(size_t size, INT32 tag, void *user, const char *file, INT32 line
void *Z_Calloc(size_t size, INT32 tag, void *user) void *Z_Calloc(size_t size, INT32 tag, void *user)
#endif #endif
{ {
I_Assert(I_GetCurrentThread() == main_thread);
#ifdef VALGRIND_MEMPOOL_ALLOC #ifdef VALGRIND_MEMPOOL_ALLOC
Z_calloc = true; Z_calloc = true;
#endif #endif
@@ -335,6 +344,8 @@ void *Z_Realloc(void *ptr, size_t size, INT32 tag, void *user)
memblock_t *block; memblock_t *block;
size_t copysize; size_t copysize;
I_Assert(I_GetCurrentThread() == main_thread);
#ifdef ZDEBUG2 #ifdef ZDEBUG2
CONS_Debug(DBG_MEMORY, "Z_Realloc %s:%d\n", file, line); CONS_Debug(DBG_MEMORY, "Z_Realloc %s:%d\n", file, line);
#endif #endif
@@ -414,6 +425,8 @@ void Z_FreeTags(INT32 lowtag, INT32 hightag)
{ {
memblock_t *block, *next; memblock_t *block, *next;
I_Assert(I_GetCurrentThread() == main_thread);
#ifdef ZDEBUG #ifdef ZDEBUG
Z_CheckHeap2(file, line); Z_CheckHeap2(file, line);
#else #else
@@ -447,6 +460,8 @@ void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *))
{ {
memblock_t *block, *next; memblock_t *block, *next;
I_Assert(I_GetCurrentThread() == main_thread);
if (!iterfunc) if (!iterfunc)
I_Error("Z_IterateTags: no iterator function was given"); I_Error("Z_IterateTags: no iterator function was given");