From f4ae2890ef95b44b8fcdfc519a50e578eb510ae4 Mon Sep 17 00:00:00 2001 From: Jukitsu <84381972+Jukitsu@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:33:11 +0200 Subject: [PATCH 1/3] Added Mixins --- .gitnore => .gitignore | 3 +- episode-11-Fire-Loader/camera.py | 8 +- episode-11-Fire-Loader/chunk.py | 23 ++++- episode-11-Fire-Loader/main.py | 13 ++- episode-11-Fire-Loader/matrix.py | 9 +- .../__pycache__/__init__.cpython-39.pyc | Bin 413 -> 0 bytes .../models/__pycache__/button.cpython-39.pyc | Bin 1080 -> 0 bytes .../models/__pycache__/cactus.cpython-39.pyc | Bin 1026 -> 0 bytes .../models/__pycache__/crop.cpython-39.pyc | Bin 1156 -> 0 bytes .../models/__pycache__/cube.cpython-39.pyc | Bin 1016 -> 0 bytes .../models/__pycache__/door.cpython-39.pyc | Bin 1016 -> 0 bytes .../models/__pycache__/fire.cpython-39.pyc | Bin 774 -> 0 bytes .../models/__pycache__/flat.cpython-39.pyc | Bin 624 -> 0 bytes .../models/__pycache__/glass.cpython-39.pyc | Bin 1016 -> 0 bytes .../models/__pycache__/ladder.cpython-39.pyc | Bin 776 -> 0 bytes .../models/__pycache__/leaves.cpython-39.pyc | Bin 1018 -> 0 bytes .../models/__pycache__/lever.cpython-39.pyc | Bin 1079 -> 0 bytes .../models/__pycache__/liquid.cpython-39.pyc | Bin 1025 -> 0 bytes .../models/__pycache__/plant.cpython-39.pyc | Bin 775 -> 0 bytes .../__pycache__/pressure_plate.cpython-39.pyc | Bin 634 -> 0 bytes .../models/__pycache__/sign.cpython-39.pyc | Bin 774 -> 0 bytes .../__pycache__/sign_post.cpython-39.pyc | Bin 779 -> 0 bytes .../models/__pycache__/slab.cpython-39.pyc | Bin 1078 -> 0 bytes .../models/__pycache__/snow.cpython-39.pyc | Bin 624 -> 0 bytes .../models/__pycache__/soil.cpython-39.pyc | Bin 1086 -> 0 bytes .../models/__pycache__/stairs.cpython-39.pyc | Bin 1080 -> 0 bytes .../models/__pycache__/torch.cpython-39.pyc | Bin 1029 -> 0 bytes episode-11-Fire-Loader/subchunk.py | 91 +++++++++++------- episode-11-Fire-Loader/world.py | 23 ++++- 29 files changed, 119 insertions(+), 51 deletions(-) rename .gitnore => .gitignore (54%) delete mode 100644 episode-11-Fire-Loader/models/__pycache__/__init__.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/button.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/cactus.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/crop.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/cube.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/door.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/fire.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/flat.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/glass.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/ladder.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/leaves.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/lever.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/liquid.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/plant.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/pressure_plate.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/sign.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/sign_post.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/slab.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/snow.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/soil.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/stairs.cpython-39.pyc delete mode 100644 episode-11-Fire-Loader/models/__pycache__/torch.cpython-39.pyc diff --git a/.gitnore b/.gitignore similarity index 54% rename from .gitnore rename to .gitignore index a2eaf75..7d2e9bd 100644 --- a/.gitnore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__/ -mods/ \ No newline at end of file +mods/ +*.pyc \ No newline at end of file diff --git a/episode-11-Fire-Loader/camera.py b/episode-11-Fire-Loader/camera.py index ba765c7..111725c 100644 --- a/episode-11-Fire-Loader/camera.py +++ b/episode-11-Fire-Loader/camera.py @@ -1,4 +1,5 @@ import math + import matrix WALKING_SPEED = 7 @@ -28,17 +29,12 @@ def __init__(self, shader, width, height): self.target_speed = WALKING_SPEED self.speed = self.target_speed - - # set variables to read - - self.walking_speed_r = WALKING_SPEED - self.sprinting_speed_r = SPRINTING_SPEED def update_camera(self, delta_time): self.speed += (self.target_speed - self.speed) * delta_time * 20 multiplier = self.speed * delta_time - self.position[1] += (1 if self.input[1] else 0) * multiplier + self.position[1] += self.input[1] * multiplier if self.input[0] or self.input[2]: angle = self.rotation[0] - math.atan2(self.input[2], self.input[0]) + math.tau / 4 diff --git a/episode-11-Fire-Loader/chunk.py b/episode-11-Fire-Loader/chunk.py index 9732e2e..2908da8 100644 --- a/episode-11-Fire-Loader/chunk.py +++ b/episode-11-Fire-Loader/chunk.py @@ -4,12 +4,22 @@ import pyglet.gl as gl import subchunk +import os CHUNK_WIDTH = 16 CHUNK_HEIGHT = 128 CHUNK_LENGTH = 16 -class Chunk: +mods = [] +mods_imported = [] + +if os.path.isdir("mods"): + mods = [os.path.join("mods", f[1], "chunk.py").replace(".py", "") for f in [[os.listdir(os.path.join("mods", d)), d] for d in os.listdir("mods") if os.path.isdir(os.path.join("mods", d))] if "chunk.py" in f[0]] + mods_imported = [__import__(m.replace("\\", "."), fromlist=[""]) for m in mods] + +print(mods) + +class ChunkBaseImpl: def __init__(self, world, chunk_position): self.world = world @@ -186,4 +196,13 @@ def draw(self): gl.GL_TRIANGLES, self.mesh_indices_length, gl.GL_UNSIGNED_INT, - None) \ No newline at end of file + None) + +ChunkMixins = [] +for module in mods_imported: + if hasattr(module, "ChunkMixin"): + ChunkMixins.append(module.ChunkMixin) + print("Applying mixin to class chunk.Chunk") + +class Chunk(*ChunkMixins, ChunkBaseImpl): + """Chunk class that handles storage of blocks and render region""" diff --git a/episode-11-Fire-Loader/main.py b/episode-11-Fire-Loader/main.py index 35e9267..5d6ec45 100644 --- a/episode-11-Fire-Loader/main.py +++ b/episode-11-Fire-Loader/main.py @@ -24,7 +24,7 @@ import hit -lines = ["--- Welcome to Fire Loader ---", "Developed by drakeerv", "Modified from obiwac", "--- Starting---", ""] +lines = ["--- Welcome to Fire Loader ---", "Developed by drakeerv and Jukitsu", "Modified from obiwac", "--- Starting---", ""] [print(line) for line in lines] del lines @@ -40,7 +40,7 @@ print("") -class Window(pyglet.window.Window): +class WindowBaseImpl(pyglet.window.Window): def __init__(self, **args): super().__init__(**args) @@ -219,6 +219,15 @@ def on_key_release(self, key, modifiers): try: module.keyboard_release(self) except Exception as e: print(e) +WindowMixins = [] +for module in mods_imported: + if hasattr(module, "WindowMixin"): + WindowMixins.append(module.WindowMixin) + print("Applying mixin to class main.Window") + +class Window(*WindowMixins, WindowBaseImpl): + """Window class that handles the game window and event callbacks""" + class Game: def __init__(self): self.config = gl.Config(major_version = 3, depth_size = 16) diff --git a/episode-11-Fire-Loader/matrix.py b/episode-11-Fire-Loader/matrix.py index f2a5c61..477eb96 100644 --- a/episode-11-Fire-Loader/matrix.py +++ b/episode-11-Fire-Loader/matrix.py @@ -3,6 +3,7 @@ import ctypes import math + def copy_matrix(matrix): return copy.deepcopy(matrix) # we need to use deepcopy since we're dealing with 2D arrays @@ -42,15 +43,18 @@ def __mul__(self, matrix): def __imul__(self, matrix): self.data = multiply_matrices(self.data, matrix.data) - def scale(self, x, y, z): + + def scale(self, scale_x, scale_y, scale_z): for i in range(4): self.data[0][i] *= scale_x for i in range(4): self.data[1][i] *= scale_y for i in range(4): self.data[2][i] *= scale_z + def translate(self, x, y, z): for i in range(4): self.data[3][i] = self.data[3][i] + (self.data[0][i] * x + self.data[1][i] * y + self.data[2][i] * z) + def rotate(self, angle, x, y, z): magnitude = math.sqrt(x * x + y * y + z * z) @@ -114,6 +118,7 @@ def frustum(self, left, right, bottom, top, near, far): self.data = multiply_matrices(self.data, frustum_matrix) + def perspective(self, fovy, aspect, near, far): frustum_y = math.tan(math.radians(fovy) / 2) frustum_x = frustum_y * aspect @@ -137,3 +142,5 @@ def orthographic(self, left, right, bottom, top, near, far): orthographic_matrix[3][2] = -(near + far) / deltaz self.data = multiply_matrices(self.data, orthographic_matrix) + + diff --git a/episode-11-Fire-Loader/models/__pycache__/__init__.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index b9d64ac3898ae53cd2cf970899e161792941dbe0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 413 zcmYk2!Ab)$5Qeku?%E3Vq~I&8vO+H&L`4uhsR()s3o+eHw}CW?Nw(t2ck$*c$@J4gu6Uq%>x{)R zBNZKc*=c5tM=XqS*o+GSF6Jpg3k551bjLdIzIVWIa)4OQ`Vfr99@;$9vgK{){U@$P zsw`#)x78qSF~*f*ERuKP#+dnaU$1b|SZ6xNm%gztVPSCkM&GUVjnvROJ`e0t84Z7B z^>TyjHsLyLRx88tw+&e7jevSOt*;WkUgIS){mH+*oV3W);(jD*w^AS5_hk<2#Urj{J9HS1LLz@1-!BkF~( z;5+aMsfUUi=N=HVV`tV_FqWU@y?HY`mRBwoGlB8&$?td9z7RK-^ka(T8NTKtLM9TC zd5MSbXd|-G7Y}hv=o3x|1Hvg{kc`oBK)l6!l(*>gAo0;RqgsoHl+Otlj6pKVmTyFO z^!7BI-{M9XKjJPC0zBjd``R}r!PpiF$Tr&3aNepc^qj88HBv@qI|sYnI6fZ+!~R9P zZg&KAJ32UVK>OXiOmB0yifbf|&3|p~OqBf>_(QOpC$$+-hVBpiihD)8VBJ5mw*3TB zxo>E91@f^u^lu+f+{7@ka~VP(oRu^5fBt0Sdklf~GjQc+3{zWScohcCVGXi0l>}AR z%``XZdUvLp$)=FTH1{tR)ard&X_MEvE=@DDbgeaHrdgT`ndRjsy_CgHnXdwtcD#kV z59-mX0=)sbHLL2XzR+dL{B_G;=A~MLJg?K|g)UWRi?(|?T3b0f&p}0nmYIT;s&b<< z6`hY}dZa(26WEwrqg=&4)$7E8p%ZlC;VE-B&W_!| zGwuk-gFi1GeQ2Qu3-Mvy*A}#Olb{n-L(6)ld73h|NjD@tgSu2{xPxjnV=PFTO`vW= z&Sy8=TCSXE8u)Be)2pw1&#GJRQJ=!n&g++=75{$%=H$$QzxsfG5o^L(_DCAfwV!ur zJo%u1w;HYub<|Xtzx}PpUmtopZ(uqvKCJ1E!8g|_*9+j8$~lOvD7%RYquGThJCl?v zRc>AhD8zM`OO+If%v9OeGLjNvRc@$D9w*r(yyEFhs5=ImdU=hvpW@3X2RQ*gRipf- zxRhCF^!G}iB$m_f2g%4fPKj{m421 diff --git a/episode-11-Fire-Loader/models/__pycache__/crop.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/crop.cpython-39.pyc deleted file mode 100644 index df6c2ecdabd59f9e426a9523a6f1e25519bb764f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1156 zcma)*Pixdb7{({N*=)MqE%jsM5TOVjiW))aNk!08ScqdX-3GFm@J_Z^{3LqxA_c$0 zeg)6LL$QbA&7*h_-+5=7NumcQE|*ui_WV%g}UgE}U4NhhQp>6Fwb-9z=`F=o$*|5yFk#hQJp`CI4Y57mz++2SP& z4qlxE^BdeXt}oH<;p^?gRRj(OcJ{X|jFHF!*ZNmmV~uohf)dOJhAp9Z2W>;D)@b*$ zg|;Q&&(3J5>0psM5OzA4^w#K9+jM<`PP29t?p`0l%+|*@Na=*sVt`bwqgYMx)-Y(( zsrLZes*$q znQ2U=giJLD>WpW3xk}D?u@UN$!5!UR%ddChcv*p50bi?Sby1(mGHLmR;b(a%QsAd` z@}!WZ*rkQ*TRTj(9iHYO!b0*)z*1DXl9>pPj=~ddKQ;Cmy+SQhkk#GlqVXS~u_?qO Y{l`$pD6WIo*mHWSo;`@OTitDI>xBL?^X1#w=_a(*suPTj?XR;Nn~+yoOh*-qUHpk#L_`7-S%HQ3 z(tt#z2MbwNv=u9gj$#$*1Z8y8RQ(^Fz((JS@=aJ*c|)(Oibwb?s{;Au1!-+6n ze6a9l@T)%=2};tTV7#()n^USWEy~ow*%r9kw42LJ3$yUg>ZK;*Tx5|QXC_~^#nhjh z9dBmxMVpyzO{RCzXHUq_VSo5gmPb4X{Gz5cRcg((-_}*U`cRQZ4c7)^)fxKl?_@mt z;7GrQe)8^v{9p}^T&HN{KvR)XU};`dV-fbo=d7p<5-LQodch!Pmtn?5oX0#BMO~IX z&LI*-TMTIwr-Sf&Ca4+F0 z`>}bWU)k$P+3Ux^yoA$;L6>E*;1TmW9dBRC2NQXOS|Yk~^tJ4&sBNJzPS}ooCt?j@ STX>ZnOJARMUFViFSA7GV1;b|m diff --git a/episode-11-Fire-Loader/models/__pycache__/door.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/door.cpython-39.pyc deleted file mode 100644 index 8a3202c7db1f2bb396bfa6b9a29a7517398de840..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1016 zcmaKq!AiqG5QaBxn%3GDUn7SIMerbM1i_Pvpr=rXYj>@IG#h49QM`Ec74+!Mr|>z< zN$?=vJbMslx4PTb>V$ro`Sb7WbQ9WcHwnh-#^>?1OUR2VCZmqU7XIW7f{}0x z5Wr;Fk!O@8*&sfr>4?h*0v**};p2+0^>PpcphMZqFN-sg#il+O*Lz9E`#?{Ncsmst z|F#9gA35kNIXF##2dSWpLyzZ)6pRPmZm^@|-LX7GEtNfnb1mnWWn&$MQOY;fJCVx> S*TJjmIp+Fsnnd%Fnvcr4; diff --git a/episode-11-Fire-Loader/models/__pycache__/fire.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/fire.cpython-39.pyc deleted file mode 100644 index 44a2da3eaccbdc2a9e160d65e7b41b5b804eb8ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 774 zcmZvZK}*9h6vxvo-R9iH&)}_x3cGj^b%L;yilC=5sIkeqLf4d}8xB8)pFnSZihT0y;5G;tT+nZ z0dAmUoxJyj`jM(MetQ}V&%&ZKitOBKq??H#k&KC8QIa+T>3Y)}mYRM@q)fMGOeE~q zjkyexfJZWIEA%)QRHj>UOlT1K?u>*}CZCY#syit8ykq;rSa4sEi5$lBWXvPC;ERmU zf{1y7j1u=G5gRIptJ!WkZ^gb|N0&C~Gc5n=j^ zhH9Ydo`KFRS*h-s$X3aA$rfwf5T|`Rbh=BNg!M64oA(9aW>SfcZu4LPYCEW?at*2m zr@M7uPH65+S7uFjgH`u>O}+1H0H#{?PprRLiFM|f&;+$}%;ocws<#2ys=byg$1Zkq zpsCC#@H8)4u?)iLJuj>%p;8umGY&a_2r?n#JQk@eItoJ}fXQN4jwy@ND45Y?%H=D8 zo*J*@=aC=z8HfnzMEco0AB!}o`MToEIOQSGQ68KpBIWC6?qn0Yp^Dv64BSlwWgL8- v#ZoZt_WSNo#TQjP!7P#fD53d5HZR)87)%p>s(!89M=>@03|q5Trrqc-Nx6|5 diff --git a/episode-11-Fire-Loader/models/__pycache__/glass.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/glass.cpython-39.pyc deleted file mode 100644 index 59de8405aec89348da35ebcd498150ad2bb3727f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1016 zcmaKq&q~8U5XLucnri=uuaQFp5j=<*LGYv^=&2Oq+HBiEnhmpQQ4r6*f*!s36h4PJ z2|W~Vo_i2yx4N6w>V*Au=Igh!(`{(8StA(Rd!LtgHX&nK6r+m80WNWm2uVvW3s$Oahn%zV}b)=y!l|^ zhry5jVk9U@hl26S(rpw}V_KG}jq@#Vw`sSKnHFZ_uibx|jB}YqcAT61uOkXSZhpME z$(J2wjy0J+Mc+Lk-r+o7E>#!a6{^S#TKhgniq* z!H?{9r0jJgU|!5=$e_*ANbrz(o15N|l#gff0JT`O)zBO1O}?^=$}nd8@=p;P2;0J^ P>{$Al+BKb9&O-GC9uUKZ diff --git a/episode-11-Fire-Loader/models/__pycache__/ladder.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/ladder.cpython-39.pyc deleted file mode 100644 index 5ab6500f6ec42b87fe4617bfa15f7f26cf17a06d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 776 zcmZvZK}*9h6vxvo-R9iH&)}_x3cGj^b%L;yilC=5sIkeqLf4d}8}8tz@Du3GPqA;| zp(jCMS8syI@FiVat-g>y@AuDpNk~Yy+eQ$3hpX%RIzq1seufEf3{z4NiX21@$ADS$ z5v@HMpmnWSs|kvoI=BtZRmBd5wWeOHDt1iTx}V z0M6}&fJ>uHu*%e8hP526PUaRyhLv)Sl4dvjsJI-yI0C9n-xdF zJHQQetdsY?P(MVUU a)&W@4kR7S7kUJpQfKhK4dVJy5-|QRaYpC7; diff --git a/episode-11-Fire-Loader/models/__pycache__/leaves.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/leaves.cpython-39.pyc deleted file mode 100644 index 89e9ecb4635a6af9868bec0a03a1f491479f8321..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1018 zcmaKqK}*9h6vxx8>vV3zuhByV5j==mLGYv^=&1~9T(hmvHRYundJwOE1wDH6Q}{XT zN!Vd{^Sp!jl4-Kd=_~#9y?_6CNz>3qqed{c_dYN0Y(hq|n2jnH2Y8EnL_`94Tagu% zx+E$+S;(@YtyocX6st%lD5GOV)&J26Z1k-v-;_0#uPN3wouCpm&WYQ+ICAS_ToJ~b z4;DTQe)Jb3K}k9kj8~R!eMU8=Wtkc{-vURQb_lAA_&{Sj;Seh5rScL7t6)P&;gbGot4;kd_I?T9;^O&cisL8U; zIYgppiXM&Pv>Og-GGOAFKvTAtnB20RRtCHav@crOP2S^asOz(7eG;dv4YZSohY3&F zx6SMS$X;8@UMB|TC7ebKS}cnNkC?Z)=^aV=cq;c%OGGPSbjZX;c2lhEqBKa@zWgg< U17TZul^si86T7B!%UP(t082l_NdN!< diff --git a/episode-11-Fire-Loader/models/__pycache__/lever.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/lever.cpython-39.pyc deleted file mode 100644 index e811391d359493dccea40032fae7f823678a3000..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1079 zcmZ`%!HU#C5bexlGVAQjtiO>%78b#Ss1bxcxgzK(48(TQI~&NPLv?0x!4KG9(4%~685lo^SlSKx{|4mK`Z1@@71g73Te4m%ml{6C%@l*@rAgtq#six&+s+Z2$@Jk z<|Q7!qm9T$pFPAep-(s=3<#%)K{7_i0r3{^QQo4{gTzPQjA|_&Qa&eKFb2saTfP?I z(VNq7ev2Dn{D`|m2=I^->}%hg1Y=tyAlqn9!+EQ+&~v&T*GL(e?HufO)kumOg4oyrn!HqpjPkGN}IgSb!nQJrE9GrGtJUm$Sf~6>7^`o%6t{DwBs$@ zeNc~973dAftyxu9^@T1|=C4|QmX~S`^1M!;7rIoPE!ytoXl>=_JO>pOT4oAXs>+Sd yRCIC@om%-tD{oON%&Jhh?{Rh296Uy4SE#4LV?GtRwW!2STtn91b; diff --git a/episode-11-Fire-Loader/models/__pycache__/liquid.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/liquid.cpython-39.pyc deleted file mode 100644 index 525523cbe9d6a95a5c3ec507e8731eef21c8787a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1025 zcmaJC9~cVt7&H=Y*BJr z`wnfYNu|xGkEN86W{+a&cD3ExR+ICsed}aRHLctCwsz`cn^|hi<_^q<{T~7TM9wbw zZ#AMu3%uteigg5CZ8Q*gV67%Y|IZ&fo+9XJzX7xIFM>V2V&HS&SNjF9OyvxCR#aV~ z;%Rx!tIj-SN>!sJhl1b6xm2PMGE-Gw)2Wn@sOp2dVTs7*@sgz_SHB$?>Gm34zVYKp z4ss4`p(gpNxRF_G_?Mbrh>TBx&5HOel^Jhr;bJ3)Q!R%x0X$44OE^q;E|g4ocz76| uYxz?xFHlR>Bo$vvksRc!s&|4?nevbNe$)Yi=i+Glt{E?0-{h{p!(IUn0LSnE diff --git a/episode-11-Fire-Loader/models/__pycache__/plant.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/plant.cpython-39.pyc deleted file mode 100644 index f76db35ba924234948f344dcc663b2c133b4915f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 775 zcmZvZK}*9h6vxvo?dIIX&)}_x3cGj^b%L;yilC=5sIkeqLf4d}8xH&yegeJuDfTTq z^duP-+CzNA~L)ff8b{eO8cFEpgnX(5Qc!{zmT9idlceufF=7(PisC~^@sTm!yZ zfN1T}0Ih4qT1`;w)`42uR~5S$_8NMxs@OGY^Agz`SADy^Sh9~d^6)%gz*vZv-kS7; z0e+3=0xpem!75Xmxvj0O-OgzNa$70awmeK1D+}G4mfhNx-Fjl#t?mEa<>{63%3;MQ z_z!Rc9joNMC)A5n#rn;(Etri(35x98wzADskXR-}usF>cq4fO84a>|RB2s4CQzlY& z>m^)*zpy1hM{0i#0h0$z>-jM%A9W3=_`Di<1w%Z=0qe;cavGx ZJODC@*pYe(xdVa?Sar+L>kBvkX5TehsE_~v diff --git a/episode-11-Fire-Loader/models/__pycache__/pressure_plate.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/pressure_plate.cpython-39.pyc deleted file mode 100644 index b24d4cf99a6f6ebd1cc34bb3ae3fba6a6de683ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 634 zcmZ9I&q~8U5XLuuTWTwwe1{w&^x{F(3PMjRf}TPluGwuGNV8!!DfR(;2t9i9Df%1+ z4}ynYJ$dj@oK4!KI$=M)-#0ru5Zdc?2-e}r>h4=31q!LCv!Zc6Aqlbj) zFB+kp05_9Lbaa~w3sBoZMU`t% z4LIGce)&SvFI|~6(+yVB>oxVhuK}29)jzTRW+m2{V?q0y;5G;tT+nZ z0dAmUoxJyj`jM(MetQ}V&%&ZKitOBKq??H#k&KC8QIa+T>3Y)}mYRM@q)fMGOeE~q zjkyexfJZWIEA%)QRHj>UOlT1K?u>*}CZCY#syit8ykq;rSa4sEi5$lBWXvPC;ERmU zf{1y7j1u=GnL>j=Fn^D|5^$M8uCLXm^0;TZ7M zd_-%H254O?)@p)crw+8CeO0l8VXvw8s)`+xwl0yiaW$|y%N6^0BM;AuC5(l5>F1;` z4DdN#2)H!L1glJKX111FtCP_JWVTYSZF!h3Ru;N7ExWZXyY$y0AI5_Ff=uKvo+o1-xrM*T z{8oR+iW7|{M9tDEgAt#iHA&UdaDYJV$d!X=Xh9|&6Ih279Q@Bia d<9XUT06GoXk$Mfe1A+}$^@gF>7jFH{z5yEEs!IR> diff --git a/episode-11-Fire-Loader/models/__pycache__/slab.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/slab.cpython-39.pyc deleted file mode 100644 index 877adac842d63587e0282ff05f7bd1986fdd0022..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1078 zcmZ`%!HU#C5bexlGVAQjtiO>%78b#Ss1bxcsR()s1F?6~I~&NPLv?0x@dx|`J<4AE z3ctggggq?YJnuoQu4JlX&gAo0;RqgsoHl+Otlj6pKVmTyFO z^!7BI-{M9XKjJPC0zBjd``R}r!PpiF$Tr&3aNepc^qj88HBv@qI|sYnI6fZ+!~R9P zZg&KAJ32UVK>OXiOmB0yifbf|&3|p~OqBf>_(QOpC$$+-hVBpiihD)8VBJ5mw*3TB zxo>E91@f^u^lu+f+{7@ka~VP(oRu^5fBt0Sdklf~GjQc+3{zWScohcCVGXi0l>}AR z%``XZdUvLp$)=FTH1{tR)ard&X_MEvE=@DDbgeaHrdgT`ndRjsy_CgHnXdwtcD#kV z59-mX0=)sbHLL2XzR+dL{B_G;=A~MLJg?K|g)UWRi?(|?T3b0f&p}0nmYIT;s&b<< x6`h>^*dOXF$!Guo diff --git a/episode-11-Fire-Loader/models/__pycache__/snow.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/snow.cpython-39.pyc deleted file mode 100644 index 7632d1ce919539cd4ed07b9e7549410cbce15426..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 624 zcmZ9I&q~8U5XLuuTWTwwe1{w&^x{F(3PMjRf}TPkuGwuGNV8!!t%^^gM{hnwpTpom z@X)I#4<3rMNt;wB?8o=}c4r1cd%X_9+CN&}d~1Y!D%dOo;RKIV!iYzh=4p8Jh%o&{ zLp4x!&p>CEtW@_*WUFMmWQ(<~h||6vI^6|M!ulAj%=;X0GpR&Jw|+1OwH;Jcxdv5( z)7`i)Cp7n^E3>A%!K!<;rr!5808_2{C)VGr#5!|KXoA`~=HmHD)!P7U)n3bmV;5UF z&{Sp=c$ycjSO($rmKRo(P$`R@8Hb$T2bqv@9*a~K9fhF~z+|y4$CSls6wGKc^OFk-_SvUQ0O6~RiThmS_17!7?h2*aRjnf%*vsmKhR%jj=kk8 z`W+EH1ab(ygq(8-nH|Zysz^uZG4IWr*^yX2osJpC+jq|=w=QFMnzUnxQSs`PmO4;0RqNio~XUuWpQ`l;h4gpu|eFqOX{Z0L%C&%Re} zmcVmWa1eP}4O11*SEr&HEHbWCwR0h$6yM@Ps3!bfn zx@NGW$7^`{F7{^y$OZ7FniZGjxy)n3k8A!Z&BYw}Ss8!KWG)(8uw2W*T+6{(3L?lP zPXx?Fkt&&pU~ext)bdd+FHy_XOvyCcEiS9k0Sc>3yw?{)?IO4iK7G$I&yzbgx#M-% E3#1^;G5`Po diff --git a/episode-11-Fire-Loader/models/__pycache__/stairs.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/stairs.cpython-39.pyc deleted file mode 100644 index 3613ffd65811998a8e2d3de258e678566d5539d1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1080 zcmZ`%!EVz)5M3vZQ_>{mH+*oV3W);(jD*w^MM!Y6BAF%Lrj{J9HS1LLz`ef!N5qA% z;5+aMsfUUi=N=HVV`tV_FqWU@y?HY`mRBwoGlB8&$?vycd?9Wu>BkhwGknc8LM9TC zd5MSbXd|-GXAf~q=o3x|1Hvg{kc`oBK)l6!l(*>gAo0;RqgsoHl+Otlj6pKVmaj#4 z^yW02-{M9XKjJPC0zBjd``R}r!PpiF$Tr&3aNepc^qj88HBv@qI|sYnI6fZ+!~R9P zZg&KAJ32UVK>OXiOmB0yifbf|&3|p~OqBf>_(QOpC$$+-hVBpiihD)8VBJ5mw*3TB zxo>E91@f^u^lu+f+{7@ka~VP(oRu^5fBI}AR z%``XZdiPE>lT9IwY3^StsMY(l(k8ESU7BWQ=~`>ZOtUl>GRw6n#x`P diff --git a/episode-11-Fire-Loader/models/__pycache__/torch.cpython-39.pyc b/episode-11-Fire-Loader/models/__pycache__/torch.cpython-39.pyc deleted file mode 100644 index 1b353f13c5089aa588c7894ab152d99eef374a36..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1029 zcmaiy!AiqG5QdXBO>1pMA0vkdB6turg5XI-&{HVHHCfw0nhmq5DEI)rf*!qj^9}Sh z%t`Pd-aLB{XD4x^MRY?x_W$SK+3dEg-|reYR@Og`8ZEhH@plG@m8*G;O~X^$!eZ?r_`bz2Fz& zxbv#XlLrmdU?RS(``Uu0DiTzpEGSubs?wCPbb3nC9#o~7g43gJ)us>CcTgGcwAz%~ z{3fdoR435FTK?wMk?*U?rNh;$f1Z^tr#!k2S6^Sc^}(pc|F@uTPha|*2evx(6xu&M zlG<~umt`8y9&}Vt!?B=_>KW#*uhe+-U`FLNbmi3p_1CVk=h($;4lI=!1D@tZJC;E> zIp#%cm@p}e`BM%#KMOJ;<2)9rEV@dDLO>*oIXPlcoDPFimQ1+3HDE!tS9rhRtAh;0 z5ZG7_vh#c-(m?C|Qt!qo4}qQJ!B!$tUd7z;m+gkic28p9ZX#I3VZgIkiio>QOYXL^ rcS?JVULps%fN->!ofn-obS4SkP`|ZYL|7(1P21GZyVccm)1FeF-zUht diff --git a/episode-11-Fire-Loader/subchunk.py b/episode-11-Fire-Loader/subchunk.py index f3ac8f9..b25c192 100644 --- a/episode-11-Fire-Loader/subchunk.py +++ b/episode-11-Fire-Loader/subchunk.py @@ -2,7 +2,16 @@ SUBCHUNK_HEIGHT = 4 SUBCHUNK_LENGTH = 4 -class Subchunk: +import os + +mods = [] +mods_imported = [] + +if os.path.isdir("mods"): + mods = [os.path.join("mods", f[1], "subchunk.py").replace(".py", "") for f in [[os.listdir(os.path.join("mods", d)), d] for d in os.listdir("mods") if os.path.isdir(os.path.join("mods", d))] if "subchunk.py" in f[0]] + mods_imported = [__import__(m.replace("\\", "."), fromlist=[""]) for m in mods] + +class SubchunkBaseImpl: def __init__(self, parent, subchunk_position): self.parent = parent self.world = self.parent.world @@ -33,6 +42,31 @@ def __init__(self, parent, subchunk_position): self.subchunk_width_r = SUBCHUNK_WIDTH self.subchunk_height_r = SUBCHUNK_HEIGHT self.subchunk_length_r = SUBCHUNK_LENGTH + + def add_face(self, face, pos, block_type): + x, y, z = pos + vertex_positions = block_type.vertex_positions[face].copy() + + for i in range(4): + vertex_positions[i * 3 + 0] += x + vertex_positions[i * 3 + 1] += y + vertex_positions[i * 3 + 2] += z + + self.mesh_vertex_positions.extend(vertex_positions) + + indices = [0, 1, 2, 0, 2, 3] + for i in range(6): + indices[i] += self.mesh_index_counter + + self.mesh_indices.extend(indices) + self.mesh_index_counter += 4 + + self.mesh_tex_coords.extend(block_type.tex_coords[face]) + self.mesh_shading_values.extend(block_type.shading_values[face]) + + def can_render_face(self, glass, block_number, position): + return not (self.world.is_opaque_block(position) + or (glass and self.world.get_block_number(position) == block_number)) def update_mesh(self): self.mesh_vertex_positions = [] @@ -42,26 +76,6 @@ def update_mesh(self): self.mesh_index_counter = 0 self.mesh_indices = [] - def add_face(face): - vertex_positions = block_type.vertex_positions[face].copy() - - for i in range(4): - vertex_positions[i * 3 + 0] += x - vertex_positions[i * 3 + 1] += y - vertex_positions[i * 3 + 2] += z - - self.mesh_vertex_positions.extend(vertex_positions) - - indices = [0, 1, 2, 0, 2, 3] - for i in range(6): - indices[i] += self.mesh_index_counter - - self.mesh_indices.extend(indices) - self.mesh_index_counter += 4 - - self.mesh_tex_coords.extend(block_type.tex_coords[face]) - self.mesh_shading_values.extend(block_type.shading_values[face]) - for local_x in range(SUBCHUNK_WIDTH): for local_y in range(SUBCHUNK_HEIGHT): for local_z in range(SUBCHUNK_LENGTH): @@ -74,32 +88,35 @@ def add_face(face): if block_number: block_type = self.world.block_types[block_number] - x, y, z = ( + x, y, z = pos = ( self.position[0] + local_x, self.position[1] + local_y, self.position[2] + local_z) - def can_render_face(position): - if not self.world.is_opaque_block(position): - if block_type.glass and self.world.get_block_number(position) == block_number: - return False - - return True - - return False + # if block is cube, we want it to check neighbouring blocks so that we don't uselessly render faces # if block isn't a cube, we just want to render all faces, regardless of neighbouring blocks # since the vast majority of blocks are probably anyway going to be cubes, this won't impact performance all that much; the amount of useless faces drawn is going to be minimal if block_type.is_cube: - if can_render_face((x + 1, y, z)): add_face(0) - if can_render_face((x - 1, y, z)): add_face(1) - if can_render_face((x, y + 1, z)): add_face(2) - if can_render_face((x, y - 1, z)): add_face(3) - if can_render_face((x, y, z + 1)): add_face(4) - if can_render_face((x, y, z - 1)): add_face(5) + if self.can_render_face(block_type.glass, block_number, (x + 1, y, z)): self.add_face(0, pos, block_type) + if self.can_render_face(block_type.glass, block_number, (x - 1, y, z)): self.add_face(1, pos, block_type) + if self.can_render_face(block_type.glass, block_number, (x, y + 1, z)): self.add_face(2, pos, block_type) + if self.can_render_face(block_type.glass, block_number, (x, y - 1, z)): self.add_face(3, pos, block_type) + if self.can_render_face(block_type.glass, block_number, (x, y, z + 1)): self.add_face(4, pos, block_type) + if self.can_render_face(block_type.glass, block_number, (x, y, z - 1)): self.add_face(5, pos, block_type) else: for i in range(len(block_type.vertex_positions)): - add_face(i) \ No newline at end of file + self.add_face(i, pos, block_type) + + +SubchunkMixins = [] +for module in mods_imported: + if hasattr(module, "SubchunkMixin"): + SubchunkMixins.append(module.SubchunkMixin) + print("Applying mixin to class subchunk.Subchunk") + +class Subchunk(*SubchunkMixins, SubchunkBaseImpl): + """Subchunk class that handles subregions of a chunk""" diff --git a/episode-11-Fire-Loader/world.py b/episode-11-Fire-Loader/world.py index 696fc07..586b14d 100644 --- a/episode-11-Fire-Loader/world.py +++ b/episode-11-Fire-Loader/world.py @@ -11,7 +11,16 @@ import models -class World: +import os + +mods = [] +mods_imported = [] + +if os.path.isdir("mods"): + mods = [os.path.join("mods", f[1], "world.py").replace(".py", "") for f in [[os.listdir(os.path.join("mods", d)), d] for d in os.listdir("mods") if os.path.isdir(os.path.join("mods", d))] if "world.py" in f[0]] + mods_imported = [__import__(m.replace("\\", "."), fromlist=[""]) for m in mods] + +class WorldBaseImpl: def __init__(self): self.texture_manager = texture_manager.Texture_manager(16, 16, 256) self.block_types = [None] @@ -159,4 +168,14 @@ def try_update_chunk_at_position(chunk_position, position): def draw(self): for chunk_position in self.chunks: - self.chunks[chunk_position].draw() \ No newline at end of file + self.chunks[chunk_position].draw() + + +WorldMixins = [] +for module in mods_imported: + if hasattr(module, "WorldMixin"): + WorldMixins.append(module.WorldMixin) + print("Applying mixin to class world.World") + +class World(*WorldMixins, WorldBaseImpl): + """World class that handles the actual minecraft world""" \ No newline at end of file From b9bedecdf9da4d621a62d1ccc33ef81dc4a8ea4d Mon Sep 17 00:00:00 2001 From: Jukitsu <84381972+Jukitsu@users.noreply.github.com> Date: Mon, 25 Oct 2021 14:05:39 +0200 Subject: [PATCH 2/3] Added mixin support for Camera and Texture Manager --- episode-11-Fire-Loader/camera.py | 21 +++++++++++++++++++-- episode-11-Fire-Loader/main.py | 4 ---- episode-11-Fire-Loader/texture_manager.py | 22 +++++++++++++++++++--- episode-11-Fire-Loader/world.py | 2 +- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/episode-11-Fire-Loader/camera.py b/episode-11-Fire-Loader/camera.py index 111725c..399b8d6 100644 --- a/episode-11-Fire-Loader/camera.py +++ b/episode-11-Fire-Loader/camera.py @@ -1,11 +1,19 @@ import math +import os import matrix WALKING_SPEED = 7 SPRINTING_SPEED = 21 -class Camera: +mods = [] +mods_imported = [] + +if os.path.isdir("mods"): + mods = [os.path.join("mods", f[1], "camera.py").replace(".py", "") for f in [[os.listdir(os.path.join("mods", d)), d] for d in os.listdir("mods") if os.path.isdir(os.path.join("mods", d))] if "camera.py" in f[0]] + mods_imported = [__import__(m.replace("\\", "."), fromlist=[""]) for m in mods] + +class CameraBaseImpl: def __init__(self, shader, width, height): self.width = width self.height = height @@ -60,4 +68,13 @@ def update_matrices(self): # modelviewprojection matrix mvp_matrix = self.p_matrix * self.mv_matrix - self.shader.uniform_matrix(self.shader_matrix_location, mvp_matrix) \ No newline at end of file + self.shader.uniform_matrix(self.shader_matrix_location, mvp_matrix) + +CameraMixins = [] +for module in mods_imported: + if hasattr(module, "CameraMixin"): + CameraMixins.append(module.CameraMixin) + print("Applying mixin to class camera.Camera") + +class Camera(*CameraMixins, CameraBaseImpl): + """Camera class that handles camera transforms""" \ No newline at end of file diff --git a/episode-11-Fire-Loader/main.py b/episode-11-Fire-Loader/main.py index 5d6ec45..7c19dfe 100644 --- a/episode-11-Fire-Loader/main.py +++ b/episode-11-Fire-Loader/main.py @@ -13,13 +13,9 @@ import pyglet.gl as gl -import matrix import shader import camera -import block_type -import texture_manager - import world import hit diff --git a/episode-11-Fire-Loader/texture_manager.py b/episode-11-Fire-Loader/texture_manager.py index 6cfc9fd..224c2b1 100644 --- a/episode-11-Fire-Loader/texture_manager.py +++ b/episode-11-Fire-Loader/texture_manager.py @@ -1,9 +1,16 @@ -import ctypes +import os import pyglet import pyglet.gl as gl -class Texture_manager: +mods = [] +mods_imported = [] + +if os.path.isdir("mods"): + mods = [os.path.join("mods", f[1], "texture_manager.py").replace(".py", "") for f in [[os.listdir(os.path.join("mods", d)), d] for d in os.listdir("mods") if os.path.isdir(os.path.join("mods", d))] if "texture_manager.py" in f[0]] + mods_imported = [__import__(m.replace("\\", "."), fromlist=[""]) for m in mods] + +class TextureManagerBaseImpl: def __init__(self, texture_width, texture_height, max_textures): self.texture_width = texture_width self.texture_height = texture_height @@ -39,4 +46,13 @@ def add_texture(self, texture): 0, 0, self.textures.index(texture), self.texture_width, self.texture_height, 1, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, - texture_image.get_data("RGBA", texture_image.width * 4)) \ No newline at end of file + texture_image.get_data("RGBA", texture_image.width * 4)) + +TextureManagerMixins = [] +for module in mods_imported: + if hasattr(module, "TextureManagerMixin"): + TextureManagerMixins.append(module.TextureManagerMixin) + print("Applying mixin to class texture_manager.TextureManager") + +class TextureManager(*TextureManagerMixins, TextureManagerBaseImpl): + """Texture Manager class""" \ No newline at end of file diff --git a/episode-11-Fire-Loader/world.py b/episode-11-Fire-Loader/world.py index 586b14d..33fad19 100644 --- a/episode-11-Fire-Loader/world.py +++ b/episode-11-Fire-Loader/world.py @@ -22,7 +22,7 @@ class WorldBaseImpl: def __init__(self): - self.texture_manager = texture_manager.Texture_manager(16, 16, 256) + self.texture_manager = texture_manager.TextureManager(16, 16, 256) self.block_types = [None] # parse block type data file From ac9e0e759e657861e608ff35812b5f6676735126 Mon Sep 17 00:00:00 2001 From: Jukitsu <84381972+Jukitsu@users.noreply.github.com> Date: Wed, 27 Oct 2021 11:59:48 +0200 Subject: [PATCH 3/3] Urgent: update nbt as they removed the root attribute --- episode-11-Fire-Loader/main.py | 2 +- episode-11-Fire-Loader/save.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/episode-11-Fire-Loader/main.py b/episode-11-Fire-Loader/main.py index 7c19dfe..199dc81 100644 --- a/episode-11-Fire-Loader/main.py +++ b/episode-11-Fire-Loader/main.py @@ -227,7 +227,7 @@ class Window(*WindowMixins, WindowBaseImpl): class Game: def __init__(self): self.config = gl.Config(major_version = 3, depth_size = 16) - self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone (Fire Loader)", resizable = True, vsync = False) + self.window = Window(config = self.config, width = 852, height = 480, caption = "Minecraft clone (Fire Loader)", resizable = True, vsync = False) def run(self): pyglet.app.run() diff --git a/episode-11-Fire-Loader/save.py b/episode-11-Fire-Loader/save.py index 646b4dc..ae87cca 100644 --- a/episode-11-Fire-Loader/save.py +++ b/episode-11-Fire-Loader/save.py @@ -23,7 +23,7 @@ def load_chunk(self, chunk_position): chunk_path = self.chunk_position_to_path(chunk_position) try: - chunk_blocks = nbt.load(chunk_path).root["Level"]["Blocks"] + chunk_blocks = nbt.load(chunk_path)["Level"]["Blocks"] except FileNotFoundError: return @@ -54,8 +54,8 @@ def save_chunk(self, chunk_position): except FileNotFoundError: chunk_data = nbt.File({"": nbt.Compound({"Level": nbt.Compound()})}) - chunk_data.root["Level"]["xPos"] = x - chunk_data.root["Level"]["zPos"] = z + chunk_data["Level"]["xPos"] = x + chunk_data["Level"]["zPos"] = z # fill the chunk file with the blocks from our chunk @@ -71,7 +71,7 @@ def save_chunk(self, chunk_position): # save the chunk file - chunk_data.root["Level"]["Blocks"] = chunk_blocks + chunk_data["Level"]["Blocks"] = chunk_blocks chunk_data.save(chunk_path, gzipped = True) def load(self):