aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232011-07-05 18:19:46 +0000
committerWillem Jan Palenstijn2013-05-08 20:30:58 +0200
commit056b69f0c8b2c69f3040fa54268b22c6463627b0 (patch)
treef1087de601bb89280b4322d4b2272d1a2aefc6ed /engines
parent6b71d177925ff21787fb792dc05ac048eadbbca3 (diff)
downloadscummvm-rg350-056b69f0c8b2c69f3040fa54268b22c6463627b0.tar.gz
scummvm-rg350-056b69f0c8b2c69f3040fa54268b22c6463627b0.tar.bz2
scummvm-rg350-056b69f0c8b2c69f3040fa54268b22c6463627b0.zip
NEVERHOOD: Module1000 and Scene1001 skeletons
- Implement BaseSurface::drawSpriteResourceEx - Use CollisionMan in Scene - Some cleanup
Diffstat (limited to 'engines')
-rw-r--r--engines/neverhood/collisionman.cpp29
-rw-r--r--engines/neverhood/collisionman.h1
-rw-r--r--engines/neverhood/graphics.cpp14
-rw-r--r--engines/neverhood/graphics.h4
-rw-r--r--engines/neverhood/module.h1
-rw-r--r--engines/neverhood/module1000.cpp90
-rw-r--r--engines/neverhood/resource.cpp10
-rw-r--r--engines/neverhood/resource.h2
-rw-r--r--engines/neverhood/scene.cpp7
-rw-r--r--engines/neverhood/sprite.cpp43
-rw-r--r--engines/neverhood/sprite.h2
11 files changed, 169 insertions, 34 deletions
diff --git a/engines/neverhood/collisionman.cpp b/engines/neverhood/collisionman.cpp
index cc40a47f1e..31bc16d23c 100644
--- a/engines/neverhood/collisionman.cpp
+++ b/engines/neverhood/collisionman.cpp
@@ -24,6 +24,8 @@
namespace Neverhood {
+static HitRect defaultHitRect = {NRect(), 0x5000};
+
CollisionMan::CollisionMan(NeverhoodEngine *vm)
: _vm(vm), _hitRects(NULL) {
}
@@ -39,13 +41,34 @@ void CollisionMan::setHitRects(HitRectList *hitRects) {
_hitRects = hitRects;
}
+void CollisionMan::clearHitRects() {
+ _hitRects = 0;
+}
+
HitRect *CollisionMan::findHitRectAtPos(int16 x, int16 y) {
- // TODO
- return NULL;
+ if (_hitRects) {
+ for (HitRectList::iterator it = _hitRects->begin(); it != _hitRects->end(); it++) {
+ HitRect *hitRect = &(*it);
+ if (x >= hitRect->rect.x1 && x <= hitRect->rect.x2 && y >= hitRect->rect.y1 && y <= hitRect->rect.y2)
+ return hitRect;
+ }
+ }
+ return &defaultHitRect;
}
void CollisionMan::addSprite(Sprite *sprite) {
- _sprites.push_back(sprite);
+ int index = 0, insertIndex = -1;
+ for (Common::Array<Sprite*>::iterator iter = _sprites.begin(); iter != _sprites.end(); iter++) {
+ if ((*iter)->getPriority() > sprite->getPriority()) {
+ insertIndex = index;
+ break;
+ }
+ index++;
+ }
+ if (insertIndex >= 0)
+ _sprites.insert_at(insertIndex, sprite);
+ else
+ _sprites.push_back(sprite);
}
void CollisionMan::removeSprite(Sprite *sprite) {
diff --git a/engines/neverhood/collisionman.h b/engines/neverhood/collisionman.h
index cfa248ab4b..426dca0c95 100644
--- a/engines/neverhood/collisionman.h
+++ b/engines/neverhood/collisionman.h
@@ -35,6 +35,7 @@ public:
~CollisionMan();
void setHitRects(uint32 id);
void setHitRects(HitRectList *hitRects);
+ void clearHitRects();
HitRect *findHitRectAtPos(int16 x, int16 y);
void addSprite(Sprite *sprite);
void removeSprite(Sprite *sprite);
diff --git a/engines/neverhood/graphics.cpp b/engines/neverhood/graphics.cpp
index fa7c15211a..3d21e8e7de 100644
--- a/engines/neverhood/graphics.cpp
+++ b/engines/neverhood/graphics.cpp
@@ -74,6 +74,20 @@ void BaseSurface::drawSpriteResource(SpriteResource &spriteResource) {
}
}
+void BaseSurface::drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height) {
+ if (spriteResource.getDimensions().width <= _sysRect.width &&
+ spriteResource.getDimensions().height <= _sysRect.height) {
+ if (width > 0 && width <= _sysRect.width)
+ _drawRect.width = width;
+ if (height > 0 && height <= _sysRect.height)
+ _drawRect.height = height;
+ if (_surface) {
+ clear();
+ spriteResource.draw((byte*)_surface->pixels, _surface->pitch, flipX, flipY);
+ }
+ }
+}
+
// Misc
void parseBitmapResource(byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, byte **palette, byte **pixels) {
diff --git a/engines/neverhood/graphics.h b/engines/neverhood/graphics.h
index cb7474c78d..ce2be1a592 100644
--- a/engines/neverhood/graphics.h
+++ b/engines/neverhood/graphics.h
@@ -41,11 +41,13 @@ struct NDimensions {
struct NRect {
int16 x1, y1, x2, y2;
NRect() : x1(0), y1(0), x2(0), y2(0) {}
+ NRect(int16 x01, int16 y01, int16 x02, int16 y02) : x1(x01), y1(y01), x2(x02), y2(y02) {}
};
struct NDrawRect {
int16 x, y, width, height;
NDrawRect() : x(0), y(0), width(0), height(0) {}
+ NDrawRect(int16 x0, int16 y0, int16 width0, int16 height0) : x(x0), y(y0), width(width0), height(height0) {}
};
class SpriteResource;
@@ -60,11 +62,13 @@ public:
virtual void addDirtyRect();
void clear();
void drawSpriteResource(SpriteResource &spriteResource);
+ void drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height);
int getPriority() const { return _priority; }
void setPriority(int priority) { _priority = priority; }
NDrawRect& getDrawRect() { return _drawRect; }
NDrawRect& getSysRect() { return _sysRect; }
NRect& getClipRect() { return _clipRect; }
+ void setClipRect(NRect clipRect) { _clipRect = clipRect; }
protected:
NeverhoodEngine *_vm;
int _priority;
diff --git a/engines/neverhood/module.h b/engines/neverhood/module.h
index d3c7b69169..7911e44072 100644
--- a/engines/neverhood/module.h
+++ b/engines/neverhood/module.h
@@ -27,6 +27,7 @@
#include "neverhood/neverhood.h"
#include "neverhood/background.h"
+#include "neverhood/collisionman.h"
#include "neverhood/entity.h"
#include "neverhood/graphics.h"
#include "neverhood/palette.h"
diff --git a/engines/neverhood/module1000.cpp b/engines/neverhood/module1000.cpp
index d1403b9307..248769ecf5 100644
--- a/engines/neverhood/module1000.cpp
+++ b/engines/neverhood/module1000.cpp
@@ -103,7 +103,95 @@ void Module1000::updateScene1005() {
// Scene1001
Scene1001::Scene1001(NeverhoodEngine *vm, Module *parentModule, int which)
- : Scene(vm, parentModule, true) {
+ : Scene(vm, parentModule, true), _fieldE4(-1), _fieldE6(-1) {
+
+ // TODO: Implement Sprite classes
+
+ Sprite *staticSprite1;
+
+ SetMessageHandler(&Scene1001::handleMessage);
+
+ _vm->_collisionMan->setHitRects(0x004B4858);
+ _surfaceFlag = false;
+ _background = addBackground(new DirtyBackground(_vm, 0x4086520E, 0, 0));
+ _palette = new Palette(_vm, 0x4086520E);
+ _palette->usePalette();
+
+ // TODO Mouse
+
+#if 0
+ // TODO: Player sprites...
+ if (which < 0) {
+ setRectList(0x004B49F0);
+ _playerSprite = new Class572(_vm, this, 200, 433, 1000, 1000);
+ setMessageList(0x004B4888);
+ } else if (which == 1) {
+ setRectList(0x004B49F0);
+ _playerSprite = new Class572(_vm, this, 640, 433, 1000, 1000);
+ setMessageList(0x004B4898);
+ } else if (which == 2) {
+ setRectList(0x004B49F0);
+ if (_vm->getGlobalVar(0xC0418A02)) {
+ _playerSprite = new Class572(_vm, this, 390, 433, 1000, 1000);
+ _playerSprite->setDoDeltaX(1);
+ } else {
+ _playerSprite = new Class572(_vm, this, 300, 433, 1000, 1000);
+ }
+ setMessageList(0x004B4970);
+ } else {
+ setRectList(0x004B4A00);
+ _playerSprite = new Class572(_vm, this, 200, 433, 1000, 1000);
+ setMessageList(0x004B4890);
+ }
+ addSprite(_playerSprite);
+#endif
+
+ staticSprite1 = addSprite(new StaticSprite(_vm, 0x2080A3A8, 1300));
+
+#if 0
+ // TODO: This sucks somehow, find a better way
+ _playerSprite->getSurface()->getClipRect().x1 = 0;
+ _playerSprite->getSurface()->getClipRect().y1 = 0;
+ _playerSprite->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width;
+ _playerSprite->getSurface()->getClipRect().y2 = 480;
+
+ if (_vm->getGlobalVar(0xD217189D) == 0) {
+ _class509 = addSprite(new Class509(_vm));
+ _class509->getSurface()->getClipRect().x1 = 0;
+ _class509->getSurface()->getClipRect().y1 = 0;
+ _class509->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width;
+ _class509->getSurface()->getClipRect().y2 = 480;
+ } else {
+ _class509 = NULL;
+ }
+
+ _class511 = addSprite(new Class511(_vm, this, 150, 433, 1));
+#endif
+
+ addSprite(new StaticSprite(_vm, 0x809861A6, 950));
+ addSprite(new StaticSprite(_vm, 0x89C03848, 1100));
+
+#if 0
+ _class608 = addSprite(new Class608(_vm, 0x15288120, 100, 0));
+#endif
+
+ if (_vm->getGlobalVar(0x03C698DA) == 0) {
+ staticSprite1 = addSprite(new StaticSprite(_vm, 0x8C066150, 200));
+#if 0
+ _class510 = addSprite(new Class510(_vm));
+ _class510->getSurface()->getClipRect().x1 = staticSprite1->getSurface()->getDrawRect().x;
+ _class510->getSurface()->getClipRect().y1 = staticSprite1->getSurface()->getDrawRect().y;
+ _class510->getSurface()->getClipRect().x2 = staticSprite1->getSurface()->getDrawRect().x + staticSprite1->getSurface()->getDrawRect().width;
+ _class510->getSurface()->getClipRect().y2 = staticSprite1->getSurface()->getDrawRect().y + staticSprite1->getSurface()->getDrawRect().height;
+#endif
+ } else {
+ _class510= NULL;
+ }
+
+#if 0
+ _class508 = addSprite(new Class508(_vm, _class509));
+#endif
+
}
void Scene1001::update() {
diff --git a/engines/neverhood/resource.cpp b/engines/neverhood/resource.cpp
index 300cf8195a..c122ca2e5e 100644
--- a/engines/neverhood/resource.cpp
+++ b/engines/neverhood/resource.cpp
@@ -220,10 +220,10 @@ bool AnimResource::load(uint32 fileHash) {
AnimFrameInfo frameInfo;
frameInfo.frameHash = READ_LE_UINT32(frameList);
frameInfo.counter = READ_LE_UINT16(frameList + 4);
- frameInfo.rect.x1 = READ_LE_UINT16(frameList + 6);
- frameInfo.rect.y1 = READ_LE_UINT16(frameList + 8);
- frameInfo.rect.x2 = READ_LE_UINT16(frameList + 10);
- frameInfo.rect.y2 = READ_LE_UINT16(frameList + 12);
+ frameInfo.rect.x = READ_LE_UINT16(frameList + 6);
+ frameInfo.rect.y = READ_LE_UINT16(frameList + 8);
+ frameInfo.rect.width = READ_LE_UINT16(frameList + 10);
+ frameInfo.rect.height = READ_LE_UINT16(frameList + 12);
frameInfo.deltaX = READ_LE_UINT16(frameList + 14);
frameInfo.deltaY = READ_LE_UINT16(frameList + 16);
frameInfo.deltaRect.x = READ_LE_UINT16(frameList + 18);
@@ -234,7 +234,7 @@ bool AnimResource::load(uint32 fileHash) {
frameInfo.spriteDataOffs = READ_LE_UINT32(frameList + 28);
debug("frameHash = %08X; counter = %d; rect = (%d,%d,%d,%d); deltaX = %d; deltaY = %d; deltaRect = (%d,%d,%d,%d); field_1A = %04X; spriteDataOffs = %08X",
frameInfo.frameHash, frameInfo.counter,
- frameInfo.rect.x1, frameInfo.rect.y1, frameInfo.rect.x2, frameInfo.rect.y2,
+ frameInfo.rect.x, frameInfo.rect.y, frameInfo.rect.width, frameInfo.rect.height,
frameInfo.deltaX, frameInfo.deltaY,
frameInfo.deltaRect.x, frameInfo.deltaRect.y, frameInfo.deltaRect.width, frameInfo.deltaRect.height,
frameInfo.field_1A, frameInfo.spriteDataOffs);
diff --git a/engines/neverhood/resource.h b/engines/neverhood/resource.h
index 868bafdc44..4199fe73e4 100644
--- a/engines/neverhood/resource.h
+++ b/engines/neverhood/resource.h
@@ -64,7 +64,7 @@ protected:
struct AnimFrameInfo {
uint32 frameHash;
int16 counter;
- NRect rect;
+ NDrawRect rect;
int16 deltaX, deltaY;
NDrawRect deltaRect;
uint16 field_1A;
diff --git a/engines/neverhood/scene.cpp b/engines/neverhood/scene.cpp
index a73b45b9f7..b06caeec14 100644
--- a/engines/neverhood/scene.cpp
+++ b/engines/neverhood/scene.cpp
@@ -21,6 +21,7 @@
*/
#include "neverhood/scene.h"
+#include "neverhood/collisionman.h"
namespace Neverhood {
@@ -42,8 +43,8 @@ Scene::Scene(NeverhoodEngine *vm, Module *parentModule, bool clearHitRects)
_background = NULL;
// TODO _field_8E = -1;
if (clearHitRects) {
- // TODO g_Class700->setHitRects(NULL, 0);
- // TODO g_Class700->clear();
+ _vm->_collisionMan->clearHitRects();
+ _vm->_collisionMan->clearSprites();
}
_vm->_screen->setFps(24);
// TODO g_screen->hSmack = NULL;
@@ -161,7 +162,7 @@ void Scene::setSurfacePriority(BaseSurface *surface, int priority) {
}
void Scene::deleteSprite(Sprite **sprite) {
- // TODO g_Class700->removeSprite(*sprite);
+ _vm->_collisionMan->removeSprite(*sprite);
removeSurface((*sprite)->getSurface());
removeEntity(*sprite);
delete *sprite;
diff --git a/engines/neverhood/sprite.cpp b/engines/neverhood/sprite.cpp
index 0157673250..0f44110cdd 100644
--- a/engines/neverhood/sprite.cpp
+++ b/engines/neverhood/sprite.cpp
@@ -119,11 +119,13 @@ void StaticSprite::init(uint32 fileHash, int surfacePriority, int16 x, int16 y,
_x = x == kDefPosition ? _spriteResource.getPosition().x : x;
_y = y == kDefPosition ? _spriteResource.getPosition().y : y;
+
+ debug("StaticSprite::init() final: x = %d; y = %d", _x, _y);
- _rect1.x1 = 0;
- _rect1.y1 = 0;
- _rect1.x2 = width;
- _rect1.y2 = height;
+ _drawRect.x = 0;
+ _drawRect.y = 0;
+ _drawRect.width = width;
+ _drawRect.width = height;
_needRedraw = true;
@@ -137,19 +139,19 @@ void StaticSprite::update() {
return;
if (_doDeltaX) {
- _x = filterX(_x - _rect1.x1 - _rect1.x2 + 1);
+ _surface->getDrawRect().x = filterX(_x - _drawRect.x - _drawRect.width + 1);
} else {
- _x = filterX(_x + _rect1.x1);
+ _surface->getDrawRect().x = filterX(_x + _drawRect.x);
}
if (_doDeltaY) {
- _y = filterY(_y - _rect1.y1 - _rect1.y2 + 1);
+ _surface->getDrawRect().y = filterY(_y - _drawRect.y - _drawRect.height + 1);
} else {
- _y = filterY(_y + _rect1.y1);
+ _surface->getDrawRect().y = filterY(_y + _drawRect.y);
}
if (_needRedraw) {
- // TODO _surface->drawSpriteResourceEx(_spriteResource, _doDeltaX, _doDeltaY, _rect1.x2, _rect1.y2);
+ _surface->drawSpriteResourceEx(_spriteResource, _doDeltaX, _doDeltaY, _drawRect.width, _drawRect.height);
_needRedraw = false;
}
@@ -160,10 +162,10 @@ void StaticSprite::load(uint32 fileHash, bool dimensions, bool position) {
_spriteResource.load2(fileHash);
if (dimensions) {
- _rect1.x1 = 0;
- _rect1.y1 = 0;
- _rect1.x2 = _spriteResource.getDimensions().width;
- _rect1.y2 = _spriteResource.getDimensions().height;
+ _drawRect.x = 0;
+ _drawRect.y = 0;
+ _drawRect.width = _spriteResource.getDimensions().width;
+ _drawRect.height = _spriteResource.getDimensions().height;
}
if (position) {
@@ -276,7 +278,7 @@ void AnimatedSprite::updateAnim() {
_frameIndex2 = _frameIndex4 != -1 ? _frameIndex4 : _animResource.getFrameCount() - 1;
}
} else {
- // TODO updateFrameIndex();
+ updateFrameIndex();
}
if (_fileHash1 == 0)
updateFrameInfo();
@@ -336,19 +338,20 @@ void AnimatedSprite::updatePosition() {
return;
if (_doDeltaX) {
- _surface->getDrawRect().x = filterX(_x - _rect1.x1 - _rect1.x2 + 1);
+ _surface->getDrawRect().x = filterX(_x - _drawRect.x - _drawRect.width + 1);
} else {
- _surface->getDrawRect().x = filterX(_x + _rect1.x1);
+ _surface->getDrawRect().x = filterX(_x + _drawRect.x);
}
if (_doDeltaY) {
- _surface->getDrawRect().y = filterY(_y - _rect1.y1 - _rect1.y2 + 1);
+ _surface->getDrawRect().y = filterY(_y - _drawRect.y - _drawRect.height + 1);
} else {
- _surface->getDrawRect().y = filterY(_y + _rect1.y1);
+ _surface->getDrawRect().y = filterY(_y + _drawRect.y);
}
if (_needRedraw) {
- // TODO _surface->drawAnimResource(_animResource, _frameIndex, _doDeltaX, _doDeltaY, _rect1.x2, _rect1.y2);
+ debug("TODO: drawAnimResource");
+ // TODO _surface->drawAnimResource(_animResource, _frameIndex, _doDeltaX, _doDeltaY, _drawRect.width, _drawRect.height);
_needRedraw = false;
}
@@ -381,7 +384,7 @@ void AnimatedSprite::updateFrameInfo() {
const AnimFrameInfo &frameInfo = _animResource.getFrameInfo(_frameIndex);
_flag = true;
- _rect1 = frameInfo.rect;
+ _drawRect = frameInfo.rect;
_deltaX = frameInfo.deltaX;
_deltaY = frameInfo.deltaY;
_deltaRect = frameInfo.deltaRect;
diff --git a/engines/neverhood/sprite.h b/engines/neverhood/sprite.h
index 708228ca2f..5d013a85e4 100644
--- a/engines/neverhood/sprite.h
+++ b/engines/neverhood/sprite.h
@@ -55,7 +55,7 @@ protected:
bool _needRedraw;
//0000002B field_2B db ?
//0000002C field2C dd ? // unused
- NRect _rect1;
+ NDrawRect _drawRect;
NDrawRect _deltaRect;
NRect _rect;
uint16 _flags;