From 921810763735b0002c490f0f9660d3bf10c9c596 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Mon, 13 Jun 2016 22:14:51 -0400 Subject: [PATCH 1/2] Add loading text at start since first draw loop takes long time --- main.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 6f962e33..8fb7e820 100644 --- a/main.py +++ b/main.py @@ -484,6 +484,13 @@ def __init__(self, *args, **kwargs): x=10, y=self.height - 10, anchor_x='left', anchor_y='top', color=(0, 0, 0, 255)) + # Boolean whether to display loading screen + self.is_initializing = True + # Loading screen label displayed in center of canvas + self.loading_label = pyglet.text.Label('', font_name='Arial', font_size=100, + x=self.width // 2, y=self.height // 2, anchor_x='center', anchor_y='center', + color=(0, 0, 0, 255)) + # This call schedules the `update()` method to be called # TICKS_PER_SEC. This is the main game event loop. pyglet.clock.schedule_interval(self.update, 1.0 / TICKS_PER_SEC) @@ -803,13 +810,16 @@ def on_draw(self): """ self.clear() - self.set_3d() - glColor3d(1, 1, 1) - self.model.batch.draw() - self.draw_focused_block() + if not self.is_initializing: + self.set_3d() + glColor3d(1, 1, 1) + self.model.batch.draw() + self.draw_focused_block() + self.set_2d() + self.draw_reticle() self.set_2d() self.draw_label() - self.draw_reticle() + self.is_initializing = False def draw_focused_block(self): """ Draw black edges around the block that is currently under the @@ -830,18 +840,24 @@ def draw_label(self): """ Draw the label in the top left of the screen. """ - x, y, z = self.position - self.label.text = '%02d (%.2f, %.2f, %.2f) %d / %d' % ( - pyglet.clock.get_fps(), x, y, z, - len(self.model._shown), len(self.model.world)) - self.label.draw() + if not self.is_initializing: + x, y, z = self.position + self.label.text = '%02d (%.2f, %.2f, %.2f) %d / %d' % ( + pyglet.clock.get_fps(), x, y, z, + len(self.model._shown), len(self.model.world)) + self.label.draw() + else: + # Only draw the loading screen during the first draw loop + self.loading_label.text = 'Loading...' + self.loading_label.draw() def draw_reticle(self): """ Draw the crosshairs in the center of the screen. """ - glColor3d(0, 0, 0) - self.reticle.draw(GL_LINES) + if not self.is_initializing: + glColor3d(0, 0, 0) + self.reticle.draw(GL_LINES) def setup_fog(): From 6ae0bd7e60d61f6d71a57db58aa49fb5fda51c76 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 14 Jun 2016 21:07:22 -0400 Subject: [PATCH 2/2] Delete loading label after it's used --- main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8fb7e820..af4cbd91 100644 --- a/main.py +++ b/main.py @@ -819,7 +819,9 @@ def on_draw(self): self.draw_reticle() self.set_2d() self.draw_label() - self.is_initializing = False + if self.is_initializing: + self.loading_label.delete() + self.is_initializing = False def draw_focused_block(self): """ Draw black edges around the block that is currently under the