In addition to logic, GPSS-Plus allows multimedia resources to be integrated, interacting with the model in real time through visualization, sound, and interfaces.
Nature of Multimedia Resources
Multimedia resources are integrated as external components that receive instructions from the model.
- They do not have access to the engine's API.
- They do not create VEs or alter the model's state.
- They do not modify the flow or timing.
- They do not return data to the model.
Their sole purpose is to perform representation or interaction actions.
Unlike logical classes:
- CLASS → transforms data (input → output)
- MEDIA → performs actions (input → visual/audio effect)
This ensures that the representation layer does not interfere with the model's logic.
Basic Usage
Multimedia resources are used in a similar way to classes:
1. Load the resource
LOAD_MEDIA https://gpss-plus.com/imports_js/Display.js
2. Instantiate it
INSTANCE_MEDIA {name:displayA, class:Display}
3. Execute it
ASSIGN panel,{operation:"write",value:"Result X$(result.out)"}
EXEC_MEDIA {name:displayA,in:V$panel}
The model sends instructions to the resource through an input object.
The resource performs the corresponding action without altering the model's state.
In the Example
- A class (
Sum) is used to perform a calculation. - The results are displayed in two panels.
- Sounds are played at different points in the flow.
The model remains in control of execution; multimedia resources simply react to it.
If continuous or time-dependent visualization is required, MEDIA resources can implement two special methods:
onRenderFrame(AC1,x,y,z,visible,subtitle){
this.mesh.visible = visible;
this.mesh.rotation.y = (AC1);
this.mesh.position.set(x,y,z);
}
onChangeVector(AC1,vector) {
/* vector composition
{
position: [x,y,z],
visible: true,
from: [x,y,z],
to: [x,y,z],
time: [t_start,t_end]
}
*/
}
onRenderFrame will be automatically invoked by the visualization engine during each redraw cycle, receiving the current simulation time and position as parameters.
This separates the reception of the required values (EXEC_MEDIA) from the visualization itself, which depends on time.
On the other hand, onChangeVector will be invoked whenever the positioning vector changes, that is, with each ADVANCE or UPDATE.
Example
/*
Injected Resources
*/
POSITION {NAME:POS1,X:620,Y:360}
GRAPHIC {NAME:Text1,TYPE:TEXT,X:373,Y:268,TEXT:"DSL Graphic",font:"24"} ; Create text graphic
LOAD_CLASS https://gpss-plus.com/imports_js/Sum.js
INSTANCE_CLASS {name:sum, class:Sum}
LOAD_MEDIA https://gpss-plus.com/imports_js/Display.js
INSTANCE_MEDIA {name:displayA, class:Display}
INSTANCE_MEDIA {name:displayB, class:Display}
LOAD_MEDIA https://gpss-plus.com/imports_js/ClickSound.js
INSTANCE_MEDIA {name:clickA, class:ClickSound}
INSTANCE_MEDIA {name:clickB, class:ClickSound}
FACILITY {NAME:counter1,X:373,Y:365,capacity:3}
START 2000
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
;*****************************************
PROCEDURE PRE_RUN
assign config,{
operation:"init",
sx:220, sy:50,
; fontSize:28,
font:"24px sans-serif",
color:"#ffff00",
background:"rgba(0,0,0,0.5)",
align:"center",
x:120, y:140, z:0
}
EXEC_MEDIA {name:displayA,in:V$config}
assign config,{
operation:"init",
sx:220, sy:50,
;fontSize:28,
font:"24px Arial",
color:"#a0b7b8ff",
background:"rgba(0,0,0,0.5)",
align:"center", x:420, y:140, z:0
}
EXEC_MEDIA {name:displayB,in:V$config}
assign soundConfig,{
operation:"init",
volume:0.3,
frequency:800,
duration:0.03
}
EXEC_MEDIA {name:clickA,in:V$soundConfig}
assign soundConfig,{
operation:"init",
volume:0.3,
frequency:400,
duration:0.03
}
EXEC_MEDIA {name:clickB,in:V$soundConfig}
TERMINATE_VE
ENDPROCEDURE
;*****************************************************
GENERATE 10,3 {NAME:GEN1,X:111,Y:366}
ADVANCE 5 {TO:counter1}
assign playInput,{operation:"play"}
assign inputs,{a:10,b:20,acc:D$N}
EXEC_CLASS {name:sum,in:V$inputs,savevalue:result}
MOVE {name:Text1,text:"Result X$(result.out) ACC: E$(sum,acc)"}
ASSIGN panel,{operation:"write",value:"Result X$(result.out)"}
EXEC_MEDIA {name:displayA,in:V$panel}
EXEC_MEDIA {name:displayB,in:V$panel}
EXEC_MEDIA {name:clickA,in:P$playInput}
SEIZE counter1
ADVANCE 20,20
EXEC_MEDIA {name:clickB,in:P$playInput}
RELEASE counter1
ADVANCE 20 {TO:POS1}
ENDGENERATE 1