• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Parabolic (or quadradic) fall of objects in Warcraft

Status
Not open for further replies.
Hiiii, guys, well, I have a real question for you (a real problem you might say).
As some of you already know I am creating a spell pack of bombardments ... A plane comes from the skies and drops some bombs upon your dam enemies!

However, Some people say my bombs are slow (ARGGH GW !!!!!) and some suggested me to add a quadratic effect to the fall of the bombs ... but I don't know how to do it !!!

I will post my plane's code here. If you guys also have any ideas about how to optimize it I would like to hear them as well. This trigger is the hear of the spell pack.

Please, help me make my bombs fall in a better way !!!

[jass=Plane Trigger]
function Trig_InBomber_Actions takes nothing returns nothing
local unit caster = GetTriggerUnit()
local location loc = GetSpellTargetLoc()
local location lc = GetUnitLoc(caster)
local real angle = (180.0 / 3.14159) * Atan2(GetLocationY(loc) - GetLocationY(lc), GetLocationX(loc) - GetLocationX(lc))
local real X = GetLocationX(loc)
local real Y = GetLocationY(loc)
local player p = GetOwningPlayer(caster)
local unit bomb
local integer fade = 0
local real height
local integer bombcounter = 0
local real heightbomb

local unit bomber = CreateUnit(p, 'h002', X - 1400 * Cos(angle * (3.14159 / 180.0)), Y - 1400 * Sin(angle * (3.14159 / 180.0)), angle)

call SetUnitVertexColor(bomber, 255, 255, 255, fade)
set height = GetUnitFlyHeight(bomber)

call IssuePointOrder( bomber, "move", X + 200 * Cos(angle * (3.14159 / 180.0)), Y + 200 * Sin(angle * (3.14159 / 180.0)))

loop
exitwhen(fade >= 255)
call TriggerSleepAction(0.1)
call IssuePointOrder( bomber, "move", X + 200 * Cos(angle * (3.14159 / 180.0)), Y + 200 * Sin(angle * (3.14159 / 180.0)))
set fade = fade + 30
call SetUnitVertexColor(bomber, 255, 255, 255, fade)
endloop

loop
exitwhen(height <= 450)
set height = height - 50
call SetUnitFlyHeight(bomber, height, 80)
call TriggerSleepAction(0.3)
call IssuePointOrder( bomber, "move", X + 200 * Cos(angle * (3.14159 / 180.0)), Y + 200 * Sin(angle * (3.14159 / 180.0)))
endloop

call TriggerSleepAction(0.6)
call IssuePointOrder( bomber, "move", X + 200 * Cos(angle * (3.14159 / 180.0)), Y + 200 * Sin(angle * (3.14159 / 180.0)))
loop
exitwhen(bombcounter == 5)
call IssuePointOrder( bomber, "move", X + 700 * Cos(angle * (3.14159 / 180.0)), Y + 700 * Sin(angle * (3.14159 / 180.0)))
set bomb = CreateUnit(p, 'h003', GetUnitX(bomber), GetUnitY(bomber), 270.0)
call SetUnitFlyHeight(bomb, height, 0)
set heightbomb = height
call UnitApplyTimedLife( bomb,'BHwe', 3)
loop
exitwhen(heightbomb <= 0)
set heightbomb = heightbomb - 100
call SetUnitFlyHeight(bomb, heightbomb, 140)
endloop
set bombcounter = bombcounter + 1
call TriggerSleepAction(0.25)
endloop

call IssuePointOrder( bomber, "move", X + 2000 * Cos(angle * (3.14159 / 180.0)), Y + 2000 * Sin(angle * (3.14159 / 180.0)))
call TriggerSleepAction(0.2)

loop
exitwhen(height >= 600)
set height = height + 50
call SetUnitFlyHeight(bomber, height, 100)
call TriggerSleepAction(0.2)
endloop

loop
exitwhen(fade <= 0)
call TriggerSleepAction(0.1)

set fade = fade - 30
call SetUnitVertexColor(bomber, 255, 255, 255, fade)
endloop

call ShowUnit(bomber, false)
call KillUnit(bomber)
call RemoveLocation(loc)
call RemoveLocation(lc)

