ScummVM API documentation
entity.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef NEVERHOOD_ENTITY_H
23#define NEVERHOOD_ENTITY_H
24
25#include "common/str.h"
26#include "neverhood/neverhood.h"
27#include "neverhood/gamevars.h"
28#include "neverhood/graphics.h"
29#include "neverhood/sound.h"
30
31namespace Neverhood {
32
33class Entity;
34class SoundResource;
35
36enum MessageParamType {
37 mptInteger,
38 mptPoint,
39 mptEntity
40};
41
43public:
44 MessageParam(uint32 value) : _type(mptInteger), _integer(value) {}
45 MessageParam(NPoint value) : _type(mptPoint), _point(value) {}
46 MessageParam(Entity *entity) : _type(mptEntity), _entity(entity) {}
47 uint32 asInteger() const;
48 NPoint asPoint() const;
49 Entity *asEntity() const;
50protected:
51 union {
52 uint32 _integer;
53 NPoint _point;
54 Entity *_entity;
55 };
56 MessageParamType _type;
57};
58
59// TODO: Disable heavy debug stuff in release mode
60
61#define SetUpdateHandler(handler) \
62 do { \
63 _updateHandlerCb = static_cast <void (Entity::*)(void)> (handler); \
64 debug(5, "SetUpdateHandler(" #handler ")"); \
65 _updateHandlerCbName = #handler; \
66 } while (0)
67
68#define SetMessageHandler(handler) \
69 do { \
70 _messageHandlerCb = static_cast <uint32 (Entity::*)(int messageNum, const MessageParam &param, Entity *sender)> (handler); \
71 debug(5, "SetMessageHandler(" #handler ")"); \
72 _messageHandlerCbName = #handler; \
73 } while (0)
74
75const uint kMaxSoundResources = 16;
76
77class Entity {
78public:
79 Common::String _updateHandlerCbName;
80 Common::String _messageHandlerCbName;
81 Entity(NeverhoodEngine *vm, int priority);
82 virtual ~Entity();
83 virtual void draw();
84 void handleUpdate();
85 uint32 receiveMessage(int messageNum, const MessageParam &param, Entity *sender);
86 // NOTE: These were overloaded before for the various message parameter types
87 // it caused some problems so each type gets its own sendMessage variant now
88 uint32 sendMessage(Entity *receiver, int messageNum, const MessageParam &param);
89 uint32 sendMessage(Entity *receiver, int messageNum, uint32 param);
90 uint32 sendPointMessage(Entity *receiver, int messageNum, const NPoint &param);
91 uint32 sendEntityMessage(Entity *receiver, int messageNum, Entity *param);
92 // Shortcuts for game variable access
93 uint32 getGlobalVar(uint32 nameHash);
94 void setGlobalVar(uint32 nameHash, uint32 value);
95 uint32 getSubVar(uint32 nameHash, uint32 subNameHash);
96 void setSubVar(uint32 nameHash, uint32 subNameHash, uint32 value);
97 void incGlobalVar(uint32 nameHash, int incrValue);
98 void incSubVar(uint32 nameHash, uint32 subNameHash, int incrValue);
99 int getPriority() const { return _priority; }
100 bool hasMessageHandler() const { return _messageHandlerCb != nullptr; }
101protected:
102 void (Entity::*_updateHandlerCb)();
103 uint32 (Entity::*_messageHandlerCb)(int messageNum, const MessageParam &param, Entity *sender);
104 NeverhoodEngine *_vm;
105 int _priority;
106 SoundResource **_soundResources;
107 SoundResource *getSoundResource(uint index);
108 void loadSound(uint index, uint32 fileHash);
109 void playSound(uint index, uint32 fileHash = 0);
110 void stopSound(uint index);
111 bool isSoundPlaying(uint index);
112 void setSoundVolume(uint index, int volume);
113 void setSoundPan(uint index, int pan);
114 void deleteSoundResources();
115};
116
117} // End of namespace Neverhood
118
119#endif /* NEVERHOOD_ENTITY_H */
Definition: str.h:59
Definition: entity.h:77
Definition: neverhood.h:69
Definition: sound.h:43
Definition: entity.h:42
Definition: graphics.h:32