gui skinning

main
Dominik Madarász 2023-11-26 16:00:28 +01:00
parent d2d22af808
commit b6805c4943
14 changed files with 688 additions and 358 deletions

View File

@ -1477,6 +1477,7 @@ ffi.cdef([[
//lcpp INF [0000] vec3: macro name but used as C declaration in:API void light_dir(light_t* l, vec3 dir);
//lcpp INF [0000] vec3: macro name but used as C declaration in:STATIC void light_dir(light_t* l, vec3 dir);
//lcpp INF [0000] vec3: macro name but used as C declaration in: void light_dir(light_t* l, vec3 dir);
//lcpp INF [0000] vec2i: macro name but used as C declaration in:vec2i* entries;
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
//lcpp INF [0000] vec4: macro name but used as C declaration in:API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
@ -1498,11 +1499,17 @@ ffi.cdef([[
//lcpp INF [0000] vec3: macro name but used as C declaration in:API void spine_render(spine_t *p, vec3 offset, unsigned flags);
//lcpp INF [0000] vec3: macro name but used as C declaration in:STATIC void spine_render(spine_t *p, vec3 offset, unsigned flags);
//lcpp INF [0000] vec3: macro name but used as C declaration in: void spine_render(spine_t *p, vec3 offset, unsigned flags);
//lcpp INF [0000] vec4: macro name but used as C declaration in:vec4 sheet;
//lcpp INF [0000] vec2: macro name but used as C declaration in:vec2 anchor;
//lcpp INF [0000] vec3i: macro name but used as C declaration in:vec3i* indices;
//lcpp INF [0000] vec2: macro name but used as C declaration in:vec2* coords;
//lcpp INF [0000] vec2: macro name but used as C declaration in:vec2* uvs;
//lcpp INF [0000] vec4: macro name but used as C declaration in:vec4 bounds;
//lcpp INF [0000] vec4: macro name but used as C declaration in:vec4 core;
//lcpp INF [0000] vec4: macro name but used as C declaration in:vec4 gamepad;
//lcpp INF [0000] vec2: macro name but used as C declaration in:vec2 fire;
//lcpp INF [0000] vec4: macro name but used as C declaration in:vec4 pos;
//lcpp INF [0000] vec2: macro name but used as C declaration in:vec2 sca;
//lcpp INF [0000] vec2i: macro name but used as C declaration in:vec2i* entries;
//lcpp INF [0000] test: macro name but used as C declaration in:API int (test)(const char *file, int line, const char *expr, bool result);
//lcpp INF [0000] test: macro name but used as C declaration in:STATIC int (test)(const char *file, int line, const char *expr, bool result);
//lcpp INF [0000] test: macro name but used as C declaration in: int (test)(const char *file, int line, const char *expr, bool result);
@ -3123,6 +3130,48 @@ int u_coefficients_sh;
light_t* scene_spawn_light();
unsigned scene_count_light();
light_t* scene_index_light(unsigned index);
char* tempvl(const char *fmt, va_list);
char* tempva(const char *fmt, ...);
char* strcatf(char **s, const char *buf);
int strmatch(const char *s, const char *wildcard);
int strmatchi(const char *s, const char *wildcard);
int strcmp_qsort(const void *a, const void *b);
int strcmpi_qsort(const void *a, const void *b);
bool strbeg(const char *src, const char *sub);
bool strend(const char *src, const char *sub);
bool strbegi(const char *src, const char *sub);
bool strendi(const char *src, const char *sub);
const char * strstri(const char *src, const char *sub);
char * strupper(const char *str);
char * strlower(const char *str);
char * strrepl(char **copy, const char *target, const char *replace);
char * strswap(char *copy, const char *target, const char *replace);
char * strcut(char *copy, const char *target);
const char * strlerp(unsigned numpairs, const char **pairs, const char *str);
size_t strlcat(char *dst, const char *src, size_t dstcap);
size_t strlcpy(char *dst, const char *src, size_t dstcap);
char** strsplit(const char *string, const char *delimiters);
char* strjoin(char** list, const char *separator);
char * string8(const wchar_t *str);
uint32_t* string32( const char *utf8 );
unsigned intern( const char *string );
const char *quark( unsigned key );
typedef struct quarks_db {
char* blob;
vec2i* entries;
} quarks_db;
unsigned quark_intern( quarks_db*, const char *string );
const char *quark_string( quarks_db*, unsigned key );
bool kit_load( const char *filename );
bool kit_merge( const char *filename );
void kit_insert( const char *id, const char *translation );
void kit_clear();
void kit_set( const char *variable, const char *value );
void kit_reset();
void kit_dump_state( FILE *fp );
char* kit_translate2( const char *id, const char *langcode_iso639_1 );
void kit_locale( const char *langcode_iso639_1 );
char* kit_translate( const char *id );
typedef enum SPRITE_FLAGS {
SPRITE_PROJECTED = 1,
SPRITE_ADDITIVE = 2,
@ -3173,6 +3222,39 @@ typedef struct spine_t spine_t;
void spine_render(spine_t *p, vec3 offset, unsigned flags);
void spine_animate(spine_t *p, float delta);
void ui_spine(spine_t *p);
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor;
vec3i* indices;
vec2* coords;
vec2* uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
unsigned name;
unsigned* frames;
} atlas_anim_t;
typedef struct atlas_slice_frame_t {
vec4 bounds;
bool has_9slice;
vec4 core;
} atlas_slice_frame_t;
typedef struct atlas_slice_t {
unsigned name;
unsigned* frames;
} atlas_slice_t;
typedef struct atlas_t {
texture_t tex;
atlas_frame_t* frames;
atlas_anim_t* anims;
atlas_slice_t* slices;
atlas_slice_frame_t* slice_frames;
quarks_db db;
} atlas_t;
atlas_t atlas_create(const char *inifile, unsigned flags);
int ui_atlas(atlas_t *a);
int ui_atlas_frame(atlas_frame_t *f);
void atlas_destroy(atlas_t *a);
typedef struct sprite_t { struct { ifdef(debug, const char *objname;) union { uintptr_t objheader; struct { uintptr_t objtype:8; uintptr_t objsizew:8; uintptr_t objrefs:8; uintptr_t objheap:1; uintptr_t objcomps:1; uintptr_t objunused:64-8-8-8-1-1-16-3; uintptr_t objid:16+3; }; }; struct obj** objchildren; };
vec4 gamepad;
vec2 fire;
@ -3187,7 +3269,7 @@ unsigned play;
bool paused;
struct atlas_t *a;
} sprite_t;
enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on_L__LINE__ : !!(10 <= 255); } static_assert_on_Lconcat(_L,3781)___COUNTER__; typedef struct { unsigned static_assert_on_L__LINE__ : !!(sizeof(sprite_t)); } static_assert_on_Lconcat(_L,3781)___COUNTER__;;
enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on_L__LINE__ : !!(10 <= 255); } static_assert_on_Lconcat(_L,3930)___COUNTER__; typedef struct { unsigned static_assert_on_L__LINE__ : !!(sizeof(sprite_t)); } static_assert_on_Lconcat(_L,3930)___COUNTER__;;
void sprite_ctor(sprite_t *s);
void sprite_dtor(sprite_t *s);
void sprite_tick(sprite_t *s);
@ -3196,48 +3278,6 @@ enum { OBJTYPE_sprite_t = 10 }; typedef struct { unsigned static_assert_on
sprite_t*sprite_new(const char *ase, int bindings[6]);
void sprite_del(sprite_t *s);
void sprite_setanim(sprite_t *s, unsigned name);
char* tempvl(const char *fmt, va_list);
char* tempva(const char *fmt, ...);
char* strcatf(char **s, const char *buf);
int strmatch(const char *s, const char *wildcard);
int strmatchi(const char *s, const char *wildcard);
int strcmp_qsort(const void *a, const void *b);
int strcmpi_qsort(const void *a, const void *b);
bool strbeg(const char *src, const char *sub);
bool strend(const char *src, const char *sub);
bool strbegi(const char *src, const char *sub);
bool strendi(const char *src, const char *sub);
const char * strstri(const char *src, const char *sub);
char * strupper(const char *str);
char * strlower(const char *str);
char * strrepl(char **copy, const char *target, const char *replace);
char * strswap(char *copy, const char *target, const char *replace);
char * strcut(char *copy, const char *target);
const char * strlerp(unsigned numpairs, const char **pairs, const char *str);
size_t strlcat(char *dst, const char *src, size_t dstcap);
size_t strlcpy(char *dst, const char *src, size_t dstcap);
char** strsplit(const char *string, const char *delimiters);
char* strjoin(char** list, const char *separator);
char * string8(const wchar_t *str);
uint32_t* string32( const char *utf8 );
unsigned intern( const char *string );
const char *quark( unsigned key );
typedef struct quarks_db {
char* blob;
vec2i* entries;
} quarks_db;
unsigned quark_intern( quarks_db*, const char *string );
const char *quark_string( quarks_db*, unsigned key );
bool kit_load( const char *filename );
bool kit_merge( const char *filename );
void kit_insert( const char *id, const char *translation );
void kit_clear();
void kit_set( const char *variable, const char *value );
void kit_reset();
void kit_dump_state( FILE *fp );
char* kit_translate2( const char *id, const char *langcode_iso639_1 );
void kit_locale( const char *langcode_iso639_1 );
char* kit_translate( const char *id );
void* thread( int (*thread_func)(void* user_data), void* user_data );
void thread_destroy( void *thd );
int argc();

View File

@ -17833,123 +17833,6 @@ API unsigned scene_count_light();
API light_t* scene_index_light(unsigned index);
#line 0
#line 1 "v4k_sprite.h"
// -----------------------------------------------------------------------------
// sprites
typedef enum SPRITE_FLAGS {
SPRITE_PROJECTED = 1,
SPRITE_ADDITIVE = 2,
SPRITE_CENTERED = 4,
SPRITE_RESOLUTION_INDEPENDANT = 128,
} SPRITE_FLAGS;
// texture id, position(x,y,depth sort), tint color, rotation angle
API void sprite( texture_t texture, float position[3], float rotation /*0*/, unsigned color /*~0u*/, unsigned flags);
// texture id, rect(x,y,w,h) is [0..1] normalized, then: pos(xyz,z-index), (scale.xy,offset.xy), rotation (degrees), color (rgba)
API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
// texture id, sheet(frameNumber,X,Y) (frame in a X*Y spritesheet), position(x,y,depth sort), rotation angle, offset(x,y), scale(x,y), is_additive, tint color
API void sprite_sheet( texture_t texture, float sheet[3], float position[3], float rotation, float offset[2], float scale[2], unsigned rgba, unsigned flags);
API void sprite_flush();
// -----------------------------------------------------------------------------
// tilemaps
typedef struct tileset_t {
texture_t tex; // spritesheet
unsigned tile_w, tile_h; // dimensions per tile in pixels
unsigned cols, rows; // tileset num_cols, num_rows
unsigned selected; // active tile (while editing)
} tileset_t;
API tileset_t tileset(texture_t tex, unsigned tile_w, unsigned tile_h, unsigned cols, unsigned rows);
API int ui_tileset( tileset_t t );
typedef struct tilemap_t {
int blank_chr; // transparent tile
unsigned cols, rows; // map dimensions (in tiles)
array(int) map;
vec3 position; // x,y,scale
float zindex;
float tilt;
unsigned tint;
bool is_additive;
} tilemap_t;
API tilemap_t tilemap(const char *map, int blank_chr, int linefeed_chr);
API void tilemap_render( tilemap_t m, tileset_t style );
API void tilemap_render_ext( tilemap_t m, tileset_t style, float zindex, float xy_zoom[3], float tilt, unsigned tint, bool is_additive );
// -----------------------------------------------------------------------------
// tiled maps
typedef struct tiled_t {
char *map_name;
unsigned first_gid, tilew, tileh, w, h;
bool parallax;
vec3 position;
array(bool) visible;
array(tilemap_t) layers;
array(tileset_t) sets;
array(char*) names;
} tiled_t;
API tiled_t tiled(const char *file_tmx);
API void tiled_render(tiled_t tmx, vec3 pos);
API void ui_tiled(tiled_t *t);
// -----------------------------------------------------------------------------
// spines
typedef struct spine_t spine_t;
API spine_t*spine(const char *file_json, const char *file_atlas, unsigned flags);
API void spine_skin(spine_t *p, unsigned skin);
API void spine_render(spine_t *p, vec3 offset, unsigned flags);
API void spine_animate(spine_t *p, float delta);
API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// sprite v2 api
typedef struct sprite_t { OBJ
vec4 gamepad; // up,down,left,right
vec2 fire; // a,b
vec4 pos;
vec2 sca;
float tilt;
unsigned tint;
unsigned frame;
unsigned timer, timer_ms;
unsigned flip_, flipped;
unsigned play;
bool paused;
// array(unsigned) play_queue; or unsigned play_next;
struct atlas_t *a; // shared
//atlas_t own; // owned
} sprite_t;
OBJTYPEDEF(sprite_t,10);
API void sprite_ctor(sprite_t *s);
API void sprite_dtor(sprite_t *s);
API void sprite_tick(sprite_t *s);
API void sprite_draw(sprite_t *s);
API void sprite_edit(sprite_t *s);
API sprite_t*sprite_new(const char *ase, int bindings[6]);
API void sprite_del(sprite_t *s);
API void sprite_setanim(sprite_t *s, unsigned name);
#line 0
#line 1 "v4k_string.h"
// string framework
// - rlyeh, public domain
@ -18062,6 +17945,166 @@ API void kit_locale( const char *langcode_iso639_1 ); // set current locale: en
API char* kit_translate( const char *id ); // perform a translation, given current locale
#line 0
#line 1 "v4k_sprite.h"
// -----------------------------------------------------------------------------
// sprites
typedef enum SPRITE_FLAGS {
SPRITE_PROJECTED = 1,
SPRITE_ADDITIVE = 2,
SPRITE_CENTERED = 4,
SPRITE_RESOLUTION_INDEPENDANT = 128,
} SPRITE_FLAGS;
// texture id, position(x,y,depth sort), tint color, rotation angle
API void sprite( texture_t texture, float position[3], float rotation /*0*/, unsigned color /*~0u*/, unsigned flags);
// texture id, rect(x,y,w,h) is [0..1] normalized, then: pos(xyz,z-index), (scale.xy,offset.xy), rotation (degrees), color (rgba)
API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
// texture id, sheet(frameNumber,X,Y) (frame in a X*Y spritesheet), position(x,y,depth sort), rotation angle, offset(x,y), scale(x,y), is_additive, tint color
API void sprite_sheet( texture_t texture, float sheet[3], float position[3], float rotation, float offset[2], float scale[2], unsigned rgba, unsigned flags);
API void sprite_flush();
// -----------------------------------------------------------------------------
// tilemaps
typedef struct tileset_t {
texture_t tex; // spritesheet
unsigned tile_w, tile_h; // dimensions per tile in pixels
unsigned cols, rows; // tileset num_cols, num_rows
unsigned selected; // active tile (while editing)
} tileset_t;
API tileset_t tileset(texture_t tex, unsigned tile_w, unsigned tile_h, unsigned cols, unsigned rows);
API int ui_tileset( tileset_t t );
typedef struct tilemap_t {
int blank_chr; // transparent tile
unsigned cols, rows; // map dimensions (in tiles)
array(int) map;
vec3 position; // x,y,scale
float zindex;
float tilt;
unsigned tint;
bool is_additive;
} tilemap_t;
API tilemap_t tilemap(const char *map, int blank_chr, int linefeed_chr);
API void tilemap_render( tilemap_t m, tileset_t style );
API void tilemap_render_ext( tilemap_t m, tileset_t style, float zindex, float xy_zoom[3], float tilt, unsigned tint, bool is_additive );
// -----------------------------------------------------------------------------
// tiled maps
typedef struct tiled_t {
char *map_name;
unsigned first_gid, tilew, tileh, w, h;
bool parallax;
vec3 position;
array(bool) visible;
array(tilemap_t) layers;
array(tileset_t) sets;
array(char*) names;
} tiled_t;
API tiled_t tiled(const char *file_tmx);
API void tiled_render(tiled_t tmx, vec3 pos);
API void ui_tiled(tiled_t *t);
// -----------------------------------------------------------------------------
// spines
typedef struct spine_t spine_t;
API spine_t*spine(const char *file_json, const char *file_atlas, unsigned flags);
API void spine_skin(spine_t *p, unsigned skin);
API void spine_render(spine_t *p, vec3 offset, unsigned flags);
API void spine_animate(spine_t *p, float delta);
API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
unsigned name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_slice_frame_t {
vec4 bounds;
bool has_9slice;
vec4 core;
} atlas_slice_frame_t;
typedef struct atlas_slice_t {
unsigned name;
array(unsigned) frames;
} atlas_slice_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
array(atlas_slice_t) slices;
array(atlas_slice_frame_t) slice_frames;
quarks_db db;
} atlas_t;
API atlas_t atlas_create(const char *inifile, unsigned flags);
API int ui_atlas(atlas_t *a);
API int ui_atlas_frame(atlas_frame_t *f);
API void atlas_destroy(atlas_t *a);
// ----------------------------------------------------------------------------
// sprite v2 api
typedef struct sprite_t { OBJ
vec4 gamepad; // up,down,left,right
vec2 fire; // a,b
vec4 pos;
vec2 sca;
float tilt;
unsigned tint;
unsigned frame;
unsigned timer, timer_ms;
unsigned flip_, flipped;
unsigned play;
bool paused;
// array(unsigned) play_queue; or unsigned play_next;
struct atlas_t *a; // shared
//atlas_t own; // owned
} sprite_t;
OBJTYPEDEF(sprite_t,10);
API void sprite_ctor(sprite_t *s);
API void sprite_dtor(sprite_t *s);
API void sprite_tick(sprite_t *s);
API void sprite_draw(sprite_t *s);
API void sprite_edit(sprite_t *s);
API sprite_t*sprite_new(const char *ase, int bindings[6]);
API void sprite_del(sprite_t *s);
API void sprite_setanim(sprite_t *s, unsigned name);
#line 0
#line 1 "v4k_system.h"
// -----------------------------------------------------------------------------
// system framework utils
@ -370446,29 +370489,6 @@ int ui_obj(const char *fmt, obj *o) {
// ----------------------------------------------------------------------------
// atlas
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
quark_t name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
quarks_db db;
} atlas_t;
int ui_atlas_frame(atlas_frame_t *f) {
ui_unsigned("delay", &f->delay);
ui_vec4("sheet", &f->sheet);
@ -370478,6 +370498,13 @@ int ui_atlas_frame(atlas_frame_t *f) {
return 0;
}
int ui_atlas_slice_frame(atlas_slice_frame_t *f) {
ui_vec4("bounds", &f->bounds);
ui_bool("9-slice", &f->has_9slice);
ui_vec4("core", &f->core);
return 0;
}
int ui_atlas(atlas_t *a) {
int changed = 0;
ui_texture(NULL, a->tex);
@ -370494,6 +370521,19 @@ int ui_atlas(atlas_t *a) {
ui_collapse_end();
}
}
for( int i = 0; i < array_count(a->slices); ++i ) {
if( ui_collapse(quark_string(&a->db, a->slices[i].name), va("%p%d", a, a->slices[i].name) ) ) {
changed = i+1;
for( int j = 0; j < array_count(a->slices[i].frames); ++j ) {
if( ui_collapse(va("[%d]",j), va("%p%d.%d", a, a->slices[i].name,j) ) ) {
// ui_unsigned("Frame", &a->slices[i].frames[j]);
ui_atlas_slice_frame(a->slice_frames + a->slices[i].frames[j]);
ui_collapse_end();
}
}
ui_collapse_end();
}
}
return changed;
}
@ -370510,11 +370550,48 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
ini_t kv = ini(inifile);
for each_map(kv, char*,k, char*,v ) {
unsigned index = atoi(k);
// printf("aaa %s=%s\n", k, v);
/**/ if( strend(k, ".name") ) {
array_reserve_(a.anims, index);
a.anims[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_name") ) {
array_reserve_(a.slices, index);
a.slices[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_frames") ) {
array_reserve_(a.slices, index);
const char *text = v;
array(char*) frames = strsplit(text, ",");
for( int i = 0; i < array_count(frames); i++ ) {
unsigned frame = atoi(frames[i]);
array_push(a.slices[index].frames, frame);
}
}
else if ( strend(k, ".sl_bounds") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].bounds = vec4(x,y,x+z,y+w);
}
else if ( strend(k, ".sl_9slice") ) {
array_reserve_(a.slice_frames, index);
a.slice_frames[index].has_9slice = atoi(v);
}
else if ( strend(k, ".sl_core") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].core = vec4(x,y,x+z,y+w);
}
else if( strend(k, ".frames") ) {
array_reserve_(a.anims, index);
@ -370604,6 +370681,16 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
}
// @todo: adjust padding/border
}
for each_array_ptr(a.slice_frames, atlas_slice_frame_t, f) {
f->bounds.x += padding+border;
f->bounds.y += padding+border;
f->bounds.z += padding+border;
f->bounds.w += padding+border;
// f->core.x += f->bounds.x;
// f->core.y += f->bounds.y;
// f->core.z += f->bounds.x;
// f->core.w += f->bounds.y;
}
#if 0
// post-process: specify an anchor for each anim based on 1st frame dims
for each_array_ptr(a.anims, atlas_anim_t, anim) {

View File

@ -142,10 +142,10 @@ extern "C" {
{{FILE:v4k_scene.h}}
{{FILE:v4k_sprite.h}}
{{FILE:v4k_string.h}}
{{FILE:v4k_sprite.h}}
{{FILE:v4k_system.h}}
{{FILE:v4k_time.h}}

View File

@ -1174,29 +1174,6 @@ int ui_obj(const char *fmt, obj *o) {
// ----------------------------------------------------------------------------
// atlas
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
quark_t name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
quarks_db db;
} atlas_t;
int ui_atlas_frame(atlas_frame_t *f) {
ui_unsigned("delay", &f->delay);
ui_vec4("sheet", &f->sheet);
@ -1206,6 +1183,13 @@ int ui_atlas_frame(atlas_frame_t *f) {
return 0;
}
int ui_atlas_slice_frame(atlas_slice_frame_t *f) {
ui_vec4("bounds", &f->bounds);
ui_bool("9-slice", &f->has_9slice);
ui_vec4("core", &f->core);
return 0;
}
int ui_atlas(atlas_t *a) {
int changed = 0;
ui_texture(NULL, a->tex);
@ -1222,6 +1206,19 @@ int ui_atlas(atlas_t *a) {
ui_collapse_end();
}
}
for( int i = 0; i < array_count(a->slices); ++i ) {
if( ui_collapse(quark_string(&a->db, a->slices[i].name), va("%p%d", a, a->slices[i].name) ) ) {
changed = i+1;
for( int j = 0; j < array_count(a->slices[i].frames); ++j ) {
if( ui_collapse(va("[%d]",j), va("%p%d.%d", a, a->slices[i].name,j) ) ) {
// ui_unsigned("Frame", &a->slices[i].frames[j]);
ui_atlas_slice_frame(a->slice_frames + a->slices[i].frames[j]);
ui_collapse_end();
}
}
ui_collapse_end();
}
}
return changed;
}
@ -1238,11 +1235,48 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
ini_t kv = ini(inifile);
for each_map(kv, char*,k, char*,v ) {
unsigned index = atoi(k);
// printf("aaa %s=%s\n", k, v);
/**/ if( strend(k, ".name") ) {
array_reserve_(a.anims, index);
a.anims[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_name") ) {
array_reserve_(a.slices, index);
a.slices[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_frames") ) {
array_reserve_(a.slices, index);
const char *text = v;
array(char*) frames = strsplit(text, ",");
for( int i = 0; i < array_count(frames); i++ ) {
unsigned frame = atoi(frames[i]);
array_push(a.slices[index].frames, frame);
}
}
else if ( strend(k, ".sl_bounds") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].bounds = vec4(x,y,x+z,y+w);
}
else if ( strend(k, ".sl_9slice") ) {
array_reserve_(a.slice_frames, index);
a.slice_frames[index].has_9slice = atoi(v);
}
else if ( strend(k, ".sl_core") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].core = vec4(x,y,x+z,y+w);
}
else if( strend(k, ".frames") ) {
array_reserve_(a.anims, index);
@ -1332,6 +1366,16 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
}
// @todo: adjust padding/border
}
for each_array_ptr(a.slice_frames, atlas_slice_frame_t, f) {
f->bounds.x += padding+border;
f->bounds.y += padding+border;
f->bounds.z += padding+border;
f->bounds.w += padding+border;
// f->core.x += f->bounds.x;
// f->core.y += f->bounds.y;
// f->core.z += f->bounds.x;
// f->core.w += f->bounds.y;
}
#if 0
// post-process: specify an anchor for each anim based on 1st frame dims
for each_array_ptr(a.anims, atlas_anim_t, anim) {

View File

@ -81,6 +81,49 @@ API void spine_animate(spine_t *p, float delta);
API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
unsigned name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_slice_frame_t {
vec4 bounds;
bool has_9slice;
vec4 core;
} atlas_slice_frame_t;
typedef struct atlas_slice_t {
unsigned name;
array(unsigned) frames;
} atlas_slice_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
array(atlas_slice_t) slices;
array(atlas_slice_frame_t) slice_frames;
quarks_db db;
} atlas_t;
API atlas_t atlas_create(const char *inifile, unsigned flags);
API int ui_atlas(atlas_t *a);
API int ui_atlas_frame(atlas_frame_t *f);
API void atlas_destroy(atlas_t *a);
// ----------------------------------------------------------------------------
// sprite v2 api

View File

@ -22708,29 +22708,6 @@ int ui_obj(const char *fmt, obj *o) {
// ----------------------------------------------------------------------------
// atlas
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
quark_t name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
quarks_db db;
} atlas_t;
int ui_atlas_frame(atlas_frame_t *f) {
ui_unsigned("delay", &f->delay);
ui_vec4("sheet", &f->sheet);
@ -22740,6 +22717,13 @@ int ui_atlas_frame(atlas_frame_t *f) {
return 0;
}
int ui_atlas_slice_frame(atlas_slice_frame_t *f) {
ui_vec4("bounds", &f->bounds);
ui_bool("9-slice", &f->has_9slice);
ui_vec4("core", &f->core);
return 0;
}
int ui_atlas(atlas_t *a) {
int changed = 0;
ui_texture(NULL, a->tex);
@ -22756,6 +22740,19 @@ int ui_atlas(atlas_t *a) {
ui_collapse_end();
}
}
for( int i = 0; i < array_count(a->slices); ++i ) {
if( ui_collapse(quark_string(&a->db, a->slices[i].name), va("%p%d", a, a->slices[i].name) ) ) {
changed = i+1;
for( int j = 0; j < array_count(a->slices[i].frames); ++j ) {
if( ui_collapse(va("[%d]",j), va("%p%d.%d", a, a->slices[i].name,j) ) ) {
// ui_unsigned("Frame", &a->slices[i].frames[j]);
ui_atlas_slice_frame(a->slice_frames + a->slices[i].frames[j]);
ui_collapse_end();
}
}
ui_collapse_end();
}
}
return changed;
}
@ -22772,11 +22769,48 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
ini_t kv = ini(inifile);
for each_map(kv, char*,k, char*,v ) {
unsigned index = atoi(k);
// printf("aaa %s=%s\n", k, v);
/**/ if( strend(k, ".name") ) {
array_reserve_(a.anims, index);
a.anims[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_name") ) {
array_reserve_(a.slices, index);
a.slices[index].name = quark_intern(&a.db, v);
}
else if ( strend(k, ".sl_frames") ) {
array_reserve_(a.slices, index);
const char *text = v;
array(char*) frames = strsplit(text, ",");
for( int i = 0; i < array_count(frames); i++ ) {
unsigned frame = atoi(frames[i]);
array_push(a.slices[index].frames, frame);
}
}
else if ( strend(k, ".sl_bounds") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].bounds = vec4(x,y,x+z,y+w);
}
else if ( strend(k, ".sl_9slice") ) {
array_reserve_(a.slice_frames, index);
a.slice_frames[index].has_9slice = atoi(v);
}
else if ( strend(k, ".sl_core") ) {
array_reserve_(a.slice_frames, index);
float x,y,z,w;
sscanf(v, "%f,%f,%f,%f", &x, &y, &z, &w);
a.slice_frames[index].core = vec4(x,y,x+z,y+w);
}
else if( strend(k, ".frames") ) {
array_reserve_(a.anims, index);
@ -22866,6 +22900,16 @@ atlas_t atlas_create(const char *inifile, unsigned flags) {
}
// @todo: adjust padding/border
}
for each_array_ptr(a.slice_frames, atlas_slice_frame_t, f) {
f->bounds.x += padding+border;
f->bounds.y += padding+border;
f->bounds.z += padding+border;
f->bounds.w += padding+border;
// f->core.x += f->bounds.x;
// f->core.y += f->bounds.y;
// f->core.z += f->bounds.x;
// f->core.w += f->bounds.y;
}
#if 0
// post-process: specify an anchor for each anim based on 1st frame dims
for each_array_ptr(a.anims, atlas_anim_t, anim) {

View File

@ -3900,123 +3900,6 @@ API unsigned scene_count_light();
API light_t* scene_index_light(unsigned index);
#line 0
#line 1 "v4k_sprite.h"
// -----------------------------------------------------------------------------
// sprites
typedef enum SPRITE_FLAGS {
SPRITE_PROJECTED = 1,
SPRITE_ADDITIVE = 2,
SPRITE_CENTERED = 4,
SPRITE_RESOLUTION_INDEPENDANT = 128,
} SPRITE_FLAGS;
// texture id, position(x,y,depth sort), tint color, rotation angle
API void sprite( texture_t texture, float position[3], float rotation /*0*/, unsigned color /*~0u*/, unsigned flags);
// texture id, rect(x,y,w,h) is [0..1] normalized, then: pos(xyz,z-index), (scale.xy,offset.xy), rotation (degrees), color (rgba)
API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
// texture id, sheet(frameNumber,X,Y) (frame in a X*Y spritesheet), position(x,y,depth sort), rotation angle, offset(x,y), scale(x,y), is_additive, tint color
API void sprite_sheet( texture_t texture, float sheet[3], float position[3], float rotation, float offset[2], float scale[2], unsigned rgba, unsigned flags);
API void sprite_flush();
// -----------------------------------------------------------------------------
// tilemaps
typedef struct tileset_t {
texture_t tex; // spritesheet
unsigned tile_w, tile_h; // dimensions per tile in pixels
unsigned cols, rows; // tileset num_cols, num_rows
unsigned selected; // active tile (while editing)
} tileset_t;
API tileset_t tileset(texture_t tex, unsigned tile_w, unsigned tile_h, unsigned cols, unsigned rows);
API int ui_tileset( tileset_t t );
typedef struct tilemap_t {
int blank_chr; // transparent tile
unsigned cols, rows; // map dimensions (in tiles)
array(int) map;
vec3 position; // x,y,scale
float zindex;
float tilt;
unsigned tint;
bool is_additive;
} tilemap_t;
API tilemap_t tilemap(const char *map, int blank_chr, int linefeed_chr);
API void tilemap_render( tilemap_t m, tileset_t style );
API void tilemap_render_ext( tilemap_t m, tileset_t style, float zindex, float xy_zoom[3], float tilt, unsigned tint, bool is_additive );
// -----------------------------------------------------------------------------
// tiled maps
typedef struct tiled_t {
char *map_name;
unsigned first_gid, tilew, tileh, w, h;
bool parallax;
vec3 position;
array(bool) visible;
array(tilemap_t) layers;
array(tileset_t) sets;
array(char*) names;
} tiled_t;
API tiled_t tiled(const char *file_tmx);
API void tiled_render(tiled_t tmx, vec3 pos);
API void ui_tiled(tiled_t *t);
// -----------------------------------------------------------------------------
// spines
typedef struct spine_t spine_t;
API spine_t*spine(const char *file_json, const char *file_atlas, unsigned flags);
API void spine_skin(spine_t *p, unsigned skin);
API void spine_render(spine_t *p, vec3 offset, unsigned flags);
API void spine_animate(spine_t *p, float delta);
API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// sprite v2 api
typedef struct sprite_t { OBJ
vec4 gamepad; // up,down,left,right
vec2 fire; // a,b
vec4 pos;
vec2 sca;
float tilt;
unsigned tint;
unsigned frame;
unsigned timer, timer_ms;
unsigned flip_, flipped;
unsigned play;
bool paused;
// array(unsigned) play_queue; or unsigned play_next;
struct atlas_t *a; // shared
//atlas_t own; // owned
} sprite_t;
OBJTYPEDEF(sprite_t,10);
API void sprite_ctor(sprite_t *s);
API void sprite_dtor(sprite_t *s);
API void sprite_tick(sprite_t *s);
API void sprite_draw(sprite_t *s);
API void sprite_edit(sprite_t *s);
API sprite_t*sprite_new(const char *ase, int bindings[6]);
API void sprite_del(sprite_t *s);
API void sprite_setanim(sprite_t *s, unsigned name);
#line 0
#line 1 "v4k_string.h"
// string framework
// - rlyeh, public domain
@ -4129,6 +4012,166 @@ API void kit_locale( const char *langcode_iso639_1 ); // set current locale: en
API char* kit_translate( const char *id ); // perform a translation, given current locale
#line 0
#line 1 "v4k_sprite.h"
// -----------------------------------------------------------------------------
// sprites
typedef enum SPRITE_FLAGS {
SPRITE_PROJECTED = 1,
SPRITE_ADDITIVE = 2,
SPRITE_CENTERED = 4,
SPRITE_RESOLUTION_INDEPENDANT = 128,
} SPRITE_FLAGS;
// texture id, position(x,y,depth sort), tint color, rotation angle
API void sprite( texture_t texture, float position[3], float rotation /*0*/, unsigned color /*~0u*/, unsigned flags);
// texture id, rect(x,y,w,h) is [0..1] normalized, then: pos(xyz,z-index), (scale.xy,offset.xy), rotation (degrees), color (rgba)
API void sprite_rect( texture_t t, vec4 rect, vec4 pos, vec4 scaleoff, float tilt_deg, unsigned tint_rgba, unsigned flags);
// texture id, sheet(frameNumber,X,Y) (frame in a X*Y spritesheet), position(x,y,depth sort), rotation angle, offset(x,y), scale(x,y), is_additive, tint color
API void sprite_sheet( texture_t texture, float sheet[3], float position[3], float rotation, float offset[2], float scale[2], unsigned rgba, unsigned flags);
API void sprite_flush();
// -----------------------------------------------------------------------------
// tilemaps
typedef struct tileset_t {
texture_t tex; // spritesheet
unsigned tile_w, tile_h; // dimensions per tile in pixels
unsigned cols, rows; // tileset num_cols, num_rows
unsigned selected; // active tile (while editing)
} tileset_t;
API tileset_t tileset(texture_t tex, unsigned tile_w, unsigned tile_h, unsigned cols, unsigned rows);
API int ui_tileset( tileset_t t );
typedef struct tilemap_t {
int blank_chr; // transparent tile
unsigned cols, rows; // map dimensions (in tiles)
array(int) map;
vec3 position; // x,y,scale
float zindex;
float tilt;
unsigned tint;
bool is_additive;
} tilemap_t;
API tilemap_t tilemap(const char *map, int blank_chr, int linefeed_chr);
API void tilemap_render( tilemap_t m, tileset_t style );
API void tilemap_render_ext( tilemap_t m, tileset_t style, float zindex, float xy_zoom[3], float tilt, unsigned tint, bool is_additive );
// -----------------------------------------------------------------------------
// tiled maps
typedef struct tiled_t {
char *map_name;
unsigned first_gid, tilew, tileh, w, h;
bool parallax;
vec3 position;
array(bool) visible;
array(tilemap_t) layers;
array(tileset_t) sets;
array(char*) names;
} tiled_t;
API tiled_t tiled(const char *file_tmx);
API void tiled_render(tiled_t tmx, vec3 pos);
API void ui_tiled(tiled_t *t);
// -----------------------------------------------------------------------------
// spines
typedef struct spine_t spine_t;
API spine_t*spine(const char *file_json, const char *file_atlas, unsigned flags);
API void spine_skin(spine_t *p, unsigned skin);
API void spine_render(spine_t *p, vec3 offset, unsigned flags);
API void spine_animate(spine_t *p, float delta);
API void ui_spine(spine_t *p);
// ----------------------------------------------------------------------------
// atlas api
typedef struct atlas_frame_t {
unsigned delay;
vec4 sheet;
vec2 anchor; // @todo
array(vec3i) indices;
array(vec2) coords;
array(vec2) uvs;
} atlas_frame_t;
typedef struct atlas_anim_t {
unsigned name;
array(unsigned) frames;
} atlas_anim_t;
typedef struct atlas_slice_frame_t {
vec4 bounds;
bool has_9slice;
vec4 core;
} atlas_slice_frame_t;
typedef struct atlas_slice_t {
unsigned name;
array(unsigned) frames;
} atlas_slice_t;
typedef struct atlas_t {
texture_t tex;
array(atlas_frame_t) frames;
array(atlas_anim_t) anims;
array(atlas_slice_t) slices;
array(atlas_slice_frame_t) slice_frames;
quarks_db db;
} atlas_t;
API atlas_t atlas_create(const char *inifile, unsigned flags);
API int ui_atlas(atlas_t *a);
API int ui_atlas_frame(atlas_frame_t *f);
API void atlas_destroy(atlas_t *a);
// ----------------------------------------------------------------------------
// sprite v2 api
typedef struct sprite_t { OBJ
vec4 gamepad; // up,down,left,right
vec2 fire; // a,b
vec4 pos;
vec2 sca;
float tilt;
unsigned tint;
unsigned frame;
unsigned timer, timer_ms;
unsigned flip_, flipped;
unsigned play;
bool paused;
// array(unsigned) play_queue; or unsigned play_next;
struct atlas_t *a; // shared
//atlas_t own; // owned
} sprite_t;
OBJTYPEDEF(sprite_t,10);
API void sprite_ctor(sprite_t *s);
API void sprite_dtor(sprite_t *s);
API void sprite_tick(sprite_t *s);
API void sprite_draw(sprite_t *s);
API void sprite_edit(sprite_t *s);
API sprite_t*sprite_new(const char *ase, int bindings[6]);
API void sprite_del(sprite_t *s);
API void sprite_setanim(sprite_t *s, unsigned name);
#line 0
#line 1 "v4k_system.h"
// -----------------------------------------------------------------------------
// system framework utils

View File

@ -607,6 +607,7 @@ atlas_t* atlas_loadimages(array(atlas_image) images, atlas_flags flags)
}
static char *atlas_anims = 0;
static char *atlas_slices = 0;
static char *atlas_current_anim = 0;
atlas_t* atlas_loadfiles(array(char*) files, atlas_flags flags)
@ -677,7 +678,34 @@ atlas_t* atlas_loadfiles(array(char*) files, atlas_flags flags)
array_push(images, img);
}
static int count = 0;
static int slice_idx = -1;
static int slice_frame_idx = 0;
static const char *slice_name = 0;
if(!atlas_slices) strcatf(&atlas_slices, "[slices]\n");
for( int t = 0; t < ase->slice_count; ++t) {
ase_slice_t *slice = ase->slices + t;
if (!slice_name || strcmp(slice_name, slice->name)) {
++slice_idx;
strcatf(&atlas_slices, "[%d].sl_name=%s\n", slice_idx, slice->name);
strcatf(&atlas_slices, "[%d].sl_frames=", slice_idx);
for( int u = 0; u < ase->slice_count; ++u) {
if (!strcmp(slice->name, ase->slices[u].name)) {
strcatf(&atlas_slices, "%d,", u);
}
}
strcatf(&atlas_slices, "\n");
}
strcatf(&atlas_slices, "[%d].sl_bounds=%d,%d,%d,%d\n", slice_idx, slice->origin_x, slice->origin_y, slice->w, slice->h);
strcatf(&atlas_slices, "[%d].sl_9slice=%d\n", slice_idx, slice->has_center_as_9_slice);
if (slice->has_center_as_9_slice)
strcatf(&atlas_slices, "[%d].sl_core=%d,%d,%d,%d\n", slice_idx, slice->center_x, slice->center_y, slice->center_w, slice->center_h);
slice_name = slice->name;
++slice_frame_idx;
}
static int anim_idx = 0;
if(!atlas_anims) strcatf(&atlas_anims, "[anims]\n");
for( int t = 0; t < ase->tag_count; ++t) {
@ -694,8 +722,8 @@ atlas_t* atlas_loadfiles(array(char*) files, atlas_flags flags)
trimspace(name);
char *sep = "";
strcatf(&atlas_anims, "[%d].name=%s.%s\n", count, atlas_current_anim, name+1);
strcatf(&atlas_anims, "[%d].frames=", count);
strcatf(&atlas_anims, "[%d].name=%s.%s\n", anim_idx, atlas_current_anim, name+1);
strcatf(&atlas_anims, "[%d].frames=", anim_idx);
if( tag->loop_animation_direction != ASE_ANIMATION_DIRECTION_BACKWARDS)
for( int from = tag->from_frame; from <= tag->to_frame; ++from ) {
strcatf(&atlas_anims, "%s%d,%d", sep, from, ase->frames[from].duration_milliseconds), sep = ",";
@ -707,7 +735,7 @@ atlas_t* atlas_loadfiles(array(char*) files, atlas_flags flags)
}
strcatf(&atlas_anims,"\n");
++count;
++anim_idx;
}
}
@ -813,8 +841,8 @@ bool atlas_save(const char *outfile, const atlas_t *atlas, atlas_flags flags)
int result = stbi_write_png_to_func(stbi_write_mem, &ctx, dst_w, dst_h, 4, dst, dst_w*4);
char *b64 = base64_encode(ctx.buffer, ctx.offset);
fprintf(writer, "bitmap=%s\n", b64); // %d:%s\n", ctx.offset, b64);
ATLAS_FREE(ctx.buffer);
free(b64);
// ATLAS_FREE(ctx.buffer);
// free(b64);
}
fprintf(writer, "size=%d,%d\n", dst_w, dst_h);
@ -849,6 +877,7 @@ bool atlas_save(const char *outfile, const atlas_t *atlas, atlas_flags flags)
}
if( atlas_anims ) fprintf(writer, "%s\n", atlas_anims);
if( atlas_slices ) fprintf(writer, "%s\n", atlas_slices);
if(writer != stdout) fclose(writer);
return true;

View File

@ -219,9 +219,9 @@ int main(int argc, char* argv[]) {
atlas_free(atlas);
}
for( int i = 0; i < array_count(files); ++i)
ATLAS_REALLOC(files[i], 0);
array_free(files);
// for( int i = 0; i < array_count(files); ++i)
// ATLAS_REALLOC(files[i], 0);
// array_free(files);
return error ? fprintf(stderr, "%s\n", error), -1 : 0;
}

BIN
tools/ase2ini.dll 100644

Binary file not shown.

Binary file not shown.

BIN
tools/ase2ini.lib 100644

Binary file not shown.

BIN
tools/ase2ini.pdb 100644

Binary file not shown.

BIN
tools/vc140.pdb 100644

Binary file not shown.