Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 2178 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

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


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

Senior Member


Projects: 1
Exp: 15 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (22 views)
2014-07-24 01:59:36

Riven (20 views)
2014-07-23 21:16:32

Riven (17 views)
2014-07-23 21:07:15

Riven (20 views)
2014-07-23 20:56:16

ctomni231 (48 views)
2014-07-18 06:55:21

Zero Volt (44 views)
2014-07-17 23:47:54

danieldean (35 views)
2014-07-17 23:41:23

MustardPeter (38 views)
2014-07-16 23:30:00

Cero (53 views)
2014-07-16 00:42:17

Riven (52 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!