Sign in to follow this  
HexDump

How to model this with a component based system? (piece of advise)

Recommended Posts

Hi all, I´m starting to code GameItems for my game. I have an Inventory component that I think is almost finished but I have come across a problem. I have a class GameItem that inherits from GameEntity (This is the container of components). I have created a Pistol game item that is using a CRenderComp (this component has the functionality to show a mesh) to show the Pistol, but the problem are the bullets. I want to use a Particle System for the bullets. So, I see some ways to model this with a component based system. 1) Creating a ParticleEffect component, that will allow me to show particle effects controled by this entity (for bullets, explosions, etc...). The problem here is that I end with a RenderComp and a ParticleEffectComp... Strange. 2) Splitting the CRenderComp. I mean, have a CRenderComp base class, and a CMeshComp and a CParticleEffectComp inherited from it. This seems the best option but don´t know if it will bring problems later. So, Could anybody give a piece of advise on this? Or perhaps another aproach? Thanks in advance, HexDump.

Share this post


Link to post
Share on other sites
You are facing two different problems:

1. How should the particle system be modeled in terms of your render component
2. How should the particle system be connected to other objects in your game


You can subdivide your particle system in the emitter part and the render part, you want to be able to use multiple emitters, so the emitter concept is an abstraction, your particle system has an emitter component, and is a render object, note that a particle system is not a mesh so it should not inherit from mesh. So it makes sense for the particle effect component to inherit from your render component (I assume you mean something like IRenderable, render component is confusing, you probably mean an interface), so in general terms:

ParticleSystem: IRenderable
{
IEmitter *m_pEmmitter;
}

So problem number 2 is different, how is a pistol related to a bullet, related to a particle system?

Pistol creates bullet, bullet has a particle system attached to it, pistol should know nothing about the particle system

Hope this helps

Share this post


Link to post
Share on other sites
Hi again,

Well it seems I did not provide all needed information.

I´m using ogre3d as my render engine, so, I can not split the Emitter concept from its render concept. Everything is built in a Particle system (PS) class that offers an interface to do things with it.

When I said that I have a Render Component I just was refering that nowadays I have a component that constructs from a "mesh file". Until now I didn´t need anything more because my game is in early stages, and I build things as long as I need it.

Like I said the problem here is that I can´t split the PS in the two parts you said. So, I have to find a workaround for this. This is why I commented the option of having a ParticleEffect. So, the Pistol entity will have a Render Component (this is the one that holds the meseh of the pistol), and a ParticleEffect component (the Pistol class will know how to handle this ParticleEffect to create bullets).

Is it more clear now?

Note: I understand what you meant by splitting the ps in the emitter concept and the render concept, but It is something I can´t not do, becase as I said I must stick to the ogre particle system that has everything built in.

Thanks in advance,
HexDump.

Share this post


Link to post
Share on other sites
Why would you want to use a particle system for bullets? Usually particle systems are used to create flashy effects that don't interact physically with the game. It could make sense for a flamethrower to use particles to generate the fire effect, although the fire particles wouldn't actually do anything besides create a neat looking effect around the actual damage volume.

Share this post


Link to post
Share on other sites
It's simple, and I know it is a bit dirty. But using particles for my bullets I will be able to reuse particles affectors, etc... to create strange paths, etc... And then do a little raycast (following particle velocity) to see if it collided with something. I think it is a good way to do it, only, just dirty because of the rendering/logic mixing.

Thanks in advance,
HexDump.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this