Skip to content

Commit

Permalink
working on console cli invokes
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed May 18, 2024
1 parent 51ebf87 commit 7ac954f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
8 changes: 6 additions & 2 deletions zss/device/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ memorysetdefaultplayer(playerid)
// manages chips
const os = createos()

// remember last tick for cli invokes
let lasttick = 0

// tracking active player ids
const SECOND_TIMEOUT = 32
const tracking: Record<string, number> = {}
Expand Down Expand Up @@ -67,7 +70,8 @@ const vm = createdevice('vm', ['tick', 'second'], (message) => {
break
// from clock
case 'tick':
memorytick(os, message.data)
lasttick = message.data ?? 0
memorytick(os, lasttick)
break
// iterate over logged in players to check activity
case 'second':
Expand All @@ -84,7 +88,7 @@ const vm = createdevice('vm', ['tick', 'second'], (message) => {
break
// user input from built-in console
case 'cli':
memorycli(os, message)
memorycli(os, lasttick, message.player ?? '', message.data ?? '')
break
// running software messages
default:
Expand Down
28 changes: 24 additions & 4 deletions zss/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createtiles,
} from 'zss/gadget/data/types'
import { average, unique } from 'zss/mapping/array'
import { createguid } from 'zss/mapping/guid'
import { clamp } from 'zss/mapping/number'
import { MAYBE, MAYBE_STRING, ispresent, isstring } from 'zss/mapping/types'
import { OS } from 'zss/os'
Expand Down Expand Up @@ -261,14 +262,33 @@ export function memorytick(os: OS, timestamp: number) {
context.inputcurrent = undefined

// run chip code
os.tick(item.id, timestamp, item.code, item.type)
os.tick(item.id, item.type, timestamp, item.code)
}
})
}

export function memorycli(os: OS, message: MESSAGE) {
//
console.info('invoke =>', message)
export function memorycli(
os: OS,
timestamp: number,
player: string,
cli: string,
) {
// player id + unique id fo run
const id = `${player}_func`

// create / update context
const context = memoryreadchip(id)
context.book = undefined
context.board = undefined
context.inputcurrent = undefined

console.info('running', timestamp, id, cli)

// run chip code
os.tick(id, CODE_PAGE_TYPE.FUNC, timestamp, cli)

// halt code
os.halt(id)
}

function memoryconverttogadgetlayers(
Expand Down
14 changes: 5 additions & 9 deletions zss/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export type OS = {
halt: (id: string) => boolean
tick: (
id: string,
type: CODE_PAGE_TYPE,
timestamp: number,
code: string,
type: CODE_PAGE_TYPE,
) => boolean
cli: MESSAGE_FUNC
message: MESSAGE_FUNC
}

Expand Down Expand Up @@ -50,15 +49,16 @@ export function createos() {
}
return !!chip
},
tick(id, timestamp, code, type) {
tick(id, type, timestamp, code) {
let chip = chips[id]

if (!ispresent(chips[id])) {
const result = build(code)

// bail on errors
if (result.errors?.length) {
// todo, need an error message
// todo, need an error message that makes sense
api_error('os', 'build', JSON.stringify(result.errors), '')
chips[id] = null
return false
}

Expand All @@ -71,10 +71,6 @@ export function createos() {

return !!chip?.tick(timestamp)
},
cli(incoming) {
console.info(incoming)
// todo, make this rad !!
},
message(incoming) {
const { target, path } = parsetarget(incoming.target)
const targetchip: CHIP | null | undefined = chips[target]
Expand Down

0 comments on commit 7ac954f

Please sign in to comment.