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

Author Topic: Lethn's Programming Questions Thread  (Read 61748 times)

0 Members and 1 Guest are viewing this topic.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #90 on: August 08, 2013, 06:04:40 pm »
Just to avoid confusion, C++ is indeed only the rules of the language, nothing else.

Even the basic functions like printf and the containers etc etc are a part of the STL or the libc or whatever other "built-in" library, every single piece of functionality is implementation specific I believe, while c++ is just the standard by which those implementators write their compilers/libraries by.

Hope its clear :D

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #91 on: August 13, 2013, 07:57:22 pm »
Sorry, I took so long to post, been very busy, that does make a bit more sense now and thanks a lot for that post Semicolon I'll have a look I was wondering if there were any tutorials etc. out there that give good explanations so I'll see if these ones work for me. For some reason I find the way the internet lays out information a lot better even for reading than books.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #92 on: August 13, 2013, 08:16:59 pm »
For some reason I find the way the internet lays out information a lot better even for reading than books.
The impression may mislead, omitting important information may look simpler. But it's not, it will make your life harder -- but you'll recognize that only when developing own projects and not while reading. I still haven't found a C++ tutorial that covers the language in-depth and in a modern way. You'll miss a lot of important details when looking only at internet tutorials. In addition, a lot of tutorials teach a C/C++ mix and ancient, bad code style (this even applies to many books). Especially now that C++11 is out, you should definitely forget the tutorials that were already outdated the last decade.

I have just looked quickly at the XoaX video tutorials, and they seem to totally confirm my expectations: C class prefixes and Hungarian Notation, useless destructors, useless variable initializations, non-local declarations and variable reuse, missing const-correctness, manual memory management (even for arrays), using namespace std at the beginning of each function, ... I'm sure there is more. You'll learn a lot of bad practices by following such tutorials, I really do not recommend them. The only way to learn C++ correctly is, again, by reading a good book.

Here's such a WTF snippet, I don't even know where to start. And this is just a simple initialization.
bool bCanMove(false);
bCanMove = mqGameBoard.CanMove(mcPlayerTurn);
« Last Edit: August 13, 2013, 08:27:41 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #93 on: August 13, 2013, 11:53:07 pm »
Quote
I'm sure there is more.
I'll tell you more: he uses void main in some videos. ;D
And the comments just praise him extremely high for his easy, simple and quick tutorials.
Nexus, you are first class comedy supplier for me recently, these youtube tutorials you mention are always extremely funny.
On a more serious note: don't you wish everyone now just used clear, efficient, expertly written but 'old' practices like doom programming team does instead of learning from youtube? ::)
Because in the real world guys like him win over you or me, we tell them: read a book, read the code, read the reference, read the iso standard pdf and he says: I'll teach you how to do XYZ in 5 minutes video with pretty visuals and music. Who do you think they will follow? ;)
I'm personally quite happy, they are competition, the worse they do the better, it's their fault if they stay this way, I was that way too but I got better.

Here are two good resources for learning c++ online:
1. Bjarne Stroustrup's FAQs and glossary:
http://www.stroustrup.com/bs_faq.html
http://www.stroustrup.com/bs_faq2.html
http://www.stroustrup.com/C++11FAQ.html
http://www.stroustrup.com/glossary.html
These are pretty much prime resources since Stroustrup is original designer and creator of c++, sits in the committee(and claims to be happy with their decisions), the fact he is extremely skilled in C also helps these texts. Of course they are not to be read in one go or completely alone but the FAQs especially are well written, not boring or dry(the papers are, as expected from academic writings ;D) and can be read part by part from time to time, since they contain some interesting gotchas and explanations that can let you understand rationale and help you develop the mental model of why it's that way and why the other ways would fail.
2. Parashift FAQ:
http://www.parashift.com/c++-faq/
Very very in depth, long.

And of course reading some source code you can get your hands on is always good if it's right complexity compared to your experience so you learn but not get bored or confused by it. Also, nothing should be taken as granted when read from some source code, ever, because not all code follows good practices and much of it is legacy or outdated.

