1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "bladerunner/movement_track.h"
24 
25 #include "bladerunner/savefile.h"
26 
27 namespace BladeRunner {
28 
MovementTrack()29 MovementTrack::MovementTrack() {
30 	reset();
31 }
32 
~MovementTrack()33 MovementTrack::~MovementTrack() {
34 	reset();
35 }
36 
reset()37 void MovementTrack::reset() {
38 	_currentIndex = -1;
39 	_lastIndex = 0;
40 	_hasNext = false;
41 	_paused = false;
42 	for (int i = 0; i < kSize; ++i) {
43 		_entries[i].waypointId = -1;
44 		_entries[i].delay = -1;
45 		_entries[i].angle = -1;
46 		_entries[i].run = false;
47 	}
48 }
49 
append(int waypointId,int32 delayMillis,bool run)50 int MovementTrack::append(int waypointId, int32 delayMillis, bool run) {
51 	return append(waypointId, delayMillis, -1, run);
52 }
53 
append(int waypointId,int32 delayMillis,int angle,bool run)54 int MovementTrack::append(int waypointId, int32 delayMillis, int angle, bool run) {
55 	if (_lastIndex >= kSize) {
56 		return 0;
57 	}
58 
59 	_entries[_lastIndex].waypointId = waypointId;
60 	_entries[_lastIndex].delay = delayMillis;
61 	_entries[_lastIndex].angle = angle;
62 	_entries[_lastIndex].run = run;
63 
64 	++_lastIndex;
65 	_hasNext = true;
66 	_currentIndex = 0;
67 	return 1;
68 }
69 
flush()70 void MovementTrack::flush() {
71 	reset();
72 }
73 
repeat()74 void MovementTrack::repeat() {
75 	_currentIndex = 0;
76 	_hasNext = true;
77 }
78 
pause()79 void MovementTrack::pause() {
80 	_paused = true;
81 }
82 
unpause()83 void MovementTrack::unpause() {
84 	_paused = false;
85 }
86 
isPaused() const87 bool MovementTrack::isPaused() const {
88 	return _paused;
89 }
90 
hasNext() const91 bool MovementTrack::hasNext() const {
92 	return _hasNext;
93 }
94 
next(int * waypointId,int32 * delayMillis,int * angle,bool * run)95 bool MovementTrack::next(int *waypointId, int32 *delayMillis, int *angle, bool *run) {
96 	if (_currentIndex < _lastIndex && _hasNext) {
97 		*waypointId = _entries[_currentIndex].waypointId;
98 		*delayMillis = _entries[_currentIndex].delay;
99 		*angle = _entries[_currentIndex].angle;
100 		*run = _entries[_currentIndex++].run;
101 		return true;
102 	} else {
103 		*waypointId = -1;
104 		*delayMillis = -1;
105 		*angle = -1;
106 		*run = false;
107 		_hasNext = false;
108 		return false;
109 	}
110 }
111 
save(SaveFileWriteStream & f)112 void MovementTrack::save(SaveFileWriteStream &f) {
113 	f.writeInt(_currentIndex);
114 	f.writeInt(_lastIndex);
115 	f.writeBool(_hasNext);
116 	f.writeBool(_paused);
117 	for (int i = 0; i < kSize; ++i) {
118 		Entry &e = _entries[i];
119 		f.writeInt(e.waypointId);
120 		f.writeInt(e.delay);
121 		f.writeInt(e.angle);
122 		f.writeBool(e.run);
123 	}
124 }
125 
load(SaveFileReadStream & f)126 void MovementTrack::load(SaveFileReadStream &f) {
127 	_currentIndex = f.readInt();
128 	_lastIndex = f.readInt();
129 	_hasNext = f.readBool();
130 	_paused = f.readBool();
131 	for (int i = 0; i < kSize; ++i) {
132 		Entry &e = _entries[i];
133 		e.waypointId = f.readInt();
134 		e.delay = f.readInt();
135 		e.angle = f.readInt();
136 		e.run = f.readBool();
137 	}
138 }
139 
140 } // End of namespace BladeRunner
141