diff --git a/CMakeLists.txt b/CMakeLists.txt index 160ee917..4421865c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,12 +93,13 @@ install( if(UNIX) add_compile_options("$<$:-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>") add_compile_options("$<$:${BITS}>") - - find_package(SDL2 REQUIRED) - # Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both. - message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}") endif() +find_package(SDL2 REQUIRED) +# Some versions of the SDL2 find_package set SDL2_INCLUDE_DIR and some set a plural SDL2_INCLUDE_DIRS. Check both. +message("SDL2 Include Dir is ${SDL2_INCLUDE_DIR} ${SDL2_INCLUDE_DIRS}") + + if(CMAKE_SYSTEM_NAME STREQUAL "Linux") message("Building for Linux") add_compile_definitions(__LINUX__ _USE_OGL_ACTIVE_TEXTURES PRIMARY_HOG=\"d3-linux.hog\") @@ -178,12 +179,12 @@ add_subdirectory(czip) add_subdirectory(d3music) add_subdirectory(ddebug) -if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - add_subdirectory(dd_grwin32) - add_subdirectory(win32) -else() - add_subdirectory(linux) -endif() +# if(CMAKE_SYSTEM_NAME STREQUAL "Windows") +# add_subdirectory(dd_grwin32) +# add_subdirectory(win32) +# else() +add_subdirectory(linux) +# endif() add_subdirectory(ddio) add_subdirectory(dd_video) diff --git a/Descent3/CMakeLists.txt b/Descent3/CMakeLists.txt index ea6c1d36..b096e82b 100644 --- a/Descent3/CMakeLists.txt +++ b/Descent3/CMakeLists.txt @@ -271,9 +271,9 @@ set(CPPS weather.cpp) if(WIN32) - set(PLATFORM_LIBS dd_grwin32 win32 wsock32.lib winmm.lib + set(PLATFORM_LIBS linux wsock32.lib winmm.lib SDL2::SDL2 ${DSOUND_LIBRARY} ${DINPUT_LIBRARY} ${DXGUID_LIBRARY} ${DDRAW_LIBRARY}) - set(PLATFORM_CPPS winmain.cpp) + set(PLATFORM_CPPS loki_utils.c lnxmain.cpp) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB:LIBC") endif() diff --git a/Descent3/ctlconfig.cpp b/Descent3/ctlconfig.cpp index 854c2d05..9bb9e3b9 100644 --- a/Descent3/ctlconfig.cpp +++ b/Descent3/ctlconfig.cpp @@ -1126,12 +1126,6 @@ int weapon_select_dialog(int wpn, bool is_secondary) { return retval; } void joystick_calibration() { -#if defined(WIN32) - extern bool Win32JoystickCalibrate(); - if (!Win32JoystickCalibrate()) { - DoMessageBox(TXT_ERROR, TXT_CALIBJOYSTICKFAIL, MB_OK); - } -#endif } void joystick_settings_dialog() { newuiTiledWindow wnd; diff --git a/Descent3/lnxmain.cpp b/Descent3/lnxmain.cpp index 9d65df78..7aecb070 100644 --- a/Descent3/lnxmain.cpp +++ b/Descent3/lnxmain.cpp @@ -26,7 +26,10 @@ #include #include #include + +#ifndef WIN32 #include +#endif #include @@ -40,6 +43,7 @@ #include "osiris_dll.h" #include "loki_utils.h" + #include "log.h" extern bool ddio_mouseGrabbed; @@ -137,10 +141,13 @@ void just_exit(void) { #endif SDL_Quit(); +#ifdef __LINUX__ sync(); // just in case. +#endif _exit(0); } +#ifdef __LINUX__ void fatal_signal_handler(int signum) { switch (signum) { case SIGHUP: @@ -172,7 +179,7 @@ void fatal_signal_handler(int signum) { void safe_signal_handler(int signum) {} -void install_signal_handlers(void) { +void install_signal_handlers() { struct sigaction sact, fact; memset(&sact, 0, sizeof(sact)); @@ -207,6 +214,9 @@ void install_signal_handlers(void) { if (sigaction(SIGTRAP, &fact, NULL)) fprintf(stderr, "SIG: Unable to install SIGTRAP\n"); } +#else +void install_signal_handlers() {} +#endif // --------------------------------------------------------------------------- // Define our operating system specific extensions to the gameos system // --------------------------------------------------------------------------- @@ -279,7 +289,6 @@ int SDLCALL d3SDLEventFilter(void *userdata, SDL_Event *event) { case SDL_KEYUP: case SDL_KEYDOWN: return (sdlKeyFilter(event)); - case SDL_JOYBALLMOTION: case SDL_MOUSEMOTION: return (sdlMouseMotionFilter(event)); @@ -341,8 +350,14 @@ static void check_beta() { // creates all the OS objects and then runs Descent 3. // this is all this function should do. // --------------------------------------------------------------------------- -int main(int argc, char *argv[]) { +// int main(int argc, char *argv[]) { +int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR szCmdLine, int nCmdShow) { +// int main(void) { + int argc = 1; + char* argv[10]; +#ifdef __LINUX__ __orig_pwd = getcwd(NULL, 0); +#endif /* Setup the logging system */ InitLog(); @@ -588,6 +603,7 @@ int main(int argc, char *argv[]) { } bool run_d3 = true; +#ifdef __LINUX__ if (flags & APPFLAG_USESERVICE) { run_d3 = false; pid_t np = fork(); @@ -601,12 +617,13 @@ int main(int argc, char *argv[]) { printf("Successfully forked process [new sid=%d pid=%d]\n", np, pp); } } +#endif if (run_d3) { oeD3LnxApp d3(flags); oeD3LnxDatabase dbase; StartDedicatedServer(); - PreInitD3Systems(); + PreInitD3Systems(); d3.init(); d3.run(); diff --git a/Descent3/program.cpp b/Descent3/program.cpp index 4292369e..1e8b8076 100644 --- a/Descent3/program.cpp +++ b/Descent3/program.cpp @@ -70,13 +70,7 @@ program_version Program_version; // Initializes the current program state void ProgramVersion(int version_type, uint8_t major, uint8_t minor, uint8_t build) { -#if defined(WIN32) // I'm sorry. Samir - oeWin32AppDatabase dbase((oeWin32AppDatabase *)Database); -#elif defined(__LINUX__) oeLnxAppDatabase dbase((oeLnxAppDatabase *)Database); -#else - oeAppDatabase dbase(Database); // this will fail without an operating system equiv -#endif Program_version.version_type = version_type; Program_version.major = major; diff --git a/dd_video/CMakeLists.txt b/dd_video/CMakeLists.txt index 7152166a..fec366e8 100644 --- a/dd_video/CMakeLists.txt +++ b/dd_video/CMakeLists.txt @@ -1,12 +1,5 @@ set(CPPS - $<$: - video_win32.cpp - vidWin32FS.cpp - vidWin32Win.cpp - > - $<$: video_lnx.cpp - > ) add_library(dd_video STATIC ${CPPS}) diff --git a/ddio/CMakeLists.txt b/ddio/CMakeLists.txt index 5b51ea92..20fedb09 100644 --- a/ddio/CMakeLists.txt +++ b/ddio/CMakeLists.txt @@ -3,23 +3,18 @@ set(CPPS ddio.cpp file.cpp key.cpp + lnxforcefeedback.cpp + lnxio.cpp + sdljoy.cpp + lnxkey.cpp + lnxkey_null.cpp + lnxmouse.cpp + lnxkey_sdl.cpp $<$: lnxfile.cpp - lnxforcefeedback.cpp - lnxio.cpp - sdljoy.cpp - lnxkey.cpp - lnxkey_null.cpp - lnxmouse.cpp - lnxkey_sdl.cpp > $<$: winfile.cpp - winforcefeedback.cpp - winio.cpp - winjoy.cpp - winkey.cpp - winmouse.cpp > ) add_library(ddio STATIC ${CPPS}) diff --git a/ddio/lnxio.cpp b/ddio/lnxio.cpp index 90076485..89e643f9 100644 --- a/ddio/lnxio.cpp +++ b/ddio/lnxio.cpp @@ -62,6 +62,10 @@ #include #endif +#ifdef WIN32 +#include +#endif + #include "application.h" #include "ddio.h" #include "pserror.h" @@ -103,12 +107,7 @@ void ddio_DebugMessage(unsigned err, char *fmt, ...) { } bool ddio_GetBinaryPath(char *exec_path, size_t len) { -#ifndef MACOSX - if (realpath("/proc/self/exe", exec_path) == NULL) { - perror("realpath"); - return false; - } -#else +#ifdef MACOSX if (exec_path == NULL || len == 0) { fprintf(stderr, "Invalid arguments\n"); return false; @@ -119,6 +118,20 @@ bool ddio_GetBinaryPath(char *exec_path, size_t len) { fprintf(stderr, "Buffer too small; need size %u\n", size); return false; } +#elif defined(__LINUX__) + if (realpath("/proc/self/exe", exec_path) == NULL) { + perror("realpath"); + return false; + } +#else + if (GetModuleFileName(NULL, exec_path, len) == 0) { + DWORD error = GetLastError(); + Error("GetModuleFileName failed!"); + return false; + } + exec_path[len - 1] = '\0'; + return true; + #endif exec_path[len - 1] = '\0'; return true; diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt index d623ba2d..e3ccb3b1 100644 --- a/editor/CMakeLists.txt +++ b/editor/CMakeLists.txt @@ -562,10 +562,10 @@ set(SOURCE ) # Editor only works in Windows -set(PLATFORM_LIBS dd_grwin32 win32 wsock32.lib winmm.lib +set(PLATFORM_LIBS wsock32.lib winmm.lib ${DSOUND_LIBRARY} ${DINPUT_LIBRARY} ${DXGUID_LIBRARY} ${DDRAW_LIBRARY}) set(PLATFORM_SOURCES ../descent3/winmain.cpp) -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE /SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC") add_executable(Descent3Editor ${HEADERS} ${SOURCE} ${PLATFORM_SOURCES}) diff --git a/lib/Controller.h b/lib/Controller.h index 29381d85..ba810339 100644 --- a/lib/Controller.h +++ b/lib/Controller.h @@ -264,10 +264,10 @@ public: gameController *CreateController(int num_funcs, ct_function *funcs, char *remote_ip); void DestroyController(gameController *ctl); -#if defined(WIN32) -#include "win\WinController.h" -#elif defined(__LINUX__) +// #if defined(WIN32) +// #include "win\WinController.h" +// #elif defined(__LINUX__) #include "lnxcontroller.h" -#endif +// #endif #endif diff --git a/lib/appdatabase.h b/lib/appdatabase.h index a29e1d0e..81cf0ebf 100644 --- a/lib/appdatabase.h +++ b/lib/appdatabase.h @@ -100,10 +100,6 @@ public: Win32 Samir Win32Database.h 06/97 */ -#if defined(WIN32) -#include "win\Win32Database.h" -#elif defined(__LINUX__) #include "linux/lnxdatabase.h" -#endif #endif diff --git a/lib/application.h b/lib/application.h index 7dcc45ad..60d5a62e 100644 --- a/lib/application.h +++ b/lib/application.h @@ -109,9 +109,9 @@ public: Add a platform to this list once implemented: Win32 Samir Win32App.h 06/97 */ -#if defined(WIN32) -#include "win\win32app.h" -#elif defined(__LINUX__) +// #if defined(WIN32) +// #include "win\win32app.h" +// #elif defined(__LINUX__) #include "lnxapp.h" -#endif -#endif +// #endif +#endif // APP_H diff --git a/lib/linux/lnxdatabase.h b/lib/linux/lnxdatabase.h index 32f839ca..bae181d0 100644 --- a/lib/linux/lnxdatabase.h +++ b/lib/linux/lnxdatabase.h @@ -31,6 +31,7 @@ class CRegistry; #include "Macros.h" +#include "appdatabase.h" /* oeLnxAppDatabase to get info about the application from a managed database (or a custom info file) diff --git a/lib/lnxscreenmode.h b/lib/lnxscreenmode.h index 7f10e4dd..3f036f4c 100644 --- a/lib/lnxscreenmode.h +++ b/lib/lnxscreenmode.h @@ -52,7 +52,9 @@ #ifndef __LNXVIDEOMODE_H__ #define __LNXVIDEOMODE_H__ +#ifdef __LINUX__ #include "linux_fix.h" +#endif #include #define MODE_OK 0 diff --git a/libmve/CMakeLists.txt b/libmve/CMakeLists.txt index 7b92311a..6c20a973 100644 --- a/libmve/CMakeLists.txt +++ b/libmve/CMakeLists.txt @@ -5,16 +5,12 @@ set(HEADERS platform.h snd8to16.h SystemInterfaces.h) + set(CPPS mveasm.cpp mvelibl.cpp - platform.cpp) - -set(PLATFORM_CPPS) - -if(UNIX) - set(PLATFORM_CPPS "lnxdsound.cpp") -endif() + platform.cpp + lnxdsound.cpp) add_library(libmve STATIC ${HEADERS} ${CPPS} ${PLATFORM_CPPS}) - +target_link_libraries(libmve PRIVATE SDL2::SDL2) diff --git a/libmve/lnxdsound.cpp b/libmve/lnxdsound.cpp index 0cc133a9..64dbed72 100644 --- a/libmve/lnxdsound.cpp +++ b/libmve/lnxdsound.cpp @@ -19,9 +19,12 @@ #include #include #include +#ifdef __LINUX__ #include #include #include +#include +#endif #include #include #include @@ -33,7 +36,6 @@ #include "SDL.h" #include "SDL_audio.h" -#include #define FRAGMENT_LENGTH (LnxBuffers[0]->bps >> 4) #define FREQUENCY_SHIFT (14) diff --git a/libmve/mvelibl.h b/libmve/mvelibl.h index b0169c9f..0540ef4d 100644 --- a/libmve/mvelibl.h +++ b/libmve/mvelibl.h @@ -23,9 +23,8 @@ #include #include "SystemInterfaces.h" -#if defined(__LINUX__) #include "lnxdsound.h" -#endif + // Call this function to provide hooks into your memory management. typedef void *(mve_cb_alloc)(unsigned size); typedef void(mve_cb_free)(void *p); diff --git a/linux/lnxapp.cpp b/linux/lnxapp.cpp index c3109abd..ee249d4e 100644 --- a/linux/lnxapp.cpp +++ b/linux/lnxapp.cpp @@ -70,9 +70,13 @@ #include #include +#ifdef __LINUX___ #include #include #include +#else +#include "winsock.h" +#endif #include "application.h" #include "lnxapp.h" @@ -81,7 +85,9 @@ #undef buttons #endif +#ifdef __LINUX___ static struct termios Linux_initial_terminal_settings; +#endif bool oeLnxApplication::os_initialized = false; bool oeLnxApplication::first_time = true; @@ -116,7 +122,9 @@ void LnxAppShutdown() { LinuxAppDontCallShutdown = true; if (LinuxAppFlags & OEAPP_CONSOLE) { con_Destroy(); +#ifdef __LINUX__ tcsetattr(0, TCSANOW, &Linux_initial_terminal_settings); +#endif } } @@ -126,7 +134,9 @@ oeLnxApplication::oeLnxApplication(unsigned flags) { m_AppActive = true; if (flags & OEAPP_CONSOLE) { +#ifdef __LINUX__ tcgetattr(0, &Linux_initial_terminal_settings); +#endif con_Create(m_Flags); } @@ -140,7 +150,9 @@ oeLnxApplication::oeLnxApplication(unsigned flags) { // Create object with a premade info oeLnxApplication::oeLnxApplication(tLnxAppInfo *appinfo) { +#ifdef __LINUX__ tcgetattr(0, &Linux_initial_terminal_settings); +#endif m_Flags = appinfo->flags; m_X = appinfo->wnd_x; m_Y = appinfo->wnd_y; diff --git a/linux/lnxapp.h b/linux/lnxapp.h index e3b059a5..486aac75 100644 --- a/linux/lnxapp.h +++ b/linux/lnxapp.h @@ -19,7 +19,9 @@ #ifndef LNXAPP_H #define LNXAPP_H +#ifdef __LINUX__ #include "linux_fix.h" +#endif // if no-display/input specifier is given, it will use defaults #define APPFLAG_USESERVICE 0x00000100 // console (run no output/input) diff --git a/linux/lnxcon.cpp b/linux/lnxcon.cpp index fbd3773d..56695809 100644 --- a/linux/lnxcon.cpp +++ b/linux/lnxcon.cpp @@ -101,18 +101,18 @@ void con_raw_Puts(int window, const char *str); Console_Commands commands[Console_total] = { { - .con_Create = con_null_Create, - .con_Destroy = con_null_Destroy, - .con_Defer = con_null_Defer, - .con_Input = con_null_Input, - .con_Puts = con_null_Puts, + con_null_Create, + con_null_Destroy, + con_null_Defer, + con_null_Input, + con_null_Puts, }, { - .con_Create = con_raw_Create, - .con_Destroy = con_raw_Destroy, - .con_Defer = con_raw_Defer, - .con_Input = con_raw_Input, - .con_Puts = con_raw_Puts, + con_raw_Create, + con_raw_Destroy, + con_raw_Defer, + con_raw_Input, + con_raw_Puts, }, }; diff --git a/linux/lnxdata.cpp b/linux/lnxdata.cpp index a87655d4..48c09388 100644 --- a/linux/lnxdata.cpp +++ b/linux/lnxdata.cpp @@ -42,11 +42,17 @@ */ #include -#include #include -#include #include +#ifdef __LINUX__ +#include +#include +#else +#include +#include +#endif + #include "appdatabase.h" #include "linux/lnxdatabase.h" #include "pserror.h" @@ -64,13 +70,14 @@ oeLnxAppDatabase::oeLnxAppDatabase() { // then close the database char *prefPath = (char *)loki_getprefpath(); - size_t fileLen = strlen(prefPath) + strlen(REGISTRY_FILENAME) + 2; - char fileName[fileLen]; + const size_t fileLen = strlen(prefPath) + strlen(REGISTRY_FILENAME) + 2; + char* fileName = new char[fileLen]; snprintf(fileName, fileLen, "%s/%s", prefPath, REGISTRY_FILENAME); database = new CRegistry(fileName); database->Import(); create_record("Version"); + delete [] fileName; } oeLnxAppDatabase::oeLnxAppDatabase(oeLnxAppDatabase *parent) { @@ -208,6 +215,7 @@ bool oeLnxAppDatabase::write(const char *label, int entry) { // get the current user's name from the os void oeLnxAppDatabase::get_user_name(char *buffer, size_t *size) { +#ifdef __LINUX__ struct passwd *pwuid = getpwuid(geteuid()); if ((pwuid != NULL) && (pwuid->pw_name != NULL)) { @@ -219,4 +227,9 @@ void oeLnxAppDatabase::get_user_name(char *buffer, size_t *size) { buffer[(*size) - 1] = '\0'; *size = strlen(buffer); } +#else +DWORD unamelen = 0; +GetUserName(buffer, &unamelen); +*size = static_cast(unamelen); +#endif } diff --git a/linux/registry.cpp b/linux/registry.cpp index 7068abe6..21d345bc 100644 --- a/linux/registry.cpp +++ b/linux/registry.cpp @@ -55,6 +55,10 @@ #include "registry.h" #include "mono.h" +#if defined(_WIN32) +#define strcasecmp stricmp +#endif + // Convert a string that represents a hex value into an int int hextoi(char *p) { int value = 0; diff --git a/movie/d3movie.cpp b/movie/d3movie.cpp index 2524a977..6168aa44 100644 --- a/movie/d3movie.cpp +++ b/movie/d3movie.cpp @@ -61,200 +61,6 @@ bool Movie_looping = false; #ifndef NO_MOVIES -#ifdef WIN32 -class MovieSoundBuffer : public ISysSoundBuffer { -private: - LPDIRECTSOUNDBUFFER m_pBuffer; - -public: - MovieSoundBuffer(LPDIRECTSOUNDBUFFER buffer) : m_pBuffer(buffer) {} - - //////////////////////////// - // Release - //////////////////////////// - // Releases the memory associated with a sound buffer. This pointer is - // no longer valid after return. - // - // Returns: - // -1 : Invalid Parameter - // 0 : Ok! - int Release() { - m_pBuffer->Release(); - delete this; - return 0; - } - - ////////////////////////////// - // SetVolume - ////////////////////////////// - // Sets the volume of a buffer. - // - // Returns: - // 0 : no error - // -1 : Cannot set volume - // -2 : Invalid parameters - int SetVolume(int32_t vol) { return m_pBuffer->SetVolume(vol); } - - /////////////////////////// - // SetPan - /////////////////////////// - // Sets the pan of a buffer. - // - // Returns: - // 0 : no error - // -1 : Cannot set pan - // -2 : Invalid parameters - int SetPan(int32_t pan) { return m_pBuffer->SetPan(pan); } - - ///////////////////////// - // Stop - ///////////////////////// - // Stops a buffer from playing - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int Stop() { return m_pBuffer->Stop(); } - - ///////////////////////// - // Play - ///////////////////////// - // Starts a buffer playing (or changes the flags for a buffer currently - // playing). - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int Play(uint32_t flags) { - DWORD dsFlags = (flags & LNXSND_LOOPING) ? DSBPLAY_LOOPING : 0; - return m_pBuffer->Play(0, 0, dsFlags); - } - - //////////////////////////// - // GetCaps - //////////////////////////// - // Get the capabilities of a sound buffer - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int GetCaps(SysSoundCaps *caps) { - DSBCAPS dsCaps; - dsCaps.dwSize = sizeof(dsCaps); - int res = m_pBuffer->GetCaps(&dsCaps); - if (res != 0) - return res; - - caps->dwBufferBytes = dsCaps.dwBufferBytes; - caps->dwFlags = dsCaps.dwFlags; - return 0; - } - - ////////////////////////////// - // GetStatus - ////////////////////////////// - // Returns the status of a buffer - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int GetStatus(uint32_t *status) { return m_pBuffer->GetStatus(reinterpret_cast(status)); } - - /////////////////////////////////////// - // GetCurrentPosition - /////////////////////////////////////// - // Returns the current play and write positions of the buffer - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int GetCurrentPosition(uint32_t *ppos, uint32_t *wpos) { - return m_pBuffer->GetCurrentPosition(reinterpret_cast(ppos), reinterpret_cast(wpos)); - } - - /////////////////////////////////////// - // SetCurrentPosition - /////////////////////////////////////// - // Sets the current play position of the buffer - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int SetCurrentPosition(uint32_t pos) { return m_pBuffer->SetCurrentPosition(pos); } - - ///////////////////////// - // Lock - ///////////////////////// - // Locks the given buffer, returning pointer(s) to the buffer(s) along with - // available the size of the buffer(s) for writing. - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int Lock(uint32_t pos, uint32_t numbytes, void **ptr1, uint32_t *numbytes1, void **ptr2, - uint32_t *numbytes2, uint32_t flags) { - return m_pBuffer->Lock(pos, numbytes, ptr1, reinterpret_cast(numbytes1), ptr2, - reinterpret_cast(numbytes2), flags); - } - - /////////////////////////// - // Unlock - /////////////////////////// - // Unlocks a buffer. - // - // Returns: - // 0 : no error - // -1 : invalid parameters - int Unlock(void *ptr1, uint32_t num1, void *ptr2, uint32_t num2) { - return m_pBuffer->Unlock(ptr1, num1, ptr2, num2); - } -}; - -class MovieSoundDevice : public ISoundDevice { -private: - LPDIRECTSOUND m_ds; - -public: - MovieSoundDevice() : m_ds(NULL) {} - - void SetDirectSound(LPDIRECTSOUND ds) { m_ds = ds; } - - LPDIRECTSOUND GetDirectSound() { return m_ds; } - - /////////////////////////////// - // CreateSoundBuffer - /////////////////////////////// - // Creates a sound buffer to be used with mixing and output. - // - // Returns: - // -1 : Invalid Parameter - // -2 : Out of memory - // 0 : Ok! - int CreateSoundBuffer(SysSoundBufferDesc *lbdesc, ISysSoundBuffer **lsndb) { - if (m_ds == NULL) - return -1; - - DSBUFFERDESC dsBufferDesc; - dsBufferDesc.dwSize = sizeof(dsBufferDesc); - dsBufferDesc.dwFlags = lbdesc->dwFlags; - dsBufferDesc.dwBufferBytes = lbdesc->dwBufferBytes; - dsBufferDesc.dwReserved = 0; - dsBufferDesc.lpwfxFormat = reinterpret_cast(lbdesc->lpwfxFormat); - - LPDIRECTSOUNDBUFFER dsSndBuffer = NULL; - int res = m_ds->CreateSoundBuffer(&dsBufferDesc, &dsSndBuffer, NULL); - if (res != DS_OK) { - *lsndb = NULL; - return res; - } - - *lsndb = new MovieSoundBuffer(dsSndBuffer); - return res; - } -}; - -#else - class MovieSoundBuffer : public ISysSoundBuffer { private: LnxSoundBuffer *m_pBuffer; @@ -427,7 +233,6 @@ public: } }; -#endif #endif } // namespace @@ -857,105 +662,6 @@ void mve_ClearRect(int16_t x1, int16_t y1, int16_t x2, int16_t y2) { } #ifndef NO_MOVIES -#ifdef WIN32 -// Internal function to enumerate sound devices -BOOL CALLBACK DSEnumCallback(LPGUID lp_guid, LPCSTR lpstr_description, LPCSTR lpstr_module, LPVOID lp_Context) { - GUID FAR *lp_ret_guid = (GUID FAR *)lp_Context; - - if (SoundCardName[0]) { - if (strcmp(lpstr_description, SoundCardName) == 0) { - if (lp_guid) { - memmove(lp_ret_guid, lp_guid, sizeof(GUID)); - } - - return FALSE; - } - } - - return TRUE; -} - -bool mve_InitSound(oeApplication *app, MovieSoundDevice &device) { - // Perform Direct Sound Initialization - device.SetDirectSound(NULL); - - GUID *pguid = NULL; - GUID card_guid, zero_card_guid; - ZeroMemory(&card_guid, sizeof(GUID)); - ZeroMemory(&zero_card_guid, sizeof(GUID)); - HRESULT hr = DirectSoundEnumerate(DSEnumCallback, &card_guid); - if (hr == DS_OK) { - if (memcmp(&card_guid, &zero_card_guid, sizeof(GUID)) != 0) { - pguid = &card_guid; - } - } - - LPDIRECTSOUND lpDS; - if (DirectSoundCreate(pguid, &lpDS, NULL) != DS_OK) { - return false; - } - - HWND hWnd = (HWND)((oeWin32Application *)app)->m_hWnd; - hr = lpDS->SetCooperativeLevel(hWnd, DSSCL_EXCLUSIVE); - if (hr != DS_OK) { - lpDS->Release(); - return false; - } - - bool use_22k_sound = false; - - // Start Mixer - LPDIRECTSOUNDBUFFER lpPrimaryBuffer; - DSBUFFERDESC dsbd; - memset(&dsbd, 0, sizeof(DSBUFFERDESC)); - dsbd.dwSize = sizeof(DSBUFFERDESC); - dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER; - hr = lpDS->CreateSoundBuffer(&dsbd, &lpPrimaryBuffer, NULL); - if (hr == DS_OK) { - // set format to 44khz if requested. - WAVEFORMATEX fmt; - fmt.cbSize = sizeof(fmt); - fmt.wFormatTag = WAVE_FORMAT_PCM; - fmt.nChannels = 2; - fmt.wBitsPerSample = 16; - fmt.nSamplesPerSec = use_22k_sound ? 22050 : 44100; - fmt.nBlockAlign = fmt.nChannels * (fmt.wBitsPerSample / 8); - fmt.nAvgBytesPerSec = ((DWORD)fmt.nSamplesPerSec) * ((DWORD)fmt.nBlockAlign); - hr = lpPrimaryBuffer->SetFormat(&fmt); - if (hr != DS_OK) { - lpPrimaryBuffer->Release(); - lpDS->Release(); - lpDS = NULL; - return false; - } - - hr = lpPrimaryBuffer->Play(0, 0, DSBPLAY_LOOPING); - if (hr != DS_OK) { - lpPrimaryBuffer->Release(); - lpDS->Release(); - return false; - } - - lpPrimaryBuffer->Release(); - } else { - lpDS->Release(); - return false; - } - - device.SetDirectSound(lpDS); - MVE_sndInit(&device); - - return true; -} - -void mve_CloseSound(MovieSoundDevice &device) { - LPDIRECTSOUND ds = device.GetDirectSound(); - if (ds) { - ds->Release(); - device.SetDirectSound(NULL); - } -} -#else bool mve_InitSound(oeApplication *app, MovieSoundDevice &device) { LnxSoundDevice snddev; @@ -975,6 +681,5 @@ bool mve_InitSound(oeApplication *app, MovieSoundDevice &device) { void mve_CloseSound(MovieSoundDevice &device) { // TODO: close the driver out } -#endif #endif diff --git a/renderer/CMakeLists.txt b/renderer/CMakeLists.txt index 248f799b..8aee52cf 100644 --- a/renderer/CMakeLists.txt +++ b/renderer/CMakeLists.txt @@ -12,12 +12,9 @@ set(CPPS HardwarePoints.cpp HardwareSetup.cpp HardwareTransforms.cpp + lnxscreenmode.cpp ) -if(UNIX) - set(CPPS ${CPPS} lnxscreenmode.cpp) -endif() - # These are excluded. #opengl.cpp #renderer.cpp diff --git a/renderer/HardwareOpenGL.cpp b/renderer/HardwareOpenGL.cpp index 259c0ac3..37117075 100644 --- a/renderer/HardwareOpenGL.cpp +++ b/renderer/HardwareOpenGL.cpp @@ -19,11 +19,9 @@ #include "byteswap.h" #if defined(WIN32) #include -#elif defined(__LINUX__) -#include "lnxscreenmode.h" -#else #endif +#include "lnxscreenmode.h" #include "pserror.h" #include "mono.h" #include "3d.h" @@ -41,6 +39,7 @@ #include #include "HardwareInternal.h" #include "../Descent3/args.h" +#include #include @@ -56,7 +55,6 @@ int FindArg(const char *); void rend_SetLightingState(light_state state); -#define CHANGE_RESOLUTION_IN_FULLSCREEN // General renderer states extern int gpu_Overlay_map; @@ -82,18 +80,9 @@ extern vector View_position; #define CHECK_ERROR(x) -#if defined(WIN32) -// Moved from DDGR library -static HWND hOpenGLWnd = NULL; -static HDC hOpenGLDC = NULL; -HGLRC ResourceContext; -static WORD Saved_gamma_values[256 * 3]; -#elif defined(__LINUX__) SDL_Window *GSDLWindow = NULL; SDL_GLContext GSDLGLContext = NULL; char loadedLibrary[_MAX_PATH]; -#else -#endif #define GET_WRAP_STATE(x) (x >> 4) #define GET_FILTER_STATE(x) (x & 0x0f) @@ -204,19 +193,6 @@ int checkForGLErrors( const char *file, int line ) // Sets up multi-texturing using ARB extensions void opengl_GetDLLFunctions(void) { -#if defined(WIN32) - oglActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)dwglGetProcAddress("glActiveTextureARB"); - if (!oglActiveTextureARB) - goto dll_error; - - oglClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)dwglGetProcAddress("glClientActiveTextureARB"); - if (!oglClientActiveTextureARB) - goto dll_error; - - oglMultiTexCoord4f = (PFNGLMULTITEXCOORD4FARBPROC)dwglGetProcAddress("glMultiTexCoord4f"); - if (!oglMultiTexCoord4f) - goto dll_error; -#else #define mod_GetSymbol(x, funcStr, y) __SDL_mod_GetSymbol(funcStr) oglActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)mod_GetSymbol(OpenGLDLLHandle, "glActiveTextureARB", 255); @@ -231,7 +207,6 @@ void opengl_GetDLLFunctions(void) { } #undef mod_GetSymbol -#endif UseMultitexture = true; return; @@ -406,103 +381,6 @@ void opengl_SetDefaults() { } } -#if defined(WIN32) -// Check for OpenGL support, -int opengl_Setup(HDC glhdc) { - if (!Already_loaded) { - if (!(OpenGLDLLHandle = LoadOpenGLDLL("opengl32.dll"))) { - rend_SetErrorMessage("Failed to load opengl dll!\n"); - Int3(); - return 0; - } - } - - // Finds an acceptable pixel format to render to - PIXELFORMATDESCRIPTOR pfd, pfd_copy; - int pf; - - memset(&pfd, 0, sizeof(pfd)); - pfd.nSize = sizeof(pfd); - pfd.nVersion = 1; - pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_GENERIC_ACCELERATED; - pfd.iPixelType = PFD_TYPE_RGBA; - - /*if (!WindowGL) - { - if (gpu_preferred_state.bit_depth==32) - { - pfd.cColorBits = 32; - pfd.cDepthBits = 32; - } - else - { - pfd.cColorBits = gpu_preferred_state.bit_depth; - pfd.cDepthBits =gpu_preferred_state.bit_depth; - } - - pfd.cColorBits = 16; - pfd.cDepthBits =16; - - } - else - { - pfd.cColorBits = 16; - pfd.cDepthBits =16; - }*/ - - // Find the user's "best match" PFD - pf = ChoosePixelFormat(glhdc, &pfd); - if (pf == 0) { - Int3(); - // FreeLibrary(opengl_dll_handle); - return NULL; - } - - mprintf(0, "Choose pixel format successful!\n"); - - // Try and set the new PFD - if (SetPixelFormat(glhdc, pf, &pfd) == FALSE) { - DWORD ret = GetLastError(); - Int3(); - // FreeLibrary(opengl_dll_handle); - return NULL; - } - - mprintf(0, "SetPixelFormat successful!\n"); - - // Get a copy of the newly set PFD - if (DescribePixelFormat(glhdc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd_copy) == 0) { - Int3(); - // FreeLibrary(opengl_dll_handle); - return NULL; - } - - // Check the returned PFD to see if it is hardware accelerated - if ((pfd_copy.dwFlags & PFD_GENERIC_ACCELERATED) == 0 && (pfd_copy.dwFlags & PFD_GENERIC_FORMAT) != 0) { - Int3(); - // FreeLibrary(opengl_dll_handle); - return NULL; - } - - // Create an OpenGL context, and make it the current context - ResourceContext = dwglCreateContext((HDC)glhdc); - if (ResourceContext == NULL) { - DWORD ret = GetLastError(); - // FreeLibrary(opengl_dll_handle); - Int3(); - return NULL; - } - - ASSERT(ResourceContext != NULL); - mprintf(0, "Making context current\n"); - dwglMakeCurrent((HDC)glhdc, ResourceContext); - - Already_loaded = 1; - - return 1; -} -#elif defined(__LINUX__) - extern bool linux_permit_gamma; extern renderer_preferred_state Render_preferred_state; extern bool ddio_mouseGrabbed; @@ -743,7 +621,6 @@ int opengl_Setup(oeApplication *app, int *width, int *height) { Already_loaded = 1; return 1; } -#endif // Sets up our OpenGL rendering context // Returns 1 if ok, 0 if something bad @@ -763,124 +640,7 @@ int opengl_Init(oeApplication *app, renderer_preferred_state *pref_state) { } int windowX = 0, windowY = 0; -#if defined(WIN32) - /*********************************************************** - * WINDOWS OPENGL - *********************************************************** - */ - static HWnd hwnd = NULL; - if (ParentApplication != NULL) { - hwnd = static_cast(reinterpret_cast(ParentApplication)->m_hWnd); - } - if (!WindowGL) { - // First set our display mode - // Create direct draw surface - - DEVMODE devmode; - - devmode.dmSize = sizeof(devmode); - devmode.dmBitsPerPel = 32; - // devmode.dmBitsPerPel=gpu_preferred_state.bit_depth; - devmode.dmPelsWidth = gpu_preferred_state.width; - devmode.dmPelsHeight = gpu_preferred_state.height; - devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - -#ifdef CHANGE_RESOLUTION_IN_FULLSCREEN - int retval = ChangeDisplaySettings(&devmode, 0); -#else - int retval = DISP_CHANGE_SUCCESSFUL; -#endif - if (retval != DISP_CHANGE_SUCCESSFUL) { - mprintf(0, "Display mode change failed (err=%d), trying default!\n", retval); - retval = -1; - devmode.dmBitsPerPel = 32; - devmode.dmPelsWidth = 640; - devmode.dmPelsHeight = 480; - devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; - - retval = ChangeDisplaySettings(&devmode, 0); - if (retval != DISP_CHANGE_SUCCESSFUL) { - mprintf(0, "OpenGL_INIT:Change display setting failed failed!\n"); - rend_SetErrorMessage("OGL: ChangeDisplaySettings failed. Make sure your desktop is set to 16bit mode!"); - ChangeDisplaySettings(NULL, 0); - opengl_Close(); - return 0; - } else { - gpu_preferred_state.bit_depth = 32; - gpu_preferred_state.width = 640; - gpu_preferred_state.height = 480; - } - } else { - mprintf(0, "Setdisplaymode to %d x %d (%d bits) is successful!\n", gpu_preferred_state.width, - gpu_preferred_state.height, gpu_preferred_state.bit_depth); - } - } - - memset(&gpu_state, 0, sizeof(rendering_state)); - - // These values are set here - samir - if (app != NULL) { - hOpenGLWnd = (HWND)((oeWin32Application *)app)->m_hWnd; - } - - hOpenGLDC = GetDC(hOpenGLWnd); - - if (WindowGL) { - RECT rect; - POINT topLeft; - GetClientRect((HWND)hOpenGLWnd, &rect); - - topLeft.x = rect.left; - topLeft.y = rect.top; - ClientToScreen((HWND)hOpenGLWnd, &topLeft); - - width = rect.right - rect.left + 1; - height = rect.bottom - rect.top + 1; - windowX = topLeft.x; - windowY = topLeft.y; - } else { - SetWindowPos(hOpenGLWnd, HWND_TOPMOST, 0, 0, gpu_preferred_state.width, gpu_preferred_state.height, - SWP_FRAMECHANGED); - width = gpu_preferred_state.width; - height = gpu_preferred_state.height; - RECT rect; - GetWindowRect((HWND)hOpenGLWnd, &rect); - mprintf(0, "rect=%d %d %d %d\n", rect.top, rect.right, rect.bottom, rect.left); - } - - gpu_state.screen_width = width; - gpu_state.screen_height = height; - - if (!opengl_Setup(hOpenGLDC)) { - opengl_Close(); - return 0; - } - - // Save gamma values for later - GetDeviceGammaRamp(hOpenGLDC, (LPVOID)Saved_gamma_values); - -#elif defined(__LINUX__) - /*********************************************************** - * LINUX OPENGL - *********************************************************** - */ - // Setup gpu_state.screen_width & gpu_state.screen_height & width & height - width = gpu_preferred_state.width; - height = gpu_preferred_state.height; - - if (!opengl_Setup(app, &width, &height)) { - opengl_Close(); - return 0; - } - - memset(&gpu_state, 0, sizeof(rendering_state)); - gpu_state.screen_width = width; - gpu_state.screen_height = height; -#else - // Setup gpu_state.screen_width & gpu_state.screen_height & width & height - -#endif // Get some info opengl_GetInformation(); @@ -1056,34 +816,18 @@ void opengl_Close(const bool just_resizing) { mem_free(delete_list); -#if defined(WIN32) - if (dwglMakeCurrent) - dwglMakeCurrent(NULL, NULL); - - if (dwglDeleteContext) - dwglDeleteContext(ResourceContext); - - // Change our display back - if (!WindowGL) { -#ifdef CHANGE_RESOLUTION_IN_FULLSCREEN - ChangeDisplaySettings(NULL, 0); -#endif + if (GSDLGLContext) { + SDL_GL_MakeCurrent(NULL, NULL); + SDL_GL_DeleteContext(GSDLGLContext); + GSDLGLContext = NULL; + GOpenGLFBOWidth = GOpenGLFBOHeight = GOpenGLFBO = GOpenGLRBOColor = GOpenGLRBODepth = 0; } -#elif defined(__LINUX__) - if (GSDLGLContext) { - SDL_GL_MakeCurrent(NULL, NULL); - SDL_GL_DeleteContext(GSDLGLContext); - GSDLGLContext = NULL; - GOpenGLFBOWidth = GOpenGLFBOHeight = GOpenGLFBO = GOpenGLRBOColor = GOpenGLRBODepth = 0; - } - if (!just_resizing && GSDLWindow) { - SDL_DestroyWindow(GSDLWindow); - GSDLWindow = NULL; - } -#else + if (!just_resizing && GSDLWindow) { + SDL_DestroyWindow(GSDLWindow); + GSDLWindow = NULL; + } -#endif if (OpenGL_packed_pixels) { if (opengl_packed_Upload_data) { @@ -1118,17 +862,6 @@ void opengl_Close(const bool just_resizing) { OpenGL_cache_initted = 0; } -#if defined(WIN32) - // Restore gamma values - SetDeviceGammaRamp(hOpenGLDC, (LPVOID)Saved_gamma_values); - // I'm freeing the DC here - samir - ReleaseDC(hOpenGLWnd, hOpenGLDC); -#elif defined(__LINUX__) - -#else - -#endif - // mod_FreeModule (OpenGLDLLHandle); gpu_state.initted = 0; } @@ -1577,26 +1310,6 @@ void rend_SetGammaValue(float val) { gpu_preferred_state.gamma = val; mprintf(0, "Setting gamma to %f\n", val); - -#if defined(WIN32) - WORD rampvals[3 * 256]; - - for (int i = 0; i < 256; i++) { - float norm = (float)i / 255.0f; - - float newval = powf(norm, 1.0f / val); - - newval *= 65535; - - newval = std::min(65535, newval); - - rampvals[i] = newval; - rampvals[i + 256] = newval; - rampvals[i + 512] = newval; - } - - SetDeviceGammaRamp(hOpenGLDC, (LPVOID)rampvals); -#endif } // Resets the texture cache @@ -1967,16 +1680,8 @@ void rend_Flip(void) { // if we're rendering to an FBO, scale to the window framebuffer! if (GOpenGLFBO != 0) { - #if defined(WIN32) - // !!! FIXME: is this expensive? - RECT rectWindow; // rectangle for the client area of the window - GetClientRect(hOpenGLWnd, &rectWindow); - int w = (int) (rectWindow.right - rectWindow.left); - int h = (int) (rectWindow.bottom - rectWindow.top); - #else int w, h; SDL_GL_GetDrawableSize(GSDLWindow, &w, &h); - #endif int scaledHeight, scaledWidth; if (w < h) { @@ -1999,11 +1704,7 @@ void rend_Flip(void) { dglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); } -#if defined(WIN32) - SwapBuffers((HDC)hOpenGLDC); -#elif defined(__LINUX__) SDL_GL_SwapWindow(GSDLWindow); -#endif // go back to drawing on the FBO until we want to blit to the window framebuffer again. if (GOpenGLFBO != 0) { diff --git a/renderer/dyna_gl.h b/renderer/dyna_gl.h index 17e9d871..c6b9a1ca 100644 --- a/renderer/dyna_gl.h +++ b/renderer/dyna_gl.h @@ -31,8 +31,6 @@ #elif defined(__LINUX__) #include #define GLFUNCCALL -#else -#define GLFUNCCALL #endif // ryan's adds. 04/18/2000. @@ -219,7 +217,6 @@ DYNAEXTERN(glBlitFramebufferEXT_fp, dglBlitFramebufferEXT); #ifdef DECLARE_OPENGL static module OpenGLDLLInst; -#ifdef __LINUX__ static void *__SDL_mod_GetSymbol(const char *funcStr) { void *retVal = NULL; @@ -240,8 +237,6 @@ static void *__SDL_mod_GetSymbol(const char *funcStr) { #define mod_GetSymbol(x, funcStr, y) __SDL_mod_GetSymbol(funcStr) /****************** WARNING: NASTY HACK! ***********************/ -#endif - #ifdef __LINUX__ extern char *__orig_pwd; extern char loadedLibrary[_MAX_PATH]; diff --git a/sndlib/CMakeLists.txt b/sndlib/CMakeLists.txt index a194d455..6f9ad8d3 100644 --- a/sndlib/CMakeLists.txt +++ b/sndlib/CMakeLists.txt @@ -4,17 +4,9 @@ set(CPPS soundload.cpp ddsoundload.cpp ssl_lib.cpp - $<$: - ds3dlib.cpp - ds3dgeometry.cpp - dsound3d.cpp - eax.cpp - > - $<$: - mixer.cpp - sdlgeometry.cpp - sdlsound.cpp - > + mixer.cpp + sdlgeometry.cpp + sdlsound.cpp ) add_library(sndlib STATIC ${CPPS}) @@ -24,6 +16,7 @@ target_link_libraries(sndlib PRIVATE mem misc stream_audio + SDL2::SDL2 ) target_include_directories(sndlib PUBLIC $=": "2.30.1" + } ] }