Monday, December 27, 2010

Porting my old C++ Templates code to C# Generics

I'm quite pessimistic about using C# Generics and how will affect the design and how it behaves but I have no choice I'm now using C# so I'll give it a try.

Part of c++ template code from my D3D game engine...

   template<class T>
   class TState
   {
   public:
      virtual ~TState() {}
      virtual void Enter(T*) = 0;
      virtual void Execute(T*) = 0;
      virtual void Exit(T*) = 0;
      virtual bool OnMessage(T*, const tTelegram&) = 0;
   };

... and new C# code for my XNA game engine.

   public interface TObjectState<T>
   {
      void Enter(T t);
      void Execute(T t);
      void Exit(T t);
      bool OnMessage(T t, MessageTelegram telegram);
   }

Yeah, now I'm very impressed how easy it is and it only took me less a minute to port all my template codes!

So far I'm liking XNA and it's pretty neat if ask me!

Cheers!

No comments:

Post a Comment