Skip to content
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
23 changes: 22 additions & 1 deletion games/NXDoom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

config GAMES_NXDOOM
bool "NXDoom"
tristate "NXDoom"
default n
depends on ALLOW_GPL_COMPONENTS
depends on VIDEO_FB
Expand Down Expand Up @@ -252,6 +252,27 @@ config GAMES_NXDOOM_MAXDRAWSEGS
memory, so you may reduce the number. However, too few will cause
rendering issues (overflow is checked to avoid crashes).

config GAMES_NXDOOM_HEAP_BUFFERS
bool "Allocate renderer scratch buffers on the heap"
default n
---help---
The visplanes/openings/drawsegs/vissprites renderer scratch buffers
(sized by the options above) are static arrays by default, matching
vanilla DOOM. On a target where their combined size threatens the
internal DRAM budget once linked into a full application image,
enable this to allocate them from the heap instead (this target's
heap may be backed by external RAM/PSRAM). Static allocation is
preferred where DRAM budget is not a concern.

config GAMES_NXDOOM_STATDUMP_MAX_CAPTURES
int "Maximum statdump capture buffer entries"
default 32
range 1 1024
---help---
Number of playtime-statistics capture slots statdump.c reserves.
This is diagnostic/debug capture storage, not required for normal
gameplay - reduce it on a DRAM-constrained target.

config GAMES_NXDOOM_RANGECHECK
bool "Perform range checks"
default y
Expand Down
4 changes: 4 additions & 0 deletions games/NXDoom/src/d_iwad.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ static void buld_iwad_dir_list(void)

add_iwad_dir(m_dir_name(myargv[0]));

/* Add the configured DOOM data directory */

add_iwad_dir(CONFIG_GAMES_NXDOOM_PREFDIR);

/* Add DOOMWADDIR if it is in the environment */

env = getenv("DOOMWADDIR");
Expand Down
1 change: 1 addition & 0 deletions games/NXDoom/src/doom/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,7 @@ void d_doomloop(void)

while (1)
{
i_poll_quit_signal();
d_run_frame();
}
}
Expand Down
4 changes: 4 additions & 0 deletions games/NXDoom/src/doom/r_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ line_t *linedef;
sector_t *frontsector;
sector_t *backsector;

#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
drawseg_t *drawsegs;
Comment thread
aviralgarg05 marked this conversation as resolved.
#else
drawseg_t drawsegs[CONFIG_GAMES_NXDOOM_MAXDRAWSEGS];
#endif
drawseg_t *ds_p;

/* newend is one past the last valid seg */
Expand Down
4 changes: 4 additions & 0 deletions games/NXDoom/src/doom/r_bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ extern boolean markceiling;

extern boolean skymap;

#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
extern drawseg_t *drawsegs;
Comment thread
aviralgarg05 marked this conversation as resolved.
#else
extern drawseg_t drawsegs[CONFIG_GAMES_NXDOOM_MAXDRAWSEGS];
#endif
extern drawseg_t *ds_p;

extern lighttable_t **hscalelight;
Expand Down
4 changes: 2 additions & 2 deletions games/NXDoom/src/doom/r_draw.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we using viewheight here? Does it get properly set?

Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ void r_draw_span(void)

#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH ||
(unsigned)ds_y > SCREENHEIGHT)
ds_y < 0 || ds_y >= viewheight)
{
i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y);
}
Expand Down Expand Up @@ -724,7 +724,7 @@ void r_draw_span_low(void)

#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
if (ds_x2 < ds_x1 || ds_x1 < 0 || ds_x2 >= SCREENWIDTH ||
(unsigned)ds_y > SCREENHEIGHT)
ds_y < 0 || ds_y >= viewheight)
{
i_error("r_draw_span: %i to %i at %i", ds_x1, ds_x2, ds_y);
}
Expand Down
11 changes: 11 additions & 0 deletions games/NXDoom/src/doom/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "d_loop.h"
#include "doomdef.h"
#include "i_system.h"

#include "m_bbox.h"
#include "m_menu.h"
Expand Down Expand Up @@ -685,6 +686,16 @@ fixed_t r_scale_from_global_angle(angle_t visangle)

