diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 78945ff..786e619 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -7,6 +7,6 @@ ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username -issuehunt: # Replace with a single IssueHunt username +issuehunt: ErikWDev otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] diff --git a/examples/multiple_scenes.nim b/examples/multiple_scenes.nim index f18dfd9..dd1943d 100644 --- a/examples/multiple_scenes.nim +++ b/examples/multiple_scenes.nim @@ -8,6 +8,7 @@ proc extraScene(): Scene = scene.add(entity) scene.play(entity.moveTo(500, 500)) + scene.wait(500) return scene diff --git a/src/nanim/core.nim b/src/nanim/core.nim index a590703..dcdff17 100644 --- a/src/nanim/core.nim +++ b/src/nanim/core.nim @@ -8,8 +8,7 @@ import os, math, times, - nanim/animation/tween, - nanim/animation/easings, + nanim/animation, nanim/drawing, nanim/logging @@ -679,7 +678,10 @@ proc draw*(scene: Scene) = scene.visualizeTracks() -proc tick*(scene: Scene) = +proc tick*(scene: Scene, deltaTime: float = 1000.0/120.0) = + scene.deltaTime = deltaTime + scene.time += scene.deltaTime + scene.done = true for track in scene.tweenTracks.values: @@ -699,9 +701,7 @@ proc update*(scene: Scene) = let goalDelta = 1000.0/120.0 if time - scene.lastTickTime >= goalDelta: - scene.deltaTime = time - scene.lastTickTime - scene.time = scene.time + scene.deltaTime - scene.tick() + scene.tick(time - scene.lastTickTime) if scene.done: scene.time = scene.restartTime diff --git a/src/nanim/entities/scene_entity.nim b/src/nanim/entities/scene_entity.nim index a0a91f1..68640f1 100644 --- a/src/nanim/entities/scene_entity.nim +++ b/src/nanim/entities/scene_entity.nim @@ -11,40 +11,40 @@ type paused: bool loop: bool + width*: int + height*: int + proc init*(sceneEntity: SceneEntity) = init(sceneEntity.Entity) sceneEntity.paused = false sceneEntity.loop = false + sceneEntity.width = 1920 + sceneEntity.height = 1080 -proc newSceneEntity*(userScene: Scene): SceneEntity = +proc newSceneEntity*(userScene: Scene, width: int = 1920, height: int = 1080): SceneEntity = new(result) result.init() result.scene = userScene.deepCopy() + result.width = width + result.height = height -proc newSceneEntity*(sceneCreator: proc(): Scene): SceneEntity = newSceneEntity(sceneCreator()) +proc newSceneEntity*(sceneCreator: proc(): Scene, width: int = 1920, height: int = 1080): SceneEntity = + newSceneEntity(sceneCreator(), width, height) method draw*(sceneEntity: SceneEntity, mainScene: Scene) = sceneEntity.scene.context = mainScene.context sceneEntity.scene.window = mainScene.window - sceneEntity.scene.width = mainScene.width - sceneEntity.scene.height = mainScene.height - - sceneEntity.scene.frameBufferWidth = mainScene.frameBufferWidth - sceneEntity.scene.frameBufferHeight = mainScene.frameBufferHeight - - if sceneEntity.paused: - sceneEntity.scene.deltaTime = 0 - else: - sceneEntity.scene.deltaTime = mainScene.deltaTime + sceneEntity.scene.width = sceneEntity.width + sceneEntity.scene.height = sceneEntity.height - sceneEntity.scene.time = mainScene.time - sceneEntity.scene.tick() + let deltaTime = if sceneEntity.paused: 0.0 else: mainScene.deltaTime + sceneEntity.scene.tick(deltaTime) if sceneEntity.loop and sceneEntity.scene.done: sceneEntity.scene.time = sceneEntity.scene.restartTime @@ -62,7 +62,6 @@ func play*(entity: SceneEntity): Tween = result = newTween(interpolators) - func start*(entity: SceneEntity): Tween = entity.play() @@ -78,6 +77,5 @@ func pause*(entity: SceneEntity): Tween = result = newTween(interpolators) - func stop*(entity: SceneEntity): Tween = entity.pause() diff --git a/src/nanim/rendering.nim b/src/nanim/rendering.nim index 74b9451..4e49ad6 100644 --- a/src/nanim/rendering.nim +++ b/src/nanim/rendering.nim @@ -109,13 +109,10 @@ proc renderVideoWithPipe(scene: Scene) = goalFps = 60 goalDeltaTime = 1000.0/goalFps.float - # ? Maybe reset time here. It is probably unexpected through - # ? if the scene explicitly has a startHere() call... - # scene.time = 0.0 - scene.deltaTime = goalDeltaTime + let + rendersFolderPath = os.joinPath(os.getAppDir(), "renders") + partsFolderPath = os.joinPath(rendersFolderPath, "parts") - let rendersFolderPath = os.joinPath(os.getAppDir(), "renders") - let partsFolderPath = os.joinPath(rendersFolderPath, "parts") createDir(partsFolderPath) # * ffmpeg -y -f rawvideo -pix_fmt rgba -s 1920x1080 -r 60 -i - -vf vflip -an -c:v libx264 -preset fast -crf 18 -tune animation -pix_fmt yuv444p @@ -172,8 +169,7 @@ proc renderVideoWithPipe(scene: Scene) = while not scene.done: scene.beginFrame() - scene.tick() - scene.time = scene.time + goalDeltaTime + scene.tick(goalDeltaTime) scene.endFrame() inc i