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 HARVESTER_ENTITY_H
23#define HARVESTER_ENTITY_H
24
25#include "common/array.h"
26#include "common/rect.h"
27#include "common/str.h"
28#include "harvester/bitmap.h"
29
30namespace Graphics {
31class Screen;
32}
33
34namespace Harvester {
35
36class ResourceManager;
37
38uint32 getRuntimeClockTicks();
39
40enum EntityClass {
41 kEntityClassObject = 0,
42 kEntityClassAnimation = 1,
43 kEntityClassCursor = 2,
44 kEntityClassBackground = 3,
45 kEntityClassNpc = 4,
46 kEntityClassPlayer = 5,
47 kEntityClassMonster = 6,
48 kEntityClassRectHotspot = 0x15,
49 kEntityClassDisabledHotspot = 0x16,
50 kEntityClassTimer = 0x17,
51 kEntityClassRectHotspot18 = 0x18,
52 kEntityClassRectHotspot19 = 0x19
53};
54
55enum EntityHitTestMode {
56 kEntityHitTestNone = 0,
57 kEntityHitTestBounds = 1,
58 kEntityHitTestOpaquePixels = 2
59};
60
61enum EntityAnchorMode {
62 kEntityAnchorTopLeft = 0,
63 kEntityAnchorCentered = 1
64};
65
66class Entity {
67public:
68 bool loadBitmapResource(ResourceManager &resources, const Common::String &path);
69 bool loadAbmResource(ResourceManager &resources, const Common::String &path);
70
71 void setName(const Common::String &name) { _name = name; }
72 const Common::String &getName() const { return _name; }
73
74 void setClassId(int classId) { _classId = classId; }
75 int getClassId() const { return _classId; }
76 void setAnchorMode(EntityAnchorMode anchorMode);
77 void setZExtent(float zExtent) { _zExtent = zExtent; }
78 float getZExtent() const { return _zExtent; }
79
80 void setLooping(bool looping) { _looping = looping; }
81 void setPingPong(bool pingPong) { _pingPong = pingPong; }
82 void setPlayBackwards(bool playBackwards) { _playBackwards = playBackwards; }
83 void setVisible(bool visible) { _visible = visible; }
84 bool isVisible() const { return _visible; }
85
86 void setPosition(int x, int y, float z);
87 int getX() const { return _x; }
88 int getY() const { return _y; }
89 float getZ() const { return _z; }
90
91 void setAnimationRate(int rate);
92 int getAnimationRate() const { return _animationRate; }
93 void setAnimationEnabled(bool enabled);
94 bool isAnimationEnabled() const { return _animationEnabled; }
95 void setCurrentFrame(int frame, bool preserveScreenBase = false);
96 int getCurrentFrame() const { return _currentFrame; }
97 int getLastFrame() const { return _lastFrame; }
98 uint getFrameCount() const { return _frames.size(); }
99 bool didAnimationAdvanceLastTick() const { return _animationAdvancedLastTick; }
100 void setAnimationFrameRange(int firstFrame, int lastFrame, bool looping);
101 void setAnimationSequence(int sequence);
102 int getAnimationSequence() const { return _animationSequence; }
103 void configureHotspotBounds(int width, int height);
104 void setHitTestMode(EntityHitTestMode mode) { _hitTestMode = mode; }
105 int getBoundsWidth() const { return _boundsWidth; }
106 int getBoundsHeight() const { return _boundsHeight; }
107 bool getCurrentFrameMetrics(int &width, int &height, int &xOffset, int &yOffset) const;
108 bool hasOpaqueFramesInRange(int firstFrame, int lastFrame) const;
109 void setDepthScale(float scale);
110 float getDepthScale() const { return _depthScale; }
111 Common::Rect getScreenRect() const;
112 void configureTimerCountdown(int initialValue, int currentValue, bool enabled, bool looping, bool global);
113 bool tickTimerState(uint32 now, Common::Array<Common::String> &expiredTimerNames);
114 void pauseTimerCountdown(uint32 now);
115 void resumeTimerCountdown(uint32 now);
116 void setTimerEnabled(bool enabled);
117 bool isTimerEnabled() const { return _timerEnabled; }
118 bool isTimerLooping() const { return _timerLooping; }
119 bool isTimerGlobal() const { return _timerGlobal; }
120 int getTimerInitialValue() const { return _timerInitialValue; }
121 int getTimerCurrentValue() const { return _timerCurrentValue; }
122
123 bool hasFrames() const { return !_frames.empty(); }
124 bool tickVisualState(uint32 now);
125 void draw(Graphics::Screen &screen) const;
126 bool hitTest(const Common::Point &point) const;
127 bool overlapsEntity(const Entity &other) const;
128 bool overlapsBitmap(const IndexedBitmap &bitmap, const Common::Point &position, bool opaquePixels) const;
129 bool measureCurrentFrameTransparency(uint32 &framePixels, uint32 &transparentPixels,
130 uint32 &preservedPixels) const;
131
132private:
133 Common::Point getDrawOrigin() const;
134 Common::Rect getFrameRect() const;
135 bool hasOpaqueFrame() const;
136 bool isOpaqueAt(const Common::Point &point) const;
137 void advanceAnimationFrame(int directive);
138 void updateBoundsFromCurrentFrame();
139 void updateScreenBaseFromCurrentFrame();
140 void scaleCurrentFrame();
141
142 Common::String _name;
143 Common::String _resourcePath;
145 Common::Array<AbmFrame> _baseFrames;
146 Common::Array<float> _frameDepthScales;
147 int _classId = 0;
148 int _x = 0;
149 int _y = 0;
150 float _z = 0.0f;
151 int _screenBaseX = 0;
152 int _screenBaseY = 0;
153 int _currentFrame = -1;
154 int _firstFrame = -1;
155 int _lastFrame = -1;
156 int _animationRate = 0;
157 uint32 _animationTickInterval = 0;
158 uint32 _nextAnimationTick = 0;
159 int _animationSequence = -1;
160 bool _looping = true;
161 bool _pingPong = false;
162 bool _playBackwards = false;
163 bool _animationEnabled = true;
164 bool _animationAdvancedLastTick = false;
165 bool _visible = true;
166 bool _drawEnabled = true;
167 int _boundsWidth = 0;
168 int _boundsHeight = 0;
169 EntityHitTestMode _hitTestMode = kEntityHitTestNone;
170 EntityAnchorMode _anchorMode = kEntityAnchorTopLeft;
171 float _zExtent = 0.0f;
172 float _depthScale = 1.0f;
173 int _timerInitialValue = 0;
174 int _timerCurrentValue = 0;
175 uint32 _timerStartTick = 0;
176 uint32 _timerNextFireTick = 0;
177 uint32 _timerPauseTick = 0;
178 bool _timerEnabled = false;
179 bool _timerLooping = false;
180 bool _timerGlobal = false;
181 bool _timerPaused = false;
182};
183
185public:
186 explicit EntityManager(ResourceManager &resources);
188
189 void clear();
190 void clearSceneEntities(bool preserveGlobalTimers = false);
191 Entity *spawnAbmEntityFromResource(const Common::String &name, const Common::String &resourcePath,
192 int classId, const Common::Point &position, float z, int animationRate, bool looping, bool pingPong);
193 Entity *spawnBitmapEntityFromResource(const Common::String &name, const Common::String &resourcePath,
194 int classId, const Common::Point &position, float z);
195 Entity *spawnCursorEntity(const Common::Point &position);
196 Entity *spawnSceneBitmapEntity(const Common::String &name, const Common::String &resourcePath,
197 const Common::Point &position, float z);
198 Entity *spawnSceneHotspotEntity(const Common::String &name, const Common::Rect &bounds, float z);
199 Entity *spawnSceneAnimationEntity(const Common::String &name, const Common::String &resourcePath,
200 const Common::Point &position, float z, int animationRate, bool active, bool visible, bool looping,
201 bool playBackwards, bool pingPong, int initialFrame = -1);
202 Entity *spawnSceneActorEntity(const Common::String &name, const Common::String &resourcePath,
203 const Common::Point &position, float z, int initialFrame);
204 Entity *spawnSceneTimerEntity(const Common::String &name, int initialValue, int currentValue,
205 bool enabled, bool looping, bool global);
206 void configureSceneTimerEntity(Entity &entity, int initialValue, int currentValue,
207 bool enabled, bool looping, bool global);
208 Entity *getCursorEntity() const { return _cursorEntity; }
209 void hideCursor();
210 void showCursor();
211 void pauseTimerCountdowns();
212 void resumeTimerCountdowns();
213 bool takeExpiredTimerNames(Common::Array<Common::String> &expiredTimerNames);
214 bool tickSceneEntities();
215 bool syncCursorEntityPosition(const Common::Point &position);
216 void drawSceneEntities(Graphics::Screen &screen) const;
217 void drawCursor(Graphics::Screen &screen) const;
218 const Entity *findTopSceneEntityAt(const Common::Point &point, int classIdFilter = -1) const;
219 const Entity *findTopSceneEntityOverlappingBitmap(const IndexedBitmap &bitmap,
220 const Common::Point &position, const Common::String &excludedName, bool opaquePixels) const;
221 int findSceneEntityDrawIndexByName(const Common::String &name) const;
222 const Entity *findSceneEntityByName(const Common::String &name) const;
223 Entity *findSceneEntityByName(const Common::String &name);
224 Entity *detachSceneEntityByName(const Common::String &name);
225 void adoptSceneEntity(Entity *entity);
226 void reinsertSceneEntity(Entity *entity);
227
228private:
229 void insertSceneEntity(Entity *entity);
230
231 ResourceManager &_resources;
232 Common::Array<Entity *> _sceneEntities;
233 Common::Array<Common::String> _expiredTimerNames;
234 Entity *_cursorEntity = nullptr;
235 int _timerPauseDepth = 0;
236};
237
238} // End of namespace Harvester
239
240#endif // HARVESTER_ENTITY_H
Definition: str.h:59
Definition: screen.h:47
Definition: entity.h:66
Definition: entity.h:184
Definition: resources.h:32
Definition: formatinfo.h:28
Definition: rect.h:144
Definition: rect.h:536
Definition: bitmap.h:33
Definition: atari-screen.h:58