splitUpdatesLogic.h 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <worldGenerator.h>
  3. #include <multyPlayer/chunkSaver.h>
  4. #include <multyPlayer/serverChunkStorer.h>
  5. #include <thread>
  6. #include <atomic>
  7. struct Client;
  8. struct ThreadPool
  9. {
  10. ThreadPool() {};
  11. constexpr static int MAX_THREADS = 12;
  12. int currentCounter = 0;
  13. std::thread threads[MAX_THREADS] = {};
  14. std::atomic_bool running[MAX_THREADS] = {};
  15. std::atomic_bool threIsWork[MAX_THREADS] = {};
  16. std::deque<std::atomic<bool>> taskTaken;
  17. void setThreadsNumber(int nr, void(*worker)(int, ThreadPool&));
  18. void setThrerIsWork();
  19. void waitForEveryoneToFinish();
  20. void cleanup();
  21. };
  22. void closeThreadPool();
  23. int getThredPoolSize();
  24. void splitUpdatesLogic(float tickDeltaTime,
  25. int tickDeltaTimeMs,
  26. std::uint64_t currentTimer,
  27. ServerChunkStorer &chunkCache, unsigned int seed,
  28. std::unordered_map<std::uint64_t, Client> &clients,
  29. WorldSaver &worldSaver, std::vector<ServerTask> &waitingTasks,
  30. Profiler &serverProfiler
  31. );