// // Load // // Load system data // void Load(BlockFile &bFile) { // Get the size of the block U32 size; // Open the data block bFile.OpenBlock(SAVEBLOCK, TRUE, &size); // Expected size of buffer U32 bufferSize = WorldCtrl::CellMapX() * WorldCtrl::CellMapZ(); // Check the block size if (bufferSize == size) { // Get the start of the buffer Game::TeamBitfield *ptr = (Game::TeamBitfield *)(bFile.GetBlockPtr()); // Iterate through each cell for (U32 i = 0; i < bufferSize; ++i) { // Setup the team bits for (U32 team = 0; team < teamCount; team++) { if (Game::TeamTest(*ptr, team)) { seeMap[0][team][0][i] |= SEENMASK; } } // Move to next cell ++ptr; } } else { LOG_WARN(("Sight: Save block was unexpected size (%d/%d)", size, bufferSize)); } // Done bFile.CloseBlock(); // Ensure display gets updated for new data DirtyAllCells(); }
// // Save // // Save system data // void Save(BlockFile &bFile) { // Size of required buffer U32 bufferSize = WorldCtrl::CellMapX() * WorldCtrl::CellMapZ(); // Allocate a buffer Game::TeamBitfield *buffer = new Game::TeamBitfield[bufferSize]; Game::TeamBitfield *ptr = buffer; // Iterate the seen map for (U32 i = 0; i < bufferSize; ++i) { // Clear the data for this cell *ptr = 0; // Now set a bit for each team that has seen this cell for (U32 team = 0; team < teamCount; team++) { if (seeMap[0][team][0][i] & SEENMASK) { Game::TeamSet(*ptr, team); } } // Move to next cell ++ptr; } // Save the buffer to the blockfile bFile.OpenBlock(SAVEBLOCK); bFile.WriteToBlock(buffer, bufferSize * sizeof(Game::TeamBitfield)); bFile.CloseBlock(); // Free up the buffer delete [] buffer; }