root / branches / netent_demo / netent.h @ 543

Revision 543, 1.6 kB (checked in by gaul@…, 6 months ago)
  • demo for simplification (read: de-templatization) of netent and its friends
Line 
1#include <string>
2
3class Ent {
4        protected: //do not instantiate directly
5                Ent(uint16_t _entid) {
6                        entid = _entid;
7                };
8        private:
9                uint16_t entid;
10        public:
11                typedef enum {
12                        Box,
13                        Sphere,
14                        Pad,
15                        PlayerBall
16                } Class;
17                typedef Ent* (*createfct)(uint16_t);
18                uint16_t get_entid() { return entid; };
19                virtual uint16_t get_classid() = 0;
20                virtual const std::string get_classname() = 0;
21};
22
23class Obj : public Ent {
24        protected:
25                Obj(uint16_t entid) : Ent(entid) {};
26};
27
28class Box : public Obj {
29        protected:
30                Box(uint16_t entid) : Obj(entid) {};
31        public:
32                virtual uint16_t get_classid() { return Ent::Box; };
33                virtual const std::string get_classname() { return "Box"; };
34                static Ent* create(uint16_t entid) { return new Box(entid); }; //Ent* seems to be needed
35};
36
37class Pad : public Box {
38        protected:
39                Pad(uint16_t entid) : Box(entid) {};
40        public:
41                virtual uint16_t get_classid() { return Ent::Pad; };
42                virtual const std::string get_classname() { return "Pad"; };
43                static Ent* create(uint16_t entid) { return new Pad(entid); };
44};
45
46#define ENTLEAF(CLASS, CLASSID, CLASSNAME) \
47                virtual uint16_t get_classid() { return Ent::CLASSID; };\
48                virtual const std::string get_classname() { return CLASSNAME; }; \
49                static Ent* create(uint16_t entid) { return new CLASS(entid); };
50
51//now this is shorter (!):
52class Sphere : public Ent {
53        protected:
54                Sphere(uint16_t entid) : Ent(entid) {};
55        public:
56                ENTLEAF(Sphere, Sphere, "Sphere");
57};
58
59class PBall : public Sphere {
60        protected:
61                PBall(uint16_t entid) : Sphere(entid) {};
62        public:
63                ENTLEAF(PBall, PlayerBall, "PlayerBall");
64};
Note: See TracBrowser for help on using the browser.