File: actions.cpp

package info (click to toggle)
qonk 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,076 kB
  • ctags: 2,026
  • sloc: cpp: 14,978; sh: 3,464; makefile: 200
file content (70 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2005 by Anthony Liekens anthony@liekens.net

#include "actions.h"

#include "settings.h"
#include <iostream>

// ##### ACTION #####
using namespace std;

Action::Action() {
	actionID = 0;
}

void
Action::setActionQueue( ActionQueue* actionQueue ) {
	this->actionQueue = actionQueue;
}

ActionQueue*
Action::getActionQueue() const {
	return actionQueue;
}

// ##### ACTIONQUEUE #####

ActionQueue::ActionQueue() {
	clear();
	time = 0;
}

void
ActionQueue::scheduleAction( Uint32 time, Action* action ) {
	if( this->time > time ) {
		std::cerr << "Action was inserted before action that has already been executed" << endl;
	}
	action->setActionQueue( this );
  insert( pair< Uint32, Action* >( time, action ) );
}

Uint32
ActionQueue::timeOfNextEvent() {
  return this->begin()->first;
}

void
ActionQueue::executeNextEvent() {
  time = this->begin()->first;
  Action* a = this->begin()->second;
//  if( time > timer.getTime() ) {
//    SDL_Delay( time - timer.getTime() );
//	}
  a->execute( time );
  erase( this->begin() );
  delete a;
}

void
ActionQueue::executeAllEvents() {
  while( size() > 0 ) {
    executeNextEvent();
  }
}

void ActionQueue::executeEventsBefore( Uint32 time ) {
	while( ( size() > 0 ) && ( timeOfNextEvent() < time ) ) {
 	  executeNextEvent();
	}
}