long str_Tokenize(char *string,char *splitter,list **tokens)
{
  long tokens_num=0;
  long offset = 0;
  long splitter_len = strlen(splitter);
  long string_len = strlen(string);
  *tokens=list_Create(0,0);
  char *pos=NULL;
  while((pos = strstr(string+offset,splitter)))
  {
    long index = (long)(pos-(string+offset));
    if(index)
    {
      char *sub = str_Sub(string+offset,0,index);
      list_Push(*tokens,sub);
      tokens_num++;
    }
    offset+=index+splitter_len;
  } 
  if(offset<string_len)
  {
    char *sub = str_Sub(string+offset,0,string_len-offset);
    list_Push(*tokens,sub);
    tokens_num++;
  }

  return(tokens_num);
}
Exemple #2
0
static void graph_InternSCC(GRAPH Graph, GRAPHNODE Node)
/**************************************************************
  INPUT:   A graph and a node of the graph.
  RETURNS: Nothing.
  EFFECT:  This is an internal function used by
           graph_StronglyConnnectedComponents.
	   It sets information in the graph structure which
           specifies the strongly connected components of
           the graph.
***************************************************************/
{
  GRAPHNODE n;
  LIST      scan;
  NAT       act_dfs;

  act_dfs = (Graph->dfscount)++;
  graph_NodeSetDfsNum(Node, act_dfs);

  graph_UNFINISHED = list_Push(Node, graph_UNFINISHED);
  graph_ROOTS      = list_Push(Node, graph_ROOTS);

  /* putchar('\n'); list_Apply(graph_NodePrint, graph_UNFINISHED);
     putchar('\n'); list_Apply(graph_NodePrint, graph_ROOTS);
     fflush(stdout); DBG */

  for (scan = graph_NodeNeighbors(Node);
       !list_Empty(scan); scan = list_Cdr(scan)) {
    n = list_Car(scan);
    if (!graph_NodeVisited(n)) {
      graph_InternSCC(Graph, n);  /* Visit <n> */
    } else if (!graph_NodeCompleted(n)) {
      /* <n> was visited but is not yet in a permanent component */
      NAT dfs_num_of_n = graph_NodeDfsNum(n);
      while (!list_StackEmpty(graph_ROOTS) &&
	     graph_NodeDfsNum(list_Top(graph_ROOTS)) > dfs_num_of_n)
	graph_ROOTS = list_Pop(graph_ROOTS);
      /* putchar('\n'); list_Apply(symbol_Print, graph_UNFINISHED);
	 putchar('\n'); list_Apply(symbol_Print, graph_ROOTS);
	 fflush(stdout); DBG */
    }
  }

  /* printf("\nDFS(%u) complete.", graph_NodeNumber(Node)); DBG */

  if (Node == list_Top(graph_ROOTS)) {
    /* Node is root of a component, so make this component permanent */
    while (!list_StackEmpty(graph_UNFINISHED) &&
	   graph_NodeDfsNum(list_Top(graph_UNFINISHED)) >= act_dfs) {
      n = list_Top(graph_UNFINISHED);
      graph_UNFINISHED = list_Pop(graph_UNFINISHED);
      graph_NodeSetCompNum(n, Graph->compcount);
    }
    Graph->compcount++;
    graph_ROOTS = list_Pop(graph_ROOTS);
  }

  /* putchar('\n'); list_Apply(graph_NodePrint, graph_UNFINISHED);
     putchar('\n'); list_Apply(graph_NodePrint, graph_ROOTS); fflush(stdout); DBG */
}
Exemple #3
0
void control_AddKeyList(Control_Event *event, unsigned int pollType, int eventType, struct list *keyList)
{
    int *key = NULL;
    int *keyValue = NULL;
    int numKey = list_Size(keyList);
    Control_Keys *cKeys = NULL;

    int x = 0;

    cKeys = control_CreateKeys(numKey, pollType, eventType);

    while(keyList != NULL)
    {
        keyValue = keyList->data;
        cKeys->keys[x] = *keyValue;

        x++;
        keyList = keyList->next;
    }

    switch (pollType)
    {
        case C_KEYBOARD:
        case C_JOYSTICK:
        case C_MOUSE:
        list_Push(&event->eventKeys, cKeys, numKey);
        break;

        default:
        file_Log(ker_Log(), 1, "Error: key not added to list, undefined poll type %d.\n", pollType);
        break;
    }

    return;
}
Exemple #4
0
/*
    Function: vUnitMenu_Select

    Description -
    Select a unit/s in the game at the ui pointers position.

    1 argument:
    Unit_Menu *menu - The unit menu containing the data needed to select units.
*/
static int vUnitMenu_Select(Unit_Menu *menu)
{
    Vent_Game *game = menu->currentGame;
    Vent_Side *playerSide = &game->side[game->playerUnit->team];

    Vent_Unit *u = NULL;
    struct list *unitList = NULL;

    /*Unit select origin*/
    Vector2DInt position = {menu->pntPos.x, menu->pntPos.y};

    /*Set the amount selected to 0*/
    list_Clear(&menu->selectedUnits);
    menu->numSelected = 0;

    /*For all the units in the players side*/
    unitList = playerSide->units;

    while(unitList != NULL)
    {
        u = unitList->data;

        /*If the unit collides with the curser and its not the player*/
        if(u->isPlayer == 0 && collisionStatic_CircRectInt(position.x, position.y, &menu->selectRadius, u->iPosition.x, u->iPosition.y, u->width, u->height) == 1)
        {
            /*Place it into the selected list and update the counter*/
            menu->numSelected ++;
            list_Push(&menu->selectedUnits, u, 0);
        }

        unitList = unitList->next;
    }

    return menu->numSelected;
}
void daemon_compute_append_queue(struct razer_daemon *daemon,list *queue)
{
	while(!list_IsEmpty(queue))
	{
		struct razer_fx_render_node *render_node = (struct razer_fx_render_node*)list_Dequeue(queue);
		list_Push(daemon->render_nodes,render_node);
		if(render_node->input_frame_linked_uid!=-1 && render_node->input_frame_linked_uid != 0)
			list_Queue(queue,daemon_get_render_node(daemon,render_node->input_frame_linked_uid));
		if(render_node->second_input_frame_linked_uid!=-1 && render_node->second_input_frame_linked_uid != 0)
			list_Queue(queue,daemon_get_render_node(daemon,render_node->second_input_frame_linked_uid));
	}
}
BOOL list_Insert(list *l, long index, void *obj)
{
	if(index == 0 && !l->num)
	{
		list_Push(l, obj);
	}
	else if(index <= l->num - 1)
	{
		l->num++;
		l->items = realloc(l->items, (l->num) * sizeof(void*));
		for(long i = l->num - 2; i >= index; i--)
		{
			list_MoveDown(l, i);
		}
		l->items[index] = obj;
		return(1);
	}
	else if(index > l->num - 1)
		list_Push(l, obj);
	return(0);
}
Exemple #7
0
struct list *list_Copy(struct list *src)
{
    struct list *cList = NULL;

