Added mouse support and changed some stuff for ldc and gdc again.

This commit is contained in:
Kapendev 2024-03-08 20:03:44 +02:00
parent ac06401bba
commit dbb8bc905a
7 changed files with 170 additions and 108 deletions

View file

@ -2,11 +2,10 @@
* Work on dialogue system. * Work on dialogue system.
* Work on UI buttons that work like RPGMaker. * Work on UI buttons that work like RPGMaker.
* Test engine on Windows.
# TODO # TODO
* Dialogue functionality in dialogue.d must be implemented.
* UI functionality must be implemented.
* Collision functionality must be implemented. * Collision functionality must be implemented.
* Add more parsing options for fmt.d and strconv.d. * Add more parsing options for fmt.d and strconv.d.
* Write tests. * Write tests.

View file

@ -266,7 +266,9 @@ const(char)* toStrz(const(char)[] str) {
static char[1024] buf = void; static char[1024] buf = void;
auto result = buf[]; auto result = buf[];
result[0 .. str.length] = str; foreach (i, c; str) {
result[i] = c;
}
result[str.length] = '\0'; result[str.length] = '\0';
return result.ptr; return result.ptr;
} }

View file

@ -6,8 +6,11 @@
module popka.core.sumtype; module popka.core.sumtype;
struct None {}; /// The none type.
struct None {}
/// A data structure that can hold one of several possible types.
/// Note that generic types are not currently supported.
struct SumType(A...) { struct SumType(A...) {
template memberName(T) { template memberName(T) {
mixin("enum memberName = \"" ~ ((T.stringof[0] >= 'A' && T.stringof[0] <= 'Z') ? cast(char) (T.stringof[0] + 32) : T.stringof[0]) ~ T.stringof[1 .. $] ~ "\";"); mixin("enum memberName = \"" ~ ((T.stringof[0] >= 'A' && T.stringof[0] <= 'Z') ? cast(char) (T.stringof[0] + 32) : T.stringof[0]) ~ T.stringof[1 .. $] ~ "\";");
@ -61,6 +64,14 @@ struct SumType(A...) {
alias Optional(T) = SumType!(None, T); alias Optional(T) = SumType!(None, T);
bool isNone(T)(T optional) {
return optional.kind == optional.noneKind;
}
bool isSome(T)(T optional) {
return optional.kind != optional.noneKind;
}
bool hasCommonBase(T)() { bool hasCommonBase(T)() {
alias Base = typeof(T.init.data.tupleof[0]); alias Base = typeof(T.init.data.tupleof[0]);
@ -76,7 +87,14 @@ bool hasCommonBase(T)() {
mixin template AddBase(T) { mixin template AddBase(T) {
T base; T base;
alias data this; alias base this;
} }
unittest {} unittest {
auto optional = Optional!int();
assert(optional.isNone);
optional = 69;
assert(optional.isSome);
optional = None();
assert(optional.isNone);
}

View file

@ -566,7 +566,10 @@ bool isWindowOpen() {
popkaFullscreenFlag = false; popkaFullscreenFlag = false;
ray.ToggleFullscreen(); ray.ToggleFullscreen();
if (!isFullscreen) { if (!isFullscreen) {
windowSize(popkaFullscreenLastWindowSize); auto size = popkaFullscreenLastWindowSize;
auto screen = screenSize;
ray.SetWindowSize(cast(int) size.x, cast(int) size.y);
ray.SetWindowPosition(cast(int) (screen.x * 0.5f - size.x * 0.5f), cast(int) (screen.y * 0.5f - size.y * 0.5f));
} }
} }
} }
@ -612,17 +615,25 @@ void toggleFullscreen() {
popkaFullscreenFlag = true; popkaFullscreenFlag = true;
if (!isFullscreen) { if (!isFullscreen) {
popkaFullscreenLastWindowSize = windowSize; popkaFullscreenLastWindowSize = windowSize;
windowSize(screenSize); auto size = screenSize;
auto screen = screenSize;
ray.SetWindowSize(cast(int) size.x, cast(int) size.y);
ray.SetWindowPosition(cast(int) (screen.x * 0.5f - size.x * 0.5f), cast(int) (screen.y * 0.5f - size.y * 0.5f));
} }
} }
} }
Vec2 screenSize(uint id) {
return Vec2(ray.GetMonitorWidth(id), ray.GetMonitorHeight(id));
}
Vec2 screenSize() { Vec2 screenSize() {
return screenSize(ray.GetCurrentMonitor()); auto id = ray.GetCurrentMonitor();
return Vec2(ray.GetMonitorWidth(id), ray.GetMonitorHeight(id));
}
float screenWidth() {
return screenSize.x;
}
float screenHeight() {
return screenSize.y;
} }
Vec2 windowSize() { Vec2 windowSize() {
@ -633,10 +644,12 @@ Vec2 windowSize() {
} }
} }
void windowSize(Vec2 size) { float windowWidth() {
auto screen = screenSize; return windowSize.x;
ray.SetWindowSize(cast(int) size.x, cast(int) size.y); }
ray.SetWindowPosition(cast(int) (screen.x * 0.5f - size.x * 0.5f), cast(int) (screen.y * 0.5f - size.y * 0.5f));
float windowHeight() {
return windowSize.y;
} }
Vec2 resolution() { Vec2 resolution() {
@ -647,6 +660,36 @@ Vec2 resolution() {
} }
} }
float resolutionWidth() {
return resolution.x;
}
float resolutionHeight() {
return resolution.y;
}
Vec2 mousePosition() {
if (isResolutionLocked) {
auto window = windowSize;
auto minRatio = min(window.x / popkaView.width, window.y / popkaView.height);
auto targetSize = popkaView.size * Vec2(minRatio);
return Vec2(
clamp((ray.GetMouseX() - (window.x - targetSize.x) * 0.5f) / minRatio, 0.0f, popkaView.width),
clamp((ray.GetMouseY() - (window.y - targetSize.y) * 0.5f) / minRatio, 0.0f, popkaView.height),
);
} else {
return Vec2(ray.GetMouseX(), ray.GetMouseY());
}
}
float mouseX() {
return mousePosition.x;
}
float mouseY() {
return mousePosition.y;
}
int fps() { int fps() {
return ray.GetFPS(); return ray.GetFPS();
} }

