Forums » Union General »
Choosing Union for a multi-user persitent environment
Added by Fiodor T 669 days ago
Hi Colin, Derek and all involved in the project,
first off thank you for the great job you're doing with Union and the opportunity you're giving Flash developers with your test server, documentation and forum.
I am a graphic and web designer with some experience in creating small AS interactive applications and games.
I'm planning to develop a website that provides the users with an evolving environment populated by different objects (images, texts, videos).
This is not intended as a game, but more as an experiment in alternative visual communication, UI and interaction.
The user experience is enriched by the ability to alter object properties, "unlock" new objects or link them together by collaborating with other connected users either in real-time or by subsequent actions.
As you might have guessed this kind of set up would need to leverage on persistence.
Having no experience in using databases I've asked a Java programmer to join me in the project.
We took a tour of the Union platform site and read the page with the persistence example (http://www.unionplatform.com/?page_id=837).
I would like to ask some questions (please forgive my poor techincal vocabulary):
1) In your example you demonstrate how to persist client attributes. Apart from server, room and client does Union provide a way to create new entities? Is this done via XML or programmatically?
2) If other entities can be created how can their attributes be persisted?Example: a new "image" entity is created, this has to be assigned a few atrtibutes:
- source path of the bitmap for the client to display
- date
- locked/unlocked status
- text description
3) Supposed it is feasible to persist these custom objects, where do we need to put Hibernate files so that Union can read them?
4) How would you manage the chat rooms if there were no delimited rooms but the user was able to send/receive messages from other users within a certain distance in space? My idea is to have a single room and just manage message reception filtering based on a calculated "distance" parameter, but maybe you have some better model.
I'm sorry if I'm asking too much, I understand you may be able to help only up to a certain extent.
Cheers,
Fiodor
Replies
RE: Choosing Union for a multi-user persitent environment - Added by derek clayton 668 days ago
Hi Fiodor,
Thank you!
1) There is no way in Union to create new entities. However, having the ability to extend the concept of object sharing, what we call multiuser objects, is something we're very interested in. It won't be in the initial release but it's certainly something we'll be focusing on more after release.
2) While the answer to 1 was no there is a trick (hack) you can use to create generic, persistent objects. You can create a room to represent each object and set the maximum clients to 0 and have it not die when empty. Once created you can set room attributes and if they are persistent they will be loaded whenever a room with the same name is loaded. It sounds a bit more quirky than it technically is since a room without occupants is really just a generic object.
As well you can take advantage of a nice feature in Reactor on the flash side. Reactor allows you to set a custom Room class when creating a room. For example,
var registry:RoomClassRegistry = reactor.getRoomManager().getRoomClassRegistry();
registry.setRoomClass("images.pic45", Image);
Image would be a subclass of Room. You can read more about the RoomClassRegistry at: http://unionplatform.com/docs/reactor/api/
3) If you ever want to edit the hibernate config to create your own mappings it is called uhibernate.cfg.xml and is located in the UNION_HOME/lib directory.
4) Union does not have a built in concept of position. However, it can be accomplished with some custom code without too much effort. You will need:
- A custom room module that will periodically (say once every 2 seconds) iterate over every client in the room and determine when clients enter/exit the awareness of other clients. When a client enters the awareness of another client because the distance between them is small enough you have them observe each other. This will make them aware of each other and share each others attributes. When the distance exceeds the awareness distance you have them stop observing each other. You will also have to maintain your own list of which clients are aware of each other so that you can selectively broadcast to them only. As an example say you want to "yell" a message that only those within your awareness receive. The client will send a room module message called "YELL" with an argument containing what the person is yelling. (see Code Snippet 1) The custom room module will iterate over the list of aware clients and send them each a custom message. (see Code Snippet 2)
- Create a single room that all clients that might potentially become aware of each other will join. Create the room with the room module specified in previous step.
- When clients join set their update levels so they receive no information. (see Code Snippet 3) The information they receive will instead be controlled through observation and the custom room module.
Note:
- Observing a client sends you all of their attributes including all scoped attributes. This shouldn't be a problem unless you are running multiple types of apps on your server and clients are allowed to join multiple rooms (eg. chess, chat, shared draw, etc).
- We plan on exposing the list of clients a client is currently observing in a future release probably before 1.0. (see ticket http://factory.user1.net/issues/show/321) This will save you having to maintain this list of awareness in your custom room module.
theRoom.sendModuleMessage("YELL", {text:"hello"});
Code Snippet 2:
private ModuleContext m_ctx;
private Map<String, List> m_observedClients; // for now you maintain this map keyed by client id of what other clients a client is observing (until it is exposed in Union)
public boolean init(ModuleContext ctx) {
m_ctx = ctx;
m_ctx.getRoom().addEventListener(RoomEvent.MODULE_MESSAGE, this, "onModuleMessage");
}
public void onModuleMessage(RoomEvent evt) {
if ("YELL".equals(evt.getMessage().getMessageName())) {
for (Client client : m_observedClients.get(evt.getClient().getClientID())) {
client.sendMessage("YELL", evt.getMessage().getArg("text"));
}
}
}
public void shutdown() {
m_ctx.getRoom().removeEventListener(RoomEvent.MODULE_MESSAGE, this, "onModuleMessage");
}
Code Snippet 3:
var updateLevels:UpdateLevels = new UpdateLevels(); updateLevels.clearAll() theRoom.join(null, updateLevels);
If we provide built in support for handling this sort of thing (such as gaming modules) it would definitely be post 1.0.
Hope that helps!
Derek
RE: Choosing Union for a multi-user persitent environment - Added by colin moock 668 days ago
Quick addition: in Union 1.0 Alpha 6, a client cannot observe another client. We added that feature in Alpha 7, which will be released in the next week or so.
colin
RE: Choosing Union for a multi-user persitent environment - Added by Fiodor T 667 days ago
Thank you very much Derek,
your answer is really exhaustive, I will surely try the trick of creating persisting custom rooms and see if it works for me.
As for simulating distance in a room and message broadcasting your example is so thourough that it will require some study on my part, I must admit I've only recently moved to AS3 (thanks to Colin's book btw).
I'm very glad to hear that you're planning to add features oriented towards multiuser game-like environments, I believe this would open huge possibilities for web and game designers.
Thanks!