Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Process/Render loop Question  (Read 1410 times)
0 Members and 1 Guest are viewing this topic.
Offline Lareon

Senior Newbie

I program for fun... Isn't that weird?!?

« Posted 2004-10-16 23:13:52 »

I'm wondering which would be faster, or if there is ANY difference one should expect in speed between the two (assuming a large-scale project with potentially hundreds of objects to sort through/process):

class ObjectManager {
 for(i = 0; i< numOfObjects; i++){

--Processing then immediately rendering each object in sequence...


class ObjectManager {
 for(i = 0; i < numOfObjects; i++){
 for(i = 0; i < numOfObjects; i++) {

--processing each object in sequence, then rendering them all straight through.

Also, is there ANY reason to do one over the other?  Or is this the wholely wrong way to do it overall?  Perhaps should the processing and rendering be seperated into different asynchronous threads?  I'm not terribly familira with what sorts of things tend to work faster or not.


PS:  Sorry if this is a repeat question, but a peripheral search through the archives presented me with nothing that looked like what I'm asking.
Offline Mithrandir

Senior Devvie

Cut from being on the bleeding edge too long

« Reply #1 - Posted 2004-10-17 01:20:18 »

Simplest way to know is to benchmark your code. In some cases, having everything in a single loop is going to be faster due to effects like cache coherence. In other cases, two separate loops will be better due to cache coherence (or more correctly, having too much stuff in a single loop blows everything out of the cache all the time, so you have no coherence at all).  Also contributing to how well each strategy works is bus bandwidth - memory, graphics card, I/O etc etc.

The site for 3D Graphics information
Aviatrix3D JOGL Scenegraph
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline trembovetski

Senior Devvie

If only I knew what I'm talking about!

« Reply #2 - Posted 2004-10-19 05:21:30 »

I'd suggest to process your objects first, and then render all of them at once. There are many benefits to this approach, including:
- during the processing you may find out that you don't even need to render some of the objects
- you may need to redo your processing after collision detection phase
- in general, it's better to have graphics calls bunched together (and, if possible,render objects with similar attributes at once to avoid thrashing), as it helps primitives batching and thus improves performance
- since you probably want to render your scene in one frame anyway, there's really not much sense in splitting the rendering, since the copy from the back-buffer (or the flip) to the screen will happen at the end of your frame

[shameless plug]
Take a look at this article in JDJ (part one), which explains some basics of game development:
[/shameless plug]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline crystalsquid

Junior Devvie

... Boing ...

« Reply #3 - Posted 2004-10-19 15:57:23 »

There are two opposing cases to consider, and only a benchmark of your app will tell the difference...

If you are code cache limited (small objects & large functions) then running method 2 (two passes) is more efficient.

If you are data cache limited (using large objects, or multiple referenced objects for the updating and drawing) then a combined update & draw for each object is better.

You can guess which will be the case, but you'll probably be wrong Tongue

You probably won't get any benefit by threading these as seperate tasks. Most times when people refer to a seperate thread for graphics, they are referring to the level of the underlying graphics engine: this needs to  set up states & hand the correct data to the hardware, applying sorting by texture, renderstate etc. for optimal performance.
Offline Lareon

Senior Newbie

I program for fun... Isn't that weird?!?

« Reply #4 - Posted 2004-10-19 16:13:17 »

Cool, thanks, guys, for the information.  I apprecited it!
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (22 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (51 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!