Пример #1
0
bool 
CreatureCore::RunTick(float delta_time)
{
	std::lock_guard<std::mutex> scope_lock(*update_lock);

	if (is_driven)
	{
		UpdateCreatureRender();
		FillBoneData();

		return true;
	}

	if (is_disabled)
	{
		return false;
	}

	if (creature_manager)
	{
		ParseEvents(delta_time);

		if (should_play) {
			creature_manager->Update(delta_time);
		}

		UpdateCreatureRender();

		FillBoneData();

	}

	return true;
}
Пример #2
0
bool GYListManager::verifyVer(const GameZone_t &gameZone, DWORD verify_client_version, BYTE &retcode)
{
	Zebra::logger->trace("GYListManager::verifyVer");
	zMutex_scope_lock scope_lock(mlock);
	bool retval = false;
	GYList *ret = NULL, *tmp = NULL;
	__gnu_cxx::pair<GYListContainer_iterator, GYListContainer_iterator> hps = gyData.equal_range(gameZone);
	for(GYListContainer_iterator it = hps.first; it != hps.second; ++it)
	{
		tmp = &(it->second);
		if (state_none == tmp->state
				&& (NULL == ret
					|| ret->wdNumOnline >= tmp->wdNumOnline))
		{
			ret = tmp;
		}
	}
	if (NULL == ret)
	{
		retcode = Cmd::LOGIN_RETURN_GATEWAYNOTAVAILABLE;
	}
	else if (ret->zoneGameVersion && ret->zoneGameVersion != verify_client_version)
	{
		retcode = Cmd::LOGIN_RETURN_VERSIONERROR;
	}
	else
	{
		retval = true;
	}
	return retval;
}
Пример #3
0
	bool handle_input_event(input_event eventid, void* eventdata) override
	{
		// Only handle raw input data
		if (!input_enabled() || eventid != INPUT_EVENT_RAWINPUT)
			return FALSE;

		HRAWINPUT rawinputdevice = *static_cast<HRAWINPUT*>(eventdata);

		BYTE small_buffer[4096];
		std::unique_ptr<BYTE[]> larger_buffer;
		LPBYTE data = small_buffer;
		BOOL result;
		UINT size;

		// ignore if not enabled
		if (!input_enabled())
			return FALSE;

		// determine the size of databuffer we need
		if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0)
			return FALSE;

		// if necessary, allocate a temporary buffer and fetch the data
		if (size > sizeof(small_buffer))
		{
			larger_buffer = std::make_unique<BYTE[]>(size);
			data = larger_buffer.get();
			if (data == nullptr)
				return FALSE;
		}

		// fetch the data and process the appropriate message types
		result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER));
		if (result)
		{
			std::lock_guard<std::mutex> scope_lock(m_module_lock);

			rawinput_device *devinfo;
			// find the device in the list and update
			for (int i = 0; i < devicelist()->size(); i++)
			{
				devinfo = dynamic_cast<rawinput_device*>(devicelist()->at(i));
				if (devinfo)
				{
					RAWINPUT *input = reinterpret_cast<RAWINPUT*>(data);
					if (input->header.hDevice == devinfo->device_handle())
					{
						devinfo->queue_events(input, 1);
						result = TRUE;
					}
				}
			}
		}

		return result;
	}
