Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] MS VJ++ and DirectX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 05 April 2000 - 03:04 PM

My current game is written in VC++ in non-object oriented way using STL. I would like to rewrite my game so it uses OOP methods and I can do it in C++ or Java. So my questions are: 1) Is it more difficult to use directx for java than directx for c++? 2) What is the speed difference between a game written in c++ vs. java both running natively in windows? 3) Those who done java and directx, would you recommend it or go back to c++ and directx? I think that''s all I wanted to ask Thanks for any info on the subject. Jerry

Sponsor:

#2 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 April 2000 - 08:59 AM

I only have limited experience with this, as shortly after I began my project I switched to JBuilder and Java 3D to achieve a pure Java implementation, but here is what little I have to offer.

There are two ways to reach the DirectX components that I know of. You could go via COM, similar to the way that you would reach the DirectX subsystem under Visual Basic. Using DirectX from a COM interface is actually easier than programming directly from C++ calls. Or you could use one of the native method interfaces (which is going to be ''similar'' to accessing the methods under C++).

I haven''t used native methods to access DirectX, but from my general use of native methods they are both faster and more difficult to use than a COM interface. With the COM interface there is going to be a performance penalty every time the Microsoft JVM has to pass requests to and from COM.

Rather the COM interface is going to be fast enough depends on what you are doing. Since most of the graphics work is done in the DirectX subsystem, screen draws and the like are not heavily penalized under this set up. ''Game'' logic and your ‘game logic to screen draw’ routines will be. If your game requires a great deal of AI code, lots of precise collision detection, high frame rates, a very fast game loop, etc... you may run into problems.

On the other hand a game based on a 2D isometric perspective, turn-based strategy system would probably work fine.

Another variable to take into consideration that I have NO experience with is writing programs in Java and DirectX and compiling the Java portion with a native compiler (I don''t know if this is even possible).

I don''t know if I can say I would recommend moving to Java from C++. There are a lot of benefits to using Java to program games (see the thread on this board from about a month ago named ‘State of Java Game Development’). But if you are already very comfortable with C++ and have a working engine, most of those advantages don’t really apply. Since you would be programming against DirectX cross-platform capabilities are not relevant either. At this point you are going to get better performance from C++ than from Java. Unless there is some reason for using Java - such as wanting to learn the language or improve your existing skills - I would stick with C++.

_____________________________________________
* It is your constitutional right to ignore *
* anything I have to say. *


#3 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 06 April 2000 - 12:19 PM

Thanks Jerry for info,

I guess the decision to go with Java is based on complexity of the game. The more complex it is the slower it runs and a faster code has to be written. For now, I think I will go with C++ and DX SDK since I don''t have to learn Java and rewrite the ddutil.h, diutil.h, dsutil3d, etc. helper files(or maybe they are written in Java already and come with Java DX SDK, that would be nice ).

I will be watching the developements of 2D and 3D for Java closely and later I would like to switch to them for 100% pure java. By that time I hope the 1GHz cpus will be common place

Jerry


#4 Altmann   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 April 2000 - 11:41 AM

How do you plan to make Java run natively under Windows ? Especially if you use VJ++ ?

#5 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 April 2000 - 12:11 PM

Maybe native compilation using Supercede''s or a similiar compiler?

#6 felonius   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 April 2000 - 02:00 PM

In my current project I am actually using a Java native code compiler (Symantic Visual Cafe) combined with Visual C++ to achieve the desired effect.

First, let me make something clear. VJ++ is NOT a native code compiler. I merely packages the interpreter into a .EXE file, but it does not run (significantly) faster.
To make it run faster you need a real native code compiler such as that from Symantic, IBM Visual Age or TowerJ.

This compiler do not support COM or RNI (the Raw Native Interface by Microsoft) so you have to JNI to access DirectX. JNI is not made for directX so you have to make some C++ wrapper that accepts calls from Java and calls DirectX in turn. JNI is part of the Java standard which means that the Java code can be removed from compiler to compiler without change (at least in principle).

JNI is not the fastest interface in this world so it must be carefully considered what is placed in C++ and what in Java. The graphics rendering routines might just as well be made in C++ for speed.

The reason why I do not use C++ for the project as a whole is that productivity is much higher using Java. The native code compilers are not that slow compared to those in C++ (less than a factor of 2 worse) so this is acceptable if a precausions are made: All code that runs very often should be placed in C++. This is usually about 10% of the code. The rest can be written in Java.

