| 09-20-2009, 06:29 PM | #1 |
So after getting some feedback from the first one made I've come up with the following system setup: JASS:scope FloatingTextSystem initializer Init globals integer MaxSlot private constant real PeriodicCheck = 0.025 timer GameTimer = CreateTimer() location Loc endglobals struct FTData extends array texttag TT string txt unit u real x0 real y0 real z0 real vx real vy real vz real ax real ay real az ARGB color real size real Fade real FaCo real Life real cslot boolean displayed player P //A few other things that I'll get to later endstruct function FTFadePath takes integer ID, integer i returns nothing if i == 1 then //Random Floating Direction set FTData[ID].vx = GetRandomReal(-100.,100.) set FTData[ID].vy = 0 set FTData[ID].vz = GetRandomReal(-100.,100.) set FTData[ID].ax = 0 set FTData[ID].ay = 0 set FTData[ID].az = 0 endif if i == 2 then// Drops down in an arc set FTData[ID].vx = GetRandomReal(-100.,100.) set FTData[ID].vy = 0 set FTData[ID].vz = GetRandomReal(300,400.) set FTData[ID].ax = 0 set FTData[ID].ay = 0 set FTData[ID].az = GetRandomReal(-800,-400) endif if i == 3 then set FTData[ID].vx = 0 set FTData[ID].vy = 0 set FTData[ID].vz = 0 set FTData[ID].ax = 0 set FTData[ID].ay = 0 set FTData[ID].az = 0 endif endfunction private function GetUnitZ takes unit u returns real return GetUnitFlyHeight(u) endfunction private function Periodic takes nothing returns nothing local integer J = 0 loop if FTData[J].Life <= 0. then if FTData[J].Fade <= 0. then if MaxSlot <= 0 then set MaxSlot = 0 call PauseTimer(GameTimer) else set MaxSlot = MaxSlot - 1 endif set FTData[J].x0 = FTData[MaxSlot].x0 set FTData[J].y0 = FTData[MaxSlot].y0 set FTData[J].z0 = FTData[MaxSlot].z0 set FTData[J].vx = FTData[MaxSlot].vx set FTData[J].vy = FTData[MaxSlot].vy set FTData[J].vz = FTData[MaxSlot].vz set FTData[J].ax = FTData[MaxSlot].ax set FTData[J].ay = FTData[MaxSlot].ay set FTData[J].az = FTData[MaxSlot].az set FTData[J].u = FTData[MaxSlot].u set FTData[J].size = FTData[MaxSlot].size set FTData[J].txt = FTData[MaxSlot].txt set FTData[J].Life = FTData[MaxSlot].Life set FTData[J].Fade = FTData[MaxSlot].Fade set FTData[J].FaCo = FTData[MaxSlot].FaCo set FTData[J].size = FTData[MaxSlot].size set FTData[J].displayed = FTData[MaxSlot].displayed set FTData[J].P = FTData[MaxSlot].P set FTData[J].color = FTData[MaxSlot].color set FTData[J].cslot = FTData[MaxSlot].cslot call SetTextTagText(FTData[J].TT,FTData[J].txt,FTData[J].size*0.0023) call SetTextTagPos(FTData[J].TT,FTData[J].x0,FTData[J].y0,FTData[J].z0+75) set FTData[J].txt = FTData[J].color.str(FTData[J].txt) if GetLocalPlayer() == FTData[J].P and IsMaskedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false and IsFoggedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false then call SetTextTagVisibility(FTData[J].TT, true) else call SetTextTagVisibility(FTData[J].TT, false) endif set FTData[MaxSlot].txt = "" call SetTextTagText(FTData[MaxSlot].TT,FTData[MaxSlot].txt,FTData[MaxSlot].size*0.0023) call SetTextTagPos(FTData[MaxSlot].TT,0,0,0) set FTData[MaxSlot].displayed = false call SetTextTagVisibility(FTData[MaxSlot].TT, false) call SetTextTagColor(FTData[MaxSlot].TT,255,255,255,255) else set FTData[J].Fade = FTData[J].Fade - PeriodicCheck call SetTextTagColor(FTData[J].TT,255,255,255,R2I(255*Pow((FTData[J].Fade/FTData[J].FaCo),0.5))) call SetTextTagText(FTData[J].TT,FTData[J].txt,FTData[J].size*0.0023) call SetTextTagPos(FTData[J].TT,FTData[J].x0+FTData[J].vx*(FTData[J].FaCo - FTData[J].Fade)+FTData[J].ax*Pow((FTData[J].FaCo - FTData[J].Fade),2),FTData[J].y0+FTData[J].vy*(FTData[J].FaCo - FTData[J].Fade)+FTData[J].ay*Pow((FTData[J].FaCo - FTData[J].Fade),2),FTData[J].z0+FTData[J].vz*(FTData[J].FaCo - FTData[J].Fade)+FTData[J].az*Pow((FTData[J].FaCo - FTData[J].Fade),2)+75) if GetLocalPlayer() == FTData[J].P and IsMaskedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false and IsFoggedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false then call SetTextTagVisibility(FTData[J].TT, true) else call SetTextTagVisibility(FTData[J].TT, false) endif endif else set FTData[J].Life = FTData[J].Life - PeriodicCheck set FTData[J].x0 = GetUnitX(FTData[J].u) set FTData[J].y0 = GetUnitY(FTData[J].u) set FTData[J].z0 = GetUnitZ(FTData[J].u) call SetTextTagText(FTData[J].TT,FTData[J].txt,FTData[J].size*0.0023) call SetTextTagPos(FTData[J].TT,FTData[J].x0,FTData[J].y0,FTData[J].z0+75) if GetLocalPlayer() == FTData[J].P and IsMaskedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false and IsFoggedToPlayer(FTData[J].x0,FTData[J].y0,FTData[J].P)==false then call SetTextTagVisibility(FTData[J].TT, true) else call SetTextTagVisibility(FTData[J].TT, false) endif endif set J = J+1 exitwhen J >= MaxSlot endloop set J = 0 endfunction function FillTextSlot takes integer ID, integer FlightPath, string txt, real size, real Life, real FadeTime, unit u, player P returns nothing set FTData[ID].P = P set FTData[ID].color=ARGB.fromPlayer(FTData[ID].P) set FTData[ID].txt = FTData[ID].color.str(txt) set FTData[ID].Life = Life set FTData[ID].Fade = FadeTime set FTData[ID].FaCo = FadeTime set FTData[ID].size = size set FTData[ID].displayed = true set FTData[ID].u = u set FTData[ID].cslot = ID set FTData[ID].x0 = GetUnitX(u) set FTData[ID].y0 = GetUnitY(u) set FTData[ID].z0 = GetUnitZ(u) call FTFadePath(ID,FlightPath) // This will denote the path the texttag will travel when it begins to fade call SetTextTagText(FTData[ID].TT,FTData[ID].txt,FTData[ID].size*0.0023) call SetTextTagPos(FTData[ID].TT,FTData[ID].x0,FTData[ID].y0,FTData[ID].z0+25) if GetLocalPlayer() == FTData[ID].P and IsMaskedToPlayer(FTData[ID].x0,FTData[ID].y0,FTData[ID].P)==false and IsFoggedToPlayer(FTData[ID].x0,FTData[ID].y0,FTData[ID].P)==false then call SetTextTagVisibility(FTData[ID].TT, true) else call SetTextTagVisibility(FTData[ID].TT, false) endif if MaxSlot <= 0 then call TimerStart(GameTimer, PeriodicCheck, true, function Periodic) endif set MaxSlot = MaxSlot + 1 endfunction private function Init takes nothing returns nothing local integer J = 0 local integer PlayNUM = 0 local trigger trg = CreateTrigger() loop if GetPlayerSlotState(Player(J)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(J)) == MAP_CONTROL_USER then set PlayNUM = PlayNUM + 1 else endif set J = J+1 exitwhen J >= 11 endloop set J = 0 loop set FTData[J].TT = CreateTextTag() set FTData[J].txt = "" set FTData[J].displayed = false call SetTextTagPermanent(FTData[J].TT,false) call SetTextTagSuspended(FTData[J].TT, false) call SetTextTagPos(FTData[J].TT,0,0,0) set J = J+1 exitwhen J >= ((PlayNUM*100)-1) endloop set J = 0 set PlayNUM = 0 set MaxSlot = 0 set trg = null endfunction endscope Now this one isn't complete yet but the general form is about the level I want it to be. So far as far as i figure, the system will automatically allow for up to 100 texttags per player playing on the map. I might modify it to dynamically change, if players leave, later but for now I just sets up at the beginning and runs with that number. This time there's no special slots reserved for a player or anything like that, information for any floating text is stored and updated there. I've also preloaded all the texttags before using them. initializing simply moves them and makes them visible to the player in question, and determines if the player would see the texttags in the first place. The system is also setup to have a custom fading flight path and texttags will fade as they fly away at a given rate. Later I'll reserve a spot for users to input their own flight paths. It's basically setup to work with a position, velocity and acceleration component and run off of that. I'm also going to including a color and sizing modifying function but that's all later. Right now, the system will display floating texts and constantly update and replace slots for all players. However, there is a bug, in at which point all floating texts begin to fade away. I'm trying to figure out why that is so I'm posting what I have here in hope that people can, once again, find the bad setup and leaks, flaws, bad practices in my revised code. [edit] could anyone also explain how this setup might break the max floating text limit? |
| 09-27-2009, 08:14 PM | #2 |
[update] Sorry for the bump, but The only way I've found that would work on the system is to create new text tags and destroy used ones. It seems any created text tag that is not permanent has a maximum lifespan of about 180 seconds, slightly less. After this point they no longer seem to show, so they either just fade away, or are destroyed after this point, I'm not sure. Now that I've cleared that up, I'd like some feedback on the coding itself, as in ways I can reduce the size and make it much neater. |
