Exemplo n.º 1
0
void Layout::SerializeTo(SerializerElement & element) const
{
    element.SetAttribute( "name", GetName());
    element.SetAttribute( "mangledName", GetMangledName());
    element.SetAttribute( "r", (int)GetBackgroundColorRed() );
    element.SetAttribute( "v", (int)GetBackgroundColorGreen() );
    element.SetAttribute( "b", (int)GetBackgroundColorBlue() );
    element.SetAttribute( "title", GetWindowDefaultTitle());
    element.SetAttribute( "oglFOV", oglFOV );
    element.SetAttribute( "oglZNear", oglZNear );
    element.SetAttribute( "oglZFar", oglZFar );
    element.SetAttribute( "standardSortMethod", standardSortMethod);
    element.SetAttribute( "stopSoundsOnStartup", stopSoundsOnStartup);
    element.SetAttribute( "disableInputWhenNotFocused", disableInputWhenNotFocused);

    #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
    GetAssociatedLayoutEditorCanvasOptions().SerializeTo(element.AddChild("uiSettings"));
    #endif

    ObjectGroup::SerializeTo(GetObjectGroups(), element.AddChild("objectsGroups"));
    GetVariables().SerializeTo(element.AddChild("variables"));
    GetInitialInstances().SerializeTo(element.AddChild("instances"));
    SerializeObjectsTo(element.AddChild("objects"));
    gd::EventsListSerialization::SerializeEventsTo(events, element.AddChild("events"));

    SerializerElement & layersElement = element.AddChild("layers");
    layersElement.ConsiderAsArrayOf("layer");
    for ( std::size_t j = 0;j < GetLayersCount();++j )
        GetLayer(j).SerializeTo(layersElement.AddChild("layer"));

    SerializerElement & behaviorDatasElement = element.AddChild("behaviorsSharedData");
    behaviorDatasElement.ConsiderAsArrayOf("behaviorSharedData");
    for (std::map<gd::String, std::shared_ptr<gd::BehaviorsSharedData> >::const_iterator it = behaviorsInitialSharedDatas.begin();
         it != behaviorsInitialSharedDatas.end();++it)
    {
        SerializerElement & dataElement = behaviorDatasElement.AddChild("behaviorSharedData");

        dataElement.SetAttribute("type", it->second->GetTypeName());
        dataElement.SetAttribute("name", it->second->GetName());
        it->second->SerializeTo(dataElement);
    }
}
Exemplo n.º 2
0
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();
}
Exemplo n.º 3
0
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();
}