src/Engine.cc
author Tero Marttila <terom@fixme.fi>
Thu, 22 Jan 2009 02:38:33 +0200
branchnew_graphics
changeset 418 194bc810a570
parent 417 c503e0c6a740
child 419 9cd4e54693b6
permissions -rw-r--r--
add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
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
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
     4
#include "Config.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     5
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
     6
// XXX: how does this work if we don't have NETWORK_ENABLED?
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
     7
#include "Network/Reactor.hh"
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
     8
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
     9
// include the real component definitions
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    10
#if NETWORK_ENABLED
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    11
    #include "Network/Client.hh"
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    12
    #include "Network/Server.hh"
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    13
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    14
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    15
#if GRAPHICS_ENABLED
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    16
    #include "Graphics/Graphics.hh"
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    17
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    18
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    19
#include <iostream>
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    20
#include <cassert>
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    21
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    22
/*
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    23
 * Initialize static Engine global state
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    24
 */
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    25
LogLevel Engine::log_level = DEBUG;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    26
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    27
Engine::Engine (const EngineConfig &config) : 
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    28
    terrain(NULL), game_state(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL),
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    29
    is_running(true), resources(config.resource_path)
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
    30
{
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    31
    // update global log_level
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    32
    Engine::log_level = config.log_level;
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
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    35
GameState& Engine::setupGame (Terrain *terrain) {
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    36
    // ensure this isn't called in inappropriate ways
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    37
    assert(!net_server);
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    38
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    39
    // remember the terrain
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    40
    this->terrain = terrain;
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    41
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    42
    // create the GameState
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    43
    game_state = new GameState(*terrain);
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    44
    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    45
    // XXX: NetworkClient + GameView?
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    46
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    47
    return *game_state;
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    48
}
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    49
        
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    50
void Engine::setupGame (const TerrainConfig &config) {
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    51
    // proxy off to setupGame(Terrain *)
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    52
    setupGame(new Terrain(config));
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    53
}
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    54
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    55
void Engine::setupGraphics (const DisplayConfig &config) {
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    56
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    57
#if GRAPHICS_ENABLED    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    58
    assert(!graphics);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    59
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    60
    // create the graphics
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    61
    graphics = new graphics::Graphics(*this, resources, config);
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    62
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    63
#else
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    64
    (void) config;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    65
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    66
    throw Error("No Graphics support available");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    67
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    68
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    69
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    70
}
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    71
        
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    72
void Engine::startGameView (LocalPlayer *player) {
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    73
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    74
#if GRAPHICS_ENABLED    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    75
    assert(graphics);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    76
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    77
    graphics->displayGameView(*game_state, player);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    78
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    79
#else
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    80
    (void) player;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    81
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    82
    throw Error("No Graphics support available");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    83
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    84
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    85
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    86
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    87
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    88
void Engine::setupNetworkServer (const std::string &listen_port) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
    89
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    90
#if NETWORK_ENABLED    
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 380
diff changeset
    91
    NetworkEndpoint listen_addr(listen_port);
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    92
    
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    93
    assert(terrain && game_state);
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    94
    
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    95
    // create the server
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
    96
    net_server = new NetworkServer(*game_state, listen_addr);
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    97
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    98
    // put graphics into GameView mode
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    99
    if (graphics)
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   100
        startGameView(NULL);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   101
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   102
#else
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   103
    (void) listen_port;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   104
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   105
    throw Error("No Network support available");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   106
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   107
#endif    
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   108
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   109
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   110
void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   111
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   112
#if NETWORK_ENABLED 
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   113
    // connect_to
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 380
diff changeset
   114
    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
   115
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   116
    // begin connecting, the client will callback us with setupGame once it's connected
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   117
    net_client_connect = new NetworkClientConnect(*this, connect_addr);
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   118
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   119
#else
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   120
    (void) connect_host;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   121
    (void) connect_port;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   122
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   123
    throw Error("No Network support available");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   124
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   125
#endif    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   126
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   127
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   128
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   129
void Engine::setupSinglePlayer (void) {
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   130
    assert(terrain && game_state);
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   131
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   132
    // create player directly
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   133
 	LocalPlayer* lp = new SinglePlayer(*game_state);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   134
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   135
    // add to gamestate
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   136
	game_state->setLocalPlayer(lp);
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   137
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   138
    // put graphics into GameView mode
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   139
    if (graphics)
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   140
        startGameView(lp);
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   141
 
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   142
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   143
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   144
void Engine::stop (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   145
    is_running = false;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   146
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   147
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   148
void Engine::run (void) {
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   149
    // timeout for NetworkReactor
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   150
    timeval timeout;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   151
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   152
    while (is_running) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   153
        /*
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   154
         * Run internal ClanLib stuff (also includes our timers) until our timeout has elapsed
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   155
         */
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   156
        CL_System::keep_alive(ENGINE_TIMEOUT_MS);
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   157
        
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   158
#if NETWORK_ENABLED 
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   159
        // setup timeout to zero
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   160
        timeout.tv_sec = 0;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   161
        timeout.tv_usec = 0;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   162
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   163
        /*
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   164
         * Thursday came and went, I re-wrote clan-event.
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   165
         *
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   166
         * (actually, we only use it for zero-timeout polling now... not sure if this is better than using the above
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   167
         * CL_System::keep_alive)
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   168
         */
418
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   169
        NetworkReactor::current->poll(&timeout);
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 413
diff changeset
   170
#endif        
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   171
    }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   172
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   173