Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

KoduConditionTimer.cc

Go to the documentation of this file.
00001 #include "Kodu/KoduWorld.h"
00002 #include "Kodu/Primitives/KoduConditionTimer.h"
00003 #include "Shared/get_time.h"
00004 
00005 namespace Kodu {
00006         
00007     bool KoduConditionTimer::evaluate(const KoduWorld& kWorldState) {
00008         // TODO (24/JUL/13) Is needToInitialize necessary?
00009         if (needToInitialize) {     // do initial setup for timer
00010             startTime = getTimeInSec();
00011             timerThreshold = numericGen.getNumericValue();
00012             needToInitialize = false;
00013         }
00014         currentTime = getTimeInSec();
00015         float timeDifference = currentTime - startTime;
00016         if (timeDifference >= timerThreshold) {
00017             timerThreshold = numericGen.getNumericValue();
00018             startTime = getTimeInSec();
00019             if (notModifierEnabled) {
00020                 return false;
00021                 
00022             } else {
00023                 std::cout << "Timer threshold reached [threshold = " << timerThreshold << " secs]\n";
00024                 return true;
00025             }
00026         } else if (timeDifference < timerThreshold && notModifierEnabled) {
00027             std::cout << "Timer threshold NOT reached [threshold = " << timerThreshold << " secs; "
00028                       << "time elasped = " << timeDifference << " secs]\n";
00029             return true;
00030         }
00031         return false;
00032     }
00033 
00034     bool KoduConditionTimer::isSameTypeAs(const KoduPrimitive* kPrimitive) {
00035         return (dynamic_cast<const KoduConditionTimer*>(kPrimitive) != NULL);
00036     }
00037 
00038     void KoduConditionTimer::reinitialize() {
00039         KoduCondition::reinitialize();
00040         needToInitialize = true;
00041     }
00042     
00043     void KoduConditionTimer::printAttrs() const {
00044         KoduCondition::printAttrs();
00045         numericGen.printAttrs();
00046         PRINT_ATTRS("Not enabled", notModifierEnabled);
00047         std::cout << "Current time difference: " << (currentTime - startTime) << std::endl;
00048         std::cout << "Current threshold: " << timerThreshold << std::endl;
00049     }
00050 
00051     float KoduConditionTimer::getTimeInSec() {
00052         return (static_cast<float>(get_time()) / 1000.0f);
00053     }
00054 } // end of Kodu namespace

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:43 2016 by Doxygen 1.6.3