Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411422 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 11:01:20 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The grumpy old programmer room
Pages: 1 ... 238 239 [240] 241 242 ... 295
Print
Author Topic: The grumpy old programmer room  (Read 738128 times)
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4780 on: April 22, 2015, 05:10:13 PM »

Yeah I dont remember GCC being that bad for me but I rarely have reason to use it outside of personal interest.
Logged

MorleyDev
Level 0
***

"It is not enough for it to just work"


View Profile WWW
« Reply #4781 on: April 23, 2015, 10:48:38 AM »

Build time comparisons between GCC and VS can get odd, Visual C++ seems faster at 'straight forward' C++, and to fall down horribly when any kind of reasonably complicated metaprogramming gets involved (especially recursion with variadics).

I wrote a unit testing and assertion library in C++ (to see how much easier such things would be to build when you use C++11 to get rid of those hideous preprocessor define hacks old libraries used), and in drone.io it builds itself and its unit tests from scratch in 1 minute in GCC, but takes 5 minutes in Visual Studio with appveyor.

And then when I used it for an actual project, builds in gcc of the unit tests for that project took like a minute tops in GCC on my machine, but 11 minutes when invoking visual studio.
« Last Edit: April 23, 2015, 12:22:22 PM by MorleyDev » Logged

oahda
Level 10
*****



View Profile
« Reply #4782 on: April 23, 2015, 11:49:27 AM »

How did you get such long build times for a library like that on any compiler?

My game in its current state has a bunch of shit plus its engine and together they compile in less than a minute on LLVM so far (including some libraries I compile myself, like AngelScript).
Logged

Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4783 on: April 23, 2015, 12:00:36 PM »

I build myself and link statically: AngelScript, freetype, TinyXML, GLFW, AOIS (now SNIIS), curl. Plus own framework. But as I said: it's mostly because I rely heavily on Precompiled Headers, and GCC does not seem to be make good use of it.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
MorleyDev
Level 0
***

"It is not enough for it to just work"


View Profile WWW
« Reply #4784 on: April 23, 2015, 01:21:55 PM »

How did you get such long build times for a library like that on any compiler?

For my post? Well, my bets are how all that was once done with heavy macros is now done with heavy templating (and variadic templates, and recursive) and makes extensive usage of SFINAE. And then this is hidden behind a couple of variadic recursive macros. Visual Studio seems to hate all of those.

Plus I favour many small classes where possible, so the initial build has to compile a lot of cpp files that only declare one or two functions (This does reduce the time of subsequent builds significantly, but increases the time of build from clean).
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4785 on: April 23, 2015, 01:52:40 PM »

How did you get such long build times for a library like that on any compiler?

My game in its current state has a bunch of shit plus its engine and together they compile in less than a minute on LLVM so far (including some libraries I compile myself, like AngelScript).

I've definitely worked on a codebase or two where a cold compile could take 30 mins :| It's absolutely huge though. Typically a warm compile is very quick though.


I hope some day another systems language picks up steam because compile times in C/C++ are archaic


 
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #4786 on: April 23, 2015, 02:35:47 PM »

I hope some day another systems language picks up steam because compile times in C/C++ are archaic

Rust is promising, though doesn't support incremental compiles at all currently, and build times with optimization can be gigantic.
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4787 on: April 24, 2015, 06:08:43 AM »

yeah rust and D are the two languages I have my eye on. I wish I had more time to spend with them.
Logged

indie11
Level 2
**


View Profile
« Reply #4788 on: April 27, 2015, 08:16:55 PM »

I am a bit confused here, need some feedback.

The speed of an Object depends on how fast a key is pressed. This means that the speed of that object will change almost every frame. Do I still multiply that speed with Delta Time to make it frame rate independent?

Logged

Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4789 on: April 28, 2015, 05:33:20 AM »

For starters? Yes. I'm not really sure what you mean by "how fast a key is pressed", but generally you could say that as long as a key is pressed, a linear acceleration affects the player. So movement of the player is basic vector math.

vel += accel * deltatime;
pos += v * deltatime + accel/2 * deltatime^2;

The first part of the pos formula is the "frame rate independent" part of linear velocity. The latter part is the added effect of a linear acceleration. You won't notice a difference for slow accelerations, though - its numbers are very small for most cases.
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #4790 on: April 28, 2015, 07:02:43 AM »