set lc = null
set loc = null
set bomber = null
set bomb = null
set caster = null
set p = null
endfunction[/code]

This code is very simple !!! If you guys don't understand it please say something about it !

HEELPPPP (plz, rep+ will be awarded as well as credits in the spell pack).
For more information please download the spell pack Bombardment Spells. This is the most recent version of the spell pack.

PS - i only need help on the Bomber trigger. I am currently optimizing the other triggers, but I don't need help on them for now =P
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
Oh god...

Waits are totally inaccurate. Use a 0.03 or something repeating timer, and carry across vertical speed, decrementing it by a certain amount each time.

Have a go at that, then you'll be a better JASSer. Come back if you get stuck with your attempt at it. You'll need some way of attaching stuff to timers; I'd suggest gamecache to attach a struct (get the NewGen pack from wc3c).
 
Captain Griffen, I am aware of the power of JNGP and timers. HOwever, Waits are not that inaccurate. The are faster, more efficient, and mainly, they are way easier to understand.

What makes this into a challenge is not being able to use JNGP. I want this to be used for all people, and vJass reduces the list of people who can use it (in theory, to achieve total compability, this should be made in GUI, but that would be a bad idea, so JASS is naturally as follows).

Using Katana's Handle system would also not be such a great idea - "Everything you do with that system, can be made without it" as PurplePoot said.

So, this difficults our job greatly - I don't mind using timers, as long as they are efficient (which they are not).

Still, this is not a discussion about Timers vs Sleeps. Therefore, I ask for more suggestions / opinions.

Btw, are you crazy !? Using timers every 3 lines of code would be huge nightmare, for me, and for people to understand....

Still, please, HELP me to add a quadratic formulae !! =S
 