Пример #4
0
void duplicateManager::registerMap(DWORD id,zTiles* _zTiles)
{
    zMutex_scope_lock scope_lock(mutex);
	dupMapCopy_it it = _dupMapCopy.find(id);
	if(it != _dupMapCopy.end())
	{
		zTiles * newTiles = new zTiles(_zTiles->begin(),_zTiles->end());
		_dupMapCopy[id] = newTiles;
	}
}
Пример #5
0
void duplicateManager::doClear()
{
		zMutex_scope_lock scope_lock(mutex);
		std::list<clearDupStruct>::iterator it = _recycleList.begin();
	    std::list<clearDupStruct>::iterator end = _recycleList.end();
		for( ; it != end;)
		{
			clearDup(it);
		}
}
Пример #6
0
//离开副本
bool duplicateManager::leaveDup(SceneUser *user,unsigned short index)
{
	zMutex_scope_lock scope_lock(mutex);
	if(user)
	{
		
		dupToUserMap_it it = _dupToUserMap.find(index);
		if(it != _dupToUserMap.end())
		{
			//_dupToUserMap[index]->push_back(user);
			std::list<SceneUser*>::iterator it = _dupToUserMap[index]->begin();
			std::list<SceneUser*>::iterator end = _dupToUserMap[index]->end();
			for(  ; it != end; ++it)
			{
				if((*it) == user)
				{
					_dupToUserMap[index]->erase(it);
					break;
				}
			}

			//找不到用户
			if(it == end)
				return false;




			fprintf(stderr,"用户离开副本%u\n",index);


			userDupMaps_it _userDupMaps_it = _userDupMaps.find(user->id);

			if(_userDupMaps_it != _userDupMaps.end())
			{
				userDupMap *_userDupMap = _userDupMaps_it->second;
				_userDupMap->_index = 0;
			}

			//用户已经全部离开副本
			if(_dupToUserMap[index]->empty())
			{
				fprintf(stderr,"用户已全部离开副本%u\n",index);
				clearDupStruct _clearDupStruct;
				_clearDupStruct.dupIndex = index;
				_clearDupStruct.timeStamp = time(NULL);
				putARecycleDup(_clearDupStruct);
				
				
			}
		}
	}

	return false;
}
Пример #7
0
	bool handle_input_event(input_event eventid, void* eventdata) override
	{
		// Only handle raw input data
		if (!input_enabled() || eventid != INPUT_EVENT_RAWINPUT)
			return false;

		HRAWINPUT rawinputdevice = *static_cast<HRAWINPUT*>(eventdata);

		BYTE small_buffer[4096];
		std::unique_ptr<BYTE[]> larger_buffer;
		LPBYTE data = small_buffer;
		UINT size;

		// ignore if not enabled
		if (!input_enabled())
			return false;

		// determine the size of databuffer we need
		if ((*get_rawinput_data)(rawinputdevice, RID_INPUT, nullptr, &size, sizeof(RAWINPUTHEADER)) != 0)
			return false;

		// if necessary, allocate a temporary buffer and fetch the data
		if (size > sizeof(small_buffer))
		{
			larger_buffer = std::make_unique<BYTE[]>(size);
			data = larger_buffer.get();
			if (data == nullptr)
				return false;
		}

		// fetch the data and process the appropriate message types
		bool result = (*get_rawinput_data)(static_cast<HRAWINPUT>(rawinputdevice), RID_INPUT, data, &size, sizeof(RAWINPUTHEADER));
		if (result)
		{
			std::lock_guard<std::mutex> scope_lock(m_module_lock);

			RAWINPUT *input = reinterpret_cast<RAWINPUT*>(data);

			// find the device in the list and update
			auto target_device = std::find_if(devicelist()->begin(), devicelist()->end(), [input](auto &device)
			{
				auto devinfo = dynamic_cast<rawinput_device*>(device.get());
				return devinfo != nullptr && input->header.hDevice == devinfo->device_handle();
			});

			if (target_device != devicelist()->end())
			{
				static_cast<rawinput_device*>((*target_device).get())->queue_events(input, 1);
				return true;
			}
		}

		return false;
	}
