Ejemplo n.º 1
0
void Game::notifyComboChange(MyGUI::ComboBox* _sender, size_t _index){
	int st = static_cast<int>(Ogre::SHADOWTYPE_NONE);

	if( mUI.IsWidget(_sender,"shadow") ){
		st = static_cast<int>(getShadowTechnique( _index ));
		if( st != static_cast<int>(Ogre::SHADOWTYPE_NONE) ){
			try{
				MyGUI::ComboBox* pcombo = mUI["lighting"]->castType<MyGUI::ComboBox>(false);
				size_t index = pcombo->getIndexSelected();
				st |= static_cast<int>(getShadowMode( index ));
			}catch( out_of_range& e ){
				WARNING_LOG(e.what());
			}
		}
	}else if( mUI.IsWidget(_sender,"lighting") ){
		try{
			MyGUI::ComboBox* pcombo = mUI["shadow"]->castType<   MyGUI::ComboBox>(false);
			int sel = pcombo->getIndexSelected();
			st = static_cast<int>(getShadowTechnique( sel ));
		}catch( out_of_range& e ){
			WARNING_LOG(e.what());
			return;
		}
		if( st != static_cast<int>(Ogre::SHADOWTYPE_NONE) )
			st |= static_cast<int>(getShadowMode( _index ));
	}
setShadowTechnique( static_cast<Ogre::ShadowTechnique>(st) );
}
Ejemplo n.º 2
0
void SetDefaultCurlOpt(CURL *handle){
	if(share_handle)
	{
		//curl_share_setopt(share_handle, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
		curl_easy_setopt(handle, CURLOPT_SHARE, share_handle);
	}
	//curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1);
	CURLcode code = curl_easy_setopt(handle, CURLOPT_DNS_CACHE_TIMEOUT, -1L);
	if(code != CURLE_OK){
        WARNING_LOG("could not set CURLOPT_DNS_CACHE_TIMEOUT"); 
	}
	code = curl_easy_setopt(handle, CURLOPT_TCP_NODELAY, 1L);
	if(code != CURLE_OK){
         WARNING_LOG(" could not set CURLOPT_TCP_NODELAY.");
	}
	code = curl_easy_setopt(handle, CURLOPT_POST, 1L);
	if(code != CURLE_OK){
        WARNING_LOG(" could not set CURLOPT_POST.");
	}
    code = curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 1L);
    if (code != CURLE_OK) {
        WARNING_LOG(" could not set CURLOPT_NOPROGRESS.");
    }
	code = curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);
	if (code != CURLE_OK) {
		WARNING_LOG(" could not set CURLOPT_NOSIGNAL.");
	}
}
Ejemplo n.º 3
0
void HotkeyManager::_load( MyGUI::xml::ElementPtr root,const string xml )
{
	if( root == nullptr || root->getName() != "HKS" )
	{
		WARNING_LOG("bad Hotkey config file "<<xml);
		return;
	}
	MyGUI::xml::ElementEnumerator node = root->getElementEnumerator();
	while( node.next() )
	{
		if( node->getName() == "hotkey" )
		{
			hotkey hk;
			if( !node->findAttribute("name",hk.mName) )
			{
				WARNING_LOG("Hotkey config file "<<xml<<" invalid hotkey node");
				continue;
			}
			node->findAttribute("caption",hk.mCaption);
			node->findAttribute("tip",hk.mTip);
			node->findAttribute("key",hk.mHotkey);
			hk.mSHotkey = getStandardHotkeyName(hk.mHotkey);
			mHotkeys.push_back( hk );
			//设置对应Widget的User string,便于其显示出正常的热键
			setWidgetHotkey( hk.mName,hk.mHotkey );
		}
	}
}
Ejemplo n.º 4
0
void RenderThread::run()
{
	qRegisterMetaType<FramePtr>("FramePtr");
	qRegisterMetaType<FrameList>("FrameList");
	qRegisterMetaType<FrameListPtr>("FrameListPtr");

	WARNING_LOG("Render run start");

	QEventLoop eventLoop;
	while (!m_Exit)
	{
		eventLoop.processEvents();
		Render();
	}

	WARNING_LOG("Render run cleaning up");

	for (int i = 0; i < m_RenderFrames.size(); i++) 
	{
		FramePtr renderFrame = m_RenderFrames.at(i);
		if (renderFrame)
		{
			m_Renderer->Deallocate(renderFrame);
		}
	}
	m_RenderFrames.clear();

	WARNING_LOG("Render run finish");
}
Ejemplo n.º 5
0
void RenderThread::Render()
{
	PlaybackControl::Status status;
	m_Control->GetStatus(&status);

	m_RenderCounter ++;
	bool nextIsSeeking = false;
	unsigned int nextPTS = GetNextPTS(nextIsSeeking);
	int diffPts = 0;
	if (!nextIsSeeking && nextPTS != INVALID_PTS && m_LastPTS != INVALID_PTS && nextPTS>m_LastPTS)
	{
		diffPts = qAbs<int>(((int)nextPTS)-((int)m_LastPTS));
	}

	bool newFrame = (nextPTS != INVALID_PTS) && (nextIsSeeking || ( diffPts < m_RenderCounter*m_RenderInterval + m_RenderInterval/2 ));
	FrameListPtr nextScene;
	if (newFrame)
	{	
		nextPTS = m_PTSQueue.takeFirst();
		nextIsSeeking = m_SeekingQueue.takeFirst();
		nextScene = m_SceneQueue.takeFirst();

		RenderFrames(nextScene, status.plane);
	}else if (m_RenderFrames.size()== 0 && m_LastSourceFrames && m_LastSourceFrames->size()>0)
	{
		// paused and render reset
		RenderFrames(m_LastSourceFrames, status.plane);
	}

	if (m_RenderFrames.size()>0)
	{
		UpdateLayout();
		m_Renderer->RenderScene(m_RenderFrames);

		int elapsedSinceLastRenderCycle = m_RenderCycleTime.restart();
		WARNING_LOG("Render cycle: %d (%.2f) ms", elapsedSinceLastRenderCycle, m_RenderInterval);
		m_RenderInterval = m_RenderInterval + 0.1f * (elapsedSinceLastRenderCycle - m_RenderInterval);
	}

	if (newFrame)
	{
		// Compute render speed ratio
		int elapsedSinceLastPTS = m_RenderSpeedTime.restart();
		WARNING_LOG("TIME %d, %d", diffPts, elapsedSinceLastPTS);
		if (diffPts > 0 && elapsedSinceLastPTS>0 && diffPts <= 1000 && elapsedSinceLastPTS<=1000)
		{
			m_SpeedRatio = m_SpeedRatio + 0.1f * (diffPts*1.0f/ elapsedSinceLastPTS - m_SpeedRatio);
		}

		m_LastSourceFrames = nextScene;
		m_LastSeeking = nextIsSeeking;
		m_LastPTS = nextPTS;

		m_RenderCounter = 0;

		m_Control->OnFrameDisplayed(m_LastPTS, m_LastSeeking);
		emit sceneRendered(nextScene, m_LastPTS, m_LastSeeking);
	}
}
Ejemplo n.º 6
0
void RenderThread::Stop()
{
	WARNING_LOG("Render Stop");
	m_Exit = true;
	wait();

	WARNING_LOG("Render Stop - Done");
 }
