diff --git a/scripts/header.d b/scripts/header.d index d1e9b5b..2a57ba4 100755 --- a/scripts/header.d +++ b/scripts/header.d @@ -10,7 +10,7 @@ enum header = "// --- // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // ---"; int main(string[] args) { diff --git a/source/popka/dialogue.d b/source/popka/dialogue.d index eb57774..c454373 100644 --- a/source/popka/dialogue.d +++ b/source/popka/dialogue.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- // TODO: The DialogueCommandRunner should work with gc functions too. Think about how to do it. diff --git a/source/popka/engine.d b/source/popka/engine.d index fccc6b4..07c7127 100644 --- a/source/popka/engine.d +++ b/source/popka/engine.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- // TODO: Test the resources code and the tag thing. @@ -1041,6 +1041,7 @@ SoundId loadSound(IStr path, float volume, float pitch, Sz tag = 0) { @trusted Result!Viewport loadRawViewport(int width, int height) { auto value = rl.LoadRenderTexture(width, height).toPopka(); + value.setFilter(engineState.defaultFilter); return Result!Viewport(value, value.isEmpty.toFault()); } diff --git a/source/popka/package.d b/source/popka/package.d index b95f2f9..c9cec61 100644 --- a/source/popka/package.d +++ b/source/popka/package.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- module popka; diff --git a/source/popka/rl/package.d b/source/popka/rl/package.d index 0784243..9460555 100644 --- a/source/popka/rl/package.d +++ b/source/popka/rl/package.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- /// The `rl` module provides access to the raylib library. diff --git a/source/popka/rl/raylib.d b/source/popka/rl/raylib.d index c9947bc..b74c48c 100644 --- a/source/popka/rl/raylib.d +++ b/source/popka/rl/raylib.d @@ -3,87 +3,9 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- -/********************************************************************************************** -* -* raylib v5.0 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com) -* -* FEATURES: -* - NO external dependencies, all required libraries included with raylib -* - Multiplatform: Windows, Linux, FreeBSD, OpenBSD, NetBSD, DragonFly, -* MacOS, Haiku, Android, Raspberry Pi, DRM native, HTML5. -* - Written in plain C code (C99) in PascalCase/camelCase notation -* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3, 4.3 or ES2 - choose at compile) -* - Unique OpenGL abstraction layer (usable as standalone module): [rlgl] -* - Multiple Fonts formats supported (TTF, XNA fonts, AngelCode fonts) -* - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC) -* - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more! -* - Flexible Materials system, supporting classic maps and PBR maps -* - Animated 3D models supported (skeletal bones animation) (IQM) -* - Shaders support, including Model shaders and Postprocessing shaders -* - Powerful math module for Vector, Matrix and Quaternion operations: [raymath] -* - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD) -* - VR stereo rendering with configurable HMD device parameters -* - Bindings to multiple programming languages available! -* -* NOTES: -* - One default Font is loaded on InitWindow()->LoadFontDefault() [core, text] -* - One default Texture2D is loaded on rlglInit(), 1x1 white pixel R8G8B8A8 [rlgl] (OpenGL 3.3 or ES2) -* - One default Shader is loaded on rlglInit()->rlLoadShaderDefault() [rlgl] (OpenGL 3.3 or ES2) -* - One default RenderBatch is loaded on rlglInit()->rlLoadRenderBatch() [rlgl] (OpenGL 3.3 or ES2) -* -* DEPENDENCIES (included): -* [rcore] rglfw (Camilla Löwy - github.com/glfw/glfw) for window/context management and input (PLATFORM_DESKTOP) -* [rlgl] glad (David Herberth - github.com/Dav1dde/glad) for OpenGL 3.3 extensions loading (PLATFORM_DESKTOP) -* [raudio] miniaudio (David Reid - github.com/mackron/miniaudio) for audio device/context management -* -* OPTIONAL DEPENDENCIES (included): -* [rcore] msf_gif (Miles Fogle) for GIF recording -* [rcore] sinfl (Micha Mettke) for DEFLATE decompression algorithm -* [rcore] sdefl (Micha Mettke) for DEFLATE compression algorithm -* [rtextures] stb_image (Sean Barret) for images loading (BMP, TGA, PNG, JPEG, HDR...) -* [rtextures] stb_image_write (Sean Barret) for image writing (BMP, TGA, PNG, JPG) -* [rtextures] stb_image_resize (Sean Barret) for image resizing algorithms -* [rtext] stb_truetype (Sean Barret) for ttf fonts loading -* [rtext] stb_rect_pack (Sean Barret) for rectangles packing -* [rmodels] par_shapes (Philip Rideout) for parametric 3d shapes generation -* [rmodels] tinyobj_loader_c (Syoyo Fujita) for models loading (OBJ, MTL) -* [rmodels] cgltf (Johannes Kuhlmann) for models loading (glTF) -* [rmodels] Model3D (bzt) for models loading (M3D, https://bztsrc.gitlab.io/model3d) -* [raudio] dr_wav (David Reid) for WAV audio file loading -* [raudio] dr_flac (David Reid) for FLAC audio file loading -* [raudio] dr_mp3 (David Reid) for MP3 audio file loading -* [raudio] stb_vorbis (Sean Barret) for OGG audio loading -* [raudio] jar_xm (Joshua Reisenauer) for XM audio module loading -* [raudio] jar_mod (Joshua Reisenauer) for MOD audio module loading -* -* -* LICENSE: zlib/libpng -* -* raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, -* BSD-like license that allows static linking with closed source software: -* -* Copyright (c) 2013-2023 Ramon Santamaria (@raysan5) -* -* This software is provided "as-is", without any express or implied warranty. In no event -* will the authors be held liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, including commercial -* applications, and to alter it and redistribute it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not claim that you -* wrote the original software. If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but is not required. -* -* 2. Altered source versions must be plainly marked as such, and must not be misrepresented -* as being the original software. -* -* 3. This notice may not be removed or altered from any source distribution. -* -**********************************************************************************************/ - /// The `rayib` module provides access to the raylib.h functions. module popka.rl.raylib; diff --git a/source/popka/rl/rlgl.d b/source/popka/rl/rlgl.d index c63fb8c..babc24a 100644 --- a/source/popka/rl/rlgl.d +++ b/source/popka/rl/rlgl.d @@ -3,115 +3,9 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- -/********************************************************************************************** -* -* rlgl v4.5 - A multi-OpenGL abstraction layer with an immediate-mode style API -* -* DESCRIPTION: -* An abstraction layer for multiple OpenGL versions (1.1, 2.1, 3.3 Core, 4.3 Core, ES 2.0) -* that provides a pseudo-OpenGL 1.1 immediate-mode style API (rlVertex, rlTranslate, rlRotate...) -* -* ADDITIONAL NOTES: -* When choosing an OpenGL backend different than OpenGL 1.1, some internal buffer are -* initialized on rlglInit() to accumulate vertex data. -* -* When an internal state change is required all the stored vertex data is renderer in batch, -* additionally, rlDrawRenderBatchActive() could be called to force flushing of the batch. -* -* Some resources are also loaded for convenience, here the complete list: -* - Default batch (RLGL.defaultBatch): RenderBatch system to accumulate vertex data -* - Default texture (RLGL.defaultTextureId): 1x1 white pixel R8G8B8A8 -* - Default shader (RLGL.State.defaultShaderId, RLGL.State.defaultShaderLocs) -* -* Internal buffer (and resources) must be manually unloaded calling rlglClose(). -* -* CONFIGURATION: -* #define GRAPHICS_API_OPENGL_11 -* #define GRAPHICS_API_OPENGL_21 -* #define GRAPHICS_API_OPENGL_33 -* #define GRAPHICS_API_OPENGL_43 -* #define GRAPHICS_API_OPENGL_ES2 -* #define GRAPHICS_API_OPENGL_ES3 -* Use selected OpenGL graphics backend, should be supported by platform -* Those preprocessor defines are only used on rlgl module, if OpenGL version is -* required by any other module, use rlGetVersion() to check it -* -* #define RLGL_IMPLEMENTATION -* Generates the implementation of the library into the included file. -* If not defined, the library is in header only mode and can be included in other headers -* or source files without problems. But only ONE file should hold the implementation. -* -* #define RLGL_RENDER_TEXTURES_HINT -* Enable framebuffer objects (fbo) support (enabled by default) -* Some GPUs could not support them despite the OpenGL version -* -* #define RLGL_SHOW_GL_DETAILS_INFO -* Show OpenGL extensions and capabilities detailed logs on init -* -* #define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT -* Enable debug context (only available on OpenGL 4.3) -* -* rlgl capabilities could be customized just defining some internal -* values before library inclusion (default values listed): -* -* #define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch elements limits -* #define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering) -* #define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture) -* #define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture()) -* -* #define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack -* #define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported -* #define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance -* #define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance -* -* When loading a shader, the following vertex attributes and uniform -* location names are tried to be set automatically: -* -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Bound by default to shader location: 0 -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Bound by default to shader location: 1 -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Bound by default to shader location: 2 -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Bound by default to shader location: 3 -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Bound by default to shader location: 4 -* #define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Bound by default to shader location: 5 -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView)) -* #define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color) -* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0) -* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1) -* #define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2) -* -* DEPENDENCIES: -* - OpenGL libraries (depending on platform and OpenGL version selected) -* - GLAD OpenGL extensions loading library (only for OpenGL 3.3 Core, 4.3 Core) -* -* -* LICENSE: zlib/libpng -* -* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) -* -* This software is provided "as-is", without any express or implied warranty. In no event -* will the authors be held liable for any damages arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, including commercial -* applications, and to alter it and redistribute it freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not claim that you -* wrote the original software. If you use this software in a product, an acknowledgment -* in the product documentation would be appreciated but is not required. -* -* 2. Altered source versions must be plainly marked as such, and must not be misrepresented -* as being the original software. -* -* 3. This notice may not be removed or altered from any source distribution. -* -**********************************************************************************************/ - /// The `rlgl` module provides access to the rlgl.h functions. module popka.rl.rlgl; diff --git a/source/popka/sprite.d b/source/popka/sprite.d index 0e8db5e..dd41985 100644 --- a/source/popka/sprite.d +++ b/source/popka/sprite.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- // TODO: Think about gaps in an atlas texture. @@ -18,15 +18,68 @@ import popka.engine; struct SpriteAnimation { ubyte frameRow; - ubyte frameCount; - ubyte frameSpeed; + ubyte frameCount = 1; + ubyte frameSpeed = 6; +} + +struct SpriteAnimationGroup2 { + ubyte[2] frameRows; + ubyte frameCount = 1; + ubyte frameSpeed = 6; + enum angleStep = 180.0f; @safe @nogc nothrow: - this(ubyte frameRow, ubyte frameCount, ubyte frameSpeed) { - this.frameRow = frameRow; - this.frameCount = frameCount; - this.frameSpeed = frameSpeed; + SpriteAnimation pick(float angle) { + auto id = wrap!int(cast(int) round(snap(angle, angleStep) / angleStep), 0, frameRows.length); + return SpriteAnimation(frameRows[id], frameCount, frameSpeed); + } +} + +struct SpriteAnimationGroup4 { + ubyte[4] frameRows; + ubyte frameCount = 1; + ubyte frameSpeed = 6; + enum angleStep = 90.0f; + + @safe @nogc nothrow: + + SpriteAnimation pick(float angle) { + // NOTE: This is a hack to make things look better in simple cases. + auto hackAngle = cast(int) round(angle); + if (hackAngle == 135) return SpriteAnimation(frameRows[1], frameCount, frameSpeed); + if (hackAngle == -135) return SpriteAnimation(frameRows[3], frameCount, frameSpeed); + + auto id = wrap!int(cast(int) round(snap(angle, angleStep) / angleStep), 0, frameRows.length); + return SpriteAnimation(frameRows[id], frameCount, frameSpeed); + } +} + +struct SpriteAnimationGroup8 { + ubyte[8] frameRows; + ubyte frameCount = 1; + ubyte frameSpeed = 6; + enum angleStep = 45.0f; + + @safe @nogc nothrow: + + SpriteAnimation pick(float angle) { + auto id = wrap!int(cast(int) round(snap(angle, angleStep) / angleStep), 0, frameRows.length); + return SpriteAnimation(frameRows[id], frameCount, frameSpeed); + } +} + +struct SpriteAnimationGroup16 { + ubyte[16] frameRows; + ubyte frameCount = 1; + ubyte frameSpeed = 6; + enum angleStep = 22.5f; + + @safe @nogc nothrow: + + SpriteAnimation pick(float angle) { + auto id = wrap!int(cast(int) round(snap(angle, angleStep) / angleStep), 0, frameRows.length); + return SpriteAnimation(frameRows[id], frameCount, frameSpeed); } } @@ -64,9 +117,9 @@ struct Sprite { frameProgress = resetFrame; } - void play(SpriteAnimation animation) { + void play(SpriteAnimation animation, bool canKeepFrame = false) { if (this.animation != animation) { - reset(); + if (!canKeepFrame) reset(); this.animation = animation; } } @@ -77,7 +130,16 @@ struct Sprite { } } +// TODO: wrap!uint NOT WORKING BECUASE IT HAS AN OVERFLOW ERROR!!! +// TODO: Add this to Joka and also make it more generic. +private +float snap(float x, float step) { + return round(x / step) * step; +} + void drawSprite(Texture texture, Sprite sprite, Vec2 position, DrawOptions options = DrawOptions()) { + if (sprite.width == 0 || sprite.height == 0) return; + auto top = sprite.atlasTop + sprite.animation.frameRow * sprite.height; auto gridWidth = max(texture.width - sprite.atlasLeft, 0) / sprite.width; auto gridHeight = max(texture.height - top, 0) / sprite.height; diff --git a/source/popka/tilemap.d b/source/popka/tilemap.d index 06b5710..f359733 100644 --- a/source/popka/tilemap.d +++ b/source/popka/tilemap.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- // TODO: Think about gaps in an atlas texture. diff --git a/source/popka/timer.d b/source/popka/timer.d index 1cfef47..b40ae8e 100644 --- a/source/popka/timer.d +++ b/source/popka/timer.d @@ -3,7 +3,7 @@ // SPDX-License-Identifier: MIT // Email: alexandroskapretsos@gmail.com // Project: https://github.com/Kapendev/popka -// Version: v0.0.20 +// Version: v0.0.21 // --- // TODO: Update all the doc comments here.