Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Mutable or immutable vectors?  (Read 2316 times)
0 Members and 1 Guest are viewing this topic.
Offline IronclawsBt

Junior Member


Medals: 1



« Posted 2011-03-10 17:37:49 »

Just wondering what type of vectors (the mathematical kind) people use. The mutable vectors would appear to have a slight performance edge, but at the cost of safety. I am currently working on some collision detection code, and haven't decided which I want to use. At the moment, I am doing some stress testing and using immutable vectors. At the current performance limit (which may not be bound by object creation), around 100,000,000 vectors (2D) are being created a second. Not too bad. What experinces have all of you had with mutable and immutable objects and object creation?

It's not what you know, it's what other people think you know.
Just hope you don't get quizzed on it.
Game engine design tutorials
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2011-03-10 17:41:36 »

That level of garbage is likely to be a big problem, to be honest.

Cas Smiley

Offline IronclawsBt

Junior Member


Medals: 1



« Reply #2 - Posted 2011-03-10 17:47:38 »

That level of garbage is likely to be a big problem, to be honest.

Cas Smiley

I would have thought so as well, but maybe the JIT compiler is being smart. Most of the objects are short lived and may be added to the stack rather than the heap. I am running OpenJDK 1.6.0_20 on a Linux machine.

And a mistake in my original post, it is 50,000,000 objects/second. I forgot that I was actually being smart when I wrote the test and was not testing symmetric collisions.

It's not what you know, it's what other people think you know.
Just hope you don't get quizzed on it.
Game engine design tutorials
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2011-03-10 17:50:38 »

No stack allocation in JDK1.6 I'm afraid. So it's likely to get a bit jittery. I use mutable stuff all over the place, and, cough splutter embarrassment, static finals as "scratch" areas to reuse.

Cas Smiley

Offline bienator

Senior Member




OutOfCoffeeException


« Reply #4 - Posted 2011-03-10 18:13:31 »

not applyable for all usecases: but what i did is to use nio bytebuffers for vector/matrix storage and do the computation on the gpu/cpu/<other hw> via JOCL. Memory is static in my case. Accessing the data from java is a bit slower however.

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2011-03-10 19:48:06 »

Yar, still no mapped ByteBuffers. Grr.

Cas Smiley

Offline lhkbob

JGO Knight


Medals: 32



« Reply #6 - Posted 2011-03-10 20:11:16 »

I wrote a vector library that had all the math logic defined in read-only types, and they took a mutable subtype as a result parameter (so you could pass in null to create a new one, or re-use an existing object for intermediate computations). This gave me some flexibility so I can have a matrix return a read-only vector over their column or row and have that mirror any changes to the matrix. 

I don't know if my abstractions are hurting my performance, currently the graphics is still such a bottleneck that it's hard to tell.  I did end up unboxing certain vector operations in my physics engine in the inner loops of an iterating constraint solver, but that's a very specific, performance intense operation.

In my high-level game objects, having them expose read-only types makes it easy for them to know when their transform or rotation or color has been changed and push out notifications.  This means my game loop has to do less work for each object and can just ask it if it's been updated instead of not knowing if something has been changed underneath it.

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.

BurntPizza (10 views)
2014-09-19 03:14:18

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (60 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!