Skip to content

Commit

Permalink
Issue #5 Remains. Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
EriKWDev committed Apr 6, 2021
1 parent c0354c3 commit 9fbef6f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
1 change: 1 addition & 0 deletions examples/multiple_scenes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ proc extraScene(): Scene =

scene.add(entity)
scene.play(entity.moveTo(500, 500))
scene.wait(500)

return scene

Expand Down
12 changes: 6 additions & 6 deletions src/nanim/core.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import
os,
math,
times,
nanim/animation/tween,
nanim/animation/easings,
nanim/animation,
nanim/drawing,
nanim/logging

Expand Down Expand Up @@ -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:
Expand All @@ -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
30 changes: 14 additions & 16 deletions src/nanim/entities/scene_entity.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,7 +62,6 @@ func play*(entity: SceneEntity): Tween =

result = newTween(interpolators)


func start*(entity: SceneEntity): Tween =
entity.play()

Expand All @@ -78,6 +77,5 @@ func pause*(entity: SceneEntity): Tween =

result = newTween(interpolators)


func stop*(entity: SceneEntity): Tween =
entity.pause()
12 changes: 4 additions & 8 deletions src/nanim/rendering.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9fbef6f

Please sign in to comment.