Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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 3125 times)
0 Members and 1 Guest are viewing this topic.
Offline Astrosmurf

Junior Newbie

Java makes your spirit soar!

« Posted 2006-10-26 11:16:54 »


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

« JGO Spiffy Duke »

Medals: 1030
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

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

Senior Devvie

Projects: 1
Exp: 15 years

Used to be bleb

« Reply #2 - Posted 2006-10-26 11: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 Devvie

Medals: 1


« Reply #3 - Posted 2006-10-26 12: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: 8
Projects: 8

« Reply #4 - Posted 2006-10-26 21: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.


Pages: [1]
  ignore  |  Print  

DesertCoockie (22 views)
2018-05-13 18:23:11

nelsongames (73 views)
2018-04-24 18:15:36

nelsongames (68 views)
2018-04-24 18:14:32

ivj94 (751 views)
2018-03-24 14:47:39

ivj94 (81 views)
2018-03-24 14:46:31

ivj94 (605 views)
2018-03-24 14:43:53

Solater (97 views)
2018-03-17 05:04:08

nelsongames (170 views)
2018-03-05 17:56:34

Gornova (388 views)
2018-03-02 22:15:33

buddyBro (1048 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!