Dejai's First Game Framework

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Dejai's First Game Framework

Post by dejai »

Hello everyone,
I have made my first game framework, partially based of irrwizards concepts. I didn't actually use any of their code, but I did take some class and naming conventions into practice. Anyway I have made my first game framework, and its looking good.. or so I think but I am not sure why it does not run a really simple test I have included in the source. I would really appreciate anyone that would take a look at the source and tell me what I am doing wrong, and what I am doing right.

Things to add:

I want to add, the same concept from irrWizard of.

Code: Select all

IrrlichtDevice* getDevice();
IrrlichtDevice* m_pDevice;

inline IrrlichtDevice* GameManger::getDevice()
{
return m_pDevice;
}
So any advice would be greatly appreciated.


Source can be download from the following link.


http://irrlicht.dejaigames.com/download ... ai/src.zip[/code]
Programming Blog: http://www.uberwolf.com
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

I somehow don't like your design having a separate device for each GameState (at least seems so for the moment?).

Ignoring that part I wouldn't set up the GameManager's members inside your (SpecificGameState)::CreateDevice();

Instead use a pointer to the GameManager as a local member and pass the Irrlicht device as to the GameManager constructor. The GameManager's constructer will then init its own local variables etc.

As a general note (imo a not that dumb one :)):
Try to avoid function calls or statements containing more than one "." or "->". Especially when using local variables there might be better way making your classes less dependent on each other.

Also I'd try to create some kind of base class for your gamestates first.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

You can't expect us to look through all your code so I'll just mention things that poped into my eyes:
1. int GetState(State& GameState); should return a State reference.
2. Why not logging with the logger class instead of printf.
3. bool Continue; // Determines the loop -> I don't like the name Continue as a variable..
4. while (m_GamePlay.Continue = true) -> you ain't checking Continue's value, you use only one '='..
5. while (m_GamePlay.Continue == true) -> while (m_GamePlay.Continue)
Last thing, I don't like using enums for game states as a game state is a much more complex object then an enum (but not that complex in general) thus require being a class.

Nice work there though but I recommend trying to design bit more before you jump on coding as listening to this advice rocked my world :lol:

Edit:
Decide a naming style and keep it like that so you won't have vars like m_pDevice, m_pGameManager and IrrlichtDevice, GameManager. Decide one way you're going to name everything and do it like that in every place in your code. Same thing bout methods.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

MasterGod wrote: Last thing, I don't like using enums for game states as a game state is a much more complex object then an enum (but not that complex in general) thus require being a class.
Enums for states are fine.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

@CuteAlien: I meant specifically Game States, not states in general as for that enums are fine as you said..
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Hello everyone thanks for the feedback.
Firstly to Ico I am confused I am trying only to use one device. What I am trying to do is for GameManager to hold the device and for it to pass it to all the GamePlayEntity Classes so that they can use the device. GameManager, just managers general things about the engine. The GamePlay class is supposed to be the main source of Game Related Information.

Ugh, I am a bit confused now I will have to relook at my code.
Programming Blog: http://www.uberwolf.com
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Oh Mastergod, answering part of your question, that Continue is a temporal thing, the exact code is going to be (m_PlayGame.Update() == true)

I just didn't know how to implement it.
Programming Blog: http://www.uberwolf.com
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Taken a closer look now and it's still a little bit confusing.
It's already past 0 am here and I'm a little bit sleepy but just wanted to finish this while watching TV. So I'm sorry if I misinterpreted anything. :)

-----

The calling path is a little bit like this (looking at constructor calls only):

Code: Select all

main()
+- CGame Game()
  +- CGamePlay m_GamePlay()
    +- CGameState m_GameState()
      +- CGamePlayBoot m_GamePlayBoot()
        +-CGameManager m_GameManager()
    +- CGameManager m_GameManager()
Now the main loop:

Code: Select all

main()
+- Game.Run()
  +- while
    +- m_GamePlay.Continue (while condition)
    +- m_GamePlay.Update()
      +- mGameManager.m_pDriver->beginScene()
      +- mGameManager.m_pSmgr->drawAll()
      +- mGameManager.m_Gui->drawAll()
      +- m_GameState.CurrentState()
        +- m_GamePlayBoot.CreateDevice()
          +- m_GameManager.m_pDevice = createDevice(...) [!]
          +- m_GameManager.m_pDriver = ... [!]
      +- m_GameManager.m_pDriver->endScene()
Look at the lines marked with "[!]". They do something with the CGameManager object but it isn't the one used by the CGamePlay class (it would have to be on the same level).
Also if I'm seeing this right, your main loop will try to render the scene before setting up the device, driver, etc. That's one of the reasons the code won't work. Also CreateDevice (CGamePlayBoot class) won't work with CGamePlay's GameManager so it will never be able to display anything.

-----

I've seen that you use variables to store your own objects (your classes). This has one big disadvantage: Every place you create such a variable it will keep its own copy of the object.

Just a short example code:

Code: Select all

class B; // content is trivial, just to show you ...

class A {
  B myobject1;
  B myobject2;

  A()
  {
    myobject1=myobject2=B();
  }
}
If you now create an object of class A its members myobject1/2 will each contain one independent object of class B. If you change myobject1 it won't change myobject2. This is the same for variables used in different classes (like your m_GameManagers).

A solution to this are pointers like you used for the Irrlicht classes. But important: Declaring variables using the same name within different classes won't mean that they share the same content.

Code: Select all

class B;
B* myobject1;
B* myobject2;

myobject1=myobject2=new B();
After those lines myobject1 as well as myobject2 will point to the same object/memory area. Don't forget that you'll have to delete objects created using the new operator. An alternative would be using a reference counter class like Irrlicht's IReferenceCounted.

A hint (not meant as an offence or anything similar): Start a new simple project and play a little bit with classes, objects and pointers. Try to create some simple class (maybe a custom vector class that allows you to call methods like GetLength()) and create it, destroy it, try to base it on IReferenceCounted, etc. just to get used to it. Then after you've done this, continue working on your game engine. This should save you a lot of trouble and time as well. :)
If you want, take a look here: http://www.cplusplus.com/doc/tutorial/pointers.html
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Thanks for the help Ico, I didn't take any offence I am confused about my own code lol. Ah so I have called to use the device without creating it and then I have used another object haha, ok thanks for the help :D
Programming Blog: http://www.uberwolf.com
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Oh Ico this is not a game engine its a Game Framework for a really simple FPS, sort of like Jps Battle Heart...

Yet I am sure his will still be more complicated than mine.

I have updated the src, it now loads all the managers, and shows the window but then crashes, and I think I am using the same device for my loop as my create device,

Code can be found at http://irrlicht.dejaigames.com/download ... cts/Dejai/

its src2.rar

Thanks for any more help suggestions on the issue.
Programming Blog: http://www.uberwolf.com
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Still similar problems:

#1: Move your "CurrentState()" call within "CGamePlay::Update()" to the beginning of the method - other way you'll call the driver before creating it.

#2 CGamePlay has a local variable "m_pDriver" but CGamePlayBoot still uses its own.

#3 "CGamePlayBoot::CreateDevice()" is missing a return value.

-----
I'm not familiar with devcpp but you might want to try Microsoft's Visual C++ 2008 EE (if running under Windows). It's for free to and you'll get a debugger you can use to stop on such crashes and take a look on your objects/variables and see what their value(s) were right before crashing.

Btw. this thread should really be in one of the other forums. :)
dejai
Posts: 522
Joined: Sat Apr 21, 2007 9:00 am

Post by dejai »

Ya,
Thanks for the help, it started out on the right track but then the framework was not functional.
Programming Blog: http://www.uberwolf.com
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post by Midnight »

lol this is great I've been R&D on this subject for 6 months now and in the end I decided that states within classes are total poop.


I'm just gonna make all my poop proceedural in the main loop and forget about having oop gamestates that improperly contain and conjunct code.
Post Reply