Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. #include "Scheduler.h"
  4.  
  5. #include "GOAP/Task.h"
  6. #include "GOAP/Chain.h"
  7. #include "GOAP/Source.h"
  8. #include "GOAP/Event.h"
  9. #include "GOAP/Semaphore.h"
  10. #include "GOAP/ChainProvider.h"
  11.  
  12. #include "TaskDelay.h"
  13. #include "TaskPrint.h"
  14. #include "TaskRoll.h"
  15.  
  16. #ifdef _WIN32
  17. #   include <Windows.h>
  18. #   define GOAP_SLEEP(Time) (::Sleep(Time))
  19. #else
  20. #   include <unistd.h>
  21. #   define GOAP_SLEEP(Time) (::usleep(Time * 1000))
  22. #endif
  23.  
  24. #include <time.h>
  25. #include <math.h>
  26.  
  27. #include <array>
  28. #include <string>
  29. #include <typeinfo>
  30.  
  31. bool scopeRepeatTest( const GOAP::SourcePtr & _scope,  Scheduler * _scheduler)
  32. {
  33.  
  34.     GOAP::EventPtr eventWait( new GOAP::Event() );
  35.     GOAP::SemaphorePtr semaphoreWait( new GOAP::Semaphore( eventWait, 0 ) );
  36.  
  37.     GOAP::SourcePtr source_until = _scope->addRepeat( [_scheduler, semaphoreWait]( const GOAP::SourcePtr & _scope_repeat )
  38.     {
  39.         _scope_repeat->addTask<TaskPrint>( "WAIT 3 SEC" );
  40.         _scope_repeat->addTask<TaskDelay>( 3000.f, _scheduler );
  41.  
  42.         _scope_repeat->addTask<TaskPrint>( "BEFORE SEMAPHORE ASSIGN" );
  43.         _scope_repeat->addSemaphoreAssign( semaphoreWait, 1 );
  44.         _scope_repeat->addTask<TaskPrint>( "AFTER SEMAPHORE ASSIGN" );
  45.  
  46.         return true;
  47.     } );
  48.  
  49.     source_until->addSemaphoreEqual( semaphoreWait, 1 );
  50.  
  51.     _scope->addTask<TaskPrint>( "END" );
  52.  
  53.     return true;
  54. }
  55.  
  56. int main()
  57. {
  58.     Scheduler * sch = new Scheduler;
  59.  
  60.     srand( (unsigned int)time( NULL ) );
  61.  
  62.     printf( "%f %f %f\n", fmod( 0.5, 1.0 ), fmod( 1.3, 1.0 ), fmod( 3.0, 1.0 ) );
  63.  
  64.     GOAP::SourcePtr source( new GOAP::Source() );
  65.    
  66.     source->addTask<TaskPrint>( "begin" );
  67.  
  68.     source->addScope( [sch](const GOAP::SourcePtr & _scope )
  69.     {
  70.         return scopeRepeatTest( _scope, sch );
  71.     } );
  72.  
  73.     GOAP::ChainPtr tc = GOAP::Helper::makeChain( source );
  74.  
  75.     tc->run();
  76.  
  77.     while( tc->isComplete() == false )
  78.     {
  79.         sch->update( 100.f );
  80.  
  81.         GOAP_SLEEP( 10 );
  82.     }
  83.  
  84.     printf( "FINALIZE\n" );
  85.  
  86.     delete sch;
  87.  
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement