src/Engine.cc
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 00:25:58 +0200
changeset 439 9823e6cd1086
parent 431 c6d7272a164b
permissions -rw-r--r--
some README text
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"
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    17
    #include "Graphics/GameView.hh"
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
    18
#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
    19
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    20
#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
    21
#include <cassert>
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
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
    23
/*
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
 * 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
    25
 */
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
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
    27
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    28
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
    29
    terrain(NULL), game_state(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL),
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
    30
    game_view(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
    31
    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
    32
{
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
    33
    // 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
    34
    Engine::log_level = config.log_level;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    35
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    36
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
    37
void Engine::setupGame (Terrain *terrain) {
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
    38
    // 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
    39
    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
    40
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
    // 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
    42
    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
    43
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
    44
    // 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
    45
    game_state = new GameState(*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
    46
}
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
        
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    48
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
    49
    // 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
    50
    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
    51
}
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
    52
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
    53
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
    54
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
#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
    56
    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
    57
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    58
    // 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
    59
    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
    60
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
    61
#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
    62
    (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
    63
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
    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
    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
#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
    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
}
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
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
    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
#if GRAPHICS_ENABLED    
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
    73
    assert(graphics && !game_view);
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
    74
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
    75
    game_view = graphics->displayGameView(*game_state, player);
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
    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
#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
    78
    (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
    79
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
    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
    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
#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
    83
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    84
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    85
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    86
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
    87
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
    88
#if NETWORK_ENABLED    
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 380
diff changeset
    89
    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
    90
    
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    91
    assert(terrain && game_state);
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    92
    
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    93
    // 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
    94
    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
    95
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
    96
    // 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
    97
    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
    98
        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
    99
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
#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
   101
    (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
   102
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
    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
   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
#endif    
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   106
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   107
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   108
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
   109
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
   110
#if NETWORK_ENABLED 
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   111
    // client operation requires graphics
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   112
    if (!GRAPHICS_ENABLED)
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   113
        throw Error("Network client mode requires graphics support");
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   114
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   115
    // connect_to
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 380
diff changeset
   116
    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
   117
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
   118
    // 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
   119
    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
   120
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
#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
   122
    (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
   123
    (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
   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
    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
   126
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
   127
#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
   128
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   129
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   130
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   131
void Engine::setupSinglePlayer (void) {
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   132
    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
   133
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   134
    // 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
   135
 	LocalPlayer* lp = new SinglePlayer(*game_state);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   136
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   137
    // 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
   138
	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
   139
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   140
    // 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
   141
    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
   142
        startGameView(lp);
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   143
}
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   144
        
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   145
GameState& Engine::onNetworkClientConnected (Terrain *terrain) {
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   146
    // sanity-check
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 424
diff changeset
   147
    assert(!this->terrain && !game_state && graphics);
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   148
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   149
    // setup the game
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   150
    setupGame(terrain);
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   151
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   152
    // start the GameView, but no LocalPlayer yet
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   153
    startGameView(NULL);
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   154
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   155
    // return GameState
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   156
    return *game_state;
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   157
}
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   158
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   159
void Engine::onNetworkClientPlayer (LocalPlayer *player) {
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   160
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   161
#if GRAPHICS_ENABLED
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   162
    assert(game_view);
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   163
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   164
    // set the GameView's player
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   165
    game_view->setPlayer(player);
423
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   166
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   167
#else
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   168
    (void) player;
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   169
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   170
    assert(graphics);
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   171
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   172
#endif
947ab54de4b7 fix worst compilation errors when using the debian lenny gcc/libc...
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   173
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   174
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   175
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   176
void Engine::stop (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   177
    is_running = false;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   178
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   179
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   180
void Engine::run (void) {
424
f337a86d144e fix GRAPHICS_ENABLED configuration... probably broken again if the <ClanLib/Display> includes aren't there
Tero Marttila <terom@fixme.fi>
parents: 423
diff changeset
   181
#if NETWORK_ENABLED 
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
   182
    // 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
   183
    timeval timeout;
424
f337a86d144e fix GRAPHICS_ENABLED configuration... probably broken again if the <ClanLib/Display> includes aren't there
Tero Marttila <terom@fixme.fi>
parents: 423
diff changeset
   184
#endif        
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
   185
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   186
    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
   187
        /*
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
   188
         * 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
   189
         */
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
   190
        CL_System::keep_alive(ENGINE_TIMEOUT_MS);
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   191
        
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
   192
#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
   193
        // 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
   194
        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
   195
        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
   196
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   197
        /*
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   198
         * Thursday came and went, I re-wrote clan-event.
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   199
         *
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
   200
         * (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
   201
         * CL_System::keep_alive)
380
d193dd1d8a7e new NetworkReactor, fix everything to actually work
terom
parents: 378
diff changeset
   202
         */
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
   203
        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
   204
#endif        
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   205
    }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   206
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   207