src/Application.cc
author nireco
Sat, 31 Jan 2009 12:33:08 +0200
changeset 443 5d1119729f58
parent 426 510c83aab425
permissions -rw-r--r--
worm02 two pics to comment
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,
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
    ARG_LOG_LEVEL       = 0xff05,
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    32
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    33
};
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    34
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    35
        
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    36
Main::Main (void) :
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    37
    graphics_enabled(false),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    38
    net_port(NETWORK_PORT_STR),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    39
    net_server(false),
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    40
    net_connect("")
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
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    43
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    44
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    45
/**
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    46
 * Set the arg_* members
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
    47
 */
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    48
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
    49
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
    50
    // 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
    51
    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
    52
    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
    53
    
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
    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
    55
        args.add_group("Network");
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    56
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
    57
        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
    58
                "set network port used");
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
    59
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
    60
        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
    61
                "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
    62
        
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
        // 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
    64
        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
    65
            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
    66
                    "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
    67
    }
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    68
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
    69
    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
    70
        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
    71
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
        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
    73
                "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
    74
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
        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
    76
                "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
    77
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
        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
    79
                "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
    80
        
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
        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
    82
                "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
    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
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
    85
    args.add_group("Game");
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    86
    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
    87
            "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
    88
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
    89
    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
    90
            "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
    91
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
    92
    
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_group("General");
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
    94
    args.add_option(ARG_LOG_LEVEL, "log-level", "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
    95
            "set maximum log level to one of FATAL/ERROR/WARN/INFO/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
    96
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
    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
    98
            "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
    99
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   100
    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
   101
            "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
   102
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
   103
#if GRAPHICS_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   104
    // 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
   105
    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
   106
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
   107
#endif    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   108
    
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   109
    try {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   110
        // parse args
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   111
        args.parse_args(argc, argv);
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
    } catch (CL_Error &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   114
        throw ArgumentError(e.message);
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   115
    }
267
2cb6f1421e45 enable graphics by default unless --server
terom
parents: 185
diff changeset
   116
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   117
    while (args.next()) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   118
        switch (args.get_key()) {
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   119
            case ARG_HELP:
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   120
                args.print_help();
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   121
                return false;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   122
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
   123
            case ARG_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
   124
                engine.log_level = parse_arg_loglevel(args.get_argument(), "--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
   125
                break;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   126
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
   127
#if NETWORK_ENABLED                
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   128
            case ARG_PORT:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   129
                net_port = 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
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   132
            case ARG_SERVER:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   133
                net_server = true;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   134
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   135
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   136
            case ARG_CLIENT:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   137
                net_connect = args.get_argument();
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   138
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   139
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
   140
#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
   141
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
   142
#if GRAPHICS_ENABLED                
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   143
            case ARG_GRAPHICS:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   144
                graphics_enabled = true;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   145
                break;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   146
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   147
            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
   148
                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
   149
                
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   150
                // 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
   151
                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
   152
                    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
   153
                    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
   154
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   155
                    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
   156
                }
6c4dc68360eb remove unused graphics_default, and default to the highest resolution available in fullscreen mode
Tero Marttila <terom@fixme.fi>
parents: 389
diff changeset
   157
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   158
                break;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   159
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   160
            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
   161
                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
   162
                resolution_default = false;
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   163
                break;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   164
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   165
            case ARG_LIST_MODES:
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   166
                dump_display_modes();
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   167
                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
   168
#endif
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   169
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   170
            case ARG_VERSION:
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   171
                dump_version();
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   172
                return false;
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   173
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   174
            case ARG_TERRAIN_SEED:
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   175
                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
   176
                break;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   177
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   178
            case ARG_TERRAIN_SIZE:
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   179
                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
   180
                break;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   181
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   182
            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
   183
                throw ArgumentError("Trailing arguments: " + args.get_argument());
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   184
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   185
            default:
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   186
                throw ArgumentError(std::string() + "Unknown argument key: " + (char) args.get_key());
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   187
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   188
        }
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   189
    }
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   190
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
   191
#if NETWORK_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   192
    // 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
   193
    if (net_server and !net_connect.empty())
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   194
        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
   195
#endif
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   196
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
   197
#if GRAPHICS_ENABLED    
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   198
    // 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
   199
    if (!net_server)
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   200
        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
   201
#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
   202
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   203
    // continue
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   204
    return true;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   205
}
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   206
        
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   207
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
   208
    int 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
    // read using istringstream
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   211
    std::istringstream ss(arg_val);
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   212
    
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   213
    if (!(ss >> int_val))
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   214
        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
   215
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   216
    return int_val;
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   217
}
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   218
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   219
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
   220
    unsigned int w, h;
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   221
    
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   222
    // sccanf as unsigned
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   223
    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
   224
        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
   225
    
