-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
85 lines (66 loc) · 2.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys, os, moss, glm, ctypes, glfw, pyglet, random, math, threading
from collections import deque
import pyglet.gl as gl
import world, player
def shaderReloadFix(self):
if self.vertexFilePath != None:
self.vertexSource = moss.readFile(self.vertexFilePath)
if self.fragmentFilePath != None:
self.fragmentSource = moss.readFile(self.fragmentFilePath)
if self.geometryFilePath != None:
self.geometrySource = moss.readFile(self.geometryFilePath)
self.delete()
self.__init__(self.vertexSource, self.fragmentSource, self.geometrySource, self.vertexFilePath, self.fragmentFilePath, self.geometryFilePath)
moss.Shader.reload = shaderReloadFix
class App:
def __init__(self):
self.window = moss.Window(
title = "AerBlock Remake",
width = 1600, # moss.context.displayWidth
height = 800, # moss.context.displayHeight
backgroundColor = moss.Color(0.0, 0.0, 0.0),
fullscreen = False, samples = 16
)
self.window.event(self.setup)
self.window.event(self.update)
self.window.event(self.exit)
def setup(self, window):
self.renderer = moss.Renderer(self.window)
self.renderer.bindTextures = lambda: None
self.shader = moss.Shader(
vertexFilePath = "shaders/default.vert",
fragmentFilePath = "shaders/default.frag",
geometryFilePath = "shaders/default.geom"
)
self.world = world.World(self.window)
self.player = player.Player(
self.world, self.shader, fov = 90,
position = glm.vec3(-5.0, 30.0, -5.0)
)
self.world.player = self.player
def update(self, window):
self.window.clear()
self.player.proccessInputs()
self.player.updatePhysics()
self.player.updateMatrices()
if self.window.input.getKey(moss.KEY_R):
self.window.reloadShaders()
self.world.tick()
self.world.prepareRendering()
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glEnable(gl.GL_CULL_FACE)
self.world.render(self.shader)
self.renderer.render(None, False, False)
gl.glDisable(gl.GL_CULL_FACE)
gl.glDisable(gl.GL_DEPTH_TEST)
def exit(self, window):
self.shader.delete()
self.renderer.delete()
def run(self):
moss.run()
def main(argv):
app = App()
app.run()
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))