Compare commits
No commits in common. "732b61e207d992702d4e92b2fa2ee9203ba21991" and "916e43375363b3f255368edd670f4e77c16015ef" have entirely different histories.
732b61e207
...
916e433753
@ -268,24 +268,6 @@
|
|||||||
{ "name": "value", "type": "Rect" },
|
{ "name": "value", "type": "Rect" },
|
||||||
{ "name": "identity", "type": "char *" }
|
{ "name": "identity", "type": "char *" }
|
||||||
]
|
]
|
||||||
},
|
|
||||||
|
|
||||||
"profile_start": {
|
|
||||||
"module": "util",
|
|
||||||
"symbol": "profile_start",
|
|
||||||
"header": "twn_util.h",
|
|
||||||
"params": [
|
|
||||||
{ "name": "profile", "type": "char *" }
|
|
||||||
]
|
|
||||||
},
|
|
||||||
|
|
||||||
"profile_end": {
|
|
||||||
"module": "util",
|
|
||||||
"symbol": "profile_end",
|
|
||||||
"header": "twn_util.h",
|
|
||||||
"params": [
|
|
||||||
{ "name": "profile", "type": "char *" }
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -461,10 +461,55 @@ void textures_update_atlas(TextureCache *cache) {
|
|||||||
arrfree(rects);
|
arrfree(rects);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
/* EXPERIMANTAL: LIKELY TO BE REMOVED! */
|
||||||
/* to prevent hashing errors */
|
#if defined(__linux_x_) /* use rodata elf section for fast lookups of repeating textures */
|
||||||
if (!path) path = "";
|
|
||||||
|
|
||||||
|
#include "system/linux/twn_elf.h"
|
||||||
|
|
||||||
|
static const char *rodata_start;
|
||||||
|
static const char *rodata_stop;
|
||||||
|
|
||||||
|
static const char *last_path = NULL;
|
||||||
|
static TextureKey last_texture;
|
||||||
|
static struct PtrToTexture {
|
||||||
|
const void *key;
|
||||||
|
TextureKey value;
|
||||||
|
} *ptr_to_texture;
|
||||||
|
|
||||||
|
/* TODO: separate and reuse */
|
||||||
|
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||||
|
if (rodata_stop == NULL)
|
||||||
|
if (!infer_elf_section_bounds(".rodata", &rodata_start, &rodata_stop))
|
||||||
|
CRY("Section inference", ".rodata section lookup failed");
|
||||||
|
|
||||||
|
/* the fastest path */
|
||||||
|
if (path == last_path)
|
||||||
|
return last_texture;
|
||||||
|
else {
|
||||||
|
/* moderately fast path, by pointer hashing */
|
||||||
|
const ptrdiff_t texture = hmgeti(ptr_to_texture, path);
|
||||||
|
if (texture != -1) {
|
||||||
|
if (path >= rodata_start && path < rodata_stop)
|
||||||
|
last_path = path;
|
||||||
|
last_texture = ptr_to_texture[texture].value;
|
||||||
|
return last_texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: this will be bad when dynamic strings are involved */
|
||||||
|
/* to mitigate that we could free ptr_to_texture each frame */
|
||||||
|
/* try loading */
|
||||||
|
last_texture = textures_load(cache, path);
|
||||||
|
hmput(ptr_to_texture, path, last_texture);
|
||||||
|
|
||||||
|
if (path >= rodata_start && path < rodata_stop)
|
||||||
|
last_path = path;
|
||||||
|
|
||||||
|
return last_texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
||||||
/* hash tables are assumed to be stable, so we just return indices */
|
/* hash tables are assumed to be stable, so we just return indices */
|
||||||
const ptrdiff_t texture = shgeti(cache->hash, path);
|
const ptrdiff_t texture = shgeti(cache->hash, path);
|
||||||
|
|
||||||
@ -475,6 +520,8 @@ TextureKey textures_get_key(TextureCache *cache, const char *path) {
|
|||||||
return (TextureKey){ (uint16_t)texture };
|
return (TextureKey){ (uint16_t)texture };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* generic implementation of textures_get_key() */
|
||||||
|
|
||||||
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key) {
|
int32_t textures_get_atlas_id(const TextureCache *cache, TextureKey key) {
|
||||||
if (m_texture_key_is_valid(key)) {
|
if (m_texture_key_is_valid(key)) {
|
||||||
if (cache->hash[key.id].value.loner_texture != 0)
|
if (cache->hash[key.id].value.loner_texture != 0)
|
||||||
@ -581,4 +628,10 @@ size_t textures_get_num_atlases(const TextureCache *cache) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void textures_reset_state(void) {
|
void textures_reset_state(void) {
|
||||||
|
#if defined(__linux__x) && !defined(HOT_RELOAD_SUPPORT)
|
||||||
|
last_path = NULL;
|
||||||
|
last_texture = (TextureKey){0};
|
||||||
|
shfree(ptr_to_texture);
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user