server.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include <unordered_map>
  3. #include <glm/vec2.hpp>
  4. using CID = int32_t;
  5. bool isServerRunning();
  6. bool startServer();
  7. int getChunkCapacity();
  8. void closeServer();
  9. void serverWorkerFunction();
  10. struct PerClientServerSettings
  11. {
  12. bool validateStuff = true;
  13. };
  14. struct ServerSettings
  15. {
  16. std::unordered_map<CID, PerClientServerSettings> perClientSettings;
  17. };
  18. ServerSettings getServerSettingsCopy();
  19. void setServerSettings(ServerSettings settings);
  20. void addCidToServerSettings(CID cid);
  21. void removeCidFromServerSettings(CID cid);
  22. //https://www.geeksforgeeks.org/how-to-create-an-unordered_map-of-user-defined-class-in-cpp/
  23. struct Ivec2Hash
  24. {
  25. size_t operator()(const glm::ivec2 &in) const
  26. {
  27. int x = in.x;
  28. int z = in.y;
  29. size_t ret = 0;
  30. ret += x;
  31. ret += (z < 32);
  32. return ret;
  33. }
  34. };
  35. struct BlockInChunkPos
  36. {
  37. BlockInChunkPos() {};
  38. BlockInChunkPos(int x, int y, int z):x(x), y(y), z(z) {};
  39. unsigned char x = 0;
  40. unsigned char y = 0;
  41. unsigned char z = 0;
  42. bool operator==(const BlockInChunkPos &other)
  43. {
  44. return x == other.x && y == other.y && z == other.z;
  45. }
  46. };
  47. bool operator==(const BlockInChunkPos &a, const BlockInChunkPos &b);
  48. struct BlockInChunkHash
  49. {
  50. size_t operator()(const BlockInChunkPos &in) const
  51. {
  52. int x = in.x;
  53. int y = in.y;
  54. int z = in.z;
  55. size_t ret = 0;
  56. ret += x;
  57. ret += (y < 8);
  58. ret += (z < 16);
  59. return ret;
  60. }
  61. };