Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DEBUG_LOG 0
- #include <iostream>
- #include <vector>
- #include <functional>
- #define SAFE_DELETE(x) if (nullptr!=x) {delete x; x=nullptr;}
- #define LOG(x) if (DEBUG_LOG == 1) std::cout << x
- using VAR = float;
- enum TypeClip
- {
- CLIP_BASE = 0,
- CLIP_MAX
- };
- enum TypeEnemy
- {
- ENEMY_BASE = 0,
- ENEMY_MAX
- };
- struct Prototype
- {
- const char* _name = "";
- };
- struct Clip : public Prototype
- {
- bool _isActive = false; // status : is clip is active !
- TypeClip _type = CLIP_BASE; // type of clip !
- VAR _x;
- VAR _y;
- VAR _z;
- std::function<void(Clip*)> _init = nullptr;
- std::function<void(Clip*)> _done = nullptr;
- std::function<void(Clip*)> _update = nullptr;
- std::function<void(Clip*)> _render = nullptr;
- std::vector<Clip*> _vecClip; // vector : Clip child !
- Clip()
- {
- LOG("Clip created ! \n");
- }
- ~Clip()
- {
- if (!_vecClip.empty())
- {
- for (auto& it : _vecClip)
- {
- if (nullptr != it)
- {
- delete it;
- it = nullptr;
- }
- }
- _vecClip.clear();
- }
- std::cout << "Delete Clip : " << _name << "\n";
- }
- Clip* addClip(Clip* clip)
- {
- _vecClip.push_back(clip);
- return static_cast<Clip*>(this);
- }
- Clip* init(std::function<void(Clip*)> init)
- {
- _init = init;
- return static_cast<Clip*>(this);
- }
- Clip* done(std::function<void(Clip*)> done)
- {
- _done = done;
- return static_cast<Clip*>(this);
- }
- Clip* update(std::function<void(Clip*)> update)
- {
- _update = update;
- return static_cast<Clip*>(this);
- }
- Clip* render(std::function<void(Clip*)> render)
- {
- _render = render;
- return static_cast<Clip*>(this);
- }
- static Clip* createClip(const char* name)
- {
- Clip* clip = new Clip();
- clip->_name = name;
- return clip;
- }
- Clip* showME()
- {
- std::cout << "Name of Clip: " << this->_name << "\n";
- if (!_vecClip.empty())
- {
- for (auto& it : _vecClip)
- {
- if (nullptr != it)
- {
- std::cout << ". . Name of Clip: " << it->_name << "\n";
- }
- }
- }
- return static_cast<Clip*>(this);
- }
- Clip* setPosition(VAR x, VAR y, VAR z=0)
- {
- _x = x;
- _y = y;
- _z = z;
- return static_cast<Clip*>(this);
- }
- };
- struct Enemy : public Clip
- {
- TypeEnemy _type = ENEMY_BASE;
- };
- struct Hero : public Clip
- {
- };
- int main()
- {
- Clip* root = Clip::createClip("root")
- ->setPosition(10,10)
- ->init([&](Clip* _this)
- {
- // init root here !
- })
- ->addClip(Clip::createClip("intro")->setPosition(15,15))
- ->addClip(Clip::createClip("title"))
- ->addClip(Clip::createClip("options"));
- root->showME();
- SAFE_DELETE(root);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement