summaryrefslogtreecommitdiff
path: root/code
diff options
context:
space:
mode:
authorRaymaekers Luca <luca@spacehb.net>2025-10-02 18:01:30 +0200
committerRaymaekers Luca <luca@spacehb.net>2025-10-02 18:01:30 +0200
commit449514853850adca190d7eba679f386c024aa929 (patch)
treede57952d2b480e7d1acc0a151d95d6637e4665b6 /code
parent02841e3c67c92006f9fe08efcda0d15f3d7283c5 (diff)
checkpoint
Diffstat (limited to 'code')
-rwxr-xr-xcode/build.sh4
-rw-r--r--code/game.c104
-rw-r--r--code/platform.js10
3 files changed, 57 insertions, 61 deletions
diff --git a/code/build.sh b/code/build.sh
index 96b9516..ed819b6 100755
--- a/code/build.sh
+++ b/code/build.sh
@@ -52,7 +52,7 @@ printf 'game.c\n'
clang \
$CompilerFlags \
-nostdlib \
- --target=wasm32 \
+ -mbulk-memory --target=wasm32 \
$WarningFlags \
$LinkerFlags \
-o ../build/game.wasm \
@@ -60,7 +60,7 @@ clang \
printf 'index.html platform.js\n'
ln -f index.html platform.js ../build
-if true
+if false
then
cd ../ws
printf 'ws.c\n'
diff --git a/code/game.c b/code/game.c
index 39420b4..edcc75c 100644
--- a/code/game.c
+++ b/code/game.c
@@ -56,8 +56,8 @@ void Logf(char *Format, ...)
LogMessage(MessageLength, MessageBuffer);
}
-void RenderGradient(s32 Width, s32 Height, r32 dtForFrame,
- b32 MouseDown, s32 MouseX, s32 MouseY)
+void RenderGradient(s32 Width, s32 Height, s32 BytesPerPixel,
+ r32 dtForFrame, b32 MouseDown, s32 MouseX, s32 MouseY)
{
local_persist s32 Counter = 0;
local_persist b32 Toggle = true;
@@ -80,11 +80,6 @@ void RenderGradient(s32 Width, s32 Height, r32 dtForFrame,
R = (r32)Counter/(r32)Width;
}
- if(MouseDown)
- {
- B = 0.5f;
- }
-
// AA BB GG RR
u32 Color = ((0xFF << 24) |
((u32)(0xFF * B) << 16) |
@@ -95,57 +90,55 @@ void RenderGradient(s32 Width, s32 Height, r32 dtForFrame,
}
}
+ u32 Color = 0;
+
if(MouseDown)
{
- u32 Color = 0;
-
- u32 Pitch = BYTES_PER_PIXEL * Width;
-
- s32 Width = 5;
- s32 MinX = MouseX - Width;
- s32 MaxX = MouseX + Width;
- s32 MinY = MouseY - Width;
- s32 MaxY = MouseY + Width;
-
-#if 0
- if(MinX < 0)
- {
- MinX = 0;
- }
-
- if(MaxX > Width)
- {
- MaxX = Width;
- }
-
- if(MinY < 0)
- {
- MinY = 0;
- }
-
- if(MaxY > Height)
- {
- MaxY = Height;
- }
-#endif
-
- u8 *Row = ((u8 *)Buffer) + ((BYTES_PER_PIXEL*MinX) + (Pitch*MinY));
-
- for(s32 Y = MinY;
- Y < MaxY;
- Y++)
+ Color = 0xFFFF0000;
+ }
+
+ u32 Pitch = BytesPerPixel * Width;
+
+ s32 Size = 5;
+ s32 MinX = MouseX - Size;
+ s32 MaxX = MouseX + Size;
+ s32 MinY = MouseY - Size;
+ s32 MaxY = MouseY + Size;
+
+ if(MinX < 0)
+ {
+ MinX = 0;
+ }
+
+ if(MaxX > Width)
+ {
+ MaxX = Width;
+ }
+
+ if(MinY < 0)
+ {
+ MinY = 0;
+ }
+
+ if(MaxY > Height)
+ {
+ MaxY = Height;
+ }
+
+ u8 *Row = ((u8 *)Buffer) + ((BytesPerPixel*MinX) + (Pitch*MinY));
+
+ for(s32 Y = MinY;
+ Y < MaxY;
+ Y++)
+ {
+ u32 *Pixel = (u32 *)Row;
+ for(s32 X = MinX;
+ X < MaxX;
+ X++)
{
- u32 *Pixel = (u32 *)Row;
- for(s32 X = MinX;
- X < MaxX;
- X++)
- {
- *Pixel++ = Color;
- }
- Row += Pitch;
+ *Pixel++ = Color;
}
-
-
+ Row += Pitch;
}
@@ -157,7 +150,8 @@ void RenderGradient(s32 Width, s32 Height, r32 dtForFrame,
}
#if 1
- Logf("%.3f / (%d, %d) / %s", dtForFrame, MouseX, MouseY, ((MouseDown) ? "down" : "up"));
+ Logf("(%d, %d) / %s",
+ MouseX, MouseY, ((MouseDown) ? "down" : "up"));
#endif
} \ No newline at end of file
diff --git a/code/platform.js b/code/platform.js
index 30034a4..fda3a49 100644
--- a/code/platform.js
+++ b/code/platform.js
@@ -79,14 +79,16 @@ async function main()
var mouse_clicked = 0;
console.log(canvas);
- document.onmousemove = function(event)
+
+ document.addEventListener('pointermove', (event) =>
{
+ // Update element position here or handle drawing
var x_offset = (window.innerWidth - width)/2;
var y_offset = (window.innerHeight - height)/2;
mouse_x = event.clientX - x_offset;
mouse_y = event.clientY - y_offset;
- };
+ });
document.onmousedown = function(event)
{
@@ -106,8 +108,8 @@ async function main()
prev = timestamp;
// TODO(luca): How to get this???
- var update_hz = 144;
- instance.exports.RenderGradient(width, height, 1/update_hz, mouse_down, mouse_x, mouse_y);
+ var update_hz = 30;
+ instance.exports.RenderGradient(width, height, bytes_per_pixel, 1/update_hz, mouse_down, mouse_x, mouse_y);
ctx.putImageData(image, 0, 0);
window.requestAnimationFrame(frame);
}