public static void Init(Pool *self, int len) { #if FDB Should.NotNull("self", self); Should.GreaterThanZero("len", len); self->type = Type; #endif self->len = len; byte *arr = self->arr = (byte *)Mem.Malloc(len); self->shift = 0; // sentinel int *head = (int *)arr; head[0] = -1; // sentinelHead.prev = -1; head[1] = HeadSize + TailSize; // sentinelhead.next = HeadSize + TailSize; head[2] = 0; // sentinelHead.size = 0; head[3] = -1; // sentinelTail.size = -1; // to prevent merging // Fdb.Dump(arr, len); // sentinel firstFree sentinel int size = len - HeadSize - TailSize - HeadSize - TailSize - HeadSize; SetFreeMeta((int *)(arr + HeadSize + TailSize), 0, -1, size); // sentinel head = (int *)(arr + len - HeadSize); head[0] = -1; // prev = -1 will prevent merging head[1] = -1; head[2] = 0; PtrLst.Init(&self->dependentLst); #if FDB Verify(self); #endif }
public static void ShiftBase(void *self, long shift) { switch (*(int *)self) { case Tag.PtrLst: PtrLst.ShiftBase((PtrLst *)self, shift); return; case Tag.PtrIntDict: PtrIntDict.ShiftBase((PtrIntDict *)self, shift); return; } }
public static void Init(Group *self) { self->tag = Tag.Group; Vec3.Zero(self->pos); Vec2.One(self->scl); self->rot = 0; self->isTransformDirty = true; self->isDepthDirty = true; Mat2D.Identity(self->mat); Mat2D.Identity(self->concatMat); self->parentMat = null; PtrLst.Init(&self->childLst); }
protected override void RunTests() { var refList = new System.Collections.Generic.List <long>(); var lst = stackalloc PtrLst[1]; PtrLst.Init(lst); StartCase(); for (long i = 0; i < 1000000; i += 1) { refList.Add(i); } RefCase(); StartCase(); for (long i = 0; i < 1000000; i += 1) { PtrLst.Push(lst, (void *)i); } LogCase("push"); var idx = new int[1000000]; for (int i = 0; i < 1000000; i += 1) { idx[i] = Random.Range(0, 1000000); } long t = 0; StartCase(); for (long i = 0; i < 1000000; i += 1) { t = refList[idx[i]]; } RefCase(); StartCase(); for (long i = 0; i < 1000000; i += 1) { t = (long)lst->arr[idx[i]]; } LogCase("rand get"); StartCase(); for (long i = 0; i < 100; i += 1) { if (idx[i] < (1000000 - i)) { refList.RemoveAt(idx[i]); } } RefCase(); StartCase(); for (long i = 0; i < 100; i += 1) { if (idx[i] < (1000000 - i)) { PtrLst.RemoveAt(lst, idx[i]); } } LogCase("rand remove"); StartCase(); for (long i = 0; i < 50000; i += 1) { refList.Add(t + i); } RefCase(); StartCase(); for (long i = 0; i < 50000; i += 1) { PtrLst.Push(lst, (void *)(t + i)); } LogCase("re push"); StartCase(); refList.Sort(0, 10000, new Cmpr()); RefCase(); StartCase(); Algo.MergeSort(lst->arr, 10000, Cmp); LogCase("sort"); }
void OnEnable() { Res.LoadAtlases(10); #if GPC_TEST nodePool = Pool.New(); nodeLst = PtrLst.New(); PtrLst.Push(&nodePool->dependentLst, nodeLst); var sprite = (TpSprite *)Pool.Alloc(nodePool, sizeof(TpSprite)); TpSprite.Init(sprite, Res.GetSpriteMeta(10001)); var container = (Group *)Pool.Alloc(nodePool, sizeof(Group)); Group.Init(container); PtrLst.Push(&nodePool->dependentLst, &container->childLst); PtrLst.Push(nodeLst, sprite); Vec4.Set(sprite->color, 1, 1, 1, 1); Vec2.Set(sprite->scl, .015f, .015f); DrawCtx.Start(); var arr = (TpSprite **)nodeLst->arr; for (int i = 0, len = nodeLst->count; i < len; i += 1) { Node.Draw(arr[i], null, false); } DrawCtx.Finish(); return; #endif gpc = new GpController(Camera.main); for (int i = 0; i < 5; i += 1) { gpc.SetCamAttr(CamAttr.Position, 0f, 0f); gpc.SetCamAttr(CamAttr.Zoom, 5f); gpc.AddImg(1, 10001); gpc.SetImgInteractable(1, (phase, x, y) => Debug.LogFormat("hit img1: phase {0}, x {1}, y {2}", phase, x, y)); gpc.SetImgAttr(1, ImgAttr.Position, 0f, 0f, 0f); gpc.SetImgAttr(1, ImgAttr.Rotation, 0f); gpc.SetImgAttr(1, ImgAttr.Alpha, 1f); gpc.SetImgAttrEased(1, ImgAttr.Scale, 1f, EsType.ElasticOut, 0.01f, 0.01f); gpc.Wait(.5f); gpc.SetImgAttrEased(1, ImgAttr.Tint, 1.5f, EsType.ElasticOut, 1f, 0.5f, 1f); gpc.SetImgAttrEased(1, ImgAttr.Position, 2f, EsType.ElasticOut, 2f, -1f, 0f); gpc.Wait(); gpc.SetImgAttrEased(1, ImgAttr.Tint, 1.5f, EsType.ElasticOut, 1f, 1f, 1f); gpc.SetImgAttrEased(1, ImgAttr.Position, 2f, EsType.ElasticOut, -2f, 2f, 0f); gpc.SetImgAttrEased(1, ImgAttr.Rotation, 1.5f, EsType.ElasticOut, Mathf.PI * 2.5f); gpc.SetCamAttrEased(CamAttr.Zoom, 1.5f, EsType.ElasticOut, 2f); gpc.SetCamAttrEased(CamAttr.Position, 2f, EsType.ElasticOut, -2f, 2f); gpc.Wait(.5f); gpc.AddImg(2, 10001); gpc.SetImgInteractable(2, (phase, x, y) => Debug.LogFormat("hit img2: phase {0}, x {1}, y {2}", phase, x, y)); gpc.SetImgAttr(2, ImgAttr.Position, 0f, 0f, -5f); gpc.SetImgAttr(2, ImgAttr.Rotation, 0f); gpc.SetImgAttr(2, ImgAttr.Scale, 0.1f, 0.1f); gpc.SetImgAttr(2, ImgAttr.Alpha, 1f); gpc.SetImgAttrEased(2, ImgAttr.Scale, 1f, EsType.ElasticOut, 0.006f, 0.006f); gpc.SetImgAttrEased(2, ImgAttr.Position, 4f, EsType.ElasticOut, -2f, 2f, 0f); gpc.SetImgInteractable(1, null); gpc.Wait(); gpc.SetImgId(2, 103); gpc.Wait(); gpc.SetImgAttrEased(1, ImgAttr.Tint, 1f, EsType.ElasticOut, 1.5f, 1.5f, 1.5f); gpc.Wait(); gpc.RmImg(1); gpc.RmImg(2); } Application.targetFrameRate = Screen.currentResolution.refreshRate; #if FDB Fdb.Test(); #endif }