Ejemplo n.º 7
0
bool MySqlConnection::ExecuteTransaction(MySqlTransaction* transaction)
{
	std::list<SQLElementData> const& queries = transaction->m_queries;
	if (queries.empty())
	{
		TRACE_LOG("MySqlConnection::ExecuteTransaction:quries is empty\n");
		return true;
	}

	if (!BeginTransaction())
	{
		TRACE_LOG("MySqlConnection::ExecuteTransaction:BeginTransaction\n");
        return false;
	}

	std::list<SQLElementData>::const_iterator itr;
	for (itr = queries.begin(); itr != queries.end(); ++itr)
	{
		SQLElementData const& data = *itr;
		switch (itr->type)
		{
			case SQL_ELEMENT_PREPARED:
            {
                PreparedStmt* stmt = data.element.stmt;
                if (!Execute(stmt))
                {
                    WARNING_LOG("Transaction aborted. %u queries not executed.\n", static_cast<uint32>(queries.size()));
                    RollbackTransaction();
                    return false;
                }
            }
            break;
			case SQL_ELEMENT_RAW:
            {
                const char* sql = data.element.query;
                if (!Execute(sql))
                {
                    WARNING_LOG("Transaction aborted. %u queries not executed.\n", static_cast<uint32>(queries.size()));
                    RollbackTransaction();
                    return false;
                }
            }
            break;
		}
	}

	// we might encounter errors during certain queries, and depending on the kind of error
	// we might want to restart the transaction. So to prevent data loss, we only clean up when it's all done.
	// This is done in calling functions DatabaseWorkerPool<T>::DirectCommitTransaction and TransactionTask::Execute,
	// and not while iterating over every element.

	CommitTransaction();
	return true;
}
Ejemplo n.º 8
0
int make_socket_non_blocking(int sfd)
{
	int flags, s;
	flags = fcntl(sfd, F_GETFL, 0);
	if(flags == -1){
		WARNING_LOG("fcntl error: %s", strerror(errno));
		return -1;
	}
	flags |= O_NONBLOCK;
	s = fcntl(sfd, F_SETFL, flags);
	if(s == -1){
		WARNING_LOG("fcntl error: %s", strerror(errno));
		return -1;
	}
	return 0;
}
Ejemplo n.º 9
0
int32_t fs_opr_t::eval(const char* key, char* val, uint32_t val_len) {
    FUNC_BEGIN();
    snprintf(szcmd, LEN_512, "api eval %s\n\n", key);
    TRACE_LOG("eval, (%s)", szcmd);

    if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS
            && (fs_resp = esl_event_get_body(_handle.last_sr_event))) {
        strncpy(val, fs_resp, val_len);

        fs_resp = val;

        while (fs_resp && *fs_resp && (fs_resp - val) < val_len) {
            if ('\n' == *fs_resp || '\r' == *fs_resp) {
                val[fs_resp - val] = '\0';
                break;
            }

            ++fs_resp;
        }

        ret = IMS_SUCCESS;
    } else {
        WARNING_LOG("fs_eval(%s) failed", key);
    }

    FUNC_END();
}
Ejemplo n.º 10
0
int32_t fs_opr_t::record(const char* uuid, const char* file, uint32_t time_s) {
    FUNC_BEGIN();

    std::string full_file = _recordbase;
    full_file += "/";
    full_file += file;

    TRACE_LOG("fs::record(%s) start.", full_file.c_str());
    //set_channel_attribute(uuid,"playback_terminators=none");
    //set_channel_attribute(uuid,"RECORD_HANGUP_ON_ERROR=false");//1.0.7的fs才有
    //set_channel_attribute(uuid,"RECORD_MIN_SEC=0");

    //TRACE_LOG("fs::record(%s) middle.",full_file.c_str());
    snprintf(szcmd, LEN_512, CMD_RECORD_FMT, uuid, full_file.c_str(), time_s);

    //if(esl_send_recv(&_handle,szcmd)==ESL_SUCCESS){
    //    if(is_result_ok(fs_resp=esl_event_get_body(_handle.last_sr_event))){
    //        ret=IMS_SUCCESS;
    //    }
    //    else{
    //        WARNING_LOG("fs:record(%s,%s,%u);ret(%s)",uuid,full_file.c_str(),time_s,fs_resp);
    //    }
    //}
    if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS &&
            is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) {
        ret = IMS_SUCCESS;
    } else {
        WARNING_LOG("fs:record(%s,%s,%u) esl_send_recv != ESL_SUCCESS", uuid, full_file.c_str(), time_s);
    }

    //TRACE_LOG("fs::record(%s) done.",full_file.c_str());

    FUNC_END();
}
Ejemplo n.º 11
0
int32_t fs_opr_t::bridge(const char* uuid, const char* called_disp, const char* dnis) {
    FUNC_BEGIN();

    if (set_channel_attribute(uuid, "bridge_early_media=true")
            && set_channel_attribute(uuid, "hangup_after_bridge=false")
            && set_channel_attribute(uuid, "bypass_media=false")
            && set_channel_attribute(uuid, "playback_terminators=none")
            && set_channel_attribute(uuid, "continue_on_fail=true")) {
        set_channel_attribute(uuid, "export_vars=IMSDATA");
        snprintf(szcmd, LEN_512, "effective_caller_id_name=%s", called_disp);
        set_channel_attribute(uuid, szcmd);
        snprintf(szcmd, LEN_512, "effective_caller_id_number=%s", called_disp);
        set_channel_attribute(uuid, szcmd);

        if (esl_execute(&_handle, "bridge", dnis, uuid) == ESL_SUCCESS &&
                is_result_ok(fs_resp = esl_event_get_header(_handle.last_sr_event, "Reply-Text"))) {
            ret = IMS_SUCCESS;
            break;
        } else {
            WARNING_LOG("fs:bridge(%s,%s,%s);ret(%s)", uuid, called_disp, dnis, fs_resp);
        }

    }

    FUNC_END();
}
Ejemplo n.º 12
0
int32_t fs_opr_t::subscribe_event(const char* event) {
    FUNC_BEGIN();

    (void)szcmd;
    (void)fs_resp;

    if (esl_events(&_handle, ESL_EVENT_TYPE_PLAIN, event) == ESL_SUCCESS) {
        TRACE_LOG("subscribe_event %s success", event);
        ret = IMS_SUCCESS;
        break;
    } else {
        WARNING_LOG("subscribe_event %s failed(connect err)", event);
        ims_tool_t::safe_sleepms(20);
    }

    /*
    if(is_handle_valid()){
        ret=IMS_FAIL_TIMEOUT;
        break;
    }
    else if(IMS_SUCCESS!=connect(_address,_port,_pswd,true)){
        WARNING_LOG("subscribe_event %s failed(connect err)",event);
        ret=IMS_FAIL_CONNECT;
        break;
    }
    */

    FUNC_END();
}
Ejemplo n.º 13
0
void Framework::loadRigid( MyGUI::xml::ElementPtr node,JointPtr parent )
{
    ObjectFactory& factory = ObjectFactory::getSingleton();
    RigidPtr rgp = boost::dynamic_pointer_cast<Rigid>(factory.createObject("Rigid"));
    if(rgp)
    {
        rgp->load(node);
        if( parent )
        {
            parent->mRigid[1] = rgp;
            parent->linkRigid(parent->mRigid[0], parent->mRigid[1]);
        }
        MyGUI::xml::ElementEnumerator ce = node->getElementEnumerator();
        while(ce.next())
        {
            MyGUI::xml::ElementPtr child = ce.current();
            if( child->getName() == "joint" )
            {
                loadJoint( child,rgp );
            }
        }
    }
    else
    {
        WARNING_LOG("Factory can't make Rigid object!");
    }
}
Ejemplo n.º 14
0
void Framework::loadJoint( MyGUI::xml::ElementPtr node,RigidPtr parent )
{
    ObjectFactory& factory = ObjectFactory::getSingleton();
    string typeName = node->findAttribute("type");
    JointPtr jpt = boost::dynamic_pointer_cast<Joint>(factory.createObject(typeName));
    if(jpt)
    {
        if( parent )
        {
            jpt->mRigid[0] = parent;
        }
        addJoint(jpt);
        jpt->load(node);
        MyGUI::xml::ElementEnumerator ce = node->getElementEnumerator();
        while(ce.next())
        {
            MyGUI::xml::ElementPtr child = ce.current();
            if( child->getName() == "rigid" )
            {
                loadRigid(child, jpt);
            }
            break;
        }
    }
    else
    {
        WARNING_LOG("Factory can't make "<<typeName);
    }
}
Ejemplo n.º 15
0
void Game::notifyButtonClick(MyGUI::Widget* _sender){
	if( mUI.IsWidget(_sender,"Cancel") ){
		mUI.close();
	}else if( mUI.IsWidget(_sender,"Apply") ){
		if( !mNeedReset ){
			mUI.close();
			return;
		}
		try{
			SimpleDataUI sdu(mUI["OgreView"]);
			Ogre::ConfigOptionMap& mp = mRoot->getRenderSystem()->getConfigOptions();
			for( Ogre::ConfigOptionMap::iterator i=mp.begin();i!=mp.end();++i ){
				SimpleData sd = sdu.get( i->first );
				if( sd.type==SimpleData::STRING&&sd.str != i->second.currentValue ){
					mRoot->getRenderSystem()->setConfigOption(i->first,sd.str);
				}
			}
			mUI.close();
			mRoot->queueEndRendering();
			reset(NORMAL);
		}catch( out_of_range& e ){
			WARNING_LOG(e.what());
		}
	}
}
Ejemplo n.º 16
0
void
OnlineLearner::learn(const char *train_file,
        const char *eval_file,
        const char *test_file) {

    RawCorpus *train_crp = reader->read(train_file);
    RawCorpus *eval_crp  = reader->read(eval_file);
    RawCorpus *test_crp  = reader->read(test_file);

    if (NULL == train_crp) {
        WARNING_LOG("Failed to load train corpus.");
        return;
    }
    if (NULL == eval_crp)
        WARNING_LOG("Failed to load eval corpus.");
    if (NULL == test_crp)
        WARNING_LOG("Failed to load test corpus.");

    TRACE_LOG("Reading corpus is done.");
    TRACE_LOG("Read train corpus [%d] line", train_crp->size());

    Alphabet *features = new HashDict();
    Alphabet *labels   = new HashDict();
    Alphabet *chars    = new HashDict();

    Data *train_dat = this->extractor->extract(train_crp, true);
    Data *eval_dat  = this->extractor->extract(eval_crp);
    Data *test_dat  = this->extractor->extract(test_crp);

    if (NULL == train_dat) {
        WARNING_LOG("No training instances is extracted.");
        return;
    }

    this->model->registAlphabet("FEATURES", features);
    this->model->registAlphabet("LABELS", labels);
    int handle = (1<<0)|(1<<1)|(1<<3);
    int numFeatures = model->getAlphabet("FEATURES")->size();
    int numLabels   = model->getAlphabet("LABELS")->size();
    int numParameters = numFeatures * numLabels + numLabels * (numLabels + 1);
    TRACE_LOG("Dimension of parameter %d", numParameters);

    this->globalParam = new CParameter(
            handle, numParameters);

    this->learn(train_dat, eval_dat, test_dat);
}
Ejemplo n.º 17
0
/**
 * 单首歌曲计算即时用户权值
 * instant_model, 即时用户模型
 * songid, 歌曲id
 * type 歌曲处理类型(加心,60s等)
 * dim 为试探的维度
 * return >=0 成功 -1失败
 */
