All pastes #626203 Raw Edit

binary reading

public text v1 · immutable
·published 2007-07-19 14:03 UTC
rendered paste body
bool CMapDataManager::read(stringc name, EMAPDATATYPE type)
{
    ifstream file;
    file.open(name.c_str(), ios::in | ios::binary);

    if(!file.is_open())
        return false;

    file.read((char*)&mapData[type]->size.Width, sizeof(u32));
    file.read((char*)&mapData[type]->size.Height, sizeof(u32));

    mapData[type]->tiles = new EMAPTILETYPE[mapData[type]->size.Width * mapData[type]->size.Height];

    for(u32 w = 0; w < mapData[type]->size.Width; w++)
    {
        for(u32 h = 0; h < mapData[type]->size.Height; h++)
        {
            file.read((char*) &mapData[type]->tiles[(w * mapData[type]->size.Height) + h], sizeof(c8));
        }
    }
    return true;
}