[Scummvm-cvs-logs] scummvm master -> c99310820720714083b34d7d01080c54c977eb75

Strangerke Strangerke at scummvm.org
Thu Sep 15 08:10:54 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c993108207 CGE: Transform some static and globals into class members


Commit: c99310820720714083b34d7d01080c54c977eb75
    https://github.com/scummvm/scummvm/commit/c99310820720714083b34d7d01080c54c977eb75
Author: Strangerke (strangerke at scummvm.org)
Date: 2011-09-14T23:00:54-07:00

Commit Message:
CGE: Transform some static and globals into class members

Changed paths:
    engines/cge/bitmap.cpp
    engines/cge/bitmap.h
    engines/cge/cge.cpp
    engines/cge/cge.h
    engines/cge/cge_main.cpp
    engines/cge/cge_main.h
    engines/cge/game.cpp
    engines/cge/general.cpp
    engines/cge/general.h
    engines/cge/snail.cpp
    engines/cge/sound.cpp
    engines/cge/talk.cpp
    engines/cge/talk.h
    engines/cge/text.cpp
    engines/cge/vga13h.cpp



diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp
index f160085..5028cbe 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 bc37591..3e195fa 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 11c722d..1297aea 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 c65c780..f62280a 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 ee6fb2a..86ea267 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 2f0e88b..a71a72e 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 0c4f597..f3855c1 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 fff3ff0..f3f24d9 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 02c9f7f..9e3fc7f 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 5d7ba50..1acfd1f 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 26a06ca..3dec5e7 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 8fd425d..6cbeb6d 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 23ef9c9..dcccc5e 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 1f2f696..3268070 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 9df61fa..286fadd 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,;/"));






More information about the Scummvm-git-logs mailing list