author | Tero Marttila <terom@fixme.fi> |
Sat, 17 Jan 2009 02:58:36 +0200 | |
changeset 405 | 7a8c7a0a1261 |
parent 389 | e74c1820fbd2 |
child 408 | e6cfc44266af |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#include "Engine.hh" |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
#include "SinglePlayer.hh" |
380 | 4 |
#include "Network/Reactor.hh" |
5 |
#include "Config.hh" |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
6 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
7 |
#include <iostream> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
8 |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
9 |
Engine::Engine (const std::string resource_xml_path) : |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
10 |
is_running(true), resources(resource_xml_path) |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
11 |
{ |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
12 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
|
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
15 |
void Engine::setupGraphics (PixelCoordinate resolution, bool fullscreen) { |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
16 |
// create the graphics |
389
e74c1820fbd2
implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
17 |
graphics = new Graphics(*this, game_state, resolution, fullscreen); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
20 |
void Engine::setupNetworkServer (const std::string &listen_port) { |
381
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
380
diff
changeset
|
21 |
NetworkEndpoint listen_addr(listen_port); |
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
380
diff
changeset
|
22 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
23 |
// create the server |
381
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
380
diff
changeset
|
24 |
net_server = new NetworkServer(game_state, listen_addr); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
25 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
27 |
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
28 |
// connect_to |
381
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
380
diff
changeset
|
29 |
NetworkEndpoint connect_addr(connect_host, connect_port); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
30 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
31 |
// create the client |
332
78657bf06302
handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents:
274
diff
changeset
|
32 |
net_client = new NetworkClient(*this, game_state, connect_addr); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
33 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
34 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
35 |
void Engine::setupSinglePlayer (void) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
36 |
// create player directly |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
37 |
LocalPlayer* lp = new SinglePlayer(game_state); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
38 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
39 |
// add to gamestate |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
233
diff
changeset
|
40 |
game_state.setLocalPlayer(lp); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
41 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
42 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
43 |
void Engine::stop (void) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
44 |
is_running = false; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
45 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
46 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
47 |
void Engine::run (void) { |
380 | 48 |
// our NetworkReactor |
49 |
NetworkReactor *reactor = NetworkReactor::current; |
|
50 |
||
51 |
// timeout info |
|
52 |
timeval timeout; |
|
53 |
||
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
54 |
while (is_running) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
55 |
// this does.... magical things |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
56 |
CL_System::keep_alive(); |
380 | 57 |
|
58 |
// setup our timeout to ENGINE_TIMEOUT_MS |
|
59 |
timeout.tv_sec = 0; |
|
60 |
timeout.tv_usec = ENGINE_TIMEOUT_MS * 1000; |
|
61 |
||
62 |
/* |
|
63 |
* Thursday came and went, I re-wrote clan-event. |
|
64 |
* |
|
65 |
* We use the NetworkReactor for sleeping, as it handles it effeciently even if we're not using network. |
|
66 |
*/ |
|
67 |
reactor->poll(&timeout); |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
68 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
69 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
70 |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
71 |
CL_ResourceManager* Engine::getResourceManager (void) { |
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
218
diff
changeset
|
72 |
return &resources; |
218
86d22fe82b30
add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents:
186
diff
changeset
|
73 |
} |
86d22fe82b30
add static Engine::graphicsEnabled function and disable player graphics loading when false
terom
parents:
186
diff
changeset
|
74 |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
75 |
Logger Engine::log (enum LogLevel level, const char *type) { |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
76 |
return Logger(level <= WARN ? std::cerr : std::cout, level, type); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
77 |
} |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
78 |