Skip to content

Commit

Permalink
fix state machine advanceAndApply
Browse files Browse the repository at this point in the history
this almost fixes the issue with ios. but somehow this ends up returning false sometimes still... it seem to stop in a similar position each time, a little nudge being enough to get it moving again for a longer while

also

```
- (bool)advanceBy:(double)elapsedSeconds
{
    return instance->advanceAndApply(elapsedSeconds);
}
```

note the intervals at which we call this function are somewhat laughable,

![CleanShot 2024-05-01 at 16 07 05](https://github.com/rive-app/rive/assets/1216025/694e61bf-8d0c-465e-9676-af221d6be174)

Diffs=
8db7cac50 fix state machine advanceAndApply (#7183)

Co-authored-by: Maxwell Talbot <[email protected]>
  • Loading branch information
mjtalbot and mjtalbot committed May 2, 2024
1 parent 1a5848d commit 3800dff
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a55f1ffb6cabe9b918fa0b8fd1ad11b4d656ae1c
8db7cac50c53ab10838da0cd80c869917c51c72a
2 changes: 1 addition & 1 deletion .rive_renderer
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b615413345a91dbfc1ada8b7c3a91c941d25ca16
988aea8692eb53d1e38579a7c3b75dc6c72e9cab
4 changes: 4 additions & 0 deletions RiveRuntime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
04BE5430264D1F4100427B39 /* LayerState.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BE542F264D1F4100427B39 /* LayerState.h */; settings = {ATTRIBUTES = (Public, ); }; };
04BE5434264D267900427B39 /* LayerState.mm in Sources */ = {isa = PBXBuildFile; fileRef = 04BE5431264D243D00427B39 /* LayerState.mm */; };
04BE5436264D2A7500427B39 /* RivePrivateHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BE5435264D2A7500427B39 /* RivePrivateHeaders.h */; };
04E222402BE3C85100D82668 /* ball_test.riv in Resources */ = {isa = PBXBuildFile; fileRef = 04E2223F2BE3C85100D82668 /* ball_test.riv */; };
04ED72F1299C114000E8DE53 /* RiveViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04ED72F0299C114000E8DE53 /* RiveViewModelTest.swift */; };
04ED72F3299C115100E8DE53 /* empty_animation_state.riv in Resources */ = {isa = PBXBuildFile; fileRef = 04ED72F2299C115100E8DE53 /* empty_animation_state.riv */; };
2A7079352726277C00C035A1 /* rive_renderer_view.hh in Headers */ = {isa = PBXBuildFile; fileRef = 2A7079342726277C00C035A1 /* rive_renderer_view.hh */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -157,6 +158,7 @@
04BE542F264D1F4100427B39 /* LayerState.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LayerState.h; sourceTree = "<group>"; };
04BE5431264D243D00427B39 /* LayerState.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LayerState.mm; sourceTree = "<group>"; };
04BE5435264D2A7500427B39 /* RivePrivateHeaders.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RivePrivateHeaders.h; sourceTree = "<group>"; };
04E2223F2BE3C85100D82668 /* ball_test.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = ball_test.riv; sourceTree = "<group>"; };
04ED72F0299C114000E8DE53 /* RiveViewModelTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RiveViewModelTest.swift; sourceTree = "<group>"; };
04ED72F2299C115100E8DE53 /* empty_animation_state.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = empty_animation_state.riv; sourceTree = "<group>"; };
2A7079342726277C00C035A1 /* rive_renderer_view.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rive_renderer_view.hh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -252,6 +254,7 @@
isa = PBXGroup;
children = (
0424A8752BD59435000A9A1C /* img_test.riv */,
04E2223F2BE3C85100D82668 /* ball_test.riv */,
0424A8732BD592F2000A9A1C /* audio_test.riv */,
041265272B0CC387009400EC /* hosted_assets.riv */,
041265292B0CCB8E009400EC /* embedded_assets.riv */,
Expand Down Expand Up @@ -525,6 +528,7 @@
04BE540D2649403600427B39 /* junk.riv in Resources */,
04BE54092649403600427B39 /* state_machine_configurations.riv in Resources */,
04BE54072649403600427B39 /* what_a_state.riv in Resources */,
04E222402BE3C85100D82668 /* ball_test.riv in Resources */,
0424A8762BD59435000A9A1C /* img_test.riv in Resources */,
04BE541A264A823000427B39 /* animationconfigurations.riv in Resources */,
04BE540E2649403600427B39 /* multiple_state_machines.riv in Resources */,
Expand Down
Binary file added Tests/Assets/ball_test.riv
Binary file not shown.
50 changes: 49 additions & 1 deletion Tests/RiveDelegatesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,50 @@ class DelegatesTest: XCTestCase {
XCTAssertTrue((delegate.events.last as? RiveOpenUrlEvent)?.url != nil)
}

func testNestedStateMachineLooping() throws {
// this test tests advancing a state machine with a one shot animation that ends after 1 second
// but the artboard has a nested artboard that is playing a looping animation via its state machine.
let delegate = DrDelegate()
let file = try RiveFile(testfileName: "ball_test")
let model = RiveModel(riveFile: file)
let viewModel = RiveViewModel(model, stateMachineName: "State Machine 1", autoPlay: true)
let view = viewModel.createRiveView()

view.playerDelegate = delegate
view.stateMachineDelegate = delegate
XCTAssertEqual(true, viewModel.isPlaying)
view.advance(delta:0.1)
XCTAssertEqual(true, viewModel.isPlaying)
view.advance(delta:1.0)
XCTAssertEqual(true, viewModel.isPlaying)
view.advance(delta:0.1)
XCTAssertEqual(true, viewModel.isPlaying)
}

func testNestedStateMachineOneShot() throws {
// this test tests advancing a state machine with a one shot animation that ends after 1 second
// but the artboard has a nested artboard that is playing a one shot animation via its state machine.
let delegate = DrDelegate()
let file = try RiveFile(testfileName: "ball_test")
let model = RiveModel(riveFile: file)
let viewModel = RiveViewModel(
model,
stateMachineName: "State Machine 1",
autoPlay: true,
artboardName: "Artboard 2"
)
let view = viewModel.createRiveView()

view.playerDelegate = delegate
view.stateMachineDelegate = delegate
XCTAssertEqual(true, viewModel.isPlaying)
view.advance(delta:0.1)
XCTAssertEqual(true, viewModel.isPlaying)
view.advance(delta:1.0)
XCTAssertEqual(false, viewModel.isPlaying)
}


func testStateMachineLayerStates() throws {
let delegate = DrDelegate()
let file = try RiveFile(testfileName: "what_a_state")
Expand Down Expand Up @@ -326,8 +370,12 @@ class DelegatesTest: XCTestCase {
XCTAssertEqual(0, delegate.stateMachineStates.count)
XCTAssertEqual(true, viewModel.isPlaying)

// animation came to an end inside this time period, this still means no state change
// state machine advance ends, but
// artboard advanced in this period, so we "keepGoing"
view.advance(delta:0.4)
XCTAssertEqual(true, viewModel.isPlaying)
// animation is done
view.advance(delta:0.1)
XCTAssertEqual(false, viewModel.isPlaying)
XCTAssertEqual(0, delegate.stateMachineStates.count)

Expand Down
2 changes: 1 addition & 1 deletion submodules/rive-cpp

0 comments on commit 3800dff

Please sign in to comment.