98
vendor/ray/raylib.d vendored
View file

@ -175,25 +175,25 @@ enum RAYWHITE = Color( 245, 245, 245, 255 ); // My own White (raylib logo)
// Vector2, 2 components // Vector2, 2 components
struct Vector2 struct Vector2
{ {
float x; // Vector x component float x = 0.0f; // Vector x component
float y; // Vector y component float y = 0.0f; // Vector y component
} }
// Vector3, 3 components // Vector3, 3 components
struct Vector3 struct Vector3
{ {
float x; // Vector x component float x = 0.0f; // Vector x component
float y; // Vector y component float y = 0.0f; // Vector y component
float z; // Vector z component float z = 0.0f; // Vector z component
} }
// Vector4, 4 components // Vector4, 4 components
struct Vector4 struct Vector4
{ {
float x; // Vector x component float x = 0.0f; // Vector x component
float y; // Vector y component float y = 0.0f; // Vector y component
float z; // Vector z component float z = 0.0f; // Vector z component
float w; // Vector w component float w = 0.0f; // Vector w component
} }
// Quaternion, 4 components (Vector4 alias) // Quaternion, 4 components (Vector4 alias)
@ -202,22 +202,22 @@ alias Quaternion = Vector4;
// Matrix, 4x4 components, column major, OpenGL style, right-handed // Matrix, 4x4 components, column major, OpenGL style, right-handed
struct Matrix struct Matrix
{ {
float m0; float m0 = 0.0f;
float m4; float m4 = 0.0f;
float m8; float m8 = 0.0f;
float m12; // Matrix first row (4 components) float m12 = 0.0f; // Matrix first row (4 components)
float m1; float m1 = 0.0f;
float m5; float m5 = 0.0f;
float m9; float m9 = 0.0f;
float m13; // Matrix second row (4 components) float m13 = 0.0f; // Matrix second row (4 components)
float m2; float m2 = 0.0f;
float m6; float m6 = 0.0f;
float m10; float m10 = 0.0f;
float m14; // Matrix third row (4 components) float m14 = 0.0f; // Matrix third row (4 components)
float m3; float m3 = 0.0f;
float m7; float m7 = 0.0f;
float m11; float m11 = 0.0f;
float m15; // Matrix fourth row (4 components) float m15 = 0.0f; // Matrix fourth row (4 components)
} }
// Color, 4 components, R8G8B8A8 (32bit) // Color, 4 components, R8G8B8A8 (32bit)
@ -232,10 +232,10 @@ struct Color
// Rectangle, 4 components // Rectangle, 4 components
struct Rectangle struct Rectangle
{ {
float x; // Rectangle top-left corner position x float x = 0.0f; // Rectangle top-left corner position x
float y; // Rectangle top-left corner position y float y = 0.0f; // Rectangle top-left corner position y
float width; // Rectangle width float width = 0.0f; // Rectangle width
float height; // Rectangle height float height = 0.0f; // Rectangle height
} }
// Image, pixel data stored in CPU memory (RAM) // Image, pixel data stored in CPU memory (RAM)
@ -313,7 +313,7 @@ struct Camera3D
Vector3 position; // Camera position Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis) 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 float fovy = 0.0f; // 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 int projection; // Camera projection: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} }
@ -324,8 +324,8 @@ struct Camera2D
{ {
Vector2 offset; // Camera offset (displacement from target) Vector2 offset; // Camera offset (displacement from target)
Vector2 target; // Camera target (rotation and zoom origin) Vector2 target; // Camera target (rotation and zoom origin)
float rotation; // Camera rotation in degrees float rotation = 0.0f; // Camera rotation in degrees
float zoom; // Camera zoom (scaling), should be 1.0f by default float zoom = 0.0f; // Camera zoom (scaling), should be 1.0f by default
} }
// Mesh, vertex data and vao/vbo // Mesh, vertex data and vao/vbo
@ -366,7 +366,7 @@ struct MaterialMap
{ {
Texture2D texture; // Material map texture Texture2D texture; // Material map texture
Color color; // Material map color Color color; // Material map color
float value; // Material map value float value = 0.0f; // Material map value
} }
// Material, includes shader and maps // Material, includes shader and maps
@ -374,7 +374,7 @@ struct Material
{ {
Shader shader; // Material shader Shader shader; // Material shader
MaterialMap* maps; // Material maps array (MAX_MATERIAL_MAPS) MaterialMap* maps; // Material maps array (MAX_MATERIAL_MAPS)
float[4] params; // Material generic parameters (if required) float[4] params = [0.0f, 0.0f, 0.0f, 0.0f]; // Material generic parameters (if required)
} }
// Transform, vertex transformation data // Transform, vertex transformation data
@ -430,7 +430,7 @@ struct Ray
struct RayCollision struct RayCollision
{ {
bool hit; // Did the ray hit something? bool hit; // Did the ray hit something?
float distance; // Distance to the nearest hit float distance = 0.0f; // Distance to the nearest hit
Vector3 point; // Point of the nearest hit Vector3 point; // Point of the nearest hit
Vector3 normal; // Surface normal of hit Vector3 normal; // Surface normal of hit
} }
@ -491,14 +491,14 @@ struct VrDeviceInfo
{ {
int hResolution; // Horizontal resolution in pixels int hResolution; // Horizontal resolution in pixels
int vResolution; // Vertical resolution in pixels int vResolution; // Vertical resolution in pixels
float hScreenSize; // Horizontal size in meters float hScreenSize = 0.0f; // Horizontal size in meters
float vScreenSize; // Vertical size in meters float vScreenSize = 0.0f; // Vertical size in meters
float vScreenCenter; // Screen center in meters float vScreenCenter = 0.0f; // Screen center in meters
float eyeToScreenDistance; // Distance between eye and display in meters float eyeToScreenDistance = 0.0f; // Distance between eye and display in meters
float lensSeparationDistance; // Lens separation distance in meters float lensSeparationDistance = 0.0f; // Lens separation distance in meters
float interpupillaryDistance; // IPD (distance between pupils) in meters float interpupillaryDistance = 0.0f; // IPD (distance between pupils) in meters
float[4] lensDistortionValues; // Lens distortion constant parameters float[4] lensDistortionValues = [0.0f, 0.0f, 0.0f, 0.0f]; // Lens distortion constant parameters
float[4] chromaAbCorrection; // Chromatic aberration correction parameters float[4] chromaAbCorrection = [0.0f, 0.0f, 0.0f, 0.0f]; // Chromatic aberration correction parameters
} }
// VrStereoConfig, VR stereo rendering configuration for simulator // VrStereoConfig, VR stereo rendering configuration for simulator
@ -506,12 +506,12 @@ struct VrStereoConfig
{ {
Matrix[2] projection; // VR projection matrices (per eye) Matrix[2] projection; // VR projection matrices (per eye)
Matrix[2] viewOffset; // VR view offset matrices (per eye) Matrix[2] viewOffset; // VR view offset matrices (per eye)
float[2] leftLensCenter; // VR left lens center float[2] leftLensCenter = [0.0f, 0.0f]; // VR left lens center
float[2] rightLensCenter; // VR right lens center float[2] rightLensCenter = [0.0f, 0.0f]; // VR right lens center
float[2] leftScreenCenter; // VR left screen center float[2] leftScreenCenter = [0.0f, 0.0f]; // VR left screen center
float[2] rightScreenCenter; // VR right screen center float[2] rightScreenCenter = [0.0f, 0.0f]; // VR right screen center
float[2] scale; // VR distortion scale float[2] scale = [0.0f, 0.0f]; // VR distortion scale
float[2] scaleIn; // VR distortion scale in float[2] scaleIn = [0.0f, 0.0f]; // VR distortion scale in
} }
// File path list // File path list

