Merge pull request #367 from winterheart/lnxcontroller

Reordering linux modules, cleanup code
This commit is contained in:
Louis Gombert
2024-05-22 18:37:18 +00:00
committed by GitHub
45 changed files with 104 additions and 230 deletions

View File

@@ -145,6 +145,7 @@ include_directories(
"ddebug" # -*-
"fix" # -*-
"lib" # TODO: Remove after untying all modules
"linux" # -*-
"Descent3"
${PLATFORM_INCLUDES}
)
@@ -161,19 +162,17 @@ add_subdirectory(ddebug)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_subdirectory(dd_grwin32)
add_subdirectory(dd_vidwin32)
add_subdirectory(win32)
add_subdirectory(dd_sndlib)
add_subdirectory(ddio_win)
else()
add_subdirectory(linux)
add_subdirectory(ddvid_lnx)
add_subdirectory(dd_lnxsound)
add_subdirectory(lnxcontroller)
add_subdirectory(ddio_lnx)
endif()
add_subdirectory(ddio_common)
add_subdirectory(dd_video)
add_subdirectory(fix)
add_subdirectory(manage)
add_subdirectory(grtext)

View File

@@ -51,7 +51,7 @@
#define __BRIEFPARSE_H_
#if defined(__LINUX__)
#include "linux/linux_fix.h" //for stricmp
#include "linux_fix.h" //for stricmp
#endif
#include "TelComEfxStructs.h"

View File

@@ -273,19 +273,19 @@ set(CPPS
weather.cpp)
if(WIN32)
set(PLATFORM_LIBS dd_sndlib dd_grwin32 dd_vidwin32 ddio_win win32 wsock32.lib winmm.lib
set(PLATFORM_LIBS dd_sndlib dd_grwin32 ddio_win win32 wsock32.lib winmm.lib
${DSOUND_LIBRARY} ${DINPUT_LIBRARY} ${DXGUID_LIBRARY} ${DDRAW_LIBRARY})
set(PLATFORM_CPPS winmain.cpp)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /NODEFAULTLIB:LIBC")
endif()
if(UNIX AND NOT APPLE)
set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL2::SDL2 m ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES})
set(PLATFORM_LIBS linux dd_lnxsound ddio_lnx SDL2::SDL2 m ${CMAKE_DL_LIBS} ${CURSES_LIBRARIES})
set(PLATFORM_CPPS loki_utils.c lnxmain.cpp)
endif()
if(APPLE)
set(PLATFORM_LIBS linux dd_lnxsound ddvid_lnx lnxcontroller ddio_lnx SDL2::SDL2 ${CURSES_LIBRARIES})
set(PLATFORM_LIBS linux dd_lnxsound ddio_lnx SDL2::SDL2 ${CURSES_LIBRARIES})
set(PLATFORM_CPPS loki_utils.c lnxmain.cpp)
set(CMAKE_EXE_LINKER_FLAGS "-framework IOKit -framework Cocoa -framework OpenGL -framework Carbon")
endif()
@@ -297,7 +297,7 @@ add_executable(Descent3
${HEADERS} ${CPPS} ${PLATFORM_CPPS} ${INCS}
)
target_link_libraries(Descent3
2dlib AudioEncode bitmap cfile czip d3music ddebug ddio_common libmve libacm
2dlib AudioEncode bitmap cfile czip d3music dd_video ddebug ddio_common libmve libacm
fix grtext manage mem misc model module movie stream_audio
music networking physics renderer rtperformance sndlib ui unzip vecmat md5
${PLATFORM_LIBS})

View File

@@ -95,7 +95,7 @@
#include "psrand.h"
#if defined(__LINUX__)
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
/*

View File

@@ -791,12 +791,9 @@ void PrintDedicatedMessage(const char *fmt, ...) {
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include "linux/linux_fix.h"
#include "linux_fix.h"
#include "errno.h"
#define BOOL bool
#ifndef SOCKET

View File

@@ -23,36 +23,26 @@
* $NoKeywords: $
*/
#include <stdlib.h>
#include <cstdlib>
#include <cstring>
#include <csignal>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <time.h>
#include "SDL.h"
#include <SDL.h>
#include "program.h"
#include "mono.h"
#include "descent.h"
#include "application.h"
#include "appdatabase.h"
#include "pserror.h"
#include "args.h"
#include "init.h"
#include "renderer.h"
#include "ddio.h"
#include "ddvid.h"
#include "osiris_dll.h"
#include "loki_utils.h"
#include "log.h"
#if defined(MACOSX)
#include <SDL.h>
#endif
extern bool ddio_mouseGrabbed;
int no_debug_dialog = 0;
const char *DMFCGetString(int d);
@@ -184,7 +174,6 @@ void fatal_signal_handler(int signum) {
break;
}
sync(); // just in case.
_exit(-10);
}

