How to implement overshoot on enemy arrival?

A place for people with an interest in developing new shmups.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

DyingIsFun wrote: I use simple geometric checks to see if a bullet is within a certain radius or rectangular area around my player or enemy. It's pretty straightforward to determine if a point is in a circle or rectangle without full fledged physics engine :D. I actually found these simple geometric checks to be more performant for me than when I did have BoxColliders on player, bullets, and enemies (which is how I originally started my prototype).
Does your geometric check only exist of mutliply, subract, or adding math ?, then your good.
If you use sqrt function, you are doing it the wrong way.
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: How to implement overshoot on enemy arrival?

Post by trap15 »

heli wrote:Trap15 you did not answer my question
What was your question then, because as shown I have looked at the code for itoa. If you mean the machine code, sure I've seen that too, yes. It's pretty much what you would expect from looking at the C version.
heli wrote:divide is very slow, not recommended for use in main loop.
You're kidding right? Divide hasn't been slow for PCs for nearly 30 years. Even when it was slow, it was "60~100 times addition", which even if it was true in the modern day is literally meaningless amounts of time. Even on 80s CPUs you can use divide instructions just fine.
heli wrote:You using itoa in your main loop for the score ?, that it has to do with video game mechanic.
Going back to thinking about software design, running something like this a single time per frame is absolutely reasonable. What else are you going to do, keep every digit in a separate byte and manually carry additions when you add to score? That's going to hurt performance way way worse than 20 divides and modulos every frame (though, again, going back to decreasing frequency, you only need to do this once each time score updates, and cache the results, so you're doing it only when necessary).
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
Sumez
Posts: 8019
Joined: Fri Feb 18, 2011 10:11 am
Location: Denmarku
Contact:

Re: How to implement overshoot on enemy arrival?

Post by Sumez »

heli wrote:divide is very slow, not recommended for use in main loop.
What do you think a "main loop" is?
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

trap15 wrote:
heli wrote:Trap15 you did not answer my question
What else are you going to do, keep every digit in a separate byte and manually carry additions when you add to score? That's going to hurt performance way way worse than 20 divides and modulos every frame (though, again, going back to decreasing frequency, you only need to do this once each time score updates, and cache the results, so you're doing it only when necessary).
Exactly, there are 4 vertices for each polygon, so i increase score by 4 only.
If you do update once in a while, you get once in a while a slow frame.

So you saying multiple modulos in 1 frame is faster then increasing a unsigned int with 4 ?
Sumez wrote: What do you think a "main loop" is?
I should have sayd : inner loop, or loop core.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

I love to see a game from you.
Just to see the system-requirements of your game, just for fun.
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: How to implement overshoot on enemy arrival?

Post by trap15 »

heli wrote:I love to see a game from you.
Just to see the system-requirements of your game, just for fun.
http://firelancer.ws/

It runs on a 3.072MHz CPU from 1999.
heli wrote:Exactly, there are 4 vertices for each polygon, so i increase score by 4 only.
This is gravely concerning to read, just by the way. How are you handling carry between digits? And, do you really think something like 500 cycles (way more than doing the itoa conversion would take, but let's just get exaggerated for point's sake) is going to affect any single frame in any significant way? A 1GHz CPU can run over 16 million cycles in one frame.
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

It inreases until 10, then it set back to 0, and count 1 more for the next number.
If you compare it to itoa :
itoa does all numbers all the time,
my function dont, it is possible, when the score is 9999999999999999999, it will take compute all the characters for 1 point increase, just like itoa does all the time, only itoa cant handle this big scores.
+ if it take all characters it is still faster.

And thank you i have a plan to increase speed, since i just wanted to tell you :
You always need to keep your frames the same speed, without peaks,
you better waste some time on things all the time then more slowdown for 1 frame.
So i was thinking, i could try if i could compute only 1 number per frame, and increase the rest when no scoring is done, maybe it will slowdown things per frame, the slowest frame will be almost equal to the fastest frame.

