diff --git a/.gitignore b/.gitignore index 27541f05..a645c131 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *.core *.log .vscode -*.ogg \ No newline at end of file +*.ogg +*.sw[nop] diff --git a/README.md b/README.md index 115a266c..50adfcc3 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,6 @@ The community has several features and options that can be toggled in `options.p - **Nim implementation:** https://github.com/phargobikcin/nim-minecraft-clone - **Java implementation:** https://github.com/StartForKillerMC/JavaMinecraft - **C++ implementation:** https://github.com/Jukitsu/CppMinecraft-clone -- **Lighting test:** https://github.com/Jukitsu/python-minecraft-clone-ep10-lighting +- **Odin implementation:** https://github.com/anthony-63/lvo +- **Lua implementation:** https://github.com/brennop/lunarcraft +- **Javascript implementation:** https://github.com/drakeerv/js-minecraft-clone ([Demo](https://drakeerv.github.io/js-minecraft-clone/)) \ No newline at end of file diff --git a/community/audio/README.md b/community/audio/README.md new file mode 100644 index 00000000..8bb7b880 --- /dev/null +++ b/community/audio/README.md @@ -0,0 +1 @@ +For music download `.ogg` (or other) from [archive.org](https://archive.org/details/C418-MinecraftSoundtrackVolumeAlpha/) and put them into the music `dir`. diff --git a/community/audio/readme.txt b/community/audio/readme.txt deleted file mode 100644 index b14182ed..00000000 --- a/community/audio/readme.txt +++ /dev/null @@ -1 +0,0 @@ -For music download .ogg or other from https://archive.org/details/C418-MinecraftSoundtrackVolumeAlpha/ and put them into the music dir \ No newline at end of file diff --git a/community/controller.py b/community/controller.py index ea47aacc..6fde7f4f 100644 --- a/community/controller.py +++ b/community/controller.py @@ -132,3 +132,8 @@ def start_modifier(self, mode): def end_modifier(self, mode): if mode == self.ModifierMode.SPRINT: self.game.player.target_speed = player.WALKING_SPEED + + def apply_deadzone(self, value): + if abs(value[0]) < self.joystick_deadzone: value[0] = 0 + if abs(value[1]) < self.joystick_deadzone: value[1] = 0 + return value diff --git a/community/keyboard_mouse.py b/community/keyboard_mouse.py index 419019dc..fbed18bc 100644 --- a/community/keyboard_mouse.py +++ b/community/keyboard_mouse.py @@ -14,6 +14,9 @@ def __init__(self, game): self.game.on_key_press = self.on_key_press self.game.on_key_release = self.on_key_release + self.w_pressed = False + self.ctrl_pressed = False + def on_mouse_press(self, x, y, button, modifiers): if not self.game.mouse_captured: self.game.mouse_captured = True @@ -43,12 +46,19 @@ def on_key_press(self, key, modifiers): if key == pyglet.window.key.D: self.start_move(self.MoveMode.RIGHT) elif key == pyglet.window.key.A: self.start_move(self.MoveMode.LEFT) - elif key == pyglet.window.key.W: self.start_move(self.MoveMode.FORWARD) + elif key == pyglet.window.key.W: + self.w_pressed = True + self.start_move(self.MoveMode.FORWARD) + if self.ctrl_pressed: + self.start_modifier(self.ModifierMode.SPRINT) elif key == pyglet.window.key.S: self.start_move(self.MoveMode.BACKWARD) elif key == pyglet.window.key.SPACE : self.start_move(self.MoveMode.UP) elif key == pyglet.window.key.LSHIFT: self.start_move(self.MoveMode.DOWN) - elif key == pyglet.window.key.LCTRL : self.start_modifier(self.ModifierMode.SPRINT) + elif key == pyglet.window.key.LCTRL: + self.ctrl_pressed = True + if self.w_pressed: + self.start_modifier(self.ModifierMode.SPRINT) elif key == pyglet.window.key.E: self.misc(self.MiscMode.SPAWN) elif key == pyglet.window.key.F: self.misc(self.MiscMode.FLY) @@ -67,9 +77,15 @@ def on_key_release(self, key, modifiers): if key == pyglet.window.key.D: self.end_move(self.MoveMode.RIGHT) elif key == pyglet.window.key.A: self.end_move(self.MoveMode.LEFT) - elif key == pyglet.window.key.W: self.end_move(self.MoveMode.FORWARD) + elif key == pyglet.window.key.W: + self.w_pressed = False + self.end_move(self.MoveMode.FORWARD) + self.end_modifier(self.ModifierMode.SPRINT) elif key == pyglet.window.key.S: self.end_move(self.MoveMode.BACKWARD) elif key == pyglet.window.key.SPACE : self.end_move(self.MoveMode.UP) elif key == pyglet.window.key.LSHIFT: self.end_move(self.MoveMode.DOWN) - elif key == pyglet.window.key.LCTRL : self.end_modifier(self.ModifierMode.SPRINT) + elif key == pyglet.window.key.LCTRL: + self.ctrl_pressed = False + if not self.w_pressed: + self.end_modifier(self.ModifierMode.SPRINT) diff --git a/community/main.py b/community/main.py index 6a8148cd..90109dc6 100644 --- a/community/main.py +++ b/community/main.py @@ -144,7 +144,7 @@ def on_close(self): for fence in self.fences: gl.glDeleteSync(fence) - self.close() + super().on_close() def update_f3(self, delta_time): """Update the F3 debug screen content""" @@ -157,7 +157,7 @@ def update_f3(self, delta_time): visible_quad_count = sum(chunk.mesh_quad_count for chunk in self.world.visible_chunks) self.f3.text = \ f""" -{round(pyglet.clock.get_fps())} FPS ({self.world.chunk_update_counter} Chunk Updates) {"inf" if not self.options.VSYNC else "vsync"}{"ao" if self.options.SMOOTH_LIGHTING else ""} +{round(1 / delta_time)} FPS ({self.world.chunk_update_counter} Chunk Updates) {"inf" if not self.options.VSYNC else "vsync"}{"ao" if self.options.SMOOTH_LIGHTING else ""} C: {visible_chunk_count} / {chunk_count} pC: {self.world.pending_chunk_update_count} pU: {len(self.world.chunk_building_queue)} aB: {chunk_count} E: {self.world.visible_entities} / {len(self.world.entities)} Client Singleplayer @{round(delta_time * 1000)} ms tick {round(1 / delta_time)} TPS @@ -218,35 +218,16 @@ def on_draw(self): # Draw the F3 Debug screen if self.show_f3: - self.draw_f3() + self.f3.draw() # CPU - GPU Sync if not self.options.SMOOTH_FPS: - self.fences.append(gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0)) + # self.fences.append(gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0)) + # Broken in pyglet 2; glFenceSync is missing + pass else: gl.glFinish() - def draw_f3(self): - """Draws the f3 debug screen. Current uses the fixed-function pipeline since pyglet labels uses it""" - gl.glDisable(gl.GL_DEPTH_TEST) - gl.glUseProgram(0) - gl.glBindVertexArray(0) - gl.glMatrixMode(gl.GL_MODELVIEW) - gl.glPushMatrix() - gl.glLoadIdentity() - - gl.glMatrixMode(gl.GL_PROJECTION) - gl.glPushMatrix() - gl.glLoadIdentity() - gl.glOrtho(0, self.width, 0, self.height, -1, 1) - - self.f3.draw() - - gl.glPopMatrix() - - gl.glMatrixMode(gl.GL_MODELVIEW) - gl.glPopMatrix() - # input functions def on_resize(self, width, height): @@ -265,10 +246,8 @@ def __init__(self): depth_size = 16, sample_buffers=bool(options.ANTIALIASING), samples=options.ANTIALIASING) self.window = Window(config = self.config, width = 852, height = 480, caption = "Minecraft clone", resizable = True, vsync = options.VSYNC) - def run(self): - pyglet.app.run() - - + def run(self): + pyglet.app.run(interval = 0) def init_logger(): log_folder = "logs/" @@ -284,9 +263,6 @@ def init_logger(): logging.basicConfig(level=logging.INFO, filename=log_path, format="[%(asctime)s] [%(processName)s/%(threadName)s/%(levelname)s] (%(module)s.py/%(funcName)s) %(message)s") - - - def main(): init_logger() game = Game() diff --git a/episode-10/main.py b/episode-10/main.py index 349d0764..5e1cb717 100644 --- a/episode-10/main.py +++ b/episode-10/main.py @@ -145,9 +145,9 @@ def on_key_release(self, key, modifiers): class Game: def __init__(self): - self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16) + self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16) self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False) - + def run(self): pyglet.app.run() diff --git a/episode-11/main.py b/episode-11/main.py index d25691be..ed1a95cc 100644 --- a/episode-11/main.py +++ b/episode-11/main.py @@ -1,4 +1,3 @@ - import math import ctypes import random @@ -154,7 +153,7 @@ def on_key_release(self, key, modifiers): class Game: def __init__(self): - self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16) + self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16) self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False) def run(self): diff --git a/episode-12/main.py b/episode-12/main.py index 72525713..fb9c0c75 100644 --- a/episode-12/main.py +++ b/episode-12/main.py @@ -1,4 +1,3 @@ - import math import ctypes import random @@ -194,7 +193,7 @@ def on_key_release(self, key, modifiers): class Game: def __init__(self): - self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16) + self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16) self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False) def run(self): diff --git a/episode-13/main.py b/episode-13/main.py index 5c6a28af..67b11c0a 100644 --- a/episode-13/main.py +++ b/episode-13/main.py @@ -1,4 +1,3 @@ - import math import random import pyglet @@ -162,7 +161,7 @@ def on_key_release(self, key, modifiers): class Game: def __init__(self): - self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16) + self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16) self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False) def run(self):