author | terom |
Tue, 18 Nov 2008 22:58:50 +0000 | |
branch | no-netsession |
changeset 35 | e21cfda0edde |
parent 28 | 3da59a3bc92e |
permissions | -rw-r--r-- |
21 | 1 |
|
2 |
#include "Engine.hh" |
|
3 |
#include "NetworkServer.hh" |
|
4 |
#include "NetworkClient.hh" |
|
35 | 5 |
#include "SinglePlayer.hh" |
21 | 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 |
||
25 | 13 |
void Engine::setupGraphics (void) { |
14 |
// create the graphics |
|
15 |
graphics = new Graphics(*this, game_state); |
|
21 | 16 |
} |
17 |
||
25 | 18 |
void Engine::setupNetworkServer (const std::string &listen_port) { |
19 |
// create the server |
|
20 |
net_server = new NetworkServer(game_state, listen_port); |
|
21 |
} |
|
21 | 22 |
|
25 | 23 |
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) { |
24 | 24 |
// connect_to |
25 |
CL_IPAddress connect_addr(connect_host, connect_port); |
|
21 | 26 |
|
25 | 27 |
// create the client |
28 |
net_client = new NetworkClient(game_state, connect_addr); |
|
21 | 29 |
} |
30 |
||
35 | 31 |
void Engine::setupSinglePlayer (void) { |
32 |
// create player directly |
|
33 |
LocalPlayer* lp = new SinglePlayer(game_state); |
|
34 |
||
35 |
// add to gamestate |
|
36 |
game_state.newLocalPlayer(lp); |
|
37 |
} |
|
38 |
||
25 | 39 |
void Engine::stop (void) { |
40 |
is_running = false; |
|
41 |
} |
|
42 |
||
43 |
void Engine::run (void) { |
|
24 | 44 |
while (is_running) { |
45 |
// this does.... magical things |
|
46 |
CL_System::keep_alive(); |
|
21 | 47 |
|
24 | 48 |
// if I can't find some better way to do this in ClanLib by next thursday, then it f*%!ing sucks |
49 |
// ideally, we should be able to have a main loop that does timed waits on I/O, fufilling some set of timers |
|
50 |
// but as far as I can tell, ClanLib doesn't have anything like that |
|
35 | 51 |
CL_System::sleep(10); |
24 | 52 |
} |
21 | 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 | 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 |