Codea 4 - Official Thread

Thanks, John. I agree, definitely wait until things are more stable and complete before releasing the beta. I work at a company where the software development has traditionally, necessarily been rushed, buggy, and unstable but still released. There are very valid business reasons to do so in that world, but it creates side effects. It’s great to get things out the door, but the company user base now has a long-ago-ingrained distrust of the software. If someone can’t find their car keys, they assume it’s because of a bug in the software. If their Internet is down… it’s because of a bug in the software. If inflation is rising… bug in the software.

It’s much better to feel like it’s closer to stable and complete before releasing it.

[FYI, I’ve been working hard at changing the culture at my company, better stabilizing the software everywhere, and building trust, but once lost, it’s hard to regain.]

@Creator27, I think I can answer for the Codea group, and save them some time. A game server doesn’t need to be created by or integrated with Codea (although that would be cool). You could create your own, and anyone (or any group) could work on a project together to create a server along with a Codea framework for integrating with a server.

Communication with the server is just standard Internet communication (http, or something else). You just use Codea’s http.request() function on your Codea code side to contact the server. The server would never, ever run Codea. That technology is entirely separate. It could run lua, but more likely would use something more typical for a server (perl, java, JavaScript/node.js, C++, etc.).

The point is, the server is just an endpoint in the Internet that knows how to handle stuff on that end, and “the Codea game” needs to know how to talk to it.

But setting up a server is a lot of work.

An open source group of coders could set up such a server, and define and code the conventions it needs (how to identify and persist a user, log in, group users for game purposes, like into teams or worlds, record scores, tell the game what other users are doing, etc.). Depending on your requirements, it can get complex: In particular, an online-real-time game requires quick response time (you might use UDP instead of HTTP because of this), which requires making trade offs (such as how many players can coexist in a world, how to structure the data, how often to synch, how to handle unpredictable delays). Then you’d want to work on a framework in Codea that makes communication with the server, as it is designed, easier and more manageable for a Codea user-developer.

Bottom line: It is a huge, huge, project, and I think the Codea guys already have too many “asks” on their plate, but it doesn’t have to be them. Anyone could do this (most of the work is non-Codea, and the Codea side doesn’t need to be built into Codea, at least, not at first). But by “anyone”, I mean someone or some group with server-side coding knowledge and experience.

One quick question about Codea 4: Is there any chance (please, please) that it will switch to using 64 bit numbers instead of 32? I’d really, really love the extra precision. 7 digits just isn’t enough, especially when trying to decompose a transform matrix into its component operations, or similar efforts involving ordinary trigonometry.

@blacatena Codea has been 64 bit math for years. Why do you think it’s only 32 bit. When I run the below example, it prints the number I show commented.

PS. What version of Codea are you running or what device are you using.

function setup()
    print(67/83)
    
    -- 0.80722891566265   
end

@blacatena I did some more checking on the forum and 64 bit math was put in Codea version 2.0 . That was back in March of 2014 .

PS. I checked Codea on my iPad 1 and it shows 32 bit math. So you need Codea version 2.0 or later.

@blacatena @dave1707
Yeah once Apple moved to a 64bit instruction set there was no reason not to use 64 bit precision maths / types

Look at the “Codea Roadmap - Current Version 3.4.6” discussion and scroll to the Codea 2.0 release. That tell about the update to 64 bit.

@John, will you aim to include Codea support for WebGL? It would seem useful if you plan to make Codea cross-platform.

hmmmm. Okay, my bad. I was looking at output from printing a vec3, which shows only 7 digit precision, but that must be just the format for printing the vec3, because when I print the components individually, I see the full precision.

@SugarRay not immediately, but my intention is to make the engine “ready” to port in the sense that it won’t strictly rely on non-cross platform technologies. Of course it will take a lot of work but will be entirely possible. Supporting multiple platforms is hard for us but will be possible (before we had a lot of non portable code relying on Apple only APIs)

Thanks for the info, @John.

@blacatena i try to avoid using vecs, vec math can’t be avoided sometimes, but the added overhead of a vec table/userdata is kinda bad compared to using individual x,y,z variables

Weekly’ish Update 2 (20/06/22)

  • Improvements to shader system and shadows (for mesh rendering)
  • Potentially fixed long standing editor crash
  • Added more example projects
  • More things that I either forgot or too minor to mention

