Watch unaligned lumps and per-region free heap

This commit is contained in:
Lephenixnoir 2021-08-24 19:12:30 +02:00
parent d075ba2174
commit 96c7a8bb11
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
9 changed files with 95 additions and 24 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
build-cg/
build-sdl2/
wad/

View File

@ -354,7 +354,7 @@ int Layout_Event(Layout *l, int key)
}
int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap,
int *startmap, int *startepisode)
int *startmap, int *startepisode, int *trustunaligned)
{
Layout l;
Layout_Init(&l);
@ -373,6 +373,14 @@ int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap,
action = "Play Doom Shareware";
else if(!strcmp(wads[i].name, "doomu.wad"))
action = "Play Ultimate Doom";
else if(!strcmp(wads[i].name, "doomu1.wad"))
action = "Play Ultimate Doom E1";
else if(!strcmp(wads[i].name, "doomu2.wad"))
action = "Play Ultimate Doom E2";
else if(!strcmp(wads[i].name, "doomu3.wad"))
action = "Play Ultimate Doom E3";
else if(!strcmp(wads[i].name, "doomu4.wad"))
action = "Play Ultimate Doom E4";
Layout_Text(&l, action, "%s (%d.%dM)",
wads[i].name, wads[i].size / 1000000,
@ -386,6 +394,7 @@ int UI_Main(WADFileInfo *wads, int wad_count, int *dev_info, int *use_mmap,
Layout_Spacing(&l, 12);
Layout_Checkbox(&l, "Developer info:", dev_info);
Layout_Checkbox(&l, "Map file to memory:", use_mmap);
Layout_Checkbox(&l, "Trust unaligned lumps:", trustunaligned);
Layout_EndFrame(&l);
Bdisp_PutDisp_DD();

View File

@ -63,10 +63,11 @@ int Layout_Event(Layout *l, int key);
/* Show the program's main screen; returns index of selected WAD file. */
int UI_Main(WADFileInfo *wads, int wad_count,
int *dev_info, /* Enable technical detail screens */
int *use_mmap, /* Map file to memory (as opposed to using Bfile) */
int *startmap, /* Warp to this map */
int *startepisode /* Warp to this episode */
int *dev_info, /* Enable technical detail screens */
int *use_mmap, /* Map file to memory (as opposed to using Bfile) */
int *startmap, /* Warp to this map */
int *startepisode, /* Warp to this episode */
int *trustunaligned /* Trust unaligned lumps */
);
#endif /* CGDOOM_UI_H */

View File

@ -377,10 +377,15 @@ static FileMapping gWADMap;
/* Index of most likely sectors for fragment search. (CGDOOM_WAD_MMAP) */
static SectorIndexInfo *gIndex = NULL;
/* Developer info */
/* Developer statistics */
static int gDevFragments = 0;
static int gDevIndexHits = 0;
static const void *gDevLowestFragment = NULL;
int gDevUnalignedLumpLoads = 0;
int gDevUnalignedLumpSize = 0;
/* Global options */
int CGD_TrustUnalignedLumps = 0;
/* Read next sector from file, while caching into a buffer. */
const void *ReadNextSector(FileAccessCache *fc, int *size)
@ -629,7 +634,7 @@ int main(void)
int dev_info = 0;
int choice = UI_Main(wads, wad_count, &dev_info, &gWADmethod,
&startmap, &startepisode);
&startmap, &startepisode, &CGD_TrustUnalignedLumps);
if(choice < 0)
return 1;
@ -716,6 +721,22 @@ int main(void)
if(gWADfd >= 0)
Bfile_CloseFile_OS(gWADfd);
if(dev_info) {
Layout l;
Layout_Init(&l);
Bdisp_AllClr_VRAM();
Layout_CenteredText(&l, "Developer info");
Layout_Spacing(&l, 12);
Layout_Text(&l, "Unaligned lumps loaded:", "%d", gDevUnalignedLumpLoads);
Layout_Text(&l, "Unaligned size:", "%d B", gDevUnalignedLumpSize);
Bdisp_FrameAndColor(3, 16);
Bdisp_FrameAndColor(1, 0);
Bdisp_PutDisp_DD();
while(PRGM_GetKey() != 0) {}
int key;
GetKey(&key);
}
return 1;
}

View File

@ -475,10 +475,21 @@ void CGSwitchClip()
void CGFreeMem()
{
static char cRAMBuff[16];
int iFree = Z_FreeMemory();
CGDAppendNum0_999("Free:",iFree,0,cRAMBuff);
plyr->message = cRAMBuff;
static char message[64];
sprintf(message, "Free: ");
for (int i = 0;; i++)
{
int size;
byte *ptr = I_ZoneBase(&size, i);
if (!ptr)
break;
sprintf(message+strlen(message), "%s%d/%d kB", (i ? ", " : ""),
Z_FreeMemory(i) >> 10, size >> 10);
}
plyr->message = message;
}
int giRefreshMask = 1;

View File

@ -303,14 +303,29 @@ void * W_ReadLumpWithZ_Malloc(int lump,int tag,int iEnableFlash)
}
// else ASSERT(lumpinfo[lump].size != 10240);
int full = (c == lumpinfo[lump].size);
int aligned = (((uint32_t)lumpcache[lump] & 1) == 0);
if(CGD_TrustUnalignedLumps)
aligned = 1;
/* Record statistics on loading unaligned but full lumps */
extern int gDevUnalignedLumpLoads;
extern int gDevUnalignedLumpSize;
if(full && !aligned) {
gDevUnalignedLumpLoads++;
gDevUnalignedLumpSize += lumpinfo[lump].size;
}
/* Allocate only if the lump spans several fragments, or is misaligned;
otherwise, returns the cached Flash address, which is just as good as what
the heap would provide. */
if(c != lumpinfo[lump].size || ((uint32_t)lumpcache[lump] & 1) != 0)
if(!full || !aligned)
{
Z_Malloc (lumpinfo[lump].size, tag, &lumpcache[lump]);
W_ReadLump (lump, lumpcache[lump]);
}
return lumpcache[lump];
}

