diff --git a/asset/AssetManagementSystem.h b/asset/AssetManagementSystem.h index f336f34..0a10963 100644 --- a/asset/AssetManagementSystem.h +++ b/asset/AssetManagementSystem.h @@ -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) diff --git a/hash/GeneralHash.h b/hash/GeneralHash.h index be8c1f4..007f26d 100644 --- a/hash/GeneralHash.h +++ b/hash/GeneralHash.h @@ -11,6 +11,7 @@ #include "../stdlib/Types.h" +inline constexpr uint64 hash_djb2(const char* key) { uint64 hash = 5381; int32 c; diff --git a/stdlib/HashMap.h b/stdlib/HashMap.h index eede30d..86ffd80 100644 --- a/stdlib/HashMap.h +++ b/stdlib/HashMap.h @@ -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]; diff --git a/ui/UILayout.h b/ui/UILayout.h index 878de95..12807ef 100644 --- a/ui/UILayout.h +++ b/ui/UILayout.h @@ -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