Score should now track to all clients
This commit is contained in:
@@ -34,6 +34,7 @@ private:
|
|||||||
EntityWrapper Player = EntityWrapper::Invalid;
|
EntityWrapper Player = EntityWrapper::Invalid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::vector<int> m_DisconnectedIdentities;
|
||||||
int m_PlayerCounter = 0;
|
int m_PlayerCounter = 0;
|
||||||
std::unordered_map<int, PlayerData> m_PlayerIdentities;
|
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">
|
<ScoreScreen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ScoreScreen.xsd">
|
||||||
<TotalIdentities>0</TotalIdentities>
|
<TotalIdentities>0</TotalIdentities>
|
||||||
<NextPosition>0</NextPosition>
|
<NextPosition>0</NextPosition>
|
||||||
|
<Offset X="0.0" Y="0.0" Z="0.0"/>
|
||||||
</ScoreScreen>
|
</ScoreScreen>
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
<xs:element name="NextPosition" type="t:int" minOccurs="0">
|
<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:annotation><xs:documentation>Where the next scoreIdentity should be placed.</xs:documentation></xs:annotation>
|
||||||
</xs:element>
|
</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:all>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|||||||
+1164
-1114
File diff suppressed because it is too large
Load Diff
@@ -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>
|
||||||
@@ -635,9 +635,13 @@ bool Server::shouldSendToClient(EntityWrapper childEntity)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return childEntity.HasComponent("Player") || childEntity.FirstParentWithComponent("Player").Valid()
|
return childEntity.HasComponent("Player")
|
||||||
|| childEntity.HasComponent("CapturePoint") || childEntity.HasComponent("HealthPickup")
|
|| childEntity.FirstParentWithComponent("Player").Valid()
|
||||||
|| childEntity.HasComponent("AmmoPickup");
|
|| childEntity.HasComponent("CapturePoint")
|
||||||
|
|| childEntity.HasComponent("HealthPickup")
|
||||||
|
|| childEntity.HasComponent("AmmoPickup")
|
||||||
|
|| childEntity.HasComponent("ScoreScreen")
|
||||||
|
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerID Server::GetPlayerIDFromEndpoint()
|
PlayerID Server::GetPlayerIDFromEndpoint()
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ ScoreScreenSystem::ScoreScreenSystem(SystemParams params)
|
|||||||
|
|
||||||
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
|
void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& capturePoint, double dt)
|
||||||
{
|
{
|
||||||
//TODO: Check team al
|
|
||||||
if (!IsServer) {
|
if (!IsServer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -37,6 +36,8 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
|
|||||||
|
|
||||||
auto children = entity.ChildrenWithComponent("ScoreIdentity");
|
auto children = entity.ChildrenWithComponent("ScoreIdentity");
|
||||||
|
|
||||||
|
float position = 0.f;
|
||||||
|
|
||||||
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
|
for (auto it = m_PlayerIdentities.begin(); it != m_PlayerIdentities.end(); ++it) {
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@@ -45,20 +46,38 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
|
|||||||
if (it->first == ID) {
|
if (it->first == ID) {
|
||||||
if (it->second.Team != currentTeam) {
|
if (it->second.Team != currentTeam) {
|
||||||
m_World->DeleteEntity(child.ID);
|
m_World->DeleteEntity(child.ID);
|
||||||
|
(int&)entity["ScoreScreen"]["TotalIdentities"] -= 1;
|
||||||
break;
|
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;
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(found == false) {
|
if(found == false) {
|
||||||
if(it->second.Team != currentTeam) {
|
if(it->second.Team != currentTeam) {
|
||||||
//This player is not the same team as this scoreboard should show.
|
//This player is not the same team as this scoreboard should show.
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
//There is no entry for this player, create one.
|
//There is no entry for this player, create one.
|
||||||
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/ScoreIdentity.xml");
|
auto entityFile = ResourceManager::Load<EntityFile>("Schema/Entities/ScoreIdentity.xml");
|
||||||
EntityWrapper scoreIdentity = entityFile->MergeInto(m_World);
|
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 cScoreIdentity = scoreIdentity["ScoreIdentity"];
|
||||||
auto data = it->second;
|
auto data = it->second;
|
||||||
|
|
||||||
@@ -67,12 +86,12 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
|
|||||||
(int&)cScoreIdentity["Ping"] = 1337;
|
(int&)cScoreIdentity["Ping"] = 1337;
|
||||||
|
|
||||||
m_World->SetParent(scoreIdentity.ID, entity.ID);
|
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.
|
//Local player should have an icon, compare with LocalPlayer somthing
|
||||||
//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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScoreScreenSystem::OnPlayerDeath(const Events::PlayerDeath& e)
|
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)
|
bool ScoreScreenSystem::OnPlayerDisconnected(const Events::PlayerDisconnected& e)
|
||||||
{
|
{
|
||||||
//player has disconnected, remove him from list of ScoreIdentities
|
//player has disconnected, remove him from list of ScoreIdentities
|
||||||
|
m_DisconnectedIdentities.push_back(e.PlayerID);
|
||||||
m_PlayerIdentities.erase(e.PlayerID);
|
m_PlayerIdentities.erase(e.PlayerID);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user