Created a static accesser for the Engine.

This commit is contained in:
2026-07-10 10:43:26 +02:00
parent a2d12f691f
commit 3148302aae
4 changed files with 28 additions and 15 deletions

View File

@@ -11,17 +11,26 @@
namespace DouwcoHivemind { namespace DouwcoHivemind {
class Engine { class Engine {
private:
static Engine* instance;
public: public:
std::map<std::string, std::unique_ptr<Room>> Rooms; 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<CreepBase>> Creeps;
std::map<std::string, std::unique_ptr<StructureBase>> Structures; std::map<std::string, std::unique_ptr<StructureBase>> Structures;
public: public:
// Static singleton access
static Engine* getInstance(){
return instance;
}
// Readout data from screeps API into C++ vectors // Readout data from screeps API into C++ vectors
Engine(); Engine();
// Loop over all rooms, screeps and structures // Loop over all rooms, screeps and structures
void loop(); void loop();
private: private:
// Readout player owned rooms // Readout player owned rooms
void ReadOutRooms(); void ReadOutRooms();

View File

@@ -18,6 +18,7 @@
#include "Structures/Tower.hpp" #include "Structures/Tower.hpp"
DouwcoHivemind::Engine::Engine() { DouwcoHivemind::Engine::Engine() {
instance = this;
JS::console.log(std::string("Reading out owned rooms")); JS::console.log(std::string("Reading out owned rooms"));
ReadOutRooms(); ReadOutRooms();
JS::console.log(std::string("Reading out creeps")); JS::console.log(std::string("Reading out creeps"));

View File

@@ -10,23 +10,24 @@
#include "Structures/Spawn.hpp" #include "Structures/Spawn.hpp"
EMSCRIPTEN_KEEPALIVE EMSCRIPTEN_KEEPALIVE
extern "C" void loop() extern "C" void loop() {
{
Screeps::Context::update(); Screeps::Context::update();
JS::console.log(std::string("\n\n\n\n\n\n\n\n\n")); 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; DouwcoHivemind::Engine engine;
engine.loop(); 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("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_BINDINGS(loop) { emscripten::function("loop", &loop); }
{
emscripten::function("loop", &loop);
}

View File

@@ -1,8 +1,10 @@
#include <Screeps/Game.hpp> #include <Screeps/Game.hpp>
#include <Screeps/Room.hpp> #include <Screeps/Room.hpp>
#include <cstdint> #include <cstdint>
#include <string>
#include "Creeps/CreepBase.hpp" #include "Creeps/CreepBase.hpp"
#include "Engine.hpp"
#include "Screeps/Constants.hpp" #include "Screeps/Constants.hpp"
#include "Screeps/Creep.hpp" #include "Screeps/Creep.hpp"
#include "Structures/Tower.hpp" #include "Structures/Tower.hpp"