diff --git a/linuxdoom-1.10/Makefile b/linuxdoom-1.10/Makefile index 8c6979455..ca48387ee 100644 --- a/linuxdoom-1.10/Makefile +++ b/linuxdoom-1.10/Makefile @@ -4,9 +4,8 @@ # # $Log:$ # -CC= gcc # gcc or g++ - -CFLAGS=-g -Wall -DNORMALUNIX -DLINUX # -DUSEASM +CC= g++ +CFLAGS= -g -Wall -DNORMALUNIX -DLINUX -std=c++11 LDFLAGS=-L/usr/X11R6/lib LIBS=-lXext -lX11 -lnsl -lm @@ -92,4 +91,4 @@ $(O)/%.o: %.c ############################################################# # -############################################################# \ No newline at end of file +############################################################# diff --git a/linuxdoom-1.10/doomdef.h b/linuxdoom-1.10/doomdef.h index 185047760..a42fd6c4a 100644 --- a/linuxdoom-1.10/doomdef.h +++ b/linuxdoom-1.10/doomdef.h @@ -95,7 +95,12 @@ typedef enum // For resize of screen, at start of game. // It will not work dynamically, see visplanes. // -#define BASE_WIDTH 320 +#define BASEWIDTH 320 +#define BASEHEIGHT 240 // Changed from 200 to 240 for proper 4:3 + +// Support for higher resolutions +#define SCREENWIDTH 640 // Can be modified at runtime +#define SCREENHEIGHT 480 // It is educational but futile to change this // scaling e.g. to 2. Drawing of status bar, diff --git a/linuxdoom-1.10/game/game.h b/linuxdoom-1.10/game/game.h new file mode 100644 index 000000000..3124736bf --- /dev/null +++ b/linuxdoom-1.10/game/game.h @@ -0,0 +1,15 @@ +// New modular structure +namespace doom { + class Game { + public: + Game(); + bool Init(); + void Tick(); + void Shutdown(); + + private: + std::unique_ptr renderer; + std::unique_ptr sound; + std::unique_ptr input; + }; +} \ No newline at end of file diff --git a/linuxdoom-1.10/i_input.h b/linuxdoom-1.10/i_input.h new file mode 100644 index 000000000..8ffb012cf --- /dev/null +++ b/linuxdoom-1.10/i_input.h @@ -0,0 +1,19 @@ +class InputSystem { +public: + void Init(); + void Update(); + + // Support for modern input devices + bool IsKeyPressed(int key); + float GetMouseX(); + float GetMouseY(); + + // Add gamepad support + bool HasGamepad(); + float GetAxisValue(int axis); + bool IsButtonPressed(int button); + +private: + void ProcessEvents(); + void UpdateGamepad(); +}; \ No newline at end of file diff --git a/linuxdoom-1.10/i_sound.c b/linuxdoom-1.10/i_sound.c index a327bfa29..202ab0ec2 100644 --- a/linuxdoom-1.10/i_sound.c +++ b/linuxdoom-1.10/i_sound.c @@ -96,7 +96,7 @@ static int flag = 0; #define BUFMUL 4 #define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) -#define SAMPLERATE 11025 // Hz +#define SAMPLERATE 44100 // Hz #define SAMPLESIZE 2 // 16bit // The actual lengths of all sound effects. @@ -182,78 +182,82 @@ myioctl // This function loads the sound data from the WAD lump, // for single sound. // -void* -getsfx -( char* sfxname, - int* len ) -{ - unsigned char* sfx; - unsigned char* paddedsfx; - int i; - int size; - int paddedsize; - char name[20]; - int sfxlump; +void* getsfx(const char* sfxname, int* len) { + unsigned char *sfx, *paddedsfx; + int i, size, paddedsize; + char name[64]; // Increased size for safety. + int sfxlump; + + // Build the lump name safely. + if (snprintf(name, sizeof(name), "ds%s", sfxname) >= sizeof(name)) { + fprintf(stderr, "Error: sfxname too long for buffer\n"); + exit(EXIT_FAILURE); + } - - // Get the sound data from the WAD, allocate lump - // in zone memory. - sprintf(name, "ds%s", sfxname); - - // Now, there is a severe problem with the - // sound handling, in it is not (yet/anymore) - // gamemode aware. That means, sounds from - // DOOM II will be requested even with DOOM - // shareware. - // The sound list is wired into sounds.c, - // which sets the external variable. - // I do not do runtime patches to that - // variable. Instead, we will use a - // default sound for replacement. - if ( W_CheckNumForName(name) == -1 ) - sfxlump = W_GetNumForName("dspistol"); - else - sfxlump = W_GetNumForName(name); - - size = W_LumpLength( sfxlump ); + // Check if the lump exists. + if (W_CheckNumForName(name) == -1) { + fprintf(stderr, "Warning: Lump '%s' not found. Using default sound 'dspistol'.\n", name); + sfxlump = W_GetNumForName("dspistol"); + if (sfxlump == -1) { + fprintf(stderr, "Critical error: Default sound 'dspistol' not found in WAD.\n"); + exit(EXIT_FAILURE); + } + } else { + sfxlump = W_GetNumForName(name); + } - // Debug. - // fprintf( stderr, "." ); - //fprintf( stderr, " -loading %s (lump %d, %d bytes)\n", - // sfxname, sfxlump, size ); - //fflush( stderr ); - - sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC ); + // Get the lump length. + size = W_LumpLength(sfxlump); + if (size < 8) { + fprintf(stderr, "Error: Lump '%s' is too small (size=%d)\n", name, size); + exit(EXIT_FAILURE); + } - // Pads the sound effect out to the mixing buffer size. - // The original realloc would interfere with zone memory. - paddedsize = ((size-8 + (SAMPLECOUNT-1)) / SAMPLECOUNT) * SAMPLECOUNT; + // Cache the lump data. + sfx = (unsigned char*)W_CacheLumpNum(sfxlump, PU_STATIC); + if (!sfx) { + fprintf(stderr, "Error: Failed to cache lump '%s'\n", name); + exit(EXIT_FAILURE); + } - // Allocate from zone memory. - paddedsfx = (unsigned char*)Z_Malloc( paddedsize+8, PU_STATIC, 0 ); - // ddt: (unsigned char *) realloc(sfx, paddedsize+8); - // This should interfere with zone memory handling, - // which does not kick in in the soundserver. + /* + * The original code seems to assume the first 8 bytes are a header, + * and the actual sound data starts at offset 8. + * Verify that this is the intended behavior. + */ + int dataSize = size - 8; + // Calculate the padded size to be a multiple of SAMPLECOUNT. + paddedsize = ((dataSize + SAMPLECOUNT - 1) / SAMPLECOUNT) * SAMPLECOUNT; + + // Allocate memory for padded data. We allocate 8 extra bytes at the beginning. + paddedsfx = (unsigned char*)Z_Malloc(paddedsize + 8, PU_STATIC, 0); + if (!paddedsfx) { + fprintf(stderr, "Error: Memory allocation failed for padded sfx data.\n"); + exit(EXIT_FAILURE); + } - // Now copy and pad. - memcpy( paddedsfx, sfx, size ); - for (i=size ; i +#include +#include "doomdef.h" +#include "i_system.h" +#include "v_video.h" +#include "d_main.h" + +static int current_mode; +static byte* screen_buffer; + +boolean I_InitSVGA(void) +{ + // Initialize SVGA library + vga_init(); + + // Try to set highest supported mode + // Common SVGA modes: 640x480, 800x600, 1024x768 + if (vga_hasmode(G1024x768x256)) { + current_mode = G1024x768x256; + SCREENWIDTH = 1024; + SCREENHEIGHT = 768; + } else if (vga_hasmode(G800x600x256)) { + current_mode = G800x600x256; + SCREENWIDTH = 800; + SCREENHEIGHT = 600; + } else { + current_mode = G640x480x256; + SCREENWIDTH = 640; + SCREENHEIGHT = 480; + } + + if (vga_setmode(current_mode) == -1) + I_Error("Could not set SVGA mode"); + + // Allocate screen buffer + screen_buffer = Z_Malloc(SCREENWIDTH * SCREENHEIGHT, PU_STATIC, NULL); + screens[0] = screen_buffer; + + return true; +} + +void I_UpdateSVGAScreen(void) +{ + // Copy buffer to SVGA memory + vga_setpage(0); + memcpy(vga_getgraphmem(), screen_buffer, SCREENWIDTH * SCREENHEIGHT); +} \ No newline at end of file diff --git a/linuxdoom-1.10/i_video.c b/linuxdoom-1.10/i_video.c index 9b311b39a..03149becd 100644 --- a/linuxdoom-1.10/i_video.c +++ b/linuxdoom-1.10/i_video.c @@ -691,7 +691,18 @@ void grabsharedmemory(int size) void I_InitGraphics(void) { - +#ifdef USE_SVGA + if (M_CheckParm("-svga")) + { + if (I_InitSVGA()) + { + // Override default update function + I_FinishUpdate = I_UpdateSVGAScreen; + return; + } + } +#endif + // Fallback to existing X11 initialization... char* displayname; char* d; int n; diff --git a/linuxdoom-1.10/m_config.h b/linuxdoom-1.10/m_config.h new file mode 100644 index 000000000..d34b6cf06 --- /dev/null +++ b/linuxdoom-1.10/m_config.h @@ -0,0 +1,22 @@ +class Config { +public: + static void LoadFromFile(const char* filename); + static void SaveToFile(const char* filename); + + // Runtime configuration + struct { + int screen_width; + int screen_height; + bool fullscreen; + bool vsync; + std::string language; + float mouse_sensitivity; + } video; + + struct { + bool enable_sound; + int sample_rate; + float music_volume; + float sfx_volume; + } audio; +}; \ No newline at end of file