Initial implementation of waypoints
Try something like this to test. S.setWaypoint("test", { position: [3E5,3E5,0], size: 5000, beaconCode: "T", beaconLabel: "Waypoint 1" });master
parent
cf5c5711d7
commit
23b5edea58
|
@ -187,7 +187,8 @@ OOLITE_ENTITY_FILES = \
|
|||
OOLaserShotEntity.m \
|
||||
OOQuiriumCascadeEntity.m \
|
||||
OORingEffectEntity.m \
|
||||
OOVisualEffectEntity.m
|
||||
OOVisualEffectEntity.m \
|
||||
OOWaypointEntity.m
|
||||
|
||||
OOLITE_GRAPHICS_DRAWABLE_FILES = \
|
||||
OODrawable.m \
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
"equipment_required" = "EQ_SCANNER_SHOW_MISSILE_TARGET";
|
||||
selector = "drawTargetReticle:";
|
||||
},
|
||||
{ // Waypoint display
|
||||
equipment_required = "EQ_ADVANCED_COMPASS";
|
||||
selector = "drawWaypoints:";
|
||||
},
|
||||
{ /* station aegis, uses Images/aegis.png as indicator */
|
||||
alpha = 0.8;
|
||||
selector = "drawAegis:";
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
equipment_required = "EQ_SCANNER_SHOW_MISSILE_TARGET";
|
||||
selector = "drawTargetReticle:";
|
||||
},
|
||||
{ // Waypoint display
|
||||
equipment_required = "EQ_ADVANCED_COMPASS";
|
||||
selector = "drawWaypoints:";
|
||||
},
|
||||
{ // scanner
|
||||
alpha = 1.0;
|
||||
selector = "drawScanner:";
|
||||
|
|
|
@ -313,6 +313,7 @@
|
|||
(
|
||||
"drawTrumbles:",
|
||||
"drawTargetReticle:",
|
||||
"drawWaypoints:",
|
||||
"drawScanner:",
|
||||
"drawScannerZoomIndicator:",
|
||||
"drawStickSensitivityIndicator:",
|
||||
|
|
|
@ -171,6 +171,7 @@ enum OOScanClass
|
|||
- (BOOL) isWormhole;
|
||||
- (BOOL) isEffect;
|
||||
- (BOOL) isVisualEffect;
|
||||
- (BOOL) isWaypoint;
|
||||
|
||||
- (BOOL) validForAddToUniverse;
|
||||
- (void) addToLinkedLists;
|
||||
|
@ -286,6 +287,25 @@ enum OOScanClass
|
|||
|
||||
@end
|
||||
|
||||
@protocol OOHUDBeaconIcon;
|
||||
|
||||
// Methods that must be supported by entities with beacons, regardless of type.
|
||||
@protocol OOBeaconEntity
|
||||
|
||||
- (NSComparisonResult) compareBeaconCodeWith:(Entity <OOBeaconEntity>*) other;
|
||||
- (NSString *) beaconCode;
|
||||
- (void) setBeaconCode:(NSString *)bcode;
|
||||
- (NSString *) beaconLabel;
|
||||
- (void) setBeaconLabel:(NSString *)blabel;
|
||||
- (BOOL) isBeacon;
|
||||
- (id <OOHUDBeaconIcon>) beaconDrawable;
|
||||
- (Entity <OOBeaconEntity> *) prevBeacon;
|
||||
- (Entity <OOBeaconEntity> *) nextBeacon;
|
||||
- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip;
|
||||
- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip;
|
||||
- (BOOL) isJammingScanning;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
enum
|
||||
|
|
|
@ -194,6 +194,12 @@ static NSString * const kOOLogEntityUpdateError = @"entity.linkedList.update.
|
|||
}
|
||||
|
||||
|
||||
- (BOOL) isWaypoint
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) validForAddToUniverse
|
||||
{
|
||||
NSUInteger mySessionID = [self sessionID];
|
||||
|
|
|
@ -39,27 +39,6 @@ MA 02110-1301, USA.
|
|||
@end
|
||||
|
||||
|
||||
@protocol OOHUDBeaconIcon;
|
||||
|
||||
// Methods that must be supported by entities with beacons, regardless of type.
|
||||
@protocol OOBeaconEntity
|
||||
|
||||
- (NSComparisonResult) compareBeaconCodeWith:(Entity <OOBeaconEntity>*) other;
|
||||
- (NSString *) beaconCode;
|
||||
- (void) setBeaconCode:(NSString *)bcode;
|
||||
- (NSString *) beaconLabel;
|
||||
- (void) setBeaconLabel:(NSString *)blabel;
|
||||
- (BOOL) isBeacon;
|
||||
- (id <OOHUDBeaconIcon>) beaconDrawable;
|
||||
- (Entity <OOBeaconEntity> *) prevBeacon;
|
||||
- (Entity <OOBeaconEntity> *) nextBeacon;
|
||||
- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip;
|
||||
- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip;
|
||||
- (BOOL) isJammingScanning;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface OOEntityWithDrawable: Entity
|
||||
{
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
|
||||
OOWaypoint.h
|
||||
|
||||
A waypoint for the HUD
|
||||
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2013 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"
|
||||
|
||||
@interface OOWaypointEntity: Entity <OOBeaconEntity>
|
||||
{
|
||||
@private
|
||||
OOScalar _size;
|
||||
|
||||
NSString *_beaconCode;
|
||||
NSString *_beaconLabel;
|
||||
OOWeakReference *_prevBeacon;
|
||||
OOWeakReference *_nextBeacon;
|
||||
id <OOHUDBeaconIcon> _beaconDrawable;
|
||||
}
|
||||
|
||||
+ (instancetype) waypointWithDictionary:(NSDictionary *)info;
|
||||
|
||||
- (id) initWithDictionary:(NSDictionary *)info;
|
||||
|
||||
- (OOScalar) size;
|
||||
- (void) setSize:(OOScalar)newSize;
|
||||
|
||||
@end
|
|
@ -0,0 +1,294 @@
|
|||
/*
|
||||
|
||||
OOWaypointEntity.m
|
||||
|
||||
Oolite
|
||||
Copyright (C) 2004-2013 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 "OOWaypointEntity.h"
|
||||
#import "Entity.h"
|
||||
#import "OOCollectionExtractors.h"
|
||||
#import "OOStringExpander.h"
|
||||
#import "Universe.h"
|
||||
#import "PlayerEntity.h"
|
||||
#import "OOPolygonSprite.h"
|
||||
#import "OOOpenGL.h"
|
||||
#import "OOMacroOpenGL.h"
|
||||
|
||||
#define OOWAYPOINT_KEY_POSITION @"position"
|
||||
#define OOWAYPOINT_KEY_ORIENTATION @"orientation"
|
||||
#define OOWAYPOINT_KEY_SIZE @"size"
|
||||
#define OOWAYPOINT_KEY_CODE @"beaconCode"
|
||||
#define OOWAYPOINT_KEY_LABEL @"beaconLabel"
|
||||
|
||||
@implementation OOWaypointEntity
|
||||
|
||||
+ (instancetype) waypointWithDictionary:(NSDictionary *)info
|
||||
{
|
||||
return [[[OOWaypointEntity alloc] initWithDictionary:info] autorelease];
|
||||
}
|
||||
|
||||
- (id) initWithDictionary:(NSDictionary *)info
|
||||
{
|
||||
self = [super init];
|
||||
if (EXPECT_NOT(self == nil)) return nil;
|
||||
|
||||
position = [info oo_hpvectorForKey:OOWAYPOINT_KEY_POSITION];
|
||||
[self setOrientation:[info oo_quaternionForKey:OOWAYPOINT_KEY_ORIENTATION]];
|
||||
[self setSize:[info oo_nonNegativeFloatForKey:OOWAYPOINT_KEY_SIZE defaultValue:1000.0]];
|
||||
[self setBeaconCode:[info oo_stringForKey:OOWAYPOINT_KEY_CODE defaultValue:@"W"]];
|
||||
[self setBeaconLabel:[info oo_stringForKey:OOWAYPOINT_KEY_LABEL defaultValue:@"Waypoint"]];
|
||||
|
||||
[self setStatus:STATUS_EFFECT];
|
||||
[self setScanClass:CLASS_NO_DRAW];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(_beaconCode);
|
||||
DESTROY(_beaconLabel);
|
||||
DESTROY(_prevBeacon);
|
||||
DESTROY(_nextBeacon);
|
||||
DESTROY(_beaconDrawable);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (OOScalar) size
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
|
||||
- (void) setSize:(OOScalar)newSize;
|
||||
{
|
||||
if (newSize > 0)
|
||||
{
|
||||
_size = newSize;
|
||||
no_draw_distance = newSize * newSize * NO_DRAW_DISTANCE_FACTOR * NO_DRAW_DISTANCE_FACTOR * 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (BOOL) isEffect
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) isWaypoint
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void) drawImmediate:(bool)immediate translucent:(bool)translucent
|
||||
{
|
||||
if (!translucent || no_draw_distance < cam_zero_distance)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (![PLAYER hasEquipmentItem:@"EQ_ADVANCED_COMPASS"])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int8_t i,j,k;
|
||||
|
||||
GLfloat a = 0.75;
|
||||
if ([PLAYER compassTarget] != self)
|
||||
{
|
||||
a *= 0.25;
|
||||
}
|
||||
if (cam_zero_distance > _size * _size)
|
||||
{
|
||||
// dim out as gets further away; 2-D HUD display more
|
||||
// important at long range
|
||||
a -= 0.004*(sqrt(cam_zero_distance) / _size);
|
||||
}
|
||||
if (a < 0.01)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GLfloat s0 = _size;
|
||||
GLfloat s1 = _size * 0.75;
|
||||
|
||||
OO_ENTER_OPENGL();
|
||||
OOSetOpenGLState(OPENGL_STATE_TRANSLUCENT_PASS);
|
||||
OOGL(glEnable(GL_BLEND));
|
||||
GLScaledLineWidth(1.0);
|
||||
|
||||
OOGL(glColor4f(0.0, 0.0, 1.0, a));
|
||||
OOGLBEGIN(GL_LINES);
|
||||
for (i = -1; i <= 1; i+=2)
|
||||
{
|
||||
for (j = -1; j <= 1; j+=2)
|
||||
{
|
||||
for (k = -1; k <= 1; k+=2)
|
||||
{
|
||||
glVertex3f(i*s0,j*s0,k*s1); glVertex3f(i*s0,j*s1,k*s0);
|
||||
glVertex3f(i*s0,j*s1,k*s0); glVertex3f(i*s1,j*s0,k*s0);
|
||||
glVertex3f(i*s1,j*s0,k*s0); glVertex3f(i*s0,j*s0,k*s1);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (s1 > 20.0)
|
||||
{
|
||||
glVertex3f(-20.0,0,-s1-20.0); glVertex3f(0,0,-s1);
|
||||
glVertex3f(20.0,0,-s1-20.0); glVertex3f(0,0,-s1);
|
||||
glVertex3f(-20.0,0,s1-20.0); glVertex3f(0,0,s1);
|
||||
glVertex3f(20.0,0,s1-20.0); glVertex3f(0,0,s1);
|
||||
s1 *= 0.5;
|
||||
}
|
||||
OOGLEND();
|
||||
|
||||
OOGL(glDisable(GL_BLEND));
|
||||
OOVerifyOpenGLState();
|
||||
}
|
||||
|
||||
|
||||
/* beacons */
|
||||
|
||||
- (NSComparisonResult) compareBeaconCodeWith:(Entity<OOBeaconEntity> *) other
|
||||
{
|
||||
return [[self beaconCode] compare:[other beaconCode] options: NSCaseInsensitiveSearch];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) beaconCode
|
||||
{
|
||||
return _beaconCode;
|
||||
}
|
||||
|
||||
|
||||
- (void) setBeaconCode:(NSString *)bcode
|
||||
{
|
||||
if ([bcode length] == 0) bcode = nil;
|
||||
|
||||
if (_beaconCode != bcode)
|
||||
{
|
||||
[_beaconCode release];
|
||||
_beaconCode = [bcode copy];
|
||||
|
||||
DESTROY(_beaconDrawable);
|
||||
}
|
||||
// if not blanking code and label is currently blank, default label to code
|
||||
if (bcode != nil && (_beaconLabel == nil || [_beaconLabel length] == 0))
|
||||
{
|
||||
[self setBeaconLabel:bcode];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (NSString *) beaconLabel
|
||||
{
|
||||
return _beaconLabel;
|
||||
}
|
||||
|
||||
|
||||
- (void) setBeaconLabel:(NSString *)blabel
|
||||
{
|
||||
if ([blabel length] == 0) blabel = nil;
|
||||
|
||||
if (_beaconLabel != blabel)
|
||||
{
|
||||
[_beaconLabel release];
|
||||
_beaconLabel = [OOExpand(blabel) retain];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) isBeacon
|
||||
{
|
||||
return [self beaconCode] != nil;
|
||||
}
|
||||
|
||||
|
||||
- (id <OOHUDBeaconIcon>) beaconDrawable
|
||||
{
|
||||
if (_beaconDrawable == nil)
|
||||
{
|
||||
NSString *beaconCode = [self beaconCode];
|
||||
NSUInteger length = [beaconCode length];
|
||||
|
||||
if (length > 1)
|
||||
{
|
||||
NSArray *iconData = [[UNIVERSE descriptions] oo_arrayForKey:beaconCode];
|
||||
if (iconData != nil) _beaconDrawable = [[OOPolygonSprite alloc] initWithDataArray:iconData outlineWidth:0.5 name:beaconCode];
|
||||
}
|
||||
|
||||
if (_beaconDrawable == nil)
|
||||
{
|
||||
if (length > 0) _beaconDrawable = [[beaconCode substringToIndex:1] retain];
|
||||
else _beaconDrawable = @"";
|
||||
}
|
||||
}
|
||||
|
||||
return _beaconDrawable;
|
||||
}
|
||||
|
||||
|
||||
- (Entity <OOBeaconEntity> *) prevBeacon
|
||||
{
|
||||
return [_prevBeacon weakRefUnderlyingObject];
|
||||
}
|
||||
|
||||
|
||||
- (Entity <OOBeaconEntity> *) nextBeacon
|
||||
{
|
||||
return [_nextBeacon weakRefUnderlyingObject];
|
||||
}
|
||||
|
||||
|
||||
- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip
|
||||
{
|
||||
if (beaconShip != [self prevBeacon])
|
||||
{
|
||||
[_prevBeacon release];
|
||||
_prevBeacon = [beaconShip weakRetain];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip
|
||||
{
|
||||
if (beaconShip != [self nextBeacon])
|
||||
{
|
||||
[_nextBeacon release];
|
||||
_nextBeacon = [beaconShip weakRetain];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) isJammingScanning
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -399,7 +399,7 @@ typedef enum
|
|||
unsigned ship_kills;
|
||||
|
||||
OOCompassMode compassMode;
|
||||
OOWeakReference *compassTarget;
|
||||
OOWeakReference *compassTarget;
|
||||
|
||||
GLfloat fuel_leak_rate;
|
||||
|
||||
|
|
|
@ -1753,7 +1753,7 @@ static GLfloat sBaseMass = 0.0;
|
|||
|
||||
[self removeAllEquipment];
|
||||
[self addEquipmentFromCollection:[shipDict objectForKey:@"extra_equipment"]];
|
||||
|
||||
|
||||
[self resetHud];
|
||||
[hud setHidden:NO];
|
||||
|
||||
|
|
|
@ -511,14 +511,6 @@ typedef enum
|
|||
- (HPVector)absoluteTractorPosition;
|
||||
|
||||
// beacons // definitions now in <OOBeaconEntity> protocol
|
||||
/*- (NSString *) beaconCode;
|
||||
- (void) setBeaconCode:(NSString *)bcode;
|
||||
- (BOOL) isBeacon;
|
||||
- (id <OOHUDBeaconIcon>) beaconDrawable;
|
||||
- (ShipEntity *) prevBeacon;
|
||||
- (ShipEntity *) nextBeacon;
|
||||
- (void) setPrevBeacon:(ShipEntity*) beaconShip;
|
||||
- (void) setNextBeacon:(ShipEntity*) beaconShip; */
|
||||
|
||||
- (void) setIsBoulder:(BOOL)flag;
|
||||
- (BOOL) isBoulder;
|
||||
|
|
|
@ -30,6 +30,7 @@ MA 02110-1301, USA.
|
|||
#import "StationEntity.h"
|
||||
#import "OOVisualEffectEntity.h"
|
||||
#import "OOQuiriumCascadeEntity.h"
|
||||
#import "OOWaypointEntity.h"
|
||||
#import "Universe.h"
|
||||
#import "OOTrumble.h"
|
||||
#import "OOColor.h"
|
||||
|
@ -83,6 +84,7 @@ static void hudDrawBarAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz, GLfloat am
|
|||
static void hudDrawSurroundAt(GLfloat x, GLfloat y, GLfloat z, NSSize siz);
|
||||
static void hudDrawStatusIconAt(int x, int y, int z, NSSize siz);
|
||||
static void hudDrawReticleOnTarget(Entity* target, PlayerEntity* player1, GLfloat z1, GLfloat alpha, BOOL reticleTargetSensitive, NSMutableDictionary *propertiesReticleTargetSensitive, BOOL colourFromScannerColour, BOOL showText);
|
||||
static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL selected);
|
||||
static void drawScannerGrid(GLfloat x, GLfloat y, GLfloat z, NSSize siz, int v_dir, GLfloat thickness, GLfloat zoom);
|
||||
|
||||
|
||||
|
@ -130,6 +132,7 @@ enum
|
|||
- (void) drawMissileDisplay:(NSDictionary *)info;
|
||||
- (void) drawTargetReticle:(NSDictionary *)info;
|
||||
- (void) drawSecondaryTargetReticle:(NSDictionary *)info;
|
||||
- (void) drawWaypoints:(NSDictionary *)info;
|
||||
- (void) drawStatusLight:(NSDictionary *)info;
|
||||
- (void) drawDirectionCue:(NSDictionary *)info;
|
||||
- (void) drawClock:(NSDictionary *)info;
|
||||
|
@ -2324,6 +2327,21 @@ static OOPolygonSprite *IconForMissileRole(NSString *role)
|
|||
}
|
||||
|
||||
|
||||
- (void) drawWaypoints:(NSDictionary *)info
|
||||
{
|
||||
GLfloat alpha = [info oo_nonNegativeFloatForKey:ALPHA_KEY defaultValue:1.0f] * overallAlpha;
|
||||
|
||||
NSEnumerator *waypoints = [[UNIVERSE currentWaypoints] objectEnumerator];
|
||||
OOWaypointEntity *waypoint = nil;
|
||||
Entity *compass = [PLAYER compassTarget];
|
||||
while ((waypoint = [waypoints nextObject]))
|
||||
{
|
||||
hudDrawWaypoint(waypoint, PLAYER, z1, alpha, waypoint==compass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (void) drawStatusLight:(NSDictionary *)info
|
||||
{
|
||||
int x, y;
|
||||
|
@ -3218,6 +3236,106 @@ static void hudDrawReticleOnTarget(Entity *target, PlayerEntity *player1, GLfloa
|
|||
}
|
||||
|
||||
|
||||
static void hudDrawWaypoint(OOWaypointEntity *waypoint, PlayerEntity *player1, GLfloat z1, GLfloat alpha, BOOL selected)
|
||||
{
|
||||
if ([player1 guiScreen] != GUI_SCREEN_MAIN) // don't draw on text screens
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OOMatrix back_mat;
|
||||
Quaternion back_q = [player1 orientation];
|
||||
back_q.w = -back_q.w; // invert
|
||||
Vector v1 = vector_up_from_quaternion(back_q);
|
||||
Vector p1;
|
||||
|
||||
// either close enough that single precision is fine or far enough
|
||||
// away that precision is irrelevant
|
||||
p1 = HPVectorToVector(HPvector_subtract([waypoint position], [player1 viewpointPosition]));
|
||||
|
||||
GLfloat rdist = magnitude(p1);
|
||||
GLfloat rsize = rdist * ONE_SIXTYFOURTH;
|
||||
|
||||
GLfloat rs0 = rsize;
|
||||
GLfloat rs2 = rsize * 0.50;
|
||||
|
||||
OOGL(glPushMatrix());
|
||||
|
||||
/* TODO: A lot of this code is common with
|
||||
* drawTargetReticle. Split out to separate function */
|
||||
|
||||
// deal with view directions
|
||||
Vector view_dir, view_up = kBasisYVector;
|
||||
switch ([UNIVERSE viewDirection])
|
||||
{
|
||||
default:
|
||||
case VIEW_FORWARD:
|
||||
view_dir.x = 0.0; view_dir.y = 0.0; view_dir.z = 1.0;
|
||||
break;
|
||||
|
||||
case VIEW_AFT:
|
||||
view_dir.x = 0.0; view_dir.y = 0.0; view_dir.z = -1.0;
|
||||
quaternion_rotate_about_axis(&back_q, v1, M_PI);
|
||||
break;
|
||||
|
||||
case VIEW_PORT:
|
||||
view_dir.x = -1.0; view_dir.y = 0.0; view_dir.z = 0.0;
|
||||
quaternion_rotate_about_axis(&back_q, v1, 0.5 * M_PI);
|
||||
break;
|
||||
|
||||
case VIEW_STARBOARD:
|
||||
view_dir.x = 1.0; view_dir.y = 0.0; view_dir.z = 0.0;
|
||||
quaternion_rotate_about_axis(&back_q, v1, -0.5 * M_PI);
|
||||
break;
|
||||
|
||||
case VIEW_CUSTOM:
|
||||
view_dir = [player1 customViewForwardVector];
|
||||
view_up = [player1 customViewUpVector];
|
||||
back_q = quaternion_multiply([player1 customViewQuaternion], back_q);
|
||||
break;
|
||||
}
|
||||
OOGL(gluLookAt(view_dir.x, view_dir.y, view_dir.z, 0.0, 0.0, 0.0, view_up.x, view_up.y, view_up.z));
|
||||
|
||||
back_mat = OOMatrixForQuaternionRotation(back_q);
|
||||
|
||||
// rotate the view
|
||||
GLMultOOMatrix([player1 rotationMatrix]);
|
||||
// translate the view
|
||||
OOGL(glTranslatef(p1.x, p1.y, p1.z));
|
||||
//rotate to face player1
|
||||
GLMultOOMatrix(back_mat);
|
||||
// draw the waypoint
|
||||
|
||||
if (selected)
|
||||
{
|
||||
GLColorWithOverallAlpha(blue_color, alpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
GLColorWithOverallAlpha(blue_color, alpha*0.25);
|
||||
}
|
||||
|
||||
OOGLBEGIN(GL_LINES);
|
||||
glVertex2f(rs0,rs2); glVertex2f(rs2,rs2);
|
||||
glVertex2f(rs2,rs0); glVertex2f(rs2,rs2);
|
||||
|
||||
glVertex2f(-rs0,rs2); glVertex2f(-rs2,rs2);
|
||||
glVertex2f(-rs2,rs0); glVertex2f(-rs2,rs2);
|
||||
|
||||
glVertex2f(-rs0,-rs2); glVertex2f(-rs2,-rs2);
|
||||
glVertex2f(-rs2,-rs0); glVertex2f(-rs2,-rs2);
|
||||
|
||||
glVertex2f(rs0,-rs2); glVertex2f(rs2,-rs2);
|
||||
glVertex2f(rs2,-rs0); glVertex2f(rs2,-rs2);
|
||||
|
||||
// glVertex2f(0,-rs2); glVertex2f(0,rs2);
|
||||
// glVertex2f(rs2,0); glVertex2f(-rs2,0);
|
||||
OOGLEND();
|
||||
|
||||
OOGL(glPopMatrix());
|
||||
}
|
||||
|
||||
|
||||
static void InitTextEngine(void)
|
||||
{
|
||||
NSDictionary *fontSpec = nil;
|
||||
|
|
|
@ -76,6 +76,7 @@ static JSBool SystemAddShipsToRoute(JSContext *context, uintN argc, jsval *vp);
|
|||
static JSBool SystemAddGroupToRoute(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool SystemAddVisualEffect(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool SystemSetPopulator(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool SystemSetWaypoint(JSContext *context, uintN argc, jsval *vp);
|
||||
|
||||
static JSBool SystemLegacyAddShips(JSContext *context, uintN argc, jsval *vp);
|
||||
static JSBool SystemLegacyAddSystemShips(JSContext *context, uintN argc, jsval *vp);
|
||||
|
@ -189,7 +190,8 @@ static JSFunctionSpec sSystemMethods[] =
|
|||
{ "locationFromCode", SystemLocationFromCode, 1 },
|
||||
// scrambledPseudoRandomNumber is implemented in oolite-global-prefix.js
|
||||
{ "sendAllShipsAway", SystemSendAllShipsAway, 1 },
|
||||
{ "setPopulator", SystemSetPopulator, 2 },
|
||||
{ "setPopulator", SystemSetPopulator, 2 },
|
||||
{ "setWaypoint", SystemSetWaypoint, 2 },
|
||||
{ "shipsWithPrimaryRole", SystemShipsWithPrimaryRole, 1 },
|
||||
{ "shipsWithRole", SystemShipsWithRole, 1 },
|
||||
|
||||
|
@ -1305,6 +1307,49 @@ static JSBool SystemSetPopulator(JSContext *context, uintN argc, jsval *vp)
|
|||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
|
||||
static JSBool SystemSetWaypoint(JSContext *context, uintN argc, jsval *vp)
|
||||
{
|
||||
OOJS_NATIVE_ENTER(context)
|
||||
|
||||
NSString *key;
|
||||
NSMutableDictionary *settings;
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
OOJSReportBadArguments(context, @"System", @"setWaypoint", MIN(argc, 0U), &OOJS_ARGV[0], nil, @"string (key), object (definition)");
|
||||
return NO;
|
||||
}
|
||||
key = OOStringFromJSValue(context, OOJS_ARGV[0]);
|
||||
if (key == nil)
|
||||
{
|
||||
OOJSReportBadArguments(context, @"System", @"setWaypoint", MIN(argc, 0U), &OOJS_ARGV[0], nil, @"key, definition");
|
||||
return NO;
|
||||
}
|
||||
if (argc < 2 || JSVAL_IS_NULL(OOJS_ARGV[1]))
|
||||
{
|
||||
// clearing
|
||||
[UNIVERSE defineWaypoint:nil forKey:key];
|
||||
}
|
||||
else
|
||||
{
|
||||
// adding
|
||||
if (!JSVAL_IS_OBJECT(OOJS_ARGV[1]) || JSVAL_IS_NULL(OOJS_ARGV[1]))
|
||||
{
|
||||
OOJSReportBadArguments(context, @"System", @"setWaypoint", MIN(argc, 1U), OOJS_ARGV, NULL, @"key, definition");
|
||||
return NO;
|
||||
}
|
||||
|
||||
settings = OOJSNativeObjectFromJSObject(context, JSVAL_TO_OBJECT(OOJS_ARGV[1]));
|
||||
|
||||
[UNIVERSE defineWaypoint:settings forKey:key];
|
||||
}
|
||||
|
||||
OOJS_RETURN_VOID;
|
||||
|
||||
OOJS_NATIVE_EXIT
|
||||
}
|
||||
|
||||
// *** Helper functions ***
|
||||
|
||||
// Shared implementation of addShips() and addGroup().
|
||||
|
|
|
@ -44,7 +44,7 @@ MA 02110-1301, USA.
|
|||
@class GameController, CollisionRegion, MyOpenGLView, GuiDisplayGen,
|
||||
Entity, ShipEntity, StationEntity, OOPlanetEntity, OOSunEntity,
|
||||
OOVisualEffectEntity, PlayerEntity, OORoleSet, WormholeEntity,
|
||||
DockEntity, OOJSScript;
|
||||
DockEntity, OOJSScript, OOWaypointEntity;
|
||||
|
||||
|
||||
typedef BOOL (*EntityFilterPredicate)(Entity *entity, void *parameter);
|
||||
|
@ -195,7 +195,8 @@ enum
|
|||
|
||||
OOWeakReference *_firstBeacon,
|
||||
*_lastBeacon;
|
||||
|
||||
NSMutableDictionary *waypoints;
|
||||
|
||||
GLfloat skyClearColor[4];
|
||||
|
||||
NSString *currentMessage;
|
||||
|
@ -424,6 +425,9 @@ enum
|
|||
- (void) setNextBeacon:(Entity <OOBeaconEntity> *) beaconShip;
|
||||
- (void) clearBeacon:(Entity <OOBeaconEntity> *) beaconShip;
|
||||
|
||||
- (NSDictionary *) currentWaypoints;
|
||||
- (void) defineWaypoint:(NSDictionary *)definition forKey:(NSString *)key;
|
||||
|
||||
- (GLfloat *) skyClearColor;
|
||||
// Note: the alpha value is also air resistance!
|
||||
- (void) setSkyColorRed:(GLfloat)red green:(GLfloat)green blue:(GLfloat)blue alpha:(GLfloat)alpha;
|
||||
|
|
|
@ -65,6 +65,7 @@ MA 02110-1301, USA.
|
|||
#import "DustEntity.h"
|
||||
#import "OOPlanetEntity.h"
|
||||
#import "OOVisualEffectEntity.h"
|
||||
#import "OOWaypointEntity.h"
|
||||
#import "OOSunEntity.h"
|
||||
#import "WormholeEntity.h"
|
||||
#import "OOBreakPatternEntity.h"
|
||||
|
@ -341,6 +342,8 @@ GLfloat docked_light_specular[4] = { DOCKED_ILLUM_LEVEL, DOCKED_ILLUM_LEVEL, DOC
|
|||
missiontext = [[ResourceManager dictionaryFromFilesNamed:@"missiontext.plist" inFolder:@"Config" andMerge:YES] retain];
|
||||
|
||||
demo_ships = [[OOShipRegistry sharedRegistry] demoShipKeys];
|
||||
|
||||
waypoints = [[NSMutableDictionary alloc] init];
|
||||
|
||||
[self setUpSettings];
|
||||
|
||||
|
@ -426,6 +429,7 @@ GLfloat docked_light_specular[4] = { DOCKED_ILLUM_LEVEL, DOCKED_ILLUM_LEVEL, DOC
|
|||
|
||||
DESTROY(_firstBeacon);
|
||||
DESTROY(_lastBeacon);
|
||||
DESTROY(waypoints);
|
||||
|
||||
unsigned i;
|
||||
for (i = 0; i < 256; i++) [system_names[i] release];
|
||||
|
@ -2944,6 +2948,33 @@ static BOOL IsFriendlyStationPredicate(Entity *entity, void *parameter)
|
|||
}
|
||||
|
||||
|
||||
- (NSDictionary *) currentWaypoints
|
||||
{
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
|
||||
- (void) defineWaypoint:(NSDictionary *)definition forKey:(NSString *)key
|
||||
{
|
||||
OOWaypointEntity *waypoint = nil;
|
||||
waypoint = [waypoints objectForKey:key];
|
||||
if (waypoint != nil)
|
||||
{
|
||||
[self removeEntity:waypoint];
|
||||
[waypoints removeObjectForKey:key];
|
||||
}
|
||||
if (definition != nil)
|
||||
{
|
||||
waypoint = [OOWaypointEntity waypointWithDictionary:definition];
|
||||
if (waypoint != nil)
|
||||
{
|
||||
[self addEntity:waypoint];
|
||||
[waypoints setObject:waypoint forKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (GLfloat *) skyClearColor
|
||||
{
|
||||
return skyClearColor;
|
||||
|
@ -4550,6 +4581,7 @@ static BOOL MaintainLinkedLists(Universe *uni)
|
|||
{
|
||||
ShipEntity *se = nil;
|
||||
OOVisualEffectEntity *ve = nil;
|
||||
OOWaypointEntity *wp = nil;
|
||||
|
||||
if (![entity validForAddToUniverse]) return NO;
|
||||
|
||||
|
@ -4638,6 +4670,14 @@ static BOOL MaintainLinkedLists(Universe *uni)
|
|||
[self setNextBeacon:ve];
|
||||
}
|
||||
}
|
||||
else if ([entity isWaypoint])
|
||||
{
|
||||
wp = (OOWaypointEntity *)entity;
|
||||
if ([wp isBeacon])
|
||||
{
|
||||
[self setNextBeacon:wp];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lighting considerations
|
||||
|
@ -4766,6 +4806,7 @@ static BOOL MaintainLinkedLists(Universe *uni)
|
|||
closeSystems = nil;
|
||||
|
||||
[self resetBeacons];
|
||||
[waypoints removeAllObjects];
|
||||
|
||||
no_update = updating; // restore drawing
|
||||
}
|
||||
|
@ -9861,6 +9902,16 @@ Entity *gOOJSPlayerIfStale = nil;
|
|||
ShipEntity *se = (ShipEntity*)entity;
|
||||
[self clearBeacon:se];
|
||||
}
|
||||
if ([entity isWaypoint])
|
||||
{
|
||||
OOWaypointEntity *wp = (OOWaypointEntity*)entity;
|
||||
[self clearBeacon:wp];
|
||||
}
|
||||
if ([entity isVisualEffect])
|
||||
{
|
||||
OOVisualEffectEntity *ve = (OOVisualEffectEntity*)entity;
|
||||
[self clearBeacon:ve];
|
||||
}
|
||||
|
||||
if ([entity isWormhole])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue