[Scummvm-cvs-logs] SF.net SVN: scummvm: [25223] scummvm/trunk/engines/scumm

cyx at users.sourceforge.net cyx at users.sourceforge.net
Sat Jan 27 03:26:37 CET 2007


Revision: 25223
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25223&view=rev
Author:   cyx
Date:     2007-01-26 18:26:37 -0800 (Fri, 26 Jan 2007)

Log Message:
-----------
cleanup (made NutRenderer::loadFont protected, added call during initialisation of the renderer object)

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/charset.cpp
    scummvm/trunk/engines/scumm/insane/insane.cpp
    scummvm/trunk/engines/scumm/nut_renderer.cpp
    scummvm/trunk/engines/scumm/nut_renderer.h
    scummvm/trunk/engines/scumm/smush/smush_font.cpp
    scummvm/trunk/engines/scumm/smush/smush_font.h
    scummvm/trunk/engines/scumm/smush/smush_player.cpp

Modified: scummvm/trunk/engines/scumm/charset.cpp
===================================================================
--- scummvm/trunk/engines/scumm/charset.cpp	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/charset.cpp	2007-01-27 02:26:37 UTC (rev 25223)
@@ -1610,8 +1610,6 @@
 
 CharsetRendererNut::~CharsetRendererNut() {
 	for (int i = 0; i < 5; i++) {
-		if ((_vm->_game.id == GID_CMI) && (_vm->_game.features & GF_DEMO) && (i == 4))
-			break;
 		delete _fr[i];
 	}
 }
@@ -1621,11 +1619,9 @@
 	assert(id < numFonts);
 	_curId = id;
 	if (!_fr[id]) {
-		_fr[id] = new NutRenderer(_vm);
 		char fontname[11];
 		sprintf(fontname, "font%d.nut", id);
-		_fr[id] = new NutRenderer(_vm);
-		_fr[id]->loadFont(fontname, true);
+		_fr[id] = new NutRenderer(_vm, fontname, true);
 	}
 	_current = _fr[id];
 	assert(_current);

Modified: scummvm/trunk/engines/scumm/insane/insane.cpp
===================================================================
--- scummvm/trunk/engines/scumm/insane/insane.cpp	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/insane/insane.cpp	2007-01-27 02:26:37 UTC (rev 25223)
@@ -65,16 +65,12 @@
 		readFileToMem("toranch.flu", &_smush_toranchFlu);
 		readFileToMem("minedriv.flu", &_smush_minedrivFlu);
 		readFileToMem("minefite.flu", &_smush_minefiteFlu);
-		_smush_bensgoggNut = new NutRenderer(_vm);
-		_smush_bensgoggNut->loadFont("bensgogg.nut", false);
-		_smush_bencutNut = new NutRenderer(_vm);
-		_smush_bencutNut->loadFont("bencut.nut", false);
+		_smush_bensgoggNut = new NutRenderer(_vm, "bensgogg.nut", false);
+		_smush_bencutNut = new NutRenderer(_vm, "bencut.nut", false);
 	}
 
