HealthMeter

This commit is contained in:
viktorljung
2016-01-23 14:53:17 +01:00
parent 46dff1a59c
commit 680a12d88f
15 changed files with 286 additions and 57 deletions
+1 -1
Submodule assets updated: b6592dbb02...e8174f630f
+8 -1
View File
@@ -16,7 +16,7 @@
struct ModelJob : RenderJob struct ModelJob : RenderJob
{ {
ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialGroup matGroup, ComponentWrapper modelComponent, World* world) ModelJob(Model* model, Camera* camera, glm::mat4 matrix, ::RawModel::MaterialGroup matGroup, ComponentWrapper modelComponent, World* world, glm::vec4 fillColor, float fillPercentage)
: RenderJob() : RenderJob()
{ {
Model = model; Model = model;
@@ -33,6 +33,10 @@ struct ModelJob : RenderJob
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1)); glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z; Depth = worldpos.z;
World = world; World = world;
FillColor = fillColor;
FillPercentage = fillPercentage;
}; };
unsigned int TextureID; unsigned int TextureID;
@@ -50,6 +54,9 @@ struct ModelJob : RenderJob
unsigned int EndIndex = 0; unsigned int EndIndex = 0;
World* World; World* World;
glm::vec4 FillColor = glm::vec4(0);
float FillPercentage = 0.0;
void CalculateHash() override void CalculateHash() override
{ {
Hash = TextureID; Hash = TextureID;
+23
View File
@@ -0,0 +1,23 @@
#ifndef PlayerHUD_h__
#define PlayerHUD_h__
#include "../../Engine/Core/System.h"
#include "../../Engine/GLM.h"
#include "../../Engine/Rendering/ESetCamera.h"
#include <imgui/imgui.h>
class PlayerHUD : public ImpureSystem
{
public:
PlayerHUD(World* world, EventBroker* eventBrokerer);
~PlayerHUD();
virtual void Update(double dt) override;
private:
World* m_World;
EventBroker* m_EventBroker;
};
#endif
+2
View File
@@ -23,4 +23,6 @@
<xs:include schemaLocation="Components/Team.xsd"/> <xs:include schemaLocation="Components/Team.xsd"/>
<xs:include schemaLocation="Components/UniformScale.xsd"/> <xs:include schemaLocation="Components/UniformScale.xsd"/>
<xs:include schemaLocation="Components/EditorWidget.xsd"/> <xs:include schemaLocation="Components/EditorWidget.xsd"/>
<xs:include schemaLocation="Components/HealthHUD.xsd"/>
<xs:include schemaLocation="Components/Fill.xsd"/>
</xs:schema> </xs:schema>
+5
View File
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Fill xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Fill.xsd">
<Percentage>0.0</Percentage>
<Color R="1" G="1" B="1" A="1"/>
</Fill>
+14
View File
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Fill">
<xs:complexType>
<xs:all>
<xs:element name="Percentage" type="t:double" minOccurs="0"/>
<xs:element name="Color" type="t:Color" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Listener xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Listener.xsd"/>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="HealthHUD">
</xs:element>
</xs:schema>
+107 -46
View File
@@ -6,43 +6,136 @@
</Components> </Components>
<Children> <Children>
<Entity> <Entity name="Player">
<Components>
<c:Health>
<Health>69.990005493164063</Health>
</c:Health>
<c:Player/>
<c:Transform>
<Position X="0" Y="0" Z="2.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="Model">
<Components>
<c:Model>
<Resource>Models/Assault.obj</Resource>
</c:Model>
<c:Transform>
<Orientation X="0" Y="3.14159203" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Camera">
<Components> <Components>
<c:Camera> <c:Camera>
<Name>ActionCamera</Name> <FOV>80</FOV>
</c:Camera> </c:Camera>
<c:Model> <c:Model>
<Resource>Models/Camera.obj</Resource> <Resource>Models/Camera.obj</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="-0.504807115" Y="6.00582743" Z="9.68687439"/> <Position X="0" Y="1.39121652" Z="-0.043014247"/>
<Orientation X="-0.733036518" Y="0.000105090476" Z="5.12391125e-07"/> <Orientation X="6.28300047" Y="0" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
<Entity> <Entity name="HUD">
<Components> <Components>
<c:Text>
<Content>Camera #2</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>0</Alignment>
</c:Text>
<c:Transform> <c:Transform>
<Position X="0.700063765" Y="0.310270816" Z="-1"/> <Position X="0" Y="-0.000463247066" Z="-0.744767368"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/> </c:Transform>
</Components>
<Children>
<Entity name="Hexagon">
<Components>
<c:HealthHUD/>
<c:Fill>
<Percentage>0.69990003108978271</Percentage>
<Color A="0" B="0.699900031" G="0" R="0.300099969"/>
</c:Fill>
<c:Model>
<Resource>Models/Core/UnitHexagon.obj</Resource>
<Color A="0.313725501" B="0.70588237" G="0.70588237" R="0.70588237"/>
</c:Model>
<c:Transform>
<Position X="-0.287027329" Y="-0.282350302" Z="-1.52214652e-05"/>
<Scale X="0.200000003" Y="0.200000003" Z="0.5"/>
<Orientation X="0" Y="0.666000009" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="Hexagon2">
<Components>
<c:Model>
<Resource>Models/Core/UnitHexagon.obj</Resource>
<Color A="0.392156869" B="1" G="1" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.120033145" Y="0.0776480734" Z="-1.56768795e-06"/>
<Scale X="0.5" Y="0.5" Z="0.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="SelectedWeaponUI">
<Components>
<c:Model>
<Resource>Models/SecondaryWeapon.fbx</Resource>
<Color A="0.784313738" B="1" G="1" R="1"/>
</c:Model>
<c:Transform>
<Position X="-0.00400000019" Y="0.0138316695" Z="0.00813383237"/>
<Scale X="2" Y="2" Z="1"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
</Children> </Children>
</Entity> </Entity>
<Entity name="Hexagon3">
<Components>
<c:Model>
<Resource>Models/Core/UnitHexagon.obj</Resource>
<Color A="0.392156869" B="1" G="1" R="1"/>
</c:Model>
<c:Transform>
<Position X="0.119999997" Y="-0.0780000016" Z="0"/>
<Scale X="0.5" Y="0.5" Z="0.5"/>
</c:Transform>
</Components>
<Children>
<Entity name="UnselectedWeaponUI">
<Components>
<c:Model>
<Resource>Models/SecondaryWeapon.fbx</Resource>
<Color A="0.588235319" B="0" G="0" R="0"/>
</c:Model>
<c:Transform>
<Position X="-0.00400000019" Y="0.0136327185" Z="0.00800000038"/>
<Scale X="2" Y="2" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity> <Entity>
<Components> <Components>
<c:Model> <c:Model>
<Resource>Models/Core/UnitPlane.obj</Resource> <Resource>Models/Core/UnitPlane.obj</Resource>
</c:Model> </c:Model>
<c:Transform> <c:Transform>
<Position X="0" Y="-1" Z="0.600000024"/> <Position X="0" Y="-0.689623177" Z="0.600000024"/>
<Scale X="100" Y="1" Z="100"/> <Scale X="100" Y="1" Z="100"/>
</c:Transform> </c:Transform>
</Components> </Components>
@@ -79,7 +172,7 @@
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Position X="0" Y="2.37320328" Z="0"/> <Position X="0" Y="2.37320328" Z="0"/>
<Orientation X="0" Y="8252.15918" Z="0"/> <Orientation X="0" Y="14039.5469" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -198,38 +291,6 @@
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity>
<Components>
<c:Camera>
<Name>MainCamera</Name>
</c:Camera>
<c:Listener/>
<c:Model>
<Resource>Models/Camera.obj</Resource>
<Visible>false</Visible>
</c:Model>
<c:Transform>
<Position X="-1.27354908" Y="5.18422079" Z="10.6223917"/>
<Orientation X="-0.436328411" Y="-0.0523675606" Z="1.67869363e-08"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Text>
<Content>Taiwan #1</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>0</Alignment>
</c:Text>
<c:Transform>
<Position X="0.716896772" Y="0.296712071" Z="-1"/>
<Scale X="0.100000001" Y="0.100000001" Z="0.100000001"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
<Entity> <Entity>
<Components> <Components>
<c:DirectionalLight> <c:DirectionalLight>
+9
View File
@@ -6,6 +6,8 @@ uniform mat4 P;
uniform vec4 Color; uniform vec4 Color;
uniform vec2 ScreenDimensions; uniform vec2 ScreenDimensions;
uniform sampler2D texture0; uniform sampler2D texture0;
uniform vec4 FillColor;
uniform float FillPercentage;
#define TILE_SIZE 16 #define TILE_SIZE 16
@@ -133,6 +135,13 @@ void main()
//fragmentColor += Input.DiffuseColor; //fragmentColor += Input.DiffuseColor;
fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color; fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse + totalLighting.Specular) * texel * Color;
float pos = ((P * vec4(Input.Position, 1)).y + 1.0)/2.0;
if(pos <= FillPercentage) {
fragmentColor += FillColor;
}
//fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color; //fragmentColor += Input.DiffuseColor * (totalLighting.Diffuse) * texel * Color;
//fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1); //fragmentColor += Input.DiffuseColor + vec4(0.0, LightGrids.Data[currentTile].Amount/3, 0, 1);
//fragmentColor = texel * Input.DiffuseColor * Color; //fragmentColor = texel * Input.DiffuseColor * Color;
+1 -1
View File
@@ -48,7 +48,7 @@ void EditorRenderSystem::Update(double dt)
EntityWrapper entity(m_World, cModel.EntityID); EntityWrapper entity(m_World, cModel.EntityID);
glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World); glm::mat4 modelMatrix = Transform::ModelMatrix(entity.ID, entity.World);
for (auto matGroup : model->MaterialGroups()) { for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World); std::shared_ptr<ModelJob> modelJob = std::make_shared<ModelJob>(model, scene.Camera, modelMatrix, matGroup, cModel, entity.World, glm::vec4(0), 0.f);
scene.ForwardJobs.push_back(modelJob); scene.ForwardJobs.push_back(modelJob);
} }
} }
+4
View File
@@ -51,6 +51,10 @@ void DrawFinalPass::Draw(RenderScene& scene)
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); glUniform4fv(glGetUniformLocation(shaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform4fv(glGetUniformLocation(shaderHandle, "FillColor"), 1, glm::value_ptr(modelJob->FillColor));
glUniform1f(glGetUniformLocation(shaderHandle, "FillPercentage"), modelJob->FillPercentage);
if(modelJob->DiffuseTexture != nullptr) { if(modelJob->DiffuseTexture != nullptr) {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
+15 -3
View File
@@ -61,9 +61,21 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
} }
} }
float fillPercentage = 0.f;
glm::vec4 fillColor = glm::vec4(0);
if(m_World->HasComponent(modelComponent.EntityID, "Fill")) {
auto fillComponent = m_World->GetComponent(modelComponent.EntityID, "Fill");
fillPercentage = (float)(double)fillComponent["Percentage"];
fillColor = (glm::vec4)fillComponent["Color"];
}
glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, m_World); glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, m_World);
for (auto matGroup : model->MaterialGroups()) { for (auto matGroup : model->MaterialGroups()) {
std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, m_World)); std::shared_ptr<ModelJob> modelJob = std::shared_ptr<ModelJob>(new ModelJob(model, m_Camera, modelMatrix, matGroup, modelComponent, m_World, fillColor, fillPercentage));
jobs.push_back(modelJob); jobs.push_back(modelJob);
} }
} }
@@ -141,8 +153,8 @@ void RenderSystem::fillText(std::list<std::shared_ptr<RenderJob>>& jobs, World*
} }
glm::mat4 modelMatrix = Transform::ModelMatrix(textComponent.EntityID, world); glm::mat4 modelMatrix = Transform::ModelMatrix(textComponent.EntityID, world);
std::shared_ptr<TextJob> modelJob = std::shared_ptr<TextJob>(new TextJob(modelMatrix, font, textComponent)); std::shared_ptr<TextJob> textJob = std::shared_ptr<TextJob>(new TextJob(modelMatrix, font, textComponent));
jobs.push_back(modelJob); jobs.push_back(textJob);
} }
} }
+3
View File
@@ -10,6 +10,7 @@
#include "Core/EntityFileWriter.h" #include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h" #include "Game/Systems/WeaponSystem.h"
#include "Game/Systems/PlayerHUD.h"
Game::Game(int argc, char* argv[]) Game::Game(int argc, char* argv[])
{ {
@@ -86,6 +87,8 @@ Game::Game(int argc, char* argv[])
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<PlayerHUD>(updateOrderLevel);
// Collision and TriggerSystem should update after player. // Collision and TriggerSystem should update after player.
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);
+79
View File
@@ -0,0 +1,79 @@
#include "Game/Systems/PlayerHUD.h"
PlayerHUD::PlayerHUD(World* world, EventBroker* eventBrokerer)
:System(world, eventBrokerer)
, m_World(world)
, m_EventBroker(eventBrokerer)
{
}
PlayerHUD::~PlayerHUD()
{
//
}
void PlayerHUD::Update(double dt)
{
if(ImGui::Button("Set Camera", ImVec2(70, 20))){
auto cameras = m_World->GetComponents("Camera");
if(cameras == nullptr) {
return;
}
EntityWrapper ew = EntityWrapper(m_World, (*cameras->begin()).EntityID);
if (ew.Valid()) {
Events::SetCamera e;
e.CameraEntity = ew;
m_EventBroker->Publish(e);
} else {
LOG_INFO("Coulnd't find a camera");
}
}
auto healthHUDs = m_World->GetComponents("HealthHUD");
if (healthHUDs == nullptr) {
return;
}
for (auto& healthHUDComponent : *healthHUDs) {
EntityWrapper entity = EntityWrapper(m_World, healthHUDComponent.EntityID);
EntityWrapper entityIDParent = entity;
while (entityIDParent.Parent().Valid()) {
entityIDParent = entityIDParent.Parent();
if (entityIDParent.HasComponent("Health")) {
break;
}
}
if (entityIDParent.HasComponent("Health")) {
if (entity.HasComponent("Text")) {
std::string s = "";
s = s + std::to_string((int)(double)entityIDParent["Health"]["Health"]);
s = s + "/";
s = s + std::to_string((int)(double)entityIDParent["Health"]["MaxHealth"]);
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"];
(glm::vec4&) entity["Text"]["Color"] = glm::vec4(1.0 - healthPercentage, healthPercentage, 0.f, 0.f);
entity["Text"]["Content"] = s;
}
if(entity.HasComponent("Fill")) {
float healthPercentage = (double)entityIDParent["Health"]["Health"]/(double)entityIDParent["Health"]["MaxHealth"];
(glm::vec4&)entity["Fill"]["Color"] = glm::vec4(1.0 - healthPercentage, 0.f, healthPercentage, 0.f);
(double&)entity["Fill"]["Percentage"] = healthPercentage;
}
}
}
}