Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
DustEntity Class Reference

#include <DustEntity.h>

+ Inheritance diagram for DustEntity:
+ Collaboration diagram for DustEntity:

Instance Methods

(void) - setDustColor:
 
(OOColor *) - dustColor
 
(id) - init [implementation]
 
(void) - dealloc [implementation]
 
(BOOL) - canCollide [implementation]
 
(void) - updateCameraRelativePosition [implementation]
 
(void) - update: [implementation]
 
(Vector) - warpVector [implementation]
 
(void) - drawImmediate:translucent: [implementation]
 
(void) - resetGraphicsState [implementation]
 
(NSString *) - descriptionForObjDump [implementation]
 
(void) - checkShaderMode [implementation]
 
- Instance Methods inherited from Entity
(NSUInteger) - sessionID
 
(BOOL) - isShip
 
(BOOL) - isDock
 
(BOOL) - isStation
 
(BOOL) - isSubEntity
 
(BOOL) - isPlayer
 
(BOOL) - isPlanet
 
(BOOL) - isSun
 
(BOOL) - isSunlit
 
(BOOL) - isStellarObject
 
(BOOL) - isSky
 
(BOOL) - isWormhole
 
(BOOL) - isEffect
 
(BOOL) - isVisualEffect
 
(BOOL) - isWaypoint
 
(BOOL) - validForAddToUniverse
 
(void) - addToLinkedLists
 
(void) - removeFromLinkedLists
 
(void) - updateLinkedLists
 
(void) - wasAddedToUniverse
 
(void) - wasRemovedFromUniverse
 
(void) - warnAboutHostiles
 
(CollisionRegion *) - collisionRegion
 
(void) - setCollisionRegion:
 
(void) - setUniversalID:
 
