00001 #ifndef OSDL_SCHEDULER_H_
00002 #define OSDL_SCHEDULER_H_
00003
00004
00005
00006
00007 #include "OSDLEngineCommon.h"
00008 #include "OSDLEvents.h"
00009 #include "OSDLPeriodicSlot.h"
00010
00011
00012
00013 #include "Ceylan.h"
00014
00015
00016 #include <string>
00017 #include <list>
00018 #include <map>
00019
00020
00021
00022 namespace OSDL
00023 {
00024
00025 namespace Events
00026 {
00027
00028
00029
00030 class EventsModule ;
00031
00032 }
00033
00034
00035 namespace Rendering
00036 {
00037
00038
00039
00040 class Renderer ;
00041
00042 }
00043
00044
00045 namespace Video
00046 {
00047
00048
00049
00050
00051
00052
00053 class VideoModule ;
00054
00055 }
00056
00057
00058 namespace Engine
00059 {
00060
00061
00062
00063 class ActiveObject ;
00064
00065
00066
00067 class PeriodicSlot ;
00068
00069
00217 class OSDL_DLL Scheduler : public Ceylan::Object
00218 {
00219
00220
00222 typedef Ceylan::Uint32 Delay ;
00223
00224
00225 public:
00226
00227
00228
00235 virtual bool hasRenderer() const throw() ;
00236
00237
00244 virtual Rendering::Renderer & getRenderer() const
00245 throw( SchedulingException ) ;
00246
00247
00259 virtual void setRenderer( Rendering::Renderer & newRenderer )
00260 throw() ;
00261
00262
00263
00299 virtual void setScreenshotMode( bool on,
00300 const std::string & frameFilenamePrefix,
00301 Events::Hertz frameFrequency = 25 ) throw() ;
00302
00303
00322 virtual void setTimeSliceDuration(
00323 Ceylan::System::Microsecond engineTickDuration ) throw() ;
00324
00325
00334 virtual Ceylan::System::Microsecond getTimeSliceDuration()
00335 const throw() ;
00336
00337
00349 virtual void setSimulationFrequency( Events::Hertz frequency )
00350 throw( SchedulingException ) ;
00351
00352
00361 virtual Events::Period getSimulationTickCount() const throw() ;
00362
00363
00374 virtual void setRenderingFrequency( Events::Hertz frequency )
00375 throw( SchedulingException ) ;
00376
00377
00386 virtual Events::Period getRenderingTickCount() const throw() ;
00387
00388
00400 virtual void setScreenshotFrequency( Events::Hertz frequency )
00401 throw( SchedulingException ) ;
00402
00403
00412 virtual Events::Period getScreenshotTickCount() const throw() ;
00413
00414
00425 virtual void setInputPollingFrequency(
00426 Events::Hertz frequency ) throw( SchedulingException ) ;
00427
00428
00437 virtual Events::Period getInputPollingTickCount()
00438 const throw() ;
00439
00440
00474 virtual void setIdleCallback(
00475 Ceylan::System::Callback idleCallback = 0 ,
00476 void * callbackData = 0,
00477 Ceylan::System::Microsecond
00478 callbackExpectedMaxDuration = 0 ) throw() ;
00479
00480
00481
00482
00487 virtual Events::EngineTick getCurrentEngineTick()
00488 const throw() ;
00489
00490
00495 virtual Events::SimulationTick getCurrentSimulationTick()
00496 const throw() ;
00497
00498
00503 virtual Events::RenderingTick getCurrentRenderingTick()
00504 const throw() ;
00505
00506
00511 virtual Events::RenderingTick getCurrentInputTick()
00512 const throw() ;
00513
00514
00531 virtual void registerObject( ActiveObject & toRegister )
00532 throw() ;
00533
00534
00543 virtual void schedule() throw( SchedulingException ) ;
00544
00545
00551 virtual void stop() throw() ;
00552
00553
00565 virtual const std::string toString(
00566 Ceylan::VerbosityLevels level = Ceylan::high )
00567 const throw() ;
00568
00569
00570
00571
00572
00573
00586 static Scheduler & GetExistingScheduler()
00587 throw( SchedulingException ) ;
00588
00589
00600 static Scheduler & GetScheduler() throw() ;
00601
00602
00609 static void DeleteExistingScheduler()
00610 throw( SchedulingException ) ;
00611
00612
00617 static void DeleteScheduler() throw() ;
00618
00619
00620
00630 static const Ceylan::System::Microsecond
00631 DefaultEngineTickDuration = 1000 ;
00632
00633
00640 static const Events::Hertz DefaultSimulationFrequency = 100 ;
00641
00642
00650 static const Events::Hertz DefaultRenderingFrequency = 40 ;
00651
00652
00661 static const Ceylan::Uint32 DefaultMovieFrameFrequency = 25 ;
00662
00663
00671 static const Events::Hertz DefaultInputFrequency = 20 ;
00672
00673
00674
00675 protected:
00676
00677
00685 explicit Scheduler() throw() ;
00686
00687
00695 virtual ~Scheduler() throw() ;
00696
00697
00706 virtual void scheduleBestEffort() throw( SchedulingException ) ;
00707
00708
00723 virtual void scheduleNoDeadline( bool pollInputs = true )
00724 throw( SchedulingException ) ;
00725
00726
00741 virtual Events::EngineTick computeEngineTickFromCurrentTime()
00742 throw() ;
00743
00744
00754 virtual void scheduleSimulation(
00755 Events::SimulationTick current ) throw() ;
00756
00757
00767 virtual void scheduleProgrammedObjects(
00768 Events::SimulationTick current ) throw() ;
00769
00770
00780 virtual void schedulePeriodicObjects(
00781 Events::SimulationTick currentSimulationTick ) throw() ;
00782
00783
00790 virtual void scheduleRendering(
00791 Events::RenderingTick currentRenderingTick ) throw() ;
00792
00793
00800 virtual void scheduleInput( Events::InputTick currentInputTick )
00801 throw() ;
00802
00803
00815 virtual void scheduleActiveObjectList(
00816 Events::RenderingTick currentSimulationTick,
00817 ListOfActiveObjects & objectList ) throw() ;
00818
00819
00841 virtual void onSimulationSkipped(
00842 Events::SimulationTick skipped )
00843 throw( SchedulingException ) ;
00844
00845
00861 virtual void onRenderingSkipped(
00862 Events::RenderingTick skipped )
00863 throw( SchedulingException ) ;
00864
00865
00882 virtual void onInputSkipped( Events::InputTick skipped )
00883 throw( SchedulingException ) ;
00884
00885
00895 virtual void onIdle() throw() ;
00896
00897
00903 static const Delay ShutdownBucketLevel ;
00904
00905
00925 virtual void onScheduleFailure( Delay currentBucket ) throw() ;
00926
00927
00928
00940 virtual void programTriggerFor( ActiveObject & objectToProgram,
00941 Events::SimulationTick targetTick ) throw() ;
00942
00943
00951 virtual PeriodicSlot & getPeriodicSlotFor(
00952 Events::Period period ) throw() ;
00953
00954
00955
00956
00957
00958
00968 bool _screenshotMode ;
00969
00970
00979 std::string _frameFilenamePrefix ;
00980
00981
00990 Events::Hertz _desiredScreenshotFrequency ;
00991
00992
01002 Events::Period _screenshotPeriod ;
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012 #pragma warning( push )
01013 #pragma warning( disable : 4251 )
01014
01015
01025 std::list<PeriodicSlot *> _periodicSlots ;
01026
01027
01048 std::map<Events::SimulationTick, ListOfActiveObjects>
01049 _programmedActivated ;
01050
01051 #pragma warning( pop )
01052
01053
01059 Ceylan::System::Microsecond _engineTickDuration ;
01060
01061
01069 Ceylan::Uint32 _secondToEngineTick ;
01070
01071
01094 Events::EngineTick _currentEngineTick ;
01095
01096
01118 Events::SimulationTick _currentSimulationTick ;
01119
01120
01142 Events::RenderingTick _currentRenderingTick ;
01143
01144
01166 Events::RenderingTick _currentInputTick ;
01167
01168
01174 Events::Period _simulationPeriod ;
01175
01176
01182 Events::Period _renderingPeriod ;
01183
01184
01190 Events::Period _inputPeriod ;
01191
01192
01200 Events::Hertz _desiredSimulationFrequency ;
01201
01202
01210 Events::Hertz _desiredRenderingFrequency ;
01211
01212
01220 Events::Hertz _desiredInputFrequency ;
01221
01222
01223
01224
01225
01226
01227
01228
01233 Ceylan::System::Callback _idleCallback ;
01234
01235
01240 void * _idleCallbackData ;
01241
01242
01250 Ceylan::System::Microsecond _idleCallbackMaxDuration ;
01251
01252
01258 Ceylan::Uint32 _idleCallsCount ;
01259
01260
01261
01263 bool _stopRequested ;
01264
01265
01270 Ceylan::System::Second _scheduleStartingSecond ;
01271
01272
01277 Ceylan::System::Microsecond _scheduleStartingMicrosecond ;
01278
01279
01280
01286 Ceylan::Uint32 _recoveredSimulationTicks ;
01287
01288
01294 Ceylan::Uint32 _missedSimulationTicks ;
01295
01296
01297
01303 Ceylan::Uint32 _recoveredRenderingTicks ;
01304
01305
01311 Ceylan::Uint32 _missedRenderingTicks ;
01312
01313
01314
01320 Ceylan::Uint32 _recoveredInputPollingTicks ;
01321
01322
01328 Ceylan::Uint32 _missedInputPollingTicks ;
01329
01330
01337 Ceylan::Uint32 _scheduleFailureCount ;
01338
01339
01347 Events::EventsModule * _eventsModule ;
01348
01349
01354 Rendering::Renderer * _renderer ;
01355
01356
01368 Video::VideoModule * _videoModule ;
01369
01370
01371
01372 private:
01373
01374
01383 explicit Scheduler( const Scheduler & source ) throw() ;
01384
01385
01394 Scheduler & operator = ( const Scheduler & source ) throw() ;
01395
01396
01398 static Scheduler * _internalScheduler ;
01399
01400
01401 } ;
01402
01403 }
01404
01405 }
01406
01407
01408 #endif // OSDL_SCHEDULER_H_
01409