So, here's how it's set up. I'll link the code that you might need to see to get an idea of how this engine works from start to finish. So first, everything in the game is an entity. An entity is just an ID number with a list of components. A component is literally just data, no logic. For instance, a player entity would have it's own unique ID number, a PositionComponent for giving it a position in the world, a graphic component used to draw it, etc. All of the logic is computed in Systems, which use the data on components to know what to do. So if we have a Movement System, it would take the player's PositionComponent, and update the PositionComponent based on, say, an InputComponent() that tells the Movement System if a key is pressed.
When I first got it running, I added one or two entities with a couple components in, and everything worked fine. Now, I tried adding in enough entities to cover the screen in tiles for a map (1280/32 tiles wide, 720 / 32 tiles high), minus one from each side just for me. Each entity for a tile on the map is just a Position component and a Graphic component, used for drawing the tile at a certain area. With that many entities, my program goes from 60FPS/ 60UPS, where it's locked to 60 UPS and if VSync is on, 60FPS, down to about 2 FPS and maybe 20 UPS.
First, I thought that it was rendering all of the graphics, but when I just add a Position Component, and throw in an InputComponent just to get a few different systems going, it is still as slow as when I was drawing graphics. After working on trying to fix this for a few days now, I come to you guys for some advice! I've put all of the code that should give you an idea of how the systems work in spoiler tags below so they don't take up pages of room. I've only included the code I thought would be what you guys needed. If I left something out that you might need to see, feel free to let me know and i'll toss it in as well.
I believe the problem lies somewhere in how i'm scanning the entire entity bank for every system to look for the components that the system needs. That's basically where I've been spending most of my time trying to fix this problem. If I tested it right, I believe that the overall Update() call from the main Game class is taking too long, since it's trying to be called a fixed amount of times per second. Any ideas would be awesome! And if you see anything else wrong with my code, feel free to toss it in here as well, but only if you happen to notice it while you're reading it! I know it's a lot of code, and a lot to ask for, but I'm pretty much out of ideas. Thanks guys
This post has been edited by Mr_Fraggs: 13 August 2013 - 02:09 PM