Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1402742 Posts in 68125 Topics- by 61742 Members - Latest Member: Todd Even

September 26, 2022, 02:23:34 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 3 4 [5] 6 7 ... 68
Print
Author Topic: General thread for quick questions  (Read 93489 times)
Prinsessa
Level 10
*****



View Profile
« Reply #80 on: July 24, 2015, 10:03:05 AM »

I use CSS includes a lot these days so that I don't have to recompile everything.
Logged

indie11
Level 2
**


View Profile
« Reply #81 on: July 24, 2015, 10:50:51 AM »

Is it possible to produce a SMB like character controller using "Variable Time Step" ?
I am implementing one, but there is always a very minute difference in min and max jump heights because of variable step

How does your acceleration formula work? I have this one written down in my notes:

Code:
position += velocity * timestep + 0.5 * acceleration * timestep * timestep;
velocity += acceleration * timestep;

Currently working on the jumping part only.

I just set the yVelocity to an Impulse every frame and stop when the jump button is UP or Max Jump Time is reached
Code:
velocity.y = jSpeed;

And this is how I am applying gravity
Code:
velocity.y += ( gravity * (UtilMethods.Sign(velocity.y) == -1 ? 0.5f:1f ) ) * Time.deltaTime;
to get floaty feeling, half gravity is applied when moving downwards
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #82 on: July 24, 2015, 11:16:15 AM »

Currently working on the jumping part only.

I just set the yVelocity to an Impulse every frame and stop when the jump button is UP or Max Jump Time is reached
Code:
velocity.y = jSpeed;

And this is how I am applying gravity
Code:
velocity.y += ( gravity * (UtilMethods.Sign(velocity.y) == -1 ? 0.5f:1f ) ) * Time.deltaTime;
to get floaty feeling, half gravity is applied when moving downwards

Give this a try and see if it does the trick:

Code:
position.y += velocity.y * Time.deltaTime + 0.5 * gravity * Time.deltaTime * Time.deltaTime;
velocity.y += gravity * Time.deltaTime;

Just changing velocity won't do it; the calculation you use for applying it to your object's position needs to change too.
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #83 on: July 24, 2015, 11:20:04 AM »

What is the best way to develop: simple, 2D games, cross-platform (Linux, Windows and Mac) in C? (C++ is out of question, I want to play with simple, small, straight forward, stuff)

Where:

1) I don't have to write very very basic stuff (or platform specific code)
2) I don't want to use a dev kit like Unreal or Game Maker or anything like that.

SDL is a reasonable choice. I'm also working on a framework for this sort of thing, though it's not quite ready for general use.
Logged

dancing_dead
Level 2
**


View Profile
« Reply #84 on: July 24, 2015, 02:22:21 PM »


What is the best way to develop: simple, 2D games, cross-platform (Linux, Windows and Mac) in C? (C++ is out of question, I want to play with simple, small, straight forward, stuff)

it's a dangerous misconception, thinking that C is somehow simpler than C++. sure, C++ got all that class stuff etc, but, in practical terms, C++ will be the simpler choice, especially for something like games. C really only shines when you already know what you're doing.
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #85 on: July 24, 2015, 03:33:44 PM »

They're two different languages. C has a lot less stuff in it. Calling it simpler is perfectly reasonable. High-level features in C++ could just as easily simplify your code as they could convolute it, depending on usage.
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #86 on: July 24, 2015, 05:05:29 PM »

I tried messing with the goto command at work today in C++ just to see what it could do. Turns out it's more useless than a pointer to itself.
Logged

indie11
Level 2
**


View Profile
« Reply #87 on: July 25, 2015, 09:56:58 AM »

Currently working on the jumping part only.

I just set the yVelocity to an Impulse every frame and stop when the jump button is UP or Max Jump Time is reached
Code:
velocity.y = jSpeed;

And this is how I am applying gravity
Code:
velocity.y += ( gravity * (UtilMethods.Sign(velocity.y) == -1 ? 0.5f:1f ) ) * Time.deltaTime;
to get floaty feeling, half gravity is applied when moving downwards

Give this a try and see if it does the trick:

Code:
position.y += velocity.y * Time.deltaTime + 0.5 * gravity * Time.deltaTime * Time.deltaTime;
velocity.y += gravity * Time.deltaTime;

