C++ vs Java

In 3d games it’s all about raw speed. Same for realtime simulation-software.

For GUI and (not too busy) webservers, a difference of factor 2 would hardly be noticed.

That doesn’t mean performance is a trivial argument, because Java is used on busy webservers and is now also more and more being used in realtime simulation and 3d games (ok, a few).

Still native SSE beats the the crap out of array/vector-math inside the JVM with over 30-50% faster execution. (>400% for sqrt) We desperately need some native math library that’s not attached to some other (commercial) project.

The latest hardware seems to make everything ‘fast enough’ to be interactive, but in the 3d-game-world, it’s about getting all possible performance out of the hardware, which is never ‘fast enough’. I remember in some wicked Sony interview about performance on the PS3 where an artist said: “in the old days, we had to put a lot of effort in optimizing the engine, with the hardware of the PS3, we can do everything without worrying about performance!” - don’t you just love those idiotic marketing talk?

we originally planned a vector math lib for lwjgl, but no one was experienced enough to handle it - and especially on multiple platforms.

I have an API that converts mathematical expressions like:

“FloatBuffer a, float b, FloatBuffer c”
“c = a * b;”

(this is the simplest expression ofcourse)

into 3 types of output:
Java FloatBuffers (explicit unrolled loops+ finalizer loop)
Java Unsafe (explicit unrolled loops+ finalizer loop)
Native C (using SSE) + Java side binding

So far it only does win32, though.

The problem is, I can’t get it to compile because my C-compiler borks at the instrincs, but Darkprophet got it to work with his compiler, and walked away with it for Volatile-Engine.

Haha. Well, that time will come. One day you’ll be able to simulate a complex world, photorealistic graphics… and all that written in interpreted basic. Then you really dont need to worry about performance anymore.

Regarding java and the present… I dont worry about java’s performance anymore. I can do the stuff I always wanted on 6 year old hardware and that with a fraction of the coding time.

Errr, that never happened. And if my memory serves me right, you were a developer for a short time on VE too. And second of all, I didn’t just compile the thing…i wrote it with you. The only reason we didn’t release that is because we had a personality clash…

I still have the code lying around if you would like to continue the project peacefully :slight_smile:

I didn’t say ‘ran away, looking back trying not to get caught’, i said ‘walked away with it’, you used it, nothing more, nothing less, maybe poor phrasing.

Let’s not get into an argument about who did what, as we both know it.

The only condition I’d want to continue on it, would be to have it not contain any reference to VE, like it has now (the package-name that you changed).

Thats fine with me, as long as the community gets something from it, im happy :). You know my email…

Maybe Volatile-Math ;D (joke)

PS. I have linux to compile things on too, so cross platfromness should be easy (hope the macs aren’t going to be a problem…although my university does have a mac lying around)

DP

Can i get a glimpse on your api?

:slight_smile:

I agree with u regarding raw speed, but not all games require maxed performance…and they can still earn cash.

The sourcecode is kinda blackmagic, but here is some input/output:

Input settings:


Declarations:
FB a;
f b;
FB d;
* e;

Statements: (for a lerp function)
e=b-a
e=e*c
d=e+a

Generated C code:


// e=b-a; e=e*c; d=e+a
JNIEXPORT void JNICALL JNICALL Java_com.eyeriv.simd_PerfMath_lerp0(JNIEnv * env, jclass clazz, jobject aBuf, jint aPos, jobject bBuf, jint bPos, jfloat cVal, jobject dBuf, jint dPos, jint elements) {
   
   int fastLoops = elements / 4;
   int slowLoops = elements % 4;
   
   long* aAddr = (long*) env->GetDirectBufferAddress(aBuf);
   long* bAddr = (long*) env->GetDirectBufferAddress(bBuf);
   long* dAddr = (long*) env->GetDirectBufferAddress(dBuf);
   
   float* aData = ((float*) aAddr) + aPos;
   float* bData = ((float*) bAddr) + bPos;
   float* dData = ((float*) dAddr) + dPos;
   
   __m128* aPnt = (__m128*) aData;
   __m128* bPnt = (__m128*) bData;
   __m128  cPnt = _mm_set_ps1(cVal);
   __m128* dPnt = (__m128*) dData;
   __m128  ePnt = _mm_set_ps1(0.0f);
   
   float eTmp;
   
   
   int shift = fastLoops * 4;
   aData += shift;
   bData += shift;
   dData += shift;
   
   for (int i = 0; i < fastLoops; i++) {
       ePnt = _mm_sub_ps(*bPnt, *aPnt);
       ePnt = _mm_mul_ps( ePnt,  cPnt);
      *dPnt = _mm_add_ps( ePnt, *aPnt);
      aPnt++; bPnt++; dPnt++; 
   }
   for (int i=0; i < slowLoops; i++) {
       eTmp = (*bData) - (*aData);
       eTmp =  eTmp *  cVal;
      *dData =  eTmp + (*aData);
      aData++; bData++; dData++; 
   }
}

