Jump to content

  • Log In with Google      Sign In   
  • Create Account

Noxil

Member Since 27 Sep 2010
Offline Last Active Nov 08 2015 09:50 AM

Posts I've Made

In Topic: Code Review(?) C++ OpenGL

16 July 2014 - 06:22 AM

Out of curiosity, what is the benefit to doing it the other way. Is it for clarity, or is there another reason?

Id say for clarity.
It sure will make it easier to work with in the long run.

 

 

Use const for input parameters in functions that you know wont change.

Example "void UpdateWorld(const float deltaTime);"
For example in your planet constructor you have a int objtypes, thats a perfect case for where it should be const.
Const can be abit tricky to see the point of in the beginning. But for me, its really great. It makes the code more clean and it prevents mistakes.

 

 

That's not the best example though, since deltaTime is already copied by value (so const here might have some meaning to the programmer such as "there is no reason to ever modify the deltaTime variable inside UpdateWorld" and some people like to do it for this reason, while others think it's ridiculous, but it can't possibly affect the function's behaviour). There is no real consensus on this use of const.

 

You are correct Bacterius, it was a bad example. Thanks for clarifying.


In Topic: Code Review(?) C++ OpenGL

16 July 2014 - 03:04 AM

Hey great work, i just briefly looked over main.cpp and planet.cpp.
And what caught my attention from the get go was functions like, SoftCollide, HardCollide, ObjClicked etc etc. Instead of sending in the object you want to operate on you are sending in the index. I would recommend sending in the object directly. So it would look something like this "void SoftCollide(Planet * planet);"

 

And i would also like to point out the usage of const. I understand it might be a hot topic where each person have his/her own idea of whats best.

But id like to suggest to try it out.
Use const for input parameters in functions that you know wont change. 

Example "void UpdateWorld(const float deltaTime);"
For example in your planet constructor you have a int objtypes, thats a perfect case for where it should be const.
Const can be abit tricky to see the point of in the beginning. But for me, its really great. It makes the code more clean and it prevents mistakes.


In Topic: Setting up VS2012 with Directx11 (multiple projects)

14 December 2013 - 09:51 AM

Thank you so much.
It was a library missing... 

 

Case closed :)


In Topic: Template content manager in c++

29 October 2013 - 05:03 PM

This can surely be done in a simple manner.

// Base class for all resources
class Resource
{
public:

    virtual void Load(const std::string & sourcePath);
    virtual void Unload();
};

// Resource manager
class ResourceManager
{
    std::map< std::string, Resource * > m_Resources;
public:

    template< class T >
    T * GetResource(const std::string & sourcePath)
    {
        if(m_Resources[sourcePath] != 0)
        {
            return dynamic_cast< T * >(m_Resources[sourcePath]);
        }

        T * newT = new T();

        newT->Load(sourcePath);
        m_Resources[sourcePath] = newT;
        return newT;
    }
};

So what happens is when you use the resource manager to get a resource.
It will first check to see if we have already loaded the resource and try to return that one.
If we havent loaded it, load it and store it so we later on can get it.
 

void Engine::Init()
{
    ResourceManager * resourceManager = GetResourceManager();
    TextureResource * textureResource = resourceManager->GetResource< TextureResource  >( "path/to/texture.png" );
}

As you can see above, its very straight forward how to use it smile.png

What is also worth mentioning is that in this example im using std::map to store the resources. You should really experiment with different types of storage to find whats best for your needs. 


In Topic: I need a C++ Mentor.

07 September 2013 - 02:19 AM

Learning C++ can be quite hard in the beginning.

I my self had some problem even when following a book.

 

But one thing that helped  me was that if i read something in the book, for example "how to use functions".

Id try and remake what i have done before, but with the new information if possible.

 

Lets take the hello world as an example.

Regular way:

void main()
{
     std::cout << "Hello world" << std::endl;
}

Functions way:

void HelloWorld()
{
     std::cout << "Hello world" << std::endl;
}
 
void main()
{
     HelloWorld();
}

Then when i got that working, i experimented before moving on.

For example, what happens if i write another row after HelloWorld(); with another HelloWorld();

For me, it was by trying out things like this, that was the "Aha" moment for me smile.png

 

Later on in the book you will come across more complicated examples.

But dont worry if you dont get it the first time. Just write down the examples, try to run them.

Try to experiment and try to do your own tweaks and adjustments.

 

What i want to convey is that, for me, the best way of learning something new is to experiment.

Get your hands dirty so to say :)


PARTNERS