2010-04-09 21:02:39 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2009-11-06 19:35:32 +01:00
|
|
|
#include "lib/app_hooks.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/input.h"
|
2007-05-26 19:56:38 +02:00
|
|
|
#include "lib/lockfree.h"
|
2009-11-06 19:35:32 +01:00
|
|
|
#include "lib/ogl.h"
|
|
|
|
#include "lib/timer.h"
|
2010-03-01 15:55:34 +01:00
|
|
|
#include "lib/utf8.h"
|
2009-11-06 19:35:32 +01:00
|
|
|
#include "lib/external_libraries/sdl.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/res/h_mgr.h"
|
2009-11-06 19:35:32 +01:00
|
|
|
#include "lib/res/graphics/cursor.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/res/sound/snd_mgr.h"
|
2009-11-06 19:35:32 +01:00
|
|
|
#include "lib/sysdep/cpu.h"
|
|
|
|
#include "lib/sysdep/gfx.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/tex/tex.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#include "ps/CConsole.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/ConfigDB.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/Filesystem.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/Font.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Game.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/Globals.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Hotkey.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/Loader.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/Overlay.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/Profile.h"
|
|
|
|
#include "ps/ProfileViewer.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "ps/StringConvert.h"
|
|
|
|
#include "ps/Util.h"
|
2010-06-03 21:07:59 +02:00
|
|
|
#include "ps/VideoMode.h"
|
2010-05-20 20:09:23 +02:00
|
|
|
#include "ps/World.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "ps/i18n.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "graphics/CinemaTrack.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "graphics/GameView.h"
|
|
|
|
#include "graphics/LightEnv.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "graphics/MapReader.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
#include "graphics/MaterialManager.h"
|
|
|
|
#include "graphics/ParticleEngine.h"
|
|
|
|
#include "graphics/TextureManager.h"
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "renderer/Renderer.h"
|
|
|
|
#include "renderer/VertexBufferManager.h"
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "maths/MathUtil.h"
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "simulation2/Simulation2.h"
|
|
|
|
|
2006-07-27 23:20:30 +02:00
|
|
|
#include "scripting/ScriptableComplex.inl"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "scripting/ScriptingHost.h"
|
2010-02-18 01:06:50 +01:00
|
|
|
#include "scripting/ScriptGlue.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "scripting/DOMEvent.h"
|
2006-07-27 04:42:35 +02:00
|
|
|
#include "scripting/ScriptableComplex.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/scripting/JSInterface_Vector3D.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "graphics/scripting/JSInterface_Camera.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "graphics/scripting/JSInterface_LightEnv.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/scripting/JSInterface_Console.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
|
2009-08-08 12:04:43 +02:00
|
|
|
#include "gui/GUI.h"
|
2009-12-03 21:17:22 +01:00
|
|
|
#include "gui/GUIManager.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "gui/scripting/JSInterface_IGUIObject.h"
|
|
|
|
#include "gui/scripting/JSInterface_GUITypes.h"
|
|
|
|
#include "gui/scripting/ScriptFunctions.h"
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "sound/JSI_Sound.h"
|
|
|
|
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "network/NetServer.h"
|
|
|
|
#include "network/NetClient.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-08-02 13:07:42 +02:00
|
|
|
#include "ps/Pyrogenesis.h" // psSetLogDir
|
2006-12-09 15:39:52 +01:00
|
|
|
#include "ps/GameSetup/Atlas.h"
|
|
|
|
#include "ps/GameSetup/GameSetup.h"
|
2009-08-08 13:11:26 +02:00
|
|
|
#include "ps/GameSetup/Paths.h"
|
2006-12-09 15:39:52 +01:00
|
|
|
#include "ps/GameSetup/Config.h"
|
|
|
|
#include "ps/GameSetup/CmdLineArgs.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-11 15:24:25 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
ERROR_GROUP(System);
|
|
|
|
ERROR_TYPE(System, SDLInitFailed);
|
|
|
|
ERROR_TYPE(System, VmodeFailed);
|
|
|
|
ERROR_TYPE(System, RequiredExtensionsMissing);
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
#define LOG_CATEGORY L"gamesetup"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-04-21 17:24:04 +02:00
|
|
|
bool g_DoRenderGui = true;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
static const int SANE_TEX_QUALITY_DEFAULT = 5; // keep in sync with code
|
2006-04-24 01:14:18 +02:00
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
static void SetTextureQuality(int quality)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
int q_flags;
|
2006-04-24 01:14:18 +02:00
|
|
|
GLint filter;
|
|
|
|
|
|
|
|
retry:
|
|
|
|
// keep this in sync with SANE_TEX_QUALITY_DEFAULT
|
|
|
|
switch(quality)
|
|
|
|
{
|
|
|
|
// worst quality
|
|
|
|
case 0:
|
|
|
|
q_flags = OGL_TEX_HALF_RES|OGL_TEX_HALF_BPP;
|
|
|
|
filter = GL_NEAREST;
|
|
|
|
break;
|
|
|
|
// [perf] add bilinear filtering
|
|
|
|
case 1:
|
|
|
|
q_flags = OGL_TEX_HALF_RES|OGL_TEX_HALF_BPP;
|
|
|
|
filter = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
// [vmem] no longer reduce resolution
|
|
|
|
case 2:
|
|
|
|
q_flags = OGL_TEX_HALF_BPP;
|
|
|
|
filter = GL_LINEAR;
|
|
|
|
break;
|
|
|
|
// [vmem] add mipmaps
|
|
|
|
case 3:
|
|
|
|
q_flags = OGL_TEX_HALF_BPP;
|
|
|
|
filter = GL_NEAREST_MIPMAP_LINEAR;
|
|
|
|
break;
|
|
|
|
// [perf] better filtering
|
|
|
|
case 4:
|
|
|
|
q_flags = OGL_TEX_HALF_BPP;
|
|
|
|
filter = GL_LINEAR_MIPMAP_LINEAR;
|
|
|
|
break;
|
|
|
|
// [vmem] no longer reduce bpp
|
|
|
|
case SANE_TEX_QUALITY_DEFAULT:
|
|
|
|
q_flags = OGL_TEX_FULL_QUALITY;
|
|
|
|
filter = GL_LINEAR_MIPMAP_LINEAR;
|
|
|
|
break;
|
|
|
|
// [perf] add anisotropy
|
|
|
|
case 6:
|
|
|
|
// TODO: add anisotropic filtering
|
|
|
|
q_flags = OGL_TEX_FULL_QUALITY;
|
|
|
|
filter = GL_LINEAR_MIPMAP_LINEAR;
|
|
|
|
break;
|
|
|
|
// invalid
|
|
|
|
default:
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_warn(L"SetTextureQuality: invalid quality");
|
2006-04-24 01:14:18 +02:00
|
|
|
quality = SANE_TEX_QUALITY_DEFAULT;
|
|
|
|
// careful: recursion doesn't work and we don't want to duplicate
|
|
|
|
// the "sane" default values.
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
ogl_tex_set_defaults(q_flags, filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// GUI integration
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// display progress / description in loading screen
|
|
|
|
void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task)
|
|
|
|
{
|
|
|
|
CStrW i18n_description = I18n::translate(pending_task);
|
|
|
|
JSString* js_desc = StringConvert::wstring_to_jsstring(g_ScriptingHost.getContext(), i18n_description);
|
|
|
|
g_ScriptingHost.SetGlobal("g_Progress", INT_TO_JSVAL(percent));
|
|
|
|
g_ScriptingHost.SetGlobal("g_LoadDescription", STRING_TO_JSVAL(js_desc));
|
2009-12-03 21:17:22 +01:00
|
|
|
g_GUI->SendEventToAll("progress");
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Render()
|
|
|
|
{
|
|
|
|
MICROLOG(L"begin frame");
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
CStr skystring = "61 193 255";
|
|
|
|
CFG_GET_USER_VAL("skycolor", String, skystring);
|
|
|
|
CColor skycol;
|
|
|
|
GUI<CColor>::ParseString(skystring, skycol);
|
2008-07-19 02:36:42 +02:00
|
|
|
g_Renderer.SetClearColor(skycol.AsSColor4ub());
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// start new frame
|
|
|
|
g_Renderer.BeginFrame();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 20:09:23 +02:00
|
|
|
if (g_Game && g_Game->IsGameStarted())
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
g_Game->GetView()->Render();
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
// set up overlay mode
|
2006-04-24 01:14:18 +02:00
|
|
|
glPushAttrib(GL_ENABLE_BIT);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
2010-06-01 00:44:59 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.f, 1000.f);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
2006-09-28 22:41:12 +02:00
|
|
|
glLoadIdentity();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Temp GUI message GeeTODO
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_START("render gui");
|
2009-12-03 21:17:22 +01:00
|
|
|
if(g_DoRenderGui) g_GUI->Draw();
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_END("render gui");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Particle Engine Updating
|
2007-05-02 14:07:08 +02:00
|
|
|
CParticleEngine::GetInstance()->UpdateEmitters();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
ogl_WarnIfError();
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// Text:
|
|
|
|
|
|
|
|
// Use the GL_ALPHA texture as the alpha channel with a flat colouring
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
// Added --
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
// -- GL
|
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
glLoadIdentity();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_START("render console");
|
|
|
|
g_Console->Render();
|
|
|
|
PROFILE_END("render console");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_START("render logger");
|
|
|
|
g_Logger->Render();
|
|
|
|
PROFILE_END("render logger");
|
|
|
|
|
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Profile information
|
|
|
|
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_START("render profiling");
|
2006-04-24 01:14:18 +02:00
|
|
|
g_ProfileViewer.RenderProfile();
|
2010-06-01 00:44:59 +02:00
|
|
|
PROFILE_END("render profiling");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Draw the cursor (or set the Windows cursor, on Windows)
|
2010-05-20 20:09:23 +02:00
|
|
|
CStrW cursorName = g_CursorName;
|
2007-06-11 01:15:14 +02:00
|
|
|
if (cursorName.empty())
|
|
|
|
cursor_draw(NULL, g_mouse_x, g_mouse_y);
|
|
|
|
else
|
2009-11-03 22:46:35 +01:00
|
|
|
cursor_draw(cursorName.c_str(), g_mouse_x, g_mouse_y);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// restore
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
|
|
|
glPopAttrib();
|
|
|
|
|
|
|
|
MICROLOG(L"end frame");
|
|
|
|
g_Renderer.EndFrame();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
static void RegisterJavascriptInterfaces()
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2008-04-06 16:03:23 +02:00
|
|
|
// maths
|
|
|
|
JSI_Vector3D::init();
|
2006-06-30 00:52:50 +02:00
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// graphics
|
|
|
|
JSI_Camera::init();
|
|
|
|
JSI_LightEnv::init();
|
|
|
|
CGameView::ScriptingInit();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// renderer
|
|
|
|
CRenderer::ScriptingInit();
|
2006-11-24 20:45:04 +01:00
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// sound
|
2006-04-24 01:14:18 +02:00
|
|
|
JSI_Sound::ScriptingInit();
|
|
|
|
|
2008-04-13 16:50:11 +02:00
|
|
|
// scripting
|
|
|
|
CScriptEvent::ScriptingInit();
|
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// ps
|
|
|
|
JSI_Console::init();
|
|
|
|
|
|
|
|
// GUI
|
2009-12-03 21:17:22 +01:00
|
|
|
CGUI::ScriptingInit();
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
GuiScriptingInit(g_ScriptingHost.GetScriptInterface());
|
2008-04-06 16:03:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InitScripting()
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER(L"InitScripting");
|
2008-04-06 16:03:23 +02:00
|
|
|
|
|
|
|
// Create the scripting host. This needs to be done before the GUI is created.
|
|
|
|
// [7ms]
|
|
|
|
new ScriptingHost;
|
|
|
|
|
|
|
|
RegisterJavascriptInterfaces();
|
2006-06-30 00:52:50 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
#define REG_JS_CONSTANT(_name) g_ScriptingHost.DefineConstant(#_name, _name)
|
|
|
|
REG_JS_CONSTANT(SDL_BUTTON_LEFT);
|
|
|
|
REG_JS_CONSTANT(SDL_BUTTON_MIDDLE);
|
|
|
|
REG_JS_CONSTANT(SDL_BUTTON_RIGHT);
|
|
|
|
REG_JS_CONSTANT(SDL_BUTTON_WHEELUP);
|
|
|
|
REG_JS_CONSTANT(SDL_BUTTON_WHEELDOWN);
|
|
|
|
#undef REG_JS_CONSTANT
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-18 13:31:12 +02:00
|
|
|
static size_t ChooseCacheSize()
|
|
|
|
{
|
|
|
|
#if OS_WIN
|
|
|
|
//const size_t overheadKiB = (wutil_WindowsVersion() >= WUTIL_VERSION_VISTA)? 1024 : 512;
|
|
|
|
#endif
|
|
|
|
return 96*MiB;
|
|
|
|
}
|
|
|
|
|
2009-08-02 13:07:42 +02:00
|
|
|
|
2006-12-09 16:47:12 +01:00
|
|
|
static void InitVfs(const CmdLineArgs& args)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER(L"InitVfs");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-08-08 13:11:26 +02:00
|
|
|
const Paths paths(args);
|
2009-08-02 13:07:42 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
fs::wpath logs(paths.Logs());
|
2009-08-04 21:57:53 +02:00
|
|
|
CreateDirectories(logs, 0700);
|
2010-03-20 18:20:23 +01:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
psSetLogDir(logs);
|
2010-03-20 18:20:23 +01:00
|
|
|
// desired location for crashlog is now known. update AppHooks ASAP
|
|
|
|
// (particularly before the following error-prone operations):
|
|
|
|
AppHooks hooks = {0};
|
|
|
|
hooks.bundle_logs = psBundleLogs;
|
|
|
|
hooks.get_log_dir = psLogDir;
|
|
|
|
app_hooks_update(&hooks);
|
2009-08-02 13:07:42 +02:00
|
|
|
|
2008-09-18 13:31:12 +02:00
|
|
|
const size_t cacheSize = ChooseCacheSize();
|
|
|
|
g_VFS = CreateVfs(cacheSize);
|
2006-06-30 00:52:50 +02:00
|
|
|
|
2009-11-05 21:46:15 +01:00
|
|
|
g_VFS->Mount(L"screenshots/", paths.Data()/L"screenshots/");
|
2010-03-20 22:37:14 +01:00
|
|
|
const fs::wpath readonlyConfig = paths.RData()/L"config/";
|
|
|
|
g_VFS->Mount(L"config/", readonlyConfig);
|
|
|
|
if(readonlyConfig != paths.Config())
|
|
|
|
g_VFS->Mount(L"config/", paths.Config());
|
2009-11-03 22:46:35 +01:00
|
|
|
g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); // (adding XMBs to archive speeds up subsequent reads)
|
2006-05-17 16:48:18 +02:00
|
|
|
|
2006-12-09 16:47:12 +01:00
|
|
|
std::vector<CStr> mods = args.GetMultiple("mod");
|
2008-09-06 23:12:36 +02:00
|
|
|
mods.push_back("public");
|
|
|
|
if(!args.Has("onlyPublicFiles"))
|
2008-09-18 13:31:12 +02:00
|
|
|
mods.push_back("internal");
|
2006-05-17 16:48:18 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
fs::wpath modArchivePath(paths.Cache()/L"mods");
|
|
|
|
fs::wpath modLoosePath(paths.RData()/L"mods");
|
2006-12-09 16:47:12 +01:00
|
|
|
for (size_t i = 0; i < mods.size(); ++i)
|
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t priority = i;
|
2010-03-20 19:12:48 +01:00
|
|
|
size_t flags = VFS_MOUNT_WATCH|VFS_MOUNT_ARCHIVABLE|VFS_MOUNT_MUST_EXIST;
|
2009-11-09 21:53:48 +01:00
|
|
|
std::wstring modName (wstring_from_utf8(mods[i]));
|
2009-11-05 21:46:15 +01:00
|
|
|
g_VFS->Mount(L"", AddSlash(modLoosePath/modName), flags, priority);
|
|
|
|
g_VFS->Mount(L"", AddSlash(modArchivePath/modName), flags, priority);
|
2006-12-09 16:47:12 +01:00
|
|
|
}
|
|
|
|
|
2009-11-04 18:26:54 +01:00
|
|
|
// note: don't bother with g_VFS->TextRepresentation - directories
|
|
|
|
// haven't yet been populated and are empty.
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
static void InitPs(bool setup_gui, const CStrW& gui_page)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
|
|
|
// console
|
|
|
|
TIMER(L"ps_console");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
g_Console->UpdateScreenSize(g_xres, g_yres);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
// Calculate and store the line spacing
|
2010-05-30 15:42:56 +02:00
|
|
|
CFont font(CONSOLE_FONT);
|
2010-05-20 02:59:01 +02:00
|
|
|
g_Console->m_iFontHeight = font.GetLineSpacing();
|
|
|
|
g_Console->m_iFontWidth = font.GetCharacterWidth(L'C');
|
|
|
|
g_Console->m_charsPerPage = (size_t)(g_xres / g_Console->m_iFontWidth);
|
|
|
|
// Offset by an arbitrary amount, to make it fit more nicely
|
2010-05-30 15:42:56 +02:00
|
|
|
g_Console->m_iFontOffset = 7;
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
// language and hotkeys
|
|
|
|
{
|
|
|
|
TIMER(L"ps_lang_hotkeys");
|
2010-03-23 23:45:07 +01:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
std::string lang = "english";
|
|
|
|
CFG_GET_SYS_VAL("language", String, lang);
|
|
|
|
I18n::LoadLanguage(lang.c_str());
|
|
|
|
|
|
|
|
LoadHotkeys();
|
|
|
|
}
|
|
|
|
|
2010-06-02 02:36:21 +02:00
|
|
|
if (!setup_gui)
|
|
|
|
{
|
|
|
|
// We do actually need *some* kind of GUI loaded, so use the
|
|
|
|
// (currently empty) Atlas one
|
|
|
|
g_GUI->SwitchPage(L"page_atlas.xml", JSVAL_VOID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
// GUI uses VFS, so this must come after VFS init.
|
|
|
|
g_GUI->SwitchPage(gui_page, JSVAL_VOID);
|
|
|
|
|
|
|
|
// Warn nicely about missing S3TC support
|
|
|
|
if (!ogl_tex_has_s3tc())
|
|
|
|
{
|
|
|
|
g_GUI->DisplayMessageBox(600, 350, L"Warning",
|
|
|
|
L"Performance warning:\n\n"
|
|
|
|
L"Your graphics drivers do not support S3TC compressed textures. This will significantly reduce performance and increase memory usage.\n\n"
|
2010-03-26 18:22:13 +01:00
|
|
|
#if !(OS_WIN || OS_MACOSX)
|
2010-05-20 02:59:01 +02:00
|
|
|
L"See http://dri.freedesktop.org/wiki/S3TC for details. "
|
|
|
|
L"Installing the libtxc_dxtn library will fix these problems. "
|
|
|
|
L"Alternatively, running 'driconf' and setting force_s3tc_enable will fix the performance but may cause rendering bugs."
|
2010-03-23 23:45:07 +01:00
|
|
|
#else
|
2010-05-20 02:59:01 +02:00
|
|
|
L"Please try updating your graphics drivers to ensure you have full hardware acceleration."
|
2010-03-23 23:45:07 +01:00
|
|
|
#endif
|
2010-05-20 02:59:01 +02:00
|
|
|
);
|
2006-09-26 03:44:20 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InitInput()
|
|
|
|
{
|
|
|
|
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
|
|
|
|
|
|
|
// register input handlers
|
|
|
|
// This stack is constructed so the first added, will be the last
|
|
|
|
// one called. This is important, because each of the handlers
|
|
|
|
// has the potential to block events to go further down
|
|
|
|
// in the chain. I.e. the last one in the list added, is the
|
|
|
|
// only handler that can block all messages before they are
|
|
|
|
// processed.
|
|
|
|
in_add_handler(game_view_handler);
|
|
|
|
|
|
|
|
in_add_handler(conInputHandler);
|
|
|
|
|
|
|
|
in_add_handler(CProfileViewer::InputThunk);
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
in_add_handler(HotkeyInputHandler);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-02 02:36:21 +02:00
|
|
|
// gui_handler needs to be registered after (i.e. called before!) the
|
|
|
|
// hotkey handler so that input boxes can be typed in without
|
|
|
|
// setting off hotkeys.
|
|
|
|
in_add_handler(gui_handler);
|
2010-06-30 23:41:04 +02:00
|
|
|
|
|
|
|
// must be registered after (called before) the GUI which relies on these globals
|
|
|
|
in_add_handler(GlobalsInputHandler);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ShutdownPs()
|
|
|
|
{
|
2009-12-03 21:17:22 +01:00
|
|
|
SAFE_DELETE(g_GUI);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
SAFE_DELETE(g_Console);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// disable the special Windows cursor, or free textures for OGL cursors
|
|
|
|
cursor_draw(0, g_mouse_x, g_mouse_y);
|
|
|
|
|
|
|
|
// Unload the real language (since it depends on the scripting engine,
|
|
|
|
// which is going to be killed later) and use the English fallback messages
|
|
|
|
I18n::LoadLanguage(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InitRenderer()
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER(L"InitRenderer");
|
2007-09-02 23:44:56 +02:00
|
|
|
|
2007-09-03 20:41:42 +02:00
|
|
|
if(g_NoGLS3TC)
|
2007-09-02 23:44:56 +02:00
|
|
|
ogl_tex_override(OGL_TEX_S3TC, OGL_TEX_DISABLE);
|
2007-09-03 20:41:42 +02:00
|
|
|
if(g_NoGLAutoMipmap)
|
2007-09-02 23:44:56 +02:00
|
|
|
ogl_tex_override(OGL_TEX_AUTO_MIPMAP_GEN, OGL_TEX_DISABLE);
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// create renderer
|
|
|
|
new CRenderer;
|
|
|
|
|
|
|
|
// set renderer options from command line options - NOVBO must be set before opening the renderer
|
|
|
|
g_Renderer.SetOptionBool(CRenderer::OPT_NOVBO,g_NoGLVBO);
|
|
|
|
g_Renderer.SetOptionBool(CRenderer::OPT_NOFRAMEBUFFEROBJECT,g_NoGLFramebufferObject);
|
|
|
|
g_Renderer.SetOptionBool(CRenderer::OPT_SHADOWS,g_Shadows);
|
2006-05-17 05:53:54 +02:00
|
|
|
g_Renderer.SetOptionBool(CRenderer::OPT_FANCYWATER,g_FancyWater);
|
2006-04-24 01:14:18 +02:00
|
|
|
g_Renderer.SetRenderPath(CRenderer::GetRenderPathByName(g_RenderPath));
|
|
|
|
g_Renderer.SetOptionFloat(CRenderer::OPT_LODBIAS, g_LodBias);
|
|
|
|
|
|
|
|
// create terrain related stuff
|
|
|
|
new CTextureManager;
|
|
|
|
|
|
|
|
// create the material manager
|
|
|
|
new CMaterialManager;
|
|
|
|
|
|
|
|
MICROLOG(L"init renderer");
|
2010-06-03 21:07:59 +02:00
|
|
|
g_Renderer.Open(g_xres,g_yres);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Setup lighting environment. Since the Renderer accesses the
|
|
|
|
// lighting environment through a pointer, this has to be done before
|
|
|
|
// the first Frame.
|
|
|
|
g_Renderer.SetLightEnv(&g_LightEnv);
|
|
|
|
|
|
|
|
// I haven't seen the camera affecting GUI rendering and such, but the
|
|
|
|
// viewport has to be updated according to the video mode
|
|
|
|
SViewPort vp;
|
|
|
|
vp.m_X=0;
|
|
|
|
vp.m_Y=0;
|
|
|
|
vp.m_Width=g_xres;
|
|
|
|
vp.m_Height=g_yres;
|
|
|
|
g_Renderer.SetViewport(vp);
|
|
|
|
|
|
|
|
ColorActivateFastImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void InitSDL()
|
|
|
|
{
|
|
|
|
MICROLOG(L"init sdl");
|
|
|
|
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0)
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, L"SDL library initialization failed: %hs", SDL_GetError());
|
2006-04-24 01:14:18 +02:00
|
|
|
throw PSERROR_System_SDLInitFailed();
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
SDL_EnableUNICODE(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EndGame()
|
|
|
|
{
|
2010-05-20 02:59:01 +02:00
|
|
|
SAFE_DELETE(g_NetServer);
|
|
|
|
SAFE_DELETE(g_NetClient);
|
|
|
|
SAFE_DELETE(g_Game);
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
void Shutdown(int UNUSED(flags))
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
MICROLOG(L"Shutdown");
|
|
|
|
|
2010-07-02 23:28:48 +02:00
|
|
|
EndGame();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-10-08 06:56:30 +02:00
|
|
|
ShutdownPs(); // Must delete g_GUI before g_ScriptingHost
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// destroy actor related stuff
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown actor stuff");
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_MaterialManager;
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown actor stuff");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// destroy terrain related stuff
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown TexMan");
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_TexMan;
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown TexMan");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// destroy renderer
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown Renderer");
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_Renderer;
|
|
|
|
g_VBMan.Shutdown();
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown Renderer");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown ScriptingHost");
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_ScriptingHost;
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown ScriptingHost");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown ConfigDB");
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_ConfigDB;
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown ConfigDB");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Really shut down the i18n system. Any future calls
|
|
|
|
// to translate() will crash.
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown I18N");
|
2006-04-24 01:14:18 +02:00
|
|
|
I18n::Shutdown();
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown I18N");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// resource
|
|
|
|
// first shut down all resource owners, and then the handle manager.
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"resource modules");
|
2006-04-24 01:14:18 +02:00
|
|
|
snd_shutdown();
|
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
g_VFS.reset();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// this forcibly frees all open handles (thus preventing real leaks),
|
|
|
|
// and makes further access to h_mgr impossible.
|
|
|
|
h_mgr_shutdown();
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"resource modules");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_BEGIN(L"shutdown misc");
|
2008-01-07 21:03:19 +01:00
|
|
|
timer_DisplayClientTotals();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// should be last, since the above use them
|
2006-09-28 22:41:12 +02:00
|
|
|
SAFE_DELETE(g_Logger);
|
2006-04-24 01:14:18 +02:00
|
|
|
delete &g_Profiler;
|
|
|
|
delete &g_ProfileViewer;
|
2009-11-03 22:46:35 +01:00
|
|
|
TIMER_END(L"shutdown misc");
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2007-05-27 01:29:20 +02:00
|
|
|
void EarlyInit()
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2007-05-27 01:29:20 +02:00
|
|
|
MICROLOG(L"EarlyInit");
|
|
|
|
|
|
|
|
// If you ever want to catch a particular allocation:
|
2009-11-03 22:46:35 +01:00
|
|
|
//_CrtSetBreakAlloc(232647);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2008-09-27 12:05:11 +02:00
|
|
|
debug_SetThreadName("main");
|
2006-04-24 01:14:18 +02:00
|
|
|
// add all debug_printf "tags" that we are interested in:
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_filter_add(L"TIMER");
|
|
|
|
debug_filter_add(L"HRT");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-09-23 17:36:29 +02:00
|
|
|
cpu_ConfigureFloatingPoint();
|
2007-05-26 19:56:38 +02:00
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
timer_LatchStartTime();
|
2007-09-03 01:38:58 +02:00
|
|
|
|
|
|
|
// Initialise the low-quality rand function
|
2007-11-18 10:09:06 +01:00
|
|
|
srand(time(NULL)); // NOTE: this rand should *not* be used for simulation!
|
2007-05-27 01:29:20 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
static bool Autostart(const CmdLineArgs& args);
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
void Init(const CmdLineArgs& args, int flags)
|
2007-05-27 01:29:20 +02:00
|
|
|
{
|
|
|
|
const bool setup_vmode = (flags & INIT_HAVE_VMODE) == 0;
|
|
|
|
|
|
|
|
MICROLOG(L"Init");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-22 01:24:56 +02:00
|
|
|
h_mgr_init();
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// Do this as soon as possible, because it chdirs
|
|
|
|
// and will mess up the error reporting if anything
|
|
|
|
// crashes before the working directory is set.
|
|
|
|
MICROLOG(L"init vfs");
|
2006-12-09 16:47:12 +01:00
|
|
|
InitVfs(args);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// This must come after VFS init, which sets the current directory
|
|
|
|
// (required for finding our output log files).
|
2006-09-28 22:41:12 +02:00
|
|
|
g_Logger = new CLogger;
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-04-09 21:02:39 +02:00
|
|
|
// Special command-line mode to dump the entity schemas instead of running the game.
|
|
|
|
// (This must be done after loading VFS etc, but should be done before wasting time
|
|
|
|
// on anything else.)
|
|
|
|
if (args.Has("dumpSchema"))
|
|
|
|
{
|
|
|
|
CSimulation2 sim(NULL, NULL);
|
|
|
|
sim.LoadDefaultScripts();
|
|
|
|
std::ofstream f("entity.rng", std::ios_base::out | std::ios_base::trunc);
|
|
|
|
f << sim.GenerateSchema();
|
|
|
|
std::cout << "Generated entity.rng\n";
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2006-06-30 00:52:50 +02:00
|
|
|
// Call LoadLanguage(NULL) to initialize the I18n system, but
|
2006-04-24 01:14:18 +02:00
|
|
|
// without loading an actual language file - translate() will
|
|
|
|
// just show the English key text, which is better than crashing
|
|
|
|
// from a null pointer when attempting to translate e.g. error messages.
|
|
|
|
// Real languages can only be loaded when the scripting system has
|
|
|
|
// been initialised.
|
|
|
|
//
|
|
|
|
// this uses LOG and must therefore come after CLogger init.
|
|
|
|
MICROLOG(L"init i18n");
|
|
|
|
I18n::LoadLanguage(NULL);
|
|
|
|
|
2006-06-23 19:41:55 +02:00
|
|
|
// override ah_translate with our i18n code.
|
|
|
|
AppHooks hooks = {0};
|
|
|
|
hooks.translate = psTranslate;
|
2006-06-25 17:35:28 +02:00
|
|
|
hooks.translate_free = psTranslateFree;
|
|
|
|
app_hooks_update(&hooks);
|
2006-06-23 19:41:55 +02:00
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// Set up the console early, so that debugging
|
|
|
|
// messages can be logged to it. (The console's size
|
|
|
|
// and fonts are set later in InitPs())
|
|
|
|
g_Console = new CConsole();
|
|
|
|
|
|
|
|
if(setup_vmode)
|
|
|
|
InitSDL();
|
|
|
|
|
|
|
|
new CProfileViewer;
|
|
|
|
new CProfileManager; // before any script code
|
|
|
|
|
|
|
|
MICROLOG(L"init scripting");
|
|
|
|
InitScripting(); // before GUI
|
|
|
|
|
|
|
|
// g_ConfigDB, command line args, globals
|
2006-12-09 15:39:52 +01:00
|
|
|
CONFIG_Init(args);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-06-03 21:07:59 +02:00
|
|
|
if (setup_vmode)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-06-03 21:07:59 +02:00
|
|
|
if (!g_VideoMode.InitSDL())
|
|
|
|
throw PSERROR_System_VmodeFailed(); // abort startup
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
SDL_WM_SetCaption("0 A.D.", "0 A.D.");
|
|
|
|
}
|
|
|
|
|
2006-06-02 05:56:24 +02:00
|
|
|
tex_codec_register_all();
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
const int quality = SANE_TEX_QUALITY_DEFAULT; // TODO: set value from config file
|
2006-04-24 01:14:18 +02:00
|
|
|
SetTextureQuality(quality);
|
|
|
|
|
2008-01-20 22:52:54 +01:00
|
|
|
// needed by ogl_tex to detect broken gfx card/driver combos,
|
|
|
|
// but takes a while due to WMI startup, so make it optional.
|
|
|
|
if(!g_Quickstart)
|
|
|
|
gfx_detect();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
if(!g_Quickstart)
|
|
|
|
{
|
|
|
|
WriteSystemInfo();
|
2006-06-03 23:21:59 +02:00
|
|
|
// note: no longer vfs_display here. it's dog-slow due to unbuffered
|
|
|
|
// file output and very rarely needed.
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
2010-06-05 02:49:14 +02:00
|
|
|
|
|
|
|
if(g_DisableAudio)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
// speed up startup by disabling all sound
|
|
|
|
// (OpenAL init will be skipped).
|
|
|
|
// must be called before first snd_open.
|
|
|
|
snd_disable(true);
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:07:59 +02:00
|
|
|
g_GUI = new CGUIManager(g_ScriptingHost.GetScriptInterface());
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// (must come after SetVideoMode, since it calls ogl_Init)
|
|
|
|
const char* missing = ogl_HaveExtensions(0,
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
"GL_ARB_multitexture",
|
|
|
|
"GL_EXT_draw_range_elements",
|
|
|
|
"GL_ARB_texture_env_combine",
|
|
|
|
"GL_ARB_texture_env_dot3",
|
2009-08-04 18:08:41 +02:00
|
|
|
NULL);
|
2006-04-24 01:14:18 +02:00
|
|
|
if(missing)
|
|
|
|
{
|
|
|
|
wchar_t buf[500];
|
2009-11-07 10:32:19 +01:00
|
|
|
swprintf_s(buf, ARRAY_SIZE(buf),
|
2007-01-29 18:46:28 +01:00
|
|
|
L"The %hs extension doesn't appear to be available on your computer."
|
|
|
|
L" The game may still work, though - you are welcome to try at your own risk."
|
2009-11-07 10:32:19 +01:00
|
|
|
L" If not or it doesn't look right, upgrade your graphics card.",
|
|
|
|
missing
|
|
|
|
);
|
2008-01-19 12:33:11 +01:00
|
|
|
DEBUG_DISPLAY_ERROR(buf);
|
2006-04-24 01:14:18 +02:00
|
|
|
// TODO: i18n
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
if (!ogl_HaveExtension("GL_ARB_texture_env_crossbar"))
|
2006-09-14 21:15:32 +02:00
|
|
|
{
|
2008-01-19 12:33:11 +01:00
|
|
|
DEBUG_DISPLAY_ERROR(
|
2006-09-14 21:15:32 +02:00
|
|
|
L"The GL_ARB_texture_env_crossbar extension doesn't appear to be available on your computer."
|
2007-01-29 18:46:28 +01:00
|
|
|
L" Shadows are not available and overall graphics quality might suffer."
|
|
|
|
L" You are advised to try installing newer drivers and/or upgrade your graphics card.");
|
2006-09-14 21:15:32 +02:00
|
|
|
g_Shadows = false;
|
|
|
|
}
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// enable/disable VSync
|
|
|
|
// note: "GL_EXT_SWAP_CONTROL" is "historical" according to dox.
|
|
|
|
#if OS_WIN
|
2007-05-02 14:07:08 +02:00
|
|
|
if(ogl_HaveExtension("WGL_EXT_swap_control"))
|
2006-04-24 01:14:18 +02:00
|
|
|
pwglSwapIntervalEXT(g_VSync? 1 : 0);
|
|
|
|
#endif
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
InitRenderer();
|
|
|
|
|
|
|
|
InitInput();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
if (!Autostart(args))
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2010-06-03 21:07:59 +02:00
|
|
|
const bool setup_gui = ((flags & INIT_NO_GUI) == 0);
|
2010-05-20 02:59:01 +02:00
|
|
|
InitPs(setup_gui, L"page_pregame.xml");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderGui(bool RenderingState)
|
|
|
|
{
|
|
|
|
g_DoRenderGui = RenderingState;
|
|
|
|
}
|
2010-02-03 21:46:05 +01:00
|
|
|
|
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
// Network autostart:
|
|
|
|
|
|
|
|
class AutostartNetServer : public CNetServer
|
|
|
|
{
|
|
|
|
public:
|
2010-06-30 23:41:04 +02:00
|
|
|
AutostartNetServer(const CStr& map, int maxPlayers) :
|
|
|
|
CNetServer(), m_NeedsStart(false), m_NumPlayers(0), m_MaxPlayers(maxPlayers)
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
2010-06-30 23:41:04 +02:00
|
|
|
CScriptValRooted attrs;
|
|
|
|
GetScriptInterface().Eval("({})", attrs);
|
|
|
|
GetScriptInterface().SetProperty(attrs.get(), "map", std::string(map), false);
|
|
|
|
UpdateGameAttributes(attrs);
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2010-06-30 23:41:04 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
protected:
|
2010-06-30 23:41:04 +02:00
|
|
|
virtual void OnAddPlayer()
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
|
|
|
m_NumPlayers++;
|
|
|
|
|
|
|
|
debug_printf(L"# player joined (got %d, need %d)\n", (int)m_NumPlayers, (int)m_MaxPlayers);
|
|
|
|
|
|
|
|
if (m_NumPlayers >= m_MaxPlayers)
|
2010-06-30 23:41:04 +02:00
|
|
|
m_NeedsStart = true; // delay until next Poll, so the new player has been fully processed
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
virtual void OnRemovePlayer()
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
|
|
|
debug_warn(L"client left?!");
|
|
|
|
m_NumPlayers--;
|
|
|
|
}
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
virtual void Poll()
|
2010-05-20 02:59:01 +02:00
|
|
|
{
|
2010-06-30 23:41:04 +02:00
|
|
|
if (m_NeedsStart)
|
|
|
|
{
|
|
|
|
StartGame();
|
|
|
|
m_NeedsStart = false;
|
|
|
|
}
|
2010-05-20 02:59:01 +02:00
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
CNetServer::Poll();
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2010-06-30 23:41:04 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_NeedsStart;
|
|
|
|
size_t m_NumPlayers;
|
|
|
|
size_t m_MaxPlayers;
|
2010-05-20 02:59:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool Autostart(const CmdLineArgs& args)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Handle various command-line options, for quick testing of various features:
|
|
|
|
* -autostart=mapname -- single-player
|
|
|
|
* -autostart=mapname -autostart-playername=Player -autostart-host -autostart-players=2 -- multiplayer host, wait for 2 players
|
|
|
|
* -autostart=mapname -autostart-playername=Player -autostart-client -autostart-ip=127.0.0.1 -- multiplayer client, connect to 127.0.0.1
|
|
|
|
*/
|
|
|
|
|
|
|
|
CStr autostartMap = args.Get("autostart");
|
|
|
|
if (autostartMap.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
g_Game = new CGame();
|
|
|
|
|
|
|
|
if (args.Has("autostart-host"))
|
|
|
|
{
|
|
|
|
InitPs(true, L"page_loading.xml");
|
|
|
|
|
|
|
|
size_t maxPlayers = 2;
|
|
|
|
if (args.Has("autostart-players"))
|
|
|
|
maxPlayers = args.Get("autostart-players").ToUInt();
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
g_NetServer = new AutostartNetServer(autostartMap, maxPlayers);
|
|
|
|
bool ok = g_NetServer->SetupConnection();
|
2010-05-20 02:59:01 +02:00
|
|
|
debug_assert(ok);
|
2010-06-30 23:41:04 +02:00
|
|
|
|
|
|
|
g_NetClient = new CNetClient(g_Game);
|
|
|
|
// TODO: player name, etc
|
|
|
|
g_NetClient->SetupLocalConnection(*g_NetServer);
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
|
|
|
else if (args.Has("autostart-client"))
|
|
|
|
{
|
|
|
|
InitPs(true, L"page_loading.xml");
|
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
g_NetClient = new CNetClient(g_Game);
|
2010-05-20 02:59:01 +02:00
|
|
|
// TODO: player name, etc
|
2010-06-30 23:41:04 +02:00
|
|
|
bool ok = g_NetClient->SetupConnection(args.Get("autostart-ip"));
|
2010-05-20 02:59:01 +02:00
|
|
|
debug_assert(ok);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-30 23:41:04 +02:00
|
|
|
CScriptValRooted attrs;
|
|
|
|
g_Game->GetSimulation2()->GetScriptInterface().Eval("({})", attrs);
|
|
|
|
g_Game->GetSimulation2()->GetScriptInterface().SetProperty(attrs.get(), "map", std::string(autostartMap), false);
|
2010-02-03 21:46:05 +01:00
|
|
|
|
2010-06-30 23:41:04 +02:00
|
|
|
g_Game->SetPlayerID(1);
|
|
|
|
g_Game->StartGame(attrs);
|
2006-04-24 01:14:18 +02:00
|
|
|
LDR_NonprogressiveLoad();
|
2010-06-30 23:41:04 +02:00
|
|
|
PSRETURN ret = g_Game->ReallyStartGame();
|
2006-04-24 01:14:18 +02:00
|
|
|
debug_assert(ret == PSRETURN_OK);
|
|
|
|
|
2010-05-20 20:09:23 +02:00
|
|
|
InitPs(true, L"page_session_new.xml");
|
2010-05-20 02:59:01 +02:00
|
|
|
}
|
2009-04-18 17:27:38 +02:00
|
|
|
|
2010-05-20 02:59:01 +02:00
|
|
|
return true;
|
2009-11-06 19:35:32 +01:00
|
|
|
}
|