Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
slot.h
Go to the documentation of this file.
1
16#ifndef SLOT_H_
17#define SLOT_H_
18
28enum
29{
30 VSlot_ShParam = 0,
31 VSlot_Scale,
32 VSlot_Rotation,
33 VSlot_Offset,
34 VSlot_Scroll,
35 VSlot_Layer,
36 VSlot_Alpha,
37 VSlot_Color,
38 VSlot_Reserved, // used by RE
39 VSlot_Refract,
40 VSlot_Detail,
41 VSlot_Angle,
42 VSlot_Num
43};
44
46{
47 enum
48 {
49 REUSE = 1<<0
50 };
51
52 const char *name;
53 size_t loc;
54 int flags;
55 float val[4];
56};
57
58struct Texture;
59class Shader;
60struct VSlot; //both slot and vslot depend on each other
61
70struct Slot
71{
72 enum
73 {
74 SlotType_Octa,
75 SlotType_Material,
76 SlotType_Decal
77 };
78
79 struct Tex
80 {
81 int type;
82 Texture *t;
83 string name;
84 int combined;
85
86 Tex() : t(nullptr), combined(-1) {}
87 };
88
89 int index, smooth;
90 std::vector<Tex> sts;
91 Shader *shader;
92 std::vector<SlotShaderParam> params;
93 VSlot *variants;
94 bool loaded;
95 uint texmask;
96 char *grass;
97 Texture *grasstex, *thumbnail;
98
99 Slot(int index = -1) : index(index), variants(nullptr), grass(nullptr) { reset(); }
100 virtual ~Slot() {}
101
102 virtual int type() const
103 {
104 return SlotType_Octa;
105 }
106
107 virtual const char *name() const;
108 virtual const char *texturedir() const
109 {
110 return "media/texture";
111 }
112
113 virtual VSlot &emptyvslot();
114
115 virtual int cancombine(int type) const;
116 virtual bool shouldpremul(int) const
117 {
118 return false;
119 }
120
132 int findtextype(int type, int last = -1) const;
133
134 void load(int index, Slot::Tex &t);
135 void load();
136
145 Texture *loadthumbnail();
146
147 void reset()
148 {
149 smooth = -1;
150 sts.clear();
151 shader = nullptr;
152 params.clear();
153 loaded = false;
154 texmask = 0;
155 delete[] grass;
156 grass = nullptr;
157 grasstex = nullptr;
158 thumbnail = nullptr;
159 }
160
161 void cleanup()
162 {
163 loaded = false;
164 grasstex = nullptr;
165 thumbnail = nullptr;
166 for(uint i = 0; i < sts.size(); i++)
167 {
168 Tex &t = sts[i];
169 t.t = nullptr;
170 t.combined = -1;
171 }
172 }
173};
174
187struct VSlot
188{
189 Slot *slot;
190 VSlot *next;
191 int index, changed;
192 std::vector<SlotShaderParam> params;
193 bool linked;
194 float scale;
195 int rotation;
196 vec angle;
197 ivec2 offset;
198 vec2 scroll;
199 int layer;
200 float alphafront, alphaback;
201 vec colorscale;
202 vec glowcolor;
203 float refractscale;
204 vec refractcolor;
205
206 VSlot(Slot *slot = nullptr, int index = -1) : slot(slot), next(nullptr), index(index), changed(0)
207 {
208 reset();
209 if(slot)
210 {
211 addvariant(slot);
212 }
213 }
214
215 void addvariant(Slot *slot);
216
217 void reset()
218 {
219 params.clear();
220 linked = false;
221 scale = 1;
222 rotation = 0;
223 angle = vec(0, sinf(0), cosf(0));
224 offset = ivec2(0, 0);
225 scroll = vec2(0, 0);
226 layer = 0;
227 alphafront = 0.5f;
228 alphaback = 0;
229 colorscale = vec(1, 1, 1);
230 glowcolor = vec(1, 1, 1);
231 refractscale = 0;
232 refractcolor = vec(1, 1, 1);
233 }
234
235 void cleanup()
236 {
237 linked = false;
238 }
239
240 bool isdynamic() const;
241};
242
246struct DecalSlot final : Slot, VSlot
247{
248 float depth, fade;
249
250 DecalSlot(int index = -1) : Slot(index), VSlot(this), depth(1), fade(0.5f) {}
251
252 int type() const override final
253 {
254 return SlotType_Decal;
255 }
256
257 const char *name() const override final;
258 const char *texturedir() const override final
259 {
260 return "media/decal";
261 }
262
263 VSlot &emptyvslot() override final
264 {
265 return *this;
266 }
267
268 int cancombine(int type) const override final;
269 bool shouldpremul(int type) const override final;
270
271 void reset()
272 {
273 Slot::reset();
274 VSlot::reset();
275 depth = 1;
276 fade = 0.5f;
277 }
278
279 void cleanup()
280 {
281 Slot::cleanup();
282 VSlot::cleanup();
283 }
284};
285
286extern std::vector<Slot *> slots;
287extern std::vector<VSlot *> vslots;
288extern std::vector<int *> editingvslots;
289
290extern const char *getshaderparamname(const char *name, bool insert = true);
291extern void setldrnotexture();
292
293extern VSlot *findvslot(const Slot &slot, const VSlot &src, const VSlot &delta);
294extern VSlot *editvslot(const VSlot &src, const VSlot &delta);
295extern Slot &lookupslot(int slot, bool load = true);
296extern VSlot &lookupvslot(int slot, bool load = true);
297extern bool unpackvslot(ucharbuf &buf, VSlot &dst, bool delta);
298extern DecalSlot &lookupdecalslot(int slot, bool load = true);
299
300#endif /* SLOT_H_ */
Definition slot.h:247
Definition slot.h:46
Definition slot.h:80
A representation of a texture inside the engine.
Definition slot.h:71
Texture * loadthumbnail()
Returns a new texture that is a thumbnail of the slot's texture.
int findtextype(int type, int last=-1) const
Attempts to find a tex with index type.
A virtual texture slot.
Definition slot.h:188
Definition tools.h:227
integer vector2
Definition geom.h:2158
two dimensional Cartesian vector object
Definition geom.h:34
three dimensional Cartesian vector object
Definition geom.h:185