Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:11:31+00:00 2026-05-27T20:11:31+00:00

I am in the process of making a game, and in that process I

  • 0

I am in the process of making a game, and in that process I have come across a bit of a problem.

I have many different types of game elements. These are all of type Entity.

There are many types of Entities, including ones that are visible and need to be drawn on the screen. These entities are of type VisibleEntity which extends Entity.

Like this, I have many different hierarchical types for the elements in the game.

My question is this:

What data structure has the best run-time complexity when issuing the following types of queries?

1) get objects of type Entity

2) get objects of type VisibleEntity

3) get objects of type SomeSpecificGameObject

The trivial solution is to store them all in a list, and iterate through them all, and if they are of the type specified, add them to a list that is to be returned.

Obviously, it is not feasible when computation is done at every frame for certain elements in the screen.

What is the best way to keep track of all this?

I appreciate any response!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:11:32+00:00Added an answer on May 27, 2026 at 8:11 pm

    The other trivial solution is to maintain one list per type. Store each list in a hashmap, with the type as the key. It’s about as instant as you can get, and will only cost you one pointer per item. It also makes it possible to add the same object to more than one list. That will handle your hierarchy.

    If you want to reduce the space required by the approach above, have each list-of-entities object also store pointers to the lists of its subclasses. That way, a VisibleEntity would live only in the VisibleEntity list, and not in the lists for its subclasses. To find all VisibleEntities, you do a hash lookup for the the main list, and then do a recursive search through the children for the subclasses. This is a simple tree structure.

    class MyEntityList {
        List<Entity> entityList = new ArrayList();
        List<MyEntityList> subclassLists = new ArrayList();
    }
    

    Depending on the height of your tree and the number of objects, you might be better off with the first approach. It’s a complexity vs time vs space tradeoff.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm making a program/game that will update automatically. i have the update part down,
I'm in the process of developing an android game. I have an activity that
In the process of making an old webpage standard compliant, the validator came across
I am in the process of making a website that involves a shopping cart.
I am currently in the process of making a snake game using VB.NET... I
In the process of making an ebook, users have to edit its content, edit
I'm in the process of making some improvements to a live Drupal site that's
Ok, so I'm in the process of making a Tic-Tac-Toe game to help me
I'm in the process of making some changes to a library that I'm using.
I am in the process of making a PHP web application. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.