Score should now track to all clients

This commit is contained in:
Tleety
2016-03-03 20:45:16 +01:00
parent 3e9ad7dc14
commit 00c585de3c
7 changed files with 1309 additions and 1123 deletions
+1
View File
@@ -34,6 +34,7 @@ private:
EntityWrapper Player = EntityWrapper::Invalid;
};
std::vector<int> m_DisconnectedIdentities;
int m_PlayerCounter = 0;
std::unordered_map<int, PlayerData> m_PlayerIdentities;
};
@@ -2,4 +2,5 @@
<ScoreScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ScoreScreen.xsd">
<TotalIdentities>0</TotalIdentities>
<NextPosition>0</NextPosition>
<Offset X="0.0" Y="0.0" Z="0.0"/>
</ScoreScreen>
@@ -11,6 +11,9 @@
<xs:element name="NextPosition" type="t:int" minOccurs="0">
<xs:annotation><xs:documentation>Where the next scoreIdentity should be placed.</xs:documentation></xs:annotation>
</xs:element>
<xs:element name="Offset" type="t:Vector" minOccurs="0">
<xs:annotation><xs:documentation>How much offset should be applied per position</xs:documentation></xs:annotation>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
File diff suppressed because it is too large Load Diff
+107
View File
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="ScoreBoardOrigin" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Position X="66.4319992" Y="37.9560013" Z="0"/>
<Orientation X="0" Y="4.71199989" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="Background_Main">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Scale X="60" Y="30" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="BlueSide">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="1" G="0.505882382" R="0"/>
</c:Model>
<c:Transform>
<Position X="16" Y="0" Z="0.5"/>
<Scale X="25" Y="28" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="RedSide">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
<Color A="1" B="0" G="0.219607845" R="1"/>
</c:Model>
<c:Transform>
<Position X="-16" Y="0" Z="0.5"/>
<Scale X="25" Y="28" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Background_Spectator">
<Components>
<c:Model>
<Resource>Models/Core/UnitCube.mesh</Resource>
</c:Model>
<c:Transform>
<Position X="0" Y="-20.5" Z="0"/>
<Scale X="20" Y="10" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ScoreBoard_Blue">
<Components>
<c:ScoreScreen>
<Offset X="0" Y="-2" Z="0"/>
</c:ScoreScreen>
<c:Team>
<Team>
<Blue/>
</Team>
</c:Team>
<c:Transform>
<Position X="16" Y="12" Z="1.5"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ScoreBoard_Red">
<Components>
<c:ScoreScreen>
<Offset X="0" Y="-2" Z="0"/>
</c:ScoreScreen>
<c:Team>
<Team>
<Red/>
</Team>
</c:Team>
<c:Transform>
<Position X="-16" Y="12" Z="1.5"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ScoreBoard_Spectators">
<Components>
<c:ScoreScreen>
<Offset X="0" Y="-1" Z="0"/>
</c:ScoreScreen>
<c:Team/>
<c:Transform>
<Position X="0" Y="-17.5" Z="1.5"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+7 -3
View File
@@ -635,9 +635,13 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
return true;
}
}
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup")
|| childEntity.HasComponent("AmmoPickup");
return childEntity.HasComponent("Player")
|| childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint")
|| childEntity.HasComponent("HealthPickup")
|| childEntity.HasComponent("AmmoPickup")
|| childEntity.HasComponent("ScoreScreen")
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
}
PlayerID Server::GetPlayerIDFromEndpoint()
+26 -6
View File
@@ -13,7 +13,6 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
{
//TODO: Check team al
if (!IsServer) {
return;
}
@@ -37,6 +36,8 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
auto children = entity.ChildrenWithComponent("ScoreIdentity");
float position = 0.f;
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
bool found = false;
@@ -45,20 +46,38 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
if (it->first == ID) {
if (it->second.Team != currentTeam) {
m_World->DeleteEntity(child.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
break;
}
for (auto it = m_DisconnectedIdentities.begin(); it != m_DisconnectedIdentities.end(); ++it) {
if (ID = *it) {
m_World->DeleteEntity(child.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
it = m_DisconnectedIdentities.erase(it);
break;
}
}
found = true;
//Update position for childs
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
(glm::vec3&) child["Transform"]["Position"] = offset * position;
position += 1.f;
break;
}
}
if(found == false) {
if(it->second.Team != currentTeam) {
//This player is not the same team as this scoreboard should show.
break;
continue;
}
//There is no entry for this player, create one.
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/ScoreIdentity.xml");
EntityWrapper scoreIdentity = entityFile->MergeInto(m_World);
glm::vec3 offset = (glm::vec3)entity["ScoreScreen"]["Offset"];
int newPosition = (int)entity["ScoreScreen"]["TotalIdentities"];
(glm::vec3&) scoreIdentity["Transform"]["Position"] = offset * (float)newPosition;
auto cScoreIdentity = scoreIdentity["ScoreIdentity"];
auto data = it->second;
@@ -67,12 +86,12 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
(int&)cScoreIdentity["Ping"] = 1337;
m_World->SetParent(scoreIdentity.ID, entity.ID);
(int&)entity["ScoreScreen"]["TotalIdentities"] += 1;
}
}
//For each scoreboard, go through children and see if they have all of the ones needed.
//Also need to take into account the order so they dont flicker.
//If they do not have all children we need to add them.
//Just add a new component to the scorescreen entity, the "ScoreIdentity" component.
//Local player should have an icon, compare with LocalPlayer somthing
}
bool ScoreScreenSystem::OnPlayerDeath(const Events::PlayerDeath& e)
@@ -113,6 +132,7 @@ bool ScoreScreenSystem::OnPlayerConnected(const Events::PlayerConnected& e)
bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e)
{
//player has disconnected, remove him from list of ScoreIdentities
m_DisconnectedIdentities.push_back(e.PlayerID);
m_PlayerIdentities.erase(e.PlayerID);
return 0;
}