|
41 | 41 |
|
42 | 42 | GL_DEBUG = False |
43 | 43 |
|
| 44 | +class StopGameException(Exception): |
| 45 | + pass |
| 46 | + |
44 | 47 | class Minecraft(window.Window): |
45 | | - VERSION_STRING = '0.0.17a' |
| 48 | + VERSION_STRING = '0.0.18a_02' |
46 | 49 | __timer = Timer(20.0) |
47 | 50 | level = None |
48 | 51 | __levelRenderer = None |
@@ -138,7 +141,7 @@ def __checkGlError(self, string): |
138 | 141 | print(errorCode) |
139 | 142 | sys.exit(1) |
140 | 143 |
|
141 | | - def __destroy(self): |
| 144 | + def destroy(self): |
142 | 145 | try: |
143 | 146 | LevelIO.save(self.level, gzip.open('level.dat', 'wb')) |
144 | 147 | except Exception as e: |
@@ -446,7 +449,7 @@ def run(self): |
446 | 449 | lastTime += 1000 |
447 | 450 | frames = 0 |
448 | 451 |
|
449 | | - self.__destroy() |
| 452 | + self.destroy() |
450 | 453 |
|
451 | 454 | def grabMouse(self): |
452 | 455 | if self.__mouseGrabbed: |
@@ -682,7 +685,7 @@ def __render(self, a): |
682 | 685 | gl.glColorMask(True, True, True, True) |
683 | 686 | if i20 > 0: |
684 | 687 | gl.glEnable(gl.GL_TEXTURE_2D) |
685 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, self.__levelRenderer.textures.loadTexture('terrain.png', gl.GL_NEAREST)) |
| 688 | + gl.glBindTexture(gl.GL_TEXTURE_2D, self.__levelRenderer.textures.getTextureId('terrain.png')) |
686 | 689 | gl.glCallLists(self.__levelRenderer.dummyBuffer.capacity(), gl.GL_INT, self.__levelRenderer.dummyBuffer) |
687 | 690 | gl.glDisable(gl.GL_TEXTURE_2D) |
688 | 691 |
|
@@ -728,7 +731,7 @@ def __renderGui(self): |
728 | 731 | gl.glTranslatef(-1.5, 0.5, 0.5) |
729 | 732 | gl.glScalef(-1.0, -1.0, -1.0) |
730 | 733 |
|
731 | | - id_ = Textures.loadTexture('terrain.png', gl.GL_NEAREST) |
| 734 | + id_ = self.__textures.getTextureId('terrain.png') |
732 | 735 | gl.glBindTexture(gl.GL_TEXTURE_2D, id_) |
733 | 736 | gl.glEnable(gl.GL_TEXTURE_2D) |
734 | 737 | t.begin() |
@@ -826,45 +829,54 @@ def __getBuffer(self, a, b, c, d): |
826 | 829 | return self.__lb |
827 | 830 |
|
828 | 831 | def beginLevelLoading(self, title): |
829 | | - self.__title = title |
830 | | - screenWidth = self.width * 240 / self.height |
831 | | - screenHeight = self.height * 240 / self.height |
832 | | - |
833 | | - gl.glClear(gl.GL_DEPTH_BUFFER_BIT) |
834 | | - gl.glMatrixMode(gl.GL_PROJECTION) |
835 | | - gl.glLoadIdentity() |
836 | | - gl.glOrtho(0.0, screenWidth, screenHeight, 0.0, 100.0, 300.0) |
837 | | - gl.glMatrixMode(gl.GL_MODELVIEW) |
838 | | - gl.glLoadIdentity() |
839 | | - gl.glTranslatef(0.0, 0.0, -200.0) |
| 832 | + if not self.running: |
| 833 | + raise StopGameException |
| 834 | + else: |
| 835 | + self.__title = title |
| 836 | + screenWidth = self.width * 240 / self.height |
| 837 | + screenHeight = self.height * 240 / self.height |
| 838 | + |
| 839 | + gl.glClear(gl.GL_DEPTH_BUFFER_BIT) |
| 840 | + gl.glMatrixMode(gl.GL_PROJECTION) |
| 841 | + gl.glLoadIdentity() |
| 842 | + gl.glOrtho(0.0, screenWidth, screenHeight, 0.0, 100.0, 300.0) |
| 843 | + gl.glMatrixMode(gl.GL_MODELVIEW) |
| 844 | + gl.glLoadIdentity() |
| 845 | + gl.glTranslatef(0.0, 0.0, -200.0) |
840 | 846 |
|
841 | 847 | def levelLoadUpdate(self, status): |
842 | | - self.__text = status |
843 | | - self.setLoadingProgress() |
| 848 | + if not self.running: |
| 849 | + raise StopGameException |
| 850 | + else: |
| 851 | + self.__text = status |
| 852 | + self.setLoadingProgress() |
844 | 853 |
|
845 | 854 | def setLoadingProgress(self): |
846 | | - screenWidth = self.width * 240 // self.height |
847 | | - screenHeight = self.height * 240 // self.height |
| 855 | + if not self.running: |
| 856 | + raise StopGameException |
| 857 | + else: |
| 858 | + screenWidth = self.width * 240 // self.height |
| 859 | + screenHeight = self.height * 240 // self.height |
848 | 860 |
|
849 | | - gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) |
| 861 | + gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) |
850 | 862 |
|
851 | | - t = tesselator |
852 | | - gl.glEnable(gl.GL_TEXTURE_2D) |
853 | | - id_ = self.__textures.loadTexture('dirt.png', gl.GL_NEAREST) |
854 | | - gl.glBindTexture(gl.GL_TEXTURE_2D, id_) |
855 | | - s = 32.0 |
856 | | - t.begin() |
857 | | - t.color(4210752) |
858 | | - t.vertexUV(0.0, screenHeight, 0.0, 0.0, screenHeight / s) |
859 | | - t.vertexUV(screenWidth, screenHeight, 0.0, screenWidth / s, screenHeight / s) |
860 | | - t.vertexUV(screenWidth, 0.0, 0.0, screenWidth / s, 0.0) |
861 | | - t.vertexUV(0.0, 0.0, 0.0, 0.0, 0.0) |
862 | | - t.end() |
863 | | - |
864 | | - self.font.drawShadow(self.__title, (screenWidth - self.font.width(self.__title)) // 2, screenHeight // 2 - 4 - 16, 0xFFFFFF) |
865 | | - self.font.drawShadow(self.__text, (screenWidth - self.font.width(self.__text)) // 2, screenHeight // 2 - 4 + 8, 0xFFFFFF) |
866 | | - clock.tick() |
867 | | - self.flip() |
| 863 | + t = tesselator |
| 864 | + gl.glEnable(gl.GL_TEXTURE_2D) |
| 865 | + id_ = self.__textures.getTextureId('dirt.png') |
| 866 | + gl.glBindTexture(gl.GL_TEXTURE_2D, id_) |
| 867 | + s = 32.0 |
| 868 | + t.begin() |
| 869 | + t.color(4210752) |
| 870 | + t.vertexUV(0.0, screenHeight, 0.0, 0.0, screenHeight / s) |
| 871 | + t.vertexUV(screenWidth, screenHeight, 0.0, screenWidth / s, screenHeight / s) |
| 872 | + t.vertexUV(screenWidth, 0.0, 0.0, screenWidth / s, 0.0) |
| 873 | + t.vertexUV(0.0, 0.0, 0.0, 0.0, 0.0) |
| 874 | + t.end() |
| 875 | + |
| 876 | + self.font.drawShadow(self.__title, (screenWidth - self.font.width(self.__title)) // 2, screenHeight // 2 - 4 - 16, 0xFFFFFF) |
| 877 | + self.font.drawShadow(self.__text, (screenWidth - self.font.width(self.__text)) // 2, screenHeight // 2 - 4 + 8, 0xFFFFFF) |
| 878 | + clock.tick() |
| 879 | + self.flip() |
868 | 880 |
|
869 | 881 | def generateLevel(self, i): |
870 | 882 | name = self.user.name if self.user else 'anonymous' |
@@ -917,7 +929,7 @@ def addChatMessage(self, string): |
917 | 929 | elif arg == '-mppass': |
918 | 930 | mpPass = sys.argv[i + 1] |
919 | 931 |
|
920 | | - game = Minecraft(fullScreen, width=854, height=480, caption='Minecraft 0.0.17a') |
| 932 | + game = Minecraft(fullScreen, width=854, height=480, caption='Minecraft 0.0.18a_02') |
921 | 933 | game.user = User(name, 0, mpPass) |
922 | 934 | if server and port: |
923 | 935 | game.setServer(server, int(port)) |
|
0 commit comments