Fixed bug where space dust velocity ignored inertial velocity of player, taking only thrust into account. Exposed player velocity to JS. Initial work on fixing player-only shader binding issue described at http://aegidian.org/bb/viewtopic.php?p=103930#103930 .

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3051 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-03-03 18:04:06 +00:00
parent 94d00e8086
commit a4382b451f
11 changed files with 165 additions and 46 deletions

View File

@ -499,6 +499,9 @@
1A7D41E30C516E9E008EDC33 /* OOCheckShipDataPListVerifierStage.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7D41E10C516E9E008EDC33 /* OOCheckShipDataPListVerifierStage.m */; };
1A7D833A0C40147800E4A5F5 /* OOAsyncQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7D83380C40147700E4A5F5 /* OOAsyncQueue.h */; };
1A7D833B0C40147800E4A5F5 /* OOAsyncQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7D83390C40147700E4A5F5 /* OOAsyncQueue.m */; };
1A7E317C113ED37C009AAB6D /* EntityShaderBindings.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7E317B113ED37C009AAB6D /* EntityShaderBindings.m */; };
1A7E3189113ED496009AAB6D /* ProxyPlayerEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A7E3187113ED496009AAB6D /* ProxyPlayerEntity.h */; };
1A7E318A113ED496009AAB6D /* ProxyPlayerEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A7E3188113ED496009AAB6D /* ProxyPlayerEntity.m */; };
1A817C17106D123F00AA2F97 /* oolite-particle-blur.png in Copy Textures */ = {isa = PBXBuildFile; fileRef = 1A817C16106D123F00AA2F97 /* oolite-particle-blur.png */; };
1A817CFC106D232100AA2F97 /* OOPlasmaShotEntity.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A817CFA106D232100AA2F97 /* OOPlasmaShotEntity.h */; };
1A817CFD106D232100AA2F97 /* OOPlasmaShotEntity.m in Sources */ = {isa = PBXBuildFile; fileRef = 1A817CFB106D232100AA2F97 /* OOPlasmaShotEntity.m */; };
@ -1597,6 +1600,9 @@
1A7D41E10C516E9E008EDC33 /* OOCheckShipDataPListVerifierStage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOCheckShipDataPListVerifierStage.m; sourceTree = "<group>"; };
1A7D83380C40147700E4A5F5 /* OOAsyncQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOAsyncQueue.h; sourceTree = "<group>"; };
1A7D83390C40147700E4A5F5 /* OOAsyncQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOAsyncQueue.m; sourceTree = "<group>"; };
1A7E317B113ED37C009AAB6D /* EntityShaderBindings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EntityShaderBindings.m; sourceTree = "<group>"; };
1A7E3187113ED496009AAB6D /* ProxyPlayerEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyPlayerEntity.h; sourceTree = "<group>"; };
1A7E3188113ED496009AAB6D /* ProxyPlayerEntity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyPlayerEntity.m; sourceTree = "<group>"; };
1A817C16106D123F00AA2F97 /* oolite-particle-blur.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "oolite-particle-blur.png"; sourceTree = "<group>"; };
1A817CFA106D232100AA2F97 /* OOPlasmaShotEntity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OOPlasmaShotEntity.h; sourceTree = "<group>"; };
1A817CFB106D232100AA2F97 /* OOPlasmaShotEntity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OOPlasmaShotEntity.m; sourceTree = "<group>"; };
@ -2196,6 +2202,8 @@
1A26D0A50BCF9CF70073F257 /* PlayerEntitySound.m */,
1A26D09F0BCF9CF70073F257 /* PlayerEntityStickMapper.h */,
1A26D09E0BCF9CF70073F257 /* PlayerEntityStickMapper.m */,
1A7E3187113ED496009AAB6D /* ProxyPlayerEntity.h */,
1A7E3188113ED496009AAB6D /* ProxyPlayerEntity.m */,
);
name = PlayerEntity;
sourceTree = "<group>";
@ -2671,6 +2679,7 @@
children = (
1A26D09D0BCF9CF70073F257 /* Entity.h */,
1A26D0A80BCF9CF70073F257 /* Entity.m */,
1A7E317B113ED37C009AAB6D /* EntityShaderBindings.m */,
1A2A1B050BD276A900152975 /* OOEntityWithDrawable.h */,
1A2A1B060BD276A900152975 /* OOEntityWithDrawable.m */,
1A2A1B280BD277D800152975 /* OOSelfDrawingEntity.h */,
@ -3173,6 +3182,7 @@
1AA7FE3410C2F26A0058FBED /* OOPlanetTextureGenerator.h in Headers */,
1ADA564810CD68D800E891B8 /* OOStellarBody.h in Headers */,
1A01574311034A86008EE36A /* ShipEntityLoadRestore.h in Headers */,
1A7E3189113ED496009AAB6D /* ProxyPlayerEntity.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -3545,6 +3555,8 @@
1AA7FE2E10C2F2070058FBED /* OOTextureGenerator.m in Sources */,
1AA7FE3510C2F26A0058FBED /* OOPlanetTextureGenerator.m in Sources */,
1A01574411034A86008EE36A /* ShipEntityLoadRestore.m in Sources */,
1A7E317C113ED37C009AAB6D /* EntityShaderBindings.m in Sources */,
1A7E318A113ED496009AAB6D /* ProxyPlayerEntity.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -55,7 +55,7 @@
/*** Module-specific message classes ***/
ai = yes; // AI messages are sent if a ship's reportAIMessages property is set, for instance through the JavaScript console.
ai = yes; // AI messages are shown if a ship's reportAIMessages property is set, for instance through the JavaScript console.
ai.message.receive = inherit;
ai.takeAction = inherit;
ai.takeAction.noAction = inherit;

View File

@ -342,7 +342,17 @@
"universalTime",
"spawnTime",
"timeElapsedSinceSpawn",
"throwingSparks"
"throwingSparks",
// Renamed, previously player-only properties for 1.74
"clock", // Was clock_number or clock_secs_number; supersedes clock_mins_number, clock_hours_number, clock_days_number
"pseudoFixedD100", // Was pseudoFixedD100_number
"pseudoFixedD256", // Was pseudoFixedD256_number
"systemGovernment", // Was systemGovernment_number
"systemEconomy", // Was systemEconomy_number
"systemTechLevel", // Was systemTechLevel_number
"systemPopulation", // Was systemPopulation_number
"systemProductivity" // Was systemProductivity_number
);
shader_ship_binding_methods =
@ -376,14 +386,19 @@
"rangeToPrimaryTarget",
"laserColor",
"isHulk",
"lightsActive"
"lightsActive",
// Renamed, previously player-only properties for 1.74
"legalStatus", // Was commanderLegalStatus_number
"fuel", // Was fuelLevel_number
"velocity" // Was velocityVector
);
shader_player_ship_binding_methods =
(
(
"fuelLeakRate", // Was fuelLeakRate_number
"massLocked",
"atHyperspeed",
"velocityVector",
"dialForwardShield",
"dialAftShield",
"dialMissileStatus",
@ -393,32 +408,7 @@
"dialMaxMissiles",
"dialIdentEngaged",
"alertCondition",
"trumbleCount",
// PlayerShipLegacyScriptEngine.m
"galaxy_number",
"planet_number",
"score_number",
"credits_number",
"scriptTimer_number",
"shipsFound_number",
"legalStatus_number",
"commanderLegalStatus_number",
"pseudoFixedD100_number",
"pseudoFixedD256_number",
"clock_number",
"clock_secs_number",
"clock_mins_number",
"clock_hours_number",
"clock_days_number",
"fuelLevel_number",
"dockedTechLevel_number",
"systemGovernment_number",
"systemEconomy_number",
"systemTechLevel_number",
"systemPopulation_number",
"systemProductivity_number",
"fuelLeakRate_number"
"trumbleCount"
);
action_method_aliases =

View File

@ -149,7 +149,7 @@ MA 02110-1301, USA.
if ([UNIVERSE breakPatternHide]) return; // DON'T DRAW
BOOL warp_stars = [player atHyperspeed];
Vector warp_vector = vector_multiply_scalar([player velocityVector], 1.0f / HYPERSPEED_FACTOR);
Vector warp_vector = vector_multiply_scalar([player velocity], 1.0f / HYPERSPEED_FACTOR);
if (translucent)
{

View File

@ -0,0 +1,80 @@
/*
EntityShaderBindings.m
Extra methods exposed for shader bindings.
Oolite
Copyright (C) 2004-2010 Giles C Williams and contributors
This program 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.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
#import "Entity.h"
#import "PlayerEntityScriptMethods.h"
#import "PlayerEntityLegacyScriptEngine.h"
@implementation Entity (ShaderBindings)
// Clock time.
- (GLfloat) clock
{
return [[PlayerEntity sharedPlayer] clockTime];
}
// System "flavour" numbers.
- (unsigned) pseudoFixedD100
{
return [[PlayerEntity sharedPlayer] systemPseudoRandom100];
}
- (unsigned) pseudoFixedD256
{
return [[PlayerEntity sharedPlayer] systemPseudoRandom256];
}
// System attributes.
- (unsigned) systemGovernment
{
return [[[PlayerEntity sharedPlayer] systemGovernment_number] unsignedIntValue];
}
- (unsigned) systemEconomy
{
return [[[PlayerEntity sharedPlayer] systemEconomy_number] unsignedIntValue];
}
- (unsigned) systemTechLevel
{
return [[[PlayerEntity sharedPlayer] systemTechLevel_number] unsignedIntValue];
}
- (unsigned) systemPopulation
{
return [[[PlayerEntity sharedPlayer] systemPopulation_number] unsignedIntValue];
}
- (unsigned) systemProductivity
{
return [[[PlayerEntity sharedPlayer] systemProductivity_number] unsignedIntValue];
}
@end

View File

@ -537,7 +537,6 @@ typedef enum
- (BOOL) massLocked;
- (BOOL) atHyperspeed;
- (Vector) velocityVector;
- (void) setDockedAtMainStation;
- (StationEntity *) dockedStation;

View File

@ -2350,16 +2350,6 @@ static GLfloat sBaseMass = 0.0;
}
- (Vector) velocityVector
{
Vector result = v_forward;
result.x *= flightSpeed;
result.y *= flightSpeed;
result.z *= flightSpeed;
return result;
}
// dial routines = all return 0.0 .. 1.0 or -1.0 .. 1.0
- (void) setDockedAtMainStation

View File

@ -632,6 +632,9 @@ MA 02110-1301, USA.
- (double) desiredSpeed;
- (void) setDesiredSpeed:(double) amount;
- (Vector) thrustVector;
- (void) setTotalVelocity:(Vector)vel; // Set velocity to vel - thrustVector, effectively setting the instanteneous velocity to vel.
- (void) increase_flight_speed:(double) delta;
- (void) decrease_flight_speed:(double) delta;
- (void) increase_flight_roll:(double) delta;

View File

@ -7935,9 +7935,21 @@ BOOL class_masslocks(int some_class)
}
- (Vector) velocity // overrides Entity velocity
- (Vector) thrustVector
{
return vector_add(velocity, vector_multiply_scalar(v_forward, flightSpeed));
return vector_multiply_scalar(v_forward, flightSpeed);
}
- (Vector) velocity
{
return vector_add([super velocity], [self thrustVector]);
}
- (void) setTotalVelocity:(Vector)vel
{
[self setVelocity:vector_subtract(vel, [self thrustVector])];
}

View File

@ -82,6 +82,12 @@ This code is hereby placed in the public domain.
// *** Proxy evilness beyond this point.
- (Class) class
{
return [_object class];
}
- (void)forwardInvocation:(NSInvocation *)invocation
{
// Does the right thing even with nil _object.

View File

@ -176,7 +176,9 @@ enum
kShip_scannerDisplayColor2, // color of lollipop shown on scanner when flashing, array, read/write
kShip_maxThrust, // maximum thrust, double, read-only
kShip_thrust, // the ship's thrust, double, read/write
kShip_lightsActive // flasher/shader light flag, boolean, read/write
kShip_lightsActive, // flasher/shader light flag, boolean, read/write
kShip_velocity, // velocity, vector, read/write
kShip_thrustVector, // thrust-related component of velocity, vector, read-only
};
@ -253,6 +255,8 @@ static JSPropertySpec sShipProperties[] =
{ "maxThrust", kShip_maxThrust, JSPROP_PERMANENT | JSPROP_ENUMERATE | JSPROP_READONLY },
{ "thrust", kShip_thrust, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "lightsActive", kShip_lightsActive, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "velocity", kShip_velocity, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ "thrustVector", kShip_thrustVector, JSPROP_PERMANENT | JSPROP_ENUMERATE },
{ 0 }
};
@ -642,6 +646,14 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsval name, js
OK = YES;
break;
case kShip_velocity:
OK = VectorToJSValue(context, [entity velocity], outValue);
break;
case kShip_thrustVector:
OK = VectorToJSValue(context, [entity thrustVector], outValue);
break;
default:
OOReportJSBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));
}
@ -892,6 +904,21 @@ static JSBool ShipSetProperty(JSContext *context, JSObject *this, jsval name, js
OK = YES;
}
break;
case kShip_velocity:
if (JSValueToVector(context, *value, &vValue))
{
/* Silliness: the ship's velocity vector is the sum of the
thrust vector and a base velocity. Here we find the
thrust vector (and any other weird vectors that may be
added into the mix) and alter the base velocity to get
the requested total velocity.
-- Ahruman 2010-03-03
*/
[entity setTotalVelocity:vValue];
OK = YES;
}
break;
default:
OOReportJSBadPropertySelector(context, @"Ship", JSVAL_TO_INT(name));