Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualeppo

Posted 16 December 2012 - 01:47 PM

Storing creatures in two separate structures (a list and a grid of lists) is a practical idea. You can iterate over the items in the list to perform general creature actions and use the grid to sample for neighboring animals.

Removing an item from one set means having to remove it from the other as well, though. To avoid having to let entities keep a reference to their current grid-cell, you could in a first pass perform the preying/eating/etc., flag killed animals for deletion, and then later sweep over the grid to remove flagged items.

Using a class hierarchy seems needlessly complicated. What are the similarities between prey and predator to have them both derive from a single base-class? And how would you (virtually) distinct between items when you grab an 'Entity'-item from a list?

#1eppo

Posted 16 December 2012 - 01:46 PM

Storing creatures in two separate structures (a list and a grid of lists) is a practical idea. You can iterate over the items in the list to perform general creature actions and use the grid to sample for neighboring animals.


Removing an item from one set means having to remove it from the other as well, though. To avoid having to let entities keep a reference to their current grid-cell, you could in a first pass perform the praying/eating/etc., flag entities for deletion, and then later sweep over the grid to remove flagged items.

Using a class hierarchy seems needlessly complicated. What are the similarities between prey and predator to have them both derive from a single base-class? And how would you (virtually) distinct between items when you grab an 'Entity'-item from a list?

PARTNERS