Comments (2)
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! 😄
from open-builder.
Ok, I see your issue here. I'll try to explain how it works in OpenMiner to give you ideas.
Basically, your Client
class is divided among multiple things.
First, the state stack:
gk::ApplicationStateStack
handles the game states (Title screen, game, pause menu, chat, etc..)gk::ApplicationState
, main class for all the game states, it's an abstract class that has:- A constructor to init the parent
- A virtual function
onEvent()
for OS events (mouse moved, key press, etc..) - A pure virtual function
update()
- A virtual function
draw()
This allows to split the code for the different states of the game.
Next, you're interested about what is in GameState
.
Basically, three main classes:
Client
which handles the socketClientCommandHandler
which handles the packets received and is also able to send packetClientWorld
, which contains the chunks and is responsible for rendering them.
GameState
also handles the shader used for 3D rendering, the camera and the HUD
class (which will render the hotbar, fps counter and debug info).
It's also responsible for PlayerBox
drawing (basically the other players model).
If you have any questions, just ask. :)
EDIT: Just noticed about the chest opening.
Basically in OpenMiner it works like this:
- User right-click on a block
- Client send
BlockActivated
packet to server - Server execute the Lua function associated to this block
- In the Lua function (for a workbench or a furnace), a GUI is created and sent to the client
- The client receives the GUI info and display it
from open-builder.
Related Issues (20)
- Cleanup the Cmake
- Document Scripting API
- GUI: Checkbox widget HOT 6
- Allow GitHub actions to recognize std::filesystem, std::optional etc HOT 5
- Doc building on Windows with Visual Studio HOT 1
- Add function to GUI textbox API to limit which characters can be added to it
- Pressing ` or Caps-Lock causes the error screen to pop up HOT 2
- [Feature] Move buttons to the texture_packs/ folder instead of res/
- World generation not working on macOS
- Building HOT 2
- Lag and block error HOT 2
- Something like redstone
- Ability for custom player models, custom block models and custom player animations
- Shader compilation error on Ubuntu 20.04 LTS HOT 9
- Client-side prediction
- Compile error HOT 1
- Big Rewrite HOT 1
- Shader compilation fails depending on drivers HOT 8
- Lower Water Level HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open-builder.