View File

@@ -651,6 +651,10 @@
*
* $NoKeywords: $
*/
#include <cstdio>
#include <cstring>
#include "menu.h"
#include "mmItem.h"
#include "game.h"
@@ -681,9 +685,6 @@ bool Directplay_lobby_launched_game = false;
#include "d3music.h"
#include "newui_core.h"
#include <string.h>
#include <algorithm>
#define IDV_QUIT 0xff
// Menu Item Defines
#define IDV_NEWGAME 10
@@ -1381,7 +1382,7 @@ int DisplayLevelWarpDlg(int max_level) {
}
sheet->NewGroup(buffer, 0, 0);
input_text = sheet->AddEditBox(NULL, 4, 64, IDV_QUIT, UIED_NUMBERS);
itoa(chosen_level, input_text, 10);
sprintf(input_text, "%d", chosen_level);
redo_level_choose:
hwnd.Open();
res = hwnd.DoUI();

View File

@@ -499,7 +499,7 @@
#include "player_external.h"
#if defined(__LINUX__)
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
#include "multi_external.h" //defines and structs are in here

View File

@@ -188,7 +188,7 @@
#define NEWUI_H
#if defined(__LINUX__)
#include "linux/linux_fix.h" //fix some of the stricmp's
#include "linux_fix.h" //fix some of the stricmp's
#endif
#include "newui_core.h"

View File

@@ -29,7 +29,7 @@
#include <io.h>
#else
// Linux Build Includes
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
#include "byteswap.h"

View File

@@ -92,7 +92,7 @@
#include "windows.h"
#include "winbase.h"
#elif defined(__LINUX__)
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
#include "ssl_lib.h"

17
dd_video/CMakeLists.txt Normal file
View File

@@ -0,0 +1,17 @@
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})
target_link_libraries(dd_video PRIVATE
$<$<PLATFORM_ID:Linux,Darwin>:
linux
>
)

View File

@@ -22,15 +22,13 @@
* $NoKeywords: $
*/
#include "pserror.h"
#include <cstring>
#include <cstdlib>
#include "ddvid.h"
#include "application.h"
#include "linux/lnxapp.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#undef EGA
// #include <vga.h>
#include "lnxapp.h"
typedef struct {
int width, height, bytesperpixel, linewidth;
} tinfo;

View File

@@ -1,8 +0,0 @@
set(HEADERS
ddvidlib.h)
set(CPPS
video_win32.cpp
vidWin32FS.cpp
vidWin32Win.cpp)
add_library(dd_vidwin32 STATIC ${HEADERS} ${CPPS})

View File

@@ -58,15 +58,17 @@
*/
#include "ddio.h"
#include "ddio_lnx.h"
#include "pserror.h"
#include "mem.h"
#include "lnxfix.h"
#include "linux_fix.h"
#if MACOSX
#include <cctype>
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
@@ -76,7 +78,6 @@
#include <errno.h>
#include <signal.h>
#include <dirent.h>
#include <ctype.h>
#define _MAX_DIR 256

View File

@@ -1,5 +0,0 @@
set(HEADERS)
set(CPPS
video_lnx.cpp)
add_library(ddvid_lnx STATIC ${HEADERS} ${CPPS})

View File

@@ -258,7 +258,7 @@ void DestroyController(gameController *ctl);
#if defined(WIN32)
#include "win\WinController.h"
#elif defined(__LINUX__)
#include "linux/lnxcontroller.h"
#include "lnxcontroller.h"
#endif
#endif

View File

@@ -112,6 +112,6 @@ public:
#if defined(WIN32)
#include "win\Win32App.h"
#elif defined(__LINUX__)
#include "linux/lnxapp.h"
#include "lnxapp.h"
#endif
#endif

