diff --git a/Duin/Duin.vcxproj b/Duin/Duin.vcxproj index 317d1bc..a4f78a0 100644 --- a/Duin/Duin.vcxproj +++ b/Duin/Duin.vcxproj @@ -161,6 +161,7 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis + @@ -191,13 +192,15 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis - + + + @@ -211,7 +214,7 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis - + diff --git a/Duin/Duin.vcxproj.filters b/Duin/Duin.vcxproj.filters index 7a4bf6c..3a5a8e1 100644 --- a/Duin/Duin.vcxproj.filters +++ b/Duin/Duin.vcxproj.filters @@ -136,7 +136,7 @@ Duin\Events - + Duin\Graphics @@ -149,6 +149,8 @@ Duin\Object + + @@ -190,7 +192,7 @@ Duin\Events - + Duin\Graphics @@ -203,5 +205,6 @@ Duin\Object + \ No newline at end of file diff --git a/Duin/src/Duin.h b/Duin/src/Duin.h index 6584483..d2fff36 100644 --- a/Duin/src/Duin.h +++ b/Duin/src/Duin.h @@ -25,7 +25,7 @@ #include "Duin/Events/InputMap.h" // ---------- Graphics ----------- -#include "Duin/Graphics/TextureResource.h" +#include "Duin/Assets/TextureResource.h" // ---------- Entities ----------- #include "Duin/Entity/Entity.h" diff --git a/Duin/src/Duin/Assets/AssetManager.cpp b/Duin/src/Duin/Assets/AssetManager.cpp new file mode 100644 index 0000000..d0f9bec --- /dev/null +++ b/Duin/src/Duin/Assets/AssetManager.cpp @@ -0,0 +1,18 @@ +#include "dnpch.h" + +#include "AssetManager.h" + +namespace Duin +{ + AssetManager::AssetManager() + { + } + + AssetManager::~AssetManager() + { + } + + void AssetManager::LoadTexture(const char* texturePath) + { + } +} \ No newline at end of file diff --git a/Duin/src/Duin/Assets/AssetManager.h b/Duin/src/Duin/Assets/AssetManager.h new file mode 100644 index 0000000..337002f --- /dev/null +++ b/Duin/src/Duin/Assets/AssetManager.h @@ -0,0 +1,24 @@ +#pragma once + +#include "Duin/Core/Core.h" +#include "Duin/Core/UUID.h" +#include "Duin/Core/Structures/RenderStructs.h" + +#include "RLImGuiComponent.h" + +#include + +namespace Duin +{ + class DUIN_API AssetManager + { + public: + AssetManager(); + ~AssetManager(); + + void LoadTexture(const char* texturePath); + + private: + std::unordered_map> textureMap; + }; +} \ No newline at end of file diff --git a/Duin/src/Duin/Assets/Particle2D.h b/Duin/src/Duin/Assets/Particle2D.h new file mode 100644 index 0000000..03c8620 --- /dev/null +++ b/Duin/src/Duin/Assets/Particle2D.h @@ -0,0 +1,12 @@ +#pragma once + +#include "Duin/Core/Core.h" + +namespace Duin +{ + class DUIN_API Particle2D + { + public: + + }; +} \ No newline at end of file diff --git a/Duin/src/Duin/Graphics/TextureResource.cpp b/Duin/src/Duin/Assets/TextureResource.cpp similarity index 87% rename from Duin/src/Duin/Graphics/TextureResource.cpp rename to Duin/src/Duin/Assets/TextureResource.cpp index 92a04d2..0f312b2 100644 --- a/Duin/src/Duin/Graphics/TextureResource.cpp +++ b/Duin/src/Duin/Assets/TextureResource.cpp @@ -34,8 +34,8 @@ namespace Duin TextureResource& TextureResource::LoadTexture(const char* texturePath) { - Texture texture = ::LoadTexture(texturePath); // supposed to call Raylib's LoadTexture() - texturePtr.reset(new Texture(texture), [](Texture* ptr) { + ::Texture texture = ::LoadTexture(texturePath); // supposed to call Raylib's LoadTexture() + texturePtr.reset(new ::Texture(texture), [](::Texture* ptr) { UnloadTexture(*ptr); // Custom deleter that calls Raylib's UnloadTexture delete ptr; // Delete the pointer after unloading the texture }); @@ -88,7 +88,7 @@ namespace Duin { position.x, position.y, textureSize.x, textureSize.y }, { origin.x, origin.y }, rotation_deg, - { 255, 255, 255, 255 } + { tintColor.r, tintColor.g, tintColor.b, tintColor.a } ); //std::cout << "Drawing texture with size: " << textureSize.x << ", " << textureSize.y << "\n"; return *this; @@ -100,6 +100,12 @@ namespace Duin return *this; } + TextureResource& TextureResource::SetTintColor(Color color) + { + tintColor = color; + return *this; + } + void TextureResource::ClearTexture() { texturePtr.reset(); diff --git a/Duin/src/Duin/Graphics/TextureResource.h b/Duin/src/Duin/Assets/TextureResource.h similarity index 88% rename from Duin/src/Duin/Graphics/TextureResource.h rename to Duin/src/Duin/Assets/TextureResource.h index 55da79c..1798901 100644 --- a/Duin/src/Duin/Graphics/TextureResource.h +++ b/Duin/src/Duin/Assets/TextureResource.h @@ -4,6 +4,7 @@ #include "Duin/Core/Core.h" #include "Duin/Core/Debug/Log.h" #include "Duin/Core/Maths/DuinMaths.h" +#include "Duin/Core/Structures/RenderStructs.h" #include @@ -27,6 +28,7 @@ namespace Duin TextureResource& Draw(Vector2 position, float rotation_deg); TextureResource& SetCentered(bool centered); + TextureResource& SetTintColor(Color color); void ClearTexture(); @@ -34,5 +36,6 @@ namespace Duin std::shared_ptr<::Texture> texturePtr; Vector2 textureSize; bool isCentered = false; + Color tintColor = WHITE; }; } \ No newline at end of file diff --git a/Duin/src/Duin/Core/Application.cpp b/Duin/src/Duin/Core/Application.cpp index a9e0b82..aa40a7e 100644 --- a/Duin/src/Duin/Core/Application.cpp +++ b/Duin/src/Duin/Core/Application.cpp @@ -13,6 +13,11 @@ namespace Duin { } + void Application::SetBackgroundColor(Color color) + { + backgroundColor = color; + } + void Application::Run() { int screenWidth = 1280; @@ -48,7 +53,7 @@ namespace Duin PhysicsUpdate(::GetFrameTime()); // TODO } - ::ClearBackground(RAYWHITE); + ::ClearBackground(::Color{ backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a }); EngineDraw(); diff --git a/Duin/src/Duin/Core/Application.h b/Duin/src/Duin/Core/Application.h index d62ba9a..c8410f6 100644 --- a/Duin/src/Duin/Core/Application.h +++ b/Duin/src/Duin/Core/Application.h @@ -5,6 +5,7 @@ #include "Duin/Events/InputMap.h" #include "Duin/Events/InputEvent.h" #include "Duin/Core/Scene/SceneManager.h" +#include "Duin/Core/Structures/RenderStructs.h" #include @@ -22,6 +23,7 @@ namespace Duin TARGET_RENDER_FRAMERATE = framerate; TARGET_PHYSICS_FRAMERATE = framerate; } + void SetBackgroundColor(Color color); void Run(); @@ -45,6 +47,7 @@ namespace Duin private: int TARGET_RENDER_FRAMERATE = 60; int TARGET_PHYSICS_FRAMERATE = 60; + Color backgroundColor = WHITE; SceneManager sceneManager; }; diff --git a/Duin/src/Duin/Core/Debug/DebugDraw.cpp b/Duin/src/Duin/Core/Debug/DebugDraw.cpp index aa39b23..51ef832 100644 --- a/Duin/src/Duin/Core/Debug/DebugDraw.cpp +++ b/Duin/src/Duin/Core/Debug/DebugDraw.cpp @@ -13,7 +13,7 @@ namespace Duin void DebugDraw::DrawLine(Vector2 v1, Vector2 v2, Color color) { ::Color rlColor{ color.r, color.g, color.b, color.a }; - ::DrawLine(v1.x, v1.y, v2.x, v2.y, rlColor); + ::DrawLine((int)v1.x, (int)v1.y, (int)v2.x, (int)v2.y, rlColor); } void DebugDraw::DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) diff --git a/Duin/src/Duin/Core/Maths/src/Maths.h b/Duin/src/Duin/Core/Maths/src/Maths.h index 708564a..7c28e43 100644 --- a/Duin/src/Duin/Core/Maths/src/Maths.h +++ b/Duin/src/Duin/Core/Maths/src/Maths.h @@ -6,19 +6,19 @@ namespace Duin { - #define EPSILON 0.05 + #define EPSILON std::numeric_limits::epsilon() class DUIN_MATHS_API Maths { public: static bool AreSame(double a, double b) { - return fabs(a - b) < EPSILON; + return std::fabs(a - b) < EPSILON; } static bool AreSame(float a, float b) { - return fabs(a - b) < EPSILON; + return std::fabs(a - b) < EPSILON; } static double RadiansToDegrees(double radians) { diff --git a/Duin/src/Duin/Core/Maths/src/Vector2.h b/Duin/src/Duin/Core/Maths/src/Vector2.h index 6a04f43..3ca0885 100644 --- a/Duin/src/Duin/Core/Maths/src/Vector2.h +++ b/Duin/src/Duin/Core/Maths/src/Vector2.h @@ -8,7 +8,12 @@ namespace Duin { struct DUIN_MATHS_API Vector2 { - #define ZERO Vector2(0, 0) + #define ZERO Vector2(0.0f, 0.0f) + #define ONE Vector2(1.0f, 1.0f) + #define UP Vector2(0.0f, -1.0f) + #define DOWN Vector2(0.0f, 1.0f) + #define LEFT Vector2(-1.0f, 0.0f) + #define RIGHT Vector2(1.0f, 0.0f) float x, y; @@ -97,30 +102,36 @@ namespace Duin { return x * other.x + y * other.y; } - - float Magnitude() const + + float Length() const { return sqrt(x * x + y * y); } + float LengthSqrd() const + { + return (x * x + y * y); + } + Vector2 Normalized() const { - float mag = Magnitude(); + float mag = Length(); if (Maths::AreSame(mag, 0)) { return ZERO; } - return Vector2(x / mag, y / mag); + float invMag = 1.0f / mag; + return Vector2(x * invMag, y * invMag); } Vector2 LimitLength(float minLength, float maxLength) const { - float mag = Magnitude(); - if (mag < minLength) + float mag = LengthSqrd(); + if (mag < (minLength * minLength)) { return Normalized() * minLength; } - else if (mag > maxLength) + else if (mag > (maxLength * maxLength)) { return Normalized() * maxLength; } diff --git a/Duin/src/Duin/Core/Structures/RenderStructs.h b/Duin/src/Duin/Core/Structures/RenderStructs.h index 8a5707a..82795ea 100644 --- a/Duin/src/Duin/Core/Structures/RenderStructs.h +++ b/Duin/src/Duin/Core/Structures/RenderStructs.h @@ -2,6 +2,9 @@ #include "Duin/Core/Core.h" #include "Duin/Core/Maths/DuinMaths.h" +#include "Duin/Core/UUID.h" + +#include namespace Duin { @@ -128,97 +131,223 @@ namespace Duin // Color, 4 components, R8G8B8A8 (32bit) - typedef struct DUIN_API Color { + struct DUIN_API Color + { unsigned char r; // Color red value unsigned char g; // Color green value unsigned char b; // Color blue value unsigned char a; // Color alpha value - } Color; + + Color() : r(0), g(0), b(0), a(255) {} // Default constructor + Color(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 255) + : r(r), g(g), b(b), a(a) {} // Parameterized constructor + + Color(const ::Color& color) // Conversion constructor from raylib::Color + : r(color.r), g(color.g), b(color.b), a(color.a) {} + ::Color ToRaylibColor() const // Method to convert back to raylib::Color + { return { r, g, b, a }; } + }; + // Image, pixel data stored in CPU memory (RAM) - typedef struct DUIN_API Image { + struct DUIN_API Image + { void* data; // Image raw data int width; // Image base width int height; // Image base height int mipmaps; // Mipmap levels, 1 by default int format; // Data format (PixelFormat type) - } Image; + UUID _uuid; // Base resource UUID + + Image() : data(nullptr), width(0), height(0), mipmaps(1), format(0) {} // Default constructor + + Image(const ::Image& image) // Conversion constructor from raylib::Image + : data(image.data), width(image.width), height(image.height), + mipmaps(image.mipmaps), format(image.format) {} + ::Image ToRaylibImage() const // Method to convert back to raylib::Image + { return { data, width, height, mipmaps, format }; } + }; + // Texture, tex data stored in GPU memory (VRAM) - typedef struct DUIN_API Texture { + struct DUIN_API Texture { unsigned int id; // OpenGL texture id int width; // Texture base width int height; // Texture base height int mipmaps; // Mipmap levels, 1 by default int format; // Data format (PixelFormat type) - } Texture; + UUID _uuid; // Base resource UUID + + Texture() : id(0), width(0), height(0), mipmaps(1), format(0) {} // Default constructor - // Texture2D, same as Texture - typedef Texture Texture2D; + Texture(const ::Texture& texture) // Conversion constructor from raylib::Texture + : id(texture.id), width(texture.width), height(texture.height), + mipmaps(texture.mipmaps), format(texture.format) {} + ::Texture ToRaylibTexture() const // Method to convert back to raylib::Texture + { return { id, width, height, mipmaps, format }; } + }; - // TextureCubemap, same as Texture - typedef Texture TextureCubemap; // RenderTexture, fbo for texture rendering - typedef struct DUIN_API RenderTexture { + struct DUIN_API RenderTexture { unsigned int id; // OpenGL framebuffer object id Texture texture; // Color buffer attachment texture Texture depth; // Depth buffer attachment texture - } RenderTexture; + UUID _uuid; // Base resource UUID + + RenderTexture() : id(0) {} // Default constructor + + RenderTexture(const ::RenderTexture& rt) // Conversion constructor from raylib::RenderTexture + : id(rt.id), texture(Texture(rt.texture)), depth(Texture(rt.depth)) {} + ::RenderTexture ToRaylibRenderTexture() const { // Method to convert back to raylib::RenderTexture + return { id, texture.ToRaylibTexture(), depth.ToRaylibTexture() }; + } + }; + + + // Shader + struct DUIN_API Shader { + unsigned int id; // Shader program id + int* locs; // Shader locations array (RL_MAX_SHADER_LOCATIONS) + + + Shader() : id(0), locs(nullptr) {} // Default constructor + ~Shader() { // Destructor to clean up allocated memory + delete[] locs; + } + + Shader(const ::Shader& shader) // Conversion constructor from raylib::Shader + : id(shader.id) { + locs = new int[32]; + for (int i = 0; i < 32; ++i) { + locs[i] = shader.locs[i]; + } + } + + ::Shader ToRaylibShader() const { // Method to convert back to raylib::Shader + ::Shader shader; + shader.id = id; + shader.locs = locs; + return shader; + } + }; + + + // MaterialMap + struct DUIN_API MaterialMap { + Texture texture; // Material map texture + Color color; // Material map color + float value; // Material map value + + MaterialMap() : value(0.0f) {} // Default constructor + + MaterialMap(const ::MaterialMap& map) // Conversion constructor from raylib::MaterialMap + : texture(Texture(map.texture)), color(map.color), value(map.value) {} + ::MaterialMap ToRaylibMaterialMap() const { // Method to convert back to raylib::MaterialMap + return { texture.ToRaylibTexture(), color.ToRaylibColor(), value }; + } + }; + + + // Material, includes shader and maps + struct DUIN_API Material { + Shader shader; // Material shader + MaterialMap* maps; // Material maps array (MAX_MATERIAL_MAPS) + float params[4]; // Material generic parameters (if required) + + Material() : maps(nullptr) { // Default constructor + std::fill(std::begin(params), std::end(params), 0.0f); + } + + Material(const ::Material& material) // Conversion constructor from raylib::Material + : shader(material.shader), maps(new MaterialMap[32]) { + for (int i = 0; i < 32; ++i) { + maps[i] = MaterialMap(material.maps[i]); + } + std::copy(std::begin(material.params), std::end(material.params), std::begin(params)); + } + + ~Material() { // Destructor to clean up allocated memory + delete[] maps; + } + + ::Material ToRaylibMaterial() const { // Method to convert back to raylib::Material + ::Material material; + material.shader = shader.ToRaylibShader(); + material.maps = (::MaterialMap*)maps; + std::copy(std::begin(params), std::end(params), std::begin(material.params)); + return material; + } + }; - // RenderTexture2D, same as RenderTexture - typedef RenderTexture RenderTexture2D; // NPatchInfo, n-patch layout info - typedef struct DUIN_API NPatchInfo { + struct DUIN_API NPatchInfo { Rectangle source; // Texture source rectangle int left; // Left border offset int top; // Top border offset int right; // Right border offset int bottom; // Bottom border offset int layout; // Layout of the n-patch: 3x3, 1x3 or 3x1 - } NPatchInfo; + + NPatchInfo() : left(0), top(0), right(0), bottom(0), layout(0) {} // Default constructor + + //NPatchInfo(const ::NPatchInfo& npi) // Conversion constructor from raylib::NPatchInfo + // : source(npi.source), left(npi.left), top(npi.top), + // right(npi.right), bottom(npi.bottom), layout(npi.layout) {} + //::NPatchInfo ToRaylibNPatchInfo() const { // Method to convert back to raylib::NPatchInfo + // return { source, left, top, right, bottom, layout }; + }; // GlyphInfo, font characters glyphs info - typedef struct DUIN_API GlyphInfo { + struct DUIN_API GlyphInfo { int value; // Character value (Unicode) int offsetX; // Character offset X when drawing int offsetY; // Character offset Y when drawing int advanceX; // Character advance position X Image image; // Character image data - } GlyphInfo; + + GlyphInfo() : value(0), offsetX(0), offsetY(0), advanceX(0) {} // Default constructor + + GlyphInfo(const ::GlyphInfo& gi) // Conversion constructor from raylib::GlyphInfo + : value(gi.value), offsetX(gi.offsetX), offsetY(gi.offsetY), + advanceX(gi.advanceX), image(Image(gi.image)) {} + ::GlyphInfo ToRaylibGlyphInfo() const { // Method to convert back to raylib::GlyphInfo + return { value, offsetX, offsetY, advanceX, image.ToRaylibImage() }; + } + }; // Font, font texture and GlyphInfo array data - typedef struct DUIN_API Font { + struct DUIN_API Font { int baseSize; // Base size (default chars height) int glyphCount; // Number of glyph characters int glyphPadding; // Padding around the glyph characters Texture2D texture; // Texture atlas containing the glyphs Rectangle* recs; // Rectangles in texture for the glyphs GlyphInfo* glyphs; // Glyphs info data - } Font; + }; // Camera, defines position/orientation in 3d space - typedef struct DUIN_API Camera3D { + struct DUIN_API Camera3D { Vector3 position; // Camera position Vector3 target; // Camera target it looks-at Vector3 up; // Camera up vector (rotation over its axis) float fovy; // Camera field-of-view aperture in Y (degrees) in perspective, used as near plane width in orthographic int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC - } Camera3D; + }; typedef Camera3D Camera; // Camera type fallback, defaults to Camera3D // Camera2D, defines position/orientation in 2d space - typedef struct DUIN_API Camera2D { + struct DUIN_API Camera2D { Vector2 offset; // Camera offset (displacement from target) Vector2 target; // Camera target (rotation and zoom origin) float rotation; // Camera rotation in degrees float zoom; // Camera zoom (scaling), should be 1.0f by default - } Camera2D; + }; // Mesh, vertex data and vao/vbo - typedef struct DUIN_API Mesh { + struct DUIN_API Mesh { int vertexCount; // Number of vertices stored in arrays int triangleCount; // Number of triangles stored (indexed or not) @@ -240,43 +369,23 @@ namespace Duin // OpenGL identifiers unsigned int vaoId; // OpenGL Vertex Array Object id unsigned int* vboId; // OpenGL Vertex Buffer Objects id (default vertex data) - } Mesh; - - // Shader - typedef struct DUIN_API Shader { - unsigned int id; // Shader program id - int* locs; // Shader locations array (RL_MAX_SHADER_LOCATIONS) - } Shader; - - // MaterialMap - typedef struct DUIN_API MaterialMap { - Texture2D texture; // Material map texture - Color color; // Material map color - float value; // Material map value - } MaterialMap; - - // Material, includes shader and maps - typedef struct DUIN_API Material { - Shader shader; // Material shader - MaterialMap* maps; // Material maps array (MAX_MATERIAL_MAPS) - float params[4]; // Material generic parameters (if required) - } Material; + }; // Transform, vertex transformation data - typedef struct DUIN_API Transform { + struct DUIN_API Transform { Vector3 translation; // Translation Quaternion rotation; // Rotation Vector3 scale; // Scale - } Transform; + }; // Bone, skeletal animation bone - typedef struct DUIN_API BoneInfo { + struct DUIN_API BoneInfo { char name[32]; // Bone name int parent; // Bone parent - } BoneInfo; + }; // Model, meshes, materials and animation data - typedef struct DUIN_API Model { + struct DUIN_API Model { Matrix transform; // Local transform matrix int meshCount; // Number of meshes @@ -289,15 +398,15 @@ namespace Duin int boneCount; // Number of bones BoneInfo* bones; // Bones information (skeleton) Transform* bindPose; // Bones base transformation (pose) - } Model; + }; // ModelAnimation - typedef struct DUIN_API ModelAnimation { + struct DUIN_API ModelAnimation { int boneCount; // Number of bones int frameCount; // Number of animation frames BoneInfo* bones; // Bones information (skeleton) Transform** framePoses; // Poses array by frame char name[32]; // Animation name - } ModelAnimation; + }; /*********************************************************************************************/ } \ No newline at end of file diff --git a/ExampleProjects/Astroids/src/Astroids.cpp b/ExampleProjects/Astroids/src/Astroids.cpp index 82b0908..cabf95e 100644 --- a/ExampleProjects/Astroids/src/Astroids.cpp +++ b/ExampleProjects/Astroids/src/Astroids.cpp @@ -32,6 +32,8 @@ Duin::Application* Duin::CreateApplication() { return new Astroids(); } void Astroids::Initialize() { + SetBackgroundColor(Duin::BLACK); + registry = new Duin::Registry(); handlerPlayerInput = new Handler_PlayerInput(registry); handlerPlayerMovement = new Handler_PlayerMovement(registry); @@ -64,7 +66,7 @@ void Astroids::Update(double rDelta) void Astroids::PhysicsUpdate(double pDelta) { - handlerPlayerMovement->Update(); + handlerPlayerMovement->Update(pDelta); handlerUpdateTransform->Update(pDelta); } diff --git a/ExampleProjects/Astroids/src/Components/Components.h b/ExampleProjects/Astroids/src/Components/Components.h index 7ac7eef..a88a7a9 100644 --- a/ExampleProjects/Astroids/src/Components/Components.h +++ b/ExampleProjects/Astroids/src/Components/Components.h @@ -11,10 +11,10 @@ struct Component_AstroidInput struct Component_Movement { - float maxSpeed = 1.0f; - float acceleration = 1.0f; - float brakingSpeed = 0.7f; + float maxLinearSpeed = 25.0f; float maxRotationSpeed = 1.0f; + float accelerationFactor = 3.5f; + float brakingFactor = 1.0f; float currRotation = 0.0f; float currSpeed = 0.0f; @@ -27,7 +27,7 @@ struct Component_Movement Component_Movement() = default; Component_Movement(float maxSpeed, float acceleration) - : maxSpeed(maxSpeed), acceleration(acceleration) + : maxLinearSpeed(maxSpeed), accelerationFactor(acceleration) {} }; @@ -51,6 +51,7 @@ struct Component_Renderable { std::shared_ptr texture; Duin::Vector2 size; + Duin::Color tint = Duin::WHITE; bool pointInInputDir = false; Component_Renderable(std::shared_ptr texture, Duin::Vector2 size) diff --git a/ExampleProjects/Astroids/src/Components/Handlers.h b/ExampleProjects/Astroids/src/Components/Handlers.h index 77168c1..deeee8d 100644 --- a/ExampleProjects/Astroids/src/Components/Handlers.h +++ b/ExampleProjects/Astroids/src/Components/Handlers.h @@ -21,11 +21,11 @@ struct Handler_PlayerInput c_movement.targetSpeed = 0; if (e.IsKeyDown(Duin::KEY_W)) { - c_movement.targetSpeed += c_movement.maxSpeed; + c_movement.targetSpeed += c_movement.maxLinearSpeed; } if (e.IsKeyDown(Duin::KEY_S)) { - c_movement.targetSpeed -= c_movement.brakingSpeed; + c_movement.targetSpeed -= c_movement.maxLinearSpeed * c_movement.brakingFactor; } c_movement.targetRotation = c_movement.currRotation; @@ -53,15 +53,16 @@ struct Handler_PlayerMovement : registry(registry) {} - void Update() + void Update(double delta) { auto view = registry->View(); for (auto [entity, c_pinput, c_movement] : view.each()) { c_movement.prevVelocity = c_movement.currVelocity; - c_movement.currVelocity += c_movement.inputVel * c_movement.acceleration; - c_movement.currVelocity.LimitLength(0.0f, c_movement.maxSpeed); + c_movement.currVelocity += c_movement.inputVel * c_movement.accelerationFactor * delta; + c_movement.currVelocity.LimitLength(0.0f, c_movement.maxLinearSpeed); c_movement.currRotation = c_movement.targetRotation; + c_movement.currSpeed = c_movement.currVelocity.Length(); } } }; diff --git a/ExampleProjects/Astroids/src/Player.cpp b/ExampleProjects/Astroids/src/Player.cpp index a9712bb..9b81cbc 100644 --- a/ExampleProjects/Astroids/src/Player.cpp +++ b/ExampleProjects/Astroids/src/Player.cpp @@ -4,6 +4,8 @@ Player::Player(Duin::Registry* registry) { std::shared_ptr texture = std::make_shared("assets/spaceship.png"); texture->SetCentered(true); + texture->SetTintColor(Duin::BLUE); + entity = Duin::Entity::Create(registry); entity->AddComponent(); entity->AddComponent(); @@ -18,3 +20,7 @@ Player::~Player() void Player::PhysicsUpdate(double pDelta) { } + +void Player::Draw() +{ +} diff --git a/ExampleProjects/Astroids/src/Player.h b/ExampleProjects/Astroids/src/Player.h index 333ace0..eb204d8 100644 --- a/ExampleProjects/Astroids/src/Player.h +++ b/ExampleProjects/Astroids/src/Player.h @@ -13,4 +13,5 @@ class Player : public Duin::Node ~Player(); void PhysicsUpdate(double pDelta) override; + void Draw() override; }; \ No newline at end of file diff --git a/ExampleProjects/Sandbox/src/Components/RenderableCMPManager.h b/ExampleProjects/Sandbox/src/Components/RenderableCMPManager.h index 61263aa..15b7eae 100644 --- a/ExampleProjects/Sandbox/src/Components/RenderableCMPManager.h +++ b/ExampleProjects/Sandbox/src/Components/RenderableCMPManager.h @@ -12,7 +12,7 @@ struct RenderableCMPManager auto view = registry->View(); for (auto [entity, transform, renderable] : view.each()) { - renderable.texture->Draw(transform.position); + renderable.texture->Draw(transform.position, 0); } } }; \ No newline at end of file diff --git a/ExampleProjects/Sandbox/src/Sandbox.cpp b/ExampleProjects/Sandbox/src/Sandbox.cpp index 3cf2378..c98c83c 100644 --- a/ExampleProjects/Sandbox/src/Sandbox.cpp +++ b/ExampleProjects/Sandbox/src/Sandbox.cpp @@ -2,8 +2,8 @@ #include -//#include "SandboxGame.h" -//Duin::Application* Duin::CreateApplication() { return new Sandbox(); } +#include "SandboxGame.h" +Duin::Application* Duin::CreateApplication() { return new Sandbox(); } -#include "DelaunayTest.h" -Duin::Application* Duin::CreateApplication() { return new DelaunayTest(); } \ No newline at end of file +//#include "DelaunayTest.h" +//Duin::Application* Duin::CreateApplication() { return new DelaunayTest(); } \ No newline at end of file