src/Application.cc
author Tero Marttila <terom@fixme.fi>
Thu, 22 Jan 2009 01:53:05 +0200
branchnew_graphics
changeset 417 c503e0c6a740
parent 412 721c60072091
child 418 194bc810a570
permissions -rw-r--r--
support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
     2
#include "Application.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: 412
diff changeset
     3
#include "Config.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     4
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
     5
#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: 412
diff changeset
     6
    // for dump_display_modes
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
     7
    #include "Graphics/Display.hh"
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
     9
    // for CL_SetupGL
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    10
    #include <ClanLib/gl.h>
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    11
#endif
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    12
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    13
#include <stdexcept>
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    14
#include <sstream>
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    15
#include <cstdio>
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    16
#include <cassert>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    17
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    18
enum ArgumentCodes {
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    19
    ARG_HELP        = 'h',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    20
    ARG_PORT        = 'p',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    21
    ARG_SERVER      = 's',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    22
    ARG_CLIENT      = 'c',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    23
    ARG_GRAPHICS    = 'g',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    24
    ARG_FULLSCREEN  = 'F',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    25
    ARG_RESOLUTION  = 'R',
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    26
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    27
    ARG_LIST_MODES      = 0xff01,
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    28
    ARG_VERSION         = 0xff02,
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    29
    ARG_TERRAIN_SEED    = 0xff03,
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    30
    ARG_TERRAIN_SIZE    = 0xff04,
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    31
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    32
};
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    33
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    34
        
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    35
Main::Main (void) :
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    36
    graphics_enabled(false),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    37
    net_port(NETWORK_PORT_STR),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    38
    net_server(false),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    39
    net_connect("")
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    40
{
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    41
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    42
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    44
/**
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    45
 * Set the arg_* members
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    46
 */
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    47
bool Main::parse_args (int argc, char **argv) {
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    48
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    49
    // set up the options
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    50
    args.add_usage("[OPTIONS]");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    51
    args.set_help_indent(30);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    52
    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    53
    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: 412
diff changeset
    54
        args.add_group("Network");
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    55
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    56
        args.add_option(ARG_PORT, "port", "PORT",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    57
                "set network port used");
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    58
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    59
        args.add_option(ARG_SERVER, "server", "",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    60
                "act as a network server");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    61
        
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    62
        // require graphics for network-client
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    63
        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: 412
diff changeset
    64
            args.add_option(ARG_CLIENT, "client", "SERVERHOST",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    65
                    "act as a network client");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    66
    }
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    67
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    68
    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: 412
diff changeset
    69
        args.add_group("Graphics");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
    71
        args.add_option(ARG_GRAPHICS, "graphics", "",        
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    72
                "run graphics/local input. Implied with --client");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
    74
        args.add_option(ARG_FULLSCREEN, "fullscreen", "",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    75
                "run graphics in fullscreen mode");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
    77
        args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    78
                "set graphics resolution");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
    80
        args.add_option(ARG_LIST_MODES, "list-modes", "",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    81
                "output a list of available display modes and exit");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    82
    }
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
    84
    args.add_group("Game");
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    85
    args.add_option(ARG_TERRAIN_SEED, "terrain-seed", "SEED",
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    86
            "set seed for terrain random generator");
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    87
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    88
    args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT",
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    89
            "set terrain size for random generator");
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    90
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    91
    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    92
    args.add_group("General");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    93
    args.add_option(ARG_HELP, "help", "",
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    94
            "display argument help and exit");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    95
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
    96
    args.add_option(ARG_VERSION, "version", "",
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    97
            "output application version plus configuration and exit");
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
    98
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
    99
#if GRAPHICS_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   100
    // extra state
392
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   101
    bool resolution_default = true;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
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: 412
diff changeset
   103
