| 04-18-2010, 05:38 PM | #1 |
Discussion for the library I'm working on. Pretty much, it's an API, for shapes. It allows you to make lines and circles, and destroy them, easily, and configure how many specialeffects you want to use, the model, and all that, pretty easily to boot. The best use is to make pretty flashy spell effects very quickly. Eventually, I`ll add the option to make hypocycloids with a maximum of five cups each. Here's the library. JASS:////////////////////////////////////////////////// // CONFIGURABLES ////////////////////////////////////////////////////// globals private constant integer Max_Global_Effects=2000 //This controls how much the main //effect array can hold. Can not be //less than Max_Array_Size. private constant integer Max_Circle_Effects=2000 //The maximum amount of effects that //can be used to make circles. private constant integer Max_Line_Effects=2000 //The maximum amount of effects that //can be used to make lines. endglobals ////////////////////////////////////////////////// // START OF SHAPE-API ////////////////////////////////////////////////////// struct Shape integer tick effect array effects [Max_Global_Effects] integer effectc =0 effect array allCirc [Max_Circle_Effects] integer circlec =0 effect array allLine [Max_Line_Effects] integer linec =0 method addCircle takes real cx,real cy,string m,real dia,integer ec returns nothing local real a=360.00/ec local real x local real y set this.tick=1 loop set x=cx+dia*Cos(this.tick*a*bj_DEGTORAD) // Calculating the x,y set y=cy+dia*Sin(this.tick*a*bj_DEGTORAD) // for the curve. set this.effects[this.effectc]=AddSpecialEffect(m,x,y) // Adding the effect. set this.allCirc[this.circlec]=this.effects[this.effectc] // Add effect to circle effect array. set this.effectc=this.effectc+1 set this.circlec=this.circlec+1 exitwhen this.tick==ec // Exit when the circle is complete. set this.tick=this.tick+1 endloop set this.tick=0 set a=0.00 set x=0.00 set y=0.00 endmethod method addLine takes real sx,real sy,real ex,real ey,string m,integer ec returns nothing local real x local real y local real a=bj_RADTODEG*Atan2(ey-sy,ex-sx) local real d=DistanceBetweenPoints(Location(sx,sy),Location(ex,ey)) local real i=d/ec // Distance divided by Effect Count loop set x=sx+(i*this.tick)*Cos(a*bj_DEGTORAD) set y=sy+(i*this.tick)*Sin(a*bj_DEGTORAD) set this.effects[this.effectc]=AddSpecialEffect(m,x,y) set this.allLine[this.linec]=this.effects[this.effectc] set this.effectc=this.effectc+1 set this.linec=this.linec+1 exitwhen this.tick==ec set this.tick=this.tick+1 endloop set this.tick=0 endmethod method destroyCirc takes nothing returns nothing local integer x=0 loop call DestroyEffect(this.allCirc[x]) exitwhen x==this.circlec set x=x+1 endloop set this.circlec=0 endmethod method destroyLine takes nothing returns nothing local integer x loop call DestroyEffect(this.allLine[x]) exitwhen x==this.linec set x=x+1 endloop set this.linec=0 endmethod method destroyAll takes nothing returns nothing local integer x=0 loop call DestroyEffect(this.effects[x]) set x=x+1 exitwhen x==this.effectc endloop set this.effectc=0 endmethod endstruct ////////////////////////////////////////////////// // END OF SHAPE-API ////////////////////////////////////////////////////// endlibrary And here's the example code. JASS:
private function actions takes nothing returns nothing
local real x=0.00
local real y=0.00
local Shape shape=Shape.create()
call shape.addCircle(x,y,"Abilities\\Spells\\Human\\Resurrect\\ResurrectCaster.mdl",400,6) // Angels
call TriggerSleepAction(.5)
call shape.addCircle(x,y,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",450,30) // +
call shape.addLine(x,y,400,0.00,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,-400,0.00,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,0.00,400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,0.00,-400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call TriggerSleepAction(.5)
call shape.addLine(x,y,-400,-400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5) // X
call shape.addLine(x,y,400,400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,-400,400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,400,-400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call TriggerSleepAction(.5)
call shape.addCircle(x,y,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",450,30) // +
call shape.addLine(x,y,400,0.00,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,-400,0.00,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,0.00,400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.addLine(x,y,0.00,-400,"Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl",5)
call shape.destroyAll()
endfunction
Anyone have comments to improve the code, or have features I should implement? |
| 04-18-2010, 08:40 PM | #2 |
first of all, you should use xefx for your effects, to make them more useable i'd also replace your shape struct with: JASS:private struct shapeElement thistype next thistype prev shape parent endstruct private struct circle extends shapeElement //circle stuff here endstruct privatestruct line //line stuff here endstruct private struct rectangle extends shapeElement private line array[4] //simply for lines endstruct //... struct shape shapeElement first method addShapeElement takes shapeElement e returns nothing if e!=0 then if .first==0 then set .first=e set e.next=0 set e.prev=0 else set .first.prev=e set e.next=.first set .first=e set e.prev=0 endif set e.parent=this endmethod method removeShapeElement takes shapeElement e returns shapeElement if e.parent!=this then debug call BJDebugMsg(SCOPE_PREFIX+"you cant remove shapelements from shapes that don't contain these") return 0 endif if .first==e then set .frist=.first.next set .first.prev=0 else set e.prev.next=e.next set e.next.prev=e.prev endif return e endmethod method onDestroy takes nothing returns nothing local shapeElement e=.first local shapeElement t=0 loop exitwhen e==0 set t=e.next call e.destroy() set e=t endloop endmethod endstruct |
| 04-18-2010, 10:25 PM | #3 |
I may use xefx, but I'm hesitant, because I hate using additional libraries. Second, I thought about using all different structs, but decided not to.
|
| 04-19-2010, 06:28 AM | #4 |
The wc3c modding community kinda builds on using standardized libraries. You don't have to reinvent the wheel once again. |