You can practically make a function that takes your unit and runs a loop, it will be shitty though.
Lets see you make a good smooth fall with ~0.27 seconds delay between each move (Hint: you can't :<).

So you guys are saying it is impossible to give a quadratic effect to the fall !? =S

JASS:
 loop
        exitwhen(bombcounter == 5)
        call IssuePointOrder( bomber, "move", X + 700 * Cos(angle * (3.14159 / 180.0)), Y + 700 * Sin(angle * (3.14159 / 180.0)))
        set bomb = CreateUnit(p, 'h003', GetUnitX(bomber), GetUnitY(bomber), 270.0)
        call SetUnitFlyHeight(bomb, height, 0)
        set heightbomb = height
        call UnitApplyTimedLife( bomb,'BHwe', 3)
        loop
            exitwhen(heightbomb <= 0)
            set heightbomb = heightbomb - 100
            call SetUnitFlyHeight(bomb, heightbomb, 140)
        endloop
        set bombcounter = bombcounter + 1
        call TriggerSleepAction(0.25)
    endloop

This nested loops create and make the bombs fall .... is it possible to change in order to make the bombs fall in a quadratic from ? I know it must be possible, i just don't know how =S
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
Captain Griffen, I am aware of the power of JNGP and timers. HOwever, Waits are not that inaccurate. The are faster, more efficient, and mainly, they are way easier to understand.

What makes this into a challenge is not being able to use JNGP. I want this to be used for all people, and vJass reduces the list of people who can use it (in theory, to achieve total compability, this should be made in GUI, but that would be a bad idea, so JASS is naturally as follows).

Using Katana's Handle system would also not be such a great idea - "Everything you do with that system, can be made without it" as PurplePoot said.

So, this difficults our job greatly - I don't mind using timers, as long as they are efficient (which they are not).

Still, this is not a discussion about Timers vs Sleeps. Therefore, I ask for more suggestions / opinions.

Btw, are you crazy !? Using timers every 3 lines of code would be huge nightmare, for me, and for people to understand....

Still, please, HELP me to add a quadratic formulae !! =S

You're screwed. Or, more accurately, you've screwed yourself.

Okay, another way you can actually do this - TimerAttach (unless you don't want to use that...) and parallel arrays using globals.

Seriously, you have to use timers for smooth movement.

And I wasn't refering to KaTaNa's system - I always did direct GC usage (ie: no system, but direct implementation). If you refuse to even do that, refuse to use structs, and refuse to use parallel arrays (as per my previous suggestion), you may as well give up.
 
Okay, another way you can actually do this - TimerAttach (unless you don't want to use that...) and parallel arrays using globals.

Instead of using a shitee parabola function, just add gravitational acceleration to velocity each timeframe, and add velocity to position each time frame. Should produce the required parabolic effect.

Ok, now we have two suggestion I am seriously considering ... They will both turn this trigger into a nightmare (do we wanted or not). So which do you guys think is easier to implement ???

Btw, I may do a vJAss version to submit to wc3Campaigns ... maybe you guys can find this spell pack less basic ...

Still for now, which do you advice ?
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Looks, it's simple:

JASS:
// Where zAcceleration is the constant of gravitational acceleration.
set zVelocity = zVelocity + zAcceleration
set xPosition = xPosition + xVelocity
set yPosition = yPosition + yVelocity
set zPosition = zPosition + zVelocity
// Render the object here.
 
Level 5
Joined
Oct 27, 2007
Messages
158
Your bombs are slow because you are ignoring physics and are using triggered waits where you shouldn't. With timers you have the benefit of smaller intervals and because of that smoother movement. Your bombs don't accelerate when they drop. And I think that's what people are trying to tell you when they say quadratic fall. Furthermore objects falling from a moving object also have a horizontal speed vector. If you want realistic acting bombs then you need to take that into account as well.

for falling object with starting vertical velocity 0 and horizontal velocity x
v(t)ver = g * t
s(t)ver= g/2 * t^2
v(t)hor = x (ignoring friction)
s(t)hor = x * t (no horizontal acceleration)
g = 9,8 m/s^2

So your bomb has to accelerate during fall and drop z distance and move further x distance until it hits the ground. With this information you should be able to create fast and realistic dropping bombs.
 
Level 11
Joined
Feb 18, 2004
Messages
394
Captain Griffen, I am aware of the power of JNGP and timers. HOwever, Waits are not that inaccurate. The are faster, more efficient, and mainly, they are way easier to understand.

No. You fail at knowing anything about programming in JASS. Timers are the only sane, efficient, accurate, and powerful way of doing time-based code. TSA() is not faster, it is not more accurate, and it is more error-prone.

The number of solutions you can use to pass data back to a timers callback are nigh innumerable, and with vJASS you can package all of that in to something simple like TimedEvent

What makes this into a challenge is not being able to use JNGP. I want this to be used for all people, and vJass reduces the list of people who can use it (in theory, to achieve total compability, this should be made in GUI, but that would be a bad idea, so JASS is naturally as follows).

Again, no, you fail. Not using vJASS because you want something to be accessible is just stupid. The only people who do not have the option of vJASS are mac users. And no one cares about mac users. NewGen is already becoming a standard for anyone who wants to use JASS; and considering the power it adds to the language, its also pushing the limits of what we can do with JASS. If you want to throw that away for some dillusion of accessibility, then you fail.

Also, the GUI is not more compatible / accessible. Really, that just weakens any argument you could have.

Using Katana's Handle system would also not be such a great idea - "Everything you do with that system, can be made without it" as PurplePoot said.
Anything you can make with that system can easily be made without it. Using vJASS. Using normal JASS, you're fucked to unreadably complex code that will in some way end up using shitloads of udg_ variables or the gamecache.

So, this difficults our job greatly - I don't mind using timers, as long as they are efficient (which they are not).

Wrong.

Still, this is not a discussion about Timers vs Sleeps. Therefore, I ask for more suggestions / opinions.

We made it such a discussion because you are wrong, and you will be unable to achieve what you want using thread sleeps. Period.

Btw, are you crazy !? Using timers every 3 lines of code would be huge nightmare, for me, and for people to understand....

You don't need to use timers every 3 lines of code. You just need to know how to design a system around a single, very fast periodic timer. Or you could use something like TimedEvent, which makes things streamlined and readable.
 
Level 6
Joined
Jun 30, 2006
Messages
230
Flame, buddy, how many times do I need to tell you that you need to quit using waits? Timers for the win! I can help you on MSN with this code, mate. If you see me, ask, it is no big deal.
 
No. You fail at knowing anything about programming in JASS. Timers are the only sane, efficient, accurate, and powerful way of doing time-based code. TSA() is not faster, it is not more accurate, and it is more error-prone.

Before saying other people are a failure, have a good look on yourself. To quote you: "Everyone that stays in THW as long as I did, will become an idiot like me".
Sorry to disappoint you, but the only idiot here is you - you even admit that yourself.
I made this post in order to accept help from people who have more experience and knowledge with JASS than I have, not to accept humiliation.

Still I appreciate your effort in the link - which by, I can't access.

However, it looks you have great experience with timers. Then please explain me this, because I don't understand it quite well:
- How is it possible for 1 line of code to be slower and less efficient than 4, 5 or even 6 lines of code, when the first one isn't even a BJ ?

Flame, buddy, how many times do I need to tell you that you need to quit using waits? Timers for the win! I can help you on MSN with this code, mate. If you see me, ask, it is no big deal.

Yes, I am aware of the dangers of the Sleeps. And to quote you "vJass is a plague, you can't run from it, it is everywhere". I must give you reasoning on that.

Just use freaking vJass and read the "How to make a good knock back" tutorial (or what ever was the name), using one timer is full of win.

Are you talking about the custom KnockBack function Silvrnoon made ?? Well, I think I found a better one made by Rising_Dusk. I didn't have time to evaluate it yet, but if you guys want, here is the map for you all to see.

In conclusion, I shall use Timers and vJass now - it seems I have no other decent choice after all ...

Finally:
for falling object with starting vertical velocity 0 and horizontal velocity x
v(t)ver = g * t
s(t)ver= g/2 * t^2
v(t)hor = x (ignoring friction)
s(t)hor = x * t (no horizontal acceleration)
g = 9,8 m/s^2

I am not very familiar with such subject. Although I know some basics of it, I am still probably not mature enough to apply it to timers and such. I would appreciate if you could explain this better.

Btw, for all those you may want to see, the spell map I am trying to improve is in my signature, and it is called Bombardment. You guys can have a look to better understand the problem.

I also intent to make this trigger work for all cases. Much like a template, you may say so.
You pass the important stuff by an argument and the the function makes the magic.
 

Attachments

  • Knockback_v1.02.w3x
    52 KB · Views: 58
Level 5
Joined
Oct 27, 2007
Messages
158
Before saying other people are a failure, have a good look on yourself. To quote you: "Everyone that stays in THW as long as I did, will become an idiot like me".
Sorry to disappoint you, but the only idiot here is you - you even admit that yourself.
I made this post in order to accept help from people who have more experience and knowledge with JASS than I have, not to accept humiliation.

Still I appreciate your effort in the link - which by, I can't access.

However, it looks you have great experience with timers. Then please explain me this, because I don't understand it quite well:
- How is it possible for 1 line of code to be slower and less efficient than 4, 5 or even 6 lines of code, when the first one isn't even a BJ ?

Flame_Phoenix, there's no point in arguing like this. Granted it could've been more constructive criticism but unfortunately it wasn't. You can expect this to happen when people have already given you the advice to use timers numerous times. I do think you could've at least tried to implement it once to actually see how it works compared to triggered waits.

When you use triggered waits you are likely to waste CPU cycles that could be used to make your spell effect go more smoothly and faster. In this case your bombs are not going fast because of the triggered waits instead of shorter timer intervals. It doesn't necessarily mean that the code is faster, but the spell effect will run faster.


Finally:


I am not very familiar with such subject. Although I know some basics of it, I am still probably not mature enough to apply it to timers and such. I would appreciate if you could explain this better.
You know in what vector your plane is moving if you know the angle at which its created. According to the direction of that vector (which quadrant) you adjust the x and y periodically. You know the location on that vector where the bomb is released. On that vector your bomb moves forward and drops at the same time. Within a timer callback function you calculate the distance it has traversed forward on the vector, and also the distance it has dropped in that vector.

The functions you can use to:

1. Calculate the new dropping speed and with that the dropped distance.
2. Calculate the traversed horizontal distance.

You can scale distance, speed and time to your liking. With this your bomb will move steadily forward while dropping faster as time passes.

So with time your x and y coordinates will increase in a linear fashion while the bomb descent distance in z direction will be the result of a quadratic function.

z(t) = g/2 * t * t

g is gravitational acceleration and is a constant.
g = 9,8 yards/meters (whatever) per second per second.
t = time passed.
z = the distance the bomb has traversed in z direction.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
You can just break it into x,y distances and z distance.
For example, every time the bomb moves it will move by a constant number towards x,y, and the z will simply decrease by the acceleration, which in this case is only the gravity.

So, it simply becomes:
x = x + number * Cos(angle * bj_DEGTORAD) y = y + number * Sin(angle * bj_DEGTORAD) z = z - g
 
Level 11
Joined
Feb 18, 2004
Messages
394
Before saying other people are a failure, have a good look on yourself. To quote you: "Everyone that stays in THW as long as I did, will become an idiot like me".
Sorry to disappoint you, but the only idiot here is you - you even admit that yourself.

An out of context quote which is only close to anything I ever remember saying? lol

I made this post in order to accept help from people who have more experience and knowledge with JASS than I have, not to accept humiliation.

You claim to accept help, yet when people tell you that you are essentially doing it wrong and very stupidly, you ignore it. You also ignore it when people tell you you'll be unable to do what you want with the method you have chosen. You then also claim you didn't post to accept humiliation, but it's your own stupid comments which humiliate you. An example:
Flame_Phoenix said:
Btw, are you crazy !? Using timers every 3 lines of code would be huge nightmare, for me, and for people to understand....


Still I appreciate your effort in the link - which by, I can't access.
Sorry, i forgot vex fails at coding a good pastebin (Links to individual posts don't work...)
http://wc3campaigns.net/pastebint.php?t=93235&code=29e26baa170b05af2d3ffd04408ae7e1

However, it looks you have great experience with timers. Then please explain me this, because I don't understand it quite well:
- How is it possible for 1 line of code to be slower and less efficient than 4, 5 or even 6 lines of code, when the first one isn't even a BJ ?

  1. BJ functions are only truly slow and cause actual issue when you're runnning code on a very fast repeating loop. The cost of a function call in JASS is high, yet not that damn high. Speed isn't the reason its suggested that you avoid them. (Or, at least, it shouldn't be.)
  2. Coding is not just about absolute efficiency. It is also about maintainability and accuracy.
  3. TSA() is a thread sleep. Such a thing is not truly designed to work the way the GUI (and you) are using it.

Sidenote: Why do we not use BJ functions?
  • Most BJ functions use locations, which are really not needed.
  • Most BJ functions are very bad abstractions of the native API. Using the native API directly usually allows better structured code, alongside many other benefits.
  • Some/Most BJ functions are poorly coded, and show a lack of knowledge of the JASS language on the part of the people who coded it.
  • Some BJ functions are just completely useless.

In conclusion, I shall use Timers and vJass now - it seems I have no other decent choice after all ...

Pretty much.


As for vectors, http://chortle.ccsu.edu/VectorLessons/vectorIndex.html may be of some help.
 
You can expect this to happen when people have already given you the advice to use timers numerous times. I do think you could've at least tried to implement it once to actually see how it works compared to triggered waits.

I've already tried to apply timers a few times. Blue_jeans can approve that. He has been helping and teaching me stuff about them and I usually ask for his help when I use them.

You don't have the knowledge to say "I never used timers before" just because you never saw me doing it, it is an invalid logic consequence.

You claim to accept help, yet when people tell you that you are essentially doing it wrong and very stupidly, you ignore it. You also ignore it when people tell you you'll be unable to do what you want with the method you have chosen. You then also claim you didn't post to accept humiliation, but it's your own stupid comments which humiliate you.

1st - If I ignore help, then please explain me why I decided to implement JNGP as along with timers as you guys suggested.

2nd - If I knew how to use timers efficiently and correctly, I wouldn't be creating this post ... makes sense rit ?

When you use triggered waits you are likely to waste CPU cycles that could be used to make your spell effect go more smoothly and faster. In this case your bombs are not going fast because of the triggered waits instead of shorter timer intervals. It doesn't necessarily mean that the code is faster, but the spell effect will run faster.

I understand what you mean, but still, Sleeps are faster than timer rit ? I know they make my spell tun slower, but in efficiency terms, a code with sleep will be faster than a code with timers rit ?

About the Bj's I actually already knew that. It is, again, an error to assume that I know nothing about JASS just because I don't know Timers as well as you do.
Still, my previously question about timers was not answered - are sleeps faster and more efficient than timers ?

EF, your post was very informative. Thx for the links and downloads. Your explanation about BJ's was also friendly as well and I appreciate really appreciate that.

Thx all for your help. I shall now enter a stage where I fully remake that trigger, and then I shall try to add what I learned from this post. If I have trouble, I shall post here as well - after all, I am new to this vJass thing.
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
1st - If I ignore help, then please explain me why I decided to implement JNGP as along with timers as you guys suggested.

Please explain why you were violently opposed to it.

2nd - If I knew how to use timers efficiently and correctly, I wouldn't be creating this post ... makes sense rit ?

If you didn't think you knew, you wouldn't argue so much with those who do.

I understand what you mean, but still, Sleeps are faster than timer rit ? I know they make my spell tun slower, but in efficiency terms, a code with sleep will be faster than a code with timers rit ?

Not really. I suspect the thread stuff in waits is actually slow. If you then use NewTimer/ReleaseTimer (ie: a timer stack; CSSafety has a good one), then it'll almost certainly be faster.

About the Bj's I actually already knew that. It is, again, an error to assume that I know nothing about JASS just because I don't know Timers as well as you do.
Still, my previously question about timers was not answered - are sleeps faster and more efficient than timers ?

Benchmark it if you really care. However, it makes no real difference. Waits can't do accurate stuff. They can't be used for high-speed stuff.
 
Level 5
Joined
Oct 27, 2007
Messages
158
I understand what you mean, but still, Sleeps are faster than timer rit ? I know they make my spell tun slower, but in efficiency terms, a code with sleep will be faster than a code with timers rit ?

Still, my previously question about timers was not answered - are sleeps faster and more efficient than timers ?

You need more CPU cycles for more frequent timer callbacks. It will cause a higher load on your CPU. If your timer callbacks are well coded and cause no leaks then this will hardly be something to worry about in terms of CPU usage. So no, the code is not noticeable faster. I will call your code faster when it achieves the same goal (smooth and fast spells) faster than code that uses timer callbacks. One instance of your trigger event takes longer to execute. Granted it does use less CPU cycles then an instance using more frequent timer callbacks. However your triggered wait instance will be holding on to resources longer, while the callback trigger instance doesn't.

Why would you want to use waits if it will cause your spells to be slow and not smooth? You don't want the CPU to idle about when it has the cycles to actually do something. If you have a lot of periodic event triggers or threads running(I don't mean irregular periodic timer callbacks or trigger events), just make sure you don't have them trying to run all at once. Use staggered waits for multi threads if you use them, and different intervals for timer trigger events.
 
Please explain why you were violently opposed to it.
I can only say I have a good reason. But instead of writing a huge off-topic text, justifying my action I will just say this:

"It's Man's nature to resist change" in Philosophy of modern age
If you didn't think you knew, you wouldn't argue so much with those who do.

Again your logic is all wrong. Just because I declined your suggestion at first, it didn't mean that I though I was better than you.
In fact you don't know me enough to make such a statement and therefore that is wrong.

However know 1 thing - I don't care if you are the greatest professional in the world, I always make a critic judgement of what people say to me, I always evaluate people opinions. I refuse, by nature, accept other ideas without even thinking about them, I refuse to sallow a suggestion or an idea like a soup, without even evaluating it.
Also, you didn't see my code, I did well in declining your suggestion that time as, with the current knowledge I had at that time, it would be madness to attempt doing so. You just said - use timers with JNGP ... you didn't say how or even gave me a decent why.
This is where I thank to Blue_jeans, once more, he explained how to use timers correctly, and how to improve them with JNGP. If not by BJ, I would still be using Sleeps.
there is the chance that I didn't understand your idea quite well thus giving me a reason to say what I said, but there is also a chance that you didn't explained yourself well enough for me to understand your point of view.

To conclude, I know my position here, I know that many of you have greater experience, but that doesn0t mean I will always do what you want just because you think that's best. This is programming after all, and there are thousands of ways to do create a code. I am not anyone's puppet, and therefore I will always (or at least most of the time) evaluate your ideas.

Finally I must apologise to people for this huge off-topic text. this will be the last comment I will answer about this business. I insist that if any of you wish to take this into a personal issue, then please use Private Messages instead of posting stuff in this thread.

Back On topic

For Drone and Captain_Griffen or for anyone who can help

So it is Ok if I use Sleeps sometimes rit ?? They are not that evil rit ?

I can use them as long as i intent the code to be slower ..mmm
Well, thx for your posts guys. So, because I want this spell to be more accurate and run faster I will use Timers, which will increase the CPU's work thus increasing the efficiency of the overall spell, correct ?
Thx, I would rep+ you guys again if I could !
(THW says i gotta spread rep points .. blarg ...)

I will now use JNGP together with Cohadars ABC timing system. If I have any question (which I will have), I will post here again.
Thx for your time guys.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
I will now use JNGP together with Cohadars ABC timing system.

You do not need ABC or any other system for this.
Here's an example (or go read that "making an efficient knock back in vJass" tutorial) on how to make this stuff with a single global timer:
JASS:
globals
    wolf array WOLF
    timer TIMER = CreateTimer()
    integer COUNT = 0
    real GRAVITY = -9.8
endglobals

struct wolf
    unit bomb
    real angle
    real velocity_xy
    real velocity_z = -9.8
endstruct

function getting takes nothing returns nothing
    local wolf w
    local integer i
    loop
        exitwhen i > COUNT
        set w = WOLF[i]
        call SetUnitX(w.bomb, GetUnitX(w.bomb) + w.velocity_xy * Cos(w.angle * bj_DEGTORAD)
        call SetUnitY(w.bomb, GetUnitY(w.bomb) + w.velocity_xy * Sin(w.angle * bj_DEGTORAD)
        call SetUnitFlyHeight(w.bomb, GetUnitFlyHeight(w.bomb) + w.velocity_z, 0)
        set w.velocity_z = w.velocity_z + GRAVITY
        if GetUnitFlyHeight(w.bomb) <= 0 then
              call w.destroy()
              set COUNT = COUNT -1
        endif
    endloop
    if COUNT = 0 then
        call PauseTimer(TIMER)
    endif
endfunction
function setting takes nothing returns nothing
    local wolf w = wolf.create()
    set w.bomb = some unit
    set w.angle = some angle
    set w.velocity_xy = some number
    if COUNT == 0 then
         call TimerStart(TIMER, 0.04, true, function getting)
    endif
    set COUNT = COUNT + 1
    set WOLF[COUNT - 1] = w
endfunction
 
Level 5
Joined
Oct 27, 2007
Messages
158

So it is Ok if I use Sleeps sometimes rit ?? They are not that evil rit ?

Depends on the use. The only use for sleeps I can think of are AI script thread sleeps and command handling stack. For a command stack it can be useful if you can't send a starting sequence of commands all at once. Without waits the stack is handled in a LIFO manner. However I don't prefer that method, since it can also be done without triggered waits.


So, because I want this spell to be more accurate and run faster I will use Timers, which will increase the CPU's work thus increasing the efficiency of the overall spell, correct ?

Yes.
 
Level 5
Joined
Oct 27, 2007
Messages
158
You do not need ABC or any other system for this.
Here's an example (or go read that "making an efficient knock back in vJass" tutorial) on how to make this stuff with a single global timer:

JASS:
struct wolf
    unit bomb
    real angle
    real velocity_xy
    real velocity_z = -9.8
endstruct

globals
    wolf array WOLF
    timer TIMER = CreateTimer()
    integer COUNT = 0
    real GRAVITY = -9.8
    boolean mutex_setting = false
    boolean mutex_getting = false
endglobals

function getting takes nothing returns nothing
    local wolf w
    local integer i = 0 // Has to be initialized before using in an evaluation.

    loop
        loop
            exitwhen not mutex_setting and not mutex_getting
        endloop
        set mutex_getting = true
        set w = WOLF[i] // Using an uninitialized and/or unchanged i will not be correct if you want to handle all triggered instances.
        call SetUnitX(w.bomb, GetUnitX(w.bomb) + w.velocity_xy * Cos(w.angle * bj_DEGTORAD)
        call SetUnitY(w.bomb, GetUnitY(w.bomb) + w.velocity_xy * Sin(w.angle * bj_DEGTORAD)
        call SetUnitFlyHeight(w.bomb, GetUnitFlyHeight(w.bomb) + w.velocity_z, 0)
        set w.velocity_z = w.velocity_z + GRAVITY
        if GetUnitFlyHeight(w.bomb) <= 0 then
            call w.destroy()
            set WOLF[i] = 0 // Remove the triggered instance.
        endif
        set i = i + 1
        set mutex_getting = false
        exitwhen i == COUNT
    endloop
    if COUNT = 0 then
        call PauseTimer(TIMER)
    endif
endfunction

function setting takes nothing returns nothing
    local wolf w = wolf.create()
    local integer index = 0

    loop
        exitwhen not mutex_getting and not mutex_setting
    endloop
    set mutex_setting = true
    set w.bomb = some unit
    set w.angle = some angle
    set w.velocity_xy = some number
    loop
        exitwhen index == COUNT or WOLF[index] == 0 // This will prevent a stacking problem where you decrement the top instead of removing one of the lower elements.
        set index = index + 1
    endloop
    set WOLF[index] = w
    if COUNT == 0 then
         call TimerStart(TIMER, 0.04, true, function getting)
    endif
    if index == COUNT then
        set COUNT = COUNT + 1
    endif
    set mutex_setting = false
endfunction
This can be tricky because you have no mutual exclusion for the global COUNT variable. Depending on the amount of time it takes to execute the timer callback you'd need as much as two mutexes. Better safe than sorry. This way the triggered event doesn't have to wait very long if the callback is busy processing a trigger instance. After processing one trigger instance the trigger event gets the chance to process another event. there's a possible situation where a trigger instance is processed in the callback and isn't yet removed, while in the mean time another trigger instance is added due to another trigger event. That new trigger instance will be removed from the callback without ever being processed.

You can't remove the top of the instances stack in this case. Most of the time a lower stack element will need to be removed. You can't just decrement the instances index like that. I didn't include top of stack checking, which would be insane if you ever got that much instances anyway. That would mean 8192 instances all at the same time.

I'd rather use a global handle var array attach system for this.
 
Last edited:
Mm, i don't seem to understand what a variable of type Wolf is ... Still, I have to use ABC system ( I think). That case you made was just to set the bombs. I intent to improve the over all trigger, and to turn the map into a system, so maybe it can get approved on wc3.net. It would be great for people to have a linear bombarding system.

Please note that I also have to:
- Move the plane with a Timer into a direction.
- Set the plane fade in and fade out with another timer
- Decrease to plane's fly heigh in order to cast bombs, with another timer
- drop the bombs (maybe using your suggestion)
- and then repeat all the stuff to make the plane go away

Yours is a possible solution, I just am not sure if it is the best for this case.
Also, please could you give me the link ?


I'd rather use a global handle var array attach system for this.
Like ABC per example rit ?
 
Level 14
Joined
Nov 20, 2005
Messages
1,156
Waits are fine so long as no real accuracy is required (~0.3 seconds out normally, use a PolledWait unless you're just looping while waiting for something, then use a TriggerSleepAction(0.)). This means basically don't use waits in many systems or pretty much any spell.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Flame, wolf is the struct.
Structs get read before every other code so you can make a global struct.
in this case, I made (or Silvenon made lol) an arrayed struct that will hold all the current "active" structs.

The global timer just loops between the wolf array (struct array) and sets the height to something else.

So for this example, you will need the x velocity, the y velocity, and the unit itself (the bomb).
Another way to do it is one velocity for x and y and using an angle.
The only thing it matters for is speed (so for perfection, you'd rather x velocity and y velocity).

For example
JASS:
struct bomb
        unit u
        real vx
        real vy
endstruct

//functions and what not
local bomb b = bomb.create()
set b.u = some unit
set b.vx = some number * Cos(some angle * bj_DEGTORAD)
set b.vy = some number * Sin(some angle * bj_DEGTORAD)

Now each time the timer runs you move unit with SetUnitX(structname.u, GetUnitX(structname.u) + structname.vx) and the same thing with the Y.

Oh and by the way, since the acceleration (gravity) is a constant, you can just global it, no need to localize it.
 
Status
Not open for further replies.
Top