Ticket #1762: rallyPointRenderer-2.diff

File rallyPointRenderer-2.diff, 7.2 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/simulation/helpers/InitSavedGame.js

     
    1 function InitSavedGame()
    2 {
    3     // This will be called after the map settings have been loaded,
    4     // before the simulation has started.
    5     // This is only called at the start of a saved game, not when loading
    6     // a new game.
    7 
    8     // rebuild the RallyPointRenderers from the RallyPoints info
    9     var rallyPoints = Engine.GetEntitiesWithInterface(IID_RallyPoint);
    10     for each (var ent in rallyPoints)
    11     {
    12         var cmpRallyPointRenderer = Engine.QueryInterface(ent, IID_RallyPointRenderer);
    13         if (!cmpRallyPointRenderer)
    14             continue;
    15         var positions = Engine.QueryInterface(ent, IID_RallyPoint).GetPositions();
    16         for each (var pos in positions)
    17             cmpRallyPointRenderer.AddPosition({'x': pos.x, 'y': pos.z});
    18     }
    19 }
    20 
    21 Engine.RegisterGlobal("InitSavedGame", InitSavedGame);
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    848848                cmpRallyPointRenderer.AddPosition({'x': pos.x, 'y': pos.z}); // AddPosition takes a CFixedVector2D which has X/Y components, not X/Z
    849849            else if (cmd.queued == false)
    850850                cmpRallyPointRenderer.SetPosition({'x': pos.x, 'y': pos.z}); // SetPosition takes a CFixedVector2D which has X/Y components, not X/Z
     851            // rebuild the renderer when not set (when reading saved game or in case of building update)
     852            else if (!cmpRallyPointRenderer.IsSet())
     853                for each (var posi in cmpRallyPoint.GetPositions())
     854                    cmpRallyPointRenderer.AddPosition({'x': posi.x, 'y': posi.z});
     855
    851856            cmpRallyPointRenderer.SetDisplayed(true);
    852857           
    853858            // remember which entities have their rally points displayed so we can hide them again
  • binaries/data/mods/public/simulation/components/Foundation.js

     
    277277        {
    278278            var rallyCoords = cmpRallyPoint.GetPositions();
    279279            var rallyData = cmpRallyPoint.GetData();
    280             var cmpBuildingRallyPointRenderer = Engine.QueryInterface(building, IID_RallyPointRenderer);
    281280            for (var i = 0; i < rallyCoords.length; ++i)
    282281            {
    283282                cmpBuildingRallyPoint.AddPosition(rallyCoords[i].x, rallyCoords[i].z);
    284283                cmpBuildingRallyPoint.AddData(rallyData[i]);
    285                 if (cmpBuildingRallyPointRenderer)
    286                     cmpBuildingRallyPointRenderer.AddPosition({'x': rallyCoords[i].x, 'y': rallyCoords[i].z});
    287284            }
    288285        }
    289286
  • source/ps/Game.cpp

     
    195195 **/
    196196PSRETURN CGame::ReallyStartGame()
    197197{
    198     // Call the script function InitGame only for new games, and InitSavedGame for saved games
     198    // Call the script function InitGame only for new games, not saved games
    199199    if (!m_IsSavedGame)
    200200    {
    201201        CScriptVal settings;
    202202        m_Simulation2->GetScriptInterface().GetProperty(m_Simulation2->GetInitAttributes().get(), "settings", settings);
    203203        m_Simulation2->InitGame(settings);
    204204    }
    205     else
    206     {
    207         m_Simulation2->InitSavedGame();
    208     }
    209205
    210206    // We need to do an initial Interpolate call to set up all the models etc,
    211207    // because Update might never interpolate (e.g. if the game starts paused)
  • source/simulation2/Simulation2.h

     
    150150     * Initialise a new game, based on some script data. (Called on CGame instantiation)
    151151     * (This mustn't be used when e.g. loading saved games, only when starting new ones.)
    152152     * This calls the InitGame function defined in helpers/InitGame.js.
    153      * Saved games are initialized with InitSavedGame.
    154153     */
    155154    void InitGame(const CScriptVal& data);
    156     void InitSavedGame();
    157155
    158156    void Update(int turnLength);
    159157    void Update(int turnLength, const std::vector<SimulationCommand>& commands);
  • source/simulation2/components/CCmpRallyPointRenderer.cpp

     
    299299        RecomputeAllRallyPointPaths();
    300300    }
    301301
     302    /**
     303     * Returns true if at least one display rally point is set; i.e., if we have a point to render our marker/line at.
     304     */
     305    bool IsSet()
     306    {
     307        return !m_RallyPoints.empty();
     308    }
     309
    302310private:
    303311
    304312    /**
     
    316324    }
    317325
    318326    /**
    319      * Returns true iff at least one display rally point is set; i.e., if we have a point to render our marker/line at.
    320      */
    321     bool IsSet()
    322     {
    323         return !m_RallyPoints.empty();
    324     }
    325 
    326     /**
    327327     * Repositions the rally point markers; moves them outside of the world (ie. hides them), or positions them at the currently
    328328     * set rally points. Also updates the actor's variation according to the entity's current owning player's civilization.
    329329     *
  • source/simulation2/components/ICmpRallyPointRenderer.h

     
    4444    /// Reset the positions of this rally point marker
    4545    virtual void Reset() = 0;
    4646
     47    /// Returns true if at least one display rally point is set
     48    virtual bool IsSet() = 0;
     49
    4750    DECLARE_INTERFACE_TYPE(RallyPointRenderer)
    4851};
    4952
  • source/simulation2/components/ICmpRallyPointRenderer.cpp

     
    2727DEFINE_INTERFACE_METHOD_1("SetPosition", void, ICmpRallyPointRenderer, SetPosition, CFixedVector2D)
    2828DEFINE_INTERFACE_METHOD_1("AddPosition", void, ICmpRallyPointRenderer, AddPosition_wrapper, CFixedVector2D)
    2929DEFINE_INTERFACE_METHOD_0("Reset", void, ICmpRallyPointRenderer, Reset)
     30DEFINE_INTERFACE_METHOD_0("IsSet", bool, ICmpRallyPointRenderer, IsSet)
    3031END_INTERFACE_WRAPPER(RallyPointRenderer)
  • source/simulation2/Simulation2.cpp

     
    652652    GetScriptInterface().CallFunctionVoid(GetScriptInterface().GetGlobalObject(), "InitGame", data);
    653653}
    654654
    655 void CSimulation2::InitSavedGame()
    656 {
    657     GetScriptInterface().CallFunctionVoid(GetScriptInterface().GetGlobalObject(), "InitSavedGame");
    658 }
    659 
    660655void CSimulation2::Update(int turnLength)
    661656{
    662657    std::vector<SimulationCommand> commands;