navpath_t* NavRep_PathFinalize(navmesh_t* navmesh, const vec2_t src, const vec2_t dest, navpolygate_t* gate) { navpath_t* navpath; navpathwaypt_t* waypoint; navpath = (navpath_t*)ALLOCATE(navpath_t); navpath->waypoints.first = NULL; navpath->waypoints.last = NULL; M_CopyVec2(dest, navpath->pos); M_CopyVec2(dest, navpath->src); M_CopyVec2(src, navpath->dest); while ( gate ) { waypoint = NavPathWaypt_Create(gate->position); if ( gate->cnxn->into->bridge2 ) { waypoint->bridge = gate->cnxn->into; } // M_CopyVec2(gate->position, waypoint->position); List_PushBack(&navpath->waypoints, waypoint); gate = gate->from; } waypoint = NavPathWaypt_Create(src); List_PushBack(&navpath->waypoints, waypoint); navpath->waypoint = navpath->waypoints.first; return navpath; }
static inline Object File_InternalReadString(Object _self, long maxLength, long stopSymbolsLength, long* stopSymbols) { Object _toReturn = List_Create(); Object_Autorelease(_toReturn); while(maxLength--) { Object _char = File_ReadChar(_self); if(_char == _nil) { if(List_Size(_toReturn) == 0) { return _nil; } else { return _toReturn; } } else { int i; long code = Number_GetLong(Char_GetMutableCode(_char)); for(i = 0; i < stopSymbolsLength; i++) { if(code == stopSymbols[i]) return _toReturn; } List_PushBack(_toReturn, _char); } } return _toReturn; }
int main() { List *a; int v; List_Foreach_Variable; a = List_CreateNew(4); if(0==a) { printf("Create New list failed!\n"); return 0; } v=0; List_PushBack(a,(void*)&v); v=1; List_PushBack(a,(void*)&v); v=2; List_PushBack(a,(void*)&v); v=3; List_PushBack(a,(void*)&v); v=4; List_PushBack(a,(void*)&v); v=5; List_PushBack(a,(void*)&v); List_PushBack(a,(void*)&v); int val; List_Foreach(a) { val = *(int*)List_Foreach_Value; if(2==val) { List_Foreach_RmCurNode; continue; } printf("%d----------\n",val); } val = 2; printf("size of list %d\n",List_Count(a)); printf("value size of list %d\n",List_ValueCount(a,(void*)&val)); printf("index of \'%d\' is %d\n",val,List_Indexof(a,&val)); List_Clear(a); return 0; }
int main(void) { LogFile = stderr; ssize_t vals[] = {-1, 2, -3, 4, -5, 6, -7, 8, -9, 0}; List *l = NewList(); for (int i = 0; i < sizeof(vals)/sizeof(ssize_t); ++i) { List_PushBack(l, (void *) vals[i]); } int i = 0; for (ListElem *e = l->Front; e != NULL; e = e->Next) { assert((ssize_t) e->Value == vals[i]); ++i; } return 0; }
int main(void) { INIT(); int i, j; Object list = List_Create(); for(j = 0; j < TIMES; j++) { Object front, back; for(i = 0; i < NODES; i++) { if(i & 1) { List_PushBack(list, INT_AS_OBJECT(i)); } else { List_PushFront(list, INT_AS_OBJECT(i)); }; }; front = List_First(list); back = List_Last(list); while(!ListIterator_ThisEnd(front)) { ListIterator_Next(front); ListIterator_Prev(back); }; if(!ListIterator_ThisBegin(back)) { return 1; }; List_Clean(list); }; Object_Release(list); return 0; };
int main(void) { INIT(); long int i; int l = 10, r = 5; Object list = List_Create(); Object list2 = List_Create(); Object temp_list; Object front, back; // list2 = (0 1 2 3 4 5 6 ... 148 149) for(i = 0; i < l + r; i++) { List_PushBack(list2, INT_AS_OBJECT(i)); }; // list = (99998 99996 ... 8 6 4 2 0 1 3 5 7 9 ... 99997 99999 ) for(i = 0; i < NODES; i++) { if(i & 1) { List_PushBack(list, INT_AS_OBJECT(i)); } else { List_PushFront(list, INT_AS_OBJECT(i)); }; }; for(front = List_First(list), i = 0; i < NODES / 2; ListIterator_Next(front), i++) { List_AddAfterPosition(list2, INT_AS_OBJECT(l - 1 + i), ListIterator_ThisData(front)); }; for(back = List_Last(list), i = 0; i < NODES / 2; ListIterator_Prev(back), i++) { List_AddAfterPosition(list2, INT_AS_OBJECT(l + NODES / 2 - 1), ListIterator_ThisData(back)); }; front = List_IteratorFromPosition(list2, INT_AS_OBJECT(l)); TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", OBJECT_AS_INT(ListIterator_ThisData(front)) == (NODES & (~1)) - ((!(NODES & 1)) * 2)); back = List_IteratorFromPosition(list2, INT_AS_OBJECT(l + NODES - 1)); TEST("Checking for correctness of IteratorFromPosition after AddList{Before|After}", OBJECT_AS_INT(ListIterator_ThisData(back)) == (NODES & (~1)) - 1 + ((NODES & 1) * 2)); temp_list = List_SublistBetweenIterators(list2, front, back); front = List_First(temp_list); back = List_Last(temp_list); for(i = 1; i < NODES / 2; i++) { if(OBJECT_AS_INT(ListIterator_ThisData(front)) != OBJECT_AS_INT(ListIterator_ThisData(back)) + 1) { DEBUG("Got %li and %li.\n", OBJECT_AS_INT(ListIterator_ThisData(front)), OBJECT_AS_INT(ListIterator_ThisData(back))); return 1; }; ListIterator_Next(front); ListIterator_Prev(back); }; Object_Release(list); Object_Release(list2); Object_Release(temp_list); return 0; };
navpath_t* NavRep_PathCreateToObject(navmeshsize_t navmeshsize, const vec3_t src, navpoly_t* navPolySrc, const baseObject_t* obj, bool close) { navmesh_t* navmesh = &navrep.navmeshes[navmeshsize]; navpath_t* navpath; navpoly_t* pathpoly_src = NULL; navpoly_t* pathpoly_dest = NULL; vec2_t point_src; vec2_t point_dest; bool approx = false; // find nearest src poly if ( navPolySrc ) { pathpoly_src = navPolySrc; M_CopyVec2(src, point_src); } else { NavMesh_FindPolyNearestPoint(navmesh, src, -1, &pathpoly_src, point_src); if ( !pathpoly_src ) { NAV_PRINTF("NavRep_PathCreateToObject could not find nearest src poly"); return NULL; } } // find nearest dest poly if ( pathpoly_src->partition == -1 ) { int ms = System_Milliseconds(); navmesh->partition = ++navmesh->partitionNext; NavPoly_Partition(navmesh, pathpoly_src); NAV_PRINTF("NavPoly_Partition took %d milliseconds\n", System_Milliseconds() - ms); } NavMesh_FindNearestPointAroundObject(navmesh, obj, src, pathpoly_src->partition, &pathpoly_dest, point_dest); if ( !pathpoly_dest ) { approx = true; NavMesh_FindPolyNearestPoint(navmesh, obj->pos, pathpoly_src->partition, &pathpoly_dest, point_dest); if ( !pathpoly_dest ) { NAV_PRINTF("NavRep_PathCreateToObject could not find nearest dest poly"); return NULL; } } // find the path navpath = NavRep_PathCreate_Internal(navmesh, point_dest, pathpoly_dest, point_src, pathpoly_src); if ( navpath ) { if ( close ) { navpathwaypt_t* waypoint; waypoint = NavPathWaypt_Create(obj->pos); List_PushBack(&navpath->waypoints, waypoint); } navpath->obj = obj; navpath->approx = approx; } return navpath; }