Calling many methods of many objects many times per second

Jan Doomwalkerx Peřina

I have a structure like that

  abstract Class Entity {
    //some variables... 
    //some methods ...
    public abstract void render(Graphics g);
    }

Thats the parent ..Now I have 3 children..

Class A extends Entity{}
Class B extends Entity{}
Class C extends Entity{} 

Every class has some different stuff do render .One is for example drawing yellow circle , second green text and the third is displaying image.

But ... there is a thing.

Class A have List<B>... 
Class B have List<C>... 

One Entity has for example 10 Bs ... and each B has 20 Cs ... So now .. I have a render method that renders 60x per second.. And I have to call every render method from every object.

So I have something like this

for(A a : listOfAs){
   for(B b : listOfBs){
      for(C c : listOfCs){
         c.render(g);
      }b.render(g);
   }a.render(g);
}

Now if you imagine I have much more objects like that and I call this method 60x per second ... I find this really ...really bad practice.. I don't know how to solve this better or so... I don't think that this for each loop is actually the best solution or not. Anyone any ideas ?

I was thinking about implementing the child like that :

Entity x = new A(); ... 
Entity y = new B(); ... 

and so but some of the classes have other methods that have to be looped like that and I cannot call them from parent.

For the render method ... Just stick to the fact that you have to loop something many times in a short period of time for a long time.

I cannot progress through this ... I got stuck here for a long time and I am not sure how to solve this.

Paul Bilnoski

Since your primary concern seems to be rendering or not rendering certain entities, regardless of whether they are child entities, you should do some research into general graphics programming optimizations and tricks and what rendering engines do to improve performance. A big gain in performance in rendering engines is not doing work that is not necessary.

One was already mentioned, which is to determine which actually changed state and only render them. Another is to check the bounds of your view against the bounds of each entity on the graphics canvas and only render things that are within the bounds. Whether you have 2D or 3D, you might have things overlapping, so you could determine what entities are occluded and avoid rendering them. If your child entities are within the bounds of the parent, then you can avoid rendering an entire tree of your object graph and avoid iteration of many elements.

Also, these things can be done in partials by checking for a part of an entity that must be re-rendered, a part that is not occluded, etc. This may require some changes to your API to pass in bounds where entities are expected to render instead of the entire graphics context to each item.

If you don't know anything else about any of your renderable entities such as dirty state or bounds, then you are stuck with iterating them all and invoking render one each of them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Failure of calling Google App Script onEdit function many times in a second

From

How do I execute commands many many times per second in Golang?

From Dev

how many is too many Kafka commits per second

From Dev

Error: too many emails per second on Heroku

From Dev

printing second variable as many times as first variable

From Dev

Best practice for calling save() many times

From Dev

android viewpagerindicator calling getPageTitle() too many times

From Dev

Object Instantiation Calling Constructor Too Many Times

From Javascript

Scroll event firing too many times. I only want it to fire a maximum of, say, once per second

From Dev

Getting "Script invoked too many times per second" when running script in Google Spreadsheet

From Dev

Java methods&objects 1:many relationship

From Dev

Many to Many mapping objects in javascript

From Dev

If I don't know how many times something will run per second, how can I get the same output?

From Dev

Count how many times a certain value per user has changed

From Dev

How many times functions can be deployed per project?

From Dev

MQTT: How many times per minute MQTT client polls the server?

From Dev

Count how many times a word occurs in a HashMap per key

From Dev

Count how many times a value appears per month in dataframe

From Dev

Many objects under objects

From Dev

Slider slides many times

From Dev

Regex to match many times

From Java

using @Autowired many times

From Dev

How to not repeat == many times

From Dev

Undo many times in Vim?

From Dev

SetState called many times

From Dev

filter many times a tibble

From Dev

How to Measure How Many Results App Can Produce Per Second

From Dev

How many attempts per second can a password cracker actually make?

From Java

How many interrupts does my cpu have per second?

Related Related

  1. 1

    Failure of calling Google App Script onEdit function many times in a second

  2. 2

    How do I execute commands many many times per second in Golang?

  3. 3

    how many is too many Kafka commits per second

  4. 4

    Error: too many emails per second on Heroku

  5. 5

    printing second variable as many times as first variable

  6. 6

    Best practice for calling save() many times

  7. 7

    android viewpagerindicator calling getPageTitle() too many times

  8. 8

    Object Instantiation Calling Constructor Too Many Times

  9. 9

    Scroll event firing too many times. I only want it to fire a maximum of, say, once per second

  10. 10

    Getting "Script invoked too many times per second" when running script in Google Spreadsheet

  11. 11

    Java methods&objects 1:many relationship

  12. 12

    Many to Many mapping objects in javascript

  13. 13

    If I don't know how many times something will run per second, how can I get the same output?

  14. 14

    Count how many times a certain value per user has changed

  15. 15

    How many times functions can be deployed per project?

  16. 16

    MQTT: How many times per minute MQTT client polls the server?

  17. 17

    Count how many times a word occurs in a HashMap per key

  18. 18

    Count how many times a value appears per month in dataframe

  19. 19

    Many objects under objects

  20. 20

    Slider slides many times

  21. 21

    Regex to match many times

  22. 22

    using @Autowired many times

  23. 23

    How to not repeat == many times

  24. 24

    Undo many times in Vim?

  25. 25

    SetState called many times

  26. 26

    filter many times a tibble

  27. 27

    How to Measure How Many Results App Can Produce Per Second

  28. 28

    How many attempts per second can a password cracker actually make?

  29. 29

    How many interrupts does my cpu have per second?

HotTag

Archive