Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  which is faster?  (Read 816 times)
0 Members and 1 Guest are viewing this topic.
Offline PRW56

Senior Newbie





« Posted 2012-12-31 07:48:45 »

For collision detection, I can either find out whether or not 2 sprites are in the same rectangular areas (up to 4, since they can be on the edge) at the same time before doing collision detection, or simply check every sprite on the entire map every time. Can anyone tell me which they think would be optimum, or rather at what point (as in after how every many collision detections need to take place) does this start saving speed? Also which is faster == or >,<,<=, and >=?
Offline Phibedy

Senior Devvie


Medals: 9



« Reply #1 - Posted 2012-12-31 08:13:29 »

How many sprites do you have?
I don't think, that you will recognise any "speedboost", for example there's no difference in the "running-time of one loop" of my game if I just have to check 1 or 500 collisions.
It might be worth it, if you got huge polygons and therefore a lot of verticles to check.
What you could do is creating a circle around each sprite and check before if they collide (circle vs circle collision is faster then rect vs rect), but I in my opinion that's not worth it, too.
best regards
Offline Cero
« Reply #2 - Posted 2012-12-31 15:58:27 »

There are many threads on jgo about "not looping through the whole array everytime"
here is one: http://www.java-gaming.org/topics/avoiding-looping-through-everything/24587/view.html

One thing you can use is a quad tree.
Grids are kinda nicer I think and to quote Riven
Quadtrees are not efficient in today's CPUs. Use a grid instead.

It's both incredibly easy to develop, and much, much faster.
Click on the quote link to get to a whole thread about this kinda topic

But overall it really depends what you are doing.
For example if you are doing collision detection with static geometry, you can just set a very limited loop in that area.

Also which is faster == or >,<,<=, and >=?
I think that not even at assembly level, that there is a difference - talking about this in Java is krazy, with a K =D

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2012-12-31 17:00:55 »

What you could do is creating a circle around each sprite and check before if they collide (circle vs circle collision is faster then rect vs rect), but I in my opinion that's not worth it, too.
best regards

Oughh... I'd be careful with that. It gives you an incredible performance boost.
(I assume we're talking about SAT collision testing now)
In case you have lots of polygons, especially polygons with lots of vertices (in my case I had 'only' Cool, circle pre-checks can improve the performance a lot. They're pretty much eqivalent to one single, simplified SAT axis test + two multiplications Wink

Also, if you think of using pre-checks I'd really suggest circles instead of rectangles.
Rectangles have the problem, that you usually need to re-compute them if you for example rotate the polygon.
Circles are circular, therefore you don't need to re-compute the radius, as it is the same all the time Wink

But I agree to Cero: Using some kind of grid will improve the performance a lot as well (after that comes the circle-check).

If we're not talking about SAT, but AABB collision tests, then you shouldn't really need to do the circle check, but the space partitioning (Grids, etc, see Cero's post) should help you.


I don't know which is the fastest from == >, <, <=, >=.
My guess is, it's ==. (As far as I know it needs a subtraction and another instruction for testing whether something is 0, but that actually only applies for native code. Java is mostly interpreted, even if everything is JIT-ted. Idk whats the case then.).

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline PRW56

Senior Newbie





« Reply #4 - Posted 2012-12-31 21:08:47 »

I read over that thread a bit, I love the idea of checking within a set rectangular grid, but it becomes a lot more complicated when you try to deal with sprites along the edges of any rectangle in the grid, because a single sprite can be in up to 4 at once (if its in the midddle of them)...
Offline Roquen
« Reply #5 - Posted 2012-12-31 21:33:11 »

Compares cost are equal.  Everything else mentioned...it pretty much depends.
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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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