View File

@@ -23,7 +23,7 @@
#include "cfile.h"
#ifdef __LINUX__
#include "linux/linux_fix.h" //needed for stricmp's throughout bitmap lib
#include "linux_fix.h" //needed for stricmp's throughout bitmap lib
#endif
#define MAX_BITMAPS 5000

View File

@@ -1,57 +0,0 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* 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 3 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
--- HISTORICAL COMMENTS FOLLOW ---
* $Logfile: /DescentIII/Main/lnxfix.h $
* $Revision: 1.2 $
* $Date: 2004/02/09 04:14:49 $
* $Author: kevinb $
*
* File operations not covered properly in ANSI C
*
* $Log: lnxfix.h,v $
* Revision 1.2 2004/02/09 04:14:49 kevinb
* Added newlines to all headers to reduce number of warnings printed
*
* Made some small changes to get everything compiling.
*
* All Ready to merge the 1.5 tree.
*
* Revision 1.1.1.1 2000/04/18 00:00:32 icculus
* initial checkin
*
*
* 2 4/15/99 1:39a Jeff
* changes for linux compile
*
* 1 4/14/99 7:51p Jeff
*
*
* $NoKeywords: $
*/
#ifndef LINUX_FIX_H_
#define LINUX_FIX_H_
#if defined(__LINUX__)
#define stricmp(x, y) strcasecmp(x, y)
#define _vsnprintf(a, b, c, d) vsnprintf(a, b, c, d)
extern bool Dedicated_server;
#endif
#endif

View File

@@ -52,7 +52,7 @@
#ifndef __LNXVIDEOMODE_H__
#define __LNXVIDEOMODE_H__
#include "linux/linux_fix.h"
#include "linux_fix.h"
#include <SDL.h>
#define MODE_OK 0

View File

@@ -26,7 +26,7 @@
#include "manage_external.h"
#if defined(__LINUX__)
#include "linux/linux_fix.h" //for strnicmp,etc.
#include "linux_fix.h" //for strnicmp,etc.
#endif
#define LOCAL_TABLE "Table.loc"

View File

@@ -211,7 +211,7 @@ static inline void INADDR_GET_SUN_SUNB(struct in_addr *st, unsigned char *s_b1,
#include "SDL.h"
#include "SDL_thread.h"
#include "linux/linux_fix.h"
#include "linux_fix.h"
#define SOCKET int
#define BOOL bool

View File

@@ -268,7 +268,7 @@
#define UI_H
#if defined(__LINUX__)
#include "linux/linux_fix.h" //for stricmp's through code
#include "linux_fix.h" //for stricmp's through code
#endif
#include "uires.h"

View File

@@ -1,10 +1,19 @@
set(HEADERS registry.h)
set(CPPS
lnxcon.cpp
lnxcon_raw.cpp
lnxcontroller.cpp
lnxapp.cpp
lnxcon_null.cpp
lnxdata.cpp
registry.cpp)
# DynXLib.cpp
add_library(linux STATIC ${HEADERS} ${CPPS})
registry.cpp
)
add_library(linux STATIC ${CPPS})
target_link_libraries(linux PRIVATE
cfile
)
target_include_directories(linux PUBLIC
$<BUILD_INTERFACE:
${PROJECT_SOURCE_DIR}/linux
>
)

View File

@@ -20,7 +20,6 @@
#define __LINUX_FIX_H_
#include <sys/stat.h>
#include <math.h>
#define LOKI_VERSION ""
@@ -30,8 +29,8 @@ void GlobalFree(void *);
void *GlobalAlloc(int flags, int size);
void *GlobalLock(HGLOBAL hMem);
void Sleep(int millis);
char *itoa(int value, char *string, int radix);
char *strupr(char *string);
// Replace missing defines from stdlib.h
#define _MAX_PATH 260 /* max. length of full pathname*/
#define _MAX_FNAME 256 /* max. length of path component*/
@@ -45,25 +44,12 @@ char *strupr(char *string);
// _stdcall replacement
#define _stdcall __attribute__((stdcall))
static inline int _filelength(int fd) {
struct stat statbuf;
if (fstat(fd, &statbuf) != 0) {
return -1;
}
return statbuf.st_size;
}
#ifndef stricmp
#define stricmp(a, b) strcasecmp(a, b)
#endif
#define strnicmp(a, b, c) strncasecmp(a, b, c)
#define _fstat(a, b) fstat(a, b)
#define _fileno(a) fileno(a)
#define strcmpi(a, b) stricmp(a, b)
#define strcmpni(a, b, c) strnicmp(a, b, c)
#define _chmod(a, b) chmod(a, b)
#if defined(__aarch64__)
#define _finite(a) isfinite(a)

