src/proto2/Network.hh
branchno-netsession
changeset 35 e21cfda0edde
parent 32 2ff929186c90
child 36 785d220fc6b7
equal deleted inserted replaced
34:1ea6554d703e 35:e21cfda0edde
     3 
     3 
     4 #include "NetworkConfig.hh"
     4 #include "NetworkConfig.hh"
     5 #include "GameState.hh"
     5 #include "GameState.hh"
     6 
     6 
     7 #include <ClanLib/network.h>
     7 #include <ClanLib/network.h>
       
     8 
       
     9 const int32_t COORDINATE_MAX = 1 << 30;
     8 
    10 
     9 class NetworkCore {
    11 class NetworkCore {
    10     protected:
    12     protected:
    11         GameState &state;
    13         GameState &state;
    12 
    14 
    13         CL_SlotContainer slots;
    15         CL_SlotContainer slots;
    14 
    16 
    15         // constructor
    17         // constructor
    16         NetworkCore (GameState &state) : state(state) { }
    18         NetworkCore (GameState &state) : state(state) { }
       
    19 
       
    20 
    17 };
    21 };
       
    22 
       
    23 // XXX: util methods
       
    24 void writeVector (CL_NetPacket &pkt, const Vector &vec);
       
    25 Vector readVector (CL_NetPacket &pkt);
    18 
    26 
    19 enum NetworkMessage {
    27 enum NetworkMessage {
    20     NETMSG_PACKET_INVALID   = 0x00,
    28     NETMSG_PACKET_INVALID   = 0x00,
    21 
    29 
    22     /*
    30     /*
    23      * You have joined the game:
    31      * You have joined the game:
    24      *
    32      *
    25      *  uint32_t x
    33      *  Vector      initial_position
    26      *  uint32_t y
       
    27      */
    34      */
    28     NETMSG_SERVER_HELLO = 0x0100,
    35     NETMSG_SERVER_HELLO = 0x0100,
    29 
    36 
    30     /*
    37     /*
    31      * New client has connected to server:
    38      * New client has connected to server:
    32      *
    39      *  
    33      *  uint32_t x
    40      *  Vector      initial_position
    34      *  uint32_t y
       
    35      */
    41      */
    36     NETMSG_PLAYER_JOIN  = 0x0101,
    42     NETMSG_PLAYER_JOIN  = 0x0101,
    37 
    43 
    38     /*
    44     /*
    39      * Client has left server:
    45      * Client has left server:
    42     NETMSG_PLAYER_QUIT  = 0x0102,
    48     NETMSG_PLAYER_QUIT  = 0x0102,
    43 
    49 
    44     /*
    50     /*
    45      * Client has moved
    51      * Client has moved
    46      *
    52      *
    47      *  int32_t dx
    53      *  Vector      impulse_force
    48      *  int32_t dy
    54      *  uint16_t    impulse_ms
    49      */
    55      */
    50     NETMSG_CLIENT_MOVE  = 0x0201,
    56     NETMSG_CLIENT_MOVE  = 0x0201,
    51     
    57     
    52     /*
    58     /*
    53      * Initial player info
    59      * Initial player info
    54      *
    60      *
    55      *  uint32_t x
    61      *  Vector      initial_position
    56      *  uint32_t y
       
    57      */
    62      */
    58     NETMSG_PLAYER_INFO  = 0x0300,
    63     NETMSG_PLAYER_INFO  = 0x0300,
    59 
    64 
    60     /*
    65     /*
    61      * Player position update
    66      * Player position update
    62      *
    67      *
    63      *  uint32_t x
    68      * Vector   position
    64      *  uint32_t y
    69      * Vector   velocity
    65      */
    70      */
    66     NETMSG_PLAYER_POSITION  = 0x0301,
    71     NETMSG_PLAYER_POSITION  = 0x0301,
    67 };
    72 };
    68 
    73 
    69 #endif
    74 #endif