42 |
42 |
var numEffects: Int = 0 // 'ToBe' will be more than mNumEffects if doWork() hasn't
|
43 |
43 |
var numEffectsToBe: Int = 0 // added them yet (or less if it hasn't removed some yet)
|
44 |
44 |
private set
|
45 |
|
var mEffects: Array<Effect?>
|
|
45 |
lateinit var mEffects: Array<Effect?>
|
46 |
46 |
var mUBF: UniformBlockFloatUniforms? = null
|
47 |
47 |
var mUBI: UniformBlockIntUniforms? = null
|
48 |
48 |
var iD: Long = 0
|
49 |
49 |
private set
|
50 |
50 |
private val mIndex: Int
|
51 |
51 |
private var mCreated = false
|
52 |
|
|
53 |
|
private class Job(var type: Int, var num1: Int, var num2: Int, var bool: Boolean, e: Effect?)
|
54 |
|
{
|
55 |
|
var effect: Effect = e!!
|
56 |
|
}
|
57 |
|
|
|
52 |
private class Job(var type: Int, var num1: Int, var num2: Int, var bool: Boolean, var effect: Effect?)
|
58 |
53 |
private val mJobs: ArrayList<Job>
|
59 |
54 |
|
60 |
55 |
companion object
|
... | ... | |
69 |
64 |
private const val DETALL = 3
|
70 |
65 |
|
71 |
66 |
///////////////////////////////////////////////////////////////////////////////////////////
|
72 |
|
fun allocateQueues(queues: Array<EffectQueue?>, from: Array<EffectQueue?>, flags: Int)
|
|
67 |
@JvmStatic
|
|
68 |
fun createQueues() : Array<EffectQueue?>
|
|
69 |
{
|
|
70 |
val queues: Array<EffectQueue?> = arrayOfNulls(EffectType.LENGTH)
|
|
71 |
|
|
72 |
queues[0] = EffectQueueMatrix()
|
|
73 |
queues[1] = EffectQueueVertex()
|
|
74 |
queues[2] = EffectQueueFragment()
|
|
75 |
queues[3] = EffectQueuePostprocess()
|
|
76 |
|
|
77 |
return queues
|
|
78 |
}
|
|
79 |
|
|
80 |
///////////////////////////////////////////////////////////////////////////////////////////
|
|
81 |
@JvmStatic
|
|
82 |
fun createQueues(from: Array<EffectQueue?>, flags: Int) : Array<EffectQueue?>
|
73 |
83 |
{
|
|
84 |
val queues: Array<EffectQueue?> = arrayOfNulls(EffectType.LENGTH)
|
|
85 |
|
74 |
86 |
queues[0] = if ((flags and DistortedLibrary.CLONE_MATRIX ) != 0) from[0] else EffectQueueMatrix()
|
75 |
87 |
queues[1] = if ((flags and DistortedLibrary.CLONE_VERTEX ) != 0) from[1] else EffectQueueVertex()
|
76 |
88 |
queues[2] = if ((flags and DistortedLibrary.CLONE_FRAGMENT ) != 0) from[2] else EffectQueueFragment()
|
77 |
89 |
queues[3] = if ((flags and DistortedLibrary.CLONE_POSTPROCESS) != 0) from[3] else EffectQueuePostprocess()
|
|
90 |
|
|
91 |
return queues
|
78 |
92 |
}
|
79 |
93 |
|
80 |
94 |
///////////////////////////////////////////////////////////////////////////////////////////
|
|
95 |
@JvmStatic
|
81 |
96 |
fun compute(queues: Array<EffectQueue>, currTime: Long, step: Long)
|
82 |
97 |
{
|
83 |
98 |
(queues[0] as EffectQueueMatrix ).compute(currTime, step)
|
... | ... | |
87 |
102 |
}
|
88 |
103 |
|
89 |
104 |
///////////////////////////////////////////////////////////////////////////////////////////
|
|
105 |
@JvmStatic
|
90 |
106 |
fun send(queues: Array<EffectQueue>, programH: Int, distance: Float, mipmap: Float,
|
91 |
107 |
projection: FloatArray, inflate: Float, variant: Int)
|
92 |
108 |
{
|
... | ... | |
114 |
130 |
|
115 |
131 |
///////////////////////////////////////////////////////////////////////////////////////////
|
116 |
132 |
@JvmStatic
|
117 |
|
fun getMax(index: Int): Int
|
118 |
|
{
|
119 |
|
return InternalStackFrameList.getMax(index)
|
120 |
|
}
|
|
133 |
fun getMax(index: Int): Int = InternalStackFrameList.getMax(index)
|
121 |
134 |
}
|
122 |
135 |
|
123 |
136 |
///////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
239 |
252 |
var ret = 0
|
240 |
253 |
|
241 |
254 |
for (i in 0..<numEffects)
|
242 |
|
{
|
243 |
255 |
if (mEffects[i]!!.name == name)
|
244 |
256 |
{
|
245 |
257 |
mJobs.add( Job(DETACH,0,0,true,mEffects[i]) )
|
246 |
258 |
ret++
|
247 |
259 |
}
|
248 |
|
}
|
249 |
260 |
|
250 |
261 |
if (ret > 0)
|
251 |
262 |
{
|
... | ... | |
362 |
373 |
///////////////////////////////////////////////////////////////////////////////////////////////
|
363 |
374 |
fun setAssociation(effectID: Long)
|
364 |
375 |
{
|
365 |
|
for (j in 0..<numEffects)
|
366 |
|
if (mEffects[j]!!.id == effectID)
|
367 |
|
mUBI!!.addAssociations(j, mEffects[j]!!)
|
|
376 |
for (i in 0..<numEffects)
|
|
377 |
if (mEffects[i]!!.id == effectID)
|
|
378 |
mUBI!!.addAssociations(i, mEffects[i]!!)
|
368 |
379 |
}
|
369 |
380 |
|
370 |
381 |
///////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
410 |
421 |
mCreated = true
|
411 |
422 |
}
|
412 |
423 |
ATTACH ->
|
413 |
|
if (InternalStackFrameList.getMax(mIndex)>numEffects) // it is possible that we have first
|
|
424 |
if (InternalStackFrameList.getMax(mIndex)>numEffects ) // it is possible that we have first
|
414 |
425 |
{ // added effects and then lowered mMax
|
415 |
426 |
val position = job.num1
|
416 |
427 |
|
417 |
428 |
if (position < 0)
|
418 |
429 |
{
|
419 |
|
addNow(numEffects, job.effect)
|
|
430 |
addNow(numEffects, job.effect!!)
|
420 |
431 |
numEffects++
|
421 |
432 |
changed = true
|
422 |
433 |
}
|
... | ... | |
424 |
435 |
{
|
425 |
436 |
System.arraycopy(mEffects, position, mEffects, position+1, numEffects - position)
|
426 |
437 |
mUBI!!.makeHole(position, numEffects)
|
427 |
|
addNow(position, job.effect)
|
|
438 |
addNow(position, job.effect!!)
|
428 |
439 |
numEffects++
|
429 |
440 |
changed = true
|
430 |
441 |
}
|
431 |
442 |
}
|
432 |
|
else
|
433 |
|
{
|
434 |
|
DistortedLibrary.logMessage("EffectQueue: failed to add effect " + job.effect.name)
|
435 |
|
}
|
|
443 |
else DistortedLibrary.logMessage("EffectQueue: failed to add effect " + job.effect!!.name)
|
436 |
444 |
|
437 |
445 |
DETACH ->
|
438 |
446 |
{
|
439 |
|
var j = 0
|
440 |
|
|
441 |
|
while (j < numEffects)
|
442 |
|
{
|
|
447 |
for (j in 0..<numEffects)
|
443 |
448 |
if (mEffects[j] === job.effect)
|
444 |
449 |
{
|
445 |
450 |
removeNow(j)
|
446 |
451 |
changed = true
|
447 |
452 |
break
|
448 |
453 |
}
|
449 |
|
j++
|
450 |
|
}
|
451 |
454 |
}
|
452 |
455 |
|
453 |
456 |
DETALL ->
|
454 |
457 |
{
|
455 |
|
var j = 0
|
456 |
|
while (j < numEffects)
|
|
458 |
for (j in 0..<numEffects)
|
457 |
459 |
{
|
458 |
460 |
changed = true
|
459 |
461 |
mEffects[j] = null
|
460 |
|
j++
|
461 |
462 |
}
|
462 |
463 |
|
463 |
464 |
// TODO: notify listeners?
|
464 |
|
/* if( job.bool )
|
465 |
|
{
|
466 |
|
// ...
|
467 |
|
}
|
468 |
|
*/
|
|
465 |
// if( job.bool ) { ... }
|
469 |
466 |
numEffects = 0
|
470 |
467 |
}
|
471 |
468 |
}
|
compiles and works now