Ticket #3952: simulationVariations.2.diff

File simulationVariations.2.diff, 11.5 KB (added by sanderd17, 8 years ago)
  • binaries/data/mods/public/art/actors/structures/hellenes/siege_tower.xml

     
    1717    </variant>
    1818  </group>
    1919  <group>
    20     <variant frequency="100" name="Idle"/>
     20    <variant frequency="1" name="ungarrisoned"/>
    2121    <variant name="garrisoned">
    2222      <props>
    2323        <prop actor="props/special/common/waypoint_flag_0ad.xml" attachpoint="garrisoned"/>
    2424      </props>
    2525    </variant>
     26  </group>
     27  <group>
     28    <variant frequency="1" name="alive"/>
    2629    <variant name="death">
    2730      <props>
    2831        <prop attachpoint="garrisoned"/>
  • binaries/data/mods/public/simulation/components/GarrisonHolder.js

     
    566566
    567567GarrisonHolder.prototype.UpdateGarrisonFlag = function()
    568568{
    569     var cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
     569    let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
    570570    if (!cmpVisual)
    571571        return;
    572     cmpVisual.SelectAnimation("garrisoned", true, 0, "");
    573     // TODO: ought to extend ICmpVisual to let us just select variant
    574     // keywords without changing the animation too
    575     if (this.entities.length)
    576         cmpVisual.SelectAnimation("garrisoned", false, 1.0, "");
    577     else
    578         cmpVisual.SelectAnimation("idle", false, 1.0, "");
     572    let selection = this.entities.length ? "garrisoned" : "ungarrisoned";
     573    cmpVisual.SetVariantSelection("garrison", selection);
    579574};
    580575
    581576/**
  • source/graphics/Unit.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    7777        m_Animation->SetEntityID(id);
    7878}
    7979
    80 void CUnit::SetEntitySelection(const CStr& selection)
     80void CUnit::SetEntitySelection(const CStr& key, const CStr& selection)
    8181{
    8282    CStr selection_lc = selection.LowerCase();
    8383
    84     // If we've already selected this, don't do anything
    85     if (m_EntitySelections.find(selection_lc) != m_EntitySelections.end())
     84    if (m_EntitySelections[key] == selection_lc)
    8685        return;
     86    m_EntitySelections[key] = selection_lc;
    8787
    88     // Just allow one selection at a time
    89     m_EntitySelections.clear();
    90     m_EntitySelections.insert(selection_lc);
     88    ReloadObject();
     89}
    9190
     91void CUnit::SetEntitySelection(const std::map<CStr, CStr>& selections)
     92{
     93    for (const std::pair<CStr, CStr>& s : selections)
     94        m_EntitySelections[s.first] = s.second.LowerCase();
     95
    9296    ReloadObject();
    9397}
    9498
     
    100104
    101105void CUnit::ReloadObject()
    102106{
     107    std::set<CStr> entitySelections;
     108    for (const std::pair<CStr, CStr>& selection : m_EntitySelections)
     109        entitySelections.insert(selection.second);
     110    // TODO: push world selections (seasons, etc) (and reload whenever they're changed)
    103111    std::vector<std::set<CStr> > selections;
    104     // TODO: push world selections (seasons, etc) (and reload whenever they're changed)
    105     selections.push_back(m_EntitySelections);
     112    selections.push_back(entitySelections);
    106113    selections.push_back(m_ActorSelections);
    107114
    108115    // randomly select any remain selections necessary to completely identify a variation (e.g., the new selection
  • source/graphics/Unit.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    6464    void UpdateModel(float frameTime);
    6565
    6666    // Sets the entity-selection, and updates the unit to use the new
    67     // actor variation.
    68     void SetEntitySelection(const CStr& selection);
     67    // actor variation. Either set one key at a time, or a complete map.
     68    void SetEntitySelection(const CStr& key, const CStr& selection);
     69    void SetEntitySelection(const std::map<CStr, CStr>& selections);
    6970
    7071    // Most units have a hopefully-unique ID number, so they can be referred to
    7172    // persistently despite saving/loading maps. Default for new units is -1; should
     
    9596    // actor-level selections for this unit
    9697    std::set<CStr> m_ActorSelections;
    9798    // entity-level selections for this unit
    98     std::set<CStr> m_EntitySelections;
     99    std::map<CStr, CStr> m_EntitySelections;
    99100
    100101    // object manager which looks after this unit's objectentry
    101102    CObjectManager& m_ObjectManager;
  • source/simulation2/components/CCmpRallyPointRenderer.cpp

     
    556556
    557557        CmpPtr<ICmpVisual> cmpVisualActor(GetSimContext(), m_MarkerEntityIds[i]);
    558558        if (cmpVisualActor)
    559             cmpVisualActor->SetUnitEntitySelection(CStrW(cmpPlayer->GetCiv()).ToUTF8());
     559            cmpVisualActor->SetVariantSelection("civ", CStrW(cmpPlayer->GetCiv()).ToUTF8());
    560560    }
    561561    m_LastMarkerCount = m_RallyPoints.size() - 1;
    562562}
  • source/simulation2/components/CCmpVisualActor.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    3232#include "ICmpValueModificationManager.h"
    3333#include "ICmpVisibility.h"
    3434
     35#include "simulation2/serialization/SerializeTemplates.h"
     36
    3537#include "graphics/Decal.h"
    3638#include "graphics/Frustum.h"
    3739#include "graphics/Model.h"
     
    8082    fixed m_AnimDesync;
    8183    fixed m_AnimSyncRepeatTime; // 0.0 if not synced
    8284
     85    std::map<CStr, CStr> m_VariantSelections;
     86
    8387    u32 m_Seed; // seed used for random variations
    8488
    8589    bool m_ConstructionPreview;
     
    229233        serialize.NumberFixed_Unbounded("anim desync", m_AnimDesync);
    230234        serialize.NumberFixed_Unbounded("anim sync repeat time", m_AnimSyncRepeatTime);
    231235
     236        SerializeMap<SerializeString, SerializeString>()(serialize, "variation", m_VariantSelections);
     237
    232238        serialize.NumberU32_Unbounded("seed", m_Seed);
    233         // TODO: variation/selection strings
    234239        serialize.String("actor", m_ActorName, 0, 256);
    235240
    236241        // TODO: store actor variables?
     
    259264        // If we serialized a different seed or different actor, reload actor
    260265        if (oldSeed != GetActorSeed() || m_BaseActorName != m_ActorName)
    261266            ReloadActor();
     267        else
     268            m_Unit->SetEntitySelection(m_VariantSelections);
    262269
    263270        fixed repeattime = m_AnimSyncRepeatTime; // save because SelectAnimation overwrites it
    264271
     
    410417        return CVector3D();
    411418    }
    412419
     420    virtual void SetVariantSelection(const CStr& key, const CStr& selection)
     421    {
     422        m_VariantSelections[key] = selection;
     423        if (!m_Unit)
     424            return;
     425        m_Unit->SetEntitySelection(key, selection);
     426    }
     427
    413428    virtual void SelectAnimation(const std::string& name, bool once, fixed speed, const std::wstring& soundgroup)
    414429    {
    415430        m_AnimRunThreshold = fixed::Zero();
     
    422437
    423438        if (m_Unit)
    424439        {
    425             m_Unit->SetEntitySelection(m_AnimName);
     440            SetVariantSelection("animation", m_AnimName);
    426441            if (m_Unit->GetAnimation())
    427442                m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str());
    428443        }
     
    440455            m_AnimOverride.erase(name);
    441456    }
    442457
    443     virtual void SetUnitEntitySelection(const CStr& selection)
    444     {
    445         if (m_Unit)
    446         {
    447             m_Unit->SetEntitySelection(selection);
    448         }
    449     }
    450 
    451458    virtual void SelectMovementAnimation(fixed runThreshold)
    452459    {
    453460        m_AnimRunThreshold = runThreshold;
     
    454461
    455462        if (m_Unit)
    456463        {
    457             m_Unit->SetEntitySelection("walk");
     464            SetVariantSelection("animation", "walk");
    458465            if (m_Unit->GetAnimation())
    459466                m_Unit->GetAnimation()->SetAnimationState("walk", false, 1.f, 0.f, L"");
    460467        }
     
    713720
    714721    InitModel(node->GetChild("VisualActor"));
    715722
    716     m_Unit->SetEntitySelection(m_AnimName);
     723    m_Unit->SetEntitySelection(m_VariantSelections);
     724
    717725    if (m_Unit->GetAnimation())
    718726        m_Unit->GetAnimation()->SetAnimationState(m_AnimName, m_AnimOnce, m_AnimSpeed.ToFloat(), m_AnimDesync.ToFloat(), m_SoundGroup.c_str());
    719727
     
    763771        if (it != m_AnimOverride.end())
    764772            name = it->second;
    765773
    766         m_Unit->SetEntitySelection(name);
    767         if (speed == 0.0f)
     774        SetVariantSelection("animation", name);
     775        if (m_Unit->GetAnimation())
    768776        {
    769             m_Unit->SetEntitySelection(name);
    770             if (m_Unit->GetAnimation())
     777            if (speed == 0.0f)
    771778                m_Unit->GetAnimation()->SetAnimationState(name, false, 1.f, 0.f, L"");
    772         }
    773         else
    774         {
    775             m_Unit->SetEntitySelection(name);
    776             if (m_Unit->GetAnimation())
     779            else
    777780                m_Unit->GetAnimation()->SetAnimationState(name, false, speed, 0.f, L"");
    778781        }
    779782    }
  • source/simulation2/components/ICmpVisual.cpp

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    2222#include "simulation2/system/InterfaceScripted.h"
    2323
    2424BEGIN_INTERFACE_WRAPPER(Visual)
     25DEFINE_INTERFACE_METHOD_2("SetVariantSelection", void, ICmpVisual, SetVariantSelection, CStr, CStr)
    2526DEFINE_INTERFACE_METHOD_4("SelectAnimation", void, ICmpVisual, SelectAnimation, std::string, bool, fixed, std::wstring)
    2627DEFINE_INTERFACE_METHOD_1("SelectMovementAnimation", void, ICmpVisual, SelectMovementAnimation, fixed)
    2728DEFINE_INTERFACE_METHOD_1("ResetMoveAnimation", void, ICmpVisual, ResetMoveAnimation, std::string)
  • source/simulation2/components/ICmpVisual.h

     
    1 /* Copyright (C) 2013 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    8080    virtual CUnit* GetUnit() = 0;
    8181
    8282    /**
     83     * Set the variant selection of the actor for a certain key
     84     */
     85    virtual void SetVariantSelection(const CStr& key, const CStr& selection) = 0;
     86
     87    /**
    8388     * Start playing the given animation. If there are multiple possible animations then it will
    8489     * pick one at random (not network-synchronised).
    8590     * If @p soundgroup is specified, then the sound will be played at each 'event' point in the
     
    107112    virtual void ResetMoveAnimation(const std::string& name) = 0;
    108113
    109114    /**
    110      * Sets the specified entity selection on the underlying unit.
    111      */
    112     virtual void SetUnitEntitySelection(const CStr& selection) = 0;
    113 
    114     /**
    115115     * Start playing the walk/run animations, scaled to the unit's movement speed.
    116116     * @param runThreshold movement speed at which to switch to the run animation
    117117     */