1
1
package baaahs
2
2
3
3
import baaahs.glshaders.GlslProgram
4
- import baaahs.glshaders.OpenPatch
4
+ import baaahs.glshaders.LinkedPatch
5
5
import baaahs.glshaders.Plugins
6
6
import baaahs.glsl.GlslContext
7
7
import baaahs.glsl.GlslRenderer
@@ -11,12 +11,15 @@ import baaahs.io.PubSubRemoteFsServerBackend
11
11
import baaahs.io.RemoteFsSerializer
12
12
import baaahs.mapper.Storage
13
13
import baaahs.model.ModelInfo
14
- import baaahs.show.*
14
+ import baaahs.show.Show
15
+ import baaahs.show.Surfaces
16
+ import baaahs.show.buildEmptyShow
15
17
import com.soywiz.klock.DateTime
16
18
import kotlinx.coroutines.CoroutineScope
17
19
import kotlinx.coroutines.Dispatchers
18
20
import kotlinx.coroutines.launch
19
21
import kotlinx.serialization.Serializable
22
+ import kotlinx.serialization.modules.SerializersModule
20
23
21
24
class StageManager (
22
25
plugins : Plugins ,
@@ -28,7 +31,7 @@ class StageManager(
28
31
private val movingHeadManager : MovingHeadManager ,
29
32
private val clock : Clock ,
30
33
modelInfo : ModelInfo
31
- ) : BaseShowResources (plugins, modelInfo) {
34
+ ) : BaseShowPlayer (plugins, modelInfo) {
32
35
val facade = Facade ()
33
36
override val glslContext: GlslContext
34
37
get() = glslRenderer.gl
@@ -116,17 +119,21 @@ class StageManager(
116
119
showRunner?.let { showRunner ->
117
120
// Unless otherwise instructed, = generate and send the next frame right away,
118
121
// then perform any housekeeping tasks immediately afterward, to avoid frame lag.
119
- if (dontProcrastinate) showRunner. housekeeping()
122
+ if (dontProcrastinate) housekeeping()
120
123
121
124
if (showRunner.renderNextFrame()) {
122
125
surfaceManager.sendFrame()
123
126
dmxUniverse.sendFrame()
124
127
}
125
128
126
- if (! dontProcrastinate) showRunner. housekeeping()
129
+ if (! dontProcrastinate) housekeeping()
127
130
}
128
131
}
129
132
133
+ private fun housekeeping () {
134
+ if (showRunner!! .housekeeping()) facade.notifyChanged()
135
+ }
136
+
130
137
fun shutDown () {
131
138
showRunner?.release()
132
139
showStateChannel.unsubscribe()
@@ -139,34 +146,20 @@ class StageManager(
139
146
var showIsUnsaved: Boolean = false
140
147
141
148
init {
142
- val commands = Topics .Commands (remoteFsSerializer)
143
- pubSub.listenOnCommandChannel(commands.newShow) { command, reply -> handleNewShow() }
149
+ val commands = Topics .Commands (SerializersModule {
150
+ include(remoteFsSerializer.serialModule)
151
+ include(plugins.serialModule)
152
+ })
153
+ pubSub.listenOnCommandChannel(commands.newShow) { command, reply -> handleNewShow(command) }
144
154
pubSub.listenOnCommandChannel(commands.switchToShow) { command, reply -> handleSwitchToShow(command.file) }
145
155
pubSub.listenOnCommandChannel(commands.saveShow) { command, reply -> handleSaveShow() }
146
156
pubSub.listenOnCommandChannel(commands.saveAsShow) { command, reply ->
147
157
handleSaveAsShow(storage.resolve(command.file.fullPath))
148
158
}
149
159
}
150
160
151
- private fun handleNewShow () {
152
- val newShow = ShowEditor (" Untitled" ).apply {
153
- addScene(" Scene 1" ) {
154
- addPatchSet(" All Dark" ) {
155
- }
156
- }
157
- addControl(" Scenes" , SpecialControl (" baaahs.Core:Scenes" ))
158
- addControl(" Patches" , SpecialControl (" baaahs.Core:Patches" ))
159
-
160
- editLayouts {
161
- copyFrom(
162
- Layouts (
163
- listOf (" Scenes" , " Patches" , " More Controls" , " Preview" , " Controls" ),
164
- mapOf (" default" to SampleData .defaultLayout)
165
- )
166
- )
167
- }
168
- }
169
- switchTo(newShow.getShow(), newShow.getShowState())
161
+ private fun handleNewShow (command : NewShowCommand ) {
162
+ switchTo(command.template ? : buildEmptyShow())
170
163
}
171
164
172
165
private fun handleSwitchToShow (file : Fs .File ? ) {
@@ -209,6 +202,12 @@ class StageManager(
209
202
inner class Facade : baaahs.ui.Facade () {
210
203
val currentShow: Show ?
211
204
get() = this @StageManager.showRunner?.show
205
+
206
+ val currentGlsl: Map <Surfaces , String >?
207
+ get() = this @StageManager.showRunner?.currentRenderPlan
208
+ ?.programs?.map { (patch, program) ->
209
+ patch.surfaces to program.fragShader.source
210
+ }?.associate { it }
212
211
}
213
212
}
214
213
@@ -238,7 +237,7 @@ class RefCounter : RefCounted {
238
237
}
239
238
}
240
239
241
- class RenderPlan (val programs : List <Pair <OpenPatch , GlslProgram >>) {
240
+ class RenderPlan (val programs : List <Pair <LinkedPatch , GlslProgram >>) {
242
241
fun render (glslRenderer : GlslRenderer ) {
243
242
glslRenderer.draw()
244
243
}
@@ -250,7 +249,9 @@ data class ClientData(
250
249
)
251
250
252
251
@Serializable
253
- class NewShowCommand {
252
+ class NewShowCommand (
253
+ val template : Show ? = null
254
+ ) {
254
255
@Serializable
255
256
class Response
256
257
}
0 commit comments