/* Implementación FALSA de las funciones de raylib que usa Tahgibu: no abre ventanas ni dibuja, * pero reproduce un guion de ratón/teclado para ejercitar el bucle real de src/ui. */ #include #include #include "raylib.h" #include "mock_raylib.h" static const mock_event *g_events; static int g_nevents, g_next, g_last_frame, g_frame; static Vector2 g_mouse; static bool g_down[3], g_pressed[3], g_released[3]; static bool g_key_down[512], g_key_pressed[512]; static int g_chars[256], g_nchars, g_char_head; static float g_wheel; static int g_tex_updates, g_draw_calls; void mock_script(const mock_event *events, int count, int last_frame) { g_events = events; g_nevents = count; g_last_frame = last_frame; g_next = 0; g_frame = 0; } int mock_frames_run(void) { return g_frame; } int mock_texture_updates(void) { return g_tex_updates; } int mock_draw_calls(void) { return g_draw_calls; } void SetConfigFlags(unsigned int flags) { (void)flags; } void InitWindow(int width, int height, const char *title) { (void)width; (void)height; (void)title; } void CloseWindow(void) {} void SetWindowMinSize(int w, int h) { (void)w; (void)h; } void SetTargetFPS(int fps) { (void)fps; } void SetExitKey(int key) { (void)key; } int GetScreenWidth(void) { return 1280; } int GetScreenHeight(void) { return 800; } float GetFrameTime(void) { return 1.0f / 60.0f; } double GetTime(void) { return 1000.0 + (double)g_frame / 60.0; } /* Se llama una vez por vuelta del bucle: avanza el guion. */ bool WindowShouldClose(void) { g_frame++; memset(g_pressed, 0, sizeof g_pressed); memset(g_released, 0, sizeof g_released); memset(g_key_pressed, 0, sizeof g_key_pressed); g_wheel = 0; while (g_next < g_nevents && g_events[g_next].frame <= g_frame) { const mock_event *e = &g_events[g_next++]; int k = (int)e->a; switch (e->type) { case EV_MOVE: g_mouse.x = e->a; g_mouse.y = e->b; break; case EV_DOWN: g_down[k] = true; g_pressed[k] = true; break; case EV_UP: g_down[k] = false; g_released[k] = true; break; case EV_KEY: if (k >= 0 && k < 512) g_key_pressed[k] = true; break; case EV_KEYDOWN: if (k >= 0 && k < 512) g_key_down[k] = true; break; case EV_KEYUP: if (k >= 0 && k < 512) g_key_down[k] = false; break; case EV_CHAR: if (g_nchars < 256) g_chars[g_nchars++] = k; break; case EV_WHEEL: g_wheel = e->a; break; } } return g_frame > g_last_frame; } void BeginDrawing(void) {} void EndDrawing(void) {} void ClearBackground(Color c) { (void)c; g_draw_calls++; } void BeginScissorMode(int x, int y, int w, int h) { (void)x; (void)y; (void)w; (void)h; } void EndScissorMode(void) {} void DrawRectangle(int x, int y, int w, int h, Color c) { (void)x; (void)y; (void)w; (void)h; (void)c; g_draw_calls++; } void DrawRectangleRec(Rectangle r, Color c) { (void)r; (void)c; g_draw_calls++; } void DrawRectangleLines(int x, int y, int w, int h, Color c) { (void)x; (void)y; (void)w; (void)h; (void)c; g_draw_calls++; } void DrawRectangleLinesEx(Rectangle r, float t, Color c) { (void)r; (void)t; (void)c; g_draw_calls++; } void DrawCircleLines(int x, int y, float r, Color c) { (void)x; (void)y; (void)r; (void)c; g_draw_calls++; } void DrawText(const char *t, int x, int y, int s, Color c) { (void)t; (void)x; (void)y; (void)s; (void)c; g_draw_calls++; } int MeasureText(const char *t, int size) { return (int)strlen(t) * size / 2; } Font GetFontDefault(void) { Font f; memset(&f, 0, sizeof f); f.baseSize = 10; f.texture.id = 1; f.texture.width = 1; f.texture.height = 1; return f; } Font LoadFontEx(const char *path, int size, int *codepoints, int count) { (void)path; (void)codepoints; (void)count; Font f = GetFontDefault(); f.baseSize = size; f.texture.id = 2; return f; } void UnloadFont(Font f) { (void)f; } void DrawTextEx(Font f, const char *t, Vector2 p, float size, float spacing, Color c) { (void)f; (void)t; (void)p; (void)size; (void)spacing; (void)c; g_draw_calls++; } Vector2 MeasureTextEx(Font f, const char *t, float size, float spacing) { (void)f; float n = (float)strlen(t); return (Vector2){n * size * 0.52f + (n > 0.0f ? (n - 1.0f) * spacing : 0.0f), size}; } Texture2D LoadTextureFromImage(Image img) { Texture2D t = {1, img.width, img.height, 1, img.format}; return t; } void UpdateTexture(Texture2D t, const void *pixels) { (void)t; if (pixels) g_tex_updates++; } void UnloadTexture(Texture2D t) { (void)t; } void SetTextureFilter(Texture2D t, int f) { (void)t; (void)f; } void DrawTexturePro(Texture2D t, Rectangle s, Rectangle d, Vector2 o, float r, Color c) { (void)t; (void)s; (void)d; (void)o; (void)r; (void)c; g_draw_calls++; } Vector2 GetMousePosition(void) { return g_mouse; } bool IsMouseButtonPressed(int b) { return g_pressed[b]; } bool IsMouseButtonDown(int b) { return g_down[b]; } bool IsMouseButtonReleased(int b) { return g_released[b]; } float GetMouseWheelMove(void) { return g_wheel; } bool IsKeyPressed(int k) { return k >= 0 && k < 512 && g_key_pressed[k]; } bool IsKeyPressedRepeat(int k) { (void)k; return false; } bool IsKeyDown(int k) { return k >= 0 && k < 512 && g_key_down[k]; } int GetCharPressed(void) { return g_char_head < g_nchars ? g_chars[g_char_head++] : 0; } const char *GetClipboardText(void) { return ""; } bool CheckCollisionPointRec(Vector2 p, Rectangle r) { return p.x >= r.x && p.x < r.x + r.width && p.y >= r.y && p.y < r.y + r.height; }