示例#1
0
Control_Keys *control_CreateKeys(int numKeys, int pollType, int eventType)
{
    Control_Keys *newKeys = (Control_Keys *)mem_Malloc(sizeof(Control_Keys), __LINE__, __FILE__);

    newKeys->numKeys = numKeys;
    newKeys->pollType = pollType;

    if(eventType < 0)
    {
        if(eventType == C_BUTTON_STATES)
        {
            newKeys->useKeystates = 1;
            newKeys->eventType = eventType;
        }
        else
        {
            newKeys->eventType = control_GetSDLEventType(pollType, eventType);
            newKeys->useKeystates = 0;
        }
    }
    else
    {
        newKeys->useKeystates = 0;
        newKeys->eventType = eventType;
    }

    if(numKeys > 0)
        newKeys->keys = (int *)mem_Malloc(sizeof(int) * numKeys, __LINE__, __FILE__);
    else
        newKeys->keys = NULL;

    return newKeys;
}
示例#2
0
memp_malloc_fn(memp_t type, const char* file, const int line)
#endif
{
    void* ptr;
    rt_uint32_t size, level;

    size = memp_sizes[type];
    LWIP_DEBUGF(MEMP_DEBUG, ("memp malloc %s, size %d, ", memp_desc[type], memp_sizes[type]));

	level = rt_hw_interrupt_disable();
	if (type == MEMP_TCP_PCB)
	{
		if (tcp_pcbs >= MEMP_NUM_TCP_PCB)
		{
			rt_hw_interrupt_enable(level);
			return RT_NULL;
		}
		else
		{
			/* increased tcp pcb allocated number */
			tcp_pcbs ++;
		}
	}
	rt_hw_interrupt_enable(level);

    ptr = mem_Malloc(size);
	LWIP_DEBUGF(MEMP_DEBUG, ("mem 0x%x\n", ptr));

    return ptr;
}
示例#3
0
Ui_ButtonChain *uiButtonChain_Create(unsigned int numButtons, ...)
{
    Ui_ButtonChain *newChain = (Ui_ButtonChain *)mem_Malloc(sizeof(Ui_ButtonChain), __LINE__, __FILE__);
    Ui_Button *button = NULL;
    va_list args;
    unsigned int x = 0;

    va_start(args, numButtons);

    button = va_arg( args, Ui_Button *);

    newChain->bList = NULL;

    newChain->currentButton = button;
    list_Stack(&newChain->bList, button, 0);

    for(x = 1; x < numButtons; x++)
    {
        button = va_arg( args, Ui_Button *);

        /*Put the buttons in the list*/
        list_Stack(&newChain->bList, button, 0);
    }

    newChain->currentList = newChain->bList;

    va_end(args); /*Always call this in the same function as va_start.*/

    return newChain;
}
示例#4
0
文件: List.c 项目: sigt44/ventifact
void list_Insert(struct list **head, struct list *insertBefore, void *data, int info)
{
	#ifdef MEM_TRACK
    struct list *listNew = (struct list *)mem_Malloc(sizeof(struct list),__LINE__,__FILE__);
    #else
	struct list *listNew = (struct list *)malloc(sizeof(struct list));
	#endif

	if(insertBefore == *head) //Same as placing it at the start
	{
		list_Push_Node(head, listNew, data, info);
		return;
	}
	else if(insertBefore == NULL) //Same as placing it at the end
	{
		list_Stack_Node(head, listNew, data, info);
		return;
	}

	listNew->previous = insertBefore->previous;

	insertBefore->previous->next = listNew;

	insertBefore->previous = listNew;

	listNew->next = insertBefore;

	listNew->data = data;
	listNew->info = info;

	return;
}
示例#5
0
/*
    Function: aiState_UnitAttack_Setup

    Description -
    This function sets up the variables for an ai state ment for a unit.

    The behaviour of the state is to have the unit attack any enemy units or buildings
    within a specific range.

    7 arguments:
    Ai_State *a - The ai state to setup
    int group - The group ID of the ai state.
    int priority - The priority of this state.
    int completeType - The completion type of this state.
    Vent_Unit *entity - The unit that this ai will control.
    Vent_Game *game - The game structure.
    int searchRange - The max distance the unit will fire at another unit.
    int targetFirst - if 0 will target enemy units first, if 1 will target enemy buildings first.
*/
Ai_State *aiState_UnitAttack_Setup(Ai_State *a,
    int group,
    int priority,
    int completeType,
    Vent_Unit *entity,
    Vent_Game *game,
    int searchRange,
    int targetFirst
    )
{
    void (*init)(Ai_State *AiState) = &aiState_UnitAttack_Init;
    void (*mainLoop)(Ai_State *AiState) = &aiState_UnitAttack_Main;
    void (*exit)(Ai_State *AiState) = &aiState_UnitAttack_Exit;

    /*Setup custom attributes*/
    AiAttributes_UnitAttack *extraStructure = (AiAttributes_UnitAttack *)mem_Malloc(sizeof(AiAttributes_UnitAttack), __LINE__, __FILE__);

    extraStructure->searchRange = searchRange;
    extraStructure->targetFirst = targetFirst;
    extraStructure->game = game;

    /*Setup the state*/
    aiState_Setup(a,
                  group,
                  priority,
                  completeType,
                  entity,
                  extraStructure,
                  init,
                  mainLoop,
                  exit
                  );
    return a;
}
示例#6
0
void *mem_Realloc(void *pOld, uint_t nSize)
#endif
{
	void *p;

	if (pOld == NULL)
#if DEBUG_MEMORY_ENABLE
		return _mem_Malloc(nSize, fn, line);
#else
		return mem_Malloc(nSize);
#endif
	if (nSize == 0) {
#if DEBUG_MEMORY_ENABLE
		_mem_Free(pOld, fn, line);
#else
		mem_Free(pOld);
#endif
		return NULL;
	}
	mem_Lock();
#if DEBUG_MEMORY_ENABLE
	p = _rt_realloc(pOld, nSize);
#else
	p = rt_realloc(pOld, nSize);
#endif
	mem_Unlock();
#if DEBUG_MEMORY_ENABLE
	mem_DebugRealloc(p, pOld, fn, line);
#endif
	return p;
}
示例#7
0
STATIC void mptask_pre_init (void) {
#if MICROPY_HW_ENABLE_RTC
    pybrtc_init();
#endif

    // Create the simple link spawn task
    ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));

    // Allocate memory for the flash file system
    ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);

    // this one allocates memory for the nvic vault
    pybsleep_pre_init();

    // this one allocates mameory for the WLAN semaphore
    wlan_pre_init();

