Skip to content

Commit

Permalink
doom: fix memory allocation for visplayes
Browse files Browse the repository at this point in the history
lib: add setGlobalHandler for controller
  • Loading branch information
and3rson committed Feb 14, 2024
1 parent 800db90 commit 9dd43a4
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 158 deletions.
10 changes: 6 additions & 4 deletions firmware-doom/lib/doomgeneric/src/d_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
#include "r_bsp.h"

void D_AllocBuffers() {
R_AllocMain();
R_AllocPlanes();
R_AllocThings();
R_AllocBSP();
printf("D_AllocBuffers: Allocating buffers\n");
printf("R_AllocMain: allocated %d bytes\n", R_AllocMain());
printf("R_AllocPlanes: allocated %d bytes\n", R_AllocPlanes());
printf("R_AllocThings: allocated %d bytes\n", R_AllocThings());
printf("R_AllocBSP: allocated %d bytes\n", R_AllocBSP());
}

void D_FreeBuffers() {
printf("D_FreeBuffers: Freeing buffers\n");
R_FreeMain();
R_FreePlanes();
R_FreeThings();
Expand Down
82 changes: 42 additions & 40 deletions firmware-doom/lib/doomgeneric/src/d_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ void D_CheckNetGame(void);
void D_ProcessEvents (void)
{
event_t* ev;

// IF STORE DEMO, DO NOT ACCEPT INPUT
if (storedemo)
return;

while ((ev = D_PopEvent()) != NULL)
{
if (M_Responder (ev))
Expand Down Expand Up @@ -184,9 +184,9 @@ void D_Display (void)

if (nodrawers)
return; // for comparative timing / profiling

redrawsbar = false;

// change the view size if needed
if (setsizeneeded)
{
Expand All @@ -206,7 +206,7 @@ void D_Display (void)

if (gamestate == GS_LEVEL && gametic)
HU_Erase();

// do buffered drawing
switch (gamestate)
{
Expand Down Expand Up @@ -235,17 +235,17 @@ void D_Display (void)
D_PageDrawer ();
break;
}

// draw buffered stuff to screen
I_UpdateNoBlit ();

// draw the view directly
if (gamestate == GS_LEVEL && !automapactive && gametic)
R_RenderPlayerView (&players[displayplayer]);

if (gamestate == GS_LEVEL && gametic)
HU_Drawer ();

// clean up border stuff
if (gamestate != oldgamestate && gamestate != GS_LEVEL)
I_SetPalette (W_CacheLumpName (DEH_String("PLAYPAL"),PU_CACHE));
Expand Down Expand Up @@ -280,7 +280,7 @@ void D_Display (void)
viewactivestate = viewactive;
inhelpscreensstate = inhelpscreens;
oldgamestate = wipegamestate = gamestate;

// draw pause pic
if (paused)
{
Expand All @@ -304,7 +304,7 @@ void D_Display (void)
I_FinishUpdate (); // page flip or blit buffer
return;
}

// wipe update
wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);

Expand All @@ -318,7 +318,7 @@ void D_Display (void)
tics = nowtime - wipestart;
I_Sleep(1);
} while (tics <= 0);

wipestart = nowtime;
done = wipe_ScreenWipe(wipe_Melt
, 0, 0, SCREENWIDTH, SCREENHEIGHT, tics);
Expand Down Expand Up @@ -392,8 +392,8 @@ boolean D_GrabMouseCallback(void)
if (drone)
return false;

// when menu is active or game is paused, release the mouse
// when menu is active or game is paused, release the mouse

if (menuactive || paused)
return false;

Expand Down Expand Up @@ -524,7 +524,7 @@ void D_DoAdvanceDemo (void)
demosequence = (demosequence+1)%7;
else
demosequence = (demosequence+1)%6;

switch (demosequence)
{
case 0:
Expand Down Expand Up @@ -638,19 +638,19 @@ static char *banners[] =
//
// Get game name: if the startup banner has been replaced, use that.
// Otherwise, use the name given
//
//

static char *GetGameName(char *gamename)
{
size_t i;
char *deh_sub;

for (i=0; i<arrlen(banners); ++i)
{
// Has the banner been replaced?

deh_sub = DEH_String(banners[i]);

if (deh_sub != banners[i])
{
size_t gamename_size;
Expand Down Expand Up @@ -721,10 +721,10 @@ static void SetMissionForPackName(char *pack_name)

void D_IdentifyVersion(void)
{
// gamemission is set up by the D_FindIWAD function. But if
// we specify '-iwad', we have to identify using
// gamemission is set up by the D_FindIWAD function. But if
// we specify '-iwad', we have to identify using
// IdentifyIWADByName. However, if the iwad does not match
// any known IWAD name, we may have a dilemma. Try to
// any known IWAD name, we may have a dilemma. Try to
// identify by its contents.

if (gamemission == none)
Expand All @@ -737,7 +737,7 @@ void D_IdentifyVersion(void)
{
gamemission = doom2;
break;
}
}
else if (!strncasecmp(lumpinfo[i].name, "E1M1", 8))
{
gamemission = doom;
Expand All @@ -764,7 +764,7 @@ void D_IdentifyVersion(void)
// Ultimate Doom

gamemode = retail;
}
}
else if (W_CheckNumForName("E3M1") > 0)
{
gamemode = registered;
Expand Down Expand Up @@ -853,7 +853,7 @@ void D_SetGameDescription(void)
}
else if (logical_gamemission == pack_plut)
{
gamedescription = GetGameName("DOOM 2: Plutonia Experiment");
gamedescription = GetGameName("DOOM 2: Plutonia Experiment");
}
else if (logical_gamemission == pack_tnt)
{
Expand All @@ -876,7 +876,7 @@ static boolean D_AddFile(char *filename)
}

// Copyright message banners
// Some dehacked mods replace these. These are only displayed if they are
// Some dehacked mods replace these. These are only displayed if they are
// replaced by dehacked.

static char *copyright_banners[] =
Expand Down Expand Up @@ -925,7 +925,7 @@ void PrintDehackedBanners(void)
}
}

static struct
static struct
{
char *description;
char *cmdline;
Expand All @@ -950,7 +950,7 @@ static void InitGameVersion(void)
int p;
int i;

//!
//!
// @arg <version>
// @category compat
//
Expand All @@ -970,8 +970,8 @@ static void InitGameVersion(void)
break;
}
}
if (gameversions[i].description == NULL)

if (gameversions[i].description == NULL)
{
printf("Supported game versions:\n");

Expand All @@ -980,7 +980,7 @@ static void InitGameVersion(void)
printf("\t%s (%s)\n", gameversions[i].cmdline,
gameversions[i].description);
}

I_Error("Unknown game version '%s'", myargv[p+1]);
}
}
Expand Down Expand Up @@ -1030,7 +1030,7 @@ static void InitGameVersion(void)
}
}
}

