ScummVM API documentation
px_globalvariables.h
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) 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 modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (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, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef ICB_PXGLOBALVARIABLES
28 #define ICB_PXGLOBALVARIABLES
29 
30 #include "common/noncopyable.h"
31 #include "engines/icb/common/px_common.h"
32 #include "engines/icb/common/px_clu_api.h"
33 
34 namespace ICB {
35 
36 #define MAX_global_vars 256
37 
38 #define GLOBAL_VAR_NOT_SET (0)
39 #define GLOBAL_VAR_SET (1)
40 
41 class CpxVariable {
42 public:
43  uint32 hash;
44  int32 value;
45 };
46 
48 private:
49  CpxVariable m_vars[MAX_global_vars];
50 
51  // This is not part of the CpxVariable class - because of memory packing reasons
52  uint8 m_varInit[MAX_global_vars];
53 
54  uint32 m_no_vars;
55  uint32 m_sorted;
56 
57 public:
59 
60  void SortVariables();
61  int32 GetVariable(uint32 hash, const char *name = NULL, int32 warn = 1); // Get a variable by hash
62  int32 GetVariable(const char *n) { // Get a variable
63  return GetVariable(EngineHashString(n), n);
64  }
65 
66  void SetVariable(uint32, int32); // Set a variable by hash
67  void SetVariable(const char *n, int32 i) { // Set a variable
68  SetVariable(EngineHashString(n), i);
69  }
70 
71  void InitVariable(uint32, int32, const char *name = NULL); // First time initialise a variable by hash
72  void InitVariable(const char *n, int32 i) { // First time initialise a variable
73  InitVariable(EngineHashString(n), i, n);
74  }
75 
76  int32 FindVariable(uint32); // is this variable taken
77  int32 FindVariable(const char *n) { // is this variable taken
78  return FindVariable(EngineHashString(n));
79  }
80 
81  uint32 GetNoItems() { return (m_no_vars); }
82 
83  const CpxVariable &operator[](uint32 n) { return (m_vars[n]); } // Return reference to variable itself (const)
84 };
85 
86 } // End of namespace ICB
87 
88 #endif
Definition: actor.h:32
Definition: noncopyable.h:39
Definition: px_globalvariables.h:41
Definition: px_globalvariables.h:47