Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/d01 display resolution #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions linuxdoom-1.10/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -92,4 +91,4 @@ $(O)/%.o: %.c

#############################################################
#
#############################################################
#############################################################
7 changes: 6 additions & 1 deletion linuxdoom-1.10/doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions linuxdoom-1.10/game/game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// New modular structure
namespace doom {
class Game {
public:
Game();
bool Init();
void Tick();
void Shutdown();

private:
std::unique_ptr<Renderer> renderer;
std::unique_ptr<Sound> sound;
std::unique_ptr<Input> input;
};
}
19 changes: 19 additions & 0 deletions linuxdoom-1.10/i_input.h
Original file line number Diff line number Diff line change
@@ -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();
};
120 changes: 62 additions & 58 deletions linuxdoom-1.10/i_sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<paddedsize+8 ; i++)
// Copy the entire lump (including header) into the new buffer.
memcpy(paddedsfx, sfx, size);
// Pad the rest of the buffer with the default value (128).
for (i = size; i < paddedsize + 8; i++) {
paddedsfx[i] = 128;
}

// Remove the cached lump.
Z_Free( sfx );
// Preserve padded length.
// Free the original cached lump.
Z_Free(sfx);

// Set the length to the size of the actual sound data (without header).
*len = paddedsize;

// Return allocated padded data.
return (void *) (paddedsfx + 8);
// Return pointer offset by 8 to skip the header.
return (void*)(paddedsfx + 8);
}






//
// This function adds a sound to the
// list of currently active sounds,
Expand Down
47 changes: 47 additions & 0 deletions linuxdoom-1.10/i_svga.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <vga.h>
#include <vgagl.h>
#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);
}
13 changes: 12 additions & 1 deletion linuxdoom-1.10/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions linuxdoom-1.10/m_config.h
Original file line number Diff line number Diff line change
@@ -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;
};