src/proto2/Network.hh
author saiam
Thu, 20 Nov 2008 21:25:09 +0000
changeset 83 cbba9729e92b
parent 66 1415a2d45686
child 89 825c4613e087
permissions -rw-r--r--
Integrointia fyssaan, jotain pikkubugausta havaittavissa.
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
     1
#ifndef NETWORK_HH
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
     2
#define NETWORK_HH
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
     3
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents: 15
diff changeset
     4
#include "NetworkConfig.hh"
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents: 15
diff changeset
     5
#include "GameState.hh"
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents: 15
diff changeset
     6
13
3fbb927c6a27 fix broken includes
terom
parents: 8
diff changeset
     7
#include <ClanLib/network.h>
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
     8
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
     9
const int32_t COORDINATE_MAX = 1 << 30;
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    10
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents: 15
diff changeset
    11
class NetworkCore {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    12
    protected:
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    13
        GameState &state;
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
    14
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    15
        CL_SlotContainer slots;
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    16
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    17
        CL_NetSession netsession;
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    18
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    19
        CL_NetObject_Controller netobjs;
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    20
        
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    21
        // constructor
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    22
        NetworkCore (GameState &state) : state(state), netsession(NETWORK_APP_NAME), netobjs(&netsession, NETWORK_NETOBJ_CHAN) { }
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    23
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    24
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    25
};
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    26
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    27
// XXX: util methods
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    28
void writeVector (CL_NetPacket &pkt, const Vector &vec);
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    29
Vector readVector (CL_NetPacket &pkt);
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    30
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    31
enum NetworkMessage {
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    32
    NETMSG_PACKET_INVALID   = 0x00,
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    33
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    34
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    35
     * You have joined the game:
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    36
     *
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    37
     *  Vector      initial_position
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    38
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    39
    NETMSG_SERVER_HELLO = 0x0100,
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    40
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    41
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    42
     * New client has connected to server:
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    43
     *  
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    44
     *  Vector      initial_position
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    45
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    46
    NETMSG_PLAYER_JOIN  = 0x0101,
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    47
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    48
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    49
     * Client has left server:
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    50
     *
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    51
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    52
    NETMSG_PLAYER_QUIT  = 0x0102,
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    53
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    54
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    55
     * Client has moved
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    56
     *
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    57
     *  Vector      impulse_force
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    58
     *  uint16_t    impulse_ms
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    59
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    60
    NETMSG_CLIENT_MOVE  = 0x0201,
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    61
    
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    62
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    63
     * Initial player info
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    64
     *
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    65
     *  Vector      initial_position
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    66
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    67
    NETMSG_PLAYER_INFO  = 0x0300,
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    68
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    69
    /*
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    70
     * Player position update
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    71
     *
66
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    72
     * Vector   position
1415a2d45686 working simple network-physics code
terom
parents: 25
diff changeset
    73
     * Vector   velocity
24
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    74
     */
b81cb670e6b2 the great :retab
terom
parents: 22
diff changeset
    75
    NETMSG_PLAYER_POSITION  = 0x0301,
5
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
    76
};
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
    77
617813994ab1 move proto/p2 -> src/proto2
terom
parents:
diff changeset
    78
#endif