Quote
The only way to learn C++ correctly is, again, by reading a good book.
There actually is another way: being experience programmer in C, some OO language, optionally in assembly and some more langauges and then picking up c++ is quite easy. That's how half of Doom 3 team, including Carmack, learned c++, Carmack himself actually had Obj C and very strong C and assembler background. Doom 3 is a bit C-ish(it takes parts of renderer and probably some other things from id tech 3 which was in pure C, it's understandable to not start 100% from scratch when there are ready engines lying around, you have to excuse them for that) but it's well designed, efficient, modular, well abstracted and extremely short compared to something like Skyrim which is supposedly 30+ million lines.
But I can understand why you'd not mention this way. ;D
« Last Edit: August 14, 2013, 12:00:43 am by FRex »
Back to C++ gamedev with SFML in May 2023

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #94 on: August 14, 2013, 10:13:45 am »
I'm personally quite happy, they are competition, the worse they do the better, it's their fault if they stay this way, I was that way too but I got better.
With this attitude, I really have to wonder what you are doing in this forum ::)

There actually is another way: being experience programmer in C, some OO language, optionally in assembly and some more langauges and then picking up c++ is quite easy. That's how half of Doom 3 team, including Carmack, learned c++
No, picking up C++ like this is far from easy, as can be seen from the result -- I won't repeat the flaws again. That's why this approach is not a good idea, with respect to code. Remember, we're not talking about finished projects or great games here, only code.

I don't know what you're trying to achieve with your recent posts, that advertise ancient C++ code and obsolete techniques, just because a game was once written with them. Several years have passed meanwhile and C++ has greatly evolved. What's the point of ignoring progress and sticking to old principles? It's not as if writing a good game and clean code would inherently conflict, even if you want to believe that. Things like RAII massively simplify code, which in turn reduces development time and thus leaves more time to work on the actual game.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #95 on: August 14, 2013, 11:26:43 am »
Quote
With this attitude, I really have to wonder what you are doing in this forum ::)
Obviously I'm here to give bad advice and advertise doom codebase. ;D
Ok, actually:
There are comments telling them xoax is bad, using namespace std; void main is bad etc. but if instead something stupid like 'unsing namespace std; is more efficient' gets upvoted and they continue on watching these tutorials it's hardly my fault so why should I be concerned?
The forum on the other hand is very good resource because it's official for SFML(unlike coding made easy's SFML forum, which I'll make fun of and mock forever, since the official one is bigger, free and has all three authors on it so why do they go there..) , problem in here is equivalent to someone approaching me(or Stroustrup, because the SFML authors are here and can help too) about c++ and saying 'I read this <insert good book or tutorial here> but I don't understand this part, can you draw it out on paper for me?', which I did in the past and I'd do again, for free(maybe that was a mistake in that situation), because I support learning for real. What I don't support is quick-gain-little-effort approaches like watching these tutorials and plagiarism like 'I'll pay you if you code my c++ assignment' to which I said 'no'. :P

