void RuntimeScene::ManageObjectsAfterEvents() { //Delete objects that were removed. RuntimeObjList allObjects = objectsInstances.GetAllObjects(); for (std::size_t id = 0;id<allObjects.size();++id) { if ( allObjects[id]->GetName().empty() ) { for (std::size_t i = 0;i<extensionsToBeNotifiedOnObjectDeletion.size();++i) extensionsToBeNotifiedOnObjectDeletion[i]->ObjectDeletedFromScene(*this, allObjects[id].get()); objectsInstances.RemoveObject(allObjects[id]); //Remove from objects instances, not from the temporary list! } } //Update objects positions, forces and behaviors allObjects = objectsInstances.GetAllObjects(); double elapsedTime = static_cast<double>(timeManager.GetElapsedTime())/1000000.0; for (std::size_t id = 0;id<allObjects.size();++id) { allObjects[id]->SetX( allObjects[id]->GetX() + (allObjects[id]->TotalForceX() * elapsedTime)); allObjects[id]->SetY( allObjects[id]->GetY() + (allObjects[id]->TotalForceY() * elapsedTime)); allObjects[id]->UpdateTime(elapsedTime); allObjects[id]->UpdateForce(elapsedTime); allObjects[id]->DoBehaviorsPostEvents(*this); } }
bool RuntimeScene::OrderObjectsByZOrder(RuntimeObjList & objList) { if ( StandardSortMethod() ) std::sort( objList.begin(), objList.end(), [](const RuntimeObjSPtr & o1, const RuntimeObjSPtr & o2) { return o1->GetZOrder() < o2->GetZOrder(); }); else std::stable_sort( objList.begin(), objList.end(), [](const RuntimeObjSPtr & o1, const RuntimeObjSPtr & o2) { return o1->GetZOrder() < o2->GetZOrder(); }); return true; }
void GD_API MoveObjects( RuntimeScene & scene ) { RuntimeObjList allObjects = scene.objectsInstances.GetAllObjects(); for (unsigned int id = 0;id < allObjects.size();++id) { allObjects[id]->SetX( allObjects[id]->GetX() + allObjects[id]->TotalForceX() * static_cast<double>(scene.GetElapsedTime())/1000000.0 ); allObjects[id]->SetY( allObjects[id]->GetY() + allObjects[id]->TotalForceY() * static_cast<double>(scene.GetElapsedTime())/1000000.0 ); allObjects[id]->UpdateForce( static_cast<double>(scene.GetElapsedTime())/1000000.0 ); } return; }
void GD_API MoveObjects( RuntimeScene & scene ) { RuntimeObjList allObjects = scene.objectsInstances.GetAllObjects(); double elapsedTime = static_cast<double>(scene.GetTimeManager().GetElapsedTime()) / 1000000.0; for (std::size_t id = 0;id < allObjects.size();++id) { allObjects[id]->SetX(allObjects[id]->GetX() + allObjects[id]->TotalForceX() * elapsedTime); allObjects[id]->SetY(allObjects[id]->GetY() + allObjects[id]->TotalForceY() * elapsedTime); allObjects[id]->UpdateForce(elapsedTime); } return; }
void RuntimeScene::ManageObjectsBeforeEvents() { RuntimeObjList allObjects = objectsInstances.GetAllObjects(); for (std::size_t id = 0;id<allObjects.size();++id) allObjects[id]->DoBehaviorsPreEvents(*this); }
void RuntimeScene::Render() { if (!renderWindow) return; renderWindow->clear( sf::Color( GetBackgroundColorRed(), GetBackgroundColorGreen(), GetBackgroundColorBlue() ) ); //Sort object by order to render them RuntimeObjList allObjects = objectsInstances.GetAllObjects(); OrderObjectsByZOrder(allObjects); #if !defined(ANDROID) //TODO: OpenGL //To allow using OpenGL to draw: glClear(GL_DEPTH_BUFFER_BIT); // Clear the depth buffer renderWindow->pushGLStates(); #endif renderWindow->setActive(); //Draw layer by layer for (std::size_t layerIndex =0;layerIndex<layers.size();++layerIndex) { if ( layers[layerIndex].GetVisibility() ) { for (std::size_t cameraIndex = 0;cameraIndex < layers[layerIndex].GetCameraCount();++cameraIndex) { RuntimeCamera & camera = layers[layerIndex].GetCamera(cameraIndex); //Prepare OpenGL rendering #if !defined(ANDROID) //TODO: OpenGL renderWindow->popGLStates(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(GetOpenGLFOV(), camera.GetWidth()/camera.GetHeight(), GetOpenGLZNear(), GetOpenGLZFar()); #endif const sf::FloatRect & viewport = camera.GetSFMLView().getViewport(); #if !defined(ANDROID) //TODO: OpenGL glViewport(viewport.left*renderWindow->getSize().x, renderWindow->getSize().y-(viewport.top+viewport.height)*renderWindow->getSize().y, //Y start from bottom viewport.width*renderWindow->getSize().x, viewport.height*renderWindow->getSize().y); renderWindow->pushGLStates(); #endif //Prepare SFML rendering renderWindow->setView(camera.GetSFMLView()); //Rendering all objects for (std::size_t id = 0;id < allObjects.size();++id) { if (allObjects[id]->GetLayer() == layers[layerIndex].GetName()) allObjects[id]->Draw(*renderWindow); } } } } // Display window contents on screen //TODO: If nothing is displayed, double check popGLStates. #if !defined(ANDROID) //TODO: OpenGL renderWindow->popGLStates(); #endif renderWindow->display(); }
/** * Refreshing the debugger. * Automatically called by the RuntimeScene */ void DebuggerGUI::UpdateGUI() { if ( !doMAJ || !IsShown()) return; //General tab generalList->SetItem(0, 1, ToString(1000000.0/static_cast<double>(scene.GetElapsedTime()))+_(" fps")); generalList->SetItem(1, 1, ToString(static_cast<double>(scene.GetElapsedTime())/1000.0)+"ms"); generalList->SetItem(2, 1, ToString(scene.objectsInstances.GetAllObjects().size())); //TODO //generalList->SetItem(3, 1, ToString(scene.game->resourcesManager.resources.size())); generalList->SetItem(4, 1, ToString(scene.game->GetMainWindowDefaultWidth())+"*"+ToString(scene.game->GetMainWindowDefaultHeight())); generalList->SetItem(5, 1, ToString(sf::Mouse::getPosition(*scene.renderWindow).x)+";"+ToString(sf::Mouse::getPosition(*scene.renderWindow).y)); generalList->SetItem(6, 1, ToString(static_cast<double>(scene.GetTimeFromStart())/1000000.0)+"s"); //Suppression des lignes en trop pour les variables while(static_cast<unsigned int>(generalList->GetItemCount()) > generalBaseItemCount + scene.GetVariables().Count() + scene.game->GetVariables().Count()+2) generalList->DeleteItem(generalBaseItemCount); //Rajout si au contraire il n'y en a pas assez while(static_cast<unsigned int>(generalList->GetItemCount()) < generalBaseItemCount + scene.GetVariables().Count() + scene.game->GetVariables().Count()+2) generalList->InsertItem(generalBaseItemCount, ""); //Update scene variables unsigned int i = 0; const std::map < std::string, gd::Variable* > & sceneVariables = scene.GetVariables().DumpAllVariables(); for (std::map < std::string, gd::Variable* >::const_iterator it = sceneVariables.begin(); it!=sceneVariables.end();++it, ++i) { generalList->SetItem(generalBaseItemCount+i, 0, it->first); generalList->SetItem(generalBaseItemCount+i, 1, it->second->IsStructure() ? _("(Structure)") : it->second->GetString()); generalList->SetItemFont(generalBaseItemCount+i, *wxNORMAL_FONT); } //White space generalList->SetItem(generalBaseItemCount+scene.GetVariables().Count(), 0, ""); generalList->SetItem(generalBaseItemCount+scene.GetVariables().Count(), 1, ""); //Global variable title generalList->SetItem(generalBaseItemCount+scene.GetVariables().Count()+1, 0, _("Globals variables")); generalList->SetItem(generalBaseItemCount+scene.GetVariables().Count()+1, 1, ""); generalList->SetItemFont(generalBaseItemCount+scene.GetVariables().Count()+1, font); generalBaseAndVariablesItemCount = generalBaseItemCount+scene.GetVariables().Count()+2; //Update global variables i = 0; const std::map < std::string, gd::Variable* > & gameVariables = scene.game->GetVariables().DumpAllVariables(); for (std::map < std::string, gd::Variable* >::const_iterator it = gameVariables.begin(); it!=gameVariables.end();++it, ++i) { generalList->SetItem(generalBaseAndVariablesItemCount+i, 0, it->first); generalList->SetItem(generalBaseAndVariablesItemCount+i, 1, it->second->IsStructure() ? _("(Structure)") : it->second->GetString()); generalList->SetItemFont(generalBaseAndVariablesItemCount+i, *wxNORMAL_FONT); } //Extensions tab unsigned int extListCtrlId = 0; for (unsigned int i = 0;i<scene.game->GetUsedExtensions().size();++i) { boost::shared_ptr<gd::PlatformExtension> gdExtension = CppPlatform::Get().GetExtension(scene.game->GetUsedExtensions()[i]); boost::shared_ptr<ExtensionBase> extension = boost::dynamic_pointer_cast<ExtensionBase>(gdExtension); if ( extension != boost::shared_ptr<ExtensionBase>() && extension->HasDebuggingProperties() && extListCtrlId < extensionsListCtrls.size() ) { //Update items count while(static_cast<unsigned int>(extensionsListCtrls[extListCtrlId]->GetItemCount()) > extension->GetNumberOfProperties(scene)) extensionsListCtrls[extListCtrlId]->DeleteItem(0); while(static_cast<unsigned int>(extensionsListCtrls[extListCtrlId]->GetItemCount()) < extension->GetNumberOfProperties(scene)) extensionsListCtrls[extListCtrlId]->InsertItem(0, ""); //Update properties for (unsigned int propertyNb = 0;propertyNb<extension->GetNumberOfProperties(scene);++propertyNb) { std::string name, value; extension->GetPropertyForDebugger(scene, propertyNb, name, value); extensionsListCtrls[extListCtrlId]->SetItem(propertyNb, 0, name); extensionsListCtrls[extListCtrlId]->SetItem(propertyNb, 1, value); } extListCtrlId++; } } //Arbre des objets : Création des objets if ( mustRecreateTree ) { objectsTree->DeleteAllItems(); objectsTree->AddRoot(_("objects")); objectsInTree.clear(); initialObjects.clear(); mustRecreateTree = false; //Scene's objects for(unsigned int i = 0;i<scene.GetObjects().size();++i) { wxTreeItemId objectItem = objectsTree->AppendItem(objectsTree->GetRootItem(), scene.GetObjects()[i]->GetName()); initialObjects[scene.GetObjects()[i]->GetName()] = objectItem; } //Globals objects for(unsigned int i = 0;i<scene.game->GetObjects().size();++i) { wxTreeItemId objectItem = objectsTree->AppendItem(objectsTree->GetRootItem(), scene.game->GetObjects()[i]->GetName()); initialObjects[scene.game->GetObjects()[i]->GetName()] = objectItem; } objectsTree->ExpandAll(); } //Ajout des objets RuntimeObjList allObjects = scene.objectsInstances.GetAllObjects(); for(unsigned int i = 0;i<allObjects.size();++i) { boost::weak_ptr<RuntimeObject> weakPtrToObject = allObjects[i]; //L'objet n'est pas dans l'arbre : on l'ajoute if ( objectsInTree.find(weakPtrToObject) == objectsInTree.end() ) { char str[24]; snprintf(str, 24, "%p", allObjects[i].get()); wxTreeItemId objectItem = objectsTree->AppendItem(initialObjects[allObjects[i]->GetName()], str); objectsInTree[weakPtrToObject] = pair<string, wxTreeItemId>(allObjects[i]->GetName(), objectItem); } else { //Si l'objet qui est dans l'arbre n'est pas le même, on le supprime et le reajoute au bon endroit if ( objectsInTree[weakPtrToObject].first != allObjects[i]->GetName() && initialObjects.find(allObjects[i]->GetName()) != initialObjects.end() ) { objectsTree->Delete(objectsInTree[weakPtrToObject].second); wxTreeItemId objectItem = objectsTree->AppendItem(initialObjects[allObjects[i]->GetName()], ToString(i)); objectsInTree[weakPtrToObject] = pair<string, wxTreeItemId>(allObjects[i]->GetName(), objectItem); } } } //Suppression des élements en trop map < boost::weak_ptr<RuntimeObject>, pair<string, wxTreeItemId> >::iterator objectsInTreeIter = objectsInTree.begin(); map < boost::weak_ptr<RuntimeObject>, pair<string, wxTreeItemId> >::const_iterator objectsInTreeEnd = objectsInTree.end(); while(objectsInTreeIter != objectsInTreeEnd) { if ( (*objectsInTreeIter).first.expired() ) { objectsTree->Delete((*objectsInTreeIter).second.second); //Delete from the tree objectsInTree.erase(objectsInTreeIter++); //Post increment is important. It increment the iterator and then return the *original* iterator. //( Erasing an value does not invalidate any iterator except the deleted one ) } else ++objectsInTreeIter; } //Obtain the shared_ptr to the selected object if ( !objectsTree->GetSelection().IsOk() ) return; RuntimeObjSPtr object = boost::shared_ptr<RuntimeObject>(); map < boost::weak_ptr<RuntimeObject>, pair<string, wxTreeItemId> >::const_iterator end = objectsInTree.end(); for (map < boost::weak_ptr<RuntimeObject>, pair<string, wxTreeItemId> >::iterator i = objectsInTree.begin();i != end;++i) { if ( i->second.second == objectsTree->GetSelection() && !i->first.expired()) { object = i->first.lock(); continue; } } if ( object == boost::shared_ptr<RuntimeObject>() ) return; objectName->SetLabel(object->GetName()); //Object selected has changed, recreate the enitre table. if ( objectChanged ) RecreateListForObject(object); string value, uselessName; unsigned int currentLine = 1; //We start a the second line, after "General" //Properties of base object for (unsigned int i = 0;i<object->RuntimeObject::GetNumberOfProperties();++i) { object->RuntimeObject::GetPropertyForDebugger(i, uselessName, value); objectList->SetItem(currentLine, 1, value); currentLine++; } currentLine += 2; //We have two lines to jump for "Specific" //Specific properties of object for (unsigned int i = 0;i<object->GetNumberOfProperties();++i) { object->GetPropertyForDebugger(i, uselessName, value); objectList->SetItem(currentLine, 1, value); currentLine++; } currentLine += 2; //We have two lines to jump for "Variables" i = 0; const std::map < std::string, gd::Variable* > & objectVariables = object->GetVariables().DumpAllVariables(); //Suppression des lignes en trop pour les variables while(objectList->GetItemCount() > baseItemCount+objectVariables.size()) objectList->DeleteItem(baseItemCount+objectVariables.size()); //Rajout si au contraire il n'y en a pas assez while(objectList->GetItemCount() < baseItemCount+objectVariables.size()) { objectList->InsertItem(baseItemCount, ""); } //Mise à jour des variables for (std::map < std::string, gd::Variable* >::const_iterator it = objectVariables.begin(); it!=objectVariables.end();++it, ++i) { objectList->SetItem(baseItemCount+i, 0, it->first); objectList->SetItem(baseItemCount+i, 1, it->second->IsStructure() ? _("(Structure)") : it->second->GetString()); } }
void RuntimeScene::ManageObjectsBeforeEvents() { RuntimeObjList allObjects = objectsInstances.GetAllObjects(); for (unsigned int id = 0;id<allObjects.size();++id) allObjects[id]->DoAutomatismsPreEvents(*this); }
void RuntimeScene::Render() { if (!renderWindow) return; renderWindow->clear( sf::Color( GetBackgroundColorRed(), GetBackgroundColorGreen(), GetBackgroundColorBlue() ) ); //Sort object by order to render them RuntimeObjList allObjects = objectsInstances.GetAllObjects(); OrderObjectsByZOrder(allObjects); //To allow using OpenGL to draw: glClear(GL_DEPTH_BUFFER_BIT); // Clear the depth buffer renderWindow->pushGLStates(); renderWindow->setActive(); //Draw layer by layer for (unsigned int layerIndex =0;layerIndex<layers.size();++layerIndex) { if ( layers[layerIndex].GetVisibility() ) { for (unsigned int cameraIndex = 0;cameraIndex < layers[layerIndex].GetCameraCount();++cameraIndex) { RuntimeCamera & camera = layers[layerIndex].GetCamera(cameraIndex); //Prepare OpenGL rendering renderWindow->popGLStates(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(GetOpenGLFOV(), camera.GetWidth()/camera.GetHeight(), GetOpenGLZNear(), GetOpenGLZFar()); const sf::FloatRect & viewport = camera.GetSFMLView().getViewport(); glViewport(viewport.left*renderWindow->getSize().x, renderWindow->getSize().y-(viewport.top+viewport.height)*renderWindow->getSize().y, //Y start from bottom viewport.width*renderWindow->getSize().x, viewport.height*renderWindow->getSize().y); renderWindow->pushGLStates(); //Prepare SFML rendering renderWindow->setView(camera.GetSFMLView()); //Rendering all objects for (unsigned int id = 0;id < allObjects.size();++id) { if (allObjects[id]->GetLayer() == layers[layerIndex].GetName()) allObjects[id]->Draw(*renderWindow); } //Texts DisplayLegacyTexts(layers[layerIndex].GetName()); } } } //Internal profiler #ifndef RELEASE if ( sf::Keyboard::isKeyPressed(sf::Keyboard::F2)) CProfileManager::Reset(); renderWindow->setView(sf::View(sf::FloatRect(0.0f,0.0f, game->GetMainWindowDefaultWidth(), game->GetMainWindowDefaultHeight()))); CProfileIterator * iter = CProfileManager::Get_Iterator(); int y = 0; DisplayProfile(renderWindow, iter, 0,y); CProfileManager::Increment_Frame_Counter(); #endif // Display window contents on screen renderWindow->popGLStates(); renderWindow->display(); }