Jump to content

  • Log In with Google      Sign In   
  • Create Account

chondee

Member Since 13 Jan 2012
Offline Last Active Jul 04 2013 08:14 PM

Topics I've Started

Custom cout formatting using /tags

09 May 2012 - 01:41 AM

Hi,

In my game engine I output stuff for debugging purposes to the windows console using std::cout.
I wanted to use colors so I can more easily oversee what is going on, as well as some "macros" using /tags.
Let me show an example of what I am talking about:

myCout << "/warn Entity: "<< EntityName << "is doing /fgRed badstuff \n";

would output:

Warning: Entity: obj1 is doing badstuff


The way I have this is that I parse a stringstream.str() and send that string to my function that will format it and output it, but it currently looks like:

mysstream << "/warn Entity: "<< EntityName << "is doing /fgRed badstuff \n";
myCout(mysstream.str());

Obviously, I don't want to do this for every output, I want to use my output function just like std::cout, having the functionality of the same << operators, but does my formatting also.

How could I achieve this?
Your help is much appreciated!

EntityID String<->Int resolution

20 April 2012 - 11:54 PM

Hi,

I am working on my component based engine, and trying to implement an entityID system.
The way I am planning it is that each entity and component has a unique int ID and a unique string ID.

I thought of two ways to implement this, but not sure which would be better:


1. Each entity has their own map.
The entities are stored in a std::map<int, string> and components inside entities are also stored in a std::map<int, string> (there are multiple maps)

2. There is only 1 (or a fixed number of) global maps that resolves everything.
The entities and components only contain an int ID, on creation their string ID is going to be added in a single global std::map<int,string> that will resolve any id access by string. (or perhaps 1 map for entities, 1 for components)


For my peace of mind I would be more comfortable of knowing that all string IDs are stored in a single place, but not sure if it is a good idea, since it will take a longer time to search through a big global map to find a string.
On the other hand, I would imagine entities would be called with their int IDs, and their string IDs would be used more for debugging, so it wouldn't make a big difference (I might be completely wrong on this one.)

I would appreciate any suggestions on this.
Thanks in advance!

EDIT: Also, is it a good idea in general for each entity to contain a string id, or no, because it is inefficient?

Component based >? Inheritance based design

12 April 2012 - 11:49 PM

I am working on a scrolling shooter in C++ / SFML, and without knowing anything about component and inheritance based design, I have intuitively started designing my engine and game objects that mostly resembles to inheritance based design.

I have stumbled upon a discussion about this then did some further research, and got to the conclusion that mostly in the 90s Inheritance based design was used in game development, but later on due to several reasons the standard shifted towards component based design, most modern games use that, and that I should probably consider rewriting what I already have following that (since I am mostly doing this for learning).

1. First of all, I would like to ask those who have some experience in this, whether this is mostly true. So is component based design in game development preferable in most cases against inheritance based, or is it not that simple? Are there cases when the opposite is true?

2. Could some of you please recommend me some material about game development related component based design?
Probably the ideal and best thing is to read through some huge book, but for me that doesn't really work when I am introduced to a new idea. It would be much more helpful if I could look at some smaller working examples, a few-page article, perhaps some general rules of thumb, stuff to look out for, or some direct comparison with inheritance based design.

Any assistance / shared opinions, experiences on this subject will be much appreciated.
Thanks in advance! Posted Image

Pointer and Value interchangeability

12 April 2012 - 01:41 PM

Hi,

I am not sure if this is the most fitting title for what I have going on, but couldn't think of any better.

I am working on a 2d scrolling shooter, and the way I have designed my entities/game objects, many times I encounter situations where I wish I could just use some variables/objects without having to know about it if it is a pointer or value. Now, I know this sounds really weird, but let me give an example:

I have a game object, destroyable.

It has a lists of colliders: shields, hull, weakPoints

if a shield is hit the damage is calculated based on the shield's own material properties, and the damage is exerted on the shield itself, not on the main destroyable object.

if a hull collider is hit the damage is calculated based on the destroyable's material properties (so for material they don't have their own, they need a pointer to the destroyable's material) and the calculated damage will be exerted on the destroyable (so they need a pointer for the destroyable's integrity, they don't have their own)

if a weakPoint is hit the damage is calculated based on the weakPoint's own material properties, but the damage exerted will be on the main destroyable, so they need a pointer for the destroyable's integrity.


As you can see the process of collision handling and taking damage is exactly the same in all three cases,but since in some cases a pointer to an object (material or integrity) needs to be used, and other times the actual value, each case needs to be treated separately and for all the combinations a separate function needs to be written.


Is some way I could make this such that when I give an integrity object or material object to a collider it can be treated either as his own, OR as a pointer to his parent's material or integrity?

For example I would just like to make the takeDamage function, in general as:
integrity -= collider.material.takedamage(&damagesource); without knowing that the integrity and the material is the collider's own, or it is a pointer to his parent's property

I would appreciate any assistance on this.
Thank you in advance!

Virtual function call to child class (Please Help)

19 February 2012 - 12:16 AM

<SOLVED> I was doing something wrong, unrelated to what I thought the problem is..

Hi,

I am writing a simple particle engine for my game, and for performance reasons, instead of having one type of particle class for every type of particle, I now rewrote the code, such that there is a Particle base class, and many Particle child classes (flash, smoke, explosion, flame).

All the different kinds of particle objects are stored in a
std::vector<unique_ptr<Particle-base>> v_particles;

I want to update all the particles in one loop, like this:
void Player::update_particles()
{
for (v_particles_it = v_particles.begin(); v_particles_it != v_particles.end(); v_particles_it++){
  (*v_particles_it)->Update();
}
}

Each different child class of Particle-base have their own Update() function.

I want (*v_particles_it)->Update(); to call the Update() function of each particle's respective Update() function, NOT Particle-base's Update() function.

If I don't include an Update() function for Particle-base, I get a compiler error (even though all particles in the vector are child objects), or if I define it as virtual void Update(), it only calls Particle-base's Update() function.

I don't have too much experience in inheritance, I know I am most likely doing this wrong.
Could someone please help me how I should set up the base and child class' functions so they are called the way I described above?

Thank you in advance!

PARTNERS