2002-07-12 16:24:11 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2003-03-06 21:46:56 +00:00
|
|
|
* Copyright (C) 2002-2003 The ScummVM project
|
2002-07-12 16:24:11 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2002-09-08 01:08:12 +00:00
|
|
|
#ifndef COMMON_UTIL_H
|
|
|
|
#define COMMON_UTIL_H
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-08-01 12:21:04 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/system.h"
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-06-05 03:28:35 +00:00
|
|
|
template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; }
|
|
|
|
template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; }
|
|
|
|
template<typename T> inline T MAX (T a, T b) { return (a>b) ? a : b; }
|
2002-08-25 10:50:18 +00:00
|
|
|
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
|
|
|
* Template method which swaps the vaulues of its two parameters.
|
|
|
|
*/
|
2003-06-14 18:15:14 +00:00
|
|
|
template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
|
2003-05-15 21:40:36 +00:00
|
|
|
|
2003-05-17 23:36:47 +00:00
|
|
|
#define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0])))
|
2002-09-08 01:08:12 +00:00
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
namespace Common {
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
class String;
|
|
|
|
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
2003-10-04 11:50:21 +00:00
|
|
|
* Print a hexdump of the data passed in. The number of bytes per line is
|
|
|
|
* customizable.
|
2003-05-29 11:40:48 +00:00
|
|
|
* @param data the data to be dumped
|
|
|
|
* @param len the lenght of that data
|
|
|
|
* @param bytes_per_line number of bytes to print per line (default: 16)
|
2002-07-25 16:29:07 +00:00
|
|
|
*/
|
2003-10-17 15:35:46 +00:00
|
|
|
extern void hexdump(const byte * data, int len, int bytesPerLine = 16);
|
2002-07-25 16:29:07 +00:00
|
|
|
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
2003-10-04 11:50:21 +00:00
|
|
|
* Simple random number generator. Although it is definitely not suitable for
|
|
|
|
* cryptographic purposes, it serves our purposes just fine.
|
2003-05-29 11:40:48 +00:00
|
|
|
*/
|
2002-12-01 14:57:50 +00:00
|
|
|
class RandomSource {
|
|
|
|
private:
|
|
|
|
uint32 _randSeed;
|
|
|
|
|
|
|
|
public:
|
2003-10-14 10:24:27 +00:00
|
|
|
RandomSource();
|
2002-12-01 14:57:50 +00:00
|
|
|
void setSeed(uint32 seed);
|
2003-05-29 11:40:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a random unsigned integer in the interval [0, max].
|
|
|
|
* @param max the upper bound
|
|
|
|
* @return a random number in the interval [0, max].
|
|
|
|
*/
|
2002-12-01 14:57:50 +00:00
|
|
|
uint getRandomNumber(uint max);
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
|
|
|
* Generates a random unsigned integer in the interval [min, max].
|
|
|
|
* @param min the lower bound
|
|
|
|
* @param max the upper bound
|
|
|
|
* @return a random number in the interval [min, max].
|
|
|
|
*/
|
2002-12-01 14:57:50 +00:00
|
|
|
uint getRandomNumberRng(uint min, uint max);
|
|
|
|
};
|
|
|
|
|
2003-07-05 15:19:11 +00:00
|
|
|
/**
|
|
|
|
* Auxillary class to (un)lock a mutex on the stack.
|
|
|
|
*/
|
|
|
|
class StackLock {
|
|
|
|
OSystem::MutexRef _mutex;
|
2003-07-05 15:28:28 +00:00
|
|
|
OSystem *_syst;
|
2003-07-05 15:19:11 +00:00
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
public:
|
2003-07-05 15:28:28 +00:00
|
|
|
StackLock(OSystem::MutexRef mutex, OSystem *syst = 0);
|
2003-07-05 15:19:11 +00:00
|
|
|
~StackLock();
|
|
|
|
};
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
/**
|
|
|
|
* List of language ids.
|
|
|
|
* @note The order and mappings of the values 0..8 are *required* to stay the
|
|
|
|
* way they are now, as scripts in COMI rely on them. So don't touch them.
|
|
|
|
* I am working on removing this restriction.
|
|
|
|
*/
|
|
|
|
enum Language {
|
|
|
|
UNK_LANG = -1, // Use default language (i.e. none specified)
|
|
|
|
EN_USA = 0,
|
|
|
|
DE_DEU = 1,
|
|
|
|
FR_FRA = 2,
|
|
|
|
IT_ITA = 3,
|
|
|
|
PT_BRA = 4,
|
|
|
|
ES_ESP = 5,
|
|
|
|
JA_JPN = 6,
|
|
|
|
ZH_TWN = 7,
|
|
|
|
KO_KOR = 8,
|
|
|
|
SE_SWE = 9,
|
|
|
|
EN_GRB = 10,
|
|
|
|
HB_HEB = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Convert a string containing a language name into a Language enum value. */
|
|
|
|
extern Language parseLanguage(const String &str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of game platforms. Specifying a platform for a target can be used to
|
|
|
|
* give the game engines a hint for which platform the game data file are.
|
|
|
|
* This may be optional or required, depending on the game engine and the
|
|
|
|
* game in question.
|
|
|
|
*/
|
|
|
|
enum Platform {
|
|
|
|
kPlatformUnknown = -1,
|
|
|
|
kPlatformPC = 0,
|
|
|
|
kPlatformAmiga = 1,
|
|
|
|
kPlatformAtariST = 2,
|
|
|
|
kPlatformMacintosh = 3
|
|
|
|
/*
|
|
|
|
kPlatformNES,
|
|
|
|
kPlatformSEGA,
|
|
|
|
kPlatformFMTowns,
|
|
|
|
kPlatformPCEngine
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Convert a string containing a platform name into a Platform enum value. */
|
|
|
|
extern Platform parsePlatform(const String &str);
|
|
|
|
|
2003-10-04 11:50:21 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
2003-07-05 15:19:11 +00:00
|
|
|
|
2003-09-10 12:15:51 +00:00
|
|
|
|
|
|
|
#if defined(__GNUC__)
|
|
|
|
void CDECL error(const char *s, ...) NORETURN;
|
|
|
|
#else
|
|
|
|
void CDECL NORETURN error(const char *s, ...);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CDECL warning(const char *s, ...);
|
|
|
|
|
|
|
|
void CDECL debug(int level, const char *s, ...);
|
|
|
|
void checkHeap();
|
|
|
|
|
|
|
|
|
2002-07-12 16:24:11 +00:00
|
|
|
#endif
|