/* 
 * Thomas Pantzer: t_trigger.cc, v0.4.7  8.6.99 16:32 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */




#include "copyright.h"


#include "timer.h"


#define _T_TRIGGER_G
#include "t_trigger.h"


void t_trigger::Init(int l)
{
	len = l;

	delta = new long int [len];	
	last = new long int [len];	
	started = new char [len];

	for (int i=0; i<len; i++)
	  started[i] = false;
} 

void t_trigger::Done(void)
{
	delete delta;
	delete last;
	delete started;
}

void t_trigger::Register(int id, long int ms)
{
	if ((id >= len) || (id < 0))
	  return;

	delta[id] = ms;
}

void t_trigger::Update(void)
{
	now = GetTime();
}

char t_trigger::Snapped(int id)
{
	if ((id >= len) || (id < 0))
	   return false;

	if (started[id] == true)
	   {
	    if (now <= (last[id] + delta[id]))
	       return false;
	   }
	 else 
	    started[id] = true; 

	last[id] = now;
	return true;
}

