start lua planning

vilmibm 2022-12-15 00:14:22 -08:00
parent f021ba0133
commit a210859041
4 changed files with 13 additions and 0 deletions

View File

@ -26,6 +26,7 @@ require ( v0.0.13 // indirect v0.9.1 // indirect v0.2.0 // indirect v0.0.0-20221210110428-332342483e3f // indirect v0.0.0-20210711020723-a769d52b0f97 // indirect v0.0.0-20210226172049-e18ecbb05110 // indirect v0.0.0-20210615035016-665e8c7367d1 // indirect

View File

@ -164,6 +164,8 @@ v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= v0.0.0-20221210110428-332342483e3f h1:wihIB0V/mGpVYrL8I7n/WxVqWnP07CBXZ5uCgxUP1tI= v0.0.0-20221210110428-332342483e3f/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=

View File

@ -22,6 +22,15 @@ var (
port = flag.Int("port", 6666, "The server port")
I'm going to take a much simpler approach to scripts than I did in tildemush: objects just get one text column with no revision tracking. to avoid re-parsing scripts per verb check (as every overheard verb has to be checked against an object's script every verb utterance) i want an in-memory cache of lua states. i'm not actually sure if the goroutine unsafety is a problem for that. if it is, i can put goroutines in memory and send them verbs over channels. annoying, but should work if i have to. going to start with a naive map of object ids to scripts, re-parsing them if they get edited and updating the cache.
The cache will grow without bound as users enter rooms with objects. they ought to be garbage collected. i can do that in a goroutine though (check DB for objects in rooms with no players). One complication will be when I have "cron" support for objects. they will need to be "live" (ie, their scripts executable) in order to do their periodic tasks.
An idea I just had for a cron system: respond to a "tick" verb. at server start, once all in-world objects get parsed, start emitting "tick" events from a for loop in a goroutine in rooms with objects. this can be optimized for having a way to flag periodic-able objects so they don't get the verb if they wouldn't respond.
func _main() (err error) {
l, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {

View File

@ -17,6 +17,7 @@ CREATE TABLE objects (
avatar boolean NOT NULL DEFAULT FALSE,
bedroom boolean NOT NULL DEFAULT FALSE,
data jsonb NOT NULL,
script text,
owner integer REFERENCES accounts ON DELETE RESTRICT