Skip to content

Commit a33b854

Browse files
committed
wip using pool allocator for better memory performance accross emulators without having to (re-)allocate the romdata which can fail. update to use menu mutex and to make images spans instead of vectors for better memory performance
1 parent 9a655da commit a33b854

File tree

38 files changed

+755
-685
lines changed

38 files changed

+755
-685
lines changed

components/box-emu/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ idf_component_register(
3030
"statistics"
3131
"max1704x"
3232
"esp-box"
33+
"pool_allocator"
3334
)

components/box-emu/include/box-emu.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "video_setting.hpp"
3737

3838
#include "make_color.h"
39+
#include "pool_allocator.h"
3940

4041
class BoxEmu : public espp::BaseComponent {
4142
public:

components/doom/include/doom.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
22

3+
#include <span>
34
#include <string>
45
#include <string_view>
56
#include <vector>
67

78
void reset_doom();
89
void init_doom(const std::string& rom_filename, uint8_t *romdata, size_t rom_data_size);
9-
void load_doom(std::string_view save_path);
10-
void save_doom(std::string_view save_path);
10+
void load_doom(int save_slot);
11+
void save_doom(int save_slot);
1112
void run_doom_rom();
1213
void deinit_doom();
13-
std::vector<uint8_t> get_doom_video_buffer();
14+
std::span<uint8_t> get_doom_video_buffer();

components/doom/prboom/lprintf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ void I_Error(const char *error, ...)
7474
{
7575
va_list arg;
7676
va_start(arg, error);
77-
char buffer[256];
78-
vsnprintf(buffer, sizeof(buffer), error, arg);
77+
vprintf(error, arg);
7978
va_end(arg);
80-
abort();
79+
// abort();
8180
}

components/doom/prboom/m_menu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include "r_demo.h"
6060
#include "r_fps.h"
6161

62-
extern patchnum_t hu_font[HU_FONTSIZE];
62+
extern patchnum_t *hu_font; // [HU_FONTSIZE];
6363

6464
int showMessages; // Show messages has default, 0 = off, 1 = on
6565
bool inhelpscreens; // indicates we are in or just left a help screen

components/doom/prboom/m_misc.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ struct default_s *M_LookupDefault(const char *name)
680680
for (int i = 0 ; i < numdefaults ; i++)
681681
if ((defaults[i].type != def_none) && !strcmp(name, defaults[i].name))
682682
return (default_t*)&defaults[i];
683-
I_Error("M_LookupDefault: %s not found",name);
683+
// I_Error("M_LookupDefault: '%s' not found\n",name);
684684
return NULL;
685685
}
686686

@@ -690,6 +690,17 @@ struct default_s *M_LookupDefault(const char *name)
690690

691691
void M_LoadDefaults(void)
692692
{
693+
// set everything to base values
694+
for (int i = 0 ; i < numdefaults ; i++) {
695+
if (defaults[i].type == def_str && defaults[i].location.ppsz)
696+
*defaults[i].location.ppsz = strdup(defaults[i].defaultvalue.psz);
697+
if (defaults[i].type != def_str && defaults[i].location.pi)
698+
*defaults[i].location.pi = defaults[i].defaultvalue.i;
699+
}
700+
701+
// return early since we have no config file
702+
return;
703+
693704
// check for a custom default file
694705
int i = M_CheckParm ("-config");
695706
if (i && i < myargc-1)
@@ -699,14 +710,6 @@ void M_LoadDefaults(void)
699710
configfile = strcat(strcpy(malloc(strlen(exedir) + 32), exedir), "/prboom.cfg");
700711
}
701712

702-
// set everything to base values
703-
for (int i = 0 ; i < numdefaults ; i++) {
704-
if (defaults[i].type == def_str && defaults[i].location.ppsz)
705-
*defaults[i].location.ppsz = strdup(defaults[i].defaultvalue.psz);
706-
if (defaults[i].type != def_str && defaults[i].location.pi)
707-
*defaults[i].location.pi = defaults[i].defaultvalue.i;
708-
}
709-
710713
// read the file in, overriding any set defaults
711714
FILE* f = fopen(configfile, "r");
712715
if (!f)

components/doom/prboom/z_zone.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ void Z_Close(void)
175175
Z_FreeTags(PU_FREE, PU_MAX);
176176
}
177177

178+
#include "pool_allocator.h"
179+
180+
static void* my_malloc(size_t size)
181+
{
182+
return pool_alloc(size);
183+
}
184+
185+
static void my_free(void* p)
186+
{
187+
pool_free(p);
188+
}
189+
178190
void Z_Init(void)
179191
{
180192
// Nothing to do
@@ -202,7 +214,7 @@ void *(Z_Malloc)(size_t size, int tag, void **user DA(const char *file, int line
202214

203215
size = (size+CHUNK_SIZE-1) & ~(CHUNK_SIZE-1); // round to chunk size
204216

205-
while (!(block = (malloc)(size + HEADER_SIZE))) {
217+
while (!(block = (my_malloc)(size + HEADER_SIZE))) {
206218
if (!blockbytag[PU_CACHE])
207219
I_Error ("Z_Malloc: Failure trying to allocate %lu bytes"
208220
#ifdef INSTRUMENTED
@@ -304,7 +316,7 @@ void (Z_Free)(void *p DA(const char *file, int line))
304316
memset(block, gametic & 0xff, block->size + HEADER_SIZE);
305317
#endif
306318

307-
(free)(block);
319+
(my_free)(block);
308320

309321
#ifdef INSTRUMENTED
310322
Z_DrawStats(); // print memory allocation stats

0 commit comments

Comments
 (0)