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  
  [Kryonet] Serializing and transmitting a JOGL Texture object over Kryonet  (Read 3184 times)
0 Members and 1 Guest are viewing this topic.
Offline Rejechted

Senior Member


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Posted 2011-12-20 16:06:38 »

Posted in JOGL Devleopment as well.

We are currently implementing Kryo.  When trying to serialize things across the network, we would like to find the best way to send JOGL Texture object.  Since this object isn't serializable by Kryonet, we can't send it with our Image wrapper.  Is there a way to deconstruct/reconstruct the Image Data from the JOGL Texture object, in a form that we can serialize (i.e. a class or data structure that ends up just holding primitives)?  Instinct tells me there must be some way to get the raw pixel data from a Texture and rebuild the Texture using TextureIO, but I'm not sure.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2011-12-20 16:44:17 »

If you have access to the TextureData used to create the Texture, then you can call getBuffer() on the TextureData to get at the primitive data in an nio buffer.  Looking through the API, it doesn't appear as though Texture has any way by itself to get the data, this is likely so that it's possible to store the data only on the GPU or use an FBO where there is no data in CPU memory.

However, I have to ask why do you need to send textures across the network? That seems like a lot of overhead.  Wouldn't everyone playing have the same assets installed locally? If you have dynamic texture modifications, I feel like it would be more efficient to sent the operations on the texture over the network and have everyone compute them locally.

Offline Rejechted

Senior Member


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Reply #2 - Posted 2011-12-20 16:51:14 »

Interesting, so only send the changes.  We can look into this option.  From valve's wiki:

Detect changes in the server-side object
Serialize (transform into a bit-stream) the changes
Send the bit-stream as a network packet
Unserialize the data on the client and update the corresponding client-side object.

It sounds like this is what you're saying; essentially the Image and Texture objects are already constructed/loaded clientside.  Our job is just to let the client know whether anything about the image has changed, rather than outright overwriting the object with an unpacked copy from the server.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #3 - Posted 2011-12-20 18:03:25 »

Exactly, and images are fairly large objects that, unless you're doing fancy destruction or world manipulation are unlikely to change in the course of a game.  I think the wiki is likely referring to changes in the state such as position, health, or equipment for objects in the game.

Offline theagentd
« Reply #4 - Posted 2011-12-20 19:38:21 »

Why are you sending a texture in the first place? Either have it on each client from the start, or if it's computed, just send a seed or whatever data you need to reconstruct it on the client too.

Myomyomyo.
Offline Rejechted

Senior Member


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Reply #5 - Posted 2011-12-20 21:32:39 »

Why are you sending a texture in the first place? Either have it on each client from the start, or if it's computed, just send a seed or whatever data you need to reconstruct it on the client too.

To be clear we aren't sending the Texture, that's the point of making it transient.  We've decided to just re-obtain it the same way we would when building a new Image object, using the reference string, which is enough.  Needed Textures are loaded into memory when the level is loaded, so they exist on the client, it's just a matter of getting them.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline ChexWithRaisins

Senior Newbie


Projects: 1


SphereCCG.com


« Reply #6 - Posted 2012-04-01 06:39:06 »

As everyone has already pointed out, it is probably better just to have the textures preloaded by the clients and send the reference from the server.

However if you encounter another object that you need to send with kryonet but can't serialize it try this:

Have the object implement Serializable

Then when you register the object with Kryonet try:
1  
kryo.register(nameofyourobject.class, new SerializableSerializer()); // this will cause it to be seralized (inefficiently) by Java's built-in serialization


You can also try:
You will need to create an empty constructor in your object for the serializer to use.
1  
2  
3  
4  
5  
6  
public nameofyourobject(){} //put this in your object to be serialized
----
//Put the following where you register your classes with kryo
FieldSerializer ObjectSerializer = new FieldSerializer(kryo, nameofyourobject.class); //kryo is your kryonet object
ObjectSerializer.setCanBeNull(true); //optional - set if some of the object's parameters might be null
kryo.register(nameofyourobject.class, ObjectSerializer);


 If your object has non-primitive parameters you may need to create a fieldserializer for each of these datatypes as well.  This method will be much more efficient than the first since it uses Kryo's serializer.


Help Beta test SphereCCG!
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-04-01 06:45:34 »

Such an old thread! Why revive it?!

Offline ChexWithRaisins

Senior Newbie


Projects: 1


SphereCCG.com


« Reply #8 - Posted 2012-04-01 06:52:08 »

Sorry new to the forum, not really sure how active it is and therefore what constitutes "old"

Also, it doesn't just help the original poster but anyone else who is searching the web with a similar problem.

Help Beta test SphereCCG!
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #9 - Posted 2012-04-01 08:48:07 »

Well thanks for your contribution Smiley

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 (26 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (55 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!