And of course the fact that I was that way(manual new/delete, cme tutorials) and got better, so they can/should too, the fact they are competition that is doing poorly is added benefit.
And I believe that most people are assholes and ungrateful and stupid by default and have to show something good(skill, willingness to learn, etc.) before I consider them worthwhile(but of course I don't say that upfront, that'd make them lock up and not able to show me their good side, which would be terrible loss). Being on this forum or reading from it is good enough thing to make me consider people who do it worthwhile(most of the time, excluding extreme cases like misusing SFML for something it wasn't meant to do or arguing about the fact that c++ is bad and SFML should be in C or something) and sacrifice a bit of my time to help here if I can.
« Last Edit: August 14, 2013, 11:53:45 am by FRex »
Back to C++ gamedev with SFML in May 2023

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #96 on: August 14, 2013, 12:47:48 pm »
What's with video tutorials these days.. What was wrong with the old way of learning? The way I learned to program was still weak compared to what it should be, in the early beginnings, but video tutorials seems like a new kind of low to me :/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #97 on: August 14, 2013, 01:28:01 pm »
Google conference keynote videos are great and on youtube, Linus' talk about git is great, interesting but not a tutorial but more of explanation of mental model behind git.

Everything seems to be some kind of low, people don't care about languages, learning, opinions like 'Linux sucks and is for poor stupid people who can't afford or pirate Windows' 'I don't give a shit about cross platform, only Windows matters' exist commonly etc. People are just bad in every respect and keep getting worse.

I say : don't worry, kick back and enjoy the laugh, this video is about 'unicode':

There are quite a lot of mistakes, barely anything is correct, comments are also very funny.
« Last Edit: August 14, 2013, 01:30:10 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #98 on: August 14, 2013, 01:37:54 pm »
What's with video tutorials these days.. What was wrong with the old way of learning? The way I learned to program was still weak compared to what it should be, in the early beginnings, but video tutorials seems like a new kind of low to me :/

Some video tutorials are bloody brilliant but I guess it can depend on what sort of thing you're trying to learn about and so on but there do seem to be unfortunately a lot of pretty crappy programming tutorials out there now I've gotten some knowledge :(. There are also those awful ones which are just crappy advertisements for paid tutorials so they'll leave stuff out etc. rather than just advertise honestly.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #99 on: August 14, 2013, 01:47:18 pm »
They might seem brilliant because they seem to be clear and explain well and the code works but it might be all crappy, not cross platform etc. the xoax unicode tutorial video is very very bad.  You should question anything you see and when in doubt you should trust Stroustrup's, Parashift's, Nexus' words and good book content. I really don't know what is in mind of guy who makes xoax tutorials, they are very harmful, unicode one especially because it's full of misinformation and windows specific stuff.
« Last Edit: August 14, 2013, 02:00:20 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #100 on: August 14, 2013, 02:22:21 pm »
Those tutorials, as great as the teaching may be, it is not teaching what it should for a complete learning.. Programming languages are pretty easy to learn as they are only a few rules of syntax etc, but then you need a ton of practicing and reading about the little things to master it.

For every major language, the hardest thing is to enter the mindset of the people who created that language, so you can take the max advantage of the tool and what it was created for. And of course, in order for the tool to be really good at something, it is designed and meant to be used in a particular way. That's why knowing all the control structures and syntax won't help much if you don't know what you SHOULD be doing with them in the particular case of that language. This is why people underestimate how hard it is to learn C++ properly, the language is pretty unforgiving, it can and will give headaches if you aren't absolutely confident of what you're doing.. Video tutorials will skip most things because if they would cover everything they would be BORING and no one would watch them..

About the OS fanboys, I have to say I hate ALL of them... Anyone who says Apple/Microsoft/Linux is the universal truth and calls morons to everyone else doesn't deserve any respect.. All systems are good equally for most tasks and its up to each person to choose what feels best... Everyone should be writing portable code for more than a decade now and just forget about stupid OS wars..(Its easy, just pickup SFML, Qt or anything else if you don't know how to do it manually..)

EDIT: I was watching the unicode video.. man.. he is trying to sell windows specific multibyte encoding as UNICODE which is plain wrong.. this video should be banned all the way :( I don't even think 16bit unicode chars even match 1:1 with those wchar_t things..
 
« Last Edit: August 14, 2013, 02:29:30 pm by Grimshaw »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #101 on: August 14, 2013, 03:10:18 pm »
He spreads Microsoft's misinformation(although there are comment saying that article is wrong), they say Unicode is 16 bit and has only 2^16 characters:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd183415%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ff381407%28v=vs.85%29.aspx
 
I'm guessing wchar_t have UCS-2 as described here:
http://www.unicode.org/faq/basic_q.html#14
which means that wchar_t is like UTF-16 limited to characters in BMP:
http://en.wikipedia.org/wiki/Plane_%28Unicode%29#Basic_Multilingual_Plane
so technically it is fixed width but that is not unicode and is extremely Windows specific and xoax instructor said they stopped using void main() because tutorials are now compatible with all compilers so it shouldn't be Windows specific.

You have to admit this is quite funny. ;D
« Last Edit: August 14, 2013, 03:21:27 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #102 on: August 14, 2013, 03:27:01 pm »
lol! Oh man the OS wars are ridiculous you have the same situation in games too as I'm sure you all know, I even discovered there are people arguing about OpenGL vs Directx.

Oh and by the way, I'm having a look at timestep so I can finally get some good interaction going without any lag and I'm having trouble understanding it, I have the SFML book explanation and I have the website the book gives but I'm having trouble understanding where it should all fit the code you make. I know about FPS etc. but because a lot of the stuff they show seems to be classes and things like that I think I need to do some more research on it.

The SFML book goes into plenty of detail into the mechanics of it but I need to have a look at more of the why is that placed there and so on.

p.s. will someone explain to me why the hell my thread is almost at 2000 views now? That's terrifying lmao :D

By the way, here's some code I'm doing with a simple stats bar as you can see, while it works, just like with my number incrementing the movement it's just way too jumpy, I need to learn how to fix the FPS issues properly so it's all nice and smooth. What's interesting for me is that it tends to get worse the higher the difference is between the number changes, it also seems to work mildly better when the window is a higher resolution.

#include <iostream>
#include <SFML/Graphics.hpp>
#include <sstream>

int main()
{

    sf::RenderWindow window(sf::VideoMode(800, 600), "");

    int healthstats = 1;


    sf::Font arial;
    if ( !arial.loadFromFile ( "arial.ttf" ) )
    { }

    sf::RectangleShape health ( sf::Vector2f ( healthstats, 5 ) );
    health.setFillColor ( sf::Color::Cyan );
    health.setPosition ( 20, 10 );

while (window.isOpen())
{
    if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::A ) )

    {
        health.setScale ( healthstats, 5 );
        healthstats = healthstats - 1;
    }

    else if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::D ) )
    {
        health.setScale ( healthstats, 5 );
        healthstats = healthstats + 1;
    }

