//[-------------------------------------------------------] //[ Protected virtual PLScene::SceneApplication functions ] //[-------------------------------------------------------] void EngineApplication::OnCreateRootScene() { // Get the scene context SceneContext *pSceneContext = GetSceneContext(); if (pSceneContext) { // First, create the scene root container which holds the scene container with our 'concrete' scene within it SceneContainer *pRootContainer = pSceneContext->GetRoot() ? static_cast<SceneContainer*>(pSceneContext->GetRoot()->Create("PLScene::SceneContainer", "RootScene")) : nullptr; if (pRootContainer) { // Protect this important container! pRootContainer->SetProtected(true); // Create a scene container with our 'concrete scene' SceneNode *pSceneContainerNode = pRootContainer->Create("PLScene::SceneContainer", "Scene"); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Connect event handler if (pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) static_cast<SceneContainer*>(pSceneContainerNode)->SignalLoadProgress.Connect(EventHandlerLoadProgress); // Create the 'concrete scene' OnCreateScene(*pSceneContainer); } // Create scene node for engine information SceneNode *pSceneNode = pRootContainer->Create("PLEngine::SNEngineInformation"); if (pSceneNode) pSceneNode->SetActive(m_bEditModeEnabled); // Create console scene node - using the console command 'timescale <value>' we // can change the scene time (slowdown or accelerate) pSceneNode = pRootContainer->Create("PLEngine::SNConsole"); if (pSceneNode && pSceneNode->GetClass()->IsDerivedFrom("PLEngine::SNConsoleBase")) { SNConsoleBase *pConsole = static_cast<SNConsoleBase*>(pSceneNode); // Register default commands pConsole->RegisterCommand(0, "quit", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "exit", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "bye", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); pConsole->RegisterCommand(0, "logout", "", "", Functor<void, ConsoleCommand &>(&EngineApplication::ConsoleCommandQuit, this)); // Set active state pConsole->SetActive(m_bEditModeEnabled); } } // Set the root scene SetRootScene(pRootContainer); } }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application67::OnCreateScene(SceneContainer &cContainer) { // Create a scene container with our 'concrete sound scene' using the default sound API SceneNode *pSceneContainerNode = cContainer.Create("PLSound::SCSound", "SoundScene"); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Populate the scene container // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(pSceneContainer); // Get the scene context SceneContext *pSceneContext = GetSceneContext(); if (pSceneContext) { // Create us a scene renderer SceneRenderer *pSceneRenderer = pSceneContext->GetSceneRendererManager().Create("2DGame"); if (pSceneRenderer) { // Add begin scene renderer pass pSceneRenderer->Create("PLCompositing::SRPBegin", "Begin", "TextureFormat=\"R8G8B8A8\" Flags=\"Inactive\""); // Add our own scene renderer pass pSceneRenderer->Create("SRP2DGame", "2DGame"); // Add post processing scene renderer pass pSceneRenderer->Create("PLCompositing::SRPPostProcessing", "PostProcessing"); // Add end scene renderer pass pSceneRenderer->Create("PLCompositing::SRPEnd", "End"); // Make this scene renderer to the default scene renderer of our scene surface painter pSPScene->SetDefaultSceneRenderer(pSceneRenderer->GetName()); } } } // Set scene container SetScene(pSceneContainer); // Start the game Restart(); } }
/** * @brief * Function that is called to create the application's root scene */ void SceneApplication::OnCreateRootScene() { // [TODO] Load 'm_sSceneFilename' if provided // Is there a scene context? if (m_pSceneContext) { // First, create the scene root container which holds the scene container with our 'concrete' scene within it SceneContainer *pRootContainer = m_pSceneContext->GetRoot() ? static_cast<SceneContainer*>(m_pSceneContext->GetRoot()->Create("PLScene::SceneContainer", "RootScene")) : nullptr; if (pRootContainer) { // Protect this important container! pRootContainer->SetProtected(true); // Create a scene container with our 'concrete scene' SceneNode *pSceneContainerNode = pRootContainer->Create("PLScene::SceneContainer", "Scene"); if (pSceneContainerNode && pSceneContainerNode->IsContainer()) { // Protect this important container! pSceneContainerNode->SetProtected(true); } } // Set the root scene SetRootScene(pRootContainer); } }
//[-------------------------------------------------------] //[ Private virtual PLEngine::EngineApplication functions ] //[-------------------------------------------------------] void Application61::OnCreateScene(SceneContainer &cContainer) { // Set no scene container as default SetScene(nullptr); // Sound API given? if (m_sSoundAPI.GetLength()) { // Create a scene container with our 'concrete sound scene' using the chosen sound API SceneNode *pSceneContainerNode = cContainer.Create("PLSound::SCSound", "SoundScene", "SoundAPI=\"" + m_sSoundAPI + "\" Pitch=\"" + Timing::GetInstance()->GetTimeScaleFactor() + '\"'); if (pSceneContainerNode && pSceneContainerNode->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pSceneContainer = static_cast<SceneContainer*>(pSceneContainerNode); // Protect this important container! pSceneContainer->SetProtected(true); // Set scene container SetScene(pSceneContainer); // Populate the scene container // Create a camera SceneNode *pCamera = pSceneContainer->Create("PLScene::SNCamera", "FreeCamera", "Position=\"0.0 -1.5 1.4\" Rotation=\"-14.0 180.0 0.0\""); if (pCamera && pCamera->IsInstanceOf("PLScene::SNCamera")) { // Make this to our main scene camera SetCamera(reinterpret_cast<SNCamera*>(pCamera)); // Add a controller modifier so we can look around the camera by using a default control pCamera->AddModifier("PLEngine::SNMEgoLookController"); // Add a controller modifier so we can move around the camera by using a default control pCamera->AddModifier("PLEngine::SNMMoveController", "Speed=\"2\""); // Make this camera to the 'sound listener' pSceneContainer->SetAttribute("Listener", pCamera->GetName()); } // Create the floor pSceneContainer->Create("PLScene::SNMesh", "Floor", "Position=\"0.0 -2.1 -5.0\" Rotation=\"0.0 180.0 0.0\" Scale=\"4.0 0.1 4.0\" Mesh=\"Default\""); // Create a box on the floor pSceneContainer->Create("PLScene::SNMesh", "Box", "Position=\"0.0 -1.5 -5.0\" Scale=\"0.5 0.5 0.5\" Mesh=\"Default\""); // Create rain particles and rain sound pSceneContainer->Create("PLParticleGroups::PGRain", "Rain", "Position=\"0.0 15.0 -5.0\" Flags=\"ForceUpdate\" MediumSize=\"3\""); pSceneContainer->Create("PLSound::SNSound", "RainSound", "Sound=\"Data/Sounds/Rain.ogg\" Volume=\"0.2\""); // Create the soldier walking in the rain :) SceneNode *pSoldier = pSceneContainer->Create("PLScene::SNMesh", "Soldier", "Position=\"0.0 -1.5 -5.0\" Scale=\"0.007 0.007 0.007\" Mesh=\"Data/Meshes/Soldier.mesh\""); if (pSoldier) { // Add animation modifier pSoldier->AddModifier("PLScene::SNMMeshAnimation", "Name=\"walk_0\" Speed=\"2\""); // Let the soldier walk on a path... pSoldier->AddModifier("PLScene::SNMPositionPath", "Filename=\"Data/Misc/61Sound_Soldier.path\" Speed=\"0.5\" Flags=\"NodeIndexProgress\" Interpolation=\"CatmullRomCurve\""); // ... and we should look into the direction he's moving pSoldier->AddModifier("PLScene::SNMRotationMoveDirection"); // Link a footsteps sound to the soldier pSoldier->AddModifier("PLSound::SNMSound","Sound=\"Data/Sounds/Walking.ogg\""); } // Setup scene surface painter SurfacePainter *pPainter = GetPainter(); if (pPainter && pPainter->IsInstanceOf("PLScene::SPScene")) { SPScene *pSPScene = static_cast<SPScene*>(pPainter); pSPScene->SetRootContainer(cContainer.GetContainer()); pSPScene->SetSceneContainer(pSceneContainer); } // Within the parent container... SceneContainer *pContainer = pSceneContainer->GetContainer(); if (pContainer) { // Get/add our information text scene nodes SceneNode *pInfoText = pContainer->Create("PLScene::SceneContainer", "InfoText", "Flags=\"NoCulling\""); if (pInfoText && pInfoText->IsInstanceOf("PLScene::SceneContainer")) { SceneContainer *pInfoTextContainer = static_cast<SceneContainer*>(pInfoText); // The name of the used sound API pInfoTextContainer->Create("PLScene::SNText2D", "SoundAPI", "Position=\"0.01 0.01\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("Sound API: ") + GetSoundAPI() + '\"'); // Draw keys information pInfoTextContainer->Create("PLScene::SNText2D", "Keys", "Position=\"0.01 0.04\" Flags=\"No3DPosition|NoCenter\" Text=\"" + PLT("Keys:") + '\"'); pInfoTextContainer->Create("PLScene::SNText2D", "TimeScale", "Position=\"0.06 0.08\" Flags=\"No3DPosition|NoCenter\""); UpdateTimeScaleTextNode(); } } } } }