bool Scene::enterScene(ServiceID avatarID, const std::string & token, SessionID sID) { EntityPtr entity = getUserEntity(avatarID); if (!entity) { return false; } if (entity->_token != token) { return false; } entity->_clientSessionID = sID; if (!getEntity(entity->_info.eid)) { addEntity(entity); } FillSceneNotice notice; EntityFullInfo info; for (auto kv : _entitys) { kv.second->pickProto(info); notice.entitys.push_back(info); } notice.serverTime = getFloatNowTime(); notice.sceneStartTime = _startTime; notice.sceneEndTime = _endTime; sendToClient(avatarID, notice); return true; }
void TestUtls(std::function<int(void)> fun, std::string name) { LOG_STREAM(LOG4Z_MAIN_LOGGER_ID, LOG_LEVEL_ALARM, nullptr, 0, ""); LOGA("begin test ----[" << name << "]----"); double now = getFloatNowTime(); int ret = fun(); if (ret == 0) { LOGA("end test ----[" << name << "](0)----" << " used second=" << getFloatNowTime() - now); } else { LOGE("end test ----[" << name << "](" << ret << ")----" << " used second=" << getFloatNowTime() - now ); exit(ret); } }
bool Scene::loadScene(SCENE_TYPE sceneType) { if (_sceneStatus != SCENE_STATUS_NONE) { LOGE("Scene::loadScene scene status error"); return false; } _sceneType = sceneType; _sceneStatus = SCENE_STATUS_WAIT; _lastStatusChangeTime = getFloatNowTime(); _startTime = getFloatNowTime(); _endTime = getFloatNowTime() + 3600; //load map //load entitys SceneMgr::getRef().refreshSceneStatusToWorld(getSceneID()); return true; }
bool Scene::removeEntity(EntityID eid) { RemoveEntityNotice notice; notice.eids.push_back(eid); notice.serverTime = getFloatNowTime(); _entitys.erase(eid); broadcast(notice); return true; }
bool Scene::addEntity(EntityPtr entity) { _entitys.insert(std::make_pair(entity->_info.eid, entity)); AddEntityNotice notice; EntityFullInfo full; entity->pickProto(full); notice.entitys.push_back(full); notice.serverTime = getFloatNowTime(); broadcast(notice, entity->_base.avatarID); return true; }
bool Scene::cleanScene() { _lastEID = ServerConfig::getRef().getSceneConfig()._sceneID * 1000 + 1000; _entitys.clear(); _players.clear(); _sceneType = SCENE_TYPE_NONE; _sceneStatus = SCENE_STATUS_NONE; _lastStatusChangeTime = getFloatNowTime(); SceneMgr::getRef().refreshSceneStatusToWorld(getSceneID()); return true; }
bool Scene::initScene(SCENE_TYPE sceneType, MapID mapID) { if (_sceneStatus != SCENE_STATE_NONE) { LOGE("Scene::loadScene scene status error"); return false; } double now = getFloatNowTime(); _sceneType = sceneType; _mapID = mapID; _sceneStatus = SCENE_STATE_ACTIVE; _lastEID = ServerConfig::getRef().getSceneConfig()._lineID * 1000 + 1000; _startTime = getFloatSteadyNowTime(); _endTime = getFloatSteadyNowTime() + 600; _move = std::make_shared<MoveSync>(); _move->init(shared_from_this()); _skill = std::make_shared<Skill>(); _skill->init(shared_from_this()); _ai = std::make_shared<AI>(); _ai->init(shared_from_this()); _script = std::make_shared<Script>(); _script->init(shared_from_this()); //load map //load entitys onSceneInit(); LOGD("initScene success. used time=" << getFloatNowTime() - now); return true; }
EntityPtr Scene::makeNewEntity(const AvatarBaseInfo & base) { EntityPtr entity = std::make_shared<Entity>(); entity->_base = base; entity->_control.spawnpoint = { 0.0,0.0 }; entity->_info.eid = ++_lastEID; entity->_control.eid = entity->_info.eid; entity->_report.eid = entity->_info.eid; entity->_control.stateChageTick = getFloatNowTime(); entity->_info.color = ECOLOR_NONE; entity->_info.curHP = entity->_base.hp; entity->_info.moveAction = MACTION_IDLE; entity->_info.pos = entity->_control.spawnpoint; entity->_info.state = ESTATE_NONE; return entity; }