воскресенье, 14 сентября 2014 г.

Planet Shooter. Physics.

Hi dear readers. Today I'm starting a series of posts about a game I'm working on in my free time. I'm seriously planning to release it. And here I'll write about my progress.

Current state of the game can be found here:

It's not pretty. Yet. But I'm planning to make an eye candy because I know that with flash it's possible. In the end I want to be close to the great Super Stardust game for PlayStation. But I don't want to make pure clone. Anyway, this blog is not about game design but about technology.

I don't want to use 3rd party libraries and my game uses only my code, no any engines. Even vectors and matrices are mine. I chose an approach of "lazy" update of game objects. This means that every time when I'm asking for position or rotation of an object, code checks if it was changed and if it was - it calculates necessary data. Currently I'm thinking about switching to another system, so I'll not write about it in detail.

For physics I'm using bounding spheres. That will be the only volumes I'll use. They're very simple and fast. For fast moving objects (bullets) I'll use continuous collision detection with spheres. In the posted video I'm using a brute force - I'm checking all objects with each other. I'm pretty happy with performance, but my next step will be spatial hierarchy for physics. I'll use simple uniform grid.

Currently I have this stats on my machine:

This is for 200 objects. Not too much. Here you can see that most of the time was spent on colision detection. We'll see how it'll be improved once spatial grid will be ready.

Couple of interesting moments:
  • On this slide you can see a big performance drop. This is caused by some "magic" Waiting for Next frame.

To be honest I don't know what it is. All I could find is that waiting appears because my CPU is busy with some other task. But that's strange - this spike appears periodically - maybe once per second. If you have a clue what is this - please drop me a comment.

  • Next interesting thing is memory allocation.

I'm little crasy about optimization, so I don't allow to create new objects during a game. I'm using pools intensively. But some allocations are impossible to avoid - native events, for example. It's ok, we're living with it for a long time and it will never change. But on the slide you can see some MethodClosure in allocations. This is caused by getTimer() call. And this is not good. I don't like such surprises from a flash player. And in this case I can't avoid it - there's no meaningful replacement for getTimer(). So All I can do is just hope that Adobe someday will fix it. Good news -  they fixed new string creation on context3d.driverInfo call!

That's all for today. Stay tuned. It'll be interesting.

2 комментария:

  1. Так заразительно пишешь, что тоже захотелось написать технологически близкую к идеалу игру )