Map HUD for custom maps?

Creating scripts
Post Reply
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Map HUD for custom maps?

Post by Lunk Portal »

I got the street map completed for TatooineRP (my SWRP sim), and I was wondering if anyone has ever made some sort of map HUD with custom maps?

I would like a simple HUD button to open this street map, and show the player's location if possible. Any suggestions???

Image
Mos Eisley Street Map copy by TatooineRP SWRP, on Flickr
These users thanked the author Lunk Portal for the post:
Ilan Tochner
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
User avatar
Story Link
Posts: 198
Joined: Thu May 25, 2017 2:29 am
Has thanked: 68 times
Been thanked: 324 times

Re: Map HUD for custom maps?

Post by Story Link »

Hi Lunk,
Saw something kinda like that on SL MP...
https://marketplace.secondlife.com/p/He ... D/13165501

Perhaps the creator would be willing to share the source code with you??
It wouldn't be a monetary infringement to them.. so maybe??
These users thanked the author Story Link for the post:
Lunk Portal
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Map HUD for custom maps?

Post by Graham Mills »

This is simple if not very elegant and should work for a standard single region world. Total n00bs might find the instructions somewhat lacking; apologies. It should work for owners and estate managers but for some reason the OSSL dynamic texture functions are not available to everyone. When I get a moment I may update it so that prims are used as markers but this is quicker albeit you get a flicker on updating. I guess this could be reduced by updating two sides alternately, ie rotating to show the updated side.

Incidentally osGetMapTexture didn't work for me or is it incredibly slow?

1. Create a cube prim with dimensions X = 0.02, Y = 0.3, Z = 0.3.
2. Attach it as a HUD to top left of screen and move it so it is fully visible. Rotation in degrees should be <0, 0, 0>.
3. To its contents add a 256x256 pixel texture representing your entire world called "map256" (it should be oriented northwards) and then the script below.

The prim should update every 20 sec with your map texture and superimposed on it your approximate avatar position as a red filled circle.
At the top right is an open black rectangle. Touch this to "hide" the map. A small black rectangle appears in its place (albeit offset to the left). Touch this to make the map reappear.

(What is happening, of course, is that the map prim is rotating when you hide it to show a face that has largely been rendered transparent. That face is narrow so the chances of an accidental touch are reduced but not eliminated. A touch anywhere rotates back to the map)

Code: Select all

float INTERVAL = 20.0;

default
{
    state_entry()
    {
        llSetTexture("map256",4);
        llSetTimerEvent(INTERVAL);
        integer face = 3;
        string CommandList = ""; 
        CommandList = osMovePen( CommandList, 0, 0 ); 
        CommandList = osSetPenColor( CommandList, "Black" ); 
        CommandList = osDrawFilledRectangle( CommandList, 250, 62 ); 
        osSetDynamicTextureDataBlendFace("", "vector", CommandList, "width:256,height:256,Alpha:0", FALSE, 2, 0, 255, face);
    }
    
    timer()
    {
        integer face = 4;
        llSetTexture("map256",4);
        string CommandList = "";  
        vector avatar = llGetPos();                                 
        CommandList = osSetPenSize( CommandList, 3 );              
        CommandList = osSetPenColor( CommandList, "Red" );        
        CommandList = osMovePen( CommandList, llRound(avatar.x), 256 - llRound(avatar.y) );     
        CommandList = osDrawFilledEllipse( CommandList, 10, 10 ); 
        CommandList = osMovePen( CommandList, 242, 5 ); 
        CommandList = osSetPenColor( CommandList, "Black" ); 
        CommandList = osDrawRectangle( CommandList, 10, 10 ); 
        osSetDynamicTextureDataBlendFace("", "vector", CommandList, "width:256,height:256,Alpha:0", TRUE, 2, 0, 255, face);
    }
    
    touch_start(integer n)
    {
        vector pos = llDetectedTouchST(0);
        integer face = 4;
        if (llDetectedTouchFace(0) == 4)
        {
            if ((pos.x > 0.95) && (pos.y > 0.95))
            {
                rotation rot90X = llAxisAngle2Rot(<0, 0, 1>, 90.0*DEG_TO_RAD);
                llSetRot(rot90X);
                llSetTimerEvent(0.0);
            }
            else
            {
                //nothing at present but could be info and/or tp?
            }
        }
        else
        {
            llSetRot(ZERO_ROTATION);
            llSetTimerEvent(INTERVAL);
        }
    }
}
These users thanked the author Graham Mills for the post:
Lunk Portal
User avatar
Shandon Loring
Posts: 1341
Joined: Sat Oct 26, 2013 3:25 am
Has thanked: 961 times
Been thanked: 1581 times
Contact:

