2006-04-24 01:14:18 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2007-05-04 19:30:32 +02:00
|
|
|
#include "lib/external_libraries/sdl.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/ogl.h"
|
|
|
|
#include "lib/timer.h"
|
|
|
|
#include "lib/input.h"
|
2007-05-26 19:56:38 +02:00
|
|
|
#include "lib/lockfree.h"
|
2006-06-23 19:41:55 +02:00
|
|
|
#include "lib/app_hooks.h"
|
2006-06-22 20:26:08 +02:00
|
|
|
#include "lib/sysdep/cpu.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/sysdep/gfx.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/res/h_mgr.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/res/sound/snd_mgr.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/tex/tex.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "lib/res/graphics/cursor.h"
|
|
|
|
|
|
|
|
#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/Interact.h"
|
|
|
|
#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"
|
# 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"
|
|
|
|
|
|
|
|
#include "simulation/Entity.h"
|
|
|
|
#include "simulation/EntityManager.h"
|
2008-04-13 16:50:11 +02:00
|
|
|
#include "simulation/Scheduler.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-07-27 23:20:30 +02:00
|
|
|
#include "scripting/ScriptableComplex.inl"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "scripting/ScriptingHost.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "scripting/DOMEvent.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#include "scripting/GameEvents.h"
|
2006-07-27 04:42:35 +02:00
|
|
|
#include "scripting/ScriptableComplex.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "maths/scripting/JSInterface_Vector3D.h"
|
|
|
|
#include "graphics/scripting/JSInterface_Camera.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "graphics/scripting/JSInterface_LightEnv.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/scripting/JSInterface_Selection.h"
|
|
|
|
#include "ps/scripting/JSInterface_Console.h"
|
|
|
|
#include "ps/scripting/JSCollection.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "simulation/scripting/SimulationScriptInit.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
#ifndef NO_GUI
|
|
|
|
# include "gui/scripting/JSInterface_IGUIObject.h"
|
|
|
|
# include "gui/scripting/JSInterface_GUITypes.h"
|
|
|
|
# include "gui/GUI.h"
|
|
|
|
#endif
|
|
|
|
#include "sound/JSI_Sound.h"
|
|
|
|
|
2008-01-10 02:17:09 +01:00
|
|
|
#include "network/NetLog.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
|
|
|
|
2006-12-09 15:39:52 +01:00
|
|
|
#include "ps/GameSetup/Atlas.h"
|
|
|
|
#include "ps/GameSetup/GameSetup.h"
|
|
|
|
#include "ps/GameSetup/Config.h"
|
|
|
|
#include "ps/GameSetup/CmdLineArgs.h"
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
ERROR_GROUP(System);
|
|
|
|
ERROR_TYPE(System, SDLInitFailed);
|
|
|
|
ERROR_TYPE(System, VmodeFailed);
|
|
|
|
ERROR_TYPE(System, RequiredExtensionsMissing);
|
|
|
|
|
|
|
|
#define LOG_CATEGORY "gamesetup"
|
|
|
|
|
|
|
|
|
|
|
|
static int SetVideoMode(int w, int h, int bpp, bool fullscreen)
|
|
|
|
{
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
|
|
|
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
|
|
|
Uint32 flags = SDL_OPENGL;
|
2006-04-24 01:14:18 +02:00
|
|
|
if(fullscreen)
|
|
|
|
flags |= SDL_FULLSCREEN;
|
|
|
|
if(!SDL_SetVideoMode(w, h, bpp, flags))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// Work around a bug in the proprietary Linux ATI driver (at least versions 8.16.20 and 8.14.13).
|
|
|
|
// The driver appears to register its own atexit hook on context creation.
|
|
|
|
// If this atexit hook is called before SDL_Quit destroys the OpenGL context,
|
|
|
|
// some kind of double-free problem causes a crash and lockup in the driver.
|
|
|
|
// Calling SDL_Quit twice appears to be harmless, though, and avoids the problem
|
|
|
|
// by destroying the context *before* the driver's atexit hook is called.
|
2007-06-03 17:37:26 +02:00
|
|
|
// (Note that atexit hooks are guaranteed to be called in reverse order of their registration.)
|
2006-04-24 01:14:18 +02:00
|
|
|
atexit(SDL_Quit);
|
|
|
|
// End work around.
|
|
|
|
|
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
|
|
|
#ifndef NO_GUI
|
|
|
|
g_GUI.UpdateResolution();
|
|
|
|
#endif
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_Init(); // required after each mode change
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
if(SDL_SetGamma(g_Gamma, g_Gamma, g_Gamma) < 0)
|
|
|
|
debug_warn("SDL_SetGamma failed");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
debug_warn("SetTextureQuality: invalid quality");
|
|
|
|
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
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void GUI_Init()
|
|
|
|
{
|
|
|
|
#ifndef NO_GUI
|
|
|
|
{TIMER("ps_gui_init");
|
|
|
|
g_GUI.Initialize();}
|
|
|
|
|
|
|
|
{TIMER("ps_gui_setup_xml");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/setup.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_styles_xml");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/styles.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_sprite1_xml");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/sprite1.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// Atlas is running, we won't need these GUI pages (for now!
|
|
|
|
// what if Atlas switches to in-game mode?!)
|
|
|
|
// TODO: temporary hack until revised GUI structure is completed.
|
|
|
|
// if(ATLAS_IsRunning())
|
|
|
|
// return;
|
|
|
|
|
|
|
|
{TIMER("ps_gui_1");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/1_init.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_2");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/2_mainmenu.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_3");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/3_loading.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_4");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/4_session.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_6");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/6_subwindows.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_6_1");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/6_1_manual.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_6_2");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/6_2_jukebox.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_7");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/7_atlas.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
{TIMER("ps_gui_9");
|
2007-05-02 14:07:08 +02:00
|
|
|
g_GUI.LoadXmlFile("gui/test/9_global.xml");}
|
2006-04-24 01:14:18 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI_Shutdown()
|
|
|
|
{
|
|
|
|
#ifndef NO_GUI
|
|
|
|
g_GUI.Destroy();
|
|
|
|
delete &g_GUI;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI_ShowMainMenu()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// display progress / description in loading screen
|
|
|
|
void GUI_DisplayLoadProgress(int percent, const wchar_t* pending_task)
|
|
|
|
{
|
|
|
|
#ifndef NO_GUI
|
|
|
|
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));
|
|
|
|
g_GUI.SendEventToAll("progress");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Render()
|
|
|
|
{
|
|
|
|
MICROLOG(L"begin frame");
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#ifndef NO_GUI // HACK: because colour-parsing requires the GUI
|
|
|
|
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
|
|
|
#endif
|
|
|
|
|
|
|
|
// start new frame
|
|
|
|
g_Renderer.BeginFrame();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
if (g_Game && g_Game->IsGameStarted())
|
|
|
|
{
|
|
|
|
g_Game->GetView()->Render();
|
|
|
|
|
|
|
|
glPushAttrib( GL_ENABLE_BIT );
|
|
|
|
glDisable( GL_LIGHTING );
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
glDisable( GL_DEPTH_TEST );
|
|
|
|
|
|
|
|
if( g_EntGraph )
|
|
|
|
{
|
|
|
|
PROFILE( "render entity overlays" );
|
|
|
|
glColor3f( 1.0f, 0.0f, 1.0f );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_EntityManager.RenderAll(); // <-- collision outlines, pathing routes
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnable( GL_DEPTH_TEST );
|
2006-09-07 00:26:27 +02:00
|
|
|
|
2006-08-25 08:04:33 +02:00
|
|
|
PROFILE_START( "render entity outlines" );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Mouseover.RenderSelectionOutlines();
|
|
|
|
g_Selection.RenderSelectionOutlines();
|
2006-07-16 21:32:48 +02:00
|
|
|
PROFILE_END( "render entity outlines" );
|
2006-08-25 08:04:33 +02:00
|
|
|
|
|
|
|
PROFILE_START( "render entity auras" );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Mouseover.RenderAuras();
|
|
|
|
g_Selection.RenderAuras();
|
2006-08-25 08:04:33 +02:00
|
|
|
PROFILE_END( "render entity auras" );
|
|
|
|
|
2006-09-07 00:26:27 +02:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-07-16 21:32:48 +02:00
|
|
|
PROFILE_START( "render entity bars" );
|
2006-05-28 23:58:56 +02:00
|
|
|
pglActiveTextureARB(GL_TEXTURE1_ARB);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
pglActiveTextureARB(GL_TEXTURE0_ARB);
|
2006-07-16 21:32:48 +02:00
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, g_Renderer.m_Options.m_LodBias);
|
2006-05-28 23:58:56 +02:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
2006-07-16 21:32:48 +02:00
|
|
|
/*glMatrixMode(GL_PROJECTION);
|
2006-04-24 01:14:18 +02:00
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2006-07-16 21:32:48 +02:00
|
|
|
glOrtho(0.f, (float)g_xres, 0.f, (float)g_yres, -1.0f, 1000.f);
|
2006-04-24 01:14:18 +02:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
2006-07-16 21:32:48 +02:00
|
|
|
glLoadIdentity();*/
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Mouseover.RenderBars();
|
|
|
|
g_Selection.RenderBars();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-07-16 21:32:48 +02:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
/*glPopMatrix();
|
2006-04-24 01:14:18 +02:00
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
2006-07-16 21:32:48 +02:00
|
|
|
glMatrixMode(GL_MODELVIEW);*/
|
|
|
|
PROFILE_END( "render entity bars" );
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
glPopAttrib();
|
2006-08-22 04:24:44 +02:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2006-07-16 21:32:48 +02:00
|
|
|
|
|
|
|
// Depth test is now enabled
|
|
|
|
PROFILE_START( "render rally points" );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Selection.RenderRallyPoints();
|
|
|
|
g_Mouseover.RenderRallyPoints();
|
2006-07-16 21:32:48 +02:00
|
|
|
PROFILE_END( "render rally points" );
|
2006-08-22 04:24:44 +02:00
|
|
|
|
|
|
|
PROFILE_START( "render cinematic splines" );
|
|
|
|
//Sets/resets renderering properties itself
|
2007-02-27 03:14:18 +01:00
|
|
|
g_Game->GetView()->GetCinema()->DrawSpline();
|
2006-08-22 04:24:44 +02:00
|
|
|
PROFILE_END( "render cinematic splines" );
|
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
|
|
|
|
|
|
|
PROFILE_START( "render fonts" );
|
|
|
|
MICROLOG(L"render fonts");
|
|
|
|
// overlay mode
|
|
|
|
glPushAttrib(GL_ENABLE_BIT);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
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
|
|
|
|
|
|
|
PROFILE_END( "render fonts" );
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#ifndef NO_GUI
|
|
|
|
// Temp GUI message GeeTODO
|
|
|
|
MICROLOG(L"render GUI");
|
|
|
|
PROFILE_START( "render gui" );
|
|
|
|
g_GUI.Draw();
|
|
|
|
PROFILE_END( "render gui" );
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
PROFILE( "render console" );
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
MICROLOG(L"render console");
|
|
|
|
CFont font("console");
|
|
|
|
font.Bind();
|
|
|
|
g_Console->Render();
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Profile information
|
|
|
|
|
|
|
|
PROFILE_START( "render profiling" );
|
|
|
|
g_ProfileViewer.RenderProfile();
|
|
|
|
PROFILE_END( "render profiling" );
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
if (g_Game && g_Game->IsGameStarted())
|
|
|
|
{
|
|
|
|
PROFILE( "render selection overlays" );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Mouseover.RenderOverlays();
|
|
|
|
g_Selection.RenderOverlays();
|
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)
|
2006-09-28 22:41:12 +02:00
|
|
|
CStr cursorName = g_BuildingPlacer.m_active ? "action-build" : g_CursorName;
|
2007-06-11 01:15:14 +02:00
|
|
|
if (cursorName.empty())
|
|
|
|
cursor_draw(NULL, g_mouse_x, g_mouse_y);
|
|
|
|
else
|
|
|
|
cursor_draw(cursorName, 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
|
|
|
|
SColour::ScriptingInit();
|
|
|
|
CScriptEvent::ScriptingInit();
|
|
|
|
// call CJSComplexPropertyAccessor's ScriptingInit. doesn't really
|
|
|
|
// matter which <T> we use, but we know CJSPropertyAccessor<T> is
|
|
|
|
// already being compiled for T = CEntity.
|
|
|
|
ScriptableComplex_InitComplexPropertyAccessor<CEntity>();
|
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// ps
|
|
|
|
JSI_Console::init();
|
|
|
|
CProfileNode::ScriptingInit();
|
|
|
|
CGameAttributes::ScriptingInit();
|
|
|
|
CPlayerSlot::ScriptingInit();
|
2006-04-24 01:14:18 +02:00
|
|
|
CPlayer::ScriptingInit();
|
2008-04-13 16:50:11 +02:00
|
|
|
PlayerCollection::Init( "PlayerCollection" );
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// network
|
|
|
|
CNetMessage::ScriptingInit();
|
2008-04-13 16:50:11 +02:00
|
|
|
CNetClient::ScriptingInit();
|
|
|
|
CNetServer::ScriptingInit();
|
2008-06-16 20:19:35 +02:00
|
|
|
CNetSession::ScriptingInit();
|
|
|
|
CServerPlayer::ScriptingInit();
|
2008-04-06 16:03:23 +02:00
|
|
|
|
|
|
|
// simulation
|
2008-04-13 16:50:11 +02:00
|
|
|
SimulationScriptInit();
|
2006-07-27 14:54:47 +02:00
|
|
|
|
2008-04-06 16:03:23 +02:00
|
|
|
// GUI
|
|
|
|
#ifndef NO_GUI
|
|
|
|
JSI_IGUIObject::init();
|
|
|
|
JSI_GUITypes::init();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InitScripting()
|
|
|
|
{
|
|
|
|
TIMER("InitScripting");
|
|
|
|
|
|
|
|
// Create the scripting host. This needs to be done before the GUI is created.
|
|
|
|
// [7ms]
|
|
|
|
new ScriptingHost;
|
|
|
|
|
|
|
|
// It would be nice for onLoad code to be able to access the setTimeout() calls.
|
|
|
|
new CScheduler;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
new CGameEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-09 16:47:12 +01:00
|
|
|
static void InitVfs(const CmdLineArgs& args)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
TIMER("InitVfs");
|
|
|
|
|
|
|
|
// set root directory to "$game_dir/data". all relative file paths
|
|
|
|
// passed to file.cpp will be based from this dir.
|
|
|
|
// (we don't set current directory because other libraries may
|
|
|
|
// hijack it).
|
|
|
|
//
|
|
|
|
// "../data" is relative to the executable (in "$game_dir/system").
|
|
|
|
//
|
|
|
|
// rationale for data/ being root: untrusted scripts must not be
|
|
|
|
// allowed to overwrite critical game (or worse, OS) files.
|
|
|
|
// the VFS prevents any accesses to files above this directory.
|
2007-12-20 21:21:45 +01:00
|
|
|
path_SetRoot(args.GetArg0(), "../data");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2008-05-13 21:43:02 +02:00
|
|
|
g_VFS = CreateVfs(96*MiB);
|
2006-06-30 00:52:50 +02:00
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
g_VFS->Mount("screenshots/", "screenshots");
|
|
|
|
g_VFS->Mount("config/", "config");
|
|
|
|
g_VFS->Mount("profiles/", "profiles");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-05-17 16:48:18 +02:00
|
|
|
// rationale:
|
|
|
|
// - this is in a separate real directory so that it can later be moved
|
|
|
|
// to $APPDATA to allow running without Admin access.
|
|
|
|
// - we mount as archivable so that all files will be added to archive.
|
|
|
|
// even though we write out XMBs here, they will eventually be read,
|
|
|
|
// so putting them in an archive boosts performance.
|
2006-06-30 00:52:50 +02:00
|
|
|
//
|
|
|
|
// [hot: 16ms]
|
2007-12-20 21:21:45 +01:00
|
|
|
g_VFS->Mount("cache/", "cache", VFS_MOUNT_ARCHIVABLE);
|
2006-05-17 16:48:18 +02:00
|
|
|
|
2006-12-09 16:47:12 +01:00
|
|
|
std::vector<CStr> mods = args.GetMultiple("mod");
|
|
|
|
if (mods.empty())
|
|
|
|
mods.push_back("official");
|
2006-05-17 16:48:18 +02:00
|
|
|
|
2006-12-09 16:47:12 +01:00
|
|
|
for (size_t i = 0; i < mods.size(); ++i)
|
|
|
|
{
|
|
|
|
CStr path = "mods/" + mods[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;
|
|
|
|
int flags = VFS_MOUNT_WATCH;
|
2006-12-09 16:47:12 +01:00
|
|
|
|
|
|
|
// TODO: currently only archive 'official' - probably ought to archive
|
|
|
|
// all mods instead?
|
|
|
|
if (mods[i] == "official")
|
|
|
|
flags |= VFS_MOUNT_ARCHIVABLE;
|
|
|
|
|
|
|
|
// [hot: 150ms for mods/official]
|
2007-12-20 21:21:45 +01:00
|
|
|
g_VFS->Mount("", path, flags, priority);
|
2006-12-09 16:47:12 +01:00
|
|
|
}
|
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
// don't try g_VFS->Display yet: SDL_Init hasn't yet redirected stdout
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void InitPs(bool setup_gui)
|
|
|
|
{
|
2006-09-26 03:44:20 +02:00
|
|
|
if (setup_gui)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2006-09-26 03:44:20 +02:00
|
|
|
// The things here aren't strictly GUI, but they're unnecessary when in Atlas
|
2007-03-20 02:06:34 +01:00
|
|
|
// because the game doesn't draw any text or handle keys or anything
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-26 03:44:20 +02:00
|
|
|
{
|
|
|
|
// console
|
|
|
|
TIMER("ps_console");
|
|
|
|
|
|
|
|
g_Console->UpdateScreenSize(g_xres, g_yres);
|
|
|
|
|
|
|
|
// Calculate and store the line spacing
|
|
|
|
CFont font("console");
|
|
|
|
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
|
|
|
|
g_Console->m_iFontOffset = 9;
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-26 03:44:20 +02:00
|
|
|
// language and hotkeys
|
|
|
|
{
|
|
|
|
TIMER("ps_lang_hotkeys");
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-26 03:44:20 +02:00
|
|
|
std::string lang = "english";
|
|
|
|
CFG_GET_SYS_VAL("language", String, lang);
|
|
|
|
I18n::LoadLanguage(lang.c_str());
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
LoadHotkeys();
|
2006-09-26 03:44:20 +02:00
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-26 03:44:20 +02:00
|
|
|
// GUI uses VFS, so this must come after VFS init.
|
2006-04-24 01:14:18 +02:00
|
|
|
GUI_Init();
|
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);
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
in_add_handler(InteractInputHandler);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
in_add_handler(GlobalsInputHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void ShutdownPs()
|
|
|
|
{
|
|
|
|
GUI_Shutdown();
|
|
|
|
|
|
|
|
delete g_Console;
|
2006-09-24 13:48:24 +02:00
|
|
|
g_Console = 0;
|
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);
|
|
|
|
|
|
|
|
// close down Xerces if it was loaded
|
|
|
|
CXeromyces::Terminate();
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
TIMER("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");
|
|
|
|
g_Renderer.Open(g_xres,g_yres,g_bpp);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "SDL library initialization failed: %s", SDL_GetError());
|
2006-04-24 01:14:18 +02:00
|
|
|
throw PSERROR_System_SDLInitFailed();
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
SDL_EnableUNICODE(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void EndGame()
|
|
|
|
{
|
|
|
|
if (g_NetServer)
|
|
|
|
{
|
|
|
|
delete g_NetServer;
|
|
|
|
g_NetServer=NULL;
|
|
|
|
}
|
|
|
|
else if (g_NetClient)
|
|
|
|
{
|
|
|
|
delete g_NetClient;
|
|
|
|
g_NetClient=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete g_Game;
|
|
|
|
g_Game=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 Shutdown(int flags)
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
MICROLOG(L"Shutdown");
|
|
|
|
|
|
|
|
if (g_Game)
|
|
|
|
EndGame();
|
|
|
|
|
2006-10-08 06:56:30 +02:00
|
|
|
ShutdownPs(); // Must delete g_GUI before g_ScriptingHost
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
TIMER_BEGIN("shutdown Scheduler");
|
|
|
|
delete &g_Scheduler;
|
|
|
|
TIMER_END("shutdown Scheduler");
|
|
|
|
|
|
|
|
delete &g_JSGameEvents;
|
2006-09-02 23:20:25 +02:00
|
|
|
|
|
|
|
if (! (flags & INIT_NO_SIM))
|
|
|
|
{
|
|
|
|
TIMER_BEGIN("shutdown mouse stuff");
|
|
|
|
delete &g_Mouseover;
|
|
|
|
delete &g_Selection;
|
|
|
|
delete &g_BuildingPlacer;
|
|
|
|
TIMER_END("shutdown mouse stuff");
|
|
|
|
|
|
|
|
TIMER_BEGIN("shutdown game scripting stuff");
|
|
|
|
delete &g_GameAttributes;
|
2008-06-16 20:19:35 +02:00
|
|
|
SimulationShutdown();
|
2006-09-02 23:20:25 +02:00
|
|
|
TIMER_END("shutdown game scripting stuff");
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// destroy actor related stuff
|
|
|
|
TIMER_BEGIN("shutdown actor stuff");
|
|
|
|
delete &g_MaterialManager;
|
|
|
|
TIMER_END("shutdown actor stuff");
|
|
|
|
|
|
|
|
// destroy terrain related stuff
|
|
|
|
TIMER_BEGIN("shutdown TexMan");
|
|
|
|
delete &g_TexMan;
|
|
|
|
TIMER_END("shutdown TexMan");
|
|
|
|
|
|
|
|
// destroy renderer
|
|
|
|
TIMER_BEGIN("shutdown Renderer");
|
|
|
|
delete &g_Renderer;
|
|
|
|
g_VBMan.Shutdown();
|
|
|
|
TIMER_END("shutdown Renderer");
|
|
|
|
|
|
|
|
TIMER_BEGIN("shutdown ScriptingHost");
|
|
|
|
delete &g_ScriptingHost;
|
|
|
|
TIMER_END("shutdown ScriptingHost");
|
|
|
|
|
|
|
|
TIMER_BEGIN("shutdown ConfigDB");
|
|
|
|
delete &g_ConfigDB;
|
|
|
|
TIMER_END("shutdown ConfigDB");
|
|
|
|
|
|
|
|
// Shut down the network loop
|
|
|
|
TIMER_BEGIN("shutdown CSocketBase");
|
|
|
|
CSocketBase::Shutdown();
|
|
|
|
TIMER_END("shutdown CSocketBase");
|
|
|
|
|
2008-01-10 02:17:09 +01:00
|
|
|
TIMER_BEGIN("shutdown CNetLogManager");
|
|
|
|
CNetLogManager::Shutdown();
|
|
|
|
TIMER_END("shutdown CNetLogManager");
|
|
|
|
|
2006-04-24 01:14:18 +02:00
|
|
|
// Really shut down the i18n system. Any future calls
|
|
|
|
// to translate() will crash.
|
|
|
|
TIMER_BEGIN("shutdown I18N");
|
|
|
|
I18n::Shutdown();
|
|
|
|
TIMER_END("shutdown I18N");
|
|
|
|
|
|
|
|
// resource
|
|
|
|
// first shut down all resource owners, and then the handle manager.
|
|
|
|
TIMER_BEGIN("resource modules");
|
|
|
|
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();
|
|
|
|
|
|
|
|
TIMER_END("resource modules");
|
|
|
|
|
|
|
|
TIMER_BEGIN("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;
|
|
|
|
TIMER_END("shutdown misc");
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
//_CrtSetBreakAlloc(321);
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
debug_set_thread_name("main");
|
|
|
|
// add all debug_printf "tags" that we are interested in:
|
|
|
|
debug_filter_add("TIMER");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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;
|
2007-01-13 19:37:51 +01:00
|
|
|
hooks.bundle_logs = psBundleLogs;
|
|
|
|
hooks.get_log_dir = psGetLogDir;
|
2006-06-25 17:35:28 +02:00
|
|
|
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();
|
|
|
|
|
|
|
|
// preferred video mode = current desktop settings
|
|
|
|
// (command line params may override these)
|
|
|
|
gfx_get_video_mode(&g_xres, &g_yres, &g_bpp, &g_freq);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// setup_gui must be set after CONFIG_Init, so command-line parameters can disable it
|
2007-02-01 15:46:14 +01:00
|
|
|
const bool setup_gui = ((flags & INIT_NO_GUI) == 0 && g_AutostartMap.empty());
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
// GUI is notified in SetVideoMode, so this must come before that.
|
|
|
|
#ifndef NO_GUI
|
|
|
|
new CGUI;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool windowed = false;
|
|
|
|
CFG_GET_SYS_VAL("windowed", Bool, windowed);
|
|
|
|
|
|
|
|
if(setup_vmode)
|
|
|
|
{
|
|
|
|
MICROLOG(L"SetVideoMode");
|
|
|
|
if(SetVideoMode(g_xres, g_yres, 32, !windowed) < 0)
|
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Could not set %dx%d graphics mode: %s", g_xres, g_yres, SDL_GetError());
|
2006-04-24 01:14:18 +02:00
|
|
|
throw PSERROR_System_VmodeFailed();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// speed up startup by disabling all sound
|
|
|
|
// (OpenAL init will be skipped).
|
|
|
|
// must be called before first snd_open.
|
|
|
|
snd_disable(true);
|
|
|
|
}
|
|
|
|
|
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",
|
|
|
|
0);
|
2006-04-24 01:14:18 +02:00
|
|
|
if(missing)
|
|
|
|
{
|
|
|
|
wchar_t buf[500];
|
|
|
|
const wchar_t* fmt =
|
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."
|
|
|
|
L" If not or it doesn't look right, upgrade your graphics card.";
|
2006-04-24 01:14:18 +02:00
|
|
|
swprintf(buf, ARRAY_SIZE(buf), fmt, 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
|
|
|
|
|
|
|
|
MICROLOG(L"init ps");
|
|
|
|
InitPs(setup_gui);
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
InitRenderer();
|
|
|
|
|
2006-09-02 23:20:25 +02:00
|
|
|
if (! (flags & INIT_NO_SIM))
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
2008-06-16 20:19:35 +02:00
|
|
|
// This needs to be done after the renderer has loaded all its actors...
|
|
|
|
SimulationInit();
|
|
|
|
|
2006-09-02 23:20:25 +02:00
|
|
|
{
|
2008-06-16 20:19:35 +02:00
|
|
|
TIMER("Init_miscgamesection");
|
2006-09-02 23:20:25 +02:00
|
|
|
new CSelectedEntities;
|
|
|
|
new CMouseoverEntities;
|
|
|
|
new CBuildingPlacer;
|
|
|
|
new CGameAttributes;
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
2006-09-02 23:20:25 +02:00
|
|
|
// Register a few Game/Network JS globals
|
|
|
|
g_ScriptingHost.SetGlobal("g_GameAttributes", OBJECT_TO_JSVAL(g_GameAttributes.GetScript()));
|
|
|
|
}
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
InitInput();
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
ogl_WarnIfError();
|
2006-04-24 01:14:18 +02:00
|
|
|
|
|
|
|
#ifndef NO_GUI
|
|
|
|
{
|
|
|
|
TIMER("Init_guiload");
|
|
|
|
g_GUI.SendEventToAll("load");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (g_FixedFrameTiming) {
|
# 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
|
|
|
CCamera &camera = *g_Game->GetView()->GetCamera();
|
2006-04-24 01:14:18 +02:00
|
|
|
#if 0 // TOPDOWN
|
# 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
|
|
|
camera.SetProjection(1.0f,10000.0f,DEGTORAD(90));
|
|
|
|
camera.m_Orientation.SetIdentity();
|
|
|
|
camera.m_Orientation.RotateX(DEGTORAD(90));
|
|
|
|
camera.m_Orientation.Translate(CELL_SIZE*250*0.5, 250, CELL_SIZE*250*0.5);
|
2006-04-24 01:14:18 +02:00
|
|
|
#else // std view
|
# 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
|
|
|
camera.SetProjection(1.0f,10000.0f,DEGTORAD(20));
|
|
|
|
camera.m_Orientation.SetXRotation(DEGTORAD(30));
|
|
|
|
camera.m_Orientation.RotateY(DEGTORAD(-45));
|
|
|
|
camera.m_Orientation.Translate(350, 350, -275);
|
2006-04-24 01:14:18 +02:00
|
|
|
#endif
|
# 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
|
|
|
camera.UpdateFrustum();
|
2006-04-24 01:14:18 +02:00
|
|
|
}
|
|
|
|
|
2007-02-01 15:46:14 +01:00
|
|
|
if (! g_AutostartMap.empty())
|
2006-04-24 01:14:18 +02:00
|
|
|
{
|
|
|
|
// Code copied mostly from atlas/GameInterface/Handlers/Map.cpp -
|
|
|
|
// maybe should be refactored to avoid duplication
|
|
|
|
g_GameAttributes.m_MapFile = g_AutostartMap+".pmp";
|
|
|
|
for (int i=1; i<8; ++i)
|
|
|
|
g_GameAttributes.GetSlot(i)->AssignLocal();
|
|
|
|
g_Game = new CGame();
|
|
|
|
|
|
|
|
PSRETURN ret = g_Game->StartGame(&g_GameAttributes);
|
|
|
|
debug_assert(ret == PSRETURN_OK);
|
|
|
|
LDR_NonprogressiveLoad();
|
|
|
|
ret = g_Game->ReallyStartGame();
|
|
|
|
debug_assert(ret == PSRETURN_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|