Skip to content

Commit

Permalink
NEVERHOOD: More work on Scene1002, Klayman and the rest
Browse files Browse the repository at this point in the history
- Add "heavy debug" output to Entity (display which update/message handler is called)
- Also add more debug output
- Error out when a StaticData resource could not be found
  • Loading branch information
johndoe123 authored and wjp committed May 8, 2013
1 parent b611b65 commit 436f895
Show file tree
Hide file tree
Showing 13 changed files with 1,701 additions and 73 deletions.
19 changes: 19 additions & 0 deletions engines/neverhood/collisionman.cpp
Expand Up @@ -39,6 +39,16 @@ void CollisionMan::setHitRects(uint32 id) {

void CollisionMan::setHitRects(HitRectList *hitRects) {
_hitRects = hitRects;

// DEBUG
if (_hitRects) {
debug("CollisionMan::setHitRects() count = %d", _hitRects->size());
for (HitRectList::iterator it = _hitRects->begin(); it != _hitRects->end(); it++) {
HitRect *hitRect = &(*it);
debug("(%d, %d, %d, %d) -> %04X", hitRect->rect.x1, hitRect->rect.y1, hitRect->rect.x2, hitRect->rect.y2, hitRect->type);
}
}

}

void CollisionMan::clearHitRects() {
Expand Down Expand Up @@ -79,6 +89,15 @@ void CollisionMan::clearSprites() {
_sprites.clear();
}

void CollisionMan::checkCollision(Sprite *sprite, uint16 flags, int messageNum, uint32 messageParam) {
for (Common::Array<Sprite*>::iterator iter = _sprites.begin(); iter != _sprites.end(); iter++) {
Sprite *collSprite = *iter;
if ((sprite->getFlags() & flags) && collSprite->checkCollision(sprite->getRect())) {
collSprite->sendMessage(messageNum, messageParam, sprite);
}
}
}

void CollisionMan::save() {
// TODO
}
Expand Down
1 change: 1 addition & 0 deletions engines/neverhood/collisionman.h
Expand Up @@ -40,6 +40,7 @@ class CollisionMan {
void addSprite(Sprite *sprite);
void removeSprite(Sprite *sprite);
void clearSprites();
void checkCollision(Sprite *sprite, uint16 flags, int messageNum, uint32 messageParam);
void save();
void restore();
uint getSpriteCount() const { return _sprites.size(); }
Expand Down
11 changes: 9 additions & 2 deletions engines/neverhood/entity.h
Expand Up @@ -23,6 +23,7 @@
#ifndef NEVERHOOD_ENTITY_H
#define NEVERHOOD_ENTITY_H

#include "common/str.h"
#include "neverhood/neverhood.h"
#include "neverhood/gamevars.h"
#include "neverhood/graphics.h"
Expand Down Expand Up @@ -71,12 +72,16 @@ struct MessageParam {
// TODO: Constructors for the param types...
};

#define SetUpdateHandler(handler) _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler)
#define SetMessageHandler(handler) _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam &param, Entity *sender)> (handler)
// TODO: Disable heavy debug stuff in release mode

#define SetUpdateHandler(handler) _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); debug("SetUpdateHandler(" #handler ")"); _updateHandlerCbName = #handler
#define SetMessageHandler(handler) _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam &param, Entity *sender)> (handler); debug("SetMessageHandler(" #handler ")"); _messageHandlerCbName = #handler

class Entity {
public:
Common::String _name; // Entity name for debugging purposes
Common::String _updateHandlerCbName;
Common::String _messageHandlerCbName;
Entity(NeverhoodEngine *vm, int priority)
: _vm(vm), _updateHandlerCb(NULL), _messageHandlerCb(NULL), _priority(priority), _name("Entity") {
}
Expand All @@ -86,11 +91,13 @@ class Entity {
}
void handleUpdate() {
//debug("Entity(%s).handleUpdate", _name.c_str());
debug(2, "handleUpdate() -> [%s]", _updateHandlerCbName.c_str());
if (_updateHandlerCb)
(this->*_updateHandlerCb)();
}
bool hasMessageHandler() const { return _messageHandlerCb != NULL; }
uint32 sendMessage(int messageNum, const MessageParam &param, Entity *sender) {
debug(2, "sendMessage(%04X) -> [%s]", messageNum, _messageHandlerCbName.c_str());
return _messageHandlerCb ? (this->*_messageHandlerCb)(messageNum, param, sender) : 0;
}
// NOTE: These were overloaded before for the various message parameter types
Expand Down

0 comments on commit 436f895

Please sign in to comment.