Re: Map HUD for custom maps?

Post by Shandon Loring »

That's rad Graham!!
These users thanked the author Shandon Loring for the post:
Graham Mills
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Map HUD for custom maps?

Post by Graham Mills »

Rendering on the reverse side and then flipping does indeed suppress the flicker although inevitably there is a delay in updating. You can also use a higher resolution map and/or make the HUD display surface larger. I need to factor in the plotting position for markers to improve accuracy. Have added click on map teleporting and am also experimenting with markers for points of interest, hard-coded at the moment but potentially pulled from a notecard along with explanatory text.

Still don't know why the OSSL dynamic texture functions are not all available to everyone given their very low threat levels. I assume all of the above is going to prove a fruitless proof-of-concept otherwise.

Nobody else experiencing issues with osGetMapTexture()?
User avatar
Ilan Tochner
Posts: 6504
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 4943 times
Been thanked: 4455 times
Contact:

Re: Map HUD for custom maps?

Post by Ilan Tochner »

Hi Graham,

Scripts that create dynamic textures are one of the more common causes for avoidable sim server load. Using them too often can easily cause sims to become very laggy. People add signs that each update themselves once every few seconds, or worse without any delay, and each such update takes up communication threads that then slow down much more important sim updates. Having a script that automatically updates a sign every few seconds when no one is viewing it is very wasteful in terms of server capacity. You don't need many such signs to easily cause your world to have high CPU usage even when there are just a few avatars inside it. My recommendation is to avoid scripts that create dynamic textures in a loop.
These users thanked the author Ilan Tochner for the post (total 2):
Graham MillsJohn Mela
User avatar
Lunk Portal
Posts: 133
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 92 times
Been thanked: 141 times
Contact:

Re: Map HUD for custom maps?

Post by Lunk Portal »

I used a simple script that makes the HUD map invisible/visible when clicked, this works well for my needs for now. A viable HUD for RPG/combat will take me months to get working LOL
These users thanked the author Lunk Portal for the post:
Graham Mills
B. A. Shields (Lunk Portal)
TatooineRP Region
TatooineRP Website
Kitely Market - Lunk's Loot
My Novels and other Projects
https://linktr.ee/bashields
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Map HUD for custom maps?

Post by Graham Mills »

You might as well move all the osDraw/Font/Pen functions to the Owner/Estate Manager category as they won't work at their current level or am I missing something?

I'll revert to moving a prim marker on a one-time rendered dynamic texture (showing POIs) subsequently used via its UUID and accessed, ie updated, from a region-based "server" on HUD attachment or region restart. Well, it's a plan.
Ilan Tochner wrote:
Sun May 08, 2022 1:01 pm
Hi Graham,

Scripts that create dynamic textures are one of the more common causes for avoidable sim server load. Using them too often can easily cause sims to become very laggy. People add signs that each update themselves once every few seconds, or worse without any delay, and each such update takes up communication threads that then slow down much more important sim updates. Having a script that automatically updates a sign every few seconds when no one is viewing it is very wasteful in terms of server capacity. You don't need many such signs to easily cause your world to have high CPU usage even when there are just a few avatars inside it. My recommendation is to avoid scripts that create dynamic textures in a loop.
User avatar
Ilan Tochner
Posts: 6504
Joined: Sun Dec 23, 2012 8:44 am
Has thanked: 4943 times
Been thanked: 4455 times
Contact:

