From 366914b4d119ad139dea330bf15ead31ef5bca50 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 13 Dec 2001 05:46:11 +0000 Subject: [PATCH] Created ZoneUtil for composing and decomposing qualified zone ids. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@767 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../whirled/zone/server/ZoneRegistry.java | 10 +++-- .../whirled/zone/util/ZoneUtil.java | 39 +++++++++++++++++++ 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/java/com/threerings/whirled/zone/util/ZoneUtil.java diff --git a/src/java/com/threerings/whirled/zone/server/ZoneRegistry.java b/src/java/com/threerings/whirled/zone/server/ZoneRegistry.java index 2e03ee368..07b847488 100644 --- a/src/java/com/threerings/whirled/zone/server/ZoneRegistry.java +++ b/src/java/com/threerings/whirled/zone/server/ZoneRegistry.java @@ -1,5 +1,5 @@ // -// $Id: ZoneRegistry.java,v 1.2 2001/12/04 01:06:33 mdb Exp $ +// $Id: ZoneRegistry.java,v 1.3 2001/12/13 05:46:11 mdb Exp $ package com.threerings.whirled.zone.server; @@ -10,6 +10,7 @@ import com.threerings.presents.server.InvocationManager; import com.threerings.whirled.Log; import com.threerings.whirled.server.SceneRegistry; +import com.threerings.whirled.zone.server.util.ZoneUtil; /** * The zone registry takes care of mapping zone requests to the @@ -50,10 +51,13 @@ public class ZoneRegistry /** * Returns the zone manager that handles the specified zone id. + * + * @param qualifiedZoneId the qualified zone id for which the manager + * should be looked up. */ - public ZoneManager getZoneManager (int zoneId) + public ZoneManager getZoneManager (int qualifiedZoneId) { - int zoneType = (0xFF000000 & zoneId) >> 24; + int zoneType = ZoneUtil.zoneType(qualifiedZoneId); return (ZoneManager)_managers.get(zoneType); } diff --git a/src/java/com/threerings/whirled/zone/util/ZoneUtil.java b/src/java/com/threerings/whirled/zone/util/ZoneUtil.java new file mode 100644 index 000000000..617819ee8 --- /dev/null +++ b/src/java/com/threerings/whirled/zone/util/ZoneUtil.java @@ -0,0 +1,39 @@ +// +// $Id: ZoneUtil.java,v 1.1 2001/12/13 05:46:11 mdb Exp $ + +package com.threerings.whirled.zone.server.util; + +/** + * Server-specific, zone-related utility functions. + */ +public class ZoneUtil +{ + /** + * Composes the zone type and zone id into a qualified zone id. A + * qualified zone id is what should be passed around so that the + * server can determine the zone type from the zone id when necessary. + */ + public static int qualifyZoneId (byte zoneType, int zoneId) + { + int qualifiedZoneId = zoneType; + qualifiedZoneId <<= 24; + qualifiedZoneId |= zoneId; + return qualifiedZoneId; + } + + /** + * Extracts the zone type from a qualified zone id. + */ + public static int zoneType (int qualifiedZoneId) + { + return (0xFF000000 & qualifiedZoneId) >> 24; + } + + /** + * Extracts the zone id from a qualified zone id. + */ + public static int zoneId (int qualifiedZoneId) + { + return (0x00FFFFFF & qualifiedZoneId); + } +}