I was reading through the PyGG2 code, trying to grok everything. I noticed that, every frame, you're completely copying every single entity. Surely that won't scale well. Is there a good reason for that design decision?
I'm not trying to suggest we embark on some premature optimization, but this seems like a strange design choice and is in a core part of the engine; it would be difficult to refactor later.
It is a design decision. You see, we need to have the complete game state in one huge "struct". In our case that's the Gamestate class. We need to copy it for each physics frame, and we interpolate between two gamestates for the rendering. If we have this we can do lag compensation, interpolation and all kinds of nifty stuff that would be nigh impossible without it.
Or do you have some sort of genious alternative?
Nope, I don't have a genius alternative, just some ideas that you may or may not have already considered
I understand it's needed for interpolation. My concern is that it's a lot of heap allocation, and not all of an entity's members are used for interpolation. Have you considered ways to let entities only duplicate the members needed by their interpolation methods, reducing the amount of copying that happens every frame?
Of course, without a proper benchmark, I can't say for certain that my way is better. And I also understand it's important to keep code simple.
Also, I don't quite understand this code snippet from GameState.interpolate()
if id in prev_state.entities:
prev_entity = next_state.entities[id]
else:
prev_entity = entity
self.entities[id].interpolate(prev_entity, entity, alpha)
It looks like prev_entity will always point to an entity from next_state instead of prev_state. Thus interpolation will be performed between two identical states instead of between the previous and next states.