void doStep(ModelInstance* comp, fmi2IntegerTime hLocal, int inBetween) { if (inBetween == 0) { } else { if ((comp->eventInfo.nextEventTimeDefined && (comp->time == comp->eventInfo.nextEventTime)) || getEventIndicator(comp) < 0) { fmi2IntegerTime currentTime = comp->time; if (_isTime(comp)) { _removeLast(comp); comp->eventInfo.nextEventTimeDefined = fmi2False; } if (!_isEmpty(comp)) { Event nextEvent = _getLast(comp); comp->eventInfo.nextEventTime = nextEvent.time; comp->eventInfo.nextEventTimeDefined = fmi2True; } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); comp->eventInfo.nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(comp); } } comp->time += hLocal; if (hLocal > 0) comp->microstep = 0; else comp->microstep++; } }
//----------------------------------------------------------------------- void CollisionModelManager::_checkMemoryUsage(void) { while (!_isEmpty() && mMemoryUsage > mCacheLimit) { CacheItem* item = _back(); mMemoryUsage -= item->getMemoryUsage(); _unlink(item); } }
fmi2Boolean _isTime(ModelInstance *comp) { if (_isEmpty(comp)) { return fmi2False; } if (comp->time == _getTime(comp) && comp->microstep == _getIndex(comp)){ return fmi2True; } else { return fmi2False; } }
bool _isTime(ModelInstance *comp) { if (_isEmpty()) { return false; } if (comp->time == _getTime() && i(microstep_) == _getIndex()){ return true; } else { return false; } }
// Used to set the next time event, if any. void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo, int isTimeEvent) { long currentTime = comp->time; if (_isTime(comp)) { _removeLast(comp); eventInfo->nextEventTimeDefined = fmi2False; } if (!_isEmpty(comp)) { Event nextEvent = _getLast(comp); comp->eventInfo.nextEventTime = nextEvent.time; eventInfo->nextEventTimeDefined = fmi2True; } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); eventInfo->nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(comp); } }
// Used to set the next time event, if any. void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo, int isTimeEvent) { long currentTime = comp->time; // printf("DELAY: eventUpdate, time = %ld, _isTime(comp) = %d\n", comp->time, _isTime(comp)); if (_isTime(comp)) { _removeLast(); eventInfo->nextEventTimeDefined = fmi2False; } if (!_isEmpty()) { Event nextEvent = _getLast(); comp->eventInfo.nextEventTime = nextEvent.time; eventInfo->nextEventTimeDefined = fmi2True; // printf("- not empty\n"); // printf("- eventInfo->nextEventTimeDefined = fmi2True\n"); // printf("- addedEvent at time %ld, %ld\n", _getTime(), _getIndex()); } if (hr(input_) == present_) { _addEvent(comp, r(input_), currentTime + i(delay_)); eventInfo->nextEventTimeDefined = fmi2True; comp->eventInfo.nextEventTime = _getTime(); // printf("- present\n"); // printf("- eventInfo->nextEventTimeDefined = fmi2True\n"); // printf("- addedEvent at time %ld, %ld\n", _getTime(), _getIndex()); } }
virtual bool isEmpty() const { return _isEmpty(); }
/* ** Take two pawn as parameter and if they form a possible three, return all possible moves for the third pawn */ std::vector<std::pair<int, int>> *RulesChecker::_checkIfThree(std::pair<int, int> a, std::pair<int, int> b, std::vector<std::vector<eBlock>> & grid, eTurn & turn){ int x1 = a.first; int y1 = a.second; int x2 = b.first; int y2 = b.second; if (!_isPlayerPawn(x1, y1, grid, turn) || !_isPlayerPawn(x2, y2, grid, turn)) return NULL; if (x1 == x2 && y1 != y2){ // It's a vertical alignement if (y2 < y1) _swapInt(y1, y2); if (y1 - 1 >= 0 && y2 + 1 < GRID_SIZE && _isEmpty(x1, y1 - 1, grid) && _isEmpty(x1, y2 + 1, grid)){ std::vector<std::pair<int, int>> *v = new std::vector<std::pair<int, int>>(); // Return a pointer on a vectore containing all possible third pawn for a three v->push_back(std::make_pair(x1, y1 - 1)); v->push_back(std::make_pair(x1, y2 + 1)); if (_isEmpty(x1, y1 - 2, grid)) v->push_back(std::make_pair(x1, y2 - 2)); if (_isEmpty(x1, y2 + 2, grid)) v->push_back(std::make_pair(x1, y2 + 2)); return v; } } else if (x1 != x2 && y1 == y2){ // Horizontal alignement if (x2 < x1) _swapInt(x1, x2); if (x1 - 1 >= 0 && x2 + 1 < GRID_SIZE && _isEmpty(x1 - 1, y1, grid) && _isEmpty(x2 + 1, y2, grid)){ std::vector<std::pair<int, int>> *v = new std::vector<std::pair<int, int>>(); // Return a pointer on a vectore containing all possible third pawn for a three v->push_back(std::make_pair(x1 - 1, y1)); v->push_back(std::make_pair(x2 + 1, y2)); if (_isEmpty(x1 - 2, y1, grid)) v->push_back(std::make_pair(x1 - 2, y1)); if (_isEmpty(x2 + 2, y2, grid)) v->push_back(std::make_pair(x2 + 2, y2)); return v; } } else if (x1 != x2 && y1 != y2){ // Diagonal alignement if ((x1 < x2 && y1 < y2) || (x2 < x1 && y2 < y1)){ // o // o if ((x2 < x1 && y2 < y1)){ _swapInt(x1, x2); _swapInt(y1, y2); } if (x1 - 1 >= 0 && y1 - 1 >= 0 && x2 + 1 < GRID_SIZE && y2 + 1 < GRID_SIZE && _isEmpty(x1 - 1, y1 - 1, grid) && _isEmpty(x2 + 1, y2 + 1, grid)){ // Return a pointer on a vectore containing all possible third pawn for a three std::vector<std::pair<int, int>> *v = new std::vector<std::pair<int, int>>(); v->push_back(std::make_pair(x1 - 1, y1 - 1)); v->push_back(std::make_pair(x2 + 1, y2 + 1)); if (_isEmpty(x1 - 2, y1 - 2, grid)) v->push_back(std::make_pair(x1 - 2, y1 - 2)); if (_isEmpty(x2 + 2, y2 + 2, grid)) v->push_back(std::make_pair(x2 + 2, y2 + 2)); return v; } } else if ((x1 > x2 && y1 < y2) || (x2 > x1 && y2 < y1)){ // o // o if ((x2 > x1 && y2 < y1)){ _swapInt(x1, x2); _swapInt(y1, y2); } if (x1 + 1 < GRID_SIZE && y1 - 1 >= 0 && x2 - 1 >= 0 && y2 + 1 < GRID_SIZE && _isEmpty(x1 + 1, y1 - 1, grid) && _isEmpty(x2 - 1, y2 + 1, grid)){ // Return a pointer on a vectore containing all possible third pawn for a three std::vector<std::pair<int, int>> *v = new std::vector<std::pair<int, int>>(); v->push_back(std::make_pair(x1 + 1, y1 - 1)); v->push_back(std::make_pair(x2 - 1, y2 + 1)); if (_isEmpty(x1 + 2, y1 - 2, grid)) v->push_back(std::make_pair(x1 + 2, y1 - 2)); if (_isEmpty(x2 - 2, y2 + 2, grid)) v->push_back(std::make_pair(x2 - 2, y2 + 2)); return v; } } } return NULL; }
//----------------------------------------------------------------------- CollisionModelManager::CacheItem* CollisionModelManager::_back(void) const { assert(!_isEmpty()); return mCacheItemSentinel.prev; }
//----------------------------------------------------------------------- CollisionModelManager::CacheItem* CollisionModelManager::_front(void) const { assert(!_isEmpty()); return mCacheItemSentinel.next; }