Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 24 Oct 2010
Offline Last Active Nov 26 2015 10:36 AM

Posts I've Made

In Topic: Forget stuff when learning a new programming language.

27 October 2015 - 04:04 PM

90% of programming c++ is the same in other langauges. The memory management stuff is not in java but it's not a big deal if you can remember about pointers and allocation/deallocation. I wouldn't worry about it much.


I programmed c++ for 3-4 years then took a year programming only c#. When I went back to c++ for a project at first it was a little weird but it all came flooding back in as I started working within an hour it felt like home again.

In Topic: C++ Passing an unknown class as an argument to a function

26 October 2015 - 10:39 AM

Like other people have said this question is very vague. I am suprised though that no one mentioned you could pass a void*. This allows you to pass the address of any class. However if you want to actually use this class you will need to convert it to something useful with casts.

In Topic: Newbie looking for a high level explination of the systems that make up a mod...

23 October 2015 - 09:27 AM

This book is awesome.



In Topic: Need advice on class responsibilities/information flow in game loop

17 October 2015 - 10:54 PM

I'd go the static class route. Since you won't have multiple "controls" there's only 1 player performing input at all times, this would indicate a good section of code to use static and/or singleton structure. This would enable anyone to query the state of the control system without having to be directly passed a pointer to it, just don't allow anyone to modify the state of the control system, probably only the "Game" class or message loop.


If you look into sfml and/or Unity, they both do this.


As far as this stuff.


Basically the question is : Is it a better mix of practice and performance to have

a) classes have direct pointers to eachother, regardless where they are in the hierarchy and regardless how chaotic the endresult is (dozens of child classes pointing to eachother) or

b) member classes access other classes by taking a detour and jumping through their "superior class" (in this case : StateGame) or

c) should instead the "parent" class (StateGame) distribute the info (in this case : pointer to player) to its member classes (in this case Controls)?


a) and b) would mean that each frame the game would loop trough all member classes, which then request player info from their parent class (StateGame)
c) would mean that each frame the StateGame class would loop through all member classes and the parent would distribute all the info the children need


What you need to think about is simple. Do the objects you are creating via new, have a owner. For example, when a game loads a scene it loads the textures/meshes/audio files and whatever else at level load. This means that any of the game objects in the scene that use these assets are referencing something that will be guaranteed to exist. So the game objects could just have pointers to those assets as the system they are in guarantees their life, therefor passing an asset pointer to a game object is not a "tangled mess" but a very well structured program, and very efficient too!


However your game objects could be destroyed at any time, say by player interaction, or game play scripts. This means their lifetime is not determinate. If one game object wants to keep track of another that could be destroyed at any time. There must be some kind of system used such as a smart pointer (shared_ptr/weak_ptr, intrusive_ptr(boost)) or some other reference counting or memory management system.


In the system described above the Scene would load all assets, then load the game objects that use those assets. When the scene is destructed, it will do that in reverse automatically as per the standard. So you see you can guarantee therefor use naked pointers to assets within the scene.


The point is, what objects do you know for sure have certain lifetimes/ownership? Use this to your advantage.

In Topic: xml file reading trouble

17 October 2015 - 10:26 PM

try make_unique<pugi::xml_document>() for instantiation and replace .push_back with emplace_back.