(OOUniversalID- universalID
 
(BOOL) - throwingSparks
 
(void) - setThrowSparks:
 
(void) - throwSparks
 
(void) - setOwner:
 
(id) - owner
 
(ShipEntity *) - parentEntity
 
(ShipEntity *) - rootShipEntity
 
(void) - setPosition:
 
(void) - setPositionX:y:z:
 
(HPVector) - position
 
(Vector) - cameraRelativePosition
 
(GLfloat) - cameraRangeFront
 
(GLfloat) - cameraRangeBack
 
(Vector) - vectorTo:
 
(HPVector) - absolutePositionForSubentity
 
(HPVector) - absolutePositionForSubentityOffset:
 
(double) - zeroDistance
 
(double) - camZeroDistance
 
(NSComparisonResult) - compareZeroDistance:
 
(BoundingBox) - boundingBox
 
(GLfloat) - mass
 
(Quaternion) - orientation
 
(void) - setOrientation:
 
(Quaternion) - normalOrientation
 
(void) - setNormalOrientation:
 
(void) - orientationChanged
 
(void) - setVelocity:
 
(Vector) - velocity
 
(double) - speed
 
(GLfloat) - distanceTravelled
 
(void) - setDistanceTravelled:
 
(void) - setStatus:
 
(OOEntityStatus- status
 
(void) - setScanClass:
 
(OOScanClass- scanClass
 
(void) - setEnergy:
 
(GLfloat) - energy
 
(void) - setMaxEnergy:
 
(GLfloat) - maxEnergy
 
(void) - applyRoll:andClimb:
 
(void) - applyRoll:climb:andYaw:
 
(void) - moveForward:
 
(OOMatrix) - rotationMatrix
 
(OOMatrix) - drawRotationMatrix
 
(OOMatrix) - transformationMatrix
 
(OOMatrix) - drawTransformationMatrix
 
(GLfloat) - collisionRadius
 
(GLfloat) - frustumRadius
 
(void) - setCollisionRadius:
 
(NSMutableArray *) - collisionArray
 
(void) - applyVelocity:
 
(BOOL) - checkCloseCollisionWith:
 
(void) - takeEnergyDamage:from:becauseOf:weaponIdentifier:
 
(void) - dumpState
 
(void) - dumpSelfState
 
(double) - findCollisionRadius
 
(BOOL) - isVisible
 
(BOOL) - isInSpace
 
(BOOL) - isImmuneToBreakPatternHide
 
(GLfloat) - universalTime
 
(GLfloat) - spawnTime
 
(GLfloat) - timeElapsedSinceSpawn
 
(void) - setAtmosphereFogging:
 
(OOColor *) - fogUniform
 
(NSString *) - descriptionForObjDumpBasic
 
(NSSet *) - allTextures
 
(NSString *) - descriptionComponents [implementation]
 
(BOOL) - checkLinkedLists [implementation]
 
(id< OOWeakReferenceSupport >) - superShaderBindingTarget [implementation]
 
(Vector) - relativePosition [implementation]
 
(void) - subEntityReallyDied: [implementation]
 
(BOOL) - isBreakPattern
 
(void) - inspect [implementation]
 
(BOOL) - isECMBlast
 
(NSArray *) - debugInspectorModules [implementation]
 
(NSString *) - inspScanClassLine
 
(NSString *) - inspStatusLine
 
(NSString *) - inspRetainCountLine
 
(NSString *) - inspPositionLine
 
(NSString *) - inspVelocityLine
 
(NSString *) - inspOrientationLine
 
(NSString *) - inspEnergyLine
 
(NSString *) - inspOwnerLine
 
(NSString *) - inspTargetLine
 
(NSString *) - inspDescription [implementation]
 
(NSString *) - inspBasicIdentityLine [implementation]
 
(BOOL) - isExhaust
 
(BOOL) - isFlasher
 
(BOOL) - isVisibleToScripts
 
(NSString *) - oo_jsClassName
 
(void) - getJSClass:andPrototype:
 
(void) - deleteJSSelf
 
(jsval) - oo_jsValueInContext: [implementation]
 
(BOOL) - isCascadeWeapon
 
(BOOL) - isPlayerLikeShip
 
(GLfloat) - clock [implementation]
 
(unsigned) - pseudoFixedD100 [implementation]
 
(unsigned) - pseudoFixedD256 [implementation]
 
(unsigned) - systemGovernment [implementation]
 
(unsigned) - systemEconomy [implementation]
 
(unsigned) - systemTechLevel [implementation]
 
(unsigned) - systemPopulation [implementation]
 
(unsigned) - systemProductivity [implementation]
 
(BOOL) - isShipWithSubEntityShip:
 
(void) - drawSubEntityImmediate:translucent: [implementation]
 
- Instance Methods inherited from OOWeakRefObject
(id) - weakSelf
 
(id) - weakRetain [implementation]
 
(void) - weakRefDied: [implementation]
 
- Instance Methods inherited from <OOWeakReferenceSupport>
(id) - OO_RETURNS_RETAINED
 

Private Attributes

OOColordust_color
 
Vector vertices [DUST_N_PARTICLES *2]
 
GLushort indices [DUST_N_PARTICLES *2]
 
GLfloat color_fv [4]
 
OOTexturetexture
 
bool hasPointSprites
 

Additional Inherited Members

- Public Attributes inherited from Entity
OOUniversalID universalID
 
unsigned isShip: 1
 
unsigned isStation: 1
 
unsigned isPlayer: 1
 
unsigned isWormhole: 1
 
unsigned isSubEntity: 1
 
unsigned hasMoved: 1
 
unsigned hasRotated: 1
 
unsigned hasCollided: 1
 
unsigned isSunlit: 1
 
unsigned collisionTestFilter: 2
 
unsigned throw_sparks: 1
 
unsigned isImmuneToBreakPatternHide: 1
 
unsigned isExplicitlyNotMainStation: 1
 
unsigned isVisualEffect: 1
 
OOScanClass scanClass
 
GLfloat zero_distance
 
GLfloat cam_zero_distance
 
GLfloat no_draw_distance
 
GLfloat collision_radius
 
HPVector position
 
Vector cameraRelativePosition
 
Quaternion orientation
 
OOColoratmosphereFogging
 
int zero_index
 
Entityx_previous
 
Entityx_next
 
Entityy_previous
 
Entityy_next
 
Entityz_previous
 
Entityz_next
 
Entitycollision_chain
 
OOUniversalID shadingEntityID
 
Entitycollider
 
CollisionRegioncollisionRegion
 
- Protected Attributes inherited from Entity
HPVector lastPosition
 
Quaternion lastOrientation
 
GLfloat distanceTravelled
 
OOMatrix rotMatrix
 
Vector velocity
 
GLfloat energy
 
GLfloat maxEnergy
 
BoundingBox boundingBox
 
GLfloat mass
 
NSMutableArray * collidingEntities
 
OOTimeAbsolute spawnTime
 
struct JSObject * _jsSelf
 
- Protected Attributes inherited from OOWeakRefObject
OOWeakReferenceweakSelf
 

Detailed Description

Definition at line 37 of file DustEntity.h.

Method Documentation

◆ canCollide

- (BOOL) canCollide
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

149{
150 return NO;
151}

◆ checkShaderMode

- (void) checkShaderMode
implementation

Provided by category DustEntity(Private).

◆ dealloc

- (void) dealloc
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

120{
123
125#if OO_SHADERS
126 DESTROY(shader);
127 DESTROY(uniforms);
128#endif
129
130 [super dealloc];
131}
#define DESTROY(x)
Definition OOCocoa.h:77
OOColor * dust_color
Definition DustEntity.h:40
OOTexture * texture
Definition DustEntity.h:44
void unregisterClient:(id< OOGraphicsResetClient > client)
OOGraphicsResetManager * sharedManager()

◆ descriptionForObjDump

- (NSString *) descriptionForObjDump
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

445{
446 // Don't include range and visibility flag as they're irrelevant.
447 return [self descriptionForObjDumpBasic];
448}

◆ drawImmediate:translucent:

- (void) drawImmediate: (bool) immediate
translucent: (bool) translucent 
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

267 :(bool)immediate translucent:(bool)translucent
268{
269 if ([UNIVERSE breakPatternHide] || !translucent) return; // DON'T DRAW
270
271 PlayerEntity* player = PLAYER;
272 assert(player != nil);
273
274#ifndef NDEBUG
275 if (gDebugFlags & DEBUG_NO_DUST) return;
276#endif
277
278#if OO_SHADERS
279 if (EXPECT_NOT(shaderMode == kShaderModeUnknown)) [self checkShaderMode];
280 BOOL useShader = (shaderMode == kShaderModeOn);
281#endif
282
283
284 GLfloat *fogcolor = [UNIVERSE skyClearColor];
285 float idealDustSize = [[UNIVERSE gameView] viewSize].width / 800.0f;
286
287 BOOL warp_stars = [player atHyperspeed];
288 float dustIntensity;
289
292 OOGL(glDisableClientState(GL_NORMAL_ARRAY));
293
294 if (!warp_stars)
295 {
296 // Draw points.
297 float dustPointSize = ceil(idealDustSize);
298 if (dustPointSize < 1.0f) dustPointSize = 1.0f;
299 OOGL(GLScaledPointSize(dustPointSize));
300 dustIntensity = OOClamp_0_1_f(idealDustSize / dustPointSize);
301 }
302 else
303 {
304 // Draw lines.
305 float idealLineSize = idealDustSize * 0.5f;
306 float dustLineSize = ceil(idealLineSize);
307 if (dustLineSize < 1.0f) dustLineSize = 1.0f;
308 GLScaledLineWidth(dustLineSize);
309 dustIntensity = OOClamp_0_1_f(idealLineSize / dustLineSize);
310 }
311 if (fogcolor[3] > 0.0)
312 {
313 // fade out dust when entering atmosphere (issue #100)
314 dustIntensity = OOClamp_0_1_f(dustIntensity-(fogcolor[3]*3.0));
315 }
316
317
318 if (dustIntensity > 0.0)
319 {
320
321 float *color = NULL;
322 if (player->isSunlit) color = color_fv;
323 else color = UNIVERSE->stars_ambient;
324 OOGL(glColor4f(color[0], color[1], color[2], dustIntensity));
325
326#if OO_SHADERS
327 if (useShader)
328 {
329 [[self shader] apply];
330 [uniforms makeObjectsPerformSelector:@selector(apply)];
331 }
332 else
333#endif
334 {
335 OOGL(glEnable(GL_FOG));
336 OOGL(glFogi(GL_FOG_MODE, GL_LINEAR));
337 OOGL(glFogfv(GL_FOG_COLOR, fogcolor));
338 OOGL(glHint(GL_FOG_HINT, GL_NICEST));
339 OOGL(glFogf(GL_FOG_START, NEAR_PLANE));
340 OOGL(glFogf(GL_FOG_END, FAR_PLANE));
341 }
342
343 OOGL(glEnable(GL_BLEND));
344 OOGL(glDepthMask(GL_FALSE));
345
346 if (warp_stars)
347 {
348 OOGL(glDisable(GL_TEXTURE_2D));
349#if OO_SHADERS
350 if (useShader)
351 {
352 OOGL(glEnableVertexAttribArrayARB(kTangentAttributeIndex));
353 OOGL(glVertexAttribPointerARB(kTangentAttributeIndex, 1, GL_FLOAT, GL_FALSE, 0, warpinessAttr));
354 }
355 else
356#endif
357 {
358 Vector warpVector = [self warpVector];
359 unsigned vi;
360 for (vi = 0; vi < DUST_N_PARTICLES; vi++)
361 {
362 vertices[vi + DUST_N_PARTICLES] = vector_subtract(vertices[vi], warpVector);
363 }
364 }
365
366 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
367 OOGL(glDrawElements(GL_LINES, DUST_N_PARTICLES * 2, GL_UNSIGNED_SHORT, indices));
368
369#if OO_SHADERS
370 if (useShader)
371 {
372 OOGL(glDisableVertexAttribArrayARB(kTangentAttributeIndex));
373 }
374#endif
375 OOGL(glEnable(GL_TEXTURE_2D));
376
377 }
378 else
379 {
380 if (hasPointSprites)
381 {
382#if OO_SHADERS
383 if (!useShader)
384#endif
385 {
386 OOGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE));
387 }
388 OOGL(glEnable(GL_POINT_SPRITE_ARB));
389 [texture apply];
390 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
391 OOGL(glDrawArrays(GL_POINTS, 0, DUST_N_PARTICLES));
392 OOGL(glDisable(GL_POINT_SPRITE_ARB));
393 }
394 else
395 {
396 OOGL(glDisable(GL_TEXTURE_2D));
397 OOGL(glVertexPointer(3, GL_FLOAT, 0, vertices));
398 OOGL(glDrawArrays(GL_POINTS, 0, DUST_N_PARTICLES));
399 OOGL(glEnable(GL_TEXTURE_2D));
400 }
401 }
402
403 // reapply normal conditions
404#if OO_SHADERS
405 if (useShader)
406 {
407 [OOShaderProgram applyNone];
408 }
409 else
410#endif
411 {
412 OOGL(glDisable(GL_FOG));
413 OOGL(glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA));
414 }
415
416 OOGL(glDisable(GL_BLEND));
417 OOGL(glDepthMask(GL_TRUE));
418
419 }
420 OOGL(glEnableClientState(GL_NORMAL_ARRAY));
421
423 OOCheckOpenGLErrors(@"DustEntity after drawing %@", self);
424}
NSUInteger gDebugFlags
Definition main.m:7
#define DUST_N_PARTICLES
Definition DustEntity.h:32
#define NEAR_PLANE
Definition DustEntity.m:45
#define FAR_PLANE
Definition DustEntity.m:44
@ DEBUG_NO_DUST
#define EXPECT_NOT(x)
#define OO_ENTER_OPENGL()
@ OPENGL_STATE_OPAQUE
Definition OOOpenGL.h:123
#define OOVerifyOpenGLState()
Definition OOOpenGL.h:136
BOOL OOCheckOpenGLErrors(NSString *format,...)
Definition OOOpenGL.m:39
void GLScaledLineWidth(GLfloat width)
Definition OOOpenGL.m:218
#define OOSetOpenGLState(STATE)
Definition OOOpenGL.h:135
#define OOGL(statement)
Definition OOOpenGL.h:251
void GLScaledPointSize(GLfloat size)
Definition OOOpenGL.m:225
return nil
#define PLAYER
#define UNIVERSE
Definition Universe.h:833
Vector vertices[DUST_N_PARTICLES *2]
Definition DustEntity.h:41
bool hasPointSprites
Definition DustEntity.h:45
GLushort indices[DUST_N_PARTICLES *2]
Definition DustEntity.h:42
GLfloat color_fv[4]
Definition DustEntity.h:43
Vector warpVector()
Definition DustEntity.m:261
unsigned isSunlit
Definition Entity.h:99

