/
Scene.h
executable file
·736 lines (592 loc) · 31.2 KB
/
Scene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _SCENE_H_
#define _SCENE_H_
#ifndef _MMATH_H_
#include "math/mMath.h"
#endif
#ifndef _VECTOR2_H_
#include "2d/core/Vector2.h"
#endif
#ifndef _NETOBJECT_H_
#include "network/netObject.h"
#endif
#ifndef _TICKABLE_H_
#include "platform/Tickable.h"
#endif
#ifndef _PHYSICS_PROXY_H_
#include "2d/scene/PhysicsProxy.h"
#endif
#ifndef _WORLD_QUERY_H_
#include "2d/scene/WorldQuery.h"
#endif
#ifndef _DEBUG_DRAW_H_
#include "2d/scene/DebugDraw.h"
#endif
#ifndef _HASHTABLE_H
#include "collection/hashTable.h"
#endif
#ifndef _BATCH_RENDER_H_
#include "2d/core/BatchRender.h"
#endif
#ifndef _SCENE_RENDER_QUEUE_H_
#include "2d/scene/SceneRenderQueue.h"
#endif
#ifndef _SCENE_RENDER_OBJECT_H_
#include "2d/scene/SceneRenderObject.h"
#endif
#ifndef _BEHAVIOR_COMPONENT_H_
#include "component/behaviors/behaviorComponent.h"
#endif
#ifndef _ASSET_PTR_H_
#include "assets/assetPtr.h"
#endif
//-----------------------------------------------------------------------------
extern EnumTable jointTypeTable;
///-----------------------------------------------------------------------------
class SceneObject;
class SceneWindow;
///-----------------------------------------------------------------------------
struct tDeleteRequest
{
SimObjectId mObjectId;
SceneObject* mpSceneObject;
bool mSafeDeleteReady;
};
///-----------------------------------------------------------------------------
struct TickContact
{
TickContact()
{
initialize( NULL, NULL, NULL, NULL, NULL );
}
void initialize(
b2Contact* pContact,
SceneObject* pSceneObjectA,
SceneObject* pSceneObjectB,
b2Fixture* pFixtureA,
b2Fixture* pFixtureB )
{
mpContact = pContact;
mpSceneObjectA = pSceneObjectA;
mpSceneObjectB = pSceneObjectB;
mpFixtureA = pFixtureA;
mpFixtureB = pFixtureB;
// Get world manifold.
if ( mpContact != NULL )
{
mPointCount = pContact->GetManifold()->pointCount;
mpContact->GetWorldManifold( &mWorldManifold );
}
else
{
mPointCount = 0;
}
// Reset impulses.
for (U32 i = 0; i < b2_maxManifoldPoints; i++)
{
mNormalImpulses[i] = 0;
mTangentImpulses[i] = 0;
}
}
inline SceneObject* getCollideWith( SceneObject* pMe ) const
{
return pMe == mpSceneObjectA ? mpSceneObjectB : mpSceneObjectA;
}
inline b2Fixture* getCollideWithFixture( b2Fixture* pMe ) const
{
return pMe == mpFixtureA ? mpFixtureB : mpFixtureA;
}
b2Contact* mpContact;
SceneObject* mpSceneObjectA;
SceneObject* mpSceneObjectB;
b2Fixture* mpFixtureA;
b2Fixture* mpFixtureB;
U32 mPointCount;
b2WorldManifold mWorldManifold;
F32 mNormalImpulses[b2_maxManifoldPoints];
F32 mTangentImpulses[b2_maxManifoldPoints];
};
///-----------------------------------------------------------------------------
class Scene :
public BehaviorComponent,
public TamlChildren,
public PhysicsProxy,
public b2ContactListener,
public b2DestructionListener,
public virtual Tickable
{
public:
typedef HashMap<S32, b2Joint*> typeJointHash;
typedef HashMap<b2Joint*, S32> typeReverseJointHash;
typedef Vector<tDeleteRequest> typeDeleteVector;
typedef Vector<TickContact> typeContactVector;
typedef HashMap<b2Contact*, TickContact> typeContactHash;
typedef Vector<AssetPtr<AssetBase>*> typeAssetPtrVector;
/// Scene Debug Options.
enum DebugOption
{
SCENE_DEBUG_INVALID,
///
SCENE_DEBUG_METRICS = BIT(0),
SCENE_DEBUG_FPS_METRICS = BIT(1),
SCENE_DEBUG_CONTROLLERS = BIT(2),
SCENE_DEBUG_JOINTS = BIT(3),
SCENE_DEBUG_WIREFRAME_RENDER = BIT(4),
SCENE_DEBUG_AUDIO_SOURCES = BIT(5),
///
SCENE_DEBUG_AABB = BIT(16),
SCENE_DEBUG_OOBB = BIT(17),
SCENE_DEBUG_SLEEP = BIT(18),
SCENE_DEBUG_COLLISION_SHAPES = BIT(19),
SCENE_DEBUG_POSITION_AND_COM = BIT(20),
SCENE_DEBUG_SORT_POINTS = BIT(21),
};
/// Pick mode.
enum PickMode
{
PICK_INVALID,
///---
PICK_ANY,
PICK_AABB,
PICK_OOBB,
PICK_COLLISION,
};
/// Debug drawing.
DebugDraw mDebugDraw;
private:
typedef BehaviorComponent Parent;
typedef SceneObject Children;
/// World.
b2World* mpWorld;
WorldQuery* mpWorldQuery;
b2Vec2 mWorldGravity;
S32 mVelocityIterations;
S32 mPositionIterations;
b2BlockAllocator mBlockAllocator;
b2Body* mpGroundBody;
/// Scene occupancy.
typeSceneObjectVector mSceneObjects;
typeSceneObjectVector mTickedSceneObjects;
/// Joint access.
typeJointHash mJoints;
typeReverseJointHash mReverseJoints;
S32 mJointMasterId;
/// Scene controllers.
SimObjectPtr<SimSet> mControllers;
/// Asset pre-loads.
typeAssetPtrVector mAssetPreloads;
/// Scene time.
F32 mSceneTime;
bool mScenePause;
/// Debug and metrics.
DebugStats mDebugStats;
U32 mDebugMask;
SceneObject* mpDebugSceneObject;
/// Layer sorting and draw order.
SceneRenderQueue::RenderSort mLayerSortModes[MAX_LAYERS_SUPPORTED];
/// Batch rendering.
BatchRender mBatchRenderer;
/// Window rendering.
SceneWindow* mpCurrentRenderWindow;
/// Window attachments.
SimSet mAttachedSceneWindows;
/// Delete requests.
typeDeleteVector mDeleteRequests;
typeDeleteVector mDeleteRequestsTemp;
/// Miscellaneous.
S32 mIsEditorScene;
bool mUpdateCallback;
bool mRenderCallback;
typeContactHash mBeginContacts;
typeContactVector mEndContacts;
U32 mSceneIndex;
private:
/// Contacts.
void forwardContacts( void );
void dispatchBeginContactCallbacks( void );
void dispatchEndContactCallbacks( void );
/// Joint definition.
struct CommonJointDefinition
{
CommonJointDefinition()
{
jointType = e_unknownJoint;
collideConnected = false;
pSceneObjectA = NULL;
pSceneObjectB = NULL;
localAnchorA = b2Vec2_zero;
localAnchorB = b2Vec2_zero;
}
b2JointType jointType;
bool collideConnected;
SceneObject* pSceneObjectA;
SceneObject* pSceneObjectB;
b2Vec2 localAnchorA;
b2Vec2 localAnchorB;
};
protected:
/// Taml callbacks.
virtual void onTamlPreRead( void );
virtual void onTamlPostRead( const TamlCustomNodes& customNodes );
virtual void onTamlCustomWrite( TamlCustomNodes& customNodes );
virtual void onTamlCustomRead( const TamlCustomNodes& customNodes );
public:
Scene();
virtual ~Scene();
/// Engine.
virtual bool onAdd();
virtual void onRemove();
virtual void onDeleteNotify( SimObject* object );
static void initPersistFields();
/// Contact processing.
virtual void PreSolve( b2Contact* pContact, const b2Manifold* pOldManifold ) {}
virtual void PostSolve( b2Contact* pContact, const b2ContactImpulse* pImpulse );
virtual void BeginContact( b2Contact* pContact );
virtual void EndContact( b2Contact* pContact );
const typeContactHash& getBeginContacts( void ) const { return mBeginContacts; }
const typeContactVector& getEndContacts( void ) const { return mEndContacts; }
/// Integration.
virtual void processTick();
virtual void interpolateTick( F32 delta );
virtual void advanceTime( F32 timeDelta ) {};
/// Render output.
void sceneRender( const SceneRenderState* pSceneRenderState );
/// World.
inline b2World* getWorld( void ) const { return mpWorld; }
inline WorldQuery* getWorldQuery( const bool clearQuery = false ) { if ( clearQuery ) mpWorldQuery->clearQuery(); return mpWorldQuery; }
b2BlockAllocator* getBlockAllocator( void ) { return &mBlockAllocator; }
inline b2Body* getGroundBody( void ) const { return mpGroundBody; }
virtual ePhysicsProxyType getPhysicsProxyType( void ) const { return PhysicsProxy::PHYSIC_PROXY_GROUNDBODY; }
void setGravity( const b2Vec2& gravity ) { mWorldGravity = gravity; if (mpWorld) mpWorld->SetGravity( gravity ); }
inline b2Vec2 getGravity( void ) { if (mpWorld) mWorldGravity = mpWorld->GetGravity(); return mWorldGravity; }
inline void setVelocityIterations( const S32 iterations ) { mVelocityIterations = iterations; }
inline S32 getVelocityIterations( void ) const { return mVelocityIterations; }
inline void setPositionIterations( const S32 iterations ) { mPositionIterations = iterations; }
inline S32 getPositionIterations( void ) const { return mPositionIterations; }
/// Scene occupancy.
void clearScene( bool deleteObjects = true );
void addToScene( SceneObject* pSceneObject );
void removeFromScene( SceneObject* pSceneObject );
inline typeSceneObjectVectorConstRef getSceneObjects( void ) const { return mSceneObjects; }
inline U32 getSceneObjectCount( void ) const { return mSceneObjects.size(); }
SceneObject* getSceneObject( const U32 objectIndex ) const;
U32 getSceneObjects( typeSceneObjectVector& objects ) const;
U32 getSceneObjects( typeSceneObjectVector& objects, const U32 sceneLayer ) const;
void mergeScene( const Scene* pScene );
inline SimSet* getControllers( void ) { return mControllers; }
inline S32 getAssetPreloadCount( void ) const { return mAssetPreloads.size(); }
const AssetPtr<AssetBase>* getAssetPreload( const S32 index ) const;
void addAssetPreload( const char* pAssetId );
void removeAssetPreload( const char* pAssetId );
void clearAssetPreloads( void );
/// Scene time.
inline F32 getSceneTime( void ) const { return mSceneTime; };
inline void setScenePause( bool status ) { mScenePause = status; }
inline bool getScenePause( void ) const { return mScenePause; };
/// Joint access.
inline U32 getJointCount( void ) const { return mJoints.size(); }
b2JointType getJointType( const S32 jointId );
b2Joint* findJoint( const S32 jointId );
S32 findJointId( b2Joint* pJoint );
S32 createJoint( b2JointDef* pJointDef );
bool deleteJoint( const U32 jointId );
bool hasJoints( SceneObject* pSceneObject );
/// Distance joint.
S32 createDistanceJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA = b2Vec2_zero, const b2Vec2& localAnchorB = b2Vec2_zero,
const F32 length = -1.0f,
const F32 frequency = 0.0f,
const F32 dampingRatio = 0.0f,
const bool collideConnected = false );
void setDistanceJointLength(
const U32 jointId,
const F32 length );
F32 getDistanceJointLength( const U32 jointId );
void setDistanceJointFrequency(
const U32 jointId,
const F32 frequency );
F32 getDistanceJointFrequency( const U32 jointId );
void setDistanceJointDampingRatio(
const U32 jointId,
const F32 dampingRatio );
F32 getDistanceJointDampingRatio( const U32 jointId );
/// Rope joint.
S32 createRopeJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA = b2Vec2_zero, const b2Vec2& localAnchorB = b2Vec2_zero,
const F32 maxLength = -1.0f,
const bool collideConnected = false );
void setRopeJointMaxLength(
const U32 jointId,
const F32 maxLength );
F32 getRopeJointMaxLength( const U32 jointId );
/// Revolute joint.
S32 createRevoluteJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA = b2Vec2_zero, const b2Vec2& localAnchorB = b2Vec2_zero,
const bool collideConnected = false );
void setRevoluteJointLimit(
const U32 jointId,
const bool enableLimit,
const F32 lowerAngle, const F32 upperAngle );
bool getRevoluteJointLimit(
const U32 jointId,
bool& enableLimit,
F32& lowerAngle, F32& upperAngle );
void setRevoluteJointMotor(
const U32 jointId,
const bool enableMotor,
const F32 motorSpeed = b2_pi,
const F32 maxMotorTorque = 0.0f );
bool getRevoluteJointMotor(
const U32 jointId,
bool& enableMotor,
F32& motorSpeed,
F32& maxMotorTorque );
F32 getRevoluteJointAngle( const U32 jointId );
F32 getRevoluteJointSpeed( const U32 jointId );
/// Weld joint.
S32 createWeldJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA = b2Vec2_zero, const b2Vec2& localAnchorB = b2Vec2_zero,
const F32 frequency = 0.0f,
const F32 dampingRatio = 0.0f,
const bool collideConnected = false );
void setWeldJointFrequency(
const U32 jointId,
const F32 frequency );
F32 getWeldJointFrequency( const U32 jointId );
void setWeldJointDampingRatio(
const U32 jointId,
const F32 dampingRatio );
F32 getWeldJointDampingRatio( const U32 jointId );
/// Wheel joint.
S32 createWheelJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA, const b2Vec2& localAnchorB,
const b2Vec2& worldAxis,
const bool collideConnected = false );
void setWheelJointMotor(
const U32 jointId,
const bool enableMotor,
const F32 motorSpeed = b2_pi,
const F32 maxMotorTorque = 0.0f );
bool getWheelJointMotor(
const U32 jointId,
bool& enableMotor,
F32& motorSpeed,
F32& maxMotorTorque );
void setWheelJointFrequency(
const U32 jointId,
const F32 frequency );
F32 getWheelJointFrequency( const U32 jointId );
void setWheelJointDampingRatio(
const U32 jointId,
const F32 dampingRatio );
F32 getWheelJointDampingRatio( const U32 jointId );
/// Friction joint.
S32 createFrictionJoint(
const SceneObject* pSceneObjectA,const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA = b2Vec2_zero, const b2Vec2& localAnchorB = b2Vec2_zero,
const F32 maxForce = 0.0f,
const F32 maxTorque = 0.0f,
const bool collideConnected = false );
void setFrictionJointMaxForce(
const U32 jointId,
const F32 maxForce );
F32 getFrictionJointMaxForce( const U32 jointId );
void setFrictionJointMaxTorque(
const U32 jointId,
const F32 maxTorque );
F32 getFrictionJointMaxTorque( const U32 jointId );
/// Prismatic joint.
S32 createPrismaticJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA, const b2Vec2& localAnchorB,
const b2Vec2& worldAxis,
const bool collideConnected = false );
void setPrismaticJointLimit(
const U32 jointId,
const bool enableLimit,
const F32 lowerTranslation, const F32 upperTranslation );
bool getPrismaticJointLimit(
const U32 jointId,
bool& enableLimit,
F32& lowerTranslation, F32& upperTranslation );
void setPrismaticJointMotor(
const U32 jointId,
const bool enableMotor,
const F32 motorSpeed = b2_pi,
const F32 maxMotorForce = 0.0f );
bool getPrismaticJointMotor(
const U32 jointId,
bool& enableMotor,
F32& motorSpeed,
F32& maxMotorTorque );
/// Pulley joint.
S32 createPulleyJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2& localAnchorA, const b2Vec2& localAnchorB,
const b2Vec2& worldGroundAnchorA, const b2Vec2& worldGroundAnchorB,
const F32 ratio,
const F32 lengthA = -1.0f, const F32 lengthB = -1.0f,
const bool collideConnected = false );
/// Target (a.k.a Mouse) joint.
S32 createTargetJoint(
const SceneObject* pSceneObject,
const b2Vec2& worldTarget,
const F32 maxForce,
const bool useCenterOfMass = false,
const F32 frequency = 5.0f,
const F32 dampingRatio = 0.7f,
const bool collideConnected = false );
void setTargetJointTarget(
const U32 jointId,
const b2Vec2& worldTarget );
b2Vec2 getTargetJointTarget( const U32 jointId );
void setTargetJointMaxForce(
const U32 jointId,
const F32 maxForce );
F32 getTargetJointMaxForce( const U32 jointId );
void setTargetJointFrequency(
const U32 jointId,
const F32 frequency );
F32 getTargetJointFrequency( const U32 jointId );
void setTargetJointDampingRatio(
const U32 jointId,
const F32 dampingRatio );
F32 getTargetJointDampingRatio( const U32 jointId );
/// Motor Joint.
S32 createMotorJoint(
const SceneObject* pSceneObjectA, const SceneObject* pSceneObjectB,
const b2Vec2 linearOffset = b2Vec2_zero,
const F32 angularOffset = 0.0f,
const F32 maxForce = 1.0f,
const F32 maxTorque = 1.0f,
const F32 correctionFactor = 0.3f,
const bool collideConnected = false );
void setMotorJointLinearOffset(
const U32 jointId,
const b2Vec2& linearOffset );
b2Vec2 getMotorJointLinearOffset( const U32 jointId );
void setMotorJointAngularOffset(
const U32 jointId,
const F32 angularOffset );
F32 getMotorJointAngularOffset( const U32 jointId );
void setMotorJointMaxForce(
const U32 jointId,
const F32 maxForce );
F32 getMotorJointMaxForce( const U32 jointId );
void setMotorJointMaxTorque(
const U32 jointId,
const F32 maxTorque );
F32 getMotorJointMaxTorque( const U32 jointId );
/// Debug and metrics.
inline void setDebugOn( const U32 debugMask ) { mDebugMask |= debugMask; }
inline void setDebugOff( const U32 debugMask ) { mDebugMask &= ~debugMask; }
inline U32 getDebugMask( void ) const { return mDebugMask; }
DebugStats& getDebugStats( void ) { return mDebugStats; }
inline void resetDebugStats( void ) { mDebugStats.reset(); }
void setDebugSceneObject( SceneObject* pSceneObject );
inline SceneObject* getDebugSceneObject( void ) const { return mpDebugSceneObject; }
/// Layer sorting.
void setLayerSortMode( const U32 layer, const SceneRenderQueue::RenderSort sortMode );
SceneRenderQueue::RenderSort getLayerSortMode( const U32 layer );
/// Window attachments.
void attachSceneWindow( SceneWindow* pSceneWindow2D );
void detachSceneWindow( SceneWindow* pSceneWindow2D );
void detachAllSceneWindows( void );
bool isSceneWindowAttached( SceneWindow* pSceneWindow2D );
inline SimSet& getAttachedSceneWindows( void ) { return mAttachedSceneWindows; }
/// Delete requests.
void addDeleteRequest( SceneObject* pSceneObject );
void processDeleteRequests( const bool forceImmediate );
/// Destruction listeners.
virtual void SayGoodbye( b2Joint* pJoint );
virtual void SayGoodbye( b2Fixture* pFixture ) {}
virtual SceneObject* create( const char* pType );
/// Miscellaneous.
inline void setBatchingEnabled( const bool enabled ) { mBatchRenderer.setBatchEnabled( enabled ); }
inline bool getBatchingEnabled( void ) const { return mBatchRenderer.getBatchEnabled(); }
inline bool getIsEditorScene( void ) const { return ((mIsEditorScene > 0) ? true : false); }
inline void setIsEditorScene( bool status ) { mIsEditorScene += (status ? 1 : -1); }
static U32 getGlobalSceneCount( void );
inline U32 getSceneIndex( void ) const { return mSceneIndex; }
inline void setUpdateCallback( const bool callback ) { mUpdateCallback = callback; }
inline bool getUpdateCallback( void ) const { return mUpdateCallback; }
inline void setRenderCallback( const bool callback ) { mRenderCallback = callback; }
inline bool getRenderCallback( void ) const { return mRenderCallback; }
static SceneRenderRequest* createDefaultRenderRequest( SceneRenderQueue* pSceneRenderQueue, SceneObject* pSceneObject );
/// Taml children.
virtual U32 getTamlChildCount( void ) const { return (U32)mSceneObjects.size(); }
virtual SimObject* getTamlChild( const U32 childIndex ) const;
virtual void addTamlChild( SimObject* pSimObject );
static b2JointType getJointTypeEnum(const char* label);
static const char* getJointTypeDescription( b2JointType jointType );
static PickMode getPickModeEnum(const char* label);
static const char* getPickModeDescription( PickMode pickMode );
static DebugOption getDebugOptionEnum(const char* label);
static const char* getDebugOptionDescription( DebugOption debugOption );
/// Declare Console Object.
DECLARE_CONOBJECT(Scene);
protected:
/// Physics.
static bool setGravity( void* obj, const char* data ) { static_cast<Scene*>(obj)->setGravity( Vector2( data ) ); return false; }
static const char* getGravity(void* obj, const char* data) { return Vector2(static_cast<Scene*>(obj)->getGravity()).scriptThis(); }
static bool writeGravity( void* obj, StringTableEntry pFieldName ) { return Vector2(static_cast<Scene*>(obj)->getGravity()).notEqual( Vector2::getZero() ); }
static bool writeVelocityIterations( void* obj, StringTableEntry pFieldName ) { return static_cast<Scene*>(obj)->getVelocityIterations() != 8; }
static bool writePositionIterations( void* obj, StringTableEntry pFieldName ) { return static_cast<Scene*>(obj)->getPositionIterations() != 3; }
static bool writeLayerSortMode( void* obj, StringTableEntry pFieldName )
{
// Find the layer index portion of the layer sort mode field.
const char* pLayerNumber = pFieldName;
while( true )
{
// Fetch character.
char value = *pLayerNumber;
// Finish if end of the field or is numeric.
if ( value == 0 || ( value >= '0' && value <= '9' ) )
break;
// Move to next value.
pLayerNumber++;
};
// Sanity!
AssertFatal( *pLayerNumber != 0, "Scene::writeLayerSortMode() - Could not find the layer index portion of the layer sort mode field." );
// Fetch layer number.
const U32 layer = dAtoi(pLayerNumber);
// Just allow the write if an bad parse.
if ( layer > MAX_LAYERS_SUPPORTED )
return true;
return static_cast<Scene*>(obj)->getLayerSortMode( layer ) != SceneRenderQueue::RENDER_SORT_NEWEST;
}
// Callbacks.
static bool writeUpdateCallback( void* obj, StringTableEntry pFieldName ) { return static_cast<Scene*>(obj)->getUpdateCallback(); }
static bool writeRenderCallback( void* obj, StringTableEntry pFieldName ) { return static_cast<Scene*>(obj)->getRenderCallback(); }
public:
static SimObjectPtr<Scene> LoadingScene;
};
//-----------------------------------------------------------------------------
extern void findObjectsCallback(SceneObject* pSceneObject, void* storage);
extern void findLayeredObjectsCallback(SceneObject* pSceneObject, void* storage);
#endif // _SCENE_H_