int detect_instant_songid(instant_model_t& instant_model, int song_id, int type, int dim) {
    int dim_type = instant_model.dim_type;
    const Song_brief_t* p_brief = get_song_brief(song_id);
    if(NULL == p_brief) {
        WARNING_LOG("detect song, no song brief, songid[%d]", song_id);
        return FAIL;
    }
    int tmp = 0;
    //语言
    if((dim_type & (1 << I_LAN_DIM)) != 0) {
        if(p_global.i_brief_lan.get(p_brief->lang, &tmp) == bsl::HASH_EXIST) {
            if(tmp == HUAYU_LAN) {
                if(type > 0) {
                    instant_model.dim_lan[tmp] += HUAYU_RATE * type * g_config.IWConf.detect_rate;
                }
                else {
                    instant_model.dim_lan[tmp] += (type * g_config.IWConf.detect_rate)/HUAYU_RATE;
                }
            } else {
                instant_model.dim_lan[tmp] += type * g_config.IWConf.detect_rate;
            }
        }
    }
    //语言
    if((dim_type & (1 << I_LAN_DIM)) != 0 && dim == I_LAN_DIM) {
        if(p_global.i_brief_lan.get(p_brief->lang, &tmp) == bsl::HASH_EXIST) {
            if(tmp == HUAYU_LAN) {
                if(type > 0) {
                    instant_model.dim_lan[tmp] += HUAYU_RATE * type * g_config.IWConf.detect_rate;
                }
                else {
                    instant_model.dim_lan[tmp] += (type * g_config.IWConf.detect_rate)/HUAYU_RATE;
                }
            } else {
                instant_model.dim_lan[tmp] += type * g_config.IWConf.detect_rate;
            }
        }
    }
    //年代
    if((dim_type & (1 << I_YEAR_DIM)) != 0  && dim == I_YEAR_DIM ) {
        if(p_global.i_brief_year.get(p_brief->year, &tmp) == bsl::HASH_EXIST) {
            instant_model.dim_year[tmp] += type * g_config.IWConf.detect_rate;
        }
    }

    //地区
    if((dim_type & (1 << I_AREA_DIM)) != 0 && dim == I_AREA_DIM ) {
        if(p_global.i_brief_area.get(p_brief->area, &tmp) == bsl::HASH_EXIST) {
            instant_model.dim_area[tmp] += type * g_config.IWConf.detect_rate;
        }
    }
    //性别
    if((dim_type & (1 << I_GENDER_DIM)) != 0 && dim == I_GENDER_DIM) {
        if(p_global.i_brief_gender.get(p_brief->gender, &tmp) == bsl::HASH_EXIST) {
            instant_model.dim_gender[tmp] += type * g_config.IWConf.detect_rate;
        }
    }
    return SUCCESS;
}
Ejemplo n.º 18
0
 static void load_model_constrain(Model * model , const char * lexicon_file = NULL) {
    if (NULL != lexicon_file) {
       std::ifstream lfs(lexicon_file);
       if (lfs) {
           std::string buffer;
           std::vector<std::string> key_values;
           int key_values_size;
           std::string key;
           int value;
           Bitset *  original_bitset;
           while (std::getline(lfs, buffer)) {
               buffer = ltp::strutils::chomp(buffer);
               if (buffer.size() == 0) {
                   continue;
               }
               Bitset values;
               key_values = ltp::strutils::split(buffer);
               key_values_size = key_values.size();
               if(key_values_size == 0 || key_values_size == 1) {
                 continue;
               }
               key = ltp::strutils::chartypes::sbc2dbc_x(key_values[0]);
               for(int i=1;i<key_values_size;i++){
                   value = model->labels.index(key_values[i]);
                   if (value != -1){
                       if(!(values.set(value))) {
                           WARNING_LOG("Tag named %s for word %s add external lexicon error.",key_values[i].c_str(),key_values[0].c_str());
                       }
                   }
                   else {
                       WARNING_LOG("Tag named %s for word %s is not existed in LTP labels set.",key_values[i].c_str(),key_values[0].c_str());
                   }
               }
               if(!values.empty()) {
                 original_bitset = model->external_lexicon.get(key.c_str());
                 if(original_bitset){
                   original_bitset->merge(values);
                 }
                 else{
                   model->external_lexicon.set(key.c_str(),values);
                 }
               }
           }
       }
   }
 }//end func load_model_constrain
