Last active
August 29, 2015 14:19
-
-
Save antonyfairport/c98cf8d53c3e23cb13dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////// | |
// Z&A Get Region Map Tile URLs | |
// By Antony Fairport | |
// | |
// Z&A Get Region Map Tile URLs - Get the map tile URLs for a given | |
// region; either the current region or one spoken by the object owner | |
// on channel 1. | |
// | |
// Revision history: | |
// ------------------------------------------------------------ | |
// | |
// 2015-04-23 | |
// Initial revision. | |
////////////////////////////////////////////////////////////////////// | |
// Globals. | |
key kRequest; | |
////////////////////////////////////////////////////////////////////// | |
// Get the size of a tile, in regions, at a given zoom level. | |
integer TileSize( integer iZoom ) | |
{ | |
return (integer) llPow( 2, iZoom - 1 ); | |
} | |
////////////////////////////////////////////////////////////////////// | |
// Calculate the position of the tile to grab given the region we're | |
// after and the zoom level we want. | |
integer CalcPos( float nSimPos, integer iZoom ) | |
{ | |
integer iGridPos = (integer) ( nSimPos / 256.0 ); | |
return iGridPos - ( iGridPos % TileSize( iZoom ) ); | |
} | |
////////////////////////////////////////////////////////////////////// | |
// Get the URL for the tile that contains the region at the given | |
// position, at the given zoom level. | |
string RegionMapURL( vector vSimPos, integer iZoom ) | |
{ | |
return "http://map.secondlife.com/map-" + ( (string) iZoom ) + "-" + | |
( (string) CalcPos( vSimPos.x, iZoom ) ) + | |
"-" + | |
( (string) CalcPos( vSimPos.y, iZoom ) ) + | |
"-objects.jpg"; | |
} | |
////////////////////////////////////////////////////////////////////// | |
// Tell the asker all the URLs for all the zoom levels. | |
TellURLs( key kAsker, vector vPos ) | |
{ | |
integer iZoom; | |
for ( iZoom = 1; iZoom <= 8; iZoom++ ) | |
{ | |
string sSize = (string) TileSize( iZoom ); | |
llRegionSayTo( kAsker, 0, | |
"Zoom " + ( (string) iZoom ) + " (" + sSize + "x" + sSize + "): " + | |
RegionMapURL( vPos, iZoom ) ); | |
} | |
} | |
////////////////////////////////////////////////////////////////////// | |
// Default state. | |
default | |
{ | |
////////////////////////////////////////////////////////////////// | |
// Start listening on channel 1 for region names. | |
state_entry() | |
{ | |
llListen( 1, "", llGetOwner(), "" ); | |
} | |
////////////////////////////////////////////////////////////////// | |
// React to any touch. | |
touch_start( integer _ ) | |
{ | |
TellURLs( llDetectedKey( 0 ), llGetRegionCorner() ); | |
} | |
////////////////////////////////////////////////////////////////// | |
// Listen for a region name. | |
listen( integer channel, string name, key id, string message ) | |
{ | |
if ( channel == 1 ) | |
{ | |
kRequest = llRequestSimulatorData( message, DATA_SIM_POS ); | |
} | |
} | |
////////////////////////////////////////////////////////////////// | |
// React to an incoming data server event. | |
dataserver( key queryid, string data ) | |
{ | |
// A query we last sent? | |
if ( queryid == kRequest ) | |
{ | |
// It is. Tell the owner the URLs for the region at that pos. | |
TellURLs( llGetOwner(), (vector) data ); | |
} | |
} | |
////////////////////////////////////////////////////////////////// | |
// React to changes. | |
changed( integer change ) | |
{ | |
// Owner changed? | |
if ( change & CHANGED_OWNER ) | |
{ | |
// Yes. Reset all the things. | |
llResetScript(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment