void heartbeat() { float now = getCurrentTime() / (float)1000.0; startTimer(); checkCollisions(); cellsClear(cells); cvsFillStyle("black"); cvsFillRect(0, 0, getWidth(), getHeight()); for(int i=0; i<numEntities; i++) { Entity *ent = objects[i]; if(ent) { updateEntity(ent, now - last); renderEntity(ent); cellsAdd(cells, ent, ent->pos.x, ent->pos.y); cellsAdd(cells, ent, ent->pos.x + ent->size.x, ent->pos.y); cellsAdd(cells, ent, ent->pos.x, ent->pos.y + ent->size.y); cellsAdd(cells, ent, ent->pos.x + ent->size.x, ent->pos.y + ent->size.y); } } //renderDebug(); endTimer(); last = now; }
static void updateEntities(PlayState *playState, EntityNode **entities, GameContext *gameContext, UserInput *userInput, GameMemory *gameMemory) { for (EntityNode **entityNode = entities; *entityNode;) { V2D position = getEntityScreenPosition(&(*entityNode)->entity, gameContext->cameraPosition); if (((*entityNode)->entity.type == PLAYER_BULLET_TYPE || (*entityNode)->entity.type == ENEMY_BULLET_TYPE || (*entityNode)->entity.type == NULL_ENTITY_TYPE) && (position.x < -(*entityNode)->entity.bitmap.width || position.x > gameContext->gameWidth + (*entityNode)->entity.bitmap.width || position.y < -(*entityNode)->entity.bitmap.height || position.y > gameContext->gameHeight + (*entityNode)->entity.bitmap.height || (*entityNode)->entity.dyingCounter == 1)) { (*entityNode)->entity.dyingCounter = 0; EntityNode *freeEntity = *entityNode; // NOTE: must modify the pointer itself *entityNode = (*entityNode)->next; freeEntity->next = playState->freeEntities; playState->freeEntities = freeEntity; assert((*entityNode == 0) || (*entityNode != (*entityNode)->next)); } else { updateEntity(playState, &(*entityNode)->entity, gameContext, userInput, gameMemory); moveEntity(playState, &(*entityNode)->entity, gameContext, userInput); entityNode = &(*entityNode)->next; assert((*entityNode == 0) || (*entityNode != (*entityNode)->next)); } } }
/** \brief Constructor. The iterator will go over the range [\p begin, \p * end). */ ConcreteRangeEntityIterator(const DuneEntityIt &begin, const DuneEntityIt &end, const DomainIndex &domain_index) : m_begin(begin), m_end(end), m_cur(begin), m_entity(domain_index), m_domain_index(domain_index) { updateFinished(); updateEntity(); }
void update(int deltaTimeMs) { float deltaTimeS = (float) deltaTimeMs / 1000; for (int i = 0; i < MAX_ENTITIES; i++) { if (entities[i] != NULL) updateEntity(entities[i], deltaTimeS); } updateCamera(); }
void System::update() { preUpdate(); auto it = entities.begin(); while(it != entities.end()){ updateEntity(**it); it++; } postUpdate(); }
void GameProcessState::update(const float & elapsed) { for (auto i = planes_.begin(); i != planes_.end();) { if ((*i)->getHitpoints() <= 0 || isEntityCollide(*i, world_)) { i = planes_.erase(i); } else { updateEntity(*i, elapsed); i++; } } }
void EntitiesPacketHandler::handlePacket(uint8_t* param, const pcap_pkthdr* header, const uint8_t* pkt_data) { if (!isEntitiesPacket(param, header, pkt_data)) return; // bit of a hacky way of doing it but basically search for 0a 0d 08, // which occurs at all the packets that we're interested in and identifies // the start of the serialized entity deserialize::Entity entityDeserializer; // advance to the start of the entity Stream stream = Stream(pkt_data, header->len); advance(stream, 74); // NOTE: the 0a is the start of a base networkable - the 0c is the length // of the base networkable, the 08 is the first byte written by the base networkable constexpr uint8_t searchFor[] = { 0x0a, 0x0c, 0x08 }; while (stream.bytes - stream.bytesStart < stream.len - 4) { // advance to the next entity uint8_t const * nextEntity = std::search(stream.bytes, stream.bytesEnd, searchFor, searchFor + 3); if (nextEntity == stream.bytesEnd) break; advance(stream, nextEntity - stream.bytes); // deserialize it entityDeserializer.reset(); entityDeserializer.deserialize(stream); // if we got a BasePlayer from it, print out the stats if (entityDeserializer.baseNetworkable.hasSerialized() && entityDeserializer.basePlayer.hasSerialized()) { updateEntity(entityDeserializer); } } }
void updateGame(Game* game) { int time = SDL_GetTicks(); game->delta = (float)(time - game->lastTime) / 1000.0f; game->lastTime = time; for(int i = 0; i < MAX_KEYS; ++i) game->keysPressed[i] = game->keysReleased[i] = false; SDL_Event event; while (SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: game->running = false; break; case SDL_KEYUP: game->keys[event.key.keysym.sym & 255] = false; game->keysPressed[event.key.keysym.sym & 255] = true; break; case SDL_KEYDOWN: game->keys[event.key.keysym.sym & 255] = true; game->keysReleased[event.key.keysym.sym & 255] = true; break; case SDL_MOUSEBUTTONDOWN: break; case SDL_MOUSEBUTTONUP: break; } } updateBackground(game); updateBehaviorPools(game, &game->behaviorPools); for(int i = 0; i < MAX_ENTITIES_PER_GAME; ++i) if(game->entities[i].alive) updateEntity(game, &game->entities[i]); updateParticles(game); }
virtual void next() { ++m_cur; updateFinished(); updateEntity(); }
/** \brief Constructor */ ConcreteEntityPointer(const DuneEntityPointer &dune_entity_pointer, const DomainIndex &domain_index) : m_dune_entity_ptr(dune_entity_pointer), m_entity(domain_index) { updateEntity(); }
int ClientNetwork::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: packetReceived(); break; case 1: packetCorrupted(); break; case 2: pingUpdated((*reinterpret_cast< quint32(*)>(_a[1]))); break; case 3: chatReceived((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[4]))); break; case 4: serverInformationsChanged((*reinterpret_cast< ServerInformations(*)>(_a[1]))); break; case 5: clientIDChanged((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 6: nicknameChanged((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 7: error((*reinterpret_cast< ENUM_TYPE(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 8: clientVoted((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break; case 9: newGameMaster((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 10: serverName((*reinterpret_cast< QString(*)>(_a[1]))); break; case 11: motdChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 12: gameLaunched(); break; case 13: narrationChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 14: mapChanged((*reinterpret_cast< MapPtr(*)>(_a[1]))); break; case 15: mapFlare((*reinterpret_cast< QPoint(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break; case 16: scriptToGMMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 17: scriptToOwnerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 18: scriptActionMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 19: scriptToPlayerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 20: scriptMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 21: scriptError((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 22: updateEntities((*reinterpret_cast< const QList<EntityInformations>(*)>(_a[1]))); break; case 23: updateEntity((*reinterpret_cast< const EntityInformations(*)>(_a[1]))); break; case 24: entityDeleted((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 25: scriptReceived((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 26: ressourcesUpdated((*reinterpret_cast< const QMap<QString,RSID>(*)>(_a[1]))); break; case 27: connectionEtablished(); break; case 28: connectionLost(); break; case 29: diceRolled((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])),(*reinterpret_cast< quint16(*)>(_a[3]))); break; case 30: sanctionned((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break; case 31: clientJoined((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 32: clientLeft((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 33: playSound((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 34: syncLibs((*reinterpret_cast< QList<SoundLibInformations>(*)>(_a[1]))); break; case 35: syncLanguagesList((*reinterpret_cast< QList<QPair<QString,QString> >(*)>(_a[1]))); break; case 36: syncDictionariesList((*reinterpret_cast< QStringList(*)>(_a[1]))); break; case 37: syncScriptList((*reinterpret_cast< QStringList(*)>(_a[1]))); break; case 38: updateCharacterList((*reinterpret_cast< const QStringList(*)>(_a[1]))); break; case 39: send((*reinterpret_cast< Packet*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break; case 40: send((*reinterpret_cast< Packet*(*)>(_a[1]))); break; case 41: send((*reinterpret_cast< Packet(*)>(_a[1]))); break; case 42: send((*reinterpret_cast< qint32(*)>(_a[1])),(*reinterpret_cast< const QByteArray(*)>(_a[2]))); break; case 43: ping(); break; case 44: { qint32 _r = getPing(); if (_a[0]) *reinterpret_cast< qint32*>(_a[0]) = _r; } break; case 45: { QString _r = serverIP(); if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; } break; case 46: { quint16 _r = serverPort(); if (_a[0]) *reinterpret_cast< quint16*>(_a[0]) = _r; } break; case 47: flush(); break; case 48: connection(); break; case 49: disconnection(); break; case 50: { bool _r = setServer((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 51: connected(); break; case 52: disconnected(); break; case 53: dataReceived(); break; case 54: socketError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break; case 55: operatePacket((*reinterpret_cast< Packet*(*)>(_a[1]))); break; default: ; } _id -= 56; } return _id; }
// Physics loop bool Physics::update() { updateFall(); updateMinecart(); updateEntity(); if (!enabled) { return true; } // Check if needs to be updated if (simList.empty()) { return true; } std::vector<vec> toAdd; std::vector<vec> toRem; std::set<vec> changed; clock_t starttime = clock(); LOG(INFO, "Physics", "Simulating " + dtos(simList.size()) + " items!"); uint32_t listSize = simList.size(); for (uint32_t simIt = 0; simIt < listSize; simIt++) { vec pos = simList[simIt].blocks[0].pos; // Blocks uint8_t block, meta; map->getBlock(pos, &block, &meta); simList[simIt].blocks[0].id = block; simList[simIt].blocks[0].meta = meta; bool used = false; for (int i = 0; i < 5; i++) { vec local(pos); bool falling = false; switch (i) { case 0: local += vec(0, -1, 0); // First tries to go down falling = true; break; case 1: local += vec(1, 0, 0); // Might be bad to have the 4 cardinal dir' // so predictable break; case 2: local += vec(-1, 0, 0); break; case 3: local += vec(0, 0, 1); break; case 4: local += vec(0, 0, -1); break; case 5: // local += vec(0,1,0); // Going UP break; } uint8_t newblock, newmeta; map->getBlock(pos, &block, &meta); map->getBlock(local, &newblock, &newmeta); if (!isLiquidBlock(block)) { toRem.push_back(pos); break; } if ((isWaterBlock(newblock) && isWaterBlock(block)) || (isLavaBlock(newblock) && isLavaBlock(block)) || (isLiquidBlock(block) && mayFallThrough(newblock))) { if (falling && !isLiquidBlock(newblock)) { map->setBlock(local, block, meta); changed.insert(local); map->setBlock(pos, BLOCK_AIR, 0); changed.insert(pos); toRem.push_back(pos); toAdd.push_back(local); used = true; continue; } if (falling && isLiquidBlock(newblock)) { int top = 8 - meta; int bot = 8 - newmeta; int volume = top + bot; if (volume > 8) { top = volume - 8; bot = 8; } else { top = 0; bot = volume; } int a_meta = 8 - top; int a_newmeta = 8 - bot; toAdd.push_back(local); if (a_meta == meta && a_newmeta == newmeta) { toRem.push_back(pos); toRem.push_back(local); continue; } if ((isWaterBlock(block) && a_meta < 8) || (isLavaBlock(block) && a_meta < 4)) { map->setBlock(pos, block, a_meta); changed.insert(pos); } else { map->setBlock(pos, BLOCK_AIR, 0); changed.insert(pos); } map->setBlock(local, block, a_newmeta); used = true; toAdd.push_back(local); toAdd.push_back(pos); changed.insert(pos); continue; } if (!isLiquidBlock(newblock)) { if (!falling) { if ((isWaterBlock(block) && meta == 7) || (isLavaBlock(block) && meta >= 3)) { toRem.push_back(pos); break; } } // We are spreading onto dry area. newmeta = 7; map->setBlock(local, block, newmeta); changed.insert(local); meta++; if (meta < 8) { map->setBlock(pos, block, meta); changed.insert(pos); } else { map->setBlock(pos, BLOCK_AIR, 0); changed.insert(pos); toRem.push_back(pos); } toAdd.push_back(local); used = true; continue; } if (meta < newmeta - 1 || (meta == newmeta && falling)) { newmeta --; map->setBlock(local, block, newmeta); changed.insert(local); meta ++; if (meta < 8) { map->setBlock(pos, block, meta); changed.insert(pos); } else { map->setBlock(pos, BLOCK_AIR, 0); changed.insert(pos); toRem.push_back(pos); } toAdd.push_back(local); used = true; continue; } } } if (!used) { toRem.push_back(pos); } } for (int i = int(toRem.size()) - 1; i >= 0; i--) { removeSimulation(toRem[i]); } for (size_t i = 0; i < toAdd.size(); i++) { addSimulation(toAdd[i]); } map->sendMultiBlocks(changed); //clock_t endtime = clock() - starttime; // LOG(INFO, "Physics", "Exit simulation, took " + dtos(endtime * 1000 / CLOCKS_PER_SEC) + " ms, " + dtos(simList.size()) + " items left"); return true; }
/** \brief Constructor. The iterator will go over the range [\p begin, \p end). */ ConcreteRangeEntityIterator(const DuneEntityIt& begin, const DuneEntityIt& end) : m_begin(begin), m_end(end), m_cur(begin) { updateFinished(); updateEntity(); }
void Universe::downloadEntities(){ for(unsigned int i = 0; i < vector_entities.size(); i++){ Entity *en = vector_entities[i]; updateEntity(en); } }