View File

@ -61,7 +61,7 @@ typedef struct
* Z_FreeTags is changed to iterate on all zones
* Z_CheckHeap is changed to iterate on all zones
* Z_ChangeTag2 operates on a single block and needs no change
* Z_FreeMemory is changed to iterate on all zones */
* Z_FreeMemory is changed to iterate on one or all zones */
static memzone_t *zones[ZONE_MAX];
static int zone_count;
@ -228,7 +228,7 @@ void* Z_Malloc( int size, int tag, void* user )
#ifdef CG_EMULATOR
{
static int iMaxFree = 1024*1024;
int iF = Z_FreeMemory();
int iF = Z_FreeMemory(-1);
if(iF < iMaxFree)
{
iMaxFree = iF;
@ -461,23 +461,29 @@ void Z_ChangeTag2(const void* ptr,int tag )
//
// Z_FreeMemory
//
int Z_FreeMemory (void)
int Z_FreeMemory (int zone)
{
if (zone < 0)
{
int free = 0;
for (int i = 0; i < zone_count; i++)
free += Z_FreeMemory (i);
return free;
}
memblock_t* block;
int free = 0;
for (int i = 0; i < zone_count; i++)
{
memzone_t* mainzone = zones[i];
memzone_t* mainzone = zones[zone];
for(block = mainzone->blocklist.next;block != &mainzone->blocklist;block = block->next)
for(block = mainzone->blocklist.next;block != &mainzone->blocklist;block = block->next)
{
if (!block->user || block->tag >= PU_PURGELEVEL)
{
if (!block->user || block->tag >= PU_PURGELEVEL)
{
free += block->size;
}
free += block->size;
}
}
return free;
}

View File

@ -52,7 +52,9 @@ void Z_DumpHeap (int lowtag, int hightag);
//void Z_FileDumpHeap (FILE *f);
void Z_CheckHeap (void);
void Z_ChangeTag2 (const void *ptr, int tag);
int Z_FreeMemory (void);
/* CGDOOM: Returns free memory in specified zone, or all zones if zone < 0 */
int Z_FreeMemory (int zone);
/* CGDOOM: Support for multiple zones is added; Z_Init() now does nothing,
zones need to be added manually (see D_DoomMain()). */

View File

@ -51,6 +51,11 @@ enum {
almost always 4 kiB-aligned, and only occasionally not */
#define FLASH_INDEX_SIZE ((FLASH_END-FLASH_FS_HINT) / 4096)
/* Whether to trust unaligned lumps. If this is set, all non-fragmented lumps
will be accessed from ROM. Otherwise, lumps that are not 4-aligned will be
loaded to the heap even if they are available. */
extern int CGD_TrustUnalignedLumps;
//---
// Display driver access
//---