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

  • Home
  • SEARCH
  • 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 6355193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:42:54+00:00 2026-05-24T22:42:54+00:00

I’m making a game with Scala. My game has several pools for keeping enemies.

  • 0

I’m making a game with Scala.

My game has several pools for keeping enemies. They are immutable Lists because they are initialized to a size that should be enough (because creating new enemy instances during the game is very expensive).

My game knows if an enemy is alive by asking enemy.isVisible. So my CollisionHandler works like:

  1. Combine all live enemies to a list
  2. Get live bullets
  3. Space partition these and do collision detection for bullets and enemies in the same space partition

What supprised me was that according to the profiler, step 1 takes most of the time. And what that step does is basically say:

def allActiveEnemies = List(enemyType1.getAllActive, enemyType2.getAllActive, ... ).flatten

the flatten there doesn’t seem expensive but instead it’s get getAllActive calls. They are implemented in my Pooled trait like this:

trait Pooled[T <: Entity] {
    var pool = List[T]()
    val INITIAL_POOL_SIZE:Int

    def initPool() {
        for(i<-1 to INITIAL_POOL_SIZE)
        {
            addToPool(disable(createNew))
        }
    }

    def getAllActive:List[T] = pool.filter(e => e.isVisible)
}

(I omitted most of the trait because I don’t think it’s relevant here.)

pool.filter is what burns like 45% of the total time spent in CollisionHandler, which seems really strange.

Any suggestions to make things faster here?

Maybe using ArrayLists instead of List? Maybe using some sorting and mutable collections? Or am I simply doing something horribly wrong?

Thanks!

  • 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-24T22:42:55+00:00Added an answer on May 24, 2026 at 10:42 pm

    How large are these pools? You do know that every time you make a list, you have to create a new object to hold each entry. You could cut down on this a little by using a view on the filter (i.e. pool.view.filter(e => e.isVisible); then return Seq[T]). Generally, I think your strategy should be to not do extra filtering work each time. Keep track of your active enemies in a Set or something; then you have them when you need them.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a reasonable size flat file database of text documents mostly saved in
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.