Пример #8
0
void Logger::DoRawPrint(const str& message, LogLevel level) {
	if (parent_) {
		parent_->DoRawPrint(message, level);
	}

	ScopeSpinLock scope_lock(logger_list_lock_);
	std::vector<LogListener*>::iterator x = logger_list_[level].begin();
	for (; x != logger_list_[level].end(); ++x) {
		(*x)->WriteLog(message, level);
	}
}
Пример #9
0
void Logger::DoPrint(const Logger* originator, const str& account, const str& message, LogLevel level) {
	if (parent_) {
		parent_->DoPrint(this, account, message, level);
	}

	ScopeSpinLock scope_lock(logger_list_lock_);
	std::vector<LogListener*>::iterator x = logger_list_[level].begin();
	for (; x != logger_list_[level].end(); ++x) {
		(*x)->OnLog(originator, account, message, level);
	}
}
Пример #10
0
void GYListManager::disableAll(const GameZone_t &gameZone)
{
	Zebra::logger->trace("GYListManager::disableAll");
	zMutex_scope_lock scope_lock(mlock);
	__gnu_cxx::pair<GYListContainer_iterator, GYListContainer_iterator> hps = gyData.equal_range(gameZone);
	for(GYListContainer_iterator it = hps.first; it != hps.second; ++it)
	{
		it->second.wdPort = 0;
		it->second.wdNumOnline = 0;
		it->second.state = state_maintain;
	}
}
Пример #11
0
bool duplicateManager::removeNpc(SceneNpc *npc,unsigned short index)
{
	zMutex_scope_lock scope_lock(mutex);
	hash_map<DWORD,SceneNpc*>::iterator it = _dupMapNpc[index]->find((DWORD)npc);
	if(it != _dupMapNpc[index]->end())
	{
		_dupMapNpc[index]->erase(it);
		return true;
	}

	return false;
}
Пример #12
0
bool duplicateManager::removeObj(zSceneObject *obj,unsigned short index)
{
	zMutex_scope_lock scope_lock(mutex);
	hash_map<DWORD,zSceneObject*>::iterator it = _dupMapObj[index]->find((DWORD)obj);
	if(it != _dupMapObj[index]->end())
	{
		_dupMapObj[index]->erase(it);
		return true;
	}

	return false;
}
Пример #13
0
void Logger::UpdateLevelThreashold() {
	LogLevel level = level_;
	ScopeSpinLock scope_lock(logger_list_lock_);
	for (int x = kLevelLowestType; x < kLevelTypeCount; ++x) {
		std::vector<LogListener*>::const_iterator y = logger_list_[x].begin();
		for (; y != logger_list_[x].end(); ++y) {
			LogLevel listener_level = (*y)->GetLevelThreashold();
			level = (level < listener_level) ? level : listener_level;
		}
	}
	LogDecorator::SetLogLevel(level);
}
Пример #14
0
void xinput_joystick_device::configure()
{
	std::lock_guard<std::mutex> scope_lock(m_device_lock);

	if (m_configured)
		return;

	// Add the axes
	for (int axisnum = 0; axisnum < XINPUT_MAX_AXIS; axisnum++)
	{
		device()->add_item(
			xinput_axis_name[axisnum],
			xinput_axis_ids[axisnum],
			generic_axis_get_state<LONG>,
			&gamepad.left_thumb_x + axisnum);
	}

	// Populate the POVs
	// For XBOX, we treat the DPAD as a hat switch
	for (int povnum = 0; povnum < XINPUT_MAX_POV; povnum++)
	{
		device()->add_item(
			xinput_pov_names[povnum],
			ITEM_ID_OTHER_SWITCH,
			generic_button_get_state<BYTE>,
			&gamepad.povs[povnum]);
	}

	// populate the buttons
	for (int butnum = 0; butnum < XINPUT_MAX_BUTTONS; butnum++)
	{
		device()->add_item(
			xinput_button_names[butnum],
			static_cast<input_item_id>(ITEM_ID_BUTTON1 + butnum),
			generic_button_get_state<BYTE>,
			&gamepad.buttons[butnum]);
	}

	device()->add_item(
		"Left Trigger",
		ITEM_ID_ZAXIS,
		generic_axis_get_state<LONG>,
		&gamepad.left_trigger);

	device()->add_item(
		"Right Trigger",
		ITEM_ID_RZAXIS,
		generic_axis_get_state<LONG>,
		&gamepad.right_trigger);

	m_configured = true;
}
Пример #15
0
LogListener* Logger::GetListener(const str& name) const {
	LogListener* listener = 0;
	ScopeSpinLock scope_lock(logger_list_lock_);
	for (int x = kLevelLowestType; !listener && x < kLevelTypeCount; ++x) {
		std::vector<LogListener*>::const_iterator y = logger_list_[x].begin();
		for (; !listener && y != logger_list_[x].end(); ++y) {
			if ((*y)->GetName() == name) {
				listener = *y;
			}
		}
	}
	return (listener);
}
Пример #16
0
void BillCache::remove(const char *tid)
{
  if (tid)
  {
    zMutex_scope_lock scope_lock(mlock);
    iter it = cache.find(tid);
    if (it != cache.end())
    {
      BillData *retval = it->second;
      cache.erase(it);
      SAFE_DELETE(retval);
    }
  }
}
zTCPServer::~zTCPServer()
{
	//m_ioService_.stop();
	stop();
	m_bMain = false;
	SAFE_DELETE(m_pAcceptor_);

	zMutex_scope_lock scope_lock(m_lock);
	for(std::vector<zTCPTask*>::iterator iter = m_TaskVec.begin(); iter != m_TaskVec.end(); ++iter)
	{
		zTCPTask* pTask = *iter;
		SAFE_DELETE(pTask);
	}
	m_TaskVec.clear();
}
Пример #18
0
	//添加NPC到副本