#endif    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   104
    
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   105
    try {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   106
        // parse args
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   107
        args.parse_args(argc, argv);
267
2cb6f1421e45 enable graphics by default unless --server
terom
parents: 185
diff changeset
   108
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   109
    } catch (CL_Error &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   110
        throw ArgumentError(e.message);
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   111
    }
267
2cb6f1421e45 enable graphics by default unless --server
terom
parents: 185
diff changeset
   112
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   113
    while (args.next()) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   114
        switch (args.get_key()) {
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   115
            case ARG_HELP:
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   116
                args.print_help();
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   117
                return false;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   118
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   119
#if NETWORK_ENABLED                
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   120
            case ARG_PORT:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   121
                net_port = args.get_argument();
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   122
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   123
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   124
            case ARG_SERVER:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   125
                net_server = true;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   126
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   127
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   128
            case ARG_CLIENT:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   129
                net_connect = args.get_argument();
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   130
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   131
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   132
#endif                
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   133
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   134
#if GRAPHICS_ENABLED                
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   135
            case ARG_GRAPHICS:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   136
                graphics_enabled = true;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   137
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   138
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   139
            case ARG_FULLSCREEN:
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   140
                display.fullscreen = true;
392
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   141
                
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   142
                // choose best resolution unless explicitly set
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   143
                if (resolution_default) {
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   144
                    const CL_DisplayMode best_mode = graphics::Display::getBestMode();
392
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   145
                    const CL_Size best_resolution = best_mode.get_resolution();
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   146
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   147
                    display.resolution = PixelDimensions(best_resolution.width, best_resolution.height);
392
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   148
                }
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   149
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   150
                break;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   151
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   152
            case ARG_RESOLUTION:
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   153
                display.resolution = parse_arg_dimensions(args.get_argument(), "--resolution");
392
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   154
                resolution_default = false;
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   155
                break;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   156
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   157
            case ARG_LIST_MODES:
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   158
                dump_display_modes();
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   159
                return false;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   160
#endif
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   161
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   162
            case ARG_VERSION:
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   163
                dump_version();
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   164
                return false;
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   165
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   166
            case ARG_TERRAIN_SEED:
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   167
                terrain.random_seed = parse_arg_int(args.get_argument(), "--terrain-seed");
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   168
                break;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   169
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   170
            case ARG_TERRAIN_SIZE:
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   171
                terrain.dimensions = parse_arg_dimensions(args.get_argument(), "--terrain-size");
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   172
                break;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   173
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   174
            case CL_CommandLine::REST_ARG:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   175
                throw ArgumentError("Trailing arguments: " + args.get_argument());
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   176
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   177
            default:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   178
                throw ArgumentError(std::string() + "Unknown argument key: " + (char) args.get_key());
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   179
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   180
        }
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   181
    }
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   182
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   183
#if NETWORK_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   184
    // check for invalid combinations of arugments
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   185
    if (net_server and !net_connect.empty())
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   186
        throw ArgumentError("cannot be both server and client");
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   187
#endif
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   188
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   189
#if GRAPHICS_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   190
    // enable graphics by default unless server
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   191
    if (!net_server)
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   192
        graphics_enabled = true;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   193
