2010-05-20 19:58:37 +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/>.
|
|
|
|
*/
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// This module defines the table of all functions callable from JS.
|
|
|
|
// it's required by the interpreter; we make use of the opportunity to
|
|
|
|
// document them all in one spot. we thus obviate having to dig through
|
|
|
|
// all the other headers. most of the functions are implemented here;
|
|
|
|
// as for the rest, we only link to their docs (duplication is bad).
|
|
|
|
|
2004-06-03 20:38:14 +02:00
|
|
|
#include "precompiled.h"
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
#include "ScriptGlue.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "JSConversions.h"
|
|
|
|
#include "GameEvents.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
|
2008-07-04 13:17:24 +02:00
|
|
|
#include "ScriptableComplex.inl"
|
|
|
|
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "graphics/GameView.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "graphics/LightEnv.h"
|
|
|
|
#include "graphics/MapWriter.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "graphics/Unit.h"
|
|
|
|
#include "graphics/UnitManager.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "graphics/scripting/JSInterface_Camera.h"
|
|
|
|
#include "graphics/scripting/JSInterface_LightEnv.h"
|
|
|
|
#include "lib/timer.h"
|
2009-02-28 17:42:46 +01:00
|
|
|
#include "lib/svn_revision.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/frequency_filter.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "maths/scripting/JSInterface_Vector3D.h"
|
2008-06-16 20:19:35 +02:00
|
|
|
#include "network/NetClient.h"
|
|
|
|
#include "network/NetServer.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "ps/CConsole.h"
|
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/CStr.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/Game.h"
|
2008-01-03 23:07:18 +01:00
|
|
|
#include "ps/Globals.h" // g_frequencyFilter
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "ps/GameSetup/GameSetup.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "ps/Hotkey.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "ps/Interact.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "ps/ProfileViewer.h"
|
2004-08-21 13:45:01 +02:00
|
|
|
#include "ps/i18n.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/scripting/JSCollection.h"
|
|
|
|
#include "ps/scripting/JSInterface_Console.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "ps/scripting/JSInterface_Selection.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/scripting/JSInterface_VFS.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "renderer/Renderer.h"
|
2006-05-16 06:41:37 +02:00
|
|
|
#include "renderer/SkyManager.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "renderer/WaterManager.h"
|
2010-01-09 20:20:14 +01:00
|
|
|
#include "scriptinterface/ScriptInterface.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "simulation/Entity.h"
|
|
|
|
#include "simulation/EntityFormation.h"
|
|
|
|
#include "simulation/EntityHandles.h"
|
|
|
|
#include "simulation/EntityManager.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 "simulation/EntityTemplate.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "simulation/EntityTemplateCollection.h"
|
2006-03-31 05:30:34 +02:00
|
|
|
#include "simulation/FormationManager.h"
|
2006-06-04 01:02:37 +02:00
|
|
|
#include "simulation/LOSManager.h"
|
|
|
|
#include "simulation/Scheduler.h"
|
|
|
|
#include "simulation/Simulation.h"
|
2007-02-10 04:09:52 +01:00
|
|
|
#include "simulation/TechnologyCollection.h"
|
|
|
|
#include "simulation/TriggerManager.h"
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
#define LOG_CATEGORY L"script"
|
2005-10-19 05:02:51 +02:00
|
|
|
extern bool g_TerrainModified;
|
2004-05-30 02:46:58 +02:00
|
|
|
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// rationale: the function table is now at the end of the source file to
|
|
|
|
// avoid the need for forward declarations for every function.
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// all normal function wrappers have the following signature:
|
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
|
|
|
// JSBool func(JSContext* cx, JSObject* globalObject, uintN argc, jsval* argv, jsval* rval);
|
2005-07-20 02:57:17 +02:00
|
|
|
// all property accessors have the following signature:
|
|
|
|
// JSBool accessor(JSContext* cx, JSObject* globalObject, jsval id, jsval* vp);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Output
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Write values to the log file.
|
|
|
|
// params: any number of any type.
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Each argument is converted to a string and then written to the log.
|
|
|
|
// - Output is in NORMAL style (see LOG).
|
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
|
|
|
JSBool WriteLog(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW logMessage;
|
2004-08-03 01:14:54 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
for (int i = 0; i < (int)argc; i++)
|
|
|
|
{
|
2004-08-03 01:14:54 +02:00
|
|
|
try
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW arg = g_ScriptingHost.ValueToUCString( argv[i] );
|
2004-08-03 01:14:54 +02:00
|
|
|
logMessage += arg;
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|
2004-08-03 01:14:54 +02:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
2004-05-30 02:46:58 +02:00
|
|
|
{
|
2004-08-03 01:14:54 +02:00
|
|
|
// Do nothing.
|
2004-05-30 02:46:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 10:32:19 +01:00
|
|
|
LOG(CLogger::Normal, LOG_CATEGORY, L"%ls", logMessage.c_str());
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2006-07-26 15:10:13 +02:00
|
|
|
*rval = JSVAL_TRUE;
|
2004-08-03 01:14:54 +02:00
|
|
|
return JS_TRUE;
|
2004-06-11 00:24:03 +02:00
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Entity
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-07-20 06:53:58 +02:00
|
|
|
// Retrieve the entity currently occupying the specified handle.
|
2005-07-20 02:57:17 +02:00
|
|
|
// params: handle [int]
|
|
|
|
// returns: entity
|
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
|
|
|
JSBool GetEntityByUnitID( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-06-11 00:24:03 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
|
2007-01-30 04:50:28 +01:00
|
|
|
int uid;
|
2004-06-11 00:24:03 +02:00
|
|
|
try
|
|
|
|
{
|
2007-01-30 04:50:28 +01:00
|
|
|
uid = ToPrimitive<int>( argv[0] );
|
2004-06-11 00:24:03 +02:00
|
|
|
}
|
2004-07-17 19:09:33 +02:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
2004-06-11 00:24:03 +02:00
|
|
|
{
|
2007-01-30 04:50:28 +01:00
|
|
|
JS_ReportError( cx, "Invalid parameter" );
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2007-01-30 04:50:28 +01:00
|
|
|
|
|
|
|
CUnit* unit = g_Game->GetWorld()->GetUnitManager().FindByID( uid );
|
|
|
|
if( !unit || !unit->GetEntity() )
|
2004-06-11 00:24:03 +02:00
|
|
|
{
|
2007-01-30 04:50:28 +01:00
|
|
|
*rval = JSVAL_NULL;
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2004-10-07 21:23:35 +02:00
|
|
|
|
2007-01-30 04:50:28 +01:00
|
|
|
*rval = OBJECT_TO_JSVAL( unit->GetEntity()->GetScript() );
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Look up an EntityTemplate by name.
|
|
|
|
// params: template name [wstring]
|
|
|
|
// returns: entity template object
|
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
|
|
|
JSBool GetEntityTemplate( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-06-11 00:24:03 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAM_RANGE(1, 2);
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
|
2004-08-03 01:14:54 +02:00
|
|
|
CStrW templateName;
|
2006-05-14 00:11:46 +02:00
|
|
|
CPlayer* player = 0;
|
|
|
|
|
2004-06-11 00:24:03 +02:00
|
|
|
try
|
|
|
|
{
|
2004-08-03 01:14:54 +02:00
|
|
|
templateName = g_ScriptingHost.ValueToUCString( argv[0] );
|
2006-05-14 00:11:46 +02:00
|
|
|
if( argc == 2 )
|
|
|
|
{
|
|
|
|
player = ToNative<CPlayer>( argv[1] );
|
|
|
|
}
|
2004-06-11 00:24:03 +02:00
|
|
|
}
|
2004-07-17 19:09:33 +02:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
2004-06-11 00:24:03 +02:00
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Invalid template identifier" );
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2006-05-14 00:11:46 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
CEntityTemplate* v = g_EntityTemplateCollection.GetTemplate( templateName, player );
|
2004-06-11 00:24:03 +02:00
|
|
|
if( !v )
|
|
|
|
{
|
2009-11-06 11:59:10 +01:00
|
|
|
JS_ReportError( cx, "No such template: %s", CStr(templateName).c_str() );
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2004-10-07 21:23:35 +02:00
|
|
|
*rval = OBJECT_TO_JSVAL( v->GetScript() );
|
2004-06-11 00:24:03 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2007-01-17 00:22:25 +01: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
|
|
|
JSBool GetPlayerUnitCount( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2007-01-17 00:22:25 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS(2);
|
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 size_t playerNum = ToPrimitive<size_t>( argv[0] );
|
|
|
|
const CStrW unitName = ToPrimitive<CStrW>( argv[1] );
|
2007-01-17 00:22:25 +01: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
|
|
|
const int unitCount = g_EntityManager.GetPlayerUnitCount(playerNum, unitName);
|
2007-04-27 05:05:26 +02:00
|
|
|
*rval = ToJSVal( unitCount );
|
2007-01-17 00:22:25 +01:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// Get the state of a given hotkey (from the hotkeys file)
|
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
|
|
|
JSBool isOrderQueued( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2007-05-02 14:07:08 +02:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
|
|
|
|
*rval = ToJSVal(hotkeys[HOTKEY_ORDER_QUEUE]);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// formations
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
JSBool CreateEntityFormation( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-04-09 00:34:54 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(2);
|
2006-04-09 00:34:54 +02:00
|
|
|
|
|
|
|
CEntityList entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));
|
|
|
|
CStrW name = ToPrimitive<CStrW>( argv[1] );
|
|
|
|
g_FormationManager.CreateFormation( entities, name );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return JS_TRUE;
|
|
|
|
|
|
|
|
}
|
2007-05-02 14:07:08 +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
|
|
|
JSBool RemoveFromFormation( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-04-09 00:34:54 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2006-04-09 00:34:54 +02:00
|
|
|
|
|
|
|
CEntityList entities;
|
2010-03-19 20:54:00 +01:00
|
|
|
if (JS_InstanceOf(cx, JSVAL_TO_OBJECT(argv[0]), &CEntity::JSI_class, NULL))
|
2006-04-09 00:34:54 +02:00
|
|
|
entities.push_back( (ToNative<CEntity>(argv[0])) ->me);
|
|
|
|
else
|
|
|
|
entities = *EntityCollection::RetrieveSet(cx, JSVAL_TO_OBJECT(argv[0]));
|
|
|
|
|
|
|
|
*rval = g_FormationManager.RemoveUnitList(entities) ? JS_TRUE : JS_FALSE;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2007-05-02 14:07:08 +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
|
|
|
JSBool LockEntityFormation( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-04-09 00:34:54 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2006-04-09 00:34:54 +02:00
|
|
|
|
|
|
|
CEntity* entity = ToNative<CEntity>( argv[0] );
|
|
|
|
entity->GetFormation()->SetLock( ToPrimitive<bool>( argv[1] ) );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2007-05-02 14:07:08 +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
|
|
|
JSBool IsFormationLocked( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-04-09 00:34:54 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2006-04-09 00:34:54 +02:00
|
|
|
|
|
|
|
CEntity* entity = ToNative<CEntity>( argv[0] );
|
|
|
|
*rval = entity->GetFormation()->IsLocked() ? JS_TRUE : JS_FALSE;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2006-08-25 06:24:06 +02:00
|
|
|
|
|
|
|
|
2006-06-06 08:31:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Techs
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
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
|
|
|
JSBool GetTechnology( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2006-06-06 08:31:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(2);
|
2006-06-06 08:31:17 +02:00
|
|
|
|
2006-07-18 06:17:46 +02:00
|
|
|
CStrW name;
|
|
|
|
CPlayer* player;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
name = g_ScriptingHost.ValueToUCString( argv[0] );
|
|
|
|
player = ToNative<CPlayer>( argv[1] );
|
|
|
|
}
|
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_ReportError( cx, "Invalid parameters for GetTechnology (expected name and player)" );
|
2006-07-18 06:17:46 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-06-07 03:04:41 +02:00
|
|
|
*rval = JSVAL_NULL;
|
2006-06-06 08:31:17 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
CTechnology* tech = g_TechnologyCollection.GetTechnology( name, player );
|
2006-06-10 01:07:11 +02:00
|
|
|
if ( tech )
|
|
|
|
*rval = ToJSVal( tech );
|
2006-06-06 08:31:17 +02:00
|
|
|
else
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Console->InsertMessage( L"Warning: Invalid tech template name \"%ls\" passed for GetTechnology()", name.c_str() );
|
2006-06-06 08:31:17 +02:00
|
|
|
|
2006-06-10 05:05:16 +02:00
|
|
|
return JS_TRUE;
|
2006-06-06 08:31:17 +02:00
|
|
|
}
|
2005-07-20 06:53:58 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Events
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-01-18 01:46:18 +01:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Register a global handler for the specified DOM event.
|
|
|
|
// params: event type name [wstring], handler [fragment or function]
|
|
|
|
// returns: whether it was actually newly registered [bool]
|
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
|
|
|
JSBool AddGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2005-03-29 00:13:47 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(2);
|
2005-03-30 18:14:19 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = BOOLEAN_TO_JSVAL( g_JSGameEvents.AddHandlerJS( cx, argc, argv ) );
|
2005-03-29 00:13:47 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-05-18 07:32:09 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Remove a previously registered global handler for the specified DOM event.
|
|
|
|
// params: event type name [wstring], handler [fragment or function]
|
|
|
|
// returns: whether it was successfully removed [bool]
|
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
|
|
|
JSBool RemoveGlobalHandler( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2005-04-22 09:12:55 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(2);
|
2005-04-22 09:12:55 +02:00
|
|
|
|
|
|
|
*rval = BOOLEAN_TO_JSVAL( g_JSGameEvents.RemoveHandlerJS( cx, argc, argv ) );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-03-29 00:13:47 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Timer
|
|
|
|
//-----------------------------------------------------------------------------
|
2005-03-29 00:13:47 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Request a callback be executed after the specified delay.
|
|
|
|
// params: callback [fragment or function], delay in milliseconds [int]
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Scripts and functions registered this way are called on the first
|
|
|
|
// simulation frame after the specified period has elapsed. If this causes
|
|
|
|
// multiple segments of code to be executed in the same frame,
|
|
|
|
// relative timing is maintained. Delays of 0 milliseconds cause code to be
|
|
|
|
// executed on the following simulation frame. If more than one script or
|
|
|
|
// function is scheduled to execute in the same millisecond, the order of
|
|
|
|
// execution is undefined. Code is scheduled in simulation time, and is
|
|
|
|
// therefore suspended while the game is paused or frozen. Granularity of
|
|
|
|
// timing is also limited to 1/(Simulation frame rate); currently 100ms.
|
|
|
|
// The called function or script executes in the same scope as the
|
2007-05-02 14:07:08 +02:00
|
|
|
// code that called SetTimeout (amongst other things, the
|
2005-07-20 02:57:17 +02:00
|
|
|
// 'this' reference is usually maintained)
|
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
|
|
|
JSBool SetTimeout( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAM_RANGE(2, 3);
|
2005-07-20 02:57:17 +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 delay;
|
2004-07-20 21:30:35 +02:00
|
|
|
try
|
|
|
|
{
|
2005-08-09 18:02:15 +02:00
|
|
|
delay = ToPrimitive<int>( argv[1] );
|
2004-07-20 21:30:35 +02:00
|
|
|
}
|
2005-07-20 02:57:17 +02:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Invalid timer parameters" );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-12-18 08:33:16 +01:00
|
|
|
JSObject* scope;
|
|
|
|
if( argc == 3 )
|
|
|
|
{
|
|
|
|
if( !JSVAL_IS_OBJECT( argv[2] ) )
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid timer parameters" );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
scope = JSVAL_TO_OBJECT( argv[2] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scope = JS_GetScopeChain( cx );
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
switch( JS_TypeOfValue( cx, argv[0] ) )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
|
|
|
case JSTYPE_STRING:
|
|
|
|
{
|
2004-09-03 16:08:12 +02:00
|
|
|
CStrW fragment = g_ScriptingHost.ValueToUCString( argv[0] );
|
2007-05-02 14:07:08 +02:00
|
|
|
int id = g_Scheduler.PushTime( delay, fragment, scope );
|
2005-12-18 08:33:16 +01:00
|
|
|
*rval = INT_TO_JSVAL( id );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
case JSTYPE_FUNCTION:
|
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JSFunction* fn = JS_ValueToFunction( cx, argv[0] );
|
2007-05-02 14:07:08 +02:00
|
|
|
int id = g_Scheduler.PushTime( delay, fn, scope );
|
2005-12-18 08:33:16 +01:00
|
|
|
*rval = INT_TO_JSVAL( id );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
default:
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Invalid timer script" );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Request a callback be executed periodically.
|
|
|
|
// params: callback [fragment or function], initial delay in ms [int], period in ms [int]
|
|
|
|
// OR callback [fragment or function], period in ms [int] (initial delay = period)
|
|
|
|
// returns:
|
|
|
|
// notes:
|
2007-05-02 14:07:08 +02:00
|
|
|
// - SetTimeout's notes apply here as well.
|
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
|
|
|
JSBool SetInterval( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAM_RANGE(2, 3);
|
2005-07-20 02:57:17 +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 first, interval;
|
2004-07-20 21:30:35 +02:00
|
|
|
try
|
|
|
|
{
|
2005-08-09 18:02:15 +02:00
|
|
|
first = ToPrimitive<int>( argv[1] );
|
2004-07-20 21:30:35 +02:00
|
|
|
if( argc == 3 )
|
|
|
|
{
|
|
|
|
// toDo, first, interval
|
2005-08-09 18:02:15 +02:00
|
|
|
interval = ToPrimitive<int>( argv[2] );
|
2004-07-20 21:30:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// toDo, interval (first = interval)
|
|
|
|
interval = first;
|
|
|
|
}
|
|
|
|
}
|
2005-07-20 02:57:17 +02:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Invalid timer parameters" );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
switch( JS_TypeOfValue( cx, argv[0] ) )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
|
|
|
case JSTYPE_STRING:
|
|
|
|
{
|
2004-09-03 16:08:12 +02:00
|
|
|
CStrW fragment = g_ScriptingHost.ValueToUCString( argv[0] );
|
2007-05-02 14:07:08 +02:00
|
|
|
int id = g_Scheduler.PushInterval( first, interval, fragment, JS_GetScopeChain( cx ) );
|
2005-12-18 08:33:16 +01:00
|
|
|
*rval = INT_TO_JSVAL( id );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
case JSTYPE_FUNCTION:
|
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JSFunction* fn = JS_ValueToFunction( cx, argv[0] );
|
2007-05-02 14:07:08 +02:00
|
|
|
int id = g_Scheduler.PushInterval( first, interval, fn, JS_GetScopeChain( cx ) );
|
2005-12-18 08:33:16 +01:00
|
|
|
*rval = INT_TO_JSVAL( id );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
default:
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Invalid timer script" );
|
2004-07-20 21:30:35 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// Cause all periodic functions registered via SetInterval to
|
2005-07-20 02:57:17 +02:00
|
|
|
// no longer be called.
|
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Execution continues until the end of the triggered function or
|
|
|
|
// script fragment, but is not triggered again.
|
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
|
|
|
JSBool CancelInterval( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-07-20 21:30:35 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2004-07-20 21:30:35 +02:00
|
|
|
g_Scheduler.m_abortInterval = true;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
// Cause the scheduled task (timeout or interval) with the given ID to
|
2005-12-18 08:33:16 +01:00
|
|
|
// no longer be called.
|
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Execution continues until the end of the triggered function or
|
|
|
|
// script fragment, but is not triggered again.
|
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
|
|
|
JSBool CancelTimer( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-12-18 08:33:16 +01:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2005-12-18 08:33:16 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int id = ToPrimitive<int>( argv[0] );
|
2007-05-02 14:07:08 +02:00
|
|
|
g_Scheduler.CancelTask( id );
|
2005-12-18 08:33:16 +01:00
|
|
|
}
|
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid ID parameter" );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2006-07-30 02:24:04 +02:00
|
|
|
|
2006-06-06 08:31:17 +02:00
|
|
|
//Set the simulation rate scalar-time becomes time * SimRate.
|
|
|
|
//Params: rate [float] : sets SimRate
|
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
|
|
|
JSBool SetSimRate(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2006-06-06 08:31:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2006-06-06 08:31:17 +02:00
|
|
|
|
|
|
|
g_Game->SetSimRate( ToPrimitive<float>(argv[0]) );
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2005-12-18 08:33:16 +01:00
|
|
|
|
2006-07-30 02:24:04 +02:00
|
|
|
//Generate a random float in [0, 1) using the simulation's random generator
|
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
|
|
|
JSBool SimRand(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2006-07-30 02:24:04 +02:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
|
|
|
|
*rval = ToJSVal( g_Game->GetSimulation()->RandFloat() );
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Generate a random float int between 0 and the given number - 1 using the simulation's RNG
|
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
|
|
|
JSBool SimRandInt(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2006-07-30 02:24:04 +02:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2007-05-02 14:07:08 +02:00
|
|
|
JSU_ASSERT(JSVAL_IS_INT(argv[0]), "SimRandInt(): first parameter must be an int");
|
2006-07-30 02:24:04 +02:00
|
|
|
|
|
|
|
*rval = ToJSVal( g_Game->GetSimulation()->RandInt(ToPrimitive<int>(argv[0])) );
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// Script profiling functions: Begin timing a piece of code with StartJsTimer(num)
|
|
|
|
// and stop timing with StopJsTimer(num). The results will be printed to stdout
|
2006-07-30 02:24:04 +02:00
|
|
|
// when the game exits.
|
2005-12-18 08:33:16 +01: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 size_t MAX_JS_TIMERS = 20;
|
2007-05-02 14:07:08 +02:00
|
|
|
static TimerUnit js_start_times[MAX_JS_TIMERS];
|
|
|
|
static TimerUnit js_timer_overhead;
|
|
|
|
static TimerClient js_timer_clients[MAX_JS_TIMERS];
|
2009-11-03 22:46:35 +01:00
|
|
|
static wchar_t js_timer_descriptions_buf[MAX_JS_TIMERS * 12]; // depends on MAX_JS_TIMERS and format string below
|
2006-07-13 22:09:20 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
static void InitJsTimers()
|
2006-07-13 22:09:20 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
wchar_t* pos = js_timer_descriptions_buf;
|
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
|
|
|
for(size_t i = 0; i < MAX_JS_TIMERS; i++)
|
2006-07-13 22:09:20 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
const wchar_t* description = pos;
|
2009-11-03 23:27:25 +01:00
|
|
|
pos += swprintf_s(pos, 12, L"js_timer %d", (int)i)+1;
|
2008-01-07 21:03:19 +01:00
|
|
|
timer_AddClient(&js_timer_clients[i], description);
|
2006-07-13 22:09:20 +02:00
|
|
|
}
|
2006-07-13 23:04:06 +02:00
|
|
|
|
2006-07-14 16:00:00 +02:00
|
|
|
// call several times to get a good approximation of 'hot' performance.
|
|
|
|
// note: don't use a separate timer slot to warm up and then judge
|
|
|
|
// overhead from another: that causes worse results (probably some
|
|
|
|
// caching effects inside JS, but I don't entirely understand why).
|
2006-07-13 23:04:06 +02:00
|
|
|
static const char* calibration_script =
|
2006-07-14 16:00:00 +02:00
|
|
|
"startXTimer(0);\n"
|
|
|
|
"stopXTimer (0);\n"
|
2006-07-13 23:04:06 +02:00
|
|
|
"\n";
|
|
|
|
g_ScriptingHost.RunMemScript(calibration_script, strlen(calibration_script));
|
2008-01-07 21:03:19 +01:00
|
|
|
// slight hack: call RunMemScript twice because we can't average several
|
|
|
|
// TimerUnit values because there's no operator/. this way is better anyway
|
|
|
|
// because it hopefully avoids the one-time JS init overhead.
|
|
|
|
g_ScriptingHost.RunMemScript(calibration_script, strlen(calibration_script));
|
|
|
|
js_timer_overhead = js_timer_clients[0].sum;
|
|
|
|
js_timer_clients[0].sum.SetToZero();
|
2006-07-13 22:09: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
|
|
|
JSBool StartJsTimer(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2006-07-13 22:09:20 +02:00
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
ONCE(InitJsTimers());
|
2006-07-13 22:09:20 +02:00
|
|
|
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(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
|
|
|
size_t slot = ToPrimitive<size_t>(argv[0]);
|
2007-05-02 14:07:08 +02:00
|
|
|
if (slot >= MAX_JS_TIMERS)
|
2006-11-07 22:03:13 +01:00
|
|
|
return JS_FALSE;
|
2006-07-13 22:09:20 +02:00
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
js_start_times[slot].SetFromTimer();
|
2006-11-07 22:03:13 +01:00
|
|
|
return JS_TRUE;
|
2006-07-13 22:09: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
|
|
|
JSBool StopJsTimer(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2006-07-13 22:09:20 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(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
|
|
|
size_t slot = ToPrimitive<size_t>(argv[0]);
|
2007-05-02 14:07:08 +02:00
|
|
|
if (slot >= MAX_JS_TIMERS)
|
2006-11-07 22:03:13 +01:00
|
|
|
return JS_FALSE;
|
2006-07-13 22:09:20 +02:00
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
TimerUnit now;
|
|
|
|
now.SetFromTimer();
|
|
|
|
now.Subtract(js_timer_overhead);
|
|
|
|
timer_BillClient(&js_timer_clients[slot], js_start_times[slot], now);
|
|
|
|
js_start_times[slot].SetToZero();
|
2006-11-07 22:03:13 +01:00
|
|
|
return JS_TRUE;
|
2006-07-13 22:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Game Setup
|
|
|
|
//-----------------------------------------------------------------------------
|
2004-10-07 21:23:35 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Create a new network server object.
|
|
|
|
// params:
|
|
|
|
// returns: net server object
|
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
|
|
|
JSBool CreateServer(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-07-11 18:22:35 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2004-07-11 18:22:35 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
if( !g_Game )
|
|
|
|
g_Game = new CGame();
|
|
|
|
if( !g_NetServer )
|
|
|
|
g_NetServer = new CNetServer(g_Game, &g_GameAttributes);
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = OBJECT_TO_JSVAL(g_NetServer->GetScript());
|
2004-07-07 20:27:25 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2004-07-09 14:44:12 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Create a new network client object.
|
|
|
|
// params:
|
|
|
|
// returns: net client object
|
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
|
|
|
JSBool CreateClient(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-08-05 15:07:51 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2004-08-16 17:19:17 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
if( !g_Game )
|
|
|
|
g_Game = new CGame();
|
|
|
|
if( !g_NetClient )
|
|
|
|
g_NetClient = new CNetClient(g_Game, &g_GameAttributes);
|
2004-08-16 17:19:17 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = OBJECT_TO_JSVAL(g_NetClient->GetScript());
|
|
|
|
return( JS_TRUE );
|
2005-01-17 05:52:02 +01:00
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Begin the process of starting a game.
|
|
|
|
// params:
|
|
|
|
// returns: success [bool]
|
|
|
|
// notes:
|
|
|
|
// - Performs necessary initialization while calling back into the
|
|
|
|
// main loop, so the game remains responsive to display+user input.
|
|
|
|
// - When complete, the engine calls the reallyStartGame JS function.
|
2007-05-02 14:07:08 +02:00
|
|
|
// TODO: Replace StartGame with Create(Game|Server|Client)/game.start() -
|
2005-07-20 02:57:17 +02:00
|
|
|
// after merging CGame and CGameAttributes
|
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
|
|
|
JSBool StartGame(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-08-16 17:19:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-02-02 18:03:37 +01:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = BOOLEAN_TO_JSVAL(JS_TRUE);
|
2005-02-02 18:03:37 +01:00
|
|
|
|
2005-01-17 05:52:02 +01:00
|
|
|
// Hosted MP Game
|
2007-06-04 09:41:05 +02:00
|
|
|
if (g_NetServer)
|
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = BOOLEAN_TO_JSVAL(g_NetServer->StartGame() == 0);
|
2007-06-04 09:41:05 +02:00
|
|
|
}
|
|
|
|
// Joined MP Game
|
2005-01-17 05:52:02 +01:00
|
|
|
else if (g_NetClient)
|
2004-09-21 18:10:46 +02:00
|
|
|
{
|
2007-06-04 09:41:05 +02:00
|
|
|
*rval = BOOLEAN_TO_JSVAL(g_NetClient->StartGame() == 0);
|
2004-09-21 18:10:46 +02:00
|
|
|
}
|
2005-01-17 05:52:02 +01:00
|
|
|
// Start an SP Game Session
|
2004-09-21 18:10:46 +02:00
|
|
|
else if (!g_Game)
|
2004-08-16 17:19:17 +02:00
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
g_Game = new CGame();
|
2005-01-15 18:20:51 +01:00
|
|
|
PSRETURN ret = g_Game->StartGame(&g_GameAttributes);
|
|
|
|
if (ret != PSRETURN_OK)
|
|
|
|
{
|
|
|
|
// Failed to start the game - destroy it, and return false
|
|
|
|
|
|
|
|
delete g_Game;
|
|
|
|
g_Game = NULL;
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
|
|
|
|
return( JS_TRUE );
|
2005-01-15 18:20:51 +01:00
|
|
|
}
|
2004-08-05 15:07:51 +02:00
|
|
|
}
|
2007-06-04 09:41:05 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*rval = BOOLEAN_TO_JSVAL(JS_FALSE);
|
|
|
|
}
|
2005-01-15 18:20:51 +01:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
return( JS_TRUE );
|
2004-08-05 15:07:51 +02:00
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Immediately ends the current game (if any).
|
|
|
|
// params:
|
|
|
|
// returns:
|
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
|
|
|
JSBool EndGame(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-08-05 15:07:51 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2004-08-05 15:07:51 +02:00
|
|
|
EndGame();
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2004-07-31 14:45:30 +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
|
|
|
JSBool GetGameMode(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2007-04-27 05:05:26 +02:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
|
|
|
|
*rval = ToJSVal( g_GameAttributes.GetGameMode() );
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2004-08-21 13:45:01 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Internationalization
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-07-20 06:53:58 +02:00
|
|
|
// these remain here instead of in the i18n tree because they are
|
|
|
|
// really related to the engine's use of them, as opposed to i18n itself.
|
|
|
|
// contrariwise, translate() cannot be moved here because that would
|
|
|
|
// make i18n dependent on this code and therefore harder to reuse.
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Replaces the current language (locale) with a new one.
|
|
|
|
// params: language id [string] as in I18n::LoadLanguage
|
|
|
|
// returns:
|
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
|
|
|
JSBool LoadLanguage(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-08-21 13:45:01 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2004-08-21 13:45:01 +02:00
|
|
|
CStr lang = g_ScriptingHost.ValueToString(argv[0]);
|
|
|
|
I18n::LoadLanguage(lang);
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Return identifier of the current language (locale) in use.
|
|
|
|
// params:
|
|
|
|
// returns: language id [string] as in I18n::LoadLanguage
|
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
|
|
|
JSBool GetLanguageID(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-09-05 13:28:59 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
|
2004-09-05 13:28:59 +02:00
|
|
|
JSString* s = JS_NewStringCopyZ(cx, I18n::CurrentLanguageName());
|
|
|
|
if (!s)
|
|
|
|
{
|
|
|
|
JS_ReportError(cx, "Error creating string");
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
*rval = STRING_TO_JSVAL(s);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Debug
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
// Deliberately cause the game to crash.
|
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - currently implemented via access violation (read of address 0)
|
|
|
|
// - useful for testing the crashlog/stack trace code.
|
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
|
|
|
JSBool ProvokeCrash(JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval)
|
2004-09-05 13:28:59 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
MICROLOG(L"Crashing at user's request.");
|
|
|
|
return *(JSBool*)0;
|
2004-09-05 13:28:59 +02:00
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// Force a JS garbage collection cycle to take place immediately.
|
2005-07-20 02:57:17 +02:00
|
|
|
// params:
|
|
|
|
// returns: true [bool]
|
|
|
|
// notes:
|
|
|
|
// - writes an indication of how long this took to the console.
|
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
|
|
|
JSBool ForceGarbageCollection(JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval)
|
2004-08-30 13:20:59 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2008-01-07 21:03:19 +01:00
|
|
|
double time = timer_Time();
|
2006-06-04 01:02:37 +02:00
|
|
|
JS_GC(cx);
|
2008-01-07 21:03:19 +01:00
|
|
|
time = timer_Time() - time;
|
2006-06-04 01:02:37 +02:00
|
|
|
g_Console->InsertMessage(L"Garbage collection completed in: %f", time);
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = JSVAL_TRUE;
|
2006-06-04 01:02:37 +02:00
|
|
|
return JS_TRUE ;
|
2004-08-30 13:20:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-21 13:45:01 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Misc. Engine Interface
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Return the global frames-per-second value.
|
|
|
|
// params:
|
|
|
|
// returns: FPS [int]
|
|
|
|
// notes:
|
|
|
|
// - This value is recalculated once a frame. We take special care to
|
|
|
|
// filter it, so it is both accurate and free of jitter.
|
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
|
|
|
JSBool GetFps( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2007-12-20 21:21:45 +01:00
|
|
|
*rval = INT_TO_JSVAL(g_frequencyFilter->StableFrequency());
|
2004-07-09 14:44:12 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2004-07-15 21:29:56 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Cause the game to exit gracefully.
|
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Exit happens after the current main loop iteration ends
|
|
|
|
// (since this only sets a flag telling it to end)
|
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
|
|
|
JSBool ExitProgram( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-07-15 21:29:56 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
kill_mainloop();
|
|
|
|
return JS_TRUE;
|
2004-07-15 21:29:56 +02:00
|
|
|
}
|
2004-08-14 13:21:29 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2007-12-29 17:22:23 +01:00
|
|
|
// Write an indication of total video RAM to console.
|
2005-07-20 02:57:17 +02:00
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
2007-12-29 17:22:23 +01:00
|
|
|
// - May not be supported on all platforms.
|
2005-07-20 02:57:17 +02:00
|
|
|
// - Only a rough approximation; do not base low-level decisions
|
|
|
|
// ("should I allocate one more texture?") on this.
|
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
|
|
|
JSBool WriteVideoMemToConsole( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2004-08-14 13:21:29 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2008-01-08 01:09:52 +01:00
|
|
|
const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo();
|
2007-12-29 17:22:23 +01:00
|
|
|
g_Console->InsertMessage(L"VRAM: total %d", videoInfo->video_mem);
|
2004-08-14 13:21:29 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2005-03-29 22:50:04 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Change the mouse cursor.
|
|
|
|
// params: cursor name [string] (i.e. basename of definition file and texture)
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Cursors are stored in "art\textures\cursors"
|
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
|
|
|
JSBool SetCursor( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2009-11-03 22:46:35 +01:00
|
|
|
g_CursorName = g_ScriptingHost.ValueToUCString(argv[0]);
|
2005-07-20 02:57:17 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2007-05-02 14:07:08 +02:00
|
|
|
|
2008-07-04 13:17:24 +02:00
|
|
|
JSBool GetCursorName( JSContext* UNUSED(cx), JSObject*, uintN UNUSED(argc), jsval* UNUSED(argv), jsval* rval )
|
2006-06-22 00:37:31 +02:00
|
|
|
{
|
|
|
|
*rval = ToJSVal(g_CursorName);
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Trigger a rewrite of all maps.
|
|
|
|
// params:
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - Usefulness is unclear. If you need it, consider renaming this and updating the docs.
|
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
|
|
|
JSBool _RewriteMaps( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-03-29 22:50:04 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2005-08-15 01:34:37 +02:00
|
|
|
g_Game->GetWorld()->RewriteMap();
|
2005-03-29 22:50:04 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2005-05-18 07:32:09 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Change the LOD bias.
|
|
|
|
// params: LOD bias [float]
|
|
|
|
// returns:
|
|
|
|
// notes:
|
|
|
|
// - value is as required by GL_TEXTURE_LOD_BIAS.
|
|
|
|
// - useful for adjusting image "sharpness" (since it affects which mipmap level is chosen)
|
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
|
|
|
JSBool _LodBias( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-05-20 19:09:47 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
g_Renderer.SetOptionFloat(CRenderer::OPT_LODBIAS, ToPrimitive<float>(argv[0]));
|
2005-05-20 19:09:47 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2005-07-20 06:53:58 +02:00
|
|
|
// Focus the game camera on a given position.
|
2005-07-20 02:57:17 +02:00
|
|
|
// params: target position vector [CVector3D]
|
|
|
|
// returns: success [bool]
|
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
|
|
|
JSBool SetCameraTarget( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2005-05-18 07:32:09 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(1);
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
CVector3D* target = ToNative<CVector3D>( argv[0] );
|
|
|
|
if(!target)
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid camera target" );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
g_Game->GetView()->SetCameraTarget( *target );
|
|
|
|
|
|
|
|
*rval = JSVAL_TRUE;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Miscellany
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Return the date/time at which the current executable was compiled.
|
2009-02-28 17:42:46 +01:00
|
|
|
// params: none (-> "date time (svn revision)") OR an integer specifying
|
|
|
|
// what to display: 0 for date, 1 for time, 2 for svn revision
|
|
|
|
// returns: string with the requested timestamp info
|
2005-07-20 02:57:17 +02:00
|
|
|
// notes:
|
|
|
|
// - Displayed on main menu screen; tells non-programmers which auto-build
|
|
|
|
// they are running. Could also be determined via .EXE file properties,
|
|
|
|
// but that's a bit more trouble.
|
|
|
|
// - To be exact, the date/time returned is when scriptglue.cpp was
|
2009-02-28 17:42:46 +01:00
|
|
|
// last compiled, but the auto-build does full rebuilds.
|
|
|
|
// - svn revision is generated by calling svnversion and cached in
|
|
|
|
// lib/svn_revision.cpp. it is useful to know when attempting to
|
|
|
|
// reproduce bugs (the main EXE and PDB should be temporarily reverted to
|
|
|
|
// that revision so that they match user-submitted crashdumps).
|
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
|
|
|
JSBool GetBuildTimestamp( JSContext* cx, JSObject*, uintN argc, jsval* argv, jsval* rval )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2009-08-02 21:52:31 +02:00
|
|
|
JSU_REQUIRE_MAX_PARAMS(1);
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2009-02-28 17:42:46 +01:00
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
// see function documentation
|
|
|
|
const int mode = argc? JSVAL_TO_INT(argv[0]) : -1;
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case -1:
|
2009-11-06 11:59:10 +01:00
|
|
|
sprintf_s(buf, ARRAY_SIZE(buf), "%s %s (%ls)", __DATE__, __TIME__, svn_revision);
|
2009-02-28 17:42:46 +01:00
|
|
|
break;
|
|
|
|
case 0:
|
2009-11-06 11:59:10 +01:00
|
|
|
sprintf_s(buf, ARRAY_SIZE(buf), "%s", __DATE__);
|
2009-02-28 17:42:46 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2009-11-06 11:59:10 +01:00
|
|
|
sprintf_s(buf, ARRAY_SIZE(buf), "%s", __TIME__);
|
2009-02-28 17:42:46 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2009-08-14 20:42:39 +02:00
|
|
|
sprintf_s(buf, ARRAY_SIZE(buf), "%ls", svn_revision);
|
2009-02-28 17:42:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
|
2005-07-20 02:57:17 +02:00
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Return distance between 2 points.
|
|
|
|
// params: 2 position vectors [CVector3D]
|
|
|
|
// returns: Euclidean distance [float]
|
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
|
|
|
JSBool ComputeDistanceBetweenTwoPoints( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsval* argv, jsval* rval )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS(2);
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
CVector3D* a = ToNative<CVector3D>( argv[0] );
|
|
|
|
CVector3D* b = ToNative<CVector3D>( argv[1] );
|
2007-05-02 14:07:08 +02:00
|
|
|
float dist = ( *a - *b ).Length();
|
2005-07-20 02:57:17 +02:00
|
|
|
*rval = ToJSVal( dist );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-20 06:53:58 +02:00
|
|
|
// Returns the global object.
|
|
|
|
// params:
|
|
|
|
// returns: global object
|
|
|
|
// notes:
|
|
|
|
// - Useful for accessing an object from another scope.
|
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
|
|
|
JSBool GetGlobal( JSContext* cx, JSObject* globalObject, uintN argc, jsval* argv, jsval* rval )
|
2005-07-20 06:53:58 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2005-07-20 06:53:58 +02:00
|
|
|
|
|
|
|
*rval = OBJECT_TO_JSVAL( globalObject );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2007-02-10 04:09:52 +01:00
|
|
|
// Saves the current profiling data to the logs/profile.txt file
|
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
|
|
|
JSBool SaveProfileData( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2007-02-10 04:09:52 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
g_ProfileViewer.SaveToFile();
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
// Activates the building placement cursor for placing a building. The currently selected units
|
|
|
|
// are then ordered to construct the building if it is placed.
|
2005-09-05 21:48:28 +02:00
|
|
|
// params: templateName - the name of the entity to place.
|
|
|
|
// returns: true if cursor was activated, false if cursor was already active.
|
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
|
|
|
JSBool StartPlacing( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-05 21:48:28 +02:00
|
|
|
{
|
|
|
|
CStrW name;
|
|
|
|
if(argc == 0) {
|
|
|
|
name = L"hele_ho"; // save some typing during testing
|
|
|
|
}
|
|
|
|
else {
|
2005-12-15 22:59:48 +01:00
|
|
|
if(!ToPrimitive<CStrW>( g_ScriptingHost.GetContext(), argv[0], name ))
|
2005-09-05 21:48:28 +02:00
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid template name argument" );
|
2005-09-18 05:47:15 +02:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
return( JS_FALSE );
|
2005-09-05 21:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
*rval = g_BuildingPlacer.Activate(name) ? JS_TRUE : JS_FALSE;
|
2005-09-05 21:48:28 +02:00
|
|
|
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
// Toggles drawing the sky
|
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
|
|
|
JSBool ToggleSky( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-05-16 06:41:37 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2006-05-16 06:41:37 +02:00
|
|
|
g_Renderer.GetSkyManager()->m_RenderSky = !g_Renderer.GetSkyManager()->m_RenderSky;
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-12-05 03:08:52 +01:00
|
|
|
// Toggles drawing territory outlines
|
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
|
|
|
JSBool ToggleTerritoryRendering( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-12-05 03:08:52 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
g_Renderer.m_RenderTerritories = !g_Renderer.m_RenderTerritories;
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// water
|
|
|
|
|
2005-09-18 05:47:15 +02:00
|
|
|
// Toggles drawing the water plane
|
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
|
|
|
JSBool ToggleWater( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 05:47:15 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_RenderWater = !g_Renderer.GetWaterManager()->m_RenderWater;
|
2005-09-18 05:47:15 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the water plane height
|
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
|
|
|
JSBool SetWaterHeight( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 05:47:15 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 1 );
|
2005-09-18 05:47:15 +02:00
|
|
|
float newHeight;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], newHeight ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid water height argument" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_WaterHeight = newHeight;
|
2005-10-19 05:02:51 +02:00
|
|
|
g_TerrainModified = true;
|
2005-09-18 05:47:15 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the water plane height
|
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
|
|
|
JSBool GetWaterHeight( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 05:47:15 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2006-01-07 02:04:26 +01:00
|
|
|
*rval = ToJSVal(g_Renderer.GetWaterManager()->m_WaterHeight);
|
2005-09-18 05:47:15 +02:00
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
2005-07-20 06:53:58 +02:00
|
|
|
|
2005-09-18 08:28:23 +02:00
|
|
|
// Sets the water color
|
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
|
|
|
JSBool SetWaterColor( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 08:28:23 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 3 );
|
2005-09-18 08:28:23 +02:00
|
|
|
float r,g,b;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid arguments" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_WaterColor = CColor(r, g, b, 1.0f);
|
2005-09-18 08:28:23 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-06-22 23:11:18 +02:00
|
|
|
// Sets the water tint (used to tint reflections in fancy water)
|
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
|
|
|
JSBool SetWaterTint( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-06-22 23:11:18 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 3 );
|
2006-06-22 23:11:18 +02:00
|
|
|
float r,g,b;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid arguments" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
|
|
|
g_Renderer.GetWaterManager()->m_WaterTint = CColor(r, g, b, 1.0f);
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2006-09-10 07:31:41 +02:00
|
|
|
// Sets the water tint (used to tint reflections in fancy water)
|
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
|
|
|
JSBool SetReflectionTint( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-09-10 07:31:41 +02:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS( 3 );
|
|
|
|
float r,g,b;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], r )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[1], g )
|
|
|
|
|| !ToPrimitive( g_ScriptingHost.GetContext(), argv[2], b ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid arguments" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
|
|
|
g_Renderer.GetWaterManager()->m_ReflectionTint = CColor(r, g, b, 1.0f);
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2005-09-18 08:28:23 +02:00
|
|
|
// Sets the max water alpha (achieved when it is at WaterFullDepth or deeper)
|
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
|
|
|
JSBool SetWaterMaxAlpha( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 08:28:23 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 1 );
|
2005-09-18 08:28:23 +02:00
|
|
|
float val;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid argument" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_WaterMaxAlpha = val;
|
2005-09-18 08:28:23 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the water full depth (when it is colored WaterMaxAlpha)
|
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
|
|
|
JSBool SetWaterFullDepth( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 08:28:23 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 1 );
|
2005-09-18 08:28:23 +02:00
|
|
|
float val;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid argument" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_WaterFullDepth = val;
|
2005-09-18 08:28:23 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the water alpha offset (added to tweak water alpha near the shore)
|
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
|
|
|
JSBool SetWaterAlphaOffset( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-09-18 08:28:23 +02:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 1 );
|
2005-09-18 08:28:23 +02:00
|
|
|
float val;
|
|
|
|
if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], val ))
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Invalid argument" );
|
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.GetWaterManager()->m_WaterAlphaOffset = val;
|
2005-09-18 08:28:23 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2006-01-02 04:07:29 +01:00
|
|
|
// Is the game paused?
|
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
|
|
|
JSBool IsPaused( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-01-02 04:07:29 +01:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-23 04:56:48 +01:00
|
|
|
if( !g_Game )
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Game is not started" );
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-01-02 04:07:29 +01:00
|
|
|
*rval = g_Game->m_Paused ? JSVAL_TRUE : JSVAL_FALSE;
|
2006-01-23 04:56:48 +01:00
|
|
|
return JS_TRUE ;
|
2006-01-02 04:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pause/unpause the game
|
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
|
|
|
JSBool SetPaused( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-01-02 04:07:29 +01:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_PARAMS( 1 );
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-23 04:56:48 +01:00
|
|
|
if( !g_Game )
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Game is not started" );
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
try
|
2006-01-02 04:07:29 +01:00
|
|
|
{
|
|
|
|
g_Game->m_Paused = ToPrimitive<bool>( argv[0] );
|
2006-02-15 01:45:16 +01:00
|
|
|
}
|
2006-01-02 04:07:29 +01:00
|
|
|
catch( PSERROR_Scripting_ConversionFailed )
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_ReportError( cx, "Invalid parameter to SetPaused" );
|
2006-01-02 04:07:29 +01:00
|
|
|
}
|
2006-01-23 04:56:48 +01:00
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get game time
|
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
|
|
|
JSBool GetGameTime( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-01-23 04:56:48 +01:00
|
|
|
{
|
2006-07-26 15:10:13 +02:00
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
2006-02-15 01:45:16 +01:00
|
|
|
|
2006-01-23 04:56:48 +01:00
|
|
|
if( !g_Game )
|
|
|
|
{
|
|
|
|
JS_ReportError( cx, "Game is not started" );
|
|
|
|
return JS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-10-23 08:52:23 +02:00
|
|
|
*rval = ToJSVal(g_Game->GetSimulation()->GetTime());
|
2006-01-23 04:56:48 +01:00
|
|
|
return JS_TRUE;
|
2006-01-02 04:07:29 +01: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
|
|
|
JSBool RegisterTrigger( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS_CPP(1);
|
|
|
|
CTrigger* trigger = ToNative<CTrigger>( argv[0] );
|
|
|
|
debug_assert( trigger );
|
|
|
|
|
|
|
|
g_TriggerManager.AddTrigger( trigger );
|
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
2007-05-02 14:07:08 +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
|
|
|
JSBool GetTrigger( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2006-11-24 20:45:04 +01:00
|
|
|
{
|
|
|
|
JSU_REQUIRE_PARAMS_CPP(1);
|
|
|
|
CStrW name = ToPrimitive<CStrW>( argv[0] );
|
|
|
|
|
|
|
|
if ( g_TriggerManager.m_TriggerMap.find(name) != g_TriggerManager.m_TriggerMap.end() )
|
|
|
|
*rval = ToJSVal( g_TriggerManager.m_TriggerMap[name] );
|
|
|
|
else
|
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
debug_printf(L"Invalid trigger name %ls", name.c_str());
|
2006-11-24 20:45:04 +01:00
|
|
|
*rval = JSVAL_NULL;
|
|
|
|
}
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-10-09 05:43:03 +02:00
|
|
|
// Reveal map
|
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
|
|
|
JSBool RevealMap( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
2005-10-09 05:43:03 +02:00
|
|
|
{
|
2009-08-02 21:52:31 +02:00
|
|
|
JSU_REQUIRE_MAX_PARAMS(1);
|
2005-10-09 05:43:03 +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 newValue;
|
2005-10-09 05:43:03 +02:00
|
|
|
if(argc == 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
|
|
|
newValue = LOS_SETTING_ALL_VISIBLE;
|
2006-12-17 01:49:09 +01:00
|
|
|
else if(!ToPrimitive( g_ScriptingHost.GetContext(), argv[0], newValue ) || newValue > 2)
|
2005-10-09 05:43:03 +02:00
|
|
|
{
|
2005-10-10 05:35:32 +02:00
|
|
|
JS_ReportError( cx, "Invalid argument (should be 0, 1 or 2)" );
|
2005-10-09 05:43:03 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_FALSE );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
g_Game->GetWorld()->GetLOSManager()->m_LOSSetting = (ELOSSetting)newValue;
|
2005-10-09 05:43:03 +02:00
|
|
|
*rval = JSVAL_VOID;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
2008-07-12 23:27:38 +02:00
|
|
|
/**
|
|
|
|
* isGameRunning
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
JSBool isGameRunning( JSContext* cx, JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* rval )
|
|
|
|
{
|
|
|
|
JSU_REQUIRE_NO_PARAMS();
|
|
|
|
|
|
|
|
if (g_Game && g_Game->IsGameStarted())
|
|
|
|
{
|
|
|
|
*rval = JSVAL_TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*rval = JSVAL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JS_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-01-09 20:20:14 +01:00
|
|
|
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// function table
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// the JS interpreter expects the table to contain 5-tuples as follows:
|
|
|
|
// - name the function will be called as from script;
|
|
|
|
// - function which will be called;
|
|
|
|
// - number of arguments this function expects
|
|
|
|
// - Flags (deprecated, always zero)
|
|
|
|
// - Extra (reserved for future use, always zero)
|
|
|
|
//
|
|
|
|
// we simplify this a bit with a macro:
|
2007-05-02 14:07:08 +02:00
|
|
|
#define JS_FUNC(script_name, cpp_function, min_params) { script_name, cpp_function, min_params, 0, 0 },
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
JSFunctionSpec ScriptFunctionTable[] =
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2005-07-20 06:53:58 +02:00
|
|
|
// Console
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("writeConsole", JSI_Console::writeConsole, 1) // external
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Entity
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("getEntityByUnitID", GetEntityByUnitID, 1)
|
|
|
|
JS_FUNC("GetPlayerUnitCount", GetPlayerUnitCount, 1)
|
|
|
|
JS_FUNC("getEntityTemplate", GetEntityTemplate, 1)
|
|
|
|
JS_FUNC("startPlacing", StartPlacing, 1)
|
|
|
|
|
|
|
|
// Formation
|
|
|
|
JS_FUNC("createEntityFormation", CreateEntityFormation, 2)
|
|
|
|
JS_FUNC("removeFromFormation", RemoveFromFormation, 1)
|
|
|
|
JS_FUNC("lockEntityFormation", LockEntityFormation, 1)
|
|
|
|
JS_FUNC("isFormationLocked", IsFormationLocked, 1)
|
|
|
|
|
|
|
|
// Trigger
|
|
|
|
JS_FUNC("registerTrigger", RegisterTrigger, 1)
|
2006-06-06 08:31:17 +02:00
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
// Tech
|
|
|
|
JS_FUNC("getTechnology", GetTechnology, 2)
|
|
|
|
|
2005-07-20 06:53:58 +02:00
|
|
|
// Camera
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("setCameraTarget", SetCameraTarget, 1)
|
2005-07-20 06:53:58 +02:00
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
// Sky
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("toggleSky", ToggleSky, 0)
|
2006-05-16 06:41:37 +02:00
|
|
|
|
2005-09-18 05:47:15 +02:00
|
|
|
// Water
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("toggleWater", ToggleWater, 0)
|
|
|
|
JS_FUNC("setWaterHeight", SetWaterHeight, 1)
|
|
|
|
JS_FUNC("getWaterHeight", GetWaterHeight, 0)
|
|
|
|
JS_FUNC("setWaterColor", SetWaterColor, 3)
|
|
|
|
JS_FUNC("setWaterTint", SetWaterTint, 3)
|
|
|
|
JS_FUNC("setReflectionTint", SetReflectionTint, 3)
|
|
|
|
JS_FUNC("setWaterMaxAlpha", SetWaterMaxAlpha, 0)
|
|
|
|
JS_FUNC("setWaterFullDepth", SetWaterFullDepth, 0)
|
|
|
|
JS_FUNC("setWaterAlphaOffset", SetWaterAlphaOffset, 0)
|
2005-09-18 05:47:15 +02:00
|
|
|
|
2006-12-05 03:08:52 +01:00
|
|
|
// Territory rendering
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("toggleTerritoryRendering", ToggleTerritoryRendering, 0)
|
2006-12-05 03:08:52 +01:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Events
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("addGlobalHandler", AddGlobalHandler, 2)
|
|
|
|
JS_FUNC("removeGlobalHandler", RemoveGlobalHandler, 2)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Timer
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("setTimeout", SetTimeout, 2)
|
|
|
|
JS_FUNC("setInterval", SetInterval, 2)
|
|
|
|
JS_FUNC("cancelInterval", CancelInterval, 0)
|
|
|
|
JS_FUNC("cancelTimer", CancelTimer, 0)
|
|
|
|
JS_FUNC("setSimRate", SetSimRate, 1)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2006-07-30 02:24:04 +02:00
|
|
|
// Random number generator
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("simRand", SimRand, 0)
|
|
|
|
JS_FUNC("simRandInt", SimRandInt, 1)
|
2006-07-30 02:24:04 +02:00
|
|
|
|
|
|
|
// Profiling
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("startXTimer", StartJsTimer, 1)
|
|
|
|
JS_FUNC("stopXTimer", StopJsTimer, 1)
|
2006-07-13 22:09:20 +02:00
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
// Game Setup
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("startGame", StartGame, 0)
|
|
|
|
JS_FUNC("endGame", EndGame, 0)
|
|
|
|
JS_FUNC("getGameMode", GetGameMode, 0)
|
|
|
|
JS_FUNC("createClient", CreateClient, 0)
|
|
|
|
JS_FUNC("createServer", CreateServer, 0)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// VFS (external)
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("buildDirEntList", JSI_VFS::BuildDirEntList, 1)
|
|
|
|
JS_FUNC("getFileMTime", JSI_VFS::GetFileMTime, 1)
|
|
|
|
JS_FUNC("getFileSize", JSI_VFS::GetFileSize, 1)
|
|
|
|
JS_FUNC("readFile", JSI_VFS::ReadFile, 1)
|
|
|
|
JS_FUNC("readFileLines", JSI_VFS::ReadFileLines, 1)
|
|
|
|
JS_FUNC("archiveBuilderCancel", JSI_VFS::ArchiveBuilderCancel, 1)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Internationalization
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("loadLanguage", LoadLanguage, 1)
|
|
|
|
JS_FUNC("getLanguageID", GetLanguageID, 0)
|
2005-07-20 06:53:58 +02:00
|
|
|
// note: i18n/ScriptInterface.cpp registers translate() itself.
|
|
|
|
// rationale: see implementation section above.
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Debug
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("crash", ProvokeCrash, 0)
|
|
|
|
JS_FUNC("forceGC", ForceGarbageCollection, 0)
|
|
|
|
JS_FUNC("revealMap", RevealMap, 1)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Misc. Engine Interface
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("writeLog", WriteLog, 1)
|
|
|
|
JS_FUNC("exit", ExitProgram, 0)
|
|
|
|
JS_FUNC("isPaused", IsPaused, 0)
|
|
|
|
JS_FUNC("setPaused", SetPaused, 1)
|
|
|
|
JS_FUNC("getGameTime", GetGameTime, 0)
|
|
|
|
JS_FUNC("vmem", WriteVideoMemToConsole, 0)
|
|
|
|
JS_FUNC("_rewriteMaps", _RewriteMaps, 0)
|
|
|
|
JS_FUNC("_lodBias", _LodBias, 0)
|
|
|
|
JS_FUNC("setCursor", SetCursor, 1)
|
|
|
|
JS_FUNC("getCursorName", GetCursorName, 0)
|
|
|
|
JS_FUNC("getFPS", GetFps, 0)
|
|
|
|
JS_FUNC("isOrderQueued", isOrderQueued, 1)
|
2008-07-12 23:27:38 +02:00
|
|
|
JS_FUNC("isGameRunning", isGameRunning, 0)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// Miscellany
|
2007-05-02 14:07:08 +02:00
|
|
|
JS_FUNC("v3dist", ComputeDistanceBetweenTwoPoints, 2)
|
|
|
|
JS_FUNC("buildTime", GetBuildTimestamp, 0)
|
|
|
|
JS_FUNC("getGlobal", GetGlobal, 0)
|
|
|
|
JS_FUNC("saveProfileData", SaveProfileData, 0)
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// end of table marker
|
|
|
|
{0, 0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
#undef JS_FUNC
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// property accessors
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool GetEntitySet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(argv), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
2007-04-30 21:58:04 +02:00
|
|
|
std::vector<HEntity> extant;
|
|
|
|
g_EntityManager.GetExtantAsHandles(extant);
|
|
|
|
*vp = OBJECT_TO_JSVAL(EntityCollection::Create(extant));
|
2005-07-20 02:57:17 +02:00
|
|
|
|
2007-04-30 21:58:04 +02:00
|
|
|
return JS_TRUE;
|
2005-07-20 02:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool GetPlayerSet( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
std::vector<CPlayer*>* players = g_Game->GetPlayers();
|
|
|
|
|
|
|
|
*vp = OBJECT_TO_JSVAL( PlayerCollection::Create( *players ) );
|
|
|
|
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool GetLocalPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
*vp = OBJECT_TO_JSVAL( g_Game->GetLocalPlayer()->GetScript() );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool GetGaiaPlayer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
*vp = OBJECT_TO_JSVAL( g_Game->GetPlayer( 0 )->GetScript() );
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool SetLocalPlayer( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
CPlayer* newLocalPlayer = ToNative<CPlayer>( *vp );
|
|
|
|
|
|
|
|
if( !newLocalPlayer )
|
2005-05-18 07:32:09 +02:00
|
|
|
{
|
2005-07-20 02:57:17 +02:00
|
|
|
JS_ReportError( cx, "Not a valid Player." );
|
|
|
|
return( JS_TRUE );
|
2005-05-18 07:32:09 +02:00
|
|
|
}
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
g_Game->SetLocalPlayer( newLocalPlayer );
|
|
|
|
return( JS_TRUE );
|
2005-05-18 07:32:09 +02:00
|
|
|
}
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
|
2005-08-09 18:02:15 +02:00
|
|
|
JSBool GetGameView( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
2005-07-20 02:57:17 +02:00
|
|
|
{
|
|
|
|
if (g_Game)
|
|
|
|
*vp = OBJECT_TO_JSVAL( g_Game->GetView()->GetScript() );
|
|
|
|
else
|
|
|
|
*vp = JSVAL_NULL;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-10 16:15:28 +02:00
|
|
|
JSBool GetRenderer( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
|
|
|
{
|
|
|
|
if (CRenderer::IsInitialised())
|
|
|
|
*vp = OBJECT_TO_JSVAL( g_Renderer.GetScript() );
|
|
|
|
else
|
|
|
|
*vp = JSVAL_NULL;
|
|
|
|
return( JS_TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-20 02:57:17 +02:00
|
|
|
enum ScriptGlobalTinyIDs
|
|
|
|
{
|
|
|
|
GLOBAL_SELECTION,
|
|
|
|
GLOBAL_GROUPSARRAY,
|
|
|
|
GLOBAL_CAMERA,
|
|
|
|
GLOBAL_CONSOLE,
|
2006-02-15 01:45:16 +01:00
|
|
|
GLOBAL_LIGHTENV
|
2005-07-20 02:57:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
JSPropertySpec ScriptGlobalTable[] =
|
|
|
|
{
|
2007-12-29 17:22:23 +01:00
|
|
|
{ "selection" , GLOBAL_SELECTION, JSPROP_PERMANENT, JSI_Selection::getSelection, JSI_Selection::SetSelection },
|
|
|
|
{ "groups" , GLOBAL_GROUPSARRAY, JSPROP_PERMANENT, JSI_Selection::getGroups, JSI_Selection::setGroups },
|
|
|
|
{ "camera" , GLOBAL_CAMERA, JSPROP_PERMANENT, JSI_Camera::getCamera, JSI_Camera::setCamera },
|
|
|
|
{ "console" , GLOBAL_CONSOLE, JSPROP_PERMANENT|JSPROP_READONLY, JSI_Console::getConsole, 0 },
|
|
|
|
{ "lightenv" , GLOBAL_LIGHTENV, JSPROP_PERMANENT, JSI_LightEnv::getLightEnv, JSI_LightEnv::setLightEnv },
|
|
|
|
{ "entities" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetEntitySet, 0 },
|
|
|
|
{ "players" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetPlayerSet, 0 },
|
|
|
|
{ "localPlayer", 0, JSPROP_PERMANENT, GetLocalPlayer, SetLocalPlayer },
|
|
|
|
{ "gaiaPlayer" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetGaiaPlayer, 0 },
|
|
|
|
{ "gameView" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetGameView, 0 },
|
|
|
|
{ "renderer" , 0, JSPROP_PERMANENT|JSPROP_READONLY, GetRenderer, 0 },
|
2005-07-20 02:57:17 +02:00
|
|
|
|
|
|
|
// end of table marker
|
|
|
|
{ 0, 0, 0, 0, 0 },
|
|
|
|
};
|