54
vendor/ray/raymath.d vendored
View file

@ -98,25 +98,25 @@ extern (D) auto Vector3ToFloat(T)(auto ref T vec)
// Vector2 type // Vector2 type
struct Vector2 struct Vector2
{ {
float x; float x = 0.0f;
float y; float y = 0.0f;
} }
// Vector3 type // Vector3 type
struct Vector3 struct Vector3
{ {
float x; float x = 0.0f;
float y; float y = 0.0f;
float z; float z = 0.0f;
} }
// Vector4 type // Vector4 type
struct Vector4 struct Vector4
{ {
float x; float x = 0.0f;
float y; float y = 0.0f;
float z; float z = 0.0f;
float w; float w = 0.0f;
} }
// Quaternion type // Quaternion type
@ -125,33 +125,33 @@ alias Quaternion = Vector4;
// Matrix type (OpenGL style 4x4 - right handed, column major) // Matrix type (OpenGL style 4x4 - right handed, column major)
struct Matrix struct Matrix
{ {
float m0; float m0 = 0.0f;
float m4; float m4 = 0.0f;
float m8; float m8 = 0.0f;
float m12; // Matrix first row (4 components) float m12 = 0.0f; // Matrix first row (4 components)
float m1; float m1 = 0.0f;
float m5; float m5 = 0.0f;
float m9; float m9 = 0.0f;
float m13; // Matrix second row (4 components) float m13 = 0.0f; // Matrix second row (4 components)
float m2; float m2 = 0.0f;
float m6; float m6 = 0.0f;
float m10; float m10 = 0.0f;
float m14; // Matrix third row (4 components) float m14 = 0.0f; // Matrix third row (4 components)
float m3; float m3 = 0.0f;
float m7; float m7 = 0.0f;
float m11; float m11 = 0.0f;
float m15; // Matrix fourth row (4 components) float m15 = 0.0f; // Matrix fourth row (4 components)
} }
// NOTE: Helper types to be used instead of array return types for *ToFloat functions // NOTE: Helper types to be used instead of array return types for *ToFloat functions
struct float3 struct float3
{ {
float[3] v; float[3] v = [0.0f, 0.0f, 0.0f];
} }
struct float16 struct float16
{ {
float[16] v; float[16] v = [0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f];
} }
// Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabs() // Required for: sinf(), cosf(), tan(), atan2f(), sqrtf(), floor(), fminf(), fmaxf(), fabs()

