예제 #1
0
파일: gl_model.c 프로젝트: Cabriter/Quake
/*
=================
Mod_LoadSpriteModel
=================
*/
void Mod_LoadSpriteModel (model_t *mod, void *buffer)
{
    int					i;
    int					version;
    dsprite_t			*pin;
    msprite_t			*psprite;
    int					numframes;
    int					size;
    dspriteframetype_t	*pframetype;

    pin = (dsprite_t *)buffer;

    version = LittleLong (pin->version);
    if (version != SPRITE_VERSION)
        Sys_Error ("%s has wrong version number "
                   "(%i should be %i)", mod->name, version, SPRITE_VERSION);

    numframes = LittleLong (pin->numframes);

    size = sizeof (msprite_t) +	(numframes - 1) * sizeof (psprite->frames);

    psprite = Hunk_AllocName (size, loadname);

    mod->cache.data = psprite;

    psprite->type = LittleLong (pin->type);
    psprite->maxwidth = LittleLong (pin->width);
    psprite->maxheight = LittleLong (pin->height);
    psprite->beamlength = LittleFloat (pin->beamlength);
    mod->synctype = LittleLong (pin->synctype);
    psprite->numframes = numframes;

    mod->mins[0] = mod->mins[1] = -psprite->maxwidth/2;
    mod->maxs[0] = mod->maxs[1] = psprite->maxwidth/2;
    mod->mins[2] = -psprite->maxheight/2;
    mod->maxs[2] = psprite->maxheight/2;

//
// load the frames
//
    if (numframes < 1)
        Sys_Error ("Mod_LoadSpriteModel: Invalid # of frames: %d\n", numframes);

    mod->numframes = numframes;

    pframetype = (dspriteframetype_t *)(pin + 1);

    for (i=0 ; i<numframes ; i++)
    {
        spriteframetype_t	frametype;

        frametype = LittleLong (pframetype->type);
        psprite->frames[i].type = frametype;

        if (frametype == SPR_SINGLE)
        {
            pframetype = (dspriteframetype_t *)
                         Mod_LoadSpriteFrame (pframetype + 1,
                                              &psprite->frames[i].frameptr, i);
        }
        else
        {
            pframetype = (dspriteframetype_t *)
                         Mod_LoadSpriteGroup (pframetype + 1,
                                              &psprite->frames[i].frameptr, i);
        }
    }

    mod->type = mod_sprite;
}
예제 #2
0
/*
=================
Mod_LoadSpriteModel
=================
*/
void Mod_LoadSpriteModel(model_t *mod, void *buffer, const char *loadname)
{
   int i;
   msprite_t *psprite;
   int numframes;
   int size;
   dspriteframetype_t *pframetype;
   dsprite_t *pin = (dsprite_t *)buffer;

#ifdef MSB_FIRST
   int version = LittleLong(pin->version);
#else
   int version = (pin->version);
#endif
   if (version != SPRITE_VERSION)
      Sys_Error("%s: %s has wrong version number (%i should be %i)",
            __func__, mod->name, version, SPRITE_VERSION);

#ifdef MSB_FIRST
   numframes = LittleLong(pin->numframes);
#else
   numframes = (pin->numframes);
#endif
   size = sizeof(*psprite) + numframes * sizeof(psprite->frames[0]);
   psprite = (msprite_t*)Hunk_AllocName(size, loadname);
   mod->cache.data = psprite;

#ifdef MSB_FIRST
   psprite->type = LittleLong(pin->type);
   psprite->maxwidth = LittleLong(pin->width);
   psprite->maxheight = LittleLong(pin->height);
   psprite->beamlength = LittleFloat(pin->beamlength);
   mod->synctype = (synctype_t)LittleLong(pin->synctype);
#else
   psprite->type = (pin->type);
   psprite->maxwidth = (pin->width);
   psprite->maxheight = (pin->height);
   psprite->beamlength = (pin->beamlength);
   mod->synctype = (synctype_t)(pin->synctype);
#endif
   psprite->numframes = numframes;

   mod->mins[0] = mod->mins[1] = -psprite->maxwidth / 2;
   mod->maxs[0] = mod->maxs[1] = psprite->maxwidth / 2;
   mod->mins[2] = -psprite->maxheight / 2;
   mod->maxs[2] = psprite->maxheight / 2;

   //
   // load the frames
   //
   if (numframes < 1)
      Sys_Error("%s: Invalid # of frames: %d", __func__, numframes);

   mod->numframes = numframes;
   mod->flags = 0;

   pframetype = (dspriteframetype_t *)(pin + 1);

   for (i = 0; i < numframes; i++) {
      spriteframetype_t frametype;

#ifdef MSB_FIRST
      frametype = (spriteframetype_t)LittleLong(pframetype->type);
#else
      frametype = (spriteframetype_t)(pframetype->type);
#endif
      psprite->frames[i].type = frametype;

      if (frametype == SPR_SINGLE) {
         pframetype = (dspriteframetype_t *)
            Mod_LoadSpriteFrame(pframetype + 1,
                  &psprite->frames[i].frameptr, loadname, i);
      } else {
         pframetype = (dspriteframetype_t *)
            Mod_LoadSpriteGroup(pframetype + 1,
                  &psprite->frames[i].frameptr, loadname, i);
      }
   }

   mod->type = mod_sprite;
}