Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 1217 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):

1  
2  
3  
4  
5  
6  
class ObjectManager {
 for(i = 0; i< numOfObjects; i++){
  processObject(i);
  renderObject(i):
 }
}

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

or

1  
2  
3  
4  
5  
6  
7  
class ObjectManager {
 for(i = 0; i < numOfObjects; i++){
  processObject(i);
 }
 for(i = 0; i < numOfObjects; i++) {
  renderObject(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.

--Lareon

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 Member




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 http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline trembovetski

Senior Member




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:
 http://www.sys-con.com/story/?storyid=46663&DE=1
[/shameless plug]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline crystalsquid

Junior Member




... 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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (67 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!