oakes / play-cljc

A Clojure and ClojureScript game library
The Unlicense
537 stars 13 forks source link

World map and instancing #12

Open Ondra09 opened 5 years ago

Ondra09 commented 5 years ago

Hi, I have taken on of your demo and rewritten it into tetris. Demo is loading map from file, and for every map tile is created one instance in OpenGL, I don't think this is optimal. Instead, you should try to create only as many OpenGL objects as needed to cover whole camera + somethink over the edge. And only be changing object's attributes from frame-to-frame. This approach is also vital for e.g. skeletal animations.

Tetris uses older demo, before tiles.cljc were moved to engine itself. Function that manipulates only instaneces is here: https://github.com/Ondra09/tetris/blob/master/src/tetris/tiles.cljc named: pdate-color-buffer-instances

oakes commented 5 years ago

Very neat, i don't think i've seen a play-cljc game from someone else before. I hit an error when the piece got to the bottom. The error happened here because spawn-new-tetro doesn't take any arguments. Make you need (assoc-in state [:active-tile] (tmove/spawn-new-tetro)) or something like that.

Yeah I think more can be done to make the tiles in super koalio only render if necessary. I haven't figured out how to do that yet.

Ondra09 commented 5 years ago

How did you start it? I am running it with: clj -A:dev dev.clj and no error given. I even trying to make new git clone. Do I need to reset some global cache?

Well changing texture for object will have huge performanc ehit, but because all textures are in texture atlas atlready, it would be probably enough to just change texture coordinates into that texture for instances and pass them as attributes (or directly Texture matrix, which I think is already used as uniform (I did not look)). At the beginning from resolution/tile size can be number of tiles needed obtained and when playre moves update instances on edges. BUT it is probably not worth the effort until your approach proves to perform badly. Without some number/measurements, it is always better to do nothing than spend weeks on optimizing something that is not needed.

oakes commented 5 years ago

Oh, I ran the native version with clj -A:dev:linux dev.clj native I have not tried the web version.

Ondra09 commented 5 years ago

Fixed, thank you for bringed that up.