Just changing velocity won't do it; the calculation you use for applying it to your object's position needs to change too.

Here's how its done..

Code:
velocity.y += ( myGravity * (UtilMethods.Sign(velocity.y) == -1 ? 0.49f:1f ) ) * Time.deltaTime;
controller.Move (velocity * Time.deltaTime, input);
//Controller Move function checks for collision after that, I simply translate the player
transform.Translate (velocity);

Is this wrong way to do it? Also there is some jitter in horizontal movement

« Last Edit: July 25, 2015, 10:16:27 AM by indie11 » Logged

Sik
Level 10
*****


View Profile WWW
« Reply #88 on: July 26, 2015, 09:00:53 AM »

What is the best way to develop: simple, 2D games, cross-platform (Linux, Windows and Mac) in C? (C++ is out of question, I want to play with simple, small, straight forward, stuff)

I use SDL 2 (don't bother with SDL 1, that one has been long dead).

There's also Allegro 5 but whether you like it or not is a different issue...
Logged
TheLastBanana
Level 9
****



View Profile WWW
« Reply #89 on: July 26, 2015, 11:37:22 AM »

I tried messing with the goto command at work today in C++ just to see what it could do. Turns out it's more useless than a pointer to itself.

There aren't too many cases where goto is useful in C++, but they do exist. One I can think of is this:

Code:
var foo()
{
    bool toBreak = false;

    for (...)
    {
        for (...)
        {
            if (...)
            {
                // Can't break out of the outer loop from here
                break;
                toBreak = true;
            }
        }
        
        if (toBreak) break;
    }

    // Do something after the loop
}

That's kind of ugly, and you can replace it with this:

Code:
void foo()
{
    for (...)
    {
        for (...)
        {
            if (...)
            {
                goto afterLoop;
            }
        }
    }

afterLoop:
    // Do something after the loop
}
Logged
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #90 on: July 26, 2015, 11:52:41 AM »

There aren't too many cases where goto is useful in C++, but they do exist. One I can think of is this:

<snip>

I love the Rust solution to this problem.

Code:
'outer: for ... in ... {
    'inner: for ... in ... {
        if ... {
            break 'outer;
        }
    }
}
Logged
Dacke
Level 10
*****



View Profile
« Reply #91 on: July 26, 2015, 12:02:03 PM »

It's not really a Rust invention, though. It works the same in Java and JavaScript.
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
Sik
Level 10
*****


View Profile WWW
« Reply #92 on: July 26, 2015, 12:54:14 PM »

And now you get nearly all the javascript programmers here with their minds blown because they weren't aware such a thing existed in the first place (I had nearly forgotten about it, actually).
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #93 on: July 26, 2015, 12:59:37 PM »

If you want to see some examples of goto used in a fairly large product take a look at the photoshop SDK (you dont need to own photoshop to look at it).

They basically use it for error handling and cleanup. A function typically represents a command in their usage patterns and you pass around this action objects you build up via passing them into mutating c functions. The problem is when build up these commands you make a lot of intermediary objects which you are responsible for cleaning up.

What they end up doing is putting all the logic in the top half of the function and if there's an issue then you goto to the error label at the bottom function which cleans up all the objects used in one place. Also by virtue of it being at the bottom of the function, if everything succeeds then it enters the error block and does the require cleanup too.

Considering usually most of the intermediate objects are created at the top of the function it's kind of a interesting way to make a lot of temporary state and clean it up. It's almost like a ctor block followed by a logic block followed by a dtor block inside a function.

I'm not advocating this method or anything, just pointing out that the photoshop SDK is a good place to see it still used in the real world.
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #94 on: July 27, 2015, 03:41:10 AM »

Yeah, I get that goto has its uses, but it can't even jump over a declaration-initialization line, which really threw me off as I tried troubleshooting that stupid bug in my program.

Besides, the break statement with a target loop to break out of works much better IMO. Goto is just an artifact of old programming languages at this point.
Logged

Sik
Level 10
*****


View Profile WWW
« Reply #95 on: July 27, 2015, 08:45:37 PM »

