-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: Big client refactor #160
Comments
Ok, I see your issue here. I'll try to explain how it works in OpenMiner to give you ideas. Basically, your First, the state stack:
This allows to split the code for the different states of the game. Next, you're interested about what is in Basically, three main classes:
It's also responsible for If you have any questions, just ask. :) EDIT: Just noticed about the chest opening. Basically in OpenMiner it works like this:
|
Hey @Unarelith Apologies I did not reply sooner, I been looking into many ways I can do this and I realise now that you are absolutely right! Organizing game code into a game state system is something I typically did before, but throwing Lua into the mix really confused me here, and instead I went with this weird route that game states don't exist, and the game is always there but inactive. This was pretty horrible way to do things. Looking back at your comment here now, I now understand that's exactly what I want,, as it enables the organisation of different stages of the game, while also being more flexible with what can be done. For example, before if I wanted to have an animated GUI (eg, Minecraft the main menu sort of rotates around a world), then I would have to awkwardly fit it in between the game logic code, which is bad for obvious reasons. The reasons I didn't do it before is because I was way too inclined on making as much as possible done from the Lua, which led to a code spagetti soup. Instead, I should be sticking with what I know, and delegate only very specific things to the Lua code, as after all this is a game and not a game engine. What I am thinking is having the GUIs still defined in the Lua, but don't allow to have an ability to change the game state (or whatever I was doing before). Instead, I could have a GUI defined as a root menu, and make the game switch to that from the "C++ side" when switching to a game state etc etc But yeah thanks so much for making me realise good ways to do things! 😄 |
What I want to do is refactor a lot of the client code.
Right now basically the entire client game is handled by a single class that can found here:
client.h
This is slowly becoming/ is a God Object/ God Class, meaning it is responsible for way too much.
It works fine, and I am low key afraid to change it as right now it is pretty easy to do things, but of course this can rapidly get out of hand.
It has the following responsibilities, all to do with gameplay:
Although this works, I feel it is doing a bit too much and so want to find a way (if possible) to split out the responsibility a bit, as eventually, this would just become a huge multi-thousand line class.
What I propose is some kind of refactor, with the intent to be that the rendering, netcode, world code etc should be split out as their own class.
This would also make it easier to delegate responsibilities in the client lua code.
For example, right now it simply wouldn't be possible to make a button for a main menu that creates a new world*, whereas if this is done correctly it could be pretty easily done while not violating things like SOLID or whatever.
*where create a new world:
The steps listed above seems like a good initial goal for this, which I am currently working on.
Definitely open to ideas on how to achieve more maintainability for the client code, which is what this issue is for :)
(And later, server code)
Other ideas/ Notes (just 1 for now lol):
Opening a chest, how could this work?
The text was updated successfully, but these errors were encountered: