• Advertisement
Sign in to follow this  

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

Recommended Posts

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.

 

Edited by hyyou

Share this post


Link to post
Share on other sites
Advertisement

Make the bullets owned by the turret, and the turret owned by the scene.

Alternatively... in the ECS pattern, components are allocated within systems. Just tell the Bullet system and the Turret system to delete all of their components at the end of a scene.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Terry Jin
      Hi everyone! 

      I am from an indie studio that has received funding for our concept and is ready to create the next generation 2D Pokemon-inspired MMORPG called Phantasy World. This ad is for a volunteer position but hopefully will transition into something more. Our vision is to create a game that draws inspiration from the series but is dramatically different in both aesthetics and gameplay as the work would be our own.
       
      We are hoping that you can help us make this a reality and are looking for game developers familiar with the unreal engine and would be happy to work on a 2D top down game. Sprite artists are also welcome as we are in desperate need of talented artists! Join our discord and let's have a chat! https://discord.gg/hfDxwDX

      Here's a teaser as to what our in game characters look like when moving in the game world! Hope to see you soon!

    • By Tea's Jams
      I'm not a beginner per se, but I don't see an introduce yourself section, so I figured this was the best place for this.

      I'm an Indie Game dev, I have had one finished game place well in a Jam and consider myself primarily a writer. I also have a YouTube channel where I review mostly game jam entries for the various game jams held throughout the year, but I enjoy playing all kinds of indie games regardless. 

      If you would like to see some of the games and jams I've covered, please feel free to check out my channel

      Here's a link to my latest vid, this game was STELLAR


      EDIT* I see now I should have put this in Announcements, sorry guys!


      .
    • By tomcalm
      So I've decided to make a multiplayer mod for dark souls, the idea was to cut a lot out of the game and make a multiplayer 5v5 or 3v3 with Stat and Item presets so the player could just go in with out the steep learning curve. 
      I have no experience what so ever. But a lot of time and patience.
    • By LifeArtist
      Good Evening,
      I want to make a 2D game which involves displaying some debug information. Especially for collision, enemy sights and so on ...
      First of I was thinking about all those shapes which I need will need for debugging purposes: circles, rectangles, lines, polygons.
      I am really stucked right now because of the fundamental question:
      Where do I store my vertices positions for each line (object)? Currently I am not using a model matrix because I am using orthographic projection and set the final position within the VBO. That means that if I add a new line I would have to expand the "points" array and re-upload (recall glBufferData) it every time. The other method would be to use a model matrix and a fixed vbo for a line but it would be also messy to exactly create a line from (0,0) to (100,20) calculating the rotation and scale to make it fit.
      If I proceed with option 1 "updating the array each frame" I was thinking of having 4 draw calls every frame for the lines vao, polygons vao and so on. 
      In addition to that I am planning to use some sort of ECS based architecture. So the other question would be:
      Should I treat those debug objects as entities/components?
      For me it would make sense to treat them as entities but that's creates a new issue with the previous array approach because it would have for example a transform and render component. A special render component for debug objects (no texture etc) ... For me the transform component is also just a matrix but how would I then define a line?
      Treating them as components would'nt be a good idea in my eyes because then I would always need an entity. Well entity is just an id !? So maybe its a component?
      Regards,
      LifeArtist
    • By nickyc95
      Hi.
      I'm kind of late to this party but I thought I would ask anyway as I haven't found a concrete answer.
       
      When creating a game engine, when should you choose one methodology over another (more specifically OOP and DOD)? Which areas benefit from DOD? Which areas benefit from OOP? Do people typically mix multiple methodologies throughout a project? I.e. certain sub-systems created in one, and others in the another?  
      DOD - Data Oriented Design
      OOP - Object Oriented Design
       
      Pretty simple
      Thanks
  • Advertisement