Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Game world objects on server and client  (Read 1952 times)
0 Members and 1 Guest are viewing this topic.
Offline Threshold

Senior Newbie





« Posted 2007-03-19 17:31:42 »

Hi,

obviously persisent game world objects on the server need to implement the ManagedObject interface.

The game world objects of my app are the same on client and server (besides that I don't need them persistent on the client).

Should I use the same game world object (as ManagedObject) in my client or is there better solution?

Also how would you replicate the server objects to the client?

Greetings from Vienna
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #1 - Posted 2007-03-19 19:24:43 »

Hi

I share some of my game objects, the way I've done it is to have an interface that is implemented by both the ManagedObject version and the normal client side version, the ManagedObject just delegates to a real object (the one from the client) that it holds a reference too (Java reference, not SGS ManagedReference). The client side object then only needs to extend serializable to be able to store it in the server. By using an interface, I can also treat all the server side objects the same as if they were client side in utility classes, I only have to know when it comes to storing reference to then in other classes that SGS uses.

HTH

Endolf

Offline tigeba

Junior Member





« Reply #2 - Posted 2007-03-19 19:29:57 »

I believe the generally accepted approach for this would be an event based system for handling the updates.  Lets say you had a server side object like:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
SimObject implements ManagedObject, SimEventListener
{
   private HashMap values;

  public String getValue(String name){...}
  public void setValue(String name, String value){
   //setting values here would generate SimEvents and update the server side model
 }

  public void event(ClientSimEvent e)
  {
   // changes to the client proxy would get sent here, where the model
 // object in the simulation would get updated if the server decides it is ok, and fire off an update to the client proxy

  }

}


You might create a client side object that would be something like this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
[code]
SimObjectProxy implements SimListener
{
   private HashMap values;

  public String getValue(String name){...}
  public void setValue(String name, String value){
    //This would generate an event to the server, the model would be updated there and
  // the simulation would send the new value if things were ok
 }

  public void event(SimEvent e)
 {
    // This method receives events generated server side and updates your client proxy model
}

}



The idea is that the server would always validate changes to the simulation side, and that you have the ability to control the amount  and priority of updates that the client receives.  Ideally, the client object and the simulation object would implement the same interface.[/code]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2007-03-19 19:45:27 »

In terms of replicating and/or tying the objects together, the Wonderland people have built a distributed object system on top of Darkstar for their use.  You can check their site since Wonderland is an Open Source project.

Be aware though that such a system does *not* deal with the fundamental issues of communciation delays between client and server and how you handle those.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #4 - Posted 2007-03-19 19:56:56 »

Sorry, I missed 1/2 the question Smiley

In terms of sharing the classes, I use a delegate pattern as above, but the actual data is all application dependant. If you do not need high throughput rates (it's all point and click rather than twitch based like an FPS) then you can go even further and like tigeba suggested, create objects that make requests across the network under the covers, which return values as events like tigeba suggests.

If you are in a twitch environment where every millisecond lag counts, then you will need to be a lot more clever, you'll want to use the channels in SGS, broadcast player object updates and update client side cached objects, you'll also need some method to hide (as much as possible) the inevitable network lag.

If you give us some more details about what you are trying to achieve, someone might be able to give you a firmer answer.

HTH

Endolf

Offline Threshold

Senior Newbie





« Reply #5 - Posted 2007-03-20 15:18:24 »

Thanks for your replies!

Quote
If you give us some more details about what you are trying to achieve, someone might be able to give you a firmer answer.

OK I have a "Character" class on the server and client that represents the players' characters. It has some attributes (name, skills, experience points, position) which values are changed on the server when the clients sends valid actions. The updates should be replicated to the clients (also to clients that don't "own" a character, if they have a character that "sees" the other)

Can you give a code example on how you would declare the classes in your solution endolf?

tigeba, I understand your solution for replication, except I don't know how the client and server classes' common interface fits in.

If I use a interface, what about the common attributes of the SimObject? Wouldn't it be better to have a base class which stores that data?

1  
2  
3  
4  
SimObject extends SimObjectBase implements ManagedObject, SimEventListener
{
   ..
}


Or maybe that's what you (endolf) mean with using a reference to a real object:

1  
2  
3  
4  
5  
SimObject implements ManagedObject, SimEventListener
{
   SimObjectBase data;
   ..
}

Offline tigeba

Junior Member





« Reply #6 - Posted 2007-03-20 17:26:12 »

Threshold,

I was kind of thinking along these lines.  The client proxy is truly a stupid object, and does not really know anything about the simulation, and really, probably shouldn't because anyone using your client is gonna have access to it.  The common interface idea was just to present the illusion of using the same set of features for a given object on the client and server.

Lets say you have Player object, it might have an inheritance tree like

SimObject -> Actor -> SimPlayer

And your proxy object might be

ProxyObject -> SimPlayerProxy

SimPlayer and SimPlayerProxy might both implement  Player, which would have stuff that was mostly related to being a player, but would not contain details about the simulation that the client shouldn't know. 

Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2007-03-21 01:37:31 »

FWIW this is much like how the Wonderland distributed object system works.  You define matched sets of player/serve objects and fields they share.
When the setter is invoked on one of those fields, it propagates a duplicate setter call to the server and to all the other player instances in other peoples machines.

But the illusion of  "shared objects" only goers so far since not everyone is going to get that setter called simultaneously th\anks to net latencies.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Threshold

Senior Newbie





« Reply #8 - Posted 2007-03-22 12:45:16 »

Thanks tigeba, I think I get it Smiley

Jeff, do you mean the lg3d-wonderland project at https://lg3d-wonderland.dev.java.net/ ?
It that's the one, I need to contact them for access to their cvs server (which keeps asking me for a pwd when I try to checkout the source).
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2007-03-22 15:50:31 »

yup thats it

I've got no hand in how they run their community so, yes, you will need to contact them directly.

Cheers

JK

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline karmaGfa

Junior Member




Miaow


« Reply #10 - Posted 2007-03-25 13:43:47 »

Jeff, do you mean the lg3d-wonderland project at https://lg3d-wonderland.dev.java.net/ ?
It that's the one, I need to contact them for access to their cvs server (which keeps asking me for a pwd when I try to checkout the source).

I tried 2 minutes ago, and there is no problem getting the sources.
What CVS request you is the login/password of your account on java.net.

<a href="http://www.le-moulin-studio.com">Le Moulin Studio</a> - MMO Technologies and Services.
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.

pw (24 views)
2014-07-24 01:59:36

Riven (22 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

ctomni231 (49 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (54 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!