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-- |
21 | 1 |
|
2 |
#include "Engine.hh" |
|
3 |
#include "NetworkServer.hh" |
|
4 |
#include "NetworkClient.hh" |
|
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 | 8 |
Engine::Engine (void) : is_running(true) { |
9 |
||
10 |
} |
|
11 |
||
25 | 12 |
void Engine::setupGraphics (void) { |
13 |
// create the graphics |
|
14 |
graphics = new Graphics(*this, game_state); |
|
21 | 15 |
} |
16 |
||
25 | 17 |
void Engine::setupNetworkServer (const std::string &listen_port) { |
18 |
// create the server |
|
19 |
net_server = new NetworkServer(game_state, listen_port); |
|
20 |
} |
|
21 | 21 |
|
25 | 22 |
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) { |
24 | 23 |
// connect_to |
24 |
CL_IPAddress connect_addr(connect_host, connect_port); |
|
21 | 25 |
|
25 | 26 |
// create the client |
27 |
net_client = new NetworkClient(game_state, connect_addr); |
|
21 | 28 |
} |
29 |
||
25 | 30 |
void Engine::stop (void) { |
31 |
is_running = false; |
|
32 |
} |
|
33 |
||
34 |
void Engine::run (void) { |
|
24 | 35 |
while (is_running) { |
36 |
// this does.... magical things |
|
37 |
CL_System::keep_alive(); |
|
21 | 38 |
|
24 | 39 |
// if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks |
40 |
// ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers |
|
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 | 43 |
} |
21 | 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 | 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 |