Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / models / GameEngine.model
init {
	enemy := {
					"position": {"x": 0.0, "y": 0.0, "z": 0.0},
					"rotation": {"x": 0.0, "y": 0.0, "z": 0.0},
					"id": "001"
				}
}

native channel SceneUpdateEvent {
	out scene.time(time: Long, updateEvent(dt: Long)) = time + dt
}

native channel SceneUpdate {
	in scene(curSc: Json, update(curSc, nextSc)) = nextSc
}

native channel CameraPositionUpdate {
	in scene.camera.transform.position(curPos: Json, updatePosition(nextPos.x, nextPos.y, nextPos.z)) = nextPos
}

native channel CameraRotationUpdate {
	in scene.camera.transform.rotation(curRot: Json, updateRotation(nextRot.x, nextRot.y, nextRot.z)) = nextRot
}

native channel CameraScaleUpdate {
	in scene.camera.transform.scale(curScale: Json, updateScale(nextScale.x, nextScale.y, nextScale.z)) = nextScale
}

native channel CameraProjectionUpdate {
	in scene.camera.projection(curProj: Json, updateProjection(curProj, nextProj)) = nextProj
}

native channel EntityPositionUpdate(eid: Str) {
	in scene.entities.{eid}.transform.position(curPos: Json, updatePosition(nextPos.x, nextPos.y, nextPos.z)) = nextPos
}

native channel EntityRotationUpdate(eid: Str) {
	in scene.entities.{eid}.transform.rotation(curRot: Json, updateRotation(nextRot.x, nextRot.y, nextRot.z)) = nextRot
}

native channel EntityScaleUpdate(eid: Str) {
	in scene.entities.{eid}.transform.scale(curScale: Json, updateScale(nextScale.x, nextScale.y, nextScale.z)) = nextScale
}

native channel EntitySpriteUpdate(eid: Str) {
	in scene.entities.{eid}.mesh(curMesh: Json, updateSprite(spritePath: Str)) = {"type": "sprite", "sprite": spritePath}
}

native channel KeyEvent(kno: Int) {
	out scene.keys.{kno}.state(curState: Int, keyEvent(nextState)) = nextState
}

native channel TimersUpdated {
	in timers(curTimers: Map, update(curTimers, nextTimers)) = nextTimers
}

native channel TimerEvent(tid: Str) {
	out timers.{tid}.count(count: Long, tick()) = count + 1
}

channel StartTimer {
	out timers(timers: Map, startTimer(tid: Str, interval: Long)) = insert(timers, tid, {"interval": interval, "count": 0})
}

channel ClearTimer {
	out timers(timers: Map, clearTimer(tid: Str)) = delete(timers, tid)
}

channel AddSprite {
	out scene.entities(entityDB: Map, addSprite(eid: Str, spritePath: Str)) = insert(entityDB, eid, {
																										"transform": {
																											"position": {"x": 0.0, "y": 0.0, "z": 0.0},
																											"rotation": {"x": 0.0, "y": 0.0, "z": 0.0},
																											"scale": {"x": 1.0, "y": 1.0, "z": 1.0}
																										},
																										"mesh": {"type": "sprite", "sprite": spritePath}
																									})
}

channel MoveEntity(eid: Str) {
	out scene.entities.{eid}.transform.position(curPos: Json, move(x: Double, y: Double, z: Double)) = {"x": x, "y": y, "z": z}
}

channel RotateEntity(eid: Str) {
	out scene.entities.{eid}.transform.rotation(curRot: Json, rotate(x: Double, y: Double, z: Double)) = {"x": x, "y": y, "z": z}
}

channel UpdateEnemy(tid: Str) {
	in timers.{tid}.count(curCount: Long, updateEnemy(nextCount)) = nextCount
	out enemy.position(curPos: Json, updateEnemy(nextCount)) = {"x": curPos.x, "y": curPos.y + 5, "z": curPos.z}
	out enemy.rotation(curRot: Json, updateEnemy(nextCount)) = {"x": curRot.x, "y": curRot.y, "z": curRot.z + 5}
}

channel MoveEnemy {
	in enemy.position(curPos: Json, moveEnemy(nextPos, nextRot, nextId)) = nextPos
	in enemy.id(curId: Str, moveEnemy(nextPos, nextRot, nextId)) = nextId
	out scene.entities.{nextId}.transform.position(curPos: Json, moveEnemy(nextPos, nextRot, nextId)) = nextPos
}

channel RotateEnemy {
	in enemy.rotation(curRot: Json, rotateEnemy(nextPos, nextRot, nextId)) = nextRot
	in enemy.id(curId: Str, rotateEnemy(nextPos, nextRot, nextId)) = nextId
	out scene.entities.{nextId}.transform.rotation(curRot: Json, rotateEnemy(nextPos, nextRot, nextId)) = nextRot
}