Potentially fixed long standing editor crash
Good news.

I’ve also done some more work on the example projects:
https://github.com/JohnTM/Codea4-Docs/tree/main/docs/source/code/Examples/How%20to%20Codea

@John - you’ve been very busy. The examples are looking good - the example game looks very involved - no doubt showing off some of the best features of 4.

Will take time to digest - I’ll post any issues or ideas I encounter. Thanks for the update.

Thanks for the regular update!

+1 for the physics2d.debugDraw = true

@John, some requests for advanced 3D functions in Codea4:

Enhanced collision detection of 3D objects in craft (beyond raycast & spherecast)

Ability to easily attach/detach 3D models from each other (e.g. move 3D character into 3D car as character’s parent, move the 3D car with the 3D character in it, then detach 3D character from 3D car parent at some point and begin moving 3D character independently again)

Support for 3D animations

Support for higher level abstractions for 3D model movement (e.g. Unity’s “Transform.forward” command)

Thanks!

@SugarRay

I assume you mean stuff like objects keeping their current world position when changing parents. That shouldn’t be too hard, I just need to update the local transform whenever a parent change occurs to keep it in the same place

I have got support for animation import and skinned meshes:

https://twitter.com/johntwolives/status/1517814624225095680?s=20&t=cCcJo4FSx6ZzE7FJFF_GXA

I also did an experiment to blend between idle and walking animations (i.e. a blend tree):

function setup()
    scn = scene.default3d()
    scn.camera:add(camera.rigs.orbit)    
    cam = scn.camera:get(camera)
    
    msh = mesh.read(asset.Idle)
    
    anims = msh.animations
    idle = anims[1]
    walking = mesh.read(asset.Walking).animations[1]
    running = mesh.read(asset.Running).animations[1]
        
    model = scn:entity()
    model.y = -0.5
    model:add(msh)
    model.meshMaterial.emissive = vec4(0,0,0,0)

    local zero = vec3(0, 0, 0)
    local x = vec3(1, 0, 0) * .25
    local y = vec3(0, 1, 0) * .25
    local z = vec3(0, 0, 1) * .25
    
    -- Draw joints
    function model.draw(entity)        
        style.stroke(255).strokeWidth(5)
        matrix.push().reset()
        entity:visitPreOrder(function(b)
            local v = b:transformPoint(zero)
            local vx = b:transformPoint(x)
            local vy = b:transformPoint(y)
            local vz = b:transformPoint(z)
            style.stroke(255, 0, 0)
            gizmos.line(v, vx)                
            style.stroke(0, 255, 0)
            gizmos.line(v, vy)    
            style.stroke(0, 0, 255)
            gizmos.line(v, vz)    
        end)
        matrix.pop()
    end
    
    parameter.number("Speed", 0, 1, 0)
    
    -- Basic Animation Blending
    local t1 = 0
    local t2 = 0
    function model:update(dt)
        local d1 = walking.duration
        local d2 = running.duration
        local d3 = math.lerp(d1, d2, Speed)
        local r1 = d3 / d1
        local r2 = d3 / d2
        walking:apply(self, t1 % d1)
        running:apply(self, t2 % d2, Speed)
        t1 = t1 + dt / r1
        t2 = t2 + dt / r2
    end
    
    ground = scn:entity("Ground")
    ground:add(mesh.box(1,0.1,5))
    ground.y = -0.6
end

function draw()    
    scn:draw()
    matrix.ortho()
    style.fontSize(30)
    style.fill(255).stroke(6).strokeWidth(4)
    style.textAlign(CENTER | TOP)
    text("Codea Animation Blending Test", WIDTH/2 + 100, HEIGHT - 50)
end

Also experimenting with the ability to create animations directly:

function setup()
    -- Do your setup here
    anim = animation()
    ch = anim:addChannel("path/to/entity<transform>.position", 1)
    ch:addKey(0, 0.0)
    ch:addKey(1, 1.0)
    ch:addKey(2, 0.0)
    ch:addKey(3, 0.5)
    ch:addKey(5, 0.0)
    print(ch.length)
    print(ch.duration)
    print(ch:evaluate(1.0, true))
end

Entity has forward which returns the world space forward vector:

https://johntm.github.io/Codea4-Docs/api/entity.html