optimization and wide theme
This commit is contained in:
parent
29ad172896
commit
010c4e81cf
|
@ -32,6 +32,7 @@ Source: themes\original\*; DestDir: {app}\themes\original
|
|||
Source: themes\fantasy\*; DestDir: {app}\themes\fantasy
|
||||
Source: themes\arctic\*; DestDir: {app}\themes\arctic
|
||||
Source: themes\bluesteel\*; DestDir: {app}\themes\bluesteel
|
||||
Source: themes\wide\*; DestDir: {app}\themes\wide
|
||||
Source: *.dll; DestDir: {app}
|
||||
|
||||
[CustomMessages]
|
||||
|
|
|
@ -7,8 +7,10 @@
|
|||
|
||||
typedef struct {
|
||||
struct list_head list;
|
||||
int auto_grow;
|
||||
int size;
|
||||
int max_size;
|
||||
int used;
|
||||
cache_free_fn free_fn;
|
||||
struct list_head hash[HASH_SIZE];
|
||||
struct list_head vhash[HASH_SIZE];
|
||||
|
@ -53,7 +55,11 @@ cache_t cache_init(int size, cache_free_fn free_fn)
|
|||
if (!c)
|
||||
return NULL;
|
||||
INIT_LIST_HEAD(&c->list);
|
||||
c->auto_grow = 0;
|
||||
c->size = 0;
|
||||
c->used = 0;
|
||||
if (!size)
|
||||
c->auto_grow = 1;
|
||||
c->max_size = size;
|
||||
c->free_fn = free_fn;
|
||||
for (i = 0; i < HASH_SIZE; i++) {
|
||||
|
@ -137,6 +143,7 @@ int cache_forget(cache_t cache, void *p)
|
|||
__cache_e_t *cc = cache_data(cache, p);
|
||||
if (cc && cc->used) {
|
||||
cc->used --;
|
||||
((__cache_t*)cache)->used --;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
|
@ -152,6 +159,7 @@ void *cache_get(cache_t cache, const char *name)
|
|||
if (!cc)
|
||||
return NULL;
|
||||
cc->used ++; /* need again! */
|
||||
((__cache_t*)cache)->used ++;
|
||||
list_move((struct list_head*)cc, &c->list); /* first place */
|
||||
// printf("%p\n", cc->data);
|
||||
return cc->data;
|
||||
|
@ -169,6 +177,19 @@ int cache_have(cache_t cache, void *p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void __cache_shrink(__cache_t *c)
|
||||
{
|
||||
while (c->size > c->max_size) {
|
||||
__cache_e_t *cc;
|
||||
cc = (__cache_e_t *)c->list.prev;
|
||||
if (!cc->used) {
|
||||
c->size --;
|
||||
cache_e_free(c, (__cache_e_t *)c->list.prev);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int cache_add(cache_t cache, const char *name, void *p)
|
||||
{
|
||||
__cache_e_t *cc;
|
||||
|
@ -206,6 +227,7 @@ int cache_add(cache_t cache, const char *name, void *p)
|
|||
}
|
||||
cc->data = p;
|
||||
cc->used = 1;
|
||||
((__cache_t*)cache)->used ++;
|
||||
cc->hash = (struct list_head*) hh;
|
||||
cc->vhash = (struct list_head*) vh;
|
||||
|
||||
|
@ -219,16 +241,17 @@ int cache_add(cache_t cache, const char *name, void *p)
|
|||
list_add((struct list_head*)vh, list);
|
||||
|
||||
c->size ++;
|
||||
// printf("size: %d:%s\n", c->size, name);
|
||||
|
||||
while (c->size > c->max_size) {
|
||||
__cache_e_t *cc;
|
||||
cc = (__cache_e_t *)c->list.prev;
|
||||
if (!cc->used) {
|
||||
c->size --;
|
||||
cache_e_free(cache, (__cache_e_t *)c->list.prev);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (c->auto_grow && c->used > c->max_size)
|
||||
c->max_size = c->used;
|
||||
__cache_shrink(c);
|
||||
// printf("size: %d:%d\n", c->size, c->max_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cache_shrink(cache_t cache)
|
||||
{
|
||||
__cache_t *c = cache;
|
||||
if (c->auto_grow && c->max_size > 2*c->used)
|
||||
c->max_size = c->used + c->used / 2;
|
||||
__cache_shrink(c);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ extern cache_t cache_init(int size, cache_free_fn);
|
|||
extern void cache_free(cache_t cache);
|
||||
extern int cache_forget(cache_t cache, void *p);
|
||||
extern void cache_zap(cache_t cache);
|
||||
extern void cache_shrink(cache_t cache);
|
||||
extern void *cache_get(cache_t cache, const char *name);
|
||||
extern int cache_add(cache_t cache, const char *name, void *p);
|
||||
extern int cache_have(cache_t cache, void *p);
|
||||
|
|
|
@ -1650,9 +1650,9 @@ struct layout *layout_new(fnt_t fn, int w, int h)
|
|||
l->lcol = gfx_col(0, 0, 255);
|
||||
l->acol = gfx_col(255, 0, 0);
|
||||
l->box = NULL;
|
||||
l->img_cache = cache_init(GFX_CACHE_SIZE, gfx_free_image);
|
||||
l->prerend_cache = cache_init(WORD_CACHE_SIZE, sdl_surface_free);
|
||||
l->hlprerend_cache = cache_init(LINK_CACHE_SIZE, sdl_surface_free);
|
||||
l->img_cache = cache_init(0, gfx_free_image);
|
||||
l->prerend_cache = cache_init(0, sdl_surface_free);
|
||||
l->hlprerend_cache = cache_init(0, sdl_surface_free);
|
||||
memset(l->scnt, 0, sizeof(l->scnt));
|
||||
memset(l->saved_align, 0, sizeof(l->saved_align));
|
||||
memset(l->saved_valign, 0, sizeof(l->saved_valign));
|
||||
|
@ -2273,6 +2273,9 @@ void txt_layout_draw_ex(layout_t lay, struct line *line, int x, int y, int off,
|
|||
word_render(layout, word, x + word->x, y + yy + line->y);
|
||||
}
|
||||
}
|
||||
cache_shrink(layout->prerend_cache);
|
||||
cache_shrink(layout->hlprerend_cache);
|
||||
cache_shrink(layout->img_cache);
|
||||
// gfx_noclip();
|
||||
}
|
||||
|
||||
|
@ -2667,7 +2670,7 @@ img_t get_img(struct layout *layout, char *p)
|
|||
} else {
|
||||
layout_add_image(layout, image);
|
||||
image->free_it = 1; /* free on layout destroy */
|
||||
if (gfx_img_w(img) <= GFX_MAX_CACHED_W && gfx_img_h(img) <= GFX_MAX_CACHED_H)
|
||||
// if (gfx_img_w(img) <= GFX_MAX_CACHED_W && gfx_img_h(img) <= GFX_MAX_CACHED_H)
|
||||
cache_add(layout->img_cache, p, img);
|
||||
}
|
||||
out:
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
#ifndef __GRAPHICS_H__
|
||||
#define __GRAPHICS_H__
|
||||
|
||||
#define GFX_CACHE_SIZE 64
|
||||
/* #define GFX_CACHE_SIZE 64
|
||||
#define GFX_MAX_CACHED_W 256
|
||||
#define GFX_MAX_CACHED_H 256
|
||||
|
||||
#define WORD_CACHE_SIZE 1024
|
||||
#define LINK_CACHE_SIZE 64
|
||||
*/
|
||||
|
||||
typedef void* gtimer_t;
|
||||
typedef void* img_t;
|
||||
|
|
10
themes/wide/theme.ini
Normal file
10
themes/wide/theme.ini
Normal file
|
@ -0,0 +1,10 @@
|
|||
; $Name:Wide
|
||||
; $Name(ru):Широкая
|
||||
; $Name(es):Amplio
|
||||
|
||||
scr.w = 800
|
||||
scr.h = 480
|
||||
win.h = 448
|
||||
inv.h = 448
|
||||
|
||||
menu.button.y = 456
|
Reference in a new issue