Minor AMS and hash access optimization

This commit is contained in:
Dennis Eichhorn 2024-10-29 02:44:37 +01:00
parent c2f4862f22
commit aac82ac61a
4 changed files with 21 additions and 2 deletions

View File

@ -194,6 +194,20 @@ Asset* ams_get_asset(AssetManagementSystem* ams, const char* key)
return entry ? (Asset *) entry->value : NULL;
}
inline
Asset* ams_get_asset(AssetManagementSystem* ams, const char* key, uint64 index)
{
HashEntry* entry = hashmap_get_entry(&ams->hash_map, key, index);
// @bug entry->value seems to be an address outside of any known buffer, how?
DEBUG_MEMORY_READ(
(uint64) (entry ? (Asset *) entry->value : 0),
entry ? ((Asset *) entry->value)->ram_size + sizeof(Asset) : 0
);
return entry ? (Asset *) entry->value : NULL;
}
// @todo implement defragment command to optimize memory layout since the memory layout will become fragmented over time
Asset* ams_reserve_asset(AssetManagementSystem* ams, const char* name, uint32 elements = 1)

View File

@ -11,6 +11,7 @@
#include "../stdlib/Types.h"
inline constexpr
uint64 hash_djb2(const char* key) {
uint64 hash = 5381;
int32 c;

View File

@ -359,6 +359,10 @@ HashEntry* hashmap_get_entry(HashMap* hm, const char* key) {
// This function only saves one step (omission of the hash function)
// The reason for this is in some cases we can use compile time hashing
HashEntry* hashmap_get_entry(HashMap* hm, const char* key, uint64 index) {
if (hm->buf.count == 0) {
return NULL;
}
index %= hm->buf.count;
HashEntry* entry = (HashEntry *) hm->table[index];

View File

@ -4,6 +4,7 @@
#include "../stdlib/Types.h"
#include "../stdlib/HashMap.h"
#include "UIElement.h"
#include "../asset/Asset.h"
// Modified for every scene
struct UILayout {
@ -25,8 +26,7 @@ struct UILayout {
HashMap hash_map;
int32 vertex_size;
int32 vertex_pos;
Vertex3DTextureColorIndex* vertices;
Asset* ui_asset;
};
inline