bool duplicateManager::addNPC(SceneNpc *npc)
{
	zMutex_scope_lock scope_lock(mutex);
	dupMapNpc_it it = _dupMapNpc.find(npc->dupIndex);
	fprintf(stderr,"添加一个NPC到副本%u\n",npc->dupIndex);
	if(it == _dupMapNpc.end())
	{
		hash_map<DWORD,SceneNpc*>* _list = new hash_map<DWORD,SceneNpc*>;
		(*_list)[(DWORD)npc] = npc;
		_dupMapNpc[npc->dupIndex] = _list;
	}
	else
	{
		(*_dupMapNpc[npc->dupIndex])[(DWORD)npc] = npc;
	}
	return true;
}
Пример #19
0
void Logger::AddListener(LogListener* logger, LogLevel level) {
	deb_assert(logger);
#ifdef NO_LEVEL_DEBUG_INFO	// Final (public release) version gets no debug messages.
	if (level >= kLevelInfo)
#endif // !NO_LEVEL_DEBUG_INFO
	{
		deb_assert(level >= kLevelLowestType && level < kLevelTypeCount);
		if (level >= kLevelLowestType && level < kLevelTypeCount) {
			ScopeSpinLock scope_lock(logger_list_lock_);
			logger_list_[level].push_back(logger);
			logger->AddLog(this);
			if (logger->GetLevelThreashold() < LogDecorator::GetLogLevel()) {
				LogDecorator::SetLogLevel(logger->GetLevelThreashold());
			}
		}
	}
}
Пример #20
0
BillData *BillCache::get(const char *tid)
{
  BillData *retval = NULL;

  if (tid)
  {
    zMutex_scope_lock scope_lock(mlock);
    iter it = cache.find(tid);
    if (it != cache.end())
    {
      retval = it->second;
      cache.erase(it);
    }
  }

  return retval;
}
Пример #21
0
	void process_events(running_machine &machine) override
	{
		std::lock_guard<std::mutex> scope_lock(m_lock);
		XEvent xevent;

		//Get XInput events
		while (XPending(m_display) != 0)
		{
			XNextEvent(m_display, &xevent);

			// Find all subscribers for the event type
			auto subscribers = m_subscription_index.equal_range(xevent.type);

			// Dispatch the events
			for (auto iter = subscribers.first; iter != subscribers.second; iter++)
				iter->second->handle_event(xevent);
		}
	}
