2002-07-12 16:24:11 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2002-2004 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"
|
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
|
2003-11-01 20:44:53 +00:00
|
|
|
* @param bytesPerLine 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-11-08 22:43:46 +00:00
|
|
|
|
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-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,
|
2004-02-10 13:24:12 +00:00
|
|
|
HB_ISR = 20,
|
2004-01-06 12:28:24 +00:00
|
|
|
RU_RUS = 21,
|
2004-02-10 04:59:02 +00:00
|
|
|
CZ_CZE = 22,
|
2004-02-10 12:37:40 +00:00
|
|
|
NL_NLD = 23
|
2003-10-17 15:35:46 +00:00
|
|
|
};
|
|
|
|
|
2003-11-05 00:58:02 +00:00
|
|
|
struct LanguageDescription {
|
2003-12-30 19:07:55 +00:00
|
|
|
const char *code;
|
2003-11-05 00:58:02 +00:00
|
|
|
const char *description;
|
|
|
|
Common::Language id;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const LanguageDescription g_languages[];
|
|
|
|
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
/** Convert a string containing a language name into a Language enum value. */
|
|
|
|
extern Language parseLanguage(const String &str);
|
2003-12-30 19:07:55 +00:00
|
|
|
extern const char *getLanguageCode(Language id);
|
|
|
|
extern const char *getLanguageDescription(Language id);
|
2003-10-17 15:35:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2004-02-07 16:01:00 +00:00
|
|
|
kPlatformMacintosh = 3,
|
2004-03-02 00:37:23 +00:00
|
|
|
kPlatformFMTowns = 4,
|
|
|
|
kPlatformWindows = 5
|
2003-10-17 15:35:46 +00:00
|
|
|
/*
|
|
|
|
kPlatformNES,
|
|
|
|
kPlatformSEGA,
|
|
|
|
kPlatformPCEngine
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
|
2004-02-07 17:10:48 +00:00
|
|
|
struct PlatformDescription {
|
|
|
|
const char *code;
|
|
|
|
const char *code2;
|
|
|
|
const char *description;
|
|
|
|
Common::Platform id;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern const PlatformDescription g_platforms[];
|
|
|
|
|
|
|
|
|
2003-10-17 15:35:46 +00:00
|
|
|
/** Convert a string containing a platform name into a Platform enum value. */
|
|
|
|
extern Platform parsePlatform(const String &str);
|
2003-12-30 19:07:55 +00:00
|
|
|
extern const char *getPlatformCode(Platform id);
|
|
|
|
extern const char *getPlatformDescription(Platform id);
|
2003-10-17 15:35:46 +00:00
|
|
|
|
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, ...);
|
2004-01-10 05:20:15 +00:00
|
|
|
void CDECL debug(const char *s, ...);
|
2003-09-10 12:15:51 +00:00
|
|
|
void checkHeap();
|
|
|
|
|
|
|
|
|
2002-07-12 16:24:11 +00:00
|
|
|
#endif
|