Beispiel #1
0
/*
	Delete()

	Elimina della lista il valore relativo alla coppia sezione/chiave.
	Non elimina fisicamente l'elemento ma si limita a marcarlo in modo tale che quando la lista
	viene salvata sul registro si possano individuare le chiavi da eliminare fisicamente.

	LPCSTR	lpcszSectionName	nome sezione
	LPCSTR	lpcszKeyName		nome chiave
*/
BOOL CConfig::Delete(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName)
{
	BOOL bDeleted = FALSE;
	CONFIG* c;
	ITERATOR iter;

	// scorre la lista cercando l'entrata relativa alla coppia sezione/chiave
	if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
	{
		do
		{
			c = (CONFIG*)iter->data;
			
			if(c)
				if(strcmp(lpcszSectionName,c->GetSection())==0)
				{
					if(strcmp(lpcszKeyName,c->GetName())==0)
					{
						// marca l'elemento per l'eliminazione
						c->SetType(NULL_TYPE);
						SetModified(TRUE);
						bDeleted = TRUE;
						break;
					}
				}

			iter = m_plistConfig->Next(iter);
		
		} while(iter!=(ITERATOR)NULL);
	}
	
	return(bDeleted);
}
Beispiel #2
0
int read_config_file(bool init, const char* fname) {
    if (!init) {
        msg_printf(NULL, MSG_INFO, "Re-reading %s", fname);
        config.defaults();
        log_flags.init();
    }
    FILE* f = boinc_fopen(fname, "r");
    if (!f) {
        msg_printf(NULL, MSG_INFO, "No config file found - using defaults");
        return ERR_FOPEN;
    }
    config.parse_client(f);
    fclose(f);
#ifndef SIM
    diagnostics_set_max_file_sizes(
        config.max_stdout_file_size, config.max_stderr_file_size
    );
#endif
    if (init) {
        coprocs = config.config_coprocs;
        config_proxy_info = config.proxy_info;
        if (strlen(config.data_dir)) {
#ifdef _WIN32
            _chdir(config.data_dir);
#else
            chdir(config.data_dir);
#endif
        }
    }
    return 0;
}
Beispiel #3
0
void SETTINGS::Load(const std::string & settingsfile, std::ostream & error)
{
	CONFIG config;
	if (!config.Load(settingsfile))
	{
		error << "Failed to load " << settingsfile << std::endl;
	}
	Serialize(false, config);
}
Beispiel #4
0
int
parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error, int err_type)
{
   int ok;
   CONFIG *config = new_config_parser();
   config->init(cf, scan_error, err_type, (void *)&res_all, res_all_size,    
                r_first, r_last, resources, res_head);
   ok = config->parse_config();
   free(config);
   return ok;
}
Beispiel #5
0
void SETTINGS::Save(const std::string & settingsfile, std::ostream & error)
{
	CONFIG config;
	if (!config.Load(settingsfile))
	{
		error << "Failed to load " << settingsfile << std::endl;
	}
	Serialize(true, config);
	if (!config.Write())
	{
		error << "Failed to save " << settingsfile << std::endl;
	}
}
Beispiel #6
0
int read_config_file(bool init) {
    FILE* f;

    if (!init) {
        msg_printf(NULL, MSG_INFO, "Re-reading cc_config.xml");
        config.clear();
    }
    f = boinc_fopen(CONFIG_FILE, "r");
    if (!f) return ERR_FOPEN;
    config.parse(f);
    fclose(f);
    return 0;
}
Beispiel #7
0
 static void save(const tomo::Color3& _c, const tbd::ConfigPath& _path, CONFIG& _config)
 {
   std::ostringstream _os;
   _os << _c.r() << " " << _c.g() << " ";
   _os << _c.b() << " ";
   _config.put(_path,_os.str());
 }