    while(src != NULL)
    {
        list_Push(&cList, src->data, src->info);

        src = src->next;
    }

    return cList;
}
Exemple #8
0
void vLevel_LoadSupply_0(Vent_Level *l, void *game, Level_Tag *tag, FILE *levelFile)
{
    const int version = 0;

    int x = 0;

    l->header.numSupply = tag->amount;

    for(x = 0; x < l->header.numSupply; x++)
    {
        /*Load the supply data and directly place it into the level*/
        list_Push(&l->unitSupply, vSupply_Load(game, l->srcTime, levelFile), 0);
    }

    return;
}
Exemple #9
0
Vent_Unit *vGame_AddUnit(Vent_Game *g, Vent_Unit *u)
{
    depWatcher_AddBoth(&u->depWatcher, &g->side[u->team].units, 0);

    list_Push(&g->units, u, 0);

    if(u->isPlayer == 0)
        vUnit_GiveDefaultAi(u, g);

	if(u->team != g->playerUnit->team)
	{
		/*Lower the unit health for easy difficulty*/
		if(ve_Options.difficulty == 0)
		{
			u->health = u->healthStarting = u->healthStarting >> 1;
		}
	}
Exemple #10
0
/*
	Function: control_AddKey

	Description -
	A function used to add one or multiple keys to trigger an event. These keys will determine whether
	the event should be activated. You can add multiple series of keys, for example using this
	function to add the letter 'a' and then calling it again to add the left mouse button would result
	in the event being activated if either of those were pressed.
	Returns no value.

	5 arguments:
	Control_Event *event - the event to add keys to.
	unsigned int pollType - the type of event the keys need to be checked from,
	unsigned int event - the event type the keys need to be checked from,
	keyboard (C_KEYBOARD), mouse (C_MOUSE), or joystick (C_JOYSTICK).
	unsigned int numKey - the number of keys to be added.
	... - here you must pass the values of any keys to be added. These values can be found from SDLKey defines for keyboards.
*/
void control_AddKey(Control_Event *event, unsigned int pollType, int eventType, unsigned int numKey, ...)
{
    unsigned int x = 0;
    Control_Keys *cKeys = NULL;

    va_list var;

	/*Check if the control component should actually poll for this type of control method*/
    if((controlData.flags & pollType) != pollType)
        return;

    va_start(var, numKey);

    cKeys = control_CreateKeys(numKey, pollType, eventType);

    for(x = 0; x < numKey; x++)
    {
        cKeys->keys[x] = va_arg(var, int);
    }

	/*Push the index/es into the list so that another function can detect whether the keys are pressed*/
    switch (pollType)
    {
        case C_KEYBOARD:;
        case C_JOYSTICK:
        case C_MOUSE:
        list_Push(&event->eventKeys, cKeys, numKey);
        break;

        default:
        file_Log(ker_Log(), 1, "Error: key not added to list, undefined poll type %d.\n", pollType);
        break;
    }

    va_end(var);

    return;
}
Exemple #11
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;
}
int daemon_register_render_node(struct razer_daemon *daemon,struct razer_fx_render_node *render_node)
{
	list_Push(daemon->fx_render_nodes,render_node);
	render_node->id = daemon->fx_render_nodes_uid++;
	return(render_node->id);
}
void daemon_render_node_add_sub(struct razer_fx_render_node *render_node,struct razer_fx_render_node *sub_node)
{
	list_Push(render_node->subs,sub_node);
	sub_node->parent = render_node;
}
Exemple #14
0
/*
    Returns a ui scroll populated with levels, either all of them or just
    the ones in a campaign.
*/
Ui_ButtonScroll *MM_CreateLevelScroll(Base_State *gState)
{
    struct menu_Game *menu = gState->info;

    DIR *levelDIR = NULL;
    //DIR *levelDIR = opendir("../LevelsOld");
    struct list *levelList = NULL;
    struct list *currentList = NULL;
    struct dirent *level;

    char *levelName = NULL;

    int totalLevels = 0;
    int x = 0;
    Vent_CaLvl *cl = NULL;

    Ui_ButtonScroll *scroll = NULL;
    Ui_Button *button = NULL;

    Sprite *sB = NULL;
    SDL_Surface *lNameSurface[2];

    scroll = uiButtonScroll_Create(ve_Menu.menuSecondPosition.x, 150, SCR_V, 7, 5, 1, 0,
                                   veMenu_ButtonSprite(ve_Menu.menuSecondPosition.x, 270, sprite_Copy(&ve_Sprites.scroll[D_UP], 1), &menu->timer, NULL, &MABFH_ButtonHover, NULL),
                                   veMenu_ButtonSprite(ve_Menu.menuSecondPosition.x + 20, 270, sprite_Copy(&ve_Sprites.scroll[D_DOWN], 1), &menu->timer, NULL, &MABFH_ButtonHover, NULL),
                                  0);

    list_ClearAll(&menu->nameList);

    menu->nameList = NULL;

    if(menu->player->playCampaign == 0)
    {
        levelDIR = opendir(kernel_GetPath("PTH_VentCustomLevels"));
        if(levelDIR == NULL)
        {
            printf("Error cannot open level directory\n");
            abort();
        }

        levelList = file_Get_Extension_List(levelDIR, ".map");
        currentList = levelList;

        /*Find all the files with the .map extension and insert the names into the menu*/
        while(currentList != NULL)
        {
            totalLevels ++;

            level = currentList->data;

            levelName = (char *)mem_Malloc(strlen(level->d_name) + 1, __LINE__, __FILE__);
            strcpy(levelName, level->d_name);

            list_Push(&menu->nameList, levelName, 0);

            //printf("Level name: %s\n", levelName);

            button = veMenu_ButtonOption(levelName, NULL, font_Get(2, 13), &menu->timer, VL_HUD + 1, &MM_ChooseLevel, &MABFH_ButtonHover, dataStruct_Create(2, menu, levelName));

            uiButtonScroll_AddButton(scroll, button, 0);

            currentList = currentList->next;
        }

        list_ClearAll(&levelList);
        closedir(levelDIR);
    }
    else
    {
        /*Build scroll with level names in campaign*/
        currentList = menu->player->campaign->lvlInfo;

        x = 0;

        while(currentList != NULL && x <= menu->player->campaign->totalLevels && x <= menu->player->campaign->upToLevel)
        {
            x++;
            cl = currentList->data;

            printf("Level name: %s\n", cl->name);

            button = veMenu_ButtonOption(cl->name, NULL, font_Get(2, 13), &menu->timer, VL_HUD + 1, &MM_ChooseLevel, &MABFH_ButtonHover, dataStruct_Create(2, menu, cl->fileName));

            uiButtonScroll_AddButton(scroll, button, 0);

            currentList = currentList->next;
        }
    }

    uiButtonScroll_SetHoverState(scroll, &MABFH_HoverLine);

    return scroll;
}
Exemple #15
0
SDL_Surface *surface_Rotate(SDL_Surface *source, float angle, int autoFree)
{
    SDL_Surface *rotatedSurface = NULL;

    int x = 0;
    int y = 0;

    float sOriginX, sOriginY;
    float distance;
    float xDis, yDis;
    float dX, dY;
    float odX, odY;

    float newAngle;
    float cosA, sinA;

    float newWidth;
    float newHeight;

    float rOriginX;
    float rOriginY;

    Uint16P *sPixel;
    Uint16P *dPixel;

    /*Fix the angle to judge the size of the new rotated image*/
    newAngle = (float)fabs(angle);

    if(newAngle > PI_2)
    {
        /*If the angle is larger than 360 then reduce it to keep it in that domain*/
        if(newAngle > PI2)
        {
            newAngle = mth_Segment(newAngle, PI2);
        }

        /*Keep the angle within 90 domain*/
        switch(mth_GetQuadrant_Angle(newAngle))
        {
            case 1:
            /*Make the new origin to be from the negative x-axis and positive y-axis*/
            newAngle = PI - newAngle;
            break;

            case 2:
            /*make the new angle be from the negative x-axis and y-axis*/
            newAngle = (float)fabs(PI - newAngle);
            break;

            case 3:
            /*make the new angle be from the positive axis and negative y-axis*/
            newAngle = PI2 - newAngle;
            break;
        }
        /*The code above in this branch is the same as doing
        newAngle = fabs(atan(tan(newAngle)));*/
    }

    /*Obtain the new width and height using trigonomentry*/
    newWidth = (source->w * cosf(newAngle)) + (source->h * cosf((PI/2) - newAngle));

    distance = sqrtf((source->w * source->w) + (source->h * source->h));
    newHeight = distance * sinf(atanf((float)source->h/(float)source->w) + newAngle);

    newWidth = (float)floor(newWidth + 0.5f);
    newHeight = (float)floor(newHeight + 0.5f);

    /*Finally create the new surface*/
    rotatedSurface = surf_Create((int)newWidth, (int)newHeight);

    pixel_Fill(0, 0, rotatedSurface->w, rotatedSurface->h, *ker_colourKey(), rotatedSurface);
    //pixel_Fill(0, 0, rotatedSurface->w, rotatedSurface->h, colourGreen, rotatedSurface);

    /*printf("Created surface (%d %d)\n", rotatedSurface->w, rotatedSurface->h);*/

    /*Obtain the middle position of the source image*/
    sOriginX = (source->w - 1)/2.0f;
    sOriginY = (source->h - 1)/2.0f;

    rOriginX = (rotatedSurface->w - 1)/2.0f;
    rOriginY = (rotatedSurface->h - 1)/2.0f;

    /*Lock the surfaces so their pixels can be written and read*/
    SDL_LockSurface(source);
    SDL_LockSurface(rotatedSurface);

    //printf("Rotating image (%d %d)(%.2f %.2f) into (%d %d)(%.2f %.2f)\n", source->w, source->h, sOriginX, sOriginY, rotatedSurface->w, rotatedSurface->h, rOriginX, rOriginY);
    cosA = cosf(angle);
    sinA = sinf(angle);

    /*For all the pixels in the rotated surface*/
    for(x = 0; x < rotatedSurface->w; x++)
    {
        for(y = 0; y < rotatedSurface->h; y++)
        {
            /*Obtain the pixel to rotate back to the original image*/
            dPixel = pixel_Get(x, y, rotatedSurface);

            /*Obtain the distance from the middle of the surface to the current pixel*/
            xDis = (float)x - rOriginX;
            yDis = (float)y - rOriginY;

            /*Update the new x and y locations of the rotated pixel that would map to this
            pixel in the rotated surface*/
            dX = sOriginX + xDis * cosA - yDis * sinA;
            dY = sOriginY + xDis * sinA + yDis * cosA;

            odX = (float)floor(dX + 0.5f);
            odY = (float)floor(dY + 0.5f);

            /*Ignore pixels that map back outside the original surfaces canvas,
            these pixels have been created to just enlarge the rotated
            surfaces canvas*/
            if(odX < 0 || odY < 0)
            {
                /*printf("ErrorUnder:(%d %d): %f %f\n", x, y, odX, odY);
                printf("Extra info: cosA %.2f, sinA %.2f, dX %.2f, dY %.2f\n", cosA, sinA, dX, dY);*/
            }
            else if(odX >= source->w || odY >= source->h)
            {
                /*printf("ErrorOver:(%d %d): %f %f\n", x, y, odX, odY);
                printf("Extra info: cosA %.2f, sinA %.2f, dX %.2f, dY %.2f\n", cosA, sinA, dX, dY);*/
            }
            else
            {
                /*Obtain the pixel at the original surface*/
                sPixel = pixel_Get((int)odX, (int)odY, source);

                /*Give the colour of this pixel to the colour of the corresponding pixel that is
                mapped onto the rotated surface*/
                *dPixel = *sPixel;
            }
        }
    }

    SDL_UnlockSurface(source);
    SDL_UnlockSurface(rotatedSurface);
    SDL_SetColorKey(rotatedSurface, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB(ker_Screen()->format, 255, 0, 255));

    if(autoFree == A_FREE)
		list_Push(&surf_C.surfaceList, rotatedSurface, autoFree);

    return rotatedSurface;
}