[Scummvm-cvs-logs] SF.net SVN: scummvm:[41604] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Wed Jun 17 06:48:54 CEST 2009


Revision: 41604
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41604&view=rev
Author:   dkasak13
Date:     2009-06-17 04:48:48 +0000 (Wed, 17 Jun 2009)

Log Message:
-----------
Began work on the Screen class. Modified the demo animation to use the it.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/draci.h
    scummvm/branches/gsoc2009-draci/engines/draci/module.mk

Added Paths:
-----------
    scummvm/branches/gsoc2009-draci/engines/draci/screen.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/screen.h

Modified: scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp	2009-06-17 04:16:51 UTC (rev 41603)
+++ scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp	2009-06-17 04:48:48 UTC (rev 41604)
@@ -37,6 +37,7 @@
 #include "draci/gpldisasm.h"
 #include "draci/font.h"
 #include "draci/sprite.h"
+#include "draci/screen.h"
 
 namespace Draci {
 
@@ -50,6 +51,9 @@
  
 	// However this is the place to specify all default directories
 	//Common::File::addDefaultDirectory(_gameDataPath + "sound/");
+
+	_screenHeight = 200;
+	_screenWidth = 320;
  	
 	// Here is the right place to set up the engine specific debug levels
 	Common::addDebugChannel(kDraciGeneralDebugLevel, "general", "Draci general debug level");
@@ -62,8 +66,10 @@
 
 int DraciEngine::init() {
 	// Initialize graphics using following:
-	initGraphics(320, 200, false);
+	initGraphics(_screenWidth, _screenHeight, false);
 
+	_screen = new Screen(this);	
+
 	// Load default font
 	_font.setFont(kFontBig);
 
@@ -106,20 +112,9 @@
 	return 0;
 }
 
-// HACK
-// Temporary hack
-
-void drawFrame(OSystem *syst, BAFile *frame) {
-	Sprite sp(frame->_data, frame->_length, ((320 - 50) / 2), 60, true);	
-	syst->copyRectToScreen(sp._data, sp._width, sp._x, sp._y, sp._width, sp._height); 
-}
-
 int DraciEngine::go() {
 	debugC(1, kDraciGeneralDebugLevel, "DraciEngine::go()");
  
-	// Read in a sample palette
-	byte *palette = new byte[4 * 256];
-
 	debugC(2, kDraciGeneralDebugLevel, "Running graphics/animation test...");
 
 	Common::String path("PALETY.DFW");	
@@ -135,28 +130,14 @@
 		return 0;
 	}	
 
-	Common::MemoryReadStream paletteReader(f->_data, f->_length);
+	_screen->setPalette(f->_data, 0, 256);
 	
-	for (unsigned int i = 0; i < 256; ++i) {
-		palette[i * 4] = paletteReader.readByte();
-		palette[i * 4 + 1] = paletteReader.readByte();
-		palette[i * 4 + 2] = paletteReader.readByte();
-		palette[i * 4 + 3] = 0;
-	}
-
-	// Shift the palette one bit to the left to make it brighter
-	for (unsigned int i = 0; i < 4 * 256; ++i) {
-		palette[i] <<= 2;
-	} 
-
-	_system->setPalette(palette, 0, 256);
-	
 	// Fill screen with white
-	_system->fillScreen(255);
+	_screen->fillScreen(255);
 
 	// Draw big string
 	Common::String testString = "Testing, testing, read all about it!";
-	Graphics::Surface *surf = _system->lockScreen();
+	Graphics::Surface *surf = _screen->getSurface();
 	_font.drawString(surf, testString, 
 		(320 - _font.getStringWidth(testString, 1)) / 2, 130, 1);
 
@@ -170,8 +151,7 @@
 	testString = "Checking overflooooooooooooooooooooooooow...";
 	_font.drawString(surf, testString, 50, 170, 1);
 
-	_system->unlockScreen();
-	_system->updateScreen();
+	_screen->copyToScreen();
 
 	// Draw and animate the dragon
 	path = "OBR_AN.DFW";
@@ -187,8 +167,9 @@
 
 		// Load frame to memory
 		f = ar[t];
-		drawFrame(_system, f);
-		_system->updateScreen();
+		Sprite sp(f->_data, f->_length, ((320 - 50) / 2), 60, true);
+		_screen->drawSprite(sp);
+		_screen->copyToScreen();
 		_system->delayMillis(100);
 
 		debugC(5, kDraciGeneralDebugLevel, "Finished frame %d", t);	
@@ -205,7 +186,7 @@
 	}	
 
 	Sprite sp(f->_data, f->_length, 0, 0, true);
-	CursorMan.pushCursorPalette(palette, 0, 256);
+	CursorMan.pushCursorPalette(_screen->getPalette(), 0, 256);
 	CursorMan.pushCursor(sp._data, sp._width, sp._height, sp._width / 2, sp._height / 2);
 	CursorMan.showMouse(true);
 
@@ -222,7 +203,7 @@
 				break;
 			}
 		}
-		_system->updateScreen();
+		_screen->copyToScreen();
 		_system->delayMillis(20);
 	}
 
@@ -232,6 +213,8 @@
 DraciEngine::~DraciEngine() {
 	// Dispose your resources here
  
+	delete _screen;
+
 	// Remove all of our debug levels here
 	Common::clearAllDebugChannels();
 }

Modified: scummvm/branches/gsoc2009-draci/engines/draci/draci.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/draci.h	2009-06-17 04:16:51 UTC (rev 41603)
+++ scummvm/branches/gsoc2009-draci/engines/draci/draci.h	2009-06-17 04:48:48 UTC (rev 41604)
@@ -30,6 +30,7 @@
 #include "engines/engine.h"
 #include "engines/advancedDetector.h"
 
+#include "draci/screen.h"
 #include "draci/font.h"
 
 namespace Draci {
@@ -46,7 +47,11 @@
 	bool hasFeature(Engine::EngineFeature f) const;
 
 	Font _font;
+	Screen *_screen;
 
+	int _screenWidth;
+	int _screenHeight;
+
 private:
 	Common::RandomSource _rnd;
 };

Modified: scummvm/branches/gsoc2009-draci/engines/draci/module.mk
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/module.mk	2009-06-17 04:16:51 UTC (rev 41603)
+++ scummvm/branches/gsoc2009-draci/engines/draci/module.mk	2009-06-17 04:48:48 UTC (rev 41604)
@@ -6,7 +6,8 @@
 	barchive.o \
 	gpldisasm.o \
 	font.o \
-	sprite.o
+	sprite.o \
+	screen.o
  
 MODULE_DIRS += \
 	engines/draci

Added: scummvm/branches/gsoc2009-draci/engines/draci/screen.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/screen.cpp	                        (rev 0)
+++ scummvm/branches/gsoc2009-draci/engines/draci/screen.cpp	2009-06-17 04:48:48 UTC (rev 41604)
@@ -0,0 +1,124 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/stream.h"
+
+#include "draci/draci.h"
+#include "draci/screen.h"
+
+namespace Draci {
+
+Screen::Screen(DraciEngine *vm) : _vm(vm) {
+	_surface = new Graphics::Surface();
+	_surface->create(_vm->_screenWidth, _vm->_screenHeight, 1);
+	this->clearScreen();
+	_palette = new byte[4 * 256];
+	setPaletteEmpty(256);
+}
+
+Screen::~Screen() {
+	_surface->free();
+	delete[] _surface;
+	delete[] _palette;
+}
+
+void Screen::setPaletteEmpty(unsigned int numEntries) {
+	for (unsigned int i = 0; i < numEntries * 4; ++i) {
+		_palette[i] = 0;
+	}
+
+	_vm->_system->setPalette(_palette, 0, numEntries);
+	_vm->_system->updateScreen();
+}	
+
+void Screen::setPalette(byte *data, uint16 start, uint16 num) {
+
+	Common::MemoryReadStream pal(data, 256 * 3);
+	pal.seek(start * 4);
+
+	// Copy the palette	
+	for (unsigned int i = start; i < start + num; ++i) {
+		_palette[i * 4] = pal.readByte();
+		_palette[i * 4 + 1] = pal.readByte();
+		_palette[i * 4 + 2] = pal.readByte();
+		_palette[i * 4 + 3] = 0;
+	}
+
+	// TODO: Investigate why this is needed
+	// Shift the palette one bit to the left to make it brighter
+	for (unsigned int i = 0; i < 4 * 256; ++i) {
+		_palette[i] <<= 2;
+	}
+
+	_vm->_system->setPalette(_palette, start, num);
+	_vm->_system->updateScreen(); 
+}
+
+void Screen::copyToScreen() const {
+	byte *ptr = (byte *)_surface->getBasePtr(0, 0);
+
+	_vm->_system->copyRectToScreen(ptr, _vm->_screenWidth, 0, 0, 
+		_vm->_screenWidth, _vm->_screenHeight);
+
+	_vm->_system->updateScreen();
+}
+
+
+void Screen::clearScreen() const {
+	byte *ptr = (byte *)_surface->getBasePtr(0, 0);
+
+	memset(ptr, 0, _vm->_screenWidth * _vm->_screenHeight);
+}
+
+void Screen::drawSprite(const Sprite &s) const { 
+	byte *dst = (byte *)_surface->getBasePtr(s._x, s._y);
+	byte *src = s._data;	
+
+	for (unsigned int i = 0; i < s._height; ++i) {
+		for(unsigned int j = 0; j < s._width; ++j) {
+			dst[j] = *src++;
+		}
+		
+		dst += _surface->pitch;
+	}
+}
+
+void Screen::fillScreen(uint16 colour) const {
+	byte *ptr = (byte *)_surface->getBasePtr(0, 0);
+	
+	memset(ptr, colour, _vm->_screenWidth * _vm->_screenHeight);
+}
+
+byte *Screen::getPalette() const {
+	return _palette;
+}
+
+Graphics::Surface *Screen::getSurface() {
+	return _surface;
+}
+
+} // End of namespace Draci
+
+


Property changes on: scummvm/branches/gsoc2009-draci/engines/draci/screen.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: scummvm/branches/gsoc2009-draci/engines/draci/screen.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/screen.h	                        (rev 0)
+++ scummvm/branches/gsoc2009-draci/engines/draci/screen.h	2009-06-17 04:48:48 UTC (rev 41604)
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef SCREEN_H
+#define SCREEN_H
+
+#include "graphics/surface.h"
+
+#include "draci/sprite.h"
+
+namespace Draci {
+
+class DraciEngine;
+
+class Screen {
+	
+public:
+	Screen(DraciEngine *vm);
+	~Screen();
+
+	void setPaletteEmpty(unsigned int numEntries);
+	void setPalette(byte *data, uint16 start, uint16 num);
+	byte *getPalette() const;
+	void copyToScreen() const;
+	void clearScreen() const;
+	void drawSprite(const Sprite &s) const;
+	void fillScreen(uint16 colour) const;
+	Graphics::Surface *getSurface();	
+	
+private:
+	Graphics::Surface *_surface;
+	byte *_palette;
+	DraciEngine *_vm;
+};
+
+} // End of namespace Draci
+
+#endif // SCREEN_H


Property changes on: scummvm/branches/gsoc2009-draci/engines/draci/screen.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


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