#endif    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   194
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   195
    // continue
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   196
    return true;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   197
}
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   198
        
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   199
int Main::parse_arg_int (const std::string &arg_val, const char *arg_name) {
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   200
    int int_val;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   201
    
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   202
    // read using istringstream
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   203
    std::istringstream ss(arg_val);
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   204
    
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   205
    if (!(ss >> int_val))
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   206
        throw ArgumentError(std::string() + "invalid integer arugment for " + arg_name + ": " + arg_val);
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   207
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   208
    return int_val;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   209
}
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   210
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   211
PixelDimensions Main::parse_arg_dimensions (const std::string &arg_val, const char *arg_name) {
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   212
    unsigned int w, h;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   213
    
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   214
    // sccanf as unsigned
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   215
    if (sscanf(arg_val.c_str(), "%ux%u", &w, &h) != 2)
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   216
        throw ArgumentError(std::string() + "invalid format for " + arg_name + ": " + arg_val);
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   217
    
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   218
    return PixelDimensions(w, h);
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   219
}
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   220
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   221
#if GRAPHICS_ENABLED
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   222
void Main::dump_display_modes (void) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   223
    // get the list of display modes from graphics
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   224
    const std::vector<CL_DisplayMode> &modes = graphics::Display::getDisplayModes();
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   225
    PixelCoordinate last_resolution;
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   226
    
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   227
    std::cout << "Available display modes:" << std::endl;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   228
    
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   229
    // iterate over the list of available display modes
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   230
    for (std::vector<CL_DisplayMode>::const_iterator it = modes.begin(); it != modes.end(); it++) {
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   231
        PixelCoordinate resolution(it->get_resolution().width, it->get_resolution().height);
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   232
        
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   233
        // filter out those that haven't changed
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   234
        if (resolution != last_resolution)
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   235
            std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   236
        
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   237
        // update for next item
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   238
        last_resolution = resolution;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   239
    }
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   240
}
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   241
#endif
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   242
        
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   243
void Main::dump_version (void) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   244
    std::cout 
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   245
        << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built [" << PROJECT_BUILD_TIMESTAMP << "]" << std::endl;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   246
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   247
    // then some additional stuff about what's enabled
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   248
    std::cout
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   249
        << std::endl
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   250
        << "Enabled components:" << std::endl
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   251
        << "\tGraphics:\t" << (GRAPHICS_ENABLED ? "Yes" : "No") << std::endl
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   252
        << "\tNetwork:\t" << (NETWORK_ENABLED ? "Yes" : "No") << std::endl;
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   253
}
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   254
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   255
/**
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   256
 * IT BEGAN IN AFRIKA
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   257
 */
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   258
int Main::main (int argc, char **argv) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   259
    // initialize the ClanLib components that we use
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   260
    CL_SetupCore setup_core;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   261
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   262
#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: 412
diff changeset
   263
    // XXX: move to Graphics/Graphics.hh?
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   264
    CL_SetupDisplay setup_disp;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   265
    CL_SetupGL setup_gl;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   266
#endif
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   267
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   268
    try {
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   269
        // parse arugments, exit if false
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   270
        if (parse_args(argc, argv) == false)
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   271
            return 0;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   272
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   273
        // our engine
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   274
        Engine engine;
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   275
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   276
        // setup game unless client
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   277
        if (net_connect.empty())
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   278
            engine.setupGame(terrain);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   279
        
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   280
        // setup graphics
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   281
        if (graphics_enabled)
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   282
            engine.setupGraphics(display);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   283
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   284
        // setup either network server, client or singleplayer
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   285
        if (net_server) {
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   286
            engine.setupNetworkServer(net_port);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   287
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   288
        } else if (!net_connect.empty()) {
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   289
            engine.setupNetworkClient(net_connect, net_port);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   290
        
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   291
        } else 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: 412
diff changeset
   292
            engine.setupSinglePlayer();
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   293
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   294
        } else {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   295
            throw ArgumentError("Nothing to do");
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   296
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   297
        }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   298
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   299
        // run the main loop
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   300
        engine.run();
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   301
        
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   302
        // succesful return
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   303
        return 0;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   304
    
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   305
    } catch (ArgumentError &e) {
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   306
        std::cerr 
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   307
            << "Error: " << e.what() << std::endl
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   308
            << std::endl;
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   309
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   310
        args.print_help();
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   311
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   312
        return 1;
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 412
diff changeset
   313
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   314
    } catch (CL_Error &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   315
        std::cerr << "main: CL_Error:" << e.message << std::endl;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   316
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   317
        return 1;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   318
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   319
    } catch (std::exception &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   320
        std::cerr << "FATAL [uncaught_exception] " << e.what() << std::endl;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   321
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   322
        return 1;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   323
    }
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   324
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   325