Re: Map HUD for custom maps?

Post by Ilan Tochner »

It's a question of how they are used, the problem is not with a sporadic frequent update in response to user action, that may be unavoidable in some cases, but with an ongoing update that offers zero value at non zero cost when no one is even looking.
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1141 times

Re: Map HUD for custom maps?

Post by Graham Mills »

Anyways, here's the final version for this thread using a prim as marker (red cylinder, size <0.01500, 0.01500, 0.03500>, rotation <0.00000, 90.00000, 0.00000>, linked as child prim. I've left some of the dynamic texture code in state_entry. This can be replaced by the appropriate textures.

Code: Select all

vector BOUNDS = <454.86401, 366.99899, 21.54020>;//position of bounding 256x256 m rectangle for map (approximated blow)
float INTERVAL = 20.0;

updateAvatar()
{
    string CommandList = "";  
    vector avatar = llGetPos();  
    avatar.x = avatar.x - (455-128);//derived from BOUNDS
    avatar.y = avatar.y - (367-128);
    vector p = llList2Vector(llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_POS_LOCAL]), 0);
    llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_POS_LOCAL, <0, 0.25-(0.5*(avatar.x/256.0)), 0.25-(0.5*((256-avatar.y)/256.0))>]);
}

default
{
    state_entry()
    {
        llSetTexture("map256",4);//set via script but could be manually textured
        //these steps need to be done manually if not owner/estate manager; in that case remove the code below
        //paint the close/hide box at top right
        integer face = 4;
        string CommandList = ""; 
        CommandList = osSetPenSize( CommandList, 3 );               
        CommandList = osMovePen( CommandList, 242, 5 ); 
        CommandList = osSetPenColor( CommandList, "Black" ); 
        CommandList = osDrawRectangle( CommandList, 10, 10 ); 
        osSetDynamicTextureDataBlendFace("", "vector", CommandList, "width:256,height:256,Alpha:0", TRUE, 2, 0, 255, face);
        //paint the side view part-alpha
        face = 3;
        CommandList = ""; 
        CommandList = osMovePen( CommandList, 0, 0 ); 
        CommandList = osSetPenColor( CommandList, "Black" ); 
        CommandList = osDrawFilledRectangle( CommandList, 250, 20 ); 
        osSetDynamicTextureDataBlendFace("", "vector", CommandList, "width:256,height:256,Alpha:0", FALSE, 2, 0, 255, face);
        //don't remove the next line(s)
        llSetTimerEvent(INTERVAL);
    }
    
    timer()
    {
        updateAvatar();
    }
    
    touch_start(integer n)
    {
        vector pos = llDetectedTouchST(0);
        if (llDetectedTouchFace(0) == 4)
        {
            if ((pos.x > 0.95) && (pos.y > 0.95))//hide map
            {
                llSetLinkAlpha(LINK_ALL_CHILDREN, 0.0, ALL_SIDES);//hide marker
                rotation rot90X = llAxisAngle2Rot(<0, 0, 1>, 90.0*DEG_TO_RAD);
                llSetRot(rot90X);
                llSetTimerEvent(0.0);
            }
            else//teleporting
            {
                pos.x = (256*pos.x) + (455 - 128);
                pos.y = (256*pos.y) + (367 - 128);
                osTeleportOwner(pos, ZERO_VECTOR);
                updateAvatar();
            }
        }
        else//unhide map
        {
            llSetRot(ZERO_ROTATION);
            llSetLinkAlpha(LINK_ALL_CHILDREN, 1.0, ALL_SIDES);//unhide marker
            llSetTimerEvent(INTERVAL);
        }
    }
}
These users thanked the author Graham Mills for the post (total 2):
Ilan TochnerLunk Portal
Post Reply