Ejemplo n.º 19
0
int Serv::initServ(struct conf_data *pconf_data)
{
	pepd_conf = new struct epd_config;
	if(pepd_conf == NULL){
		WARNING_LOG("Out of memory.");
		return -1;
	}
	if( init_epd_config(pepd_conf, pconf_data) < 0 ){
		WARNING_LOG("init_epd_config failed");
		return -1;
	}	
	if( bind_and_listen(pepd_conf->server_port) < 0){
		WARNING_LOG("failed to bind and listen!");
		return -1;
	}
	return 0;
}
Ejemplo n.º 20
0
bool SavePersistedData(void)
{
	CharacterData *characterData;

	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
	}
	
	if(sizeof(CharacterData) > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("CharacterData is too big to save (%d).", sizeof(CharacterData));
		return false;
	}

	if(GetSizeOfItemsOwned() > PERSIST_DATA_MAX_LENGTH )
	{
		ERROR_LOG("Item data is too big to save (%d).", GetSizeOfItemsOwned());
		return false;
	}

	ProfileLogStart("SavePersistedData");
	INFO_LOG("Saving persisted data.");
	DEBUG_VERBOSE_LOG("Saving meta data");
	persist_write_bool(PERSISTED_IS_DATA_SAVED, true);
	persist_write_int(PERSISTED_CURRENT_DATA_VERSION, CURRENT_DATA_VERSION);
	persist_write_int(PERSISTED_MAX_KEY_USED, MAX_PERSISTED_KEY);
	
	DEBUG_VERBOSE_LOG("Saving character");
	characterData = GetCharacter();
	persist_write_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	
	DEBUG_VERBOSE_LOG("Saving floor");
	persist_write_int(PERSISTED_CURRENT_FLOOR, GetCurrentFloor());
	
	DEBUG_VERBOSE_LOG("Saving item data");
	persist_write_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned());
	
	DEBUG_VERBOSE_LOG("Saving stat points");
	persist_write_int(PERSISTED_STAT_POINTS_PURCHASED, GetStatPointsPurchased());

	DEBUG_VERBOSE_LOG("Saving option data");
	persist_write_bool(PERSISTED_VIBRATION, GetVibration());
	persist_write_bool(PERSISTED_FAST_MODE, GetFastMode());
	persist_write_bool(PERSISTED_WORKER_APP, GetWorkerApp());
	persist_write_bool(PERSISTED_WORKER_CAN_LAUNCH, GetWorkerCanLaunch());
	persist_write_bool(PERSISTED_USE_OLD_ASSETS, GetUseOldAssets());

	DEBUG_VERBOSE_LOG("Saving combat data");
	persist_write_bool(PERSISTED_IN_COMBAT, ClosingWhileInBattle());
	persist_write_int(PERSISTED_MONSTER_TYPE, GetMostRecentMonster());
	persist_write_int(PERSISTED_MONSTER_HEALTH, GetCurrentMonsterHealth());
	INFO_LOG("Done saving persisted data.");
	ProfileLogStop("SavePersistedData");
	
	return true;
}
Ejemplo n.º 21
0
bool LoadPersistedData(void)
{
	CharacterData *characterData;
	int floor = 0;
	bool useWorkerApp = false;
	if(!persist_exists(PERSISTED_IS_DATA_SAVED) || !persist_read_bool(PERSISTED_IS_DATA_SAVED))
		return false;
		
	if(!IsPersistedDataCurrent())
	{
		WARNING_LOG("Persisted data does not match current version, clearing.");
		ClearPersistedData();
		return false;
	}

	ProfileLogStart("LoadPersistedData");
	INFO_LOG("Loading persisted data.");
	characterData = GetCharacter();
	persist_read_data(PERSISTED_CHARACTER_DATA, characterData, sizeof(CharacterData));
	floor = persist_read_int(PERSISTED_CURRENT_FLOOR);
	SetCurrentFloor(floor);
	persist_read_data(PERSISTED_ITEM_DATA, GetItemsOwned(), GetSizeOfItemsOwned());
	SetStatPointsPurchased(persist_read_int(PERSISTED_STAT_POINTS_PURCHASED));
	SetVibration(persist_read_bool(PERSISTED_VIBRATION));
	SetFastMode(persist_read_bool(PERSISTED_FAST_MODE));
	if(persist_exists(PERSISTED_USE_OLD_ASSETS))
		SetUseOldAssets(persist_read_bool(PERSISTED_USE_OLD_ASSETS));
	useWorkerApp = persist_read_bool(PERSISTED_WORKER_APP);
	if(useWorkerApp)
	{
		AttemptToLaunchWorkerApp();
	}
	else
	{
		// If the user has launched the worker app outside of MiniDungeon,
		// they want it on.
		if(WorkerIsRunning())
			SetWorkerApp(true);
	}
	SetWorkerCanLaunch(persist_read_bool(PERSISTED_WORKER_CAN_LAUNCH));

	if(persist_read_bool(PERSISTED_IN_COMBAT))
	{
		int currentMonster = persist_read_int(PERSISTED_MONSTER_TYPE);
		int currentMonsterHealth = persist_read_int(PERSISTED_MONSTER_HEALTH);
		ResumeBattle(currentMonster, currentMonsterHealth);
	}
	ProfileLogStop("LoadPersistedData");
	if(characterData->level == 0)
	{
		// Something bad happened to the data, possible due to a watch crash
		ERROR_LOG("Persisted data was broken somehow, clearing");
		ClearPersistedData();
		return false;
	}
	return true;
}
Ejemplo n.º 22
0
void RenderThread::Start()
{
	WARNING_LOG("Render Start");

	m_LastPTS = INVALID_PTS;
	m_LastSeeking = false;
	m_Exit = false;

	m_RenderInterval = 16;
	m_RenderCounter = 0;

	QThread::start();

	m_RenderSpeedTime.start();
	m_RenderCycleTime.start();

	WARNING_LOG("Render Start - Done");
}
Ejemplo n.º 23
0
//数据发生改变
void Game::simpleDataChange(SimpleData* psd){
	assert( psd );
	try{
		mNeedReset = true;
		MyGUI::Button* pb = mUI["Apply"]->castType<MyGUI::Button>(false);
		if( pb )pb->setStateSelected(true);
	}catch(  out_of_range& e ){
		WARNING_LOG(e.what());
	}
}
Ejemplo n.º 24
0
void SimpleUI::checkItem( const string& name,bool b )
{
	try{
		MyGUI::Button * c = operator [](name)->castType<MyGUI::Button>(false);
		if( c )
			c->setStateSelected( b );
	}catch( out_of_range& e ){
		WARNING_LOG(e.what());
	}
}
Ejemplo n.º 25
0
int32_t fs_opr_t::uuid_bridge(const char* uuid1, const char* uuid2, char* uuid_output,
                              uint32_t output_len) {
    FUNC_BEGIN();

    snprintf(szcmd, LEN_512, CMD_UUIDBRIDGE_FMT, uuid1, uuid2);
    TRACE_LOG("uuid_bridge(%s)", szcmd);

    if (set_channel_attribute(uuid1, "bypass_media=false") &&
            set_channel_attribute(uuid2, "bypass_media=false")) {
        if (esl_send_recv(&_handle, szcmd) == ESL_SUCCESS) {
            if (is_result_ok(fs_resp = esl_event_get_body(_handle.last_sr_event))) {
                fs_resp += 3;

                while (*fs_resp && ' ' == *fs_resp) {
                    fs_resp++;
                }

                if (*fs_resp && uuid_output && output_len > 0) {
                    strncpy(uuid_output, fs_resp, output_len);
                    uint32_t idx = 0;

                    do {
                        if ('\n' == uuid_output[idx]) {
                            uuid_output[idx] = '\0';
                            break;
                        }

                        ++idx;
                    } while (uuid_output[idx]);
                }

                ret = IMS_SUCCESS;
            } else {
                WARNING_LOG("fs:uuid_bridge(%s,%s,%s);ret(%s)", uuid1, uuid2, uuid_output, fs_resp);
            }
        }
    } else {
        WARNING_LOG("fs:uuid_bridge(%s,%s) failed(set channel attribute err)", uuid1, uuid2);
    }

    FUNC_END();
}
Ejemplo n.º 26
0
int Serv::bind_and_listen(const char *serv_port) 
{ 
	int n; const int on = 1; 
	struct addrinfo hints;
    struct addrinfo	*res = NULL, *ressave = NULL; 
	bzero(&hints, sizeof(struct addrinfo));
	hints.ai_flags= AI_PASSIVE;
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;

	if((n = getaddrinfo(NULL, serv_port, &hints, &res)) != 0){
		WARNING_LOG("tcp listen error for %s : %s", serv_port, gai_strerror(n));
	}
	ressave = res;
	do{
		listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
		if(listenfd < 0){
			continue;
		}
		if(setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0){
			WARNING_LOG("setsockopt REUSEADDR error!");
			break;
		}
		if(bind(listenfd, res->ai_addr, res->ai_addrlen) == 0){
			break;
		}
		close(listenfd);
	}while( (res = res->ai_next) != NULL );
	if(res == NULL){
		WARNING_LOG("tcp listen error for %s", serv_port);
		return -1;
	}
	make_socket_non_blocking(listenfd);
	listen(listenfd, 1024);
	/*
	if(addrlenp){
		*addrlenp = res->ai_addrlen;
	}
	*/
	freeaddrinfo(ressave);
	return listenfd;
}
Ejemplo n.º 27
0
static int init_epd_config(struct epd_config *pepd_conf, struct conf_data *pconf_data){
	if(pepd_conf == NULL){
		WARNING_LOG("init epd config error");
		return -1;
	}
	get_conf_int(pconf_data, "max_work_num", &(pepd_conf->max_work_num));
	get_conf_nstr(pconf_data, "doc_root", pepd_conf->doc_root, 1024);
	get_conf_nstr(pconf_data, "server_port", pepd_conf->server_port, 8);
	get_conf_nstr(pconf_data, "server_name", pepd_conf->server_name, 1024);
	return 0;
}
Ejemplo n.º 28
0
bool Database::Initialize(const char* Hostname, unsigned int port, const char* Username, const char* Password, const char* DatabaseName, uint32 ConnectionCount, uint32 BufferSize)
{
	uint32 i;
	MYSQL * temp, * temp2;
	my_bool my_true = true;

	mHostname = string(Hostname);
	mUsername = string(Username);
	mPassword = string(Password);
	mDatabaseName = string(DatabaseName);

	INFO_LOG(format("MySQLDatabase Connecting to `%1%`, database `%2%`...") % Hostname % DatabaseName);

	for( i = 0; i < ConnectionCount; ++i )
	{
		temp = mysql_init( NULL );
		if(mysql_options(temp, MYSQL_SET_CHARSET_NAME, "utf8"))
			WARNING_LOG("MySQLDatabase Could not set utf8 character set.");

		if (mysql_options(temp, MYSQL_OPT_RECONNECT, &my_true))
			WARNING_LOG("MYSQL_OPT_RECONNECT could not be set, connection drops may occur but will be counteracted.");

		temp2 = mysql_real_connect( temp, Hostname, Username, Password, DatabaseName, port, NULL, 0 );
		if( temp2 == NULL )
		{
			CRITICAL_LOG(format("MySQLDatabase Connection failed due to: `%1%`") % mysql_error( temp ) );
			return false;
		}

		m_connections.push_back(DatabaseConnection(temp2));
	}

	// Spawn Database thread
	ThreadPool.ExecuteTask(this);

	// launch the query thread
	qt = new QueryThread(this);
	ThreadPool.ExecuteTask(qt);

	return true;
}
Ejemplo n.º 29
0
static int get_conf_int(struct conf_data *pconf_data, const char *key, int *value)
{
	if(pconf_data == NULL || key == NULL || value == NULL){
		WARNING_LOG("illegal params!");
		return -1;
	}
	int n = 0;
	int i = 0;
	n = pconf_data->real_num;
	for(; i < n; ++i){
		if(strncmp(key, pconf_data->conf_item_arr[i].key, strlen(key)) == 0){
			sscanf((pconf_data->conf_item_arr)[i].value, "%d", value);
			break;
		}
	}
	if(i == n){
		WARNING_LOG("conf file don't has param [%s] !", key);
		return -1;
	}
	return 0;
}
Ejemplo n.º 30
0
bool WriteMessage(const shared_ptr<UnixSocketConnection> &connection,
                  uint32_t type,
                  const google::protobuf::Message &response) {
  shared_ptr<vector<char> > data(new vector<char>(response.ByteSize() + sizeof(type)));
  char *ptr = &(*data)[0];
  *reinterpret_cast<uint32_t *>(ptr) = type;
  if (!response.SerializeToArray(ptr + sizeof(type), data->size() - sizeof(type))) {
    WARNING_LOG("serialize message to string failed.");
    return false;
  }
  connection->Write(data);
  return true;
}