src/proto2/Engine.cc
author terom
Mon, 10 Nov 2008 01:29:43 +0000
changeset 28 3da59a3bc92e
parent 25 af75a1894a32
child 35 e21cfda0edde
child 56 38f269310f77
permissions -rw-r--r--
add assert, lower main loop sleep interval to 20ms. CL_NetSession is buggy, goes into deadlock due to missing mutex
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"
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     5
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
     6
#include <iostream>
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
     7
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     8
Engine::Engine (void) : is_running(true) {
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
     9
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
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    12
void Engine::setupGraphics (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    13
    // create the graphics
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    14
    graphics = new Graphics(*this, game_state);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    15
}
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    16
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    17
void Engine::setupNetworkServer (const std::string &listen_port) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    18
    // create the server
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    19
    net_server = new NetworkServer(game_state, listen_port);
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    20
}
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    21
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    22
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    23
    // connect_to
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    24
    CL_IPAddress connect_addr(connect_host, connect_port);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    25
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    26
    // create the client
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    27
    net_client = new NetworkClient(game_state, connect_addr);
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    28
}
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    29
25
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    30
void Engine::stop (void) {
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    31
    is_running = false;
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    32
}
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    33
af75a1894a32 simple proto *almost* works
terom
parents: 24
diff changeset
    34
void Engine::run (void) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    35
    while (is_running) {
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    36
        // this does.... magical things
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    37
        CL_System::keep_alive();
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    38
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    39
        // 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
    40
        // 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
    41
        // but as far as I can tell, ClanLib doesn't have anything like that
28
3da59a3bc92e add assert, lower main loop sleep interval to 20ms. CL_NetSession is buggy, goes into deadlock due to missing mutex
terom
parents: 25
diff changeset
    42
        CL_System::sleep(20);
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    43
    }
21
32c6cc55256a change proto2 network code to use CL_NetSession
terom
parents:
diff changeset
    44
}
22
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    45
23
8d802b573cf0 fixed more network code, there's actually a high probability of it working now
terom
parents: 22
diff changeset
    46
Logger Engine::log (enum LogLevel level, const char *type) {
24
b81cb670e6b2 the great :retab
terom
parents: 23
diff changeset
    47
    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
    48
}
b70d30e1b0fe all the network code is now there, although it doesn't quite work
terom
parents: 21
diff changeset
    49