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

View file

@ -1,6 +1,7 @@
#pragma once
namespace map {
// action, that takes place on map
class Action {
private:
public:

View file

@ -1,7 +1,7 @@
#pragma once
namespace map {
enum CellType { // needed to choose final types
enum class CellType { // needed to choose final types
ctNone,
ctUnit,
ctWeapon,
@ -9,7 +9,7 @@ namespace map {
ctMoutain
};
enum CellPlayer {
enum class CellPlayer {
cpNone,
cpPlayer0,
cpPlayer1,

View file

@ -8,9 +8,13 @@
namespace unit {
class Unit {
private:
// parts of unit, that do something
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:
Unit();

View file

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