Quantcast
Viewing all articles
Browse latest Browse all 6821

"Generic" achitecture

@Alkher wrote:

Hi !

I have a somewhat simple problem (at least, easy for me in c++ with pointers and classes aggregation, but not with c#)

I need, in order to optimize my classes, to have a class like this:

class Object_Default
{
	public Vector3 _Pos3D;
	public Texsture2D _TexChannelA;
	... (other mandatory properties)
}

and I need some versions of this class to be "specialized" with more properties:

class Object_OnlyColor:Object_Default
{
	public Vector4 _Color;
    //Other props
}

class Object_LightnShadows:Object_OnlyColor
{
	public bool _IsReceivingLight;
	public bool _IsCastingShadows;
	public bool _IsCastingLight;
	public bool _IsReceivingShadows;
    //Other props
}

How can I have a generic array of one of these types, without having to test the type each frame with:

if(_objectsarray is Object_OnlyColor[])
{
//Do something according to this type: set values to be used with the effect, etc.
}
else
if(_objectsarray is Object_LightnShadows[])
{
//Do something according to this type: set values to be used with the effect, etc.
}

Is there anyone with a good architecture, with fast performances ? I don't think creating a "object" type array and casting it each frame would solve this. And I'm not sure an abstract class is the solution. Since aggregation is not possible with C#, how to achieve this ?

Posts: 8

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles