mirror of
https://github.com/Kapendev/parin.git
synced 2025-04-27 13:39:54 +03:00
Some docs and some setup fixes.
This commit is contained in:
parent
3b5e1b24e6
commit
0c96ee0bec
4 changed files with 60 additions and 24 deletions
41
TOUR.md
41
TOUR.md
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## Understanding the Code
|
## Understanding the Code
|
||||||
|
|
||||||
To begin, open the main file of your project and copy-paste the following code:
|
To begin, open the main project file and copy-paste the following code:
|
||||||
|
|
||||||
```d
|
```d
|
||||||
import popka;
|
import popka;
|
||||||
|
@ -45,7 +45,7 @@ Here is a breakdown of how this code works:
|
||||||
```
|
```
|
||||||
|
|
||||||
This function is the main loop of the game.
|
This function is the main loop of the game.
|
||||||
It is called every frame while the game is running and, in this example, draws the message "Hello world!" at position `Vec2(8.0)`.
|
It is called every frame while the game is running and, in this example, draws the message "Hello world!" at position `Vec2(8)`.
|
||||||
The `return false` statement indicates that the game should continue running.
|
The `return false` statement indicates that the game should continue running.
|
||||||
If `true` were returned, the game would stop running.
|
If `true` were returned, the game would stop running.
|
||||||
|
|
||||||
|
@ -84,14 +84,18 @@ void drawCirc(Circ area, Color color = white);
|
||||||
void drawLine(Line area, float size, Color color = white);
|
void drawLine(Line area, float size, Color color = white);
|
||||||
|
|
||||||
void drawTexture(Texture texture, Vec2 position, DrawOptions options = DrawOptions());
|
void drawTexture(Texture texture, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
|
void drawTexture(TextureId texture, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
void drawTextureArea(Texture texture, Rect area, Vec2 position, DrawOptions options = DrawOptions());
|
void drawTextureArea(Texture texture, Rect area, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
|
void drawTextureArea(TextureId texture, Rect area, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
|
|
||||||
void drawRune(Font font, dchar rune, Vec2 position, DrawOptions options = DrawOptions());
|
void drawRune(Font font, dchar rune, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
|
void drawRune(FontId font, dchar rune, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
void drawText(Font font, IStr text, Vec2 position, DrawOptions options = DrawOptions());
|
void drawText(Font font, IStr text, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
|
void drawText(FontId font, IStr text, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
void drawDebugText(IStr text, Vec2 position, DrawOptions options = DrawOptions());
|
void drawDebugText(IStr text, Vec2 position, DrawOptions options = DrawOptions());
|
||||||
```
|
```
|
||||||
|
|
||||||
Additional drawing functions can be found in other modules, such as `popka.tilemap`.
|
Additional drawing functions can be found in other modules, such as `popka.sprite`.
|
||||||
|
|
||||||
## Loading and Saving Resources
|
## Loading and Saving Resources
|
||||||
|
|
||||||
|
@ -99,8 +103,33 @@ Functions that start with the word load/save will always try to read/write resou
|
||||||
These functions handle both forward slashes and backslashes in file paths, ensuring compatibility across operating systems.
|
These functions handle both forward slashes and backslashes in file paths, ensuring compatibility across operating systems.
|
||||||
|
|
||||||
```d
|
```d
|
||||||
loadText("levels/level5.txt"); // Works on Windows, Linux and MacOS.
|
Result!TextId loadText(IStr path, Sz tag = 0);
|
||||||
loadText("levels\\level5.txt"); // Works on Windows, Linux and MacOS.
|
Result!TextureId loadTexture(IStr path, Sz tag = 0);
|
||||||
|
Result!FontId loadFont(IStr path, int size, int runeSpacing, int lineSpacing, const(dchar)[] runes = [], Sz tag = 0);
|
||||||
|
Result!SoundId loadSound(IStr path, float volume, float pitch, Sz tag = 0);
|
||||||
|
|
||||||
|
Result!LStr loadRawText(IStr path);
|
||||||
|
Result!Texture loadRawTexture(IStr path);
|
||||||
|
Result!Font loadRawFont(IStr path, int size, int runeSpacing, int lineSpacing, const(dchar)[] runes = []);
|
||||||
|
Result!Sound loadRawSound(IStr path, float volume, float pitch);
|
||||||
|
|
||||||
|
Result!IStr loadTempText(IStr path);
|
||||||
|
|
||||||
|
Fault saveText(IStr path, IStr text);
|
||||||
```
|
```
|
||||||
|
|
||||||
If text is needed for only a single frame, use the `loadTempText` function.
|
### Managed Resources
|
||||||
|
|
||||||
|
Managed resources are cached by their path and grouped based on the tag they were loaded with.
|
||||||
|
To free these resources, use the `freeResources` function or the `free` method on the resource identifier.
|
||||||
|
The resource identifier is automatically invalidated when the resource is freed.
|
||||||
|
|
||||||
|
### Raw Resources
|
||||||
|
|
||||||
|
Raw resources are managed directly by the user and are not cached or grouped.
|
||||||
|
They must be freed manually when no longer needed.
|
||||||
|
|
||||||
|
### Temporary Resources
|
||||||
|
|
||||||
|
Temporary resources are only valid until the function that provided them is called again.
|
||||||
|
They don’t need to be freed manually.
|
||||||
|
|
|
@ -104,6 +104,12 @@ int main(string[] args) {
|
||||||
auto isDubProject = exists(dubFile);
|
auto isDubProject = exists(dubFile);
|
||||||
auto isFirstRun = !exists(assetsDir);
|
auto isFirstRun = !exists(assetsDir);
|
||||||
|
|
||||||
|
// Sometimes I remove the app.d file and this makes a new one lol.
|
||||||
|
// Also raylib-d:install does not like it when you don't have one.
|
||||||
|
if (isDubProject) {
|
||||||
|
if (!exists(appFile)) std.file.write(appFile, appFileContent);
|
||||||
|
}
|
||||||
|
|
||||||
// Use the raylib-d script to download the raylib library files.
|
// Use the raylib-d script to download the raylib library files.
|
||||||
if (isDubProject) {
|
if (isDubProject) {
|
||||||
writeln("\n Simply say \"yes\" to all prompts. \n");
|
writeln("\n Simply say \"yes\" to all prompts. \n");
|
||||||
|
|
|
@ -701,93 +701,93 @@ struct EngineState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib color to a Popka color.
|
private
|
||||||
Color toPopka(rl.Color from) {
|
Color toPopka(rl.Color from) {
|
||||||
return Color(from.r, from.g, from.b, from.a);
|
return Color(from.r, from.g, from.b, from.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib vector to a Popka vector.
|
private
|
||||||
Vec2 toPopka(rl.Vector2 from) {
|
Vec2 toPopka(rl.Vector2 from) {
|
||||||
return Vec2(from.x, from.y);
|
return Vec2(from.x, from.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib vector to a Popka vector.
|
private
|
||||||
Vec3 toPopka(rl.Vector3 from) {
|
Vec3 toPopka(rl.Vector3 from) {
|
||||||
return Vec3(from.x, from.y, from.z);
|
return Vec3(from.x, from.y, from.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib vector to a Popka vector.
|
private
|
||||||
Vec4 toPopka(rl.Vector4 from) {
|
Vec4 toPopka(rl.Vector4 from) {
|
||||||
return Vec4(from.x, from.y, from.z, from.w);
|
return Vec4(from.x, from.y, from.z, from.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib rectangle to a Popka rectangle.
|
private
|
||||||
Rect toPopka(rl.Rectangle from) {
|
Rect toPopka(rl.Rectangle from) {
|
||||||
return Rect(from.x, from.y, from.width, from.height);
|
return Rect(from.x, from.y, from.width, from.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib texture to a Popka texture.
|
private
|
||||||
Texture toPopka(rl.Texture2D from) {
|
Texture toPopka(rl.Texture2D from) {
|
||||||
auto result = Texture();
|
auto result = Texture();
|
||||||
result.data = from;
|
result.data = from;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib font to a Popka font.
|
private
|
||||||
Font toPopka(rl.Font from) {
|
Font toPopka(rl.Font from) {
|
||||||
auto result = Font();
|
auto result = Font();
|
||||||
result.data = from;
|
result.data = from;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a raylib render texture to a Popka viewport.
|
private
|
||||||
Viewport toPopka(rl.RenderTexture2D from) {
|
Viewport toPopka(rl.RenderTexture2D from) {
|
||||||
auto result = Viewport();
|
auto result = Viewport();
|
||||||
result.data = from;
|
result.data = from;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka color to a raylib color.
|
private
|
||||||
rl.Color toRl(Color from) {
|
rl.Color toRl(Color from) {
|
||||||
return rl.Color(from.r, from.g, from.b, from.a);
|
return rl.Color(from.r, from.g, from.b, from.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka vector to a raylib vector.
|
private
|
||||||
rl.Vector2 toRl(Vec2 from) {
|
rl.Vector2 toRl(Vec2 from) {
|
||||||
return rl.Vector2(from.x, from.y);
|
return rl.Vector2(from.x, from.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka vector to a raylib vector.
|
private
|
||||||
rl.Vector3 toRl(Vec3 from) {
|
rl.Vector3 toRl(Vec3 from) {
|
||||||
return rl.Vector3(from.x, from.y, from.z);
|
return rl.Vector3(from.x, from.y, from.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka vector to a raylib vector.
|
private
|
||||||
rl.Vector4 toRl(Vec4 from) {
|
rl.Vector4 toRl(Vec4 from) {
|
||||||
return rl.Vector4(from.x, from.y, from.z, from.w);
|
return rl.Vector4(from.x, from.y, from.z, from.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka rectangle to a raylib rectangle.
|
private
|
||||||
rl.Rectangle toRl(Rect from) {
|
rl.Rectangle toRl(Rect from) {
|
||||||
return rl.Rectangle(from.position.x, from.position.y, from.size.x, from.size.y);
|
return rl.Rectangle(from.position.x, from.position.y, from.size.x, from.size.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka texture to a raylib texture.
|
private
|
||||||
rl.Texture2D toRl(Texture from) {
|
rl.Texture2D toRl(Texture from) {
|
||||||
return from.data;
|
return from.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka font to a raylib font.
|
private
|
||||||
rl.Font toRl(Font from) {
|
rl.Font toRl(Font from) {
|
||||||
return from.data;
|
return from.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka viewport to a raylib render texture.
|
private
|
||||||
rl.RenderTexture2D toRl(Viewport from) {
|
rl.RenderTexture2D toRl(Viewport from) {
|
||||||
return from.data;
|
return from.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Popka filter to a raylib filter.
|
private
|
||||||
int toRl(Filter filter) {
|
int toRl(Filter filter) {
|
||||||
final switch (filter) {
|
final switch (filter) {
|
||||||
case Filter.nearest: return rl.TEXTURE_FILTER_POINT;
|
case Filter.nearest: return rl.TEXTURE_FILTER_POINT;
|
||||||
|
@ -795,6 +795,7 @@ int toRl(Filter filter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private
|
||||||
rl.Camera2D toRl(Camera camera) {
|
rl.Camera2D toRl(Camera camera) {
|
||||||
return rl.Camera2D(
|
return rl.Camera2D(
|
||||||
Rect(resolution).origin(camera.isCentered ? Hook.center : Hook.topLeft).toRl(),
|
Rect(resolution).origin(camera.isCentered ? Hook.center : Hook.topLeft).toRl(),
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
// Version: v0.0.18
|
// Version: v0.0.18
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
/// The `sprite` module provides a simple and extensible sprite.
|
/// The `sprite` module provides a simple and flexible sprite.
|
||||||
module popka.sprite;
|
module popka.sprite;
|
||||||
|
|
||||||
import popka.engine;
|
import popka.engine;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue