コード例 #1
0
ファイル: newgrf_config.cpp プロジェクト: tony/openttd
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
{
	GRFConfig *c = new GRFConfig(filename + basepath_length);

	bool added = true;
	if (FillGRFDetails(c, false)) {
		if (_all_grfs == NULL) {
			_all_grfs = c;
		} else {
			/* Insert file into list at a position determined by its
			 * name, so the list is sorted as we go along */
			GRFConfig **pd, *d;
			bool stop = false;
			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
				if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
				 *  just after the first with the same name. Avoids doubles in the list. */
				if (strcasecmp(c->GetName(), d->GetName()) <= 0) {
					stop = true;
				} else if (stop) {
					break;
				}
			}
			if (added) {
				c->next = d;
				*pd = c;
			}
		}
	} else {
		added = false;
	}

	this->num_scanned++;
	if (this->next_update <= _realtime_tick) {
		_modal_progress_work_mutex->EndCritical();
		_modal_progress_paint_mutex->BeginCritical();

		const char *name = NULL;
		if (c->name != NULL) name = GetGRFStringFromGRFText(c->name->text);
		if (name == NULL) name = c->filename;
		UpdateNewGRFScanStatus(this->num_scanned, name);

		_modal_progress_work_mutex->BeginCritical();
		_modal_progress_paint_mutex->EndCritical();

		this->next_update = _realtime_tick + 200;
	}

	if (!added) {
		/* File couldn't be opened, or is either not a NewGRF or is a
		 * 'system' NewGRF or it's already known, so forget about it. */
		delete c;
	}

	return added;
}
コード例 #2
0
ファイル: newgrf_sl.cpp プロジェクト: Junky2008/OpenTTD
static void Load_NGRF_common(GRFConfig *&grfconfig)
{
	ClearGRFConfigList(&grfconfig);
	while (SlIterateArray() != -1) {
		GRFConfig *c = new GRFConfig();
		SlObject(c, _grfconfig_desc);
		if (IsSavegameVersionBefore(101)) c->SetSuitablePalette();
		AppendToGRFConfigList(&grfconfig, c);
	}
}
コード例 #3
0
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length)
{
	GRFConfig *c = new GRFConfig(filename + basepath_length);

	bool added = true;
	if (FillGRFDetails(c, false)) {
		if (_all_grfs == NULL) {
			_all_grfs = c;
		} else {
			/* Insert file into list at a position determined by its
			 * name, so the list is sorted as we go along */
			GRFConfig **pd, *d;
			bool stop = false;
			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
				if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
				 *  just after the first with the same name. Avoids doubles in the list. */
				if (strcasecmp(c->GetName(), d->GetName()) <= 0) {
					stop = true;
				} else if (stop) {
					break;
				}
			}
			if (added) {
				c->next = d;
				*pd = c;
			}
		}
	} else {
		added = false;
	}

	if (!added) {
		/* File couldn't be opened, or is either not a NewGRF or is a
		 * 'system' NewGRF or it's already known, so forget about it. */
		delete c;
	}

	return added;
}
コード例 #4
0
ファイル: newgrf_config.cpp プロジェクト: tony/openttd
/**
 * Update the palettes of the graphics from the config file.
 * Called when changing the default palette in advanced settings.
 * @param p1 Unused.
 * @return Always true.
 */
bool UpdateNewGRFConfigPalette(int32 p1)
{
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->SetSuitablePalette();
	for (GRFConfig *c = _all_grfs;          c != NULL; c = c->next) c->SetSuitablePalette();
	return true;
}
コード例 #5
0
/**
 * Update the palettes of the graphics from the config file.
 * This is needed because the config file gets read and parsed
 * before the palette is chosen (one can configure the base
 * graphics set governing the palette in the config after all).
 * As a result of this we update the settings from the config
 * once we have determined the palette.
 */
void UpdateNewGRFConfigPalette()
{
	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->SetSuitablePalette();
}