slifer 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +2 -1
- package/index.ts +2 -1
- package/package.json +1 -1
- package/src/download.ts +39 -18
- package/src/engine/canvas.ts +90 -0
- package/src/engine/image.ts +33 -22
- package/src/engine/render.ts +13 -3
- package/src/engine/window.ts +15 -8
- package/src/ffi.ts +32 -4
- package/src/modules/graphics.ts +51 -78
- package/src/slifer.test.ts +2 -2
- package/src/slifer.ts +9 -4
package/.npmignore
CHANGED
package/index.ts
CHANGED
@@ -5,6 +5,7 @@ import Color from "./src/engine/color";
|
|
5
5
|
import Audio from "./src/engine/audio";
|
6
6
|
import Rectangle from "./src/engine/rectangle";
|
7
7
|
import Font from "./src/engine/font";
|
8
|
+
import Canvas from './src/engine/canvas';
|
8
9
|
|
9
10
|
const slf = new Slifer();
|
10
|
-
export { Vector2, Color, Image, Audio, Rectangle, Font, slf as Slifer };
|
11
|
+
export { Vector2, Color, Image, Audio, Rectangle, Font, Canvas, slf as Slifer };
|
package/package.json
CHANGED
package/src/download.ts
CHANGED
@@ -1,27 +1,48 @@
|
|
1
1
|
import * as path from 'path';
|
2
|
+
import { parseArgs } from 'util';
|
2
3
|
|
3
4
|
const libDir = path.join(__dirname, '../libs/');
|
4
5
|
|
5
6
|
async function downloadLibrary(url: string, filename: string) {
|
6
7
|
const response = await fetch(url);
|
7
8
|
await Bun.write(libDir + filename, response);
|
8
|
-
|
9
|
-
|
10
9
|
}
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
11
|
+
function downloadFiles(check: string) {
|
12
|
+
if (check == "darwin") {
|
13
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2.dylib", "libSDL2.dylib");
|
14
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_image.dylib", "libSDL2_image.dylib");
|
15
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_mixer.dylib", "libSDL2_mixer.dylib");
|
16
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_ttf.dylib", "libSDL2_ttf.dylib");
|
17
|
+
} else if (check == "win32") {
|
18
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2.dll", "SDL2.dll");
|
19
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_image.dll", "SDL2_image.dll");
|
20
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_mixer.dll", "SDL2_mixer.dll");
|
21
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/SDL2_ttf.dll", "SDL2_ttf.dll");
|
22
|
+
} else if (check == "linux") {
|
23
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2.so", "libSDL2.so");
|
24
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_image.so", "libSDL2_image.so");
|
25
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_mixer.so", "libSDL2_mixer.so");
|
26
|
+
downloadLibrary("https://github.com/HazyVT/Slifer/releases/download/Libraries/libSDL2_ttf.so", "libSDL2_ttf.so");
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
const { values } = parseArgs({
|
31
|
+
args: Bun.argv,
|
32
|
+
options: {
|
33
|
+
mode: {
|
34
|
+
type: 'string'
|
35
|
+
}
|
36
|
+
},
|
37
|
+
strict: true,
|
38
|
+
allowPositionals: true
|
39
|
+
})
|
40
|
+
|
41
|
+
if (values.mode == undefined) {
|
42
|
+
downloadFiles(process.platform);
|
43
|
+
} else {
|
44
|
+
downloadFiles(values.mode);
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { type Pointer, ptr } from 'bun:ffi';
|
2
|
+
import { libsdl, libttf } from '../ffi';
|
3
|
+
import Image from './image';
|
4
|
+
import Render from './render';
|
5
|
+
import Color from './color';
|
6
|
+
import Font from './font';
|
7
|
+
|
8
|
+
/** @internal */
|
9
|
+
export default class Canvas {
|
10
|
+
|
11
|
+
private pointer : Pointer;
|
12
|
+
private destArray: Uint32Array;
|
13
|
+
|
14
|
+
public readonly width;
|
15
|
+
public readonly height;
|
16
|
+
|
17
|
+
constructor(width: number, height: number) {
|
18
|
+
const surPointer = libsdl.symbols.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
|
19
|
+
if (surPointer == null) throw `Canvas creation failed`;
|
20
|
+
this.pointer = surPointer;
|
21
|
+
this.width = width;
|
22
|
+
this.height = height;
|
23
|
+
this.destArray = new Uint32Array(4);
|
24
|
+
this.destArray[2] = this.width;
|
25
|
+
this.destArray[3] = this.height;
|
26
|
+
}
|
27
|
+
|
28
|
+
private drawBG(color: Color) {
|
29
|
+
const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
|
30
|
+
|
31
|
+
libsdl.symbols.SDL_FillRect(this.pointer, ptr(this.destArray), _col);
|
32
|
+
}
|
33
|
+
|
34
|
+
clear() {
|
35
|
+
this.drawBG(new Color(0, 0, 0, 0));
|
36
|
+
}
|
37
|
+
|
38
|
+
setBackground(color: Color) {
|
39
|
+
this.drawBG(color);
|
40
|
+
}
|
41
|
+
|
42
|
+
draw(drawable: Image | Canvas, x: number, y: number) : void {
|
43
|
+
(drawable as any).destArray[0] = x;
|
44
|
+
(drawable as any).destArray[1] = y;
|
45
|
+
|
46
|
+
libsdl.symbols.SDL_UpperBlitScaled(
|
47
|
+
(drawable as any).pointer,
|
48
|
+
null,
|
49
|
+
this.pointer,
|
50
|
+
ptr((drawable as any).destArray)
|
51
|
+
);
|
52
|
+
}
|
53
|
+
|
54
|
+
public print(text: string, x: number, y: number, font: Font, color: Color) {
|
55
|
+
const wArr = new Uint32Array(1);
|
56
|
+
const hArr = new Uint32Array(1);
|
57
|
+
|
58
|
+
libttf.symbols.TTF_SizeText(
|
59
|
+
(font as any).pointer,
|
60
|
+
Buffer.from(text+"\x00"),
|
61
|
+
ptr(wArr),
|
62
|
+
ptr(hArr)
|
63
|
+
);
|
64
|
+
|
65
|
+
const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
|
66
|
+
|
67
|
+
const surface = libttf.symbols.TTF_RenderText_Solid(
|
68
|
+
(font as any).pointer,
|
69
|
+
Buffer.from(text+'\x00'),
|
70
|
+
_col
|
71
|
+
);
|
72
|
+
if (surface == null) throw `Rendering text failed`;
|
73
|
+
|
74
|
+
const destRect = new Uint32Array(4);
|
75
|
+
destRect[0] = x;
|
76
|
+
destRect[1] = y;
|
77
|
+
destRect[2] = wArr[0];
|
78
|
+
destRect[3] = hArr[0];
|
79
|
+
|
80
|
+
libsdl.symbols.SDL_UpperBlitScaled(
|
81
|
+
surface,
|
82
|
+
null,
|
83
|
+
this.pointer,
|
84
|
+
ptr(destRect)
|
85
|
+
);
|
86
|
+
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
}
|
package/src/engine/image.ts
CHANGED
@@ -1,34 +1,45 @@
|
|
1
1
|
import { libimage, libsdl } from "../ffi";
|
2
|
-
import { type Pointer, ptr } from 'bun:ffi';
|
2
|
+
import { type Pointer, ptr, toArrayBuffer } from 'bun:ffi';
|
3
3
|
import Render from "./render";
|
4
4
|
|
5
5
|
/** @internal */
|
6
6
|
export default class Image {
|
7
7
|
|
8
8
|
private pointer: Pointer;
|
9
|
-
private
|
9
|
+
private destArray: Uint32Array;
|
10
10
|
|
11
|
-
public readonly width;
|
12
|
-
public readonly height;
|
11
|
+
public readonly width: number;
|
12
|
+
public readonly height: number;
|
13
13
|
|
14
14
|
constructor(path: string) {
|
15
15
|
const cs = Buffer.from(path+'\x00');
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
16
|
+
const surface = libimage.symbols.IMG_Load(cs);
|
17
|
+
if (surface == null) throw `Loading ${path} failed`;
|
18
|
+
this.pointer = surface;
|
19
|
+
|
20
|
+
|
21
|
+
// Convert to texture
|
22
|
+
const texture = libsdl.symbols.SDL_CreateTextureFromSurface(
|
23
|
+
Render.pointer,
|
24
|
+
this.pointer
|
25
|
+
)
|
26
|
+
if (texture == null) throw `Loading ${path} failed`;
|
27
|
+
|
28
|
+
const wArr = new Uint32Array(1);
|
29
|
+
const hArr = new Uint32Array(1);
|
30
|
+
libsdl.symbols.SDL_QueryTexture(
|
31
|
+
texture,
|
32
|
+
null,
|
33
|
+
null,
|
34
|
+
ptr(wArr),
|
35
|
+
ptr(hArr)
|
36
|
+
)
|
37
|
+
|
38
|
+
this.width = wArr[0];
|
39
|
+
this.height = hArr[0];
|
40
|
+
|
41
|
+
this.destArray = new Uint32Array(4);
|
42
|
+
this.destArray[2] = this.width;
|
43
|
+
this.destArray[3] = this.height;
|
33
44
|
}
|
34
|
-
}
|
45
|
+
}
|
package/src/engine/render.ts
CHANGED
@@ -6,10 +6,20 @@ import Window from "./window";
|
|
6
6
|
export default class Render {
|
7
7
|
|
8
8
|
public static pointer : Pointer;
|
9
|
+
public static surface: Pointer;
|
10
|
+
public static destArray : Uint32Array;
|
9
11
|
|
10
|
-
public static createRenderer() {
|
11
|
-
const renPointer = libsdl.symbols.SDL_CreateRenderer(Window.pointer, -1,
|
12
|
+
public static createRenderer(width: number, height: number) {
|
13
|
+
const renPointer = libsdl.symbols.SDL_CreateRenderer(Window.pointer, -1, 0x00000004 + 0x00000002);
|
12
14
|
if (renPointer == null) throw `Renderer creation failed.`;
|
13
15
|
this.pointer = renPointer;
|
16
|
+
const surPointer = libsdl.symbols.SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0)
|
17
|
+
if (surPointer == null) throw `Surface creation failed`;
|
18
|
+
this.surface = surPointer;
|
19
|
+
this.destArray = new Uint32Array(4);
|
20
|
+
this.destArray[0] = 0;
|
21
|
+
this.destArray[1] = 0;
|
22
|
+
this.destArray[2] = width;
|
23
|
+
this.destArray[3] = height;
|
14
24
|
}
|
15
|
-
}
|
25
|
+
}
|
package/src/engine/window.ts
CHANGED
@@ -4,29 +4,32 @@ import { libsdl } from '../ffi';
|
|
4
4
|
|
5
5
|
/** @internal */
|
6
6
|
export default class Window {
|
7
|
-
public static pointer: Pointer;
|
8
7
|
|
8
|
+
public static pointer: Pointer;
|
9
|
+
public static size: Vector2;
|
10
|
+
|
9
11
|
private static centerPos = 0x2fff0000;
|
10
12
|
|
11
|
-
|
13
|
+
|
14
|
+
|
15
|
+
public static createWindow(title: string, width: number, height: number) : void {
|
12
16
|
const winPointer = libsdl.symbols.SDL_CreateWindow(
|
13
|
-
//@ts-expect-error Buffer error
|
14
17
|
Buffer.from(title + '\x00'),
|
15
18
|
this.centerPos,
|
16
19
|
this.centerPos,
|
17
|
-
|
18
|
-
|
20
|
+
width,
|
21
|
+
height,
|
19
22
|
0
|
20
|
-
)
|
23
|
+
);
|
21
24
|
|
22
25
|
if (winPointer == null) throw `Window creation failed.`;
|
23
26
|
this.pointer = winPointer;
|
27
|
+
this.size = new Vector2(width, height);
|
24
28
|
}
|
25
29
|
|
26
30
|
public setTitle(title: string): void {
|
27
31
|
libsdl.symbols.SDL_SetWindowTitle(
|
28
32
|
Window.pointer,
|
29
|
-
//@ts-expect-error Buffer error
|
30
33
|
Buffer.from(title + "\x00")
|
31
34
|
);
|
32
35
|
}
|
@@ -46,4 +49,8 @@ export default class Window {
|
|
46
49
|
public centerWindow() {
|
47
50
|
this.setPosition(new Vector2(Window.centerPos, Window.centerPos));
|
48
51
|
}
|
49
|
-
|
52
|
+
|
53
|
+
public setSize(width: number, height: number) {
|
54
|
+
libsdl.symbols.SDL_SetWindowSize(Window.pointer, width, height);
|
55
|
+
}
|
56
|
+
}
|
package/src/ffi.ts
CHANGED
@@ -27,10 +27,14 @@ if (process.platform == "win32") {
|
|
27
27
|
//@ts-expect-error
|
28
28
|
libMixerImport = await import("../libs/libSDL2_mixer.dylib");
|
29
29
|
} else if (process.platform == "linux") {
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
//@ts-expect-error
|
31
|
+
libSDLImport = await import("../libs/libSDL2.so");
|
32
|
+
//@ts-expect-error
|
33
|
+
libImageImport = await import("../libs/libSDL2_image.so");
|
34
|
+
//@ts-expect-error
|
35
|
+
libTTFImport = await import("../libs/libSDL2_ttf.so");
|
36
|
+
//@ts-expect-error
|
37
|
+
libMixerImport = await import("../libs/libSDL2_mixer.so");
|
34
38
|
}
|
35
39
|
|
36
40
|
/** @internal */
|
@@ -222,6 +226,30 @@ export const libsdl = dlopen(libSDLImport.default, {
|
|
222
226
|
},
|
223
227
|
SDL_GetTicks64: {
|
224
228
|
returns: 'u64'
|
229
|
+
},
|
230
|
+
SDL_CreateRGBSurface: {
|
231
|
+
args: ['int', 'int', 'int', 'int', 'int', 'int', 'int', 'int'],
|
232
|
+
returns: 'pointer'
|
233
|
+
},
|
234
|
+
SDL_UpperBlitScaled: {
|
235
|
+
args: ['pointer', 'pointer','pointer','pointer'],
|
236
|
+
returns: 'int'
|
237
|
+
},
|
238
|
+
SDL_FillRect: {
|
239
|
+
args: ['pointer', 'pointer', 'int'],
|
240
|
+
returns: 'int'
|
241
|
+
},
|
242
|
+
SDL_DestroyTexture : {
|
243
|
+
args: ['pointer'],
|
244
|
+
returns: 'void'
|
245
|
+
},
|
246
|
+
SDL_MapRGB: {
|
247
|
+
args: ['pointer', 'int', 'int', 'int'],
|
248
|
+
returns: 'u32'
|
249
|
+
},
|
250
|
+
SDL_FreeSurface: {
|
251
|
+
args: ['pointer'],
|
252
|
+
returns: 'void'
|
225
253
|
}
|
226
254
|
});
|
227
255
|
|
package/src/modules/graphics.ts
CHANGED
@@ -4,118 +4,91 @@ import { ptr } from 'bun:ffi';
|
|
4
4
|
import Font from '../engine/font';
|
5
5
|
import type Image from "../engine/image";
|
6
6
|
import Render from "../engine/render";
|
7
|
+
import Window from '../engine/window';
|
7
8
|
import type Color from "../engine/color";
|
8
|
-
import
|
9
|
+
import Rectangle from "../engine/rectangle";
|
10
|
+
import Canvas from '../engine/canvas';
|
9
11
|
|
10
12
|
/** @internal */
|
11
13
|
export default class Graphics {
|
12
14
|
|
13
15
|
public render() : void {
|
16
|
+
const texture = libsdl.symbols.SDL_CreateTextureFromSurface(Render.pointer, Render.surface);
|
17
|
+
if (texture == null) throw `Render texture creation failed`;
|
18
|
+
libsdl.symbols.SDL_RenderCopy(
|
19
|
+
Render.pointer,
|
20
|
+
texture,
|
21
|
+
null,
|
22
|
+
null
|
23
|
+
);
|
14
24
|
libsdl.symbols.SDL_RenderPresent(Render.pointer);
|
25
|
+
libsdl.symbols.SDL_DestroyTexture(texture);
|
15
26
|
}
|
16
27
|
|
17
|
-
public draw(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
}
|
29
|
-
|
30
|
-
public drawEx(image: Image, x: number, y: number, rotation?: number, scaleX?: number, scaleY?: number, flipH?: boolean) {
|
31
|
-
|
32
|
-
const destArr = (image as any).destArr;
|
33
|
-
destArr[0] = x;
|
34
|
-
destArr[1] = y;
|
35
|
-
destArr[2] = image.width * (scaleX ? scaleX : 1)
|
36
|
-
destArr[3] = image.height * (scaleY ? scaleY : 1);
|
37
|
-
|
38
|
-
libsdl.symbols.SDL_RenderCopyEx(
|
39
|
-
Render.pointer,
|
40
|
-
(image as any).pointer,
|
41
|
-
null,
|
42
|
-
ptr(destArr),
|
43
|
-
rotation ? rotation : 0,
|
44
|
-
null,
|
45
|
-
Number(flipH)
|
28
|
+
public draw(drawable: Image | Canvas, x: number, y: number) : void {
|
29
|
+
|
30
|
+
(drawable as any).destArray[0] = x;
|
31
|
+
(drawable as any).destArray[1] = y;
|
32
|
+
|
33
|
+
|
34
|
+
libsdl.symbols.SDL_UpperBlitScaled(
|
35
|
+
(drawable as any).pointer,
|
36
|
+
null,
|
37
|
+
Render.surface,
|
38
|
+
ptr((drawable as any).destArray)
|
46
39
|
);
|
47
|
-
|
48
|
-
|
49
40
|
}
|
50
41
|
|
51
42
|
public setBackground(color: Color) : void {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
color.a
|
57
|
-
);
|
58
|
-
libsdl.symbols.SDL_RenderClear(Render.pointer);
|
59
|
-
}
|
43
|
+
const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
|
44
|
+
libsdl.symbols.SDL_FillRect(Render.surface, ptr(Render.destArray), _col);
|
45
|
+
|
46
|
+
}
|
60
47
|
|
61
48
|
public drawRect(rectangle: Rectangle, color: Color) {
|
62
|
-
|
63
|
-
Render.pointer,
|
64
|
-
color.r,
|
65
|
-
color.g,
|
66
|
-
color.b,
|
67
|
-
color.a
|
68
|
-
);
|
49
|
+
const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
|
69
50
|
|
70
51
|
const rect = new Uint32Array(4);
|
71
52
|
rect[0] = rectangle.position.x;
|
72
|
-
|
53
|
+
rect[1] = rectangle.position.y;
|
73
54
|
rect[2] = rectangle.size.x;
|
74
55
|
rect[3] = rectangle.size.y;
|
75
56
|
|
76
|
-
libsdl.symbols.
|
57
|
+
libsdl.symbols.SDL_FillRect(Render.surface, ptr(rect), _col);
|
77
58
|
}
|
78
|
-
|
59
|
+
|
79
60
|
public print(text: string, x: number, y: number, font: Font, color: Color) {
|
80
61
|
const wArr = new Uint32Array(1);
|
81
62
|
const hArr = new Uint32Array(1);
|
82
|
-
|
63
|
+
|
83
64
|
libttf.symbols.TTF_SizeText(
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
65
|
+
(font as any).pointer,
|
66
|
+
Buffer.from(text+"\x00"),
|
67
|
+
ptr(wArr),
|
68
|
+
ptr(hArr)
|
88
69
|
);
|
89
70
|
|
90
|
-
const _col = ((color.r <<
|
71
|
+
const _col = ((color.r << 16) + (color.g << 8) + (color.b << 0));
|
91
72
|
|
92
73
|
const surface = libttf.symbols.TTF_RenderText_Solid(
|
93
74
|
(font as any).pointer,
|
94
|
-
|
95
|
-
|
75
|
+
Buffer.from(text+'\x00'),
|
76
|
+
_col
|
96
77
|
);
|
97
78
|
if (surface == null) throw `Rendering text failed`;
|
98
79
|
|
99
|
-
const
|
100
|
-
|
101
|
-
|
80
|
+
const destRect = new Uint32Array(4);
|
81
|
+
destRect[0] = x;
|
82
|
+
destRect[1] = y;
|
83
|
+
destRect[2] = wArr[0];
|
84
|
+
destRect[3] = hArr[0];
|
85
|
+
|
86
|
+
libsdl.symbols.SDL_UpperBlitScaled(
|
87
|
+
surface,
|
88
|
+
null,
|
89
|
+
Render.surface,
|
90
|
+
ptr(destRect)
|
102
91
|
);
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
const destRect = new Uint32Array(4);
|
107
|
-
destRect[0] = x;
|
108
|
-
destRect[1] = y;
|
109
|
-
destRect[2] = wArr[0];
|
110
|
-
destRect[3] = hArr[0];
|
111
|
-
libsdl.symbols.SDL_RenderCopy(
|
112
|
-
Render.pointer,
|
113
|
-
texture,
|
114
|
-
null,
|
115
|
-
ptr(destRect)
|
116
|
-
);
|
117
|
-
|
118
|
-
|
119
|
-
|
92
|
+
|
120
93
|
}
|
121
94
|
}
|
package/src/slifer.test.ts
CHANGED
@@ -31,13 +31,13 @@ describe("Initializing SDL Mixer ", () => {
|
|
31
31
|
describe("Window Creation ", () => {
|
32
32
|
it("Should create window without error", () => {
|
33
33
|
expect(() =>
|
34
|
-
Window.createWindow("Game",
|
34
|
+
Window.createWindow("Game", 1, 1)
|
35
35
|
).not.toThrow(Error);
|
36
36
|
});
|
37
37
|
});
|
38
38
|
|
39
39
|
describe("Renderer Creation ", () => {
|
40
40
|
it("Should create renderer without error", () => {
|
41
|
-
expect(() => Render.createRenderer()).not.toThrow(Error);
|
41
|
+
expect(() => Render.createRenderer(1, 1)).not.toThrow(Error);
|
42
42
|
});
|
43
43
|
});
|
package/src/slifer.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { libsdl } from "./ffi";
|
2
2
|
import Window from "./engine/window";
|
3
|
-
import Renderer from "./engine/render";
|
4
3
|
import { ptr } from "bun:ffi";
|
5
4
|
import { initLibraries } from "./engine";
|
6
5
|
import { version } from "../package.json";
|
@@ -9,6 +8,7 @@ import Graphics from "./modules/graphics";
|
|
9
8
|
import Keyboard from "./modules/keyboard";
|
10
9
|
import Mouse from "./modules/mouse";
|
11
10
|
import Render from "./engine/render";
|
11
|
+
import Color from './engine/color';
|
12
12
|
|
13
13
|
class Slifer {
|
14
14
|
public isRunning: boolean;
|
@@ -21,16 +21,18 @@ class Slifer {
|
|
21
21
|
|
22
22
|
private start = 0;
|
23
23
|
private end = 0;
|
24
|
+
private black : Color;
|
24
25
|
|
25
26
|
constructor() {
|
26
27
|
initLibraries();
|
27
28
|
this.isRunning = true;
|
28
29
|
this.deltaTime = 0;
|
30
|
+
this.black = new Color(0,0,0,0);
|
29
31
|
}
|
30
32
|
|
31
|
-
public createWindow(title: string,
|
32
|
-
Window.createWindow(title,
|
33
|
-
|
33
|
+
public createWindow(title: string, width: number, height: number): Window {
|
34
|
+
Window.createWindow(title, width, height);
|
35
|
+
Render.createRenderer(width, height);
|
34
36
|
|
35
37
|
this.start = Number(libsdl.symbols.SDL_GetTicks64());
|
36
38
|
|
@@ -40,6 +42,8 @@ class Slifer {
|
|
40
42
|
public shouldClose(): boolean {
|
41
43
|
libsdl.symbols.SDL_RenderClear(Render.pointer);
|
42
44
|
|
45
|
+
this.Graphics.setBackground(this.black);
|
46
|
+
|
43
47
|
const eventArray = new Uint16Array(32);
|
44
48
|
const event = libsdl.symbols.SDL_PollEvent(ptr(eventArray));
|
45
49
|
if (event) {
|
@@ -76,6 +80,7 @@ class Slifer {
|
|
76
80
|
}
|
77
81
|
|
78
82
|
public quit(): void {
|
83
|
+
libsdl.symbols.SDL_FreeSurface(Render.surface);
|
79
84
|
libsdl.symbols.SDL_DestroyRenderer(Render.pointer);
|
80
85
|
libsdl.symbols.SDL_DestroyWindow(Window.pointer);
|
81
86
|
libsdl.symbols.SDL_Quit();
|