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

Reduce DOOM memory use #8

Open
wants to merge 3 commits into
base: rv32emu
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
18 changes: 18 additions & 0 deletions src/doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
#include <stdio.h>
#include <string.h>

// Disable screens wipe effect, you will get worse game experience,
// but it can save about 130KB on DOOMHEAP.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to provide the proof for memory reduction. Check the report later.

// In f_wipe.c, only wipe_initMelt() and wipe_shittyColMajorXform() call Z_Malloc ask for some sapce,
// wipe_initMelt() ask 320 * 8(width * sizeof(int)) = 2560 bytes,
// wipe_shittyColMajorXform() ask 160 * 200 * 2(width/2 * height*2) = 64000 bytes,
// it will be call twice so it will totaly ask 128000 bytes,
// it means we can save 2560 + 128000 = 130560 bytes on DOOMHEAP when disable screens wipe.
#define DISABLE_WIPES

// Discard screen buffers, any screen effect will direct output on your screen,
// It can save 192kb memory usage.
// Each screen buffer is 320 * 200 * 1 = 64000 bytes,
// COMBINE_SCREENS will make four screen buffers merge to one,
// so we can save (4 - 1) * 320 * 200 = 192000 bytes.
// In this Implement it will set "CombinedScreens[SCREENWIDTH*SCREENHEIGHT]" to replace original "CombinedScreens[SCREENWIDTH*SCREENHEIGHT*4]".
// Remeber you can only use this when disable screens wipe.
#define COMBINE_SCREENS

// The packed attribute forces structures to be packed into the minimum
// space necessary. If this is not done, the compiler may align structure
// fields differently to optimise memory access, inflating the overall
Expand Down
19 changes: 18 additions & 1 deletion src/f_wipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static byte* wipe_scr_start;
static byte* wipe_scr_end;
static byte* wipe_scr;


#ifndef DISABLE_WIPES
void
wipe_shittyColMajorXform
( short* array,
Expand Down Expand Up @@ -233,6 +233,7 @@ wipe_exitMelt
Z_Free(y);
return 0;
}
#endif

int
wipe_StartScreen
Expand All @@ -246,6 +247,7 @@ wipe_StartScreen
return 0;
}

#ifndef DISABLE_WIPES
int
wipe_EndScreen
( int x,
Expand Down Expand Up @@ -301,3 +303,18 @@ wipe_ScreenWipe
return !go;

}
#else
int
wipe_ScreenWipe
( int wipeno,
int x,
int y,
int width,
int height,
int ticks )
{
//Because we don't need wipe effct, just move screens[3] to screens[0]
memcpy( screens[0], wipe_scr_end, width*height );
return 1;
}
#endif
28 changes: 23 additions & 5 deletions src/riscv/i_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@

#include "console.h"

#ifdef COMBINE_SCREENS
static unsigned char CombinedScreens[SCREENWIDTH*SCREENHEIGHT];
#else
static unsigned char CombinedScreens[SCREENWIDTH*SCREENHEIGHT*4];
#endif

/* Original 6M - wipe function (130560 bytes) */
#ifdef DISABLE_WIPES
#define DOOM_HEAP_SIZE 6*1024*1024 - 130560
#else
#define DOOM_HEAP_SIZE 6*1024*1024
#endif

static unsigned char DOOMHeap[DOOM_HEAP_SIZE];

enum {
KEY_EVENT = 0,
MOUSE_MOTION_EVENT = 1,
Expand Down Expand Up @@ -139,9 +154,9 @@ I_Init(void)
byte *
I_ZoneBase(int *size)
{
/* Give 6M to DOOM */
*size = 6 * 1024 * 1024;
return (byte *) malloc (*size);
/* Give DOOM_HEAP_SIZE to DOOM */
*size = DOOM_HEAP_SIZE;
return (byte *) DOOMHeap;
}


Expand Down Expand Up @@ -313,8 +328,11 @@ I_Quit(void)
byte *
I_AllocLow(int length)
{
/* FIXME: check if memory allocation succeeds */
return calloc(1, length);
/* Return screen buffer */
byte* mem;
mem = CombinedScreens;
memset (mem,0,length);
return mem;
}


Expand Down
9 changes: 8 additions & 1 deletion src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,16 @@ void V_Init (void)
byte* base;

// stick these in low dos memory on PCs


#ifndef COMBINE_SCREENS
base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT*4);

for (i=0 ; i<4 ; i++)
screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
#else
base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT);

for (i=0 ; i<4 ; i++)
screens[i] = base;
#endif
}