Пример #22
0
DWORD GYListManager::getOnline(void)
{
	DWORD                    dwCount;
	GYList                   *pGYL;
	GYListContainer_iterator pGYLCI;

	Zebra::logger->debug("GYListManager::getOnline");
	zMutex_scope_lock scope_lock(mlock);

	dwCount = 0;
	for(pGYLCI=gyData.begin();pGYLCI != gyData.end();pGYLCI++)
	{
		pGYL = &(pGYLCI->second);
		dwCount += pGYL->wdNumOnline;
	}

	return dwCount;
}
Пример #23
0
bool duplicateManager::addObj(zSceneObject *obj)
{
	zMutex_scope_lock scope_lock(mutex);
	dupMapObj_it it = _dupMapObj.find(obj->dupIndex);
	fprintf(stderr,"添加一个Obj到副本%u\n",obj->dupIndex);
	if(it == _dupMapObj.end())
	{
		hash_map<DWORD,zSceneObject*>* _list = new hash_map<DWORD,zSceneObject*>;
		(*_list)[(DWORD)obj]= obj;
		_dupMapObj[obj->dupIndex] = _list;
	}
	else
	{
		//_dupMapObj[obj->dupIndex]->push_back(obj);
		(*_dupMapObj[obj->dupIndex])[(DWORD)obj] = obj;
	}
	return true;
}
Пример #24
0
/**
 * \brief 随机获取一个人数最小的网关信息
 * \return 网关信息
 */
GYList *GYListManager::getAvl(const GameZone_t &gameZone)
{
	Zebra::logger->trace("GYListManager::getAvl");
	zMutex_scope_lock scope_lock(mlock);
	GYList *ret = NULL, *tmp = NULL;
	__gnu_cxx::pair<GYListContainer_iterator, GYListContainer_iterator> hps = gyData.equal_range(gameZone);
	for(GYListContainer_iterator it = hps.first; it != hps.second; ++it)
	{
		tmp = &(it->second);
		if (state_none == tmp->state
				&& (NULL == ret
					|| ret->wdNumOnline >= tmp->wdNumOnline))
		{
			ret = tmp;
		}
	}
	return ret;
}
Пример #25
0
void sdl_event_manager::process_events(running_machine &machine)
{
	std::lock_guard<std::mutex> scope_lock(m_lock);
	SDL_Event sdlevent;
	while (SDL_PollEvent(&sdlevent))
	{
		// process window events if they come in
		if (sdlevent.type == SDL_WINDOWEVENT)
			process_window_event(machine, sdlevent);

		// Find all subscribers for the event type
		auto subscribers = m_subscription_index.equal_range(sdlevent.type);

		// Dispatch the events
		for (auto iter = subscribers.first; iter != subscribers.second; iter++)
			iter->second->handle_event(sdlevent);
	}
}
Пример #26
0
void Logger::RemoveListener(LogListener* logger) {
	deb_assert(logger);
	{
		ScopeSpinLock scope_lock(logger_list_lock_);
		for (int x = kLevelLowestType; x < kLevelTypeCount; ++x) {
			std::vector<LogListener*>::iterator y = logger_list_[x].begin();
			for (; y != logger_list_[x].end(); ++y) {
				if (*y == logger) {
					logger_list_[x].erase(y);
					break;
				}
			}
		}
		logger->RemoveLog(this);
	}
	if (logger->GetLevelThreashold() == LogDecorator::GetLogLevel()) {
		UpdateLevelThreashold();
	}
}
Пример #27
0
/**
 * \brief 获取网关列表
 * \return 网关信息
 */
