Skip to content

Commit

Permalink
REVIEWED: Automation events mouse wheel #4263
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Aug 20, 2024
1 parent 7fab03c commit 039df36
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
70 changes: 36 additions & 34 deletions examples/core/core_automation_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(void)
// Update
//----------------------------------------------------------------------------------
float deltaTime = 0.015f;//GetFrameTime();

// Dropped files logic
//----------------------------------------------------------------------------------
if (IsFileDropped())
Expand Down Expand Up @@ -157,11 +157,6 @@ int main(void)
}
else player.canJump = true;

camera.zoom += ((float)GetMouseWheelMove()*0.05f);

if (camera.zoom > 3.0f) camera.zoom = 3.0f;
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;

if (IsKeyPressed(KEY_R))
{
// Reset game state
Expand All @@ -176,12 +171,44 @@ int main(void)
}
//----------------------------------------------------------------------------------

// Events playing
// NOTE: Logic must be before Camera update because it depends on mouse-wheel value,
// that can be set by the played event... but some other inputs could be affected
//----------------------------------------------------------------------------------
if (eventPlaying)
{
// NOTE: Multiple events could be executed in a single frame
while (playFrameCounter == aelist.events[currentPlayFrame].frame)
{
PlayAutomationEvent(aelist.events[currentPlayFrame]);
currentPlayFrame++;

if (currentPlayFrame == aelist.count)
{
eventPlaying = false;
currentPlayFrame = 0;
playFrameCounter = 0;

TraceLog(LOG_INFO, "FINISH PLAYING!");
break;
}
}

playFrameCounter++;
}
//----------------------------------------------------------------------------------

// Update camera
//----------------------------------------------------------------------------------
camera.target = player.position;
camera.offset = (Vector2){ screenWidth/2.0f, screenHeight/2.0f };
float minX = 1000, minY = 1000, maxX = -1000, maxY = -1000;

// WARNING: On event replay, mouse-wheel internal value is set
camera.zoom += ((float)GetMouseWheelMove()*0.05f);
if (camera.zoom > 3.0f) camera.zoom = 3.0f;
else if (camera.zoom < 0.25f) camera.zoom = 0.25f;

for (int i = 0; i < MAX_ENVIRONMENT_ELEMENTS; i++)
{
EnvElement *element = &envElements[i];
Expand All @@ -200,8 +227,8 @@ int main(void)
if (min.y > 0) camera.offset.y = screenHeight/2 - min.y;
//----------------------------------------------------------------------------------

// Toggle events recording
if (IsKeyPressed(KEY_S))
// Events management
if (IsKeyPressed(KEY_S)) // Toggle events recording
{
if (!eventPlaying)
{
Expand All @@ -222,7 +249,7 @@ int main(void)
}
}
}
else if (IsKeyPressed(KEY_A))
else if (IsKeyPressed(KEY_A)) // Toggle events playing (WARNING: Starts next frame)
{
if (!eventRecording && (aelist.count > 0))
{
Expand All @@ -241,32 +268,7 @@ int main(void)
camera.zoom = 1.0f;
}
}

if (eventPlaying)
{
// NOTE: Multiple events could be executed in a single frame
while (playFrameCounter == aelist.events[currentPlayFrame].frame)
{
TraceLog(LOG_INFO, "PLAYING: PlayFrameCount: %i | currentPlayFrame: %i | Event Frame: %i, param: %i",
playFrameCounter, currentPlayFrame, aelist.events[currentPlayFrame].frame, aelist.events[currentPlayFrame].params[0]);

PlayAutomationEvent(aelist.events[currentPlayFrame]);
currentPlayFrame++;

if (currentPlayFrame == aelist.count)
{
eventPlaying = false;
currentPlayFrame = 0;
playFrameCounter = 0;

TraceLog(LOG_INFO, "FINISH PLAYING!");
break;
}
}

playFrameCounter++;
}

if (eventRecording || eventPlaying) frameCounter++;
else frameCounter = 0;
//----------------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ void InitWindow(int width, int height, const char *title)
#endif
#endif


CORE.Time.frameCounter = 0;
CORE.Window.shouldClose = false;

Expand Down Expand Up @@ -2707,8 +2706,8 @@ void PlayAutomationEvent(AutomationEvent event)
} break;
case INPUT_MOUSE_WHEEL_MOTION: // param[0]: x delta, param[1]: y delta
{
CORE.Input.Mouse.currentWheelMove.x = (float)event.params[0]; break;
CORE.Input.Mouse.currentWheelMove.y = (float)event.params[1]; break;
CORE.Input.Mouse.currentWheelMove.x = (float)event.params[0];
CORE.Input.Mouse.currentWheelMove.y = (float)event.params[1];
} break;
case INPUT_TOUCH_UP: CORE.Input.Touch.currentTouchState[event.params[0]] = false; break; // param[0]: id
case INPUT_TOUCH_DOWN: CORE.Input.Touch.currentTouchState[event.params[0]] = true; break; // param[0]: id
Expand Down Expand Up @@ -2745,6 +2744,8 @@ void PlayAutomationEvent(AutomationEvent event)
case ACTION_SETTARGETFPS: SetTargetFPS(event.params[0]); break;
default: break;
}

TRACELOG(LOG_INFO, "AUTOMATION PLAY: Frame: %i | Event type: %i | Event parameters: %i, %i, %i", event.frame, event.type, event.params[0], event.params[1], event.params[2]);
}
#endif
}
Expand Down

0 comments on commit 039df36

Please sign in to comment.