-
Notifications
You must be signed in to change notification settings - Fork 190
Add TIME for when the runtime started #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RobLoach
wants to merge
14
commits into
aduros:main
Choose a base branch
from
RobLoach:start_time
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a45df4d
Add START_TIME to retrieve when the runtime started
RobLoach 2af2945
Fix reserved length
RobLoach 1182f46
Add a small clock demo
RobLoach 22fab6f
Merge branch 'start_time' of github.com:RobLoach/wasm4 into start_time
RobLoach 8f63f1e
Merge branch 'main' into start_time
RobLoach 58419a8
Rename START_TIME to TIME
RobLoach 0ba5f74
Merge branch 'start_time' of github.com:RobLoach/wasm4 into start_time
RobLoach 5222f4b
Rename to TIME
RobLoach c88a78d
Set the bigint timestamp
RobLoach 1c12e2b
Draw an actual clock
RobLoach 83eec46
Allow changing the timezone
RobLoach 0a9b71e
Fix startTime to time
RobLoach 6fa8b37
Fix startTime to Time
RobLoach a4d33d3
Fix startTime to Time
RobLoach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/build | ||
/package-lock.json | ||
/node_modules |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"entries": [ | ||
"./src/main.ts" | ||
], | ||
"options": { | ||
"binaryFile": "build/cart.wasm", | ||
"runtime": "incremental", | ||
"importMemory": true, | ||
"initialMemory": 1, | ||
"maximumMemory": 1, | ||
"noExportMemory": true, | ||
"zeroFilledMemory": true, | ||
"memoryBase": 6560, | ||
"use": [ | ||
"seed=src/wasm4/seedHandler", | ||
"trace=" | ||
] | ||
}, | ||
"targets": { | ||
"release": { | ||
"optimizeLevel": 3, | ||
"shrinkLevel": 0, | ||
"noAssert": true, | ||
"use": "abort=" | ||
}, | ||
"debug": { | ||
"debug": true, | ||
"sourceMap": "http://localhost:4444/cart.wasm.map", | ||
"use": "abort=src/wasm4/abortHandler" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "wasm4-clock", | ||
"version": "1.0.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "asc --target release", | ||
"build:debug": "asc --target debug" | ||
}, | ||
"dependencies": { | ||
"as-date": "^0.1.3" | ||
}, | ||
"devDependencies": { | ||
"assemblyscript": "^0.19.11" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as w4 from "./wasm4"; | ||
import { Date } from "as-date"; | ||
|
||
let time: f64; | ||
let timezone: i32; | ||
let previousGamepad: u8; | ||
|
||
export function start(): void { | ||
// Get the time the runtime was started. | ||
time = load<u64>(w4.TIME) as f64; | ||
|
||
// Load the timezone. | ||
const ptr = memory.data(sizeof<i32>()); | ||
w4.diskr(ptr, sizeof<i32>()); | ||
timezone = load<i32>(ptr); | ||
|
||
// Palette. | ||
store<u32>(w4.PALETTE, Number.parseInt("000000", 16) as u32); | ||
store<u32>(w4.PALETTE, Number.parseInt("ffffff", 16) as u32, 4); | ||
store<u32>(w4.PALETTE, Number.parseInt("ff0000", 16) as u32, 8); | ||
store<u32>(w4.PALETTE, Number.parseInt("00ff00", 16) as u32, 12); | ||
} | ||
|
||
function setTimezone(newTimezone:i32): void { | ||
const ptr = memory.data(sizeof<i32>()); | ||
store<i32>(ptr, newTimezone); | ||
w4.diskw(ptr, sizeof<i32>()); | ||
timezone = newTimezone; | ||
} | ||
|
||
export function update(): void { | ||
// Increase the seconds. | ||
time += 1 / 60; // 60 frames per second | ||
|
||
// Clear the screen. | ||
store<u16>(w4.DRAW_COLORS, 0x2); | ||
w4.rect(0, 0, w4.SCREEN_SIZE, w4.SCREEN_SIZE); | ||
|
||
// Interpret the time into a valid Date. | ||
const date = new Date((time as i64) * 1000); // Date() expects milliseconds | ||
date.setTimezoneOffset(timezone * 60); | ||
|
||
// Draw the clock. | ||
let center:i32 = w4.SCREEN_SIZE / 2; | ||
let clockRadius = w4.SCREEN_SIZE / 2 * 0.95; | ||
store<u16>(w4.DRAW_COLORS, 0x12); | ||
w4.oval(center - clockRadius as u32, center - clockRadius as u32, clockRadius * 2 as u32, clockRadius * 2 as u32); | ||
|
||
// Draw the numbers on the clock. | ||
store<u16>(w4.DRAW_COLORS, 0x1); | ||
let textRadius = clockRadius * 0.85 | ||
for (let i = 0; i < 12; i++) { | ||
let clockPosition = i * 5; | ||
let text = i == 0 ? "12" : i.toString() | ||
let textWidth = text.length * 8; | ||
let textHeight = 8; | ||
w4.text(text, center + textRadius * Math.sin(clockPosition * (2 * Math.PI / 60)) - textWidth / 2 as i32 , center - textRadius * Math.cos(clockPosition * (2 * Math.PI / 60)) - textHeight / 2 as i32); | ||
} | ||
|
||
// Draw the hands. | ||
let sradius = clockRadius * 0.8; | ||
let mradius = clockRadius * 0.9; | ||
let hradius = clockRadius * 0.6; | ||
store<u16>(w4.DRAW_COLORS, 0x3); | ||
w4.line(center, center, center + sradius * Math.sin(date.getSeconds() * (2 * Math.PI / 60)) as i32, center - sradius * Math.cos(date.getSeconds() * (2 * Math.PI / 60)) as i32) | ||
store<u16>(w4.DRAW_COLORS, 0x1); | ||
w4.line(center, center, center + mradius * Math.sin(date.getMinutes() * (2 * Math.PI / 60)) as i32, center - mradius * Math.cos(date.getMinutes() * (2 * Math.PI / 60)) as i32); | ||
store<u16>(w4.DRAW_COLORS, 0x1); | ||
let h = date.getHours() % 12 + date.getMinutes() / 60.0; | ||
w4.line(center, center, center + hradius * Math.sin(h * (2 * Math.PI / 60)) as i32, center - hradius * Math.cos(h * (2 * Math.PI / 60)) as i32); | ||
|
||
// Allow changing the timezone. | ||
const gamepad = load<u8>(w4.GAMEPAD1); | ||
const pressedThisFrame = gamepad & (gamepad ^ previousGamepad); | ||
previousGamepad = gamepad; | ||
if (pressedThisFrame & w4.BUTTON_LEFT) { | ||
setTimezone(timezone - 1); | ||
} | ||
if (pressedThisFrame & w4.BUTTON_RIGHT) { | ||
setTimezone(timezone + 1); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.