void GYListManager::full_ping_list(Cmd::stPingList* cmd, const GameZone_t& gameZone)
{
	Zebra::logger->trace("GYListManager::full_ping_list");
	zMutex_scope_lock scope_lock(mlock);
	GYList *ret = NULL;
	const int per_num = 5;   // 档数
	int server_num = gyData.count(gameZone);
	int max_per = server_num * 2000;  // 最大人数
	int per_per = max_per/per_num; // 分成五档,每一档的人数
	int total_personal = 0; // 该区总人数
	int i=0;

	__gnu_cxx::pair<GYListContainer_iterator, GYListContainer_iterator> hps = gyData.equal_range(gameZone);

	cmd->zone_id = gameZone.id;
	//      Cmd::ping_element* tempElement = cmd->ping_list;

	for (GYListContainer_iterator it = hps.first; it != hps.second; ++it, i++)
	{
		ret = &(it->second);
		if (state_none == ret->state)
		{
			if (i<server_num)
			{
				strncpy((char*)cmd->ping_list.gateway_ip, (char*)ret->pstrIP, 15);
				total_personal += ret->wdNumOnline;
			}
			else
			{
				break;
			}
		}
	}

	for (int i=0; i<5; i++)
	{
		if (total_personal>=per_per*i && total_personal<(per_per*(i+1)-1))
		{
			cmd->ping_list.state = i;
			break;
		}
	}
}
Пример #28
0
void BillCache::update(const zTime &ct)
{
  zMutex_scope_lock scope_lock(mlock);
  for(iter it = cache.begin(); it != cache.end();)
  {
    if (ct.sec() > it->second->timeout
        && (ct.sec() - it->second->timeout) >= DEFAULT_BILL_TIMEOUT)
    {
      //TODO FIXME 这个交易超时,作废写日志
      Zebra::logger->debug("tradeSN timeout: %s",it->second->tid);
      iter tmp = it;
      BillData *bd = tmp->second;
      ++it;
      cache.erase(tmp);
      SAFE_DELETE(bd);
    }
    else
      ++it;
  }
}
Пример #29
0
/**
 * \brief 添加网关信息
 * 如果已经存在,直接更新信息,没有需要新建立记录
 * \param gameZone 游戏区信息
 * \param gy 网关信息
 * \return 添加是否成功
 */
bool GYListManager::put(const GameZone_t &gameZone, const GYList &gy)
{
	Zebra::logger->trace("GYListManager::put");
	zMutex_scope_lock scope_lock(mlock);
	__gnu_cxx::pair<GYListContainer_iterator, GYListContainer_iterator> hps = gyData.equal_range(gameZone);
	for(GYListContainer_iterator it = hps.first; it != hps.second; ++it)
	{
		if (it->second.wdServerID == gy.wdServerID)
		{
			//找到了,只是更新,只限于网关连接数和网关状态
			bcopy(gy.pstrIP, it->second.pstrIP, MAX_IP_LENGTH);
			it->second.wdPort = gy.wdPort;
			it->second.wdNumOnline = gy.wdNumOnline;
			it->second.state = gy.state;
			return true;
		}
	}

	//没有找到,需要插入新的记录
	gyData.insert(GYListContainer_value_type(gameZone, gy));
	return true;
}
	void CreateDirectVertexData()
	{
		const int x_id = 0;
		const int y_id = 2;
		const int z_id = 1;

		FScopeLock scope_lock(update_lock.Get());

		if (VertexCache.Num() != point_num)
		{
			VertexCache.Reset(point_num);
			VertexCache.AddUninitialized(point_num);
		}

#ifdef CREATURE_MULTICORE
		ParallelFor(this->point_num, [&](int32 i) {
#else
		for (int32 i = 0; i < this->point_num; i++) {
#endif
			FDynamicMeshVertex& curVert = VertexCache[i];

			int pos_idx = i * 3;
			curVert.Position = FVector(this->points[pos_idx + x_id],
				this->points[pos_idx + y_id],
				this->points[pos_idx + z_id]);

			float set_alpha = (*this->region_alphas)[i];
			curVert.Color = FColor(set_alpha, set_alpha, set_alpha, set_alpha);

			int uv_idx = i * 2;
			for (int texCoord = 0; texCoord < MAX_STATIC_TEXCOORDS; texCoord++)
			{
				curVert.TextureCoordinate[texCoord].Set(this->uvs[uv_idx], this->uvs[uv_idx + 1]);
			}
#ifdef CREATURE_MULTICORE
		});
#else
		}