34
vendor/ray/rlgl.d vendored
View file

@ -272,22 +272,22 @@ enum RL_BLEND_COLOR = 0x8005; // GL_BLEND_COLOR
// Matrix, 4x4 components, column major, OpenGL style, right handed // Matrix, 4x4 components, column major, OpenGL style, right handed
struct Matrix struct Matrix
{ {
float m0; float m0 = 0.0f;
float m4; float m4 = 0.0f;
float m8; float m8 = 0.0f;
float m12; // Matrix first row (4 components) float m12 = 0.0f; // Matrix first row (4 components)
float m1; float m1 = 0.0f;
float m5; float m5 = 0.0f;
float m9; float m9 = 0.0f;
float m13; // Matrix second row (4 components) float m13 = 0.0f; // Matrix second row (4 components)
float m2; float m2 = 0.0f;
float m6; float m6 = 0.0f;
float m10; float m10 = 0.0f;
float m14; // Matrix third row (4 components) float m14 = 0.0f; // Matrix third row (4 components)
float m3; float m3 = 0.0f;
float m7; float m7 = 0.0f;
float m11; float m11 = 0.0f;
float m15; // Matrix fourth row (4 components) float m15 = 0.0f; // Matrix fourth row (4 components)
} }
// Dynamic vertex buffers (position + texcoords + colors + indices arrays) // Dynamic vertex buffers (position + texcoords + colors + indices arrays)
@ -333,7 +333,7 @@ struct rlRenderBatch
rlDrawCall* draws; // Draw calls array, depends on textureId rlDrawCall* draws; // Draw calls array, depends on textureId
int drawCounter; // Draw calls counter int drawCounter; // Draw calls counter
float currentDepth; // Current depth value for next draw float currentDepth = 0.0f; // Current depth value for next draw
} }
// OpenGL version // OpenGL version