Skip to content

Commit

Permalink
pooling improvements, HBAO changes, new decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
IzaZed committed Jul 7, 2023
1 parent 9527d0d commit 26b81a8
Show file tree
Hide file tree
Showing 28 changed files with 193 additions and 115 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def read_file(name):
return f.read()


version = 'v1.9.1.2'
version = 'v1.9.3'
shortdesc = "Uplogic utility for UPBGE."
longdesc = '\n\n'.join([read_file(name) for name in [
'README.md',
Expand All @@ -31,7 +31,7 @@ def read_file(name):
author='Leopold Auersperg-Castell',
author_email='[email protected]',
url='https://github.com/UPBGE/uplogic',
download_url='https://github.com/UPBGE/uplogic/archive/refs/tags/v1.9.1.2.tar.gz',
download_url='https://github.com/UPBGE/uplogic/archive/refs/tags/v1.9.3.tar.gz',
license='GPLv2',
packages=[
'uplogic',
Expand Down
3 changes: 2 additions & 1 deletion uplogic/animation/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def __init__(
# self.finished = True
# return
layer = self.layer
same_action = game_object.getActionName(layer) == action_name
layer_action_name = game_object.getActionName(layer)
same_action = layer_action_name == action_name
self.on_start()
if (not same_action and self.is_playing):
game_object.stopAction(layer)
Expand Down
47 changes: 47 additions & 0 deletions uplogic/decorators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,53 @@ def setPropObject(self, value, attr_name=game_prop):
return deco


def instance_props(*prop_names) -> KX_PythonComponent:
"""Decorator for `KX_PythonComponent` or `KX_GameObject` classes and subclasses.
Automatically adds property handlers for this class to use the `game_object[prop]`
syntax instead of saving values on the instance itself.
:param `prop_names`: Names of game properties as a list.
"""

def on_attr(self, val):
pass

def deco(cls: KX_PythonComponent or KX_GameObject) -> KX_PythonComponent or KX_GameObject:
if not (issubclass(cls, KX_PythonComponent) or issubclass(cls, KX_GameObject)):
raise TypeMismatchError('Decorator only viable for KX_PythonComponent or KX_GameObject subclasses!')
if not (isinstance(prop_names, list) or isinstance(prop_names, tuple)):
raise TypeMismatchError('Expected property names as a list or tuple!')
for game_prop in prop_names:

def getPropComponent(self, attr_name=game_prop):
return self.object.groupObject.get(attr_name)

def setPropComponent(self, value, attr_name=game_prop):
getattr(self, f'on_{game_prop}')(value)
self.object.groupObject[attr_name] = value

def getPropObject(self, attr_name=game_prop):
return self.groupObject.get(attr_name)

def setPropObject(self, value, attr_name=game_prop):
getattr(self, f'on_{game_prop}')(value)
self.groupObject[attr_name] = value

if issubclass(cls, KX_PythonComponent):
prop = property(getPropComponent, setPropComponent)
elif issubclass(cls, KX_GameObject):
prop = property(getPropObject, setPropObject)
else:
return

setattr(cls, game_prop, prop)
if not hasattr(cls, f'on_{game_prop}'):
setattr(cls, f'on_{game_prop}', on_attr)
return cls
return deco


def bl_attrs(*attr_names) -> KX_PythonComponent:
"""Decorator for `KX_PythonComponent` or `KX_GameObject` classes and subclasses.
Expand Down
8 changes: 4 additions & 4 deletions uplogic/input/gamepad.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def gamepad_axis(
def gamepad_trigger(
trigger: str = 'LT',
idx: int = 0,
threshold: float = .07
threshold: float = .1
) -> float:
"""Retrieve gamepad trigger values.
Expand All @@ -153,8 +153,8 @@ def gamepad_trigger(
def gamepad_stick(
stick: str = LS,
idx: int = 0,
threshold: float = .07
) -> set:
threshold: float = .1
) -> Vector:
'''Retrieve stick values.
:param stick: which stick to use.
Expand All @@ -168,7 +168,7 @@ def gamepad_stick(
yaxis = STICKS[stick][1]
return Vector((
gamepad_axis(xaxis, idx, threshold=threshold),
gamepad_axis(yaxis, idx, threshold=threshold)
-gamepad_axis(yaxis, idx, threshold=threshold)
))


Expand Down
9 changes: 5 additions & 4 deletions uplogic/network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def on_receive(self, msg):

def send(self, msg, subject=''):
if self.socket and self.running:
msg = {
'subject': subject,
'content': msg
}
if subject:
msg = {
'subject': subject,
'content': msg
}
for conn in self.clients:
conn.send(pickle.dumps(msg))

Expand Down
5 changes: 4 additions & 1 deletion uplogic/nodes/actions/createuibutton.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uplogic.nodes import ULOutSocket
from uplogic.ui import LabelButton
from uplogic.utils import not_met
from math import degrees
import bpy


Expand Down Expand Up @@ -76,6 +77,7 @@ def evaluate(self):
pos = ipt(self.pos)
rel_size = ipt(self.rel_size)
size = ipt(self.size)
angle = degrees(ipt(self.angle))
color = ipt(self.color)
border_width = ipt(self.border_width)
border_color = ipt(self.border_color)
Expand Down Expand Up @@ -106,7 +108,8 @@ def evaluate(self):
border_width=border_width,
border_color=border_color,
halign=self.halign_type,
valign=self.valign_type
valign=self.valign_type,
angle=angle
)
if parent:
parent.add_widget(self._widget)
Expand Down
5 changes: 4 additions & 1 deletion uplogic/nodes/actions/createuiimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uplogic.nodes import ULOutSocket
from uplogic.ui import Image
from uplogic.utils import not_met
from math import degrees


class ULCreateUIImage(ULActionNode):
Expand Down Expand Up @@ -42,6 +43,7 @@ def evaluate(self):
pos = ipt(self.pos)
rel_size = ipt(self.rel_size)
size = ipt(self.size)
angle = degrees(ipt(self.angle))
texture = ipt(self.texture)

self._widget = Image(
Expand All @@ -50,7 +52,8 @@ def evaluate(self):
texture=texture,
relative={'pos': rel_pos, 'size': rel_size},
halign=self.halign_type,
valign=self.valign_type
valign=self.valign_type,
angle=angle
)
if parent:
parent.add_widget(self._widget)
Expand Down
6 changes: 5 additions & 1 deletion uplogic/nodes/actions/createuilabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uplogic.nodes import ULOutSocket
from uplogic.ui import Label
from uplogic.utils import not_met
from math import degrees
import bpy


Expand All @@ -13,6 +14,7 @@ def __init__(self):
self.rel_pos = None
self.pos = None
self.rel_size = None
self.angle = None
self.text = None
self.text_pos = None
self.font = None
Expand Down Expand Up @@ -45,6 +47,7 @@ def evaluate(self):
parent = ipt(self.parent)
rel_pos = ipt(self.rel_pos)
pos = ipt(self.pos)
angle = degrees(ipt(self.angle))
text = ipt(self.text)
font = ipt(self.font)
font_size = ipt(self.font_size)
Expand Down Expand Up @@ -74,7 +77,8 @@ def evaluate(self):
font_color=font_color,
shadow=use_shadow,
shadow_offset=shadow_offset,
shadow_color=shadow_color
shadow_color=shadow_color,
angle=angle
)
if parent:
parent.add_widget(self._widget)
Expand Down
5 changes: 4 additions & 1 deletion uplogic/nodes/actions/createuilayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from uplogic.nodes import ULOutSocket
from uplogic.ui import RelativeLayout, FloatLayout, BoxLayout
from uplogic.utils import not_met
from math import degrees


layouts = {
Expand Down Expand Up @@ -52,6 +53,7 @@ def evaluate(self):
pos = ipt(self.pos)
rel_size = ipt(self.rel_size)
size = ipt(self.size)
angle = degrees(ipt(self.angle))
color = ipt(self.color)
border_width = ipt(self.border_width)
border_color = ipt(self.border_color)
Expand All @@ -64,7 +66,8 @@ def evaluate(self):
border_width=border_width,
border_color=border_color,
halign=self.halign_type,
valign=self.valign_type
valign=self.valign_type,
angle=angle
)
if self.layout_type == 'BoxLayout':
self._widget.orientation = self.boxlayout_type
Expand Down
4 changes: 2 additions & 2 deletions uplogic/nodes/actions/followpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uplogic.nodes import ULOutSocket
from uplogic.utils import is_invalid
from uplogic.utils import not_met
from uplogic.utils.objects import rot_to
from uplogic.utils.objects import rotate_to
from uplogic.utils.objects import move_to


Expand Down Expand Up @@ -107,7 +107,7 @@ def evaluate(self):
if next_point:
tpf = self.network.time_per_frame
if look_at:
rot_to(
rotate_to(
rot_axis,
rotating_object,
next_point,
Expand Down
4 changes: 2 additions & 2 deletions uplogic/nodes/actions/movetowithnavmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from uplogic.nodes import ULActionNode, ULOutSocket
from uplogic.utils import is_invalid
from uplogic.utils import not_met
from uplogic.utils.objects import rot_to
from uplogic.utils.objects import rotate_to
from uplogic.utils.objects import move_to


Expand Down Expand Up @@ -120,7 +120,7 @@ def evaluate(self):
if next_point:
tpf = self.network.time_per_frame
if look_at and (rotating_object is not None):
rot_to(
rotate_to(
rot_axis,
rotating_object,
next_point,
Expand Down
19 changes: 2 additions & 17 deletions uplogic/nodes/actions/rotateto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from uplogic.utils import is_invalid
from uplogic.utils import is_waiting
from uplogic.utils import not_met
from uplogic.utils import rotate_to


class ULActionRotateTo(ULActionNode):
Expand Down Expand Up @@ -40,21 +41,5 @@ def evaluate(self):
return
self._set_ready()
aim = get_local(moving_object, target_point)
if front_axis > 2:
speed = -speed
front_axis -= 3
if rot_axis == front_axis:
return
if rot_axis == 0:
aim = aim.yz.normalized()
rot = -aim.x if front_axis == 2 else aim.y
moving_object.applyRotation((rot * speed, 0, 0), True)
elif rot_axis == 1:
aim = aim.xz.normalized()
rot = aim.x if front_axis == 2 else -aim.y
moving_object.applyRotation((0, rot * speed, 0), True)
elif rot_axis == 2:
aim = aim.xy.normalized()
rot = -aim.x if front_axis == 1 else aim.y
moving_object.applyRotation((0, 0, rot * speed), True)
rotate_to(rot_axis, moving_object, target_point, front_axis, speed)
self._done = True
1 change: 1 addition & 0 deletions uplogic/nodes/actions/setuiwidgetattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"opacity": 'alpha_value',
"pos": 'vec2_value',
"size": 'vec2_value',
"angle": 'angle_value',
"width": 'float_value',
"height": 'float_value',
"use_clipping": 'bool_value',
Expand Down
1 change: 1 addition & 0 deletions uplogic/nodes/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@
from .getfont import ULGetFont
from .getuiwidgetattr import ULGetUIWidgetAttr
from .serializedata import ULSerializeData
from .rebuilddata import ULRebuildData
4 changes: 3 additions & 1 deletion uplogic/nodes/parameters/objectattr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def __init__(self):
ULParameterNode.__init__(self)
self.game_object = None
self.attribute_name = None
self.OUT = ULOutSocket(self, self.get_done)
self.VAL = ULOutSocket(self, self.get_done)
self.VEC = ULOutSocket(self, self.get_done)
self.BOOL = ULOutSocket(self, self.get_done)

def get_done(self):
game_object = self.get_input(self.game_object)
Expand Down
1 change: 0 additions & 1 deletion uplogic/nodes/parameters/storevalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ def evaluate(self):
condition = True
if not_met(condition):
return
print('STORING')
self._stored_value = self.get_input(self.value)
18 changes: 14 additions & 4 deletions uplogic/physics/character.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from bge import logic
from bge.constraints import getCharacter
from bge.types import KX_GameObject as GameObject
from uplogic.utils.constants import FRAMETIME_COMPARE
# from uplogic.logging import warning
from mathutils import Vector
import bpy

Expand Down Expand Up @@ -42,7 +44,8 @@ def on_ground(self) -> bool:

@on_ground.setter
def on_ground(self, value):
debug('ULCharacter.on_ground is Read-Only!')
# warning('ULCharacter.on_ground is Read-Only!')
pass

@property
def max_jumps(self) -> int:
Expand Down Expand Up @@ -74,16 +77,23 @@ def jump_count(self) -> int:

@jump_count.setter
def jump_count(self, value):
debug('Character.jump_count is Read-Only!')
# warning('Character.jump_count is Read-Only!')
pass

@property
def walk(self) -> Vector:
return ((self.wrapper.walkDirection @ self.owner.worldOrientation) * self._phys_step) / self.speed
fps = logic.getAverageFrameRate()
frametime = 1 / fps if fps > 0 else FRAMETIME_COMPARE
fps_factor = frametime / FRAMETIME_COMPARE
return ((self.wrapper.walkDirection @ self.owner.worldOrientation) * self._phys_step) / self.speed / fps_factor

@walk.setter
def walk(self, value):
fps = logic.getAverageFrameRate()
frametime = 1 / fps if fps > 0 else FRAMETIME_COMPARE
fps_factor = frametime / FRAMETIME_COMPARE
self.is_walking = True
self.wrapper.walkDirection = ((self.owner.worldOrientation @ value) / self._phys_step) * self.speed
self.wrapper.walkDirection = ((self.owner.worldOrientation @ value) / self._phys_step) * self.speed * fps_factor

@property
def velocity(self) -> Vector:
Expand Down
Loading

0 comments on commit 26b81a8

Please sign in to comment.