ISimpleExtension in Multiple Classes

#1
The question might be a bit shaky, since I'm still learning OOC and its terminology.

for context, I'm using BuildingManager.h to hold all of the building classes, and making a separate cpp file for each building entity. Which sounds right (tell me if its not)
How can I implement the ISimpleExtension interface functions into my building classes without having to call the function every time? Or is it required that it works that way?

Code: Select all

//BuildingManager.h #pragma once #include "StdAfx.h" #include "Entities\Helpers\ISimpleExtension.h" #include "Game\ResourceManager.h" class CBuildingManager : CGameObjectExtensionHelper<CBuildingManager, ISimpleExtension> { public: enum BuildingTypes { eBuilding_Road = 0, eBuilding_WaterTower = 1, eBuilding_House = 2, eBuilding_OilPump = 4, eBuilding_GasPlant = 8, eBuilding_GasStation = 16 }; //ISimpleExtension virtual bool Init(IGameObject* pGameObject) override; virtual void PostInit(IGameObject* pGameObject) override; virtual void Update(SEntityUpdateContext& ctx, int updateSlot) override; virtual void ProcessEvent(SEntityEvent& event) override; //~ISimpleExtension }; class CWaterTower : CGameObjectExtensionHelper<CWaterTower, ISimpleExtension> { //How can I pull the ISimpleExtension interface from CBuildingManager so I dont have to reimpliment the functions every class? public: //ISimpleExtension virtual bool Init(IGameObject* pGameObject) override; virtual void PostInit(IGameObject* pGameObject) override; virtual void Update(SEntityUpdateContext& ctx, int updateSlot) override; virtual void ProcessEvent(SEntityEvent& event) override; //~ISimpleExtension protected: CResourceManager *m_pResourceManager; };
PIC HERE
Thanks!
-Moose
ImageTwitterImage

Re: ISimpleExtension in Multiple Classes

#2
Hi!
I'm not sure I understood your problem but from what I gather you want default implementation for some of "ISimpleExtension" functions. In that case the solution is easy, just define another interface ("IBuildingExtension" for example) that inherits (Implements) "ISimpleExtension" interface and provide default implementation for the desired methods. Your extensions could then implement this interface instead of "ISimpleExtension".
But I believe this is not a good design choice for your building manager. You see, judging by "BuildingTypes" enum, it seems your buildings only differ in resources they produce. In other words, only their data (resources, mesh and ...) are different, not their behavior. You could implement and register only one building extension and set it's data during creation.
Check out this link:
http://gameprogrammingpatterns.com/type-object.html

Who is online

Users browsing this forum: No registered users and 2 guests