Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Zeet's first 3d game engine project.  (Read 2328 times)

zeet

  • Bay Watcher
  • Programming lunatic.
    • View Profile
Zeet's first 3d game engine project.
« on: June 18, 2011, 08:45:18 am »

Hi, I'm zeet, I'm a long time lurker, but only recently joined this marvelous community.

Anyway, I'm kind of a novice graphics programmer, and want to learn more about graphics programming, the best way I felt I could do that was by creating my own little 3d engine, and since this is a creative project, I felt it would make a great thread.
Now, I am not trying to create some über optimized 3d engine capable of challenging Unity or UDK. But rather my own little thing so I can point at the screen and say: "I made this."

A little info about the project:
  • Written in c++.
  • Using SDL for painless window creation/input events and threading.
  • SDL_image for texture loading.
  • OpenGL for graphics.

Now first step was to create a game entity/object class of some sort, to contain and execute game logic code. Some call this a scene graph, but considering I want them to exist in a scene without actually physically being anywhere I call them objects instead.
Anyway, the point of these objects is to execute game logic code, this way game logic will not bloat the rest of the engine.
So each game object has four redefinable functions, or so called virtual functions, called Initialize, Update, Draw, and DeInitialize where, for an example, Initialize is called upon adding a new object to the scene etc. basically, all you need to do to create a new object, is to make a new class and inherit the object class.
I realized quite fast that because c++ static language, and because I don’t like to have game logic variables in the basic game object, you would need to know exactly what class objects are to be able to access other objects’ game logic variables.
To solve this I designed a parameter class, which every object has. This way it is possible for an object to simply declare a few parameter on initialization, for an example:
Code: [Select]
class Example : object{
        int MookHealth, MookDamage;
        Public:
        bool initialize(){
                CreateParameter<int>("HP",&MookHealth);
                CreateParameter<int>("Damage",&MookDamage);
                return 1;
        }
}
Other objects could then access them by calling a GetParameter function, in my opinion it is more elegant than having to
Code: [Select]
redefine_cast<Example>(objectPointer)->MookHealthEven if my solution is slower.

I then created a window manager class, I won't be getting much into that since it's basically just a class that wraps around SDL's window functions. I also made a Game class which keeps track of FPS and updates all objects.

To tests out the object system I made a basic object that sets the window caption to current FPS.
Code: [Select]
class FPSTest : object{
string FPS; char _str[5];
public:
bool update(){
FPS = "Game engine. FPS: ";
sprintf(_str,"%d",Game.gameFPS);
FPS = _str;
return 1;
}
bool draw(){
Game.gameWindow.SetCaption(FPS);
return 1;
}
};

And voila, we now have a window:
Spoiler (click to show/hide)
(I know it's not much, but it's a start..)

If people are interested I will post my progress. I actually have A LOT more of the engine finished, as I started writing it quite a while ago. But I try to keep forum post chronological with the order in which I programmed the engine.

Next time, I will create a input manager class of some sort, we want to be able to INTERACT with our games.

Edited for clarity..
« Last Edit: June 19, 2011, 10:52:28 am by zeet »
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Zeet's first 3d game engine project.
« Reply #1 on: June 18, 2011, 09:53:28 am »

I realized quite fast that because c++ static language, and because I don’t like to have game logic variables on the basic game object, you would need to know exactly what objects you have to be able to access other objects’ game logic variables.

I'm not sure exactly what you mean here?
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

zeet

  • Bay Watcher
  • Programming lunatic.
    • View Profile
Re: Zeet's first 3d game engine project.
« Reply #2 on: June 18, 2011, 10:04:05 am »

Since all objects are derived from the base class, you would need to know what derived class is is to access the derived class variables.
I'm sorry if it was not explained well enough.
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Zeet's first 3d game engine project.
« Reply #3 on: June 18, 2011, 10:13:11 am »

No offence, but if you need to know what the derived class is, then it probably isn't proper OOP.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

zeet

  • Bay Watcher
  • Programming lunatic.
    • View Profile
Re: Zeet's first 3d game engine project.
« Reply #4 on: June 18, 2011, 10:23:06 am »

Nope, probably not.
This is why I am using a parameter class to expose object variables to other objects.
Logged

malimbar04

  • Bay Watcher
    • View Profile
Re: Zeet's first 3d game engine project.
« Reply #5 on: June 19, 2011, 09:27:42 am »

posting to follow. Yes I'm interested, and if you continue along I'll happily try to learn from your work.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...