From 721903998029966a020e8eb0091afc449c638761 Mon Sep 17 00:00:00 2001 From: Roz K Date: Mon, 2 Jan 2023 12:43:25 +0100 Subject: [PATCH] Split scene groups and nodes. --- game/game.py | 32 ++++++++++++++++---------------- game/scene.py | 16 ++++++++-------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/game/game.py b/game/game.py index 9948add..1fca74f 100644 --- a/game/game.py +++ b/game/game.py @@ -33,7 +33,7 @@ from game.environment import Environment from game.inputs import InputFloat from game.batch import Batch from game.entity import Entity -from game.scene import Node, SceneNode, TextureNode, ShaderNode, InputNode, DrawNode, FuncNode +from game.scene import Group, SceneGroup, TextureGroup, ShaderGroup, InputNode, DrawNode, FuncNode from game import sea proj_hfov = pi * 0.25 @@ -44,11 +44,11 @@ proj_far_z = 3000.0 sun_direction = math.vec3_normalize((1.0, 0.0, 0.5)) sun_power = 1.0 -class PerfNode(Node): +class PerfGroup(Group): __slots__ = '_count', '_min', '_max', '_total', '_name' def __init__(self, name, *subnodes): - Node.__init__(self, *subnodes) + Group.__init__(self, *subnodes) self._count = None self._min = 10000.0 self._max = 0.0 @@ -62,7 +62,7 @@ class PerfNode(Node): def draw(self, time): begin = thread_time() - Node.draw(self, time) + Group.draw(self, time) elapsed = (thread_time() - begin) * 1000.0 if self._count is None: self._count = 0 @@ -189,27 +189,27 @@ def create_scene(keyboard, mouse): assert tiles_shader.u_height_sampler == tests_shader.u_height_sampler assert tiles_shader.u_normal_sampler == tests_shader.u_normal_sampler - return SceneNode( - PerfNode('frame', - TextureNode({tiles_shader.u_height_sampler: heightmap, tiles_shader.u_normal_sampler: normalmap}, + return SceneGroup( + PerfGroup('frame', + TextureGroup({tiles_shader.u_height_sampler: heightmap, tiles_shader.u_normal_sampler: normalmap}, FuncNode(update_camera, (mouse, camera, environment)), - TextureNode({tiles_shader.u_texture_sampler: tiles_texture}, - ShaderNode(tiles_shader, + TextureGroup({tiles_shader.u_texture_sampler: tiles_texture}, + ShaderGroup(tiles_shader, InputNode(tiles_shader, camera, environment), - PerfNode('tiles_batch', + PerfGroup('tiles_batch', DrawNode(tiles_batch)))), FuncNode(update_tests, (blob, cube, clouds)), - TextureNode({tests_shader.u_texture_sampler: tests_texture}, - ShaderNode(tests_shader, + TextureGroup({tests_shader.u_texture_sampler: tests_texture}, + ShaderGroup(tests_shader, InputNode(tests_shader, camera, environment), - PerfNode('tests_batch', + PerfGroup('tests_batch', DrawNode(tests_batch))))), FuncNode(update_sea, (camera, sea_phase)), - TextureNode( + TextureGroup( {sea_shader.u_polar_sampler: sea_polar_textures, sea_shader.u_detail_sampler: sea_detail_texture}, - ShaderNode(sea_shader, + ShaderGroup(sea_shader, InputNode(sea_shader, camera, environment, sea_phase), - PerfNode('sea_triangles', + PerfGroup('sea_triangles', DrawNode(sea_triangles)))))) def loop(display): diff --git a/game/scene.py b/game/scene.py index 980e0af..24d12a0 100644 --- a/game/scene.py +++ b/game/scene.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -class Node: +class Group: __slots__ = '_subnodes' def __init__(self, *subnodes): @@ -23,34 +23,34 @@ class Node: for subnode in self._subnodes: subnode.draw(time) -class SceneNode(Node): +class SceneGroup(Group): pass -class TextureNode(Node): +class TextureGroup(Group): __slots__ = '_textures' def __init__(self, textures, *subnodes): - Node.__init__(self, *subnodes) + Group.__init__(self, *subnodes) self._textures = textures def draw(self, time): items = self._textures.items() for slot, texture in items: texture.select(slot) - Node.draw(self, time) + Group.draw(self, time) for slot, texture in items: texture.unselect(slot) -class ShaderNode(Node): +class ShaderGroup(Group): __slots__ = '_shader' def __init__(self, shader, *subnodes): - Node.__init__(self, *subnodes) + Group.__init__(self, *subnodes) self._shader = shader def draw(self, time): self._shader.select() - Node.draw(self, time) + Group.draw(self, time) self._shader.unselect() class InputNode: