예제 #1
0
            public static List <GameObject> Read(Byte[] data)
            {
                unsafe
                {
                    fixed(Byte *ptr = data)
                    {
                        if (ptr == null)
                        {
                            return(null);
                        }
                        Header *   header    = (Header *)ptr;
                        Group *    areas     = (Group *)(ptr + sizeof(Header));
                        Group *    doors     = areas + header->CountAreas;
                        Group *    modules   = doors + header->CountDoors;
                        Group *    objects   = modules + header->CountModules;
                        Group *    end       = objects + header->CountObjects;
                        Script *   scripts   = (Script *)(ptr + header->ScriptsOffset);
                        Operation *operation = (Operation *)(ptr + header->OperationsOffset);

                        Int64 groupNumber = end - areas;

                        Group[] groups = new Group[groupNumber];
                        for (Group *group = areas; group < end; group++)
                        {
                            groups[--groupNumber] = *group;
                        }

                        List <GameObject> gameObjects = new List <GameObject>(groups.Length);

                        foreach (Group group in groups.OrderBy(g => g.Label))
                        {
                            List <GameScript> objectScripts = new List <GameScript>(group.ScriptsCount + 1);

                            for (Int32 s = 0; s <= group.ScriptsCount; s++)
                            {
                                Int32 scriptLabel = group.Label + s;

                                UInt16 position = scripts->Position;
                                scripts++;

                                UInt16 count = (UInt16)(scripts->Position - position);
                                Jsm.ExecutableSegment scriptSegment = MakeScript(operation + position, count);

                                objectScripts.Add(new GameScript(scriptLabel, scriptSegment));
                            }

                            gameObjects.Add(new GameObject(group.Label, objectScripts));
                        }

                        return(gameObjects);
                    }
                }
            }
예제 #2
0
파일: Group.cs 프로젝트: DotLab/Futilef
        /**
         * parentMat: null -> no change
         *            same pointer -> parent transform changed
         *            diff pointer -> parent changed
         */
        public static void Draw(Group *self, float *parentMat, bool isParentTransformDirty)
        {
            var    childLst   = &self->childLst;
            int    childCount = childLst->count;
            void **childArr   = childLst->arr;

            // sort by depth if any child depth is changed
            for (int i = 0; i < childCount; i += 1)
            {
                if (Node.IsDepthDirty(childArr[i]))
                {
                    Algo.MergeSort(childArr, childCount, Node.DepthCmp);
                    break;
                }
            }

            float *mat       = self->mat;
            float *concatMat = self->concatMat;

            bool isTransformDirty = self->isTransformDirty;

            if (isTransformDirty)
            {
                self->isTransformDirty = false;
                Mat2D.FromScalingRotationTranslation(mat, self->pos, self->scl, self->rot);
            }

            if (isParentTransformDirty)
            {
                self->parentMat = parentMat;
            }

            if (isTransformDirty || isParentTransformDirty)
            {
                isParentTransformDirty = true;
                if (parentMat == null)
                {
                    Mat2D.Copy(concatMat, mat);
                }
                else
                {
                    Mat2D.Mul(concatMat, parentMat, mat);
                }
            }

            for (int i = 0; i < childCount; i += 1)
            {
                Node.Draw(childArr[i], concatMat, isParentTransformDirty);
            }
        }
예제 #3
0
파일: Group.cs 프로젝트: DotLab/Futilef
        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);
        }