aboutsummaryrefslogtreecommitdiff
path: root/engines/draci
diff options
context:
space:
mode:
authorDenis Kasak2009-06-17 04:48:48 +0000
committerDenis Kasak2009-06-17 04:48:48 +0000
commit997b37eff15485c095181b2b1c3ade24722bdb8f (patch)
treec15d54a5449415af3eeaf1fbcb475ba70ffa43c6 /engines/draci
parent7420c1bfb620b62ae59c1ca91df6267281a9455a (diff)
downloadscummvm-rg350-997b37eff15485c095181b2b1c3ade24722bdb8f.tar.gz
scummvm-rg350-997b37eff15485c095181b2b1c3ade24722bdb8f.tar.bz2
scummvm-rg350-997b37eff15485c095181b2b1c3ade24722bdb8f.zip
Began work on the Screen class. Modified the demo animation to use the it.
svn-id: r41604
Diffstat (limited to 'engines/draci')
-rw-r--r--engines/draci/draci.cpp53
-rw-r--r--engines/draci/draci.h5
-rw-r--r--engines/draci/module.mk3
-rw-r--r--engines/draci/screen.cpp124
-rw-r--r--engines/draci/screen.h60
5 files changed, 209 insertions, 36 deletions
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index 99b9cd1ab2..2ffec72927 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -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 @@ DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
// 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,7 +66,9 @@ DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
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 @@ int DraciEngine::init() {
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 @@ int DraciEngine::go() {
return 0;
}
- Common::MemoryReadStream paletteReader(f->_data, f->_length);
-
- 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);
+ _screen->setPalette(f->_data, 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 @@ int DraciEngine::go() {
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 @@ int DraciEngine::go() {
// 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 @@ int DraciEngine::go() {
}
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 @@ int DraciEngine::go() {
break;
}
}
- _system->updateScreen();
+ _screen->copyToScreen();
_system->delayMillis(20);
}
@@ -232,6 +213,8 @@ int DraciEngine::go() {
DraciEngine::~DraciEngine() {
// Dispose your resources here
+ delete _screen;
+
// Remove all of our debug levels here
Common::clearAllDebugChannels();
}
diff --git a/engines/draci/draci.h b/engines/draci/draci.h
index 8a0e073101..481de8e4b3 100644
--- a/engines/draci/draci.h
+++ b/engines/draci/draci.h
@@ -30,6 +30,7 @@
#include "engines/engine.h"
#include "engines/advancedDetector.h"
+#include "draci/screen.h"
#include "draci/font.h"
namespace Draci {
@@ -46,6 +47,10 @@ public:
bool hasFeature(Engine::EngineFeature f) const;
Font _font;
+ Screen *_screen;
+
+ int _screenWidth;
+ int _screenHeight;
private:
Common::RandomSource _rnd;
diff --git a/engines/draci/module.mk b/engines/draci/module.mk
index b41154b576..ac214d0ccd 100644
--- a/engines/draci/module.mk
+++ b/engines/draci/module.mk
@@ -6,7 +6,8 @@ MODULE_OBJS := \
barchive.o \
gpldisasm.o \
font.o \
- sprite.o
+ sprite.o \
+ screen.o
MODULE_DIRS += \
engines/draci
diff --git a/engines/draci/screen.cpp b/engines/draci/screen.cpp
new file mode 100644
index 0000000000..b1c12ccbae
--- /dev/null
+++ b/engines/draci/screen.cpp
@@ -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
+
+
diff --git a/engines/draci/screen.h b/engines/draci/screen.h
new file mode 100644
index 0000000000..0180cc7f6f
--- /dev/null
+++ b/engines/draci/screen.h
@@ -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