The Visual Layer

Updated: 2026-05-29

Although GPSS-Plus allows animations to be created using native agents and graphics, the Conveyor algorithm delegates visual responsibility to an external resource of type MEDIA.

In this way, the DES logic only needs to emit vector states, allowing the simulation engine to run while rendering is managed independently.

 

LOAD_MEDIA https://gpss-plus.com/imports_js/Conveyor_medio.js
INSTANCE_MEDIA {name:conveyor, class:Conveyor}

This better expresses the idea of "fire & forget", allowing us to completely disregard the visual layer.

This script, injected into GPSS-Plus, receives the boxes' vector data and takes care of everything.

On the one hand, we have this PROCEDURE in the code, which sends data to MEDIA only when there is a relevant change in the logic (a new event), in keeping with the philosophy of minimizing computation. The state being sent is entirely declarative: the logic does not report movements, but rather kinematic states and causal relationships:

PROCEDURE setStatusDisplay
    assign stateData,[]
    FOREACH entityNumber,IN_RESOURCE,RR_Conveyor
        assign.push stateData,{
                    id: P$entityNumber,
                    position: P$(RR_Position,P$entityNumber),
                    time:   P$(RR_Time,P$entityNumber),
                    length: P$(RR_Length,P$entityNumber),
                    height: P$(RR_Height,P$entityNumber),
                    width:  P$(RR_Width,P$entityNumber),
                    moving: P$(RR_Moving,P$entityNumber),
                    color: "P$(RR_Color,P$entityNumber)"
                }
    ENDFOREACH
    ASSIGN msg,{operation:"set",state:V$stateData}
    EXEC_MEDIA {name:conveyor,in:V$msg}
ENDPROCEDURE

On the other hand, the injected script implements the onRenderFrame method, which is automatically invoked by the rendering engine in each cycle. Internally, the moveBox method handles kinematic interpolation based on the current time (AC1):

 moveBox({ AC1, id, position }) {

  const obj = this.boxes.get(id);
  if (!obj) return;

  const { mesh, length, cube } = obj;

  // ----------------------------------------
  // position = LONGITUDINAL CENTER
  // ----------------------------------------

  // distance of the center along the conveyor
  const centerDistance = position * this.scale;

  // actual half-length
  const half = length * this.scale * 0.5;

  // actual center in world coordinates
  const cx = this.belt_x1 + this.dir_x * centerDistance;
  const cy = this.belt_y1 + this.dir_y * centerDistance;

  // tail
  const x1 = cx - this.dir_x * half;
  const y1 = cy - this.dir_y * half;

  // head
  const x2 = cx + this.dir_x * half;
  const y2 = cy + this.dir_y * half;

  // ----------------------------------------
  // update line
  // ----------------------------------------

  const positions = mesh.geometry.attributes.position.array;

  // tail
  positions[0] = x1;
  positions[1] = y1;
  positions[2] = 0;

  // head
  positions[3] = x2;
  positions[4] = y2;
  positions[5] = 0;

  mesh.geometry.attributes.position.needsUpdate = true;

  // ----------------------------------------
  // update derived visual representation
  // ----------------------------------------

  cube.onRenderFrame(AC1,cx,cy,0, true,"");
      
}

Visual conclusion: By limiting ourselves to these rendering requirements, the logic becomes dramatically simpler. The system does not search for visual collisions; it simply emits a perfect current state, and the renderer does whatever is necessary to display it at each instant.