| 07-04-2011, 03:58 PM | #1 |
Purpose: To create wisp wheels in as generic a way as possible and allow them to be manipulated easily. Use: Primarily in mazing maps, this library uses up a hashtable per instantiation and thus isn't particularly viable for most maps. I've played a very very large amount of mazes and have seen maybe 1 that used hashtables at all, as such: hashtable use in mazes is not a problem as far as hitting the maximum number of hashes in a map goes. The way its done utilizes every aspect of the hashtable. the keys correspond to the spoke number and position in that spoke and map to the correct unit. To make the equivalent using arrays, I'd have to put a hard cap on the number of spokes possible in any wheel Code: JASS:library WispWheel requires ListModule globals //the time interval used for each periodic call on Wheel.rotate private constant real wTIMESTEP = .05 //maximum number of spokes supported //the less the better, but never less then used in any wheel private constant integer wNUMSPOKES = 20 //the timer used for all wisp wheels private timer wTimer = CreateTimer() endglobals ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Wheel Struct // by Serenity09 // Credits to grim001 for ListModule // // to create a Wheel: // SimpleWheel.create(unit <centerunit>, player <player owner>, integer <spoke unit ID>, integer <numspokes>, integer <spokelength>, real <degbetween>, real <distbetween>, real <angvelocity>) // distbetween should be somewhere from 100 to 1000, situation depending. angvelocity is very slow around 10 and very fast around 30. zheight is nonexistant at 0 and very high at 600 // center unit: is the center of the wheel. this unit may move and the wheel will follow it // spoke unit ID: the integer ID for the unit that composes the wheel // num spokes: the number of spokes in a wheel (may not exceed wNUMSPOKES) // spoke length: the number of units of the matching ID in each spoke // deg between: the amount of degrees between each spoke (does not include the degrees between the last spoke and the first on purpose) // dist between: the distance between each unit in a spoke // ang velocity: the rate at which a wheel turns. a negative value will make the wheel turn counter clockwise (possitive vice-versa) // // To make a wheel rotate: // create a wheel (either simple or advanced) and store it as a variable (global); it will rotate automatically on creation // do not destroy wheels, as there is no way to destroy hashtables // instead just pause and unpause that wheel using <yourwheel>.wStart() and <yourwheel>.wStop() // // to import into a map // import the ListModule library by grim001 and this WispWheel library // thats it, the Wheel struct is ready to go // this will create conflicts if you have any other struct named SimpleWheel/AdvancedWheel, or the global variables wTIMESTEP/wNUMSPOKES/wTimer are already in use // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// struct SimpleWheel //I'd rather have everything public than having to do Get methods for each //Just don't be retarded setting these and you'll be fine public unit center public integer nSpoke public integer nSpokeLength public integer unitID public real degBetween public real distBetween public real angVelocity public player owner public hashtable units public real array degrees[wNUMSPOKES] implement List private static method wPeriodic takes nothing returns nothing local SimpleWheel e = .first loop exitwhen e == 0 call e.rotate() set e = e.next endloop endmethod public method wStart takes nothing returns nothing call .listAdd() endmethod public method wStop takes nothing returns nothing call .listRemove() endmethod public stub method rotate takes nothing returns nothing local integer i = 1 local integer j = 1 local unit u local real x local real y local real distFromCent //how much the angle should change with each run of the periodic local real dtheta = wTIMESTEP * angVelocity local real thetaOld local real thetaNew local real r loop exitwhen i > nSpoke //every unit in the same spoke should make the same angle with the center. every spoke has at least 1 unit set thetaOld = this.degrees[i] //the new angle is given by the old angle + the change in angle per every time step set thetaNew = thetaOld + dtheta //prevents bloated reals if thetaNew < 360 then set this.degrees[i] = thetaNew else set this.degrees[i] = thetaNew - 360 endif //the angle in radians set r = thetaNew * bj_PI / 180 loop exitwhen j > nSpokeLength //dist from center is linear set distFromCent = j * distBetween //the new x and y value for the unit after the change set x = GetUnitX(this.center) + Cos(r) * distFromCent set y = GetUnitY(this.center) + Sin(r) * distFromCent //the current unit being moved in the wheel set u = LoadUnitHandleBJ(i, j, this.units) //actually moving the unit call SetUnitX(u, x) call SetUnitY(u, y) set j = j + 1 endloop //reset j set j = 1 set i = i + 1 endloop set u = null endmethod public method getUnitInWheel takes integer spokenum, integer wispnum returns unit return LoadUnitHandleBJ(spokenum, wispnum, this.units) endmethod static method create takes unit centerunit, player powner, integer spokeunitID, integer numspokes, integer spokelength, real degreesbetween, real distbetween, real angvelocity returns SimpleWheel local SimpleWheel newwheel = SimpleWheel.allocate() local integer i = 1 local integer j = 1 local real deg local real dist local real x local real y local real r set newwheel.center = centerunit set newwheel.unitID = spokeunitID set newwheel.owner = powner set newwheel.nSpoke = numspokes set newwheel.nSpokeLength = spokelength set newwheel.degBetween = degreesbetween set newwheel.distBetween = distbetween set newwheel.angVelocity = angvelocity set newwheel.units = InitHashtable() loop exitwhen i > newwheel.nSpoke set deg = i*newwheel.degBetween set newwheel.degrees[i] = deg set r = deg * bj_PI / 180 loop exitwhen j > newwheel.nSpokeLength set dist = j*newwheel.distBetween set x = GetUnitX(newwheel.center) + Cos(r) * dist set y = GetUnitY(newwheel.center) + Sin(r) * dist call SaveUnitHandleBJ(CreateUnit(newwheel.owner, newwheel.unitID, x, y, 0), i, j, newwheel.units) set j = j + 1 endloop set j = 1 set i = i + 1 endloop call newwheel.listAdd() call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) return newwheel endmethod endstruct endlibrary questions: 1. hashtable functions so in the code i used bj stuff to access the hashtable this is for a simple reason i have no idea what the hashtable functions are i tried updating jass helper but that didn't help is there a list of the new functions that go with hashtables? or at least could someone tell me the equivalent for the ones I used in my code? 2. onDestroy it might be helpful to some map makers (of mazes) to be able to destroy wisp wheels. personally, I would rather leave the wisp wheel on a level (albeit paused) then destroy it and have to create it again later on, but some people might want to destroy them in the camera help thread I made a little while back, anitarf said that a group would automatically be recycled along with the struct as long as it wasn't destroyed. will this apply for hashtables as well? and in anitarf's example he cleared his group when the last instance was being recycled. because the hashtable is iterated through with wheel specific parameters - I won't run into any problems with old variables for previous wheels, but the lookup speed would still be slower. as such, how do you clear a hashtable? 3. are there any glaring flaws/leaks in my code? besides the bj hash functions that is. as always, thanks very much to anyone for some pointers (0x000000) (0x000001) |
| 07-04-2011, 04:01 PM | #2 |
For BJ replacements, I advise an MPQ browser so you can extract common.j, common.ai, blizzard.j and cheats.j Having blizzard.j open in a properly-highlighted text editor is very useful and fixes problems like "waiting for TESH to update" |
| 07-04-2011, 05:20 PM | #3 | |
Quote:
By the way, I haven't played many maze maps so I don't know what's the point of this wheel. All the code seems to do is rotate a few lines of units in a circle around a central unit. |
| 07-04-2011, 05:26 PM | #4 | |||
Quote:
Hashtable API (common.j):native InitHashtable takes nothing returns hashtable native SaveInteger takes hashtable table, integer parentKey, integer childKey, integer value returns nothing native SaveReal takes hashtable table, integer parentKey, integer childKey, real value returns nothing native SaveBoolean takes hashtable table, integer parentKey, integer childKey, boolean value returns nothing native SaveStr takes hashtable table, integer parentKey, integer childKey, string value returns boolean native SavePlayerHandle takes hashtable table, integer parentKey, integer childKey, player whichPlayer returns boolean native SaveWidgetHandle takes hashtable table, integer parentKey, integer childKey, widget whichWidget returns boolean native SaveDestructableHandle takes hashtable table, integer parentKey, integer childKey, destructable whichDestructable returns boolean native SaveItemHandle takes hashtable table, integer parentKey, integer childKey, item whichItem returns boolean native SaveUnitHandle takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean native SaveAbilityHandle takes hashtable table, integer parentKey, integer childKey, ability whichAbility returns boolean native SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean native SaveTriggerHandle takes hashtable table, integer parentKey, integer childKey, trigger whichTrigger returns boolean native SaveTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey, triggercondition whichTriggercondition returns boolean native SaveTriggerActionHandle takes hashtable table, integer parentKey, integer childKey, triggeraction whichTriggeraction returns boolean native SaveTriggerEventHandle takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean native SaveForceHandle takes hashtable table, integer parentKey, integer childKey, force whichForce returns boolean native SaveGroupHandle takes hashtable table, integer parentKey, integer childKey, group whichGroup returns boolean native SaveLocationHandle takes hashtable table, integer parentKey, integer childKey, location whichLocation returns boolean native SaveRectHandle takes hashtable table, integer parentKey, integer childKey, rect whichRect returns boolean native SaveBooleanExprHandle takes hashtable table, integer parentKey, integer childKey, boolexpr whichBoolexpr returns boolean native SaveSoundHandle takes hashtable table, integer parentKey, integer childKey, sound whichSound returns boolean native SaveEffectHandle takes hashtable table, integer parentKey, integer childKey, effect whichEffect returns boolean native SaveUnitPoolHandle takes hashtable table, integer parentKey, integer childKey, unitpool whichUnitpool returns boolean native SaveItemPoolHandle takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean native SaveQuestHandle takes hashtable table, integer parentKey, integer childKey, quest whichQuest returns boolean native SaveQuestItemHandle takes hashtable table, integer parentKey, integer childKey, questitem whichQuestitem returns boolean native SaveDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey, defeatcondition whichDefeatcondition returns boolean native SaveTimerDialogHandle takes hashtable table, integer parentKey, integer childKey, timerdialog whichTimerdialog returns boolean native SaveLeaderboardHandle takes hashtable table, integer parentKey, integer childKey, leaderboard whichLeaderboard returns boolean native SaveMultiboardHandle takes hashtable table, integer parentKey, integer childKey, multiboard whichMultiboard returns boolean native SaveMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey, multiboarditem whichMultiboarditem returns boolean native SaveTrackableHandle takes hashtable table, integer parentKey, integer childKey, trackable whichTrackable returns boolean native SaveDialogHandle takes hashtable table, integer parentKey, integer childKey, dialog whichDialog returns boolean native SaveButtonHandle takes hashtable table, integer parentKey, integer childKey, button whichButton returns boolean native SaveTextTagHandle takes hashtable table, integer parentKey, integer childKey, texttag whichTexttag returns boolean native SaveLightningHandle takes hashtable table, integer parentKey, integer childKey, lightning whichLightning returns boolean native SaveImageHandle takes hashtable table, integer parentKey, integer childKey, image whichImage returns boolean native SaveUbersplatHandle takes hashtable table, integer parentKey, integer childKey, ubersplat whichUbersplat returns boolean native SaveRegionHandle takes hashtable table, integer parentKey, integer childKey, region whichRegion returns boolean native SaveFogStateHandle takes hashtable table, integer parentKey, integer childKey, fogstate whichFogState returns boolean native SaveFogModifierHandle takes hashtable table, integer parentKey, integer childKey, fogmodifier whichFogModifier returns boolean native LoadInteger takes hashtable table, integer parentKey, integer childKey returns integer native LoadReal takes hashtable table, integer parentKey, integer childKey returns real native LoadBoolean takes hashtable table, integer parentKey, integer childKey returns boolean native LoadStr takes hashtable table, integer parentKey, integer childKey returns string native LoadPlayerHandle takes hashtable table, integer parentKey, integer childKey returns player native LoadWidgetHandle takes hashtable table, integer parentKey, integer childKey returns widget native LoadDestructableHandle takes hashtable table, integer parentKey, integer childKey returns destructable native LoadItemHandle takes hashtable table, integer parentKey, integer childKey returns item native LoadUnitHandle takes hashtable table, integer parentKey, integer childKey returns unit native LoadAbilityHandle takes hashtable table, integer parentKey, integer childKey returns ability native LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer native LoadTriggerHandle takes hashtable table, integer parentKey, integer childKey returns trigger native LoadTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey returns triggercondition native LoadTriggerActionHandle takes hashtable table, integer parentKey, integer childKey returns triggeraction native LoadTriggerEventHandle takes hashtable table, integer parentKey, integer childKey returns event native LoadForceHandle takes hashtable table, integer parentKey, integer childKey returns force native LoadGroupHandle takes hashtable table, integer parentKey, integer childKey returns group native LoadLocationHandle takes hashtable table, integer parentKey, integer childKey returns location native LoadRectHandle takes hashtable table, integer parentKey, integer childKey returns rect native LoadBooleanExprHandle takes hashtable table, integer parentKey, integer childKey returns boolexpr native LoadSoundHandle takes hashtable table, integer parentKey, integer childKey returns sound native LoadEffectHandle takes hashtable table, integer parentKey, integer childKey returns effect native LoadUnitPoolHandle takes hashtable table, integer parentKey, integer childKey returns unitpool native LoadItemPoolHandle takes hashtable table, integer parentKey, integer childKey returns itempool native LoadQuestHandle takes hashtable table, integer parentKey, integer childKey returns quest native LoadQuestItemHandle takes hashtable table, integer parentKey, integer childKey returns questitem native LoadDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey returns defeatcondition native LoadTimerDialogHandle takes hashtable table, integer parentKey, integer childKey returns timerdialog native LoadLeaderboardHandle takes hashtable table, integer parentKey, integer childKey returns leaderboard native LoadMultiboardHandle takes hashtable table, integer parentKey, integer childKey returns multiboard native LoadMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey returns multiboarditem native LoadTrackableHandle takes hashtable table, integer parentKey, integer childKey returns trackable native LoadDialogHandle takes hashtable table, integer parentKey, integer childKey returns dialog native LoadButtonHandle takes hashtable table, integer parentKey, integer childKey returns button native LoadTextTagHandle takes hashtable table, integer parentKey, integer childKey returns texttag native LoadLightningHandle takes hashtable table, integer parentKey, integer childKey returns lightning native LoadImageHandle takes hashtable table, integer parentKey, integer childKey returns image native LoadUbersplatHandle takes hashtable table, integer parentKey, integer childKey returns ubersplat native LoadRegionHandle takes hashtable table, integer parentKey, integer childKey returns region native LoadFogStateHandle takes hashtable table, integer parentKey, integer childKey returns fogstate native LoadFogModifierHandle takes hashtable table, integer parentKey, integer childKey returns fogmodifier native HaveSavedInteger takes hashtable table, integer parentKey, integer childKey returns boolean native HaveSavedReal takes hashtable table, integer parentKey, integer childKey returns boolean native HaveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns boolean native HaveSavedString takes hashtable table, integer parentKey, integer childKey returns boolean native HaveSavedHandle takes hashtable table, integer parentKey, integer childKey returns boolean native RemoveSavedInteger takes hashtable table, integer parentKey, integer childKey returns nothing native RemoveSavedReal takes hashtable table, integer parentKey, integer childKey returns nothing native RemoveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns nothing native RemoveSavedString takes hashtable table, integer parentKey, integer childKey returns nothing native RemoveSavedHandle takes hashtable table, integer parentKey, integer childKey returns nothing native FlushParentHashtable takes hashtable table returns nothing native FlushChildHashtable takes hashtable table, integer parentKey returns nothing Hashtable API (Blizzard.j):globals hashtable bj_lastCreatedHashtable = null // Hashtable value types constant integer bj_HASHTABLE_BOOLEAN = 0 constant integer bj_HASHTABLE_INTEGER = 1 constant integer bj_HASHTABLE_REAL = 2 constant integer bj_HASHTABLE_STRING = 3 constant integer bj_HASHTABLE_HANDLE = 4 endglobals //=========================================================================== function InitHashtableBJ takes nothing returns hashtable set bj_lastCreatedHashtable = InitHashtable() return bj_lastCreatedHashtable endfunction //=========================================================================== function GetLastCreatedHashtableBJ takes nothing returns hashtable return bj_lastCreatedHashtable endfunction //=========================================================================== function SaveRealBJ takes real value, integer key, integer missionKey, hashtable table returns nothing call SaveReal(table, missionKey, key, value) endfunction //=========================================================================== function SaveIntegerBJ takes integer value, integer key, integer missionKey, hashtable table returns nothing call SaveInteger(table, missionKey, key, value) endfunction //=========================================================================== function SaveBooleanBJ takes boolean value, integer key, integer missionKey, hashtable table returns nothing call SaveBoolean(table, missionKey, key, value) endfunction //=========================================================================== function SaveStringBJ takes string value, integer key, integer missionKey, hashtable table returns boolean return SaveStr(table, missionKey, key, value) endfunction //=========================================================================== function SavePlayerHandleBJ takes player whichPlayer, integer key, integer missionKey, hashtable table returns boolean return SavePlayerHandle(table, missionKey, key, whichPlayer) endfunction //=========================================================================== function SaveWidgetHandleBJ takes widget whichWidget, integer key, integer missionKey, hashtable table returns boolean return SaveWidgetHandle(table, missionKey, key, whichWidget) endfunction //=========================================================================== function SaveDestructableHandleBJ takes destructable whichDestructable, integer key, integer missionKey, hashtable table returns boolean return SaveDestructableHandle(table, missionKey, key, whichDestructable) endfunction //=========================================================================== function SaveItemHandleBJ takes item whichItem, integer key, integer missionKey, hashtable table returns boolean return SaveItemHandle(table, missionKey, key, whichItem) endfunction //=========================================================================== function SaveUnitHandleBJ takes unit whichUnit, integer key, integer missionKey, hashtable table returns boolean return SaveUnitHandle(table, missionKey, key, whichUnit) endfunction //=========================================================================== function SaveAbilityHandleBJ takes ability whichAbility, integer key, integer missionKey, hashtable table returns boolean return SaveAbilityHandle(table, missionKey, key, whichAbility) endfunction //=========================================================================== function SaveTimerHandleBJ takes timer whichTimer, integer key, integer missionKey, hashtable table returns boolean return SaveTimerHandle(table, missionKey, key, whichTimer) endfunction //=========================================================================== function SaveTriggerHandleBJ takes trigger whichTrigger, integer key, integer missionKey, hashtable table returns boolean return SaveTriggerHandle(table, missionKey, key, whichTrigger) endfunction //=========================================================================== function SaveTriggerConditionHandleBJ takes triggercondition whichTriggercondition, integer key, integer missionKey, hashtable table returns boolean return SaveTriggerConditionHandle(table, missionKey, key, whichTriggercondition) endfunction //=========================================================================== function SaveTriggerActionHandleBJ takes triggeraction whichTriggeraction, integer key, integer missionKey, hashtable table returns boolean return SaveTriggerActionHandle(table, missionKey, key, whichTriggeraction) endfunction //=========================================================================== function SaveTriggerEventHandleBJ takes event whichEvent, integer key, integer missionKey, hashtable table returns boolean return SaveTriggerEventHandle(table, missionKey, key, whichEvent) endfunction //=========================================================================== function SaveForceHandleBJ takes force whichForce, integer key, integer missionKey, hashtable table returns boolean return SaveForceHandle(table, missionKey, key, whichForce) endfunction //=========================================================================== function SaveGroupHandleBJ takes group whichGroup, integer key, integer missionKey, hashtable table returns boolean return SaveGroupHandle(table, missionKey, key, whichGroup) endfunction //=========================================================================== function SaveLocationHandleBJ takes location whichLocation, integer key, integer missionKey, hashtable table returns boolean return SaveLocationHandle(table, missionKey, key, whichLocation) endfunction //=========================================================================== function SaveRectHandleBJ takes rect whichRect, integer key, integer missionKey, hashtable table returns boolean return SaveRectHandle(table, missionKey, key, whichRect) endfunction //=========================================================================== function SaveBooleanExprHandleBJ takes boolexpr whichBoolexpr, integer key, integer missionKey, hashtable table returns boolean return SaveBooleanExprHandle(table, missionKey, key, whichBoolexpr) endfunction //=========================================================================== function SaveSoundHandleBJ takes sound whichSound, integer key, integer missionKey, hashtable table returns boolean return SaveSoundHandle(table, missionKey, key, whichSound) endfunction //=========================================================================== function SaveEffectHandleBJ takes effect whichEffect, integer key, integer missionKey, hashtable table returns boolean return SaveEffectHandle(table, missionKey, key, whichEffect) endfunction //=========================================================================== function SaveUnitPoolHandleBJ takes unitpool whichUnitpool, integer key, integer missionKey, hashtable table returns boolean return SaveUnitPoolHandle(table, missionKey, key, whichUnitpool) endfunction //=========================================================================== function SaveItemPoolHandleBJ takes itempool whichItempool, integer key, integer missionKey, hashtable table returns boolean return SaveItemPoolHandle(table, missionKey, key, whichItempool) endfunction //=========================================================================== function SaveQuestHandleBJ takes quest whichQuest, integer key, integer missionKey, hashtable table returns boolean return SaveQuestHandle(table, missionKey, key, whichQuest) endfunction //=========================================================================== function SaveQuestItemHandleBJ takes questitem whichQuestitem, integer key, integer missionKey, hashtable table returns boolean return SaveQuestItemHandle(table, missionKey, key, whichQuestitem) endfunction //=========================================================================== function SaveDefeatConditionHandleBJ takes defeatcondition whichDefeatcondition, integer key, integer missionKey, hashtable table returns boolean return SaveDefeatConditionHandle(table, missionKey, key, whichDefeatcondition) endfunction //=========================================================================== function SaveTimerDialogHandleBJ takes timerdialog whichTimerdialog, integer key, integer missionKey, hashtable table returns boolean return SaveTimerDialogHandle(table, missionKey, key, whichTimerdialog) endfunction //=========================================================================== function SaveLeaderboardHandleBJ takes leaderboard whichLeaderboard, integer key, integer missionKey, hashtable table returns boolean return SaveLeaderboardHandle(table, missionKey, key, whichLeaderboard) endfunction //=========================================================================== function SaveMultiboardHandleBJ takes multiboard whichMultiboard, integer key, integer missionKey, hashtable table returns boolean return SaveMultiboardHandle(table, missionKey, key, whichMultiboard) endfunction //=========================================================================== function SaveMultiboardItemHandleBJ takes multiboarditem whichMultiboarditem, integer key, integer missionKey, hashtable table returns boolean return SaveMultiboardItemHandle(table, missionKey, key, whichMultiboarditem) endfunction //=========================================================================== function SaveTrackableHandleBJ takes trackable whichTrackable, integer key, integer missionKey, hashtable table returns boolean return SaveTrackableHandle(table, missionKey, key, whichTrackable) endfunction //=========================================================================== function SaveDialogHandleBJ takes dialog whichDialog, integer key, integer missionKey, hashtable table returns boolean return SaveDialogHandle(table, missionKey, key, whichDialog) endfunction //=========================================================================== function SaveButtonHandleBJ takes button whichButton, integer key, integer missionKey, hashtable table returns boolean return SaveButtonHandle(table, missionKey, key, whichButton) endfunction //=========================================================================== function SaveTextTagHandleBJ takes texttag whichTexttag, integer key, integer missionKey, hashtable table returns boolean return SaveTextTagHandle(table, missionKey, key, whichTexttag) endfunction //=========================================================================== function SaveLightningHandleBJ takes lightning whichLightning, integer key, integer missionKey, hashtable table returns boolean return SaveLightningHandle(table, missionKey, key, whichLightning) endfunction //=========================================================================== function SaveImageHandleBJ takes image whichImage, integer key, integer missionKey, hashtable table returns boolean return SaveImageHandle(table, missionKey, key, whichImage) endfunction //=========================================================================== function SaveUbersplatHandleBJ takes ubersplat whichUbersplat, integer key, integer missionKey, hashtable table returns boolean return SaveUbersplatHandle(table, missionKey, key, whichUbersplat) endfunction //=========================================================================== function SaveRegionHandleBJ takes region whichRegion, integer key, integer missionKey, hashtable table returns boolean return SaveRegionHandle(table, missionKey, key, whichRegion) endfunction //=========================================================================== function SaveFogStateHandleBJ takes fogstate whichFogState, integer key, integer missionKey, hashtable table returns boolean return SaveFogStateHandle(table, missionKey, key, whichFogState) endfunction //=========================================================================== function SaveFogModifierHandleBJ takes fogmodifier whichFogModifier, integer key, integer missionKey, hashtable table returns boolean return SaveFogModifierHandle(table, missionKey, key, whichFogModifier) endfunction //=========================================================================== function SaveAgentHandleBJ takes agent whichAgent, integer key, integer missionKey, hashtable table returns boolean return SaveAgentHandle(table, missionKey, key, whichAgent) endfunction //=========================================================================== function SaveHashtableHandleBJ takes hashtable whichHashtable, integer key, integer missionKey, hashtable table returns boolean return SaveHashtableHandle(table, missionKey, key, whichHashtable) endfunction //=========================================================================== function LoadRealBJ takes integer key, integer missionKey, hashtable table returns real //call SyncStoredReal(table, missionKey, key) return LoadReal(table, missionKey, key) endfunction //=========================================================================== function LoadIntegerBJ takes integer key, integer missionKey, hashtable table returns integer //call SyncStoredInteger(table, missionKey, key) return LoadInteger(table, missionKey, key) endfunction //=========================================================================== function LoadBooleanBJ takes integer key, integer missionKey, hashtable table returns boolean //call SyncStoredBoolean(table, missionKey, key) return LoadBoolean(table, missionKey, key) endfunction //=========================================================================== function LoadStringBJ takes integer key, integer missionKey, hashtable table returns string local string s //call SyncStoredString(table, missionKey, key) set s = LoadStr(table, missionKey, key) if (s == null) then return "" else return s endif endfunction //=========================================================================== function LoadPlayerHandleBJ takes integer key, integer missionKey, hashtable table returns player return LoadPlayerHandle(table, missionKey, key) endfunction //=========================================================================== function LoadWidgetHandleBJ takes integer key, integer missionKey, hashtable table returns widget return LoadWidgetHandle(table, missionKey, key) endfunction //=========================================================================== function LoadDestructableHandleBJ takes integer key, integer missionKey, hashtable table returns destructable return LoadDestructableHandle(table, missionKey, key) endfunction //=========================================================================== function LoadItemHandleBJ takes integer key, integer missionKey, hashtable table returns item return LoadItemHandle(table, missionKey, key) endfunction //=========================================================================== function LoadUnitHandleBJ takes integer key, integer missionKey, hashtable table returns unit return LoadUnitHandle(table, missionKey, key) endfunction //=========================================================================== function LoadAbilityHandleBJ takes integer key, integer missionKey, hashtable table returns ability return LoadAbilityHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTimerHandleBJ takes integer key, integer missionKey, hashtable table returns timer return LoadTimerHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTriggerHandleBJ takes integer key, integer missionKey, hashtable table returns trigger return LoadTriggerHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTriggerConditionHandleBJ takes integer key, integer missionKey, hashtable table returns triggercondition return LoadTriggerConditionHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTriggerActionHandleBJ takes integer key, integer missionKey, hashtable table returns triggeraction return LoadTriggerActionHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTriggerEventHandleBJ takes integer key, integer missionKey, hashtable table returns event return LoadTriggerEventHandle(table, missionKey, key) endfunction //=========================================================================== function LoadForceHandleBJ takes integer key, integer missionKey, hashtable table returns force return LoadForceHandle(table, missionKey, key) endfunction //=========================================================================== function LoadGroupHandleBJ takes integer key, integer missionKey, hashtable table returns group return LoadGroupHandle(table, missionKey, key) endfunction //=========================================================================== function LoadLocationHandleBJ takes integer key, integer missionKey, hashtable table returns location return LoadLocationHandle(table, missionKey, key) endfunction //=========================================================================== function LoadRectHandleBJ takes integer key, integer missionKey, hashtable table returns rect return LoadRectHandle(table, missionKey, key) endfunction //=========================================================================== function LoadBooleanExprHandleBJ takes integer key, integer missionKey, hashtable table returns boolexpr return LoadBooleanExprHandle(table, missionKey, key) endfunction //=========================================================================== function LoadSoundHandleBJ takes integer key, integer missionKey, hashtable table returns sound return LoadSoundHandle(table, missionKey, key) endfunction //=========================================================================== function LoadEffectHandleBJ takes integer key, integer missionKey, hashtable table returns effect return LoadEffectHandle(table, missionKey, key) endfunction //=========================================================================== function LoadUnitPoolHandleBJ takes integer key, integer missionKey, hashtable table returns unitpool return LoadUnitPoolHandle(table, missionKey, key) endfunction //=========================================================================== function LoadItemPoolHandleBJ takes integer key, integer missionKey, hashtable table returns itempool return LoadItemPoolHandle(table, missionKey, key) endfunction //=========================================================================== function LoadQuestHandleBJ takes integer key, integer missionKey, hashtable table returns quest return LoadQuestHandle(table, missionKey, key) endfunction //=========================================================================== function LoadQuestItemHandleBJ takes integer key, integer missionKey, hashtable table returns questitem return LoadQuestItemHandle(table, missionKey, key) endfunction //=========================================================================== function LoadDefeatConditionHandleBJ takes integer key, integer missionKey, hashtable table returns defeatcondition return LoadDefeatConditionHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTimerDialogHandleBJ takes integer key, integer missionKey, hashtable table returns timerdialog return LoadTimerDialogHandle(table, missionKey, key) endfunction //=========================================================================== function LoadLeaderboardHandleBJ takes integer key, integer missionKey, hashtable table returns leaderboard return LoadLeaderboardHandle(table, missionKey, key) endfunction //=========================================================================== function LoadMultiboardHandleBJ takes integer key, integer missionKey, hashtable table returns multiboard return LoadMultiboardHandle(table, missionKey, key) endfunction //=========================================================================== function LoadMultiboardItemHandleBJ takes integer key, integer missionKey, hashtable table returns multiboarditem return LoadMultiboardItemHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTrackableHandleBJ takes integer key, integer missionKey, hashtable table returns trackable return LoadTrackableHandle(table, missionKey, key) endfunction //=========================================================================== function LoadDialogHandleBJ takes integer key, integer missionKey, hashtable table returns dialog return LoadDialogHandle(table, missionKey, key) endfunction //=========================================================================== function LoadButtonHandleBJ takes integer key, integer missionKey, hashtable table returns button return LoadButtonHandle(table, missionKey, key) endfunction //=========================================================================== function LoadTextTagHandleBJ takes integer key, integer missionKey, hashtable table returns texttag return LoadTextTagHandle(table, missionKey, key) endfunction //=========================================================================== function LoadLightningHandleBJ takes integer key, integer missionKey, hashtable table returns lightning return LoadLightningHandle(table, missionKey, key) endfunction //=========================================================================== function LoadImageHandleBJ takes integer key, integer missionKey, hashtable table returns image return LoadImageHandle(table, missionKey, key) endfunction //=========================================================================== function LoadUbersplatHandleBJ takes integer key, integer missionKey, hashtable table returns ubersplat return LoadUbersplatHandle(table, missionKey, key) endfunction //=========================================================================== function LoadRegionHandleBJ takes integer key, integer missionKey, hashtable table returns region return LoadRegionHandle(table, missionKey, key) endfunction //=========================================================================== function LoadFogStateHandleBJ takes integer key, integer missionKey, hashtable table returns fogstate return LoadFogStateHandle(table, missionKey, key) endfunction //=========================================================================== function LoadFogModifierHandleBJ takes integer key, integer missionKey, hashtable table returns fogmodifier return LoadFogModifierHandle(table, missionKey, key) endfunction //=========================================================================== function LoadHashtableHandleBJ takes integer key, integer missionKey, hashtable table returns hashtable return LoadHashtableHandle(table, missionKey, key) endfunction //=========================================================================== function FlushParentHashtableBJ takes hashtable table returns nothing call FlushParentHashtable(table) endfunction //=========================================================================== function FlushChildHashtableBJ takes integer missionKey, hashtable table returns nothing call FlushChildHashtable(table, missionKey) endfunction //=========================================================================== function HaveSavedValue takes integer key, integer valueType, integer missionKey, hashtable table returns boolean if (valueType == bj_HASHTABLE_BOOLEAN) then return HaveSavedBoolean(table, missionKey, key) elseif (valueType == bj_HASHTABLE_INTEGER) then return HaveSavedInteger(table, missionKey, key) elseif (valueType == bj_HASHTABLE_REAL) then return HaveSavedReal(table, missionKey, key) elseif (valueType == bj_HASHTABLE_STRING) then return HaveSavedString(table, missionKey, key) elseif (valueType == bj_HASHTABLE_HANDLE) then return HaveSavedHandle(table, missionKey, key) else // Unrecognized value type - ignore the request. return false endif endfunction Quote:
Quote:
|
| 07-04-2011, 11:06 PM | #5 | ||||||||
Quote:
Quote:
each unit needs a move coordinate suited specifically to it that coordinate is easily given by utilizing the key values as factors it would be possible to do this with a group, but you would need a lot more calculations and function calls - ie. if hashtable use is not a problem its much much faster Quote:
ermm how? Quote:
in a maze each wisp in the wheel has collision also if you ever feel like playing a few more mazes, you should shoot me a message/pm :D kinda curious, did gameslayer's Platform Escape use your keyboard event library? Quote:
the most wisp wheels i've ever seen in any maze is about 20 and thats being generous with the number for mine, I plan to use 40 or so tops as cool as bribe's array looks, it shares the same problem as anitarf's idea in respect to how to store the wisp wheel Its not really a question of how best to store it, the hashtable is a perfect solution to it... minus the problem that using hashtables en masse is taboo Maybe it'd be best to include a ConservativeWheel struct in the library that doesn't use the hashtable (but also is far more inefficient) Quote:
Quote:
but because they aren't relevant to this, I didn't see any reason to post them I edited out most of the stuff that hinted about them, but I missed the stub declaration. only rotate is a stub, because only rotate needs to be changed this actually made me think of an important question I know that all structs that are children/parent share the same maximum of 8190 possible instances, but do they also share the same List Module? It seems like they do, but this is important enough to get verification Quote:
tyvm I had no idea anyways ty anitarf, bribe and bbq for the tips |
| 07-04-2011, 11:37 PM | #6 | ||||
Quote:
Since JASS uses 32-bit signed integers, the parent- and child-keys can be anywhere from -(2^31) to 2^31 - 1. That means that you can store a lot of data in a single hashtable. And as I said, that's where theurl Array library comes in handy. Quote:
Quote:
Quote:
|
| 07-05-2011, 03:02 AM | #7 | |
Quote:
oh okay, very cool - I wasn't as far as dual array when I posted last. I'll probably try to do this, but first I wanna take care of the existing bugs specifically the bugs with wPause and wUnpause here is the shortened current code with what I'm pretty sure are the only relevant parts just below it is the complete current code - just in case what's shown in the first isn't enough JASS:struct SimpleWheel //member vars implement List public stub method rotate takes nothing returns nothing //... endmethod private static method wPeriodic takes nothing returns nothing local thistype e = .first loop exitwhen e == 0 call e.rotate() set e = e.next endloop endmethod public method wUnpause takes nothing returns nothing if .count == 0 then call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) endif call .listAdd() endmethod public method wPause takes nothing returns nothing call .listRemove() if .count == 0 then call PauseTimer(wTimer) endif endmethod public method GetUnitInWheel takes integer spokenum, integer wispnum returns unit //... endmethod static method create takes unit centerunit, player powner, integer spokeunitID, integer numspokes, integer spokelength, real degreesbetween, real distbetween, real angvelocity returns SimpleWheel local SimpleWheel newwheel = SimpleWheel.allocate() //... call newwheel.listAdd() call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) set u = null return newwheel endmethod endstruct JASS:struct SimpleWheel //I'd rather have everything public than having to do Get methods for each public unit center public integer nSpoke public integer nSpokeLength public integer unitID public real degBetween public real distBetween public real angVelocity public player owner public hashtable units public real array degrees[wNUMSPOKES] implement List public stub method rotate takes nothing returns nothing local integer i = 1 local integer j = 1 local unit u local real x local real y local real distFromCent //how much the angle should change with each run of the periodic local real dtheta = wTIMESTEP * angVelocity local real thetaOld local real thetaNew local real r loop exitwhen i > nSpoke //every unit in the same spoke should make the same angle with the center. every spoke has at least 1 unit set thetaOld = this.degrees[i] //the new angle is given by the old angle + the change in angle per every time step set thetaNew = thetaOld + dtheta //prevents bloated reals if thetaNew < 360 then set this.degrees[i] = thetaNew else set this.degrees[i] = thetaNew - 360 endif //the angle in radians set r = thetaNew * bj_PI / 180 loop exitwhen j > nSpokeLength //dist from center is linear set distFromCent = j * distBetween //the new x and y value for the unit after the change set x = GetUnitX(this.center) + Cos(r) * distFromCent set y = GetUnitY(this.center) + Sin(r) * distFromCent //the current unit being moved in the wheel //set u = LoadUnitHandleBJ(i, j, this.units) set u = LoadUnitHandle(this.units, i, j) //actually moving the unit call SetUnitX(u, x) call SetUnitY(u, y) //call SetUnitFlyHeight(u, GetUnitFlyHeight(center), 0) set j = j + 1 endloop //reset j set j = 1 set i = i + 1 endloop set u = null endmethod private static method wPeriodic takes nothing returns nothing //use of thistype because it might not be called by a simple wheel local thistype e = .first loop exitwhen e == 0 call e.rotate() set e = e.next endloop endmethod public method wUnpause takes nothing returns nothing if .count == 0 then call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) endif call .listAdd() endmethod public method wPause takes nothing returns nothing call .listRemove() if .count == 0 then call PauseTimer(wTimer) endif endmethod public method GetUnitInWheel takes integer spokenum, integer wispnum returns unit return LoadUnitHandle(this.units, spokenum, wispnum) endmethod static method create takes unit centerunit, player powner, integer spokeunitID, integer numspokes, integer spokelength, real degreesbetween, real distbetween, real angvelocity returns SimpleWheel local SimpleWheel newwheel = SimpleWheel.allocate() local integer i = 1 local integer j = 1 local real deg local real dist local real x local real y local real r local unit u set newwheel.center = centerunit set newwheel.unitID = spokeunitID set newwheel.owner = powner set newwheel.nSpoke = numspokes set newwheel.nSpokeLength = spokelength set newwheel.degBetween = degreesbetween set newwheel.distBetween = distbetween set newwheel.angVelocity = angvelocity set newwheel.units = InitHashtable() loop exitwhen i > newwheel.nSpoke set deg = i*newwheel.degBetween set newwheel.degrees[i] = deg set r = deg * bj_PI / 180 loop exitwhen j > newwheel.nSpokeLength set dist = j*newwheel.distBetween set x = GetUnitX(newwheel.center) + Cos(r) * dist set y = GetUnitY(newwheel.center) + Sin(r) * dist set u = CreateUnit(newwheel.owner, newwheel.unitID, x, y, 0) call SaveUnitHandle(newwheel.units, i, j, u) call SetUnitInvulnerable(u, true) set j = j + 1 endloop set j = 1 set i = i + 1 endloop call newwheel.listAdd() call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) set u = null return newwheel endmethod endstruct so when i call .wPause() on a wheel, all rotation stops, which is perfect but when i cal .wUnpause() on the same wheel, the game goes into overdrive and lags too badly to even quit however, in the very few frames you get, you can see that the wheel has resumed rotation the ability to pause/unpause wheels is crucial for this to be useful any ideas are much welcome and appreciated just in case, the newest test map is attached |
| 07-05-2011, 11:13 AM | #8 |
Here, try this. No hashtable used. JASS:library WispWheel requires ListModule globals //the time interval used for each periodic call on Wheel.rotate private constant real wTIMESTEP = .05 //maximum number of spokes supported //the less the better, but never less then used in any wheel private constant integer wNUMSPOKES = 20 //the timer used for all wisp wheels private timer wTimer = CreateTimer() endglobals struct SimpleWheel //I'd rather have everything public than having to do Get methods for each //Just don't be retarded setting these and you'll be fine //you know, there's a readonly keyword ;) readonly unit center readonly integer nSpoke readonly integer nSpokeLength readonly integer unitID readonly real degBetween readonly real distBetween readonly real angVelocity readonly player owner private group wisps implement List private static method wPeriodic takes nothing returns nothing local SimpleWheel e = .first loop exitwhen e == 0 call e.rotate() set e = e.next endloop endmethod public method wStart takes nothing returns nothing call .listAdd() endmethod public method wStop takes nothing returns nothing call .listRemove() endmethod private static thistype current private static integer spoke private static integer count private static method groupEnum takes nothing returns nothing local thistype this=current call SetUnitX(GetEnumUnit(), GetUnitX(this.center) + Cos(degBetween*spoke*bj_DEGTORAD) * distBetween*count) call SetUnitY(GetEnumUnit(), GetUnitY(this.center) + Sin(degBetween*spoke*bj_DEGTORAD) * distBetween*count) set .count=.count+1 if .count>.nSpokeLength then set .count=0 set .spoke=.spoke+1 endif endmethod public stub method rotate takes nothing returns nothing set .current=this set .spoke=0 set .count=0 call ForGroup(.wisps, function thistype.groupEnum) endmethod static method create takes unit centerunit, player powner, integer spokeunitID, integer numspokes, integer spokelength, real degreesbetween, real distbetween, real angvelocity returns SimpleWheel local SimpleWheel newwheel = SimpleWheel.allocate() local integer i = 1 local integer j = 1 local real deg local real dist local real x local real y local real r set newwheel.center = centerunit set newwheel.unitID = spokeunitID set newwheel.owner = powner set newwheel.nSpoke = numspokes set newwheel.nSpokeLength = spokelength set newwheel.degBetween = degreesbetween set newwheel.distBetween = distbetween set newwheel.angVelocity = angvelocity loop exitwhen i > newwheel.nSpoke set deg = i*newwheel.degBetween set newwheel.degrees[i] = deg set r = deg * bj_PI / 180 loop exitwhen j > newwheel.nSpokeLength set dist = j*newwheel.distBetween set x = GetUnitX(newwheel.center) + Cos(r) * dist set y = GetUnitY(newwheel.center) + Sin(r) * dist call GroupAddUnit(.wisps, CreateUnit(newwheel.owner, newwheel.unitID, x, y, 0)) set j = j + 1 endloop set j = 1 set i = i + 1 endloop call newwheel.listAdd() call TimerStart(wTimer, wTIMESTEP, true, function thistype.wPeriodic) return newwheel endmethod endstruct endlibrary If you feel this is too inefficient, you could always use a LinkedList instead of a group. |
| 07-05-2011, 10:46 PM | #9 |
very cool, anitarf - i'll try this when i get home tyvm i'm wondering if the count variable you made will collide with the one from ListModule though? personally I think it'd be plenty efficient - but I'll offer several different types to suit whatever the maze maker wants also I have an update on narrowing down the problem with pausing and unpausing wheels on map creation 5 wheels are added to the list (and begin rotating) and all is well if I pause then unpause any of those wheels, the game lags out - however the wheel does rotate (for 2ish very sketchy frames) if I pause all the current wheels in the map, then i can unpause 1 wheel (or sets of wheels) just fine however something weird happened when I was testing this to pause/unpause the wheels I was using these triggers JASS://red has 5 wisp wheels circling him, they are separate but run together function Trig_pause_Actions takes nothing returns nothing call testwheel.wPause() call testwheelattach1.wPause() call testwheelattach2.wPause() call testwheelattach3.wPause() call testwheelattach4.wPause() endfunction //=========================================================================== function InitTrig_pause takes nothing returns nothing set gg_trg_pause = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_pause, Player(0), "-off", true ) call TriggerAddAction( gg_trg_pause, function Trig_pause_Actions ) endfunction JASS:function Trig_unpause_Actions takes nothing returns nothing call testwheel.wUnpause() call testwheelattach1.wUnpause() call testwheelattach2.wUnpause() call testwheelattach3.wUnpause() call testwheelattach4.wUnpause() endfunction //=========================================================================== function InitTrig_unpause takes nothing returns nothing set gg_trg_unpause = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_unpause, Player(0), "-on", true ) call TriggerAddAction( gg_trg_unpause, function Trig_unpause_Actions ) endfunction JASS:function Trig_pause_Actions2 takes nothing returns nothing call testwheel2.wPause() endfunction //=========================================================================== function InitTrig_pause_blue takes nothing returns nothing set gg_trg_pause_blue = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_pause_blue, Player(0), "-off2", true ) call TriggerAddAction( gg_trg_pause_blue, function Trig_pause_Actions2 ) endfunction JASS:function Trig_unpause_Actions2 takes nothing returns nothing call testwheel2.wUnpause() endfunction //=========================================================================== function InitTrig_unpause_blue takes nothing returns nothing set gg_trg_unpause_blue = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_unpause_blue, Player(0), "-on2", true ) call TriggerAddAction( gg_trg_unpause_blue, function Trig_unpause_Actions2 ) endfunction basically red has 5 wisp wheels that all run at once (or not at all) and blue has just the 1. anyways here's the weird thing(s): if I pause both, I can unpause them (even both at the same time), but I can't unpause either if I haven't already paused them both (possibly unrelated) if I pause unpause them enough - the game gets very confused. ie typing -off, will pause the wrong wisp wheel or typing -on will unpause both red and blues wheels (both unpause test triggers) once things start getting entangled, they never get better without a restart anyways, ideas are much appreciated |
| 07-06-2011, 07:27 AM | #10 | |
Quote:
The sudden drop in fps would suggest that a lot more code is suddenly being executed. Two scenarios come to mind: either one of the loops isn't exiting properly or the timer starts expiring way more often. I don't see how the timer could do that, but to rule it out completely change your code so that you start the timer in an onInit method and then don't start/pause it in the create/wUnpause/wPause methods. As for the loops, I found a bug in listModule that would cause it to bug if a null struct instance (0) was accidentally added to the list, however I don't see you doing that anywhere and besides, if anything this bug would cause the loop to exit sooner. Still, you can fix it by changing the if statement in the listAdd method to if inlist or destroying or this==0 then. Other than this, I'm out of ideas since the other loops appear like they should be completely unaffected by pausing/unpausing. Try these changes for now and if the problem persists, we'll try to figure out something else. |
| 07-07-2011, 12:28 AM | #11 | ||
Quote:
JASS:
static method onInit takes nothing returns nothing
call TimerStart(wTimer, wTIMESTEP, true, function SimpleWheel.wPeriodic)
endmethodbut the problem persisted fixing the problem you found in ListModule had no effect either Quote:
and its not like its a temporary lag spike from executing a gigantic function, its permanent (probably) and only gets worse until the game crashes. I went through the ListModule code until I understood the bug you found (and all the rest of it) the only thing I don't understand is why JASS:thistype(0).prev is thistype(n) equal to the nth newest instantiation of a struct? but that wouldn't work either. |
| 07-07-2011, 10:42 PM | #12 | ||
Quote:
Quote:
original (with fixed bugs):module List private static boolean destroying = false private boolean inlist = false readonly static integer count = 0 readonly thistype next = 0 readonly thistype prev = 0 static method operator first takes nothing returns thistype return thistype(0).next endmethod static method operator last takes nothing returns thistype return thistype(0).prev endmethod method listRemove takes nothing returns nothing if not inlist then return endif set inlist = false set prev.next = next set next.prev = prev set count = count - 1 endmethod method listAdd takes nothing returns nothing if inlist or destroying or this==0 then return endif set inlist = true set last.next = this set prev = last set thistype(0).prev = this set next=thistype(0) set count = count + 1 endmethod static method listDestroy takes nothing returns nothing local thistype this = last set destroying = true loop exitwhen this == 0 call destroy() set this = prev endloop set destroying = false endmethod endmodule alternative:module List private static boolean destroying = false private boolean inlist = false readonly static integer count = 0 readonly thistype next = 0 readonly thistype prev = 0 readonly thistype first = 0 readonly thistype last = 0 method listRemove takes nothing returns nothing if not inlist then return endif set inlist = false if prev==0 then set first.next = next else set prev.next = next endif if next==0 then set last.prev = prev else set next.prev = prev endif set count = count - 1 endmethod method listAdd takes nothing returns nothing if inlist or destroying then return endif set inlist = true if last==0 then set first.next = this set prev = thistype(0) else set last.next = this set prev = last endif set last = this set next = thistype(0) set count = count + 1 endmethod static method listDestroy takes nothing returns nothing local thistype this = last set destroying = true loop exitwhen this == 0 call destroy() set this = prev endloop set destroying = false endmethod endmodule |
| 07-07-2011, 11:53 PM | #13 | ||
Quote:
Quote:
seriously i'm considering naming my firstborn anitarf well mb not we'll see how much i like the kid the wisp wheel works like a charm :DDDD |
