1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
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 STARK_RESOURCES_LAYER_H
24 #define STARK_RESOURCES_LAYER_H
25 
26 #include "common/array.h"
27 #include "common/str.h"
28 
29 #include "engines/stark/gfx/renderentry.h"
30 #include "engines/stark/resources/object.h"
31 
32 namespace Stark {
33 
34 namespace Formats {
35 class XRCReadStream;
36 }
37 
38 namespace Resources {
39 
40 class Item;
41 
42 /**
43  * A location layer
44  *
45  * Layers own the scene items
46  */
47 class Layer : public Object {
48 public:
49 	static const Type::ResourceType TYPE = Type::kLayer;
50 
51 	enum SubType {
52 		kLayer2D = 1,
53 		kLayer3D = 2
54 	};
55 
56 	/** Layer factory */
57 	static Object *construct(Object *parent, byte subType, uint16 index, const Common::String &name);
58 
59 	Layer(Object *parent, byte subType, uint16 index, const Common::String &name);
60 	virtual ~Layer();
61 
62 	// Resource API
63 	virtual void readData(Formats::XRCReadStream *stream) override;
64 	virtual void saveLoad(ResourceSerializer *serializer) override;
65 	virtual void saveLoadCurrent(ResourceSerializer *serializer) override;
66 
67 	/** Obtain the render entry for the background item */
68 	virtual Gfx::RenderEntry *getBackgroundRenderEntry() = 0;
69 
70 	/** Obtain the render entries for all items, including the background */
71 	virtual Gfx::RenderEntryArray listRenderEntries() = 0;
72 
73 	/** Obtain a list of render entries for all the lights in the layer */
74 	Gfx::LightEntryArray listLightEntries();
75 
76 	/** Scroll the layer to the specified position */
77 	void setScrollPosition(const Common::Point &position);
78 
79 	/** Get the current scroll for this layer */
80 	Common::Point getScroll() const;
81 
82 	/** Set the current scroll for this layer */
83 	void setScroll(const Common::Point &scroll);
84 
85 	/** Enable the layer */
86 	void enable(bool enabled);
87 
88 	/** Is the layer enabled? Disabled layers are not drawn. */
89 	bool isEnabled() const;
90 
91 protected:
92 	void printData() override;
93 
94 	Common::Point _scroll;
95 	float _scrollScale; // Used for the parallax effect
96 	bool _enabled;
97 };
98 
99 /**
100  * A 2D layer
101  *
102  * 2D layers contain 2D positioned items
103  */
104 class Layer2D : public Layer {
105 public:
106 	Layer2D(Object *parent, byte subType, uint16 index, const Common::String &name);
107 	virtual ~Layer2D();
108 
109 	// Resource API
110 	void readData(Formats::XRCReadStream *stream) override;
111 	void onEnterLocation() override;
112 	void onExitLocation() override;
113 
114 	// Layer API
115 	Gfx::RenderEntry *getBackgroundRenderEntry() override;
116 	Gfx::RenderEntryArray listRenderEntries() override;
117 
118 protected:
119 	void printData() override;
120 
121 	Common::Array<uint32> _itemIndices;
122 	Common::Array<Item *> _items;
123 };
124 
125 /**
126  * A 3D layer
127  *
128  * 3D layers contain 3D positioned items, a camera and a floorfield
129  */
130 class Layer3D : public Layer {
131 public:
132 	Layer3D(Object *parent, byte subType, uint16 index, const Common::String &name);
133 	virtual ~Layer3D();
134 
135 	// Resource API
136 	void readData(Formats::XRCReadStream *stream) override;
137 	void onAllLoaded() override;
138 
139 	// Layer API
140 	Gfx::RenderEntry *getBackgroundRenderEntry() override;
141 	Gfx::RenderEntryArray listRenderEntries() override;
142 
143 protected:
144 	void printData() override;
145 
146 	uint32 _field_54;
147 	uint32 _maxShadowLength;
148 	float _nearClipPlane;
149 	float _farClipPlane;
150 
151 	Item *_backgroundItem;
152 	Common::Array<Item *> _items;
153 };
154 
155 } // End of namespace Resources
156 } // End of namespace Stark
157 
158 #endif // STARK_RESOURCES_LAYER_H
159