예제 #1
0
int main(void) {
  FILE *file = tmpfile();
  size_t len;

  title("fpack()");

  test("s");
  rewind(file);
  len = fpack(file, "s", 0);
  size_ok(len, 1*sizeof(short));
  rewind(file);
  int_ok(fget_short(file), 0);

  test("ss");
  rewind(file);
  len = fpack(file, "ss", 1, 2);
  size_ok(len, 2*sizeof(short));
  rewind(file);
  int_ok(fget_short(file), 1);
  int_ok(fget_short(file), 2);

  test("i");
  rewind(file);
  len = fpack(file, "i", 0);
  size_ok(len, 1*sizeof(int));
  rewind(file);
  int_ok(fget_int(file), 0);

  test("ii");
  rewind(file);
  len = fpack(file, "ii", 1, 2);
  size_ok(len, 2*sizeof(int));
  rewind(file);
  int_ok(fget_int(file), 1);
  int_ok(fget_int(file), 2);

  test("l");
  rewind(file);
  len = fpack(file, "l", 0L);
  long_ok(len, 1*sizeof(long));
  rewind(file);
  long_ok(fget_long(file), 0);

  test("ll");
  rewind(file);
  len = fpack(file, "ll", 1L, 2L);
  long_ok(len, 2*sizeof(long));
  rewind(file);
  long_ok(fget_long(file), 1);
  long_ok(fget_long(file), 2);

  title("funpack()");

  short s1, s2;

  test("s");
  rewind(file);
  fput_short(0, file);
  rewind(file);
  len = funpack(file, "s", &s1);
  size_ok(len, 1*sizeof(short));
  int_ok(s1, 0);

  test("ss");
  rewind(file);
  fput_short(1, file);
  fput_short(2, file);
  rewind(file);
  len = funpack(file, "ss", &s1, &s2);
  size_ok(len, 2*sizeof(short));
  int_ok(s1, 1);
  int_ok(s2, 2);

  int i1, i2;

  test("i");
  rewind(file);
  fput_int(0, file);
  rewind(file);
  len = funpack(file, "i", &i1);
  size_ok(len, 1*sizeof(int));
  int_ok(i1, 0);

  test("ii");
  rewind(file);
  fput_int(1, file);
  fput_int(2, file);
  rewind(file);
  len = funpack(file, "ii", &i1, &i2);
  size_ok(len, 2*sizeof(int));
  int_ok(i1, 1);
  int_ok(i2, 2);

  long l1, l2;

  test("l");
  rewind(file);
  fput_long(0, file);
  rewind(file);
  len = funpack(file, "l", &l1);
  size_ok(len, 1*sizeof(long));
  long_ok(l1, 0);

  test("ll");
  rewind(file);
  fput_long(1, file);
  fput_long(2, file);
  rewind(file);
  len = funpack(file, "ll", &l1, &l2);
  size_ok(len, 2*sizeof(long));
  long_ok(l1, 1);
  long_ok(l2, 2);

  return 0;
}
예제 #2
0
파일: pip_file.c 프로젝트: wangeek/Egoboo
//--------------------------------------------------------------------------------------------
pip_t * load_one_pip_file_vfs( const char *szLoadName, pip_t * ppip )
{
    /// @details ZZ@> This function loads a particle template, returning bfalse if the file wasn't
    ///    found

    vfs_FILE* fileread;
    IDSZ idsz;
    char cTmp;

    fileread = vfs_openRead( szLoadName );
    if ( NULL == fileread )
    {
        return NULL;
    }

    pip_init( ppip );

    // set up the EGO_PROFILE_STUFF
    strncpy( ppip->name, szLoadName, SDL_arraysize( ppip->name ) );
    ppip->loaded = btrue;

    // read the 1 line comment at the top of the file
    vfs_gets( ppip->comment, SDL_arraysize( ppip->comment ) - 1, fileread );

    // rewind the file
    vfs_seek( fileread, 0 );

    // General data
    ppip->force = fget_next_bool( fileread );

    cTmp = fget_next_char( fileread );
    if ( 'L' == toupper( cTmp ) )  ppip->type = SPRITE_LIGHT;
    else if ( 'S' == toupper( cTmp ) )  ppip->type = SPRITE_SOLID;
    else if ( 'T' == toupper( cTmp ) )  ppip->type = SPRITE_ALPHA;

    ppip->image_base = fget_next_int( fileread );
    ppip->numframes = fget_next_int( fileread );
    ppip->image_add.base = fget_next_int( fileread );
    ppip->image_add.rand = fget_next_int( fileread );
    ppip->rotate_pair.base = fget_next_int( fileread );
    ppip->rotate_pair.rand = fget_next_int( fileread );
    ppip->rotate_add = fget_next_int( fileread );
    ppip->size_base = fget_next_int( fileread );
    ppip->size_add = fget_next_int( fileread );
    ppip->spdlimit = fget_next_float( fileread );
    ppip->facingadd = fget_next_int( fileread );

    // override the base rotation
    if ( ppip->image_base < 256 && prt_u != prt_direction[ ppip->image_base ] )
    {
        ppip->rotate_pair.base = prt_direction[ ppip->image_base ];
    };

    // Ending conditions
    ppip->end_water     = fget_next_bool( fileread );
    ppip->end_bump      = fget_next_bool( fileread );
    ppip->end_ground    = fget_next_bool( fileread );
    ppip->end_lastframe = fget_next_bool( fileread );
    ppip->end_time      = fget_next_int( fileread );

    // Collision data
    ppip->dampen     = fget_next_float( fileread );
    ppip->bump_money  = fget_next_int( fileread );
    ppip->bump_size   = fget_next_int( fileread );
    ppip->bump_height = fget_next_int( fileread );

    fget_next_range( fileread, &( ppip->damage ) );
    ppip->damagetype = fget_next_damage_type( fileread );

    // Lighting data
    cTmp = fget_next_char( fileread );
    if ( 'T' == toupper( cTmp ) ) ppip->dynalight.mode = DYNA_MODE_ON;
    else if ( 'L' == toupper( cTmp ) ) ppip->dynalight.mode = DYNA_MODE_LOCAL;
    else                             ppip->dynalight.mode = DYNA_MODE_OFF;

    ppip->dynalight.level   = fget_next_float( fileread );
    ppip->dynalight.falloff = fget_next_int( fileread );

    // Initial spawning of this particle
    ppip->facing_pair.base    = fget_next_int( fileread );
    ppip->facing_pair.rand    = fget_next_int( fileread );
    ppip->spacing_hrz_pair.base = fget_next_int( fileread );
    ppip->spacing_hrz_pair.rand = fget_next_int( fileread );
    ppip->spacing_vrt_pair.base  = fget_next_int( fileread );
    ppip->spacing_vrt_pair.rand  = fget_next_int( fileread );
    ppip->vel_hrz_pair.base     = fget_next_int( fileread );
    ppip->vel_hrz_pair.rand     = fget_next_int( fileread );
    ppip->vel_vrt_pair.base      = fget_next_int( fileread );
    ppip->vel_vrt_pair.rand      = fget_next_int( fileread );

    // Continuous spawning of other particles
    ppip->contspawn_delay      = fget_next_int( fileread );
    ppip->contspawn_amount    = fget_next_int( fileread );
    ppip->contspawn_facingadd = fget_next_int( fileread );
    ppip->contspawn_lpip       = fget_next_int( fileread );

    // End spawning of other particles
    ppip->endspawn_amount    = fget_next_int( fileread );
    ppip->endspawn_facingadd = fget_next_int( fileread );
    ppip->endspawn_lpip       = fget_next_int( fileread );

    // Bump spawning of attached particles
    ppip->bumpspawn_amount = fget_next_int( fileread );
    ppip->bumpspawn_lpip    = fget_next_int( fileread );

    // Random stuff  !!!BAD!!! Not complete
    ppip->daze_time    = fget_next_int( fileread );
    ppip->grog_time    = fget_next_int( fileread );
    ppip->spawnenchant = fget_next_bool( fileread );

    ppip->cause_roll    = fget_next_bool( fileread );  // !!Cause roll
    ppip->cause_pancake = fget_next_bool( fileread );

    ppip->needtarget         = fget_next_bool( fileread );
    ppip->targetcaster       = fget_next_bool( fileread );
    ppip->startontarget      = fget_next_bool( fileread );
    ppip->onlydamagefriendly = fget_next_bool( fileread );

    ppip->soundspawn = fget_next_int( fileread );

    ppip->end_sound = fget_next_int( fileread );

    ppip->friendlyfire = fget_next_bool( fileread );

    ppip->hateonly = fget_next_bool( fileread );

    ppip->newtargetonspawn = fget_next_bool( fileread );

    ppip->targetangle = fget_next_int( fileread ) >> 1;
    ppip->homing      = fget_next_bool( fileread );

    ppip->homingfriction = fget_next_float( fileread );
    ppip->homingaccel    = fget_next_float( fileread );
    ppip->rotatetoface   = fget_next_bool( fileread );

    goto_colon( NULL, fileread, bfalse );  // !!Respawn on hit is unused

    ppip->manadrain         = fget_next_int( fileread ) * 256;
    ppip->lifedrain         = fget_next_int( fileread ) * 256;

    // assume default end_wall
    ppip->end_wall = ppip->end_ground;

    // assume default damfx
    if ( ppip->homing )  ppip->damfx = DAMFX_NONE;

    // Read expansions
    while ( goto_colon( NULL, fileread, btrue ) )
    {
        idsz = fget_idsz( fileread );

        if ( idsz == MAKE_IDSZ( 'T', 'U', 'R', 'N' ) )       SET_BIT( ppip->damfx, DAMFX_NONE );        //ZF> This line doesnt do anything?
        else if ( idsz == MAKE_IDSZ( 'A', 'R', 'M', 'O' ) )  SET_BIT( ppip->damfx, DAMFX_ARMO );
        else if ( idsz == MAKE_IDSZ( 'B', 'L', 'O', 'C' ) )  SET_BIT( ppip->damfx, DAMFX_NBLOC );
        else if ( idsz == MAKE_IDSZ( 'A', 'R', 'R', 'O' ) )  SET_BIT( ppip->damfx, DAMFX_ARRO );
        else if ( idsz == MAKE_IDSZ( 'T', 'I', 'M', 'E' ) )  SET_BIT( ppip->damfx, DAMFX_TIME );
        else if ( idsz == MAKE_IDSZ( 'Z', 'S', 'P', 'D' ) )  ppip->zaimspd = fget_float( fileread );
        else if ( idsz == MAKE_IDSZ( 'F', 'S', 'N', 'D' ) )  ppip->end_sound_floor = fget_int( fileread );
        else if ( idsz == MAKE_IDSZ( 'W', 'S', 'N', 'D' ) )  ppip->end_sound_wall = fget_int( fileread );
        else if ( idsz == MAKE_IDSZ( 'W', 'E', 'N', 'D' ) )  ppip->end_wall = ( 0 != fget_int( fileread ) );
        else if ( idsz == MAKE_IDSZ( 'P', 'U', 'S', 'H' ) )  ppip->allowpush = ( 0 != fget_int( fileread ) );
        else if ( idsz == MAKE_IDSZ( 'D', 'L', 'E', 'V' ) )  ppip->dynalight.level_add = fget_int( fileread ) / 1000.0f;
        else if ( idsz == MAKE_IDSZ( 'D', 'R', 'A', 'D' ) )  ppip->dynalight.falloff_add = fget_int( fileread ) / 1000.0f;
        else if ( idsz == MAKE_IDSZ( 'I', 'D', 'A', 'M' ) )  ppip->intdamagebonus = ( 0 != fget_int( fileread ) );
        else if ( idsz == MAKE_IDSZ( 'W', 'D', 'A', 'M' ) )  ppip->wisdamagebonus = ( 0 != fget_int( fileread ) );
        else if ( idsz == MAKE_IDSZ( 'O', 'R', 'N', 'T' ) )
        {
            char cTmp = fget_first_letter( fileread );
            switch ( toupper( cTmp ) )
            {
                case 'X': ppip->orientation = ORIENTATION_X; break;  // put particle up along the world or body-fixed x-axis
                case 'Y': ppip->orientation = ORIENTATION_Y; break;  // put particle up along the world or body-fixed y-axis
                case 'Z': ppip->orientation = ORIENTATION_Z; break;  // put particle up along the world or body-fixed z-axis
                case 'V': ppip->orientation = ORIENTATION_V; break;  // vertical, like a candle
                case 'H': ppip->orientation = ORIENTATION_H; break;  // horizontal, like a plate
                case 'B': ppip->orientation = ORIENTATION_B; break;  // billboard
            }
        }
    }

    vfs_close( fileread );

    return ppip;
}
예제 #3
0
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
mod_file_t * module_load_info_vfs( const char * szLoadName, mod_file_t * pmod )
{
    /// @details BB@> this function actually reads in the module data

    vfs_FILE * fileread;
    int cnt;
    char cTmp;

    // clear all the module info
    if ( NULL == pmod ) return NULL;

    memset( pmod, 0, sizeof( *pmod ) );

    // see if we can open the file
    fileread = vfs_openRead( szLoadName );
    if ( NULL == fileread ) return NULL;

    // Read basic data
    fget_next_name( fileread, pmod->longname, sizeof( pmod->longname ) );
    fget_next_string( fileread, pmod->reference, SDL_arraysize( pmod->reference ) );
    pmod->unlockquest.id    = fget_next_idsz( fileread );
    pmod->unlockquest.level = fget_int( fileread );

    pmod->importamount = fget_next_int( fileread );
    pmod->allowexport  = fget_next_bool( fileread );
    pmod->minplayers   = fget_next_int( fileread );
    pmod->maxplayers   = fget_next_int( fileread );

    cTmp = fget_next_char( fileread );
    if ( 'T' == toupper( cTmp ) )  pmod->respawnvalid = btrue;
    if ( 'A' == toupper( cTmp ) )  pmod->respawnvalid = RESPAWN_ANYTIME;

    fget_next_char( fileread );
    pmod->rtscontrol = bfalse;        //< depecrated, not in use

    fget_next_string( fileread, pmod->rank, SDL_arraysize( pmod->rank ) );
    str_trim( pmod->rank );

    // convert the special ranks of "unranked" or "-" ("rank 0") to an empty string
    if ( 0 == strncmp( pmod->rank, "-", RANKSIZE ) )
    {
        pmod->rank[0] = CSTR_END;
    }
    else if ( 'U' == toupper( pmod->rank[0] ) )
    {
        pmod->rank[0] = CSTR_END;
    }
    pmod->rank[RANKSIZE-1] = CSTR_END;

    // Read the summary
    for ( cnt = 0; cnt < SUMMARYLINES; cnt++ )
    {
        // load the string
        fget_next_string( fileread,  pmod->summary[cnt], SDL_arraysize( pmod->summary[cnt] ) );
        pmod->summary[cnt][SUMMARYSIZE-1] = CSTR_END;

        // remove the '_' characters
        str_decode( pmod->summary[cnt], SDL_arraysize( pmod->summary[cnt] ), pmod->summary[cnt] );
    }

    // Assume default module type as a sidequest
    pmod->moduletype = FILTER_SIDE;

    // Read expansions
    while ( goto_colon( NULL, fileread, btrue ) )
    {
        IDSZ idsz = fget_idsz( fileread );

        // Read module type
        if ( idsz == MAKE_IDSZ( 'T', 'Y', 'P', 'E' ) )
        {
            // grab the expansion value
            cTmp = fget_first_letter( fileread );

            // parse the expansion value
            if ( 'M' == toupper( cTmp ) )  pmod->moduletype = FILTER_MAIN;
            else if ( 'S' == toupper( cTmp ) )  pmod->moduletype = FILTER_SIDE;
            else if ( 'T' == toupper( cTmp ) )  pmod->moduletype = FILTER_TOWN;
            else if ( 'F' == toupper( cTmp ) )  pmod->moduletype = FILTER_FUN;
            else if ( 'S' == toupper( cTmp ) )  pmod->moduletype = FILTER_STARTER;
        }
        else if ( idsz == MAKE_IDSZ( 'B', 'E', 'A', 'T' ) )
        {
            pmod->beaten = btrue;
        }
    }

    vfs_close( fileread );

    return pmod;
}