Skip to content

Commit bd63063

Browse files
tseng0201tseng
authored and
tseng
committed
IMPLEMENT COMBINE SCREENS AND CUT WIPE SCREEN EFFECT
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.
1 parent 09d7634 commit bd63063

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

src/doomdef.h

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
#include <stdio.h>
2828
#include <string.h>
2929

30+
// Disable screens wipe effect, you will get worse game experience,
31+
// but it can save about 130KB on DOOMHEAP.
32+
#define DISABLE_WIPES
33+
34+
// Discard screen buffers, any screen effect will direct output on your screen,
35+
// It can save 192kb on heap.
36+
// Remeber you can only use this when disable screens wipe.
37+
#define COMBINE_SCREENS
38+
3039
// The packed attribute forces structures to be packed into the minimum
3140
// space necessary. If this is not done, the compiler may align structure
3241
// fields differently to optimise memory access, inflating the overall

src/f_wipe.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static byte* wipe_scr_start;
4646
static byte* wipe_scr_end;
4747
static byte* wipe_scr;
4848

49-
49+
#ifndef DISABLE_WIPES
5050
void
5151
wipe_shittyColMajorXform
5252
( short* array,
@@ -233,6 +233,7 @@ wipe_exitMelt
233233
Z_Free(y);
234234
return 0;
235235
}
236+
#endif
236237

237238
int
238239
wipe_StartScreen
@@ -246,6 +247,7 @@ wipe_StartScreen
246247
return 0;
247248
}
248249

250+
#ifndef DISABLE_WIPES
249251
int
250252
wipe_EndScreen
251253
( int x,
@@ -301,3 +303,18 @@ wipe_ScreenWipe
301303
return !go;
302304

303305
}
306+
#else
307+
int
308+
wipe_ScreenWipe
309+
( int wipeno,
310+
int x,
311+
int y,
312+
int width,
313+
int height,
314+
int ticks )
315+
{
316+
//Because we don't need wipe effct, just move screens[3] to screens[0]
317+
memcpy( screens[0], wipe_scr_end, width*height );
318+
return 1;
319+
}
320+
#endif

src/riscv/i_system.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@
3939

4040
#include "console.h"
4141

42+
#ifdef COMBINE_SCREENS
43+
unsigned char CombinedScreens[SCREENWIDTH*SCREENHEIGHT];
44+
#else
45+
unsigned char CombinedScreens[SCREENWIDTH*SCREENHEIGHT*4];
46+
#endif
47+
48+
/* Original 6M - wipe function (130560 bytes) */
49+
#ifdef DISABLE_WIPES
50+
#define DOOM_HEAP_SIZE 6*1024*1024 - 130560
51+
#else
52+
#define DOOM_HEAP_SIZE 6*1024*1024
53+
#endif
54+
55+
unsigned char DOOMHeap[DOOM_HEAP_SIZE];
56+
4257
enum {
4358
KEY_EVENT = 0,
4459
MOUSE_MOTION_EVENT = 1,
@@ -139,9 +154,9 @@ I_Init(void)
139154
byte *
140155
I_ZoneBase(int *size)
141156
{
142-
/* Give 6M to DOOM */
143-
*size = 6 * 1024 * 1024;
144-
return (byte *) malloc (*size);
157+
/* Give DOOM_HEAP_SIZE to DOOM */
158+
*size = DOOM_HEAP_SIZE;
159+
return (byte *) DOOMHeap;
145160
}
146161

147162

@@ -313,8 +328,11 @@ I_Quit(void)
313328
byte *
314329
I_AllocLow(int length)
315330
{
316-
/* FIXME: check if memory allocation succeeds */
317-
return calloc(1, length);
331+
/* Return screen buffer */
332+
byte* mem;
333+
mem = CombinedScreens;
334+
memset (mem,0,length);
335+
return mem;
318336
}
319337

320338

src/v_video.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,16 @@ void V_Init (void)
463463
byte* base;
464464

465465
// stick these in low dos memory on PCs
466-
466+
467+
#ifndef COMBINE_SCREENS
467468
base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT*4);
468469

469470
for (i=0 ; i<4 ; i++)
470471
screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
472+
#else
473+
base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT);
474+
475+
for (i=0 ; i<4 ; i++)
476+
screens[i] = base;
477+
#endif
471478
}

0 commit comments

Comments
 (0)