bool plDynamicTextMap::IIsValid( void ) { if( GetImage() == nil && fHasCreateBeenCalled ) { // we are going to allocate the fImage at this point... when someone is looking for it fImage = (void *)IAllocateOSSurface( (uint16_t)fWidth, (uint16_t)fHeight ); hsColorRGBA color; if( fInitBuffer != nil ) { IClearFromBuffer( fInitBuffer ); } else { color.Set( 0.f, 0.f, 0.f, 1.f ); ClearToColor( color ); FlushToHost(); } IBuildLevelSizes(); fTotalSize = GetLevelSize( 0 ); SetCurrLevel( 0 ); // Destroy the old texture ref, if we have one. This should force the // pipeline to recreate one more suitable for our use SetDeviceRef( nil ); plProfile_NewMem(MemMipmaps, fTotalSize); plProfile_NewMem(DynaTextMem, fTotalSize); #ifdef MEMORY_LEAK_TRACER IAddToMemRecord( this, plRecord::kViaCreate ); #endif } if( GetImage() == nil ) return false; return true;//fWriter->IsValid(); }
void plDynamicTextMap::Create( uint32_t width, uint32_t height, bool hasAlpha, uint32_t extraWidth, uint32_t extraHeight ) { SetConfig( hasAlpha ? kARGB32Config : kRGB32Config ); fVisWidth = (uint16_t)width; fVisHeight = (uint16_t)height; fHasAlpha = hasAlpha; for( fWidth = 1; fWidth < width + extraWidth; fWidth <<= 1 ); for( fHeight = 1; fHeight < height + extraHeight; fHeight <<= 1 ); // instead of allocating the fImage here, we'll wait for the first draw operation to be called (in IIsValid) fHasCreateBeenCalled = true; fRowBytes = fWidth << 2; fNumLevels = 1; fFlags |= plMipmap::kDontThrowAwayImage | plMipmap::kAutoGenMipmap; fCompressionType = plMipmap::kUncompressed; fUncompressedInfo.fType = plMipmap::UncompressedInfo::kRGB8888; // Destroy the old texture ref, if we have one. This should force the // pipeline to recreate one more suitable for our use SetDeviceRef( nil ); // Some init color SetFont( "Arial", 12 ); hsColorRGBA color; color.Set( 0,0,1,1); SetTextColor( color ); SetCurrLevel( 0 ); plProfile_Inc(DynaTexts); }
// allow the user of the DynaTextMap that they are done with the image... for now // ... the fImage will be re-created on the next operation that requires the image void plDynamicTextMap::PurgeImage() { IDestroyOSSurface(); fTotalSize = 0; SetCurrLevel( 0 ); // Destroy the old texture ref, if we have one. This should force the // pipeline to recreate one more suitable for our use SetDeviceRef( nil ); }
void CSaveSlotState::SetSaveSlot(const int nSlot) { //if index is too low if(nSlot < 0 ) { m_nCurrSaveSlot = (MAXSLOTS - 1); SetCurrLevel(m_nLoadedLevels[m_nCurrSaveSlot]); return; } //if index is too high if(nSlot >= MAXSLOTS) { m_nCurrSaveSlot = 0; SetCurrLevel(m_nLoadedLevels[m_nCurrSaveSlot]); return; } m_nCurrSaveSlot = nSlot; SetCurrLevel(m_nLoadedLevels[m_nCurrSaveSlot]); }
void CSaveSlotState::Save() { CGamePlayState* pGamePlay = CGamePlayState::GetInstance(); SetCurrLevel(pGamePlay->GetCurrentLevel()); //save settings ofstream out; char filename[255] = {0}; int nLevel = GetCurrLevel(); sprintf_s(filename, "resource/Game Saves/Slot%d.dat", m_nCurrSaveSlot); out.open(filename, ios_base::out | ios_base::trunc | ios_base::binary); if (out.is_open()) { if (out.good()) out.write(((const char *)&nLevel), 4); out.close(); } }
void CSaveSlotState::Delete() { CGamePlayState* pGamePlay = CGamePlayState::GetInstance(); //delete settings - restart from the first level ofstream out; char filename[255] = {0}; int nLevel = 1; sprintf_s(filename, "resource/Game Saves/Slot%d.dat", m_nCurrSaveSlot); out.open(filename, ios_base::out | ios_base::trunc | ios_base::binary); if (out.is_open()) { if (out.good()) { out.write(((const char *)&nLevel), 4); } out.close(); } Load(m_nCurrSaveSlot); SetCurrLevel(nLevel); }