main.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <client/ClientParams.h>
00022 #include <client/ScorchedClient.h>
00023 #include <client/ClientMain.h>
00024 #include <server/ScorchedServer.h>
00025 #include <engine/ModDirs.h>
00026 #include <common/OptionsScorched.h>
00027 #include <common/ARGParser.h>
00028 #include <common/Defines.h>
00029 #include <common/OptionsTransient.h>
00030 #include <graph/OptionsDisplay.h>
00031 #include <locale.h>
00032 #include <math.h>
00033 #include <signal.h>
00034 #include <float.h>
00035 #include <time.h>
00036 #include <common/main.h>
00037 #include <SDL/SDL.h>
00038 
00039 void checkLaunchFile(char *progPath)
00040 {
00041         if (!ClientParams::instance()->getNonParam()[0]) return;
00042 
00043         // Read launcher file
00044         FILE *in = fopen(ClientParams::instance()->getNonParam(), "r");
00045         if (!in)
00046         {
00047                 S3D::dialogExit(scorched3dAppName, "Failed to open launchfile");
00048         }
00049         char buffer[2048];
00050         if (!fgets(buffer, 2048, in))
00051         {
00052                 S3D::dialogExit(scorched3dAppName, "Failed to read launchfile");
00053         }
00054         fclose(in);
00055 
00056         // Set the launch
00057         ClientParams::instance()->setConnect(buffer);
00058 }
00059 
00060 int main(int argc, char *argv[])
00061 {
00062         setlocale(LC_ALL, "C");
00063 
00064         // From main.h
00065         run_main(argc, argv, *ClientParams::instance());
00066         checkLaunchFile(argv[0]);
00067 
00068         // Read display options from a file
00069         // **This NEEDS to be after the arg parser**
00070         if (!OptionsDisplay::instance()->readOptionsFromFile())
00071         {
00072                 return 0;
00073         }
00074 
00075         // Set the exittime
00076         if (ClientParams::instance()->getExitTime() > 0)
00077         {
00078                 ClientParams::instance()->setExitTime(
00079                         int(ClientParams::instance()->getExitTime() + time(0)));
00080         }
00081 
00082         // Get this host's description and username
00083         if (!OptionsDisplay::instance()->getHostDescription()[0])
00084         {
00085                 OptionsDisplay::instance()->getHostDescriptionEntry().setValue(S3D::getOSDesc());
00086                 OptionsDisplay::instance()->getOnlineUserNameEntry().setValue("Player");
00087         }
00088 
00089         // Write the new options back the the file
00090         OptionsDisplay::instance()->writeOptionsToFile();
00091 
00092         // Init SDL
00093         unsigned int initFlags = SDL_INIT_VIDEO;
00094         if (ClientParams::instance()->getAllowExceptions()) initFlags |= SDL_INIT_NOPARACHUTE;
00095         if (SDL_Init(initFlags) < 0)
00096         {
00097                 S3D::dialogExit(
00098                         scorched3dAppName,
00099                         "This game uses the SDL library to provide graphics.\n"
00100                         "The graphics section of this library failed to initialize.");
00101         }
00102 
00103         if (!ClientMain::clientMain()) exit(64);
00104 
00105         // Write display options back to the file
00106         // in case they have been changed by this client (in game by the console)
00107         OptionsDisplay::instance()->writeOptionsToFile();
00108 
00109         SDL_Quit();
00110         return 0; // exit(0)
00111 }

Generated on Mon Feb 16 15:14:47 2009 for Scorched3D by  doxygen 1.5.3