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
16 changes: 15 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,20 @@ 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---
Use heap-backed renderer buffers instead of the default static arrays.
Enable this only when the target heap can hold them.

config GAMES_NXDOOM_STATDUMP_MAX_CAPTURES
int "Maximum statdump capture buffer entries"
default 32
range 1 1024
---help---
Number of diagnostic playtime-statistics capture slots.

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

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 not always use heap and remove CONFIG_GAMES_NXDOOM_HEAP_BUFFERS

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.

Is it not beneficial to use static buffers on some devices?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i felt static buffers are still useful on some targets, so i kept both options

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.

if so, why do we need add the code to allocate from heap

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.

Some devices also lack static storage, I think Aviral ran into this issue on his board.

@xiaoxiang781216 xiaoxiang781216 Aug 18, 2026

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.

but, there is no difference to define global variable or allocate from heap from the view of total memory consumption.

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.

But some targets are able to allocate more statically that they can't on heap, and vice versa

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.

so, what's problem to keep it as global variable. Before @aviralgarg05 could explain the real case, I prefer don't add the ugly code.

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.

It is still a global variable, isn't it? Just the allocation is different

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.

yes, that's why I can't understand what's benefit we can get from this change.

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
Comment thread
aviralgarg05 marked this conversation as resolved.
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
8 changes: 8 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,13 @@ fixed_t r_scale_from_global_angle(angle_t visangle)

void r_set_view_size(int blocks, int detail)
{
/* Reject invalid screen sizes before calculating view geometry. */

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
108 changes: 95 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,21 @@ 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. */

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 +174,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 +224,58 @@ 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.

/* Release heap buffers when the game exits. */

i_at_exit(r_shutdown_planes, true);
#endif
}

/* r_shutdown_planes
* Free heap-backed renderer buffers.
*/

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 +394,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