mirror of
https://github.com/ProgramSnail/rts_game_backend.git
synced 2026-01-07 20:25:08 +00:00
some improvements
This commit is contained in:
parent
4f2bfac443
commit
4406ca4167
5 changed files with 17 additions and 20 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace unit {
|
|
||||||
struct MemoryElem {
|
|
||||||
int value = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue