Exemple #1
0
/** Perform the delayed (thread safe) insertion into the game list */
static void NetworkGameListHandleDelayedInsert()
{
	_network_game_list_mutex->BeginCritical();
	while (_network_game_delayed_insertion_list != NULL) {
		NetworkGameList *ins_item = _network_game_delayed_insertion_list;
		_network_game_delayed_insertion_list = ins_item->next;

		NetworkGameList *item = NetworkGameListAddItem(ins_item->address);

		if (item != NULL) {
			if (StrEmpty(item->info.server_name)) {
				ClearGRFConfigList(&item->info.grfconfig);
				memset(&item->info, 0, sizeof(item->info));
				strecpy(item->info.server_name, ins_item->info.server_name, lastof(item->info.server_name));
				strecpy(item->info.hostname, ins_item->info.hostname, lastof(item->info.hostname));
				item->online = false;
			}
			item->manually |= ins_item->manually;
			if (item->manually) NetworkRebuildHostList();
			UpdateNetworkGameWindow(false);
		}
		free(ins_item);
	}
	_network_game_list_mutex->EndCritical();
}
Exemple #2
0
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);
	}
}
Exemple #3
0
	virtual void OnDropdownSelect(int widget, int index)
	{
		if (index == -1) {
			ClearGRFConfigList(&this->list);
			this->preset = -1;
		} else {
			GRFConfig *c = LoadGRFPresetFromConfig(_grf_preset_list[index]);

			if (c != NULL) {
				this->sel = NULL;
				ClearGRFConfigList(&this->list);
				this->list = c;
				this->preset = index;
			}
		}

		this->sel = NULL;
		this->InvalidateData(3);
	}
Exemple #4
0
	~NewGRFWindow()
	{
		if (this->editable && !this->execute) {
			CopyGRFConfigList(this->orig_list, this->list, true);
			ResetGRFConfig(false);
			ReloadNewGRFData();
		}

		/* Remove the temporary copy of grf-list used in window */
		ClearGRFConfigList(&this->list);
		_grf_preset_list.Clear();
	}
Exemple #5
0
/**
 * Really perform the scan for all NewGRFs.
 * @param callback The callback to call after the scanning is complete.
 */
void DoScanNewGRFFiles(void *callback)
{
	_modal_progress_work_mutex->BeginCritical();

	ClearGRFConfigList(&_all_grfs);
	TarScanner::DoScan(TarScanner::NEWGRF);

	DEBUG(grf, 1, "Scanning for NewGRFs");
	uint num = GRFFileScanner::DoScan();

	DEBUG(grf, 1, "Scan complete, found %d files", num);
	if (num != 0 && _all_grfs != NULL) {
		/* Sort the linked list using quicksort.
		 * For that we first have to make an array, then sort and
		 * then remake the linked list. */
		GRFConfig **to_sort = MallocT<GRFConfig*>(num);

		uint i = 0;
		for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
			to_sort[i] = p;
		}
		/* Number of files is not necessarily right */
		num = i;

		QSortT(to_sort, num, &GRFSorter);

		for (i = 1; i < num; i++) {
			to_sort[i - 1]->next = to_sort[i];
		}
		to_sort[num - 1]->next = NULL;
		_all_grfs = to_sort[0];

		free(to_sort);

#ifdef ENABLE_NETWORK
		NetworkAfterNewGRFScan();
#endif
	}

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

	/* Yes... these are the NewGRF windows */
	InvalidateWindowClassesData(WC_SAVELOAD, 0, true);
	InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true);
	if (callback != NULL) ((NewGRFScanCallback*)callback)->OnNewGRFsScanned();

	DeleteWindowByClass(WC_MODAL_PROGRESS);
	SetModalProgress(false);
	MarkWholeScreenDirty();
	_modal_progress_paint_mutex->EndCritical();
}
Exemple #6
0
/**
 * Reset read data.
 */
void LoadCheckData::Clear()
{
    this->checkable = false;
    this->error = INVALID_STRING_ID;
    free(this->error_data);
    this->error_data = NULL;

    this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
    this->current_date = 0;
    memset(&this->settings, 0, sizeof(this->settings));

    const CompanyPropertiesMap::iterator end = this->companies.End();
    for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
        delete it->second;
    }
    companies.Clear();

    ClearGRFConfigList(&this->grfconfig);
}
/** Scan for all NewGRFs. */
void ScanNewGRFFiles()
{
	ClearGRFConfigList(&_all_grfs);

	TarScanner::DoScan();

	DEBUG(grf, 1, "Scanning for NewGRFs");
	uint num = GRFFileScanner::DoScan();

	DEBUG(grf, 1, "Scan complete, found %d files", num);
	if (num == 0 || _all_grfs == NULL) return;

	/* Sort the linked list using quicksort.
	 * For that we first have to make an array, then sort and
	 * then remake the linked list. */
	GRFConfig **to_sort = MallocT<GRFConfig*>(num);

	uint i = 0;
	for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
		to_sort[i] = p;
	}
	/* Number of files is not necessarily right */
	num = i;

	QSortT(to_sort, num, &GRFSorter);

	for (i = 1; i < num; i++) {
		to_sort[i - 1]->next = to_sort[i];
	}
	to_sort[num - 1]->next = NULL;
	_all_grfs = to_sort[0];

	free(to_sort);

#ifdef ENABLE_NETWORK
	NetworkAfterNewGRFScan();
#endif
}
Exemple #8
0
/**
 * Remove an item from the gamelist linked list
 * @param remove pointer to the item to be removed
 */
void NetworkGameListRemoveItem(NetworkGameList *remove)
{
	NetworkGameList *prev_item = NULL;
	for (NetworkGameList *item = _network_game_list; item != NULL; item = item->next) {
		if (remove == item) {
			if (prev_item == NULL) {
				_network_game_list = remove->next;
			} else {
				prev_item->next = remove->next;
			}

			/* Remove GRFConfig information */
			ClearGRFConfigList(&remove->info.grfconfig);
			free(remove);
			remove = NULL;

			DEBUG(net, 4, "[gamelist] removed server from list");
			NetworkRebuildHostList();
			UpdateNetworkGameWindow(false);
			return;
		}
		prev_item = item;
	}
}