Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Java's implementation of PriorityQueue?  (Read 1686 times)
0 Members and 1 Guest are viewing this topic.
Offline Astrosmurf

JGO n00b
*

Posts: 7


Java makes your spirit soar!


« on: 2006-10-26 07:16:54 »

Hi,

In my networked car game, I am going to use a priority queue for incoming messages. That way, messages with higher proiority (player death, new player joined etc etc)
will be handled before those of lower priority such as position updates.

Is it a good idea to use java.utilPriorityQueue directly? Since this class works with Objects and Comparable.compareTo() the performance might be lower than if I would implement my own PriorityQueue using just  "int" and ">" for comparison.
What do you think, would it be worth the effort?

Regards Anders

If a problem has a solution, why worry? If a problem does not have a solution, why worry?
Offline princec
« League of Dukes »

JGO Kernel
*****

Posts: 8088
Medals: 95


Eh? Who? What? ... Me?


« Reply #1 on: 2006-10-26 07:33:05 »

Probably not. ISTR there's a bug in it in 1.5 as well, something to do with remove() using the comparator rather than ==.

Cas Smiley

Offline ryanm
« League of Dukes »

JGO Strike Force
*****

Posts: 788
Medals: 4


Used to be bleb


« Reply #2 on: 2006-10-26 07:44:27 »

In the vast majority of cases, premature optimisation will cause you pain for little to no benefit. Unless you know for sure that it is a problem, don't worry about it.
It's more important that your game works correctly in the first instance, so using java.util.PriorityQueue is probably the best and easiest way to go for now.
If you get to the point that you have profiled your game and PriorityQueue is showing as a bottleneck, then you can worry about writing a drop-in replacement.

However, be aware of this. It caused me much puzzlement.

As an aside, wouldn't it be better to process events in the order that they happened? For example, if you receive the movement updates that show some car has piled into a wall, and the death event for the now-flaming wreck in the same frame, you might end up drawing the explosion in the wrong place if you process the death event before the movement updates. Similarly, if death events have a higher priority than player join events, you might end up with the situation where a non-existent player dies!
Games published by our own members! Go get 'em!
Offline Mr_Light

JGO Strike Force
***

Posts: 893


shiny.


« Reply #3 on: 2006-10-26 08:40:04 »

code against an interface replace later if needed.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline jojoh

JGO Ninja
***

Posts: 554
Medals: 6


games4j.com


« Reply #4 on: 2006-10-26 17:28:29 »

I have created a networked car game, and I simply used one game thread, and one thread for reading incoming messages. The message reader contained almost no logic, and just some set some variables or flagged events, that then were used in the gameloop. This may or may not be applicable for you depending on what sort of game you are doing.

Jojoh

Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.105 seconds with 20 queries.