[java] Java Networking for a C++ Game

Started by
17 comments, last by archon 23 years, 6 months ago
> I think I''m going to work on a 3D graphics engine in C++ and
> then try and convert it to Java. Should be a fairly
> interesting experiment at the very least....

Don''t do a 3D graphics engine in java. You will certainly get low performance. C++ is good at low level stuff, so when doing low level stuff nothing can beat it.
And more thing, my personal opinion is that you are wasting time writing your own 3D engine. There are so many out there that are free or can be bought cheaply that you are just doing the same work again that hundreds have done before you. Get one of these and the concentrate more on the content of your game - this is more fun, anyway and your game will get done quicker and will probably look better than if you are making your own engine.

> Felonious, your idea to keep the control code in Java sounds
> right to me. Are you suggesting a Java wrapper on top of the
> entire game engine? That way all the networking code
> can remain in Java with a performance hit for the
> wrapping, correct?

Correct, but if you are sending full objects over the network
you will get the best performance by having the objects you need to send represented in Java all the time so you don''t have to convert them from C++ to java at run-time, send them, and convert them back at the reciever, but if you put all control in Java then this is indeed the case.

> As far as going back and forth between
> the languages, are there any universal data types or are
> they so simple that they wouldn''t be useful?

I am not sure what you mean. Read a JNI tutorial and you will get your answers.

> I guess
> an interpreter class would be the best way to do it....
> class babblefish {

Not sure what you mean here either.

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Advertisement
I am assuming when you state that you want to build a 3D engine you are referring to a low level API that will render the 3D constructs in memory to pixels on the screen (not an engine that translates game objects into data structures that can be rendered by a lower level API, such as OpenGL). If that is the case you may want to check out the 3D engines list. They have several pure Java 3D engines (some of them with source code) that you might be able to use as a reference when designing your own.

http://cg.cs.tu-berlin.de/~ki/engines.html
Thanks for the advice, though I think I''m going to try and code the engine myself anyway....mostly because I''d like to learn how its all done, the magic behind the magic.

The babblefish class would be an interpreter, taking in the messages in Java format and passing them into the C++ engine underneath. I don''t quite understand when the engine would need to get its messages from the network code. I assume state variables, posistion of enemies and missles, and game clock synching would all have to be sent over the network, but would these all need to go to the engine? If all this info was held in Java object, couldn''t that Java class output strings to be passed into gameMain, or simply update gameMain itself? I haven''t looked into JNI yet, and really don''t know what its for so...
Similarly, could the engine output a Java object to send across the network and then wait for one to come back, all the while accepting user input from the keyboard/mouse?

And for another, general quesiton, are there numbers out there showing the minimum speed for network request/reponse times for the game to remain playable....again this is probably something I should research, but you have to start somewhere


Thanks,
archon

Didn''t see that last post before my own.

Indeed I am referrring to the basic pixel drawing type of engine, and I will use someone else''s for a reference....I''d like to learn how to drive, not invent the wheel...
thanks
archon,

This dicussion is getting quite vague and I am having trouble following you. I think you should read something about JNI (the free java tutorial at Sun for instance) and return later when you know more.

As for the thing about waiting, though, no you will not wait. To do networking the normal way is to spawn a new thread that does the waiting while the rest of the program continues. You usually also have a thread that listens for incoming messages and reacts to them. If you don't know about multithreading I think you should read about that too.

A word of warning, if you intend to make your own low level engine putting pixels on screen you should be aware that such thing invariably gets quite slow compared with commercial enginesm because you are not making use of 3D hardware acceleration. At least use opengl, directX or something like it. By the way,there already exists an OpenGL wrapper somewhere that you might find useful to save some time. Nobody (except maybe during graphic classes) writes pixelputting level engines anymore.

Jacob Marner

Edited by - felonius on September 25, 2000 1:13:28 PM
Jacob Marner, M.Sc.Console Programmer, Deadline Games
Ahh, knowledge.
I''ve read the recommended tutorial and see the answers to many of my questions there.

I''ll get cracking on this thing and come back with the more specific issues that I''m sure I''ll face.

And don''t worry, I''m planning on using Direct3D for the engine, but thanks for the warning.

archon
I see...

If you are going to use an existing API might I recommend that you check out one of the OpenGL bindings for Java (I like either GL4Java or Magician).

- Just a suggestion

http://games.cpbinc.com/faq/ogl.asp


I believe the postmortem felonius referred to is the one foer Rainbow Six, which you can read here. A good read, actually.

Edited by - Aldacron on September 25, 2000 8:48:19 PM
Thanks again everyone. These links and info are really helpful. Is there an engine out there you''d recommend to study?

This topic is closed to new replies.

Advertisement