Game Development Community

Creating a copy of the ParticleEmitter classes

by Lukas Joergensen · in Torque 3D Professional · 05/17/2012 (10:24 am) · 2 replies

Soo i tried to create a copy of the files:
  • particleEmitter.cpp
  • particleEmitter.h
  • particleEmitterNode.cpp
  • particleEmitterNode.h

But after playing a little with it i ended up with a bug that i simply can't get rid of.

First the error message:
Quote:Error 6 error LNK2005: "int TypeParticleBlendStyle" (?TypeParticleBlendStyle@@3HA) already defined in graphEmitter.obj C:TorqueTorque 3D 1.2My ProjectsEmptyProjectbuildFilesVisualStudio 2010projectsparticleEmitter.obj EmptyProject DLL
I looked at it and it is talking about the code:
// Enum tables used for fields blendStyle, srcBlendFactor, dstBlendFactor.
// Note that the enums for srcBlendFactor and dstBlendFactor are consistent
// with the blending enums used in Torque Game Builder.

typedef ParticleRenderInst::BlendStyle ParticleBlendStyle;
DefineEnumType( ParticleBlendStyle );

ImplementEnumType( ParticleBlendStyle,
   "The type of visual blending style to apply to the particles.n"
   "@ingroup FXnn")
   { ParticleRenderInst::BlendNormal,         "NORMAL",        "No blending style.n" },
   { ParticleRenderInst::BlendAdditive,       "ADDITIVE",      "Adds the color of the pixel to the frame buffer with full alpha for each pixel.n" },
   { ParticleRenderInst::BlendSubtractive,    "SUBTRACTIVE",   "Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect.n" },
   { ParticleRenderInst::BlendPremultAlpha,   "PREMULTALPHA",  "Color blends with the colors of the imagemap rather than the alpha.n" },
EndImplementEnumType;

I thought, ok fair the enum can't be defined both places. So first i tried renaming the enum in one of the files, and it gave me the same error.

Then i tried moving the file to an external file and including it in both files. The include file looked like this:
#ifndef _H_PARTICLE_TYPES
#define _H_PARTICLE_TYPES

#ifndef _PARTICLE_H_
#include "T3D/fx/particle.h"
#endif
#ifndef _RENDERPASSMANAGER_H_
#include "renderInstance/renderPassManager.h"
#endif

// Enum tables used for fields blendStyle, srcBlendFactor, dstBlendFactor.
// Note that the enums for srcBlendFactor and dstBlendFactor are consistent
// with the blending enums used in Torque Game Builder.

typedef ParticleRenderInst::BlendStyle ParticleBlendStyle;
DefineEnumType( ParticleBlendStyle );

ImplementEnumType( ParticleBlendStyle,
   "The type of visual blending style to apply to the particles.n"
   "@ingroup FXnn")
   { ParticleRenderInst::BlendNormal,         "NORMAL",        "No blending style.n" },
   { ParticleRenderInst::BlendAdditive,       "ADDITIVE",      "Adds the color of the pixel to the frame buffer with full alpha for each pixel.n" },
   { ParticleRenderInst::BlendSubtractive,    "SUBTRACTIVE",   "Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect.n" },
   { ParticleRenderInst::BlendPremultAlpha,   "PREMULTALPHA",  "Color blends with the colors of the imagemap rather than the alpha.n" },
EndImplementEnumType;

#endif // _H_PARTICLE_TYPES
But that made every file using the particleEmitter return this error:
Quote:Error 5 error LNK2005: "int TypeParticleBlendStyle" (?TypeParticleBlendStyle@@3HA) already defined in graphEmitter.obj C:TorqueTorque 3D 1.2My ProjectsEmptyProjectbuildFilesVisualStudio 2010projectsgraphEmitterNode.obj EmptyProject DLL
And some more errors which i did not include due to post size but basically just som already defined errors.
Any ideas?

#1
05/19/2012 (9:07 am)
Obviously my lack of c++ skills comes into play.

Had to take part of the .h file and put it into a .cpp file:

particleTypes.h
#ifndef _H_PARTICLE_TYPES
#define _H_PARTICLE_TYPES

#ifndef _RENDERPASSMANAGER_H_
#include "renderInstance/renderPassManager.h"
#endif

typedef ParticleRenderInst::BlendStyle ParticleBlendStyle;

#endif // _H_PARTICLE_TYPES

particleTypes.cpp
#include "platform/platform.h"
#include "T3D/fx/particleTypes.h"


// Enum tables used for fields blendStyle, srcBlendFactor, dstBlendFactor.
// Note that the enums for srcBlendFactor and dstBlendFactor are consistent
// with the blending enums used in Torque Game Builder.

DefineEnumType( ParticleBlendStyle );

ImplementEnumType( ParticleBlendStyle,
   "The type of visual blending style to apply to the particles.n"
   "@ingroup FXnn")
   { ParticleRenderInst::BlendNormal,         "NORMAL",        "No blending style.n" },
   { ParticleRenderInst::BlendAdditive,       "ADDITIVE",      "Adds the color of the pixel to the frame buffer with full alpha for each pixel.n" },
   { ParticleRenderInst::BlendSubtractive,    "SUBTRACTIVE",   "Subtractive Blending. Reverses the color model, causing dark colors to have a stronger visual effect.n" },
   { ParticleRenderInst::BlendPremultAlpha,   "PREMULTALPHA",  "Color blends with the colors of the imagemap rather than the alpha.n" },
EndImplementEnumType;

But now i am stuck with 4 errors:
Quote:Error 1 error C2838: '_smTypeId' : illegal qualified name in member declaration C:TorqueTorque 3D 1.2EnginesourceconsoledynamicTypes.h 223 1 EmptyProject DLL
I get this twice and
Quote:Error 2 error C2065: '_smTypeId' : undeclared identifier C:TorqueTorque 3D 1.2EnginesourceconsoledynamicTypes.h 223 1 EmptyProject DLL
I get this twice as well
#2
05/19/2012 (9:11 am)
Also a specification of the C2838 error:
// C2838.cpp
// compile with: /c
class Bellini {
public:
    void Norma();
};

class Bottesini {
   Bellini::Norma();  // C2838
};

Edit:
Commenting this code out from initPersistFields(
addField( "blendStyle", TYPEID< ParticleRenderInst::BlendStyle >(), Offset(blendStyle, GraphEmitterData),
         "String value that controls how emitted particles blend with the scene." );
Removes the error. I would like to have that field tho so deleting it is not an option.
However it seems more specifically to be due to
TYPEID< ParticleRenderInst::BlendStyle >()
Does the typeid not work if DefineEnumType and ImplementEnumType is moved to another file?

Edit:
Oh yeah the TYPEID definition:
/// Return the type ID for the primary console type associated with the given native type.
///
/// There can only be one console type associated with a C++ type.  This is referred to as the primary
/// console type.
///
/// @return The type ID of the primary console type for "T".
template< typename T >
S32 TYPEID() { return T::_smTypeId; } // Default assumes a structured type storing its ID in a static member variable.