mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Change cobject allowlist to C++ maps
This commit is contained in:
parent
f6a78e0c77
commit
2a809f2bdc
4 changed files with 23 additions and 1315 deletions
|
|
@ -1,15 +1,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "smlua.h"
|
#include "smlua.h"
|
||||||
#define STB_DS_IMPLEMENTATION 1
|
#include "data/dynos_cmap.cpp.h"
|
||||||
#include "pc/utils/stb_ds.h"
|
|
||||||
|
|
||||||
struct AllowList {
|
|
||||||
u64 key;
|
|
||||||
u8 value;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define LOT_COUNT (LOT_MAX + (LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN))
|
#define LOT_COUNT (LOT_MAX + (LOT_AUTOGEN_MAX - LOT_AUTOGEN_MIN))
|
||||||
static struct AllowList* sObjectAllowList[LOT_COUNT] = { 0 };
|
static void* sObjectAllowList[LOT_COUNT] = { NULL };
|
||||||
static u64 sCachedObjectAllowed[LOT_COUNT] = { 0 };
|
static u64 sCachedObjectAllowed[LOT_COUNT] = { 0 };
|
||||||
|
|
||||||
static u16 smlua_lot_mapping(u16 lot) {
|
static u16 smlua_lot_mapping(u16 lot) {
|
||||||
|
|
@ -28,11 +22,9 @@ void smlua_cobject_allowlist_shutdown(void) {
|
||||||
for (s32 i = 0; i < LOT_COUNT; i++) {
|
for (s32 i = 0; i < LOT_COUNT; i++) {
|
||||||
sCachedObjectAllowed[i] = 0;
|
sCachedObjectAllowed[i] = 0;
|
||||||
|
|
||||||
while (sObjectAllowList[i] && hmlen(sObjectAllowList[i]) > 0) {
|
if (sObjectAllowList[i]) {
|
||||||
hmdel(sObjectAllowList[i], sObjectAllowList[i]->key);
|
hmap_clear(sObjectAllowList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sObjectAllowList[i] = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,8 +36,12 @@ void smlua_cobject_allowlist_add(u16 lot, u64 pointer) {
|
||||||
if (sCachedObjectAllowed[m] == pointer) { return; }
|
if (sCachedObjectAllowed[m] == pointer) { return; }
|
||||||
sCachedObjectAllowed[m] = pointer;
|
sCachedObjectAllowed[m] = pointer;
|
||||||
|
|
||||||
if (!hmget(sObjectAllowList[m], pointer)) {
|
if (!sObjectAllowList[m]) {
|
||||||
hmput(sObjectAllowList[m], pointer, 1);
|
sObjectAllowList[m] = hmap_create();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hmap_get(sObjectAllowList[m], pointer)) {
|
||||||
|
hmap_put(sObjectAllowList[m], pointer, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,12 +52,13 @@ bool smlua_cobject_allowlist_contains(u16 lot, u64 pointer) {
|
||||||
u16 m = smlua_lot_mapping(lot);
|
u16 m = smlua_lot_mapping(lot);
|
||||||
if (sCachedObjectAllowed[m] == pointer) { return true; }
|
if (sCachedObjectAllowed[m] == pointer) { return true; }
|
||||||
|
|
||||||
return hmget(sObjectAllowList[m], pointer);
|
if (!sObjectAllowList[m]) { return false; }
|
||||||
|
return hmap_get(sObjectAllowList[m], pointer) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
static struct AllowList* sPointerAllowList[LVT_MAX] = { 0 };
|
static void* sPointerAllowList[LVT_MAX] = { 0 };
|
||||||
static u64 sCachedPointerAllowed[LVT_MAX] = { 0 };
|
static u64 sCachedPointerAllowed[LVT_MAX] = { 0 };
|
||||||
|
|
||||||
void smlua_cpointer_allowlist_init(void) {
|
void smlua_cpointer_allowlist_init(void) {
|
||||||
|
|
@ -72,11 +69,9 @@ void smlua_cpointer_allowlist_shutdown(void) {
|
||||||
for (s32 i = 0; i < LVT_MAX; i++) {
|
for (s32 i = 0; i < LVT_MAX; i++) {
|
||||||
sCachedPointerAllowed[i] = 0;
|
sCachedPointerAllowed[i] = 0;
|
||||||
|
|
||||||
while (sPointerAllowList[i] && hmlen(sPointerAllowList[i]) > 0) {
|
if (sPointerAllowList[i]) {
|
||||||
hmdel(sPointerAllowList[i], sPointerAllowList[i]->key);
|
hmap_clear(sPointerAllowList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sPointerAllowList[i] = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,8 +82,12 @@ void smlua_cpointer_allowlist_add(u16 lvt, u64 pointer) {
|
||||||
if (sCachedPointerAllowed[lvt] == pointer) { return; }
|
if (sCachedPointerAllowed[lvt] == pointer) { return; }
|
||||||
sCachedPointerAllowed[lvt] = pointer;
|
sCachedPointerAllowed[lvt] = pointer;
|
||||||
|
|
||||||
if (!hmget(sPointerAllowList[lvt], pointer)) {
|
if (!sPointerAllowList[lvt]) {
|
||||||
hmput(sPointerAllowList[lvt], pointer, 1);
|
sPointerAllowList[lvt] = hmap_create();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hmap_get(sPointerAllowList[lvt], pointer)) {
|
||||||
|
hmap_put(sPointerAllowList[lvt], pointer, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,5 +97,6 @@ bool smlua_cpointer_allowlist_contains(u16 lvt, u64 pointer) {
|
||||||
|
|
||||||
if (sCachedPointerAllowed[lvt] == pointer) { return true; }
|
if (sCachedPointerAllowed[lvt] == pointer) { return true; }
|
||||||
|
|
||||||
return hmget(sPointerAllowList[lvt], pointer);
|
if (!sPointerAllowList[lvt]) { return false; }
|
||||||
|
return hmap_get(sPointerAllowList[lvt], pointer) != 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
#include "types.h"
|
|
||||||
#include "PR/gbi.h"
|
|
||||||
#include "pc/utils/stb_ds.h"
|
|
||||||
#include "pc/debuglog.h"
|
|
||||||
#ifdef HAVE_SDL2
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct ProfileCounters {
|
|
||||||
const char* key;
|
|
||||||
f64 start;
|
|
||||||
f64 end;
|
|
||||||
f64 sum;
|
|
||||||
f64 disp;
|
|
||||||
f64 avg;
|
|
||||||
f64 max;
|
|
||||||
u8 newMax;
|
|
||||||
u32 indent;
|
|
||||||
};
|
|
||||||
|
|
||||||
static u32 sProfileIndent = 0;
|
|
||||||
|
|
||||||
static struct { char *key; struct ProfileCounters* value; } *sCounters = NULL;
|
|
||||||
|
|
||||||
void profiler_reset_counters(void) {
|
|
||||||
s32 counters = hmlen(sCounters);
|
|
||||||
for (s32 i = 0; i < counters; ++i) {
|
|
||||||
struct ProfileCounters* v = sCounters[i].value;
|
|
||||||
if (v == NULL) { continue; }
|
|
||||||
v->disp = 0;
|
|
||||||
v->max = 0;
|
|
||||||
v->avg = 0;
|
|
||||||
v->sum = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void profiler_start_counter(const char* keyName) {
|
|
||||||
u32 counters = -1;
|
|
||||||
struct ProfileCounters* v = hmget(sCounters, (char*)keyName);
|
|
||||||
if (v == NULL) {
|
|
||||||
v = calloc(1, sizeof(struct ProfileCounters));
|
|
||||||
if (v == NULL) { return; }
|
|
||||||
//hm_new_strdup(sCounters);
|
|
||||||
hmput(sCounters, (char*)keyName, v);
|
|
||||||
counters = hmlenu(sCounters);
|
|
||||||
}
|
|
||||||
|
|
||||||
counters = counters;
|
|
||||||
f64 freq;
|
|
||||||
f64 curr;
|
|
||||||
#ifdef HAVE_SDL2
|
|
||||||
freq = SDL_GetPerformanceFrequency();
|
|
||||||
curr = SDL_GetPerformanceCounter();
|
|
||||||
#endif
|
|
||||||
v->key = keyName;
|
|
||||||
v->start = curr / freq;
|
|
||||||
v->indent = sProfileIndent++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void profiler_stop_counter(const char* keyName) {
|
|
||||||
struct ProfileCounters* v = hmget(sCounters, (char*)keyName);
|
|
||||||
if (v == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
f64 freq;
|
|
||||||
f64 curr;
|
|
||||||
#ifdef HAVE_SDL2
|
|
||||||
freq = SDL_GetPerformanceFrequency();
|
|
||||||
curr = SDL_GetPerformanceCounter();
|
|
||||||
#endif
|
|
||||||
v->end = curr / freq;
|
|
||||||
v->sum += v->end - v->start;
|
|
||||||
sProfileIndent--;
|
|
||||||
}
|
|
||||||
|
|
||||||
void profiler_update_counters() {
|
|
||||||
s32 counters = hmlen(sCounters);
|
|
||||||
bool slow = false;
|
|
||||||
for (s32 i = 0; i < counters; ++i) {
|
|
||||||
struct ProfileCounters* v = sCounters[i].value;
|
|
||||||
if (v == NULL) { continue; }
|
|
||||||
v->disp = v->sum;// / (f64) REFRESH_RATE;
|
|
||||||
v->newMax = (v->max < v->sum);
|
|
||||||
v->max = MAX(v->sum, v->max);
|
|
||||||
v->avg = v->avg * 0.9 + v->sum * 0.1;
|
|
||||||
|
|
||||||
slow = slow || v->sum > 0.034;
|
|
||||||
v->sum = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (slow) {
|
|
||||||
printf("-----------------------------------\n");
|
|
||||||
char indent[64] = { 0 };
|
|
||||||
for (s32 i = 0; i < counters; ++i) {
|
|
||||||
struct ProfileCounters* v = sCounters[i].value;
|
|
||||||
if (v == NULL) { continue; }
|
|
||||||
|
|
||||||
v->indent = MIN(v->indent, 63);
|
|
||||||
char* ind = indent;
|
|
||||||
while (v->indent > 0) {
|
|
||||||
*ind = ' ';
|
|
||||||
ind++;
|
|
||||||
v->indent--;
|
|
||||||
}
|
|
||||||
*ind = '\0';
|
|
||||||
|
|
||||||
printf("PROF: %f : %f : %f : %s%s%s\n", v->disp, v->avg, v->max, indent, v->key, v->newMax ? " <<<" : "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sProfileIndent = 0;
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
#ifndef PROFILE_H
|
|
||||||
#define PROFILE_H
|
|
||||||
|
|
||||||
#define PROFILE_BEGIN() profiler_start_counter(__FUNCTION__)
|
|
||||||
#define PROFILE_END() profiler_stop_counter(__FUNCTION__)
|
|
||||||
|
|
||||||
void profiler_reset_counters(void);
|
|
||||||
void profiler_start_counter(const char* key);
|
|
||||||
void profiler_stop_counter(const char* key);
|
|
||||||
void profiler_update_counters();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue