Moved JS Entity.call() into debug console, so it is only active with debug OXP. Exposed ship desiredSpeed property to JS.
git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1641 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
parent
b30914187c
commit
ed6319c50c
@ -37,6 +37,7 @@ SOFTWARE.
|
||||
#import "OOJSScript.h"
|
||||
#import "OOJSVector.h"
|
||||
#import "OOJSEntity.h"
|
||||
#import "OOJSCall.h"
|
||||
|
||||
|
||||
@interface Entity (OODebugInspector)
|
||||
@ -60,6 +61,7 @@ static JSBool ConsoleConsoleMessage(JSContext *context, JSObject *this, uintN ar
|
||||
static JSBool ConsoleClearConsole(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool ConsoleScriptStack(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool ConsoleInspectEntity(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool ConsoleCallObjCMethod(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
static JSBool ConsoleSettingsDeleteProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
static JSBool ConsoleSettingsGetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
|
||||
@ -105,6 +107,7 @@ static JSFunctionSpec sConsoleMethods[] =
|
||||
{ "clearConsole", ConsoleClearConsole, 0 },
|
||||
{ "scriptStack", ConsoleScriptStack, 0 },
|
||||
{ "inspectEntity", ConsoleInspectEntity, 1 },
|
||||
{ "__callObjCMethod", ConsoleCallObjCMethod, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -407,4 +410,19 @@ static JSBool ConsoleInspectEntity(JSContext *context, JSObject *this, uintN arg
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
static JSBool ConsoleCallObjCMethod(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
|
||||
{
|
||||
id object = nil;
|
||||
|
||||
object = JSObjectToObject(context, this);
|
||||
if (object == nil)
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Attempt to call __callObjCMethod() for non-Objective-C object %@.", JSValToNSString(context, OBJECT_TO_JSVAL(this)));
|
||||
return YES;
|
||||
}
|
||||
|
||||
return OOJSCallObjCObjectMethod(context, object, [object jsClassName], argc, argv, outResult);
|
||||
}
|
||||
|
||||
#endif /* OO_EXCLUDE_DEBUG_SUPPORT */
|
||||
|
@ -515,6 +515,7 @@ MA 02110-1301, USA.
|
||||
- (void) setCargoFlag:(OOCargoFlag) flag;
|
||||
|
||||
- (void) setSpeed:(double) amount;
|
||||
- (double) desiredSpeed;
|
||||
- (void) setDesiredSpeed:(double) amount;
|
||||
|
||||
- (void) increase_flight_speed:(double) delta;
|
||||
|
@ -3762,6 +3762,12 @@ NSComparisonResult planetSort(id i1, id i2, void* context)
|
||||
}
|
||||
|
||||
|
||||
- (double) desiredSpeed
|
||||
{
|
||||
return desired_speed;
|
||||
}
|
||||
|
||||
|
||||
- (void) setDesiredSpeed:(double) amount
|
||||
{
|
||||
desired_speed = amount;
|
||||
|
@ -67,10 +67,8 @@ MA 02110-1301, USA.
|
||||
|
||||
- (void) setDestinationToCurrentLocation
|
||||
{
|
||||
destination = position;
|
||||
destination.x += (ranrot_rand() % 100)*0.01 - 0.5; // randomly add a .5m variance
|
||||
destination.y += (ranrot_rand() % 100)*0.01 - 0.5;
|
||||
destination.z += (ranrot_rand() % 100)*0.01 - 0.5;
|
||||
// randomly add a .5m variance
|
||||
destination = vector_add(position, OOVectorRandomSpatial(0.5));
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,6 +121,34 @@ void OOPrintLogHeader(void)
|
||||
#if OOLITE_MAC_OS_X
|
||||
#import <sys/sysctl.h>
|
||||
|
||||
|
||||
#ifndef CPUFAMILY_INTEL_6_13
|
||||
// Copied from OS X 10.5 SDK
|
||||
#define CPUFAMILY_INTEL_6_13 0xaa33392b
|
||||
#define CPUFAMILY_INTEL_6_14 0x73d67300 /* "Intel Core Solo" and "Intel Core Duo" (32-bit Pentium-M with SSE3) */
|
||||
#define CPUFAMILY_INTEL_6_15 0x426f69ef /* "Intel Core 2 Duo" */
|
||||
#define CPUFAMILY_INTEL_6_23 0x78ea4fbc /* Penryn */
|
||||
#define CPUFAMILY_INTEL_6_26 0x6b5a4cd2
|
||||
|
||||
#define CPUFAMILY_INTEL_YONAH CPUFAMILY_INTEL_6_14
|
||||
#define CPUFAMILY_INTEL_MEROM CPUFAMILY_INTEL_6_15
|
||||
#define CPUFAMILY_INTEL_PENRYN CPUFAMILY_INTEL_6_23
|
||||
#define CPUFAMILY_INTEL_NEHALEM CPUFAMILY_INTEL_6_26
|
||||
|
||||
#define CPUFAMILY_INTEL_CORE CPUFAMILY_INTEL_6_14
|
||||
#define CPUFAMILY_INTEL_CORE2 CPUFAMILY_INTEL_6_15
|
||||
#endif
|
||||
|
||||
#ifndef CPU_TYPE_ARM
|
||||
#define CPU_TYPE_ARM ((cpu_type_t) 12)
|
||||
#define CPU_SUBTYPE_ARM_ALL ((cpu_subtype_t) 0)
|
||||
#define CPU_SUBTYPE_ARM_V4T ((cpu_subtype_t) 5)
|
||||
#define CPU_SUBTYPE_ARM_V6 ((cpu_subtype_t) 6)
|
||||
#define CPUFAMILY_ARM_9 0xe73283ae
|
||||
#define CPUFAMILY_ARM_11 0x8ff620d8
|
||||
#endif
|
||||
|
||||
|
||||
static NSString *GetSysCtlString(const char *name);
|
||||
static unsigned long long GetSysCtlInt(const char *name);
|
||||
static NSString *GetCPUDescription(void);
|
||||
@ -139,12 +167,13 @@ static NSString *AdditionalLogHeaderInfo(void)
|
||||
|
||||
static NSString *GetCPUDescription(void)
|
||||
{
|
||||
unsigned long long sysCPUType, sysCPUSubType,
|
||||
sysCPUFrequency, sysCPUCount;
|
||||
unsigned long long sysCPUType, sysCPUSubType, sysCPUFamily,
|
||||
sysCPUFrequency, sysCPUCount;
|
||||
NSString *typeStr = nil, *subTypeStr = nil;
|
||||
|
||||
sysCPUType = GetSysCtlInt("hw.cputype");
|
||||
sysCPUSubType = GetSysCtlInt("hw.cpusubtype");
|
||||
sysCPUFamily = GetSysCtlInt("hw.cpufamily");
|
||||
sysCPUFrequency = GetSysCtlInt("hw.cpufrequency");
|
||||
sysCPUCount = GetSysCtlInt("hw.logicalcpu");
|
||||
|
||||
@ -158,34 +187,88 @@ static NSString *GetCPUDescription(void)
|
||||
case CPU_TYPE_POWERPC:
|
||||
typeStr = @"PowerPC";
|
||||
switch (sysCPUSubType)
|
||||
{
|
||||
case CPU_SUBTYPE_POWERPC_750:
|
||||
subTypeStr = @" G3 (750)";
|
||||
break;
|
||||
{
|
||||
case CPU_SUBTYPE_POWERPC_750:
|
||||
subTypeStr = @" G3 (750)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_7400:
|
||||
subTypeStr = @" G4 (7400)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_7450:
|
||||
subTypeStr = @" G4 (7450)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_970:
|
||||
subTypeStr = @" G5 (970)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_7400:
|
||||
subTypeStr = @" G4 (7400)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_7450:
|
||||
subTypeStr = @" G4 (7450)";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_POWERPC_970:
|
||||
subTypeStr = @" G5 (970)";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
subTypeStr = [NSString stringWithFormat:@":%u", sysCPUSubType];
|
||||
}
|
||||
break;
|
||||
|
||||
case CPU_TYPE_I386:
|
||||
typeStr = @"x86";
|
||||
// Currently all x86 CPUs seem to report subtype CPU_SUBTYPE_486, which isn't very useful.
|
||||
if (sysCPUSubType == CPU_SUBTYPE_486) subTypeStr = @"";
|
||||
switch (sysCPUFamily)
|
||||
{
|
||||
case CPUFAMILY_INTEL_6_13:
|
||||
subTypeStr = @" (Intel 6:13)";
|
||||
break;
|
||||
|
||||
case CPUFAMILY_INTEL_YONAH:
|
||||
subTypeStr = @" (Core/Yonah)";
|
||||
break;
|
||||
|
||||
case CPUFAMILY_INTEL_MEROM:
|
||||
subTypeStr = @" (Core 2/Merom)";
|
||||
break;
|
||||
|
||||
case CPUFAMILY_INTEL_PENRYN:
|
||||
subTypeStr = @" (Penryn)";
|
||||
break;
|
||||
|
||||
case CPUFAMILY_INTEL_NEHALEM:
|
||||
subTypeStr = @" (Nehalem)";
|
||||
break;
|
||||
|
||||
default:
|
||||
subTypeStr = [NSString stringWithFormat:@" (family %u)", sysCPUFamily];
|
||||
}
|
||||
break;
|
||||
|
||||
case CPU_TYPE_ARM:
|
||||
typeStr = @"ARM";
|
||||
switch (sysCPUSubType)
|
||||
{
|
||||
case CPU_SUBTYPE_ARM_V4T:
|
||||
subTypeStr = @" v4T";
|
||||
break;
|
||||
|
||||
case CPU_SUBTYPE_ARM_V6:
|
||||
subTypeStr = @"v6"; // No space
|
||||
break;
|
||||
}
|
||||
if (subTypeStr == nil)
|
||||
{
|
||||
switch (sysCPUFamily)
|
||||
{
|
||||
case CPUFAMILY_ARM_9:
|
||||
subTypeStr = @"9"; // No space
|
||||
break;
|
||||
|
||||
case CPUFAMILY_ARM_11:
|
||||
subTypeStr = @"11"; // No space
|
||||
break;
|
||||
|
||||
default:
|
||||
subTypeStr = [NSString stringWithFormat:@" (family %u)", sysCPUFamily];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeStr == nil) typeStr = [NSString stringWithFormat:@"%u", sysCPUType];
|
||||
if (subTypeStr == nil) subTypeStr = [NSString stringWithFormat:@":%u", sysCPUSubType];
|
||||
|
||||
return [NSString stringWithFormat:@"%llu x %@%@ @ %llu MHz", sysCPUCount, typeStr, subTypeStr, (sysCPUFrequency + 500000) / 1000000];
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ static JSBool EntitySetProperty(JSContext *context, JSObject *this, jsval name,
|
||||
// Methods
|
||||
static JSBool EntitySetPosition(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool EntitySetOrientation(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
static JSBool EntityCall(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
|
||||
// Static methods
|
||||
static JSBool EntityStaticEntityWithID(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult);
|
||||
@ -129,7 +128,6 @@ static JSFunctionSpec sEntityMethods[] =
|
||||
{ "toString", JSObjectWrapperToString, 0 },
|
||||
{ "setPosition", EntitySetPosition, 1 },
|
||||
{ "setOrientation", EntitySetOrientation, 1 },
|
||||
{ "call", EntityCall, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -376,17 +374,6 @@ static JSBool EntitySetOrientation(JSContext *context, JSObject *this, uintN arg
|
||||
}
|
||||
|
||||
|
||||
static JSBool EntityCall(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
|
||||
{
|
||||
Entity *entity = nil;
|
||||
|
||||
if (!JSEntityGetEntity(context, this, &entity)) return YES;
|
||||
if (entity == nil) return YES; // Stale entity
|
||||
|
||||
return OOJSCallObjCObjectMethod(context, entity, [entity jsClassName], argc, argv, outResult);
|
||||
}
|
||||
|
||||
|
||||
static JSBool EntityStaticEntityWithID(JSContext *context, JSObject *this, uintN argc, jsval *argv, jsval *outResult)
|
||||
{
|
||||
Entity *result = nil;
|
||||
|
@ -114,7 +114,8 @@ enum
|
||||
kShip_reportAIMessages, // report AI messages, boolean, read/write
|
||||
kShip_withinStationAegis, // within main station aegis, boolean, read/write
|
||||
kShip_maxCargo, // maximum cargo, integer, read-only
|
||||
kShip_speed, // current flight speed, double, read-only (should probably be read/write, but may interfere with AI behaviour)
|
||||
kShip_speed, // current flight speed, double, read-only
|
||||
kShip_desiredSpeed, // AI desired flight speed, double, read/write
|
||||
kShip_maxSpeed, // maximum flight speed, double, read-only
|
||||
kShip_script, // script, Script, read-only
|
||||
kShip_isPirate, // is pirate, boolean, read-only
|
||||
@ -165,6 +166,7 @@ static JSPropertySpec sShipProperties[] =
|
||||
{ "shipDescription", kShip_shipDescription, JSPROP_PERMANENT | JSPROP_ENUMERATE },
|
||||
{ "shipDisplayName", kShip_shipDisplayName, JSPROP_PERMANENT | JSPROP_ENUMERATE },
|
||||
{ "speed", kShip_speed, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
|
||||
{ "desiredSpeed", kShip_desiredSpeed, JSPROP_PERMANENT | JSPROP_ENUMERATE },
|
||||
{ "subEntities", kShip_subEntities, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
|
||||
{ "target", kShip_target, JSPROP_PERMANENT | JSPROP_ENUMERATE },
|
||||
{ "temperature", kShip_temperature, JSPROP_PERMANENT | JSPROP_ENUMERATE },
|
||||
@ -369,6 +371,10 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
JS_NewDoubleValue(context, [entity flightSpeed], outValue);
|
||||
break;
|
||||
|
||||
case kShip_desiredSpeed:
|
||||
JS_NewDoubleValue(context, [entity desiredSpeed], outValue);
|
||||
break;
|
||||
|
||||
case kShip_maxSpeed:
|
||||
JS_NewDoubleValue(context, [entity maxFlightSpeed], outValue);
|
||||
break;
|
||||
@ -437,7 +443,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
switch (JSVAL_TO_INT(name))
|
||||
{
|
||||
case kShip_shipDescription:
|
||||
if (entity->isPlayer)
|
||||
if ([entity isPlayer])
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Ship.%@ [setter]: cannot set %@ for player.", @"name", @"name");
|
||||
}
|
||||
@ -449,7 +455,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_shipDisplayName:
|
||||
if (entity->isPlayer)
|
||||
if ([entity isPlayer])
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Ship.%@ [setter]: cannot set %@ for player.", @"displayName", @"displayName");
|
||||
}
|
||||
@ -461,7 +467,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_primaryRole:
|
||||
if (entity->isPlayer)
|
||||
if ([entity isPlayer])
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Ship.%@ [setter]: cannot set %@ for player.", @"primaryRole", @"primary role");
|
||||
}
|
||||
@ -473,7 +479,7 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
break;
|
||||
|
||||
case kShip_AIState:
|
||||
if (entity->isPlayer)
|
||||
if ([entity isPlayer])
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Ship.%@ [setter]: cannot set %@ for player.", @"AIState", @"AI state");
|
||||
}
|
||||
@ -544,6 +550,20 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
|
||||
}
|
||||
break;
|
||||
|
||||
case kShip_desiredSpeed:
|
||||
if ([entity isPlayer])
|
||||
{
|
||||
OOReportJavaScriptError(context, @"Ship.%@ [setter]: cannot set %@ for player.", @"desiredSpeed", @"desired speed");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (JS_ValueToNumber(context, *value, &fValue))
|
||||
{
|
||||
[entity setDesiredSpeed:fmax(fValue, 0.0)];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
OOReportJavaScriptBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
|
||||
return NO;
|
||||
|
Loading…
x
Reference in New Issue
Block a user