What they end up doing is putting all the logic in the top half of the function and if there's an issue then you goto to the error label at the bottom function which cleans up all the objects used in one place. Also by virtue of it being at the bottom of the function, if everything succeeds then it enters the error block and does the require cleanup too.

Holy shit that's what I came to start doing in C these days =o (amusingly I took the idea from assembly, where in case of bailing out I'd normally just jump straight to the label before the return - I was like "that's much cleaner than spreading deinit calls everywhere, why not just do that?")

I know OOP people swear for exceptions, but honestly they tend to have tons of issues (it requires so much error checking that it ends up making programmers not use them properly, and at least in C++ they're also a massive source of hazard situations). If I were to design a language I'd replace exceptions with some variant of this system (without goto of course, but the basic idea is there).
Logged
Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #96 on: July 27, 2015, 09:34:45 PM »

I know OOP people swear for exceptions, but honestly they tend to have tons of issues (it requires so much error checking that it ends up making programmers not use them properly, and at least in C++ they're also a massive source of hazard situations). If I were to design a language I'd replace exceptions with some variant of this system (without goto of course, but the basic idea is there).

Languages that have enums with variants can cleanly represent an error in their return value:

Code:
fn is_five(v: i32) -> Result<i32, i32> {
    if v == 5 { Ok(5) }
    else { Err(-1) }
}

You can even use language tricks to get all the value of exceptions without losing any of the performance or having to deal with all the unwrapping problems.

Code:
fn do_things() -> Result<i32, i32> {
    let my_val = try!(is_five(5)); // <- Will return the error if one happens
    Ok(my_val)
}

And if you're absolutely absolutely sure it won't happen, you can even ignore that it might give an error, and make it drop into an actual exception (a panic!() in Rust), which you can then interpret as something beyond expectation having gone seriously wrong.

Code:
let my_val = do_things().unwrap();
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #97 on: July 28, 2015, 04:35:51 AM »

What they end up doing is putting all the logic in the top half of the function and if there's an issue then you goto to the error label at the bottom function which cleans up all the objects used in one place. Also by virtue of it being at the bottom of the function, if everything succeeds then it enters the error block and does the require cleanup too.

Holy shit that's what I came to start doing in C these days =o (amusingly I took the idea from assembly, where in case of bailing out I'd normally just jump straight to the label before the return - I was like "that's much cleaner than spreading deinit calls everywhere, why not just do that?")

I know OOP people swear for exceptions, but honestly they tend to have tons of issues (it requires so much error checking that it ends up making programmers not use them properly, and at least in C++ they're also a massive source of hazard situations). If I were to design a language I'd replace exceptions with some variant of this system (without goto of course, but the basic idea is there).

Yeah I have similar feelings about exceptions. I just finished reading the noexcept chapter in Scott Meyers C++11 book and the number of exceptions to using noexcept (pun intended :p ) makes me understand why so many developers still disable exceptions at the compiler level.

I think a lot of the stigma against goto is because people are mistaking goto line number versus goto label.

Logged

Sik
Level 10
*****


View Profile WWW
« Reply #98 on: July 28, 2015, 05:39:39 AM »

Languages that have enums with variants can cleanly represent an error in their return value:

The whole point of exceptions is that you can't get away with error codes (because they're easy to just ignore).

Mind you, not like the other system being talked here would work alone as-is, since it's on the other extreme (isolate everything to the most you get is an error code). To make it work well, you need the APIs to handle being passed error values gracefully so you aren't required to check all the time (e.g. if a function taking a bitmap receives nothing then it could treat that like it got a 0×0 bitmap instead, or a function taking a null file would always treat it as a 0 bytes long file always at EOF that can't be written (check the error codes explicitly if you care about the file existing, ignore them if you're OK with getting emptiness)).

...in hindsight I'm literally just suggesting to make fault tolerant APIs (・~・)
Logged
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #99 on: July 28, 2015, 05:52:22 AM »

But fault tolerant APIs are hard to debug...
Why not just tolerate faults but also send error messages? Like, if something comes up that's not supposed to happen, keep working correctly but still push something to a txt file or a debug console.
Logged

Pages: 1 ... 3 4 [5] 6 7 ... 68
Print
Jump to:  

Theme orange-lt created by panic