I'll create a GUI interface using Visual Basic, see if I can track an IP address

This commit is contained in:
2014-05-24 20:37:55 +02:00
parent 2fbcad4dbf
commit 07c74ff9f5
14 changed files with 401 additions and 85 deletions
+48 -14
View File
@@ -2,12 +2,14 @@
#define GUI_Frame_h__
#include <memory>
#include <map>
#include "Util/Rectangle.h"
#include "EventBroker.h"
// HACK: Decouple renderer plz
#include "ResourceManager.h"
#include "Renderer.h"
#include "RenderQueue.h"
#include "Texture.h"
namespace GUI
{
@@ -24,13 +26,16 @@ public:
};
// Set up a base frame with an event broker
Frame(std::shared_ptr<::EventBroker> eventBroker)
Frame(std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: EventBroker(eventBroker)
, Rectangle()
, ResourceManager(resourceManager)
, Rectangle()
, m_Name("UIParent")
{ Initialize(); }
// Create a frame as a child
Frame(std::shared_ptr<Frame> parent)
Frame(std::shared_ptr<Frame> parent, std::string name)
: Rectangle(static_cast<Rectangle>(*parent)) // Clone parent rectangle using copy constructor
, m_Name(name)
{ SetParent(parent); Initialize(); }
virtual void Initialize() { }
@@ -40,18 +45,15 @@ public:
parent->AddChild(std::shared_ptr<Frame>(this));
m_Parent = parent;
EventBroker = parent->EventBroker;
ResourceManager = parent->ResourceManager;
}
void AddChild(std::shared_ptr<Frame> child)
{
m_Children.push_back(child);
if (m_Parent != nullptr)
{
m_Parent->AddChild(child);
}
m_Children.push_back(std::make_pair(child->Name(), child));
}
typedef std::list<std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
typedef std::map<std::string, std::shared_ptr<Frame>>::const_iterator FrameChildrenIterator;
FrameChildrenIterator begin()
{
return m_Children.begin();
@@ -61,13 +63,45 @@ public:
return m_Children.end();
}
virtual void Update(double dt) { }
virtual void Draw(Renderer* renderer) { }
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
virtual void Update(double dt)
{
for (auto &pair : m_Children)
{
pair.second->Update(dt);
}
}
void DrawLayered(std::shared_ptr<Renderer> renderer)
{
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
this->Draw(renderer);
renderer->Draw();
for (auto &pair : m_Children)
{
pair.second->Draw(renderer);
}
}
virtual void Draw(std::shared_ptr<Renderer> renderer)
{
renderer->SetViewport(GetLeft(), GetTop(), GetRight(), GetBottom());
renderer->Draw();
}
protected:
std::shared_ptr<::EventBroker> EventBroker;
std::shared_ptr<::ResourceManager> ResourceManager;
std::string m_Name;
std::shared_ptr<Frame> m_Parent;
std::list<std::shared_ptr<Frame>> m_Children;
std::multimap<std::string, std::shared_ptr<Frame>> m_Children; // name -> frame
};
}
+52
View File
@@ -0,0 +1,52 @@
#ifndef GUI_TextureFrame_h__
#define GUI_TextureFrame_h__
#include "GUI/Frame.h"
#include "Texture.h"
namespace GUI
{
class TextureFrame : public Frame
{
public:
TextureFrame(std::shared_ptr<Frame> parent, std::string name)
: Frame(parent, name) { }
void Update(double dt) override
{
Frame::Update(dt);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
if (m_Texture == nullptr)
return;
RenderQueue<SpriteJob> rq;
auto textureAsset = ResourceManager->Load<Texture>("Texture", m_Texture);
SpriteJob job;
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
*glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
}
std::shared_ptr<::Texture> Texture() const { return m_Texture; }
void SetTexture(std::string resourceName)
{
m_Texture = std::shared_ptr<::Texture>(ResourceManager->Load<::Texture>("Texture", resourceName));
}
protected:
std::shared_ptr<::Texture> m_Texture;
};
}
#endif // GUI_TextureFrame_h__
+55 -3
View File
@@ -4,6 +4,11 @@
#include <memory>
#include "GUI/Frame.h"
#include "World.h"
#include "Components/Transform.h"
#include "Components/Camera.h"
#include "RenderQueue.h"
#include "Camera.h"
namespace GUI
{
@@ -11,9 +16,56 @@ namespace GUI
class Viewport : public Frame
{
public:
// Create a frame as a child
Viewport(std::shared_ptr<Frame> parent)
: Frame(parent) { }
Viewport(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{ }
EntityID CameraEntity() const { return m_CameraEntity; }
void SetCameraEntity(EntityID cameraEntity)
{
m_CameraEntity = cameraEntity;
auto transformComponent = m_World->GetComponent<Components::Transform>(cameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(cameraEntity);
if (!cameraComponent)
return;
m_Camera = std::make_shared<Camera>(cameraComponent->FOV, cameraComponent->NearClip, cameraComponent->FarClip);
}
void Initialize() override
{
}
void Update(double dt) override
{
auto transformComponent = m_World->GetComponent<Components::Transform>(m_CameraEntity);
if (!transformComponent)
return;
auto cameraComponent = m_World->GetComponent<Components::Camera>(m_CameraEntity);
if (!cameraComponent)
return;
m_Camera->SetFOV(cameraComponent->FOV);
m_Camera->SetNearClip(cameraComponent->NearClip);
m_Camera->SetFarClip(cameraComponent->FarClip);
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
renderer->SetCamera(m_Camera);
Frame::Draw(renderer);
}
private:
std::shared_ptr<World> m_World;
std::shared_ptr<Camera> m_Camera;
EntityID m_CameraEntity;
};
}
+144
View File
@@ -0,0 +1,144 @@
#ifndef GUI_WorldFrame_h__
#define GUI_WorldFrame_h__
#include "GUI/Frame.h"
#include "GUI/Viewport.h"
#include "RenderQueue.h"
#include "World.h"
#include "Systems/TransformSystem.h"
#include "Events/SetViewportCamera.h"
#include "Components/Transform.h"
#include "Components/Model.h"
#include "Components/Sprite.h"
#include "Components/PointLight.h"
namespace GUI
{
class WorldFrame : public Frame
{
public:
WorldFrame(std::shared_ptr<Frame> parent, std::string name, std::shared_ptr<World> world)
: Frame(parent, name)
, m_World(world)
{ }
void Initialize() override
{
EVENT_SUBSCRIBE_MEMBER(m_ESetViewportCamera, &WorldFrame::OnSetViewportCamera);
m_World->Initialize();
}
void Update(double dt) override
{
m_World->Update(dt);
m_TransformSystem = m_World->GetSystem<Systems::TransformSystem>();
}
void Draw(std::shared_ptr<Renderer> renderer) override
{
renderer->Flush();
RenderQueue<ModelJob> modelQueue;
RenderQueue<SpriteJob> spriteQueue;
for (auto &pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
auto transform = m_World->GetComponent<Components::Transform>(entity);
if (!transform)
continue;
auto modelComponent = m_World->GetComponent<Components::Model>(entity);
if (modelComponent)
{
auto modelAsset = ResourceManager->Load<Model>("Model", modelComponent->ModelFile);
if (modelAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::mat4 modelMatrix = glm::translate(glm::mat4(), absoluteTransform.Position)
* glm::toMat4(absoluteTransform.Orientation)
* glm::scale(absoluteTransform.Scale);
EnqueueModel(modelQueue, modelAsset, modelMatrix);
}
}
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
if (spriteComponent)
{
auto textureAsset = ResourceManager->Load<Texture>("Texture", spriteComponent->SpriteFile);
if (textureAsset)
{
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform->Orientation).z, glm::vec3(0, 0, -1));
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position);
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(spriteQueue, textureAsset, modelMatrix);
}
}
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
if (pointLightComponent)
{
// TODO: Push lights to renderer
// renderer->PushLight(...);
}
}
renderer->PushQueue(rq);
Frame::Draw(renderer);
}
protected:
std::shared_ptr<World> m_World;
private:
EventRelay<Frame, Events::SetViewportCamera> m_ESetViewportCamera;
bool OnSetViewportCamera(const Events::SetViewportCamera &event)
{
auto itpair = m_Children.equal_range(event.ViewportFrame);
for (auto it = itpair.first; it != itpair.second; ++it)
{
auto viewportFrame = std::dynamic_pointer_cast<GUI::Viewport>(it->second);
if (!viewportFrame)
continue;
viewportFrame->SetCamera(event.CameraEntity);
}
}
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
void EnqueueModel(RenderQueue<ModelJob> &renderQueue, Model* model, glm::mat4 modelMatrix)
{
for (auto texGroup : model->TextureGroups)
{
ModelJob job;
job.TextureID = texGroup.Texture->ResourceID;
job.DiffuseTexture = *texGroup.Texture;
job.NormalTexture = *texGroup.NormalMap;
job.SpecularTexture = *texGroup.SpecularMap;
job.VAO = model->VAO;
job.StartIndex = texGroup.StartIndex;
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
renderQueue.Add(job);
}
}
void EnqueueSprite(RenderQueue<SpriteJob> &renderQueue, Texture* texture, glm::mat4 modelMatrix)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
job.Texture = *texture;
job.ModelMatrix = modelMatrix;
}
};
}
#endif // GUI_WorldFrame_h__