Skip to content

Commit

Permalink
More checkForError = true and remove a Box usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
smack0007 committed Sep 10, 2024
1 parent 6f58e7b commit b541c54
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 89 deletions.
12 changes: 9 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
"deno.lint": true,
"deno.unstable": true,

"editor.defaultFormatter": "denoland.vscode-deno",

"editor.tabSize": 2,

"[josn,typescript]": {
// Ensure deno is the formatter for all file types.
"editor.defaultFormatter": "denoland.vscode-deno",
"[josn]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[markdown]": {
"editor.defaultFormatter": "denoland.vscode-deno"
},
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
55 changes: 42 additions & 13 deletions examples/doom-fire/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,42 @@ const FIRE_WIDTH = 1024;
const FIRE_HEIGHT = 120;

const FIRE_COLORS = [
0x00000000, 0xc0070707, 0xc007071f, 0xc0070f2f, 0xc0070f47, 0xc0071757,
0xc0071f67, 0xc0071f77, 0xc007278f, 0xc0072f9f, 0xc0073faf, 0xc00747bf,
0xc00747c7, 0xc0074fdf, 0xc00757df, 0xc00757df, 0xc0075fd7, 0xc00f67d7,
0xc00f6fcf, 0xc00f77cf, 0xc00f7fcf, 0xc01787cf, 0xc01787c7, 0xc0178fc7,
0xc01f97c7, 0xc01f9fbf, 0xc01f9fbf, 0xc027a7bf, 0xc027a7bf, 0xc02fafbf,
0xc02fafb7, 0xc02fb7b7, 0xc037b7b7, 0xc06fcfcf, 0xc09fdfdf, 0xc0c7efef,
0x00000000,
0xc0070707,
0xc007071f,
0xc0070f2f,
0xc0070f47,
0xc0071757,
0xc0071f67,
0xc0071f77,
0xc007278f,
0xc0072f9f,
0xc0073faf,
0xc00747bf,
0xc00747c7,
0xc0074fdf,
0xc00757df,
0xc00757df,
0xc0075fd7,
0xc00f67d7,
0xc00f6fcf,
0xc00f77cf,
0xc00f7fcf,
0xc01787cf,
0xc01787c7,
0xc0178fc7,
0xc01f97c7,
0xc01f9fbf,
0xc01f9fbf,
0xc027a7bf,
0xc027a7bf,
0xc02fafbf,
0xc02fafb7,
0xc02fb7b7,
0xc037b7b7,
0xc06fcfcf,
0xc09fdfdf,
0xc0c7efef,
0xc0ffffff,
];

Expand All @@ -30,19 +60,19 @@ function main(): void {
SDL.WindowPos.CENTERED,
WINDOW_WIDTH,
WINDOW_HEIGHT,
SDL.WindowFlags.SHOWN
SDL.WindowFlags.SHOWN,
);

const frontBuffer = SDL.GetWindowSurface(window);

const denoSurfaceUnoptimized = IMG.Load(
join(ASSETS_PATH, "jurassicDeno.png")
join(ASSETS_PATH, "jurassicDeno.png"),
);

const denoSurface = SDL.ConvertSurface(
denoSurfaceUnoptimized,
frontBuffer.format,
0
0,
);

SDL.FreeSurface(denoSurfaceUnoptimized);
Expand All @@ -57,21 +87,20 @@ function main(): void {
0x000000ff,
0x0000ff00,
0x00ff0000,
0xff000000
0xff000000,
);

const flamesRect = new SDL.Rect(
0,
HALF_WINDOW_HEIGHT,
frontBuffer.w,
HALF_WINDOW_HEIGHT
HALF_WINDOW_HEIGHT,
);

firePixels.fill(0x00000000);

for (let x = 0; x < FIRE_WIDTH; x += 1) {
firePixels[(FIRE_HEIGHT - 1) * FIRE_WIDTH + x] =
FIRE_COLORS[FIRE_COLORS.length - 1];
firePixels[(FIRE_HEIGHT - 1) * FIRE_WIDTH + x] = FIRE_COLORS[FIRE_COLORS.length - 1];
}

let lastFrame = SDL.GetTicks64();
Expand Down
22 changes: 10 additions & 12 deletions examples/renderer/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function main(): void {
const [window, renderer] = SDL.CreateWindowAndRenderer(
WINDOW_WIDTH,
WINDOW_HEIGHT,
SDL.WindowFlags.SHOWN | SDL.WindowFlags.RESIZABLE
SDL.WindowFlags.SHOWN | SDL.WindowFlags.RESIZABLE,
);

SDL.RenderSetLogicalSize(renderer, WINDOW_WIDTH, WINDOW_HEIGHT);
Expand All @@ -23,7 +23,7 @@ function main(): void {
console.info(rendererInfo.max_texture_height);
console.info(
(rendererInfo.flags & SDL.RendererFlags.ACCELERATED) ===
SDL.RendererFlags.ACCELERATED
SDL.RendererFlags.ACCELERATED,
);

SDL.SetRenderDrawColor(renderer, 0, 0, 0, 255);
Expand All @@ -40,15 +40,13 @@ function main(): void {
const texture = SDL.CreateTextureFromSurface(renderer, denoSurface);
SDL.FreeSurface(denoSurface);

const points = new BoxArray<SDL.Point>(SDL.Point, 4);
points.at(0).x = 0;
points.at(0).y = 0;
points.at(1).x = 1;
points.at(1).y = 0;
points.at(2).x = 1;
points.at(2).y = 1;
points.at(3).x = 0;
points.at(3).y = 1;
// deno-fmt-ignore
const points = new Uint32Array([
0, 0,
1, 0,
1, 1,
0, 1
]);

const event = new SDL.Event();
let done = false;
Expand Down Expand Up @@ -81,7 +79,7 @@ function main(): void {
destRect,
textureRotation,
textureCenter,
SDL.RendererFlip.NONE
SDL.RendererFlip.NONE,
);

SDL.SetRenderDrawColor(renderer, 255, 0, 0, 255);
Expand Down
Loading

0 comments on commit b541c54

Please sign in to comment.