denniskaselow / dartemis

A Dart port of the Artemis Entity System Framework
BSD 2-Clause "Simplified" License
47 stars 6 forks source link

Performance of ComponentMapper #36

Closed Rodeoclash closed 10 years ago

Rodeoclash commented 10 years ago

First of all, thanks for porting this. It's awesome fun to play around with!

I'm play around with building an isometric engine which uses Dartemis for the EPS and PixiJS for the rendering. I'm noticing a bit of hitching when my isometric tile entity is being processed through the system which renders it to the screen. Essentially, the more tiles I have, the worse the performance hit. At a world size of 64x64 (4096 tile entities) it's not noticeable but as the world size increases from there (say 128x128, 16384 tiles) I'm starting to get a some hits to the frame rate when I use the component mapper to fetch tile entities that implement a tile component.

Should I be seeing performance hits when using the ComponentMapper with that many objects? I've mitigated the effects somewhat by only running the system on an interval and faking the smooth scrolling by moving the box containing the tiles, however I still get some small hitches.

Rodeoclash commented 10 years ago

I should say that I have some optimisations for only drawing tiles on the screen but every game loop I'm checking every tile to see if it's visible or not.

denniskaselow commented 10 years ago

Thanks for trying dartemis :).

I guess you mean an access like this?

ComponentMapper<Tile> tileMapper;
...
var tile = tileMapper.get(entity);

Are you sure it's the ComponentMapper? If it is, there isn't much I would be able to do, because in the end it's just accessing a list by index.

For simple canvas2D games I usually draw all tiles to another canvas as a buffer once and then use that buffer (isometric would require some refreshing of tiles) but that's probably not a solution if using PixiJS/WebGL.

Do you get the performance hits when running in JS or Dart and does it make a difference if you don't run it in checked mode in Dart?

It may take a while for me to look into it, with Ludum Dare taking all my time this weekend ;).

denniskaselow commented 10 years ago

You could use a Manager to have "sectors" with some fixed amount of tiles per sector and then only check which sector is visible instead of checking every tile. This would mean more draw calls for the tiles in a sector that isn't completely visible, but it should improve performance if there are many invisible sectors.

Rodeoclash commented 10 years ago

Yep, that's exactly it, build the mapper object then using that to look up the entities.

The DartVM actually runs it great. No slowdown unless I'm running something extreme like 512x512 world maps however running it in JS isn't too hot, it's ok in Chrome but Firefox is a bit worse.

It looks like the mapper works the way I expected it to (by index) I just wanted to double check if their was anything that you might have known about performance wise that might be affecting it.

Thanks for the tip on the sectors, it's quite a good idea and I'm going to have a crack at implementing it.

Finally, sorry for the "tech support" style ticket ;) and good luck with Ludum, I'd love to see what you build for it.

denniskaselow commented 10 years ago

No problem, tech support style ticket is okay :)..

BTW, there is a Dart port of PixiJS: https://github.com/playif/play_pixi

My Ludum Dare entry is this one: http://www.ludumdare.com/compo/ludum-dare-30/?action=preview&uid=17933 A bit incomplete, but good enough for 48 hours :).

Rodeoclash commented 10 years ago

Awesome! I'll give it a bit more of a play when I get back.

I'm using this port of Pixi here:

https://github.com/emergent-design/pixi.dart

But I think the version you linked is a bit further along in what it's implemented.

I got quite far without a game framework at all, what I've done so far (just isometric tiles and smooth scrolling)

https://www.youtube.com/watch?v=rtUiqWZrDk8

(The flash artefacts are a problem with the video capture I think) but now I'm converting to your framework instead so re-implementing a bit of stuff.

I think I've solved the performance issues, I haven't fully implemented but I'm planning on just converting the top left and bottom right screen coordinates to x,y coordinates in my data array and iterating over that by creating them in the EPS system on scroll event. That's the theory anyway ;)

My end goal I'm not quite sure. I'd really like to build some sort of MMO isometric game. I want to make it continuous gameplay unless you enter combat then it switches to turn based. The difference is, simultaneous turn based, so even though you might have 50 people on one zone, they all input their turn in the same 10 second window.

denniskaselow commented 10 years ago

A MMO; quite an ambitious project. Good luck ).

Feel free to open an issue or send a pull request if you require access to internal variables of dartemis for world/entity serialization/deserialization for client-server communication. Haven't used dartemis for anything related to client/server communication, so I'm not sure if everything would work out of the box.