Created a static accesser for the Engine.
This commit is contained in:
@@ -11,17 +11,26 @@
|
||||
|
||||
namespace DouwcoHivemind {
|
||||
class Engine {
|
||||
private:
|
||||
static Engine* instance;
|
||||
|
||||
public:
|
||||
std::map<std::string, std::unique_ptr<Room>> Rooms;
|
||||
std::map<std::string, std::unique_ptr<CreepBase>> Creeps;
|
||||
std::map<std::string, std::unique_ptr<StructureBase>> Structures;
|
||||
|
||||
public:
|
||||
// Static singleton access
|
||||
static Engine* getInstance(){
|
||||
return instance;
|
||||
}
|
||||
// Readout data from screeps API into C++ vectors
|
||||
Engine();
|
||||
// Loop over all rooms, screeps and structures
|
||||
void loop();
|
||||
|
||||
|
||||
|
||||
private:
|
||||
// Readout player owned rooms
|
||||
void ReadOutRooms();
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "Structures/Tower.hpp"
|
||||
|
||||
DouwcoHivemind::Engine::Engine() {
|
||||
instance = this;
|
||||
JS::console.log(std::string("Reading out owned rooms"));
|
||||
ReadOutRooms();
|
||||
JS::console.log(std::string("Reading out creeps"));
|
||||
|
||||
@@ -10,23 +10,24 @@
|
||||
#include "Structures/Spawn.hpp"
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE
|
||||
extern "C" void loop()
|
||||
{
|
||||
extern "C" void loop() {
|
||||
Screeps::Context::update();
|
||||
|
||||
JS::console.log(std::string("\n\n\n\n\n\n\n\n\n"));
|
||||
JS::console.log(std::string("Processing tick:\t") + std::to_string(Screeps::Game.time()));
|
||||
JS::console.log(std::string("Processing tick:\t") +
|
||||
std::to_string(Screeps::Game.time()));
|
||||
|
||||
{
|
||||
DouwcoHivemind::Engine engine;
|
||||
engine.loop();
|
||||
|
||||
auto test = &(DouwcoHivemind::Engine::getInstance()->Structures);
|
||||
JS::console.log(std::string("test: ") + std::to_string(test->size()));
|
||||
}
|
||||
|
||||
JS::console.log("Used CPU:\t" + std::to_string(Screeps::Game.cpuGetUsed()));
|
||||
JS::console.log("Bucket:\t" + std::to_string(static_cast<int>(Screeps::Game.cpu()["bucket"])));
|
||||
JS::console.log("Bucket:\t" + std::to_string(static_cast<int>(
|
||||
Screeps::Game.cpu()["bucket"])));
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(loop)
|
||||
{
|
||||
emscripten::function("loop", &loop);
|
||||
}
|
||||
EMSCRIPTEN_BINDINGS(loop) { emscripten::function("loop", &loop); }
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <Screeps/Game.hpp>
|
||||
#include <Screeps/Room.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "Creeps/CreepBase.hpp"
|
||||
#include "Engine.hpp"
|
||||
#include "Screeps/Constants.hpp"
|
||||
#include "Screeps/Creep.hpp"
|
||||
#include "Structures/Tower.hpp"
|
||||
|
||||
Reference in New Issue
Block a user