Jump to content

Furbolg

Members
  • Posts

    243
  • Joined

  • Last visited

Posts posted by Furbolg

  1. You should name your #define macros like XXX_INPUT, where XXX stands for your project or your favorite name.

     

    That's also a good scenario why c++ programmer use namespace and why "using namespace" shouldn't be in header files (if your #define would be a const int input = 0x01 for example and windows.h (or some other header) using the same variable name, you would have similiar problems).

     

    Good to see, you could resolve your problem *cheers*

  2. No pre-coded system on the planet can know what I'm doing with my code better than my own flow of thought.

     

    Auto completion is just suggesting what you probably want to write.

     

    I dont understand these kind of guys like you, "i just use notepad" ... sure just do it if you want. But when you don't want to see to improvement in workflow with auto completion, high lighting and refactoring ... then sorry but you are living in the 80s (hungarian notation *wave*).

     

    Why not use these helpers ? There is enaugh hard stuff to care about in programming, why not use this comfort and concentrate on the important stuff ?

  3. Wow ... really good tutorial aggror smile.png

     

    You are right about XML its a good format because you can change your level format in a minor way without messing up your loading routine. The problem with XML is its size, i would prefer a binary level format in the final result/game (with stream::writeint etc) because its faster to load.

     

    // edit:

     

    If you want to see a real bloated XML file, have a look at an animated complex Model in COLLADA Format... its the worst i've ever seen...

  4. Hi Aggror,

     

    good c++ classes tutorial, thanks for mentioning me wub.png Am i famous now ? wink.png

     

    I just get some suggestions:

    - when you speak from a class: it's definitely method not function

    - you can use "using namespace leadwerks;" within cpp files (it's bad style to use it in a header because everyone that includes your header also get this "using namespace xxx;" to work with... within cpp files it doesnt matter)

    - std::string::c_str() is from the Standard Template Library (STL) not c++ (im a bit of smart *** ohmy.png) and stands for const string

     

    Im a also doing something like this:

     

    class foo()
    {
    // C'Tor / D'Tor
    public:
    foo();
    ~foo();
    // Methods
    public:
    void method();
    };
    

  5. Try this one:

     

    CComponent

    
    #ifndef CCOMPONENT
    #define CCOMPONENT
    
    class GameObject;
    
    class CComponent
    {
    public:
    CComponent();
    CComponent(GameObject* parent);
    ~CComponent();
    
    int ID;
    GameObject* parent;
    virtual void Init() = 0;
    virtual void Update() = 0;
    virtual void Draw() = 0 ;
    bool enabled;
    };
    
    #endif
    
    

     

    GameObject

    
    #ifndef GAMEOBJECT
    #define GAMEOBJECT
    
    #include "Leadwerks.h"
    #include <list>
    #include "CComponent.h"
    
    class GameObject : public CComponent
    {
    public:
    GameObject();
    GameObject(GameObject* parent);
    ~GameObject();
    
    void Init();
    void Update();
    void Draw();
    void RemoveComponent(CComponent* component);
    void AddComponent(CComponent* component);
    
    //holds all the components of that game object
    list<CComponent*> components;
    };
    
    #endif
    

     

    You have to add the GameObject Header include in the CComponent C++ File ( #include "gameobject.h" in ccomponent.cpp).

     

     

    Sorry for double post :(

    • Upvote 1
  6. thanks for the help Rick.

     

    I got rid of the error in the CComponent class, but the one in GameObject is still there. This is how the GameObject looks now:

     

    #include "CComponent.h"
    class CComponent;
    class GameObject : public CComponent
    {
    

     

    You done it the wrong way, as rick mentioned you cant use forward declaration (btw. you are using forward declaration and the CComponent header file... this can't work) as a normal class (inherit from it) just as a pointer.

     

    Your CGameObject has to include CComponent the normal way but your CComponent has to use forward declaration.

     

    Forward declaration works like this:

    //test.h:
    class cgameobject;
    class ccomponent
    {
       public:
       ccomponent(cgameobject* obj);
       private:
       cgameobject* gameobject;
    };
    
    // test.c++
    #include "test.h"
    #include "cgameobject.h"
    ccomponent::ccomponent(cgameobject* obj)
    {
     this->gameobject = obj;
    }
    

  7. Forward declaration is the solution but as rick mentioned you can only use pointers.

     

    You should avoid circular dependencies whereever possible.

     

     

    // Edit:

     

    You should also avoid "using namespace xxx;" in your header files, it can happen that you use another library and as soon as you include your header it will have multiple classes / types with the same name.

     

    Use "using namespace xxx;" only in c++ files.

     

    (of course your code will work but its bad style and you CAN run into problems later)

    • Upvote 1
  8. Could you explain why it irritated you? Since it is static I figured it wouldn't really matter whether is was public or private.

     

    I didnt realized it is a class ;)

     

    Ah thanks. I actually had a working sample of this in a school project. I simply forgot the class 'Test::' before the static variable in the cpp. I actually don't have to set it NULL. It works perfect like this as well:

    Leadwerks::Window* Test::window;
    

     

    Only in debug mode, try this in release mode and you will wonder what an uninitialized variable can do.

  9. Can you post more / attach a sample project ?

     

    Right now, im am wondering: why you declaring "window" two times (in *.h and *.cpp) ?

     

    // Edit: (your "public:" irritated me wink.png)

     

    Sorry my mistake, Rick is right you have to initialize the static variable and not just declare it because the static variable exists (or can exists) before your class does.

  10. Maybe have a look at your "competitors" and look what they did. Maybe you can gain some ideas from it wink.png

     

    I mean you can do what you like, for example:

     

    -Bomberman

    -3D Tetris

    -Counterstrike 2D

    -Scrabble

    -Yatzee

    -Sodoku

    -Four wins

    (for the oldschool: Hangman)

     

    etc..

  11. You can also realize small parts of your game, for example networking (with some cubes), terrain/environment, ai... just split your big project in some smaller chunks and try to realize them.

     

    Just my 10 cents.

  12. Typedef is just a shorter form / comfort:

     

    (these example are from a dll (plugin system) and i dont put in c++ casts, they would make it harder to understand)

    Typedef:

    // define the type
    typedef int(__stdcall *CallBack)(void);
    // use it to load the method
    CallBack callme = (CallBack)::GetProcAddress(hDLL, "somecallback");
    // call the method
    callme();
    

     

    Without:

    // use it
    int(__stdcall *CallBack)(void) = 0;
    CallBack = (int(__stdcall*)(void))::GetProcAddress(hDLL, "somecallback");
    // call it
    CallBack();
    

  13. Just try and post your statement in a c++ forum.... but take cover wink.png

     

    Is it a problem ?

    For c++ programmers (the guys who love c++ and not only use it because of speed/portability): yes

    For the big part of this community: probably not

     

    But you mentioned a messed up callstack, this can't be happening when used correct c++ patterns (mcp posted).

     

    // edit:

     

     

    Josh using the doc posted for object::addhook (link here http://www.leadwerks...ectaddhook-r759). My code now compiles but throws the above mentioned runtime error. MPC says this error needs to be fixed in the LE3 source code for OS X b/c it apprently works for windows according to rick.

     

    It is working but the behavior is undefined, it can work on windows but dont work on *nix.

  14. What else would they be? It's just a memory address.

     

    If you argue this way then let me ask: whats the difference between integer and string ?

     

    In theory (assembler) you are right josh but c++ has some patterns / behavior which define some basic rules. You can't just take the ones you like and ignore the rest.

     

    // Edit:

     

    LE3 is a C++ library now so there is no harm in doing this.

     

    To be honest, its actually more C/C++ then C++... dont take it personal, please.

×
×
  • Create New...