Compare commits

..

9 Commits

21 changed files with 6337 additions and 6087 deletions
@@ -0,0 +1,15 @@
#ifndef Events_BecomeServerOrClient_h__
#define Events_BecomeServerOrClient_h__
#include "Core/EventBroker.h"
namespace Events
{
struct BecomeServer : public Event { };
struct BecomeClient : public Event { };
}
#endif
@@ -0,0 +1,19 @@
#ifndef EResolutionChanged_h__
#define EResolutionChanged_h__
#include "../Core/Event.h"
#include "../Core/Util/Rectangle.h"
namespace Events
{
// Fired when the framebuffer size changes
struct ResolutionChanged : Event
{
Rectangle OldResolution;
Rectangle NewResolution;
};
}
#endif
+3 -3
View File
@@ -54,7 +54,7 @@ private:
struct Frustum {
Plane Planes[4];
};
Frustum* m_Frustums;
Frustum* m_Frustums = nullptr;
//This should be a component
struct LightSource {
@@ -74,11 +74,11 @@ private:
glm::vec2 Padding = glm::vec2(1.f, 2.f);
};
LightGrid* m_LightGrid;
LightGrid* m_LightGrid = nullptr;
int m_LightOffset = 0;
float* m_LightIndex;
float* m_LightIndex = nullptr;
};
+3
View File
@@ -19,6 +19,7 @@
#include "../Core/Octree.h"
#include "../Collision/EntityAABB.h"
#include "../Core/ConfigFile.h"
#include "EResolutionChanged.h"
class RenderSystem : public ImpureSystem
{
@@ -36,6 +37,8 @@ private:
EntityWrapper m_LocalPlayer = EntityWrapper::Invalid;
Octree<EntityAABB>* m_Octree;
EventRelay<RenderSystem, Events::ResolutionChanged> m_EResolutionChanged;
bool OnResolutionChanged(Events::ResolutionChanged &event);
EventRelay<RenderSystem, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(Events::SetCamera &event);
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
+8 -2
View File
@@ -28,10 +28,12 @@
#include "Util/CommonFunctions.h"
#include "Core/PerformanceTimer.h"
#include "ShadowPass.h"
#include "EResolutionChanged.h"
class Renderer : public IRenderer
{
static void glfwFrameBufferCallback(GLFWwindow* window, int width, int height);
static void glfwWindowSizeCallback(GLFWwindow* window, int width, int height);
public:
Renderer(EventBroker* eventBroker, ConfigFile* config)
@@ -40,13 +42,14 @@ public:
{ }
~Renderer();
virtual void SetResolution(const Rectangle& resolution) override;
virtual void Initialize() override;
virtual void Update(double dt) override;
virtual void Draw(RenderFrame& frame) override;
virtual PickData Pick(glm::vec2 screenCoord) override;
private:
//----------------------Variables----------------------//
@@ -90,11 +93,14 @@ private:
void InputUpdate(double dt);
//void PickingPass(RenderQueueCollection& rq);
//void DrawScreenQuad(GLuint textureToDraw);
void setWindowSize(Rectangle size);
void updateFramebufferSize();
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
void SortRenderJobsByDepth(RenderScene &scene);
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type);
//--------------------ShaderPrograms-------------------//
//--------------------ShaderPrograms-------------------//
ShaderProgram* m_BasicForwardProgram;
ShaderProgram* m_ExplosionEffectProgram;
+4
View File
@@ -16,7 +16,11 @@ inline bool _GLERROR(const char* info, const char* file, const char* func, unsig
return false;
}
#ifndef DEBUG
#define GLERROR(function) \
_GLERROR(function, __BASE_FILE__, __func__, __LINE__)
#else
#define GLERROR(function) false
#endif
#endif
+6
View File
@@ -29,6 +29,7 @@
#include "Network/Network.h"
#include "Network/Server.h"
#include "Network/Client.h"
#include "Network/EBecomeServerOrClient.h"
// Sound
#include "Sound/SoundManager.h"
@@ -70,6 +71,11 @@ private:
bool m_IsServer = false;
int parseArgs(int argc, char* argv[]);
EventRelay<Game, Events::BecomeServer> m_EBecomeServer;
bool OnBecomeServer(const Events::BecomeServer& e);
EventRelay<Game, Events::BecomeClient> m_EBecomeClient;
bool OnBecomeClient(const Events::BecomeClient& e);
};
#endif
+1
View File
@@ -14,6 +14,7 @@
#include "Input/EInputCommand.h"
#include "Network/ESearchForServers.h"
#include "Network/EConnectRequest.h"
#include "Network/EBecomeServerOrClient.h"
class MainMenuSystem : public ImpureSystem
@@ -3,7 +3,6 @@
#include "Core/System.h"
#include "Input/EInputCommand.h"
#include "Network/EPlayerDisconnected.h"
class SpectatorCameraSystem : public ImpureSystem
{
@@ -18,8 +17,6 @@ private:
EventRelay<SpectatorCameraSystem, Events::InputCommand> m_EInputCommand;
bool OnInputCommand(const Events::InputCommand& e);
EventRelay<SpectatorCameraSystem, Events::PlayerDisconnected> m_EDisconnect;
bool OnDisconnect(const Events::PlayerDisconnected& e);
};
#endif
+1 -3
View File
@@ -29,6 +29,4 @@ K=TakeDamage,1500
F2=PerformanceTimingResetAllTimers
F3=PerformanceTimingCreateExcelData
Comma=SwapToClassPick
Period=SwapToTeamPick
Enter=PickClass,1
F5=DisconnectFromServer
Period=SwapToTeamPick
+72 -15
View File
@@ -319,23 +319,80 @@
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity name="Popup_Origin">
<Components>
<c:Transform>
<Position X="-0.103822395" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity name="PlaySpawner">
<Entity name="ButtonPos_5">
<Components>
<c:Spawner>
<EntityFile>Schema/Entities/ServerList.xml</EntityFile>
</c:Spawner>
<c:Transform/>
<c:Transform>
<Position X="0" Y="-0.280000001" Z="0"/>
</c:Transform>
</Components>
<Children/>
<Children>
<Entity name="Button_5">
<Components>
<c:Button/>
<c:Sprite>
<DiffuseTexture>Textures/Core/White.png</DiffuseTexture>
<BlurBackground>true</BlurBackground>
<GlowMap></GlowMap>
<DepthSort>false</DepthSort>
<Color A="0.392156869" B="0" G="0" R="0"/>
</c:Sprite>
<c:Transform>
<Scale X="0.200000003" Y="0.0500000007" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="Text">
<Components>
<c:Text>
<Content>Host</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>
<Right/>
</Alignment>
</c:Text>
<c:Transform>
<Position X="0.0920000002" Y="-0.0150000006" Z="0.00499999989"/>
<Scale X="0.0199999996" Y="0.0199999996" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="ButtonCorner_Origin">
<Components>
<c:Transform/>
</Components>
<Children>
<Entity name="TopRight">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/HUD/ButtonCorner_16.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:Transform>
<Position X="0.0970000029" Y="0.0220000017" Z="0.00499999989"/>
<Scale X="0.00499999989" Y="0.00499999989" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity name="BottomRight">
<Components>
<c:Sprite>
<DiffuseTexture>Textures/HUD/ButtonCorner_16.png</DiffuseTexture>
<GlowMap></GlowMap>
</c:Sprite>
<c:Transform>
<Position X="0.0970000029" Y="-0.0219999999" Z="0.00499999989"/>
<Orientation X="0" Y="0" Z="4.71199989"/>
<Scale X="0.00499999989" Y="0.00499999989" Z="1"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
File diff suppressed because it is too large Load Diff
-1
View File
@@ -47,7 +47,6 @@ EditorSystem::EditorSystem(SystemParams params, IRenderer* renderer, RenderFrame
Enable();
} else {
Disable();
m_EventBroker->Publish(Events::UnlockMouse());
}
}
+1 -6
View File
@@ -1,5 +1,4 @@
#include "Network/Client.h"
#include "Network/EPlayerDisconnected.h"
using namespace boost::asio::ip;
Client::Client(World* world, EventBroker* eventBroker)
@@ -225,7 +224,7 @@ void Client::parseServerlist(Packet& packet)
void Client::parseKick()
{
LOG_WARNING("You have been kicked from the server.");
disconnect();
m_IsConnected = false;
}
void Client::parseSpawnEvents()
@@ -465,10 +464,6 @@ void Client::disconnect()
Packet packet(MessageType::Disconnect, m_SendPacketID);
m_Reliable.Send(packet);
m_Reliable.Disconnect();
Events::PlayerDisconnected e;
e.Entity = m_LocalPlayer.ID;
e.PlayerID = -1;
m_EventBroker->Publish(e);
createMainMenu();
}
+2 -1
View File
@@ -22,7 +22,8 @@ Server::Server(World* world, EventBroker* eventBroker, int port)
port = config->Get<float>("Networking.Port", 27666);
}
m_Port = port;
LOG_INFO("Server initialized and bound to port %i", port);
printf("Server initialized and bound to port %i\n", port);
}
Server::~Server()
@@ -42,6 +42,15 @@ void LightCullingPass::SetSSBOSizes()
{
m_NumberOfTiles = (int)(m_Renderer->GetViewportSize().Width/TILE_SIZE) * (int)(m_Renderer->GetViewportSize().Height/TILE_SIZE);
if (m_Frustums != nullptr) {
delete[] m_Frustums;
}
if (m_LightGrid != nullptr) {
delete[] m_LightGrid;
}
if (m_LightIndex != nullptr) {
delete[] m_LightIndex;
}
m_Frustums = new Frustum[m_NumberOfTiles];
m_LightGrid = new LightGrid[m_NumberOfTiles];
m_LightIndex = new float[m_NumberOfTiles*MAX_LIGHTS_PER_TILE];
+9 -1
View File
@@ -9,10 +9,11 @@ RenderSystem::RenderSystem(SystemParams params, const IRenderer* renderer, Rende
, m_Octree(frustumCullOctree)
{
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
EVENT_SUBSCRIBE_MEMBER(m_EResolutionChanged, &RenderSystem::OnResolutionChanged);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &RenderSystem::OnPlayerSpawned);
m_Camera = new Camera((float)m_Renderer->Resolution().Width / m_Renderer->Resolution().Height, glm::radians(45.f), 0.01f, 5000.f);
m_Camera = new Camera((float)m_Renderer->GetViewportSize().Width / m_Renderer->GetViewportSize().Height, glm::radians(45.f), 0.01f, 5000.f);
}
RenderSystem::~RenderSystem()
@@ -20,6 +21,13 @@ RenderSystem::~RenderSystem()
delete m_Camera;
}
bool RenderSystem::OnResolutionChanged(Events::ResolutionChanged& e)
{
// Update camera aspect ration on resolution change
m_Camera->SetAspectRatio((float)e.NewResolution.Width / e.NewResolution.Height);
return true;
}
bool RenderSystem::OnSetCamera(Events::SetCamera& e)
{
ComponentWrapper cTransform = e.CameraEntity["Transform"];
+42 -8
View File
@@ -36,16 +36,24 @@ void Renderer::Initialize()
m_ImGuiRenderPass = new ImGuiRenderPass(this, m_EventBroker);
}
void Renderer::glfwWindowSizeCallback(GLFWwindow* window, int width, int height)
{
m_WindowToRenderer[window]->setWindowSize(Rectangle(width, height));
}
void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
Renderer* currentRenderer = m_WindowToRenderer[window];
currentRenderer->m_ViewportSize = Rectangle(width, height);
currentRenderer->m_PickingPass->OnWindowResize();
currentRenderer->m_DrawFinalPass->OnWindowResize();
currentRenderer->m_LightCullingPass->OnWindowResize();
currentRenderer->m_DrawBloomPass->OnWindowResize();
currentRenderer->m_SSAOPass->OnWindowResize();
m_WindowToRenderer[window]->updateFramebufferSize();
}
void Renderer::SetResolution(const Rectangle& resolution)
{
m_Resolution = resolution;
if (m_Window != nullptr) {
setWindowSize(resolution);
updateFramebufferSize();
}
}
void Renderer::InitializeWindow()
@@ -67,6 +75,7 @@ void Renderer::InitializeWindow()
LOG_ERROR("GLFW: Failed to create window");
exit(EXIT_FAILURE);
}
glfwSetWindowSizeCallback(m_Window, &glfwWindowSizeCallback);
glfwSetFramebufferSizeCallback(m_Window, &glfwFrameBufferCallback);
glfwMakeContextCurrent(m_Window);
@@ -111,6 +120,30 @@ void Renderer::InputUpdate(double dt)
}
void Renderer::setWindowSize(Rectangle size)
{
glfwSetWindowSize(m_Window, size.Width, size.Height);
}
void Renderer::updateFramebufferSize()
{
Events::ResolutionChanged e;
e.OldResolution = m_ViewportSize;
int width, height;
glfwGetFramebufferSize(m_Window, &width, &height);
glViewport(0, 0, width, height);
m_ViewportSize = Rectangle(width, height);
m_PickingPass->OnWindowResize();
m_DrawFinalPass->OnWindowResize();
m_LightCullingPass->OnWindowResize();
m_DrawBloomPass->OnWindowResize();
m_SSAOPass->OnWindowResize();
e.NewResolution = m_ViewportSize;
m_EventBroker->Publish(e);
}
void Renderer::Update(double dt)
{
m_EventBroker->Process<Renderer>();
@@ -263,6 +296,7 @@ void Renderer::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filterin
GLERROR("Texture initialization failed");
}
void Renderer::InitializeRenderPasses()
{
m_PickingPass = new PickingPass(this, m_EventBroker);
+44 -17
View File
@@ -58,7 +58,6 @@ Game::Game(int argc, char* argv[])
ResourceManager::RegisterType<EntityFile>("EntityFile");
ResourceManager::RegisterType<EntityXMLFile>("EntityXMLFile");
ResourceManager::RegisterType<Font>("FontFile");
m_Config = ResourceManager::Load<ConfigFile>("Config.ini");
ResourceManager::UseThreading = m_Config->Get<bool>("Multithreading.ResourceLoading", true);
DisableMemoryPool::Value = m_Config->Get<bool>("Debug.DisableMemoryPool", false);
@@ -66,6 +65,8 @@ Game::Game(int argc, char* argv[])
// Create the core event broker
m_EventBroker = new EventBroker();
EVENT_SUBSCRIBE_MEMBER(m_EBecomeServer, &Game::OnBecomeServer);
EVENT_SUBSCRIBE_MEMBER(m_EBecomeClient, &Game::OnBecomeClient);
// Create the renderer
m_Renderer = new Renderer(m_EventBroker, m_Config);
@@ -76,7 +77,7 @@ Game::Game(int argc, char* argv[])
0,
m_Config->Get<int>("Video.Width", 1280),
m_Config->Get<int>("Video.Height", 720)
));
));
m_Renderer->Initialize();
//m_Renderer->Camera()->SetFOV(glm::radians(m_Config->Get<float>("Video.FOV", 90.f)));
m_RenderFrame = new RenderFrame();
@@ -99,21 +100,7 @@ Game::Game(int argc, char* argv[])
// Create the sound manager
m_SoundManager = new SoundManager(m_World, m_EventBroker);
// Initialize network
if (m_Config->Get<bool>("Networking.StartNetwork", false)) {
if (m_IsServer) {
m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
} else if (m_IsClient) {
m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
}
} else {
// If network is disabled, pretend we're a server
m_IsClient = true;
m_IsServer = true;
}
// Create Octrees
// TODO: Perhaps the world bounds should be set in some non-arbitrary way instead of this.
@@ -188,6 +175,8 @@ Game::~Game()
delete m_OctreeCollision;
delete m_OctreeTrigger;
delete m_SoundManager;
m_EventBroker->Unsubscribe(m_EBecomeServer);
m_EventBroker->Unsubscribe(m_EBecomeClient);
if (m_NetworkClient != nullptr) {
delete m_NetworkClient;
}
@@ -210,6 +199,7 @@ void Game::Tick()
double dt = currentTime - m_LastTime;
m_LastTime = currentTime;
m_EventBroker->Process<Game>();
// Handle input in a weird looking but responsive way
m_EventBroker->Process<InputManager>();
m_EventBroker->Swap();
@@ -284,3 +274,40 @@ int Game::parseArgs(int argc, char* argv[])
return 0;
}
bool Game::OnBecomeServer(const Events::BecomeServer& e)
{
// if (m_IsServer) {
// m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
// m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
// } else if (m_IsClient) {
// m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
// m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
// m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
// }
if (m_NetworkServer != nullptr) {
delete m_NetworkServer;
}
if (m_NetworkClient != nullptr) {
delete m_NetworkClient;
}
m_NetworkServer = new Server(m_World, m_EventBroker, m_NetworkPort);
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " SERVER");
return true;
}
bool Game::OnBecomeClient(const Events::BecomeClient& e)
{
if (m_NetworkServer != nullptr) {
delete m_NetworkServer;
}
if (m_NetworkClient != nullptr) {
delete m_NetworkClient;
}
m_NetworkClient = new Client(m_World, m_EventBroker, std::make_unique<MultiplayerSnapshotFilter>(m_EventBroker));
m_NetworkClient->Connect(m_NetworkAddress, m_NetworkPort);
m_Renderer->SetWindowTitle(m_Renderer->WindowTitle() + " CLIENT");
return true;
}
+10 -4
View File
@@ -21,7 +21,7 @@ bool MainMenuSystem::OnButtonClick(const Events::ButtonClicked& e)
if (e.EntityName == "ServerIdentityConnect") {
EntityWrapper entity = e.Entity;
EntityWrapper serverIdentityEntity = entity.FirstParentWithComponent("ServerIdentity");
if(serverIdentityEntity.Valid()) {
if (serverIdentityEntity.Valid()) {
Events::ConnectRequest event;
event.IP = (std::string)serverIdentityEntity["ServerIdentity"]["IP"];
event.Port = (int)serverIdentityEntity["ServerIdentity"]["Port"];
@@ -44,7 +44,13 @@ bool MainMenuSystem::OnButtonPress(const Events::ButtonPressed& e)
bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
{
if(e.Command == "Play" && e.Value == 1) {
if (e.Command == "Host" && e.Value == 1) {
printf("Sending event...\n");
m_EventBroker->Publish(Events::BecomeServer());
return true;
}
if (e.Command == "Play" && e.Value == 1) {
m_EventBroker->Publish(Events::BecomeClient());
auto menus = m_World->GetComponents("Menu");
if (menus == nullptr) {
return 0;
@@ -64,7 +70,7 @@ bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
break;
}
} else if(!m_OpenSubMenu.HasComponent("ServerList")) {
} 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;
@@ -85,7 +91,7 @@ bool MainMenuSystem::OnInputCommand(const Events::InputCommand& e)
m_World->DeleteEntity(m_OpenSubMenu.ID);
m_OpenSubMenu = EntityWrapper::Invalid;
}
} else if (e.Command == "RefreshServerList" && e.Value == 1){
} else if (e.Command == "RefreshServerList" && e.Value == 1) {
Events::SearchForServers event;
m_EventBroker->Publish(event);
}
+1 -15
View File
@@ -8,7 +8,6 @@ SpectatorCameraSystem::SpectatorCameraSystem(SystemParams params)
, m_PickedTeam(-1)
{
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SpectatorCameraSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_EDisconnect, &SpectatorCameraSystem::OnDisconnect);
}
void SpectatorCameraSystem::Update(double dt)
@@ -88,17 +87,4 @@ bool SpectatorCameraSystem::OnInputCommand(const Events::InputCommand& e)
}
return true;
}
bool SpectatorCameraSystem::OnDisconnect(const Events::PlayerDisconnected& e)
{
// If local player gets disconnected, they should be set to
// the spectator camera next time a map loads that has one.
if (e.Entity == LocalPlayer.ID) {
m_CamSetToTeamPick = false;
// They will also be set to menu, so unlock mouse just in case they were in game with locked mouse.
Events::UnlockMouse unlock;
m_EventBroker->Publish(unlock);
}
return true;
}
}