DEADSOFTWARE

Изменён способ передачи does команд и исправлены адские тормоза
[netwar.git] / protocol.h
index 26815532050839457926e8bb89b51c21bd170a71..68ec54a55aaa9a7c44b2a1af22c74c6c66a71652 100644 (file)
@@ -5,8 +5,8 @@
 #include <stdbool.h>
 #include <string.h>
 
-#define DEFAULT_PORT     29386
-#define PROTOCOL_VERSION 0
+#define PROTOCOL_PORT    29386
+#define PROTOCOL_VERSION 2
 #define PROTOCOL_F8FRAC  (1 << 7)
 
 #define PACKED __attribute__((__packed__))
@@ -21,15 +21,19 @@ typedef enum {
        SV_INFO = 128,
        SV_KILL = 139,
        SV_SPLR = 130,
+       SV_SBUL = 131,
 } MessageType;
 
-typedef enum {
-       DOES_UP    = 0,
-       DOES_DOWN  = 1,
-       DOES_LEFT  = 2,
-       DOES_RIGHT = 3,
-       DOES_FIRE  = 4,
-} DoesCode;
+typedef union DoesBits {
+       uint8_t bits;
+       struct PACKED {
+               uint8_t up    : 1;
+               uint8_t down  : 1;
+               uint8_t left  : 1;
+               uint8_t right : 1;
+               uint8_t fire  : 1;
+       };
+} DoesBits;
 
 typedef struct PACKED ClInfo {
        uint8_t type;
@@ -42,8 +46,8 @@ typedef struct PACKED ClKill {
 } ClKill;
 
 typedef struct PACKED ClDoes {
-       uint8_t type;
-       uint8_t code;
+       uint8_t  type;
+       DoesBits code;
 } ClDoes;
 
 typedef struct PACKED SvInfo {
@@ -67,6 +71,16 @@ typedef struct PACKED SvSplr {
        uint8_t vx, vy, vr;
 } SvSplr;
 
+typedef struct PACKED SvSbul {
+       uint8_t type;
+       uint8_t id;
+       uint8_t owner;
+       uint8_t live;
+       uint8_t x, y;
+       uint8_t vx, vy;
+       uint8_t tick;
+} SvSbul;
+
 typedef union ClMessage {
        uint8_t type;
        ClInfo  info;
@@ -79,6 +93,7 @@ typedef union SvMessage {
        SvInfo  info;
        SvKill  kill;
        SvSplr  splr;
+       SvSbul  sbul;
 } SvMessage;
 
 typedef union ProtocolMessage {
@@ -99,6 +114,7 @@ static inline int  MessageTypeSize(MessageType type) {
        case SV_INFO: return sizeof(SvInfo);
        case SV_KILL: return sizeof(SvKill);
        case SV_SPLR: return sizeof(SvSplr);
+       case SV_SBUL: return sizeof(SvSbul);
        default:      return sizeof(ProtocolMessage);
        }
 }
@@ -122,7 +138,7 @@ static inline ProtocolMessage cl_kill() {
        };
 }
 
-static inline ProtocolMessage cl_does(DoesCode code) {
+static inline ProtocolMessage cl_does(DoesBits code) {
        return (ProtocolMessage) (ClMessage) (ClDoes) {
                .type = CL_DOES,
                .code = code,
@@ -162,6 +178,20 @@ static inline ProtocolMessage sv_splr(int clid, bool live, float x, float y, flo
        };
 }
 
+static inline ProtocolMessage sv_sbul(int id, int owner, bool live, float x, float y, float vx, float vy, int tick) {
+       return (ProtocolMessage) (SvMessage) (SvSbul) {
+               .type  = SV_SBUL,
+               .id    = id,
+               .owner = owner,
+               .live  = live,
+               .x     = f2b(x),
+               .y     = f2b(y),
+               .vx    = f2b(vx),
+               .vy    = f2b(vy),
+               .tick  = tick,
+       };
+}
+
 #undef PACKED
 
 #endif /* PROTOCOL_H_INCLUDED */