Working on a codebase that goes out to about 5 different c++ compilers. Managed to make an coding error that caused clang and another compiler fail with a linkage error. It was relating to constructing a param to a function inside the param brackets. Once I just brought it out as a local and passed it in it passed on clang.

Still not entirely sure about the cause. It's possible our clang is running at a higher warning-as-error level than the other compilers but if that were true it wouldn't be a linker error.
Logged

indie11
Level 2
**


View Profile
« Reply #4791 on: April 29, 2015, 07:20:35 PM »

For starters? Yes. I'm not really sure what you mean by "how fast a key is pressed", but generally you could say that as long as a key is pressed, a linear acceleration affects the player. So movement of the player is basic vector math.

vel += accel * deltatime;
pos += v * deltatime + accel/2 * deltatime^2;

The first part of the pos formula is the "frame rate independent" part of linear velocity. The latter part is the added effect of a linear acceleration. You won't notice a difference for slow accelerations, though - its numbers are very small for most cases.

 Hand Any Key this is what I am currently doing... the speed of this button press is applied on the objects so they can move
Logged

Boreal
Level 6
*


Reinventing the wheel


View Profile
« Reply #4792 on: April 30, 2015, 05:07:16 PM »

For starters? Yes. I'm not really sure what you mean by "how fast a key is pressed", but generally you could say that as long as a key is pressed, a linear acceleration affects the player. So movement of the player is basic vector math.

vel += accel * deltatime;
pos += v * deltatime + accel/2 * deltatime^2;

The first part of the pos formula is the "frame rate independent" part of linear velocity. The latter part is the added effect of a linear acceleration. You won't notice a difference for slow accelerations, though - its numbers are very small for most cases.

It's a mistake to incorporate acceleration into the position integration.  It should simply be:
Code:
x += v * dt;
v += a * dt;
for Euler integration (which I don't recommend, but that's outside the scope of this).  Doing it your way, you're integrating acceleration twice.  The 0.5a^2 term comes from the indefinite integration of a.
« Last Edit: April 30, 2015, 07:31:29 PM by Boreal » Logged

"In software, the only numbers of significance are 0, 1, and N." - Josh Barczak

magma - Reconstructed Mantle API
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #4793 on: April 30, 2015, 06:06:52 PM »


Assuming the problem being solved is that of applying constant acceleration over a time period, Schrompf has provided the correct formulae:

Quote
vel += accel * deltatime;
pos += v * deltatime + accel/2 * deltatime^2;

This is correct.

Further confirmation:

- http://en.wikipedia.org/wiki/Equations_of_motion (see "Uniform acceleration").
- http://www.google.com.au/?q=position+given+constant+acceleration
Logged
Boreal
Level 6
*


Reinventing the wheel


View Profile
« Reply #4794 on: April 30, 2015, 07:26:58 PM »

I'll go from first principles to prove my point.  Definite integration is signified by integral(f, a, b) where f is the function to integrate and a and b are the lower and upper bounds.

The differential equations we are working with are simple.

a = dv/dt
v = dx/dt

Given a changing acceleration a(t), we want to find the changing position x(t).

dx = v*dt
x(t) = x(0) + integral(v, 0, t)

But what is the changing velocity v(t)?

dv = a*dt
v(t) = v(0) + integral(a, 0, t)

If a(t) was a constant a, we could do analytical integration and end up with a couple of familiar equations of motion.

v(t) = v(0) + a*t
x(t) = x(0) + v(0)*t + 0.5*a*t^2

However, in a game an object's acceleration is often dependent on too many factors to analytically model, so we use numerical integration instead (Euler method for illustration).

v(t+dt) = v(t) + a(t)*dt
x(t+dt) = x(t) + v(t)*dt

This easily translates into the simple pseudocode I posted earlier.

Code:
x += v * dt;
v += a * dt;

Adding in an extra (improper) integration of velocity as you have is not terribly bad with a small timestep, but especially as you start using more accurate integrators like midpoint or RK4 it is mathematically incorrect.
« Last Edit: April 30, 2015, 07:32:55 PM by Boreal » Logged

"In software, the only numbers of significance are 0, 1, and N." - Josh Barczak

magma - Reconstructed Mantle API
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #4795 on: April 30, 2015, 10:11:35 PM »

However, in a game an object's acceleration is often dependent on too many factors to analytically model...

