Skip to content

Commit

Permalink
fix animation started/finished
Browse files Browse the repository at this point in the history
  • Loading branch information
IzaZed committed Jun 27, 2024
1 parent f6c3201 commit 7d41024
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
16 changes: 11 additions & 5 deletions uplogic/animation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from uplogic.animation.actionsystem import get_action_system
from uplogic.events import schedule
from uplogic.console import warning
from uplogic.utils.constants import FRAMETIME_COMPARE
import bpy
from uplogic.utils.math import clamp

Expand All @@ -28,8 +29,9 @@
"""Available blending modes of [`"blend"`, `"add"`]"""


ACTION_STARTED = 'ACTION_STARTED'
ACTION_FINISHED = 'ACTION_FINISHED'
ACTION_STARTED = 0
ACTION_RUNNING = 1
ACTION_FINISHED = 2


class ActionCallback:
Expand Down Expand Up @@ -81,7 +83,8 @@ def __init__(
speed: float = 1,
intensity: float = 1,
blend_mode: str = 'blend',
keep: bool = False
keep: bool = False,
on_start = None
):
if self._deprecated:
warning('Warning: ULAction class will be renamed to "Action" in future releases!')
Expand Down Expand Up @@ -126,6 +129,8 @@ def __init__(
layer_action_name = game_object.getActionName(layer)
same_action = layer_action_name == action_name
self._callbacks: list[ActionCallback] = []
if on_start:
self.on_start = on_start
if (not same_action and self.is_playing):
game_object.stopAction(layer)
if not (self.is_playing or same_action):
Expand Down Expand Up @@ -172,11 +177,12 @@ def is_playing(self):

@property
def started(self):
return self.frame - self.start_frame < self.speed
return self.frame - self.start_frame < self.speed * FRAMETIME_COMPARE

@property
def finished(self):
return self.end_frame - self.frame < self.speed
# print(self.end_frame - self.frame, self.speed * FRAMETIME_COMPARE)
return self.end_frame - self.frame < 1

@property
def frame(self) -> float:
Expand Down
31 changes: 18 additions & 13 deletions uplogic/nodes/actions/playaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ def get_act_system(self):
else:
return ActionSystem('default')

def on_start(self):
self._started = True

def _get_started(self):
return self._action and self._action.started
return self._started

def on_finish(self):
self._finished = True

def _get_finished(self):
return self._action and self._action.finished
return self._finished

def _get_running(self):
if self._action:
Expand All @@ -66,6 +69,7 @@ def _get_frame(self):

def reset(self):
self._finished = False
self._started = False
return super().reset()

def evaluate(self):
Expand Down Expand Up @@ -113,17 +117,18 @@ def evaluate(self):
speed = 0.01

self._action = Action(
game_object,
bpy_action.name,
start_frame,
end_frame,
layer,
priority,
blendin,
play_mode,
speed,
intensity,
blend_mode
game_object=game_object,
action_name=bpy_action.name,
start_frame=start_frame,
end_frame=end_frame,
layer=layer,
priority=priority,
blendin=blendin,
play_mode=play_mode,
speed=speed,
intensity=intensity,
blend_mode=blend_mode,
on_start=self.on_start
)
self._action.on_finish = self.on_finish
self.in_use = True
2 changes: 1 addition & 1 deletion uplogic/nodes/logictree.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def is_stopped(self):
def stop(self, network=None):
if self.stopped:
return
self._time_then = None
# self._time_then = None # XXX: Was this important? Causes issues when stopping and restarting
self.stopped = True
for cell in self._cells:
cell.stop(self)
Expand Down
5 changes: 5 additions & 0 deletions uplogic/shaders/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def texture(self, val):
val.gl_load()
self.uniforms['tex'] = val

def free_textue(self):
self.uniforms['tex'].gl_free()
self.uniforms['tex'].buffers_free()


@property
def opacity(self):
return self.uniforms['opacity']
Expand Down
3 changes: 2 additions & 1 deletion uplogic/utils/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import operator
from mathutils import Vector
from bge import logic
import bpy


# uplogic game properties
Expand Down Expand Up @@ -60,7 +61,7 @@ def MATMUL (a, b):
}


FRAMETIME_COMPARE = 1 / 60
FRAMETIME_COMPARE = 1 / bpy.data.scenes[logic.getCurrentScene().name].render.fps


def FPS_FACTOR() -> float:
Expand Down

0 comments on commit 7d41024

Please sign in to comment.