// The original exe does not support retail - 4th episode not supported

if (gameversion < exe_ultimate && gamemode == retail)
Expand Down Expand Up @@ -1168,6 +1168,8 @@ void D_DoomMain (void)
#if ORIGCODE
int numiwadlumps;
#endif
// Disable stdout buffering
setbuf(stdout, NULL);

I_AtExit(D_Endoom, false);

Expand Down Expand Up @@ -1242,7 +1244,7 @@ void D_DoomMain (void)
//
// Disable monsters.
//

nomonsters = M_CheckParm ("-nomonsters");

//!
Expand All @@ -1261,7 +1263,7 @@ void D_DoomMain (void)

fastparm = M_CheckParm ("-fast");

//!
//!
// @vanilla
//
// Developer mode. F1 saves a screenshot in the current working
Expand Down Expand Up @@ -1295,7 +1297,7 @@ void D_DoomMain (void)

if (devparm)
DEH_printf(D_DEVSTR);

// find which dir to use for config files

#ifdef _WIN32
Expand Down Expand Up @@ -1335,7 +1337,7 @@ void D_DoomMain (void)
int scale = 200;
extern int forwardmove[2];
extern int sidemove[2];

if (p<myargc-1)
scale = atoi (myargv[p+1]);
if (scale < 10)
Expand All @@ -1348,7 +1350,7 @@ void D_DoomMain (void)
sidemove[0] = sidemove[0]*scale/100;
sidemove[1] = sidemove[1]*scale/100;
}

// init subsystems
DEH_printf("V_Init: allocate screens.\n");
V_Init ();
Expand Down Expand Up @@ -1570,13 +1572,13 @@ void D_DoomMain (void)
"dphoof","bfgga0","heada1","cybra1","spida1d1"
};
int i;

if ( gamemode == shareware)
I_Error(DEH_String("\nYou cannot -file with the shareware "
"version. Register!"));

// Check for fake IWAD with right name,
// but w/o all the lumps of the registered version.
// but w/o all the lumps of the registered version.
if (gamemode == registered)
for (i = 0;i < 23; i++)
if (W_CheckNumForName(name[i])<0)
Expand Down Expand Up @@ -1659,10 +1661,10 @@ void D_DoomMain (void)
startmap = 1;
autostart = true;
}

timelimit = 0;

//!
//!
// @arg <n>
// @category net
// @vanilla
Expand Down Expand Up @@ -1746,7 +1748,7 @@ void D_DoomMain (void)
//

p = M_CheckParmWithArgs("-loadgame", 1);

if (p)
{
startloadgame = atoi(myargv[p+1]);
Expand Down
4 changes: 0 additions & 4 deletions firmware-doom/lib/doomgeneric/src/doomgeneric.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ void doomgeneric_Create(int argc, char **argv)

DG_ScreenBuffer = malloc(DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);

D_AllocBuffers();

DG_Init();

D_DoomMain ();

D_FreeBuffers();
}

4 changes: 2 additions & 2 deletions firmware-doom/lib/doomgeneric/src/doomgeneric.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <stdlib.h>
#include <stdint.h>

#define DOOMGENERIC_RESX 240
#define DOOMGENERIC_RESY 150
#define DOOMGENERIC_RESX 320
#define DOOMGENERIC_RESY 200


extern uint32_t* DG_ScreenBuffer;
Expand Down
4 changes: 2 additions & 2 deletions firmware-doom/lib/doomgeneric/src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

// Screen width and height.

#define SCREENWIDTH 240
#define SCREENHEIGHT 150
#define SCREENWIDTH 320
#define SCREENHEIGHT 200

// Screen width used for "squash" scale functions

Expand Down
10 changes: 8 additions & 2 deletions firmware-doom/lib/doomgeneric/src/r_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,15 @@ drawseg_t* drawsegs;
drawseg_t* ds_p;


void R_AllocBSP (void)
int R_AllocBSP (void)
{
drawsegs = malloc (sizeof(*drawsegs) * MAXDRAWSEGS);
int size = sizeof(drawseg_t) * MAXDRAWSEGS;
drawsegs = malloc (size);
if (drawsegs == NULL)
{
return -1;
}
return size;
}

void R_FreeBSP (void)
Expand Down
2 changes: 1 addition & 1 deletion firmware-doom/lib/doomgeneric/src/r_bsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern lighttable_t** dscalelight;

typedef void (*drawfunc_t) (int start, int stop);

void R_AllocBSP (void);
int R_AllocBSP (void);
void R_FreeBSP (void);


Expand Down
Loading

0 comments on commit 9dd43a4

Please sign in to comment.