Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Codea Beta 1.5.3

SimeonSimeon Admin Mod
edited June 2013 in Beta Posts: 5,054

Hi beta-people

It's been a while since the last beta, sorry about that.

Codea is getting a lot of improvement now, though.

1.5.3 will focus on adding some missing, useful functions to the API (restart, alert, perhaps programmatically creating projects, and so on). As well as optimisations to common rendering scenarios — such as sprite()

This first release integrates an experimental new feature: automatic sprite batching. It is enabled by default, you can see the release notes for more information.

Basically it attempts to draw consecutive calls to sprite as a single mesh(), if possible. This should allow you to do things like render particle systems with sprite(), as well as speed up common uses like lots of the same enemy type being rendered over and over.

There's also been a lot of other optimisations to sprite() — I'm hoping that many people will find less of a need to implement their code using mesh() due to performance concerns. That is, I'm hoping that sprite() will be "good enough" for a lot of uses.

(mesh() is great, but it requires you to carefully structure your code to work with it. It's also less intuitive to use.)

If you'd like to see a demo of how sprite batching makes a difference, try out the following Gist:

https://gist.github.com/TwoLivesLeft/5692210

This renders 1600 sprites using a number of different methods (including mesh()). You can toggle on/off the different uses.

EDIT: Fixed link

Tagged:
«1

Comments

  • BortelsBortels Mod
    Posts: 1,557

    UI bug: When I run a fullscreen app, the (new?) icon in the upper left to bring out the sidebar with the console output, when tapped, pops it out, then immediately hides it again. This happens anywhere from 5 to maybe 20 times - ie. I tap, expose/unexpose, I tap, expose/unexpose - then it "fixes" itself, and behaves like you would expect (tap, it exposes the sidebar. tap the close, sidebar goes away).

    is there a way to kill that button entirely (and the buttons along the bottom)? FULLSCREEN_NO_BUTTONS (which isn't listed by the tooltip, but is in the docs) behaves weirdly - I get no buttons until I tap, then they all come back.

    Nice to see the sprite optimization - I expect you've hit on a common case, this should be helpful in lots of stuff. I've been crazy busy with Amazon Web Services, so I've neglected my Codea work; there is no AWS library for lua. Hmm. Maybe I should make one... (The AWS API is very fragmented - it would be a chunk of work...)

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    Hi Simeon. Great news!
    Problem with your gist: the project is pulled corrrectly, but:
    - tabs are not in good order : i had to move the Juice class manually just after the main to have it compile.
    - then i get the error:

    error: [string "-- Juice..."]:78: attempt to call method 'draw' (a nil value).

    It seems that you renames rect:draw into rect:drawObject. I created a :draw, then no error. But when i click a choice i get errors again.
    So:
    - either you didnt post the good final project.
    - either it is a tab order problem: could you rename the tab in: T00... T01... Etc so they come in the appropriate order?

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Oops! Hadnt seen the Juice thread yet! Sorry for posting this.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Jmv38 drawObject is correctly named. The draw method is in the base class which invokes drawObject

  • Jmv38Jmv38 Mod
    Posts: 3,295

    I tried the alert(). Works fine in the setup(). Then i put it in touched(touch) and then when i touch the screen, it goes dim and codea freezes. Have to kill it manully.


    -- test alert -- Use this function to perform your initial setup function setup()     print("Hello World!")     --alert("hello") end -- This function gets called once every frame function draw()     -- This sets a dark background color      background(40, 40, 50)     -- This sets the line thickness     strokeWidth(5)     -- Do your drawing here      end function touched(touch)     alert("touch") end
  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Bortels that's an odd one. The sidebar button has been there since 1.5 — does anyone else have this issue?

    @Jmv38 thanks for reporting the alert() issue. I'll check it out

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Bortels just a thought — you're not calling displayMode(FULLSCREEN) at the start of draw()? That would cause the behaviour you're describing, as it would be resetting the fullscreen mode every frame.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Jmv38 alert() issue in touched() should be fixed in the next build. It's an iOS 5.x specific bug that was easy to work around.

  • BortelsBortels Mod
    Posts: 1,557

    I am. Where should it be, in setup?

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Yes (or on some action, such as a button press) — if you call it every frame it will keep resetting the screen mode back to full screen. Pressing the sidebar button simply toggles the displayMode, but your code is resetting it back immediately.

  • SimeonSimeon Admin Mod
    edited June 2013 Posts: 5,054

    @Jmv38 out of curiosity, does the sprite batching make much difference on iPad 1? (You can try it in the gist I linked: https://gist.github.com/TwoLivesLeft/5692210)

    I don't have an iPad 1 for testing at the moment. So I wonder if it makes a big difference there.

    Edit: fixed link

  • Jmv38Jmv38 Mod
    Posts: 3,295

    This link is to Juice, which has only 1 sprite?

  • Jmv38Jmv38 Mod
    Posts: 3,295

    I tried with Spritely: with 400 sprites the fps oscillate between 50-60 fps, which is, i think, better than before. But to check it i should revert to the previous version of codea.
    My other programs use meshes.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Sorry! Wrong link

    This is the link: https://gist.github.com/TwoLivesLeft/5692210

    There should be 1600 sprites

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Here are the results:
    - initial 4.0 fps.
    - use string false: 7.7 fps.
    - use mesh or use batch : 14.5 fps.
    So is is about x2 improvement from the regular sprite usage (i always load them in memory). And using the mesh is not better.
    Btw i had a memory crash while playing with the options (setting batch and mesh on).
    When you create your mesh from sprite images, how do arrange them? There may be a lot of lost space when image sizes do not fit? Or do you use a smart algorithm to arrange them?

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Jmv38 Thanks for testing it out. Good to see there is some improvement! Codea won't auto-batch over multiple textures. It behaves similar to mesh in that there is one texture per batch.

    I think the worst-case in the old version of Codea (1.5.2) would have been a lot slower than 4.0 fps on iPad 1, the string (and non-string) lookup mechanism was substantially improved in 1.5.3.

  • edited June 2013 Posts: 580

    @Simeon: FYI, on a 4th gen iPad, here are the numbers I'm getting:


    UseString on: ~12fps All off: ~25fps All On: ~52-57fps Batch on: ~52-57fps UseMesh on: ~52-57fps Batch + UseMesh on: ~52-57fps
  • Posts: 580

    @Simeon: What do you think the chances are of including the feature to optionally disable tab compilation/execution in the next release? It's not critical, but my hope is that it might be a simple enough task that it wouldn't take too long to implement.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @toadkick I would like to but it's slightly tricky for a number of reasons — the actual functionality is not hard, but the colour schemes will need new states for disabled tabs and dependent projects will need to respect them. I'll keep it in mind, but I can't say for sure.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Just sent out beta 2. This includes Air Code — see the release notes for a brief overview of how it works. Let me know how it goes for you.

  • Posts: 580

    @Simeon: fair enough :)

    BTW, AirCode works great, this is a very cool feature!

  • BortelsBortels Mod
    Posts: 1,557

    Aircode rocks. Having said that - it would be nice to be able to "re-attach" a session after you break out (in my case, to look at the docs).

    I also notice it doesn't re-interpret setup() when you change it - I added a global to my draw loop (rotate(r)) - and it barfed, so I added "r=0" to setup() - no luck, even with ctrl-r.

    This is a good opportunity to ask - are the docs online? I've been so busy at work I've been out of touch, and if they're up, I dunno where (and neither does Google, which is a seperate bad thing; the first link there, for Codea 1.5, has a page that says "Documentation", no link to anything) - before, docs online would be convenient, but with aircode - they're essential.

    BUT - those are quirks. This is awesome. I hope I can make it work at work, where we have some pretty silly/draconian wireless policies on our setup. :-)

  • edited June 2013 Posts: 580

    @Simeon: If you have a chance, would you mind explaining how you pulled this off (mainly on the Codea side, as I can see the page source from the browser side)? I am very interested in the implementation behind this.

    The main reason I'm curious is because I'm also curious about whether bits of this could be integrated into the Codea API to allow us to do similar things from within our Codea programs.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Bortels thanks for the feedback!

    Air Code reloads the code in the current file when you make a change. It does re-interpret setup(), it just doesn't re-run it (or else it would restart your project on every code change). This allows you to edit code and see visual changes in the current state of the app. (And if you pause your app then Codea will frame-step on Air Code changes.)

    Cmd+R (or Ctrl+R) from the code editor should have worked, that will restart the project, running setup() and so on. I wonder what the issue was.

    Re-attaching would be good, the state is entirely URL based, so it should be possible to make it work when you re-launch Air Code. I'll look into it.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @toadkick it runs a web server in Codea, connections are handled by Objective-C code that parses the URL and figures out what projects to serve.

    When a file is requested the editor document is populated with the file contents and sent to the browser.

    When a file is edited in the browser an ajax.post request is made, Codea gets the updated file data and attempts to execute it (lua_pcall). If there are errors, the data is not written to the project. If no errors, then the project is updated — the Lua state will have already been updated from the pcall.

    There is some fancy stuff going on in order to allow you to re-execute MyClass = class() tabs without overwriting the original class and failing to adjust existing instances. Basically when the changed code comes in, Codea uses a regex to find all class names from their code definitions. Before executing the changed code I check with Lua to see if the class has already been defined, and if so, strip the re-definition from the changed code. I was really happy that this aspect worked out. It lets you do things like alter the draw() function for a class and see all the existing instances update immediately.

  • Posts: 580

    @Simeon: very clever (particularly the part about handling classes), thanks for the explanation!

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    Confirmed: Alert is ok with ios5.

  • Posts: 2,161

    I had a go with one iPad from another. I know that that's completely daft, but figured someone had to do it. When editing a line, the cursor position was not where it ought to be (the line in question was camera(0,0,10,0,0,0,0,1,0)) but was slightly to the right. (This was with the standard Safari browser.)

    Using Firefox on my desktop worked just fine.

    I'd quite like to be able to add, delete, and rename tabs. It'd be really easy to cut-and-paste code from one project to another using this.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Andrew_Stacey yes, the code editor isn't mobile compatible. Regarding file creation — there are plans to expand on the feature if Apple approves it. I'd like to have a tab bar with a split code view. But I don't want to spend too much time on this feature until I know whether it's allowed.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Bortels sorry I missed your question — the docs are no longer online, but they are now all YAML source files. If anyone is interested in doing a quick YAML->HTML conversion on them I would be happy to put them up as a GitHub project or similar.

    @toadkick we could expose a web server as a Codea API. That would be interesting.

  • Posts: 580

    @Simeon: I was thinking along the same lines :)

  • BortelsBortels Mod
    Posts: 1,557

    I tried a docs conversion in the past - but I don't recall them being in YAML format. It proved to be a far uglier task than I had figured on, and I got distracted by bright lights and pretty colors. Got a link to the YAML docs? I may try it again.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Thanks for the offer @Bortels — they used to be written in JSON, we moved to YAML because it is much easier to write and much more readable.

    I've set up an open source project for the documentation here:
    https://github.com/TwoLivesLeft/Codea-Documentation

    Anyone who wants to help with conversion scripts, submit fixes or improve the documentation in any way, feel free to send a pull request.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @Simeon - I found one possible issue with Air Code (which is amazing).

    I ran it on this sample code
    https://gist.github.com/dermotbalson/5719306

    It worked fine when I loaded the main tab, but as soon as I pressed Crtl-R, even without changing anything, the colours in the image went black.

    It is probably because the image is drawn using a shader. This is a stencil (fragment) shader that uses one image to "cut out" part of a second image.

    It's not serious, and I guess few people use shaders like this, so it may not be worth bothering with, but that's up to you.

    I have quite a few other shader projects, and they all seemed to work ok.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Ignatz thanks for the report, I've added it to my list. I'll probably only look at bug fixing Air Code if it actually gets approved. The first release is more of an experiment to see if it gets through and into a release version of Codea.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Alert() is great and was a must.
    What about extending it a little bit?
    I think of the following syntax:

    alert(message, title, button1,button2,...,callback)
    

    button1,button2,... are strings, displayed as buttons under the message. The number of buttons is leaved to the user.
    When the user hits button1 then callback(button1) is fired.
    Would really be all we need to interract with the user.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @Simeon any feedback on my suggestion?

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Jmv38 I like your idea a lot — perhaps the callback should take the index of the button pressed (1, 2, 3 ...) instead of the name? That way you can change the button names without having to go and change your callback code.

    An alternate API design might be

    alert( message, title, { "Button Name" = function, "Button Name 2" = function } )

    This is more stable (the button name is strongly associated with the callback, but it is harder to write.

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    Why not allowing both option? As for tables, we can index them with 1,2,3 or ''blabla1", etc...
    My 'dumb programmer' experience is that it is easier for me to remember what i did if i use names, rather than numbers...
    Thanks for considering my suggestion.

  • edited June 2013 Posts: 580

    @Simeon @Jmv38: FWIW, I prefer to be provided with the index. Conceptually it's easier and generates simpler code.

    EDIT: also, it's very easy to provide your own "constants", I don't think that design choice should be baked into the API. I prefer the interface to be very simple for alerts.

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    Anyway, whatever the final syntax, it will be fine for me as long as the functionnallity is there.
    Since i can always encapsulate the function into my preferred syntax.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Not sure if this addition will make 1.5.3 or wether it will be in the next update.

  • SimeonSimeon Admin Mod
    edited June 2013 Posts: 5,054

    Beta 3 is out — @Jmv38 let me know how your physics trouble goes.

    This version is probably close to submission. I've decided against including the Juice library in this release. I'm still using it quite a lot and it's changing too quickly to be included at this point.

  • Posts: 580

    I'm very happy to see the addition of tween.delay, that should probably solve about 90% of my needs for deferred function calls :)

    While I'm sad to see Juice go, I'm glad you're still cranking on it, and I can't wait to see the final result. I wish more SDKs offered libraries like this, it makes it so much easier to polish an app to a shine.

  • Posts: 1,255

    I'll join on the Sad about Juice. Very nice stuff in there. But I'll trust that by the time it makes its way into a release, it's going to be even... juicier.

  • Jmv38Jmv38 Mod
    edited June 2013 Posts: 3,295

    Hello guys, i really feel stupid here but... can you have a look at this?

    -- Use this function to perform your initial setup
    function setup()
        img = image(200,200)
        setContext(img)
            background(255, 0, 0, 255)
            translate(100,100)
            sprite("Planet Cute:Character Boy")
        setContext()
    end
    
    
    -- This function gets called once every frame
    function draw()
        background(40, 40, 50)
        translate(200,200)
        sprite("Planet Cute:Character Boy")
        translate(200,0)
        sprite(img)
    end
    

    on my ipad the sprite doesnt seem to work in setContext(img): i get not boy in the red rectangle.
    See: https://pbs.twimg.com/media/BNO8sAfCYAAqNjw.jpg
    Is it a known bug? Or have i missed sthg obvious?
    Thanks.
    Ps: 1.5.3

  • IgnatzIgnatz Mod
    Posts: 5,396

    looks like some kind of bug, same for me

    if you add an ellipse to your custom image (just after drawing the boy), it works....

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Thanks for confirm that is a problem @ignatz.
    @Simeon can you correct that? The codea doc clearly says sprite is supposed to work within setcontext(img). Thanks

  • SimeonSimeon Admin Mod
    Posts: 5,054

    @Jmv38 thanks for finding the bug. I think it's an issue caused by the new sprite batching mechanism. Looking into it.

  • SimeonSimeon Admin Mod
    Posts: 5,054

    Fixed

Sign In or Register to comment.