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  * Additional copyright for this file:
8  * Copyright (C) 1994-1998 Revolution Software Ltd.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24 
25 
26 #include "common/textconsole.h"
27 
28 #include "sword2/sword2.h"
29 #include "sword2/defs.h"
30 #include "sword2/header.h"
31 #include "sword2/logic.h"
32 
33 namespace Sword2 {
34 
35 /**
36  * Clear any syncs registered for this id. Call this just after the id has been
37  * processed. Theoretically there could be more than one sync waiting for us,
38  * so clear the lot.
39  */
40 
clearSyncs(uint32 id)41 void Logic::clearSyncs(uint32 id) {
42 	for (int i = 0; i < ARRAYSIZE(_syncList); i++) {
43 		if (_syncList[i].id == id) {
44 			debug(5, "removing sync %d for %d", i, id);
45 			_syncList[i].id = 0;
46 		}
47 	}
48 }
49 
sendSync(uint32 id,uint32 sync)50 void Logic::sendSync(uint32 id, uint32 sync) {
51 	for (int i = 0; i < ARRAYSIZE(_syncList); i++) {
52 		if (_syncList[i].id == 0) {
53 			debug(5, "%d sends sync %d to %d", readVar(ID), sync, id);
54 			_syncList[i].id = id;
55 			_syncList[i].sync = sync;
56 			return;
57 		}
58 	}
59 
60 	// The original code didn't even check for this condition, so maybe
61 	// it should be a fatal error?
62 
63 	warning("No free sync slot");
64 }
65 
66 /**
67  * Check for a sync waiting for this character. Called from fnAnim() to see if
68  * animation is to be finished. Returns an index into _syncList[], or -1.
69  */
70 
getSync()71 int Logic::getSync() {
72 	uint32 id = readVar(ID);
73 
74 	for (int i = 0; i < ARRAYSIZE(_syncList); i++) {
75 		if (_syncList[i].id == id)
76 			return i;
77 	}
78 
79 	return -1;
80 }
81 
82 } // End of namespace Sword2
83