Beispiel #8
0
static void Param(
	CONFIG & config,
	bool write,
	CONFIG::iterator & section,
	const std::string & name,
	T & value)
{
	if (write)
	{
		config.SetParam(section, name, value);
	}
	else
	{
		config.GetParam(section, name, value);
	}
}
Beispiel #9
0
void SETTINGS::Get(std::map<std::string, std::string> & options)
{
	CONFIG tempconfig;
	Serialize(true, tempconfig);
	for (CONFIG::const_iterator ic = tempconfig.begin(); ic != tempconfig.end(); ++ic)
	{
		std::string section = ic->first;
		for (CONFIG::SECTION::const_iterator is = ic->second.begin(); is != ic->second.end(); ++is)
		{
			if (section.length() > 0)
				options[section + "." + is->first] = is->second;
			else
				options[is->first] = is->second;
		}
	}
}
Beispiel #10
0
/*
	Insert()

	Inserisce nella lista il valore (numerico) per la sezione/chiave specificati.

	LPCSTR	lpcszSectionName	nome sezione
	LPCSTR	lpcszKeyName		nome chiave
	LPCSTR	lpcszKeyValue		valore chiave (numero)
*/
BOOL CConfig::Insert(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,DWORD dwKeyValue)
{
	BOOL bInserted = FALSE;

	if(m_plistConfig)
	{
		CONFIG* c = (CONFIG*)m_plistConfig->Add();
		if(c)
		{
			c->Init(lpcszSectionName,lpcszKeyName,dwKeyValue);
			SetModified(TRUE);
			bInserted = TRUE;
		}
	}

	return(bInserted);
}
Beispiel #11
0
void SETTINGS::Set(const std::map<std::string, std::string> & options)
{
	CONFIG tempconfig;
	for (std::map<std::string, std::string>::const_iterator i = options.begin(); i != options.end(); ++i)
	{
		std::string section;
		std::string param = i->first;
		size_t n = param.find(".");
		if (n < param.length())
		{
			section = param.substr(0, n);
			param.erase(0, n + 1);
		}
		tempconfig.SetParam(section, param, i->second);
	}
	Serialize(false, tempconfig);
}
Beispiel #12
0
/*
	SaveSection()

	Salva nel registro i valori presenti nella lista relativi alla sezione.

	LPCSTR	lpcszRootKey		nome della chiave base
	LPCSTR	lpcszSectionKey	nome della sezione
*/
void CConfig::SaveSection(LPCSTR lpcszRootKey,LPCSTR lpcszSectionKey)
{
	CONFIG* c;
	ITERATOR iter;
	LONG lRet;
	char szKey[REGKEY_MAX_KEY_VALUE+1];

	if(m_pRegistry)
	{
		m_pRegistry->Attach(HKEY_CURRENT_USER);

		// scorre la lista aggiornando la sezione
		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
			
				if(c)
					// non inserisce nel registro le chiavi eliminate
					if(c->GetType()!=NULL_TYPE && strcmp(c->GetSection(),lpcszSectionKey)==0)
					{
						// salva la chiave nel registro
						_snprintf(szKey,sizeof(szKey)-1,DEFAULT_REG_KEY"\\%s\\%s",lpcszRootKey,c->GetSection());

						if((lRet = m_pRegistry->Open(HKEY_CURRENT_USER,szKey))!=ERROR_SUCCESS)
							lRet = m_pRegistry->Create(HKEY_CURRENT_USER,szKey);
						if(lRet==ERROR_SUCCESS)
						{
							if(c->GetType()==LPSTR_TYPE)
								m_pRegistry->SetValue(c->GetValue((LPCSTR)NULL),c->GetName());
							else if(c->GetType()==DWORD_TYPE)
								m_pRegistry->SetValue(c->GetValue((DWORD)0L),c->GetName());
							
							m_pRegistry->Close();
						}
					}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		m_pRegistry->Detach();
	}
}
Beispiel #13
0
int algorithms::Planner<IROBOT>::find_next_owner(int cell, const CONFIG& bnd_cfg ) const
{
    for (int index : get_cell(cell).get_boundaries()) {
        int neighbor = get_boundary(index).otherside(cell);
        if(get_cell(neighbor).on_boundary(bnd_cfg.vector(), 1e-15))
            return neighbor;
    }
    return NOT_FOUND;
}
Beispiel #14
0
/*
	Export()

	Esporta la configurazione corrente nel file specificato.
*/
BOOL	CConfig::Export(LPCSTR /*lpcszRootKey*/,LPCSTR lpcszFileName)
{
	BOOL bSaved = FALSE;
	FILE* fp;

	if((fp = fopen(lpcszFileName,"w"))!=(FILE*)NULL)
	{
		CONFIG* c;
		ITERATOR iter;

		fprintf(fp,"[%s]\n","Configuration File");

		// salva nel file le chiavi presenti nella lista
		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
				
				if(c)
					// non inserisce le chiavi eliminate
					if(c->GetType()!=NULL_TYPE)
					{
						if(c->GetType()==LPSTR_TYPE)
							fprintf(fp,"%s;%s;%s;%s\n",c->GetSection(),c->GetName(),c->GetValue((LPCSTR)NULL),"SZ");
						else if(c->GetType()==DWORD_TYPE)
							fprintf(fp,"%s;%s;%ld;%s\n",c->GetSection(),c->GetName(),c->GetValue((DWORD)0L),"DW");
					}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		fclose(fp);
		
		bSaved = TRUE;
	}

	return(bSaved);
}
Beispiel #15
0
/*
	DeleteAll()

	Elimina della lista tutti i valori, rimuovendoli anche dal registro.
*/
BOOL CConfig::DeleteAll(LPCSTR lpcszRootKey)
{
	BOOL bDeleted = TRUE;
	CONFIG* c;
	ITERATOR iter;
	char szKey[REGKEY_MAX_KEY_VALUE+1];

	if(m_pRegistry)
	{
		m_pRegistry->Attach(HKEY_CURRENT_USER);

		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
			
				if(c)
				{
					_snprintf(szKey,sizeof(szKey)-1,DEFAULT_REG_KEY"\\%s\\%s",lpcszRootKey,c->GetSection());
					if(m_pRegistry->Open(HKEY_CURRENT_USER,szKey)==ERROR_SUCCESS)
					{
						m_pRegistry->DeleteValue(c->GetName());
						m_pRegistry->Close();
					}
				}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		m_pRegistry->Detach();
	
		SetModified(TRUE);
	}

	m_plistConfig->RemoveAll();

	return(bDeleted);
}
Beispiel #16
0
unsigned Convolution(CONFIG &config)
{
    time_t  time1, time2;
    time(&time1);
    int dim;

    cout << "Add " << config.atoms_box << " atoms to the box" << endl;

    for(int i = 0; i < config.atoms_box; i++) // check all atoms of this grain
    {
        for(dim=0; dim < 3; dim++)
        {
            if (config.atom_box[i].r(dim) >  config.shift(dim)) config.atom_box[i].r(dim) -= config.l(dim);
            else
            if (config.atom_box[i].r(dim) < -config.shift(dim)) config.atom_box[i].r(dim) += config.l(dim);
        }
    }

    time(&time2);
    if (config.time) cout << "Done in " << time2-time1 << " s." << endl;

    return 0;
}
Beispiel #17
0
void GUICONTROL::RegisterActions(
	const std::map<std::string, Slot1<const std::string &>*> & vactionmap,
	const std::map<std::string, Slot0*> & actionmap,
	const std::string & name,
	const CONFIG & cfg)
{
	CONFIG::const_iterator section;
	cfg.GetSection(name, section);
	std::string actionstr;

	if (cfg.GetParam(section, "onselectx", actionstr))
		SetActions(vactionmap, actionstr, onselectx);

	if (cfg.GetParam(section, "onselecty", actionstr))
		SetActions(vactionmap, actionstr, onselecty);

	if (cfg.GetParam(section, "onselect", actionstr))
		SetActions(actionmap, actionstr, onselect);

	if (cfg.GetParam(section, "onfocus", actionstr))
		SetActions(actionmap, actionstr, onfocus);

	if (cfg.GetParam(section, "onblur", actionstr))
		SetActions(actionmap, actionstr, onblur);

	if (cfg.GetParam(section, "onmoveup", actionstr))
		SetActions(actionmap, actionstr, onmoveup);

	if (cfg.GetParam(section, "onmovedown", actionstr))
		SetActions(actionmap, actionstr, onmovedown);

	if (cfg.GetParam(section, "onmoveleft", actionstr))
		SetActions(actionmap, actionstr, onmoveleft);

	if (cfg.GetParam(section, "onmoveright", actionstr))
		SetActions(actionmap, actionstr, onmoveright);
}
Beispiel #18
0
/*
	String()

	Restituisce o aggiorna il valore (stringa) associato alla sezione/chiave a seconda del parametro
	associato al valore (NULL/-1 recupera, in caso contrario aggiorna).

	LPCSTR	lpcszSectionName	nome sezione
	LPCSTR	lpcszKeyName		nome chiave
	LPCSTR	lpcszKeyValue		valore chiave (stringa)
*/
LPCSTR CConfig::String(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,LPCSTR lpcszKeyValue/*=NULL*/)
{
	static char* p;
	CONFIG* c;
	ITERATOR iter;

	p = "";

	// scorre la lista cercando l'entrata relativa alla coppia sezione/chiave
	if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
	{
		do
		{
			c = (CONFIG*)iter->data;
			if(c)
				if(strcmp(lpcszSectionName,c->GetSection())==0)
				{
					if(strcmp(lpcszKeyName,c->GetName())==0)
					{
						// salta i valori marcati per l'eliminazione (NULL_TYPE)
						if(c->GetType()!=NULL_TYPE)
						{
							if(lpcszKeyValue!=NULL)
							{
								// aggiorna il valore
								c->SetValue(lpcszKeyValue);
								p = (char*)c->GetValue(p);
								break;
							}
							else
							{
								// ricava il valore
								p = (char*)c->GetValue(p);
								if(!*p)
									p = "";
								break;
							}
						}
					}
				}

			iter = m_plistConfig->Next(iter);
		
		} while(iter!=(ITERATOR)NULL);
	}
	
	return(p);
}
Beispiel #19
0
/*
	DeleteSection()

	Elimina dal registro (e dalla lista) i valori presenti nella lista relativi alla sezione.

	LPCSTR	lpcszRootKey		nome della chiave base
	LPCSTR	lpcszSectionKey	nome della sezione
	BOOL		bDeleteFromRegistry	flag per eliminazione delle chiavi dal registro
*/
void CConfig::DeleteSection(LPCSTR lpcszRootKey,LPCSTR lpcszSectionKey,BOOL bDeleteFromRegistry/*=FALSE*/)
{
	CONFIG* c;
	ITERATOR iter;
	char szKey[REGKEY_MAX_KEY_VALUE+1];

	if(m_pRegistry)
	{
		m_pRegistry->Attach(HKEY_CURRENT_USER);

		// elimina (dalla lista e dal registro) le chiavi relative alla sezione
		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
				
				if(c)
					// chiave da eliminare
					if(c->GetType()!=NULL_TYPE && strcmp(c->GetSection(),lpcszSectionKey)==0)
					{
						// elimina la chiave dal registro
						if(bDeleteFromRegistry)
						{
							_snprintf(szKey,sizeof(szKey)-1,DEFAULT_REG_KEY"\\%s\\%s",lpcszRootKey,c->GetSection());
							if(m_pRegistry->Open(HKEY_CURRENT_USER,szKey)==ERROR_SUCCESS)
							{
								m_pRegistry->DeleteValue(c->GetName());
								m_pRegistry->Close();
							}
						}

						// elimina la chiave dalla lista
						//m_plistConfig->Remove(iter);
						
						// eliminando l'elemento della lista (iter) e non la chiave (marcandola come cancellata) i salvataggi successivi
						// non possono eliminare dal registro le serie di chiavi come Key[0]...Key[n]
						//Delete(c->GetSection(),c->GetName());
						
						c->SetType(NULL_TYPE);
						SetModified(TRUE);
					}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		m_pRegistry->Detach();
	
		SetModified(TRUE);
	}
}
Beispiel #20
0
void algorithms::Planner<IROBOT>::compute_potential(const IROBOT& robot, const CONFIG& goal)
{
    std::clock_t    t0 = std::clock();
    int goal_cell  = NOT_FOUND;
    for (int i = 0; i < cells.size(); ++i) {
        if( goal_cell == NOT_FOUND && cells[i].contains(goal.vector())) {
            goal_cell = i;
            break;
        }
    }
    if (goal_cell == NOT_FOUND)
        std::cout << "Can't find goal cell\n";
    // Build potential field
    cells[goal_cell].set_potential(0.0);
    std::priority_queue<Potential_node> queue;
    
    for (int index : cells[goal_cell].get_boundaries()) {
        int neighbor = all_boundaries[index].otherside(goal_cell);
        cells[neighbor].set_potential(0.0);
        queue.emplace(neighbor, 0.0);
    }
    // Dijkstra's algorithm
    while( !queue.empty() )
    {
        Potential_node node = queue.top();
        queue.pop();
        int current = node.cell;
        if (node.priority > cells[current].get_potential())
            continue;
        Cell<IROBOT>& current_cell = cells[current];
        for (int index : current_cell.get_boundaries()) {
            Boundary<IROBOT>& boundary = all_boundaries[index];
            int neighbor = boundary.otherside(current);
            Cell<IROBOT>& neighbor_cell = cells[neighbor];
            double tentative_potential = current_cell.get_potential() + boundary.get_weight();
            if (tentative_potential < neighbor_cell.get_potential()) {
                neighbor_cell.set_potential(tentative_potential);
                queue.emplace(neighbor, tentative_potential);
            }
        }
    }
    std::clock_t    t1 = std::clock();
    std::cout << "Time cost for building potential field: \n\t" << (t1 - t0) / (double)(CLOCKS_PER_SEC / 1000) << " ms\n";
}
Beispiel #21
0
/*
	Number()

	Restituisce o aggiorna il valore (numerico) associato alla sezione/nome a seconda del parametro
	associato al valore (NULL/-1 recupera, in caso contrario aggiorna).

	LPCSTR	lpcszSectionName	nome sezione
	LPCSTR	lpcszKeyName		nome chiave
	LPCSTR	lpcszKeyValue		valore chiave (numero)
*/
DWORD CConfig::Number(LPCSTR lpcszSectionName,LPCSTR lpcszKeyName,DWORD dwKeyValue/*=(DWORD)-1L*/)
{
	DWORD l = (DWORD)-1L;
	CONFIG* c;
	ITERATOR iter;

	// scorre la lista cercando l'entrata relativa alla coppia sezione/chiave
	if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
	{
		do
		{
			c = (CONFIG*)iter->data;
			
			if(c)
				if(strcmp(lpcszSectionName,c->GetSection())==0)
				{
					if(strcmp(lpcszKeyName,c->GetName())==0)
					{
						// salta i valori marcati per l'eliminazione (NULL_TYPE)
						if(c->GetType()!=NULL_TYPE)
						{
							if(dwKeyValue!=(DWORD)-1L)
							{
								// aggiorna il valore
								c->SetValue(dwKeyValue);
								l = c->GetValue(l);
								break;
							}
							else
							{
								// ricava il valore
								l = c->GetValue(l);
								break;
							}
						}
					}
				}

			iter = m_plistConfig->Next(iter);
		
		} while(iter!=(ITERATOR)NULL);
	}
	
	return(l);
}
Beispiel #22
0
unsigned IniGrainCenters(CONFIG& config)
{
    Vector3d a;
    Vector3d rotv;
    Vector3d rtmp;
    double angle;
    time_t  time1, time2;
    time(&time1);


    cout << "Initialize grain centers ";
    for (int ig=0; ig<config.grains; ig++)
    {
        for (int dim=0; dim<3; dim++)
        {
            config.grain[ig].r(dim) = config.shift(dim) * (rand()%2000000/1000000. - 1);
        }

        for (unsigned j=0; j<3; j++)
        {
            config.grain[ig].angle(j) = 2.0 * M_PI * (rand()%1000000/1000000.);
        }

        a = config.grain[ig].angle;
        rotv << 1/cos(a(0))*sin(a(1)), 1/sin(a(0))*sin(a(1)), 1/cos(a(1));
        angle = -a(2);
        rtmp = -config.grain[ig].r;
        config.grain[ig].rotvT = rtmp * cos(angle) + rotv.cross(rtmp) * sin(angle) + (1 - cos(angle)) * rotv *(rotv.dot(rtmp)) + config.grain[ig].r; //  Rodrigue's rotation formula
        cout << ".";
    }

    time(&time2);
    if (config.time) cout << endl << "Done in " << time2-time1 << " s.";
    cout << endl;
    return 0;
}
Beispiel #23
0
/*
	Import()

	Importa la configurazione corrente dal file specificato.
*/
BOOL	CConfig::Import(LPCSTR lpcszRootKey,LPCSTR lpcszFileName)
{
	BOOL bLoaded = FALSE;
	FILE* fp;

	if((fp = fopen(lpcszFileName,"r"))!=(FILE*)NULL)
	{
		char* p;
		char szBuffer[REGKEY_MAX_SECTION_NAME+REGKEY_MAX_KEY_NAME+REGKEY_MAX_KEY_VALUE+16];
		char szSection[REGKEY_MAX_SECTION_NAME+1];
		char szName[REGKEY_MAX_KEY_NAME+1];
		char szValue[REGKEY_MAX_KEY_VALUE+1];
		char szType[5];

		// legge la prima linea controllando se si tratta di un file di configurazione
		fgets(szBuffer,sizeof(szBuffer)-1,fp);
		if((p = strchr(szBuffer,'\r'))==NULL)
			p = strchr(szBuffer,'\n');
		if(p)
			*p = '\0';
		if(strcmp(szBuffer,"[Configuration File]")!=0)
		{
			fclose(fp);
			return(bLoaded);
		}

		// legge il file di configurazione per linee
		while(fgets(szBuffer,sizeof(szBuffer)-1,fp))
		{
			if((p = strchr(szBuffer,'\r'))==NULL)
				p = strchr(szBuffer,'\n');
			if(p)
				*p = '\0';
			
			// estrae i valori dalla linea (sezione, chiave, valore, tipo)
			memset(szSection,'\0',sizeof(szSection));
			memset(szName,'\0',sizeof(szName));
			memset(szValue,'\0',sizeof(szValue));
			memset(szType,'\0',sizeof(szType));

			p = strrchr(szBuffer,';');
			if(p)
			{
				strcpyn(szType,p+1,sizeof(szType));
				*p = '\0';
			}
			p = strrchr(szBuffer,';');
			if(p)
			{
				strcpyn(szValue,p+1,sizeof(szValue));
				*p = '\0';
			}
			p = strrchr(szBuffer,';');
			if(p)
			{
				strcpyn(szName,p+1,sizeof(szName));
				*p = '\0';
			}
			p = szBuffer;
			if(p)
				strcpyn(szSection,p,sizeof(szSection));

			if(szSection[0]!='\0' && szName[0]!='\0' && szValue[0]!='\0' && szType[0]!='\0')
			{
				if(strcmp(szType,"SZ")==0)
				{
					if(strcmp(UpdateString(szSection,szName,szValue),"")==0)
					{
						CONFIG* c = (CONFIG*)m_plistConfig->Add();
						if(c)
							c->Init(szSection,szName,szValue);
					}
				}
				else if(strcmp(szType,"DW")==0)
				{
					if(UpdateNumber(szSection,szName,strtoul(szValue,NULL,0))==(DWORD)-1)
					{
						CONFIG* c = (CONFIG*)m_plistConfig->Add();
						if(c)
							c->Init(szSection,szName,strtoul(szValue,NULL,0));
					}
				}
			}
		}

		fclose(fp);
		
		Save(lpcszRootKey);
		
		bLoaded = TRUE;
	}

	return(bLoaded);
}
Beispiel #24
0
void SETTINGS::Serialize(bool write, CONFIG & config)
{
	CONFIG::iterator section;

	config.GetSection("game", section);
	Param(config, write, section, "vehicle_damage", vehicle_damage);
	Param(config, write, section, "ai_difficulty", ai_difficulty);
	Param(config, write, section, "track", track);
	Param(config, write, section, "antilock", abs);
	Param(config, write, section, "traction_control", tcs);
	Param(config, write, section, "record", recordreplay);
	Param(config, write, section, "selected_replay", selected_replay);
	Param(config, write, section, "player", player);
	Param(config, write, section, "player_paint", player_paint);
	Param(config, write, section, "player_color", player_color);
	Param(config, write, section, "opponent", opponent);
	Param(config, write, section, "opponent_paint", opponent_paint);
	Param(config, write, section, "opponent_color", opponent_color);
	Param(config, write, section, "reverse", trackreverse);
	Param(config, write, section, "track_dynamic", trackdynamic);
	Param(config, write, section, "batch_geometry", batch_geometry);
	Param(config, write, section, "number_of_laps", number_of_laps);
	Param(config, write, section, "camera_mode", camera_mode);

	config.GetSection("display", section);
	if (!res_override)
	{
		Param(config, write, section, "width", resolution_x);
		Param(config, write, section, "height", resolution_y);
	}
	Param(config, write, section, "depth", bpp);
	Param(config, write, section, "zdepth", depthbpp);
	Param(config, write, section, "fullscreen", fullscreen);
	Param(config, write, section, "shaders", shaders);
	Param(config, write, section, "skin", skin);
	Param(config, write, section, "language", language);
	Param(config, write, section, "show_fps", show_fps);
	Param(config, write, section, "anisotropic", anisotropic);
	Param(config, write, section, "antialiasing", antialiasing);
	Param(config, write, section, "trackmap", trackmap);
	Param(config, write, section, "show_hud", show_hud);
	Param(config, write, section, "FOV", FOV);
	Param(config, write, section, "mph", mph);
	Param(config, write, section, "view_distance", view_distance);
	Param(config, write, section, "racingline", racingline);
	Param(config, write, section, "texture_size", texturesize);
	Param(config, write, section, "shadows", shadows);
	Param(config, write, section, "shadow_distance", shadow_distance);
	Param(config, write, section, "shadow_quality", shadow_quality);
	Param(config, write, section, "reflections", reflections);
	Param(config, write, section, "input_graph", input_graph);
	Param(config, write, section, "lighting", lighting);
	Param(config, write, section, "bloom", bloom);
	Param(config, write, section, "normalmaps", normalmaps);
	Param(config, write, section, "camerabounce", camerabounce);
	Param(config, write, section, "contrast", contrast);

	config.GetSection("sound", section);
	Param(config, write, section, "volume", mastervolume);

	config.GetSection("joystick", section);
	Param(config, write, section, "type", joytype);
	Param(config, write, section, "two_hundred", joy200);
	joy200 = false;
	Param(config, write, section, "calibrated", joystick_calibrated);
	Param(config, write, section, "ff_device", ff_device);
	Param(config, write, section, "ff_gain", ff_gain);
	Param(config, write, section, "ff_invert", ff_invert);
	Param(config, write, section, "hgateshifter", hgateshifter);

	config.GetSection("control", section);
	Param(config, write, section, "speed_sens_steering", speed_sensitivity);
	Param(config, write, section, "autoclutch", autoclutch);
	Param(config, write, section, "autotrans", autoshift);
	Param(config, write, section, "mousegrab", mousegrab);
	Param(config, write, section, "button_ramp", button_ramp);
}
void CARCONTROLMAP_LOCAL::Save(CONFIG & controls_config)
{
	int id = 0;
	for (size_t n = 0; n < controls.size(); ++n)
	{
		std::string ctrl_name = GetStringFromInput(CARINPUT::CARINPUT(n));
		if (ctrl_name.empty())
			continue;

		for (size_t i = 0; i < controls[n].size(); ++i)
		{
			std::stringstream ss;
			ss << "control mapping " << std::setfill('0') << std::setw(2) << id;

			CONFIG::iterator section;
			controls_config.GetSection(ss.str(), section);
			controls_config.SetParam(section, "name", ctrl_name);

			CONTROL & curctrl = controls[n][i];
			if (curctrl.type == CONTROL::JOY)
			{
				controls_config.SetParam(section, "type", "joy");
				controls_config.SetParam(section, "joy_index", curctrl.joynum);

				if (curctrl.joytype == CONTROL::JOYAXIS)
				{
					controls_config.SetParam(section, "joy_type", "axis");
					controls_config.SetParam(section, "joy_axis", curctrl.joyaxis );
					switch (curctrl.joyaxistype) {
						case CONTROL::POSITIVE:
							controls_config.SetParam(section, "joy_axis_type", "positive");
							break;
						case CONTROL::NEGATIVE:
							controls_config.SetParam(section, "joy_axis_type", "negative");
							break;
					}
					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
				else if (curctrl.joytype == CONTROL::JOYBUTTON)
				{
					controls_config.SetParam(section, "joy_type", "button");
					controls_config.SetParam(section, "joy_button", curctrl.keycode);
					controls_config.SetParam(section, "once", curctrl.onetime);
					controls_config.SetParam(section, "down", curctrl.pushdown);
				}
			}
			else if (curctrl.type == CONTROL::KEY)
			{
				controls_config.SetParam(section, "type", "key");
				std::string keyname = GetStringFromKeycode(curctrl.keycode);
				controls_config.SetParam(section, "key", keyname);
				controls_config.SetParam(section, "keycode", curctrl.keycode);
				controls_config.SetParam(section, "once", curctrl.onetime);
				controls_config.SetParam(section, "down", curctrl.pushdown);
			}
			else if (curctrl.type == CONTROL::MOUSE)
			{
				controls_config.SetParam(section, "type", "mouse");
				if (curctrl.mousetype == CONTROL::MOUSEBUTTON)
				{
					controls_config.SetParam(section, "mouse_type", "button");
					controls_config.SetParam(section, "mouse_button", curctrl.keycode );
					controls_config.SetParam(section, "once", curctrl.onetime );
					controls_config.SetParam(section, "down", curctrl.pushdown );
				}
				else if (curctrl.mousetype == CONTROL::MOUSEMOTION)
				{
					std::string direction = "invalid";
					CONTROL::MOUSEDIRECTION mdir = curctrl.mdir;
					if ( mdir == CONTROL::UP )
					{
						direction = "up";
					}
					else if ( mdir == CONTROL::DOWN )
					{
						direction = "down";
					}
					else if ( mdir == CONTROL::LEFT )
					{
						direction = "left";
					}
					else if ( mdir == CONTROL::RIGHT )
					{
						direction = "right";
					}

					controls_config.SetParam(section, "mouse_type", "motion");
					controls_config.SetParam(section, "mouse_motion", direction);

					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
			}

			id++;
		}
	}
}
Beispiel #26
0
void CARCONTROLMAP_LOCAL::Save(CONFIG & controls_config, std::ostream & info_output, std::ostream & error_output)
{
	int id = 0;
	for (std::map <CARINPUT::CARINPUT, std::vector <CONTROL> >::iterator n = controls.begin(); n != controls.end(); ++n)
	{
		for (std::vector <CONTROL>::iterator i = n->second.begin(); i != n->second.end(); ++i)
		{
			std::string ctrl_name = "INVALID";
			CARINPUT::CARINPUT inputid = n->first;
			for (std::map <std::string, CARINPUT::CARINPUT>::const_iterator s = carinput_stringmap.begin(); s != carinput_stringmap.end(); ++s)
			{
				if (s->second == inputid) ctrl_name = s->first;
			}

			std::stringstream ss;
			ss << "control mapping " << std::setfill('0') << std::setw(2) << id;

			CONFIG::iterator section;
			controls_config.GetSection(ss.str(), section);
			controls_config.SetParam(section, "name", ctrl_name);

			CONTROL & curctrl = *i;
			if (curctrl.type == CONTROL::JOY)
			{
				controls_config.SetParam(section, "type", "joy");
				controls_config.SetParam(section, "joy_index", curctrl.joynum);

				if (curctrl.joytype == CONTROL::JOYAXIS)
				{
					controls_config.SetParam(section, "joy_type", "axis");
					controls_config.SetParam(section, "joy_axis", curctrl.joyaxis );
					switch (curctrl.joyaxistype) {
						case CONTROL::POSITIVE:
							controls_config.SetParam(section, "joy_axis_type", "positive");
							break;
						case CONTROL::NEGATIVE:
							controls_config.SetParam(section, "joy_axis_type", "negative");
							break;
						case CONTROL::BOTH:
							controls_config.SetParam(section, "joy_axis_type", "both");
							break;
					}
					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
				else if (curctrl.joytype == CONTROL::JOYBUTTON)
				{
					controls_config.SetParam(section, "joy_type", "button");
					controls_config.SetParam(section, "joy_button", curctrl.joybutton);
					controls_config.SetParam(section, "once", curctrl.onetime);
					controls_config.SetParam(section, "down", curctrl.joypushdown);
				}
			}
			else if (curctrl.type == CONTROL::KEY)
			{
				controls_config.SetParam(section, "type", "key");
				std::string keyname = "UNKNOWN";
				for (std::map <std::string, int>::iterator k = legacy_keycodes.begin(); k != legacy_keycodes.end(); k++)
					if (k->second == curctrl.keycode)
						keyname = k->first;
				controls_config.SetParam(section, "key", keyname);
				controls_config.SetParam(section, "keycode", curctrl.keycode);
				controls_config.SetParam(section, "once", curctrl.onetime);
				controls_config.SetParam(section, "down", curctrl.keypushdown);
			}
			else if (curctrl.type == CONTROL::MOUSE)
			{
				controls_config.SetParam(section, "type", "mouse");
				if (curctrl.mousetype == CONTROL::MOUSEBUTTON)
				{
					controls_config.SetParam(section, "mouse_type", "button");
					controls_config.SetParam(section, "mouse_button", curctrl.mbutton );
					controls_config.SetParam(section, "once", curctrl.onetime );
					controls_config.SetParam(section, "down", curctrl.mouse_push_down );
				}
				else if (curctrl.mousetype == CONTROL::MOUSEMOTION)
				{
					std::string direction = "invalid";
					CONTROL::MOUSEDIRECTION mdir = curctrl.mdir;
					if ( mdir == CONTROL::UP )
					{
						direction = "up";
					}
					else if ( mdir == CONTROL::DOWN )
					{
						direction = "down";
					}
					else if ( mdir == CONTROL::LEFT )
					{
						direction = "left";
					}
					else if ( mdir == CONTROL::RIGHT )
					{
						direction = "right";
					}

					controls_config.SetParam(section, "mouse_type", "motion");
					controls_config.SetParam(section, "mouse_motion", direction);

					controls_config.SetParam(section, "deadzone", curctrl.deadzone);
					controls_config.SetParam(section, "exponent", curctrl.exponent);
					controls_config.SetParam(section, "gain", curctrl.gain);
				}
			}

			id++;
		}
	}
}
Beispiel #27
0
/*
	Save()

	Salva nel registro i valori presenti nella lista.

	LPCSTR	lpcszRootKey	nome della chiave base
*/
void CConfig::Save(LPCSTR lpcszRootKey)
{
	CONFIG* c;
	ITERATOR iter;
	LONG lRet;
	char szKey[REGKEY_MAX_KEY_VALUE+1];
	memset(szKey,'\0',sizeof(szKey));

	if(m_pRegistry)
	{
		m_pRegistry->Attach(HKEY_CURRENT_USER);

		// elimina (dalla lista e dal registro) le chiavi marcate per la cancellazione
		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
				
				if(c)
					// chiave da eliminare
					if(c->GetType()==NULL_TYPE)
					{
						// elimina la chiave dal registro
						_snprintf(szKey,sizeof(szKey)-1,DEFAULT_REG_KEY"\\%s\\%s",lpcszRootKey,c->GetSection());
						if(m_pRegistry->Open(HKEY_CURRENT_USER,szKey)==ERROR_SUCCESS)
						{
							m_pRegistry->DeleteValue(c->GetName());
							m_pRegistry->Close();
						}

						// elimina la chiave dalla lista
						m_plistConfig->Remove(iter);
					}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		// salva nel registro le chiavi presenti nella lista
		if((iter = m_plistConfig->First())!=(ITERATOR)NULL)
		{
			do
			{
				c = (CONFIG*)iter->data;
				if(c)
					// non inserisce nel registro le chiavi eliminate
					if(c->GetType()!=NULL_TYPE)
					{
						_snprintf(szKey,sizeof(szKey)-1,DEFAULT_REG_KEY"\\%s\\%s",lpcszRootKey,c->GetSection());

						if((lRet = m_pRegistry->Open(HKEY_CURRENT_USER,szKey))!=ERROR_SUCCESS)
							lRet = m_pRegistry->Create(HKEY_CURRENT_USER,szKey);
						if(lRet==ERROR_SUCCESS)
						{
							if(c->GetType()==LPSTR_TYPE)
								m_pRegistry->SetValue(c->GetValue((LPCSTR)NULL),c->GetName());
							else if(c->GetType()==DWORD_TYPE)
								m_pRegistry->SetValue(c->GetValue((DWORD)0L),c->GetName());
							
							m_pRegistry->Close();
						}
					}

				iter = m_plistConfig->Next(iter);
			
			} while(iter!=(ITERATOR)NULL);
		}
		
		m_pRegistry->Detach();
	
		SetModified(FALSE);
	}
}
Beispiel #28
0
std::vector<typename IROBOT::CONFIG> algorithms::Planner<IROBOT>::AStar(const IROBOT& robot, const CONFIG& start, const CONFIG& goal)
{
    
    double smallest_radius = get_smallest_radius();
    // Find the cells containing the start and the goal
    int start_cell = NOT_FOUND, goal_cell = NOT_FOUND;
    for (int i = 0; i < cells.size(); ++i) {
        if( cells[i].contains(goal.vector()))
            goal_cell = i;
        if (cells[i].contains(start.vector())) {
            start_cell = i;
            std::cout << "Start cell potential : " << cells[i].get_potential() << '\n';
        }
    }
    for (Boundary<IROBOT>& boundary : all_boundaries)
        boundary.reset();
    
    if( start_cell == NOT_FOUND)
        throw "start config is not in any cell!";
    else if (goal_cell == NOT_FOUND )
        throw "goal config is not in any cell!";
    
    // Initialize for the nodes
    nodes.clear();
    nodes.reserve(1000000);
    int start_node = get_new_info(start);
    get_info(start_node).came_from = -1;
    int goal_node = get_new_info(goal);
    get_info(goal_node).cell = goal_cell;
    int metric_query = 0;
    std::cout << "Initialize the queue of AStar\n";
    // Initialize for the queue
    std::priority_queue<AStar_node> openset;
    {
        double g_score_start = 0.0;
        int current_cell_index = start_cell;
        double interval = (std::log(cells[current_cell_index].radius() / smallest_radius) + 1) * smallest_radius;
        for (int boundary_index : cells[current_cell_index].get_boundaries()) {
            int begin, end;
            get_boundary(boundary_index).get_boundary_configs(*this, interval, begin, end);
            for (int vertex = begin; vertex < end; ++vertex) {
                double tentative_g_score = g_score_start + IROBOT::metric(robot, start, nodes[vertex].cfg);
                nodes[vertex].came_from = start_node;
                nodes[vertex].g_score = tentative_g_score;
                nodes[vertex].f_score = tentative_g_score + cells[current_cell_index].get_potential();
                nodes[vertex].heuristic = cells[current_cell_index].get_potential();
                nodes[vertex].cell = start_cell;
                nodes[vertex].set_open();
                openset.emplace(vertex, nodes[vertex].f_score);
                ++metric_query;
            }
            
        }
    }
    std::cout << "Start AStar\n";
    // Starting A*
    while (!openset.empty()) {
        int current_node = openset.top().info_index;
        openset.pop();
        if (nodes[current_node].is_closed())
            continue;
        get_info(current_node).set_closed();
        if (current_node == goal_node) {
            std::cout << "Find Goal by expolring " << nodes.size() << " nodes with " << metric_query << " queries\n";
            return this->trace_back(nodes[current_node], start, goal);
        }
        
        int prev_cell;
        int current_cell;
        // Special case for start's neighbor
        if (nodes[current_node].came_from == start_node) {
            prev_cell = nodes[current_node].cell;
            current_cell = prev_cell;
        } else {
            prev_cell = nodes[nodes[current_node].came_from].cell;
            current_cell = find_next_owner(prev_cell, nodes[nodes[current_node].came_from].cfg); // search the neighbors of prev cell to see which cell contians current_cfg, that is the current_cell. ( there is only one such cell )
            
        }
        get_info(current_node).cell = current_cell;
        
        // time to check if the path has common cells.
        int neighbor_cell_index = find_next_owner(current_cell, nodes[current_node].cfg); // get the cell that also contains current config
        if( neighbor_cell_index == NOT_FOUND ) {
            continue;
        }
        cells[current_cell].set_visited();
        cells[neighbor_cell_index].set_visited();
        // Special case for goal's neighbor
        if (cells[neighbor_cell_index].contains(goal.vector())) {
            if( !nodes[goal_node].is_open() ) {
                nodes[goal_node].set_open();
                nodes[goal_node].g_score = get_info(current_node).g_score + IROBOT::metric(robot, nodes[current_node].cfg, goal);
                nodes[goal_node].came_from = current_node;
                openset.emplace(goal_node, nodes[goal_node].g_score);
                ++metric_query;
            } else {
                double distance_to_goal = IROBOT::metric(robot, nodes[current_node].cfg, goal);
                ++metric_query;
                if (get_info(current_node).g_score + distance_to_goal < nodes[goal_node].g_score) {
                    // 1. remove the neighbor_cfg from openset
                    // 2. re-add neighbor_cfg to openset with new priority.
                    nodes[goal_node].g_score = get_info(current_node).g_score + distance_to_goal;
                    nodes[goal_node].came_from = current_node;
                    openset.emplace(goal_node, nodes[goal_node].g_score);
                }
            }
            continue;
        }
        
        int neighbor_count = 0;
        // Compute successors
        for (int boundary_index : cells[neighbor_cell_index].get_boundaries()) {
            double interval = (std::log(cells[neighbor_cell_index].radius() / smallest_radius) + 1) * smallest_radius;
            int begin, end;
            get_boundary(boundary_index).get_boundary_configs(*this, interval, begin, end);
            for (int neighbor = begin; neighbor < end; ++neighbor) {
                if (nodes[neighbor].is_closed())    // already in closed set
                    continue;
                if (nodes[neighbor].is_open() && nodes[neighbor].g_score <= nodes[current_node].g_score)
                    continue;
                ++neighbor_count;
                double tentative_g_score = get_info(current_node).g_score + IROBOT::metric(robot, nodes[current_node].cfg, nodes[neighbor].cfg);
                ++metric_query;
                if (!nodes[neighbor].is_open() || tentative_g_score < nodes[neighbor].g_score)
                {
                    nodes[neighbor].came_from = current_node;
                    nodes[neighbor].g_score = tentative_g_score;
                    
                    nodes[neighbor].f_score = nodes[neighbor].g_score + cells[neighbor_cell_index].get_potential();
                    nodes[neighbor].heuristic = cells[neighbor_cell_index].get_potential();
                    if( !nodes[neighbor].is_open() ) {
                        //get_info(neighbor).f_score = get_info(neighbor).g_score + metric(robot, get_info(neighbor).cfg, goal);
                        nodes[neighbor].set_open();
                        openset.emplace(neighbor, nodes[neighbor].f_score);
                    } else{
                        //get_info(neighbor).f_score = get_info(neighbor).g_score + get_info(neighbor).heuristic;
                        // 1. remove the neighbor_cfg from openset
                        // 2. re-add neighbor_cfg to openset with new priority.
                        openset.emplace(neighbor, nodes[neighbor].f_score); // (two steps are done inside)
                    }
                }
            }
        }
        //std::cout << neighbor_count << '\n';
    }
    throw "The path doesn't exist";
}