Merge remote-tracking branch 'origin/master' into Weapons

# Conflicts:
#	assets
#	resources/Schema/Entities/Player.xml
#	resources/Schema/Entities/PlayerAssaultFallbackBlue.xml
#	resources/Schema/Entities/PlayerAssaultFallbackRed.xml
#	resources/Schema/Entities/PlayerAssaultRed.xml
#	resources/Schema/Entities/aaaatestremoveme.xml
#	resources/Schema/Entities/aim_rays.xml
This commit is contained in:
2016-03-09 15:52:13 +01:00
76 changed files with 10364 additions and 7770 deletions
+2 -2
View File
@@ -40,7 +40,7 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e)
//You have clicked on a button entity, send pressed event.
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.PlayerID = -1;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
@@ -68,7 +68,7 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e)
if (m_World->HasComponent(m_PickData.Entity, "InputCmdButton")) {
Events::InputCommand eInputCmd;
eInputCmd.PlayerID = LocalPlayer.ID;
eInputCmd.PlayerID = -1;
eInputCmd.Player = LocalPlayer;
EntityWrapper button = EntityWrapper(m_World, m_PickData.Entity);
eInputCmd.Command = (std::string)button["InputCmdButton"]["Command"];
-57
View File
@@ -1,57 +0,0 @@
#include "GUI/MainMenuSystem.h"
MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
: System(params)
, ImpureSystem()
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
}
void MainMenuSystem::Update(double dt)
{
}
bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
{
if(e.EntityName == "Play") {
//Run play code
} else if(e.EntityName == "Connect") {
//Run connect code
} else if(e.EntityName == "Host") {
//Run host code
} else if(e.EntityName == "Quit") {
printf("No, you stay");
} else if (e.EntityName == "Res1080") {
glfwSetWindowSize(m_Renderer->Window(), 1920, 1080);
printf("\n1080");
} else if (e.EntityName == "Res720") {
glfwSetWindowSize(m_Renderer->Window(), 1280, 720);
glViewport(0, 0, 1280, 720);
printf("\n720");
} else if (e.EntityName == "Res480") {
glfwSetWindowSize(m_Renderer->Window(), 854, 480);
glViewport(0, 0, 854, 480);
printf("\n480");
} else if (e.EntityName == "FullScreen") {
printf("No fullscreen for now");
}
return true;
}
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
{
return true;
}
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
{
return true;
}
+4 -8
View File
@@ -82,7 +82,10 @@ void Client::Update()
if (m_SearchingForServers) {
if (m_SearchingTime < (1000* (std::clock() - m_StartSearchTime) / (double)CLOCKS_PER_SEC)) {
m_SearchingForServers = false;
displayServerlist();
//displayServerlist();
Events::DisplayServerlist e;
e.Serverlist = m_Serverlist;
m_EventBroker->Publish(e);
}
}
@@ -463,12 +466,6 @@ void Client::disconnect()
bool Client::OnInputCommand(const Events::InputCommand & e)
{
// TEMP
if (e.Command == "SearchForServers" && e.Value > 0) {
Events::SearchForServers e;
m_EventBroker->Publish(e);
}
if (e.PlayerID != -1) {
return false;
}
@@ -553,7 +550,6 @@ bool Client::OnSearchForServers(const Events::SearchForServers& e)
m_SearchingForServers = true;
m_StartSearchTime = std::clock();
m_Serverlist.clear();
LOG_INFO("Searching for LAN servers...\n");
Packet packet(MessageType::ServerlistRequest);
m_ServerlistRequest.Broadcast(packet, 13); // TODO: Config
return true;
+3 -17
View File
@@ -162,7 +162,7 @@ void Server::unreliableBroadcast(Packet& packet)
{
for (auto& kv : m_ConnectedPlayers) {
packet.ChangePacketID(kv.second.PacketID);
// m_Unreliable.Send(packet, kv.second);
// m_Unreliable.Send(packet, kv.second);
}
}
@@ -641,21 +641,7 @@ void Server::parsePlayerTransform(Packet& packet)
bool Server::shouldSendToClient(EntityWrapper childEntity)
{
auto children = m_World->GetDirectChildren(childEntity.ID);
for (auto it = children.first; it != children.second; it++) {
EntityWrapper child(m_World, it->second);
if (child.HasComponent("CapturePoint") || child.HasComponent("HealthPickup")
|| child.HasComponent("AmmoPickup")) {
return true;
}
}
return childEntity.HasComponent("Player")
|| childEntity.FirstParentWithComponent("Player").Valid()
|| childEntity.HasComponent("CapturePoint")
|| childEntity.HasComponent("HealthPickup")
|| childEntity.HasComponent("AmmoPickup")
|| childEntity.HasComponent("ScoreScreen")
|| childEntity.FirstParentWithComponent("ScoreScreen").Valid();
return childEntity.HasComponent("NetworkComponent") || childEntity.FirstParentWithComponent("NetworkComponent").Valid();
}
PlayerID Server::getPlayerIDFromEndpoint()
@@ -674,7 +660,7 @@ PlayerID Server::getPlayerIDFromEndpoint()
PlayerID Server::getPlayerIDFromEntityID(EntityID entityID)
{
for(auto& kv : m_ConnectedPlayers) {
for (auto& kv : m_ConnectedPlayers) {
if (entityID == kv.second.EntityID) {
return kv.first;
}
+282
View File
@@ -0,0 +1,282 @@
#include "Rendering/BlurHUD.h"
BlurHUD::BlurHUD(IRenderer* renderer)
: m_Renderer(renderer)
{
InitializeShaderPrograms();
InitializeBuffers();
InitializeTextures();
}
void BlurHUD::InitializeTextures()
{
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
}
void BlurHUD::InitializeShaderPrograms()
{
m_GaussianProgram_horiz = ResourceManager::Load<ShaderProgram>("##GaussianProgramHoriz");
if (m_GaussianProgram_horiz->GetHandle() == 0) {
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_horiz.vert.glsl")));
m_GaussianProgram_horiz->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_horiz.frag.glsl")));
m_GaussianProgram_horiz->Compile();
m_GaussianProgram_horiz->BindFragDataLocation(0, "fragmentColor");
m_GaussianProgram_horiz->Link();
}
m_GaussianProgram_vert = ResourceManager::Load<ShaderProgram>("##GaussianProgramVert");
if (m_GaussianProgram_vert->GetHandle() == 0) {
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Gaussian_vert.vert.glsl")));
m_GaussianProgram_vert->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Gaussian_vert.frag.glsl")));
m_GaussianProgram_vert->Compile();
m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor");
m_GaussianProgram_vert->Link();
}
m_FillDepthStencilProgram = ResourceManager::Load<ShaderProgram>("#FillDepthStencilProgram");
if (m_FillDepthStencilProgram->GetHandle() == 0) {
m_FillDepthStencilProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBuffer.vert.glsl")));
m_FillDepthStencilProgram->Compile();
m_FillDepthStencilProgram->Link();
}
m_CombineTexturesProgram = ResourceManager::Load<ShaderProgram>("#CombineTexturesProgram");
if (m_CombineTexturesProgram->GetHandle() == 0) {
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CombineTexture.vert.glsl")));
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CombineTexture.frag.glsl")));
m_CombineTexturesProgram->Compile();
m_CombineTexturesProgram->BindFragDataLocation(0, "sceneColor");
m_CombineTexturesProgram->BindFragDataLocation(1, "bloomColor");
m_CombineTexturesProgram->Link();
}
GLERROR("Creating DepthFill program");
}
void BlurHUD::InitializeBuffers()
{
glm::vec2 res = glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glm::vec2 res2 = glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
CommonFunctions::GenerateTexture(&m_DepthStencil_horiz, GL_CLAMP_TO_BORDER, GL_NEAREST,
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_horiz, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_horiz.Generate();
CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_vert, GL_DEPTH_STENCIL_ATTACHMENT)));
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_vert.Generate();
CommonFunctions::GenerateTexture(&m_CombinedTexture, GL_CLAMP_TO_BORDER, GL_NEAREST,
res, GL_RGB16F, GL_RGB, GL_FLOAT);
if (m_CombinedTextureBuffer.GetHandle() == 0) {
m_CombinedTextureBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_CombinedTexture, GL_COLOR_ATTACHMENT0)));
}
m_CombinedTextureBuffer.Generate();
}
void BlurHUD::ClearBuffer()
{
GLERROR("PRE");
m_GaussianFrameBuffer_horiz.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_horiz.Unbind();
m_GaussianFrameBuffer_vert.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_vert.Unbind();
m_CombinedTextureBuffer.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT);
m_CombinedTextureBuffer.Unbind();
GLERROR("END");
}
//Returns the finished blurred texture
GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
{
GLERROR("DrawBloomPass::Draw: Pre");
FillStencil(scene);
RenderState state;
state.Disable(GL_BLEND);
state.Disable(GL_DEPTH_TEST);
state.Disable(GL_CULL_FACE);
state.Enable(GL_STENCIL_TEST);
state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
state.Enable(GL_SCISSOR_TEST);
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle();
//Horizontal pass, first use the given texture then save it to the horizontal framebuffer.
m_GaussianFrameBuffer_horiz.Bind();
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//Iterate some times to make it more gaussian.
for (int i = 1; i < m_Iterations; i++) {
//Vertical pass
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//horizontal pass
m_GaussianFrameBuffer_vert.Unbind();
m_GaussianFrameBuffer_horiz.Bind();
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
m_GaussianFrameBuffer_horiz.Unbind();
}
//final vertical gaussian after the iterations are done
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_horiz);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
GLERROR("DrawBloomPass::Draw: END");
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
return m_GaussianTexture_vert;
}
void BlurHUD::OnWindowResize()
{
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.Generate();
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.Generate();
}
void BlurHUD::FillStencil(RenderScene& scene)
{
RenderState state;
state.BindFramebuffer(m_GaussianFrameBuffer_horiz.GetHandle());
state.Disable(GL_DEPTH_TEST);
state.Enable(GL_CULL_FACE);
state.Enable(GL_STENCIL_TEST);
state.StencilFunc(GL_ALWAYS, 1, 0xFF);
state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.StencilMask(0xFF);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
m_FillDepthStencilProgram->Bind();
GLuint shaderHandle = m_FillDepthStencilProgram->GetHandle();
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob) {
continue;
}
if (!spriteJob->BlurBackground) {
continue;
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
state.BindFramebuffer(m_GaussianFrameBuffer_vert.GetHandle());
for (auto& job : scene.Jobs.SpriteJob) {
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (!spriteJob) {
continue;
}
if(!spriteJob->BlurBackground) {
continue;
}
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(spriteJob->Matrix));
glBindVertexArray(spriteJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
}
//Texture 1 will be used if texture 2 is black at that texel, else texture 2 is used.
GLuint BlurHUD::CombineTextures(GLuint texture1, GLuint texture2)
{
//RenderState state;
//state.BindFramebuffer(m_CombinedTextureBuffer.GetHandle());
//state.Disable(GL_DEPTH_TEST);
//state.Disable(GL_STENCIL_TEST);
m_CombineTexturesProgram->Bind();
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture1);
glBindTexture(GL_TEXTURE_2D, texture2);
glBindVertexArray(m_ScreenQuad->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
return m_CombinedTexture;
}
@@ -50,13 +50,15 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
glm::vec4 perspective;
glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);
glm::vec3 angles = glm::vec3(-glm::pitch(rotation), -glm::yaw(rotation), -glm::roll(rotation));
rotation = glm::quat((glm::vec3)entity["BoneAttachment"]["OrientationOffset"]) * rotation;
rotation = glm::inverse(rotation);
glm::vec3 angles = glm::eulerAngles(rotation);
if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
(glm::vec3&)entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
}
if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
(glm::vec3&)entity["Transform"]["Orientation"] = angles + (glm::vec3)entity["BoneAttachment"]["OrientationOffset"];
(glm::vec3&)entity["Transform"]["Orientation"] = angles;
}
if ((bool)entity["BoneAttachment"]["InheritScale"]) {
(glm::vec3&)entity["Transform"]["Scale"] = scale * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
+18 -2
View File
@@ -233,7 +233,7 @@ void DrawFinalPass::InitializeShaderPrograms()
}
void DrawFinalPass::Draw(RenderScene& scene)
void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
{
GLERROR("Pre");
DrawFinalPassState* stateDethp = new DrawFinalPassState(m_ShieldDepthFrameBuffer.GetHandle());
@@ -280,16 +280,32 @@ void DrawFinalPass::Draw(RenderScene& scene)
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
GLERROR("Shielded Transparent objects");
//Generate blur texture.
delete state;
if (scene.ShouldBlur) {
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
}
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete state;
delete stateSprite;
GLERROR("END");
}
+1
View File
@@ -435,6 +435,7 @@ void RenderSystem::Update(double dt)
}
RenderScene scene;
scene.ShouldBlur = true;
scene.Camera = m_Camera;
scene.Viewport = Rectangle(1280, 720);
+11 -3
View File
@@ -110,7 +110,7 @@ void Renderer::Draw(RenderFrame& frame)
{
GLERROR("PRE");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion");
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking\0Ambient Occlusion\0Combined Scene Texture\0Full Blurred Texture");
ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)");
if(m_CubeMapTexture == 0) {
m_CubeMapPass->LoadTextures("Nevada");
@@ -133,6 +133,7 @@ void Renderer::Draw(RenderFrame& frame)
m_DrawFinalPass->ClearBuffer();
m_DrawBloomPass->ClearBuffer();
m_SSAOPass->ClearBuffer();
m_BlurHUDPass->ClearBuffer();
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
GLERROR("ClearBuffers");
for (auto scene : frame.RenderScenes) {
@@ -158,7 +159,7 @@ void Renderer::Draw(RenderFrame& frame)
m_LightCullingPass->CullLights(*scene);
GLERROR("LightCulling");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
m_DrawFinalPass->Draw(*scene);
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene);
@@ -194,6 +195,12 @@ void Renderer::Draw(RenderFrame& frame)
if (m_DebugTextureToDraw == 5) {
m_DrawScreenQuadPass->Draw(m_SSAOPass->SSAOTexture());
}
if (m_DebugTextureToDraw == 6) {
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->CombinedSceneTexture());
}
if (m_DebugTextureToDraw == 7) {
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->FullBlurredTexture());
}
PerformanceTimer::StopTimer("Renderer-Misc Debug Draws");
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
@@ -244,9 +251,10 @@ void Renderer::InitializeRenderPasses()
m_LightCullingPass = new LightCullingPass(this);
m_CubeMapPass = new CubeMapPass(this);
m_SSAOPass = new SSAOPass(this, m_Config);
m_BlurHUDPass = new BlurHUD(this);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass);
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
}
+5 -8
View File
@@ -35,8 +35,10 @@
#include "Game/Systems/BoostSystem.h"
#include "Game/Systems/BoostIconsHUDSystem.h"
#include "Game/Systems/ScoreScreenSystem.h"
#include "Game/Systems/SpectatorCameraSystem.h"
#include "GUI/ButtonSystem.h"
#include "GUI/MainMenuSystem.h"
#include "Game/Systems/MainMenuSystem.h"
#include "Game/Systems/ServerListSystem.h"
Game::Game(int argc, char* argv[])
@@ -137,25 +139,20 @@ Game::Game(int argc, char* argv[])
m_SystemPipeline->AddSystem<LifetimeSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<AbilityCooldownHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointArrowHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<CapturePointHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<PickupSpawnSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<AmmoPickupSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<DamageIndicatorSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<TextFieldReader>(updateOrderLevel);
m_SystemPipeline->AddSystem<KillFeedSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<BoostSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ButtonSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<MainMenuSystem>(updateOrderLevel, m_Renderer);
m_SystemPipeline->AddSystem<BoostIconsHUDSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ScoreScreenSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<SpectatorCameraSystem>(updateOrderLevel);
m_SystemPipeline->AddSystem<ServerListSystem>(updateOrderLevel, m_Renderer);
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem<FillOctreeSystem>(updateOrderLevel, m_OctreeCollision, "Collidable");
+59 -10
View File
@@ -11,23 +11,72 @@ void AbilityCooldownHUDSystem::Update(double dt)
for (auto& abilityHUDC : *abilityHUDs) {
EntityWrapper entity = EntityWrapper(m_World, abilityHUDC.EntityID);
EntityWrapper abilityEntity = entity.FirstParentWithComponent("DashAbility");
if (!abilityEntity.Valid())
return;
EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown");
std::string abilityName = "";
double maxAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownMaxTimer"];
double currentAbilityCD = (double)abilityEntity["DashAbility"]["CoolDownTimer"];
if (!abilityEntity.Valid()) {
//If we dont have a dash ability on player, we check for Sprint ability
abilityEntity = entity.FirstParentWithComponent("SprintAbility");
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
if (!abilityEntity.Valid()) {
//If we dont have a sprint ability on player, we check for shield ability
abilityEntity = entity.FirstParentWithComponent("ShieldAbility");
if(cooldownTextEntity.Valid()) {
if(cooldownTextEntity.HasComponent("Text"))
{
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
if (!abilityEntity.Valid()) {
//If we dont have a shield ability, we return, since we cannot do anything.
return;
} else {
//If we have a shield ability, we set the right icon
abilityName = "ShieldAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\SheildDots-01.png";
}
}
} else {
//If we do have a sprint ability, we change the icon
abilityName = "SprintAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Dash-01.png";
}
}
} else {
//If we have a dash ability, we set the icon to the correct one.
abilityName = "DashAbility";
if (entity.HasComponent("Sprite")) {
(std::string&)entity["Sprite"]["DiffuseTexture"] = "Textures\\Icons\\Abilities\\Superman-01.png";
}
}
EntityWrapper cooldownTextEntity = entity.FirstChildByName("Cooldown");
//TODO: Fix so this track correctly for shield and sprint depending on how they work.
double maxAbilityCD, currentAbilityCD;
if (abilityName == "DashAbility") {
maxAbilityCD = (double)abilityEntity[abilityName]["CoolDownMaxTimer"];
currentAbilityCD = (double)abilityEntity[abilityName]["CoolDownTimer"];
currentAbilityCD = currentAbilityCD >= 0.0 ? currentAbilityCD : 0.0;
if (cooldownTextEntity.Valid()) {
if (cooldownTextEntity.HasComponent("Text")) {
std::string t = (std::string&)cooldownTextEntity["Text"]["Content"] = std::to_string(currentAbilityCD).substr(0, 3);
}
}
}
if (abilityName == "ShieldAbility") {
maxAbilityCD = 0.0;
currentAbilityCD = 1 - (bool)abilityEntity[abilityName]["Active"];
}
if (abilityName == "SprintAbility") {
maxAbilityCD = 0.0;
currentAbilityCD = 1 - (bool)abilityEntity[abilityName]["Active"];
}
if (entity.HasComponent("Fill")) {
entity["Fill"]["Percentage"] = currentAbilityCD/maxAbilityCD;
}
}
}
+65 -16
View File
@@ -37,8 +37,7 @@ void AmmoPickupSystem::Update(double dt)
//erase the current element (somePickup)
it = m_ETriggerTouchVector.erase(it);
}
else {
} else {
it++;
}
}
@@ -48,7 +47,7 @@ void AmmoPickupSystem::Update(double dt)
m_PickupAtMaximum.erase(it);
break;
}
if ((int)it->player["AssaultWeapon"]["Ammo"] < (int)it->player["AssaultWeapon"]["MaxAmmo"]) {
if (!DoesPlayerHaveMaxAmmo(it->player)) {
DoPickup(it->player, it->trigger);
m_PickupAtMaximum.erase(it);
break;
@@ -56,6 +55,58 @@ void AmmoPickupSystem::Update(double dt)
}
}
}
bool AmmoPickupSystem::DoesPlayerHaveMaxAmmo(EntityWrapper &player) {
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
return !((int)player["DefenderWeapon"]["Ammo"] < (int)player["DefenderWeapon"]["MaxAmmo"]);
} else if (playerClass == PlayerClass::Sniper) {
return !((int)player["SniperWeapon"]["Ammo"] < (int)player["SniperWeapon"]["MaxAmmo"]);
} else if (playerClass == PlayerClass::Assault) {
return !((int)player["AssaultWeapon"]["Ammo"] < (int)player["AssaultWeapon"]["MaxAmmo"]);
} else {
return false;
}
}
void AmmoPickupSystem::SetPlayerAmmo(EntityWrapper &player, int ammoGain) {
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
(int&)player["DefenderWeapon"]["Ammo"] = std::min((int)player["DefenderWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else if (playerClass == PlayerClass::Sniper) {
(int&)player["SniperWeapon"]["Ammo"] = std::min((int)player["SniperWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else if (playerClass == PlayerClass::Assault) {
(int&)player["AssaultWeapon"]["Ammo"] = std::min((int)player["AssaultWeapon"]["Ammo"] + ammoGain, maxWeaponAmmo);
} else {
//unknown class - ignore
}
}
int AmmoPickupSystem::GetPlayerMaxAmmo(EntityWrapper &player) {
PlayerClass playerClass = DetermineClass(player);
if (playerClass == PlayerClass::Defender) {
return (int)player["DefenderWeapon"]["MaxAmmo"];
} else if (playerClass == PlayerClass::Sniper) {
return (int)player["SniperWeapon"]["MaxAmmo"];
} else if (playerClass == PlayerClass::Assault) {
return (int)player["AssaultWeapon"]["MaxAmmo"];
} else {
return -1;
}
}
AmmoPickupSystem::PlayerClass AmmoPickupSystem::DetermineClass(EntityWrapper &player)
{
//determine the class based on what component the inflictor-player has
if (m_World->HasComponent(player.ID, "DashAbility")) {
return PlayerClass::Assault;
}
if (m_World->HasComponent(player.ID, "ShieldAbility")) {
return PlayerClass::Defender;
}
if (m_World->HasComponent(player.ID, "SprintAbility")) {
return PlayerClass::Sniper;
}
return PlayerClass::None;
}
bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
{
@@ -63,7 +114,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
return false;
}
//TODO: add other weapontypes
if (!e.Entity.HasComponent("AssaultWeapon")) {
if (DetermineClass(e.Entity) == PlayerClass::None) {
return false;
}
if (!e.Trigger.HasComponent("AmmoPickup")) {
@@ -71,7 +122,7 @@ bool AmmoPickupSystem::OnTriggerTouch(Events::TriggerTouch& e)
}
//if at maxammo, save the trigger-touch to a vector since standing inside it will not re-trigger the trigger
if ((int)e.Entity["AssaultWeapon"]["Ammo"] >= (int)e.Entity["AssaultWeapon"]["MaxAmmo"]) {
if (DoesPlayerHaveMaxAmmo(e.Entity)) {
m_PickupAtMaximum.push_back({ e.Entity, e.Trigger });
return false;
}
@@ -85,18 +136,16 @@ bool AmmoPickupSystem::OnAmmoPickup(Events::AmmoPickup & e)
return false;
}
//TODO: add other weapontypes
if (!e.Player.HasComponent("AssaultWeapon")) {
if (DetermineClass(e.Player) == PlayerClass::None) {
return false;
}
int maxWeaponAmmo = (int)e.Player["AssaultWeapon"]["MaxAmmo"];
int& currentAmmo = (int)e.Player["AssaultWeapon"]["Ammo"];
//cant pick up ammopacks if you are already at MaxAmmo
if (currentAmmo >= maxWeaponAmmo) {
if (DoesPlayerHaveMaxAmmo(e.Player)) {
return false;
}
SetPlayerAmmo(e.Player, e.AmmoGain);
currentAmmo = std::min(currentAmmo + e.AmmoGain, maxWeaponAmmo);
return false;
return true;
}
bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
@@ -114,8 +163,11 @@ bool AmmoPickupSystem::OnTriggerLeave(Events::TriggerLeave& e) {
}
void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
int maxWeaponAmmo = (int)player["AssaultWeapon"]["MaxAmmo"];
int& currentAmmo = (int)player["AssaultWeapon"]["Ammo"];
//trigger should be valid but if it isnt we just return (to avoid crash)
if (!trigger.Valid()) {
return;
}
int maxWeaponAmmo = GetPlayerMaxAmmo(player);
int ammoGiven = 0.01*(double)trigger["AmmoPickup"]["AmmoGain"] * maxWeaponAmmo;
Events::AmmoPickup ePlayerAmmoPickup;
@@ -123,9 +175,6 @@ void AmmoPickupSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger) {
ePlayerAmmoPickup.Player = player;
m_EventBroker->Publish(ePlayerAmmoPickup);
//immediately give the player the ammo (on server)
currentAmmo = std::min(currentAmmo + ammoGiven, maxWeaponAmmo);
//copy position, ammogain, respawntimer (twice since one of the values will be counted down to 0, the other will be set in the new object)
//we need to copy all values since each value can be different for each ammoPickup
m_ETriggerTouchVector.push_back({ (glm::vec3)trigger["Transform"]["Position"], trigger["AmmoPickup"]["AmmoGain"],
+12
View File
@@ -69,6 +69,7 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
int ownedBy = teamComponent["Team"];
int redTeamPlayersStandingInside = 0;
int blueTeamPlayersStandingInside = 0;
//note: old color system
if (capturePointEntity.HasComponent("Model")) {
//Now sets team color to the capturepoint, or white if it is uncaptured.
capturePointEntity["Model"]["Color"] = ownedBy == blueTeam ? glm::vec4(0, 0.0f, 1, 0.3) : ownedBy == redTeam ? glm::vec4(1, 0.0f, 0, 0.3) : glm::vec4(1, 1, 1, 0.3);
@@ -102,7 +103,18 @@ void CapturePointSystem::UpdateComponent(EntityWrapper& capturePointEntity, Comp
nextPossibleCapturePoint["Blue"] = i - 1;
}
}
if (m_RecentlyCapturedNeedNextCapturePointNow) {
//change what model is displaying (change all in case 2 capturepoints has been captured on the same frame)
for (int i = 0; i < m_NumberOfCapturePoints; i++) {
auto owner = (int)m_CapturePointNumberToEntityMap[i]["Team"]["Team"];
if (m_CapturePointNumberToEntityMap[i].FirstChildByName("Red").ID != EntityID_Invalid) {
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Red")["Model"]["Visible"] = owner == redTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Blue")["Model"]["Visible"] = owner == blueTeam ? true : false;
(bool&)m_CapturePointNumberToEntityMap[i].FirstChildByName("Spectator")["Model"]["Visible"] = owner == spectatorTeam ? true : false;
}
}
//save the next cap points and publish the captured event
m_CapturedEvent.BlueTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Blue"]];
m_CapturedEvent.RedTeamNextCapturePoint = m_CapturePointNumberToEntityMap[nextPossibleCapturePoint["Red"]];
m_EventBroker->Publish(m_CapturedEvent);
+10 -4
View File
@@ -10,10 +10,11 @@ DamageIndicatorSystem::DamageIndicatorSystem(SystemParams params)
//load texture to cache
auto texture = CommonFunctions::LoadTexture("Textures/DamageIndicator.png", false);
auto entityFile = ResourceManager::Load<EntityXMLFile>("Schema/Entities/DamageIndicator.xml");
m_NetworkEnabled = ResourceManager::Load<ConfigFile>("Config.ini")->Get("Networking.StartNetwork", false);
}
void DamageIndicatorSystem::Update(double dt) {
if (!IsServer && LocalPlayer.Valid()) {
if ((!IsServer || !m_NetworkEnabled) && LocalPlayer.Valid()) {
for (auto& iter = updateDamageIndicatorVector.begin(); iter != updateDamageIndicatorVector.end(); iter++) {
if (!iter->spriteEntity.Valid()) {
updateDamageIndicatorVector.erase(iter);
@@ -40,10 +41,15 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
return false;
}
//friendly fire - return
if (e.Damage < 0.1f) {
return false;
}
glm::vec3 inflictorPos = e.Inflictor["Transform"]["Position"];
//if testing
#ifdef INDICATOR_TEST
inflictorPos = DamageIndicatorTest(e.Victim);
inflictorPos = DamageIndicatorTest(e.Victim);
#endif
float angleBetweenVectors = CalculateAngle(e.Victim, inflictorPos);
@@ -55,7 +61,7 @@ bool DamageIndicatorSystem::OnPlayerDamage(Events::PlayerDamage& e)
//simply set the rotation z-wise to the angleBetweenVectors
sprite["Transform"]["Orientation"] = glm::vec3(0, 0, angleBetweenVectors);
if (!IsServer) {
if (!IsServer || !m_NetworkEnabled) {
updateDamageIndicatorVector.emplace_back(sprite, inflictorPos);
}
@@ -122,7 +128,7 @@ glm::vec3 DamageIndicatorSystem::DamageIndicatorTest(EntityWrapper player) {
}
m_TestVar++;
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
auto inflictorPos = glm::vec3(currentPos.x + testVar*6.0f, currentPos.y, currentPos.z + testVar2*6.0f);
//load the explosioneffect XML
auto deathEffect = ResourceManager::Load<EntityXMLFile>("Schema/Entities/PlayerDeathExplosionWithCamera.xml");
+94
View File
@@ -0,0 +1,94 @@
#include "../Game/Systems/MainMenuSystem.h"
MainMenuSystem::MainMenuSystem(SystemParams params, IRenderer* renderer)
: System(params)
, ImpureSystem()
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EPressed, &MainMenuSystem::OnButtonPress);
EVENT_SUBSCRIBE_MEMBER(m_EReleased, &MainMenuSystem::OnButtonRelease);
EVENT_SUBSCRIBE_MEMBER(m_EClicked, &MainMenuSystem::OnButtonClick);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &MainMenuSystem::OnInputCommand);
}
void MainMenuSystem::Update(double dt)
{
}
bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
{
if (e.EntityName == "ServerIdentityConnect") {
EntityWrapper entity = e.Entity;
EntityWrapper serverIdentityEntity = entity.FirstParentWithComponent("ServerIdentity");
if(serverIdentityEntity.Valid()) {
Events::ConnectRequest event;
event.IP = (std::string)entity["ServerIdentity"]["IP"];
event.Port = (int)entity["ServerIdentity"]["Port"];
printf("\n ----Request Server Connect----\nIP: %s\nPort: %i\n ------------------------------", event.IP, event.Port);
m_EventBroker->Publish(event);
}
}
return true;
}
bool MainMenuSystem::OnButtonRelease(const Events::ButtonReleased& e)
{
return true;
}
bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
{
return true;
}
bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
{
if(e.Command == "Play" && e.Value == 1) {
auto menus = m_World->GetComponents("Menu");
if (menus == nullptr) {
return 0;
}
if (m_OpenSubMenu == EntityWrapper::Invalid) {
//No submenu is open, open one.
for (auto& menu : *menus) {
EntityWrapper menuEntity = EntityWrapper(m_World, menu.EntityID);
auto serverListSpawner = menuEntity.FirstChildByName(e.Command + "Spawner");
if (!serverListSpawner.HasComponent("Spawner")) {
return 0;
}
m_OpenSubMenu = SpawnerSystem::Spawn(serverListSpawner, serverListSpawner);
Events::SearchForServers event;
m_EventBroker->Publish(event);
break;
}
} else if(!m_OpenSubMenu.HasComponent("ServerList")) {
//Menu is open, but not the right one, delete the old one and open a new one.
m_World->DeleteEntity(m_OpenSubMenu.ID);
m_OpenSubMenu = EntityWrapper::Invalid;
for (auto& menu : *menus) {
EntityWrapper menuEntity = EntityWrapper(m_World, menu.EntityID);
auto serverListSpawner = menuEntity.FirstChildByName(e.Command + "Spawner");
if (!serverListSpawner.HasComponent("Spawner")) {
return 0;
}
m_OpenSubMenu = SpawnerSystem::Spawn(serverListSpawner, serverListSpawner);
Events::SearchForServers event;
m_EventBroker->Publish(event);
break;
}
} else {
//Serverlist submenu is open, close it.
printf("\n\nMenuShit\n\n");
m_World->DeleteEntity(m_OpenSubMenu.ID);
m_OpenSubMenu = EntityWrapper::Invalid;
}
} else if (e.Command == "RefreshServerList" && e.Value == 1){
Events::SearchForServers event;
m_EventBroker->Publish(event);
}
return true;
}
+4
View File
@@ -83,6 +83,10 @@ bool PickupSpawnSystem::OnTriggerLeave(Events::TriggerLeave& e)
}
void PickupSpawnSystem::DoPickup(EntityWrapper &player, EntityWrapper &trigger)
{
//trigger should be valid but if it isnt we just return (to avoid crash)
if (!trigger.Valid()) {
return;
}
double healthGiven = 0.01*(double)trigger["HealthPickup"]["HealthGain"] * (double)player["Health"]["MaxHealth"];
//only the server will increase the players hp and set it in the next delta
+30 -7
View File
@@ -1,10 +1,12 @@
#include "Systems/PlayerDeathSystem.h"
#include "Core/ELockMouse.h"
PlayerDeathSystem::PlayerDeathSystem(SystemParams params)
: System(params)
{
EVENT_SUBSCRIBE_MEMBER(m_OnPlayerDeath, &PlayerDeathSystem::OnPlayerDeath);
EVENT_SUBSCRIBE_MEMBER(m_EEntityDeleted, &PlayerDeathSystem::OnEntityDeleted);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &PlayerDeathSystem::OnInputCommand);
}
void PlayerDeathSystem::Update(double dt)
@@ -33,10 +35,10 @@ void PlayerDeathSystem::createDeathEffect(EntityWrapper player)
//components that we need from player
auto playerModel = player.FirstChildByName("PlayerModel");
if (!playerModel.Valid()) {
return;
}
if (!playerModel.HasComponent("Model") || !playerModel.HasComponent("Animation")) {
if (player == LocalPlayer) {
setSpectatorCamera();
}
return;
}
auto playerEntityModel = playerModel["Model"];
@@ -68,14 +70,35 @@ bool PlayerDeathSystem::OnEntityDeleted(Events::EntityDeleted& e)
if (m_LocalPlayerDeathEffect.ID != e.DeletedEntity) {
return false;
}
// If the player hasn't spawned already, activate the spectator camera.
if (!LocalPlayer.Valid()) {
setSpectatorCamera();
}
return true;
}
void PlayerDeathSystem::setSpectatorCamera()
{
// Look for the spectator camera entity in the level.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera");
if (!spectatorCam.Valid() || !spectatorCam.HasComponent("Camera") || LocalPlayer.Valid()) {
return false;
if (!spectatorCam.HasComponent("Camera")) {
return;
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
return true;
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
bool PlayerDeathSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Value == 0 || e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
return false;
}
// Ensure that we don't set spectator camera if the player deliberately changes to class/team pick.
m_LocalPlayerDeathEffect = EntityWrapper::Invalid;
return true;
}
+61 -40
View File
@@ -1,4 +1,5 @@
#include "Systems/PlayerSpawnSystem.h"
#include "Core/ELockMouse.h"
PlayerSpawnSystem::PlayerSpawnSystem(SystemParams params)
: System(params)
@@ -59,7 +60,15 @@ void PlayerSpawnSystem::Update(double dt)
}
int numSpawnedPlayers = 0;
for (auto& req : m_SpawnRequests) {
int playersSpectating = 0;
const int numRequestsToHandle = (int)m_SpawnRequests.size();
for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) {
// It is valid if they didn't pick class yet
// but don't spawn anything, goto next spawnrequest.
if (it->Class == PlayerClass::None) {
++playersSpectating;
continue;
}
for (auto& cPlayerSpawn : *playerSpawns) {
EntityWrapper spawner(m_World, cPlayerSpawn.EntityID);
if (!spawner.HasComponent("Spawner")) {
@@ -69,43 +78,49 @@ void PlayerSpawnSystem::Update(double dt)
// If the spawner has a team affiliation, check it
if (spawner.HasComponent("Team")) {
auto cSpawnerTeam = spawner["Team"];
if ((int)cSpawnerTeam["Team"] != req.Team) {
// Increase num spawned players if someone picks spectator, since it is valid to pick spectator
// but don't spawn anything, goto next spawnrequest.
if (req.Team == (int)cSpawnerTeam["Team"].Enum("Spectator")) {
++numSpawnedPlayers;
if ((int)cSpawnerTeam["Team"] != it->Team) {
// If they somehow has a valid class as spectator, don't spawn them.
if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) {
++playersSpectating;
break;
}
continue;
}
}
// TODO: Choose a different spawner depending on class picked?
// Spawn the player!
EntityWrapper player = SpawnerSystem::Spawn(spawner, EntityWrapper::Invalid, "Player");
// Set the player team affiliation
player["Team"]["Team"] = req.Team;
player["Team"]["Team"] = it->Team;
// Publish a PlayerSpawned event
Events::PlayerSpawned e;
e.PlayerID = req.PlayerID;
e.PlayerID = it->PlayerID;
e.Player = player;
e.Spawner = spawner;
m_EventBroker->Publish(e);
++numSpawnedPlayers;
it = m_SpawnRequests.erase(it);
break;
}
if (it == m_SpawnRequests.end()) {
break;
}
}
if (numSpawnedPlayers != (int)m_SpawnRequests.size()) {
LOG_DEBUG("%i players were supposed to be spawned or set as spectator, but only %i was handled.", (int)m_SpawnRequests.size(), numSpawnedPlayers);
if (numSpawnedPlayers != numRequestsToHandle - playersSpectating) {
LOG_DEBUG("%i players were supposed to be spawned, but only %i was successfully.", numRequestsToHandle - playersSpectating, numSpawnedPlayers);
} else {
LOG_DEBUG("%i players were spawned or set as spectator.", numSpawnedPlayers);
std::string dbg = numSpawnedPlayers != 0 ? std::to_string(numSpawnedPlayers) + " players were spawned. " : "";
dbg += playersSpectating != 0 ? std::to_string(playersSpectating) + " players are spectating/picking class. " : "";
LOG_DEBUG(dbg.c_str());
}
m_SpawnRequests.clear();
}
bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
{
if (e.Command != "PickTeam" && e.Command != "SwapToClassPick") {
if (e.Command != "PickTeam" && e.Command != "PickClass" && e.Command != "SwapToTeamPick" && e.Command != "SwapToClassPick") {
return false;
}
@@ -113,19 +128,6 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
return false;
}
// A dead client should be able to swap to the overwatch camera.
if (IsClient && !LocalPlayer.Valid()) {
// Set the camera as active, if it exists.
// Find the respawn camera or class pick camera.
std::string camName = e.Command == "SwapToClassPick" ? "PickClassCamera" : "SpectatorCamera";
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
if (spectatorCam.Valid() && spectatorCam.HasComponent("Camera")) {
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
}
}
// Team picks should be processed ONLY server-side!
// Don't make a spawn request if we're the client.
if (!IsServer && m_NetworkEnabled) {
@@ -136,27 +138,38 @@ bool PlayerSpawnSystem::OnInputCommand(Events::InputCommand& e)
auto iter = m_SpawnRequests.begin();
for (; iter != m_SpawnRequests.end(); ++iter) {
if (iter->PlayerID == e.PlayerID) {
// If player wants to switch class, remove their spawn request.
if (e.Command == "SwapToClassPick") {
m_SpawnRequests.erase(iter);
// If player wants to switch team or class , remove their selected class so they don't spawn.
if (e.Command == "SwapToTeamPick" || e.Command == "SwapToClassPick") {
iter->Class = PlayerClass::None;
return true;
}
break;
}
}
if (e.Command == "SwapToClassPick") {
return true;
}
//If we get here we got a PickTeam or PickClass, so add or alter a spawn request.
if (iter != m_SpawnRequests.end()) {
// If player is in queue to spawn, then change their team affiliation in the request.
iter->Team = (ComponentInfo::EnumType)e.Value;
// If player is in queue to spawn, then change their team affiliation or class in the request.
if (e.Command == "PickTeam") {
iter->Team = (ComponentInfo::EnumType)e.Value;
} else {
iter->Class = static_cast<PlayerClass>((int)e.Value);
}
} else if (m_PlayerEntities.count(e.PlayerID) == 0 || !m_PlayerEntities[e.PlayerID].Valid()) {
// If player is not in queue to spawn, then create a spawn request,
// but only if they are spectating and/or just connected.
SpawnRequest req;
req.PlayerID = e.PlayerID;
req.Team = (ComponentInfo::EnumType)e.Value;
if (e.Command == "PickTeam") {
req.Team = (ComponentInfo::EnumType)e.Value;
req.Class = PlayerClass::None;
} else {
// Should never get here, since you should have picked a team before you ever get a chance to pick class.
LOG_WARNING("Sequence error: Should not be able to pick class before team");
req.Team = 1; // TODO: 1 Signifies spectator, should probably have real enum here later.
req.Class = static_cast<PlayerClass>((int)e.Value);
}
m_SpawnRequests.push_back(req);
} else {
return false;
@@ -191,6 +204,8 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
Events::SetCamera e;
e.CameraEntity = cameraEntity;
m_EventBroker->Publish(e);
Events::LockMouse lock;
m_EventBroker->Publish(lock);
}
// HACK: Set the player model color to team color
@@ -210,7 +225,7 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
{
//Only spawn request if network is disabled or we are server.
// Only spawn request if network is disabled or we are server.
if (!IsServer && m_NetworkEnabled) {
return false;
}
@@ -218,10 +233,6 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
return false;
}
ComponentWrapper cTeam = e.Player["Team"];
//A spectator can't die anyway
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Spectator")) {
return false;
}
if (m_PlayerIDs.count(e.Player.ID) == 0) {
return false;
@@ -230,6 +241,16 @@ bool PlayerSpawnSystem::OnPlayerDeath(Events::PlayerDeath& e)
SpawnRequest req;
req.PlayerID = m_PlayerIDs.at(e.Player.ID);
req.Team = cTeam["Team"];
// TODO: Something better than temp class state code, if we ever add class enums in .xml
if (e.Player.HasComponent("DashAbility")) {
req.Class = PlayerClass::Assault;
} else if (e.Player.HasComponent("SprintAbility")) {
req.Class = PlayerClass::Sniper;
} else if (e.Player.HasComponent("ShieldAbility")) {
req.Class = PlayerClass::Defender;
} else {
req.Class = PlayerClass::None;
}
m_SpawnRequests.push_back(req);
return true;
+1 -1
View File
@@ -78,7 +78,7 @@ void ScoreScreenSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper&
if (it == m_PlayerIdentities.end()) {
break;
}
}
if(found == false) {
if(it->second.Team != currentTeam) {
+53
View File
@@ -0,0 +1,53 @@
#include "../Game/Systems/ServerListSystem.h"
ServerListSystem::ServerListSystem(SystemParams params, IRenderer* renderer)
: System(params)
, PureSystem("ServerList")
, m_Renderer(renderer)
{
EVENT_SUBSCRIBE_MEMBER(m_EServerListRecieved, &ServerListSystem::OnServerListRecieved);
}
void ServerListSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cServerList, double dt)
{
}
void ServerListSystem::RefreshList()
{
Events::SearchForServers event;
m_EventBroker->Publish(event);
}
bool ServerListSystem::OnServerListRecieved(const Events::DisplayServerlist& e)
{
if (e.Serverlist.size() == 0) {
return 1;
}
auto serverLists = m_World->GetComponents("ServerList");
if (serverLists == nullptr)
return 1;
for (auto& cServerList : *serverLists) {
EntityWrapper serverListEntity = EntityWrapper(m_World, cServerList.EntityID);
EntityWrapper identitySpawner = serverListEntity.FirstChildByName("ServerIdentitySpawner");
identitySpawner.DeleteChildren();
(int&)cServerList["TotalIdentities"] = (int)e.Serverlist.size();
for (int i = 0; i < e.Serverlist.size(); i++) {
//Create Identities for each server and place them on the right position.
EntityWrapper newIdentity = SpawnerSystem::Spawn(identitySpawner, identitySpawner);
glm::vec3 offset = (glm::vec3)serverListEntity["ServerList"]["Offset"];
(glm::vec3&)newIdentity["Transform"]["Position"] = offset * (float)i;
auto& cIdentity = newIdentity["ServerIdentity"];
(std::string&)cIdentity["IP"] = e.Serverlist[i].Address;
(std::string&)cIdentity["ServerName"] = e.Serverlist[i].Name;
(int&)cIdentity["Port"] = e.Serverlist[i].Port;
(int&)cIdentity["PlayersConnected"] = e.Serverlist[i].PlayersConnected;
}
}
return 1;
}
@@ -0,0 +1,90 @@
#include "Systems/SpectatorCameraSystem.h"
#include "Rendering/ESetCamera.h"
#include "Core/ELockMouse.h"
SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
: System(params)
, m_CamSetToTeamPick(false)
, m_PickedTeam(-1)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
}
void SpectatorCameraSystem::Update(double dt)
{
if (!m_CamSetToTeamPick && IsClient) {
// Find the class pick camera and set them to it, since they need to pick a team before they can leave the screen.
EntityWrapper spectatorCam = m_World->GetFirstEntityByName("PickTeamCamera");
if (spectatorCam.HasComponent("Camera")) {
m_CamSetToTeamPick = true;
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
}
}
bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
{
// Only the client should do this, and only if player is not spawned.
if (!IsClient || LocalPlayer.Valid()) {
return false;
}
bool swapToClass = e.Command == "PickTeam" || e.Command == "SwapToClassPick";
if (e.Value == 0 || !swapToClass && e.Command != "SwapToTeamPick" && e.Command != "PickClass") {
return false;
}
if (e.Command == "PickTeam") {
m_PickedTeam = e.Value;
}
// If a team has not been picked, they may not exit the pick team screen.
if (m_PickedTeam == -1) {
return false;
}
// A dead client should be able to swap to and between the overwatch cameras.
std::string camName;
// TODO: 1 Signifies spectator, should probably have real enum here later.
// Spectators should never end up at the class select, instead put them at the SpectatorCamera.
if (swapToClass && m_PickedTeam != 1) {
camName = "PickClassCamera";
} else if (e.Command == "SwapToTeamPick") {
camName = "PickTeamCamera";
} else {
camName = "SpectatorCamera";
}
EntityWrapper spectatorCam = m_World->GetFirstEntityByName(camName);
// Set the camera as active, if it exists.
if (spectatorCam.HasComponent("Camera")) {
// Set the class pick button visible if a blue or red team is picked, else invisible.
EntityWrapper HUD;
if (camName == "SpectatorCamera") {
HUD = spectatorCam.FirstChildByName("SpectatorHUD");
} else if (camName == "PickTeamCamera") {
HUD = spectatorCam.FirstChildByName("PickTeamHUD");
}
// If we are at the class pick already, or if HUD is invalid for any other reason, do nothing.
if (HUD.Valid()) {
EntityWrapper toClassButton = spectatorCam.FirstChildByName("ToClassPick");
if (toClassButton.Valid()) {
// Set ClassButton as invisible if spectator, else visible.
bool visible = m_PickedTeam != 1; // TODO: 1 Signifies spectator.
toClassButton["Sprite"]["Visible"] = visible;
for (auto& child : toClassButton.ChildrenWithComponent("Text")) {
child["Text"]["Visible"] = visible;
}
}
}
Events::SetCamera eSetCamera;
eSetCamera.CameraEntity = spectatorCam;
m_EventBroker->Publish(eSetCamera);
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
return true;
}