411
106aaf6eadfe there's a grain of truth in the new graphics code now...
Tero Marttila <terom@fixme.fi>
parents: 409
diff changeset
   226
    return PixelDimensions(w, h);
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   227
}
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
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
   229
LogLevel Main::parse_arg_loglevel (const std::string &arg_val, const char *arg_name) {
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   230
    // brute-force if-elseif
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   231
    if (arg_val == "FATAL")
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   232
        return FATAL;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   233
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   234
    else if (arg_val == "ERROR")
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   235
        return ERROR;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   236
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   237
    else if (arg_val == "WARN")
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   238
        return WARN;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   239
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   240
    else if (arg_val == "INFO")
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   241
        return INFO;
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   242
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   243
    else if (arg_val == "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
   244
        return 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
   245
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   246
    else
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   247
        throw ArgumentError(std::string() + "invalid log level for " + arg_name + ": " + arg_val);
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   248
}
194bc810a570 add --log-level option, improve Config/Logger documentation, fix NETWORK_EANBLED typos in Engine
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   249
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
   250
#if GRAPHICS_ENABLED
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   251
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
   252
    // 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
   253
    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
   254
    PixelCoordinate last_resolution;
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   255
    
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   256
    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
   257
    
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
   258
    // 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
   259
    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
   260
        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
   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
        // 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
   263
        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
   264
            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
   265
        
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
        // 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
   267
        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
   268
    }
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   269
}
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
   270
#endif
397
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   271
        
13fa0546ef87 hopefully version stuff is now run properly on every make...
Tero Marttila <terom@fixme.fi>
parents: 392
diff changeset
   272
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
   273
    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
   274
        << 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
   275
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
   276
    // 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
   277
    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
   278
        << 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
   279
        << "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
   280
        << "\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
   281
        << "\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
   282
}
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   283
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   284
/**
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   285
 * IT BEGAN IN AFRIKA
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   286
 */
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   287
int Main::main (int argc, char **argv) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   288
    // initialize the ClanLib components that we use
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   289
    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
   290
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
#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
    // XXX: move to Graphics/Graphics.hh?
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   293
    CL_SetupDisplay setup_disp;
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   294
    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
   295
#endif
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   296
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   297
    try {
389
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   298
        // parse arugments, exit if false
e74c1820fbd2 implement --help, --fullscreen, --resolution and --list-modes
Tero Marttila <terom@fixme.fi>
parents: 358
diff changeset
   299
        if (parse_args(argc, argv) == false)
426
510c83aab425 use EXIT_SUCCESS/FAILURE return codes from main
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   300
            return EXIT_SUCCESS;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   301
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   302
        // our engine
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
   303
        Engine engine(this->engine);
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   304
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   305
        // setup game unless client
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   306
        if (net_connect.empty())
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   307
            engine.setupGame(terrain);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   308
        
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   309
        // setup graphics
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   310
        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
   311
            engine.setupGraphics(display);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   312
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   313
        // 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
   314
        if (net_server) {
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   315
            engine.setupNetworkServer(net_port);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   316
409
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   317
        } else if (!net_connect.empty()) {
1a03ff151abc add --terrain-seed and --terrain-size arguments, plus bugfixes
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
   318
            engine.setupNetworkClient(net_connect, net_port);
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   319
        
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
   320
        } 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
   321
            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
   322
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   323
        } 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
   324
            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
   325
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   326
        }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   327
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   328
        // run the main loop
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   329
        engine.run();
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   330
        
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   331
        // succesful return
426
510c83aab425 use EXIT_SUCCESS/FAILURE return codes from main
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   332
        return EXIT_SUCCESS;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   333
    
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   334
    } 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
   335
        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
   336
            << "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
   337
            << 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
   338
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   339
        args.print_help();
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   340
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   341
    } catch (CL_Error &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   342
        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
   343
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   344
    } catch (std::exception &e) {
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   345
        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
   346
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   347
    }
426
510c83aab425 use EXIT_SUCCESS/FAILURE return codes from main
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   348
    
510c83aab425 use EXIT_SUCCESS/FAILURE return codes from main
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   349
    // fallthrough from catch's
510c83aab425 use EXIT_SUCCESS/FAILURE return codes from main
Tero Marttila <terom@fixme.fi>
parents: 418
diff changeset
   350
    return EXIT_FAILURE;
358
37b18b779ffb PIMP MAH DOXYGEN
terom
parents: 267
diff changeset
   351
}
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   352