void Level::MenuTick(double deltaTime) { switch (m_GameMenu->GetSelection()) { case GameMenu::SelectionState::NONE: m_GameMenu->Tick(deltaTime); break; case GameMenu::SelectionState::RESUME: DeleteResource(m_GameMenu); SetActive(true); m_LevelState = LevelState::PLAYING; break; case GameMenu::SelectionState::SAVE: { std::wstring path = SaveGames::SAVEGAMES_DIRECTORY_PATH + m_GameMenu->GetSaveName() + L".xml"; SaveToFile(path, true); m_LastSaveConfigPath = path; std::wstring date = current_date(DATE_FORMAT); // Create a save game entry SaveGameEntry entry; entry.name = m_GameMenu->GetSaveName(); entry.file = path; entry.date = date; entry.level = m_LevelName; SAVEGAMES_MANAGER->AddSaveGameEntry(entry); SAVEGAMES_MANAGER->SaveToFile(); } m_GameMenu->Reset(); break; case GameMenu::SelectionState::LOAD: // Load the latest saved game of the level Singleton<StreetJustice911>::GetInstance()->LoadLevel(m_LastSaveConfigPath); break; case GameMenu::SelectionState::RESET: // Reset the level with the standard configuration Singleton<StreetJustice911>::GetInstance()->LoadLevel(m_StandardConfigPath); break; case GameMenu::SelectionState::EXIT: DeleteResource(m_GameMenu); { StreetJustice911* game = Singleton<StreetJustice911>::GetInstance(); game->QuitGame(); } break; } }
void Level::GameTick(double deltaTime) { // Tick score m_ScorePtr->Tick(deltaTime); // Tick player if (m_PlayerPtr != nullptr) { m_PlayerPtr->Tick(deltaTime); } // Tick enemies // The vector for enemies is done using a size_t iterator, because in the rare case that an // enemy kills another enemy, they remove each other from the list, causing a crash at this point for (size_t i = 0; i < m_EnemyPtrs.size(); ++i) { m_EnemyPtrs[i]->Tick(deltaTime); } /*for (std::vector<Enemy*>::iterator it = m_EnemyPtrs.begin(); it != m_EnemyPtrs.end(); ++it) { (*it)->Tick(deltaTime); }*/ // Tick Hostages for (std::vector<Hostage*>::iterator it = m_HostagePtrs.begin(); it != m_HostagePtrs.end(); ++it) { (*it)->Tick(deltaTime); } // Tick pickups for (std::vector<Pickup*>::iterator it = m_PickupPtrs.begin(); it != m_PickupPtrs.end(); ++it) { (*it)->Tick(deltaTime); } // Tick killed avatars for (std::vector<KilledAvatar*>::iterator it = m_KilledAvatars.begin(); it != m_KilledAvatars.end(); ++it) { (*it)->Tick(deltaTime); } m_HUD->Tick(deltaTime); // Delete all scheduled avatars and replace them with a sprite for (std::vector<Avatar*>::iterator it = m_KilledAvatarsScheduled.begin(); it != m_KilledAvatarsScheduled.end(); ++it) { DeleteResource(*it); } m_KilledAvatarsScheduled.clear(); if ((m_EndZonePtr != nullptr) && m_EndZonePtr->IsPlayerInZone()) { m_LevelState = LevelState::COMPLETED; SetActive(false); } }
void Release() { DeleteResource(eFunc_DelProg, uProgramLogo); DeleteResource(eFunc_DelShader, uFragmentShaderLogo); DeleteResource(eFunc_DelShader, uVertexShaderLogo); DeleteResource(eFunc_DelProg, uProgramLogo); DeleteResource(eFunc_DelShader, uFragmentShaderLogo); DeleteResource(eFunc_DelShader, uVertexShaderLogo); DeleteResource(eFunc_DelTex, uTextureIMGLogo); DeleteResource(eFunc_DelTex, uTexturePowerVRLogo); }
CachedResource_ptr ImplResourceLoader<Material>::operator()() { Material_ptr ptr(MemoryManager_NEW Material(_context.gfx(), _cache, _loadingDescriptorHash, _descriptor.resourceName()), DeleteResource(_cache)); assert(ptr != nullptr); if (!load(ptr, _descriptor.onLoadCallback())) { ptr.reset(); } else { ptr->setHardwareSkinning(_descriptor.getEnumValue() == to_base(Object3D::ObjectFlag::OBJECT_FLAG_SKINNED)); } return ptr; }
Weapon::~Weapon() { if (m_HitRegionPtr != nullptr) { m_HitRegionPtr->RemoveContactListener(this); } DeleteResource(m_HitRegionPtr); m_TargetPtrs.clear(); // Remove the weapons from all weapon instances m_WeaponInstances.remove(this); }
/////////////////////////////////////////////////////////////////////////////// /// \brief /// Performs the specified operation. /// void MgdResourcePackageLoader::PerformOperation(const MgOperationInfo& opInfo) { MG_RESOURCE_SERVICE_TRY() CREFSTRING opName = opInfo.GetName(); if (MgdOperationName::UpdateRepository == opName) { UpdateRepository(opInfo); } else if (MgdOperationName::SetResource == opName) { SetResource(opInfo); } else if (MgdOperationName::DeleteResource == opName) { DeleteResource(opInfo); } else if (MgdOperationName::MoveResource == opName) { MoveResource(opInfo); } else if (MgdOperationName::CopyResource == opName) { CopyResource(opInfo); } else if (MgdOperationName::ChangeResourceOwner == opName) { ChangeResourceOwner(opInfo); } else if (MgdOperationName::InheritPermissionsFrom == opName) { InheritPermissionsFrom(opInfo); } else if (MgdOperationName::SetResourceData == opName) { SetResourceData(opInfo); } else if (MgdOperationName::DeleteResourceData == opName) { DeleteResourceData(opInfo); } else if (MgdOperationName::RenameResourceData == opName) { RenameResourceData(opInfo); } MG_RESOURCE_SERVICE_CATCH_AND_THROW(L"MgdResourcePackageLoader.PerformOperation") }
virtual bool OnPopup(long Id) { if ( Id == EditOpenId ) { m_Resource->EditOpen(); return true; } if ( Id == EditCloseId ) { m_Resource->EditClose(); return true; } if ( Id == DeleteId ) { DeleteResource(); return true; } return m_Resource->OnPopupMenu(Id); }
// pass resFile as -1 to use the current file OSErr BetterAddResource(short resFile,Handle theData,ResType type,short *id,StringPtr name,short mode) { short oldResFile=::CurResFile(); OSErr err=noErr; if (resFile!=-1) UseResFile(resFile); // If this resource exists then we may have some problems if (ResourceExists(-1,type,*id)) { switch (mode) { case kOverwriteResource: if (!DeleteResource(-1,type,*id)) err=rmvResFailed; break; case kUniqueID: *id=Unique1ID(type); break; case kBottleIt: err=userCanceledErr; break; } } if (!err) { // Now there is space for the resource lets add it AddResource(theData,type,*id,name ? name:"\p"); err=ResError(); if (err==noErr) { WriteResource(theData); err=ResError(); } }
void Level::ObjectivePaint() { GAME_ENGINE->SetWorldMatrix(MATRIX3X2::CreateIdentityMatrix()); GAME_ENGINE->SetColor(COLOR(0, 0, 0, (int)(255.0 * m_FadeTimer / LEVEL_FADE_TIMER))); GAME_ENGINE->FillRect(DOUBLE2(0, 0), DOUBLE2(GAME_ENGINE->GetWidth(), GAME_ENGINE->GetHeight())); if (m_FadeTimer == LEVEL_FADE_TIMER) { Font* font = new Font(String("Arial"), 16); GAME_ENGINE->SetColor(COLOR(255, 255, 255)); GAME_ENGINE->SetFont(font); GAME_ENGINE->DrawString(String("Press 'ENTER' to continue"), DOUBLE2(10, GAME_ENGINE->GetHeight() - 50)); GAME_ENGINE->SetDefaultFont(); DeleteResource(font); if (m_ImgIntroPtr != nullptr) { DOUBLE2 pos((GAME_ENGINE->GetWidth() - m_ImgIntroPtr->GetWidth()) / 2.0, (GAME_ENGINE->GetHeight() - m_ImgIntroPtr->GetHeight()) / 2.0); GAME_ENGINE->DrawBitmap(m_ImgIntroPtr, pos); } } }
/** * Entity handler callback that fills the resPayload of the entityHandlerRequest. */ OCEntityHandlerResult PluginInterfaceEntityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest, void* callbackParam) { if (!entityHandlerRequest) { OIC_LOG (ERROR, TAG, "Invalid request pointer"); return OC_EH_ERROR; } OCEntityHandlerResult ehResult = OC_EH_ERROR; OCStackResult result = OC_STACK_ERROR; PIPluginBase * plugin = (PIPluginBase *) callbackParam; OCEntityHandlerResponse * response = (OCEntityHandlerResponse *) OICCalloc(1, sizeof(*response)); if (!response) { return OC_EH_ERROR; } OCRepPayload* payload = (OCRepPayload *) entityHandlerRequest->payload; if (flag & OC_REQUEST_FLAG) { if (plugin->processEHRequest) { ehResult = plugin->processEHRequest(plugin, entityHandlerRequest, &payload); } } // If the result isn't an error or forbidden, send response if (!((ehResult == OC_EH_ERROR) || (ehResult == OC_EH_FORBIDDEN))) { // Format the response. Note this requires some info about the request response->requestHandle = entityHandlerRequest->requestHandle; response->resourceHandle = entityHandlerRequest->resource; response->ehResult = ehResult; response->payload = (OCPayload*) payload; // Indicate that response is NOT in a persistent buffer response->persistentBufferFlag = 0; result = OCDoResponse(response); if (result != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "Error sending response %u", result); ehResult = OC_EH_ERROR; } } else { OIC_LOG_V(ERROR, TAG, "Error handling request %u", ehResult); PIResource * piResource = NULL; result = GetResourceFromHandle(plugin, &piResource, response->resourceHandle); OIC_LOG_V(ERROR, TAG, "Deleting resource \"%s\" because of failed request.", piResource->uri); result = DeleteResource(plugin, piResource); if(result != OC_STACK_OK) { OIC_LOG_V(ERROR, TAG, "Failed to delete resource after failed request."); ehResult = OC_EH_ERROR; } } OCPayloadDestroy(response->payload); OICFree(response); return ehResult; }
Level::~Level() { DeleteResource(m_ActorLayoutPtr); DeleteResource(m_ImgVisualsPtr); DeleteResource(m_ImgShadowsPtr); DeleteResource(m_ImgIntroPtr); DeleteResource(m_PlayerPtr); DeleteResource(m_CameraPtr); DeleteResource(m_HUD); DeleteResource(m_DoorPtrs); DeleteResource(m_EnemyPtrs); DeleteResource(m_HostagePtrs); DeleteResource(m_PickupPtrs); DeleteResource(m_KilledAvatarsScheduled); DeleteResource(m_KilledAvatars); DeleteResource(m_ScorePtr); DeleteResource(m_EndZonePtr); DeleteResource(m_GameMenu); m_NavigationGrid.clear(); }
void Level::ParseLevelConfig(std::wstring fileName) { XMLParser* parser = new XMLParser(); parser->LoadFile(fileName); while (parser->Parse(L"Level")) { // Skip the tag if its not an opening tag. if (parser->GetTagType() != XMLParser::OPENING) { continue; } // Read the tag if its an opening tag std::wstring tagName = parser->GetTagName(); std::wstring tagContent = parser->GetTagContent(); if (tagName.compare(L"ID") == 0) { m_LevelName = tagContent; } else if (tagName.compare(L"StandardConfig") == 0) { m_StandardConfigPath = tagContent; } else if (tagName.compare(L"SVG") == 0) { m_SVGPath = tagContent; m_ActorLayoutPtr->AddSVGShape(String(m_SVGPath.c_str())); } else if (tagName.compare(L"Visuals") == 0) { m_VisualsPath = tagContent; m_ImgVisualsPtr = new Bitmap(String(m_VisualsPath.c_str())); // Add a polygonal shape around the level std::vector<DOUBLE2> levelBoundaries(4); levelBoundaries[0] = DOUBLE2(0, 0); levelBoundaries[1] = DOUBLE2(0, m_ImgVisualsPtr->GetHeight()); levelBoundaries[2] = DOUBLE2(m_ImgVisualsPtr->GetWidth(), m_ImgVisualsPtr->GetHeight()); levelBoundaries[3] = DOUBLE2(m_ImgVisualsPtr->GetWidth(), 0); m_ActorLayoutPtr->AddChainShape(levelBoundaries, true); } else if (tagName.compare(L"Shadows") == 0) { m_ShadowsPath = tagContent; m_ImgShadowsPtr = new Bitmap(String(m_ShadowsPath.c_str())); } else if (tagName.compare(L"Navigation") == 0) { // Loads an image that is converted and used a navigation grid m_NavigationPath = tagContent; Bitmap* navigationImg = new Bitmap(String(m_NavigationPath.c_str())); // Create a navigation grid for the pathfinding algorithm. std::vector<std::vector<COLOR>> rawPixelData = navigationImg->GetRawPixelData(); m_NavigationGrid = std::vector<std::vector<bool>>(navigationImg->GetHeight(), std::vector<bool>(navigationImg->GetWidth())); for (int i = 0; i < navigationImg->GetHeight(); ++i) { for (int j = 0; j < navigationImg->GetWidth(); ++j) { COLOR color = rawPixelData[i][j]; int avarageValue = (color.red + color.green + color.blue) / 3; if (avarageValue < 128) { m_NavigationGrid[i][j] = false; } else { m_NavigationGrid[i][j] = true; } } rawPixelData[i].clear(); } rawPixelData.clear(); delete navigationImg; } else if (tagName.compare(L"Objective") == 0) { m_ObjectivePath = tagContent; m_ImgIntroPtr = new Bitmap(String(m_ObjectivePath.c_str())); } else if (tagName.compare(L"AudioMainMusic") == 0) { m_AudioMainMusic = tagContent; } else if (tagName.compare(L"AudioCompletedMusic") == 0) { m_AudioCompletedMusic = tagContent; } else if (tagName.compare(L"AudioCompletedEffect") == 0) { m_AudioCompletedEffect = tagContent; } else if (tagName.compare(L"EndZone") == 0) { if (m_EndZonePtr != nullptr) { DeleteResource(m_EndZonePtr); } m_EndZonePtr = new LevelEndZone(parser); m_EndZonePtr->SetActive(false); } else if (tagName.compare(L"Score") == 0) { if (m_ScorePtr != nullptr) { DeleteResource(m_ScorePtr); } m_ScorePtr = new LevelScore(parser); } else if (tagName.compare(L"TargetTime") == 0) { m_TargetCompletionTime = std::stod(tagContent); } else if (tagName.compare(L"Door") == 0) { m_DoorPtrs.push_back(new Door(parser)); } else if (tagName.compare(L"Pickup") == 0) { m_PickupPtrs.push_back(new Pickup(parser)); } else if (tagName.compare(L"Enemies") == 0) { // Sub-parsing level. // Per enemy type (a patrolling or stationary unit) while (parser->Parse(L"Enemies")) { if (parser->GetTagType() != XMLParser::OPENING) { continue; } tagName = parser->GetTagName(); if (tagName.compare(L"Patrol") == 0) { m_EnemyPtrs.push_back(new PatrollingEnemy(parser)); } else if (tagName.compare(L"Guard") == 0) { m_EnemyPtrs.push_back(new GuardingEnemy(parser)); } } } else if (tagName.compare(L"Hostages") == 0) { // Sub-level parsing for hostages while (parser->Parse(L"Hostages")) { if (parser->GetTagType() != XMLParser::OPENING) { continue; } tagName = parser->GetTagName(); if (tagName.compare(L"Hostage") == 0) { m_HostagePtrs.push_back(new Hostage(parser)); } } } else if (tagName.compare(L"Player") == 0) { m_PlayerPtr = new Player(parser); m_CameraPtr = new Camera(m_PlayerPtr); m_CameraPtr->Tick(0.0); m_HUD->SetTarget(m_PlayerPtr); } } delete parser; }