some improvements

This commit is contained in:
ProgramSnail 2021-04-11 12:45:39 +03:00
parent 4f2bfac443
commit 4406ca4167
5 changed files with 17 additions and 20 deletions

View file

@ -1,7 +1,7 @@
#include <vector> #include <vector>
#include <functional> #include <functional>
#include <string> #include <string>
#include <map> #include <unordered_map>
#pragma once #pragma once
@ -15,9 +15,8 @@ namespace events {
public: public:
EventId() = default; EventId() = default;
EventId(std::string name) : name(name) { EventId(std::string name) : name(name),
nameHash = std::hash<std::string>{}(name); nameHash(std::hash<std::string>{}(name)) {}
}
bool operator==(const EventId& eId) const { bool operator==(const EventId& eId) const {
return nameHash == eId.nameHash && name == eId.name; return nameHash == eId.nameHash && name == eId.name;
@ -32,7 +31,7 @@ namespace events {
private: private:
using T = int; using T = int;
std::map<std::string, T> data; std::unordered_map<std::string, T> data;
public: public:
EventData() {} EventData() {}
@ -100,7 +99,7 @@ namespace events {
class EventCenter { class EventCenter {
private: private:
std::map<EventId, std::vector<EventHandler>> handlers; std::unordered_map<EventId, std::vector<EventHandler>> handlers;
public: public:
void addEventHandler(const EventHandler& handler) { void addEventHandler(const EventHandler& handler) {
handlers[handler.getEventId()].push_back(handler); handlers[handler.getEventId()].push_back(handler);

View file

@ -1,9 +1,10 @@
#pragma once #pragma once
namespace map { namespace map {
// action, that takes place on map
class Action { class Action {
private: private:
public: public:
void update(); void update();
}; };
} }

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
namespace map { namespace map {
enum CellType { // needed to choose final types enum class CellType { // needed to choose final types
ctNone, ctNone,
ctUnit, ctUnit,
ctWeapon, ctWeapon,
@ -9,7 +9,7 @@ namespace map {
ctMoutain ctMoutain
}; };
enum CellPlayer { enum class CellPlayer {
cpNone, cpNone,
cpPlayer0, cpPlayer0,
cpPlayer1, cpPlayer1,
@ -21,4 +21,4 @@ namespace map {
CellType type; CellType type;
// int ??speed??; // speed when move inside // int ??speed??; // speed when move inside
}; };
} }

View file

@ -8,12 +8,16 @@
namespace unit { namespace unit {
class Unit { class Unit {
private: private:
// parts of unit, that do something
std::vector<Module> modules; std::vector<Module> modules;
std::vector<MemoryElem> memory;
map::GameMap map; // memory, help modules communicate and handle events
std::vector<int> memory;
map::GameMap* map;
public: public:
Unit(); Unit();
void update(); void update();
}; };
} }

View file

@ -1,7 +0,0 @@
#pragma once
namespace unit {
struct MemoryElem {
int value = 0;
};
}