Packets.h 713 B

12345678910111213141516171819202122232425262728293031
  1. #ifndef PACKETS_H
  2. #define PACKETS_H
  3. #include "math/Vector.h"
  4. #include "network/Packet.h"
  5. namespace Packets {
  6. // packets from the server to clients
  7. enum ServerPacket { S_CHAT, S_WORLD_SEGMENT, S_ENTITY_UPDATE };
  8. // packets from clients to the server
  9. enum ClientPacket { C_CHAT, C_CONTROLLER };
  10. template<int N>
  11. void writeVector(OutPacket& out, const Vector<N>& v) {
  12. for(int i = 0; i < N; i++) {
  13. out.writeFloat(v[i]);
  14. }
  15. }
  16. template<int N>
  17. bool readVector(InPacket& in, Vector<N>& v) {
  18. for(int i = 0; i < N; i++) {
  19. if(in.readFloat(v[i])) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. }
  26. #endif