Add project files.

This commit is contained in:
alejo committed 2026-10-25 03:29:04 -03:00
commit a9ae435321
52 files changed
+65378

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# Headless editor logic tests
Runs the editor's real command / picking / camera / tool code (`editor.cpp`, `viewport.cpp`, `render.cpp`)
against **no-op raylib and Dear ImGui back-ends** (`stubs/` + `impl.cpp`), driving it with a scripted mouse.
No GPU or window needed, so it also works in CI.
cmake -B build -DHPP_BUILD_EDITOR_LOGIC_TESTS=ON && cmake --build build --target test_editor_logic
ctest --test-dir build -R editor_logic --output-on-failure
Linux + GNU ld/lld only (it links with `--unresolved-symbols=ignore-all` so UI-only code paths may stay
unresolved). The stubs mirror the raylib 5.5 / ImGui 1.91 signatures the editor uses; they are not a
re-implementation - they only exist so this code can be compiled and exercised without the real libraries.
+24
View File
@@ -0,0 +1,24 @@
// No-op raylib / ImGui back-ends + scripted mouse state so the editor's logic can run headless.
#include <cstdarg>
#include <cstdlib>
#include <cstdio>
#include "raylib.h"
#include "imgui.h"
#include "rlgl.h"
void *MemAlloc(unsigned int size) { return calloc(1, size); }
void MemFree(void *p) { free(p); }
void UploadMesh(Mesh *, bool) {}
void UnloadMesh(Mesh m) { MemFree(m.vertices); MemFree(m.texcoords); MemFree(m.normals); MemFree(m.colors); }
bool FileExists(const char *) { return false; }
bool DirectoryExists(const char *) { return false; }
void TraceLog(int, const char *, ...) {}
static ImGuiIO g_io;
bool g_down[3], g_clicked[3], g_released[3];
ImGuiIO &ImGui::GetIO() { return g_io; }
bool ImGui::IsMouseDown(ImGuiMouseButton b) { return g_down[b]; }
bool ImGui::IsMouseClicked(ImGuiMouseButton b, bool) { return g_clicked[b]; }
bool ImGui::IsMouseReleased(ImGuiMouseButton b) { return g_released[b]; }
bool ImGui::IsKeyDown(ImGuiKey) { return false; }
bool ImGui::IsKeyPressed(ImGuiKey, bool) { return false; }
+98
View File
@@ -0,0 +1,98 @@
// Minimal stand-in for Dear ImGui 1.91 docking (declarations only)
#pragma once
#include <stddef.h>
#define IMGUI_VERSION_NUM 19100
#ifndef STUB_NO_DOCK
#define IMGUI_HAS_DOCK 1
#endif
#define IM_ARRAYSIZE(_ARR) ((int)(sizeof(_ARR) / sizeof(*(_ARR))))
#define IM_COL32(R, G, B, A) (((unsigned)(A) << 24) | ((unsigned)(B) << 16) | ((unsigned)(G) << 8) | ((unsigned)(R)))
typedef unsigned int ImGuiID; typedef unsigned int ImU32;
typedef int ImGuiCol, ImGuiCond, ImGuiDir, ImGuiKey, ImGuiMouseButton, ImGuiStyleVar, ImGuiButtonFlags, ImGuiColorEditFlags, ImGuiConfigFlags,
ImGuiInputTextFlags, ImGuiSelectableFlags, ImGuiTreeNodeFlags, ImGuiWindowFlags, ImGuiChildFlags, ImGuiDockNodeFlags, ImGuiComboFlags,
ImGuiHoveredFlags, ImGuiSliderFlags, ImGuiPopupFlags, ImGuiTabBarFlags, ImGuiTabItemFlags;
struct ImGuiInputTextCallbackData; typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
struct ImVec2 { float x, y; constexpr ImVec2() : x(0), y(0) {} constexpr ImVec2(float _x, float _y) : x(_x), y(_y) {} };
struct ImVec4 { float x, y, z, w; constexpr ImVec4() : x(0), y(0), z(0), w(0) {} constexpr ImVec4(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) {} };
enum { ImGuiCol_Text, ImGuiCol_TextDisabled, ImGuiCol_WindowBg, ImGuiCol_ChildBg, ImGuiCol_PopupBg, ImGuiCol_Border, ImGuiCol_BorderShadow,
ImGuiCol_FrameBg, ImGuiCol_FrameBgHovered, ImGuiCol_FrameBgActive, ImGuiCol_TitleBg, ImGuiCol_TitleBgActive, ImGuiCol_TitleBgCollapsed,
ImGuiCol_MenuBarBg, ImGuiCol_ScrollbarBg, ImGuiCol_ScrollbarGrab, ImGuiCol_CheckMark, ImGuiCol_SliderGrab, ImGuiCol_SliderGrabActive,
ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive, ImGuiCol_Header, ImGuiCol_HeaderHovered, ImGuiCol_HeaderActive,
ImGuiCol_Separator, ImGuiCol_ResizeGrip, ImGuiCol_ResizeGripHovered, ImGuiCol_Tab, ImGuiCol_TabHovered, ImGuiCol_TabSelected,
ImGuiCol_DockingPreview, ImGuiCol_COUNT };
enum { ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize };
enum { ImGuiWindowFlags_None = 0, ImGuiWindowFlags_NoTitleBar = 1, ImGuiWindowFlags_NoResize = 2, ImGuiWindowFlags_NoMove = 4, ImGuiWindowFlags_NoScrollbar = 8,
ImGuiWindowFlags_NoScrollWithMouse = 16, ImGuiWindowFlags_NoCollapse = 32, ImGuiWindowFlags_AlwaysAutoResize = 64, ImGuiWindowFlags_MenuBar = 1 << 10,
ImGuiWindowFlags_NoBringToFrontOnFocus = 1 << 13, ImGuiWindowFlags_NoNavFocus = 1 << 19, ImGuiWindowFlags_NoDocking = 1 << 21 };
enum { ImGuiCond_Appearing = 8, ImGuiCond_FirstUseEver = 4 };
enum { ImGuiDir_Left = 0, ImGuiDir_Right = 1, ImGuiDir_Up = 2, ImGuiDir_Down = 3 };
enum { ImGuiDockNodeFlags_None = 0 };
enum { ImGuiConfigFlags_DockingEnable = 1 << 7 };
enum { ImGuiMouseButton_Left = 0, ImGuiMouseButton_Right = 1, ImGuiMouseButton_Middle = 2 };
enum { ImGuiButtonFlags_MouseButtonLeft = 1, ImGuiButtonFlags_MouseButtonRight = 2, ImGuiButtonFlags_MouseButtonMiddle = 4 };
enum { ImGuiColorEditFlags_NoInputs = 1, ImGuiColorEditFlags_NoTooltip = 2, ImGuiColorEditFlags_NoPicker = 4, ImGuiColorEditFlags_PickerHueWheel = 8 };
enum { ImGuiInputTextFlags_EnterReturnsTrue = 32 };
enum { ImGuiSelectableFlags_AllowDoubleClick = 4 };
enum { ImGuiTreeNodeFlags_DefaultOpen = 32 };
enum { ImGuiKey_None = 0, ImGuiKey_Tab = 512, ImGuiKey_Delete, ImGuiKey_Enter, ImGuiKey_Escape, ImGuiKey_LeftBracket, ImGuiKey_RightBracket,
ImGuiKey_1, ImGuiKey_2, ImGuiKey_3, ImGuiKey_4, ImGuiKey_A, ImGuiKey_D, ImGuiKey_E, ImGuiKey_F, ImGuiKey_G, ImGuiKey_H, ImGuiKey_N, ImGuiKey_O,
ImGuiKey_Q, ImGuiKey_S, ImGuiKey_T, ImGuiKey_W, ImGuiKey_Y, ImGuiKey_Z, ImGuiKey_F1, ImGuiKey_F9 };
struct ImGuiIO {
ImGuiConfigFlags ConfigFlags; const char *IniFilename; bool ConfigWindowsMoveFromTitleBarOnly; float DeltaTime;
ImVec2 MousePos, MouseDelta; float MouseWheel; bool MouseDown[5]; bool KeyCtrl, KeyShift, KeyAlt, KeySuper; bool WantTextInput;
};
struct ImGuiStyle {
float WindowRounding, ChildRounding, FrameRounding, PopupRounding, ScrollbarRounding, GrabRounding, TabRounding, WindowBorderSize, FrameBorderSize, ScrollbarSize;
ImVec2 WindowPadding, FramePadding, ItemSpacing; ImVec4 Colors[ImGuiCol_COUNT];
};
struct ImGuiViewport { ImVec2 WorkPos, WorkSize; };
struct ImDrawList { void AddText(const ImVec2 &pos, ImU32 col, const char *text_begin, const char *text_end = nullptr); };
struct ImGuiTextFilter { bool Draw(const char *label = "Filter (inc,-exc)", float width = 0.0f); bool PassFilter(const char *text, const char *text_end = nullptr) const; bool IsActive() const; };
struct ImGuiListClipper { int DisplayStart, DisplayEnd; void Begin(int items_count, float items_height = -1.0f); bool Step(); };
namespace ImGui {
ImGuiIO &GetIO(); ImGuiStyle &GetStyle(); ImGuiViewport *GetMainViewport();
bool Begin(const char *name, bool *p_open = nullptr, ImGuiWindowFlags flags = 0); void End();
bool BeginChild(const char *str_id, const ImVec2 &size = ImVec2(0, 0), ImGuiChildFlags child_flags = 0, ImGuiWindowFlags window_flags = 0); void EndChild();
void SetNextWindowPos(const ImVec2 &pos, ImGuiCond cond = 0, const ImVec2 &pivot = ImVec2(0, 0));
void SetNextWindowSize(const ImVec2 &size, ImGuiCond cond = 0);
ImVec2 GetContentRegionAvail(); ImDrawList *GetWindowDrawList(); float GetWindowWidth();
float GetScrollY(); float GetScrollMaxY(); void SetScrollHereY(float center_y_ratio = 0.5f);
void PushStyleColor(ImGuiCol idx, ImU32 col); void PushStyleColor(ImGuiCol idx, const ImVec4 &col); void PopStyleColor(int count = 1);
void PushStyleVar(ImGuiStyleVar idx, float val); void PushStyleVar(ImGuiStyleVar idx, const ImVec2 &val); void PopStyleVar(int count = 1);
const ImVec4 &GetStyleColorVec4(ImGuiCol idx);
void SetNextItemWidth(float item_width);
void Separator(); void SameLine(float offset_from_start_x = 0.0f, float spacing = -1.0f); void Spacing(); void BeginGroup(); void EndGroup();
void SetCursorPos(const ImVec2 &local_pos); void SetCursorScreenPos(const ImVec2 &pos); float GetFrameHeightWithSpacing();
void Text(const char *fmt, ...); void TextColored(const ImVec4 &col, const char *fmt, ...); void TextDisabled(const char *fmt, ...);
void TextWrapped(const char *fmt, ...); void TextUnformatted(const char *text, const char *text_end = nullptr); void BulletText(const char *fmt, ...);
void SeparatorText(const char *label);
bool Button(const char *label, const ImVec2 &size = ImVec2(0, 0)); bool SmallButton(const char *label);
bool InvisibleButton(const char *str_id, const ImVec2 &size, ImGuiButtonFlags flags = 0);
bool Checkbox(const char *label, bool *v);
bool Combo(const char *label, int *current_item, const char *const items[], int items_count, int popup_max_height_in_items = -1);
bool Combo(const char *label, int *current_item, const char *items_separated_by_zeros, int popup_max_height_in_items = -1);
bool DragFloat(const char *label, float *v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char *format = "%.3f", ImGuiSliderFlags flags = 0);
bool DragFloat2(const char *label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char *format = "%.3f", ImGuiSliderFlags flags = 0);
bool DragFloat3(const char *label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char *format = "%.3f", ImGuiSliderFlags flags = 0);
bool DragInt(const char *label, int *v, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char *format = "%d", ImGuiSliderFlags flags = 0);
bool SliderInt(const char *label, int *v, int v_min, int v_max, const char *format = "%d", ImGuiSliderFlags flags = 0);
bool InputInt(const char *label, int *v, int step = 1, int step_fast = 100, ImGuiInputTextFlags flags = 0);
bool ColorEdit3(const char *label, float col[3], ImGuiColorEditFlags flags = 0);
bool ColorButton(const char *desc_id, const ImVec4 &col, ImGuiColorEditFlags flags = 0, const ImVec2 &size = ImVec2(0, 0));
bool BeginCombo(const char *label, const char *preview_value, ImGuiComboFlags flags = 0); void EndCombo();
bool Selectable(const char *label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2 &size = ImVec2(0, 0));
bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags = 0); bool TreeNode(const char *label); void TreePop();
bool BeginMenuBar(); void EndMenuBar(); bool BeginMenu(const char *label, bool enabled = true); void EndMenu();
bool MenuItem(const char *label, const char *shortcut = nullptr, bool selected = false, bool enabled = true);
bool MenuItem(const char *label, const char *shortcut, bool *p_selected, bool enabled = true);
void SetTooltip(const char *fmt, ...);
bool BeginPopupModal(const char *name, bool *p_open = nullptr, ImGuiWindowFlags flags = 0); void EndPopup(); void OpenPopup(const char *str_id, ImGuiPopupFlags popup_flags = 0);
void CloseCurrentPopup(); bool BeginPopupContextItem(const char *str_id = nullptr, ImGuiPopupFlags popup_flags = 1);
bool BeginTabBar(const char *str_id, ImGuiTabBarFlags flags = 0); void EndTabBar(); bool BeginTabItem(const char *label, bool *p_open = nullptr, ImGuiTabItemFlags flags = 0); void EndTabItem();
void PushID(const char *str_id); void PushID(const char *str_id_begin, const char *str_id_end); void PushID(const void *ptr_id); void PushID(int int_id); void PopID(); ImGuiID GetID(const char *str_id);
bool IsItemHovered(ImGuiHoveredFlags flags = 0); bool IsItemActive(); bool IsAnyItemActive(); ImVec2 GetItemRectMin();
bool IsKeyDown(ImGuiKey key); bool IsKeyPressed(ImGuiKey key, bool repeat = true);
bool IsMouseDown(ImGuiMouseButton button); bool IsMouseClicked(ImGuiMouseButton button, bool repeat = false); bool IsMouseReleased(ImGuiMouseButton button); bool IsMouseDoubleClicked(ImGuiMouseButton button);
void ShowDemoWindow(bool *p_open = nullptr);
ImGuiID DockSpace(ImGuiID dockspace_id, const ImVec2 &size = ImVec2(0, 0), ImGuiDockNodeFlags flags = 0, const void *window_class = nullptr);
}
@@ -0,0 +1,13 @@
#pragma once
#include "imgui.h"
struct ImGuiDockNode;
enum ImGuiDockNodeFlagsPrivate_ { ImGuiDockNodeFlags_DockSpace = 1 << 10 };
namespace ImGui {
ImGuiDockNode *DockBuilderGetNode(ImGuiID node_id);
void DockBuilderRemoveNode(ImGuiID node_id);
ImGuiID DockBuilderAddNode(ImGuiID node_id = 0, ImGuiDockNodeFlags flags = 0);
void DockBuilderSetNodeSize(ImGuiID node_id, ImVec2 size);
ImGuiID DockBuilderSplitNode(ImGuiID node_id, ImGuiDir split_dir, float size_ratio_for_node_at_dir, ImGuiID *out_id_at_dir, ImGuiID *out_id_at_opposite_dir);
void DockBuilderDockWindow(const char *window_name, ImGuiID node_id);
void DockBuilderFinish(ImGuiID node_id);
}
@@ -0,0 +1,7 @@
#pragma once
#include <string>
#include "imgui.h"
namespace ImGui {
bool InputText(const char *label, std::string *str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void *user_data = nullptr);
bool InputTextWithHint(const char *label, const char *hint, std::string *str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void *user_data = nullptr);
}
+103
View File
@@ -0,0 +1,103 @@
// Minimal stand-in for raylib 5.5 (declarations only; used for -fsyntax-only checking)
#pragma once
#include <stdbool.h>
#include <stdarg.h>
typedef struct Vector2 { float x, y; } Vector2;
typedef struct Vector3 { float x, y, z; } Vector3;
typedef struct Vector4 { float x, y, z, w; } Vector4;
typedef struct Matrix { float m0, m4, m8, m12, m1, m5, m9, m13, m2, m6, m10, m14, m3, m7, m11, m15; } Matrix;
typedef struct Color { unsigned char r, g, b, a; } Color;
typedef struct Rectangle { float x, y, width, height; } Rectangle;
typedef struct Image { void *data; int width, height, mipmaps, format; } Image;
typedef struct Texture { unsigned int id; int width, height, mipmaps, format; } Texture;
typedef Texture Texture2D;
typedef struct RenderTexture { unsigned int id; Texture texture; Texture depth; } RenderTexture;
typedef RenderTexture RenderTexture2D;
typedef struct Camera3D { Vector3 position, target, up; float fovy; int projection; } Camera3D;
typedef Camera3D Camera;
typedef struct BoundingBox { Vector3 min, max; } BoundingBox;
typedef struct Shader { unsigned int id; int *locs; } Shader;
typedef struct MaterialMap { Texture2D texture; Color color; float value; } MaterialMap;
typedef struct Material { Shader shader; MaterialMap *maps; float params[4]; } Material;
typedef struct Mesh {
int vertexCount, triangleCount;
float *vertices, *texcoords, *texcoords2, *normals, *tangents;
unsigned char *colors; unsigned short *indices;
float *animVertices, *animNormals; unsigned char *boneIds; float *boneWeights; Matrix *boneMatrices; int boneCount;
unsigned int vaoId; unsigned int *vboId;
} Mesh;
typedef struct Model {
Matrix transform; int meshCount, materialCount; Mesh *meshes; Material *materials; int *meshMaterial;
int boneCount; void *bones; void *bindPose;
} Model;
#define WHITE Color{255,255,255,255}
#define YELLOW Color{253,249,0,255}
#define SKYBLUE Color{102,191,255,255}
#define RAYWHITE Color{245,245,245,255}
#define RED Color{230,41,55,255}
typedef enum { FLAG_VSYNC_HINT = 0x40, FLAG_WINDOW_RESIZABLE = 0x04, FLAG_MSAA_4X_HINT = 0x20 } ConfigFlags;
typedef enum { LOG_ALL = 0, LOG_INFO = 3 } TraceLogLevel;
typedef enum { KEY_NULL = 0, KEY_W = 87, KEY_A = 65, KEY_S = 83, KEY_D = 68, KEY_LEFT_SHIFT = 340 } KeyboardKey;
typedef enum { MOUSE_BUTTON_LEFT = 0, MOUSE_BUTTON_RIGHT = 1 } MouseButton;
typedef enum { CAMERA_PERSPECTIVE = 0, CAMERA_ORTHOGRAPHIC } CameraProjection;
typedef enum { MATERIAL_MAP_ALBEDO = 0, MATERIAL_MAP_DIFFUSE = 0 } MaterialMapIndex;
typedef enum { SHADER_UNIFORM_FLOAT = 0, SHADER_UNIFORM_VEC2, SHADER_UNIFORM_VEC3, SHADER_UNIFORM_VEC4, SHADER_UNIFORM_INT } ShaderUniformDataType;
typedef enum { TEXTURE_FILTER_POINT = 0, TEXTURE_FILTER_BILINEAR, TEXTURE_FILTER_TRILINEAR } TextureFilter;
typedef enum { TEXTURE_WRAP_REPEAT = 0 } TextureWrap;
void InitWindow(int width, int height, const char *title);
void CloseWindow(void);
bool WindowShouldClose(void);
void SetConfigFlags(unsigned int flags);
void SetWindowMinSize(int width, int height);
void SetExitKey(int key);
void BeginDrawing(void); void EndDrawing(void);
void ClearBackground(Color color);
void BeginMode3D(Camera3D camera); void EndMode3D(void);
void BeginTextureMode(RenderTexture2D target); void EndTextureMode(void);
RenderTexture2D LoadRenderTexture(int width, int height);
void UnloadRenderTexture(RenderTexture2D target);
Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode);
void UnloadShader(Shader shader);
int GetShaderLocation(Shader shader, const char *uniformName);
void SetShaderValue(Shader shader, int locIndex, const void *value, int uniformType);
void SetShaderValueV(Shader shader, int locIndex, const void *value, int uniformType, int count);
Material LoadMaterialDefault(void);
Model LoadModel(const char *fileName);
void UnloadModel(Model model);
BoundingBox GetModelBoundingBox(Model model);
void UploadMesh(Mesh *mesh, bool dynamic);
void UnloadMesh(Mesh mesh);
void DrawMesh(Mesh mesh, Material material, Matrix transform);
Texture2D LoadTexture(const char *fileName);
Texture2D LoadTextureFromImage(Image image);
void UnloadTexture(Texture2D texture);
void UnloadImage(Image image);
Image GenImageChecked(int width, int height, int checksX, int checksY, Color col1, Color col2);
void GenTextureMipmaps(Texture2D *texture);
void SetTextureFilter(Texture2D texture, int filter);
void SetTextureWrap(Texture2D texture, int wrap);
bool FileExists(const char *fileName);
bool DirectoryExists(const char *dirPath);
const char *GetApplicationDirectory(void);
char *LoadFileText(const char *fileName);
void UnloadFileText(char *text);
void TraceLog(int logLevel, const char *text, ...);
void *MemAlloc(unsigned int size);
void MemFree(void *ptr);
void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color);
void DrawCircle(int centerX, int centerY, float radius, Color color);
void DrawRectangle(int posX, int posY, int width, int height, Color color);
void DrawRectangleLines(int posX, int posY, int width, int height, Color color);
void DrawText(const char *text, int posX, int posY, int fontSize, Color color);
void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color);
void DrawCube(Vector3 position, float width, float height, float length, Color color);
void DrawCubeWires(Vector3 position, float width, float height, float length, Color color);
void DrawCylinderEx(Vector3 startPos, Vector3 endPos, float startRadius, float endRadius, int sides, Color color);
void DrawSphere(Vector3 centerPos, float radius, Color color);
void SetTargetFPS(int fps);
float GetFrameTime(void);
int GetFPS(void);
Vector2 GetMouseDelta(void);
bool IsMouseButtonDown(int button);
bool IsKeyDown(int key);
const char *TextFormat(const char *text, ...);
+4
View File
@@ -0,0 +1,4 @@
#pragma once
#include "raylib.h"
Matrix MatrixIdentity(void);
Matrix MatrixMultiply(Matrix left, Matrix right);
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include "raylib.h"
#include "imgui.h"
void rlImGuiSetup(bool darkTheme); void rlImGuiBegin(void); void rlImGuiEnd(void); void rlImGuiShutdown(void);
void rlImGuiImageRenderTexture(const RenderTexture *image);
bool rlImGuiImageButtonSize(const char *name, const Texture *image, ImVec2 size);
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include "raylib.h"
#define RL_LINES 0x0001
void rlBegin(int mode); void rlEnd(void);
void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
void rlVertex3f(float x, float y, float z);
void rlEnableDepthTest(void); void rlDisableDepthTest(void);
void rlEnableBackfaceCulling(void); void rlDisableBackfaceCulling(void);
void rlDrawRenderBatchActive(void);
void rlSetClipPlanes(double nearPlane, double farPlane);
unsigned int rlGetShaderIdDefault(void);
int *rlGetShaderLocsDefault(void);
+324
View File
@@ -0,0 +1,324 @@
#include <cmath>
#include <cstdio>
#include <cstring>
#include "editor.h"
using namespace hpp;
extern bool g_down[3], g_clicked[3], g_released[3];
static int fails = 0, checks = 0;
#define CHECK(c) do { ++checks; if (!(c)) { ++fails; std::printf(" FAIL line %d: %s\n", __LINE__, #c); } } while (0)
#define NEAR(a, b, eps) CHECK(std::fabs((double)(a) - (double)(b)) < (eps))
static void setupViews(Editor& ed) {
const ViewKind kinds[4] = {ViewKind::Persp, ViewKind::Top, ViewKind::Front, ViewKind::Side};
for (int i = 0; i < 4; ++i) { ed.views[i].kind = kinds[i]; ed.views[i].w = 800; ed.views[i].h = 600; ed.views[i].hovered = true; ed.views[i].zoom = 1.0f; }
ed.views[0].pos = {0, 150, 400}; ed.views[0].yaw = 0; ed.views[0].pitch = -15;
}
// emulate one UI frame of left-mouse state, then feed the 2D/3D tool handler
static void frame(Editor& ed, Viewport& v, float mx, float my, int phase /*0 press,1 hold,2 release,3 idle*/) {
for (int b = 0; b < 3; ++b) g_down[b] = g_clicked[b] = g_released[b] = false;
if (phase == 0) { g_clicked[0] = true; g_down[0] = true; }
if (phase == 1) g_down[0] = true;
if (phase == 2) g_released[0] = true;
ImGuiIO& io = ImGui::GetIO();
io.MousePos = ImVec2(mx + v.imgMin.x, my + v.imgMin.y);
if (v.ortho()) ed.toolInput2D(v, ImVec2(mx, my)); else ed.toolInput3D(v, ImVec2(mx, my));
}
static void drag2D(Editor& ed, Viewport& v, float x0, float y0, float x1, float y1) {
frame(ed, v, x0, y0, 0); frame(ed, v, (x0 + x1) / 2, (y0 + y1) / 2, 1); frame(ed, v, x1, y1, 1); frame(ed, v, x1, y1, 2);
}
static hmap::AABB firstBrushBounds(Editor& ed) { return hmap::buildBrushGeometry(ed.doc.brushes[0]).bounds; }
static void kill(Editor* e) { e->renderer.setEditBatches({}); e->renderer.setCompiledBatches({}); delete e; }
static Editor* make() {
Editor* ed = new Editor();
ed->entdefs = hmap::EntityRegistry::builtin();
ed->newMap(false);
ed->doc.brushes.clear(); ed->doc.entities.clear(); ed->doc.meshes.clear(); ed->touch();
setupViews(*ed);
return ed;
}
int main() {
std::puts("camera math");
{
Editor* ed = make();
uint32_t seed = 9;
auto rnd = [&]() { seed = seed * 1664525u + 1013904223u; return (float)((seed >> 8) & 0xffff) / 65535.0f * 600.0f - 300.0f; };
ed->views[1].center = {20, 5, -40}; ed->views[2].center = {-30, 10, 15}; ed->views[3].center = {5, -20, 60};
ed->views[0].pos = {50, 120, 380}; ed->views[0].yaw = 33; ed->views[0].pitch = -21;
for (int vi = 0; vi < 4; ++vi) {
Viewport& v = ed->views[vi];
for (int i = 0; i < 200; ++i) {
Vec3 p(rnd() * 0.3f, rnd() * 0.3f, rnd() * 0.3f - (vi == 0 ? 100.0f : 0.0f));
float sx, sy;
if (!v.project(p, sx, sy)) continue;
HRay r = v.ray(sx, sy);
Vec3 d = p - r.o;
float t = hmap::dot(d, r.d);
Vec3 closest = r.o + r.d * t;
CHECK(hmap::length(closest - p) < 0.05f);
if (v.ortho()) {
Vec3 q = v.planePoint(sx, sy, p[v.depthAxis()]);
CHECK(hmap::length(q - p) < 0.01f);
}
}
}
// handedness: world +X is to the right of the screen centre in Top/Front, -Z (up) in Top
float ax, ay, bx, by;
ed->views[1].project(ed->views[1].center, ax, ay);
ed->views[1].project(ed->views[1].center + Vec3(10, 0, 0), bx, by);
CHECK(bx > ax); NEAR(by, ay, 1e-3);
ed->views[1].project(ed->views[1].center + Vec3(0, 0, -10), bx, by);
CHECK(by < ay); // -Z is up on screen in the top view
ed->views[2].project(ed->views[2].center + Vec3(0, 10, 0), bx, by);
ed->views[2].project(ed->views[2].center, ax, ay);
CHECK(by < ay); // +Y is up on screen in the front view
kill(ed);
}
std::puts("commands: create / undo / hollow / clip / tie / duplicate / delete");
{
Editor* ed = make();
ed->shape = Shape::Box; ed->createAsMesh = false;
ed->createPrimitive({0, 0, 0}, {64, 64, 64});
CHECK(ed->doc.brushes.size() == 1 && ed->sel.objs.size() == 1);
ed->undo(); CHECK(ed->doc.brushes.empty());
ed->redo(); CHECK(ed->doc.brushes.size() == 1);
ed->selectAll();
ed->hollowSelection(8);
CHECK(ed->doc.brushes.size() == 6 && ed->sel.objs.size() == 6);
ed->undo(); CHECK(ed->doc.brushes.size() == 1);
// clip through x = 20, keep both halves
ed->selectAll();
ed->clipSelection(Plane{{1, 0, 0}, 20}, 2);
CHECK(ed->doc.brushes.size() == 2);
hmap::AABB a = hmap::buildBrushGeometry(ed->doc.brushes[0]).bounds, b = hmap::buildBrushGeometry(ed->doc.brushes[1]).bounds;
NEAR(std::max(a.mx.x, b.mx.x), 64, 0.01); NEAR(std::min(a.mn.x, b.mn.x), 0, 0.01);
ed->undo(); CHECK(ed->doc.brushes.size() == 1);
ed->selectAll();
ed->clipSelection(Plane{{1, 0, 0}, 20}, 0); // keep front (x >= 20)
CHECK(ed->doc.brushes.size() == 1);
NEAR(hmap::buildBrushGeometry(ed->doc.brushes[0]).bounds.mn.x, 20, 0.01);
ed->undo();
ed->selectAll();
ed->tieSelectionToEntity("func_door");
CHECK(ed->doc.entities.size() == 1 && ed->doc.brushes[0].owner == ed->doc.entities[0].id);
hmap::CompiledMap cm = hmap::compile(ed->doc);
CHECK(cm.models.size() == 2);
ed->duplicateSelection();
CHECK(ed->doc.brushes.size() == 2 && ed->doc.brushes[1].owner == ed->doc.entities[0].id);
ed->deleteSelection();
CHECK(ed->doc.brushes.size() == 1);
ed->selectAll(); ed->deleteSelection();
CHECK(ed->doc.brushes.empty() && ed->doc.entities.empty()); // orphaned brush entity was pruned
ed->undo(); CHECK(ed->doc.brushes.size() == 1 && ed->doc.entities.size() == 1);
// every primitive the Create menu offers must produce valid geometry
for (int s = 0; s < 8; ++s) for (int asMesh = 0; asMesh < 2; ++asMesh) {
Editor* e2 = make();
e2->shape = (Shape)s; e2->createAsMesh = asMesh;
e2->createPrimitive({-32, 0, -32}, {32, 64, 32});
CHECK(!e2->sel.objs.empty());
hmap::CompiledMap c2 = hmap::compile(e2->doc);
CHECK(c2.stats.triangles > 0);
kill(e2);
}
kill(ed);
}
std::puts("transforms");
{
Editor* ed = make();
ed->createPrimitive({0, 0, 0}, {64, 32, 16});
ed->selectAll();
Vec3 c = ed->selectionCenter();
ed->applyMatrix(Mat34::translate(c) * Mat34::rotate({0, 1, 0}, 90) * Mat34::translate(-c), false);
hmap::AABB bb = firstBrushBounds(*ed);
NEAR(bb.size().x, 16, 0.02); NEAR(bb.size().z, 64, 0.02); NEAR(bb.center().x, c.x, 0.02);
ed->applyMatrix(Mat34::translate(c) * Mat34::scale({2, 1, 1}) * Mat34::translate(-c), false);
NEAR(firstBrushBounds(*ed).size().x, 32, 0.02);
ed->applyMatrix(Mat34::translate(c) * Mat34::scale({-1, 1, 1}) * Mat34::translate(-c), false); // mirror
CHECK(hmap::buildBrushGeometry(ed->doc.brushes[0]).valid);
hmap::Entity e; e.id = ed->doc.newId(); e.classname = "info_player_start"; e.origin = {10, 0, 0};
ed->doc.entities.push_back(e); ed->touch();
ed->sel.clear(); ed->sel.objs.push_back({ObjType::Entity, e.id});
ed->applyMatrix(Mat34::rotate({0, 1, 0}, 90), false);
const hmap::Entity* pe = ed->doc.findEntity(e.id);
NEAR(pe->origin.z, -10, 0.01); // (10,0,0) rotated +90 about Y
Vec3 f = pe->forward();
NEAR(f.x, -1, 0.01); NEAR(f.z, 0, 0.01);
kill(ed);
}
std::puts("mouse: select / move / resize / box-select in a 2D view");
{
Editor* ed = make();
ed->createPrimitive({0, 0, 0}, {64, 64, 64});
ed->clearSelection();
ed->tool = Tool::Select; ed->grid = 16; ed->snapOn = true;
Viewport& top = ed->views[1];
top.center = {32, 0, 32}; top.zoom = 1.0f; // box covers screen x 368..432, y 268..332
size_t undo0 = ed->undoStack.size();
drag2D(*ed, top, 400, 300, 432, 300); // click inside + drag 32 px right
CHECK(ed->sel.objs.size() == 1);
hmap::AABB bb = firstBrushBounds(*ed);
NEAR(bb.mn.x, 32, 0.02); NEAR(bb.mx.x, 96, 0.02); NEAR(bb.mn.z, 0, 0.02);
CHECK(ed->undoStack.size() == undo0 + 1);
ed->undo();
NEAR(firstBrushBounds(*ed).mn.x, 0, 0.02);
// resize: right-middle handle dragged from x=64 to x=96
ed->select({ObjType::Brush, ed->doc.brushes[0].id}, false);
drag2D(*ed, top, 432, 300, 464, 300);
bb = firstBrushBounds(*ed);
NEAR(bb.mn.x, 0, 0.02); NEAR(bb.mx.x, 96, 0.02); NEAR(bb.size().z, 64, 0.02);
ed->undo();
// top-middle handle (screen y 268 = world z 0): drag 32px up => z range grows to -32..64
drag2D(*ed, top, 400, 268, 400, 236);
bb = firstBrushBounds(*ed);
NEAR(bb.mn.z, -32, 0.02); NEAR(bb.mx.z, 64, 0.02); NEAR(bb.size().x, 64, 0.02);
ed->undo();
// corner handle: bottom-right (screen 432,332) to (448,348) => +16 in x and z
drag2D(*ed, top, 432, 332, 448, 348);
bb = firstBrushBounds(*ed);
NEAR(bb.mx.x, 80, 0.02); NEAR(bb.mx.z, 80, 0.02); NEAR(bb.mn.x, 0, 0.02);
ed->undo();
// box select on empty space
ed->clearSelection();
drag2D(*ed, top, 300, 200, 500, 400);
CHECK(ed->sel.objs.size() == 1);
ed->clearSelection();
drag2D(*ed, top, 300, 200, 400, 300); // only covers part of the brush: not selected
CHECK(ed->sel.objs.empty());
// click on empty space clears the selection
ed->select({ObjType::Brush, ed->doc.brushes[0].id}, false);
frame(*ed, top, 100, 100, 0); frame(*ed, top, 100, 100, 2);
CHECK(ed->sel.objs.empty());
kill(ed);
}
std::puts("mouse: block tool, entity tool, clip tool");
{
Editor* ed = make();
Viewport& top = ed->views[1];
top.center = {0, 0, 0}; top.zoom = 1.0f;
ed->tool = Tool::Block; ed->grid = 16; ed->blockHeight = 48; ed->shape = Shape::Box;
drag2D(*ed, top, 400 + 16, 300 + 16, 400 + 80, 300 + 48); // x 16..80, z 16..48
CHECK(ed->doc.brushes.size() == 1);
hmap::AABB bb = firstBrushBounds(*ed);
NEAR(bb.mn.x, 16, 0.02); NEAR(bb.mx.x, 80, 0.02); NEAR(bb.mn.z, 16, 0.02); NEAR(bb.mx.z, 48, 0.02);
NEAR(bb.mn.y, 0, 0.02); NEAR(bb.mx.y, 48, 0.02);
ed->tool = Tool::Entity; ed->curEntity = "light";
frame(*ed, top, 400 + 32, 300 - 48, 0); frame(*ed, top, 400 + 32, 300 - 48, 2);
CHECK(ed->doc.entities.size() == 1 && ed->doc.entities[0].classname == "light");
NEAR(ed->doc.entities[0].origin.x, 32, 0.02); NEAR(ed->doc.entities[0].origin.z, -48, 0.02);
CHECK(ed->doc.entities[0].find("radius") != nullptr); // defaults applied
// clip tool: vertical line at x = 48 in the top view
ed->tool = Tool::Clip; ed->select({ObjType::Brush, ed->doc.brushes[0].id}, false);
frame(*ed, top, 400 + 48, 300 + 0, 0); frame(*ed, top, 400 + 48, 300 + 0, 2);
frame(*ed, top, 400 + 48, 300 + 100, 0); frame(*ed, top, 400 + 48, 300 + 100, 2);
CHECK(ed->clipHasA && ed->clipHasB);
Vec3 depthDir(0, 1, 0);
Vec3 n = hmap::normalize(hmap::cross(ed->clipB - ed->clipA, depthDir));
ed->clipSelection(Plane::fromNormalPoint(n, ed->clipA), 2);
CHECK(ed->doc.brushes.size() == 2);
kill(ed);
}
std::puts("mouse: 3D picking, gizmo drag, face select, paint");
{
Editor* ed = make();
ed->createPrimitive({-32, 0, -32}, {32, 64, 32});
ed->clearSelection();
Viewport& v = ed->views[0];
v.pos = {0, 80, 300}; v.yaw = 0; v.pitch = 0;
float sx, sy;
v.project({0, 32, 0}, sx, sy);
Hit h = ed->pick(v.ray(sx, sy));
CHECK(h.hit && h.obj.type == ObjType::Brush);
NEAR(h.normal.z, 1, 0.01); // front face (+Z) facing the camera
v.project({400, 32, 0}, sx, sy);
CHECK(!ed->pick(v.ray(sx, sy)).hit);
ed->tool = Tool::Select; ed->selMode = SelMode::Object;
v.project({0, 32, 0}, sx, sy);
frame(*ed, v, sx, sy, 0); frame(*ed, v, sx, sy, 2);
CHECK(ed->sel.objs.size() == 1);
// gizmo: grab the X arm halfway along, drag 48 units
Vec3 c = ed->gizmoCenter();
float L = std::max(8.0f, hmap::length(c - v.pos) * 0.16f);
float gx, gy, gx2, gy2;
v.project(c + Vec3(L * 0.5f, 0, 0), gx, gy);
v.project(c + Vec3(L * 0.5f + 48.0f, 0, 0), gx2, gy2);
CHECK(ed->gizmoHit(v, ImVec2(gx, gy)) == 0);
frame(*ed, v, gx, gy, 0);
CHECK(ed->drag.kind == DragState::Gizmo);
frame(*ed, v, (gx + gx2) / 2, (gy + gy2) / 2, 1); frame(*ed, v, gx2, gy2, 1); frame(*ed, v, gx2, gy2, 2);
hmap::AABB bb = firstBrushBounds(*ed);
NEAR(bb.mn.x, -32 + 48, 0.5); NEAR(bb.mx.y, 64, 0.01);
ed->undo();
NEAR(firstBrushBounds(*ed).mn.x, -32, 0.01);
// face mode: click the front face, then paint it with another material through Alt+click
ed->selMode = SelMode::Face;
ed->clearSelection();
v.project({0, 32, 0}, sx, sy);
frame(*ed, v, sx, sy, 0); frame(*ed, v, sx, sy, 2);
CHECK(ed->sel.objs.size() == 1 && ed->sel.faces.size() == 1);
int face = ed->sel.faces[0];
CHECK(ed->doc.brushes[0].faces[(size_t)face].plane.n.z > 0.99f);
ed->curMaterial = 3;
Hit hit = ed->pick(v.ray(sx, sy));
ed->paintHit(hit, false);
CHECK(ed->doc.brushes[0].faces[(size_t)face].material == 3);
int others = 0;
for (size_t i = 0; i < ed->doc.brushes[0].faces.size(); ++i) others += (int)i != face && ed->doc.brushes[0].faces[i].material == 3;
CHECK(others == 0);
ed->applyMaterialToSelection(5);
CHECK(ed->doc.brushes[0].faces[(size_t)face].material == 5);
kill(ed);
}
std::puts("mesh vertex mode");
{
Editor* ed = make();
ed->shape = Shape::Terrain; ed->createPrimitive({-64, 0, -64}, {64, 8, 64});
CHECK(ed->doc.meshes.size() == 1);
ed->selMode = SelMode::Vertex;
Viewport& top = ed->views[1];
top.center = {0, 0, 0}; top.zoom = 2.0f;
// click the vertex at world (0,4,0): screen (400,300)
frame(*ed, top, 400, 300, 0);
CHECK(ed->sel.verts.size() == 1);
int vi = ed->sel.verts[0];
NEAR(ed->doc.meshes[0].verts[(size_t)vi].x, 0, 1e-3);
// drag it 32 world units along +X (64 screen px at zoom 2) -> mouse press already started the drag
frame(*ed, top, 400 + 32, 300, 1); frame(*ed, top, 400 + 64, 300, 1); frame(*ed, top, 400 + 64, 300, 2);
NEAR(ed->doc.meshes[0].verts[(size_t)vi].x, 32, 0.02);
ed->undo();
NEAR(ed->doc.meshes[0].verts[(size_t)vi].x, 0, 0.02);
kill(ed);
}
std::puts("compile + build preview data");
{
Editor* ed = make();
ed->newMap(true);
ed->compileOpt.bakeLighting = true;
ed->compileNow();
CHECK(ed->hasCompiled && !ed->compiledStale && ed->compiled.baked);
ed->createPrimitive({0, 0, 0}, {32, 32, 32});
CHECK(ed->compiledStale);
ed->exportFbx("editor_test.fbx"); ed->exportObj("editor_test.obj"); ed->exportCompiled("editor_test.hmap");
CHECK(ed->saveMap("editor_test_src.hmap"));
Editor* e2 = make();
CHECK(e2->openMap("editor_test_src.hmap") && e2->doc.brushes.size() == ed->doc.brushes.size());
kill(e2); kill(ed);
}
std::printf("\n%d checks, %d failed\n", checks, fails);
return fails ? 1 : 0;
}