Skip to content

Commit

Permalink
IMPLEMENT COMBINE SCREENS AND CUT WIPE SCREEN EFFECT
Browse files Browse the repository at this point in the history
Reduce memory use for doom
Control flag "DISABLE_WIPES" and "COMBINE_SCREENS" are define in doomdef.h.
DISABLE_WIPES will cut wipe screen effect, COMBINE_SCREENS will discard screen buffer #1#2#3.
V_Init() function make four screen buffers pointer to same address(address of screen buffer #0) In v_video.c.
DOOMHEAP are replaced by static array and it size are controled by DOOM_HEAP_SIZE, both are in i_system.c.
Screen buffers are replaced by static array and I_AllocLow will return screen buffers directly in i_system.c.
If cut wipe screen effect, in f_wipe.c only wipe_StartScreen()、wipe_EndScreen()、wipe_ScreenWipe() will remain,
wipe_ScreenWipe() only copy data from screen buffer #3 to screen buffer #0 directly.
  • Loading branch information
tseng0201 authored and tseng committed Jan 13, 2023
1 parent 09d7634 commit bd63063
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/doomdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
#include <stdio.h>
#include <string.h>

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

// Discard screen buffers, any screen effect will direct output on your screen,
// It can save 192kb on heap.
// 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
unsigned char CombinedScreens[SCREENWIDTH*SCREENHEIGHT];
#else
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

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
}

0 comments on commit bd63063

Please sign in to comment.