Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
slot.h
Go to the documentation of this file.
1
15
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;
192 int changed;
193 std::vector<SlotShaderParam> params;
194 bool linked;
195 float scale;
196 int rotation;
197 vec angle;
198 ivec2 offset;
199 vec2 scroll;
200 int layer;
201 float alphafront, alphaback;
202 vec colorscale;
203 vec glowcolor;
204 float refractscale;
205 vec refractcolor;
206
207 VSlot(Slot *slot = nullptr, int index = -1) : slot(slot), next(nullptr), index(index), changed(0)
208 {
209 reset();
210 if(slot)
211 {
212 addvariant(slot);
213 }
214 }
215
216 void addvariant(Slot *slot);
217
218 void reset()
219 {
220 params.clear();
221 linked = false;
222 scale = 1;
223 rotation = 0;
224 angle = vec(0, sinf(0), cosf(0));
225 offset = ivec2(0, 0);
226 scroll = vec2(0, 0);
227 layer = 0;
228 alphafront = 0.5f;
229 alphaback = 0;
230 colorscale = vec(1, 1, 1);
231 glowcolor = vec(1, 1, 1);
232 refractscale = 0;
233 refractcolor = vec(1, 1, 1);
234 }
235
236 void cleanup()
237 {
238 linked = false;
239 }
240
241 bool isdynamic() const;
242};
243
247struct DecalSlot final : Slot, VSlot
248{
249 float depth, fade;
250
251 DecalSlot(int index = -1) : Slot(index), VSlot(this), depth(1), fade(0.5f) {}
252
253 int type() const override final
254 {
255 return SlotType_Decal;
256 }
257
258 const char *name() const override final;
259 const char *texturedir() const override final
260 {
261 return "media/decal";
262 }
263
264 VSlot &emptyvslot() override final
265 {
266 return *this;
267 }
268
269 int cancombine(int type) const override final;
270 bool shouldpremul(int type) const override final;
271
272 void reset()
273 {
274 Slot::reset();
275 VSlot::reset();
276 depth = 1;
277 fade = 0.5f;
278 }
279
280 void cleanup()
281 {
282 Slot::cleanup();
283 VSlot::cleanup();
284 }
285};
286
287extern std::vector<Slot *> slots;
288extern std::vector<VSlot *> vslots;
289extern std::vector<int *> editingvslots;
290
291extern const char *getshaderparamname(const char *name, bool insert = true);
292extern void setldrnotexture();
293
294extern VSlot *findvslot(const Slot &slot, const VSlot &src, const VSlot &delta);
295extern VSlot *editvslot(const VSlot &src, const VSlot &delta);
296extern Slot &lookupslot(int slot, bool load = true);
297extern VSlot &lookupvslot(int slot, bool load = true);
298extern bool unpackvslot(ucharbuf &buf, VSlot &dst, bool delta);
299extern DecalSlot &lookupdecalslot(int slot, bool load = true);
300
301#endif /* SLOT_H_ */
Definition slot.h:248
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
std::vector< SlotShaderParam > params
bitmask containing zero or more bits defined above in the VSlot enum values.
Definition slot.h:193
integer vector2
Definition geom.h:2646
two dimensional Cartesian vector object
Definition geom.h:34
three dimensional Cartesian vector object
Definition geom.h:207