Generated Java code:


   /**
    * e=b-a; e=e*c; d=e+a
    */
   public final void lerp(FloatBuffer a, FloatBuffer b, float c, FloatBuffer d) {
      
      checkBuffers(a, b, d);
      
      int elements = a.remaining();
      
      float e;
      
      boolean fast = (a.position() | b.position() | d.position()) == 0;
      int fastLoops = fast ? (elements / 8) : 0;
      int fastFinish = fastLoops * 8;
      
      int aPos = a.position() + fastFinish;
      int bPos = b.position() + fastFinish;
      int dPos = d.position() + fastFinish;
      
      for (int pntr = 0; pntr < fastFinish;) {
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
   
         e = b.get(pntr) - a.get(pntr);
         e = e * c;
         d.put(pntr, e + a.get(pntr)); pntr++;
      }
      
      for (int i = fastFinish; i < elements; i++) {
         e = b.get(bPos) - a.get(aPos);
         e = e * c;
         d.put(dPos, e + a.get(aPos));
         
         aPos++; bPos++; dPos++; 
      }
   }

IMHO, that’s not true at all. A factor of 2 performance is ALWAYS noticed. For instance, if the webserver runs twice as fast, you can use much cheaper hardware (hosting companies always have “old” servers lieing around not being used that they’ll rent to you cheaper).

Just going by the publicly available info on the PS3, that’s blatantly not true :).

In a GUI you often wont. Whether it takes 0.01s or 0.02s to repaint a button or do some fancy stuff…

I meant: hosting a small website on a ultra-low-end PC (P2 / 468 / etc), for hosting-companies it’s a whole other story ofcourse.

(this topic is old, but on the first page still, so i figured replying would be ok)

about the casino games, don’t forget that they’re all about making $$$, so they choose C++ (native) over Java (needs JRE) because (slightly) more people can run that, especially the less technical and intelligent sort, who are a main target of these games ::slight_smile:

Hmm, but I’m seeing lots of popular poker websites using Java applications. There’s even pokerroom that lets you play online poker using a Java applet if you don’t want to install the app! And that’s not limited to just the free play poker either.

When it comes to games with a lot of computation, I agree with the whole MMX side of things. Without it Java is not going to be as attractive, any intensive multimedia processing task is going to rely on it.

This caught my eye and sorry for digging up zombie threads BUT…SWG was scripted entirely in Java. Yes, yes…I know…not really a Java game but :slight_smile:

Scripted, but was it coded in Java?

http://beanshell.org

close enough, especially since scripted java runs slower than JIT java

imagine if they used java for the whole thing…

Hate to break it to you but most big games use scripting languages for high level actions and code the core of the game in C++! No RPG is coded in one language, they all use scripting languages for actions, etc.

Eh… well, they used most likely so called “dirty Java” (like in Vampires the Masquerade). The complete game logic is written in Java and the rendering, sound, input and maybe networking as well is handled by some native engine.

So, the position of the interface is quite different compared to usual scripting solutions. Most scripting languages are simply too slow for doing anything remotely processing intensive. That means that all interesting bits need to be written in C/C++ and you only call those functions from your script.

Also scripted Java isn’t necessarily slower than usual Java, because it isn’t necessarily interpreted or has to stay interpreted. Java is pretty awesome and flexible in this regard.

Well as much as that is a bit of a good thing I wouldn’t jump out of my seat and cheer. Using Java as a scripting language is far more easier than creating your own scripting language, which is what a lot of people did in the past. One of the first things I figured out when I was trying to second guess how they made Zelda (aged 15/16) was the need to create some form of action language (scripting, but I didn’t know that).

I think Java is a good choice, but may just see .NET taking over if Microsoft have their way. Sun needs to put their foot in the door before that happens, having said that Java as a scripting language might not be a good way to publicise its place in the game development world. What Java needs is MMX, SSE and ASIO access.

As for gambling games and such, I it might make sense to develop them in Flash/Java so that you can have people playing it at work, college and without the need/worry of installing a potentially harmful program on a computer.

I don’t know a word about C++ but Java is well known as the turtle of programmatics when we’re looking to optimize the velocity of our programs. That’be my word about that topic C++ vs. Java… 8)