Beispiel #1
0
void ASNeighborListAdd(ASNeighborList list, void *node, float edgeCost)
{
    if (list->count == list->capacity) {
        list->capacity = 1 + (list->capacity * 2);
		CREALLOC(list->costs, sizeof(float) * list->capacity);
		CREALLOC(list->nodeKeys, list->source->nodeSize * list->capacity);
    }
    list->costs[list->count] = edgeCost;
    memcpy((char *)list->nodeKeys + (list->count * list->source->nodeSize), node, list->source->nodeSize);
    list->count++;
}
Beispiel #2
0
void MenuSystemAddCustomDisplay(
	MenuSystem *ms, MenuDisplayFunc func, void *data)
{
	ms->numCustomDisplayFuncs++;
	CREALLOC(
		ms->customDisplayFuncs,
		ms->numCustomDisplayFuncs * sizeof *ms->customDisplayFuncs);
	ms->customDisplayFuncs[ms->numCustomDisplayFuncs - 1] = func;
	CREALLOC(
		ms->customDisplayDatas,
		ms->numCustomDisplayFuncs * sizeof *ms->customDisplayDatas);
	ms->customDisplayDatas[ms->numCustomDisplayFuncs - 1] = data;
}
Beispiel #3
0
static Node GetNode(VisitedNodes nodes, void *nodeKey)
{
    size_t first;
    Node node;
    NodeRecord *record;
    if (!nodeKey) {
        return NodeNull;
    }
    
    // looks it up in the index, if it's not found it inserts a new record in the sorted index and the nodeRecords array and returns a reference to it
    first = 0;

    if (nodes->nodeRecordsCount > 0) {
        size_t last = nodes->nodeRecordsCount-1;

        while (first <= last) {
            const size_t mid = (first + last) / 2;
            const int comp = NodeKeyCompare(NodeMake(nodes, nodes->nodeRecordsIndex[mid]), nodeKey);

            if (comp < 0) {
                first = mid + 1;
            } else if (comp > 0 && mid > 0) {
                last = mid - 1;
            } else if (comp > 0) {
                break;
            } else {
                return NodeMake(nodes, nodes->nodeRecordsIndex[mid]);
            }
        }
    }
    
    if (nodes->nodeRecordsCount == nodes->nodeRecordsCapacity) {
        nodes->nodeRecordsCapacity = 1 + (nodes->nodeRecordsCapacity * 2);
        CREALLOC(nodes->nodeRecords, nodes->nodeRecordsCapacity * (sizeof(NodeRecord) + nodes->source->nodeSize));
		CREALLOC(nodes->nodeRecordsIndex, nodes->nodeRecordsCapacity * sizeof(size_t));
    }
    
    node = NodeMake(nodes, nodes->nodeRecordsCount);
    nodes->nodeRecordsCount++;
    
    memmove(&nodes->nodeRecordsIndex[first+1], &nodes->nodeRecordsIndex[first], (nodes->nodeRecordsCapacity - first - 1) * sizeof(size_t));
    nodes->nodeRecordsIndex[first] = node.index;
    
    record = NodeGetRecord(node);
    memset(record, 0, sizeof(NodeRecord));
    memcpy(record->nodeKey, nodeKey, nodes->source->nodeSize);

    return node;
}
Beispiel #4
0
static inline void AddNodeToOpenSet(Node n, float cost, Node parent)
{
    NodeRecord *record = NodeGetRecord(n);
    const size_t openIndex = n.nodes->openNodesCount;

    if (!NodeIsNull(parent)) {
        record->hasParent = 1;
        record->parentIndex = parent.index;
    } else {
        record->hasParent = 0;
    }

    if (n.nodes->openNodesCount == n.nodes->openNodesCapacity) {
        n.nodes->openNodesCapacity = 1 + (n.nodes->openNodesCapacity * 2);
       CREALLOC(n.nodes->openNodes, n.nodes->openNodesCapacity * sizeof(size_t));
    }

    n.nodes->openNodes[openIndex] = n.index;
    n.nodes->openNodesCount++;

    record->openIndex = openIndex;
    record->isOpen = 1;
    record->cost = cost;

    DidInsertIntoOpenSetAtIndex(n.nodes, openIndex);
}
Beispiel #5
0
void MenuAddExitType(MenuSystem *menu, menu_type_e exitType)
{
	if (MenuHasExitType(menu, exitType))
	{
		return;
	}
	// Add the new exit type
	menu->numExitTypes++;
	CREALLOC(menu->exitTypes, menu->numExitTypes * sizeof *menu->exitTypes);
	menu->exitTypes[menu->numExitTypes - 1] = exitType;
}
Beispiel #6
0
campaign_entry_t *AddAndGetCampaignEntry(
	campaign_list_t *list, const char *title, campaign_mode_e mode)
{
	campaign_entry_t *entry;
	list->num++;
	CREALLOC(list->list, sizeof(campaign_entry_t)*list->num);
	entry = &list->list[list->num-1];
	memset(entry, 0, sizeof *entry);
	strcpy(entry->info, title);
	entry->mode = mode;
	return entry;
}
Beispiel #7
0
bool UIObjectAddChar(UIObject *o, char c)
{
	if (!o)
	{
		return false;
	}
	if (o->Type != UITYPE_TEXTBOX)
	{
		return UIObjectAddChar(o->Highlighted, c);
	}
	else if (UIObjectAddChar(o->Highlighted, c))
	{
		// See if there are highlighted textbox children;
		// if so activate them instead
		return true;
	}
	if (o->u.Textbox.TextSourceFunc)
	{
		// Dynamically-allocated char buf, expand
		char **s = o->u.Textbox.TextSourceFunc(o->Data);
		if (!s)
		{
			return false;
		}
		size_t l = *s ? strlen(*s) : 0;
		CREALLOC(*s, l + 2);
		(*s)[l + 1] = 0;
		(*s)[l] = c;
	}
	else
	{
		// Static char buf, simply append
		// TODO: char buf limits?
		char *s = o->u.Textbox.TextLinkFunc(o, o->Data);
		size_t l = strlen(s);
		if ((int)l >= 4096 - 1)
		{
			return false;
		}
		s[l + 1] = 0;
		s[l] = c;
	}
	if (o->ChangeFunc)
	{
		o->ChangeFunc(o->Data, 1);
	}
	return o->ChangesData;
}
Beispiel #8
0
static void AddGraphicsMode(
	GraphicsDevice *device, int width, int height, int scaleFactor)
{
	int i = 0;
	int actualResolutionToAdd = width * height * scaleFactor * scaleFactor;
	GraphicsMode *mode = NULL;

	// Don't add if mode already exists
	if (FindValidMode(device, width, height, scaleFactor) != -1)
	{
		return;
	}

	for (; i < device->numValidModes; i++)
	{
		// Ordered by actual resolution ascending and scale descending
		int actualResolution;
		mode = &device->validModes[i];
		actualResolution =
			mode->Width * mode->Height * mode->ScaleFactor * mode->ScaleFactor;
		if (actualResolution > actualResolutionToAdd ||
			(actualResolution == actualResolutionToAdd &&
			mode->ScaleFactor < scaleFactor))
		{
			break;
		}
	}
	device->numValidModes++;
	CREALLOC(device->validModes, device->numValidModes * sizeof *device->validModes);
	// If inserting, move later modes one place further
	if (i < device->numValidModes - 1)
	{
		memmove(
			device->validModes + i + 1,
			device->validModes + i,
			(device->numValidModes - 1 - i) * sizeof *device->validModes);
	}
	mode = &device->validModes[i];
	mode->Width = width;
	mode->Height = height;
	mode->ScaleFactor = scaleFactor;
}
Beispiel #9
0
void LoadCampaignsFromFolder(
	campaign_list_t *list, const char *name, const char *path, campaign_mode_e mode)
{
	tinydir_dir dir;
	int i;

	strcpy(list->name, name);
	if (tinydir_open_sorted(&dir, path) == -1)
	{
		printf("Cannot load campaigns from path %s\n", path);
		return;
	}

	for (i = 0; i < dir.n_files; i++)
	{
		tinydir_file file;
		tinydir_readfile_n(&dir, &file, i);

		if (file.is_dir &&
			strcmp(file.name, ".") != 0 && strcmp(file.name, "..") != 0)
		{
			campaign_list_t *subFolder;
			list->numSubFolders++;
			CREALLOC(list->subFolders, sizeof(campaign_list_t)*list->numSubFolders);
			subFolder = &list->subFolders[list->numSubFolders-1];
			CampaignListInit(subFolder);
			LoadCampaignsFromFolder(subFolder, file.name, file.path, mode);
		}
		else if (file.is_reg)
		{
			char title[256];
			if (IsCampaignOK(file.path, title))
			{
				AddCustomCampaignEntry(list, file.name, file.path, title, mode);
			}
		}
	}

	tinydir_close(&dir);
}
Beispiel #10
0
void MenuAddSubmenu(menu_t *menu, menu_t *subMenu)
{
	menu_t *subMenuLoc = NULL;
	int i;

	menu->u.normal.numSubMenus++;
	CREALLOC(menu->u.normal.subMenus, menu->u.normal.numSubMenus*sizeof(menu_t));
	subMenuLoc = &menu->u.normal.subMenus[menu->u.normal.numSubMenus - 1];
	memcpy(subMenuLoc, subMenu, sizeof(menu_t));
	if (subMenu->type == MENU_TYPE_QUIT)
	{
		menu->u.normal.quitMenuIndex = menu->u.normal.numSubMenus - 1;
	}
	CFREE(subMenu);

	// update all parent pointers, in grandchild menus as well
	for (i = 0; i < menu->u.normal.numSubMenus; i++)
	{
		subMenuLoc = &menu->u.normal.subMenus[i];
		subMenuLoc->parentMenu = menu;
		if (MenuTypeHasSubMenus(subMenuLoc->type))
		{
			int j;

			for (j = 0; j < subMenuLoc->u.normal.numSubMenus; j++)
			{
				menu_t *subSubMenu = &subMenuLoc->u.normal.subMenus[j];
				subSubMenu->parentMenu = subMenuLoc;
			}
		}
	}

	// move cursor in case first menu item(s) are separators
	while (menu->u.normal.index < menu->u.normal.numSubMenus &&
		menu->u.normal.subMenus[menu->u.normal.index].type == MENU_TYPE_SEPARATOR)
	{
		menu->u.normal.index++;
	}
}
Beispiel #11
0
int kindOf_building_newItem(kindOf_building_t* b)
{
	b->items = CREALLOC(b->items, transform_t, b->n_items+1);
	transform_init(&b->items[b->n_items]);
	return b->n_items++;
}