Fixed web bug and added vsync support.

This commit is contained in:
Kapendev 2024-08-14 17:21:57 +03:00
parent bd2530b615
commit f3784c11c1
11 changed files with 41 additions and 19 deletions

View file

@ -79,6 +79,8 @@ If you encounter errors with BetterC, try using the `-i` flag.
To export a game to the web, the game must be compatible with BetterC.
The [web](web) folder contains a helper script to assist with the web export process.
It can be used with DUB by running the following command:
```bash
dub run popka:web
```
@ -90,19 +92,15 @@ Popka provides bindings for raylib that are compatible with BetterC and the web.
```d
import popka.ray;
int main() {
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
SetTargetFPS(60);
void main() {
InitWindow(800, 450, "raylib");
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
DrawText("Hello world from raylib!", 16, 16, 20, GRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
```

View file

@ -10,7 +10,7 @@ enum header = "// ---
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---";
int main(string[] args) {

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/// The `dialogue` module provides a simple and versatile dialogue system.

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/// The `engine` module functions as a lightweight 2D game engine.
@ -146,6 +146,7 @@ void openWindow(int width, int height, IStr title = "Popka") {
ray.InitAudioDevice();
ray.SetExitKey(ray.KEY_NULL);
lockFps(60);
engineState.flags.isVsync = true;
engineState.backgroundColor = gray2;
engineState.fullscreenState.lastWindowSize = Vec2(width, height);
}
@ -346,6 +347,14 @@ void showCursor() {
ray.ShowCursor();
}
void toggleCursor() {
if (isCursorHidden) {
showCursor();
} else {
hideCursor();
}
}
/// Returns true if the window is in fullscreen mode.
@trusted
bool isFullscreen() {
@ -378,6 +387,16 @@ void togglePixelPerfect() {
engineState.flags.isPixelPerfect = !engineState.flags.isPixelPerfect;
}
bool isVsync() {
return engineState.flags.isVsync;
}
@trusted
void toggleVsync() {
engineState.flags.isVsync = !engineState.flags.isVsync;
ray.glfwSwapInterval(engineState.flags.isVsync ? 1 : 0);
}
@trusted
int screenWidth() {
return ray.GetMonitorWidth(ray.GetCurrentMonitor());

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
module popka;

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/// The `ray` module provides access to the raylib library.
@ -12,9 +12,13 @@ module popka.ray;
public import popka.ray.raylib;
public import popka.ray.rlgl;
@nogc nothrow extern(C):
void glfwSwapInterval(int interval);
version (WebAssembly) {
@nogc nothrow extern(C)
@nogc nothrow extern(C):
void emscripten_set_main_loop(void* ptr, int fps, int loop);
@nogc nothrow extern(C)
void emscripten_cancel_main_loop();
}

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/**********************************************************************************************

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/**********************************************************************************************

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/// The `tilemap` module provides a simple and fast tile map.

View file

@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
// Email: alexandroskapretsos@gmail.com
// Project: https://github.com/Kapendev/popka
// Version: v0.0.15
// Version: v0.0.16
// ---
/// The `types` module defines all the types used within the `engine` module.
@ -142,6 +142,7 @@ enum Gamepad {
struct EngineFlags {
bool isUpdating;
bool isPixelPerfect;
bool isVsync;
bool isFpsLocked;
bool isCursorHidden;
}

View file

@ -196,7 +196,7 @@ int main(string[] args) {
if (run(command.format(extraFlags, dflags, popkaParentDir, sourceDir, firstFiles))) return 1;
}
} else {
enum command = "dub build --compiler ldc --config %s --build release";
enum command = "dub build --compiler ldc2 --config %s --build release";
if (run(command.format(dubWebConfig))) return 1;
}