Permalink
Browse files

pack pointer

  • Loading branch information...
cloudwu committed Jan 18, 2016
1 parent f2748a6 commit 993d09c74ba4b491b9bec56b7af4218ddc616f16
Showing with 236 additions and 152 deletions.
  1. +60 −43 lib/lsprite.c
  2. +5 −3 lib/renderbuffer.c
  3. +74 −37 lib/sprite.c
  4. +2 −0 lib/sprite.h
  5. +44 −34 lib/spritepack.c
  6. +51 −35 lib/spritepack.h
View
@@ -33,6 +33,7 @@ newlabel(lua_State *L, struct pack_label *label) {
// label never has a child
struct pack_label * pl = (struct pack_label *)(s+1);
*pl = *label;
s->pack = NULL;
s->s.label = pl;
s->t.mat = NULL;
s->t.color = 0xffffffff;
@@ -145,15 +146,22 @@ static const char * srt_key[] = {
static void
update_message(struct sprite * s, struct sprite_pack * pack, int parentid, int componentid, int frame) {
struct pack_animation * ani = (struct pack_animation *)pack->data[parentid];
update_message(struct sprite * s, int parentid, int componentid, int frame) {
struct sprite_pack * pack = s->pack;
if (pack == NULL)
return;
void ** data = (void **)OFFSET_TO_POINTER(pack, pack->data);
struct pack_animation * ani = (struct pack_animation *)data[parentid];
if (frame < 0 || frame >= ani->frame_number) {
return;
}
struct pack_frame pframe = ani->frame[frame];
struct pack_frame *pframe = OFFSET_TO_POINTER(pack, ani->frame);
pframe = &pframe[frame];
int i = 0;
for (; i < pframe.n; i++) {
if (pframe.part[i].component_id == componentid && pframe.part[i].touchable) {
for (; i < pframe->n; i++) {
struct pack_part * pp = OFFSET_TO_POINTER(pack, pframe->part);
pp = &pp[i];
if (pp->component_id == componentid && pp->touchable) {
s->flags |= SPRFLAG_MESSAGE;
return;
}
@@ -165,6 +173,7 @@ newanchor(lua_State *L) {
int sz = sizeof(struct sprite) + sizeof(struct anchor_data);
struct sprite * s = (struct sprite *)lua_newuserdata(L, sz);
s->parent = NULL;
s->pack = NULL;
s->t.mat = NULL;
s->t.color = 0xffffffff;
s->t.additive = 0;
@@ -208,7 +217,7 @@ newsprite(lua_State *L, struct sprite_pack *pack, int id) {
if (c) {
c->name = sprite_childname(s, i);
sprite_mount(s, i, c);
update_message(c, pack, id, i, s->frame);
update_message(c, id, i, s->frame);
lua_rawseti(L, -2, i+1);
}
}
@@ -993,8 +1002,8 @@ lchildren_name(lua_State *L) {
int cnt=0;
struct pack_animation * ani = s->s.ani;
for (i=0;i<ani->component_number;i++) {
if (ani->component[i].name != NULL) {
lua_pushstring(L, ani->component[i].name);
if (ani->component[i].name != 0) {
lua_pushstring(L, OFFSET_TO_STRING(s->pack, ani->component[i].name));
cnt++;
}
}
@@ -1377,48 +1386,56 @@ lmethod(lua_State *L) {
luaL_setfuncs(L,l2,nk);
}
struct dummy_pack {
struct sprite_pack dummy;
char name[8];
struct pack_part part;
struct pack_frame frame;
struct pack_action action;
struct pack_animation animation;
};
static int
lnewproxy(lua_State *L) {
static struct pack_part part = {
{
NULL, // mat
0xffffffff, // color
0, // additive
PROGRAM_DEFAULT,
0, // _dummy
}, // trans
0, // component_id
0, // touchable
};
static struct pack_frame frame = {
&part,
1, // n
0, // _dummy
};
static struct pack_action action = {
NULL, // name
1, // number
0, // start_frame
};
static struct pack_animation ani = {
&frame,
&action,
1, // frame_number
1, // action_number
1, // component_number
0, // _dummy
{{
"proxy", // name
0, // id
0, // _dummy
}},
static struct dummy_pack dp = {
{ 0 , 0, 0, { 0, 0 } }, // dummy
"proxy", // name
{ // part
{
0, // mat
0xffffffff, // color
0, // additive
}, // trans
0, // component_id
0, // touchable
},
{ // frame
POINTER_TO_OFFSET(&dp, &dp.part),
1, // n
},
{ // action
0, // name
1, // number
0, // start_frame
},
{ // animation
POINTER_TO_OFFSET(&dp, &dp.frame),
POINTER_TO_OFFSET(&dp, &dp.action),
1, // frame_number
1, // action_number
1, // component_number
{{
POINTER_TO_OFFSET(&dp, &dp.name),
0, // id
}},
}
};
struct sprite * s = (struct sprite *)lua_newuserdata(L, sizeof(struct sprite));
lua_newtable(L);
lua_setuservalue(L, -2);
s->parent = NULL;
s->s.ani = &ani;
s->pack = &dp.dummy;
s->s.ani = &dp.animation;
s->t.mat = NULL;
s->t.color = 0xffffffff;
s->t.additive = 0;
View
@@ -176,18 +176,20 @@ drawsprite(struct render_buffer *rb, struct sprite *s, struct sprite_trans * ts)
frame += s->total_frame;
}
frame += s->start_frame;
struct pack_frame * pf = &ani->frame[frame];
struct pack_frame * pf = OFFSET_TO_POINTER(s->pack, ani->frame);
pf = &pf[frame];
int i;
for (i=0;i<pf->n;i++) {
struct pack_part *pp = &pf->part[i];
struct pack_part *pp = OFFSET_TO_POINTER(s->pack, pf->part);
pp = &pp[i];
int index = pp->component_id;
struct sprite * child = s->data.children[index];
if (child == NULL || (child->flags & SPRFLAG_INVISIBLE)) {
continue;
}
struct sprite_trans temp2;
struct matrix temp_matrix2;
struct sprite_trans *ct = sprite_trans_mul(&pp->t, t, &temp2, &temp_matrix2);
struct sprite_trans *ct = sprite_trans_mul2(s->pack, &pp->t, t, &temp2, &temp_matrix2);
int r = drawsprite(rb, child, ct);
if (r)
return r;
Oops, something went wrong.

0 comments on commit 993d09c

Please sign in to comment.