Viewports fixed. Damage HUD. Free steering fixed.
This commit is contained in:
@@ -9,9 +9,9 @@ namespace Components
|
||||
struct Health : Component
|
||||
{
|
||||
Health()
|
||||
: health(1.0f){ }
|
||||
: Amount(1.0f) { }
|
||||
|
||||
float health;
|
||||
float Amount;
|
||||
|
||||
virtual Health* Clone() const override { return new Health(*this); }
|
||||
};
|
||||
|
||||
+3
-3
@@ -5,13 +5,13 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct Damage : Event
|
||||
{
|
||||
EntityID Entity;
|
||||
float damage;
|
||||
float Amount;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // Events_Damage_h__
|
||||
+3
-2
@@ -36,8 +36,7 @@ public:
|
||||
|
||||
// Create a frame as a child
|
||||
Frame(Frame* parent, std::string name)
|
||||
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
|
||||
, m_Name(name)
|
||||
: m_Name(name)
|
||||
, m_Layer(0)
|
||||
{ SetParent(std::shared_ptr<Frame>(parent)); }
|
||||
|
||||
@@ -52,6 +51,8 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
Width = parent->Width;
|
||||
Height = parent->Height;
|
||||
m_Layer = parent->Layer() + 1;
|
||||
parent->AddChild(std::shared_ptr<Frame>(this));
|
||||
m_Parent = parent;
|
||||
|
||||
+9
-20
@@ -5,8 +5,7 @@
|
||||
#include "GUI/WorldFrame.h"
|
||||
#include "GUI/Viewport.h"
|
||||
#include "GUI/TextureFrame.h"
|
||||
|
||||
#include "Events/Damage.h"
|
||||
#include "GUI/PlayerHUD.h"
|
||||
|
||||
#include "GameWorld.h"
|
||||
|
||||
@@ -19,42 +18,32 @@ public:
|
||||
GameFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDamage, &GameFrame::OnDamage);
|
||||
|
||||
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
|
||||
auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
|
||||
{
|
||||
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
|
||||
vp1->X = 0;
|
||||
vp1->Width = 640;
|
||||
vp1->Height = 720 / 2;
|
||||
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
|
||||
|
||||
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
|
||||
vp2->X = vp1->Right();
|
||||
vp2->Width = 640;
|
||||
vp2->Height = 720 / 2;
|
||||
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
|
||||
|
||||
tex = new TextureFrame(vp1, "TextureFrameThingy");
|
||||
tex->SetTexture("Textures/GUI/hurt.png");
|
||||
auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World);
|
||||
vpc->Y = 720 / 2;
|
||||
vpc->Height = 720 / 2;
|
||||
}
|
||||
m_World->Initialize();
|
||||
}
|
||||
|
||||
void Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool OnDamage(const Events::Damage &event)
|
||||
{
|
||||
//tex->SetTexture("Textures/GUI/hurt.png");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
EventRelay<Frame, Events::Damage> m_EDamage;
|
||||
std::shared_ptr<GameWorld> m_World;
|
||||
Viewport* vp1;
|
||||
Viewport* vp2;
|
||||
TextureFrame* tex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef GUI_HealthOverlay_h__
|
||||
#define GUI_HealthOverlay_h__
|
||||
|
||||
#include "GUI/TextureFrame.h"
|
||||
#include "World.h"
|
||||
#include "Events/Damage.h"
|
||||
#include "Components/Player.h"
|
||||
#include "Components/Health.h"
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class HealthOverlay : public TextureFrame
|
||||
{
|
||||
public:
|
||||
HealthOverlay(Frame* parent, std::string name, std::shared_ptr<World> world, int playerID)
|
||||
: TextureFrame(parent, name)
|
||||
, m_World(world)
|
||||
, m_PlayerID(playerID)
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EDamage, &HealthOverlay::OnDamage);
|
||||
|
||||
SetTexture("Textures/GUI/hurt.png");
|
||||
SetColor(glm::vec4(0.f));
|
||||
}
|
||||
|
||||
bool OnDamage(const Events::Damage &event)
|
||||
{
|
||||
auto player = m_World->GetComponent<Components::Player>(event.Entity);
|
||||
if (!player)
|
||||
return false;
|
||||
|
||||
if (player->ID != m_PlayerID)
|
||||
return false;
|
||||
|
||||
auto health = m_World->GetComponent<Components::Health>(event.Entity);
|
||||
if (!health)
|
||||
return false;
|
||||
|
||||
SetColor(glm::vec4(1.f, 1.f, 1.f, 1 - health->Amount / 100.f));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<World> m_World;
|
||||
int m_PlayerID;
|
||||
EventRelay<Frame, Events::Damage> m_EDamage;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_TextureFrame_h__
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "GUI/Frame.h"
|
||||
#include "GUI/HealthOverlay.h"
|
||||
|
||||
#ifndef GUI_PlayerHUD_h__
|
||||
#define GUI_PlayerHUD_h__
|
||||
|
||||
namespace GUI
|
||||
{
|
||||
|
||||
class PlayerHUD : public Frame
|
||||
{
|
||||
public:
|
||||
PlayerHUD(Frame* parent, std::string name, std::shared_ptr<World> world, int playerID)
|
||||
: Frame(parent, name)
|
||||
, m_World(world)
|
||||
, m_PlayerID(playerID)
|
||||
{
|
||||
m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID);
|
||||
}
|
||||
|
||||
protected:
|
||||
std::shared_ptr<World> m_World;
|
||||
int m_PlayerID;
|
||||
|
||||
HealthOverlay* m_HealthOverlay;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // GUI_TextureFrame_h__
|
||||
+13
-4
@@ -11,7 +11,10 @@ class TextureFrame : public Frame
|
||||
{
|
||||
public:
|
||||
TextureFrame(Frame* parent, std::string name)
|
||||
: Frame(parent, name) { }
|
||||
: Frame(parent, name)
|
||||
, m_Texture(nullptr)
|
||||
, m_Color(glm::vec4(1.f, 1.f, 1.f, 1.f))
|
||||
{ }
|
||||
|
||||
void Draw(std::shared_ptr<Renderer> renderer) override
|
||||
{
|
||||
@@ -22,20 +25,26 @@ public:
|
||||
SpriteJob job;
|
||||
job.TextureID = m_Texture->ResourceID;
|
||||
job.Texture = *m_Texture;
|
||||
job.Color = m_Color;
|
||||
RenderQueue.Add(job);
|
||||
|
||||
renderer->SetCamera(nullptr);
|
||||
renderer->DrawFrame(RenderQueue);
|
||||
}
|
||||
|
||||
std::shared_ptr<::Texture> Texture() const { return m_Texture; }
|
||||
::Texture* Texture() const { return m_Texture; }
|
||||
void SetTexture(std::string resourceName)
|
||||
{
|
||||
m_Texture = std::shared_ptr<::Texture>(ResourceManager->Load<::Texture>("Texture", resourceName));
|
||||
m_Texture = ResourceManager->Load<::Texture>("Texture", resourceName);
|
||||
}
|
||||
|
||||
glm::vec4 Color() const { return m_Color; }
|
||||
void SetColor(glm::vec4 val) { m_Color = val; }
|
||||
|
||||
protected:
|
||||
std::shared_ptr<::Texture> m_Texture;
|
||||
::Texture* m_Texture;
|
||||
glm::vec4 m_Color;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+602
-1085
File diff suppressed because it is too large
Load Diff
@@ -57,6 +57,9 @@ public:
|
||||
|
||||
void Initialize();
|
||||
|
||||
EntityID CreateTank(int playerID);
|
||||
EntityID CreateJeep(int playerID);
|
||||
|
||||
void RegisterSystems() override;
|
||||
void AddSystems() override;
|
||||
void RegisterComponents() override;
|
||||
|
||||
+2
-2
@@ -30,10 +30,10 @@ struct ModelJob : RenderJob
|
||||
unsigned int ShaderID;
|
||||
unsigned int TextureID;
|
||||
|
||||
GLuint ShaderProgram;
|
||||
GLuint DiffuseTexture;
|
||||
GLuint NormalTexture;
|
||||
GLuint SpecularTexture;
|
||||
glm::vec4 Color;
|
||||
GLuint VAO;
|
||||
unsigned int StartIndex;
|
||||
unsigned int EndIndex;
|
||||
@@ -50,8 +50,8 @@ struct SpriteJob : RenderJob
|
||||
unsigned int ShaderID;
|
||||
unsigned int TextureID;
|
||||
|
||||
GLuint ShaderProgram;
|
||||
GLuint Texture;
|
||||
glm::vec4 Color;
|
||||
glm::mat4 ModelMatrix;
|
||||
|
||||
void CalculateHash() override
|
||||
|
||||
+5
-4
@@ -259,8 +259,8 @@ void Renderer::Draw(double dt)
|
||||
void Renderer::DrawFrame(RenderQueue &rq)
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
|
||||
glScissor(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
|
||||
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
|
||||
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
|
||||
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
|
||||
@@ -341,6 +341,7 @@ void Renderer::DrawFrame(RenderQueue &rq)
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(glm::mat4()));
|
||||
glUniform4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "Color"), 1, glm::value_ptr(spriteJob->Color));
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, spriteJob->Texture);
|
||||
@@ -362,8 +363,8 @@ void Renderer::DrawWorld(RenderQueue &rq)
|
||||
Base pass
|
||||
*/
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
|
||||
glViewport(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
|
||||
glScissor(m_Viewport.X, -m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
|
||||
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
|
||||
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
|
||||
//glViewport(0, 0, m_Width, m_Height);
|
||||
|
||||
// Clear G-buffer
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 430
|
||||
|
||||
uniform vec4 Color;
|
||||
|
||||
layout(binding=0) uniform sampler2D texture0;
|
||||
|
||||
in VertexData {
|
||||
@@ -14,5 +16,5 @@ void main() {
|
||||
// Texture
|
||||
vec4 texel = texture(texture0, Input.TextureCoord);
|
||||
|
||||
fragmentColor = texel;
|
||||
fragmentColor = texel * Color;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ void Systems::DamageSystem::Initialize()
|
||||
bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
|
||||
{
|
||||
auto health = m_World->GetComponent<Components::Health>(event.Entity);
|
||||
health->health -= event.damage;
|
||||
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->health);
|
||||
health->Amount -= event.Amount;
|
||||
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
|
||||
return true;
|
||||
}
|
||||
@@ -40,6 +40,7 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
|
||||
glm::quat mouseOrientationPitch = glm::quat(m_InputController->MouseOrientation * glm::vec3(1, 0, 0));
|
||||
glm::quat mouseOrientationYaw = glm::quat(m_InputController->MouseOrientation * glm::vec3(0, 1, 0));
|
||||
m_InputController->MouseOrientation = glm::vec3(0);
|
||||
|
||||
glm::vec3 controllerOrientationEuler = m_InputController->ControllerOrientation * (float)dt;
|
||||
glm::quat controllerOrientationPitch = glm::quat(controllerOrientationEuler * glm::vec3(1, 0, 0));
|
||||
@@ -53,8 +54,6 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
//---------------------------------------------------------------------
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS
|
||||
}
|
||||
|
||||
m_InputController->MouseOrientation = glm::vec3(0);
|
||||
}
|
||||
|
||||
bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
@@ -80,7 +79,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnCommand(const E
|
||||
}
|
||||
|
||||
// Mouse click
|
||||
else if (event.Command == "cam_attack")
|
||||
else if (event.Command == "cam_lock")
|
||||
{
|
||||
OrientationActive = event.Value > 0;
|
||||
|
||||
@@ -113,6 +112,7 @@ bool Systems::FreeSteeringSystem::FreeSteeringInputController::OnMouseMove(const
|
||||
if (OrientationActive)
|
||||
{
|
||||
MouseOrientation = -glm::vec3(event.DeltaY / 300.f, event.DeltaX / 300.f, 0.f);
|
||||
LOG_DEBUG("Mouse DX: %f", event.DeltaX);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -813,4 +813,4 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
|
||||
m_PhysicsWorld->setCollisionFilter(m_CollisionFilter);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
|
||||
{
|
||||
Events::Damage d;
|
||||
d.Entity = physicsEntity;
|
||||
d.damage = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
|
||||
d.Amount = (1.f - pow(distance / radius, 2)) * shellComponent->Damage;
|
||||
EventBroker->Publish(d);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +195,8 @@
|
||||
<ClInclude Include="..\..\src\GUI\Frame.h" />
|
||||
<ClInclude Include="..\..\src\EventBroker.h" />
|
||||
<ClInclude Include="..\..\src\GUI\GameFrame.h" />
|
||||
<ClInclude Include="..\..\src\GUI\HealthOverlay.h" />
|
||||
<ClInclude Include="..\..\src\GUI\PlayerHUD.h" />
|
||||
<ClInclude Include="..\..\src\GUI\WorldFrame.h" />
|
||||
<ClInclude Include="..\..\src\GUI\TextureFrame.h" />
|
||||
<ClInclude Include="..\..\src\GUI\Viewport.h" />
|
||||
|
||||
@@ -169,8 +169,7 @@
|
||||
</Filter>
|
||||
<Filter Include="Gameplay\Systems">
|
||||
<UniqueIdentifier>{3c2ea0e5-41a1-4b11-a891-1d59ead7223c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
||||
</Filter>
|
||||
<Filter Include="Rendering\Events">
|
||||
<UniqueIdentifier>{a025d51e-594d-4844-983b-f683726bf1bf}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -473,6 +472,12 @@
|
||||
<ClInclude Include="..\..\src\GUI\GameFrame.h">
|
||||
<Filter>GUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\GUI\HealthOverlay.h">
|
||||
<Filter>GUI</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\GUI\PlayerHUD.h">
|
||||
<Filter>GUI</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||
|
||||
Reference in New Issue
Block a user