Split scene groups and nodes.
This commit is contained in:
parent
3344ac7d6c
commit
7219039980
32
game/game.py
32
game/game.py
@ -33,7 +33,7 @@ from game.environment import Environment
|
|||||||
from game.inputs import InputFloat
|
from game.inputs import InputFloat
|
||||||
from game.batch import Batch
|
from game.batch import Batch
|
||||||
from game.entity import Entity
|
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
|
from game import sea
|
||||||
|
|
||||||
proj_hfov = pi * 0.25
|
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_direction = math.vec3_normalize((1.0, 0.0, 0.5))
|
||||||
sun_power = 1.0
|
sun_power = 1.0
|
||||||
|
|
||||||
class PerfNode(Node):
|
class PerfGroup(Group):
|
||||||
__slots__ = '_count', '_min', '_max', '_total', '_name'
|
__slots__ = '_count', '_min', '_max', '_total', '_name'
|
||||||
|
|
||||||
def __init__(self, name, *subnodes):
|
def __init__(self, name, *subnodes):
|
||||||
Node.__init__(self, *subnodes)
|
Group.__init__(self, *subnodes)
|
||||||
self._count = None
|
self._count = None
|
||||||
self._min = 10000.0
|
self._min = 10000.0
|
||||||
self._max = 0.0
|
self._max = 0.0
|
||||||
@ -62,7 +62,7 @@ class PerfNode(Node):
|
|||||||
|
|
||||||
def draw(self, time):
|
def draw(self, time):
|
||||||
begin = thread_time()
|
begin = thread_time()
|
||||||
Node.draw(self, time)
|
Group.draw(self, time)
|
||||||
elapsed = (thread_time() - begin) * 1000.0
|
elapsed = (thread_time() - begin) * 1000.0
|
||||||
if self._count is None:
|
if self._count is None:
|
||||||
self._count = 0
|
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_height_sampler == tests_shader.u_height_sampler
|
||||||
assert tiles_shader.u_normal_sampler == tests_shader.u_normal_sampler
|
assert tiles_shader.u_normal_sampler == tests_shader.u_normal_sampler
|
||||||
|
|
||||||
return SceneNode(
|
return SceneGroup(
|
||||||
PerfNode('frame',
|
PerfGroup('frame',
|
||||||
TextureNode({tiles_shader.u_height_sampler: heightmap, tiles_shader.u_normal_sampler: normalmap},
|
TextureGroup({tiles_shader.u_height_sampler: heightmap, tiles_shader.u_normal_sampler: normalmap},
|
||||||
FuncNode(update_camera, (mouse, camera, environment)),
|
FuncNode(update_camera, (mouse, camera, environment)),
|
||||||
TextureNode({tiles_shader.u_texture_sampler: tiles_texture},
|
TextureGroup({tiles_shader.u_texture_sampler: tiles_texture},
|
||||||
ShaderNode(tiles_shader,
|
ShaderGroup(tiles_shader,
|
||||||
InputNode(tiles_shader, camera, environment),
|
InputNode(tiles_shader, camera, environment),
|
||||||
PerfNode('tiles_batch',
|
PerfGroup('tiles_batch',
|
||||||
DrawNode(tiles_batch)))),
|
DrawNode(tiles_batch)))),
|
||||||
FuncNode(update_tests, (blob, cube, clouds)),
|
FuncNode(update_tests, (blob, cube, clouds)),
|
||||||
TextureNode({tests_shader.u_texture_sampler: tests_texture},
|
TextureGroup({tests_shader.u_texture_sampler: tests_texture},
|
||||||
ShaderNode(tests_shader,
|
ShaderGroup(tests_shader,
|
||||||
InputNode(tests_shader, camera, environment),
|
InputNode(tests_shader, camera, environment),
|
||||||
PerfNode('tests_batch',
|
PerfGroup('tests_batch',
|
||||||
DrawNode(tests_batch))))),
|
DrawNode(tests_batch))))),
|
||||||
FuncNode(update_sea, (camera, sea_phase)),
|
FuncNode(update_sea, (camera, sea_phase)),
|
||||||
TextureNode(
|
TextureGroup(
|
||||||
{sea_shader.u_polar_sampler: sea_polar_textures, sea_shader.u_detail_sampler: sea_detail_texture},
|
{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),
|
InputNode(sea_shader, camera, environment, sea_phase),
|
||||||
PerfNode('sea_triangles',
|
PerfGroup('sea_triangles',
|
||||||
DrawNode(sea_triangles))))))
|
DrawNode(sea_triangles))))))
|
||||||
|
|
||||||
def loop(display):
|
def loop(display):
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
class Node:
|
class Group:
|
||||||
__slots__ = '_subnodes'
|
__slots__ = '_subnodes'
|
||||||
|
|
||||||
def __init__(self, *subnodes):
|
def __init__(self, *subnodes):
|
||||||
@ -23,34 +23,34 @@ class Node:
|
|||||||
for subnode in self._subnodes:
|
for subnode in self._subnodes:
|
||||||
subnode.draw(time)
|
subnode.draw(time)
|
||||||
|
|
||||||
class SceneNode(Node):
|
class SceneGroup(Group):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class TextureNode(Node):
|
class TextureGroup(Group):
|
||||||
__slots__ = '_textures'
|
__slots__ = '_textures'
|
||||||
|
|
||||||
def __init__(self, textures, *subnodes):
|
def __init__(self, textures, *subnodes):
|
||||||
Node.__init__(self, *subnodes)
|
Group.__init__(self, *subnodes)
|
||||||
self._textures = textures
|
self._textures = textures
|
||||||
|
|
||||||
def draw(self, time):
|
def draw(self, time):
|
||||||
items = self._textures.items()
|
items = self._textures.items()
|
||||||
for slot, texture in items:
|
for slot, texture in items:
|
||||||
texture.select(slot)
|
texture.select(slot)
|
||||||
Node.draw(self, time)
|
Group.draw(self, time)
|
||||||
for slot, texture in items:
|
for slot, texture in items:
|
||||||
texture.unselect(slot)
|
texture.unselect(slot)
|
||||||
|
|
||||||
class ShaderNode(Node):
|
class ShaderGroup(Group):
|
||||||
__slots__ = '_shader'
|
__slots__ = '_shader'
|
||||||
|
|
||||||
def __init__(self, shader, *subnodes):
|
def __init__(self, shader, *subnodes):
|
||||||
Node.__init__(self, *subnodes)
|
Group.__init__(self, *subnodes)
|
||||||
self._shader = shader
|
self._shader = shader
|
||||||
|
|
||||||
def draw(self, time):
|
def draw(self, time):
|
||||||
self._shader.select()
|
self._shader.select()
|
||||||
Node.draw(self, time)
|
Group.draw(self, time)
|
||||||
self._shader.unselect()
|
self._shader.unselect()
|
||||||
|
|
||||||
class InputNode:
|
class InputNode:
|
||||||
|
Loading…
Reference in New Issue
Block a user