Merge branch 'message' into pathfinding
This commit is contained in:
commit
dac18364aa
@ -19,6 +19,7 @@ Engine::Engine() :
|
|||||||
m_clock = new sf::Clock();
|
m_clock = new sf::Clock();
|
||||||
m_clock->restart();
|
m_clock->restart();
|
||||||
m_renderer = new SparrowRenderer();
|
m_renderer = new SparrowRenderer();
|
||||||
|
|
||||||
//m_renderer->setCamera(NULL);
|
//m_renderer->setCamera(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ Engine::~Engine()
|
|||||||
delete m_clock;
|
delete m_clock;
|
||||||
if(m_window != NULL)
|
if(m_window != NULL)
|
||||||
// m_renderer->destroyGL();
|
// m_renderer->destroyGL();
|
||||||
|
// m_renderer->destroyGL();
|
||||||
delete m_renderer;
|
delete m_renderer;
|
||||||
if(m_window != NULL)
|
if(m_window != NULL)
|
||||||
{
|
{
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include "tools/loader.h"
|
#include "tools/loader.h"
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
/* CameraNode camera;
|
/* CameraNode camera;
|
||||||
RESOURCE_ADD(&camera, SceneNode, "camera");
|
RESOURCE_ADD(&camera, SceneNode, "camera");
|
||||||
|
|
||||||
Scene scene("testScene");
|
Scene scene("testScene");
|
||||||
@ -44,9 +44,10 @@ int main(){
|
|||||||
std::cout << "Path Size: " << path.size() << std::endl;
|
std::cout << "Path Size: " << path.size() << std::endl;
|
||||||
for(GraphNode* gn: path){
|
for(GraphNode* gn: path){
|
||||||
std::cout << gn->getValue() << std::endl;
|
std::cout << gn->getValue() << std::endl;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
Loader::setObjDirectory("../data/");
|
Loader::setObjDirectory("../data/");
|
||||||
Loader::setMtlDirectory("../data/");
|
Loader::setMtlDirectory("../data/");
|
||||||
Loader::setTexDirectory("../data/");
|
Loader::setTexDirectory("../data/");
|
||||||
std::vector<Mesh*> meshes = Loader::loadMesh("sword.obj");
|
std::vector<Mesh*> meshes = Loader::loadMesh("sword.obj");*/
|
||||||
}
|
}
|
||||||
|
7
src/message.cpp
Normal file
7
src/message.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "message.h"
|
||||||
|
|
||||||
|
|
||||||
|
Message::Message(std::string id, SystemType sender):m_id(id),m_sender(sender)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
18
src/message.h
Normal file
18
src/message.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef MESSAGE_H
|
||||||
|
#define MESSAGE_H
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
class Message
|
||||||
|
{
|
||||||
|
std::string m_id;
|
||||||
|
SystemType m_sender;
|
||||||
|
public:
|
||||||
|
Message(std::string,SystemType);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // MESSAGE_H
|
29
src/messagebus.cpp
Normal file
29
src/messagebus.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "messagebus.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
MessageBus::MessageBus()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBus::registerSystem(SystemType type, System* system){
|
||||||
|
systems[type] = system;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBus::update()
|
||||||
|
{
|
||||||
|
while (!message_list.empty()){
|
||||||
|
Message* msg = message_list.front();
|
||||||
|
message_list.pop();
|
||||||
|
for(auto const &entity : systems){
|
||||||
|
entity.second->handleMessage(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MessageBus::postMessage(Message *msg)
|
||||||
|
{
|
||||||
|
message_list.push(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
26
src/messagebus.h
Normal file
26
src/messagebus.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MESSAGEBUS_H
|
||||||
|
#define MESSAGEBUS_H
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
class Message;
|
||||||
|
class System;
|
||||||
|
|
||||||
|
class MessageBus
|
||||||
|
{
|
||||||
|
std::map<SystemType,System*> systems;
|
||||||
|
std::queue<Message*> message_list; //message file
|
||||||
|
|
||||||
|
public:
|
||||||
|
MessageBus();
|
||||||
|
void registerSystem(SystemType,System*);
|
||||||
|
void postMessage(Message* msg);
|
||||||
|
void update();
|
||||||
|
void handleMessage();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MESSAGEBUS_H
|
51
src/sparrowshell.cpp
Normal file
51
src/sparrowshell.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "sparrowshell.h"
|
||||||
|
|
||||||
|
#include "message.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
|
const int SparrowShell::BUFFER_MAX_LENGTH = 50;
|
||||||
|
const int SparrowShell::BUFFER_DISPLAYED_NUMBER = 10;
|
||||||
|
const int SparrowShell::SCROLLBAR_PIXEL_WIDTH = 2;
|
||||||
|
|
||||||
|
SparrowShell::SparrowShell(sf::Window* window, Input* input): m_position(glm::ivec2(0,0)),m_window(window),m_input(input),m_scrollbar(this)
|
||||||
|
{
|
||||||
|
//m_dimension = glm::ivec2();//
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::out(std::string s)
|
||||||
|
{
|
||||||
|
if (m_buffer.size() == BUFFER_MAX_LENGTH)
|
||||||
|
m_buffer.pop_back();
|
||||||
|
m_buffer.push_front(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::scrollUp(){
|
||||||
|
if (m_index + BUFFER_DISPLAYED_NUMBER < m_buffer.size()) m_index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::scrollDown(){
|
||||||
|
if (m_index > 0) m_index--;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::update()
|
||||||
|
{
|
||||||
|
//TODO : update TextMesh
|
||||||
|
m_scrollbar.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
SparrowShell::ScrollBar::ScrollBar(SparrowShell* shell):m_shell(shell){
|
||||||
|
m_position = glm::ivec2(m_shell->m_dimension.x - SCROLLBAR_PIXEL_WIDTH,0);
|
||||||
|
m_dimension = glm::ivec2(SCROLLBAR_PIXEL_WIDTH,m_shell->m_dimension.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SparrowShell::ScrollBar::update(){
|
||||||
|
m_position.y = m_shell->m_position.y;
|
||||||
|
m_dimension.y = m_shell->m_dimension.y;
|
||||||
|
|
||||||
|
if (m_shell->m_buffer.size() > BUFFER_DISPLAYED_NUMBER){
|
||||||
|
float cran = ((float)m_shell->m_dimension.y/(float)m_shell->m_buffer.size());
|
||||||
|
int indexCursor = m_shell->m_buffer.size()-(m_shell->m_index+SCROLLBAR_PIXEL_WIDTH);
|
||||||
|
m_position.y += (int)(cran * indexCursor);
|
||||||
|
m_dimension.y = (int)(cran * BUFFER_DISPLAYED_NUMBER);
|
||||||
|
}
|
||||||
|
}
|
55
src/sparrowshell.h
Normal file
55
src/sparrowshell.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef SPARROWSHELL_H
|
||||||
|
#define SPARROWSHELL_H
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
#include "system.h"
|
||||||
|
#include "scene.h"
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
class Input;
|
||||||
|
|
||||||
|
namespace sf {
|
||||||
|
class Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SparrowShell : public SceneNode
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
class ScrollBar{
|
||||||
|
SparrowShell* m_shell;
|
||||||
|
glm::ivec2 m_position;
|
||||||
|
glm::ivec2 m_dimension;
|
||||||
|
//TODO : Add rectangle mesh
|
||||||
|
|
||||||
|
public:
|
||||||
|
ScrollBar();
|
||||||
|
ScrollBar(SparrowShell* shell);
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
static const int BUFFER_MAX_LENGTH;
|
||||||
|
static const int BUFFER_DISPLAYED_NUMBER;
|
||||||
|
static const int SCROLLBAR_PIXEL_WIDTH;
|
||||||
|
|
||||||
|
std::list<std::string> m_buffer;
|
||||||
|
sf::Window* m_window;
|
||||||
|
Input* m_input;
|
||||||
|
int m_index = 0;
|
||||||
|
|
||||||
|
glm::ivec2 m_position;
|
||||||
|
glm::ivec2 m_dimension;
|
||||||
|
|
||||||
|
//textMesh
|
||||||
|
ScrollBar m_scrollbar;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SparrowShell(sf::Window*, Input*);
|
||||||
|
|
||||||
|
void update();
|
||||||
|
void scrollUp();
|
||||||
|
void scrollDown();
|
||||||
|
void out(std::string);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SPARROWSHELL_H
|
28
src/system.cpp
Normal file
28
src/system.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
#include "messagebus.h"
|
||||||
|
#include "message.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
System::System()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
InputSystem::InputSystem(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputSystem::initInput(sf::Window *window){
|
||||||
|
m_input = new Input(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InputSystem::update(){
|
||||||
|
int action;
|
||||||
|
Message* message;
|
||||||
|
while (action = m_input->getAction() != NO_ACTION){
|
||||||
|
message = new Message(std::to_string(action),SystemType::INPUT_SYSTEM);
|
||||||
|
m_msgBus->postMessage(message);
|
||||||
|
}
|
||||||
|
}
|
36
src/system.h
Normal file
36
src/system.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef SYSTEM_H
|
||||||
|
#define SYSTEM_H
|
||||||
|
|
||||||
|
class MessageBus;
|
||||||
|
class Message;
|
||||||
|
class Input;
|
||||||
|
|
||||||
|
namespace sf{
|
||||||
|
class Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO:complete this part with other existing system,
|
||||||
|
enum SystemType {INPUT_SYSTEM, RENDERER_SYSTEM, IA_SYSTEM,GAME_SYSTEM,LENGTH};
|
||||||
|
|
||||||
|
class System
|
||||||
|
{
|
||||||
|
SystemType m_type;
|
||||||
|
protected:
|
||||||
|
MessageBus* m_msgBus;
|
||||||
|
|
||||||
|
public:
|
||||||
|
System();
|
||||||
|
virtual void handleMessage(Message* message) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class InputSystem : public System{
|
||||||
|
private:
|
||||||
|
Input* m_input;
|
||||||
|
public:
|
||||||
|
InputSystem();
|
||||||
|
~InputSystem();
|
||||||
|
void initInput(sf::Window* window);
|
||||||
|
void update();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SYSTEM_H
|
Loading…
x
Reference in New Issue
Block a user