Advertisement
SilverTES

MugenEngine Next

Aug 28th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. #define DEBUG_LOG 0
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <functional>
  6.  
  7. #define SAFE_DELETE(x) if (nullptr!=x) {delete x; x=nullptr;}
  8.  
  9. #define LOG(x) if (DEBUG_LOG == 1) std::cout << x
  10.  
  11. using VAR = float;
  12.  
  13. enum TypeClip
  14. {
  15.     CLIP_BASE = 0,
  16.     CLIP_MAX
  17. };
  18.  
  19. enum TypeEnemy
  20. {
  21.     ENEMY_BASE = 0,
  22.     ENEMY_MAX
  23. };
  24.  
  25. struct Prototype
  26. {
  27.     const char* _name = "";
  28. };
  29.  
  30. struct Clip : public Prototype
  31. {
  32.     bool _isActive = false;  // status : is clip is active !
  33.     TypeClip _type = CLIP_BASE;  // type of clip !
  34.    
  35.     VAR _x;
  36.     VAR _y;
  37.     VAR _z;
  38.  
  39.     std::function<void(Clip*)> _init = nullptr;
  40.     std::function<void(Clip*)> _done = nullptr;
  41.     std::function<void(Clip*)> _update = nullptr;
  42.     std::function<void(Clip*)> _render = nullptr;
  43.  
  44.     std::vector<Clip*> _vecClip; // vector : Clip child !
  45.  
  46.     Clip()
  47.     {
  48.         LOG("Clip created ! \n");
  49.     }
  50.     ~Clip()
  51.     {
  52.         if (!_vecClip.empty())
  53.         {
  54.             for (auto& it : _vecClip)
  55.             {
  56.                 if (nullptr != it)
  57.                 {
  58.                     delete it;
  59.                     it = nullptr;
  60.                 }
  61.             }
  62.             _vecClip.clear();
  63.         }
  64.         std::cout << "Delete Clip : " << _name << "\n";
  65.     }
  66.     Clip* addClip(Clip* clip)
  67.     {
  68.         _vecClip.push_back(clip);
  69.  
  70.         return static_cast<Clip*>(this);
  71.     }
  72.     Clip* init(std::function<void(Clip*)> init)
  73.     {
  74.         _init = init;
  75.         return static_cast<Clip*>(this);
  76.     }
  77.     Clip* done(std::function<void(Clip*)> done)
  78.     {
  79.         _done = done;
  80.         return static_cast<Clip*>(this);
  81.     }
  82.     Clip* update(std::function<void(Clip*)> update)
  83.     {
  84.         _update = update;
  85.         return static_cast<Clip*>(this);
  86.     }  
  87.     Clip* render(std::function<void(Clip*)> render)
  88.     {
  89.         _render = render;
  90.         return static_cast<Clip*>(this);
  91.     }
  92.  
  93.     static Clip* createClip(const char* name)
  94.     {
  95.         Clip* clip = new Clip();
  96.         clip->_name = name;
  97.         return clip;
  98.     }
  99.  
  100.     Clip* showME()
  101.     {
  102.         std::cout << "Name of Clip: " << this->_name << "\n";
  103.  
  104.         if (!_vecClip.empty())
  105.         {
  106.             for (auto& it : _vecClip)
  107.             {
  108.                 if (nullptr != it)
  109.                 {
  110.                     std::cout << ". . Name of Clip: " << it->_name << "\n";
  111.                 }
  112.             }
  113.         }
  114.         return static_cast<Clip*>(this);
  115.     }  
  116.  
  117.     Clip* setPosition(VAR x, VAR y, VAR z=0)
  118.     {
  119.         _x = x;
  120.         _y = y;
  121.         _z = z;
  122.         return static_cast<Clip*>(this);
  123.     }                            
  124.  
  125. };
  126.  
  127. struct Enemy : public Clip
  128. {
  129.     TypeEnemy _type = ENEMY_BASE;      
  130. };
  131.  
  132. struct Hero : public Clip
  133. {
  134.    
  135. };
  136.  
  137. int main()
  138. {
  139.     Clip* root = Clip::createClip("root")
  140.     ->setPosition(10,10)
  141.     ->init([&](Clip* _this)
  142.     {
  143.         // init root here !
  144.        
  145.     })
  146.     ->addClip(Clip::createClip("intro")->setPosition(15,15))
  147.     ->addClip(Clip::createClip("title"))
  148.     ->addClip(Clip::createClip("options"));
  149.    
  150.     root->showME();
  151.  
  152.     SAFE_DELETE(root);
  153.    
  154.     system("pause");
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement