Ticket #1762: rallyPointRenderer.diff

File rallyPointRenderer.diff, 6.5 KB (added by mimo, 11 years ago)
  • binaries/data/mods/public/simulation/helpers/Commands.js

     
    296296        {
    297297            var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint);
    298298            if (cmpRallyPoint)
    299                 cmpRallyPoint.Unset();
     299                cmpRallyPoint.Reset();
    300300        }
    301301        break;
    302302
  • binaries/data/mods/public/simulation/helpers/InitSavedGame.js

     
     1function 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
     21Engine.RegisterGlobal("InitSavedGame", InitSavedGame);
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    2020    this.placementEntity = undefined; // = undefined or [templateName, entityID]
    2121    this.placementWallEntities = undefined;
    2222    this.placementWallLastAngle = 0;
    23     this.rallyPoints = undefined;
    2423    this.notifications = [];
    2524    this.renamedEntities = [];
    2625};
  • binaries/data/mods/public/simulation/components/RallyPoint.js

     
    4343    this.data = [];
    4444};
    4545
     46RallyPoint.prototype.Reset = function()
     47{
     48    this.Unset();
     49    var cmpRallyPointRenderer = Engine.QueryInterface(this.entity, IID_RallyPointRenderer);
     50    if (cmpRallyPointRenderer)
     51        cmpRallyPointRenderer.Reset();
     52};
     53
    4654Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);
  • source/simulation2/components/ICmpRallyPointRenderer.cpp

     
    2626DEFINE_INTERFACE_METHOD_1("SetDisplayed", void, ICmpRallyPointRenderer, SetDisplayed, bool)
    2727DEFINE_INTERFACE_METHOD_1("SetPosition", void, ICmpRallyPointRenderer, SetPosition, CFixedVector2D)
    2828DEFINE_INTERFACE_METHOD_1("AddPosition", void, ICmpRallyPointRenderer, AddPosition_wrapper, CFixedVector2D)
     29DEFINE_INTERFACE_METHOD_0("Reset", void, ICmpRallyPointRenderer, Reset)
    2930END_INTERFACE_WRAPPER(RallyPointRenderer)
  • source/simulation2/components/CCmpRallyPointRenderer.cpp

     
    293293        }
    294294    }
    295295
     296    virtual void Reset()
     297    {
     298        m_RallyPoints.clear();
     299        RecomputeAllRallyPointPaths();
     300    }
     301
    296302private:
    297303
    298304    /**
  • source/simulation2/components/ICmpRallyPointRenderer.h

     
    4141    /// to the previous one.
    4242    virtual void AddPosition_wrapper(CFixedVector2D position) = 0;
    4343
     44    /// Reset the positions of this rally point marker
     45    virtual void Reset() = 0;
     46
    4447    DECLARE_INTERFACE_TYPE(RallyPointRenderer)
    4548};
    4649
  • source/simulation2/Simulation2.cpp

     
    649649    GetScriptInterface().CallFunctionVoid(GetScriptInterface().GetGlobalObject(), "InitGame", data);
    650650}
    651651
     652void CSimulation2::InitSavedGame()
     653{
     654    GetScriptInterface().CallFunctionVoid(GetScriptInterface().GetGlobalObject(), "InitSavedGame");
     655}
     656
    652657void CSimulation2::Update(int turnLength)
    653658{
    654659    std::vector<SimulationCommand> commands;
  • 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.
    153154     */
    154155    void InitGame(const CScriptVal& data);
     156    void InitSavedGame();
    155157
    156158    void Update(int turnLength);
    157159    void Update(int turnLength, const std::vector<SimulationCommand>& commands);
  • source/ps/Game.cpp

     
    195195 **/
    196196PSRETURN CGame::ReallyStartGame()
    197197{
    198     // Call the script function InitGame only for new games, not saved games
     198    // Call the script function InitGame only for new games, and InitSavedGame for 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    }
    205209
    206210    // We need to do an initial Interpolate call to set up all the models etc,
    207211    // because Update might never interpolate (e.g. if the game starts paused)