mirror of
https://github.com/Kapendev/parin.git
synced 2025-04-28 22:19:55 +03:00
Bug fixes and added wrap enum.
This commit is contained in:
parent
d54610d430
commit
37d3901936
2 changed files with 57 additions and 15 deletions
|
@ -42,6 +42,12 @@ enum Filter : ubyte {
|
||||||
linear = rl.TEXTURE_FILTER_BILINEAR, /// Bilinear filtering (smooth).
|
linear = rl.TEXTURE_FILTER_BILINEAR, /// Bilinear filtering (smooth).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A type representing texture wrapping modes.
|
||||||
|
enum Wrap : ubyte {
|
||||||
|
repeat = rl.TEXTURE_WRAP_REPEAT, // Repeats texture.
|
||||||
|
clamp = rl.TEXTURE_WRAP_CLAMP, // Clamps texture.
|
||||||
|
}
|
||||||
|
|
||||||
/// A type representing blending modes.
|
/// A type representing blending modes.
|
||||||
enum Blend : ubyte {
|
enum Blend : ubyte {
|
||||||
alpha = rl.BLEND_CUSTOM_SEPARATE, /// Standard alpha blending.
|
alpha = rl.BLEND_CUSTOM_SEPARATE, /// Standard alpha blending.
|
||||||
|
@ -52,7 +58,7 @@ enum Blend : ubyte {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type representing a limited set of keyboard keys.
|
/// A type representing a limited set of keyboard keys.
|
||||||
enum Keyboard {
|
enum Keyboard : ushort {
|
||||||
a = rl.KEY_A, /// The A key.
|
a = rl.KEY_A, /// The A key.
|
||||||
b = rl.KEY_B, /// The B key.
|
b = rl.KEY_B, /// The B key.
|
||||||
c = rl.KEY_C, /// The C key.
|
c = rl.KEY_C, /// The C key.
|
||||||
|
@ -133,14 +139,14 @@ enum Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type representing a limited set of mouse keys.
|
/// A type representing a limited set of mouse keys.
|
||||||
enum Mouse {
|
enum Mouse : ubyte {
|
||||||
left = rl.MOUSE_BUTTON_LEFT, /// The left mouse button.
|
left = rl.MOUSE_BUTTON_LEFT, /// The left mouse button.
|
||||||
right = rl.MOUSE_BUTTON_RIGHT, /// The right mouse button.
|
right = rl.MOUSE_BUTTON_RIGHT, /// The right mouse button.
|
||||||
middle = rl.MOUSE_BUTTON_MIDDLE, /// The middle mouse button.
|
middle = rl.MOUSE_BUTTON_MIDDLE, /// The middle mouse button.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A type representing a limited set of gamepad buttons.
|
/// A type representing a limited set of gamepad buttons.
|
||||||
enum Gamepad {
|
enum Gamepad : ubyte {
|
||||||
left = rl.GAMEPAD_BUTTON_LEFT_FACE_LEFT, /// The left button.
|
left = rl.GAMEPAD_BUTTON_LEFT_FACE_LEFT, /// The left button.
|
||||||
right = rl.GAMEPAD_BUTTON_LEFT_FACE_RIGHT, /// The right button.
|
right = rl.GAMEPAD_BUTTON_LEFT_FACE_RIGHT, /// The right button.
|
||||||
up = rl.GAMEPAD_BUTTON_LEFT_FACE_UP, /// The up button.
|
up = rl.GAMEPAD_BUTTON_LEFT_FACE_UP, /// The up button.
|
||||||
|
@ -268,6 +274,13 @@ struct Texture {
|
||||||
rl.SetTextureFilter(data, value);
|
rl.SetTextureFilter(data, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the wrap mode of the texture.
|
||||||
|
@trusted
|
||||||
|
void setWrap(Wrap value) {
|
||||||
|
if (isEmpty) return;
|
||||||
|
rl.SetTextureWrap(data, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Frees the loaded texture.
|
/// Frees the loaded texture.
|
||||||
@trusted
|
@trusted
|
||||||
void free() {
|
void free() {
|
||||||
|
@ -352,6 +365,13 @@ struct Font {
|
||||||
rl.SetTextureFilter(data.texture, value);
|
rl.SetTextureFilter(data.texture, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the wrap mode of the font.
|
||||||
|
@trusted
|
||||||
|
void setWrap(Wrap value) {
|
||||||
|
if (isEmpty) return;
|
||||||
|
rl.SetTextureWrap(data.texture, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Frees the loaded font.
|
/// Frees the loaded font.
|
||||||
@trusted
|
@trusted
|
||||||
void free() {
|
void free() {
|
||||||
|
@ -594,6 +614,7 @@ struct Viewport {
|
||||||
if (!isEmpty) rl.UnloadRenderTexture(data);
|
if (!isEmpty) rl.UnloadRenderTexture(data);
|
||||||
data = rl.LoadRenderTexture(width, height);
|
data = rl.LoadRenderTexture(width, height);
|
||||||
setFilter(engineState.defaultFilter);
|
setFilter(engineState.defaultFilter);
|
||||||
|
setWrap(engineState.defaultWrap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attaches the viewport, making it active.
|
/// Attaches the viewport, making it active.
|
||||||
|
@ -634,6 +655,13 @@ struct Viewport {
|
||||||
rl.SetTextureFilter(data.texture, value);
|
rl.SetTextureFilter(data.texture, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the wrap mode of the viewport.
|
||||||
|
@trusted
|
||||||
|
void setWrap(Wrap value) {
|
||||||
|
if (isEmpty) return;
|
||||||
|
rl.SetTextureWrap(data.texture, value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Frees the loaded viewport.
|
/// Frees the loaded viewport.
|
||||||
@trusted
|
@trusted
|
||||||
void free() {
|
void free() {
|
||||||
|
@ -911,6 +939,7 @@ struct EngineState {
|
||||||
|
|
||||||
Color borderColor;
|
Color borderColor;
|
||||||
Filter defaultFilter;
|
Filter defaultFilter;
|
||||||
|
Wrap defaultWrap;
|
||||||
Sz tickCount;
|
Sz tickCount;
|
||||||
|
|
||||||
@safe @nogc nothrow:
|
@safe @nogc nothrow:
|
||||||
|
@ -1130,6 +1159,7 @@ TextId loadText(IStr path, Sz tag = 0) {
|
||||||
Result!Texture loadRawTexture(IStr path) {
|
Result!Texture loadRawTexture(IStr path) {
|
||||||
auto value = rl.LoadTexture(path.toAssetsPath().toCStr().getOr()).toParin();
|
auto value = rl.LoadTexture(path.toAssetsPath().toCStr().getOr()).toParin();
|
||||||
value.setFilter(engineState.defaultFilter);
|
value.setFilter(engineState.defaultFilter);
|
||||||
|
value.setWrap(engineState.defaultWrap);
|
||||||
return Result!Texture(value, value.isEmpty.toFault(Fault.cantFind));
|
return Result!Texture(value, value.isEmpty.toFault(Fault.cantFind));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1168,6 +1198,7 @@ Result!Font loadRawFont(IStr path, int size, int runeSpacing, int lineSpacing, I
|
||||||
value.runeSpacing = runeSpacing;
|
value.runeSpacing = runeSpacing;
|
||||||
value.lineSpacing = lineSpacing;
|
value.lineSpacing = lineSpacing;
|
||||||
value.setFilter(engineState.defaultFilter);
|
value.setFilter(engineState.defaultFilter);
|
||||||
|
value.setWrap(engineState.defaultWrap);
|
||||||
return Result!Font(value, value.isEmpty.toFault(Fault.cantFind));
|
return Result!Font(value, value.isEmpty.toFault(Fault.cantFind));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1498,16 +1529,31 @@ Filter defaultFilter() {
|
||||||
return engineState.defaultFilter;
|
return engineState.defaultFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the default wrap mode for textures.
|
||||||
|
Wrap defaultWrap() {
|
||||||
|
return engineState.defaultWrap;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the default filter mode for textures to the specified value.
|
/// Sets the default filter mode for textures to the specified value.
|
||||||
void setDefaultFilter(Filter value) {
|
void setDefaultFilter(Filter value) {
|
||||||
engineState.defaultFilter = value;
|
engineState.defaultFilter = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the default wrap mode for textures to the specified value.
|
||||||
|
void setDefaultWrap(Wrap value) {
|
||||||
|
engineState.defaultWrap = value;
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the filter mode used by the engine viewport to the specified value.
|
/// Sets the filter mode used by the engine viewport to the specified value.
|
||||||
void setEngineViewportFilter(Filter value) {
|
void setEngineViewportFilter(Filter value) {
|
||||||
engineState.viewport.setFilter(value);
|
engineState.viewport.setFilter(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the wrap mode used by the engine viewport to the specified value.
|
||||||
|
void setEngineViewportWrap(Wrap value) {
|
||||||
|
engineState.viewport.setWrap(value);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the current master volume level.
|
/// Returns the current master volume level.
|
||||||
@trusted
|
@trusted
|
||||||
float masterVolume() {
|
float masterVolume() {
|
||||||
|
|
|
@ -22,14 +22,14 @@ public import joka.types;
|
||||||
@safe @nogc nothrow:
|
@safe @nogc nothrow:
|
||||||
|
|
||||||
struct Tile {
|
struct Tile {
|
||||||
int width;
|
int width = 16;
|
||||||
int height;
|
int height = 16;
|
||||||
Sz id;
|
short id;
|
||||||
Vec2 position;
|
Vec2 position;
|
||||||
|
|
||||||
@safe @nogc nothrow:
|
@safe @nogc nothrow:
|
||||||
|
|
||||||
this(int width, int height, Sz id, Vec2 position = Vec2()) {
|
this(int width, int height, short id, Vec2 position = Vec2()) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -70,6 +70,7 @@ struct TileMap {
|
||||||
int tileWidth = 16;
|
int tileWidth = 16;
|
||||||
int tileHeight = 16;
|
int tileHeight = 16;
|
||||||
Vec2 position;
|
Vec2 position;
|
||||||
|
|
||||||
alias data this;
|
alias data this;
|
||||||
|
|
||||||
@safe @nogc nothrow:
|
@safe @nogc nothrow:
|
||||||
|
@ -83,11 +84,6 @@ struct TileMap {
|
||||||
this.data.fill(-1);
|
this.data.fill(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the tile map has not been loaded.
|
|
||||||
bool isEmpty() {
|
|
||||||
return data.length == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int width() {
|
int width() {
|
||||||
return cast(int) (softMaxColCount * tileWidth);
|
return cast(int) (softMaxColCount * tileWidth);
|
||||||
}
|
}
|
||||||
|
@ -231,7 +227,7 @@ Result!TileMap loadRawTileMap(IStr path, int tileWidth, int tileHeight) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTile(Texture texture, Tile tile, DrawOptions options = DrawOptions()) {
|
void drawTile(Texture texture, Tile tile, DrawOptions options = DrawOptions()) {
|
||||||
if (texture.isEmpty || tile.width == 0 || tile.height == 0) return;
|
if (texture.isEmpty || tile.id < 0 || tile.width <= 0 || tile.height <= 0) return;
|
||||||
drawTextureArea(texture, tile.textureArea(texture.width / tile.width), tile.position, options);
|
drawTextureArea(texture, tile.textureArea(texture.width / tile.width), tile.position, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +236,7 @@ void drawTile(TextureId texture, Tile tile, DrawOptions options = DrawOptions())
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawTileMap(Texture texture, TileMap map, Camera camera, DrawOptions options = DrawOptions()) {
|
void drawTileMap(Texture texture, TileMap map, Camera camera, DrawOptions options = DrawOptions()) {
|
||||||
if (texture.isEmpty || map.tileWidth == 0 || map.tileHeight == 0) return;
|
if (texture.isEmpty || map.tileWidth <= 0 || map.tileHeight <= 0) return;
|
||||||
|
|
||||||
auto textureColCount = texture.width / map.tileWidth;
|
auto textureColCount = texture.width / map.tileWidth;
|
||||||
auto targetTileWidth = cast(int) (map.tileWidth * options.scale.x);
|
auto targetTileWidth = cast(int) (map.tileWidth * options.scale.x);
|
||||||
|
@ -253,7 +249,7 @@ void drawTileMap(Texture texture, TileMap map, Camera camera, DrawOptions option
|
||||||
foreach (row; colRow1.y .. colRow2.y) {
|
foreach (row; colRow1.y .. colRow2.y) {
|
||||||
foreach (col; colRow1.x .. colRow2.x) {
|
foreach (col; colRow1.x .. colRow2.x) {
|
||||||
auto id = map[row, col];
|
auto id = map[row, col];
|
||||||
if (id == -1) continue;
|
if (id < 0) continue;
|
||||||
textureArea.position.x = (id % textureColCount) * map.tileWidth;
|
textureArea.position.x = (id % textureColCount) * map.tileWidth;
|
||||||
textureArea.position.y = (id / textureColCount) * map.tileHeight;
|
textureArea.position.y = (id / textureColCount) * map.tileHeight;
|
||||||
drawTextureArea(
|
drawTextureArea(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue