Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] Java Networking for a C++ Game


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
18 replies to this topic

#1 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 05:04 AM

This is a general question, so let me know if I need to be more specific, but I''m thinking about making a networked game and I know Java pretty well, but networking not at all. My question is, do you think it would be possible to use Java for the synching and C++ for the game code? I''ve heard Java is faster than C++ online.

Sponsor:

#2 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 08:06 AM

this is just a theroy I thought up in a couple of mins.
you could develop a servlet then have your c++ app send different types of packets to the servlet giving back the data you want. I think it might be better if you were more specific on what you are stating. I am not sure of your direct question

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

#3 JonStelly   Members   -  Reputation: 127

Like
Likes
Like

Posted 22 September 2000 - 08:42 AM

As a general rule, function for function Java will rarely, if ever, be faster than C++. *assuming both are properly written*

It is possible to communicate from C++ application to Java and back to C++ app. There are some things to consider though. Serialization will add a layer ''gunk'' to your network code and you''ll have to deal with it in your C++ app in a way that is less elegant than what you do in Java.

Depending on the platform, the ''optimal'' sockets design will vary. On Windows, you have Winsock 1.1 and 2.0. Winsock 2.0 Overlapped I/O is generally considered to be the most effective method, with IO Completion Ports being the choice on NT/2K. For BSD/Unix, blocking sockets work well for some cases, non-blocking work better for others.

You''ll just have to read up on the sockets API and decide which is best for your case. I have a lot of experience developing winsock applications, let us know what your target platform is and what you need to do and I might be able to offer some suggestions.



#4 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 09:33 AM

Thanks for the suggestions. Essentially the game will run on windows initially, on the client side, and the server could be the most reasonable/cost effective alternative available. Though I haven''t researched hosting, and imagine I''d end up running the app on someone else''s machine.
My direct question would then be:

The game itself will be a BAD 3-D first person roamer, with an expansive world bereft of terrain. I plan to use the natural grid elements of a map as the scenery for the most part, but intend to also have a much more sofisticated interface for actual battles. Like Archon. So, considering that C++ will have to be used for the secondary interface, for a cool real time battle to take place, would it be worth it to code the "roaming" section of the game in java?

I hope that was more clear. And yes, I have alot of researching to do, if you could point me in the direction of some books/articles on the networking/multiplayer topics, that would be great.

And I heard Java was faster than C++, or had the potential to be so, in the context of Corba and COM. Assuming there was an additional layer(not sure exactly where) between clients and server anyway, java was supposed to take advantage of the added high-level logic better than C++.......just something I read....

Thanks Again,

archon


#5 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 11:01 AM

Java is faster than C in the average. Sun claims that Java at one point be as or faster than C++ someday


I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

Edited by - ARCHIGAMER on September 22, 2000 6:01:55 PM

#6 JonStelly   Members   -  Reputation: 127

Like
Likes
Like

Posted 22 September 2000 - 11:23 AM

Well, COM is built on C++ VTables, so I''d be sceptical of any claims that Java is faster than C++ in accessing COM objects. Although I have to say that even I was impressed with the Java 1.3SDK / Runtime performance, and I''m not a big Java supporter.

"Java is faster than C in the average. Sun claims that Java at one point be as or faster than C++ someday"

Care to clarify that one a bit ArchiGamer? It''s generally accepted that properly written C is a tad faster than C++, so how could it be faster than C now, and hope to be faster than C++ someday? Not trying to be a punk, but I don''t like spreading misinformation. I have yet to see any official reviews / tests that claim that Java is faster than C or C++. Let me know if you have the URL for any.

And now on to the original subject. If you''re going to learn enough C++ to create the user interface for a 3D game, I''d suggest just using it for the whole thing. Switching back and forth would be slow at best.

http://www.stardust.com/

is a good place to start out for Winsock questions. They also have a Winsock 2 mailing list that has a lot of people who are well respected in the field. It''s not directed at games, so I''d subscribe and wait a couple days to get the feel for what kinds of questions get asked there.

Anyway, hope that helps some.



#7 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 01:16 PM

I read that in a book while studying java. Plus if you look in the thread list look for a post about it. is is called "Java faster than C in the average" i believe or something similar

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

#8 ARCHIGAMER   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 September 2000 - 01:20 PM

heres a link to the post here

I wish there was a button on my monitor to turn up the intellegince.
Theres a button called 'brightness' but it doesn't work

#9 felonius   Members   -  Reputation: 122

Like
Likes
Like

Posted 24 September 2000 - 06:08 PM

I am not joining the discussion about what is best C++/Java/C, because it is pretty fruitless and has been parts of this forum numerous times.

Doing network with Java is pretty easy, more so than with C++, but according to some PostMortem article (can''t remember which) I read in Game Developer magazine once there was some people that did their game in C++ but put all networking in Java.
The conclusion was that working with networking in Java was a blis but because they had a need to interface networking on many levels of their system the interface between Java and C++ became so large that it actually took them longer to do than doing it all in C++ - it actually ended with them skipping Java networking and doing it all in C++.
They empahasized that they though Java was good but that their interface needs for the networking made it unsuitable.

In conclusion, you can use Java for networking, but it is most useful if most of your application data you need to send over the network already is in Java format. Otherwise, all the ease of use will be eaten up.

I personally think that one should write ones game in java first (except the graphics engine - those are best done in C++) and then isolated bottlenecks afterwords with a profiler and then recode those parts in C++. If you do this you will have a good advantage of using Java networking and many other Java features.

One thing that I myself has begun to do is to take 3rd party engines (the 6DX 3D engine for instance) provide thin Java wrappers for them and then do the control code in Java. Most of the time the game is down in the engine anyway doing rendering so the fact that the control code is written in Java doesn''t make much difference to the overall speed.

Jacob Marner

#10 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 03:22 AM

Thanks for all the replies....Looks like I have some research to do.


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....
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? 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 guess an interpreter class would be the best way to do it....class babblefish {


At the very least, if its too slow I can always unwrap the code,
Merry Christmas

archon


#11 felonius   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 04:04 AM

> 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


#12 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 05:02 AM

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


#13 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 05:09 AM

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



#14 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 05:12 AM

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

#15 felonius   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 06:07 AM

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

#16 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 09:53 AM

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

#17 Jerry Lynn   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2000 - 10:25 AM

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




#18 Aldacron   GDNet+   -  Reputation: 3130

Like
Likes
Like

Posted 25 September 2000 - 01:47 PM

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

#19 archon   Members   -  Reputation: 122

Like
Likes
Like

Posted 26 September 2000 - 05:06 AM

Thanks again everyone. These links and info are really helpful. Is there an engine out there you''d recommend to study?




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