Oolite 1.91.0.7650-250121-affa790
Loading...
Searching...
No Matches
Entity.h
Go to the documentation of this file.
1/*
2
3Entity.h
4
5Base class for entities, i.e. drawable world objects.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
27
28#import "OOCocoa.h"
29#import "OOMaths.h"
30#import "OOCacheManager.h"
31#import "OOTypes.h"
32#import "OOWeakReference.h"
33#import "OOColor.h"
34
36
37
38#ifndef NDEBUG
39
40extern uint32_t gLiveEntityCount;
41extern size_t gTotalEntityMemory;
42
43#endif
44
45
46#define NO_DRAW_DISTANCE_FACTOR 1024.0
47#define ABSOLUTE_NO_DRAW_DISTANCE2 (2500.0 * 2500.0 * NO_DRAW_DISTANCE_FACTOR * NO_DRAW_DISTANCE_FACTOR)
48// ie. the furthest away thing we can draw is at 1280km (a 2.5km wide object would disappear at that range)
49
50
51#define SCANNER_MAX_RANGE 25600.0
52#define SCANNER_MAX_RANGE2 655360000.0
53
54#define CLOSE_COLLISION_CHECK_MAX_RANGE2 1000000000.0
55
56
57#define ENTRY(label, value) label = value,
58
59typedef enum OOEntityStatus
60{
61 #include "OOEntityStatus.tbl"
63
64
65#ifndef OO_SCANCLASS_TYPE
66#define OO_SCANCLASS_TYPE
68#endif
69
71{
72 #include "OOScanClass.tbl"
73};
74
75#undef ENTRY
76
77
79{
80 // the base object for ships/stations/anything actually
82 //
83 // @public variables:
84 //
85 // we forego encapsulation for some variables in order to
86 // lose the overheads of Obj-C accessor methods...
87 //
88@public
89 OOUniversalID universalID; // used to reference the entity
90
91 unsigned isShip: 1,
92 isStation: 1,
93 isPlayer: 1,
94 isWormhole: 1,
95 isSubEntity: 1,
99 isSunlit: 1,
105
107
110 GLfloat no_draw_distance; // 10 km initially
112 HPVector position; // use high-precision vectors for global position
114 Quaternion orientation;
116
118
119 // Linked lists of entites, sorted by position on each (world) axis
123
125
127
129
130 CollisionRegion *collisionRegion; // initially nil - then maintained
131
132@protected
133 HPVector lastPosition;
134 Quaternion lastOrientation;
135
136 GLfloat distanceTravelled; // set to zero initially
137
138 OOMatrix rotMatrix;
139
140 Vector velocity;
141
142 GLfloat energy;
143 GLfloat maxEnergy;
144
145 BoundingBox boundingBox;
146 GLfloat mass;
147
148 NSMutableArray *collidingEntities;
149
151
152 struct JSObject *_jsSelf;
153
154@private
155 NSUInteger _sessionID;
156
159}
160
161// The session in which the entity was created.
162- (NSUInteger) sessionID;
163
164- (BOOL) isShip;
165- (BOOL) isDock;
166- (BOOL) isStation;
167- (BOOL) isSubEntity;
168- (BOOL) isPlayer;
169- (BOOL) isPlanet;
170- (BOOL) isSun;
171- (BOOL) isSunlit;
172- (BOOL) isStellarObject;
173- (BOOL) isSky;
174- (BOOL) isWormhole;
175- (BOOL) isEffect;
177- (BOOL) isWaypoint;
178
179- (BOOL) validForAddToUniverse;
180- (void) addToLinkedLists;
181- (void) removeFromLinkedLists;
182
183- (void) updateLinkedLists;
184
185- (void) wasAddedToUniverse;
187
188- (void) warnAboutHostiles;
189
191- (void) setCollisionRegion:(CollisionRegion*)region;
192
193- (void) setUniversalID:(OOUniversalID)uid;
195
196- (BOOL) throwingSparks;
197- (void) setThrowSparks:(BOOL)value;
198- (void) throwSparks;
199
200- (void) setOwner:(Entity *)ent;
201- (id) owner;
202- (ShipEntity *) parentEntity; // owner if self is subentity of owner, otherwise nil.
203- (ShipEntity *) rootShipEntity; // like parentEntity, but recursive.
204
205- (void) setPosition:(HPVector)posn;
206- (void) setPositionX:(OOHPScalar)x y:(OOHPScalar)y z:(OOHPScalar)z;
207- (HPVector) position;
209- (GLfloat) cameraRangeFront;
210- (GLfloat) cameraRangeBack;
211
213// gets a low-position relative vector
214- (Vector) vectorTo:(Entity *)entity;
215
217- (HPVector) absolutePositionForSubentityOffset:(HPVector) offset;
218
219- (double) zeroDistance;
220- (double) camZeroDistance;
221- (NSComparisonResult) compareZeroDistance:(Entity *)otherEntity;
222
223- (BoundingBox) boundingBox;
224
225- (GLfloat) mass;
226
227- (Quaternion) orientation;
228- (void) setOrientation:(Quaternion) quat;
229- (Quaternion) normalOrientation; // Historical wart: orientation.w is reversed for player; -normalOrientation corrects this.
230- (void) setNormalOrientation:(Quaternion) quat;
231- (void) orientationChanged;
232
233- (void) setVelocity:(Vector)vel;
234- (Vector) velocity;
235- (double) speed;
236
238- (void) setDistanceTravelled:(GLfloat)value;
239
240
241- (void) setStatus:(OOEntityStatus)stat;
243
244- (void) setScanClass:(OOScanClass)sClass;
246
247- (void) setEnergy:(GLfloat)amount;
248- (GLfloat) energy;
249
250- (void) setMaxEnergy:(GLfloat)amount;
251- (GLfloat) maxEnergy;
252
253- (void) applyRoll:(GLfloat)roll andClimb:(GLfloat)climb;
254- (void) applyRoll:(GLfloat)roll climb:(GLfloat) climb andYaw:(GLfloat)yaw;
255- (void) moveForward:(double)amount;
256
257- (OOMatrix) rotationMatrix;
258- (OOMatrix) drawRotationMatrix;
259- (OOMatrix) transformationMatrix;
260- (OOMatrix) drawTransformationMatrix;
261
262- (BOOL) canCollide;
263- (GLfloat) collisionRadius;
264- (GLfloat) frustumRadius;
265- (void) setCollisionRadius:(GLfloat)amount;
266- (NSMutableArray *)collisionArray;
267
268- (void) update:(OOTimeDelta)delta_t;
269
270- (void) applyVelocity:(OOTimeDelta)delta_t;
271- (BOOL) checkCloseCollisionWith:(Entity *)other;
272
273- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier;
274
275- (void) dumpState; // General "describe situtation verbosely in log" command.
276- (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first.
277
278// Subclass repsonsibilities
279- (double) findCollisionRadius;
280- (void) drawImmediate:(bool)immediate translucent:(bool)translucent;
281- (BOOL) isVisible;
282- (BOOL) isInSpace;
284
285// For shader bindings.
286- (GLfloat) universalTime;
287- (GLfloat) spawnTime;
288- (GLfloat) timeElapsedSinceSpawn;
289- (void) setAtmosphereFogging: (OOColor *) fogging;
290- (OOColor *) fogUniform;
291
292#ifndef NDEBUG
293- (NSString *) descriptionForObjDumpBasic;
294- (NSString *) descriptionForObjDump;
295
296- (NSSet *) allTextures;
297#endif
298
299@end
300
301@protocol OOHUDBeaconIcon;
302
303// Methods that must be supported by entities with beacons, regardless of type.
304@protocol OOBeaconEntity
305
306- (NSComparisonResult) compareBeaconCodeWith:(Entity <OOBeaconEntity>*) other;
307- (NSString *) beaconCode;
308- (void) setBeaconCode:(NSString *)bcode;
309- (NSString *) beaconLabel;
310- (void) setBeaconLabel:(NSString *)blabel;
311- (BOOL) isBeacon;
312- (id <OOHUDBeaconIcon>) beaconDrawable;
313- (Entity <OOBeaconEntity> *) prevBeacon;
314- (Entity <OOBeaconEntity> *) nextBeacon;
315- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip;
316- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip;
318
319@end
320
321
322enum
323{
324 // Values used for unknown strings.
325 kOOEntityStatusDefault = STATUS_INACTIVE,
326 kOOScanClassDefault = CLASS_NOT_SET
327};
328
331
332NSString *OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC;
@ kOOScanClassDefault
Definition Entity.h:326
@ kOOEntityStatusDefault
Definition Entity.h:325
OOEntityStatus
Definition Entity.h:60
OOEntityStatus OOEntityStatusFromString(NSString *string) PURE_FUNC
OOScanClass OOScanClassFromString(NSString *string) PURE_FUNC
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
OOScanClass
Definition Entity.h:71
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
uint32_t gLiveEntityCount
Definition Entity.m:43
size_t gTotalEntityMemory
Definition Entity.m:44
#define PURE_FUNC
#define CONST_FUNC
double OOHPScalar
Definition OOMaths.h:69
uint16_t OOUniversalID
Definition OOTypes.h:189
double OOTimeDelta
Definition OOTypes.h:224
double OOTimeAbsolute
Definition OOTypes.h:223
OOColor * fogUniform()
Definition Entity.m:1081
unsigned isImmuneToBreakPatternHide
Definition Entity.m:1139
unsigned throw_sparks
Definition Entity.h:101
BOOL validForAddToUniverse()
Definition Entity.m:214
void throwSparks()
Definition Entity.m:570
OOWeakReference * _owner
Definition Entity.h:157
void wasAddedToUniverse()
Definition Entity.m:514
OOColor * atmosphereFogging
Definition Entity.h:115
unsigned hasRotated
Definition Entity.h:97
void removeFromLinkedLists()
Definition Entity.m:286
GLfloat collision_radius
Definition Entity.h:111
GLfloat maxEnergy
Definition Entity.m:829
unsigned isVisualEffect
Definition Entity.m:202
GLfloat timeElapsedSinceSpawn()
Definition Entity.m:1069
CollisionRegion * collisionRegion
Definition Entity.m:533
OOUniversalID universalID
Definition Entity.m:552
HPVector absolutePositionForSubentity()
Definition Entity.m:669
Entity * z_next
Definition Entity.h:122
NSMutableArray * collisionArray()
Definition Entity.m:923
double camZeroDistance()
Definition Entity.m:698
void dumpState()
Definition Entity.m:996
NSMutableArray * collidingEntities
Definition Entity.h:148
Entity * z_previous
Definition Entity.h:122
Quaternion orientation
Definition Entity.m:732
NSString * descriptionForObjDumpBasic()
Definition Entity.m:1087
unsigned isSubEntity
Definition Entity.m:149
BOOL isSun()
Definition Entity.m:167
GLfloat cameraRangeFront()
Definition Entity.m:622
void updateCameraRelativePosition()
Definition Entity.m:663
unsigned hasMoved
Definition Entity.h:96
int zero_index
Definition Entity.h:117
GLfloat energy
Definition Entity.m:817
GLfloat zero_distance
Definition Entity.h:108
unsigned isShip
Definition Entity.m:131
unsigned collisionTestFilter
Definition Entity.h:100
OOTimeAbsolute spawnTime
Definition Entity.m:1063
double zeroDistance()
Definition Entity.m:692
GLfloat collisionRadius()
Definition Entity.m:905
unsigned hasCollided
Definition Entity.h:98
OOScanClass scanClass
Definition Entity.m:805
Entity * x_previous
Definition Entity.h:120
void wasRemovedFromUniverse()
Definition Entity.m:520
BOOL isDock()
Definition Entity.m:137
BOOL isInSpace()
Definition Entity.m:1120
void orientationChanged()
Definition Entity.m:750
NSSet * allTextures()
Definition Entity.m:1107
Vector cameraRelativePosition
Definition Entity.m:617
OOEntityStatus status()
Definition Entity.m:793
unsigned isWormhole
Definition Entity.m:190
GLfloat frustumRadius()
Definition Entity.m:911
GLfloat cam_zero_distance
Definition Entity.h:109
GLfloat distanceTravelled
Definition Entity.m:775
OOMatrix transformationMatrix()
Definition Entity.m:885
OOMatrix drawTransformationMatrix()
Definition Entity.m:892
BOOL isSky()
Definition Entity.m:185
BOOL isEffect()
Definition Entity.m:196
void updateLinkedLists()
Definition Entity.m:413
void warnAboutHostiles()
Definition Entity.m:526
ShipEntity * rootShipEntity()
Definition Entity.m:603
BoundingBox boundingBox
Definition Entity.m:713
unsigned isStation
Definition Entity.m:143
unsigned isPlayer
Definition Entity.m:155
BOOL throwingSparks()
Definition Entity.m:558
void dumpSelfState()
Definition Entity.m:1013
BOOL isVisible()
Definition Entity.m:1114
NSUInteger _sessionID
Definition Entity.h:155
HPVector position
Definition Entity.m:612
BOOL canCollide()
Definition Entity.m:899
GLfloat cameraRangeBack()
Definition Entity.m:627
Quaternion lastOrientation
Definition Entity.h:134
BOOL isWaypoint()
Definition Entity.m:208
NSString * descriptionForObjDump()
Definition Entity.m:1097
Entity * x_next
Definition Entity.h:120
struct JSObject * _jsSelf
Definition Entity.h:152
GLfloat no_draw_distance
Definition Entity.h:110
OOMatrix rotationMatrix()
Definition Entity.m:873
Quaternion normalOrientation()
Definition Entity.m:738
BOOL isStellarObject()
Definition Entity.m:179
OOUniversalID shadingEntityID
Definition Entity.h:126
Vector velocity
Definition Entity.m:763
GLfloat universalTime()
Definition Entity.m:1057
ShipEntity * parentEntity()
Definition Entity.m:589
BOOL isPlanet()
Definition Entity.m:161
unsigned isExplicitlyNotMainStation
Definition Entity.h:103
Entity * collider
Definition Entity.h:128
void addToLinkedLists()
Definition Entity.m:228
Entity * collision_chain
Definition Entity.h:124
OOEntityStatus _status
Definition Entity.h:158
HPVector lastPosition
Definition Entity.h:133
double speed()
Definition Entity.m:769
OOMatrix rotMatrix
Definition Entity.h:138
id owner()
Definition Entity.m:583
Entity * y_next
Definition Entity.h:121
unsigned isSunlit
Definition Entity.m:173
Entity * y_previous
Definition Entity.h:121
GLfloat mass
Definition Entity.m:719
double findCollisionRadius()
Definition Entity.m:977
OOMatrix drawRotationMatrix()
Definition Entity.m:879
Entity< OOBeaconEntity > * nextBeacon()
id< OOHUDBeaconIcon > beaconDrawable()
NSString * beaconCode()
Entity< OOBeaconEntity > * prevBeacon()
NSString * beaconLabel()