I'm fairly confident that this argument does not invalidate the formulae provided.

The formulae are well-established and correct with multiple sources confirming. If my appeal to authority is insufficient, a single counter-example could be provided to disprove the formuale. I do not think there is one though. Saying that the formulae are incorrect is, well, incorrect. Saying that games are complex is irrelevant to the correctness of the equations provided.

But perhaps what you mean to say is: For games (or perhaps the particular application discussed here), there is a better approach than assuming constant acceleration? That's reasonable to say. It would then come down to demonstrating why an alternate approach is superior.

I am curious as to the advantages of the approach you are suggesting.

EDIT: Missed an "e".
« Last Edit: April 30, 2015, 10:30:37 PM by Garthy » Logged
GuiltyGreens
Level 0
*


View Profile
« Reply #4796 on: April 30, 2015, 11:00:01 PM »

Boreal isn't saying that the links you provided are incorrect. You and indie11 are incorrectly applying the formula.

It's a mistake to incorporate acceleration into the position integration.  It should simply be:
Code:
x += v * dt;
v += a * dt;
for Euler integration (which I don't recommend, but that's outside the scope of this). Doing it your way, you're integrating acceleration twice.  The 0.5a^2 term comes from the indefinite integration of a.

...

Adding in an extra (improper) integration of velocity as you have is not terribly bad with a small timestep, but especially as you start using more accurate integrators like midpoint or RK4 it is mathematically incorrect.


The wiki link shows that Eq1 and Eq2:

v = vo + at
x = xo + vot + .5at2, where

xo is the initial position
vo is the initial velocity
v is the final velocity
x is the final position

Also note that vo appears in both equations. Eq2 accounts for the change in velocity (.5at2) which is why it does not use the final velocity, v. It would be incorrect to do so again.

Edit:

Oh, I see.

For starters? Yes. I'm not really sure what you mean by "how fast a key is pressed", but generally you could say that as long as a key is pressed, a linear acceleration affects the player. So movement of the player is basic vector math.

vel += accel * deltatime;
pos += v * deltatime + accel/2 * deltatime^2;

The first part of the pos formula is the "frame rate independent" part of linear velocity. The latter part is the added effect of a linear acceleration. You won't notice a difference for slow accelerations, though - its numbers are very small for most cases.

I mistook vel for v. But, v is the initial velocity and vel is still the final velocity.
« Last Edit: April 30, 2015, 11:06:57 PM by BeTheLeaf » Logged
Garthy
Level 9
****


Quack, verily


View Profile WWW
« Reply #4797 on: April 30, 2015, 11:29:44 PM »


You and indie11 are incorrectly applying the formula.

Me? I believe my application of the formulae is entirely correct.

I mistook vel for v. But, v is the initial velocity and vel is still the final velocity.

Yeah, it's a touch confusing as expressed. "v" is used to mean "v(0)". The form used in your post is the most clear IMHO:

v = vo + at
x = xo + vot + .5at2, where
Logged
Schrompf
Level 9
****

C++ professional, game dev sparetime


View Profile WWW
« Reply #4798 on: May 01, 2015, 05:42:00 AM »

Didn't want to create confusion. I realize the code is wrong when written directly like this.

Given current position p0, velocity v0 and a constant acceleration a = a0 = a1, the per-frame code would look like

v1 = v0 + dt * a;
p1 = p0 + dt * v0 + 0.5 * a * dt2;

Which is what Garthy and BeTheLeaf already wrote. Now stop being helpful and return to being grumpy :-)
Logged

Snake World, multiplayer worm eats stuff and grows DevLog
Boreal
Level 6
*


Reinventing the wheel


View Profile
« Reply #4799 on: May 01, 2015, 09:27:15 AM »

I've personally never seen the twice-integrated acceleration term as part of an Euler integration, but I did a simple test in MATLAB and it does make it match the analytical solution perfectly.  So that would be the error term of the Euler integration for those simple equations of motion.

But if you are using a different integrator like the midpoint method, Verlet, or RK4 it is incorrect to include that error term.  It is also not really correct to include it unless a constant acceleration due to gravity is the only acceleration you are modelling.
Logged

"In software, the only numbers of significance are 0, 1, and N." - Josh Barczak

magma - Reconstructed Mantle API
Pages: 1 ... 238 239 [240] 241 242 ... 295
Print
Jump to:  

Theme orange-lt created by panic