// // Created by aurailus on 16/03/19. // #pragma once #include #include #include #include #include #include "../../../util/Vec.h" #include "../../../def/gen/MapGen.h" class Chunk; class LocalSubgame; class PacketView; class WorldInterpolationStream { public: static const int THREADS = 4; static const int THREAD_QUEUE_SIZE = 16; WorldInterpolationStream(unsigned int seed, LocalSubgame& game); // Queue parsing of packet `p`. void queuePacket(std::unique_ptr p); // Queue interpolation of Mapblock at `pos`. // bool queuePosition(glm::vec3 pos); // Returns a vector of BlockChunks that have finished processing, // and gives the threads new data to work with. std::unique_ptr>> update(); ~WorldInterpolationStream(); private: // enum class JobType { // EMPTY, // PACKET, // FARMAP // }; struct Job { bool locked = false; // JobType job = JobType::EMPTY; std::shared_ptr packet = nullptr; std::vector> chunks = {}; // std::shared_ptr mapblock = nullptr; // glm::vec3 mapBlockPos = {0, 0, 0}; }; struct Thread { explicit Thread(LocalSubgame& game, unsigned int seed); void exec(); bool kill = false; std::vector jobs = std::vector(THREAD_QUEUE_SIZE); MapGen gen; std::thread thread; }; std::vector threads; std::queue> queuedPacketTasks; // std::unordered_set queuedInterpMap; // std::queue queuedInterpTasks; };