◆ dustColor

- (OOColor *) dustColor

Definition at line 1 of file DustEntity.m.

143{
144 return dust_color;
145}

◆ init

- (id) init
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

68{
69 int vi;
70
71// this should be unnecessary
72// ranrot_srand((uint32_t)[[NSDate date] timeIntervalSince1970]); // seed randomiser by time
73
74 self = [super init];
75
76 for (vi = 0; vi < DUST_N_PARTICLES; vi++)
77 {
78 vertices[vi].x = (ranrot_rand() % DUST_SCALE) - DUST_SCALE / 2;
79 vertices[vi].y = (ranrot_rand() % DUST_SCALE) - DUST_SCALE / 2;
80 vertices[vi].z = (ranrot_rand() % DUST_SCALE) - DUST_SCALE / 2;
81
82 // Set up element index array for warp mode.
83 indices[vi * 2] = vi;
84 indices[vi * 2 + 1] = vi + DUST_N_PARTICLES;
85
86#if OO_SHADERS
87 vertices[vi + DUST_N_PARTICLES] = vertices[vi];
88 warpinessAttr[vi] = 0.0f;
89 warpinessAttr[vi + DUST_N_PARTICLES] = 1.0f;
90#endif
91 }
92
93#if OO_SHADERS
94 shaderMode = kShaderModeUnknown;
95#endif
96
97 dust_color = [[OOColor colorWithRed:0.5 green:1.0 blue:1.0 alpha:1.0] retain];
98 [self setStatus:STATUS_ACTIVE];
99
101
102 if (hasPointSprites)
103 {
104 texture = [[OOTexture textureWithName:@"oolite-particle-dust.png"
105 inFolder:@"Textures"
106 options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
107 anisotropy:kOOTextureDefaultAnisotropy / 2.0
108 lodBias:0.0] retain];
109 }
110
111 collision_radius = DUST_SCALE; // for draw pass calculations
112
114
115 return self;
116}
#define DUST_SCALE
Definition DustEntity.h:31
GLfloat collision_radius
Definition Entity.h:111
OOColor * colorWithRed:green:blue:alpha:(float red,[green] float green,[blue] float blue,[alpha] float alpha)
Definition OOColor.m:95
void registerClient:(id< OOGraphicsResetClient > client)
OOOpenGLExtensionManager * sharedManager()
BOOL haveExtension:(NSString *extension)
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
Definition OOTexture.m:134
#define ranrot_rand()