#if MICROPY_HW_HAS_SDCARD
    pybsd_init0();
#endif

#ifdef DEBUG
    ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
                                     (const signed char *)"Servers",
                                     SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle));
#else
    ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
                                     (const signed char *)"Servers",
                                     SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL));
#endif
}
示例#8
0
STATIC void mptask_pre_init (void) {
    // this one only makes sense after a poweron reset
    pyb_rtc_pre_init();

    // Create the simple link spawn task
    ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));

    // Allocate memory for the flash file system
    ASSERT ((sflash_vfs_fat = mem_Malloc(sizeof(*sflash_vfs_fat))) != NULL);

    // this one allocates memory for the nvic vault
    pyb_sleep_pre_init();

    // this one allocates memory for the WLAN semaphore
    wlan_pre_init();

    // this one allocates memory for the updater semaphore
    updater_pre_init();

    // this one allocates memory for the socket semaphore
    modusocket_pre_init();

    //CRYPTOHASH_Init();

#ifndef DEBUG
    OsiTaskHandle svTaskHandle;
#endif
    svTaskHandle = xTaskCreateStatic(TASK_Servers, "Servers",
        SERVERS_STACK_LEN, NULL, SERVERS_PRIORITY, svTaskStack, &svTaskTCB);
    ASSERT(svTaskHandle != NULL);
}
示例#9
0
STATIC void mptask_pre_init (void) {
    // this one only makes sense after a poweron reset
    pyb_rtc_pre_init();

    // Create the simple link spawn task
    ASSERT (OSI_OK == VStartSimpleLinkSpawnTask(SIMPLELINK_SPAWN_TASK_PRIORITY));

    // Allocate memory for the flash file system
    ASSERT ((sflash_fatfs = mem_Malloc(sizeof(FATFS))) != NULL);

    // this one allocates memory for the nvic vault
    pyb_sleep_pre_init();

    // this one allocates memory for the WLAN semaphore
    wlan_pre_init();

    // this one allocates memory for the updater semaphore
    updater_pre_init();

    // this one allocates memory for the socket semaphore
    modusocket_pre_init();

    //CRYPTOHASH_Init();

#ifdef DEBUG
    ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
                                     (const signed char *)"Servers",
                                     SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, &svTaskHandle));
#else
    ASSERT (OSI_OK == osi_TaskCreate(TASK_Servers,
                                     (const signed char *)"Servers",
                                     SERVERS_STACK_SIZE, NULL, SERVERS_PRIORITY, NULL));