View File

@@ -68,39 +68,27 @@
* $NoKeywords: $
*/
#include "application.h"
#include "linux/lnxapp.h"
#include "mono.h"
#include <stdlib.h>
#include "ddio.h"
// #include "local_malloc.h"
#include <unistd.h>
#include <ctype.h>
#include <cstdlib>
#include <cctype>
#include <sys/time.h>
#include <sys/types.h>
#include <term.h>
#include <termios.h>
#include "application.h"
#include "lnxapp.h"
#ifdef buttons // termios.h defines buttons, but SDL's headers use that symbol.
#undef buttons
#endif
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <SDL.h>
static struct termios Linux_initial_terminal_settings;
bool oeLnxApplication::os_initialized = false;
bool oeLnxApplication::first_time = true;
bool con_Create(int flags);
void con_Destroy(void);
void con_Defer(void);
void con_Destroy();
void con_Defer();
void GlobalFree(void *mptr) {
if (mptr)
@@ -109,17 +97,17 @@ void GlobalFree(void *mptr) {
void *GlobalAlloc(int flags, int size) {
if (size <= 0)
return NULL;
return nullptr;
return malloc(size);
}
void *GlobalLock(HGLOBAL hMem) { return hMem; }
void Sleep(int millis) {
struct timeval tv;
struct timeval tv{};
tv.tv_sec = 0;
tv.tv_usec = millis * 1000;
select(0, NULL, NULL, NULL, &tv);
select(0, nullptr, nullptr, nullptr, &tv);
}
char *strupr(char *string) {
@@ -130,23 +118,12 @@ char *strupr(char *string) {
return string;
}
char *itoa(int value, char *string, int radix) {
if (radix == 10) {
sprintf(string, "%d", value);
} else if (radix == 16) {
sprintf(string, "%x", value);
} else {
mprintf((0, "!!!!!!!!!!!!!!!WARNING CALLING itoa WITHOUT 10 or 16 RADIX!!!!!!!!!!!!!!!!!!!!!!\n"));
sprintf(string, "%d", value);
}
return string;
}
static unsigned int LinuxAppFlags = 0;
// static Display *LinuxAppDisplay=NULL;
static bool LinuxAppSetAtExit = false;
static bool LinuxAppDontCallShutdown = false;
void LnxAppShutdown(void) {
void LnxAppShutdown() {
if (LinuxAppDontCallShutdown)
return;
LinuxAppDontCallShutdown = true;
@@ -240,7 +217,7 @@ void oeLnxApplication::delay(float secs) {
}
// Function to get the flags
int oeLnxApplication::flags(void) const { return m_Flags; }
int oeLnxApplication::flags() const { return m_Flags; }
// Sizes the displayable region of the app (the window)
void oeLnxApplication::set_sizepos(int x, int y, int w, int h) {

View File

@@ -41,13 +41,13 @@
* $NoKeywords: $
*/
#include <cstring>
#include "Controller.h"
#include <string.h>
#include <memory.h>
#include "ddio.h"
#include "pserror.h"
#include "joystick.h"
#include "inffile.h"
#include "lnxcontroller.h"
// Sorry! This is needed for the semi-hacky mouselook support
#include "descent.h"

View File

@@ -1,7 +0,0 @@
set(HEADERS)
set(CPPS lnxcontroller.cpp)
add_library(lnxcontroller STATIC ${HEADERS} ${CPPS})
target_link_libraries(lnxcontroller PRIVATE
cfile
)

View File

@@ -441,7 +441,7 @@
#include <errno.h>
#include <string.h>
#if defined(__LINUX__)
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
#include "descent.h"
#include "manage.h"

View File

@@ -109,7 +109,7 @@ static bool mod_FindRealFileNameCaseInsenstive(const char *directory, const char
#include <stdarg.h>
#include <string.h>
#if defined(__LINUX__)
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
#if defined(WIN32) // INSTEAD OF MAKING MODULE HAVE DEPENDENCIES, PUT THE 2 DDIO FUNCTIONS I NEED HERE
// Split a pathname into its component parts

View File

@@ -269,7 +269,7 @@
#ifdef __LINUX__
#include <string.h>
#include "linux/linux_fix.h"
#include "linux_fix.h"
#endif
// Uncomment out this line of code to build the demo version of the multiplayer connection dlls

View File

@@ -98,7 +98,7 @@
#include <sys/time.h>
#include <unistd.h>
#include "linux/linux_fix.h"
#include "linux_fix.h"
// Linux includes/defines
#if !MACOSX

View File

@@ -20,18 +20,14 @@
#if defined(WIN32)
#include <windows.h>
#elif defined(__LINUX__)
#include "linux/linux_fix.h"
#include "lnxscreenmode.h"
#else
#endif
#include "pstypes.h"
#include "pserror.h"
#include "mono.h"
#include "3d.h"
#include "renderer.h"
#include "ddvid.h"
#include "ddio.h"
#include "application.h"
#include "bitmap.h"
#include "lightmap.h"

View File

@@ -1217,14 +1217,11 @@ Parameters:
$$END
*/
void aShowHUDMessage(const char *format, ...) {
#if defined(__LINUX__)
#define _vsnprintf vsnprintf
#endif
msafe_struct mstruct;
va_list args;
va_start(args, format);
_vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
va_end(args);
mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
@@ -1252,7 +1249,7 @@ void aShowHUDMessageObj(const char *format, int objhandle, ...) {
va_list args;
va_start(args, objhandle);
_vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
va_end(args);
mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
@@ -1283,7 +1280,7 @@ void aShowColoredHUDMessage(int red, int green, int blue, const char *format, ..
va_list args;
va_start(args, format);
_vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
va_end(args);
mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate
@@ -1314,7 +1311,7 @@ void aShowColoredHUDMessageObj(int red, int green, int blue, const char *format,
va_list args;
va_start(args, objhandle);
_vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
vsnprintf(mstruct.message, sizeof(mstruct.message) - 1, format, args);
va_end(args);
mstruct.message[sizeof(mstruct.message) - 1] = 0; // if message too long, vsnprintf() won't terminate

View File

@@ -16,14 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
int _vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
int stricmp(const char *string1, const char *string2);
#include <cstring>
void _splitpath(const char *srcPath, char *drive, char *path, char *filename, char *ext) {
int pathStart = -1;
@@ -103,8 +96,4 @@ void _splitpath(const char *srcPath, char *drive, char *path, char *filename, ch
}
}
int _vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) {
return vsnprintf(buffer, count, format, argptr);
}
int stricmp(const char *string1, const char *string2) { return strcasecmp(string1, string2); }

View File

@@ -19,12 +19,11 @@
#ifndef __LINUX_LIB_H_
#define __LINUX_LIB_H_
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
int _vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
int stricmp(const char *string1, const char *string2);
#endif

View File

@@ -25,13 +25,7 @@
#include "osiris_common.h"
#ifdef __LINUX__
#ifndef MACOSX
// typedef unsigned int size_t;
#endif
#include <stdarg.h>
void _splitpath(const char *path, char *drive, char *dir, char *fname, char *ext);
int _vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
int stricmp(const char *string1, const char *string2);
#include "linux_lib.h"
#endif
// ===========================================================

View File

@@ -132,13 +132,15 @@
* $NoKeywords: $
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "UIlib.h"
#include "grtext.h"
#include "Macros.h"
#include "mem.h"
#include <string.h>
#include <stdlib.h>
static UIEdit *UI_current_editbox = NULL;
@@ -203,7 +205,7 @@ void UIEdit::SetText(const char *text) {
if (CHECK_FLAG(m_Flags, UIED_NUMBERS)) {
int num = atoi(text);
itoa(num, m_TextBuf, 10);
sprintf(m_TextBuf, "%d", num);
} else {
strcpy(m_TextBuf, text);
}