I my current project I am simply making a thin wrapper class in C++ and thereby expose the DirectX classes (or something similar) to the Java programmer. This will certainly be slow but instead of making a lot of C++ development I will program it in Java first and only later profile the code and move the CPU intensive routines to C++.

And one more thing, if you intend to use DirectX from Java you might also what to implement callback routines. JNI can also be used for this. In effect you can write your event handlers for windows directly in Java.


B.Sc. Jacob Marner
Graduate Student of Computer Science, The University of Copenhagen, Denmark.
http://fp.image.dk/fpelisjac/rolemaker/




#7 javanerd   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 April 2000 - 05:32 PM

1) Is it more difficult to use directx for java than directx for c++?
No, IMHO it is easier. The Microsoft Java''s COM to Java class mapping makes all the COM objects look like real objects, which makes it easier to handle and understand. Also the classes map quite well to code that you would produce with C++, so you can use your old books on the DirectX programming with small modifications to the code.

2) What is the speed difference between a game written in c++ vs. java both running natively in windows?
What kind of a game are you talking about? This is a bit difficult to answer straight away, but I think that at least the 2D things I''ve been making are almost as fast as the C++ counterpart would be.

3) Those who done java and directx, would you recommend it or go back to c++ and directx?
Another difficult one... I''ve been happy with the MS Java + DirectX combo. But if you are going to do 3D programming, then you should take note that you are limited to DirectX SDK 3.0 level API when you use the MS Java DirectX classes. So for 3D the C++ and DirectX SDK 7.x are a lot better (no execution buffer handling etc.).


#8 JD   Members   -  Reputation: 208

Like
Likes
Like

Posted 09 April 2000 - 10:48 PM

Thank you all for your responses, you all have valid points.

My current game is a 2D game and runs 140fps on cyrix 233Mhz(true mhz) using Permedia2 gfx chip with 4mb memory. I feel like in the near future I might rewrite the game to use pure Java and its 2D classes which in itself might be quite educational

>> take note that you are limited to DirectX SDK 3.0 level API when you use the MS Java DirectX classes <<

Now that I find interesting. You would think that MS would try to move coders to Java by providing them with the latest and greatest DX7 sdk, oh well...

Thanks all,

Jerry

#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 10 April 2000 - 12:47 AM


You can''t use direct x with java, cuss java is platform independent and directx isn''t. There is a 3D Api which uses Glade & direct X in development (which can be found some where @ http://developer.java.sun.com/developer/index.html). In general this is bad, java which isn''t platform independent isn''t true java, and as a zealot i''ll have to kill you

#10 felonius   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2000 - 09:11 AM

What nonsense!

It is true that using directX from Java is not 100% pure Java, but that doesn''t make a game non-Java for that reason.

I think that the use of Java is much more justified for games if you use it together with code written C++. This way you can make the game go real fast while gaining the benefits of Java programming.

100% pure Java programs are portable (at least the source code) but they are also quite user unfriendly. As windows user I require some kind of InstallShield (or something pltform dependent system like it) based installation and that the program works with my drivers and make full use of my system. This is more important to me than portability.

If I distribute .class files (for true portability) then the program wil run interpreted meaning that it will be quite slow compared to C++ code. Then nobody will play the game. I know that some of you strongly believe that games written properly will run as fast as C++ code, but in my experience that is simply not true. Game players today expect high speed games and this we must deliver if we wish to earn any money. You may argue that player should be concerned with gameplay and not graphics, but the fact is that users today want great graphics at a high speed.

By the way, the java 3D API is quite primitive and is generally not useful for professional games. You need to use a more low level interface such as OpenGL, 3dfx Glide (not *Glade*) or DirectX.

By combining C++ with Java you are able to use any of these interface with no problems at all. Using Java I have for instance written programs that access the MFC object library without using MJ++.


#11 SteveMeister   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 April 2000 - 10:26 AM

I agree -- in games, the important thing is performance, and if that comes at the cost of some portability, so be it. Java''s a nice enough language that it has a wide range of applications in gaming, but some things, like 3D rendering and perhaps the game''s inner loop, are best left to more native languages in the interest of performance. Use the JNI when you need to. At least if you encapsulate the platform-specific code well enough, you can just re-write those segments for other platforms. A really good example of this is JDK 1.3''s new capability of using a native method to paint on a canvas.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS