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
|
|
|
|
2002-07-12 16:24:11 +00:00
|
|
|
int RGBMatch(byte *palette, int r, int g, int b);
|
|
|
|
int Blend(int src, int dst, byte *palette);
|
2003-05-21 16:59:51 +00:00
|
|
|
void ClearBlendCache();
|
2002-07-12 16:24:11 +00:00
|
|
|
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
|
|
|
* Print a hexdump of the data passed in. The number of bytes per line
|
|
|
|
* is customizable.
|
|
|
|
* @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-05-04 13:46:06 +00:00
|
|
|
void hexdump(const byte * data, int len, int bytes_per_line = 16);
|
2002-07-25 16:29:07 +00:00
|
|
|
|
2003-05-29 11:40:48 +00:00
|
|
|
/**
|
|
|
|
* A simple random number generator. Although it is definitely not suitable
|
|
|
|
* for cryptographic purposes, it serves our purposes just fine.
|
|
|
|
*/
|
2002-12-01 14:57:50 +00:00
|
|
|
class RandomSource {
|
|
|
|
private:
|
|
|
|
uint32 _randSeed;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RandomSource(uint32 seed = 0xA943DE33);
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-07-12 16:24:11 +00:00
|
|
|
#endif
|