home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WWTCLKit / WWTCLTimer.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.0 KB  |  89 lines

  1.  
  2. #import "WWTCLTimer.h"
  3. #import "WWTCLInterp.h"
  4.  
  5. @implementation WWTCLTimer
  6.  
  7. // function that does what's necessary to the object.  To maximise speed, 
  8. // methodFor: is used.
  9. void static wwtclTimerHandle(DPSTimedEntry tag, double now, char *userdata)
  10. {
  11.    WWTCLTimer *self = (id)userdata;
  12.  
  13.    self->value += self->incrementBy;
  14.    self->syncCounter++;
  15.    if (self->bFlags.sync && (self->syncCounter >= self->syncValue)) 
  16.    {  [self synchronize:self];
  17.       self->syncCounter = 0;
  18.    }
  19.    if (self->bFlags.wrap && (self->value >= self->wrapValue))
  20.    {  self->value = self->startValue;
  21.    }
  22.    if (self->actionFunc)
  23.    {  self->actionFunc(self->target, self->action, self);
  24.    }
  25.  
  26.    [self evalCmd];
  27.  
  28.    return;
  29. }
  30.  
  31. - evalCmd 
  32. {  
  33.    // the idea here is that we have some control string which we want
  34.    // to send to the our interp outlet for it to evaluate.
  35.    // the trick is to have already constructed the control string, 
  36.    // or at least already know if we have to sprintf in our 
  37.    // floating point value.
  38.    [interp globalEval:tclCommand]; 
  39.    return self; 
  40. }
  41.  
  42. - startEntry
  43. {
  44.    if (entry != NULL) 
  45.    {  [self stopEntry];
  46.    }
  47.  
  48.    // get function for method, so we can be super-efficient
  49.    if (target && action)
  50.    {  actionFunc = [target methodFor:action];
  51.    }
  52.  
  53.    // make a new timed entry
  54.    entry = DPSAddTimedEntry(period,(DPSTimedEntryProc)wwtclTimerHandle, self, priority);
  55.  
  56.    // check it
  57.    if ((int)entry == -1) 
  58.    {  [self logError:"Couldn't start timer!\n"];
  59.       entry = NULL;
  60.       return nil;
  61.    }
  62.    return self;
  63. }
  64.  
  65. - interp { return interp; }
  66. - setInterp:newInterp { interp = newInterp; return self; }
  67.  
  68. - init
  69. {
  70.   [super init];
  71.  
  72.   controlStringSize = 32;
  73.   controlString = (char *)NXZoneCalloc([self zone], controlStringSize, sizeof(char));
  74.   tclCommandSize = 32;
  75.   tclCommand = (char *)NXZoneCalloc([self zone], tclCommandSize, sizeof(char));
  76.  
  77.   return self;
  78. }
  79.  
  80. - free
  81. {
  82.   if (controlString) { NXZoneFree([self zone], controlString); }
  83.   if (tclCommand) { NXZoneFree([self zone], tclCommand); }
  84.   return [super free];
  85. }
  86.  
  87.  
  88. @end
  89.