szmate1618 / comets

1 stars 0 forks source link

Better entity management in client #87

Closed szmate1618 closed 4 years ago

szmate1618 commented 4 years ago

This PR introduces EntityFactory to manage entity creation, and EntityController, to encapsulate position and other state updates of entities. I made almost everything non-static, because the initialization of TextureManager (reading in texture files) seem to have quite a big performance overhead if done in a static (actually it probably takes the same amount of time, but it happens at a totally unexpected and annoying time). Also made every class explcitily public if it wasn't aleady. Pay special attention to the part

entities.Add(entity.entity_id, Instantiate(placeHolder));
entities[entity.entity_id].AddComponent<entity.EntityController>();

Placeholder entities also have to have their own EntityController, otherwise the GetComponent calls return nulls, accessing those naturally cause NullReferenceExceptions (and consequently lag spikes), and to make things worse, for whatever reason Unity seems to swallow exceptions, so it's pretty hard to track down. Further details here: https://www.reddit.com/r/Unity2D/comments/egda2u/unity_swallowing_exceptions/ Edit: Unity does not swallow exceptions, they should be shown on the console, unless it's explicitly turned off by the button above the console, to right. Which in my setting was unfortunately outside of my computer's screen.