Add perf node.
This commit is contained in:
parent
8e49c16929
commit
3621a340f1
75
game/game.py
75
game/game.py
@ -13,6 +13,7 @@
|
||||
# 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/>.
|
||||
|
||||
from time import thread_time
|
||||
from math import pi, tau, dist
|
||||
|
||||
from engine import *
|
||||
@ -32,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 SceneNode, TextureNode, ShaderNode, InputNode, DrawNode, FuncNode
|
||||
from game.scene import Node, SceneNode, TextureNode, ShaderNode, InputNode, DrawNode, FuncNode
|
||||
from game import sea
|
||||
|
||||
proj_hfov = pi * 0.25
|
||||
@ -43,6 +44,34 @@ proj_far_z = 3000.0
|
||||
sun_direction = math.vec3_normalize((1.0, 0.0, 0.5))
|
||||
sun_power = 1.0
|
||||
|
||||
class PerfNode(Node):
|
||||
__slots__ = '_count', '_min', '_max', '_total', '_name'
|
||||
|
||||
def __init__(self, name, *subnodes):
|
||||
Node.__init__(self, *subnodes)
|
||||
self._count = None
|
||||
self._min = 10000.0
|
||||
self._max = 0.0
|
||||
self._total = 0.0
|
||||
self._name = name
|
||||
|
||||
def __del__(self):
|
||||
avg = round(self._total / self._count, 2)
|
||||
print(self._name, "*", self._count,
|
||||
": min =", round(self._min, 2), ", max =", round(self._max, 2), ", avg =", avg, "(ms)")
|
||||
|
||||
def draw(self, time):
|
||||
begin = thread_time()
|
||||
Node.draw(self, time)
|
||||
elapsed = (thread_time() - begin) * 1000.0
|
||||
if self._count is None:
|
||||
self._count = 0
|
||||
else:
|
||||
self._count += 1
|
||||
self._min = min(self._min, elapsed)
|
||||
self._max = max(self._max, elapsed)
|
||||
self._total += elapsed
|
||||
|
||||
class TestEntity(Entity):
|
||||
__slots__ = 'translation', 'orientation', 'spawn_translation', 'spawn_orientation'
|
||||
|
||||
@ -158,30 +187,26 @@ def create_scene(keyboard, mouse):
|
||||
sea_triangles = sea.sea_triangles(64, proj_far_z - 0.1, proj_ratio)
|
||||
|
||||
return SceneNode(
|
||||
TextureNode({1: heightmap, 2: normalmap},
|
||||
FuncNode(update_camera, (mouse, camera, environment)),
|
||||
TextureNode({0: tiles_texture},
|
||||
ShaderNode(tiles_shader,
|
||||
InputNode(tiles_shader, camera, environment),
|
||||
DrawNode(tiles_batch)
|
||||
)
|
||||
),
|
||||
FuncNode(update_tests, (blob, cube, clouds)),
|
||||
TextureNode({0: tests_texture},
|
||||
ShaderNode(tests_shader,
|
||||
InputNode(tests_shader, camera, environment),
|
||||
DrawNode(tests_batch)
|
||||
)
|
||||
)
|
||||
),
|
||||
FuncNode(update_sea, (camera, sea_phase)),
|
||||
TextureNode({0: sea_polar_textures, 1: sea_detail_texture},
|
||||
ShaderNode(sea_shader,
|
||||
InputNode(sea_shader, camera, environment, sea_phase),
|
||||
DrawNode(sea_triangles)
|
||||
)
|
||||
)
|
||||
)
|
||||
PerfNode('frame',
|
||||
TextureNode({1: heightmap, 2: normalmap},
|
||||
FuncNode(update_camera, (mouse, camera, environment)),
|
||||
TextureNode({0: tiles_texture},
|
||||
ShaderNode(tiles_shader,
|
||||
InputNode(tiles_shader, camera, environment),
|
||||
PerfNode('tiles_batch',
|
||||
DrawNode(tiles_batch)))),
|
||||
FuncNode(update_tests, (blob, cube, clouds)),
|
||||
TextureNode({0: tests_texture},
|
||||
ShaderNode(tests_shader,
|
||||
InputNode(tests_shader, camera, environment),
|
||||
PerfNode('tests_batch',
|
||||
DrawNode(tests_batch))))),
|
||||
FuncNode(update_sea, (camera, sea_phase)),
|
||||
TextureNode({0: sea_polar_textures, 1: sea_detail_texture},
|
||||
ShaderNode(sea_shader,
|
||||
InputNode(sea_shader, camera, environment, sea_phase),
|
||||
PerfNode('sea_triangles',
|
||||
DrawNode(sea_triangles))))))
|
||||
|
||||
def loop(display):
|
||||
events = Events(display)
|
||||
|
Loading…
Reference in New Issue
Block a user