GithubHelp home page GithubHelp logo

Palette does not work as expected about wasm4 HOT 11 OPEN

aduros avatar aduros commented on May 22, 2024
Palette does not work as expected

from wasm4.

Comments (11)

aduros avatar aduros commented on May 22, 2024

Hmm, it turns out the 3rd param to store is in bytes and not in elements. So it should be:

store<u32>(w4.PALETTE, 0xff0000, 0);    // light
store<u32>(w4.PALETTE, 0xe30000, 4);    // red
store<u32>(w4.PALETTE, 0x306850, 8);    // green
store<u32>(w4.PALETTE, 0x000000, 12);    // black

I'll update the docs accordingly.

from wasm4.

ttulka avatar ttulka commented on May 22, 2024

Yeah, it is not very use-friendly... What about making it explicit that only four colors are supported?:

store<u32>(w4.PALETTE_1, 0xff0000);    // light
store<u32>(w4.PALETTE_2, 0xe30000);    // red
store<u32>(w4.PALETTE_3, 0x306850);    // green
store<u32>(w4.PALETTE_4, 0x000000);    // black

Some more high-level API wouldn't be quite bad, too:

w4.setPallete(0xff0000, 1);
w4.setPallete(0xe30000, 2);
w4.setPallete(0x306850, 3);
w4.setPallete(0x000000, 4);

Or even?:

w4.setPallete1(0xff0000);
w4.setPallete2(0xe30000);
w4.setPallete3(0x306850);
w4.setPallete4(0x000000);

// or...

w4.setPallete(0xff0000, 0xe30000, 0x306850, 0x000000);

from wasm4.

aduros avatar aduros commented on May 22, 2024

PALETTE1 to PALETTE4 sounds good!

I think we should also ask the AssemblyScript folks if there's a bug with the 3rd param to store. This documentation seems wrong https://www.assemblyscript.org/introduction.html#low-level-perspective

from wasm4.

ttulka avatar ttulka commented on May 22, 2024

documentation seems wrong

Could you collaborate more?

The AS community is very active on Discord, that would be the best plate where to ask.

from wasm4.

aduros avatar aduros commented on May 22, 2024

Could you collaborate more?

In the store() example at that link, the 3rd param should be 32 instead of 8 to match the C example... I'll ping Discord about it.

from wasm4.

aduros avatar aduros commented on May 22, 2024

Opened https://github.com/AssemblyScript/assemblyscript/issues/2044

from wasm4.

ttulka avatar ttulka commented on May 22, 2024

Cool!

from wasm4.

aduros avatar aduros commented on May 22, 2024

So unfortunately the AS behavior is intended and the documentation was just wrong. I changed the WASM-4 documentation to use sizeof() to calculate the array index positions. Let's let that sit for a bit and see how it feels before adding PALETTE1-4.

from wasm4.

ttulka avatar ttulka commented on May 22, 2024

In Snake, I have already used

store<u32>(w4.PALETTE, 0xe0f8cf, 0 * sizeof<u32>());

But I find it plain ugly. Especially in JS-related languages such as AS, things like sizeof are very alien.

Another benefit of using PALETTE1-4 would be preventing developers from writing:

store<u32>(w4.PALETTE, 0xe0f8cf, 5 * sizeof<u32>());

It is really not a big deal, but IMHO it would increase the Developer Experience.

What speaks against that?

from wasm4.

eXponenta avatar eXponenta commented on May 22, 2024

There are a lot of another ways to damage WASM memory.
You can wrap pallete inside your app on AS like this (you can remove trash code, this is generic pointer):

https://github.com/AssemblyScript/assemblyscript/blob/main/tests/compiler/std/pointer.ts

from wasm4.

MaxGraey avatar MaxGraey commented on May 22, 2024

It should be

store<u32>(w4.PALETTE, 0xe0f8cf, 0 * sizeof<u32>());    // light
store<u32>(w4.PALETTE, 0xe30000, 1 * sizeof<u32>());    // red
store<u32>(w4.PALETTE, 0x306850, 2 * sizeof<u32>());    // green
store<u32>(w4.PALETTE, 0x000000, 3 * sizeof<u32>());    // black

from wasm4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.