Oolite 1.91.0.7644-241112-7f5034b
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
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;
176- (BOOL) isVisualEffect;
177- (BOOL) isWaypoint;
178
179- (BOOL) validForAddToUniverse;
180- (void) addToLinkedLists;
181- (void) removeFromLinkedLists;
182
183- (void) updateLinkedLists;
184
185- (void) wasAddedToUniverse;
186- (void) wasRemovedFromUniverse;
187
188- (void) warnAboutHostiles;
189
190- (CollisionRegion *) collisionRegion;
191- (void) setCollisionRegion:(CollisionRegion*)region;
192
193- (void) setUniversalID:(OOUniversalID)uid;
194- (OOUniversalID) universalID;
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;
208- (Vector) cameraRelativePosition;
209- (GLfloat) cameraRangeFront;
210- (GLfloat) cameraRangeBack;
211
212- (void) updateCameraRelativePosition;
213// gets a low-position relative vector
214- (Vector) vectorTo:(Entity *)entity;
215
216- (HPVector) absolutePositionForSubentity;
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
237- (GLfloat) distanceTravelled;
238- (void) setDistanceTravelled:(GLfloat)value;
239
240
241- (void) setStatus:(OOEntityStatus)stat;
242- (OOEntityStatus) status;
243
244- (void) setScanClass:(OOScanClass)sClass;
245- (OOScanClass) scanClass;
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;
283- (BOOL) isImmuneToBreakPatternHide;
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;
317- (BOOL) isJammingScanning;
318
319@end
320
321
322enum
323{
324 // Values used for unknown strings.
325 kOOEntityStatusDefault = STATUS_INACTIVE,
326 kOOScanClassDefault = CLASS_NOT_SET
328
331
332NSString *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:326
@ kOOEntityStatusDefault
Definition Entity.h:325
NSString * OOStringFromScanClass(OOScanClass scanClass) CONST_FUNC
NSString * OOStringFromEntityStatus(OOEntityStatus status) CONST_FUNC
OOScanClass
Definition Entity.h:71
#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:157
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
BoundingBox boundingBox
Definition Entity.h:145
unsigned isStation
Definition Entity.h:92
unsigned isPlayer
Definition Entity.h:93
NSUInteger _sessionID
Definition Entity.h:155
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:158
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