diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 729b5896a..4ce38953d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -228,6 +228,14 @@ set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL "Use statically linked OpenGL. NOT RECOMMENDED.") set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL "Enable OpenGL FBO Downsampling support.") +set(SRB2_CONFIG_DEDICATED OFF CACHE BOOL + "Build a dedicated server.") + +if(${SRB2_CONFIG_DEDICATED}) + set(SRB2_CONFIG_HAVE_GME NO) + set(SRB2_CONFIG_HAVE_OPENMPT NO) + set(SRB2_CONFIG_HWRENDER NO) +endif() ### use internal libraries? if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only @@ -554,7 +562,11 @@ add_definitions(-DCMAKECONFIG) # ${SRB2_BLUA_HEADERS} #) -add_subdirectory(sdl) +if(${SRB2_CONFIG_DEDICATED}) + add_subdirectory(dedicated) +else() + add_subdirectory(sdl) +endif() if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") diff --git a/src/Makefile b/src/Makefile index db2c717b6..8a0c94214 100644 --- a/src/Makefile +++ b/src/Makefile @@ -116,6 +116,8 @@ # SDL_CONFIG= - sdl-config command. # SDL_CFLAGS=, SDL_LDFLAGS= +NOBLUAJIT=1 + clean_targets=cleandep clean distclean info .PHONY : $(clean_targets) all diff --git a/src/Makefile.d/dedicated.mk b/src/Makefile.d/dedicated.mk index af7904887..698ea5531 100644 --- a/src/Makefile.d/dedicated.mk +++ b/src/Makefile.d/dedicated.mk @@ -13,7 +13,10 @@ ifdef MINGW libs+=-mconsole endif +ifndef NOTHREADS +opts+=-DHAVE_THREADS sources+=dedicated/i_threads.c +endif NOOPENMPT=1 NOGME=1 diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk index 3c8b4f256..9f2074d9d 100644 --- a/src/Makefile.d/sdl.mk +++ b/src/Makefile.d/sdl.mk @@ -14,7 +14,6 @@ sources+=$(call List,sdl/Sourcefile) opts+=-DDIRECTFULLSCREEN -DHAVE_SDL NOUPNP=1 -NOBLUAJIT=1 # FIXME: UNTESTED #ifdef PANDORA diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 71c8d7216..ea08ed792 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -302,14 +302,12 @@ consvar_t cv_verticallook[MAXSPLITSCREENPLAYERS] = { {"verticallook4", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL} }; -#if defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 consvar_t cv_usejoystick[MAXSPLITSCREENPLAYERS] = { {"use_joystick", "1", CV_SAVE|CV_CALL, NULL, I_InitJoystick1, 0, NULL, NULL, 0, 0, NULL}, {"use_joystick2", "2", CV_SAVE|CV_CALL, NULL, I_InitJoystick2, 0, NULL, NULL, 0, 0, NULL}, {"use_joystick3", "3", CV_SAVE|CV_CALL, NULL, I_InitJoystick3, 0, NULL, NULL, 0, 0, NULL}, {"use_joystick4", "4", CV_SAVE|CV_CALL, NULL, I_InitJoystick4, 0, NULL, NULL, 0, 0, NULL} }; -#endif #if defined (HAVE_SDL) consvar_t cv_joyscale[MAXSPLITSCREENPLAYERS] = { diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt new file mode 100644 index 000000000..36f670251 --- /dev/null +++ b/src/dedicated/CMakeLists.txt @@ -0,0 +1,108 @@ +# Declare dedicated interface sources + +target_sourcefile(c) + +target_sources(SRB2SDL2 PRIVATE) + +if(${CMAKE_SYSTEM} MATCHES Windows) + target_sources(SRB2SDL2 PRIVATE + ../win32/win_dbg.c + ../win32/Srb2win.rc) +endif() + +if(${CMAKE_SYSTEM} MATCHES Windows) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2legacy) +elseif(${CMAKE_SYSTEM} MATCHES Linux) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME lsrb2dlegacy) +else() + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2legacy) +endif() + +if(${CMAKE_SYSTEM} MATCHES Darwin) + find_library(CORE_LIB CoreFoundation) + target_link_libraries(SRB2SDL2 PRIVATE + ${CORE_LIB} + ${PNG_LIBRARIES} + ${ZLIB_LIBRARIES} + ) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") +else() + target_link_libraries(SRB2SDL2 PRIVATE + ${PNG_LIBRARIES} + ${ZLIB_LIBRARIES} + ) + + if(${CMAKE_SYSTEM} MATCHES Linux) + target_link_libraries(SRB2SDL2 PRIVATE + m + rt + ) + endif() +endif() + +#target_link_libraries(SRB2SDL2 PRIVATE SRB2Core) + +set_target_properties(SRB2SDL2 PROPERTIES VERSION ${SRB2_VERSION}) + +if(${CMAKE_SYSTEM} MATCHES Windows) + target_link_libraries(SRB2SDL2 PRIVATE + ws2_32 + ) + target_compile_options(SRB2SDL2 PRIVATE + -U_WINDOWS + ) +endif() + +target_include_directories(SRB2SDL2 PRIVATE + ${PNG_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIRS} +) + +target_compile_definitions(SRB2SDL2 PRIVATE + -DDEDICATED +) + +## strip debug symbols into separate file when using gcc +if(CMAKE_COMPILER_IS_GNUCC) + if(${CMAKE_BUILD_TYPE} MATCHES Debug) + message(STATUS "Will make separate debug symbols in *.debug") + add_custom_command(TARGET SRB2SDL2 POST_BUILD + COMMAND ${OBJCOPY} --only-keep-debug $ $.debug + COMMAND ${OBJCOPY} --strip-debug $ + COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ + ) + endif() +endif() + +#### Installation #### +if(${CMAKE_SYSTEM} MATCHES Darwin) + install(TARGETS SRB2SDL2 + BUNDLE DESTINATION . + ) +else() + install(TARGETS SRB2SDL2 SRB2SDL2 + RUNTIME DESTINATION . + ) +endif() + +# Mac bundle fixup +# HACK: THIS IS IMPORTANT! See the escaped \${CMAKE_INSTALL_PREFIX}? This +# makes it so that var is evaluated LATER during cpack, not right now! +# This fixes the quirk where the bundled libraries don't land in the final package +# https://cmake.org/pipermail/cmake/2011-March/043532.html +# +# HOWEVER: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} is NOT escaped, because that var +# is only available to us at this step. Read the link: ${CMAKE_INSTALL_PREFIX} at +# this current step points to the CMAKE build folder, NOT the folder that CPACK uses. +# Therefore, it makes sense to escape that var, but not the other. +if(${CMAKE_SYSTEM} MATCHES Darwin) + install(CODE " + include(BundleUtilities) + fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\" + \"\" + /Library/Frameworks + )" + ) +endif() + +set(SRB2_SDL2_AVAILABLE YES PARENT_SCOPE) diff --git a/src/dedicated/Sourcefile b/src/dedicated/Sourcefile new file mode 100644 index 000000000..176e60a96 --- /dev/null +++ b/src/dedicated/Sourcefile @@ -0,0 +1,7 @@ +i_system.c +i_main.c +i_video.c +i_sound.c +i_threads.c +dosstr.c +endtxt.c diff --git a/src/dedicated/dosstr.c b/src/dedicated/dosstr.c new file mode 100644 index 000000000..f9bbee9b4 --- /dev/null +++ b/src/dedicated/dosstr.c @@ -0,0 +1,38 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// This file is in the public domain. +// (Re)written by Graue in 2006. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief String uppercasing/lowercasing functions for non-DOS non-Win32 +/// systems + +#include "../doomtype.h" + +#ifndef HAVE_DOSSTR_FUNCS + +#include + +int strupr(char *n) +{ + while (*n != '\0') + { + *n = toupper(*n); + n++; + } + return 1; +} + +int strlwr(char *n) +{ + while (*n != '\0') + { + *n = tolower(*n); + n++; + } + return 1; +} + +#endif diff --git a/src/dedicated/endtxt.c b/src/dedicated/endtxt.c new file mode 100644 index 000000000..1e72ca9a8 --- /dev/null +++ b/src/dedicated/endtxt.c @@ -0,0 +1,234 @@ +/* + * Function to write the SRB2 end message text + * + * Copyright (C) 1998 by Udo Munk + * + * This code is provided AS IS and there are no guarantees, none. + * Feel free to share and modify. + */ +//----------------------------------------------------------------------------- +/// \file +/// \brief Support to show ENDOOM text +/// +/// Loads the lump ENDOOM, set up the console to print +/// out the colors and text + +#include +#include + +// need this 19990118 by Kin +#include "../doomdef.h" +#include "../w_wad.h" +#include "../z_zone.h" +#include "endtxt.h" +/** \brief The ShowEndTxt function + + + Prints out the ENDOOM the way DOOM.EXE/DOOM2.EXE did for Win32 or Linux/GNU + + \return void + + +*/ + +void ShowEndTxt(void) +{ + INT32 i; + UINT16 j, att = 0; + INT32 nlflag = 1; +#ifdef _WIN32 + HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD mode, bytesWritten; + CONSOLE_SCREEN_BUFFER_INFO backupcon; + COORD resizewin = {80,-1}; + CHAR let = 0; +#endif + UINT16 *ptext; + void *data; + lumpnum_t endoomnum = W_GetNumForName("ENDOOM"); + //char *col; + + /* if the xterm has more then 80 columns we need to add nl's */ + /* doesn't work, COLUMNS is not in the environment at this time ??? + col = I_getenv("COLUMNS"); + if (col) { + if (atoi(col) > 80) + nlflag++; + } + */ + + /* get the lump with the text */ + data = ptext = W_CacheLumpNum(endoomnum, PU_CACHE); + +#ifdef _WIN32 + if (co == INVALID_HANDLE_VALUE || GetFileType(co) != FILE_TYPE_CHAR || !GetConsoleMode(co, &mode)) // test if it a good handle + { + Z_Free(data); + return; + } + + backupcon.wAttributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE; // Just in case + GetConsoleScreenBufferInfo(co, &backupcon); //Store old state + resizewin.Y = backupcon.dwSize.Y; + if (backupcon.dwSize.X < resizewin.X) + SetConsoleScreenBufferSize(co, resizewin); + + for (i=1; i<=80*25; i++) // print 80x25 text and deal with the attributes too + { + j = (UINT16)(*ptext >> 8); // attribute first + let = (char)(*ptext & 0xff); // text second + if (j != att) // attribute changed? + { + att = j; // save current attribute + SetConsoleTextAttribute(co, j); //set fg and bg color for buffer + } + + WriteConsoleA(co, &let, 1, &bytesWritten, NULL); // now the text + + if (nlflag && !(i % 80) && backupcon.dwSize.X > resizewin.X) // do we need a nl? + { + att = backupcon.wAttributes; + SetConsoleTextAttribute(co, att); // all attributes off + WriteConsoleA(co, "\n", 1, &bytesWritten, NULL); // newline to console + } + ptext++; + } + SetConsoleTextAttribute(co, backupcon.wAttributes); // all attributes off +#else + /* print 80x25 text and deal with the attributes too */ + for (i=1; i<=80*25; i++) { + /* attribute first */ + /* attribute changed? */ + if ((j = *ptext >> 8) != att) { + /* save current attribute */ + att = j; + /* set new attribute, forground color first */ + printf("\033["); + switch (j & 0x0f) { + case 0: /* black */ + printf("30"); + break; + case 1: /* blue */ + printf("34"); + break; + case 2: /* green */ + printf("32"); + break; + case 3: /* cyan */ + printf("36"); + break; + case 4: /* red */ + printf("31"); + break; + case 5: /* magenta */ + printf("35"); + break; + case 6: /* brown */ + printf("33"); + break; + case 7: /* bright grey */ + printf("37"); + break; + case 8: /* dark grey */ + printf("1;30"); + break; + case 9: /* bright blue */ + printf("1;34"); + break; + case 10: /* bright green */ + printf("1;32"); + break; + case 11: /* bright cyan */ + printf("1;36"); + break; + case 12: /* bright red */ + printf("1;31"); + break; + case 13: /* bright magenta */ + printf("1;35"); + break; + case 14: /* yellow */ + printf("1;33"); + break; + case 15: /* white */ + printf("1;37"); + break; + } + printf("m"); + /* now background color */ + printf("\033["); + switch ((j >> 4) & 0x0f) { + case 0: /* black */ + printf("40"); + break; + case 1: /* blue */ + printf("44"); + break; + case 2: /* green */ + printf("42"); + break; + case 3: /* cyan */ + printf("46"); + break; + case 4: /* red */ + printf("41"); + break; + case 5: /* magenta */ + printf("45"); + break; + case 6: /* brown */ + printf("43"); + break; + case 7: /* bright grey */ + printf("47"); + break; + case 8: /* dark grey */ + printf("1;40"); + break; + case 9: /* bright blue */ + printf("1;44"); + break; + case 10: /* bright green */ + printf("1;42"); + break; + case 11: /* bright cyan */ + printf("1;46"); + break; + case 12: /* bright red */ + printf("1;41"); + break; + case 13: /* bright magenta */ + printf("1;45"); + break; + case 14: /* yellow */ + printf("1;43"); + break; + case 15: /* white */ + printf("1;47"); + break; + } + printf("m"); + } + + /* now the text */ + printf("%c",*ptext++ & 0xff); + + /* do we need a nl? */ + if (nlflag) + { + if (!(i % 80)) + { + printf("\033[0m"); + att = 0; + printf("\n"); + } + } + } + /* all attributes off */ + printf("\033[0m"); +#endif + if (nlflag) + printf("\n"); + + Z_Free(data); +} diff --git a/src/dedicated/endtxt.h b/src/dedicated/endtxt.h new file mode 100644 index 000000000..41f8e51ad --- /dev/null +++ b/src/dedicated/endtxt.h @@ -0,0 +1,24 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Support to show ENDOOM text + +#ifndef __ENDTXT__ +#define __ENDTXT__ + +void ShowEndTxt (void); + +#endif diff --git a/src/dedicated/i_main.c b/src/dedicated/i_main.c new file mode 100644 index 000000000..911e356d0 --- /dev/null +++ b/src/dedicated/i_main.c @@ -0,0 +1,238 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Copyright (C) 1998-2000 by DooM Legacy Team. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief Main program, simply calls D_SRB2Main and D_SRB2Loop, the high level loop. + +#include "../doomdef.h" +#include "../m_argv.h" +#include "../d_main.h" +#include "../m_misc.h" /* path shit */ +#include "../i_system.h" +#include "../d_clisrv.h" + +#if defined (__GNUC__) || defined (__unix__) +#include +#endif + +#ifdef __unix__ +#include +#endif + +#include "time.h" // For log timestamps + +#ifdef HAVE_TTF +#include "i_ttf.h" +#endif + +#ifdef HAVE_LIBBACKTRACE +#include + +struct backtrace_state *bt_state = NULL; +#endif + +#ifdef LOGMESSAGES +FILE *logstream = NULL; +char logfilename[1024]; +#endif + +#ifndef DOXYGEN +#ifndef O_TEXT +#define O_TEXT 0 +#endif + +#ifndef O_SEQUENTIAL +#define O_SEQUENTIAL 0 +#endif +#endif + +#ifdef _WIN32 +#ifndef _AMD64_ +#include "exchndl.h" +#define DRMINGW +#endif +#endif + +#if defined (_WIN32) +#include "../win32/win_dbg.h" +typedef BOOL (WINAPI *p_IsDebuggerPresent)(VOID); +#endif + +#ifdef _WIN32 +static void +ChDirToExe (void) +{ + CHAR path[MAX_PATH]; + if (GetModuleFileNameA(NULL, path, MAX_PATH) > 0) + { + strrchr(path, '\\')[0] = '\0'; + SetCurrentDirectoryA(path); + } +} +#endif + +/** \brief The main function + + \param argc number of arg + \param *argv string table + + \return int +*/ +#if defined (__GNUC__) && (__GNUC__ >= 4) +#pragma GCC diagnostic ignored "-Wmissing-noreturn" +#endif + +#ifdef LOGMESSAGES +static void InitLogging(void) +{ + const char *logdir = NULL; + time_t my_time; + struct tm * timeinfo; + const char *format; + const char *reldir; + int left; + boolean fileabs; +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + const char *link; +#endif + + logdir = D_Home(); + + my_time = time(NULL); + timeinfo = localtime(&my_time); + + if (M_CheckParm("-logfile") && M_IsNextParm()) + { + format = M_GetNextParm(); + fileabs = M_IsPathAbsolute(format); + } + else + { + format = "log-%Y-%m-%d_%H-%M-%S.txt"; + fileabs = false; + } + + if (fileabs) + { + strftime(logfilename, sizeof logfilename, format, timeinfo); + } + else + { + if (M_CheckParm("-logdir") && M_IsNextParm()) + reldir = M_GetNextParm(); + else + reldir = "logs"; + + if (M_IsPathAbsolute(reldir)) + { + left = snprintf(logfilename, sizeof logfilename, + "%s"PATHSEP, reldir); + } + else +#ifdef DEFAULTDIR + if (logdir) + { + left = snprintf(logfilename, sizeof logfilename, + "%s"PATHSEP DEFAULTDIR PATHSEP"%s"PATHSEP, logdir, reldir); + } + else +#endif/*DEFAULTDIR*/ + { + left = snprintf(logfilename, sizeof logfilename, + "."PATHSEP"%s"PATHSEP, reldir); + } + + strftime(&logfilename[left], sizeof logfilename - left, + format, timeinfo); + } + + M_MkdirEachUntil(logfilename, + M_PathParts(logdir) - 1, + M_PathParts(logfilename) - 1, 0755); + +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + logstream = fopen(logfilename, "w"); +#ifdef DEFAULTDIR + if (logdir) + link = va("%s/"DEFAULTDIR"/latest-log.txt", logdir); + else +#endif/*DEFAULTDIR*/ + link = "latest-log.txt"; + unlink(link); + if (symlink(logfilename, link) == -1) + { + I_OutputMsg("Error symlinking latest-log.txt: %s\n", strerror(errno)); + } +#else/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ + logstream = fopen("latest-log.txt", "wt+"); +#endif/*defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)*/ +} +#endif + +int main(int argc, char **argv) +{ + myargc = argc; + myargv = argv; /// \todo pull out path to exe from this string + + dedicated = true; + +#ifdef HAVE_LIBBACKTRACE + bt_state = backtrace_create_state( + argv[0], +#ifdef HAVE_THREADS + 1, +#else + 0, +#endif + NULL, + NULL + ); +#endif + +#ifdef _WIN32 + ChDirToExe(); +#endif + +#ifdef LOGMESSAGES + if (!M_CheckParm("-nolog")) + InitLogging(); +#endif/*LOGMESSAGES*/ + + //I_OutputMsg("I_StartupSystem() ...\n"); + I_StartupSystem(); +#if defined (_WIN32) + { +#ifdef DRMINGW + ExcHndlInit(); +#endif + } +#endif + + // startup SRB2 + CONS_Printf("Setting up SRB2Kart...\n"); + D_SRB2Main(); + CONS_Printf("Entering main game loop...\n"); + // never return + D_SRB2Loop(); + +#ifdef BUGTRAP + // This is safe even if BT didn't start. + ShutdownBugTrap(); +#endif + + // return to OS + return 0; +} diff --git a/src/dedicated/i_sound.c b/src/dedicated/i_sound.c new file mode 100644 index 000000000..de43aab85 --- /dev/null +++ b/src/dedicated/i_sound.c @@ -0,0 +1,339 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// The source is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief SDL interface for sound + +#include +#include "../doomdef.h" +#include "../i_sound.h" +#include "../s_sound.h" + +/** \brief Sound subsystem runing and waiting +*/ +UINT8 sound_started = false; + +/** \brief The I_GetSfx function + + \param sfx sfx to setup + + \return data for sfx +*/ +void *I_GetSfx(sfxinfo_t *sfx) +{ + (void)sfx; + return NULL; +} + +/** \brief The I_FreeSfx function + + \param sfx sfx to be freed up + + \return void +*/ +void I_FreeSfx(sfxinfo_t *sfx) +{ + (void)sfx; +} + +/** \brief Init at program start... +*/ +void I_StartupSound(void){} + +/** \brief ... shut down and relase at program termination. +*/ +void I_ShutdownSound(void){} + +/// ------------------------ +/// SFX I/O +/// ------------------------ + +/** \brief Starts a sound in a particular sound channel. + \param id sfxid + \param vol volume for sound + \param sep left-right balancle + \param pitch not used + \param priority not used + + \return sfx handle +*/ +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) +{ + (void)id; + (void)vol; + (void)sep; + (void)pitch; + (void)priority; + (void)channel; + return 0; +} + +/** \brief Stops a sound channel. + + \param handle stop sfx handle + + \return void +*/ +void I_StopSound(INT32 handle) +{ + (void)handle; +} + +/** \brief Some digital sound drivers need this. +*/ +void I_UpdateSound(void){} + +/** \brief Called by S_*() functions to see if a channel is still playing. + + \param handle sfx handle + + \return 0 if no longer playing, 1 if playing. +*/ +boolean I_SoundIsPlaying(INT32 handle) +{ + (void)handle; + return false; +} + +/** \brief Updates the sfx handle + + \param handle sfx handle + \param vol volume + \param sep separation + \param pitch ptich + + \return void +*/ +void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch) +{ + (void)handle; + (void)vol; + (void)sep; + (void)pitch; +} + +/** \brief The I_SetSfxVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetSfxVolume(UINT8 volume) +{ + (void)volume; +} + +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ + +/** \brief Init the music systems +*/ +void I_InitMusic(void){} + +/** \brief Shutdown the music systems +*/ +void I_ShutdownMusic(void){} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_SongType(void) +{ + return MU_NONE; +} + +boolean I_SongPlaying(void) +{ + return false; +} + +boolean I_SongPaused(void) +{ + return false; +} + +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} + +/// ------------------------ +// MUSIC SEEKING +/// ------------------------ + +UINT32 I_GetSongLength(void) +{ + return 0; +} + +boolean I_SetSongLoopPoint(UINT32 looppoint) +{ + (void)looppoint; + return false; +} + +UINT32 I_GetSongLoopPoint(void) +{ + return 0; +} + +boolean I_SetSongPosition(UINT32 position) +{ + (void)position; + return false; +} + +UINT32 I_GetSongPosition(void) +{ + return 0; +} + +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ + +/** \brief Registers a song handle to song data. + + \param data pointer to song data + \param len len of data + + \return song handle + + \todo Remove this +*/ +boolean I_LoadSong(char *data, size_t len) +{ + (void)data; + (void)len; + return false; +} + +/** \brief See ::I_LoadSong, then think backwards + + \param handle song handle + + \sa I_LoadSong + \todo remove midi handle +*/ +void I_UnloadSong(void){} + +/** \brief Called by anything that wishes to start music + + \param handle Song handle + \param looping looping it if true + + \return if true, it's playing the song + + \todo pass music name, not handle +*/ +boolean I_PlaySong(boolean looping) +{ + (void)looping; + return false; +} + +/** \brief Stops a song over 3 seconds + + \param handle Song handle + \return void + + /todo drop handle +*/ +void I_StopSong(void){} + +/** \brief PAUSE game handling. + + \param handle song handle + + \return void +*/ +void I_PauseSong(void){} + +/** \brief RESUME game handling + + \param handle song handle + + \return void +*/ +void I_ResumeSong(void){} + +/** \brief The I_SetMusicVolume function + + \param volume volume to set at + + \return void +*/ +void I_SetMusicVolume(UINT8 volume) +{ + (void)volume; +} + +boolean I_SetSongTrack(INT32 track) +{ + (void)track; + return false; +} + +/// ------------------------ +/// MUSIC FADING +/// ------------------------ + +void I_SetInternalMusicVolume(UINT8 volume) +{ + (void)volume; +} + +void I_StopFadingSong(void){} + +boolean I_FadeSongFromVolume(UINT8 target_volume, UINT8 source_volume, UINT32 ms, void (*callback)(void)) +{ + (void)target_volume; + (void)source_volume; + (void)ms; + (void)callback; + return false; +} + +boolean I_FadeSong(UINT8 target_volume, UINT32 ms, void (*callback)(void)) +{ + (void)target_volume; + (void)ms; + (void)callback; + return false; +} + +boolean I_FadeOutStopSong(UINT32 ms) +{ + (void)ms; + return false; +} + +boolean I_FadeInPlaySong(UINT32 ms, boolean looping) +{ + (void)ms; + (void)looping; + return false; +} + +void I_UpdateSongLagThreshold(void) +{ +} diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c new file mode 100644 index 000000000..e568873f0 --- /dev/null +++ b/src/dedicated/i_system.c @@ -0,0 +1,2218 @@ +// Emacs style mode select -*- C++ -*- +// +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 2014-2018 by Sonic Team Junior. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// Changes by Graue are in the public domain. +// +//----------------------------------------------------------------------------- +/// \file +/// \brief SRB2 system stuff for dedicated + +#ifdef CMAKECONFIG +#include "config.h" +#else +#include "../config.h.in" +#endif + +#include + +// A little more than the minimum sleep duration on Windows. +// May be incorrect for other platforms, but we don't currently have a way to +// query the scheduler granularity. SDL will do what's needed to make this as +// low as possible though. +#define MIN_SLEEP_DURATION_MS 2.1 + +#ifdef _WIN32 +#define RPC_NO_WINDOWS_H +#include +#include "../doomtype.h" +typedef BOOL (WINAPI *p_GetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); +typedef BOOL (WINAPI *p_IsProcessorFeaturePresent) (DWORD); +typedef DWORD (WINAPI *p_timeGetTime) (void); +typedef UINT (WINAPI *p_timeEndPeriod) (UINT); +typedef HANDLE (WINAPI *p_OpenFileMappingA) (DWORD, BOOL, LPCSTR); +typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); +#endif + +#include +#include +#include +#ifdef __GNUC__ +#include +#elif defined (_MSC_VER) +#include +#endif +#if defined (__unix__) || defined (UNIXCOMMON) +#include +#endif + +#include +#ifdef _WIN32 +#include +#endif + +#ifdef _MSC_VER +#pragma warning(disable : 4214 4244) +#endif + +#if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) +#include +#if defined (__linux__) +#include +#else +#include +#include +/*For meminfo*/ +#include +#ifdef FREEBSD +#include +#endif +#include +#include +#endif +#endif + +#if defined (__linux__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) +#ifndef NOTERMIOS +#include +#include // ioctl +#define HAVE_TERMIOS +#endif +#endif + +#if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__)) +#include +#include +#include +#define NEWSIGNALHANDLER +#endif + +#ifndef NOMUMBLE +#ifdef __linux__ // need -lrt +#include +#ifdef MAP_FAILED +#define HAVE_SHM +#endif +#include +#endif + +#ifdef _WIN32 +#define HAVE_MUMBLE +#define WINMUMBLE +#elif defined (HAVE_SHM) +#define HAVE_MUMBLE +#endif +#endif // NOMUMBLE + +#ifndef O_BINARY +#define O_BINARY 0 +#endif + +#ifdef __APPLE__ +#include "macosx/mac_resources.h" +#endif + +#ifndef errno +#include +#endif + +// Locations for searching the srb2.srb +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) +#define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2Kart" +#define DEFAULTWADLOCATION2 "/usr/local/games/SRB2Kart" +#define DEFAULTWADLOCATION3 "/usr/share/games/SRB2Kart" +#define DEFAULTWADLOCATION4 "/usr/games/SRB2Kart" +#define DEFAULTSEARCHPATH1 "/usr/local/games" +#define DEFAULTSEARCHPATH2 "/usr/games" +#define DEFAULTSEARCHPATH3 "/usr/local" +#endif + +/** \brief WAD file to look for +*/ +#define WADKEYWORD1 "srb2.srb" +#define WADKEYWORD2 "srb2.wad" +/** \brief holds wad path +*/ +static char returnWadPath[256]; + +#include "../doomdef.h" +#include "../m_misc.h" +#include "../i_video.h" +#include "../i_sound.h" +#include "../i_system.h" +#include "../screen.h" //vid.WndParent +#include "../d_net.h" +#include "../g_game.h" +#include "../filesrch.h" +#include "../z_zone.h" // Z_Free +#include "endtxt.h" + +#include "../i_joy.h" + +#include "../m_argv.h" + +#ifdef MAC_ALERT +#include "macosx/mac_alert.h" +#endif + +#include "../d_main.h" + +#if !defined(NOMUMBLE) && defined(HAVE_MUMBLE) +// Mumble context string +#include "../d_clisrv.h" +#include "../byteptr.h" +#endif + +#ifdef HAVE_LIBBACKTRACE +#include +// TODO - move this to some header file instead +extern struct backtrace_state *bt_state; + +typedef struct bt_crash_reason_s { + enum { + BTCRASH_SIGNAL, + BTCRASH_ERRORMSG, + } type; + + union { + INT32 signal; + const char *errormsg; + } value; +} bt_crash_reason_t; + +#define BT_CRASH_REASON_SIGNAL(num) (bt_crash_reason_t){ .type = BTCRASH_SIGNAL, .value = { .signal = num } } +#define BT_CRASH_REASON_ERRORMSG(msg) (bt_crash_reason_t){ .type = BTCRASH_ERRORMSG, .value = { .errormsg = msg } } + +static void printsignal(FILE *fp, INT32 num) +{ + switch (num) + { + case SIGILL: + fprintf(fp, "SIGILL - illegal instruction - invalid function image"); + break; + case SIGFPE: + fprintf(fp, "SIGFPE - mathematical exception"); + break; + case SIGSEGV: + fprintf(fp, "SIGSEGV - segment violation"); + break; + case SIGABRT: + fprintf(fp, "SIGABRT - abnormal termination triggered by abort call"); + break; + default: + fprintf(fp, "Signal number %d", num); + } +} + +typedef struct bt_out_buf_s { + boolean error; + char *pos; + size_t size; +} bt_out_buf_t; + +static void bt_syminfo_cb(void *data, uintptr_t pc, const char *symname, uintptr_t symval, uintptr_t symsize) +{ + (void)symval; + (void)symsize; + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!symname) + symname = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n", (void*)pc, symname); + + if (n <= 0) + { + buf->size = 0; + return; + } + + buf->pos += n; + buf->size -= n; +} + +static int bt_simple_cb(void *data, uintptr_t pc) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + backtrace_syminfo(bt_state, pc, bt_syminfo_cb, NULL, data); + + if (!buf->size) return 1; + + return 0; +} + +static int bt_full_cb(void *data, uintptr_t pc, const char *filename, int lineno, const char *function) +{ + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + if (!filename) filename = "???"; + if (!function) function = "???"; + + int n = snprintf(buf->pos, buf->size, "%p %s\n\t%s:%d\n", (void*)pc, function, filename, lineno); + + if (n <= 0) return 1; + + buf->pos += n; + buf->size -= n; + + if (!buf->size) return 1; + + return 0; +} + +static void bt_error_cb(void *data, const char *msg, int errnum) +{ + (void)msg; // We don't need this + + bt_out_buf_t *buf = (bt_out_buf_t*)data; + + // No debug info + if (errnum == -1) + buf->error = true; +} + +static void write_backtrace(bt_crash_reason_t reason) +{ + FILE *out = fopen(va("%s" PATHSEP "%s", srb2home, "srb2kart-crash-log.txt"), "a"); + + time_t rawtime; + struct tm *timeinfo; + + const size_t BUFSIZE = 8192; + char backtrace[BUFSIZE]; + + bt_out_buf_t buf; + buf.error = false; + buf.pos = backtrace; + buf.size = BUFSIZE; + + + if (!out) + { + fprintf(stderr, "\nWARNING: Couldn't open crash log for writing! Make sure your permissions are correct. Please save the below report!\n"); + out = stderr; + } + + // Get the current time as a string. + time(&rawtime); + timeinfo = localtime(&rawtime); + + fprintf(out, "------------------------\n\n"); + + fprintf(out, "Program name: %s %s\n", SRB2APPLICATION, VERSIONSTRING); + + if (compdate && comptime && comprevision && compbranch) + fprintf(out, "Compiled: %s %s, commit %s, branch %s\n", compdate, comptime, comprevision, compbranch); + + if (gamestate == GS_LEVEL) + { + char *title = G_BuildMapTitle(gamemap); + + if (title) + { + fprintf(out, "Game map: %s (%s)\n", title, G_BuildMapName(gamemap)); + Z_Free(title); + } + else + fprintf(out, "Game map: %s\n", G_BuildMapName(gamemap)); + } + + fprintf(out, "Time of crash: %s\n", asctime(timeinfo)); + + fprintf(out, "Caused by: "); + + switch (reason.type) + { + case BTCRASH_SIGNAL: + printsignal(out, reason.value.signal); + break; + + case BTCRASH_ERRORMSG: + fprintf(out, "%s", reason.value.errormsg); + break; + } + + fprintf(out, "\nBacktrace:\n"); + + // Try to get full backtrace, it will print files and line numbers + backtrace_full(bt_state, 2, bt_full_cb, bt_error_cb, (void*)&buf); + + if (buf.error) + { + // Fall back to simple backtrace, only prints function names + backtrace_simple(bt_state, 2, bt_simple_cb, NULL, (void*)&buf); + } + + fputs(backtrace, out); + + if (out != stderr) + { + fclose(out); + fprintf(stderr, "Crash report created, find srb2kart-crash-log.txt in your SRB2Kart directory\n"); + } +} + +#endif + +boolean consolevent = false; +boolean framebuffer = false; + +boolean g_in_exiting_signal_handler = false; + +UINT8 keyboard_started = false; + +static void I_ReportSignal(int num, int coredumped) +{ + //static char msg[] = "oh no! back to reality!\r\n"; + const char * sigmsg; + char msg[256]; + + switch (num) + { +// case SIGINT: +// sigmsg = "SIGINT - interrupted"; +// break; + case SIGILL: + sigmsg = "SIGILL - illegal instruction - invalid function image"; + break; + case SIGFPE: + sigmsg = "SIGFPE - mathematical exception"; + break; + case SIGSEGV: + sigmsg = "SIGSEGV - segment violation"; + break; +// case SIGTERM: +// sigmsg = "SIGTERM - Software termination signal from kill"; +// break; +// case SIGBREAK: +// sigmsg = "SIGBREAK - Ctrl-Break sequence"; +// break; + case SIGABRT: + sigmsg = "SIGABRT - abnormal termination triggered by abort call"; + break; + default: + sprintf(msg,"signal number %d", num); + if (coredumped) + sigmsg = 0; + else + sigmsg = msg; + } + + if (coredumped) + { + if (sigmsg) + sprintf(msg, "%s (core dumped)", sigmsg); + else + strcat(msg, " (core dumped)"); + } + else + { + sprintf(msg, "%s", sigmsg); + } + +#ifdef HAVE_LIBBACKTRACE + strncat(msg, "\n\nCrash report has been saved into srb2kart-crash-log.txt", 255); +#elif defined(_WIN32) && !defined(__MINGW64__) + strncat(msg, "\n\nCrash report has been saved into srb2kart.rpt", 255); +#endif + + I_OutputMsg("\nProcess killed by signal: %s\n\n", sigmsg); +} + +#ifndef NEWSIGNALHANDLER +FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) +{ + g_in_exiting_signal_handler = true; + + D_QuitNetGame(); // Fix server freezes + +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + + if (demo.recording) + G_SaveDemo(); + + I_ReportSignal(num, 0); + I_ShutdownSystem(); + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} +#endif + +FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +{ + signal(num, SIG_DFL); //default signal action + raise(num); + I_Quit(); +} + +#ifdef HAVE_TERMIOS +// TERMIOS console code from Quake3: thank you! +boolean stdin_active = true; + +typedef struct +{ + size_t cursor; + char buffer[256]; +} feild_t; + +feild_t tty_con; + +// lock to prevent clearing partial lines, since not everything +// printed ends on a newline. +static boolean ttycon_ateol = true; +// some key codes that the terminal may be using +// TTimo NOTE: I'm not sure how relevant this is +static INT32 tty_erase; +static INT32 tty_eof; + +static struct termios tty_tc; + +// ============================================================= +// tty console routines +// NOTE: if the user is editing a line when something gets printed to the early console then it won't look good +// so we provide tty_Clear and tty_Show to be called before and after a stdout or stderr output +// ============================================================= + +// flush stdin, I suspect some terminals are sending a LOT of garbage +// FIXME TTimo relevant? +#if 0 +static inline void tty_FlushIn(void) +{ + char key; + while (read(STDIN_FILENO, &key, 1)!=-1); +} +#endif + +// do a backspace +// TTimo NOTE: it seems on some terminals just sending '\b' is not enough +// so for now, in any case we send "\b \b" .. yeah well .. +// (there may be a way to find out if '\b' alone would work though) +// Hanicef NOTE: using \b this way is unreliable because of terminal state, +// it's better to use \r to reset the cursor to the beginning of the +// line and clear from there. +static void tty_Back(void) +{ + write(STDOUT_FILENO, "\r", 1); + if (tty_con.cursor>0) + { + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + } + write(STDOUT_FILENO, " \b", 2); +} + +static void tty_Clear(void) +{ + size_t i; + write(STDOUT_FILENO, "\r", 1); + if (tty_con.cursor>0) + { + for (i=0; i 0) + { + tty_con.cursor--; + tty_con.buffer[tty_con.cursor] = '\0'; + tty_Back(); + } + ev.data1 = KEY_BACKSPACE; + } + else if (key < ' ') // check if this is a control char + { + if (key == '\n') + { + tty_Clear(); + tty_con.cursor = 0; + ev.data1 = KEY_ENTER; + } + else if (key == 0x4) // ^D, aka EOF + { + // shut down, most unix programs behave this way + I_Quit(); + } + else continue; + } + else if (tty_con.cursor < sizeof(tty_con.buffer)) + { + // push regular character + ev.data1 = tty_con.buffer[tty_con.cursor] = key; + tty_con.cursor++; + // print the current line (this is differential) + write(STDOUT_FILENO, &key, 1); + } + if (ev.data1) D_PostEvent(&ev); + } +} + +#elif defined (_WIN32) +static BOOL I_ReadyConsole(HANDLE ci) +{ + DWORD gotinput; + if (ci == INVALID_HANDLE_VALUE) return FALSE; + if (WaitForSingleObject(ci,0) != WAIT_OBJECT_0) return FALSE; + if (GetFileType(ci) != FILE_TYPE_CHAR) return FALSE; + if (!GetConsoleMode(ci, &gotinput)) return FALSE; + return (GetNumberOfConsoleInputEvents(ci, &gotinput) && gotinput); +} + +static boolean entering_con_command = false; + +static void Impl_HandleKeyboardConsoleEvent(KEY_EVENT_RECORD evt, HANDLE co) +{ + event_t event; + CONSOLE_SCREEN_BUFFER_INFO CSBI; + DWORD t; + + memset(&event,0x00,sizeof (event)); + + if (evt.bKeyDown) + { + event.type = ev_console; + entering_con_command = true; + switch (evt.wVirtualKeyCode) + { + case VK_ESCAPE: + case VK_TAB: + event.data1 = KEY_NULL; + break; + case VK_RETURN: + entering_con_command = false; + // Fall through. + default: + //event.data1 = MapVirtualKey(evt.wVirtualKeyCode,2); // convert in to char + event.data1 = evt.uChar.AsciiChar; + } + if (co != INVALID_HANDLE_VALUE && GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &t)) + { + if (event.data1 && event.data1 != KEY_LSHIFT && event.data1 != KEY_RSHIFT) + { +#ifdef _UNICODE + WriteConsole(co, &evt.uChar.UnicodeChar, 1, &t, NULL); +#else + WriteConsole(co, &evt.uChar.AsciiChar, 1 , &t, NULL); +#endif + } + if (evt.wVirtualKeyCode == VK_BACK + && GetConsoleScreenBufferInfo(co,&CSBI)) + { + WriteConsoleOutputCharacterA(co, " ",1, CSBI.dwCursorPosition, &t); + } + } + } + if (event.data1) D_PostEvent(&event); +} + +void I_GetConsoleEvents(void) +{ + HANDLE ci = GetStdHandle(STD_INPUT_HANDLE); + HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE); + INPUT_RECORD input; + DWORD t; + + while (I_ReadyConsole(ci) && ReadConsoleInput(ci, &input, 1, &t) && t) + { + switch (input.EventType) + { + case KEY_EVENT: + Impl_HandleKeyboardConsoleEvent(input.Event.KeyEvent, co); + break; + case MOUSE_EVENT: + case WINDOW_BUFFER_SIZE_EVENT: + case MENU_EVENT: + case FOCUS_EVENT: + break; + } + } +} + +static void I_StartupConsole(void) +{ + HANDLE ci, co; + const INT32 ded = M_CheckParm("-dedicated"); + BOOL gotConsole = FALSE; + if (M_CheckParm("-console") || ded) + gotConsole = AllocConsole(); +#ifdef _DEBUG + else if (M_CheckParm("-noconsole") && !ded) +#else + else if (!M_CheckParm("-console") && !ded) +#endif + { + FreeConsole(); + gotConsole = FALSE; + } + + if (gotConsole) + { + SetConsoleTitleA("SRB2Kart Console"); + consolevent = true; + } + + //Let get the real console HANDLE, because Mingw's Bash is bad! + ci = CreateFile(TEXT("CONIN$") , GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + co = CreateFile(TEXT("CONOUT$"), GENERIC_WRITE|GENERIC_READ, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (ci != INVALID_HANDLE_VALUE) + { + const DWORD CM = ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT; + SetStdHandle(STD_INPUT_HANDLE, ci); + if (GetFileType(ci) == FILE_TYPE_CHAR) + SetConsoleMode(ci, CM); //default mode but no ENABLE_MOUSE_INPUT + } + if (co != INVALID_HANDLE_VALUE) + { + SetStdHandle(STD_OUTPUT_HANDLE, co); + SetStdHandle(STD_ERROR_HANDLE, co); + } +} +static inline void I_ShutdownConsole(void){} +#else +void I_GetConsoleEvents(void){} +static inline void I_StartupConsole(void) +{ +#ifdef _DEBUG + consolevent = !M_CheckParm("-noconsole"); +#else + consolevent = M_CheckParm("-console"); +#endif + + framebuffer = M_CheckParm("-framebuffer"); + + if (framebuffer) + consolevent = false; +} +static inline void I_ShutdownConsole(void){} +#endif + +// +// StartupKeyboard +// +static void I_RegisterSignals (void) +{ +#ifdef SIGINT + signal(SIGINT , quit_handler); +#endif +#ifdef SIGBREAK + signal(SIGBREAK , quit_handler); +#endif +#ifdef SIGTERM + signal(SIGTERM , quit_handler); +#endif + + // If these defines don't exist, + // then compilation would have failed above us... +#ifndef NEWSIGNALHANDLER + signal(SIGILL , signal_handler); + signal(SIGSEGV , signal_handler); + signal(SIGABRT , signal_handler); + signal(SIGFPE , signal_handler); +#endif +} + +#ifdef NEWSIGNALHANDLER +static void signal_handler_child(INT32 num) +{ +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_SIGNAL(num)); +#endif + + if (demo.recording) + G_SaveDemo(); + + signal(num, SIG_DFL); //default signal action + raise(num); +} + +static void I_RegisterChildSignals(void) +{ + // If these defines don't exist, + // then compilation would have failed above us... + signal(SIGILL , signal_handler_child); + signal(SIGSEGV , signal_handler_child); + signal(SIGABRT , signal_handler_child); + signal(SIGFPE , signal_handler_child); +} +#endif + +// +//I_OutputMsg +// +void I_OutputMsg(const char *fmt, ...) +{ + size_t len; + char *txt; + va_list argptr; + + va_start(argptr,fmt); + len = vsnprintf(NULL, 0, fmt, argptr); + va_end(argptr); + if (len == 0) + return; + + txt = malloc(len+1); + va_start(argptr,fmt); + vsprintf(txt, fmt, argptr); + va_end(argptr); + +#ifdef HAVE_TTF + if (TTF_WasInit()) I_TTFDrawText(currentfont, solid, DEFAULTFONTFGR, DEFAULTFONTFGG, DEFAULTFONTFGB, DEFAULTFONTFGA, + DEFAULTFONTBGR, DEFAULTFONTBGG, DEFAULTFONTBGB, DEFAULTFONTBGA, txt); +#endif + +#if defined (_WIN32) && defined (_MSC_VER) + OutputDebugStringA(txt); +#endif + + len = strlen(txt); + +#ifdef LOGMESSAGES + if (logstream) + { + size_t d = fwrite(txt, len, 1, logstream); + fflush(logstream); + (void)d; + } +#endif + +#if defined (_WIN32) +#ifdef DEBUGFILE + if (debugfile != stderr) +#endif + { + HANDLE co = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD bytesWritten; + + if (co == INVALID_HANDLE_VALUE) + { + free(txt); + return; + } + + if (GetFileType(co) == FILE_TYPE_CHAR && GetConsoleMode(co, &bytesWritten)) + { + static COORD coordNextWrite = {0,0}; + LPVOID oldLines = NULL; + INT oldLength; + CONSOLE_SCREEN_BUFFER_INFO csbi; + + // Save the lines that we're going to obliterate. + GetConsoleScreenBufferInfo(co, &csbi); + oldLength = csbi.dwSize.X * (csbi.dwCursorPosition.Y - coordNextWrite.Y) + csbi.dwCursorPosition.X - coordNextWrite.X; + + if (oldLength > 0) + { + LPVOID blank = malloc(oldLength); + if (!blank) + { + free(txt); + return; + } + memset(blank, ' ', oldLength); // Blank out. + oldLines = malloc(oldLength*sizeof(TCHAR)); + if (!oldLines) + { + free(txt); + free(blank); + return; + } + + ReadConsoleOutputCharacter(co, oldLines, oldLength, coordNextWrite, &bytesWritten); + + // Move to where we what to print - which is where we would've been, + // had console input not been in the way, + SetConsoleCursorPosition(co, coordNextWrite); + + WriteConsoleA(co, blank, oldLength, &bytesWritten, NULL); + free(blank); + + // And back to where we want to print again. + SetConsoleCursorPosition(co, coordNextWrite); + } + + // Actually write the string now! + WriteConsoleA(co, txt, (DWORD)len, &bytesWritten, NULL); + + // Next time, output where we left off. + GetConsoleScreenBufferInfo(co, &csbi); + coordNextWrite = csbi.dwCursorPosition; + + // Restore what was overwritten. + if (oldLines && entering_con_command) + WriteConsole(co, oldLines, oldLength, &bytesWritten, NULL); + if (oldLines) free(oldLines); + } + else // Redirected to a file. + WriteFile(co, txt, (DWORD)len, &bytesWritten, NULL); + } +#else +#ifdef HAVE_TERMIOS + if (consolevent && ttycon_ateol) + { + tty_Clear(); + ttycon_ateol = false; + } +#endif + + if (!framebuffer) + fprintf(stderr, "%s", txt); +#ifdef HAVE_TERMIOS + if (consolevent && txt[len-1] == '\n') + { + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + ttycon_ateol = true; + } +#endif + + // 2004-03-03 AJR Since not all messages end in newline, some were getting displayed late. + if (!framebuffer) + fflush(stderr); + +#endif + free(txt); +} + +// +// I_GetKey +// +INT32 I_GetKey (void) +{ + // Warning: I_GetKey empties the event queue till next keypress + event_t *ev; + INT32 rc = 0; + + // return the first keypress from the event queue + for (; eventtail != eventhead; eventtail = (eventtail+1)&(MAXEVENTS-1)) + { + ev = &events[eventtail]; + if (ev->type == ev_keydown || ev->type == ev_console) + { + rc = ev->data1; + continue; + } + } + + return rc; +} + +// +// I_JoyScale +// +void I_JoyScale(void) +{ +} + +void I_JoyScale2(void) +{ +} + +void I_JoyScale3(void) +{ +} + +void I_JoyScale4(void) +{ +} + +/** \brief Shuts down joystick 1 + + + \return void + + +*/ +void I_ShutdownJoystick(void) +{ +} + +void I_GetJoystickEvents(UINT8 index) +{ + (void)index; +} + +// +// I_InitJoystick +// +void I_InitJoystick(UINT8 index) +{ + (void)index; +} + +void I_InitJoystick1(void) +{ +} + +void I_InitJoystick2(void) +{ +} + +void I_InitJoystick3(void) +{ +} + +void I_InitJoystick4(void) +{ +} + +INT32 I_NumJoys(void) +{ + return 0; +} + +const char *I_GetJoyName(INT32 joyindex) +{ + (void)joyindex; + return NULL; +} + +void I_GamepadRumble(INT32 playernum, UINT16 low_strength, UINT16 high_strength, UINT32 duration) +{ + (void)playernum; + (void)low_strength; + (void)high_strength; + (void)duration; +} + +void I_SetGamepadIndicatorColor(INT32 playernum, UINT8 red, UINT8 green, UINT8 blue) +{ + (void)playernum; + (void)red; + (void)green; + (void)blue; +} + +#ifndef NOMUMBLE +#ifdef HAVE_MUMBLE +// Best Mumble positional audio settings: +// Minimum distance 3.0 m +// Bloom 175% +// Maximum distance 80.0 m +// Minimum volume 50% +#define DEG2RAD (0.017453292519943295769236907684883l) // TAU/360 or PI/180 +#define MUMBLEUNIT (64.0f) // FRACUNITS in a Meter + +static struct { +#ifdef WINMUMBLE + UINT32 uiVersion; + DWORD uiTick; +#else + UINT32 uiVersion; + UINT32 uiTick; +#endif + float fAvatarPosition[3]; + float fAvatarFront[3]; + float fAvatarTop[3]; // defaults to Y-is-up (only used for leaning) + wchar_t name[256]; // game name + float fCameraPosition[3]; + float fCameraFront[3]; + float fCameraTop[3]; // defaults to Y-is-up (only used for leaning) + wchar_t identity[256]; // player id +#ifdef WINMUMBLE + UINT32 context_len; +#else + UINT32 context_len; +#endif + unsigned char context[256]; // server/team + wchar_t description[2048]; // game description +} *mumble = NULL; +#endif // HAVE_MUMBLE + +static void I_SetupMumble(void) +{ +#ifdef WINMUMBLE + HANDLE hMap = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink"); + if (!hMap) + return; + + mumble = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(*mumble)); + if (!mumble) + CloseHandle(hMap); +#elif defined (HAVE_SHM) + int shmfd; + char memname[256]; + + snprintf(memname, 256, "/MumbleLink.%d", getuid()); + shmfd = shm_open(memname, O_RDWR, S_IRUSR | S_IWUSR); + + if(shmfd < 0) + return; + + mumble = mmap(NULL, sizeof(*mumble), PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0); + if (mumble == MAP_FAILED) + mumble = NULL; +#endif +} + +void I_UpdateMumble(const mobj_t *mobj, const listener_t listener) +{ +#ifdef HAVE_MUMBLE + double angle; + fixed_t anglef; + + if (!mumble) + return; + + if (mumble->uiVersion != 2) { + wcsncpy(mumble->name, L"SRB2Kart "VERSIONSTRINGW, 256); + wcsncpy(mumble->description, L"Sonic Robo Blast 2 Kart with integrated Mumble Link support.", 2048); + mumble->uiVersion = 2; + } + mumble->uiTick++; + + if (!netgame || gamestate != GS_LEVEL) { // Zero out, but never delink. + mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; + mumble->fAvatarFront[0] = 1.0f; + mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; + mumble->fCameraPosition[0] = mumble->fCameraPosition[1] = mumble->fCameraPosition[2] = 0.0f; + mumble->fCameraFront[0] = 1.0f; + mumble->fCameraFront[1] = mumble->fCameraFront[2] = 0.0f; + return; + } + + { + UINT8 *p = mumble->context; + WRITEMEM(p, server_context, 8); + WRITEINT16(p, gamemap); + mumble->context_len = (UINT32)(p - mumble->context); + } + + if (mobj) { + mumble->fAvatarPosition[0] = FIXED_TO_FLOAT(mobj->x) / MUMBLEUNIT; + mumble->fAvatarPosition[1] = FIXED_TO_FLOAT(mobj->z) / MUMBLEUNIT; + mumble->fAvatarPosition[2] = FIXED_TO_FLOAT(mobj->y) / MUMBLEUNIT; + + anglef = AngleFixed(mobj->angle); + angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; + mumble->fAvatarFront[0] = (float)cos(angle); + mumble->fAvatarFront[1] = 0.0f; + mumble->fAvatarFront[2] = (float)sin(angle); + } else { + mumble->fAvatarPosition[0] = mumble->fAvatarPosition[1] = mumble->fAvatarPosition[2] = 0.0f; + mumble->fAvatarFront[0] = 1.0f; + mumble->fAvatarFront[1] = mumble->fAvatarFront[2] = 0.0f; + } + + mumble->fCameraPosition[0] = FIXED_TO_FLOAT(listener.x) / MUMBLEUNIT; + mumble->fCameraPosition[1] = FIXED_TO_FLOAT(listener.z) / MUMBLEUNIT; + mumble->fCameraPosition[2] = FIXED_TO_FLOAT(listener.y) / MUMBLEUNIT; + + anglef = AngleFixed(listener.angle); + angle = FIXED_TO_FLOAT(anglef)*DEG2RAD; + mumble->fCameraFront[0] = (float)cos(angle); + mumble->fCameraFront[1] = 0.0f; + mumble->fCameraFront[2] = (float)sin(angle); +#else + (void)mobj; + (void)listener; +#endif // HAVE_MUMBLE +} +#undef WINMUMBLE +#endif // NOMUMBLE + + +/** \brief empty ticcmd for player 1 +*/ +static ticcmd_t emptycmd; + +ticcmd_t *I_BaseTiccmd(void) +{ + return &emptycmd; +} + +/** \brief empty ticcmd for player 2 +*/ +static ticcmd_t emptycmd2; + +ticcmd_t *I_BaseTiccmd2(void) +{ + return &emptycmd2; +} + +/** \brief empty ticcmd for player 3 + */ +static ticcmd_t emptycmd3; + +ticcmd_t *I_BaseTiccmd3(void) +{ + return &emptycmd3; +} + +/** \brief empty ticcmd for player 4 + */ +static ticcmd_t emptycmd4; + +ticcmd_t *I_BaseTiccmd4(void) +{ + return &emptycmd4; +} + +// +// I_GetTime +// returns time in 1/TICRATE second tics +// + +precise_t I_GetPreciseTime(void) +{ +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return (precise_t)ts.tv_sec * 1000000000 + ts.tv_nsec; +#elif defined (_WIN32) + LARGE_INTEGER counter; + QueryPerformanceCounter(&counter); + return (precise_t)counter.QuadPart; +#else + return 0; +#endif +} + +UINT64 I_GetPrecisePrecision(void) +{ +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + return 1000000000; +#elif defined (_WIN32) + LARGE_INTEGER frequency; + QueryPerformanceFrequency(&frequency); + return (UINT64)frequency.QuadPart; +#else + return 1000000; +#endif +} + +void I_StartupTimer(void){} + +void I_Sleep(UINT32 ms) +{ +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) + struct timespec ts = { + .tv_sec = ms / 1000, + .tv_nsec = ms % 1000 * 1000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); +#elif defined (_WIN32) + Sleep(ms); +#else + (void)ms; +#warning No sleep function for this system! +#endif +} + +void I_SleepDuration(precise_t duration) +{ +#if defined(__linux__) || defined(__FreeBSD__) || defined(__HAIKU__) + UINT64 precision = I_GetPrecisePrecision(); + struct timespec ts = { + .tv_sec = duration / precision, + .tv_nsec = duration * 1000000000 / precision % 1000000000, + }; + int status; + do status = clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts); + while (status == EINTR); +#elif defined (MIN_SLEEP_DURATION_MS) + UINT64 precision = I_GetPrecisePrecision(); + INT32 sleepvalue = cv_sleep.value; + UINT64 delaygranularity; + precise_t cur; + precise_t dest; + + { + double gran = round(((double)(precision / 1000) * sleepvalue * MIN_SLEEP_DURATION_MS)); + delaygranularity = (UINT64)gran; + } + + cur = I_GetPreciseTime(); + dest = cur + duration; + + // the reason this is not dest > cur is because the precise counter may wrap + // two's complement arithmetic is our friend here, though! + // e.g. cur 0xFFFFFFFFFFFFFFFE = -2, dest 0x0000000000000001 = 1 + // 0x0000000000000001 - 0xFFFFFFFFFFFFFFFE = 3 + while ((INT64)(dest - cur) > 0) + { + // If our cv_sleep value exceeds the remaining sleep duration, use the + // hard sleep function. + if (sleepvalue > 0 && (dest - cur) > delaygranularity) + { + I_Sleep(sleepvalue); + } + + // Otherwise, this is a spinloop. + + cur = I_GetPreciseTime(); + } +#endif +} + +#ifdef NEWSIGNALHANDLER +FUNCNORETURN static ATTRNORETURN void newsignalhandler_Warn(const char *pr) +{ + char text[128]; + + snprintf(text, sizeof text, + "Error while setting up signal reporting: %s: %s", + pr, + strerror(errno) + ); + + I_OutputMsg("%s\n", text); + + I_ShutdownConsole(); + exit(-1); +} + +static void I_Fork(void) +{ + int child; + int status; + int signum; + int c; + + child = fork(); + + switch (child) + { + case -1: + newsignalhandler_Warn("fork()"); + break; + case 0: + I_RegisterChildSignals(); + break; + default: + if (logstream) + fclose(logstream);/* the child has this */ + + c = wait(&status); + +#ifdef LOGMESSAGES + /* By the way, exit closes files. */ + logstream = fopen(logfilename, "at"); +#else + logstream = 0; +#endif + + if (c == -1) + { + kill(child, SIGKILL); + newsignalhandler_Warn("wait()"); + } + else + { + if (WIFSIGNALED (status)) + { + signum = WTERMSIG (status); +#ifdef WCOREDUMP + I_ReportSignal(signum, WCOREDUMP (status)); +#else + I_ReportSignal(signum, 0); +#endif + status = 128 + signum; + } + else if (WIFEXITED (status)) + { + status = WEXITSTATUS (status); + } + + I_ShutdownConsole(); + exit(status); + } + } +} +#endif/*NEWSIGNALHANDLER*/ + +INT32 I_StartupSystem(void) +{ + I_StartupConsole(); +#ifdef NEWSIGNALHANDLER + I_Fork(); +#endif +#ifdef HAVE_THREADS + I_start_threads(); + I_AddExitFunc(I_stop_threads); +#endif + I_RegisterSignals(); +#ifndef NOMUMBLE + I_SetupMumble(); +#endif + return 0; +} + +// +// I_Quit +// +void I_Quit(void) +{ + static boolean quiting = false; + + /* prevent recursive I_Quit() */ + if (quiting) goto death; + quiting = false; + I_ShutdownConsole(); + M_SaveConfig(NULL); //save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif + G_SaveGameData(false); // Tails 12-08-2002 + //added:16-02-98: when recording a demo, should exit using 'q' key, + // but sometimes we forget and use 'F10'.. so save here too. + + if (demo.recording) + G_CheckDemoStatus(); + if (metalrecording) + G_StopMetalRecording(); + + D_QuitNetGame(); + I_ShutdownMusic(); + I_ShutdownSound(); + // use this for 1.28 19990220 by Kin + I_ShutdownGraphics(); + I_ShutdownSystem(); + /* if option -noendtxt is set, don't print the text */ + if (!M_CheckParm("-noendtxt") && W_CheckNumForName("ENDOOM") != LUMPERROR) + { + printf("\r"); + ShowEndTxt(); + } + if (myargmalloc) + free(myargv); // Deallocate allocated memory +death: + W_Shutdown(); + exit(0); +} + +void I_WaitVBL(INT32 count) +{ + count = 1; + I_Sleep(count); +} + +void I_BeginRead(void) +{ +} + +void I_EndRead(void) +{ +} + +// +// I_Error +// +/** \brief phuck recursive errors +*/ +static INT32 errorcount = 0; + +/** \brief recursive error detecting +*/ +static boolean shutdowning = false; + +void I_Error(const char *error, ...) +{ + va_list argptr; + char buffer[8192]; + + // recursive error detecting + if (shutdowning) + { + errorcount++; + // try to shutdown each subsystem separately + if (errorcount == 1) + I_ShutdownMusic(); + if (errorcount == 2) + I_ShutdownSound(); + if (errorcount == 3) + I_ShutdownGraphics(); + if (errorcount == 4) + I_ShutdownSystem(); + if (errorcount == 5) + { + M_SaveConfig(NULL); + G_SaveGameData(false); + } + if (errorcount > 20) + { + va_start(argptr, error); + vsprintf(buffer, error, argptr); + va_end(argptr); + + I_OutputMsg("SRB2Kart %s Recursive Error", buffer); + + W_Shutdown(); + exit(-1); // recursive errors detected + } + } + + shutdowning = true; + + // Display error message in the console before we start shutting it down + va_start(argptr, error); + vsprintf(buffer, error, argptr); + va_end(argptr); + I_OutputMsg("\nI_Error(): %s\n", buffer); + +#ifdef HAVE_LIBBACKTRACE + write_backtrace(BT_CRASH_REASON_ERRORMSG(buffer)); +#endif + // --- + + I_ShutdownConsole(); + + M_SaveConfig(NULL); // save game config, cvars.. +#ifndef NONET + D_SaveBan(); // save the ban list +#endif + G_SaveGameData(false); // Tails 12-08-2002 + + // Shutdown. Here might be other errors. + if (demo.recording) + G_CheckDemoStatus(); + if (metalrecording) + G_StopMetalRecording(); + + D_QuitNetGame(); + I_ShutdownMusic(); + I_ShutdownSound(); + // use this for 1.28 19990220 by Kin + I_ShutdownGraphics(); + I_ShutdownSystem(); + + W_Shutdown(); + +#if defined (PARANOIA) && defined (__CYGWIN__) + *(INT32 *)2 = 4; //Alam: Debug! +#endif + + exit(-1); +} + +/** \brief quit function table +*/ +static quitfuncptr quit_funcs[MAX_QUIT_FUNCS]; /* initialized to all bits 0 */ + +// +// Adds a function to the list that need to be called by I_SystemShutdown(). +// +void I_AddExitFunc(void (*func)()) +{ + INT32 c; + + for (c = 0; c < MAX_QUIT_FUNCS; c++) + { + if (!quit_funcs[c]) + { + quit_funcs[c] = func; + break; + } + } +} + + +// +// Removes a function from the list that need to be called by +// I_SystemShutdown(). +// +void I_RemoveExitFunc(void (*func)()) +{ + INT32 c; + + for (c = 0; c < MAX_QUIT_FUNCS; c++) + { + if (quit_funcs[c] == func) + { + while (c < MAX_QUIT_FUNCS-1) + { + quit_funcs[c] = quit_funcs[c+1]; + c++; + } + quit_funcs[MAX_QUIT_FUNCS-1] = NULL; + break; + } + } +} + +#if !(defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)) +static void Shittycopyerror(const char *name) +{ + I_OutputMsg( + "Error copying log file: %s: %s\n", + name, + strerror(errno) + ); +} + +static void Shittylogcopy(void) +{ + char buf[8192]; + FILE *fp; + size_t r; + if (fseek(logstream, 0, SEEK_SET) == -1) + { + Shittycopyerror("fseek"); + } + else if (( fp = fopen(logfilename, "wt") )) + { + while (( r = fread(buf, 1, sizeof buf, logstream) )) + { + if (fwrite(buf, 1, r, fp) < r) + { + Shittycopyerror("fwrite"); + break; + } + } + if (ferror(logstream)) + { + Shittycopyerror("fread"); + } + fclose(fp); + } + else + { + Shittycopyerror(logfilename); + } +} +#endif/*!(defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON))*/ + +// +// Closes down everything. This includes restoring the initial +// palette and video mode, and removing whatever mouse, keyboard, and +// timer routines have been installed. +// +// NOTE: Shutdown user funcs are effectively called in reverse order. +// +void I_ShutdownSystem(void) +{ + INT32 c; + +#ifndef NEWSIGNALHANDLER + I_ShutdownConsole(); +#endif + + for (c = MAX_QUIT_FUNCS-1; c >= 0; c--) + if (quit_funcs[c]) + (*quit_funcs[c])(); +#ifdef LOGMESSAGES + if (logstream) + { + I_OutputMsg("I_ShutdownSystem(): end of logstream.\n"); +#if !(defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON)) + Shittylogcopy(); +#endif + fclose(logstream); + logstream = NULL; + } +#endif +} + +void I_GetDiskFreeSpace(INT64 *freespace) +{ +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) +#if defined (SOLARIS) || defined (__HAIKU__) + *freespace = INT32_MAX; + return; +#else // Both Linux and BSD have this, apparently. + struct statfs stfs; + if (statfs(".", &stfs) == -1) + { + *freespace = INT32_MAX; + return; + } + *freespace = stfs.f_bavail * stfs.f_bsize; +#endif +#elif defined (_WIN32) + static p_GetDiskFreeSpaceExA pfnGetDiskFreeSpaceEx = NULL; + static boolean testwin95 = false; + ULARGE_INTEGER usedbytes, lfreespace; + + if (!testwin95) + { + pfnGetDiskFreeSpaceEx = (p_GetDiskFreeSpaceExA)(LPVOID)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetDiskFreeSpaceExA"); + testwin95 = true; + } + if (pfnGetDiskFreeSpaceEx) + { + if (pfnGetDiskFreeSpaceEx(NULL, &lfreespace, &usedbytes, NULL)) + *freespace = lfreespace.QuadPart; + else + *freespace = INT32_MAX; + } + else + { + DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters; + GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, + &NumberOfFreeClusters, &TotalNumberOfClusters); + *freespace = BytesPerSector*SectorsPerCluster*NumberOfFreeClusters; + } +#else // Dummy for platform independent; 1GB should be enough + *freespace = 1024*1024*1024; +#endif +} + +char *I_GetUserName(void) +{ + static char username[MAXPLAYERNAME+1]; + char *p; +#ifdef _WIN32 + DWORD i = MAXPLAYERNAME; + + if (!GetUserNameA(username, &i)) +#endif + { + p = I_GetEnv("USER"); + if (!p) + { + p = I_GetEnv("user"); + if (!p) + { + p = I_GetEnv("USERNAME"); + if (!p) + { + p = I_GetEnv("username"); + if (!p) + { + return NULL; + } + } + } + } + strncpy(username, p, MAXPLAYERNAME); + } + + + if (strcmp(username, "") != 0) + return username; + return NULL; // dummy for platform independent version +} + +INT32 I_mkdir(const char *dirname, INT32 unixright) +{ +//[segabor] +#if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) || defined (__CYGWIN__) || defined (__OS2__) + return mkdir(dirname, unixright); +#elif defined (_WIN32) + UNREFERENCED_PARAMETER(unixright); /// \todo should implement ntright under nt... + return CreateDirectoryA(dirname, NULL); +#else + (void)dirname; + (void)unixright; + return false; +#endif +} + +char *I_GetEnv(const char *name) +{ + return getenv(name); +} + +INT32 I_PutEnv(char *variable) +{ + return putenv(variable); +} + +INT32 I_ClipboardCopy(const char *data, size_t size) +{ + (void)data; + (void)size; + return -1; +} + +const char *I_ClipboardPaste(void) +{ + return NULL; +} + +/** \brief The isWadPathOk function + + \param path string path to check + + \return if true, wad file found + + +*/ +static boolean isWadPathOk(const char *path) +{ + char *wad3path = malloc(256); + + if (!wad3path) + return false; + + sprintf(wad3path, pandf, path, WADKEYWORD1); + + if (FIL_ReadFileOK(wad3path)) + { + free(wad3path); + return true; + } + + sprintf(wad3path, pandf, path, WADKEYWORD2); + + if (FIL_ReadFileOK(wad3path)) + { + free(wad3path); + return true; + } + + free(wad3path); + return false; +} + +static void pathonly(char *s) +{ + size_t j; + + for (j = strlen(s); j != (size_t)-1; j--) + if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) + { + if (s[j] == ':') s[j+1] = 0; + else s[j] = 0; + return; + } +} + +/** \brief search for srb2.srb in the given path + + \param searchDir starting path + + \return WAD path if not NULL + + +*/ +static const char *searchWad(const char *searchDir) +{ + static char tempsw[256] = ""; + filestatus_t fstemp; + + strcpy(tempsw, WADKEYWORD1); + fstemp = filesearch(tempsw,searchDir,NULL,true,20); + if (fstemp == FS_FOUND) + { + pathonly(tempsw); + return tempsw; + } + + strcpy(tempsw, WADKEYWORD2); + fstemp = filesearch(tempsw, searchDir, NULL, true, 20); + if (fstemp == FS_FOUND) + { + pathonly(tempsw); + return tempsw; + } + return NULL; +} + +/** \brief go through all possible paths and look for srb2.srb + + \return path to srb2.srb if any +*/ +static const char *locateWad(void) +{ + const char *envstr; + const char *WadPath; + + I_OutputMsg("SRB2WADDIR"); + // does SRB2WADDIR exist? + if (((envstr = I_GetEnv("SRB2WADDIR")) != NULL) && isWadPathOk(envstr)) + return envstr; + +#ifndef NOCWD + I_OutputMsg(",."); + // examine current dir + strcpy(returnWadPath, "."); + if (isWadPathOk(returnWadPath)) + return NULL; +#endif + + +#ifdef DEFAULTDIR + I_OutputMsg(",HOME/" DEFAULTDIR); + // examine user jart directory + if ((envstr = I_GetEnv("HOME")) != NULL) + { + sprintf(returnWadPath, "%s" PATHSEP DEFAULTDIR, envstr); + if (isWadPathOk(returnWadPath)) + return returnWadPath; + } +#endif + + +#ifdef CMAKECONFIG +#ifndef NDEBUG + I_OutputMsg(","CMAKE_ASSETS_DIR); + strcpy(returnWadPath, CMAKE_ASSETS_DIR); + if (isWadPathOk(returnWadPath)) + { + return returnWadPath; + } +#endif +#endif + +#ifdef __APPLE__ + OSX_GetResourcesPath(returnWadPath); + I_OutputMsg(",%s", returnWadPath); + if (isWadPathOk(returnWadPath)) + { + return returnWadPath; + } +#endif + + // examine default dirs +#ifdef DEFAULTWADLOCATION1 + I_OutputMsg(","DEFAULTWADLOCATION1); + strcpy(returnWadPath, DEFAULTWADLOCATION1); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION2 + I_OutputMsg(","DEFAULTWADLOCATION2); + strcpy(returnWadPath, DEFAULTWADLOCATION2); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION3 + I_OutputMsg(","DEFAULTWADLOCATION3); + strcpy(returnWadPath, DEFAULTWADLOCATION3); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION4 + I_OutputMsg(","DEFAULTWADLOCATION4); + strcpy(returnWadPath, DEFAULTWADLOCATION4); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION5 + I_OutputMsg(","DEFAULTWADLOCATION5); + strcpy(returnWadPath, DEFAULTWADLOCATION5); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION6 + I_OutputMsg(","DEFAULTWADLOCATION6); + strcpy(returnWadPath, DEFAULTWADLOCATION6); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifdef DEFAULTWADLOCATION7 + I_OutputMsg(","DEFAULTWADLOCATION7); + strcpy(returnWadPath, DEFAULTWADLOCATION7); + if (isWadPathOk(returnWadPath)) + return returnWadPath; +#endif +#ifndef NOHOME + // find in $HOME + I_OutputMsg(",HOME/" DEFAULTDIR); + if ((envstr = I_GetEnv("HOME")) != NULL) + { + char *tmp = malloc(strlen(envstr) + sizeof(PATHSEP) + sizeof(DEFAULTDIR)); + strcpy(tmp, envstr); + strcat(tmp, PATHSEP); + strcat(tmp, DEFAULTDIR); + WadPath = searchWad(tmp); + free(tmp); + if (WadPath) + return WadPath; + } +#endif +#ifdef DEFAULTSEARCHPATH1 + // find in /usr/local + I_OutputMsg(", in:"DEFAULTSEARCHPATH1); + WadPath = searchWad(DEFAULTSEARCHPATH1); + if (WadPath) + return WadPath; +#endif +#ifdef DEFAULTSEARCHPATH2 + // find in /usr/games + I_OutputMsg(", in:"DEFAULTSEARCHPATH2); + WadPath = searchWad(DEFAULTSEARCHPATH2); + if (WadPath) + return WadPath; +#endif +#ifdef DEFAULTSEARCHPATH3 + // find in ??? + I_OutputMsg(", in:"DEFAULTSEARCHPATH3); + WadPath = searchWad(DEFAULTSEARCHPATH3); + if (WadPath) + return WadPath; +#endif + // if nothing was found + return NULL; +} + +const char *I_LocateWad(void) +{ + const char *waddir; + + I_OutputMsg("Looking for WADs in: "); + waddir = locateWad(); + I_OutputMsg("\n"); + + if (waddir) + { + // change to the directory where we found srb2.srb +#if defined (_WIN32) + SetCurrentDirectoryA(waddir); +#else + if (chdir(waddir) == -1) + I_OutputMsg("Couldn't change working directory\n"); +#endif + } + return waddir; +} + +#ifdef __linux__ +#define MEMINFO_FILE "/proc/meminfo" +#define MEMTOTAL "MemTotal:" +#define MEMAVAILABLE "MemAvailable:" +#define MEMFREE "MemFree:" +#define CACHED "Cached:" +#define BUFFERS "Buffers:" +#define SHMEM "Shmem:" + +/* Parse the contents of /proc/meminfo (in buf), return value of "name" + * (example: MemTotal) */ +static long get_entry(const char* name, const char* buf) +{ + long val; + char* hit = strstr(buf, name); + if (hit == NULL) { + return -1; + } + + errno = 0; + val = strtol(hit + strlen(name), NULL, 10); + if (errno != 0) { + CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); + return -1; + } + return val; +} +#endif + +size_t I_GetFreeMem(size_t *total) +{ +#ifdef FREEBSD + u_int v_free_count, v_page_size, v_page_count; + size_t size = sizeof(v_free_count); + sysctlbyname("vm.stats.vm.v_free_count", &v_free_count, &size, NULL, 0); + size = sizeof(v_page_size); + sysctlbyname("vm.stats.vm.v_page_size", &v_page_size, &size, NULL, 0); + size = sizeof(v_page_count); + sysctlbyname("vm.stats.vm.v_page_count", &v_page_count, &size, NULL, 0); + + if (total) + *total = v_page_count * v_page_size; + return v_free_count * v_page_size; +#elif defined (SOLARIS) + /* Just guess */ + if (total) + *total = 32 << 20; + return 32 << 20; +#elif defined (_WIN32) + MEMORYSTATUS info; + + info.dwLength = sizeof (MEMORYSTATUS); + GlobalMemoryStatus( &info ); + if (total) + *total = (size_t)info.dwTotalPhys; + return (size_t)info.dwAvailPhys; +#elif defined (__OS2__) + UINT32 pr_arena; + + if (total) + DosQuerySysInfo( QSV_TOTPHYSMEM, QSV_TOTPHYSMEM, + (PVOID) total, sizeof (UINT32)); + DosQuerySysInfo( QSV_MAXPRMEM, QSV_MAXPRMEM, + (PVOID) &pr_arena, sizeof (UINT32)); + + return pr_arena; +#elif defined (__linux__) + /* Linux */ + char buf[1024]; + char *memTag; + size_t freeKBytes; + size_t totalKBytes; + INT32 n; + INT32 meminfo_fd = -1; + long Cached; + long MemFree; + long Buffers; + long Shmem; + long MemAvailable = -1; + + meminfo_fd = open(MEMINFO_FILE, O_RDONLY); + n = read(meminfo_fd, buf, 1023); + close(meminfo_fd); + + if (n < 0) + { + // Error + if (total) + *total = 0L; + return 0; + } + + buf[n] = '\0'; + if ((memTag = strstr(buf, MEMTOTAL)) == NULL) + { + // Error + if (total) + *total = 0L; + return 0; + } + + memTag += sizeof (MEMTOTAL); + totalKBytes = (size_t)atoi(memTag); + + if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) + { + Cached = get_entry(CACHED, buf); + MemFree = get_entry(MEMFREE, buf); + Buffers = get_entry(BUFFERS, buf); + Shmem = get_entry(SHMEM, buf); + MemAvailable = Cached + MemFree + Buffers - Shmem; + + if (MemAvailable == -1) + { + // Error + if (total) + *total = 0L; + return 0; + } + freeKBytes = MemAvailable; + } + else + { + memTag += sizeof (MEMAVAILABLE); + freeKBytes = atoi(memTag); + } + + if (total) + *total = totalKBytes << 10; + return freeKBytes << 10; +#else + // Guess 48 MB. + if (total) + *total = 48<<20; + return 48<<20; +#endif +} + +// note CPUAFFINITY code used to reside here +void I_RegisterSysCommands(void) {} + +boolean I_InitNetwork(void) +{ + // this must exist, but this is actually handled in i_tcp.c + return false; +} diff --git a/src/dedicated/i_threads.c b/src/dedicated/i_threads.c new file mode 100644 index 000000000..f981fa961 --- /dev/null +++ b/src/dedicated/i_threads.c @@ -0,0 +1,364 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2020-2023 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 + +#if defined (__unix__) || (!defined(__APPLE__) && defined (UNIXCOMMON)) + +#include + +#include "../i_threads.h" +#include "../doomdef.h" + +typedef struct thread_s thread_t; + +struct thread_s +{ + thread_t *next; + void *userdata; + I_thread_fn func; + pthread_t thread; +}; + +// we use a linked list to avoid moving memory blocks when allocating new threads. +static thread_t *thread_list; +static pthread_mutex_t thread_lock = PTHREAD_MUTEX_INITIALIZER; + +static void *HandleThread(void *data) +{ + thread_t *thread = data; + thread->func(thread->userdata); + + pthread_mutex_lock(&thread_lock); + thread->func = NULL; + pthread_mutex_unlock(&thread_lock); + return NULL; +} + +void +I_spawn_thread ( + const char * name, + I_thread_fn entry, + void * userdata +) +{ + thread_t *thread; + (void)name; + + pthread_mutex_lock(&thread_lock); + thread = thread_list; + while (thread != NULL) + { + if (thread->func == NULL) + { + // join with the exited thread to release it's resources. + pthread_join(thread->thread, NULL); + break; + } + thread = thread->next; + } + if (thread == NULL) + { + thread = malloc(sizeof(thread_t)); + thread->next = thread_list; + thread_list = thread; + } + + thread->func = entry; + thread->userdata = userdata; + pthread_create(&thread->thread, NULL, HandleThread, thread); + pthread_mutex_unlock(&thread_lock); +} + +int I_thread_is_stopped(void) +{ + thread_t *thread; + pthread_mutex_lock(&thread_lock); + thread = thread_list; + while (thread != NULL) + { + if (thread->func != NULL) + { + pthread_mutex_unlock(&thread_lock); + return false; + } + thread = thread->next; + } + pthread_mutex_unlock(&thread_lock); + return true; +} + +void I_start_threads(void) +{ +} + +void I_stop_threads(void) +{ + thread_t *thread = thread_list; + while (thread != NULL) + { + // join with all threads here, since finished threads haven't been awaited yet. + pthread_join(thread->thread, NULL); + thread = thread->next; + } +} + +void I_lock_mutex(I_mutex *anchor) +{ + pthread_mutex_lock(&thread_lock); + if (*anchor == NULL) + { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + + // SRB2 relies on lock recursion, so we need a mutex configured for that. + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + *anchor = malloc(sizeof(pthread_mutex_t)); + pthread_mutex_init(*anchor, &attr); + pthread_mutexattr_destroy(&attr); + } + pthread_mutex_unlock(&thread_lock); + pthread_mutex_lock(*anchor); +} + +void I_unlock_mutex(I_mutex id) +{ + pthread_mutex_unlock(id); +} + +void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) +{ + I_Assert(mutex_id != NULL); + pthread_mutex_lock(&thread_lock); + if (*cond_anchor == NULL) + { + *cond_anchor = malloc(sizeof(pthread_cond_t)); + pthread_cond_init(*cond_anchor, NULL); + } + pthread_mutex_unlock(&thread_lock); + pthread_cond_wait(*cond_anchor, mutex_id); +} + +void I_wake_one_cond(I_cond *anchor) +{ + pthread_mutex_lock(&thread_lock); + if (*anchor == NULL) + { + *anchor = malloc(sizeof(pthread_cond_t)); + pthread_cond_init(*anchor, NULL); + } + pthread_mutex_unlock(&thread_lock); + pthread_cond_signal(*anchor); +} + +void I_wake_all_cond(I_cond *anchor) +{ + pthread_mutex_lock(&thread_lock); + if (*anchor == NULL) + { + *anchor = malloc(sizeof(pthread_cond_t)); + pthread_cond_init(*anchor, NULL); + } + pthread_mutex_unlock(&thread_lock); + pthread_cond_broadcast(*anchor); +} +#elif defined (_WIN32) +#include + +#include "../i_threads.h" +#include "../doomdef.h" +#include "../doomtype.h" + +typedef struct thread_s thread_t; + +struct thread_s +{ + thread_t *next; + void *userdata; + I_thread_fn func; + HANDLE thread; + DWORD thread_id; +}; + +// we use a linked list to avoid moving memory blocks when allocating new threads. +static thread_t *thread_list; +static CRITICAL_SECTION thread_lock; + +static DWORD __stdcall HandleThread(void *data) +{ + thread_t *thread = data; + thread->func(thread->userdata); + + EnterCriticalSection(&thread_lock); + thread->func = NULL; + LeaveCriticalSection(&thread_lock); + return 0; +} + +void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata) +{ + thread_t *thread; + (void)name; + EnterCriticalSection(&thread_lock); + thread = thread_list; + while (thread != NULL) + { + if (thread->func == NULL) + { + CloseHandle(thread->thread); + break; + } + thread = thread->next; + } + if (thread == NULL) + { + thread = malloc(sizeof(thread_t)); + thread->next = thread_list; + thread_list = thread; + } + + thread->func = entry; + thread->userdata = userdata; + thread->thread = CreateThread(NULL, 0, HandleThread, thread, 0, &thread->thread_id); + LeaveCriticalSection(&thread_lock); +} + +int I_thread_is_stopped(void) +{ + thread_t *thread; + EnterCriticalSection(&thread_lock); + thread = thread_list; + while (thread != NULL) + { + if (thread->func != NULL) + { + LeaveCriticalSection(&thread_lock); + return false; + } + thread = thread->next; + } + LeaveCriticalSection(&thread_lock); + return true; +} + +void I_start_threads(void) +{ + InitializeCriticalSection(&thread_lock); +} + +void I_stop_threads(void) +{ + thread_t *thread = thread_list; + while (thread != NULL) + { + WaitForSingleObject(thread->thread, INFINITE); + CloseHandle(thread->thread); + thread = thread->next; + } + DeleteCriticalSection(&thread_lock); +} + +void I_lock_mutex(I_mutex *anchor) +{ + EnterCriticalSection(&thread_lock); + if (*anchor == NULL) + { + *anchor = malloc(sizeof(CRITICAL_SECTION)); + InitializeCriticalSection(*anchor); + } + LeaveCriticalSection(&thread_lock); + EnterCriticalSection(*anchor); +} + +void I_unlock_mutex(I_mutex id) +{ + LeaveCriticalSection(id); +} + +void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) +{ + I_Assert(mutex_id != NULL); + EnterCriticalSection(&thread_lock); + if (*cond_anchor == NULL) + { + *cond_anchor = malloc(sizeof(CONDITION_VARIABLE)); + InitializeConditionVariable(*cond_anchor); + } + LeaveCriticalSection(&thread_lock); + SleepConditionVariableCS(*cond_anchor, mutex_id, INFINITE); +} + +void I_wake_one_cond(I_cond *anchor) +{ + EnterCriticalSection(&thread_lock); + if (*anchor == NULL) + { + *anchor = malloc(sizeof(CONDITION_VARIABLE)); + InitializeConditionVariable(*anchor); + } + LeaveCriticalSection(&thread_lock); + WakeConditionVariable(*anchor); +} + +void I_wake_all_cond(I_cond *anchor) +{ + EnterCriticalSection(&thread_lock); + if (*anchor == NULL) + { + *anchor = malloc(sizeof(CONDITION_VARIABLE)); + InitializeConditionVariable(*anchor); + } + LeaveCriticalSection(&thread_lock); + WakeAllConditionVariable(*anchor); +} +#else +void I_spawn_thread(const char *name, I_thread_fn entry, void *userdata) +{ + (void)name; + entry(userdata); +} + +int I_thread_is_stopped(void) +{ +} + +void I_start_threads(void) +{ +} + +void I_stop_threads(void) +{ +} + +void I_lock_mutex(I_mutex *anchor) +{ + (void)anchor; +} + +void I_unlock_mutex(I_mutex id) +{ + (void)id; +} + +void I_hold_cond(I_cond *cond_anchor, I_mutex mutex_id) +{ + (void)cond_anchor; + (void)mutex_id; +} + +void I_wake_one_cond(I_cond *anchor) +{ + (void)anchor; +} + +void I_wake_all_cond(I_cond *anchor) +{ + (void)anchor; +} +#endif diff --git a/src/dedicated/i_video.c b/src/dedicated/i_video.c new file mode 100644 index 000000000..6c0b6644a --- /dev/null +++ b/src/dedicated/i_video.c @@ -0,0 +1,154 @@ +// Emacs style mode select -*- C++ -*- +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// +// Copyright (C) 1993-1996 by id Software, Inc. +// Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 2014-2018 by Sonic Team Junior. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +//----------------------------------------------------------------------------- +/// \file +/// \brief SRB2 graphics stuff for dedicated + +#include "../doomdef.h" +#include "../i_system.h" +#include "../i_video.h" +#include "../console.h" +#include "../command.h" +#include "../i_system.h" +#include "../screen.h" + +rendermode_t rendermode = render_none; + +boolean highcolor = false; + +// synchronize page flipping with screen refresh +consvar_t cv_vidwait = {"vid_wait", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +static CV_PossibleValue_t keyboardlayout_cons_t[] = {{1,"Default US"}, {2, "Native"}, {3, "AZERTY"}, {0, NULL}}; +consvar_t cv_keyboardlayout = {"keyboardlayout", "Default US", CV_SAVE, keyboardlayout_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_alwaysgrabmouse = {"alwaysgrabmouse", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + +INT32 numcontrollers = 0; + +UINT8 graphics_started = 0; // Is used in console.c and screen.c + +// To disable fullscreen at startup; is set in VID_PrepareModeList +boolean allow_fullscreen = false; +UINT16 realwidth = BASEVIDWIDTH; +UINT16 realheight = BASEVIDHEIGHT; + +extern boolean consolevent; + +void I_GetConsoleEvents(void); + +void I_GetEvent(void) +{ +} + +void I_StartupMouse(void) +{ +} + +// +// I_OsPolling +// +void I_OsPolling(void) +{ + if (consolevent) + I_GetConsoleEvents(); +} + +// +// I_UpdateNoBlit +// +void I_UpdateNoBlit(void) +{ +} + +// +// I_FinishUpdate +// +void I_FinishUpdate(void) +{ +} + +// +// I_UpdateNoVsync +// +void I_UpdateNoVsync(void) +{ +} + +// +// I_ReadScreen +// +void I_ReadScreen(UINT8 *scr) +{ + (void)scr; +} + +// +// I_SetPalette +// +void I_SetPalette(RGBA_t *palette) +{ + (void)palette; +} + +// return number of fullscreen + X11 modes +INT32 VID_NumModes(void) +{ + return 0; +} + +const char *VID_GetModeName(INT32 modenum) +{ + (void)modenum; + return NULL; +} + +INT32 VID_GetModeForSize(INT32 w, INT32 h) +{ + (void)w; + (void)h; + return -1; +} + +void VID_PrepareModeList(void) +{ +} + +INT32 VID_SetMode(INT32 modeNum) +{ + (void)modeNum; + return true; +} + +void I_StartupGraphics(void) +{ +} + +void I_ShutdownGraphics(void) +{ +} + +UINT32 I_GetRefreshRate(void) +{ + return 0; +} + +boolean I_UseNativeKeyboard(void) +{ + return false; +} diff --git a/src/m_misc.c b/src/m_misc.c index 3f57c7c7c..bdfa0c779 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -55,12 +55,13 @@ #ifdef HAVE_SDL #include "sdl/hwsym_sdl.h" +#endif + #ifdef __linux__ #ifndef _LARGEFILE64_SOURCE typedef off_t off64_t; #endif #endif -#endif #if defined(__MINGW32__) && ((__GNUC__ > 7) || (__GNUC__ == 6 && __GNUC_MINOR__ >= 3)) && (__GNUC__ < 8) #define PRIdS "u" diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index d6a007919..f033b678a 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -20,7 +20,7 @@ #include "../doomdef.h" #include "../m_argv.h" #include "../d_main.h" -#include "../m_misc.h"/* path shit */ +#include "../m_misc.h" /* path shit */ #include "../i_system.h" #if defined (__GNUC__) || defined (__unix__)