So you are saying you using all sine cosine and other math functions to make a game for a 1999 PC ?
How do you aim the tanks ?, with atanf function ?
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: How to implement overshoot on enemy arrival?

Post by trap15 »

heli wrote:It inreases until 10, then it set back to 0, and count 1 more for the next number.
If you compare it to itoa :
itoa does all numbers all the time,
my function dont, it is possible, when the score is 9999999999999999999, it will take compute all the characters for 1 point increase, just like itoa does all the time, only itoa cant handle this big scores.
+ if it take all characters it is still faster.
Seems like a pain to deal with, but you do you. Of course itoa has limitations, but there's nothing wrong with it if it fits the bill. If the extra couple hundred cycles (again, exaggeration for making the point) are the breaking point between running full speed and not, there's something seriously slow elsewhere that's more worthwhile to optimize.
heli wrote:You always need to keep your frames the same speed, without peaks,
you better waste some time on things all the time then more slowdown for 1 frame.
So i was thinking, i could try if i could compute only 1 number per frame, and increase the rest when no scoring is done, maybe it will slowdown things per frame, the slowest frame will be almost equal to the fastest frame.
So I take it you don't know about the concept of a frame limiter or something then. Spending more or less time per frame doesn't matter as long as your total time in the frame is less than a frame's length, because your frame beginning and ending is quantized to the frame rate. If you had to make sure every frame's code lasted the same exact length to avoid slowdown or speedups, I don't think modern software could ever exist.
heli wrote:So you are saying you using all sine cosine and other math functions to make a game for a 1999 PC ?
How do you aim the tanks ?, with atanf function ?
It's for a handheld console, not PC. As a result, I don't have these math library functions anyways, but they're not that different. Yes I use arctangent for aiming, but yes I wrote my own implementation. Because I need to, because my platform only lets me run 50 thousand cycles per frame.
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

Glad we finally agree.
Can i have your code for the aiming ?, or give me a hint how u made it ?
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

trap15 wrote: So I take it you don't know about the concept of a frame limiter or something then. Spending more or less time per frame doesn't matter as long as your total time in the frame is less than a frame's length, because your frame beginning and ending is quantized to the frame rate. If you had to make sure every frame's code lasted the same exact length to avoid slowdown or speedups, I don't think modern software could ever exist.
You might have all the peaks in 1 frame.
Computers are great, like you say, handheld hardware is not.
I like to have my code without librarys so i can run on anything like handheld.
Building hardware a bit, looking forward to make a handheld game console one day,
i am very intrested in how old games work, whats in those ROMs for nice tricks to make it run on a 80s chip.
I cant read it, i just play for inspiration, battle garegga had me inspired to make the score like this.
User avatar
trap15
Posts: 7835
Joined: Mon Aug 31, 2009 4:13 am
Location: 東京都杉並区
Contact:

Re: How to implement overshoot on enemy arrival?

Post by trap15 »

heli wrote:You might have all the peaks in 1 frame.
This is very unlikely, and mostly not worth serious consideration unless profiling says otherwise. Single frame hitches basically go unnoticed anyways. Again, a 500 cycle penalty per frame, even every frame, is not going to matter.
heli wrote:Can i have your code for the aiming ?, or give me a hint how u made it ?
Just made a program that pre-calculates a table of atan values to include into my code, then a function that uses the table as if it was the function. Do some research on the implementation of atan2 and using arctangent to turn coordinate offsets into angles, it's very worthwhile.
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

Thank you.
User avatar
heli
Posts: 585
Joined: Fri Sep 13, 2019 3:58 pm

Re: How to implement overshoot on enemy arrival?

Post by heli »

Trap15 i use this piece of code to aim my turrets :
https://en.wikipedia.org/wiki/Fast_inverse_square_root

Get normal values with that, then pass it in the render-matrix.
For aiming i use vectors that i move, no rotations.
Post Reply