Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Shutdown : an exceptional case in the last timestep of game (ECS)

$
0
0
I have a game loop in Entity-Component-System architecture (heavily simplified) :- spawn some enemy Turret, only in some timesteps; every Turret : try to shoot -> create new Bullet(); every Bullet : destroy itself if lifeTime = 0; every Turret : destroy itself if hp = 0; entity_component_system->cleanUpAsNeed(); It works, but to make it complete, I am supposed to delete entity at the last time step myself. Thus, I add many condition involving ☁lastFrame☁ :- if(!☁lastFrame☁ ) spawn some enemy Turret, only in some timesteps; if(!☁lastFrame☁) every Turret : try to shoot -> create new Bullet(); every Bullet : destroy itself if (lifeTime = 0 || ☁lastFrame☁); every Turret : destroy itself if (hp = 0 || ☁lastFrame☁); entity_component_system->cleanUpAsNeed(); It works but it is very dirty and error-prone. I imagine that this will also happen when room/scene changes. How to solve it elegantly? How do good games solve this problem typically? Are there any related "design pattern" I should read? Is it already OK, i.e. am I too nervous? Some days, I had nightmare because of it .... ... a nightmare that my code become ☁lastFrame☁-flavor spaghetti.

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>