Ticket #4046: messageChangesV0.patch
File messageChangesV0.patch, 52.0 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Formation.js
334 334 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 335 335 cmpUnitAI.UpdateWorkOrders(); 336 336 cmpUnitAI.SetFormationController(INVALID_ENTITY); 337 Engine.UnsubscribeFromEntity(IID_Formation, this.entity, ent); 337 338 } 338 339 339 340 for each (var ent in this.formationMembersWithAura) … … 379 380 cmpAuras.RemoveFormationBonus(this.members); 380 381 } 381 382 383 for (let ent of ents) 384 { 385 Engine.SubscribeToEntity(IID_Formation, this.entity, ent); 386 } 387 382 388 this.members = this.members.concat(ents); 383 389 384 390 for each (var ent in this.members) … … 924 930 } 925 931 }; 926 932 927 Formation.prototype.On GlobalOwnershipChanged = function(msg)933 Formation.prototype.OnSubscribedOwnershipChanged = function(msg) 928 934 { 929 935 // When an entity is captured or destroyed, it should no longer be 930 936 // controlled by this formation … … 933 939 this.RemoveMembers([msg.entity]); 934 940 }; 935 941 936 Formation.prototype.On GlobalEntityRenamed = function(msg)942 Formation.prototype.OnSubscribedOwnershipChanged = function(msg) 937 943 { 938 944 if (this.members.indexOf(msg.entity) != -1) 939 945 { 946 this.UnsubscribeFromEntity(IID_Formation, this.entity, msg.entity) 947 this.SubscribeToEntity(IID_Formation, this.entity, msg.newentity) 948 940 949 this.offsets = undefined; 941 950 var cmpNewUnitAI = Engine.QueryInterface(msg.newentity, IID_UnitAI); 942 951 if (cmpNewUnitAI) -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
278 278 if (cmpAura && cmpAura.HasGarrisonAura()) 279 279 cmpAura.ApplyGarrisonBonus(this.entity); 280 280 281 Engine.SubscribeToEntity(IID_GarrisonHolder, this.entity, entity); 282 281 283 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [entity], "removed": [] }); 282 284 283 285 var cmpUnitAI = Engine.QueryInterface(entity, IID_UnitAI); … … 411 413 412 414 if (this.Eject(entity, forced)) 413 415 { 416 Engine.UnsubscribeFromEntity(IID_GarrisonHolder, this.entity, entity); 414 417 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 415 418 var cmpEntOwnership = Engine.QueryInterface(entity, IID_Ownership); 416 419 if (cmpOwnership && cmpEntOwnership && cmpOwnership.GetOwner() == cmpEntOwnership.GetOwner()) … … 585 588 } 586 589 }; 587 590 591 592 GarrisonHolder.prototype.OnOwnershipChanged = function(msg) 593 { 594 var entities = []; 595 for each (var entity in this.entities) 596 { 597 if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, entity)) 598 entities.push(entity); 599 } 600 if (entities.length) 601 this.EjectOrKill(entities); 602 return; 603 } 588 604 /** 589 605 * If a garrisoned entity is captured, or about to be killed (so its owner 590 606 * changes to '-1'), remove it from the building so we only ever contain valid 591 607 * entities 592 608 */ 593 GarrisonHolder.prototype.On GlobalOwnershipChanged = function(msg)609 GarrisonHolder.prototype.OnSubscribedOwnershipChanged = function(msg) 594 610 { 595 // the ownership change may be on the garrisonholder596 if (this.entity == msg.entity)597 {598 var entities = [];599 for each (var entity in this.entities)600 {601 if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, entity))602 entities.push(entity);603 }604 if (entities.length)605 this.EjectOrKill(entities);606 return;607 }608 609 611 // or on some of its garrisoned units 610 612 var entityIndex = this.entities.indexOf(msg.entity); 611 613 if (entityIndex != -1) 614 warn("no sanity check"); 615 616 // If the entity is dead, remove it directly instead of ejecting the corpse 617 var cmpHealth = Engine.QueryInterface(msg.entity, IID_Health); 618 if (cmpHealth && cmpHealth.GetHitpoints() == 0) 612 619 { 613 // If the entity is dead, remove it directly instead of ejecting the corpse 614 var cmpHealth = Engine.QueryInterface(msg.entity, IID_Health); 615 if (cmpHealth && cmpHealth.GetHitpoints() == 0) 616 { 617 this.entities.splice(entityIndex, 1); 618 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] }); 619 this.UpdateGarrisonFlag(); 620 this.entities.splice(entityIndex, 1); 621 Engine.PostMessage(this.entity, MT_GarrisonedUnitsChanged, { "added" : [], "removed": [msg.entity] }); 622 this.UpdateGarrisonFlag(); 620 623 621 for (var pt of this.visibleGarrisonPoints) 622 if (pt.entity == msg.entity) 623 pt.entity = null; 624 } 625 else if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, msg.entity)) 626 this.EjectOrKill([msg.entity]); 624 Engine.UnsubscribeFromEntity(IID_GarrisonHolder, this.entity, entity); 625 626 for (var pt of this.visibleGarrisonPoints) 627 if (pt.entity == msg.entity) 628 pt.entity = null; 627 629 } 630 else if (msg.to == -1 || !IsOwnedByMutualAllyOfEntity(this.entity, msg.entity)) 631 this.EjectOrKill([msg.entity]); 628 632 }; 629 633 630 /** 631 * Update list of garrisoned entities if one gets renamed (e.g. by promotion) 632 */ 633 GarrisonHolder.prototype.OnGlobalEntityRenamed = function(msg) 634 GarrisonHolder.prototype.OnEntityRenamed = function(msg) 634 635 { 635 636 var entityIndex = this.entities.indexOf(msg.entity); 636 637 if (entityIndex != -1) … … 646 647 this.Eject(msg.entity); 647 648 this.Garrison(msg.newentity, vgpRenamed); 648 649 } 649 650 } 651 /** 652 * Update list of garrisoned entities if one gets renamed (e.g. by promotion) 653 */ 654 GarrisonHolder.prototype.OnSubscribedEntityRenamed = function(msg) 655 { 650 656 if (!this.initGarrison) 651 657 return; 652 658 … … 659 665 } 660 666 else 661 667 { 668 Engine.UnsubscriptionFromEntity(IID_GarrisonHolder, this.entity, msg.entity); 669 Engine.SubscriptionToEntity(IID_GarrisonHolder, this.entity, msg.newentity); 670 662 671 let entityIndex = this.initGarrison.indexOf(msg.entity); 663 672 if (entityIndex != -1) 664 673 this.initGarrison[entityIndex] = msg.newentity; … … 681 690 */ 682 691 GarrisonHolder.prototype.EjectOrKill = function(entities) 683 692 { 693 for (let entity of entities) 694 { 695 Engine.UnsubscribeFromEntity(IID_GarrisonHolder, this.entity, entity); 696 } 684 697 var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 685 698 // Eject the units which can be ejected (if not in world, it generally means this holder 686 699 // is inside a holder which kills its entities, so do not eject) -
binaries/data/mods/public/simulation/components/Guard.js
37 37 { 38 38 if (this.entities.indexOf(ent) != -1) 39 39 return; 40 Engine.SubscribeToEntity(IID_Guard, this.entity, ent); 40 41 this.entities.push(ent); 41 42 }; 42 43 … … 43 44 Guard.prototype.RemoveGuard = function(ent) 44 45 { 45 46 var index = this.entities.indexOf(ent); 46 if (index != -1) 47 this.entities.splice(index, 1); 47 if (index == -1) 48 return; 49 this.entities.splice(index, 1); 50 Engine.UnsubscribeFromEntity(IID_Guard, this.entity, ent); 48 51 }; 49 52 50 53 Guard.prototype.OnAttacked = function(msg) … … 56 59 /** 57 60 * Update list of guarding/escorting entities if one gets renamed (e.g. by promotion) 58 61 */ 59 Guard.prototype.On GlobalEntityRenamed = function(msg)62 Guard.prototype.OnSubscribedEntityRenamed = function(msg) 60 63 { 61 64 var entityIndex = this.entities.indexOf(msg.entity); 62 if (entityIndex != -1) 63 this.entities[entityIndex] = msg.newentity; 65 if (entityIndex == -1) 66 return; 67 68 Engine.UnsubscribeFromEntity(IID_Guard, this.entity, msg.entity); 69 Engine.SubscribeToEntity(IID_Guard, this.entity, msg.newentity); 70 this.entities[entityIndex] = msg.newentity; 64 71 }; 65 72 66 /** 67 * If an entity is captured, or about to be killed (so its owner 68 * changes to '-1'), update the guards list 69 */ 70 Guard.prototype.OnGlobalOwnershipChanged = function(msg) 73 Guard.prototype.OnOwnershipChanged = function(msg) 71 74 { 72 75 // the ownership change may be on the guarded 73 76 if (this.entity == msg.entity) … … 87 90 this.entities = entities; 88 91 return; 89 92 } 90 93 } 94 /** 95 * If an entity is captured, or about to be killed (so its owner 96 * changes to '-1'), update the guards list 97 */ 98 Guard.prototype.OnSubscribedOwnershipChanged = function(msg) 99 { 91 100 // or on some of its guards 92 101 if (this.entities.indexOf(msg.entity) != -1) 93 102 { -
source/simulation2/components/CCmpAIManager.cpp
939 939 m_JustDeserialized = true; 940 940 } 941 941 942 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))942 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 943 943 { 944 944 switch (msg.GetType()) 945 945 { -
source/simulation2/components/CCmpCinemaManager.cpp
174 174 g_Game->GetView()->GetCinema()->SetEnabled(p_CinematicSimulationData->m_Enabled); 175 175 } 176 176 177 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))177 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 178 178 { 179 179 if (!g_Game || !g_Game->GetView()) 180 180 return; -
source/simulation2/components/CCmpDecay.cpp
125 125 Init(paramNode); 126 126 } 127 127 128 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))128 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 129 129 { 130 130 switch (msg.GetType()) 131 131 { -
source/simulation2/components/CCmpMinimap.cpp
145 145 SerializeCommon(deserialize); 146 146 } 147 147 148 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))148 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 149 149 { 150 150 switch (msg.GetType()) 151 151 { -
source/simulation2/components/CCmpMotionBall.cpp
66 66 deserialize.NumberFloat_Unbounded("speed z", m_SpeedZ); 67 67 } 68 68 69 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))69 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 70 70 { 71 71 switch (msg.GetType()) 72 72 { -
source/simulation2/components/CCmpObstruction.cpp
297 297 SerializeCommon(deserialize); 298 298 } 299 299 300 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))300 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 301 301 { 302 302 switch (msg.GetType()) 303 303 { -
source/simulation2/components/CCmpObstructionManager.cpp
215 215 m_UpdateInformations.dirtinessGrid = Grid<u8>(m_TerrainTiles*Pathfinding::NAVCELLS_PER_TILE, m_TerrainTiles*Pathfinding::NAVCELLS_PER_TILE); 216 216 } 217 217 218 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))218 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 219 219 { 220 220 switch (msg.GetType()) 221 221 { -
source/simulation2/components/CCmpOverlayRenderer.cpp
74 74 Init(paramNode); 75 75 } 76 76 77 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))77 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 78 78 { 79 79 switch (msg.GetType()) 80 80 { -
source/simulation2/components/CCmpOwnership.cpp
64 64 deserialize.NumberI32_Unbounded("owner", m_Owner); 65 65 } 66 66 67 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))67 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 68 68 { 69 69 switch (msg.GetType()) 70 70 { -
source/simulation2/components/CCmpParticleManager.cpp
60 60 Init(paramNode); 61 61 } 62 62 63 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))63 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberTypelobal)) 64 64 { 65 65 switch (msg.GetType()) 66 66 { -
source/simulation2/components/CCmpPathfinder.cpp
153 153 deserialize.NumberU16_Unbounded("same turn moves count", m_SameTurnMovesCount); 154 154 } 155 155 156 void CCmpPathfinder::HandleMessage(const CMessage& msg, bool UNUSED(global))156 void CCmpPathfinder::HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 157 157 { 158 158 switch (msg.GetType()) 159 159 { -
source/simulation2/components/CCmpPathfinder_Common.h
197 197 198 198 virtual void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize); 199 199 200 virtual void HandleMessage(const CMessage& msg, bool global);200 virtual void HandleMessage(const CMessage& msg, SubscriptionType subscriberType); 201 201 202 202 virtual pass_class_t GetPassabilityClass(const std::string& name); 203 203 -
source/simulation2/components/CCmpPosition.cpp
753 753 pos1.Y += GetConstructionProgressOffset(pos1); 754 754 } 755 755 756 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))756 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 757 757 { 758 758 switch (msg.GetType()) 759 759 { -
source/simulation2/components/CCmpProjectileManager.cpp
88 88 deserialize.NumberU32_Unbounded("next id", m_NextId); 89 89 } 90 90 91 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))91 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 92 92 { 93 93 switch (msg.GetType()) 94 94 { -
source/simulation2/components/CCmpRallyPointRenderer.cpp
212 212 Init(paramNode); 213 213 } 214 214 215 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))215 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 216 216 { 217 217 switch (msg.GetType()) 218 218 { -
source/simulation2/components/CCmpRangeManager.cpp
447 447 m_Deserializing = false; 448 448 } 449 449 450 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))450 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 451 451 { 452 452 switch (msg.GetType()) 453 453 { -
source/simulation2/components/CCmpSelectable.cpp
165 165 Init(paramNode); 166 166 } 167 167 168 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global));168 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)); 169 169 170 170 virtual void SetSelectionHighlight(const CColor& color, bool selected) 171 171 { … … 283 283 284 284 const double CCmpSelectable::FADE_DURATION = 0.3; 285 285 286 void CCmpSelectable::HandleMessage(const CMessage& msg, bool UNUSED(global))286 void CCmpSelectable::HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 287 287 { 288 288 switch (msg.GetType()) 289 289 { -
source/simulation2/components/CCmpTemplateManager.cpp
79 79 m_LatestTemplates[id] = mapEl.first; 80 80 } 81 81 82 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))82 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 83 83 { 84 84 switch (msg.GetType()) 85 85 { -
source/simulation2/components/CCmpTerritoryManager.cpp
162 162 deserialize.Bool("trigger event", m_TriggerEvent); 163 163 } 164 164 165 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))165 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 166 166 { 167 167 switch (msg.GetType()) 168 168 { -
source/simulation2/components/CCmpTest.cpp
70 70 return m_x; 71 71 } 72 72 73 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))73 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 74 74 { 75 75 switch (msg.GetType()) 76 76 { … … 84 84 m_x = 0; 85 85 break; 86 86 } 87 debug_printf("x is %i\n", m_x); 87 88 } 88 89 }; 89 90 … … 131 132 return m_x; 132 133 } 133 134 134 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))135 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 135 136 { 136 137 switch (msg.GetType()) 137 138 { … … 192 193 return m_x; 193 194 } 194 195 195 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))196 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 196 197 { 197 198 switch (msg.GetType()) 198 199 { -
source/simulation2/components/CCmpUnitMotion.cpp
371 371 m_PassClass = cmpPathfinder->GetPassabilityClass(m_PassClassName); 372 372 } 373 373 374 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))374 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 375 375 { 376 376 switch (msg.GetType()) 377 377 { -
source/simulation2/components/CCmpUnitRenderer.cpp
156 156 Init(paramNode); 157 157 } 158 158 159 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))159 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 160 160 { 161 161 switch (msg.GetType()) 162 162 { -
source/simulation2/components/CCmpVision.cpp
79 79 Init(paramNode); 80 80 } 81 81 82 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))82 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 83 83 { 84 84 switch (msg.GetType()) 85 85 { -
source/simulation2/components/CCmpVisualActor.cpp
284 284 } 285 285 } 286 286 287 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))287 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 288 288 { 289 289 // Quick exit for running in non-graphical mode 290 290 if (m_Unit == NULL) -
source/simulation2/components/CCmpWaterManager.cpp
69 69 deserialize.NumberFixed_Unbounded("height", m_WaterHeight); 70 70 } 71 71 72 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))72 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 73 73 { 74 74 switch (msg.GetType()) 75 75 { -
source/simulation2/components/tests/test_Position.h
89 89 90 90 // Latch new position for interpolation 91 91 CMessageTurnStart msg; 92 test.HandleMessage(cmp, msg, false);92 test.HandleMessage(cmp, msg, SubscriptionType::OWN); 93 93 94 94 // Move smoothly to new position 95 95 cmp->MoveTo(entity_pos_t::FromInt(400), entity_pos_t::FromInt(300)); -
source/simulation2/components/tests/test_RangeManager.h
102 102 103 103 cmp->SetBounds(entity_pos_t::FromInt(0), entity_pos_t::FromInt(0), entity_pos_t::FromInt(512), entity_pos_t::FromInt(512), 512/TERRAIN_TILE_SIZE + 1); 104 104 cmp->Verify(); 105 { CMessageCreate msg(100); cmp->HandleMessage(msg, false); }105 { CMessageCreate msg(100); cmp->HandleMessage(msg, SubscriptionType::OWN); } 106 106 cmp->Verify(); 107 { CMessageOwnershipChanged msg(100, -1, 1); cmp->HandleMessage(msg, false); }107 { CMessageOwnershipChanged msg(100, -1, 1); cmp->HandleMessage(msg, SubscriptionType::OWN); } 108 108 cmp->Verify(); 109 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(247), entity_pos_t::FromDouble(257.95), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }109 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(247), entity_pos_t::FromDouble(257.95), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 110 110 cmp->Verify(); 111 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(247), entity_pos_t::FromInt(253), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }111 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(247), entity_pos_t::FromInt(253), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 112 112 cmp->Verify(); 113 113 114 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }114 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 115 115 cmp->Verify(); 116 116 117 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256) +entity_pos_t::Epsilon(), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }117 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256) + entity_pos_t::Epsilon(), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 118 118 cmp->Verify(); 119 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256) -entity_pos_t::Epsilon(), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }119 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256) - entity_pos_t::Epsilon(), entity_pos_t::FromInt(256), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 120 120 cmp->Verify(); 121 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256) +entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }121 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256) + entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 122 122 cmp->Verify(); 123 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256) -entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }123 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256) - entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 124 124 cmp->Verify(); 125 125 126 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(383), entity_pos_t::FromInt(84), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }126 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(383), entity_pos_t::FromInt(84), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 127 127 cmp->Verify(); 128 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }128 { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 129 129 cmp->Verify(); 130 130 131 131 WELL512 rng; … … 133 133 { 134 134 double x = boost::uniform_real<>(0.0, 512.0)(rng); 135 135 double z = boost::uniform_real<>(0.0, 512.0)(rng); 136 { CMessagePositionChanged msg(100, true, entity_pos_t::FromDouble(x), entity_pos_t::FromDouble(z), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }136 { CMessagePositionChanged msg(100, true, entity_pos_t::FromDouble(x), entity_pos_t::FromDouble(z), entity_angle_t::Zero()); cmp->HandleMessage(msg, SubscriptionType::OWN); } 137 137 cmp->Verify(); 138 138 } 139 139 } -
source/simulation2/docs/CCmpExample.cpp
46 46 // ... 47 47 } 48 48 49 virtual void HandleMessage(const CMessage& msg, bool UNUSED(global))49 virtual void HandleMessage(const CMessage& msg, SubscriptionType UNUSED(subscriberType)) 50 50 { 51 51 // ... 52 52 } -
source/simulation2/MessageTypes.h
34 34 #define DEFAULT_MESSAGE_IMPL(name) \ 35 35 virtual int GetType() const { return MT_##name; } \ 36 36 virtual const char* GetScriptHandlerName() const { return "On" #name; } \ 37 virtual const char* GetScriptSubscribedHandlerName() const { return "OnSubscribed" #name; } \ 37 38 virtual const char* GetScriptGlobalHandlerName() const { return "OnGlobal" #name; } \ 38 39 virtual JS::Value ToJSVal(ScriptInterface& scriptInterface) const; \ 39 40 static CMessage* FromJSVal(ScriptInterface&, JS::HandleValue val); -
source/simulation2/scripting/ScriptComponent.cpp
53 53 m_ScriptInterface.CallFunctionVoid(m_Instance, "Deinit"); 54 54 } 55 55 56 void CComponentTypeScript::HandleMessage(const CMessage& msg, bool global)56 void CComponentTypeScript::HandleMessage(const CMessage& msg, SubscriptionType subscriberType) 57 57 { 58 58 JSContext* cx = m_ScriptInterface.GetContext(); 59 59 JSAutoRequest rq(cx); 60 60 61 const char* name = global ? msg.GetScriptGlobalHandlerName() : msg.GetScriptHandlerName(); 61 const char* name; 62 switch (subscriberType) 63 { 64 case SubscriptionType::OWN: 65 name = msg.GetScriptHandlerName(); 66 break; 67 case SubscriptionType::SUBSCRIBED: 68 name = msg.GetScriptSubscribedHandlerName(); 69 break; 70 case SubscriptionType::GLOBAL: 71 name = msg.GetScriptGlobalHandlerName(); 72 break; 73 default: 74 LOGERROR("Unknown message subscription type"); 75 return; 76 } 62 77 63 78 JS::RootedValue msgVal(cx, msg.ToJSValCached(m_ScriptInterface)); 64 79 -
source/simulation2/scripting/ScriptComponent.h
40 40 41 41 void Init(const CParamNode& paramNode, entity_id_t ent); 42 42 void Deinit(); 43 void HandleMessage(const CMessage& msg, bool global);43 void HandleMessage(const CMessage& msg, SubscriptionType subscriberType); 44 44 45 45 void Serialize(ISerializer& serialize); 46 46 void Deserialize(const CParamNode& paramNode, IDeserializer& deserialize, entity_id_t ent); -
source/simulation2/system/Component.h
72 72 { \ 73 73 m_Script.Deinit(); \ 74 74 } \ 75 virtual void HandleMessage(const CMessage& msg, bool global) \75 virtual void HandleMessage(const CMessage& msg, SubscriptionType subscriberType) \ 76 76 { \ 77 m_Script.HandleMessage(msg, global); \77 m_Script.HandleMessage(msg, subscriberType); \ 78 78 } \ 79 79 virtual void Serialize(ISerializer& serialize) \ 80 80 { \ -
source/simulation2/system/ComponentManager.cpp
40 40 virtual int GetType() const { return mtid; } 41 41 virtual const char* GetScriptHandlerName() const { return handlerName.c_str(); } 42 42 virtual const char* GetScriptGlobalHandlerName() const { return globalHandlerName.c_str(); } 43 virtual const char* GetScriptSubscribedHandlerName() const { return subscribedHandlerName.c_str(); } 43 44 virtual JS::Value ToJSVal(ScriptInterface& UNUSED(scriptInterface)) const { return msg.get(); } 44 45 45 46 CMessageScripted(ScriptInterface& scriptInterface, int mtid, const std::string& name, JS::HandleValue msg) : 46 mtid(mtid), handlerName("On" + name), globalHandlerName("OnGlobal" + name), msg(scriptInterface.GetJSRuntime(), msg) 47 mtid(mtid), handlerName("On" + name), subscribedHandlerName("OnSubscribed" + name), 48 globalHandlerName("OnGlobal" + name), msg(scriptInterface.GetJSRuntime(), msg) 47 49 { 48 50 } 49 51 50 52 int mtid; 51 53 std::string handlerName; 54 std::string subscribedHandlerName; 52 55 std::string globalHandlerName; 53 56 JS::PersistentRootedValue msg; 54 57 }; … … 79 82 m_ScriptInterface.RegisterFunction<IComponent*, int, int, CComponentManager::Script_QueryInterface> ("QueryInterface"); 80 83 m_ScriptInterface.RegisterFunction<std::vector<int>, int, CComponentManager::Script_GetEntitiesWithInterface> ("GetEntitiesWithInterface"); 81 84 m_ScriptInterface.RegisterFunction<std::vector<IComponent*>, int, CComponentManager::Script_GetComponentsWithInterface> ("GetComponentsWithInterface"); 82 m_ScriptInterface.RegisterFunction<void, int, int, JS::HandleValue, CComponentManager::Script_PostMessage> ("PostMessage"); 85 m_ScriptInterface.RegisterFunction<void, int, int, int, CComponentManager::Script_SubscribeToEntity>("SubscribeToEntity"); 86 m_ScriptInterface.RegisterFunction<void, int, int, int, CComponentManager::Script_UnsubscribeFromEntity>("UnsubscribeFromEntity"); 87 m_ScriptInterface.RegisterFunction<void, int, int, JS::HandleValue, CComponentManager::Script_PostMessage>("PostMessage"); 83 88 m_ScriptInterface.RegisterFunction<void, int, JS::HandleValue, CComponentManager::Script_BroadcastMessage> ("BroadcastMessage"); 84 89 m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddEntity> ("AddEntity"); 85 90 m_ScriptInterface.RegisterFunction<int, std::string, CComponentManager::Script_AddLocalEntity> ("AddLocalEntity"); … … 222 227 if (ctit != types.end()) 223 228 types.erase(ctit); 224 229 } 230 for (it = componentManager->m_SubscriberMessageSubscriptions.begin(); it != componentManager->m_SubscriberMessageSubscriptions.end(); ++it) 231 { 232 std::vector<ComponentTypeId>& types = it->second; 233 std::vector<ComponentTypeId>::iterator ctit = find(types.begin(), types.end(), cid); 234 if (ctit != types.end()) 235 types.erase(ctit); 236 } 225 237 for (it = componentManager->m_GlobalMessageSubscriptions.begin(); it != componentManager->m_GlobalMessageSubscriptions.end(); ++it) 226 238 { 227 239 std::vector<ComponentTypeId>& types = it->second; … … 277 289 { 278 290 std::string name = (*it).substr(2); // strip the "On" prefix 279 291 280 // Handle "OnGlobalFoo" functions specially281 bool isGlobal = false;282 if (name.substr(0, 6) == "Global")292 SubscriptionType subscriptionType = SubscriptionType::OWN; 293 294 if (name.substr(0, 10) == "Subscribed") 283 295 { 284 isGlobal = true; 296 subscriptionType = SubscriptionType::SUBSCRIBED; 297 name = name.substr(10); 298 } 299 else if (name.substr(0, 6) == "Global") 300 { 301 subscriptionType = SubscriptionType::GLOBAL; 285 302 name = name.substr(6); 286 303 } 287 304 … … 292 309 componentManager->m_ScriptInterface.ReportError(msg.c_str()); 293 310 return; 294 311 } 295 296 if (isGlobal) 312 313 if (subscriptionType == SubscriptionType::SUBSCRIBED) 314 componentManager->SubscribeOnSubscriptionToMessageType(mit->second); 315 else if (subscriptionType == SubscriptionType::GLOBAL) 297 316 componentManager->SubscribeGloballyToMessageType(mit->second); 298 317 else 299 318 componentManager->SubscribeToMessageType(mit->second); … … 439 458 } 440 459 } 441 460 461 void CComponentManager::Script_SubscribeToEntity(ScriptInterface::CxPrivate* pCxPrivate, int iid, int subscriber, int target) 462 { 463 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); 464 465 const SEntityComponentCache* entcache = componentManager->LookupEntityHandle(subscriber).GetComponentCache(); 466 467 if (iid >= entcache->numInterfaces || entcache->interfaces[iid] == NULL) 468 { 469 LOGWARNING("Interface %i of entity %i trying to subscribe to entity %i but there is no component for that interface", 470 iid, subscriber, target); 471 return; 472 } 473 IComponent* component = entcache->interfaces[iid]; 474 475 componentManager->SubscribeToEntity(component, target); 476 } 477 478 void CComponentManager::Script_UnsubscribeFromEntity(ScriptInterface::CxPrivate* pCxPrivate, int iid, int subscriber, int target) 479 { 480 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); 481 482 const SEntityComponentCache* entcache = componentManager->LookupEntityHandle(subscriber).GetComponentCache(); 483 484 if (iid >= entcache->numInterfaces || entcache->interfaces[iid] == NULL) 485 { 486 LOGWARNING("Interface %i of entity %i trying to unsubscribe from entity %i but there is no component for that interface", 487 iid, subscriber, target); 488 return; 489 } 490 IComponent* component = entcache->interfaces[iid]; 491 492 componentManager->UnsubscribeFromEntity(component, target); 493 } 494 442 495 void CComponentManager::Script_PostMessage(ScriptInterface::CxPrivate* pCxPrivate, int ent, int mtid, JS::HandleValue data) 443 496 { 444 497 CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); … … 577 630 std::sort(types.begin(), types.end()); // TODO: just sort once at the end of LoadComponents 578 631 } 579 632 633 void CComponentManager::SubscribeOnSubscriptionToMessageType(MessageTypeId mtid) 634 { 635 // TODO: verify mtid 636 ENSURE(m_CurrentComponent != CID__Invalid); 637 std::vector<ComponentTypeId>& types = m_SubscriberMessageSubscriptions[mtid]; 638 types.push_back(m_CurrentComponent); 639 std::sort(types.begin(), types.end()); // TODO: just sort once at the end of LoadComponents 640 } 641 580 642 void CComponentManager::SubscribeGloballyToMessageType(MessageTypeId mtid) 581 643 { 582 644 // TODO: verify mtid … … 586 648 std::sort(types.begin(), types.end()); // TODO: just sort once at the end of LoadComponents 587 649 } 588 650 651 void CComponentManager::SubscribeToEntity(IComponent* subscriber, entity_id_t target) 652 { 653 // [] operator calls the default constructor if it doesn't exist, resulting in an empty vector 654 // which is what we want in this case. 655 std::vector<IComponent*>& subscribers = m_SubscriptionsToEntities[target]; 656 657 if (ENTITY_IS_LOCAL(target)) 658 { 659 LOGWARNING("Component type %i of entity %i is trying to subscribe to local entity %i", 660 subscriber->GetComponentTypeId(), subscriber->GetEntityId(), target); 661 return; 662 } 663 664 // make sure we aren't already subscribed 665 if (std::find(subscribers.begin(), subscribers.end(), subscriber) != subscribers.end()) 666 { 667 LOGWARNING("Component type %i of entity %i trying to subscribe several times to messages of %i", 668 subscriber->GetComponentTypeId(), subscriber->GetEntityId(), target); 669 return; 670 } 671 672 m_SubscriptionsToEntitiesByComponent[subscriber].insert(target); 673 subscribers.push_back(subscriber); 674 } 675 void CComponentManager::UnsubscribeFromEntity(IComponent* subscriber, entity_id_t target) 676 { 677 auto subscribers = m_SubscriptionsToEntities.find(target); 678 679 if (subscribers == m_SubscriptionsToEntities.end()) 680 { 681 LOGWARNING("Component type %i of entity %i trying to unsubscribe from entity %i but hasnt subscribed", 682 subscriber->GetComponentTypeId(), subscriber->GetEntityId(), target); 683 return; 684 } 685 686 std::vector<IComponent*>::iterator subit = std::find(subscribers->second.begin(), subscribers->second.end(), subscriber); 687 if (subit == subscribers->second.end()) 688 { 689 LOGWARNING("Component type %i of entity %i trying to unsubscribe from entity %i but hasnt subscribed - 2", 690 subscriber->GetComponentTypeId(), subscriber->GetEntityId(), target); 691 return; 692 } 693 694 m_SubscriptionsToEntitiesByComponent[subscriber].erase(target); 695 696 std::swap(*subit, subscribers->second.back()); 697 subscribers->second.pop_back(); 698 } 699 589 700 void CComponentManager::FlattenDynamicSubscriptions() 590 701 { 591 702 std::map<MessageTypeId, CDynamicSubscription>::iterator it; … … 925 1036 std::map<entity_id_t, IComponent*>::iterator eit = iit->second.find(ent); 926 1037 if (eit != iit->second.end()) 927 1038 { 1039 m_SubscriptionsToEntitiesByComponent.erase(eit->second); 928 1040 eit->second->Deinit(); 929 1041 RemoveComponentDynamicSubscriptions(eit->second); 930 1042 m_ComponentTypesById[iit->first].dealloc(eit->second); … … 1001 1113 { 1002 1114 PROFILE2_IFSPIKE("Post Message", 0.0005); 1003 1115 PROFILE2_ATTR("%s", msg.GetScriptHandlerName()); 1004 // Send the message to components of ent, that subscribed locally to this message 1116 1117 // check that some components care about this message 1005 1118 std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator it; 1006 1119 it = m_LocalMessageSubscriptions.find(msg.GetType()); 1007 1120 if (it != m_LocalMessageSubscriptions.end()) 1008 1121 { 1009 std::vector<ComponentTypeId>::const_iterator ctit = it->second.begin();1010 for ( ; ctit != it->second.end(); ++ctit)1122 const SEntityComponentCache* entcache = LookupEntityHandle(ent).GetComponentCache(); 1123 for (const ComponentTypeId& ctype : it->second) 1011 1124 { 1012 // Find the component instances of this type (if any) 1013 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> >::const_iterator emap = m_ComponentsByTypeId.find(*ctit); 1014 if (emap == m_ComponentsByTypeId.end()) 1015 continue; 1125 std::map<ComponentTypeId, ComponentType>::const_iterator ctit = m_ComponentTypesById.find(ctype); 1016 1126 1017 // Send the message to all of them 1018 std::map<entity_id_t, IComponent*>::const_iterator eit = emap->second.find(ent); 1019 if (eit != emap->second.end()) 1020 eit->second->HandleMessage(msg, false); 1127 // send the message to the target entity components of that type if they exist 1128 if (entcache && entcache->interfaces[ctit->second.iid] != NULL) 1129 entcache->interfaces[ctit->second.iid]->HandleMessage(msg, SubscriptionType::OWN); 1021 1130 } 1022 1131 } 1023 1132 1133 SendSubscribedMessage(ent, msg); 1024 1134 SendGlobalMessage(ent, msg); 1025 1135 } 1026 1136 … … 1042 1152 // Send the message to all of them 1043 1153 std::map<entity_id_t, IComponent*>::const_iterator eit = emap->second.begin(); 1044 1154 for (; eit != emap->second.end(); ++eit) 1045 eit->second->HandleMessage(msg, false); 1155 { 1156 eit->second->HandleMessage(msg, SubscriptionType::OWN); 1157 } 1046 1158 } 1047 1159 } 1048 1160 1161 SendSubscribedMessage(INVALID_ENTITY, msg); 1049 1162 SendGlobalMessage(INVALID_ENTITY, msg); 1050 1163 } 1051 1164 1165 void CComponentManager::SendSubscribedMessage(entity_id_t ent, const CMessage& msg) 1166 { 1167 // find subscribers, ie components that listen to that entity 1168 std::unordered_map<entity_id_t, std::vector<IComponent*> >::const_iterator subscribers; 1169 subscribers = m_SubscriptionsToEntities.find(ent); 1170 bool hasSubscribers = subscribers != m_SubscriptionsToEntities.end(); 1171 if (!hasSubscribers) 1172 return; 1173 1174 // find component types that want this message 1175 std::map<MessageTypeId, std::vector<ComponentTypeId> >::const_iterator sit; 1176 sit = m_SubscriberMessageSubscriptions.find(msg.GetType()); 1177 if (sit == m_SubscriberMessageSubscriptions.end()) 1178 return; 1179 1180 // send it to them 1181 for (const ComponentTypeId& ctype : sit->second) 1182 { 1183 for (IComponent* subscriber : subscribers->second) 1184 { 1185 if (subscriber->GetComponentTypeId() != ctype) 1186 continue; 1187 subscriber->HandleMessage(msg, SubscriptionType::SUBSCRIBED); 1188 } 1189 } 1190 } 1191 1052 1192 void CComponentManager::SendGlobalMessage(entity_id_t ent, const CMessage& msg) 1053 1193 { 1054 1194 PROFILE2_IFSPIKE("SendGlobalMessage", 0.001); … … 1081 1221 // Send the message to all of them 1082 1222 std::map<entity_id_t, IComponent*>::const_iterator eit = emap->second.begin(); 1083 1223 for (; eit != emap->second.end(); ++eit) 1084 eit->second->HandleMessage(msg, true);1224 eit->second->HandleMessage(msg, SubscriptionType::GLOBAL); 1085 1225 } 1086 1226 } 1087 1227 … … 1092 1232 dit->second.Flatten(); 1093 1233 const std::vector<IComponent*>& dynamic = dit->second.GetComponents(); 1094 1234 for (size_t i = 0; i < dynamic.size(); i++) 1095 dynamic[i]->HandleMessage(msg, false);1235 dynamic[i]->HandleMessage(msg, SubscriptionType::OWN); 1096 1236 } 1097 1237 } 1098 1238 -
source/simulation2/system/ComponentManager.h
28 28 #include <boost/unordered_map.hpp> 29 29 30 30 #include <map> 31 #include <unordered_map> 31 32 32 33 class IComponent; 33 34 class CParamNode; … … 149 150 void SubscribeToMessageType(MessageTypeId mtid); 150 151 151 152 /** 153 * Subscribe the current component type to the given message type for subscribed entities 154 * Each component's HandleMessage will be called on any BroadcastMessage of this message type, 155 * or on any PostMessage of this type targeted at an entity this entity subscribes to. 156 * Must only be called by a component type's ClassInit. 157 */ 158 void SubscribeOnSubscriptionToMessageType(MessageTypeId mtid); 159 160 /** 152 161 * Subscribe the current component type to all messages of the given message type. 153 162 * Each component's HandleMessage will be called on any BroadcastMessage or PostMessage of this message type, 154 163 * regardless of the entity. … … 157 166 void SubscribeGloballyToMessageType(MessageTypeId mtid); 158 167 159 168 /** 169 * Allow an entity to receive messages about an entity. 170 * Called automatically by entities upon themselves on creation 171 * Can be called at anytime by an entity interested in another entity. 172 */ 173 void SubscribeToEntity(IComponent* subscriber, entity_id_t target); 174 175 void UnsubscribeFromEntity(IComponent* subscriber, entity_id_t target); 176 177 /** 160 178 * Subscribe the given component instance to all messages of the given message type. 161 179 * The component's HandleMessage will be called on any BroadcastMessage or PostMessage of 162 180 * this message type, regardless of the entity. … … 319 337 static IComponent* Script_QueryInterface(ScriptInterface::CxPrivate* pCxPrivate, int ent, int iid); 320 338 static std::vector<int> Script_GetEntitiesWithInterface(ScriptInterface::CxPrivate* pCxPrivate, int iid); 321 339 static std::vector<IComponent*> Script_GetComponentsWithInterface(ScriptInterface::CxPrivate* pCxPrivate, int iid); 340 static void Script_SubscribeToEntity(ScriptInterface::CxPrivate* pCxPrivate, int iid, int subscriber, int target); 341 static void Script_UnsubscribeFromEntity(ScriptInterface::CxPrivate* pCxPrivate, int iid, int subscriber, int target); 322 342 static void Script_PostMessage(ScriptInterface::CxPrivate* pCxPrivate, int ent, int mtid, JS::HandleValue data); 323 343 static void Script_BroadcastMessage(ScriptInterface::CxPrivate* pCxPrivate, int mtid, JS::HandleValue data); 324 344 static int Script_AddEntity(ScriptInterface::CxPrivate* pCxPrivate, const std::string& templateName); … … 334 354 static Status FindJSONFilesCallback(const VfsPath&, const CFileInfo&, const uintptr_t); 335 355 336 356 CMessage* ConstructMessage(int mtid, JS::HandleValue data); 357 void SendSubscribedMessage(entity_id_t ent, const CMessage& msg); 337 358 void SendGlobalMessage(entity_id_t ent, const CMessage& msg); 338 359 339 360 void FlattenDynamicSubscriptions(); … … 357 378 std::vector<boost::unordered_map<entity_id_t, IComponent*> > m_ComponentsByInterface; // indexed by InterfaceId 358 379 std::map<ComponentTypeId, std::map<entity_id_t, IComponent*> > m_ComponentsByTypeId; 359 380 std::map<MessageTypeId, std::vector<ComponentTypeId> > m_LocalMessageSubscriptions; 381 std::map<MessageTypeId, std::vector<ComponentTypeId> > m_SubscriberMessageSubscriptions; 360 382 std::map<MessageTypeId, std::vector<ComponentTypeId> > m_GlobalMessageSubscriptions; 361 383 std::map<std::string, ComponentTypeId> m_ComponentTypeIdsByName; 362 384 std::map<std::string, MessageTypeId> m_MessageTypeIdsByName; … … 363 385 std::map<MessageTypeId, std::string> m_MessageTypeNamesById; 364 386 std::map<std::string, InterfaceId> m_InterfaceIdsByName; 365 387 388 std::unordered_map<entity_id_t, std::vector<IComponent*> > m_SubscriptionsToEntities; 389 std::map<IComponent*, std::set<entity_id_t> > m_SubscriptionsToEntitiesByComponent; 390 366 391 std::map<MessageTypeId, CDynamicSubscription> m_DynamicMessageSubscriptionsNonsync; 367 392 std::map<IComponent*, std::set<MessageTypeId> > m_DynamicMessageSubscriptionsNonsyncByComponent; 368 393 -
source/simulation2/system/ComponentTest.h
109 109 m_ComponentManager.AddMockComponent(handle, iid, component); 110 110 } 111 111 112 void HandleMessage(IComponent* cmp, const CMessage& msg, bool global)112 void HandleMessage(IComponent* cmp, const CMessage& msg, SubscriptionType subscriberType) 113 113 { 114 cmp->HandleMessage(msg, global);114 cmp->HandleMessage(msg, subscriberType); 115 115 } 116 116 117 117 /** -
source/simulation2/system/IComponent.cpp
29 29 return "<empty/>"; 30 30 } 31 31 32 void IComponent::HandleMessage(const CMessage& UNUSED(msg), bool UNUSED(global))32 void IComponent::HandleMessage(const CMessage& UNUSED(msg), SubscriptionType UNUSED(subscriberType)) 33 33 { 34 34 } 35 35 -
source/simulation2/system/IComponent.h
30 30 class ISerializer; 31 31 class IDeserializer; 32 32 33 enum struct SubscriptionType 34 { 35 OWN, 36 SUBSCRIBED, 37 GLOBAL 38 }; 39 33 40 class IComponent 34 41 { 35 42 public: … … 40 47 virtual void Init(const CParamNode& paramNode) = 0; 41 48 virtual void Deinit() = 0; 42 49 43 virtual void HandleMessage(const CMessage& msg, bool global);50 virtual void HandleMessage(const CMessage& msg, SubscriptionType subscriptionType); 44 51 45 52 CEntityHandle GetEntityHandle() const { return m_EntityHandle; } 46 53 void SetEntityHandle(CEntityHandle ent) { m_EntityHandle = ent; } -
source/simulation2/system/Message.h
30 30 virtual ~CMessage() { } 31 31 virtual int GetType() const = 0; 32 32 virtual const char* GetScriptHandlerName() const = 0; 33 virtual const char* GetScriptSubscribedHandlerName() const = 0; 33 34 virtual const char* GetScriptGlobalHandlerName() const = 0; 34 35 virtual JS::Value ToJSVal(ScriptInterface&) const = 0; 35 36 JS::Value ToJSValCached(ScriptInterface&) const; -
source/simulation2/tests/test_ComponentManager.h
173 173 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent4, IID_Test1))->GetX(), 11000); 174 174 TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent4, IID_Test2))->GetX(), 21000); 175 175 176 debug_printf("sending mess\n"); 177 176 178 // Test_1A subscribed locally to msg1, nothing subscribed globally 177 179 man.PostMessage(ent1, msg1); 178 180 man.PostMessage(ent1, msg2); … … 482 484 { 483 485 CSimContext context; 484 486 CComponentManager man(context, g_ScriptRuntime); 487 485 488 man.LoadComponentTypes(); 486 489 TS_ASSERT(man.LoadScript(L"simulation/components/test-msg.js")); 487 490 491 man.ResetState(); 492 488 493 entity_id_t ent1 = 1, ent2 = 2, ent3 = 3; 489 494 CEntityHandle hnd1 = man.AllocateEntityHandle(ent1); 490 495 CEntityHandle hnd2 = man.AllocateEntityHandle(ent2); … … 497 502 man.AddComponent(hnd2, CID_Test2A, noParam); 498 503 man.AddComponent(hnd3, man.LookupCID("TestScript1B"), noParam); 499 504 505 debug_printf("ahajhtzrt"); 506 500 507 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 100); 501 508 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 100); 502 509 TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 21000); … … 505 512 // This GetX broadcasts messages 506 513 TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent1, IID_Test2))->GetX(), 200); 507 514 515 debug_printf("before"); 516 508 517 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent1, IID_Test1))->GetX(), 650); 509 518 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent2, IID_Test1))->GetX(), 5150); 510 519 TS_ASSERT_EQUALS(static_cast<ICmpTest2*> (man.QueryInterface(ent2, IID_Test2))->GetX(), 26050); 511 520 TS_ASSERT_EQUALS(static_cast<ICmpTest1*> (man.QueryInterface(ent3, IID_Test1))->GetX(), 5650); 521 debug_printf("ended"); 522 512 523 } 513 524 514 525 void test_script_template()