diff options
| -rw-r--r-- | engines/cge/bitmap.cpp | 10 | ||||
| -rw-r--r-- | engines/cge/bitmap.h | 12 | ||||
| -rw-r--r-- | engines/cge/cge.cpp | 4 | ||||
| -rw-r--r-- | engines/cge/cge.h | 25 | ||||
| -rw-r--r-- | engines/cge/cge_main.cpp | 34 | ||||
| -rw-r--r-- | engines/cge/cge_main.h | 2 | ||||
| -rw-r--r-- | engines/cge/game.cpp | 10 | ||||
| -rw-r--r-- | engines/cge/general.cpp | 58 | ||||
| -rw-r--r-- | engines/cge/general.h | 14 | ||||
| -rw-r--r-- | engines/cge/snail.cpp | 2 | ||||
| -rw-r--r-- | engines/cge/sound.cpp | 17 | ||||
| -rw-r--r-- | engines/cge/talk.cpp | 28 | ||||
| -rw-r--r-- | engines/cge/talk.h | 18 | ||||
| -rw-r--r-- | engines/cge/text.cpp | 2 | ||||
| -rw-r--r-- | engines/cge/vga13h.cpp | 8 | 
15 files changed, 111 insertions, 133 deletions
| diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index f1600854b2..5028cbeb1a 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -155,6 +155,16 @@ Bitmap &Bitmap::operator=(const Bitmap &bmp) {  	return *this;  } +char *Bitmap::forceExt(char *buf, const char *name, const char *ext) { +	strcpy(buf, name); +	char *dot = strrchr(buf, '.'); +	if (dot) +		*dot = '\0'; +	strcat(buf, ext); + +	return buf; +} +  uint16 Bitmap::moveVmap(uint8 *buf) {  	debugC(1, kCGEDebugBitmap, "Bitmap::moveVmap(buf)"); diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index bc37591399..3e195fad14 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -33,12 +33,13 @@  namespace CGE { -#define kBmpEOI      0x0000 -#define kBmpSKP      0x4000 -#define kBmpREP      0x8000 -#define kBmpCPY      0xC000 -  #define kMaxPath  128 +enum { +	kBmpEOI = 0x0000, +	kBmpSKP = 0x4000, +	kBmpREP = 0x8000, +	kBmpCPY = 0xC000 +};  #include "common/pack-start.h" @@ -50,6 +51,7 @@ struct HideDesc {  #include "common/pack-end.h"  class Bitmap { +	char *forceExt(char *buf, const char *name, const char *ext);  	bool loadVBM(EncryptedStream *f);  public:  	static Dac *_pal; diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 11c722d32b..1297aea5e3 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -86,10 +86,10 @@ void CGEEngine::init() {  	// Initialise classes that have static members  	Bitmap::init(); -	Talk::init();  	Cluster::init(this);  	// Initialise engine objects +	_font = new Font(this, "CGE");  	_text = new Text(this, "CGE");  	_vga = new Vga();  	_sys = new System(this); @@ -141,7 +141,6 @@ void CGEEngine::init() {  void CGEEngine::deinit() {  	// Call classes with static members to clear them up -	Talk::deinit();  	Bitmap::deinit();  	Cluster::init(this); @@ -168,6 +167,7 @@ void CGEEngine::deinit() {  	delete _eventManager;  	delete _fx;  	delete _sound; +	delete _font;  	delete _snail;  	delete _snail_;  	delete _hero; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index c65c780f6e..f62280aabc 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -23,7 +23,6 @@  #ifndef CGE_H  #define CGE_H -#include "cge/general.h"  #include "common/random.h"  #include "common/savefile.h"  #include "common/serializer.h" @@ -57,6 +56,9 @@ class Sprite;  #define kSceneNx    8  #define kSceneNy    3  #define kSceneMax   kSceneNx * kSceneNy +#define kPathMax    128 +#define kCryptSeed  0xA5 +#define kMaxFile    128  // our engine debug channels @@ -90,6 +92,20 @@ struct Bar {  	uint8 _vert;  }; +class Font { +	char _path[kPathMax]; +	void load(); +	CGEEngine *_vm; +public: +	uint8  *_widthArr; +	uint16 *_pos; +	uint8  *_map; +	Font(CGEEngine *vm, const char *name); +	~Font(); +	uint16 width(const char *text); +	void save(); +}; +  class CGEEngine : public Engine {  private:  	uint32 _lastFrame, _lastTick; @@ -136,7 +152,8 @@ public:  	Sprite *_sprK3;  	Common::Point _heroXY[kSceneMax]; -	Bar _barriers[kSceneMax]; +	Bar _barriers[kSceneMax + 1]; +	Font *_font;  	Common::RandomSource _randomSource;  	MusicPlayer _midiPlayer; @@ -209,6 +226,10 @@ public:  	void postMiniStep(int stp);  	void showBak(int ref);  	void initSceneValues(); +	char *mergeExt(char *buf, const char *name, const char *ext); +	int  takeEnum(const char **tab, const char *text); +	int  newRandom(int range); +	void sndSetVolume();  	void snBackPt(Sprite *spr, int stp);  	void snHBarrier(const int scene, const int barX); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ee6fb2a951..86ea267c80 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -139,6 +139,38 @@ const Dac g_stdPal[] =  {// R    G   B  	{ 255, 255, 255},   // 255  }; +char *CGEEngine::mergeExt(char *buf, const char *name, const char *ext) { +	strcpy(buf, name); +	char *dot = strrchr(buf, '.'); +	if (!dot) +		strcat(buf, ext); + +	return buf; +} + +int CGEEngine::takeEnum(const char **tab, const char *text) { +	const char **e; +	if (text) { +		for (e = tab; *e; e++) { +			if (scumm_stricmp(text, *e) == 0) { +				return e - tab; +			} +		} +	} +	return -1; +} + +int CGEEngine::newRandom(int range) { +	if (!range) +		return 0; + +	return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); +} + +void CGEEngine::sndSetVolume() { +	// USeless for ScummVM +} +  void CGEEngine::syncHeader(Common::Serializer &s) {  	debugC(1, kCGEDebugEngine, "CGEEngine::syncHeader(s)"); @@ -823,7 +855,7 @@ void System::tick() {  				if (_vm->_flag[0]) // Pain flag  					_vm->heroCover(9);  				else { // CHECKME: Before, was: if (Startup::_core >= CORE_MID) { -					int n = newRandom(100); +					int n = _vm->newRandom(100);  					if (n > 96)  						_vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2));  					else if (n > 90) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 2f0e88b9df..a71a72e5a7 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -89,8 +89,6 @@ namespace CGE {  #define kGameFrameDelay (1000 / 50)  #define kGameTickDelay  (1000 / 62) - -  class System : public Sprite {  public:  	int _funDel; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 0c4f5971bc..f3855c147d 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -50,17 +50,17 @@ const int Fly::_l = 20,  Fly::Fly(CGEEngine *vm, Bitmap **shpl)  	: Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { -	step(newRandom(2)); -	gotoxy(_l + newRandom(_r - _l - _w), _t + newRandom(_b - _t - _h)); +	step(_vm->newRandom(2)); +	gotoxy(_l + _vm->newRandom(_r - _l - _w), _t + _vm->newRandom(_b - _t - _h));  }  void Fly::tick() {  	step();  	if (_flags._kept)  		return; -	if (newRandom(10) < 1) { -		_tx = newRandom(3) - 1; -		_ty = newRandom(3) - 1; +	if (_vm->newRandom(10) < 1) { +		_tx = _vm->newRandom(3) - 1; +		_ty = _vm->newRandom(3) - 1;  	}  	if (_x + _tx < _l || _x + _tx + _w > _r)  		_tx = -_tx; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index fff3ff0212..f3f24d9a47 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -30,63 +30,5 @@  namespace CGE { -char *mergeExt(char *buf, const char *name, const char *ext) { -	strcpy(buf, name); -	char *dot = strrchr(buf, '.'); -	if (!dot) -		strcat(buf, ext); - -	return buf; -} - -char *forceExt(char *buf, const char *name, const char *ext) { -	strcpy(buf, name); -	char *dot = strrchr(buf, '.'); -	if (dot) -		*dot = '\0'; -	strcat(buf, ext); - -	return buf; -} - -void sndSetVolume() { -	// USeless for ScummVM -} - -DataCk *loadWave(EncryptedStream *file) { -	byte *data = (byte *)malloc(file->size()); -	file->read(data, file->size()); - -	return new DataCk(data, file->size()); -} - -int takeEnum(const char **tab, const char *text) { -	const char **e; -	if (text) { -		for (e = tab; *e; e++) { -			if (scumm_stricmp(text, *e) == 0) { -				return e - tab; -			} -		} -	} -	return -1; -} - -int newRandom(int range) { -	if (!range) -		return 0; - -	return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); -} - -DataCk::DataCk(byte *buf, int bufSize) { -	_buf = buf; -	_ckSize = bufSize; -} - -DataCk::~DataCk() { -	free(_buf); -} -  } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 02c9f7fd9a..9e3fc7f249 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -28,30 +28,16 @@  #ifndef CGE_GENERAL_H  #define CGE_GENERAL_H -#include "common/system.h"  #include "common/file.h" -#include "common/random.h" -#include "common/textconsole.h" -#include "common/str.h"  namespace CGE { -#define kCryptSeed  0xA5 -#define kMaxFile      128 -  struct Dac {  	uint8 _r;  	uint8 _g;  	uint8 _b;  }; -int     takeEnum(const char **tab, const char *text); -uint16  chkSum(void *m, uint16 n); -char   *mergeExt(char *buf, const char *name, const char *ext); -char   *forceExt(char *buf, const char *name, const char *ext); -int     newRandom(int range); -void    sndSetVolume(); -  } // End of namespace CGE  #endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 5d7ba502d1..1acfd1f9d5 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -1150,7 +1150,7 @@ void Snail::runCom() {  				_vm->xScene();  				break;  			case kSndSetVolume: -				sndSetVolume(); +				_vm->sndSetVolume();  				break;  			default:  				error("Unknown Callback Type in SNEXEC"); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 26a06cae41..3dec5e749b 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -25,7 +25,6 @@   * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon   */ -#include "cge/general.h"  #include "cge/sound.h"  #include "cge/text.h"  #include "cge/cge_main.h" @@ -36,6 +35,22 @@  namespace CGE { +DataCk *loadWave(EncryptedStream *file) { +	byte *data = (byte *)malloc(file->size()); +	file->read(data, file->size()); + +	return new DataCk(data, file->size()); +} + +DataCk::DataCk(byte *buf, int bufSize) { +	_buf = buf; +	_ckSize = bufSize; +} + +DataCk::~DataCk() { +	free(_buf); +} +  Sound::Sound(CGEEngine *vm) : _vm(vm) {  	_audioStream = NULL;  	_soundRepeatCount = 1; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 8fd425d328..6cbeb6d940 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -33,13 +33,13 @@  namespace CGE { -Font::Font(const char *name) { +Font::Font(CGEEngine *vm, const char *name) : _vm(vm) {  	_map = (uint8 *)malloc(kMapSize);  	_pos = (uint16 *)malloc(kPosSize * sizeof(uint16));  	_widthArr = (uint8 *)malloc(kWidSize);  	assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL)); -	mergeExt(_path, name, kFontExt); +	_vm->mergeExt(_path, name, kFontExt);  	load();  } @@ -87,16 +87,6 @@ Talk::Talk(CGEEngine *vm)  	_flags._syst = true;  } -Font *Talk::_font; - -void Talk::init() { -	_font = new Font("CGE"); -} - -void Talk::deinit() { -	delete _font; -} -  void Talk::update(const char *text) {  	const uint16 vmarg = (_mode) ? kTextVMargin : 0;  	const uint16 hmarg = (_mode) ? kTextHMargin : 0; @@ -114,7 +104,7 @@ void Talk::update(const char *text) {  					mw = k;  				k = 2 * hmarg;  			} else -				k += _font->_widthArr[(unsigned char)*p]; +				k += _vm->_font->_widthArr[(unsigned char)*p];  		}  		if (k > mw)  			mw = k; @@ -130,8 +120,8 @@ void Talk::update(const char *text) {  		if (*text == '|' || *text == '\n') {  			m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg;  		} else { -			int cw = _font->_widthArr[(unsigned char)*text]; -			uint8 *f = _font->_map + _font->_pos[(unsigned char)*text]; +			int cw = _vm->_font->_widthArr[(unsigned char)*text]; +			uint8 *f = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text];  			for (int i = 0; i < cw; i++) {  				uint8 *pp = m;  				uint16 n; @@ -221,8 +211,8 @@ void Talk::putLine(int line, const char *text) {  	uint8 *q = v + size;  	while (*text) { -		uint16 cw = _font->_widthArr[(unsigned char)*text], i; -		uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; +		uint16 cw = _vm->_font->_widthArr[(unsigned char)*text], i; +		uint8 *fp = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text];  		for (i = 0; i < cw; i++) {  			uint16 b = fp[i]; @@ -278,8 +268,8 @@ void InfoLine::update(const char *text) {  		uint8 *p = v + 2, * q = p + size;  		while (*text) { -			uint16 cw = _font->_widthArr[(unsigned char)*text]; -			uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; +			uint16 cw = _vm->_font->_widthArr[(unsigned char)*text]; +			uint8 *fp = _vm->_font->_map + _vm->_font->_pos[(unsigned char)*text];  			for (uint16 i = 0; i < cw; i++) {  				uint16 b = fp[i]; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 23ef9c9c07..dcccc5e20e 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -44,23 +44,9 @@ namespace CGE {  #define kMapSize          (256*8)  #define kFontHigh          8  #define kFontExt           ".CFT" -#define kPathMax           128  enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; -class Font { -	char _path[kPathMax]; -	void load(); -public: -	uint8  *_widthArr; -	uint16 *_pos; -	uint8  *_map; -	Font(const char *name); -	~Font(); -	uint16 width(const char *text); -	void save(); -}; -  class Talk : public Sprite {  protected:  	TextBoxStyle _mode; @@ -71,10 +57,6 @@ public:  	Talk(CGEEngine *vm);  	//~TALK(); -	static Font *_font; -	static void init(); -	static void deinit(); -  	virtual void update(const char *text);  	virtual void update() {}  	void putLine(int line, const char *text); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 1f2f696f8c..3268070aff 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -39,7 +39,7 @@ Text *_text;  Talk *_talk = NULL;  Text::Text(CGEEngine *vm, const char *fname) : _vm(vm) { -	mergeExt(_fileName, fname, kSayExt); +	_vm->mergeExt(_fileName, fname, kSayExt);  	if (!_resman->exist(_fileName))  		error("No talk (%s)\n", _fileName);  	int16 txtCount = count() + 1; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 9df61fa8a3..286fadd1ef 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -225,7 +225,7 @@ Sprite *Sprite::expand() {  	Snail::Com *nearList = NULL;  	Snail::Com *takeList = NULL; -	mergeExt(fname, _file, kSprExt); +	_vm->mergeExt(fname, _file, kSprExt);  	if (_resman->exist(fname)) { // sprite description file exist  		EncryptedStream sprf(fname);  		if (sprf.err()) @@ -242,7 +242,7 @@ Sprite *Sprite::expand() {  				continue;  			Snail::Com *c; -			switch (takeEnum(Comd, strtok(tmpStr, " =\t"))) { +			switch (_vm->takeEnum(Comd, strtok(tmpStr, " =\t"))) {  			case 0:  				// Name  				setName(strtok(NULL, "")); @@ -287,7 +287,7 @@ Sprite *Sprite::expand() {  				nearList = (Snail::Com *)realloc(nearList, (nearCount + 1) * sizeof(*nearList));  				assert(nearList != NULL);  				c = &nearList[nearCount++]; -				if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) +				if ((c->_com = (SnCom)_vm->takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)  					error("Bad NEAR in %d [%s]", lcnt, fname);  				c->_ref = atoi(strtok(NULL, " \t,;/"));  				c->_val = atoi(strtok(NULL, " \t,;/")); @@ -300,7 +300,7 @@ Sprite *Sprite::expand() {  				takeList = (Snail::Com *)realloc(takeList, (takeCount + 1) * sizeof(*takeList));  				assert(takeList != NULL);  				c = &takeList[takeCount++]; -				if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) +				if ((c->_com = (SnCom)_vm->takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0)  					error("Bad NEAR in %d [%s]", lcnt, fname);  				c->_ref = atoi(strtok(NULL, " \t,;/"));  				c->_val = atoi(strtok(NULL, " \t,;/")); | 
