Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 Oct 2012
Offline Last Active Mar 08 2014 06:52 PM

Posts I've Made

In Topic: Suggestion for a cross-platform C++ 3D game engine/framework

15 December 2013 - 01:27 AM

No one has mentioned gameplay


Also, if you're considering Magnum, I actually have integrated libRocket with Magnum (for rendering). You can look at the code here: https://github.com/miguelishawt/Magnum-libRocket

In Topic: C++11 in class initialization

03 November 2013 - 07:55 AM

Seems to work in GCC (or Clang, or whatever Ideone.com uses): http://ideone.com/WI9JmW



It uses GCC 4.8.1. Just thought I'd mention it.

this only works for static arrays.

And only for the first element. e.g. int array[][] = { 1, 2, 3, 4 5, 6, 7, 8 } does not work, however, int array[][2] = { 1, 2, 3, 4, 5, 6, 7, 8 } } does.

In Topic: Template content manager in c++

03 November 2013 - 07:27 AM

This can surely be done in a simple manner.

// Base class for all resources
class Resource

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

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

    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();

        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. 


That dynamic cast is unnecessary IMO. If you know the type, just use a static_cast, no need to check if it's valid. If it's not then you'll get a runtime error and it's the programmer's fault, not the user's. Also you may want to consider using a std::shared_ptr rather than a raw pointer, or returning by reference and having a Release method.

In Topic: Some pointers please (Entity component systems).

07 October 2013 - 03:39 AM

Pro tip: If you want more people to look at your code, host it on GitHub or BitBucket. That way they can browse it online instead of downloading it completely. I recommend you version control all your projects regardless.


You should really put #pragma once at the top of your code, that way it doesn't get in the way and you can read the necessary code. This is more of a convention, but still. Also, I believe #ifndef/#define/#endif is more portable, so if you want portability use that instead of #pragma once. Although I think most modern compilers support the use of #pragma once.


In your InputComponent, I personally think boolean(*handleInput)(Entity* entity) should be typedef'd, as if you change it, you'll have to change it twice (this can cause annoying compiler errors) and plus you get more readability if you typedef it. e.g. typedef boolean(*HandleInputFn)(Entity* entity). Also what the f*ck is boolean? Did you typedef bool or is this a C++ .NET primitive? Just use bool.


Use initializer lists, don't assign in the constructor. e.g. in your PositionComponent

struct PositionComponent
     int X;
     int Y;
     PositionComponent(int x,int y) : X(x), Y(y) { /* this should be empty */}

And god dammit, use smart pointers. There is more than likely going to be some leaks in your program (I'm not going to check if there is, because I can't be bothered looking for any). Raw pointers should only be used for non-owning objects (i.e. objects that you don't allocate with new/delete).


Also, try to use the stack more often, this isn't Java. In Main.cpp you're allocating objects with new for no goddamn reason. A stack allocation could suffice. For example, your WorldState and GameNode objects are allocated with new when they don't need to be. WHY? You don't even delete them (good practice to, even known they will be deleted on exit of the program, but still), which brings me to the previous point I made: USE SMART POINTERS. 

In Topic: C++ Libraries - Where to find a list ?

07 October 2013 - 03:16 AM

The first place to start is the Standard C++ Library, sometimes (erroneously) referred to as the STL*. This contains lots of libraries relating to containers (lists, arrays, vectors, etc), strings (not a part of the language, but a library) and various other stuff (input/output streams, algorithms, etc).

+1 for linking to en.cppreference instead of cplusplus.com. @OP Don't use cplusplus.com for a reference on the standard library (for one, it's not official documentation).


Also, OP, if you're looking for a particular library for C++ that does something the standard library (or even boost) doesn't offer, e.g. a rendering library, then google it. Google is your friend, you could also try to look on GitHub or BitBucket if you can't find it on google or another search engine.