Esempio n. 1
0
int
load_cache(SSL* ssl, struct worker* worker)
{
	if(!load_rrset_cache(ssl, worker))
		return 0;
	if(!load_msg_cache(ssl, worker))
		return 0;
	return read_fixed(ssl, worker->env.scratch_buffer, "EOF");
}
Esempio n. 2
0
/** load msg cache */
static int
load_msg_cache(SSL* ssl, struct worker* worker)
{
	sldns_buffer* buf = worker->env.scratch_buffer;
	if(!read_fixed(ssl, buf, "START_MSG_CACHE")) return 0;
	while(ssl_read_buf(ssl, buf) && 
		strcmp((char*)sldns_buffer_begin(buf), "END_MSG_CACHE")!=0) {
		if(!load_msg(ssl, buf, worker))
			return 0;
	}
	return 1;
}
Esempio n. 3
0
Entity* spriter_load(const char* compiled_spriter, SpriteAtlas atlas) {
  FILE* cs = fopen(compiled_spriter, "rb");
  if(!cs) {
    fail_exit("failed to load %s", compiled_spriter);
  }

  Entity* ent = (Entity*)malloc(sizeof(Entity));

  read_ushort(cs, &ent->nanimations);
  ent->animations = (Animation*)malloc(sizeof(Animation) * ent->nanimations);

  for(int aidx = 0; aidx < ent->nanimations; ++aidx) {
    Animation* anim = &ent->animations[aidx];
    fread(anim->name, sizeof(anim->name), 1, cs);
    read_ushort(cs, &anim->length_ms);
    read_ushort(cs, &anim->looping);
    read_ushort(cs, &anim->nframes);
    anim->frames = (MasterKey*)malloc(sizeof(MasterKey) * anim->nframes);

    for(int fidx = 0; fidx < anim->nframes; ++fidx) {
      MasterKey* frame = &anim->frames[fidx];
      read_ushort(cs, &frame->time_ms);

      read_ushort(cs, &frame->nrefs);
      frame->refs = (MasterElementRef*)malloc(sizeof(MasterElementRef) * frame->nrefs);

      for(int ridx = 0; ridx < frame->nrefs; ++ridx) {
        MasterElementRef* ref = &frame->refs[ridx];
        read_ushort(cs, &ref->timeline_idx);
        read_ushort(cs, &ref->keyframe_idx);
        read_short(cs, &ref->parent_idx);
      }

      read_ushort(cs, &frame->nbones);
      frame->bones = (MasterElementRef*)malloc(sizeof(MasterElementRef) * frame->nbones);

      for(int ridx = 0; ridx < frame->nbones; ++ridx) {
        MasterElementRef* ref = &frame->bones[ridx];
        read_ushort(cs, &ref->timeline_idx);
        read_ushort(cs, &ref->keyframe_idx);
        read_short(cs, &ref->parent_idx);
      }
    }

    read_ushort(cs, &anim->ntimelines);
    anim->timelines = (Timeline*)malloc(sizeof(Timeline) * anim->ntimelines);
    for(int tidx = 0; tidx < anim->ntimelines; ++tidx) {
      Timeline* tl = &anim->timelines[tidx];
      read_ushort(cs, &tl->nelements);
      tl->elements = (KeyFrameElement*)malloc(sizeof(KeyFrameElement) * tl->nelements);

      for(int eidx = 0; eidx < tl->nelements; ++eidx) {
        KeyFrameElement* el = &tl->elements[eidx];
        char entry_name[MAX_ENTRY_NAME];
        fread(entry_name, sizeof(entry_name), 1, cs);
        if(entry_name[0] != '\0') {
          el->entry = spriteatlas_find(atlas, entry_name);
        } else {
          // must be a bone
          el->entry = NULL;
        }
        read_fixed(cs, &el->angle);
        read_fixed(cs, &el->pivot_x);
        read_fixed(cs, &el->pivot_y);
        read_fixed(cs, &el->scale_x);
        read_fixed(cs, &el->scale_y);
        read_fixed(cs, &el->x);
        read_fixed(cs, &el->y);
        read_short(cs, &el->spin);
      }
    }
  }
  fclose(cs);

  return ent;
}