| 08-08-2009, 04:17 PM | #1 |
So, you all know 2D3S, a system that will soon allow people to make awesome spells with awesome shapes. The reason why I am posting this thread here is because I made a major modification to one of the modules. In order to keep progress going on, I need to know if this specific module is Ok, so I can replicate the main idea into other modules. What I need to know is, if you think the xefxLineModule is nice, that's all I ask. I also post here 2D3S core and Line shape, you will see how trivial they are: 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 private real pointTang 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 method operator tang takes nothing returns real return .pointTang 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 method operator tang= takes real newTang returns nothing set .pointTang = newTang 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 // // //Methods: // - To use this just have a look on the example trigger. // // method drawXefxLine takes string path, real interval returns nothing // - draws the line using the model path suggested and by creatin 1 effect every //interval seconds. To create an instant line just set the interval lenght to zero. // //method ereaseXefxLine takes nothing returns nothing // - erases the line created by drawXefxLine, by killing all xefx object. If a //line is not completed yet then it will still be immediatly deleted and it will //not reach the final stage of the draw. // //method destroyXefxLine takes boolean eraseLine returns nothing // - if eraseLine == true, then destroy method will erase the Line object //created by drawXefxLine. 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 2.0.0 //=========================================================================== library XefxLineModule requires LineShape, xefx, LinkedList //=========================================================================== //==========================SETUP START====================================== //=========================================================================== globals public real PERIOD = .025 //the period of the timer endglobals //=========================================================================== //=============================SETUP END===================================== //=========================================================================== globals //for the stack ! private timer xefxTimer = null private integer instancesCount = 0 private Line array lines endglobals module XefxLineModule private List effects private real overTimeCount 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 real interval private method updateTimeCounter takes nothing returns nothing local xefx object set .overTimeCount = .overTimeCount + PERIOD if .overTimeCount >= .interval then //draw picture set .overTimeL = .overTimeL.next //we create the xefx object set object = xefx.create(Point(.overTimeL.data).x, Point(.overTimeL.data).y, 0) set object.fxpath = .overTimePath call Link.createLast(.effects, object) //if we are done we get rid of the timer if .overTimeL == .points.last then set .drawDone = true endif set .overTimeCount = 0 endif endmethod private static method periodic takes nothing returns nothing local integer currentIndex = 0 local Line currentLine loop set currentLine = lines[currentIndex] call currentLine.updateTimeCounter() //if our instance is done, we decrement the number of total instances //and then we check if there are any more instances being run if currentLine.drawDone then set instancesCount = instancesCount - 1 //if there are more instances running, then we update our instance to the next of the array //and we correct the index if (instancesCount > 0) then set lines[currentIndex] = lines[instancesCount] set currentIndex = currentIndex - 1 //else we just release the timer else call PauseTimer(xefxTimer) endif endif set currentIndex = currentIndex + 1 exitwhen currentIndex >= instancesCount endloop endmethod method drawXefxLine takes string path, real interval returns nothing local xefx object set .interval = interval set .overTimePath = path set .overTimeCount = 0 set .drawDone = false set .overTimeL = .points.first set .effects = List.create() set object = xefx.create(Point(.overTimeL.data).x, Point(.overTimeL.data).y, 0) set object.fxpath = .overTimePath call Link.createLast(.effects, object) if instancesCount == 0 then //if the number of instances is 0 and xefxTimer == null then we //need to create it because it isthe first time we are using the spell if xefxTimer == null then set xefxTimer = CreateTimer() endif //if instances == 0 but xefxTimer != null means the timer is paused and //we need to start it again! call TimerStart(xefxTimer, PERIOD, true, function Line.periodic) endif set lines[instancesCount] = this set instancesCount = instancesCount + 1 endmethod method eraseXefxLine takes nothing returns nothing local Link link = .effects.first //if we didn't finished the picture yet, we finish it now if not(.drawDone) then set .drawDone = true endif //we need to wait to make the variable true make it's work call TriggerSleepAction(0.) call xefx(link.data).destroy() //we destroy all xefx effects done loop set link = link.next call xefx(link.data).destroy() exitwhen(link == .effects.last) endloop call .effects.destroy() endmethod method destroyXefxLine takes boolean ereaseLine returns nothing if ereaseLine then if .effects == null then debug call BJDebugMsg("destroyXefxLine: There is no drawing to be erased") else call .eraseXefxLine() endif endif call .destroy() endmethod endmodule endlibrary Thx in advance... |
| 08-08-2009, 06:50 PM | #2 |
I'm not quite good in coding, but the upper two seem to work (not really tried) it's very similiar to what I used in my TFormula lib, so it should work the last one I don't understand (need time to read it) haaahaaa you're using a squareRoot, I thought they are bad ![]() too stupid that I'm too stupid to code something like this (but better), too @Scar: won my bet a gramatically correct english sentence with more than 3x "too"! BÄM! |
| 08-08-2009, 07:12 PM | #3 | ||
Everything here works fine Tot. I am only worried about the "cleanness" of the code. Quote:
JASS:local integer size = R2I(dist / (interval ) ) Quote:
I see few people are familiar with module keywword, but it is in fact the easiest thing on earth: http://www.wc3c.net/vexorian/jasshel...al.html#module |
| 08-08-2009, 07:16 PM | #4 |
yay, I've only a probleme with 3d shapes and i wanna make a Tesseract no idea what it is, but I'm sure it's smoething in 3d... but have first to finish the sms |
| 08-09-2009, 01:28 AM | #5 |
The xefx and the lightning modules could easily be the same for all shapes. |
| 08-09-2009, 08:04 AM | #6 | |
Quote:
For a complex shape like an XSpot (per example) I use the xefxLineModule of the oject line. For a simple shape like a line, I have to code it like here. Your approach also occurred me, but I didn't see a way of having them for all shapes. I thought "Maybe if I add a massive if statement like If Shape== Line then draw line else ..."but I saw that as a very ugly idea ... |
| 08-09-2009, 03:32 PM | #7 |
Shapes are just lists of points anyway. You should be able to create an effect for each of those points regardless of how those points are distributed. |
| 08-09-2009, 05:55 PM | #8 |
I know I could make an xefx module for all simple shapes. However, it is not that easy for complex shapes. How can I tell the difference between a 5 point star (made by 5 lines) and a 7 point star? What about a pentagon with a circle? There is no sane way to make a unique xefx module for all complex shapes, since they are made by many simple shapes or even by other complex shapes - I have to make an xefx module for each complex shape. |
| 08-16-2009, 10:28 AM | #9 |
A few days have past and I made more major modifications to xefxLineModule by completely remaking it. I can also attach a test map for those who want. Now xefxmodule is using a stack (I learned it from DarkLightning xD) and it only has 5 mehotds (pretty small). To be honest, I've been thinking on Anitarf's idea of creating one xefxModule for all simple shapes and another xefxModule for complex shapes ... few days ago I was having a walk to clear my mind and it occurred me such a thing may be possible if I use a List to store the shapes a complex shape needs. I have not tested this idea yet, but it is a possibility. I am open to suggestions, if I manage to make the complex list idea real, this may become the module for all simple shapes. PS: I hope this doesn't count as reviving a thread. |
| 08-17-2009, 11:53 AM | #10 |
Bump, I've been thinking, there is no way I can follow ani's suggestion... =S Anyways, 1st post uptaded. |
| 08-17-2009, 12:35 PM | #11 |
How about putting all methods into a single struct? I dunno exactly what you mean by using 1 module. If I understand it right, points are just connected to form shapes, if so just make different methods that connects those points, and put them in one module. |