-	_smush_iconsNut = new NutRenderer(_vm);
-	_smush_iconsNut->loadFont("icons.nut", false);
-	_smush_icons2Nut = new NutRenderer(_vm);
-	_smush_icons2Nut->loadFont("icons2.nut", false);
+	_smush_iconsNut = new NutRenderer(_vm, "icons.nut", false);
+	_smush_icons2Nut = new NutRenderer(_vm, "icons2.nut", false);
 }
 
 Insane::~Insane(void) {

Modified: scummvm/trunk/engines/scumm/nut_renderer.cpp
===================================================================
--- scummvm/trunk/engines/scumm/nut_renderer.cpp	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/nut_renderer.cpp	2007-01-27 02:26:37 UTC (rev 25223)
@@ -27,19 +27,20 @@
 
 namespace Scumm {
 
-NutRenderer::NutRenderer(ScummEngine *vm) :
+NutRenderer::NutRenderer(ScummEngine *vm, const char *filename, bool bitmap) :
 	_vm(vm),
-	_loaded(false),
+	_bitmapFont(bitmap),
 	_numChars(0),
 	_decodedData(0) {
 	memset(_chars, 0, sizeof(_chars));
+	loadFont(filename);
 }
 
 NutRenderer::~NutRenderer() {
 	delete [] _decodedData;
 }
 
-void NutRenderer::codec1(bool bitmap, byte *dst, const byte *src, int width, int height, int pitch) {
+void NutRenderer::codec1(byte *dst, const byte *src, int width, int height, int pitch) {
 	byte val, code;
 	int32 length;
 	int h = height, size_line;
@@ -56,7 +57,7 @@
 			if (code & 1) {
 				val = *src++;
 				size_line--;
-				if (bitmap) {
+				if (_bitmapFont) {
 					for (int i = 0; i < length; i++) {
 						if (val)
 							*dst |= bit;
@@ -75,7 +76,7 @@
 				size_line -= length;
 				while (length--) {
 					val = *src++;
-					if (bitmap) {
+					if (_bitmapFont) {
 						if (val)
 							*dst |= bit;
 						bit >>= 1;
@@ -95,7 +96,7 @@
 	}
 }
 
-void NutRenderer::codec21(bool bitmap, byte *dst, const byte *src, int width, int height, int pitch) {
+void NutRenderer::codec21(byte *dst, const byte *src, int width, int height, int pitch) {
 	while (height--) {
 		byte *dstPtrNext = dst + pitch;
 		const byte *srcPtrNext = src + 2 + READ_LE_UINT16(src);
@@ -105,7 +106,7 @@
 		do {
 			int i;
 			int offs = READ_LE_UINT16(src); src += 2;
-			if (bitmap) {
+			if (_bitmapFont) {
 				for (i = 0; i < offs; i++) {
 					bit >>= 1;
 					if (!bit) {
@@ -129,7 +130,7 @@
 			//  src bytes equal to 255 are replaced by 0 in dst
 			//  src bytes equal to 1 are replaced by a color passed as an argument in the original function
 			//  other src bytes values are copied as-is
-			if (bitmap) {
+			if (_bitmapFont) {
 				for (i = 0; i < w; i++) {
 					if (src[i])
 						*dst |= bit;
@@ -150,24 +151,16 @@
 	}
 }
 
-bool NutRenderer::loadFont(const char *filename, bool bitmap) {
-	if (_loaded) {
-		debug(0, "NutRenderer::loadFont() Font already loaded, ok, loading...");
-	}
-
-	_bitmapFont = bitmap;
-
+void NutRenderer::loadFont(const char *filename) {
 	ScummFile file;
 	_vm->openFile(file, filename);
 	if (!file.isOpen()) {
 		error("NutRenderer::loadFont() Can't open font file: %s", filename);
-		return false;
 	}
 
 	uint32 tag = file.readUint32BE();
 	if (tag != 'ANIM') {
 		error("NutRenderer::loadFont() there is no ANIM chunk in font header");
-		return false;
 	}
 
 	uint32 length = file.readUint32BE();
@@ -177,8 +170,6 @@
 
 	if (READ_BE_UINT32(dataSrc) != 'AHDR') {
 		error("NutRenderer::loadFont() there is no AHDR chunk in font header");
-		free(dataSrc);
-		return false;
 	}
 
 	// We pre-decode the font, which may seem wasteful at first. Actually,
@@ -242,11 +233,11 @@
 		const uint8 *fobjptr = dataSrc + offset + 22;
 		switch (codec) {
 		case 1:
-			codec1(_bitmapFont, _chars[l].src, fobjptr, _chars[l].width, _chars[l].height, pitch);
+			codec1(_chars[l].src, fobjptr, _chars[l].width, _chars[l].height, pitch);
 			break;
 		case 21:
 		case 44:
-			codec21(_bitmapFont, _chars[l].src, fobjptr, _chars[l].width, _chars[l].height, pitch);
+			codec21(_chars[l].src, fobjptr, _chars[l].width, _chars[l].height, pitch);
 			break;
 		default:
 			error("NutRenderer::loadFont: unknown codec: %d", codec);
@@ -254,16 +245,9 @@
 	}
 
 	delete [] dataSrc;
-	_loaded = true;
-	return true;
 }
 
 int NutRenderer::getCharWidth(byte c) const {
-	if (!_loaded) {
-		error("NutRenderer::getCharWidth() Font is not loaded");
-		return 0;
-	}
-
 	if (c >= 0x80 && _vm->_useCJKMode)
 		return _vm->_2byteWidth / 2;
 
@@ -274,11 +258,6 @@
 }
 
 int NutRenderer::getCharHeight(byte c) const {
-	if (!_loaded) {
-		error("NutRenderer::getCharHeight() Font is not loaded");
-		return 0;
-	}
-
 	if (c >= 0x80 && _vm->_useCJKMode)
 		return _vm->_2byteHeight;
 
@@ -289,10 +268,6 @@
 }
 
 void NutRenderer::drawShadowChar(const Graphics::Surface &s, int c, int x, int y, byte color, bool showShadow) {
-	if (!_loaded) {
-		error("NutRenderer::drawShadowChar() Font is not loaded");
-		return;
-	}
 
 	// We draw the character a total of 7 times: 6 times shifted and in black
 	// for the shadow, and once in the right color and position. This way we
@@ -405,11 +380,6 @@
 }
 
 void NutRenderer::draw2byte(const Graphics::Surface &s, int c, int x, int y, byte color) {
-	if (!_loaded) {
-		error("NutRenderer::draw2byte() Font is not loaded");
-		return;
-	}
-
 	byte *dst = (byte *)s.pixels + y * s.pitch + x;
 	const int width = _vm->_2byteWidth;
 	const int height = MIN(_vm->_2byteHeight, s.h - y);

Modified: scummvm/trunk/engines/scumm/nut_renderer.h
===================================================================
--- scummvm/trunk/engines/scumm/nut_renderer.h	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/nut_renderer.h	2007-01-27 02:26:37 UTC (rev 25223)
@@ -32,7 +32,6 @@
 class NutRenderer {
 protected:
 	ScummEngine *_vm;
-	bool _loaded;
 	bool _bitmapFont;
 	int _numChars;
 	byte *_decodedData;
@@ -42,19 +41,19 @@
 		byte *src;
 	} _chars[256];
 
-	static void codec1(bool bitmap, byte *dst, const byte *src, int width, int height, int pitch);
-	static void codec21(bool bitmap, byte *dst, const byte *src, int width, int height, int pitch);
+	void codec1(byte *dst, const byte *src, int width, int height, int pitch);
+	void codec21(byte *dst, const byte *src, int width, int height, int pitch);
 
 	void drawChar(const Graphics::Surface &s, byte c, int x, int y, byte color);
 	void draw2byte(const Graphics::Surface &s, int c, int x, int y, byte color);
 
+	void loadFont(const char *filename);
+
 public:
-	NutRenderer(ScummEngine *vm);
+	NutRenderer(ScummEngine *vm, const char *filename, bool bitmap);
 	virtual ~NutRenderer();
 	int getNumChars() const { return _numChars; }
 
-	bool loadFont(const char *filename, bool bitmap);
-
 	void drawFrame(byte *dst, int c, int x, int y);
 	void drawShadowChar(const Graphics::Surface &s, int c, int x, int y, byte color, bool showShadow);
 

Modified: scummvm/trunk/engines/scumm/smush/smush_font.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_font.cpp	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/smush/smush_font.cpp	2007-01-27 02:26:37 UTC (rev 25223)
@@ -29,8 +29,8 @@
 
 namespace Scumm {
 
-SmushFont::SmushFont(ScummEngine *vm, bool use_original_colors, bool new_colors) :
-	NutRenderer(vm),
+SmushFont::SmushFont(ScummEngine *vm, const char *filename, bool use_original_colors, bool new_colors) :
+	NutRenderer(vm, filename, false),
 	_color(-1),
 	_new_colors(new_colors),
 	_original(use_original_colors) {
@@ -38,10 +38,6 @@
 
 int SmushFont::getStringWidth(const char *str) {
 	assert(str);
-	if (!_loaded) {
-		error("SmushFont::getStringWidth() Font is not loaded");
-		return 0;
-	}
 
 	int width = 0;
 	while (*str) {
@@ -56,10 +52,6 @@
 
 int SmushFont::getStringHeight(const char *str) {
 	assert(str);
-	if (!_loaded) {
-		error("SmushFont::getStringHeight() Font is not loaded");
-		return 0;
-	}
 
 	int height = 0;
 	while (*str) {

Modified: scummvm/trunk/engines/scumm/smush/smush_font.h
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_font.h	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/smush/smush_font.h	2007-01-27 02:26:37 UTC (rev 25223)
@@ -42,7 +42,7 @@
 	void drawSubstring(const char *str, byte *buffer, int dst_width, int x, int y);
 
 public:
-	SmushFont(ScummEngine *vm, bool use_original_colors, bool new_colors);
+	SmushFont(ScummEngine *vm, const char *filename, bool use_original_colors, bool new_colors);
 
 	void setColor(byte c) { _color = c; }
 	void drawString    (const char *str, byte *buffer, int dst_width, int dst_height, int x, int y, bool center);

Modified: scummvm/trunk/engines/scumm/smush/smush_player.cpp
===================================================================
--- scummvm/trunk/engines/scumm/smush/smush_player.cpp	2007-01-27 01:59:37 UTC (rev 25222)
+++ scummvm/trunk/engines/scumm/smush/smush_player.cpp	2007-01-27 02:26:37 UTC (rev 25223)
@@ -1051,24 +1051,21 @@
 
 			assert(font >= 0 && font < ARRAYSIZE(ft_fonts));
 
-			_sf[font] = new SmushFont(_vm, true, false);
-			_sf[font]->loadFont(ft_fonts[font], false);
+			_sf[font] = new SmushFont(_vm, ft_fonts[font], true, false);
 		}
 	} else if (_vm->_game.id == GID_DIG) {
 		if (!(_vm->_game.features & GF_DEMO)) {
 			assert(font >= 0 && font < 4);
 
 			sprintf(file_font, "font%d.nut", font);
-			_sf[font] = new SmushFont(_vm, font != 0, false);
-			_sf[font]->loadFont(file_font, false);
+			_sf[font] = new SmushFont(_vm, file_font, font != 0, false);
 		}
 	} else if (_vm->_game.id == GID_CMI) {
 		int numFonts = (_vm->_game.features & GF_DEMO) ? 4 : 5;
 		assert(font >= 0 && font < numFonts);
 
 		sprintf(file_font, "font%d.nut", font);
-		_sf[font] = new SmushFont(_vm, false, true);
-		_sf[font]->loadFont(file_font, false);
+		_sf[font] = new SmushFont(_vm, file_font, false, true);
 	} else {
 		error("SmushPlayer::getFont() Unknown font setup for game");
 	}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list