Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0a1550acd | |||
| 7d4b9927d8 | |||
| 0ee3385e96 | |||
| d7f166b8ae | |||
| 28de31d84d | |||
| e9ef0e7060 | |||
| 416f55b6ce | |||
| 0346f81234 | |||
| a6ef026db5 | |||
| f26b24ef6b | |||
| 5e747f53db | |||
| 012420b4da | |||
| 50b0a091ec | |||
| 727b6ba871 | |||
| e11cdaa662 |
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "Input/EInputCommand.h"
|
||||
#include "Network/ESearchForServers.h"
|
||||
#include "Network/EConnectRequest.h"
|
||||
#include "Network/EBecomeServerOrClient.h"
|
||||
|
||||
|
||||
class MainMenuSystem : public ImpureSystem
|
||||
|
||||
@@ -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>
|
||||
|
||||
+6087
-6008
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,7 @@ glm::vec3 Transform::AbsolutePosition(World* world, EntityID entity)
|
||||
while (entity != EntityID_Invalid) {
|
||||
ComponentWrapper transform = world->GetComponent(entity, "Transform");
|
||||
EntityID parent = world->GetParent(entity);
|
||||
position += Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"];
|
||||
position += Transform::AbsoluteScale(world, parent) * (Transform::AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]);
|
||||
entity = parent;
|
||||
}
|
||||
|
||||
@@ -89,12 +89,12 @@ glm::mat4 Transform::ModelMatrix(EntityID entity, World* world)
|
||||
{
|
||||
return AbsoluteTransformation(EntityWrapper(world, entity));
|
||||
|
||||
glm::vec3 position = Transform::AbsolutePosition(world, entity);
|
||||
glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
|
||||
glm::vec3 scale = Transform::AbsoluteScale(world, entity);
|
||||
//glm::vec3 position = Transform::AbsolutePosition(world, entity);
|
||||
//glm::quat orientation = Transform::AbsoluteOrientation(world, entity);
|
||||
//glm::vec3 scale = Transform::AbsoluteScale(world, entity);
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
return modelMatrix;
|
||||
//glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
//return modelMatrix;
|
||||
}
|
||||
|
||||
glm::vec3 Transform::TransformPoint(const glm::vec3& point, const glm::mat4& matrix)
|
||||
|
||||
@@ -7,7 +7,7 @@ EditorRenderSystem::EditorRenderSystem(SystemParams params, IRenderer* renderer,
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &EditorRenderSystem::OnSetCamera);
|
||||
auto resolution = Rectangle::Rectangle(1280, 720);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_EditorCamera = new Camera((float)resolution.Width / resolution.Height, glm::radians(45.f), 0.001f, 500.f);
|
||||
}
|
||||
|
||||
void EditorRenderSystem::Update(double dt)
|
||||
|
||||
@@ -204,14 +204,21 @@ bool EditorSystem::OnWidgetDelta(const Events::WidgetDelta& e)
|
||||
if (m_CurrentSelection.Valid()) {
|
||||
if (m_WidgetSpace == EditorGUI::WidgetSpace::Global) {
|
||||
glm::quat parentOrientation;
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentOrientation = glm::inverse(Transform::AbsoluteOrientation(parent));
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
}
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation;
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += parentOrientation * e.Translation / parentScale;
|
||||
} else if (m_WidgetSpace == EditorGUI::WidgetSpace::Local) {
|
||||
glm::vec3 parentScale(1.f);
|
||||
EntityWrapper parent = m_CurrentSelection.Parent();
|
||||
if (parent.Valid()) {
|
||||
parentScale = Transform::AbsoluteScale(parent);
|
||||
}
|
||||
glm::quat selectionOri = glm::quat((glm::vec3)m_CurrentSelection["Transform"]["Orientation"]);
|
||||
glm::vec3 localTranslation = selectionOri * e.Translation;
|
||||
glm::vec3 localTranslation = selectionOri * e.Translation / parentScale;
|
||||
(glm::vec3&)m_CurrentSelection["Transform"]["Position"] += localTranslation;
|
||||
}
|
||||
m_EditorGUI->SetDirty(m_CurrentSelection);
|
||||
|
||||
@@ -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,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"];
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -208,18 +208,6 @@ bool PlayerSpawnSystem::OnPlayerSpawned(Events::PlayerSpawned& e)
|
||||
m_EventBroker->Publish(lock);
|
||||
}
|
||||
|
||||
// HACK: Set the player model color to team color
|
||||
EntityWrapper playerModel = e.Player.FirstChildByName("PlayerModel");
|
||||
if (playerModel.Valid() && e.Player.HasComponent("Team")) {
|
||||
ComponentWrapper cTeam = e.Player["Team"];
|
||||
ComponentWrapper cModel = playerModel["Model"];
|
||||
if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Red")) {
|
||||
cModel["Color"] = glm::vec3(1.f, 0.f, 0.f);
|
||||
} else if ((ComponentInfo::EnumType)cTeam["Team"] == cTeam["Team"].Enum("Blue")) {
|
||||
cModel["Color"] = glm::vec3(0.f, 0.25f, 1.f);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user