mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-02-04 21:28:40 +00:00
Minor AMS and hash access optimization
This commit is contained in:
parent
c2f4862f22
commit
aac82ac61a
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "../stdlib/Types.h"
|
||||
|
||||
inline constexpr
|
||||
uint64 hash_djb2(const char* key) {
|
||||
uint64 hash = 5381;
|
||||
int32 c;
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user