◆ resetGraphicsState

- (void) resetGraphicsState
implementation

Definition at line 1 of file DustEntity.m.

428{
429#if OO_SHADERS
430 DESTROY(shader);
431 DESTROY(uniforms);
432
433 shaderMode = kShaderModeUnknown;
434
435 /* Duplicate vertex data. This is only required if we're switching from
436 non-shader mode to a shader mode, but let's KISS.
437 */
439#endif
440}

◆ setDustColor:

- (void) setDustColor: (OOColor *) color

Definition at line 1 of file DustEntity.m.

134 :(OOColor *) color
135{
136 if (dust_color) [dust_color release];
137 dust_color = [color retain];
138 [dust_color getRed:&color_fv[0] green:&color_fv[1] blue:&color_fv[2] alpha:&color_fv[3]];
139}

◆ update:

- (void) update: (OOTimeDelta) delta_t
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

161 :(OOTimeDelta) delta_t
162{
163 // [self setPosition:position];
164 zero_distance = 0.0;
165
166#if OO_SHADERS
167 if (EXPECT_NOT(shaderMode == kShaderModeUnknown)) [self checkShaderMode];
168
169 // Shader takes care of repositioning.
170 if (shaderMode == kShaderModeOn) return;
171#endif
172
173 Vector offset = vector_flip(cameraRelativePosition);
174 GLfloat half_scale = DUST_SCALE * 0.50;
175 int vi;
176 for (vi = 0; vi < DUST_N_PARTICLES; vi++)
177 {
178 while (vertices[vi].x - offset.x < -half_scale)
179 vertices[vi].x += DUST_SCALE;
180 while (vertices[vi].x - offset.x > half_scale)
181 vertices[vi].x -= DUST_SCALE;
182
183 while (vertices[vi].y - offset.y < -half_scale)
184 vertices[vi].y += DUST_SCALE;
185 while (vertices[vi].y - offset.y > half_scale)
186 vertices[vi].y -= DUST_SCALE;
187
188 while (vertices[vi].z - offset.z < -half_scale)
189 vertices[vi].z += DUST_SCALE;
190 while (vertices[vi].z - offset.z > half_scale)
191 vertices[vi].z -= DUST_SCALE;
192 }
193}
float y
float x
double OOTimeDelta
Definition OOTypes.h:224
GLfloat zero_distance
Definition Entity.h:108
Vector cameraRelativePosition
Definition Entity.h:113
voidpf uLong offset
Definition ioapi.h:140

