Toying with raylib automation

This commit is contained in:
Krzosa Karol
2024-06-28 18:04:39 +02:00
parent 8528bfefc1
commit 2807573012
2 changed files with 87 additions and 17 deletions

View File

@@ -88,7 +88,7 @@ int main() {
cmd.add("../src/basic/win32.cpp"); cmd.add("../src/basic/win32.cpp");
cmd.add("/link"); cmd.add("/link");
cmd.add("../src/external/raylib/lib/raylib.lib"); cmd.add("../src/external/raylib/raylib.lib");
cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib"); cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib");
cmd.add("/NODEFAULTLIB:LIBCMT"); cmd.add("/NODEFAULTLIB:LIBCMT");
cmd.add("/incremental:no"); cmd.add("/incremental:no");
@@ -110,8 +110,8 @@ int main() {
cmd.add("../src/basic/win32.cpp"); cmd.add("../src/basic/win32.cpp");
cmd.add("/link"); cmd.add("/link");
cmd.add("../src/external/raylib/lib/raylib.lib"); cmd.add("../src/external/raylib/raylib.lib");
cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib msvcrt.lib shell32.lib"); cmd.add("opengl32.lib kernel32.lib user32.lib gdi32.lib winmm.lib shell32.lib");
cmd.add("/NODEFAULTLIB:LIBCMT"); cmd.add("/NODEFAULTLIB:LIBCMT");
cmd.add("/incremental:no"); cmd.add("/incremental:no");

View File

@@ -126,6 +126,68 @@ void Dbg_Draw() {
} }
} }
bool EventRecording = false;
bool EventPlaying = false;
AutomationEventList EventList;
void InitEventRecording() {
EventList = LoadAutomationEventList(0);
SetAutomationEventList(&EventList);
EventList = LoadAutomationEventList("automation.rae");
EventPlaying = true;
}
int ModifiedGetCharPressed() {
static int i;
int result = GetCharPressed();
if (EventPlaying && (i % 2) == 0) {
result = 'a';
}
i += 1;
return result;
}
void UpdateEventRecording() {
static unsigned int frameCounter;
static unsigned int playFrameCounter;
static unsigned int currentPlayFrame;
if (IsKeyPressed(KEY_F5)) {
if (EventRecording) {
StopAutomationEventRecording();
ExportAutomationEventList(EventList, "automation.rae");
EventRecording = false;
} else {
SetAutomationEventBaseFrame(0);
StartAutomationEventRecording();
EventRecording = true;
}
}
if (EventPlaying) {
// NOTE: Multiple events could be executed in a single frame
while (playFrameCounter == EventList.events[currentPlayFrame].frame) {
TraceLog(LOG_INFO, "PLAYING: PlayFrameCount: %i | currentPlayFrame: %i | Event Frame: %i, param: %i",
playFrameCounter, currentPlayFrame, EventList.events[currentPlayFrame].frame, EventList.events[currentPlayFrame].params[0]);
PlayAutomationEvent(EventList.events[currentPlayFrame]);
currentPlayFrame++;
if (currentPlayFrame == EventList.count) {
EventPlaying = false;
currentPlayFrame = 0;
playFrameCounter = 0;
TraceLog(LOG_INFO, "FINISH PLAYING!");
break;
}
}
playFrameCounter++;
}
}
int main() { int main() {
InitScratch(); InitScratch();
InitWindow(800, 600, "Hello"); InitWindow(800, 600, "Hello");
@@ -135,10 +197,8 @@ int main() {
InitArena(&PermArena); InitArena(&PermArena);
float font_size = 64; float font_size = 64;
float font_spacing = 1; float font_spacing = 1;
Font font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)font_size, NULL, 250); Font font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
float title_bar_font_size = 15;
Font title_bar_font = LoadFontEx("C:/Windows/Fonts/times.ttf", (int)title_bar_font_size, NULL, 250);
if (0) font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250); if (0) font = LoadFontEx("C:/Windows/Fonts/consola.ttf", (int)font_size, NULL, 250);
Array<Window> windows = {}; Array<Window> windows = {};
@@ -152,14 +212,14 @@ int main() {
InitBuffer(&window.buffer); InitBuffer(&window.buffer);
if (1) { if (1) {
Array<Edit> edits = {FrameArena}; // Array<Edit> edits = {FrameArena};
AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1")); // AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: 1"));
ApplyEdits(&window.buffer, edits); // ApplyEdits(&window.buffer, edits);
// for (int i = 0; i < 5; i += 1) { for (int i = 0; i < 5; i += 1) {
// Array<Edit> edits = {FrameArena}; Array<Edit> edits = {FrameArena};
// AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i)); AddEdit(&edits, GetEnd(window.buffer), Format(FrameArena, "line number: %d\n", i));
// ApplyEdits(&window.buffer, edits); ApplyEdits(&window.buffer, edits);
// } }
} }
window.cursors.add({}); window.cursors.add({});
@@ -168,6 +228,7 @@ int main() {
windows.add(window); windows.add(window);
} }
InitEventRecording();
// @todo: multiple ui elements, add focus // @todo: multiple ui elements, add focus
// @todo: immediate mode interface for all this // @todo: immediate mode interface for all this
Vec2 camera_offset_world_to_render_units = {}; Vec2 camera_offset_world_to_render_units = {};
@@ -176,6 +237,9 @@ int main() {
Assert(it.cursors.len); Assert(it.cursors.len);
it.main_cursor_begin_frame = it.cursors[0]; it.main_cursor_begin_frame = it.cursors[0];
} }
UpdateEventRecording();
{ {
Window *focused_window = &windows[0]; Window *focused_window = &windows[0];
@@ -247,10 +311,14 @@ int main() {
} }
if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) { if (IsKeyPressed(KEY_DOWN) || IsKeyPressedRepeat(KEY_DOWN)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + down
Array<Cursor> cursors_to_add = {FrameArena};
For(focused_window->cursors) { For(focused_window->cursors) {
int64_t front = GetFront(it); int64_t front = GetFront(it);
front = MoveDown(focused_window->buffer, front); front = MoveDown(focused_window->buffer, front);
focused_window->cursors.add({front, front}); cursors_to_add.add({front, front});
}
For(cursors_to_add) {
focused_window->cursors.add(it);
} }
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + down } else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + down
BeforeEdit(focused_window); BeforeEdit(focused_window);
@@ -281,11 +349,13 @@ int main() {
if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) { if (IsKeyPressed(KEY_UP) || IsKeyPressedRepeat(KEY_UP)) {
if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up if (IsKeyDown(KEY_LEFT_SHIFT) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Ctrl + Alt + up
Array<Cursor> cursors_to_add = {FrameArena};
For(focused_window->cursors) { For(focused_window->cursors) {
int64_t front = GetFront(it); int64_t front = GetFront(it);
front = MoveUp(focused_window->buffer, front); front = MoveUp(focused_window->buffer, front);
focused_window->cursors.add({front, front}); cursors_to_add.add({front, front});
} }
For(cursors_to_add) focused_window->cursors.add(it);
} else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + up } else if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyDown(KEY_LEFT_ALT)) { // Default in VSCode seems to be Shift + Alt + up
BeforeEdit(focused_window); BeforeEdit(focused_window);
Array<Edit> edits = {FrameArena}; Array<Edit> edits = {FrameArena};
@@ -423,7 +493,7 @@ int main() {
// Handle user input // Handle user input
for (;;) { for (;;) {
int c = GetCharPressed(); int c = ModifiedGetCharPressed();
if (!c) break; if (!c) break;
String string = "?"; String string = "?";