| 07-27-2009, 02:59 PM | #1 |
Ok guys, because 3 major remakes are never enough, here is new version. Fortunately for me, this remake wasn't as bad as I was thinking. The core and LineShape are quite simple. I assume I fixed the serious bug Pyrogasm reported (yes, Anitarf, Pyro was the first guy, you lost the race =P )... and Anitarf also reported it yes ... So now I am concerned about LineXefx module. I fear it may be messy, don't know. SimpleShapes (core): JASS://=========================================================================== //Description: // - A system that allows the user to create many shapes in a very simple and //customizable way. This is simply the core of the system. To draw more shapes //you will have to import libraries. // //Author: // - Flame_Phoenix // //Credits: // - ThredNThrash, for the main idea and math formulas // - BubleTech, for efficiency advices // - Pyro and Anitarf for suggestions on how to improve // - Veev, for fixing grammar // //@version 1.1.3 //=========================================================================== library SimpleShapes requires LinkedList struct Point private real pointx private real pointy static method create takes real newX, real newY returns Point local Point this = Point.allocate() //setting members set .pointx = newX set.pointy = newY return this endmethod //Getters method operator x takes nothing returns real return .pointx endmethod method operator y takes nothing returns real return .pointy endmethod //Setters method operator x= takes real newX returns nothing set .pointx = newX endmethod method operator y= takes real newY returns nothing set .pointy = newY endmethod endstruct struct Shape List points static method create takes nothing returns Shape local Shape this = Shape.allocate() //create our list set .points = List.create() return this endmethod method onDestroy takes nothing returns nothing call .points.destroy() endmethod endstruct endlibrary LineShape JASS://=========================================================================== //Description: // - This library allows you to have an object called Line. It has two optional //modules you can import to have extra features: xefxLineModule and //lightningLineModule. // //Requires: // - SimpleShapes // //Methods you can use: // static method createLine takes real sX, real sY, real eX, real eY, real interval //returns Line // - sX and sY and startX and startY where the Line begins. eX and eY stand for endX //and endY respectively. The interval is the space between points. // //Members you can use: // real ANGLE - imagine that you want to move an object accross a line. This is the angle //the object needs to have and it is in radians. To get the inverse of an angle just do //ANGLE + bj_PI. // //Author: // - Flame_Phoenix // //Credits: // - Chobibo, for reporting major problems // //@version 1.2.1 //=========================================================================== library LineShape requires SimpleShapes struct Line extends Shape private real LINE_ANGLE // the tangent line in rads, useful to move projectiles implement optional XefxLineModule implement optional LightningLineModule static method createLine takes real sX, real sY, real eX, real eY, real interval returns Line local Line this = Line.allocate() //the distance of the line local real dx = sX - eX local real dy = sY - eY local real dist = SquareRoot(dx*dx + dy*dy) //temporary variables that will allow us to create many points local integer i = 0 //this is to make code easier to read in the loop local real x local real y //this variables are for efficiency reasons local real xAng local real yAng local integer size = R2I(dist / (interval ) ) //setting our members set .LINE_ANGLE = Atan2(eY - sY, eX - sX) set xAng = Cos(.LINE_ANGLE) set yAng = Sin(.LINE_ANGLE) loop exitwhen(i == size) //polar projection stuff set x = sX + ((i * dist) / size) * xAng set y = sY + ((i * dist) / size) * yAng call Link.createLast(.points, Point.create(x, y)) set i = i + 1 endloop return this endmethod //getter method operator ANGLE takes nothing returns real return .LINE_ANGLE endmethod endstruct endlibrary XefxLineModule JASS://=========================================================================== //Description: // - This optional module allows you to draw lines using xefx. // //Requires: // - LineShape // - xefx // - TimerUtils // // //Methods: // - To use this just have a look on the example trigger. // // method drawXefxLine takes string path returns nothing // - draws the line using the model path suggested. This line is created using //xefx objects and it is instant. // //method drawXefxLineOverTime takes string path, real interval returns nothing // - same as drawXefxLine, however it takes a time interval that is the wait between //creating points. // //method ereaseXefxLine takes nothing returns nothing // - erases the line created by drawXefxLine or be drawXefxLineOverTime, by //killing all xefx object. If a line is not completed yet (because you are //using drawXefxLineOverTime) then it does NOT DELETE the objects but displays //an error message instead. // //method destroyXefxLine takes boolean eraseLine returns nothing // - if eraseLine == true, then destroy method will erase the Line object //created by drawXefxLine or drawXefxLineOverTiem. If eraseLine == false, //then it simply destroys the line object but it lets the drawing live. // //Author: // - Flame_Phoenix // //Credits: // - Vexorian, for xefx // - Veev, for fixing grammar // - Chobibo, for reporting major problems // //@version 1.0.0 //=========================================================================== library XefxLineModule requires LineShape, xefx, TimerUtils module XefxLineModule private xefx array effects[2000] private integer overTimeCounter private Link overTimeL private string overTimePath private boolean drawDone //when we want to erase a line, we must be sure it is completed. This flag tells us that! private static method drawOverTimeLoop takes nothing returns nothing //we get the structure from the timer local Line this = Line(GetTimerData(GetExpiredTimer())) //we create the xefx object set .effects[.overTimeCounter] = xefx.create(Point(.overTimeL.data).x, Point(.overTimeL.data).y, 0) set .effects[.overTimeCounter].fxpath = .overTimePath set .overTimeL = .overTimeL.next set .overTimeCounter = .overTimeCounter + 1 //if we are done we get rid of the timer if .overTimeCounter == .points.size then set .drawDone = true call ReleaseTimer(GetExpiredTimer()) endif endmethod method drawXefxLineOverTime takes string path, real interval returns nothing local timer xefxTimer = NewTimer() set .drawDone = false set .overTimePath = path set .overTimeCounter = 0 set .overTimeL = .points.first call SetTimerData(xefxTimer, integer(this)) call TimerStart(xefxTimer, interval, true, function Line.drawOverTimeLoop) endmethod method drawXefxLine takes string path returns nothing //now we create 1 unit per each point local Link L = .points.first local Point point local integer i = 0 loop exitwhen(i == .points.size) set point = L.data set .effects[i] = xefx.create(point.x, point.y, 0) set .effects[i].fxpath = path set L = L.next set i = i + 1 endloop set .drawDone = true endmethod method eraseXefxLine takes nothing returns nothing local integer i if .drawDone then set i = 0 loop exitwhen(i == .points.size) call .effects[i].destroy() set i = i + 1 endloop else debug call BJDebugMsg("eraseXefxLine: draw is not complete and so it can not be erased!") endif endmethod method destroyXefxLine takes boolean ereaseLine returns nothing if ereaseLine then if .effects[0] == null then debug call BJDebugMsg("destroyXefxLine: There is no drawing to be erased") else call .eraseXefxLine() endif endif call .destroy() endmethod endmodule endlibrary |
| 07-27-2009, 03:05 PM | #2 |
Please make something like this. I haven't read the code yet, later I will. |
| 07-27-2009, 07:04 PM | #3 |
JASS:public constant integer MAX_SIZE = 1000 real array COORD_X[MAX_SIZE] real array COORD_Y[MAX_SIZE] That sort of limitation is unacceptable in this sort of system. |
| 07-27-2009, 07:14 PM | #4 |
What do I do if I want to draw ten lines? Edit: dammit Pyro! :) |
| 07-27-2009, 07:17 PM | #5 |
Procrastination claims yet another potentially useful post... |
| 07-28-2009, 09:07 AM | #6 |
@Chobibo: I am sorry but I can not add spirals right now. I have established a set of priorities. I order to get the system approved I need more shapes, therefore I will invest time in making new shapes using the ones I already have such as BullzEye and TargetX and Wheel. After that I will try adding CosLine and SinLine for my spell in contest 15 (if I have time). However After that I guarantee you that Siprals will be top priority, with more priority than Starts, Polygons and rotates methods. Ahh, you are talking about the MAX_SIZE variable correct ? Well, if I am not mistaken, that is in the SETUP part of the core. If the user needs more he/she can always pick a lower number. I just decided that for a sample map, this wouldn't be important. Is this the answer to your question ? |
| 07-28-2009, 09:25 AM | #7 |
It's still a limitation that could get very nasty. Think about it; say you make a more complex shape that requires two x-spots. Even if MAX_SIZE was decreased to 500 (half of its current size), the maximum number of instances is then still only 8! Hell, even make MAX_SIZE 360 (to have 1 effect ever 1 degree in a circle, and your instance cap is still 22. So a unit has a spell that creates a circle effect on the ground that lasts for a short amount of time; what if you have lots of units casting that spell? That's still only 22 instances. Total. What if you want to use two circles in creating a spell? Then you're down to 11 instances. That is a severe limitation inherent in your system. |
| 07-28-2009, 09:41 AM | #8 |
JASS:( 360.00 / (radius / interval)) * bj_DEGTORAD |
| 07-28-2009, 12:36 PM | #9 |
Pyro, I don't get your point. Sure it is a limitation, but all other similar systems I recall have arrays. I even saw IronDoors systems (you suggested me to follow it) and it uses arrays like I do. What do you suggest? That I use a LinkedList to save Reals !? That will be extremely slow compared to this solution. The reason why I do it this way is because I don't know any other sane way. If you do know another (better) way that doesn't sacrifice speed in an insane manner, please indicate it to me... I guess I will have to make version 4.0 after all. And what do you think about the demo map ? xD Tyrande: I don't get your tip .. what Shape is it for and what is it about? |
| 07-28-2009, 01:02 PM | #10 |
I don't like the system, the array idea inside a struct limits you totally. I'd suggest to do this: JASS:struct point // defines a point in the shape real x real y // add your methods for the points, like show effects endstruct struct connector // allows to connect 2 points point start point end static method create takes point A, point B returns thistype endmethod endstruct struct line // the methods to gather several connectors and form a line endstruct struct circle // the methods to gather several connectors and form a circle endstruct Just a suggestion. |
| 07-28-2009, 01:43 PM | #11 |
My original idea was to have a struct Point, like you have Moyack. Then Shape would be able to save MAX_SIZE Point objects. However this solution turned out to be very inefficient and so I changed to parallel arrays. I don't get your idea of a "connector"... The idea why I am using SHape as a core is because it sounds natural to me ... Besides, I don't think your suggestion would be faster than my previous approach ... Thx for the suggestions Moyack, but I simply don't like it that much either (lol). Anyway ... looks like every time I advance 1 step, I have to take 2 steps back ... arrghhh.. |
| 07-28-2009, 02:12 PM | #12 |
I actually much prefer moyack's approach to this. |
| 07-28-2009, 02:38 PM | #13 | ||
Quote:
Quote:
|
| 07-28-2009, 03:09 PM | #14 | ||
Quote:
Quote:
So ... the reason I don't like Moyacks way is because I don't understand it much, it doesn't seem natural nor trivial to me =( I mean, accordingly to what I understood, he wants me to make a pseudo-linkedlist and that's the only thing I get .. what about Shape, what about everything else? How am I supposed to use a connection and what about the speed ? I see speed is not that crucial here ... I really feel like using two parallel linked lists to store X and Y ... anyone is with me? This is ironic having in mind it was one of the first approaches I took to make the system and it got quite rejected by Pyro ... I never though I would go back to this point. Anyway, I guess times changes and so do rules. |
| 07-28-2009, 03:34 PM | #15 | ||||
Quote:
Quote:
Quote:
Quote:
|