◆ updateCameraRelativePosition

- (void) updateCameraRelativePosition
implementation

Reimplemented from Entity.

Definition at line 1 of file DustEntity.m.

155{
156 HPVector c_pos = [PLAYER viewpointPosition];
157 cameraRelativePosition = make_vector((OOScalar)-fmod(c_pos.x,DUST_SCALE),(OOScalar)-fmod(c_pos.y,DUST_SCALE),(OOScalar)-fmod(c_pos.z,DUST_SCALE));
158}
GLfloat OOScalar
Definition OOMaths.h:64

◆ warpVector

- (Vector) warpVector
implementation

Definition at line 1 of file DustEntity.m.

262{
263 return vector_multiply_scalar([PLAYER velocity], 1.0f / HYPERSPEED_FACTOR);
264}
#define HYPERSPEED_FACTOR
Vector velocity
Definition Entity.h:140

Member Data Documentation

◆ color_fv

- (GLfloat color_fv[4])
private

Definition at line 43 of file DustEntity.h.

◆ dust_color

- (OOColor*) dust_color
private

Definition at line 40 of file DustEntity.h.

◆ hasPointSprites

- (bool) hasPointSprites
private

Definition at line 45 of file DustEntity.h.

◆ indices

- (GLushort indices[DUST_N_PARTICLES *2])
private

Definition at line 42 of file DustEntity.h.

◆ texture

- (OOTexture*) texture
private

Definition at line 44 of file DustEntity.h.

◆ vertices

- (Vector vertices[DUST_N_PARTICLES *2])
private

Definition at line 41 of file DustEntity.h.


The documentation for this class was generated from the following files: