src/proto2/Engine.cc
author terom
Tue, 18 Nov 2008 22:58:50 +0000
branchno-netsession
changeset 35 e21cfda0edde
parent 28 3da59a3bc92e
permissions -rw-r--r--
Merge from at r31:36
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     1
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     2
#include "Engine.hh"
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     3
#include "NetworkServer.hh"
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     4
#include "NetworkClient.hh"
35
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
     5
#include "SinglePlayer.hh"
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     6
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
     7
#include <iostream>
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
     8
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     9
Engine::Engine (void) : is_running(true) {
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    10
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    11
}
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    12
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    13
void Engine::setupGraphics (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    14
    // create the graphics
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    15
    graphics = new Graphics(*this, game_state);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    16
}
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    17
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    18
void Engine::setupNetworkServer (const std::string &listen_port) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    19
    // create the server
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    20
    net_server = new NetworkServer(game_state, listen_port);
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    21
}
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    22
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    23
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    24
    // connect_to
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    25
    CL_IPAddress connect_addr(connect_host, connect_port);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    26
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    27
    // create the client
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    28
    net_client = new NetworkClient(game_state, connect_addr);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    29
}
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    30
35
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    31
void Engine::setupSinglePlayer (void) {
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    32
    // create player directly
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    33
 	LocalPlayer* lp = new SinglePlayer(game_state);
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    34
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    35
    // add to gamestate
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    36
	game_state.newLocalPlayer(lp);
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    37
}
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    38
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    39
void Engine::stop (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    40
    is_running = false;
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    41
}
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    42
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    43
void Engine::run (void) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    44
    while (is_running) {
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    45
        // this does.... magical things
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    46
        CL_System::keep_alive();
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    47
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    48
        // if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    49
        // ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    50
        // but as far as I can tell, ClanLib doesn't have anything like that
35
e21cfda0edde Merge from at r31:36
terom
parents: 28
diff changeset
    51
        CL_System::sleep(10);
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    52
    }
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    53
}
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    54
23
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 22
diff changeset
    55
Logger Engine::log (enum LogLevel level, const char *type) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    56
    return Logger(level <= WARN ? std::cerr : std::cout, level, type);
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    57
}
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    58