1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef NEVERHOOD_ENTITY_H 24 #define NEVERHOOD_ENTITY_H 25 26 #include "common/str.h" 27 #include "neverhood/neverhood.h" 28 #include "neverhood/gamevars.h" 29 #include "neverhood/graphics.h" 30 #include "neverhood/sound.h" 31 32 namespace Neverhood { 33 34 class Entity; 35 class SoundResource; 36 37 enum MessageParamType { 38 mptInteger, 39 mptPoint, 40 mptEntity 41 }; 42 43 struct MessageParam { 44 public: MessageParamMessageParam45 MessageParam(uint32 value) : _type(mptInteger), _integer(value) {} MessageParamMessageParam46 MessageParam(NPoint value) : _type(mptPoint), _point(value) {} MessageParamMessageParam47 MessageParam(Entity *entity) : _type(mptEntity), _entity(entity) {} 48 uint32 asInteger() const; 49 NPoint asPoint() const; 50 Entity *asEntity() const; 51 protected: 52 union { 53 uint32 _integer; 54 NPoint _point; 55 Entity *_entity; 56 }; 57 MessageParamType _type; 58 }; 59 60 // TODO: Disable heavy debug stuff in release mode 61 62 #define SetUpdateHandler(handler) \ 63 do { \ 64 _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \ 65 debug(5, "SetUpdateHandler(" #handler ")"); \ 66 _updateHandlerCbName = #handler; \ 67 } while (0) 68 69 #define SetMessageHandler(handler) \ 70 do { \ 71 _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam ¶m, Entity *sender)> (handler); \ 72 debug(5, "SetMessageHandler(" #handler ")"); \ 73 _messageHandlerCbName = #handler; \ 74 } while (0) 75 76 const uint kMaxSoundResources = 16; 77 78 class Entity { 79 public: 80 Common::String _updateHandlerCbName; 81 Common::String _messageHandlerCbName; 82 Entity(NeverhoodEngine *vm, int priority); 83 virtual ~Entity(); 84 virtual void draw(); 85 void handleUpdate(); 86 uint32 receiveMessage(int messageNum, const MessageParam ¶m, Entity *sender); 87 // NOTE: These were overloaded before for the various message parameter types 88 // it caused some problems so each type gets its own sendMessage variant now 89 uint32 sendMessage(Entity *receiver, int messageNum, const MessageParam ¶m); 90 uint32 sendMessage(Entity *receiver, int messageNum, uint32 param); 91 uint32 sendPointMessage(Entity *receiver, int messageNum, const NPoint ¶m); 92 uint32 sendEntityMessage(Entity *receiver, int messageNum, Entity *param); 93 // Shortcuts for game variable access 94 uint32 getGlobalVar(uint32 nameHash); 95 void setGlobalVar(uint32 nameHash, uint32 value); 96 uint32 getSubVar(uint32 nameHash, uint32 subNameHash); 97 void setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value); 98 void incGlobalVar(uint32 nameHash, int incrValue); 99 void incSubVar(uint32 nameHash, uint32 subNameHash, int incrValue); getPriority()100 int getPriority() const { return _priority; } hasMessageHandler()101 bool hasMessageHandler() const { return _messageHandlerCb != nullptr; } 102 protected: 103 void (Entity::*_updateHandlerCb)(); 104 uint32 (Entity::*_messageHandlerCb)(int messageNum, const MessageParam ¶m, Entity *sender); 105 NeverhoodEngine *_vm; 106 int _priority; 107 SoundResource **_soundResources; 108 SoundResource *getSoundResource(uint index); 109 void loadSound(uint index, uint32 fileHash); 110 void playSound(uint index, uint32 fileHash = 0); 111 void stopSound(uint index); 112 bool isSoundPlaying(uint index); 113 void setSoundVolume(uint index, int volume); 114 void setSoundPan(uint index, int pan); 115 void deleteSoundResources(); 116 }; 117 118 } // End of namespace Neverhood 119 120 #endif /* NEVERHOOD_ENTITY_H */ 121