fixed editor zooming if gui is not active
[twcon.git] / src / engine / kernel.h
blobb5961bc372dab8b23eb43a99eef1c485a1daf7be
1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef ENGINE_KERNEL_H
4 #define ENGINE_KERNEL_H
6 #include <base/system.h>
8 class IKernel;
9 class IInterface;
11 class IInterface
13 // friend with the kernel implementation
14 friend class CKernel;
15 IKernel *m_pKernel;
16 protected:
17 IKernel *Kernel() { return m_pKernel; }
18 public:
19 IInterface() : m_pKernel(0) {}
20 virtual ~IInterface() {}
22 //virtual unsigned InterfaceID() = 0;
23 //virtual const char *InterfaceName() = 0;
26 #define MACRO_INTERFACE(Name, ver) \
27 public: \
28 static const char *InterfaceName() { return Name; } \
29 private:
31 //virtual unsigned InterfaceID() { return INTERFACE_ID; }
32 //virtual const char *InterfaceName() { return name; }
35 // This kernel thingie makes the structure very flat and basiclly singletons.
36 // I'm not sure if this is a good idea but it works for now.
37 class IKernel
39 // hide the implementation
40 virtual bool RegisterInterfaceImpl(const char *InterfaceName, IInterface *pInterface) = 0;
41 virtual bool ReregisterInterfaceImpl(const char *InterfaceName, IInterface *pInterface) = 0;
42 virtual IInterface *RequestInterfaceImpl(const char *InterfaceName) = 0;
43 public:
44 static IKernel *Create();
45 virtual ~IKernel() {}
47 // templated access to handle pointer convertions and interface names
48 template<class TINTERFACE>
49 bool RegisterInterface(TINTERFACE *pInterface)
51 return RegisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface);
53 template<class TINTERFACE>
54 bool ReregisterInterface(TINTERFACE *pInterface)
56 return ReregisterInterfaceImpl(TINTERFACE::InterfaceName(), pInterface);
59 // Usage example:
60 // IMyInterface *pMyHandle = Kernel()->RequestInterface<IMyInterface>()
61 template<class TINTERFACE>
62 TINTERFACE *RequestInterface()
64 return reinterpret_cast<TINTERFACE *>(RequestInterfaceImpl(TINTERFACE::InterfaceName()));
68 #endif