Advertisement
historic_bruno

Untitled

Jun 7th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.72 KB | None | 0 0
  1. Index: binaries/data/mods/public/simulation/components/Player.js
  2. ===================================================================
  3. --- binaries/data/mods/public/simulation/components/Player.js   (revision 11947)
  4. +++ binaries/data/mods/public/simulation/components/Player.js   (working copy)
  5. @@ -221,8 +221,32 @@
  6.  Player.prototype.SetDiplomacy = function(dipl)
  7.  {
  8.     this.diplomacy = dipl;
  9. +   this.UpdateSharedLos();
  10.  };
  11.  
  12. +Player.prototype.SetDiplomacyIndex = function(idx, value)
  13. +{
  14. +   // TODO: send a message too?
  15. +   this.diplomacy[idx] = value;
  16. +   this.UpdateSharedLos();
  17. +};
  18. +
  19. +Player.prototype.UpdateSharedLos = function()
  20. +{
  21. +   var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
  22. +   if (!cmpRangeManager)
  23. +       return;
  24. +
  25. +   // TODO: only check our alliances currently, more advanced checks
  26. +   //  will be needed when we have full diplomacy
  27. +   var sharedLos = [];
  28. +   for (var i = 0; i < this.diplomacy.length; ++i)
  29. +       if (this.IsAlly(i))
  30. +           sharedLos.push(i);
  31. +
  32. +   cmpRangeManager.SetSharedLos(this.playerID, sharedLos);
  33. +};
  34. +
  35.  Player.prototype.GetFormations = function()
  36.  {
  37.     return this.formations;
  38. @@ -275,7 +299,7 @@
  39.  
  40.  Player.prototype.SetAlly = function(id)
  41.  {
  42. -   this.diplomacy[id] = 1;
  43. +   this.SetDiplomacyIndex(id, 1);
  44.  };
  45.  
  46.  /**
  47. @@ -288,7 +312,7 @@
  48.  
  49.  Player.prototype.SetEnemy = function(id)
  50.  {
  51. -   this.diplomacy[id] = -1;
  52. +   this.SetDiplomacyIndex(id, -1);
  53.  };
  54.  
  55.  /**
  56. @@ -301,7 +325,7 @@
  57.  
  58.  Player.prototype.SetNeutral = function(id)
  59.  {
  60. -   this.diplomacy[id] = 0;
  61. +   this.SetDiplomacyIndex(id, 0);
  62.  };
  63.  
  64.  /**
  65. Index: source/graphics/LOSTexture.cpp
  66. ===================================================================
  67. --- source/graphics/LOSTexture.cpp  (revision 11947)
  68. +++ source/graphics/LOSTexture.cpp  (working copy)
  69. @@ -178,7 +178,7 @@
  70.     if (!cmpRangeManager)
  71.         return;
  72.  
  73. -   ICmpRangeManager::CLosQuerier los (cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID()));
  74. +   ICmpRangeManager::CLosQuerier los(cmpRangeManager->GetLosQuerier(g_Game->GetPlayerID()));
  75.  
  76.     GenerateBitmap(los, &losData[0], m_MapSize, m_MapSize);
  77.  
  78. Index: source/simulation2/components/CCmpRangeManager.cpp
  79. ===================================================================
  80. --- source/simulation2/components/CCmpRangeManager.cpp  (revision 11947)
  81. +++ source/simulation2/components/CCmpRangeManager.cpp  (working copy)
  82. @@ -22,6 +22,7 @@
  83.  
  84.  #include "simulation2/MessageTypes.h"
  85.  #include "simulation2/components/ICmpPosition.h"
  86. +#include "simulation2/components/ICmpPlayerManager.h"
  87.  #include "simulation2/components/ICmpTerritoryManager.h"
  88.  #include "simulation2/components/ICmpVision.h"
  89.  #include "simulation2/helpers/Render.h"
  90. @@ -57,7 +58,7 @@
  91.   * Convert an owner ID (-1 = unowned, 0 = gaia, 1..30 = players)
  92.   * into a 32-bit mask for quick set-membership tests.
  93.   */
  94. -static u32 CalcOwnerMask(i32 owner)
  95. +static u32 CalcOwnerMask(player_id_t owner)
  96.  {
  97.     if (owner >= -1 && owner < 31)
  98.         return 1 << (1+owner);
  99. @@ -66,6 +67,23 @@
  100.  }
  101.  
  102.  /**
  103. + * Returns shared LOS mask for given list of players.
  104. + */
  105. +static u32 CalcSharedLosMask(std::vector<player_id_t> players)
  106. +{
  107. +   u32 playerMask = 0;
  108. +   player_id_t player;
  109. +   for (size_t i = 0; i < players.size(); i++)
  110. +   {
  111. +       player = players[i];
  112. +       if (player > 0 && player <= 16)
  113. +           playerMask |= ICmpRangeManager::LOS_MASK << (2*(player-1));
  114. +   }
  115. +
  116. +   return playerMask;
  117. +}
  118. +
  119. +/**
  120.   * Representation of an entity, with the data needed for queries.
  121.   */
  122.  struct EntityData
  123. @@ -212,6 +230,9 @@
  124.     // (TODO: this is usually a waste of memory)
  125.     std::vector<u32> m_LosStateRevealed;
  126.  
  127. +   // Shared LOS masks, one per player.
  128. +   std::map<player_id_t, u32> m_SharedLosMasks;
  129. +
  130.     static std::string GetSchema()
  131.     {
  132.         return "<a:component type='system'/><empty/>";
  133. @@ -234,6 +255,10 @@
  134.         // will get confused when trying to run from enemies
  135.         m_LosRevealAll[0] = true;
  136.  
  137. +       // This is not really an error condition, an entity recently created or destroyed
  138. +       //  might have an owner of INVALID_PLAYER
  139. +       m_SharedLosMasks[INVALID_PLAYER] = 0;
  140. +
  141.         m_LosCircular = false;
  142.         m_TerrainVerticesPerSide = 0;
  143.  
  144. @@ -265,6 +290,8 @@
  145.         // m_LosState must be serialized since it depends on the history of exploration
  146.  
  147.         SerializeVector<SerializeU32_Unbounded>()(serialize, "los state", m_LosState);
  148. +
  149. +       SerializeMap<SerializeI32_Unbounded, SerializeU32_Unbounded>()(serialize, "shared los masks", m_SharedLosMasks);
  150.     }
  151.  
  152.     virtual void Serialize(ISerializer& serialize)
  153. @@ -910,13 +937,18 @@
  154.     virtual CLosQuerier GetLosQuerier(player_id_t player)
  155.     {
  156.         if (GetLosRevealAll(player))
  157. -           return CLosQuerier(player, m_LosStateRevealed, m_TerrainVerticesPerSide);
  158. +           return CLosQuerier(GetSharedLosMask(player), m_LosStateRevealed, m_TerrainVerticesPerSide);
  159.         else
  160. -           return CLosQuerier(player, m_LosState, m_TerrainVerticesPerSide);
  161. +           return CLosQuerier(GetSharedLosMask(player), m_LosState, m_TerrainVerticesPerSide);
  162.     }
  163.  
  164.     virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, bool forceRetainInFog)
  165.     {
  166. +       return GetLosVisibility(ent, player, 0, forceRetainInFog);
  167. +   }
  168. +
  169. +   virtual ELosVisibility GetLosVisibility(entity_id_t ent, player_id_t player, u32 playerMask, bool forceRetainInFog)
  170. +   {
  171.         // (We can't use m_EntityData since this needs to handle LOCAL entities too)
  172.  
  173.         // Entities not with positions in the world are never visible
  174. @@ -939,8 +971,10 @@
  175.         }
  176.  
  177.         // Visible if within a visible region
  178. +       if (!playerMask)
  179. +           playerMask = GetSharedLosMask(player);
  180.  
  181. -       CLosQuerier los(player, m_LosState, m_TerrainVerticesPerSide);
  182. +       CLosQuerier los(playerMask, m_LosState, m_TerrainVerticesPerSide);
  183.  
  184.         if (los.IsVisible(i, j))
  185.             return VIS_VISIBLE;
  186. @@ -991,6 +1025,19 @@
  187.         return m_LosCircular;
  188.     }
  189.  
  190. +   virtual void SetSharedLos(player_id_t player, std::vector<player_id_t> players)
  191. +   {
  192. +       m_SharedLosMasks[player] = CalcSharedLosMask(players);
  193. +   }
  194. +
  195. +   virtual u32 GetSharedLosMask(player_id_t player)
  196. +   {
  197. +       std::map<player_id_t, u32>::const_iterator it = m_SharedLosMasks.find(player);
  198. +       ENSURE(it != m_SharedLosMasks.end());
  199. +
  200. +       return m_SharedLosMasks[player];
  201. +   }
  202. +
  203.     void UpdateTerritoriesLos()
  204.     {
  205.         CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
  206. Index: source/simulation2/components/ICmpRangeManager.cpp
  207. ===================================================================
  208. --- source/simulation2/components/ICmpRangeManager.cpp  (revision 11947)
  209. +++ source/simulation2/components/ICmpRangeManager.cpp  (working copy)
  210. @@ -48,5 +48,6 @@
  211.  DEFINE_INTERFACE_METHOD_3("GetLosVisibility", std::string, ICmpRangeManager, GetLosVisibility_wrapper, entity_id_t, player_id_t, bool)
  212.  DEFINE_INTERFACE_METHOD_1("SetLosCircular", void, ICmpRangeManager, SetLosCircular, bool)
  213.  DEFINE_INTERFACE_METHOD_0("GetLosCircular", bool, ICmpRangeManager, GetLosCircular)
  214. +DEFINE_INTERFACE_METHOD_2("SetSharedLos", void, ICmpRangeManager, SetSharedLos, player_id_t, std::vector<player_id_t>)
  215.  DEFINE_INTERFACE_METHOD_1("GetPercentMapExplored", i32, ICmpRangeManager, GetPercentMapExplored, player_id_t)
  216.  END_INTERFACE_WRAPPER(RangeManager)
  217. Index: source/simulation2/components/ICmpRangeManager.h
  218. ===================================================================
  219. --- source/simulation2/components/ICmpRangeManager.h    (revision 11947)
  220. +++ source/simulation2/components/ICmpRangeManager.h    (working copy)
  221. @@ -185,13 +185,10 @@
  222.         friend class CCmpRangeManager;
  223.         friend class TestLOSTexture;
  224.  
  225. -       CLosQuerier(player_id_t player, const std::vector<u32>& data, ssize_t verticesPerSide) :
  226. +       CLosQuerier(u32 playerMask, const std::vector<u32>& data, ssize_t verticesPerSide) :
  227.             m_Data(&data[0]), m_VerticesPerSide(verticesPerSide)
  228.         {
  229. -           if (player > 0 && player <= 16)
  230. -               m_PlayerMask = LOS_MASK << (2*(player-1));
  231. -           else
  232. -               m_PlayerMask = 0;
  233. +           m_PlayerMask = playerMask;
  234.         }
  235.  
  236.         const CLosQuerier& operator=(const CLosQuerier&); // not implemented
  237. @@ -266,7 +263,8 @@
  238.     };
  239.  
  240.     /**
  241. -    * Returns a CLosQuerier for checking whether vertex positions are visible to the given player.
  242. +    * Returns a CLosQuerier for checking whether vertex positions are visible to the given player
  243. +    *  (or other players it shares LOS with).
  244.      */
  245.     virtual CLosQuerier GetLosQuerier(player_id_t player) = 0;
  246.  
  247. @@ -308,6 +306,16 @@
  248.     virtual bool GetLosCircular() = 0;
  249.  
  250.     /**
  251. +    * Sets shared LOS data for player to the given list of players.
  252. +    */
  253. +   virtual void SetSharedLos(player_id_t player, std::vector<player_id_t> players) = 0;
  254. +
  255. +   /**
  256. +    * Returns shared LOS mask for player.
  257. +    */
  258. +   virtual u32 GetSharedLosMask(player_id_t player) = 0;
  259. +
  260. +   /**
  261.      * Get percent map explored statistics for specified player.
  262.      */
  263.     virtual i32 GetPercentMapExplored(player_id_t player) = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement