Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include "Scheduler.h"
- #include "GOAP/Task.h"
- #include "GOAP/Chain.h"
- #include "GOAP/Source.h"
- #include "GOAP/Event.h"
- #include "GOAP/Semaphore.h"
- #include "GOAP/ChainProvider.h"
- #include "TaskDelay.h"
- #include "TaskPrint.h"
- #include "TaskRoll.h"
- #ifdef _WIN32
- # include <Windows.h>
- # define GOAP_SLEEP(Time) (::Sleep(Time))
- #else
- # include <unistd.h>
- # define GOAP_SLEEP(Time) (::usleep(Time * 1000))
- #endif
- #include <time.h>
- #include <math.h>
- #include <array>
- #include <string>
- #include <typeinfo>
- bool scopeRepeatTest( const GOAP::SourcePtr & _scope, Scheduler * _scheduler)
- {
- GOAP::EventPtr eventWait( new GOAP::Event() );
- GOAP::SemaphorePtr semaphoreWait( new GOAP::Semaphore( eventWait, 0 ) );
- GOAP::SourcePtr source_until = _scope->addRepeat( [_scheduler, semaphoreWait]( const GOAP::SourcePtr & _scope_repeat )
- {
- _scope_repeat->addTask<TaskPrint>( "WAIT 3 SEC" );
- _scope_repeat->addTask<TaskDelay>( 3000.f, _scheduler );
- _scope_repeat->addTask<TaskPrint>( "BEFORE SEMAPHORE ASSIGN" );
- _scope_repeat->addSemaphoreAssign( semaphoreWait, 1 );
- _scope_repeat->addTask<TaskPrint>( "AFTER SEMAPHORE ASSIGN" );
- return true;
- } );
- source_until->addSemaphoreEqual( semaphoreWait, 1 );
- _scope->addTask<TaskPrint>( "END" );
- return true;
- }
- int main()
- {
- Scheduler * sch = new Scheduler;
- srand( (unsigned int)time( NULL ) );
- printf( "%f %f %f\n", fmod( 0.5, 1.0 ), fmod( 1.3, 1.0 ), fmod( 3.0, 1.0 ) );
- GOAP::SourcePtr source( new GOAP::Source() );
- source->addTask<TaskPrint>( "begin" );
- source->addScope( [sch](const GOAP::SourcePtr & _scope )
- {
- return scopeRepeatTest( _scope, sch );
- } );
- GOAP::ChainPtr tc = GOAP::Helper::makeChain( source );
- tc->run();
- while( tc->isComplete() == false )
- {
- sch->update( 100.f );
- GOAP_SLEEP( 10 );
- }
- printf( "FINALIZE\n" );
- delete sch;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement