CGenius.cpp 3.94 KB
Newer Older
1 2 3
/**
 CGenius.cpp
 This is Commander Genius main source file.
4

5
 The Commander Genius source may be freely distributed and
6
 modified as per the GPL but please give credit to
7
 the original authors.
8

9 10
 If you make any changes or improvements to the code that
 you feel merit inclusion in the source tree email them
11
 to me at gerstrong@gmail.com.
12

13
 Thanks to ID Software for the "Commander Keen" series.
14
 "Commander Keen" and it's associated
15 16
 graphics, level, and sound files are the property of ID
 Software. Commander Genius requires the original version of a
17
 Commander Keen game in order to be able to interpret them.
18

19
 Enjoy our hard work!
20
 - The Commander Genius Team
21

22
 CloneKeen          2003-2005   Caitlin Shaw
Gerhard Stein's avatar
Gerhard Stein committed
23
 CloneKeenPlus      2008-2018   Gerstrong
Gerhard Stein's avatar
Gerhard Stein committed
24 25
 Commander Genius   2009-2014   Tulip,
 Commander Genius   2009-2013   NY00123,
26
 Commander Genius   2009-2013   Pickle, DaVince, Albert and Pizza2004
Gerhard Stein's avatar
Gerhard Stein committed
27
 Commander Genius   2010-2012   Lemm, Commander Spleen, Zear, Pelya and FCTW
Gerhard Stein's avatar
Gerhard Stein committed
28 29
 Commander Genius   2013-2015   Hagel
 Commander Genius   2018        Zilem
30 31
 */

Gerhard Stein's avatar
Gerhard Stein committed
32
#include "../version.h"
33
#include "engine/core/CSettings.h"
Gerhard Stein's avatar
Gerhard Stein committed
34
#include "base/video/CVideoDriver.h"
Gerhard Stein's avatar
Gerhard Stein committed
35

Gerhard's avatar
Gerhard committed
36

37
#ifdef ANDROID
38
#include <SDL_main.h>
39
#endif
Gerhard Stein's avatar
Gerhard Stein committed
40

41
#include <base/utils/FindFile.h>
Gerhard Stein's avatar
Gerhard Stein committed
42
#include <base/GsApp.h>
43
#include <base/GsLogging.h>
44

45
#include "engine/CGameLauncher.h"
46

Gerhard Stein's avatar
Gerhard Stein committed
47 48
#include "sdl/audio/Audio.h"

49 50


51
/**
52
 * @brief  This is the function where CG beings
53
 *
54 55
 * @param	argc   	number of arguments
 * @param	argv   	pointer to  char arrays where
56 57
 * 					where the passed arguments are stored
 * 					in the process
58
 * @return	        This always returns 0. If
Gerhard Stein's avatar
Gerhard Stein committed
59
 * 					some errors appear, take a look
60 61 62
 * 					at the Logfile.
 *
 */
63 64
int main(int argc, char *argv[])
{
Gerhard Stein's avatar
Gerhard Stein committed
65 66

#if SDL_VERSION_ATLEAST(2, 0, 0)
67 68 69
#ifdef ANDROID
    SDL_SetMainReady( );
#endif
Gerhard Stein's avatar
Gerhard Stein committed
70 71
#endif

72 73 74 75 76 77 78 79 80 81
    // Check if CG should look into a given directory
    std::string binary_dir;
    if(argc >= 1)
    {
        binary_dir = argv[0];
        size_t slashpos = findLastPathSep(binary_dir);

        if(slashpos != std::string::npos)
        {
            binary_dir.erase(slashpos);
Gerhard Stein's avatar
Gerhard Stein committed
82
            binary_dir = SystemNativeToUtf8(binary_dir);
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        }
        else
        {
            binary_dir = ".";
        }
    }
    else
    {
        warnings << "Binary-argument not given, assuming current dir" << endl;
        binary_dir = ".";
    }

    SetBinaryDir( GetAbsolutePath(binary_dir) );

    InitThreadPool();
98
    InitSearchPaths(gSettings.getConfigFileName());
99

100 101
    if( !gLogging.CreateLogfile("CGLog.html", APP_NAME, CGVERSION) )
    {
102
        errors << "Not even able to create \"CGLog.html\"." << endl;
103
      return 1;
104
    }
105

Gerhard Stein's avatar
Gerhard Stein committed
106

107 108
  // Init Video Driver with SDL all together
  if( !gVideoDriver.init() )
Gerhard Stein's avatar
Gerhard Stein committed
109
    {
110
      return 1;
Gerhard Stein's avatar
Gerhard Stein committed
111 112
    }

113 114
  // Check if there are settings on the PC, otherwise use defaults.
  if( !gSettings.loadDrvCfg() )
115 116
    {
        //m_firsttime = true;
117 118 119
        gLogging.textOut(FONTCOLORS::RED,"First time message: CG didn't find the driver config file. ");
        gLogging.textOut(FONTCOLORS::RED,"However, it generated some default values and will save them now.\n");
        gSettings.saveDrvCfg();
120 121
    }

122 123
    gLogging.textOut(FONTCOLORS::GREEN,"Loading game options...\n");
    if(!gSettings.loadGameOptions())
124
    {
125 126
        gLogging.textOut(FONTCOLORS::RED,"Cannot load defaults...\n");
        gSettings.loadDefaultGameCfg();
127 128
    }

Gerhard Stein's avatar
Gerhard Stein committed
129
    // Init the Game sound
130
    gSound.init();
Gerhard Stein's avatar
Gerhard Stein committed
131

132 133 134
    ////////////////////////////////////////////////////
    // Initialize CG and run the main cycle if worthy //
    ////////////////////////////////////////////////////
135
    if( gApp.init( argc, argv ) )
136
    {
137 138 139
        ////////////////////////////////
        // Set GameLauncher as Engine //
        ////////////////////////////////
140
        gApp.setEngine(new CGameLauncher(false));
141 142 143 144

        //////////////////////////////
        // Run the Commander Genius //
        //////////////////////////////
145
        gApp.runMainCycle();
146
    }
147

148
    gSettings.saveDispCfg();
149

150 151
    UnInitThreadPool();
    return 0;
152
}