#endif
}
示例#10
0
文件: List.c 项目: sigt44/ventifact
/*Push the node into the front of the list, making it the head*/
void list_Push(struct list **head,void *data,int info)
{
	struct list *listNew = NULL;

    #ifdef MEM_TRACK
    listNew = (struct list *)mem_Malloc(sizeof(struct list),__LINE__,__FILE__);
    #else
	listNew = (struct list *)malloc(sizeof(struct list));
	#endif

    if(*head == NULL)
    {
        listNew->next = NULL;
        listNew->previous = NULL;
    }
    else
    {
        if((*head)->previous == NULL) /*First catch*/
            listNew->previous = *head; /*The new head->previous now points to the end of the list*/
        else
            listNew->previous = (*head)->previous; /*Same here*/
        (*head)->previous = listNew; /*Moving the previous head forward*/
        listNew->next = *head; /*Linking them together*/
    }


	listNew->info = info;
	listNew->data = data;

	*head = listNew;

	return;
}
示例#11
0
/*
    Function: control_Load

    Description -
    Load the keys of a control from a file.
    The FILE pointer should be located at the start of where the control was saved.

    2 arguments:
    Control_Event *c - The control that has been setup already and is to have keys loaded in from the file.
    FILE *load - The FILE holding the keys, must point to the start of where the control was saved.
*/
void control_Load(Control_Event *c, FILE *load)
{
    Control_Keys cKey;
    struct list *controlList = NULL;
    int nameLength = 0;
    int x = 0;
    int y = 0;
    char controlName[255];
    int totalControls = 0;

    int *key = NULL;

    /*First load in the name and controls*/
    fscanf(load, "%d ", &nameLength);

    if(nameLength < 0 || nameLength > 253)
    {
        nameLength = 0;
    }
    else
        nameLength += 1;

    fgets(controlName , nameLength, load);

    fscanf(load, "%d", &totalControls);

    string_ReplaceChar(controlName, '%', ' ');

    if(strcmp(c->name, controlName) != 0)
    {
        printf("Error loading keys for  (%s) ment for (%s)\n", c->name, controlName);
        return;
    }

    /*Now load in each control event*/
    for(x = 0; x < totalControls; x++)
    {
        /*Load in the details of the key/s*/
        fscanf(load, "%d %d %d", &cKey.numKeys, &cKey.eventType, &cKey.pollType);

        /*Load in the values of each key*/
        for(y = 0; y < cKey.numKeys; y++)
        {
            key = (int *)mem_Malloc(sizeof(int), __LINE__, __FILE__);

            fscanf(load, "%d", key);

            /*Insert each value into a list so that they can all be added*/
            list_Stack(&controlList, key, 0);
        }

        /*Place the loaded keys into the control*/
        control_AddKeyList(c, cKey.pollType, cKey.eventType, controlList);

        list_ClearAll(&controlList);
    }

    return;
}
示例#12
0
/*
	Function: control_CopyEvent

	Description -
    Create a new SDL_Event and copy the contents of the perameter event to it.
    Return the new event.

	1 argument:
    SDL_Event *copyEvent - The event to be copied.
*/
SDL_Event *control_CopyEvent(SDL_Event *copyEvent)
{
    SDL_Event *newEvent = (SDL_Event *)mem_Malloc(sizeof(SDL_Event), __LINE__, __FILE__);

    *newEvent = *copyEvent;

    return newEvent;
}
示例#13
0
/*
    Function: uiTextInput_Create

    Description -

    Allocates memory and returns a Ui_TextInput structure defining a text input region.

    11 arguments:
    int x - The x axis location of the text input region.
    int y - The y axis location of the text input region.
    int layer - Layer of the graphics.
    char *text - The text that will be displayed before the input region.
    TTF_Font *font - Font of the text displayed by the input region.
    int maxLength - Max amount of characters allowed to be in the region.
    int outputType - Whether the output variable is an integer(UI_OUTPUT_INT) or string(UI_OUTPUT_STR).
    void *outputVar - The address of the output variable, this variable receives the value of the text input once finished. Can be NULL and then set later.
    Control_Event *cActivate - The control to be used to enter and exit the input state.
    Ui_Pointer *pnt - The pointer that will be used to activate the text region.
    Timer *srcTimer - Source timer used for input delay.
*/
Ui_TextInput *uiTextInput_Create(int x, int y, int layer, char *text, TTF_Font *font, int maxLength, int outputType, void *outputVar, Control_Event *cActivate, Ui_Pointer *pnt, Timer *srcTimer)
{
    Ui_TextInput *textInput = mem_Malloc(sizeof(Ui_TextInput), __LINE__, __FILE__);

    uiTextInput_Setup(textInput, x, y, layer, text, font, maxLength, outputType, outputVar, cActivate, pnt, srcTimer);

    return textInput;
}
示例#14
0
void uiTextInput_Setup(Ui_TextInput *textInput, int x, int y, int layer, char *text, TTF_Font *font, int maxLength, int outputType, void *outputVar, Control_Event *cActivate, Ui_Pointer *pnt, Timer *srcTimer)
{
    int i = 0;
    int buttonWidth = 0;
    int buttonHeight = 0;
    Sprite *buttonSprite = NULL;
    Ui_TextBox *textBox = NULL;

    /*Setup the input buffer*/
    textInput->textLength = maxLength;

    textInput->inputText = (char *)mem_Malloc((maxLength + 1) * sizeof(char), __LINE__, __FILE__);
    for(i = 0; i < maxLength + 1; i++)
        textInput->inputText[i] = '\0';

    /*Setup output variable*/
    textInput->outputType = outputType;
    textInput->outputVar = outputVar;

    /*Setup the letter marking graphic*/
    sprite_Setup(&textInput->sMarker, 0, layer, srcTimer, 1,
                 frame_CreateBasic(0, surf_SimpleBox(2, 2, &colourBlack, &colourBlack, 1), A_FREE));


    /*Create the text box that is to be linked to the button*/
    textBox = uiTextBox_CreateBase(0, 0, layer, 0, NULL, font, tColourBlack, srcTimer);
    uiTextBox_AddText(textBox,
                     0, 0, text, NULL);

    /*Make sure the text starts to the left of the button*/
    uiTextBox_SetPos(textBox, -(int)sprite_Width(textBox->graphic) - 5, 0);

    buttonSprite = sprite_Setup(sprite_Create(),  1, layer, srcTimer, 1,
                              frame_CreateBasic(0, NULL, M_FREE)
    );

    /*Approximate the needed button width by using the '0' character width then
    multiplying it by the maximum text length*/
    TTF_SizeText(font,"0", &buttonWidth, &buttonHeight);
    buttonWidth *= maxLength;

    uiRect_SetDim(&textInput->rect, buttonWidth, buttonHeight);

    uiButton_Setup(&textInput->button, x, y, buttonWidth, buttonHeight, BFA_EnterPoll, BFA_Hover, dataStruct_Create(2, textInput, pnt), buttonSprite, 0, 250, srcTimer);

    uiButton_AddText(&textInput->button, textBox);

    uiButton_CopyControl(&textInput->button, cActivate, BC_POINTER);
    uiButton_CopyControl(&textInput->button, cActivate, BC_KEY);

    uiTextInput_SetPos(textInput, x, y);
    uiTextInput_SetState(textInput, pnt, UI_TEXTINPUT_BASE);
    uiTextInput_AssignInput(textInput);

    depWatcher_Setup(&textInput->dW, textInput);

    return;
}
示例#15
0
文件: reg.c 项目: comrid1987/jb3500
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
int reg_ArithmeticCopy(uint_t nDestDa, uint_t nDestReg, uint_t nSrcDa, uint_t nSrcReg, uint_t nType, uint32_t nParam, uint_t nSave)
{
	int nLen;
	uint64_t nTemp;
	void *pBuf;
	
	nLen = reg_GetRegSize(nSrcReg);
	if (nLen < 0)
		return 0;
	if (nType == REG_O_COPY) {
		pBuf = mem_Malloc(nLen);
		if (pBuf == NULL)
			return 0;
		reg_Get(nSrcDa, nSrcReg, pBuf);
		reg_Set(nDestDa, nDestReg, pBuf, nSave);
		mem_Free(pBuf);
	} else {
		if (nLen > 8)
			return 0;
		nTemp = 0;
		reg_Get(nSrcDa, nSrcReg, &nTemp);
		switch (nType) {
		case REG_O_ADD:
			nTemp += nParam;
			break;
		case REG_O_SUB:
			nTemp -= nParam;
			break;
		case REG_O_MUL:
			nTemp *= nParam;
			break;
		case REG_O_DIV:
			nTemp /= nParam;
			break;
		case REG_O_OR:
			//或
			nTemp |= nParam;
			break;
		case REG_O_AND:
			//与
			nTemp &= nParam;
			break;
		case REG_O_SETBIT:
			//置位
			SETBIT(nTemp, nParam);
			break;
		case REG_O_CLRBIT:
			//清位
			CLRBIT(nTemp, nParam);
			break;
		default:
			break; 
		}
		reg_Set(nDestDa, nDestReg, &nTemp, nSave);
	}
	return nLen; 
}
示例#16
0
int surf_Init(const char *rootDIR)
{
    surf_C.surfacesDIR = (char *)mem_Malloc(256, __LINE__, __FILE__);
    strncpy(surf_C.surfacesDIR, rootDIR, 255);

    surf_C.surfaceList = NULL;
    surf_C.totalSurfacesInList = 0;

    return 0;
}
示例#17
0
/*
    Function: vLevel_LoadHeader

    Description -
    Loads a level header from a file.

    3 arguments:
    Vent_Level_Header *header - The level header to be loaded into.
    char *directory - The directory name of the level to load.
    char *name - The file name of the level to load.
*/
void vLevel_LoadHeader(Vent_Level_Header *header, char *directory, char *name)
{
    char *loadFolder = directory;
    char *loadName = (char *)mem_Malloc(strlen(loadFolder) + strlen(name) + 1, __LINE__, __FILE__);

    int finishedLoading = 0;

    FILE *load = NULL;
    Level_Tag tag;

    /*Setup the default values of the header*/
    vLevel_SetupHeader(header, NULL, 0, 0);

    /*Find the level file*/
    strcpy(loadName, loadFolder);
    strcat(loadName, name);

    load = fopen(loadName, "r");

    if(load == NULL)
    {
        file_Log(ker_Log(), 1, "Error: Could not load level file for header. (%s)\n", loadName);

        return;
    }

    while(vLevel_TagVerify(&tag, load) == 1 && finishedLoading == 0)
    {
        switch(tag.type)
        {
            case TAG_HEADER:

            if(tag.version < HEADER_VERSIONS)
            {
                vLevel_LoadHeaderVer[tag.version](header, &tag, load);
                finishedLoading = 1;
            }

            break;

            default:

            file_Log(ker_Log(), 1, "Error unknown tag type (while searching for header) %s -> %d\n", tag.name, tag.type);

            break;
        }
    }

    fclose(load);

    mem_Free(loadName);

    return;
}
示例#18
0
/*
    Function: drawLayer_Create

    Description -
    Creates and returns a new layer for the draw manager.

    2 arguments:
    int layer - The 'height' of the layer.
    int *totalObjectLocations - Should point to the draw managers variable that holds the total amount of space that has been created for objects to draw.
*/
Draw_Layer *drawLayer_Create(int layer, int *totalObjectLocations)
{
    Draw_Layer *drawLayer = (Draw_Layer *)mem_Malloc(sizeof(Draw_Layer), __LINE__, __FILE__);

    drawLayer->objectList = NULL;

    drawLayer->totalNodes = 0;

    drawLayer->totalObjectLocations = totalObjectLocations;
    drawLayer->layer = layer;

    return drawLayer;
}
示例#19
0
/*
    Function: vLevel_Save

    Description -
    Function that saves a level in the /Level/ folder.

    3 arguments:
    Vent_Level *l - the level to save
	char *directory - the name of the directory to save the level in
    char *name - the name to save the level as, .map will be appended to this
*/
void vLevel_Save(Vent_Level *l, char *directory, char *name)
{
    char *saveFolder = directory;
    char *saveName = (char *)mem_Malloc(strlen(saveFolder) + strlen(name) + strlen(".map") + 1, __LINE__, __FILE__);

    int x = 0;

    FILE *save = NULL;

    strcpy(saveName, saveFolder);
    strcat(saveName, name);
    strcat(saveName, ".map");

    save = fopen(saveName, "w");

    if(save == NULL)
    {
        printf("Error could not save level %s\n", saveName);

        return;
    }

    l->header.numCustomSurfaces = vLevel_GetCustomSurfaces(l);

    /*Structure of the level in a file -
    First write the object tag - [TAGNAME] objectAmount tagVersion
    Then below that write all the object data.
    */
    vLevel_SaveHeader(&l->header, save);

    vLevel_SaveCustomSurface(l, save);

    vLevel_SaveTile(l, save);

    vLevel_SaveSupply(l, save);

    vLevel_SaveNode(l, save);

    vLevel_SaveEdge(l, save);

    vLevel_SaveTag(save, 0, TAG_END);

    fclose(save);

    mem_Free(saveName);

    return;
}
示例#20
0
DRESULT sflash_disk_init (void) {
    _i32 fileHandle;
    SlFsFileInfo_t FsFileInfo;

    if (!sflash_init_done) {
        // Allocate space for the block cache
        ASSERT ((sflash_block_cache = mem_Malloc(SFLASH_BLOCK_SIZE)) != NULL);
        sflash_init_done = true;
        sflash_prblock = UINT32_MAX;
        sflash_cache_is_dirty = false;

        // In order too speed up booting, check the last block, if exists, then
        // it means that the file system has been already created
        print_block_name (SFLASH_BLOCK_COUNT - 1);
        sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
        if (!sl_FsGetInfo(sflash_block_name, 0, &FsFileInfo)) {
            sl_LockObjUnlock (&wlan_LockObj);
            return RES_OK;
        }
        sl_LockObjUnlock (&wlan_LockObj);

        // Proceed to format the memory
        for (int i = 0; i < SFLASH_BLOCK_COUNT; i++) {
            print_block_name (i);
            sl_LockObjLock (&wlan_LockObj, SL_OS_WAIT_FOREVER);
            // Create the block file if it doesn't exist
            if (sl_FsGetInfo(sflash_block_name, 0, &FsFileInfo) != 0) {
                if (!sl_FsOpen(sflash_block_name, FS_MODE_OPEN_CREATE(SFLASH_BLOCK_SIZE, 0), NULL, &fileHandle)) {
                    sl_FsClose(fileHandle, NULL, NULL, 0);
                    sl_LockObjUnlock (&wlan_LockObj);
                    memset(sflash_block_cache, 0xFF, SFLASH_BLOCK_SIZE);
                    if (!sflash_access(FS_MODE_OPEN_WRITE, sl_FsWrite)) {
                        return RES_ERROR;
                    }
                }
                else {
                    // Unexpected failure while creating the file
                    sl_LockObjUnlock (&wlan_LockObj);
                    return RES_ERROR;
                }
            }
            sl_LockObjUnlock (&wlan_LockObj);
        }
    }
    return RES_OK;
}
示例#21
0
文件: Node.c 项目: sigt44/ventifact
/*
    Function - node_Create

    Description -
    Returns a pointer to a new base node of structure B_Node.

    3 arguments:
    int index - this is the unique index to give the node
    int x - this is the x location of the node
    int y - the y location of the node
*/
B_Node *node_Create(int index, int x, int y)
{
    B_Node *newNode = (B_Node *)mem_Malloc(sizeof(B_Node), __LINE__, __FILE__);

    if(newNode == NULL)
        return NULL;

    newNode->index = index;
    newNode->x = x;
    newNode->y = y;

    newNode->degree = 0;
    newNode->edges = NULL;

    newNode->adv = NULL;

    return newNode;
}
示例#22
0
static void MM_QuitCampaign(Ui_Button *button)
{
    Base_State *gState = button->info->dataArray[0];
    int accepted = (int)button->info->dataArray[1];

    struct menu_Game *menu = gState->info;

    char *campaignName = (char *)mem_Malloc(strlen(menu->selectedCampaign) + 1, __LINE__, __FILE__);

    strcpy(campaignName, menu->selectedCampaign);

    /*Fix the campaign name*/
    string_RemoveExt(campaignName);

    /*Revert to the main ui section*/
    uiSpine_Close(uiSpine_GetEntity(&menu->spine, "Spine:Campaign"));

    /*If the campaign chosen was accepted*/
    if(accepted == 1)
    {
        vPlayer_LoadCampaign(menu->player, campaignName);

        if(menu->player->playCampaign == 1 && menu->player->campaign != NULL)
        {
            menu->selectedCampaign = menu->player->campaign->name;
            menu->player->levelDirectory = kernel_GetPath("PTH_VentLevels");
        }
        else
        {
            menu->player->levelDirectory = kernel_GetPath("PTH_VentCustomLevels");
        }

        /*Repopulate the level scroll*/
        MM_RepopulateLevels(gState);
    }

    timer_StopSkip(&menu->spine.sTimer, 0, 1);
    control_Pause(500);

    mem_Free(campaignName);

    return;
}
示例#23
0
文件: List.c 项目: sigt44/ventifact
void list_Stack(struct list **head,void *data,int info)
{
	struct list *listNew = NULL;
	struct list *listStart = *head;
	struct list *listCurrentEnd = NULL;

    #ifdef MEM_TRACK
    listNew = (struct list *)mem_Malloc(sizeof(struct list),__LINE__,__FILE__);
    #else
	listNew = (struct list *)malloc(sizeof(struct list));
	#endif

	if(*head == NULL)
	{
		*head = listNew;
		(*head)->previous = NULL;
	}
	else
	{
		listCurrentEnd = (*head)->previous;

		(*head)->previous = listNew;

		if(listCurrentEnd == NULL)
		{
		    (*head)->next = listNew;
            listNew->previous = *head;
		}
		else
        {
            listCurrentEnd->next = listNew;
            listNew->previous = listCurrentEnd;
        }
	}

	listNew->info = info;
	listNew->data = data;
	listNew->next = NULL;

	return;
}
示例#24
0
void control_CopyKeys(Control_Keys *destKeys, Control_Keys *sourceKeys)
{
    int x = 0;

    destKeys->numKeys = sourceKeys->numKeys;
    destKeys->pollType = sourceKeys->pollType;
    destKeys->useKeystates = sourceKeys->useKeystates;
    destKeys->eventType = sourceKeys->eventType;

    if(destKeys->numKeys > 0)
        destKeys->keys = (int *)mem_Malloc(sizeof(int) * destKeys->numKeys, __LINE__, __FILE__);
    else
        destKeys->keys = NULL;

    for(x = 0; x < destKeys->numKeys; x++)
    {
        destKeys->keys[x] = sourceKeys->keys[x];
    }

    return;
}
示例#25
0
/*
    Function: aiState_UnitAttackArea_Setup

    Description -
    This function sets up the variables for an ai state ment for a unit.

    The behaviour of the state is to have the unit move to a specific area and attack the
    enemy units that are within range.

    10 arguments:
    Ai_State *a - The ai state to setup
    int group - The group ID of the ai state.
    int priority - The priority of this state.
    int completeType - The completion type of this state.
    Vent_Unit *entity - The unit that this ai will control.
    Vent_Game *game - The game structure.
    int xArea - The x-axis location of the centre of the area.
    int yArea - The y-axis location of the centre of the area.
    int attackRangeSqr - The radius of the area to attack in (squared)
    unsigned int maxDurationTime - The maximum time that the unit will wait if there are no units in range.
*/
Ai_State *aiState_UnitAttackArea_Setup(Ai_State *a,
    int group,
    int priority,
    int completeType,
    Vent_Unit *entity,
    Vent_Game *game,
    int xArea,
    int yArea,
    int attackRangeSqr,
    unsigned int maxDurationTime
    )
{
    void (*init)(Ai_State *AiState) = &aiState_UnitAttackArea_Init;
    void (*mainLoop)(Ai_State *AiState) = &aiState_UnitAttackArea_Main;
    void (*exit)(Ai_State *AiState) = &aiState_UnitAttackArea_Exit;

    /*Setup custom attributes*/
    AiAttributes_UnitAttackArea *extraStructure = (AiAttributes_UnitAttackArea *)mem_Malloc(sizeof(AiAttributes_UnitAttackArea), __LINE__, __FILE__);

    extraStructure->attackRangeSqr = attackRangeSqr;
    extraStructure->durationTimer = timer_Setup(&game->gTimer, 0, maxDurationTime, 0);
    extraStructure->game = game;
    extraStructure->areaLocation.x = xArea;
    extraStructure->areaLocation.y = yArea;

    /*Setup the state*/
    aiState_Setup(a,
                  group,
                  priority,
                  completeType,
                  entity,
                  extraStructure,
                  init,
                  mainLoop,
                  exit
                  );
    return a;
}
示例#26
0
int surf_Load(SDL_Surface **image, char *name, int autoFreeID)
{
    char *imageLoc;
	SDL_Surface *optimizedImage = NULL;

    imageLoc = (char *)mem_Malloc(strlen(surf_C.surfacesDIR) + strlen(name) + 1, __LINE__, __FILE__);

    strcpy(imageLoc, surf_C.surfacesDIR);
    strcat(imageLoc, name);

    *image = IMG_Load(imageLoc);

	mem_Free(imageLoc);

	if(*image == NULL)
	{
	    printf("\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
        file_Log(ker_Log(), 0, "\nError - could not load image\n\t%s. (%s)\n", name, SDL_GetError());
		return 1;
	}

	optimizedImage = SDL_DisplayFormat(*image);

	SDL_FreeSurface(*image);

	if(optimizedImage == NULL)
		return 2;

	SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY | SDL_RLEACCEL, *ker_colourKey());

	*image = optimizedImage;

	if(autoFreeID == A_FREE)
		list_Push(&surf_C.surfaceList, *image, autoFreeID);

	return 0;
}
示例#27
0
/*
    Function: aiState_UnitAttackBuilding_Setup

    Description -
    This function sets up the variables for an ai state ment for a unit.

    The behaviour of the state is to have the unit find an enemy building/tile and move towards it
    with the attack area state.

    6 arguments:
    Ai_State *a - The ai state to setup
    int group - The group ID of the ai state.
    int priority - The priority of this state.
    int completeType - The completion type of this state.
    Vent_Unit *entity - The unit that this ai will control.
    Vent_Game *game - The game structure. Contains the buildings and tiles.
*/
Ai_State *aiState_UnitAttackBuilding_Setup(Ai_State *a,
    int group,
    int priority,
    int completeType,
    Vent_Unit *entity,
    Vent_Game *game
    )
{
    void (*init)(Ai_State *AiState) = &aiState_UnitAttackBuilding_Init;
    void (*mainLoop)(Ai_State *AiState) = &aiState_UnitAttackBuilding_Main;
    void (*exit)(Ai_State *AiState) = &aiState_UnitAttackBuilding_Exit;

    /*Setup custom attributes*/
    AiAttributes_UnitAttackBuilding *extraStructure = (AiAttributes_UnitAttackBuilding *)mem_Malloc(sizeof(AiAttributes_UnitAttackBuilding), __LINE__, __FILE__);

    extraStructure->target = NULL;
    extraStructure->game = game;
    extraStructure->moveState = NULL;
    extraStructure->attackRangeSqr = 0;

    /*Setup the state*/
    aiState_Setup(a,
                  group,
                  priority,
                  completeType,
                  entity,
                  extraStructure,
                  init,
                  mainLoop,
                  exit
                  );
    return a;
}
示例#28
0
/******************************************************************************
 DEFINE PUBLIC FUNCTIONS
 ******************************************************************************/