void r_set_view_size(int blocks, int detail)
{
/* The view geometry divides by values derived from blocks, so a value
* outside 3..11 produces a division by zero. The options menu cannot
* produce one; a malformed configuration file can.
*/

if (blocks < 3 || blocks > 11)
{
i_error("r_set_view_size: screenblocks=%d out of range", blocks);
}
Comment thread
aviralgarg05 marked this conversation as resolved.

setsizeneeded = true;
setblocks = blocks;
setdetail = detail;
Expand Down
113 changes: 100 additions & 13 deletions games/NXDoom/src/doom/r_plane.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ planefunction_t ceilingfunc;

/* Here comes the obnoxious "visplane". */

#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
visplane_t *visplanes;
Comment thread
aviralgarg05 marked this conversation as resolved.
short *openings;
#else
visplane_t visplanes[CONFIG_GAMES_NXDOOM_MAXVISPLANES];
short openings[MAXOPENINGS];
#endif
visplane_t *lastvisplane;
visplane_t *floorplane;
visplane_t *ceilingplane;

short openings[MAXOPENINGS];
short *lastopening;

/* Clip values are the solid pixel bounding the range. floorclip starts out
Expand Down Expand Up @@ -114,12 +119,24 @@ static void r_map_plane(int y, int x1, int x2)
fixed_t length;
unsigned index;

#ifdef CONFIG_GAMES_NXDOOM_RANGECHECK
if (x2 < x1 || x1 < 0 || x2 >= viewwidth || y > viewheight)
/* Ensure array indices are in range before access. The bound is
* viewheight rather than SCREENHEIGHT because r_init_buffer() only
* populates ylookup[] for [0, viewheight).
*/

if (x2 < x1 || x1 < 0 || x2 >= viewwidth)
{
i_error("R_MapPlane: %i, %i at %i", x1, x2, y);
return;
Comment thread
aviralgarg05 marked this conversation as resolved.
}

if (y < 0)
{
y = 0;
}
else if (y >= viewheight)
{
y = viewheight - 1;
}
#endif

if (planeheight != cachedheight[y])
{
Expand Down Expand Up @@ -160,27 +177,42 @@ static void r_map_plane(int y, int x1, int x2)
spanfunc();
}

static inline boolean r_row_in_range(int row)
{
return row >= 0 && row < SCREENHEIGHT;
}

static void r_make_spans(int x, int t1, int b1, int t2, int b2)
{
/* Check that row is in range before indexing arrays. */

while (t1 < t2 && t1 <= b1)
{
r_map_plane(t1, spanstart[t1], x - 1);
r_map_plane(t1, r_row_in_range(t1) ? spanstart[t1] : 0, x - 1);
t1++;
}
while (b1 > b2 && b1 >= t1)
{
r_map_plane(b1, spanstart[b1], x - 1);
r_map_plane(b1, r_row_in_range(b1) ? spanstart[b1] : 0, x - 1);
b1--;
}

while (t2 < t1 && t2 <= b2)
{
spanstart[t2] = x;
if (r_row_in_range(t2))
{
spanstart[t2] = x;
}

t2++;
}
while (b2 > b1 && b2 >= t2)
{
spanstart[b2] = x;
if (r_row_in_range(b2))
{
spanstart[b2] = x;
}

b2--;
}
}
Expand All @@ -195,7 +227,60 @@ static void r_make_spans(int x, int t1, int b1, int t2, int b2)

void r_init_planes(void)
{
/* Doh! */
#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
visplanes = malloc(sizeof(visplane_t) * CONFIG_GAMES_NXDOOM_MAXVISPLANES);
openings = malloc(sizeof(short) * MAXOPENINGS);
drawsegs = malloc(sizeof(drawseg_t) * CONFIG_GAMES_NXDOOM_MAXDRAWSEGS);
vissprites = malloc(sizeof(vissprite_t) *
CONFIG_GAMES_NXDOOM_MAXVISSPRITES);

if (visplanes == NULL || openings == NULL || drawsegs == NULL ||
vissprites == NULL)
{
r_shutdown_planes();

i_error("r_init_planes: failed to allocate renderer buffers");
}
Comment thread
aviralgarg05 marked this conversation as resolved.

/* Free these on exit; the game can be started again in this process. */

i_at_exit(r_shutdown_planes, true);
#endif
}

/* r_shutdown_planes
* Frees the renderer scratch buffers allocated by r_init_planes. Only
* registered as an exit handler when CONFIG_GAMES_NXDOOM_HEAP_BUFFERS is
* set - the static-array buffers have nothing to free.
*/

void r_shutdown_planes(void)
{
#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
if (visplanes != NULL)
{
free(visplanes);
visplanes = NULL;
}

if (openings != NULL)
{
free(openings);
openings = NULL;
}

if (drawsegs != NULL)
{
free(drawsegs);
drawsegs = NULL;
}

if (vissprites != NULL)
{
free(vissprites);
vissprites = NULL;
}
#endif
}

/* r_clear_planes
Expand Down Expand Up @@ -314,13 +399,15 @@ visplane_t *r_check_plane(visplane_t *pl, int start, int stop)

/* make a new visplane */

if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES)
{
i_error("r_check_plane: no more visplanes");
}

lastvisplane->height = pl->height;
lastvisplane->picnum = pl->picnum;
lastvisplane->lightlevel = pl->lightlevel;

if (lastvisplane - visplanes == CONFIG_GAMES_NXDOOM_MAXVISPLANES)
i_error("r_check_plane: no more visplanes");

pl = lastvisplane++;
pl->minx = start;
pl->maxx = stop;
Expand Down
1 change: 1 addition & 0 deletions games/NXDoom/src/doom/r_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern fixed_t distscale[SCREENWIDTH];
****************************************************************************/

void r_init_planes(void);
void r_shutdown_planes(void);
void r_clear_planes(void);

void r_draw_planes(void);
Expand Down
4 changes: 4 additions & 0 deletions games/NXDoom/src/doom/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ spriteframe_t sprtemp[29];
int maxframe;
const char *spritename;

#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
vissprite_t *vissprites;
#else
vissprite_t vissprites[CONFIG_GAMES_NXDOOM_MAXVISSPRITES];
#endif
vissprite_t *vissprite_p;
int newvissprite;

Expand Down
4 changes: 4 additions & 0 deletions games/NXDoom/src/doom/r_things.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
* Public Data
****************************************************************************/

#ifdef CONFIG_GAMES_NXDOOM_HEAP_BUFFERS
extern vissprite_t *vissprites;
#else
extern vissprite_t vissprites[CONFIG_GAMES_NXDOOM_MAXVISSPRITES];
#endif
extern vissprite_t *vissprite_p;
extern vissprite_t vsprsortedhead;

Expand Down
2 changes: 1 addition & 1 deletion games/NXDoom/src/doom/statdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* Pre-processor Definitions
****************************************************************************/

#define MAX_CAPTURES 32
#define MAX_CAPTURES CONFIG_GAMES_NXDOOM_STATDUMP_MAX_CAPTURES

/****************************************************************************
* Private Data
Expand Down
2 changes: 2 additions & 0 deletions games/NXDoom/src/i_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ void d_doom_main(void);

int main(int argc, char **argv)
{
i_install_quit_signal();

/* save arguments */

myargc = argc;
Expand Down
Loading
Loading