Oolite
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,
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 NSUInteger lastDrawCounter;
154
155@private
156 NSUInteger _sessionID;
157
160}
161
162// The session in which the entity was created.
163- (NSUInteger) sessionID;
164
165- (BOOL) isShip;
166- (BOOL) isDock;
167- (BOOL) isStation;
168- (BOOL) isSubEntity;
169- (BOOL) isPlayer;
170- (BOOL) isPlanet;
171- (BOOL) isSun;
172- (BOOL) isSunlit;
173- (BOOL) isStellarObject;
174- (BOOL) isSky;
175- (BOOL) isWormhole;
176- (BOOL) isEffect;
177- (BOOL) isVisualEffect;
178- (BOOL) isWaypoint;
179
180- (BOOL) validForAddToUniverse;
181- (void) addToLinkedLists;
182- (void) removeFromLinkedLists;
183
184- (void) updateLinkedLists;
185
186- (void) wasAddedToUniverse;
187- (void) wasRemovedFromUniverse;
188
189- (void) warnAboutHostiles;
190
191- (CollisionRegion *) collisionRegion;
192- (void) setCollisionRegion:(CollisionRegion*)region;
193
194- (void) setUniversalID:(OOUniversalID)uid;
195- (OOUniversalID) universalID;
196
197- (BOOL) throwingSparks;
198- (void) setThrowSparks:(BOOL)value;
199- (void) throwSparks;
200
201- (void) setOwner:(Entity *)ent;
202- (id) owner;
203- (ShipEntity *) parentEntity; // owner if self is subentity of owner, otherwise nil.
204- (ShipEntity *) rootShipEntity; // like parentEntity, but recursive.
205
206- (void) setPosition:(HPVector)posn;
207- (void) setPositionX:(OOHPScalar)x y:(OOHPScalar)y z:(OOHPScalar)z;
208- (HPVector) position;
209- (Vector) cameraRelativePosition;
210- (GLfloat) cameraRangeFront;
211- (GLfloat) cameraRangeBack;
212
213- (void) updateCameraRelativePosition;
214// gets a low-position relative vector
215- (Vector) vectorTo:(Entity *)entity;
216
217- (HPVector) absolutePositionForSubentity;
218- (HPVector) absolutePositionForSubentityOffset:(HPVector) offset;
219
220- (double) zeroDistance;
221- (double) camZeroDistance;
222- (NSComparisonResult) compareZeroDistance:(Entity *)otherEntity;
223
224- (BoundingBox) boundingBox;
225
226- (GLfloat) mass;
227
228- (Quaternion) orientation;
229- (void) setOrientation:(Quaternion) quat;
230- (Quaternion) normalOrientation; // Historical wart: orientation.w is reversed for player; -normalOrientation corrects this.
231- (void) setNormalOrientation:(Quaternion) quat;
232- (void) orientationChanged;
233
234- (void) setVelocity:(Vector)vel;
235- (Vector) velocity;
236- (double) speed;
237
238- (GLfloat) distanceTravelled;
239- (void) setDistanceTravelled:(GLfloat)value;
240
241
242- (void) setStatus:(OOEntityStatus)stat;
243- (OOEntityStatus) status;
244
245- (void) setScanClass:(OOScanClass)sClass;
246- (OOScanClass) scanClass;
247
248- (void) setEnergy:(GLfloat)amount;
249- (GLfloat) energy;
250
251- (void) setMaxEnergy:(GLfloat)amount;
252- (GLfloat) maxEnergy;
253
254- (void) applyRoll:(GLfloat)roll andClimb:(GLfloat)climb;
255- (void) applyRoll:(GLfloat)roll climb:(GLfloat) climb andYaw:(GLfloat)yaw;
256- (void) moveForward:(double)amount;
257
258- (OOMatrix) rotationMatrix;
259- (OOMatrix) drawRotationMatrix;
260- (OOMatrix) transformationMatrix;
261- (OOMatrix) drawTransformationMatrix;
262
263- (BOOL) canCollide;
264- (GLfloat) collisionRadius;
265- (GLfloat) frustumRadius;
266- (void) setCollisionRadius:(GLfloat)amount;
267- (NSMutableArray *)collisionArray;
268
269- (void) update:(OOTimeDelta)delta_t;
270
271- (void) applyVelocity:(OOTimeDelta)delta_t;
272- (BOOL) checkCloseCollisionWith:(Entity *)other;
273
274- (void) takeEnergyDamage:(double)amount from:(Entity *)ent becauseOf:(Entity *)other weaponIdentifier:(NSString *)weaponIdentifier;
275
276- (void) dumpState; // General "describe situtation verbosely in log" command.
277- (void) dumpSelfState; // Subclasses should override this, not -dumpState, and call throught to super first.
278
279- (NSUInteger) lastDrawCounter;
280- (void) setLastDrawCounter: (NSUInteger) drawCounter;
281
282// Subclass repsonsibilities
283- (double) findCollisionRadius;
284- (void) drawImmediate:(bool)immediate translucent:(bool)translucent;
285- (BOOL) isVisible;
286- (BOOL) isInSpace;
287- (BOOL) isImmuneToBreakPatternHide;
288
289// For shader bindings.
290- (GLfloat) universalTime;
291- (GLfloat) spawnTime;
292- (GLfloat) timeElapsedSinceSpawn;
293- (void) setAtmosphereFogging: (OOColor *) fogging;
294- (OOColor *) fogUniform;
295
296#ifndef NDEBUG
297- (NSString *) descriptionForObjDumpBasic;
298- (NSString *) descriptionForObjDump;
299
300- (NSSet *) allTextures;
301#endif
302
303@end
304
305@protocol OOHUDBeaconIcon;
306
307// Methods that must be supported by entities with beacons, regardless of type.
308@protocol OOBeaconEntity
309
310- (NSComparisonResult) compareBeaconCodeWith:(Entity <OOBeaconEntity>*) other;
311- (NSString *) beaconCode;
312- (void) setBeaconCode:(NSString *)bcode;
313- (NSString *) beaconLabel;
314- (void) setBeaconLabel:(NSString *)blabel;
315- (BOOL) isBeacon;
316- (id <OOHUDBeaconIcon>) beaconDrawable;
317- (Entity <OOBeaconEntity> *) prevBeacon;
318- (Entity <OOBeaconEntity> *) nextBeacon;
319- (void) setPrevBeacon:(Entity <OOBeaconEntity> *)beaconShip;
320- (void) setNextBeacon:(Entity <OOBeaconEntity> *)beaconShip;
321- (BOOL) isJammingScanning;
322
323@end
324
325
326enum
327{
328 // Values used for unknown strings.
329 kOOEntityStatusDefault = STATUS_INACTIVE,
330 kOOScanClassDefault = CLASS_NOT_SET
332
335
336NSString *OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC;
uint32_t gLiveEntityCount
Definition Entity.m:43
OOEntityStatus
Definition Entity.h:60
size_t gTotalEntityMemory
Definition Entity.m:44
OOEntityStatus OOEntityStatusFromString(NSString *string) PURE_FUNC
OOScanClass OOScanClassFromString(NSString *string) PURE_FUNC
@ kOOScanClassDefault
Definition Entity.h:330
@ kOOEntityStatusDefault
Definition Entity.h:329
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
OOScanClass
Definition Entity.h:71
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
#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
unsigned isImmuneToBreakPatternHide
Definition Entity.h:102
unsigned throw_sparks
Definition Entity.h:101
OOWeakReference * _owner
Definition Entity.h:158
OOColor * atmosphereFogging
Definition Entity.h:115
unsigned hasRotated
Definition Entity.h:97
GLfloat collision_radius
Definition Entity.h:111
GLfloat maxEnergy
Definition Entity.h:143
unsigned isVisualEffect
Definition Entity.h:104
CollisionRegion * collisionRegion
Definition Entity.h:130
OOUniversalID universalID
Definition Entity.h:89
Entity * z_next
Definition Entity.h:122
NSMutableArray * collidingEntities
Definition Entity.h:148
Entity * z_previous
Definition Entity.h:122
Quaternion orientation
Definition Entity.h:114
unsigned isSubEntity
Definition Entity.h:95
unsigned hasMoved
Definition Entity.h:96
int zero_index
Definition Entity.h:117
GLfloat energy
Definition Entity.h:142
GLfloat zero_distance
Definition Entity.h:108
unsigned isShip
Definition Entity.h:91
unsigned collisionTestFilter
Definition Entity.h:100
OOTimeAbsolute spawnTime
Definition Entity.h:150
unsigned hasCollided
Definition Entity.h:98
OOScanClass scanClass
Definition Entity.h:106
Entity * x_previous
Definition Entity.h:120
Vector cameraRelativePosition
Definition Entity.h:113
unsigned isWormhole
Definition Entity.h:94
GLfloat cam_zero_distance
Definition Entity.h:109
GLfloat distanceTravelled
Definition Entity.h:136
NSUInteger lastDrawCounter
Definition Entity.h:153
BoundingBox boundingBox
Definition Entity.h:145
unsigned isStation
Definition Entity.h:92
unsigned isPlayer
Definition Entity.h:93
NSUInteger _sessionID
Definition Entity.h:156
HPVector position
Definition Entity.h:112
Quaternion lastOrientation
Definition Entity.h:134
Entity * x_next
Definition Entity.h:120
struct JSObject * _jsSelf
Definition Entity.h:152
GLfloat no_draw_distance
Definition Entity.h:110
OOUniversalID shadingEntityID
Definition Entity.h:126
Vector velocity
Definition Entity.h:140
unsigned isExplicitlyNotMainStation
Definition Entity.h:103
Entity * collider
Definition Entity.h:128
Entity * collision_chain
Definition Entity.h:124
OOEntityStatus _status
Definition Entity.h:159
HPVector lastPosition
Definition Entity.h:133
OOMatrix rotMatrix
Definition Entity.h:138
Entity * y_next
Definition Entity.h:121
unsigned isSunlit
Definition Entity.h:99
Entity * y_previous
Definition Entity.h:121
GLfloat mass
Definition Entity.h:146