Windows SDL2 compilation

This commit is contained in:
Louis Gombert 2024-06-21 18:46:53 +02:00
parent d9749b729d
commit 91c18fefc5
29 changed files with 148 additions and 727 deletions

View File

@ -93,12 +93,13 @@ install(
if(UNIX)
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:-Wno-multichar;${BITS};${EXTRA_CXX_FLAGS}>")
add_compile_options("$<$<COMPILE_LANGUAGE:C>:${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)

View File

@ -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()

View File

@ -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;

View File

@ -26,7 +26,10 @@
#include <cstdlib>
#include <cstring>
#include <csignal>
#ifndef WIN32
#include <unistd.h>
#endif
#include <SDL.h>
@ -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();

View File

@ -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;

View File

@ -1,12 +1,5 @@
set(CPPS
$<$<PLATFORM_ID:Windows>:
video_win32.cpp
vidWin32FS.cpp
vidWin32Win.cpp
>
$<$<PLATFORM_ID:Linux,Darwin>:
video_lnx.cpp
>
)
add_library(dd_video STATIC ${CPPS})

View File

@ -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
$<$<PLATFORM_ID:Darwin,Linux>:
lnxfile.cpp
lnxforcefeedback.cpp
lnxio.cpp
sdljoy.cpp
lnxkey.cpp
lnxkey_null.cpp
lnxmouse.cpp
lnxkey_sdl.cpp
>
$<$<PLATFORM_ID:Windows>:
winfile.cpp
winforcefeedback.cpp
winio.cpp
winjoy.cpp
winkey.cpp
winmouse.cpp
>
)
add_library(ddio STATIC ${CPPS})

View File

@ -62,6 +62,10 @@
#include <mach-o/dyld.h>
#endif
#ifdef WIN32
#include <windows.h>
#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;

View File

@ -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})

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -52,7 +52,9 @@
#ifndef __LNXVIDEOMODE_H__
#define __LNXVIDEOMODE_H__
#ifdef __LINUX__
#include "linux_fix.h"
#endif
#include <SDL.h>
#define MODE_OK 0

View File

@ -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)

View File

@ -19,9 +19,12 @@
#include <assert.h>
#include <errno.h>
#include <sys/types.h>
#ifdef __LINUX__
#include <sys/time.h>
#include <sys/fcntl.h>
#include <unistd.h>
#include <sched.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -33,7 +36,6 @@
#include "SDL.h"
#include "SDL_audio.h"
#include <sched.h>
#define FRAGMENT_LENGTH (LnxBuffers[0]->bps >> 4)
#define FREQUENCY_SHIFT (14)

View File

@ -23,9 +23,8 @@
#include <cstdint>
#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);

View File

@ -70,9 +70,13 @@
#include <cstdlib>
#include <cctype>
#ifdef __LINUX___
#include <sys/time.h>
#include <term.h>
#include <termios.h>
#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;

View File

@ -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)

View File

@ -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,
},
};

View File

@ -42,11 +42,17 @@
*/
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#ifdef __LINUX__
#include <unistd.h>
#include <pwd.h>
#else
#include <windows.h>
#include <Lmcons.h>
#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<size_t>(unamelen);
#endif
}

View File

@ -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;

View File

@ -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<LPDWORD>(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<LPDWORD>(ppos), reinterpret_cast<LPDWORD>(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<LPDWORD>(numbytes1), ptr2,
reinterpret_cast<LPDWORD>(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<LPWAVEFORMATEX>(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

View File

@ -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

View File

@ -19,11 +19,9 @@
#include "byteswap.h"
#if defined(WIN32)
#include <windows.h>
#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 <string.h>
#include "HardwareInternal.h"
#include "../Descent3/args.h"
#include <SDL.h>
#include <NewBitmap.h>
@ -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<HWnd>(reinterpret_cast<oeWin32Application *>(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<float>(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) {

View File

@ -31,8 +31,6 @@
#elif defined(__LINUX__)
#include <unistd.h>
#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];

View File

@ -4,17 +4,9 @@ set(CPPS
soundload.cpp
ddsoundload.cpp
ssl_lib.cpp
$<$<PLATFORM_ID:Windows>:
ds3dlib.cpp
ds3dgeometry.cpp
dsound3d.cpp
eax.cpp
>
$<$<PLATFORM_ID:Darwin,Linux>:
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
$<BUILD_INTERFACE:

View File

@ -464,11 +464,7 @@
#include "voice.h"
#include "descent.h"
#if defined(WIN32)
#include "ds3dlib.h"
#elif defined(__LINUX__)
#include "sdlsound.h"
#endif
hlsSystem Sound_system;
char Sound_quality = SQT_NORMAL;
@ -528,11 +524,7 @@ int hlsSystem::InitSoundLib(oeApplication *sos, char mixer_type, char quality, b
// Create and initialize the low-level sound library
if (m_ll_sound_ptr == NULL)
#if defined(WIN32)
m_ll_sound_ptr = new win_llsSystem;
#elif defined(__LINUX__)
m_ll_sound_ptr = new lnxsound;
#endif
ASSERT(m_ll_sound_ptr);
if (m_ll_sound_ptr == NULL)
return 0;

View File

@ -2,6 +2,10 @@
"builtin-baseline": "000d1bda1ffa95a73e0b40334fa4103d6f4d3d48",
"dependencies": [
"gtest",
"zlib"
"zlib",
{
"name": "sdl2",
"version>=": "2.30.1"
}
]
}