Comments (11)
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.
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.
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.
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.
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.
Opened https://github.com/AssemblyScript/assemblyscript/issues/2044
from wasm4.
Cool!
from wasm4.
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.
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.
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.
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)
- tracef should not emit a newline at the end HOT 3
- The online multiplayer system has stalls and halts
- Expose A Portable Web Runtime? HOT 1
- Zig v0.11 breaks w4's build file
- Run-native under Linux: lots of buttons donβt work, and some undocumented ones do HOT 1
- Document embedding carts using a wasm4.org iframe
- Suggestion: display runtime version number on menu HOT 1
- WASM globals are not managed by the netplay synchronization engine HOT 1
- Move games elsewhere
- [Web build] Mouse can be detected outside the screen HOT 3
- Use Go 1.21 WASI GOOS in examples HOT 2
- Start function is not called when DEV_NETPLAY flag is set.
- update zig template HOT 5
- wasm4 project runs on native mode, but doesnt run on browser HOT 1
- Inconsistent Audio Output HOT 2
- WasmGC support? HOT 1
- Correct FPS not being passed to devtools
- Zig template doesn't build HOT 3
- Make `w4 watch` less resource-hungry
- Cut new release? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wasm4.