author | terom |
Sat, 08 Nov 2008 21:25:56 +0000 | |
changeset 23 | 8d802b573cf0 |
parent 22 | b70d30e1b0fe |
child 24 | b81cb670e6b2 |
permissions | -rw-r--r-- |
21 | 1 |
|
2 |
#include "Engine.hh" |
|
3 |
#include "GameState.hh" |
|
4 |
#include "NetworkServer.hh" |
|
5 |
#include "NetworkClient.hh" |
|
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 | 9 |
Engine::Engine (void) : is_running(true) { |
10 |
||
11 |
} |
|
12 |
||
13 |
void Engine::runNetworkServer (const std::string &listen_port) { |
|
14 |
// the engine |
|
15 |
Engine engine; |
|
16 |
||
17 |
// setup network |
|
18 |
CL_SetupNetwork setup_network; |
|
19 |
||
20 |
try { |
|
21 |
// create the server |
|
22 |
engine.net_server = new NetworkServer(engine.game_state, listen_port); |
|
23 |
||
24 |
// run the main loop |
|
25 |
engine.main_loop(); |
|
26 |
||
27 |
} catch (CL_Error &e) { |
|
28 |
std::cerr << "NetworkServer::main: CL_Error:" << e.message << std::endl; |
|
29 |
||
30 |
throw; |
|
31 |
} |
|
32 |
} |
|
33 |
||
34 |
void Engine::runNetworkClient (const std::string &connect_host, const std::string &connect_port) { |
|
35 |
// the engine |
|
36 |
Engine engine; |
|
37 |
||
38 |
// setup network |
|
39 |
CL_SetupNetwork setup_network; |
|
40 |
||
41 |
// connect_to |
|
42 |
CL_IPAddress connect_addr(connect_host, connect_port); |
|
43 |
||
44 |
try { |
|
45 |
// create the server |
|
46 |
engine.net_client = new NetworkClient(engine.game_state, connect_addr); |
|
47 |
||
48 |
// run the main loop |
|
49 |
engine.main_loop(); |
|
50 |
||
51 |
} catch (CL_Error &e) { |
|
52 |
std::cerr << "NetworkServer::main: CL_Error:" << e.message << std::endl; |
|
53 |
||
54 |
throw; |
|
55 |
} |
|
56 |
||
57 |
} |
|
58 |
||
59 |
void Engine::main_loop (void) { |
|
60 |
while (is_running) { |
|
61 |
// this does.... magical things |
|
62 |
CL_System::keep_alive(); |
|
63 |
||
64 |
// if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks |
|
65 |
// ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers |
|
66 |
// but as far as I can tell, ClanLib doesn't have anything like that |
|
67 |
CL_System::sleep(100); |
|
68 |
||
69 |
} |
|
70 |
} |
|
22
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
71 |
|
23
8d802b573cf0
fixed more network code, there's actually a high probability of it working now
terom
parents:
22
diff
changeset
|
72 |
Logger Engine::log (enum LogLevel level, const char *type) { |
8d802b573cf0
fixed more network code, there's actually a high probability of it working now
terom
parents:
22
diff
changeset
|
73 |
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
|
74 |
} |
b70d30e1b0fe
all the network code is now there, although it doesn't quite work
terom
parents:
21
diff
changeset
|
75 |