Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  Java's implementation of PriorityQueue?  (Read 1930 times)
0 Members and 1 Guest are viewing this topic.
Offline Astrosmurf

Junior Newbie




Java makes your spirit soar!


« Posted 2006-10-26 13: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


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #1 - Posted 2006-10-26 13: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 »

Senior Member


Projects: 1


Used to be bleb


« Reply #2 - Posted 2006-10-26 13: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2006-10-26 14: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 Knight


Medals: 5
Projects: 7


games4j.com


« Reply #4 - Posted 2006-10-26 23: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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (84 views)
2013-05-17 21:29:12

alaslipknot (92 views)
2013-05-16 21:24:48

gouessej (123 views)
2013-05-16 00:53:38

gouessej (115 views)
2013-05-16 00:17:58

theagentd (127 views)
2013-05-15 15:01:13

theagentd (114 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (187 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.548 seconds with 21 queries.