CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2011
    Posts
    25

    Question Object Managment

    I do have some code for this but i forgot to grab it so ill have to add it later. I'm working on a game engine... funny its my first real project im doing other than a few other small ones, but i learn better with experience so i might as well learn a little bit of everything. Anyways im trying to make a object managment system and im stuck on how im gonna hold the objects and their information. Each object will have its own individual ID 1,2,3,4,5,6,,7,8,9,10,etc. But then (most) or probably all have to hold more information such as color and weight for some of them. But the only thing I can think of is a normal array as im pretty sure that none of the stl arrays can hold more than one matching piece. One alternative could be that whenever an object is created the creator would have to give it a name and that would be the name of the array. Or should each object just be made as a class and then just have another declaration of the class made when you want to have it exist. Also I have a couple more questions...

    - What is the difference between these two methods and when and where should i use them if there is one:

    Code:
    class ObjectManager
    {
     public:
         int Start();
     private:
         
    };
    
    ObjectManager::Start()
    {
    char ObjectManagerStatus;
    }
    Code:
    class ObjectManager
    {
     public:
         int Start();
     private:
         
    };
    ObjectManager ObjMan;
    
    ObjMan.Start()
    {
    char ObjectManagerStatus;
    }
    Also do I have too put what the function Start() does in a .cpp file or can I just put it all in a header file. Every Obect will also have its own individual Id for when there is a clone of itself.
    Last edited by HavingPhun; February 24th, 2012 at 08:19 PM.

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Object Managment

    Quote Originally Posted by HavingPhun View Post
    I'm working on a game engine... funny its my first real project im doing other than a few other small ones
    Building a game engine is complex and requires experience. I would start with some smaller, more concrete projects to learn C++.
    Quote Originally Posted by HavingPhun View Post
    Anyways im trying to make a object managment system and im stuck on how im gonna hold the objects and their information. Each object will have its own individual ID 1,2,3,4,5,6,,7,8,9,10,etc. But then (most) or probably all have to hold more information such as color and weight for some of them. But the only thing I can think of is a normal array as im pretty sure that none of the stl arrays can hold more than one matching piece.
    What is the purpose of this "object management system"? It's no problem to keep objects of different types in a container as long as they are derived from the same base class. But that means that the functionality of all these objects should also be accessible through the base class (using virtual functions).
    Quote Originally Posted by HavingPhun View Post
    Or should each object just be made as a class and then just have another declaration of the class made when you want to have it exist.
    That doesn't make any sense. An object is an instance of a class. You create classes at compile time; objects are created at run-time.
    Quote Originally Posted by HavingPhun View Post
    - What is the difference between these two methods and when and where should i use them if there is one:
    Neither are valid C++, so which 'methods' do you mean?
    Quote Originally Posted by HavingPhun View Post
    Also do I have too put what the function Start() does in a .cpp file or can I just put it all in a header file.
    You can inline functions in a header file either by writing the function definition in the class definition or prefixing the function definition with the 'inline' keyword. However, you should only do that for small (one-liner) functions to improve performance.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Sep 2011
    Posts
    25

    Re: Object Managment

    I think your right about me starting with something smaller. I dont think im really sure i know what im talking about. Also I didnt mean an object in cpp. But an object such as a ball or a cube, etc. But programming it to exist in the game\program. I would want to be able to manage there stats. So would that make more since now. Also what kind of thing should i make first as a easy project?

  4. #4
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Object Managment

    Quote Originally Posted by HavingPhun View Post
    Also I didnt mean an object in cpp. But an object such as a ball or a cube, etc. But programming it to exist in the game\program. I would want to be able to manage there stats. So would that make more since now.
    You can write classes Ball and Cube, but if you want to have 2 cubes you don't define an extra class, you just create two Cube objects. How to 'manage' those objects is about application design. Before delving into that I would suggest you get yourself familiar with the techniques by writing programs where most things are fixed in the code. So, if you want two cubes, you write
    Code:
    Cube cube1;
    Cube cube2;
    inside a function and then do something with them.
    Quote Originally Posted by HavingPhun View Post
    Also what kind of thing should i make first as a easy project?
    That depends on how much you have learned, but in principle it can be anything. I remember writing all kinds of simple games before I even learned how to write classes.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  5. #5
    Join Date
    Sep 2011
    Posts
    25

    Re: Object Managment

    Ok thanks. Also I still need to learn alot more about physics and graphics to make it. Also Im starting by making the graphics system with opengl. Do you think I should switch to directx eventually or not? Also what are the advantages of each other. I know that opengl 3.0/4.0 are supposebly as good as directx, is that true?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured