Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 435 lines (341 sloc) 8.208 kB
17b8b79 @rygorous RG2 license stuff
rygorous authored
1 // This code is in the public domain. See LICENSE for details.
2
c46c5bb @rygorous RG2 Initial checkin
rygorous authored
3 #include "stdafx.h"
4
5 #include "types.h"
6 #include "tool.h"
7 #include "plugbase.h"
8 #include "debug.h"
9 #include "tstream.h"
10 #include <string.h>
11
12 static sU32 globalRevCounter = 0;
13
14 // ---- toolstuff
15
16 fr::streamWrapper& operator << (fr::streamWrapper& strm, frColor& col)
17 {
18 return strm << col.r << col.g << col.b;
19 }
20
21 fr::streamWrapper& operator << (fr::streamWrapper& strm, frPoint& p)
22 {
23 return strm << p.x << p.y;
24 }
25
26 fr::streamWrapper& operator << (fr::streamWrapper& strm, frTFloat& t)
27 {
28 return strm << t.a << t.b;
29 }
30
31 fr::streamWrapper& operator << (fr::streamWrapper& strm, fr3Float& t)
32 {
33 return strm << t.a << t.b << t.c;
34 }
35
36 fr::streamWrapper& operator << (fr::streamWrapper& strm, frSelect& s)
37 {
38 return strm << s.sel;
39 }
40
41 fr::streamWrapper& operator << (fr::streamWrapper& strm, frFColor& c)
42 {
43 return strm << c.r << c.g << c.b;
44 }
45
46 fr::streamWrapper& operator << (fr::streamWrapper& strm, frLink*& link)
47 {
48 // links aren't really stored, they are resolved by the load/store code by the dependency graph anyway!
49 return strm;
50 }
51
52 // ---- frPlugin
53
54 frPlugin::frPlugin(const frPluginDef* d, sInt nLinks)
55 {
56 def = d;
57 if (d->nInputs || nLinks)
58 input = new frLink[d->nInputs + nLinks];
59 else
60 input = 0;
61
62 dirty = sTRUE;
63 revision = 0;
64
65 params = 0;
66 nParams = 0;
67 nTotalInputs = d->nInputs + nLinks;
68 nInputIdx = d->nInputs;
69
70 for (sU32 i = 0; i < nTotalInputs; i++)
71 {
72 input[i].opID = 0;
73 input[i].plg = 0;
74 }
75 }
76
77 frPlugin::~frPlugin()
78 {
79 FRSAFEDELETEA(input);
80
81 clearParams();
82 def = 0;
83 }
84
85 void frPlugin::clearParams()
86 {
87 FRSAFEDELETEA(params);
88 nParams = 0;
89 nInputIdx = def->nInputs;
90 }
91
92 sInt frPlugin::addParam()
93 {
94 frParam* oldParams = params;
95
96 params = new frParam[++nParams];
97 if (oldParams)
98 {
99 for (sInt i = 0; i < nParams - 1; i++)
100 params[i] = oldParams[i];
101
102 delete[] oldParams;
103 }
104
105 params[nParams-1].animIndex = 0;
106
107 return nParams - 1;
108 }
109
110 sInt frPlugin::addColorParam(const sChar* desc, sU32 defColor)
111 {
112 sInt ndx = addParam();
113
114 params[ndx].type = frtpColor;
115 params[ndx].desc = desc;
116 params[ndx].colorv.r = (defColor >> 16) & 0xff;
117 params[ndx].colorv.g = (defColor >> 8) & 0xff;
118 params[ndx].colorv.b = defColor & 0xff;
119
120 return ndx;
121 }
122
123 sInt frPlugin::addColorParam(const sChar* desc, const frColor& defColor)
124 {
125 return addColorParam(desc, ((sU32) defColor.r << 16) | ((sU32) defColor.g << 8) | ((sU32) defColor.b));
126 }
127
128 sInt frPlugin::addPointParam(const sChar* desc, sF32 x, sF32 y, sBool clipped)
129 {
130 sInt ndx = addParam();
131
132 params[ndx].type = frtpPoint;
133 params[ndx].desc = desc;
134 params[ndx].pointv.x = x;
135 params[ndx].pointv.y = y;
136 params[ndx].clip = clipped;
137
138 return ndx;
139 }
140
141 sInt frPlugin::addSelectParam(const sChar* desc, const sChar* opts, sInt sel)
142 {
143 sInt ndx = addParam();
144
145 params[ndx].type = frtpSelect;
146 params[ndx].desc = desc;
147 params[ndx].selectv.opts = opts;
148 params[ndx].selectv.sel = sel;
149
150 return ndx;
151 }
152
153 sInt frPlugin::addIntParam(const sChar* desc, sInt val, sInt min, sInt max, sF32 step)
154 {
155 sInt ndx = addParam();
156
157 params[ndx].type = frtpInt;
158 params[ndx].desc = desc;
159 params[ndx].intv = val;
160 params[ndx].min = min;
161 params[ndx].max = max;
162 params[ndx].step = step;
163 params[ndx].prec = 0;
164
165 return ndx;
166 }
167
168 sInt frPlugin::addFloatParam(const sChar* desc, sF32 val, sF32 min, sF32 max, sF32 step, sInt prec)
169 {
170 sInt ndx = addParam();
171
172 params[ndx].type = frtpFloat;
173 params[ndx].desc = desc;
174 params[ndx].floatv = val;
175 params[ndx].min = min;
176 params[ndx].max = max;
177 params[ndx].step = step;
178 params[ndx].prec = prec;
179
180 return ndx;
181 }
182
183 sInt frPlugin::addStringParam(const sChar* desc, sInt len, const sChar* val)
184 {
185 sInt ndx = addParam();
186
187 params[ndx].type = frtpString;
188 params[ndx].desc = desc;
189 params[ndx].maxLen = len;
190 params[ndx].stringv = val;
191
192 return ndx;
193 }
194
195 sInt frPlugin::addTwoFloatParam(const sChar* desc, sF32 val1, sF32 val2, sF32 min, sF32 max, sF32 step, sInt prec)
196 {
197 sInt ndx = addParam();
198
199 params[ndx].type = frtpTwoFloat;
200 params[ndx].desc = desc;
201 params[ndx].tfloatv.a = val1;
202 params[ndx].tfloatv.b = val2;
203 params[ndx].min = min;
204 params[ndx].max = max;
205 params[ndx].step = step;
206 params[ndx].prec = prec;
207
208 return ndx;
209 }
210
211 sInt frPlugin::addThreeFloatParam(const sChar* desc, sF32 val1, sF32 val2, sF32 val3, sF32 min, sF32 max, sF32 step, sInt prec)
212 {
213 sInt ndx = addParam();
214
215 params[ndx].type = frtpThreeFloat;
216 params[ndx].desc = desc;
217 params[ndx].trfloatv.a = val1;
218 params[ndx].trfloatv.b = val2;
219 params[ndx].trfloatv.c = val3;
220 params[ndx].min = min;
221 params[ndx].max = max;
222 params[ndx].step = step;
223 params[ndx].prec = prec;
224
225 return ndx;
226 }
227
228 sInt frPlugin::addFloatColorParam(const sChar* desc, sF32 r, sF32 g, sF32 b)
229 {
230 sInt ndx = addParam();
231
232 params[ndx].type = frtpFloatColor;
233 params[ndx].desc = desc;
234 params[ndx].fcolorv.r = r;
235 params[ndx].fcolorv.g = g;
236 params[ndx].fcolorv.b = b;
237
238 return ndx;
239 }
240
241 sInt frPlugin::addLinkParam(const sChar *desc, sU32 defaultOp, sInt opType)
242 {
243 sInt ndx = addParam();
244
245 params[ndx].type = frtpLink;
246 params[ndx].desc = desc;
247 params[ndx].linkv = input + nInputIdx;
248 params[ndx].linkv->opID = defaultOp;
249 params[ndx].linkv->plg = 0;
250 params[ndx].maxLen = opType;
251 nInputIdx++;
252
253 return ndx;
254 }
255
256 void frPlugin::updateRevision()
257 {
258 revision = globalRevCounter++;
259 }
260
261 sBool frPlugin::onParamChanged(sInt param)
262 {
263 return sFALSE;
264 }
265
266 sBool frPlugin::doProcess()
267 {
268 return sFALSE;
269 }
270
271 sBool frPlugin::process(sU32 counter)
272 {
273 return sFALSE;
274 }
275
276 sBool frPlugin::onConnectUpdate()
277 {
278 return sFALSE;
279 }
280
281 const sChar* frPlugin::getDisplayName() const
282 {
283 return def->name;
284 }
285
286 void frPlugin::setInput(sU32 index, sU32 refID)
287 {
288 if (index < def->nInputs)
289 {
290 if (input[index].opID != refID)
291 {
292 input[index].opID = refID;
293 input[index].plg = 0;
294
295 dirty = sTRUE;
296 }
297 }
298 }
299
300 sBool frPlugin::setParam(sU32 i, frParam* p)
301 {
302 sBool ret = sFALSE;
303
304 if (i < nParams)
305 {
306 ATLASSERT(p == (params+i));
307
308 ret = onParamChanged(i);
309 dirty = sTRUE;
310 }
311
312 return ret;
313 }
314
315 void frPlugin::markNew()
316 {
317 dirty = sTRUE;
318 }
319
320 void frPlugin::setAnim(sInt index, const sF32* vals)
321 {
322 }
323
324 void frPlugin::serialize(fr::streamWrapper& strm)
325 {
326 }
327
32fcb71 @rygorous RG2 compiles with VS2010
rygorous authored
328 void frPlugin::exportTo(fr::stream& f, const frGraphExporter& exp)
c46c5bb @rygorous RG2 Initial checkin
rygorous authored
329 {
330 }
331
332 sInt frPlugin::getButtonType()
333 {
334 if (def->nInputs == 0)
335 return 0; // generator
336 else if (def->nInputs == 1)
337 return 1; // filter
338 else
339 return 2; // combiner
340 }
341
342 sBool frPlugin::displayParameter(sU32 index)
343 {
344 return sTRUE;
345 }
346
347 // ---- housekeeping
348
349 static frPluginDef* plugins = 0;
350 static sInt nPlugins = 0, maxPlugins = 0;
351
352 int __cdecl defCompareFunc(const void* elem1, const void* elem2)
353 {
354 const frPluginDef* d1=(const frPluginDef*) elem1;
355 const frPluginDef* d2=(const frPluginDef*) elem2;
356
357 return stricmp(d1->name, d2->name);
358 }
359
360 void frRegisterPlugin(frPluginDef* d)
361 {
362 if (d->ID < 0)
363 {
364 d->isVisible = sFALSE;
365 d->ID = -d->ID;
366 }
367 else
368 d->isVisible = sTRUE;
369
370 for (sInt i = 0; i < nPlugins; i++)
371 FRASSERT(plugins[i].ID != d->ID);
372
373 if (nPlugins == maxPlugins)
374 plugins = (frPluginDef*) realloc(plugins, (maxPlugins += 8) * sizeof(frPluginDef));
375
376 plugins[nPlugins] = *d;
377 nPlugins++;
378
379 qsort(plugins, nPlugins, sizeof(frPluginDef), defCompareFunc);
380 }
381
382 frPluginDef* frGetPluginByIndex(sInt i)
383 {
384 return (i < nPlugins) ? plugins + i : 0;
385 }
386
387 frPluginDef* frGetPluginByID(sU32 id)
388 {
389 for (sInt i = 0; i < nPlugins; i++)
390 {
391 if (plugins[i].ID == id)
392 return plugins + i;
393 }
394
395 return 0;
396 }
397
398 struct pluginDeInit
399 {
400 ~pluginDeInit()
401 {
402 free(plugins);
403 }
404 };
405
406 static pluginDeInit pdi;
407
408 // ---- frPluginDefIterator
409
410 frPluginDefIterator::frPluginDefIterator()
411 : index(0)
412 {
413 }
414
415 frPluginDefIterator& frPluginDefIterator::operator ++()
416 {
417 index++;
418 return *this;
419 }
420
421 const frPluginDef* frPluginDefIterator::operator ->() const
422 {
423 return (index < nPlugins) ? plugins + index : 0;
424 }
425
426 frPluginDefIterator::operator const frPluginDef* () const
427 {
428 return (index < nPlugins) ? plugins + index : 0;
429 }
430
431 sInt frPluginDefIterator::getIndex() const
432 {
433 return index;
17b8b79 @rygorous RG2 license stuff
rygorous authored
434 }
Something went wrong with that request. Please try again.