void telnet_init (void) {
    // Allocate memory for the receive buffer (from the RTOS heap)
    ASSERT ((telnet_data.rxBuffer = mem_Malloc(TELNET_RX_BUFFER_SIZE)) != NULL);
    telnet_data.state = E_TELNET_STE_DISABLED;
}
示例#29
0
文件: List.c 项目: sigt44/ventifact
void list_Push_SortL(struct list **head, void *data, int info)
{
	struct list *listCurrent = *head;
	struct list *listNew = NULL;
	int *sortCompare[2];

    #ifdef MEM_TRACK
    listNew = (struct list *)mem_Malloc(sizeof(struct list),__LINE__,__FILE__);
    #else
	listNew = (struct list *)malloc(sizeof(struct list));
	#endif

    if(*head == NULL)
    {
        listNew->next = NULL;
        listNew->previous = NULL;
        *head = listNew;
    }
    else
    {
        sortCompare[0] = data;
        while(listCurrent != NULL)
        {
            sortCompare[1] = listCurrent->data;
            if(*sortCompare[0] <= *sortCompare[1])
            {
                listNew->previous = listCurrent->previous;

                if(listCurrent->previous != NULL)
                    listCurrent->previous->next = listNew;

                listCurrent->previous = listNew;
                listNew->next = listCurrent;

                if(listCurrent == *head)
                    *head = listNew;

                listCurrent = NULL;
            }
            else
            {
                if(listCurrent->next == NULL)
                {
                    (*head)->previous = listNew; /*Correct the list*/
                    listCurrent->next = listNew;
                    listNew->previous = listCurrent;
                    listNew->next = NULL;

                    listCurrent = NULL;
                }
                else
                    listCurrent = listCurrent->next;
            }
        }
    }

	listNew->info = info;
	listNew->data = data;

	return;
}
示例#30
0
文件: List.c 项目: sigt44/ventifact
/*Smallest first, based on the number given to info*/
void list_Push_Sort(struct list **head, void *data, int info)
{
	struct list *listCurrent = *head;
	struct list *listNew = NULL;

    #ifdef MEM_TRACK
    listNew = (struct list *)mem_Malloc(sizeof(struct list),__LINE__,__FILE__);
    #else
	listNew = (struct list *)malloc(sizeof(struct list));
	#endif

    if(*head == NULL)
    {
        listNew->next = NULL;
        listNew->previous = NULL;
        *head = listNew;
    }
    else
    {
        while(listCurrent != NULL)
        {
            if(info <= listCurrent->info)
            {
                listNew->previous = listCurrent->previous;

                if(listNew->previous != NULL)
                    listNew->previous->next = listNew;

                listCurrent->previous = listNew;
                listNew->next = listCurrent;

                if(listCurrent == *head)
                {
                    *head = listNew;
                    if(listNew->previous != NULL)
                    { /*Linking in a node that will become the new head, so the new end node should always 				point to null*/
                    	listNew->previous->next = NULL; /*Ie what if the second node was the end node? There would be an endless loop if this was the case*/
                    }
                    else
                    {
                        listNew->previous = listCurrent;
                    }
                }

                listCurrent = NULL;
            }
            else
            {
                if(listCurrent->next == NULL) /*We are at the end of the list*/
                {
                    (*head)->previous = listNew; /*Correct the list*/
                    listCurrent->next = listNew;
                    listNew->previous = listCurrent;
                    listNew->next = NULL;

                    listCurrent = NULL;
                }
                else
                    listCurrent = listCurrent->next;
            }
        }
    }

	listNew->info = info;
	listNew->data = data;

	return;
}