1 /* ResidualVM - A 3D game interpreter 2 * 3 * ResidualVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the AUTHORS 5 * file distributed with this source distribution. 6 * 7 * Additional copyright for this file: 8 * Copyright (C) 1999-2000 Revolution Software Ltd. 9 * This code is based on source code created by Revolution Software, 10 * used with permission. 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * You should have received a copy of the GNU General Public License 23 * along with this program; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 25 * 26 */ 27 28 #ifndef ICB_PXGLOBALVARIABLES 29 #define ICB_PXGLOBALVARIABLES 30 31 #include "common/noncopyable.h" 32 #include "engines/icb/common/px_common.h" 33 #include "engines/icb/common/px_clu_api.h" 34 35 namespace ICB { 36 37 void Fatal_error(const char *format, ...); // Game engine compatible error routine 38 39 #define MAX_global_vars 256 40 41 #define GLOBAL_VAR_NOT_SET (0) 42 #define GLOBAL_VAR_SET (1) 43 44 class CpxVariable { 45 public: 46 uint32 hash; 47 int32 value; 48 }; 49 50 class CpxGlobalScriptVariables : Common::NonCopyable { 51 private: 52 CpxVariable m_vars[MAX_global_vars]; 53 54 // This is not part of the CpxVariable class - because of memory packing reasons 55 uint8 m_varInit[MAX_global_vars]; 56 57 uint32 m_no_vars; 58 uint32 m_sorted; 59 60 public: 61 CpxGlobalScriptVariables(); 62 63 void SortVariables(); 64 int32 GetVariable(uint32 hash, const char *name = NULL, int32 warn = 1); // Get a variable by hash GetVariable(const char * n)65 int32 GetVariable(const char *n) { // Get a variable 66 return GetVariable(EngineHashString(n), n); 67 } 68 69 void SetVariable(uint32, int32); // Set a variable by hash SetVariable(const char * n,int32 i)70 void SetVariable(const char *n, int32 i) { // Set a variable 71 SetVariable(EngineHashString(n), i); 72 } 73 74 void InitVariable(uint32, int32, const char *name = NULL); // First time initialise a variable by hash InitVariable(const char * n,int32 i)75 void InitVariable(const char *n, int32 i) { // First time initialise a variable 76 InitVariable(EngineHashString(n), i, n); 77 } 78 79 int32 FindVariable(uint32); // is this variable taken FindVariable(const char * n)80 int32 FindVariable(const char *n) { // is this variable taken 81 return FindVariable(EngineHashString(n)); 82 } 83 GetNoItems()84 uint32 GetNoItems() { return (m_no_vars); } 85 86 const CpxVariable &operator[](uint32 n) { return (m_vars[n]); } // Return reference to variable itself (const) 87 }; 88 89 } // End of namespace ICB 90 91 #endif 92