this post was submitted on 20 Jul 2023
11 points (100.0% liked)

Game Development

3439 readers
2 users here now

Welcome to the game development community! This is a place to talk about and post anything related to the field of game development.

Community Wiki

founded 1 year ago
MODERATORS
 

For some time I've been trying to create some rudimentary hack'n'slash game. I didn't want to use ready game engine because I consider it more of an exercise in programming a game than an honest attempt at creating one if that makes sense. So I started with SFML.
Along the way I've recognized the need for loading settings from files(Json library), logging, map editor(ImGUI) etc and it's posing a questions to me for which I struggle to find answers to.

For example let's consider map editor. Currently loading/saving the map to file is done by TileMap class itself but I don't know if it should be. If the map is not as big as render window, should it itself be responsible for centering it or class/function using it should do it? What about scrolling map bigger than render window?

Another example is I have Entity class (player, monster can be entity) which can have Graphics, Physics component etc and it is responsible for rendering itself. But I don't know if it's the right approach. I would like to have logic separate from drawing but Entity essentially merges the two with some extra steps

Add to that is that I would like to painlessly inject debug enabled logging into different parts of this code and I'm afraid I will end up with spaghetti monster for code

What this long windup is leading to is a question. How do I write render independent, reusable game architecture? Where can I read more about this so I can make better decision about what I'm creating.

Now that I've read all of this before submitting it seems to me like what I'm really asking is "how do I make a game engine?". And this was not supposed to be exercise in creating one, at least I didn't think so when I started

you are viewing a single comment's thread
view the rest of the comments
[–] MercuryFox@lemmy.world 5 points 1 year ago

There is no right answer. Every game and game engine gets tailored at some point or another to solve a problem unique to the game being made. Making a game is as much of an art form as it is a science. If you’re in it for the journey, you will spend the rest of your life optimizing and refactoring for ever diminishing returns and technology and techniques will forever outpace you. Just enjoy what you have accomplished and move on to the next most critical thing. Focus on 80/20. This will keep you moving and you’ll actually learn more by the things you realize in hindsight rather then getting stuck trying to plan for imagined scenarios that may or may not happen.

That said…

Tilemap: pick a spot that makes the most sense at the moment and just write your initial logic. Don’t worry about optimizing. If you’re not sure what to optimize, then you need to define bounds and stick to them. Let the game rules define the technology requirements, not the other way around. If you need to center, just write it, if you need to scroll, do it there too. Eventually you’ll get to the point your class does a few too many things and you can reconsider refactoring. In the meanwhile, just get it in, build a level and see if that’s even what you really need. Don’t be afraid to deprecate code.

Entity: Ecs is a great pattern. The question you should be asking is whether your game runs under this pattern acceptably. If your goal is 90fps let’s say, and you are hitting it, then don’t worry about separating your graphics component into a seperate system. You’ll gain nothing but a longer task list out of it.

That said, if you are after knowledge, consider a study of unreal to learn how they organize their threads and components. You might pick up a few tricks. They use a dedicated render thread that basically takes proxy data from the previous main game logic frame and runs alongside the main thread.