ScummVM API documentation
room_object.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//=============================================================================
23//
24// Runtime room object definition.
25//
26//=============================================================================
27
28#ifndef AGS_ENGINE_AC_ROOM_OBJECT_H
29#define AGS_ENGINE_AC_ROOM_OBJECT_H
30
31#include "ags/shared/core/types.h"
32#include "ags/shared/ac/common_defines.h"
33#include "ags/shared/util/string.h"
34
35namespace AGS3 {
36
37namespace AGS {
38namespace Shared {
39class Stream;
40} // namespace Shared
41} // namespace AGS
42
43using namespace AGS; // FIXME later
44
45// RoomObject's internal values, packed in RoomObject::cycling
46// Animates once and stops at the *last* frame
47#define OBJANIM_ONCE (ANIM_ONCE + 1)
48// Animates infinitely until stopped by command
49#define OBJANIM_REPEAT (ANIM_REPEAT + 1)
50// Animates once and stops, resetting to the very first frame
51#define OBJANIM_ONCERESET (ANIM_ONCERESET + 1)
52// Animates backwards, as opposed to forwards
53#define OBJANIM_BACKWARDS 10
54
55// IMPORTANT: exposed to plugin API as AGSObject!
56// keep that in mind if extending this struct, and dont change existing fields
57// unless you plan on adjusting plugin API as well.
58struct RoomObject {
59 static const uint16_t NoView = UINT16_MAX;
60
61 int x, y;
62 int transparent; // current transparency setting
63 short tint_r, tint_g; // specific object tint
64 short tint_b, tint_level;
65 short tint_light;
66 short zoom; // zoom level, either manual or from the current area
67 short last_width, last_height; // width/height based on a scaled sprite
68 uint16_t num; // sprite slot number
69 short baseline; // <=0 to use Y co-ordinate; >0 for specific baseline
70 uint16_t view, loop, frame; // only used to track animation - 'num' holds the current sprite
71 short wait, moving;
72 int8 cycling; // stores OBJANIM_* flags and values
73 int8 overall_speed; // animation delay
74 int8 on;
75 int8 flags;
76 // Down to here is a part of the plugin API
77 short blocking_width, blocking_height;
78 int anim_volume = 100; // default animation volume (relative factor)
79 int cur_anim_volume = 100; // current animation sound volume (relative factor)
80 Shared::String name;
81
82 RoomObject();
83
84 int get_width() const;
85 int get_height() const;
86 int get_baseline() const;
87
88 inline bool has_explicit_light() const {
89 return (flags & OBJF_HASLIGHT) != 0;
90 }
91 inline bool has_explicit_tint() const {
92 return (flags & OBJF_HASTINT) != 0;
93 }
94
95 inline bool is_animating() const {
96 return (cycling > 0);
97 }
98 // repeat may be ANIM_ONCE, ANIM_REPEAT, ANIM_ONCERESET;
99 // get_anim_repeat() converts from OBJANIM_* to ANIM_* values
100 inline int get_anim_repeat() const {
101 return (cycling % OBJANIM_BACKWARDS) - 1;
102 }
103 inline bool get_anim_forwards() const {
104 return (cycling < OBJANIM_BACKWARDS);
105 }
106 inline int get_anim_delay() const {
107 return overall_speed;
108 }
109 // repeat may be ANIM_ONCE, ANIM_REPEAT, ANIM_ONCERESET
110 inline void set_animating(int repeat, bool forwards, int delay) {
111 // convert "repeat" to 1-based OBJANIM_* flag
112 cycling = (repeat + 1) + (!forwards * OBJANIM_BACKWARDS);
113 overall_speed = delay;
114 }
115
116 void UpdateCyclingView(int ref_id);
117 // Calculate wanted frame sound volume based on multiple factors
118 int GetFrameSoundVolume() const;
119 // Process the current animation frame for the room object:
120 // play linked sounds, and so forth.
121 void CheckViewFrame();
122
123 void ReadFromSavegame(Shared::Stream *in, int save_ver);
124 void WriteToSavegame(Shared::Stream *out) const;
125};
126
127} // namespace AGS3
128
129#endif
Definition: stream.h:52
Definition: string.h:60
Definition: room_object.h:58