Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

significant slow-down

A topic by kinkykikker created 45 days ago Views: 279 Replies: 6
Viewing posts 1 to 3
(+2)

hi there, 

i've been working with version 1.70 and i've come upon a strange case where a card runs great in the editor, but terribly in the browser. it's sort of an edge case, but i have three very wide (~3000px) canvases scrolling along with zazz, and some functionality on top of that in the card.

in the editor it works perfectly, no lag at all, but once it's online it stutters something awful and the draggable canvas used elsewhere on the card is almost unusable.

i don't expect there's much to be done about this, except use a smaller image or try a different technique, but i thought i'd make note of my experience.

on another note, is the maximum size of a canvas recorded anywhere in the api? at least the size beyond which the image distorts to fit those constraints.

thanks,

kikker

Developer (1 edit) (+2)

We were just having a discussion about improvements to general image compositing performance that may positively impact your use-case once v1.72 comes out.

You may also find performance is much better if you copy[] out a screen-sized chunk of a large canvas and paste[] it to a smaller canvas or card background image using coordinates that change over time instead of scrolling the large canvas (which necessarily updates every pixel) in-place. I'd be happy to work up an example if you need more detail.

The maximum size for widgets is currently 4096x4096 pixels, but I'd expect performance to be abysmal if a deck contained widgets that were close to that big on both axes!

Wait, do you mean do not use ZAZZ scroll and instead move a physical canvas over another image is less 'intense' computationally? Or is am I misunderstanding?

Developer (1 edit) (+1)

The zazz.scrol[] function is a thin wrapper around image.translate[], which updates every pixel of an image in-place.

Given a large source canvas/image that you want to scroll and a comparatively small window that you want to be visible at any given time, it is much less work to leave the source canvas static and copy out a window from a varying position than it is to scroll every pixel of the entire source canvas and then have Decker's compositor implicitly clip off the parts that are outside the card. See the example below.

(+2)

thanks for the quick reply,

i'll stay tuned for this update, it might help out!

for your solution, do you mean i would chop up the image into smaller chunks at runtime, at an increasing offset, and paste them over the 'viewport' canvas every couple frames? that would have me discard zazz, i take it.

i considered a system where i scroll a smaller texture and replace it when it reaches the end, but i couldn't think of a way to implement it with my knowledge of lil. it sounds like your idea is better, if you have an example of it at hand i'd love to try it!

going over my assets again i can see that around 4k i finally lost the warping, so that tracks.

Developer(+2)

Let's say we have a wide canvas with graphics in it, "source", a smaller display canvas of the same height, "target", and a field for keeping track of how far we've scrolled, "offset". In this example "target" is marked as "volatile"- since we'll be redrawing it on each frame- and "animated"- so that it gets a view[] event for redrawing itself each frame:


We can nearly achieve a horizontal scroll effect by filling in target's view[] event handler to increment the number in "offset", wrap it based on the size of "source" using the modulus operator "%" (note that this operator takes its arguments in the opposite order of modulus/remainder in many non-Lil programming languages!) and pastes a chunk copied from "source" onto "target" based on this horizontal offset:

on view do
 offset.data:offset.data+2
 x:source.size[0]%offset.data
 target.paste[source.copy[x,0 target.size]]
end

It looks like this:


When our offset reaches the edge of "source", we're missing a screenful of graphics on the right edge. Here's one way to patch it up:

on view do
 offset.data:offset.data+2
 x:source.size[0]%offset.data
 target.paste[source.copy[x,0 target.size]]
 w:source.size[0]-target.size[0]
 if x>w
  x2:target.size[0]-x-w
  target.paste[source.copy[0,0 target.size] x2,0]
 end
end


Here's the whole card as an example you can copy and paste:

%%CRD0{"c":{"name":"home","widgets":{"source":{"type":"canvas","size":[460,100],"pos":[26,46],"image":"%%IMG3AcwAZAKEj6nL7Q+jnLTai7PevPsPhuJIluaJpurKtu4Lx/JM1/aN5/rO9/4PDAqHxKLxiEwql8ym8wmNSqfUqvWKzWq33K73Cw6Lx+Sy+YxOq9fstvsNj8vn9Lr9js/r4YG+/w8YuDdIGOVXiJi4FZAhqPgIicOIETgZeYnZYjnxl+n5ybIp0QdaamoiCpF6ytpKabHqKjvbEOtgS5ubi7vAq/vL6psgDFz8SXyAbLz8qAzgzBxN6AwtbX1Hfa2Nmb3tTVXd0f2td0hnHgpLXp48RxquUQ2/LiY6v2h5r75PL0eqoO9Kqn8p5PXzdyvgFFsKVb062IZgQjQSexVsBFFNRVUNlRDbGGKeso4j0GWsAI9kEZC3UG0w2YuljX8qpckc9eXmxJIeBh7SKcPeSZziavIAypFn0U7JjIqzOLQlCKQeO1KlcPWCUw4MozIwmnVIWE5KRWx9+eCsq7NjfbBVWVOtVmFyTdVtmwMvLKtmd4z0+kyT3hgwL37gq2NcxsEv6z4l3FChY04GV1KswdhApciYDzPdKyml5ck9Mk+9t+qz1humhzmSOlMf6Xjt6h0VnTBr69MnNquesXv26tpghGOtHOG3a7e7jTQPDERoTiFh5fkW+/xHds3aY3Yx3ggZ+NjjURSe6ha2wPLhk5s5j0Q5Cfbe09J3uQToffJHALnYj4B4AKLnxE0D8qcdfOmwBs12MCiYRFcRORgehcMBN5iFKhzIG1RuyLcChMBBFhmHyZkYEkAo+gViSCJ2FsqLlKyoIhev4VFJTzJKcppvdwWhIWDH7dhUkCVwFltpNHrlY45NiERkiLM1aaSQdeDGnJVapojSkk1tCSZXWPXnZZh2ERVfj1WaqYgvZe5UIZtD4fJmUqDJyWR9UOiGp5VOgkNXn4JWIdOagx4qmIeILrrnjYw+Cmmkkk5KaaWWXopppppuymmnnn4Kaqiijkpqqaaeimqqqq7KaquuvgprrLLOSmuttt6Ka6667sprr77+Cmywwg5LLDAFAA==","scale":1},"target":{"type":"canvas","size":[100,100],"pos":[26,196],"locked":1,"animated":1,"volatile":1,"script":"on view do\n offset.data:offset.data+2\n \n x:source.size[0]%offset.data\n target.paste[source.copy[x,0 target.size]]\n \n w:source.size[0]-target.size[0]\n if x>w\n  x2:target.size[0]-x-w\n  target.paste[source.copy[0,0 target.size] x2,0]\n end\nend","scale":1},"offset":{"type":"field","size":[100,20],"pos":[265,196]}}},"d":{}}

Alternatively, you could make the graphics in "source" include an extra duplicate screenful at the end, and adjust where you wrap the "x" coordinate. Then there's no need for the "fixup" part of the script, but preparing the graphics in the "source" canvas might be more annoying and it'll take up a bit more space in the file.

To be able to scroll both left and right, you'd need to similarly handle a fixup on the left edge of the display, and so on.

Does that make sense?

(+1)

yes! that makes sense.

i've gone ahead and implemented this, but sadly the poor performance persists. it's got to come down to the large textures then, not to mention scrolling three at once.

for the purposes of this prototype i have enough to move on to godot now (as was the plan regardless) and leave this test as is. thanks for your time and the breakdown, i'll definitely check out version 1.72 when it comes along!

cheers