Sorry :) :oops:
Before we kill this thread, what is the dpf block type name for Sounds and Music?
Thanks in advanced!
Before we kill this thread, what is the dpf block type name for Sounds and Music?
Thanks in advanced!
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menu
// Loads (and creates) a Tileset and returns it's pointer. Returns NULL if Failed.
// You must delete the Tileset yourself when you are finished with it.
CRM32Pro_CTile* load_tileset(CRM32Pro_CTile* ptile, char* dpfname)
{
if(!sts_dpf_initialized) return NULL; // Always make sure a DPF was loaded, if not
// there's nothing here to do.
for(int i=0; i < sts_total_tilesets; ++i) // Now find dpfname in the tileset names list.
{
if(sts_tileset_names[i].compare(dpfname)==0) // If the Tileset asked for is in the array,
{ // we can begin to create that Tileset.
int dpfid = IStuffDPF->Open(sts_dpf_filename); // To get the Tileset's data, open the DPF.
if(dpfid<0) return NULL;
DPF_BlockData dpf_db; // If the data block has a size of 0 or less,
if(!IStuffDPF->LoadBlock(dpfid,"TILE2",dpfname,&dpf_db))// something went wrong and we must NULL out.
{
IStuffDPF->Close(dpfid);
return NULL;
}
SDL_Surface* tsurf = NULL; // Create some vars that will hold the data
long surf_x_size = 0; // used to create the Tileset's Surface (image),
long surf_y_size = 0; // and then to create the Tileset itself.
long pitch = 0; // sdl note: pitch is width of image in bytes
long x_off = 0;
long y_off = 0;
SDL_PixelFormat surf_pf;
int surf_pixels_size = dpf_db.size - 128;
char* surf_pixels = new char[ (surf_pixels_size) ];
// The following is a _guess_ on the methods of: how to get the data required to
// create a Tileset, and: How to, in return, create that Tileset.
/*CRM32Pro_*/ memcpy(&surf_x_size, &dpf_db.data[0], 4);
/*CRM32Pro_*/ memcpy(&surf_y_size, &dpf_db.data[4], 4);
/*CRM32Pro_*/ memcpy(&x_off, &dpf_db.data[20], 4);
/*CRM32Pro_*/ memcpy(&surf_pf, &dpf_db.data[24], 40);
pitch = surf_pf.BytesPerPixel * surf_x_size;
//pitch = surf_pixels_size / surf_y_size;
/*CRM32Pro_*/ memcpy(surf_pixels, &dpf_db.data[64], surf_pixels_size );
/*CRM32Pro_*/ memcpy(&y_off, &dpf_db.data[64 + surf_pixels_size], 4);
// Create SDL_Surface for Tileset.
tsurf = SDL_CreateRGBSurfaceFrom(surf_pixels, surf_x_size, surf_y_size, surf_pf.BitsPerPixel,
pitch, surf_pf.Rmask, surf_pf.Gmask, surf_pf.Bmask, surf_pf.Amask);
if(!tsurf) // If we failed to create the SDL_Surface for
{ // the Tileset we have to return NULL, there's
delete [] surf_pixels; // nothing else we can do to be successful.
IStuffDPF->Close(dpfid);
return NULL;
}
if(!ptile)
CRM32Pro_CTile* ptile = new CRM32Pro_CTile(); // Now we can create the Tileset, and set
ptile->Create(tsurf, dpfname); // it's data we just obtained.
ptile->SetTileSet(1, x_off, y_off); // Set Tileset flag and size per tile.
IStuffDPF->Close(dpfid);
//
// UNFREED MEMORY: (unintentional) tsurf, (unintentional) surf_pixels, (intentional) ptile
//
return ptile;
}
}
return NULL; // We've gone this far only if the Tileset
// dpfname we were searching for was not found.
}