Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <functional>
- #include <algorithm>
- #include <vector>
- #include <list>
- #include <deque>
- #include <map>
- #include <ctime>
- #include <memory>
- #include <allegro5/allegro.h>
- #include <allegro5/allegro_font.h>
- #include <allegro5/allegro_primitives.h>
- #pragma region Globals Vars
- bool _quit = false;
- ALLEGRO_KEYBOARD_STATE keyState;
- ALLEGRO_MOUSE_STATE mouseState;
- bool keyPause = false;
- bool bruteMethod = false;
- bool quadMethod = false;
- bool gridMethod = false;
- int fps = 60;
- int xMouse;
- int yMouse;
- int screenW = 640;
- int screenH = 480;
- int scaleWin = 2;
- ALLEGRO_EVENT_SOURCE eventSource;
- ALLEGRO_EVENT_QUEUE *eventQueue;
- ALLEGRO_EVENT event;
- ALLEGRO_EVENT userEvent;
- ALLEGRO_TIMER *timer = nullptr;
- ALLEGRO_DISPLAY* display = nullptr;
- ALLEGRO_BITMAP* buffer = nullptr;
- ALLEGRO_FONT* font = nullptr;
- #pragma endregion
- template <class M = const char*, class E = int>
- E log(M msg, E error = 0)
- {
- printf(msg);
- return error;
- }
- enum
- {
- NW = 0,
- NE,
- SW,
- SE
- };
- struct Circle
- {
- int _x;
- int _y;
- int _r;
- };
- struct Rect
- {
- int _x;
- int _y;
- int _w;
- int _h;
- };
- enum EventType
- {
- EV_QUIT = 1,
- EV_COLLISION = 2
- };
- int random(int mini, int maxi)
- {
- return (rand() % (maxi-mini)) + mini;
- }
- bool collisionCC(Circle &c1, Circle &c2)
- {
- int d2 = (c1._x - c2._x)*(c1._x - c2._x) + (c1._y - c2._y)*(c1._y - c2._y);
- if (d2 > (c1._r + c2._r)*(c1._r + c2._r))
- return false;
- else
- return true;
- }
- bool collisionRR(Rect &r1, Rect &r2)
- {
- if ((r2._x >= r1._x + r1._w) // trop à droite
- || (r2._x + r2._w <= r1._x) // trop à gauche
- || (r2._y >= r1._y + r1._h) // trop en bas
- || (r2._y + r2._h <= r1._y)) // trop en haut
- return false;
- else
- return true;
- }
- struct Ball
- {
- int _x;
- int _y;
- int _r;
- int _vx;
- int _vy;
- Rect _rect;
- int _screenW;
- int _screenH;
- bool _isCollide = false;
- Ball(int x, int y, int r, int screenW, int screenH) :
- _x(x),
- _y(y),
- _r(r),
- _screenW(screenW),
- _screenH(screenH)
- {
- _vx = (random(1, 3));
- _vy = (random(1, 3));
- _rect._x = _x - _r;
- _rect._y = _y - _r;
- _rect._w = _r * 2;
- _rect._h = _r * 2;
- }
- virtual ~Ball()
- {
- }
- void update()
- {
- _x += _vx;
- _y += _vy;
- _rect._x = _x - _r;
- _rect._y = _y - _r;
- _rect._w = _r * 2;
- _rect._h = _r * 2;
- if (_x < 0)
- _vx = (random(1,3));
- if (_x > _screenW)
- _vx = -(random(1,3));
- if (_y < 0)
- _vy = (random(1, 3));
- if (_y > _screenH)
- _vy = -(random(1, 3));
- }
- void render()
- {
- if (_isCollide)
- {
- //al_draw_filled_circle(_x, _y, _r, al_map_rgba(255,125,100,50));
- al_draw_filled_rectangle(
- _rect._x + .5, _rect._y + .5,
- _rect._x - .5 + _rect._w, _rect._y - .5 + _rect._h,
- al_map_rgb(255, 155, 100));
- }
- //else
- //{
- //al_draw_circle(_x, _y, _r, al_map_rgb(255,255,0),0);
- al_draw_rectangle(
- _rect._x+.5, _rect._y+.5,
- _rect._x-.5 + _rect._w, _rect._y-.5 + _rect._h,
- al_map_rgb(255,55,0),0);
- //}
- }
- };
- std::vector<Ball*> _vecBall;
- struct BallManager
- {
- BallManager()
- {
- }
- virtual ~BallManager()
- {
- if (!_vecBall.empty())
- for (auto & it : _vecBall)
- if (it != nullptr)
- {
- delete it;
- it = nullptr;
- }
- _vecBall.clear();
- }
- void add(Ball *ball)
- {
- if (ball != nullptr)
- _vecBall.push_back(ball);
- }
- void add(int x, int y, int r, int screenW, int screenH)
- {
- this->add(new Ball(x, y, r, screenW, screenH));
- }
- void update()
- {
- if (!_vecBall.empty())
- for (auto & it : _vecBall)
- if (it != nullptr)
- {
- it->_isCollide = false;
- it->update();
- }
- }
- void render()
- {
- if (!_vecBall.empty())
- {
- unsigned index = 0;
- for (auto & it : _vecBall)
- {
- if (it != nullptr)
- {
- it->render();
- //al_draw_textf(font, al_map_rgb(255, 25, 255),
- // it->_rect._x, it->_rect._y - 12, 0,
- // "%i", index
- //);
- }
- ++index;
- }
- }
- }
- void testCollide()
- {
- if (!_vecBall.empty())
- {
- for (unsigned i = 0; i < _vecBall.size(); ++i)
- {
- for (unsigned j = i+1; j < _vecBall.size(); ++j)
- {
- //Circle c1 = {_vecBall[i]->_x, _vecBall[i]->_y, _vecBall[i]->_r};
- //Circle c2 = {_vecBall[j]->_x, _vecBall[j]->_y, _vecBall[j]->_r};
- if (collisionRR(_vecBall[i]->_rect, _vecBall[j]->_rect))
- {
- _vecBall[i]->_isCollide = true;
- _vecBall[j]->_isCollide = true;
- //log("collide !");
- //userEvent.user.data1 = EV_COLLISION;
- //Collision collision(i,j);
- //userEvent.user.data2 = (intptr_t)&collision;
- //al_emit_user_event(&eventSource, &userEvent, 0);
- }
- }
- }
- }
- }
- };
- struct Entity
- {
- unsigned _index;
- Rect _rect;
- };
- struct QuadTree
- {
- unsigned _currentLevel = 0;
- unsigned _maxObject;
- unsigned _maxLevel;
- Rect _rect;
- QuadTree *_parent;
- QuadTree *_node[4] = {nullptr};
- std::vector<Entity*> _vecIndex; // Contain all index of entity in the Quad
- QuadTree(Rect rect, QuadTree *parent = nullptr, int maxObject = 8, int maxLevel = 5) :
- _rect(rect),
- _parent(parent),
- _maxObject(maxObject),
- _maxLevel(maxLevel)
- {
- if (_parent == nullptr)
- _currentLevel = 0;
- else
- {
- _currentLevel = _parent->_currentLevel + 1;
- _maxObject = _parent->_maxObject;
- _maxLevel = _parent->_maxLevel;
- }
- }
- ~QuadTree()
- {
- clearNode();
- }
- bool haveChild()
- {
- return (_node[0] != nullptr);
- }
- bool isLastBranch()
- {
- bool isLastBranch = true;
- for (int i = 0; i < 4; ++i)
- {
- if (_node[i] != nullptr)
- {
- if (_node[i]->haveChild())
- isLastBranch = false;
- }
- }
- if (isLastBranch)
- log("- is Last Branch -");
- return isLastBranch;
- }
- void split()
- {
- if (_currentLevel < _maxLevel)
- {
- int x = _rect._x;
- int y = _rect._y;
- int w = _rect._w;
- int h = _rect._h;
- int cW = w / 2;
- int cH = h / 2;
- _node[NW] = new QuadTree(Rect{x,y,cW,cH}, this);
- _node[NE] = new QuadTree(Rect{x+cW,y,cW,cH}, this);
- _node[SW] = new QuadTree(Rect{x,y+cH,cW,cH}, this);
- _node[SE] = new QuadTree(Rect{x+cW,y+cH,cW,cH}, this);
- }
- }
- void unSplit()
- {
- clearNode();
- }
- void clearNode()
- {
- if (!_vecIndex.empty())
- {
- for (auto & it : _vecIndex)
- {
- if (it != nullptr)
- {
- delete it;
- it = nullptr;
- }
- }
- _vecIndex.clear();
- //log("- vecIndex cleared -");
- }
- //log("- Begin Clear Node -");
- if (haveChild())
- {
- //log("- Node have child -");
- for (int i = 0; i < 4; ++i)
- {
- //if (_node[i] != nullptr)
- //{
- if (_node[i]->haveChild())
- _node[i]->clearNode();
- delete _node[i];
- _node[i] = nullptr;
- //printf("Delete Node %i \n", i);
- //}
- }
- }
- }
- // Return wich node the object belongs to , -1 = Object belong Parent node
- int getQuadIndex(Rect &rect)
- {
- int index = -1;
- int cX = _rect._x + _rect._w / 2;
- int cY = _rect._y + _rect._h / 2;
- bool inN = (rect._y + rect._h < cY);
- bool inS = (rect._y > cY);
- bool inW = (rect._x + rect._w < cX);
- bool inE = (rect._x > cX);
- if (inN && inW) index = NW;
- if (inN && inE) index = NE;
- if (inS && inW) index = SW;
- if (inS && inE) index = SE;
- return index;
- }
- void insert(unsigned index, Rect rect)
- {
- if (haveChild()) // If have child transmit to child
- {
- int quadIndex = getQuadIndex(rect);
- if (quadIndex != -1)
- _node[quadIndex]->insert(index, rect);
- return;
- }
- _vecIndex.push_back(new Entity{ index, rect });
- if (_vecIndex.size() > _maxObject && _currentLevel < _maxLevel)
- {
- //log("- need split -\n");
- if (!haveChild())
- split();
- unsigned i = 0;
- while (i < _vecIndex.size())
- {
- int quadIndex = getQuadIndex(_vecIndex[i]->_rect);
- if (quadIndex != -1)
- {
- _node[quadIndex]->insert(_vecIndex[i]->_index, _vecIndex[i]->_rect);
- delete _vecIndex[i]; // don't forget to delete Entity pointer !
- _vecIndex.erase(_vecIndex.begin() + i);
- }
- else
- {
- ++i;
- }
- }
- }
- }
- void findNear(std::vector<Entity*> &vecEntity, Rect &rect)
- {
- if (haveChild())
- {
- int quadIndex = getQuadIndex(rect);
- if (quadIndex != -1)
- {
- _node[quadIndex]->findNear(vecEntity, rect);
- }
- else
- {
- for (unsigned i = 0; i < 4; ++i)
- {
- _node[i]->findNear(vecEntity, rect);
- }
- }
- }
- for (auto & it: _vecIndex)
- vecEntity.push_back(it);
- }
- void update(int mouseX, int mouseY, int mouseB)
- {
- //if ((mouseB & 1) && !haveChild())
- //{
- // if (mouseX > _rect._x && mouseX < _rect._x + _rect._w &&
- // mouseY > _rect._y && mouseY < _rect._y + _rect._h)
- // {
- // split();
- // }
- // mouseB = 0;
- //}
- //if ((mouseB & 2) && haveChild())
- //{
- // if (mouseX > _rect._x && mouseX < _rect._x + _rect._w &&
- // mouseY > _rect._y && mouseY < _rect._y + _rect._h)
- // {
- // bool nodeHaveChild = false;
- // for (int i = 0; i < 4; ++i)
- // {
- // if (_node[i] != nullptr)
- // {
- // if (_node[i]->haveChild())
- // nodeHaveChild = true;
- //
- // }
- // }
- // if (!nodeHaveChild)
- // unSplit();
- // }
- //}
- //if (haveChild())
- //{
- // for (int i = 0; i < 4; ++i)
- // {
- // if (_node[i] != nullptr)
- // {
- // _node[i]->update(mouseX, mouseY, mouseB);
- // }
- // }
- //}
- }
- void render(int mouseX, int mouseY, int mouseB)
- {
- if (mouseX > _rect._x && mouseX < _rect._x + _rect._w &&
- mouseY > _rect._y && mouseY < _rect._y + _rect._h &&
- !haveChild())
- {
- al_draw_filled_rectangle(
- .5 + _rect._x, .5 + _rect._y,
- .5 + _rect._x + _rect._w + 1, .5 + _rect._y + _rect._h + 1,
- al_map_rgba(0, 155, 100, 50));
- //for (unsigned i = 0; i < _vecIndex.size(); ++i)
- //{
- // al_draw_textf(font, al_map_rgb(25, 205, 255),
- // mouseX, mouseY + (i * 12), 0,
- // "vec[%i]=%i", i, _vecIndex[i]->_index
- // );
- //}
- }
- if (haveChild())
- {
- al_draw_line(
- .5 + _rect._x + _rect._w / 2, .5 + _rect._y,
- .5 + _rect._x + _rect._w / 2, .5 + _rect._y + _rect._h,
- al_map_rgb(0, 155, 100), 0);
- al_draw_line(
- .5 + _rect._x , .5 + _rect._y + _rect._h / 2 ,
- .5 + _rect._x + _rect._w, .5 + _rect._y + _rect._h / 2,
- al_map_rgb(0, 155, 100), 0);
- //for (unsigned i = 0; i < _vecIndex.size(); ++i)
- //{
- // al_draw_textf(font, al_map_rgb(25, 205, 255),
- // _rect._x + 2, _rect._y + 12 + (i * 12) , 0,
- // "vec[%i]=%i", i, _vecIndex[i]->_index
- // );
- //}
- }
- if (haveChild())
- for (int i = 0; i < 4; ++i)
- {
- if (_node[i] != nullptr)
- {
- _node[i]->render(mouseX, mouseY, mouseB);
- }
- }
- if (!haveChild())
- {
- al_draw_filled_circle(
- .5 + _rect._x + _rect._w/2, .5 + _rect._y + _rect._h/2, 1,
- al_map_rgba(0, 155, 100, 255));
- //al_draw_textf(font, al_map_rgb(255, 200, 200),
- // _rect._x + 2, _rect._y + 2, 0,
- // //_rect._x + _rect._w / 2, _rect._y - 1 + _rect._h / 2, 1,
- // "%i:%i", _currentLevel, _vecIndex.size());
- }
- }
- };
- struct Cell
- {
- std::vector<Entity*> _vecIndex; // Contain all index of entity in the Cell
- };
- struct GridSpatialPart
- {
- int _originX;
- int _originY;
- int _gridW;
- int _gridH;
- int _cellSize;
- std::vector<std::vector<Cell*>> _vec2dCell;
- GridSpatialPart(int gridW, int gridH, int cellSize)
- {
- _cellSize = cellSize;
- _gridW = gridW;
- _gridH = gridH;
- _vec2dCell.resize(_gridW);
- for (int x = 0; x < _gridW; ++x)
- {
- _vec2dCell[x].resize(_gridH);
- for (int y = 0; y < _gridH; ++y)
- {
- _vec2dCell[x][y] = new Cell();
- }
- }
- }
- Cell *cell(unsigned x, unsigned y)
- {
- return _vec2dCell[x][y];
- }
- void clear()
- {
- for (int x = 0; x < _gridW; ++x)
- {
- for (int y = 0; y < _gridH; ++y)
- {
- if (cell(x,y) != nullptr)
- {
- if (!cell(x, y)->_vecIndex.empty())
- {
- for (auto & it: cell(x, y)->_vecIndex)
- if (it != nullptr)
- {
- delete it;
- it = nullptr;
- }
- cell(x, y)->_vecIndex.clear();
- }
- }
- }
- }
- }
- void insert(unsigned index, Rect rect)
- {
- int left = std::max(0, rect._x / _cellSize);
- int top = std::max(0,rect._y / _cellSize);
- int right = std::min(_gridW-1,(rect._x + rect._w - 1) / _cellSize);
- int bottom = std::min(_gridH-1,(rect._y + rect._h - 1) / _cellSize);
- for (int x = left; x <= right; ++x)
- {
- for (int y = top; y <= bottom; ++y)
- {
- cell(x, y)->_vecIndex.push_back(new Entity{ index, rect });
- }
- }
- }
- void findNear(std::vector<Entity*> &_vecIndexTemp, Rect rect)
- {
- int left = std::max(0, rect._x / _cellSize);
- int top = std::max(0, rect._y / _cellSize);
- int right = std::min(_gridW - 1, (rect._x + rect._w - 1) / _cellSize);
- int bottom = std::min(_gridH - 1, (rect._y + rect._h - 1) / _cellSize);
- for (int x = left; x <= right; ++x)
- {
- for (int y = top; y <= bottom; ++y)
- {
- for (unsigned i = 0; i < cell(x, y)->_vecIndex.size(); ++i)
- {
- Entity *entity = cell(x, y)->_vecIndex[i];
- //if (entity->_index != index)
- _vecIndexTemp.push_back(entity);
- }
- }
- }
- }
- Entity* getNearest()
- {
- }
- void update()
- {
- }
- void render()
- {
- for (int x = 0; x < _gridW; ++x)
- {
- for (int y = 0; y < _gridH; ++y)
- {
- int px = x*_cellSize;
- int py = y*_cellSize;
- al_draw_rectangle(
- px, py,
- px + _cellSize, py + _cellSize,
- al_map_rgb(255, 205, 120), 0
- );
- //al_draw_textf(
- // font,
- // al_map_rgb(250,250,0),
- // px + 2, py + 2, 0,
- // "%i,%i = %i",
- // x, y, cell(x, y)->_vecIndex.size()
- //);
- if (!(cell(x, y)->_vecIndex.empty()))
- {
- //log("not empty !\n");
- //for (unsigned i = 0; i < cell(x, y)->_vecIndex.size(); ++i)
- //{
- // al_draw_textf(font, al_map_rgb(25, 205, 255),
- // px + 2, py+12 + (i * 12) , 0,
- // "vec[%i]=%i", i, cell(x, y)->_vecIndex[i]->_index
- // );
- //}
- }
- }
- }
- }
- };
- int init()
- {
- srand(time(0));
- al_init();
- al_init_font_addon();
- al_init_primitives_addon();
- al_install_keyboard();
- al_install_mouse();
- al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
- display = al_create_display(screenW*scaleWin, screenH*scaleWin);
- buffer = al_create_bitmap(screenW, screenH);
- font = al_create_builtin_font();
- al_init_user_event_source(&eventSource);
- eventQueue = al_create_event_queue();
- al_register_event_source(eventQueue, &eventSource);
- //userEvent.user.data1 = 42;
- //al_emit_user_event(&eventSource, &userEvent, 0);
- timer = al_create_timer(1.0 / fps);
- al_register_event_source(eventQueue, al_get_timer_event_source(timer));
- al_start_timer(timer);
- return log("Init OK !\n");
- }
- int main()
- {
- if (init())
- _quit = true;
- std::shared_ptr<BallManager> _manBall;
- QuadTree *_quad = new QuadTree(Rect{ 0,0,screenW,screenH }, nullptr, 8);
- int cellSize = 64;
- int gridW = screenW / cellSize;
- int gridH = screenH / cellSize;
- GridSpatialPart *_grid = new GridSpatialPart(gridW, gridH, cellSize);
- int rangeX = _grid->_gridW* _grid->_cellSize;
- int rangeY = _grid->_gridH* _grid->_cellSize;
- for (int i = 0; i < 3200; ++i)
- {
- int x = random(0, rangeX);
- int y = random(0, rangeY);
- int r = random(4, 8);
- //_manBall->add(new Ball(x, y, r, screenW, screenH));
- //_manBall->add(x, y, r, screenW, screenH);
- _manBall->add(x, y, r, rangeX, rangeY);
- }
- //auto _quad = std::make_shared<QuadTree<Ball>>(0, Rect{0, 0, screenW, screenH});
- bool mouseDown = false;
- int mouseB = 0;
- bool pause = false;
- std::vector<Entity*> vecEntity;
- while (!_quit)
- {
- // update
- al_wait_for_event(eventQueue, &event);
- if ((int)event.user.data1 == EV_QUIT)
- {
- printf("Wee quiiit !!! \n");
- _quit = true;
- }
- al_get_keyboard_state(&keyState);
- al_get_mouse_state(&mouseState);
- if (!al_key_down(&keyState, ALLEGRO_KEY_SPACE)) keyPause = false;
- if (al_key_down(&keyState, ALLEGRO_KEY_SPACE) && !keyPause)
- {
- keyPause = true;
- pause = !pause;;
- }
- if (al_key_down(&keyState, ALLEGRO_KEY_ESCAPE))
- _quit = true;
- //if (al_key_down(&keyState, ALLEGRO_KEY_Q))
- //{
- // userEvent.user.data1 = EV_QUIT;
- // al_emit_user_event(&eventSource, &userEvent, 0);
- //}
- if (al_key_down(&keyState, ALLEGRO_KEY_BACKSPACE))
- {
- bruteMethod = false;
- quadMethod = false;
- gridMethod = false;
- }
- if (al_key_down(&keyState, ALLEGRO_KEY_A))
- {
- bruteMethod = true;
- quadMethod = false;
- gridMethod = false;
- }
- if (al_key_down(&keyState, ALLEGRO_KEY_Q))
- {
- bruteMethod = false;
- quadMethod = true;
- gridMethod = false;
- }
- if (al_key_down(&keyState, ALLEGRO_KEY_G))
- {
- bruteMethod = false;
- quadMethod = false;
- gridMethod = true;
- }
- xMouse = mouseState.x / scaleWin;
- yMouse = mouseState.y / scaleWin;
- mouseB = 0;
- if (!mouseState.buttons) mouseDown = false;
- if (mouseState.buttons && !mouseDown)
- {
- //log(" <clicked> ");
- mouseDown = true;
- mouseB = mouseState.buttons;
- }
- if (mouseB & 1)
- {
- _manBall->add(xMouse, yMouse, 4, screenW, screenH);
- }
- if (!pause)
- {
- _manBall->update();
- }
- if (bruteMethod)
- _manBall->testCollide();
- if (gridMethod)
- {
- _grid->clear();
- for (unsigned i = 0 ; i < _vecBall.size(); ++i)
- {
- _grid->insert(i, _vecBall[i]->_rect);
- }
- for (unsigned i = 0; i < _vecBall.size(); ++i)
- {
- vecEntity.clear();
- _grid->findNear(vecEntity, _vecBall[i]->_rect);
- if (!vecEntity.empty())
- {
- for (unsigned x = 0; x < vecEntity.size(); ++x)
- {
- unsigned j = vecEntity[x]->_index;
- if (i != j)
- {
- if (j >= 0 && j < _vecBall.size())
- {
- if (collisionRR(_vecBall[i]->_rect, _vecBall[j]->_rect))
- {
- _vecBall[i]->_isCollide = true;
- _vecBall[j]->_isCollide = true;
- }
- }
- }
- }
- }
- }
- }
- if (quadMethod)
- {
- _quad->clearNode();
- for (unsigned i = 0; i < _vecBall.size(); ++i)
- {
- _quad->insert(i, _vecBall[i]->_rect);
- }
- std::vector<Entity*> vecEntity;
- for (unsigned i = 0; i < _vecBall.size(); ++i)
- {
- vecEntity.clear();
- _quad->findNear(vecEntity, _vecBall[i]->_rect);
- for (unsigned x = 0; x < vecEntity.size(); ++x)
- {
- unsigned j = vecEntity[x]->_index;
- if (i != j)
- {
- //Circle c1 = { _vecBall[i]->_x, _vecBall[i]->_y, _vecBall[i]->_r };
- //Circle c2 = { _vecBall[j]->_x, _vecBall[j]->_y, _vecBall[j]->_r };
- if (collisionRR(_vecBall[i]->_rect, _vecBall[j]->_rect))
- {
- _vecBall[i]->_isCollide = true;
- _vecBall[j]->_isCollide = true;
- }
- }
- }
- }
- _quad->update(xMouse, yMouse, mouseB);
- }
- // render
- al_set_target_bitmap(buffer);
- al_clear_to_color(al_map_rgb(0, 0, 0));
- //al_draw_text(font, al_map_rgb(255, 255, 255), screenW/2, 2, ALLEGRO_ALIGN_CENTER, "MugenEgine : Event and Collision System");
- _manBall->render();
- if (gridMethod)
- _grid->render();
- if (quadMethod)
- {
- _quad->render(xMouse, yMouse, mouseB);
- for (unsigned i = 0; i < _quad->_vecIndex.size(); ++i)
- {
- al_draw_textf(font, al_map_rgb(25, 205, 255),
- 2, 2 + (i * 12), 0,
- "vec[%i]=%i", i, _quad->_vecIndex[i]->_index
- );
- }
- }
- //al_draw_line(0, yMouse + .5,
- // screenW, yMouse + .5,
- // al_map_rgba(55, 125, 100, 25), 0);
- //al_draw_line(xMouse + .5, 0,
- // xMouse + .5, screenH,
- // al_map_rgba(55, 125, 100, 25), 0);
- al_set_target_backbuffer(display);
- al_draw_scaled_bitmap(buffer,
- 0, 0,
- screenW, screenH,
- 0, 0,
- screenW*scaleWin, screenH*scaleWin,
- 0);
- const char *method = "No Collisions Test !";
- if (bruteMethod) method = "Brute Force !";
- if (quadMethod) method = "QuadTree !";
- if (gridMethod) method = "Grid Spatial Partition !";
- al_draw_textf(font, al_map_rgb(25, 205, 255),
- (screenW*scaleWin) /2, (screenH*scaleWin)-12, -1,
- "NB ENTITY = %i :(A)BruteForce (Q)QuadTree (G)Grid : Method = %s", _vecBall.size(), method);
- al_flip_display();
- }
- if (!_grid)
- delete _grid;
- if (!_quad)
- delete _quad;
- _manBall.reset();
- al_destroy_timer(timer);
- al_destroy_event_queue(eventQueue);
- al_destroy_bitmap(buffer);
- al_destroy_display(display);
- al_destroy_font(font);
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement