Good day!
I have the few sections of game logic and few folders with game resources.
For example, there are characters logic and them sprites and also location logic and them sprites. What practice is more common and what is more clear and readable for you:
load all graphics on the big data set with the one unit of code. After that, all components of game will use this collections.
load sprites for character and write characters logic in the one unit; load sprites and write logic for location in the anither one e t.c.
Make the separate units for loading resourced for every component part of the game and separate units for the game logic.
For now I think that the first way is more straight and clear, but it will lead to the growing of the unit for loading resources…
Third way seems good too, but I afraid by the tangle of the many units of code.
And small addition question: how many strings of code in the one unit is a good practice? When you understand: “Ok, this is the time to divide this code on two units”?
It’s a hard question, as it grows “organically” in my experience and it’s a little OK That is, you can start with 1 or 2 units, and just keep it in mind and refactor (move stuff to other units) as project grows.
For characters / enemies, I would usually advise to immediately have a separate unit with logic controlling them (maybe using TCastleBehavior, Behaviors | Manual | Castle Game Engine, see also “New Project → 3D FPS Game” template). You maybe don’t need to really load them separately, it’s OK to have them in one big design (to be able to set them up in editor), but then split Pascal code handling characters / enemies into another unit.
But again, it’s definitely a matter of project size. In https://unholy-society.com/ we had separate units to manage locations, npcs, location sensors, fpp enemies etc. But then, the game grew large
My “rule of thumb” about line count is that when the unit hits 1 thousand lines, a little alarm bell goes off and I start to think “is it worth to split it?”
But I really only actually do it is there’s a “logical” split, i.e. if I can see that something done by 1 unit (maybe even 1 class) can be logically done using 2 units (and 2 or more classes) and the “split” version “sounds actually simpler in my head” and the separated “helper class” nicely hides (“abstracts”) some logic that one no longer needs to think about. So, don’t force it I have units with 2k or 4k lines. We even have some huge units in CGE too with lots of include files (but I don’t recommend doing this in your games!). I also have units with 200-300 lines, and it also sometimes feels OK.
You can also follow rule of thumb from Java: a new class → new unit. As a “rule of thumb” (that you know when to break, because you can break it freely in Pascal ) it’s absolutely OK. Of course you still should then think when to split 1 class into more classes.