sf::Event event;
while (window.pollEvent(event))
{

if (event.type == sf::Event::Closed)
window.close();
}
        window.clear();
        window.draw ( health );
        window.display();

    }
    return 0;
}
 

Edit: For the record, I do have the source code from the SFML book so I probably just need to take a closer look at it all to get it working properly in the context of my own programs, this is what I'm working with.

void Game::run()
{
        sf::Clock clock;
        sf::Time timeSinceLastUpdate = sf::Time::Zero;
        while (mWindow.isOpen())
        {
                sf::Time elapsedTime = clock.restart();
                timeSinceLastUpdate += elapsedTime;
                while (timeSinceLastUpdate > TimePerFrame)
                {
                        timeSinceLastUpdate -= TimePerFrame;

                        processEvents();
                        update(TimePerFrame);
                }

                updateStatistics(elapsedTime);
                render();
        }
}

It's probably time I obeyed the SFML book a bit more and got some seperate files and classes running so I know how it's all done.
« Last Edit: August 14, 2013, 10:44:16 pm by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #103 on: August 16, 2013, 02:10:10 pm »
I asked about timestep etc. on another forum and I got what I thought was an extremely good explanation about it, I'll post it up here for people to have a look at.

Quote

Foxpup ( User on Bitcointalk )

"TimePerFrame" is a constant that you should set to whatever your game needs, eg if you need a constant framerate of 50 fps, you should set it to 20 (assuming the clock returns values in milliseconds; I think it does, but I'm not very familiar with SFML).

Then, with every iteration of the loop, it looks at how long it's been since the last time the game state was last updated, and if it was longer than 20 ms (or whatever you set for TimePerFrame), it runs the update() function (possibly multiple times, if your render framerate is slower than your game framerate, so it needs to update multiple times per frame).

The update() function is where you do your actual updating of the game state, eg incrementing the position of moving objects, applying health damage, whatever it is you need to happen in your game.

Finally, after all that, render() is where you put your actual rendering (screen drawing) code. A more advanced version of this code (which you should not attempt until you get the basics working) would have render() take timeSinceLastUpdate as an argument, and use it to do interpolation of moving objects (ie, don't draw them where they are, but where they will be timeSinceLastUpdate milliseconds from now; this allows for smoother animation, but since you're only drawing them in a different position instead of actually moving them, rounding errors will not accumulate).

One major problem with this code that you need to be aware of is that it will livelock (the technical term for what is referred to in the article as the "spiral of death") if TimePerFrame is less than the time it takes to run the update() function. Don't set TimePerFrame too low!

« Last Edit: August 16, 2013, 02:11:43 pm by Lethn »

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #104 on: August 16, 2013, 02:25:02 pm »
You can also look pretty much anywhere on google and find that too:
http://gafferongames.com/game-physics/fix-your-timestep/
http://fabiensanglard.net/timer_and_framerate/

It's very well known method.
Even my Man uses that and might spiral into semi-deadlock(in theory, in practice it won't ever):
https://github.com/FRex/Man/blob/master/src/GameState.cpp#L134
« Last Edit: August 16, 2013, 02:31:10 pm by FRex »
Back to C++ gamedev with SFML in May 2023