Пример #1
0
        public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
        {
            List<RenderInfo> result = new List<RenderInfo>();
            transform.Push();
            transform.NJTranslate(item.Position);
            transform.NJRotateY(item.Rotation.Y - 0x5772);
            transform.NJScale((item.Scale.X), (item.Scale.Y), (item.Scale.Z));

            float largestScale = item.Scale.X;
            if (item.Scale.Y > largestScale) largestScale = item.Scale.Y;
            if (item.Scale.Z > largestScale) largestScale = item.Scale.Z;

            BoundingSphere boxSphere = new BoundingSphere() { Center = new Vertex(item.Position.X, item.Position.Y, item.Position.Z), Radius = (1.5f * largestScale) };

            RenderInfo outputInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.Solid, boxSphere);
            result.Add(outputInfo);

            if (item.Selected)
            {
                RenderInfo highlightInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.WireFrame, boxSphere);
                result.Add(highlightInfo);
            }

            transform.Pop();
            return result;
        }
Пример #2
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateY(item.Rotation.Y);
     result.AddRange(ballmodel.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), ballmeshes));
     if (item.Selected)
         result.AddRange(ballmodel.DrawModelTreeInvert(dev, transform, ballmeshes));
     transform.Pop();
     double v24 = item.Scale.X * 0.05000000074505806;
     transform.Push();
     double v22 = item.Scale.X * 0.5 + item.Position.Y;
     transform.NJTranslate(item.Position.X, (float)v22, item.Position.Z);
     transform.NJScale(1.0f, (float)v24, 1.0f);
     result.AddRange(cylindermodel.DrawModelTree(dev, transform, null, cylindermeshes));
     if (item.Selected)
         result.AddRange(cylindermodel.DrawModelTreeInvert(dev, transform, cylindermeshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(item.Position.X, item.Position.Y + item.Scale.Z, item.Position.Z);
     result.AddRange(spheremodel.DrawModelTree(dev, transform, null, spheremeshes));
     if (item.Selected)
         result.AddRange(spheremodel.DrawModelTreeInvert(dev, transform, spheremeshes));
     transform.Pop();
     return result;
 }
Пример #3
0
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     HitResult result = HitResult.NoHit;
     transform.Push();
     transform.NJTranslate(item.Position.ToVector3());
     transform.NJRotateY(item.Rotation.Y);
     transform.Push();
     transform.NJTranslate(0, 0, 10);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 2);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0x2000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0xE000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, 0.1000000014901161f);
     result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
     transform.Pop();
     return result;
 }
Пример #4
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     int rows = (int)Math.Max(item.Scale.X, 1);
     int cols = (int)Math.Max(item.Scale.Z, 1);
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation.X & 0xC000, item.Rotation.Y, 0);
     transform.NJTranslate((1 - rows) * 7.5f, 0, (1 - cols) * 7.5f);
     for (int i = 0; i < rows; ++i)
     {
         transform.Push();
         for (int j = 0; j < cols; ++j)
         {
             result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
             if (item.Selected)
                 result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
             transform.NJTranslate(0, 0, 15);
         }
         transform.Pop();
         transform.NJTranslate(15, 0, 0);
     }
     transform.Pop();
     return result;
 }
Пример #5
0
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation);
     HitResult result = model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes);
     transform.Pop();
     return result;
 }
Пример #6
0
        public override BoundingSphere GetBounds(SETItem item, NJS_OBJECT model)
        {
            float largestScale = (item.Scale.X + 10) / 5f;
            if (item.Scale.Y > largestScale) largestScale = (item.Scale.Y + 10) / 5f;
            if (item.Scale.Z > largestScale) largestScale = (item.Scale.Z + 10) / 5f;

            BoundingSphere boxSphere = new BoundingSphere() { Center = new Vertex(item.Position.X, item.Position.Y, item.Position.Z), Radius = largestScale };

            return boxSphere;
        }
Пример #7
0
        public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
        {
            transform.Push();
            transform.NJTranslate(item.Position);
            transform.NJRotateY(item.Rotation.Y - 0x5772);
            transform.NJScale((item.Scale.X), (item.Scale.Y), (item.Scale.Z));
            HitResult result = mesh.CheckHit(Near, Far, Viewport, Projection, View, transform);

            transform.Pop();
            return result;
        }
Пример #8
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation.X, item.Rotation.Y - 0x8000, item.Rotation.Z);
     result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Пример #9
0
 public static object GetShadow(SETItem item)
 {
     long v5 = Math.Abs((long)item.Scale.Z % 100);
     if (v5 >= 10)
     {
         if (v5 < 90)
             return ShadowType.Off;
         else
             return ShadowType.Heavy;
     }
     else
         return ShadowType.Light;
 }
Пример #10
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateY(item.Rotation.Y);
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, (item.Scale.Z + 10) / 5f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Пример #11
0
        public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
        {
            transform.Push();
            transform.NJTranslate(item.Position);
            transform.NJRotateY(item.Rotation.Y);

            float X, Y;
            X = (float)((item.Scale.X + 10.0) * 0.1f);
            Y = (float)((item.Scale.Y + 10.0) * 0.1f);
            transform.NJScale(X, Y, X);

            HitResult result = model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes);
            transform.Pop();
            return result;
        }
Пример #12
0
        /// <summary>
        /// Returns a bounding sphere for the supplied SET Item.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public virtual BoundingSphere GetBounds(SETItem item, NJS_OBJECT model=null)
        {
            BoundingSphere result = new BoundingSphere();

            if (model != null)
            {
                // build bounding spheres for all children using BoundingSphere.CreateMerged
                if (model.Attach != null)
                {
                    result = model.Attach.Bounds;
                }

                ProcessModel(model, ref result);
            }

            return new BoundingSphere(item.Position, result.Radius);
        }
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     transform.Push();
     Matrix m = transform.Top;
     transform.NJTranslate(xpos ?? item.Position.X, ypos ?? item.Position.Y, zpos ?? item.Position.Z);
     transform.NJRotateXYZ(xrot ?? item.Rotation.X, yrot ?? item.Rotation.Y, zrot ?? item.Rotation.Z);
     HitResult result;
     if (model == null)
         result = ObjectHelper.CheckSpriteHit(Near, Far, Viewport, Projection, View, transform);
     else
     {
         transform.NJScale(xscl ?? item.Scale.X, yscl ?? item.Scale.Y, zscl ?? item.Scale.Z);
         result = model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes);
     }
     transform.Pop();
     return result;
 }
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(xpos ?? item.Position.X, ypos ?? item.Position.Y, zpos ?? item.Position.Z);
     transform.NJRotateXYZ(xrot ?? item.Rotation.X, yrot ?? item.Rotation.Y, zrot ?? item.Rotation.Z);
     if (model == null)
         result.AddRange(ObjectHelper.RenderSprite(dev, transform, null, item.Position.ToVector3(), item.Selected));
     else
     {
         transform.NJScale(xscl ?? item.Scale.X, yscl ?? item.Scale.Y, zscl ?? item.Scale.Z);
         result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures(texture), meshes));
         if (item.Selected)
             result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     }
     transform.Pop();
     return result;
 }
Пример #15
0
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     HitResult result = HitResult.NoHit;
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateY(item.Rotation.Y);
     result = HitResult.Min(result, ballmodel.CheckHit(Near, Far, Viewport, Projection, View, transform, ballmeshes));
     transform.Pop();
     double v24 = item.Scale.X * 0.05000000074505806;
     transform.Push();
     double v22 = item.Scale.X * 0.5 + item.Position.Y;
     transform.NJTranslate(item.Position.X, (float)v22, item.Position.Z);
     transform.NJScale(1.0f, (float)v24, 1.0f);
     result = HitResult.Min(result, cylindermodel.CheckHit(Near, Far, Viewport, Projection, View, transform, cylindermeshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(item.Position.X, item.Position.Y + item.Scale.Z, item.Position.Z);
     result = HitResult.Min(result, spheremodel.CheckHit(Near, Far, Viewport, Projection, View, transform, spheremeshes));
     transform.Pop();
     return result;
 }
Пример #16
0
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     HitResult result = HitResult.NoHit;
     for (int i = 0; i < Math.Min(item.Scale.X + 1, 8); i++)
     {
         transform.Push();
         if (item.Scale.Z == 1) // circle
         {
             double v4 = i * 360.0;
             Vector3 v7 = new Vector3(
                 ObjectHelper.ConvertBAMS((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y,
                 0,
                 ObjectHelper.ConvertBAMSInv((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y);
             transform.Push();
             transform.NJTranslate(item.Position);
             transform.NJRotateObject(item.Rotation);
             Vector3 pos = Vector3.TransformCoordinate(v7, transform.Top);
             transform.Pop();
             transform.NJTranslate(pos);
             result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
         }
         else // line
         {
             transform.Push();
             transform.NJTranslate(item.Position);
             transform.NJRotateObject(item.Rotation);
             double v5;
             if (i % 2 == 1)
                 v5 = i * item.Scale.Y * -0.5;
             else
                 v5 = Math.Ceiling(i * 0.5) * item.Scale.Y;
             Vector3 pos = Vector3.TransformCoordinate(new Vector3(0, 0, (float)v5), transform.Top);
             transform.Pop();
             transform.NJTranslate(pos);
             result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
         }
         transform.Pop();
     }
     return result;
 }
Пример #17
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position.ToVector3());
     transform.NJRotateY(item.Rotation.Y);
     transform.Push();
     transform.NJTranslate(0, 0, 10);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 2);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0x2000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0xE000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, 0.1000000014901161f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Пример #18
0
 public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
 {
     HitResult result = HitResult.NoHit;
     int rows = (int)Math.Max(item.Scale.X, 1);
     int cols = (int)Math.Max(item.Scale.Z, 1);
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation.X & 0xC000, item.Rotation.Y, 0);
     transform.NJTranslate((1 - rows) * 7.5f, 0, (1 - cols) * 7.5f);
     for (int i = 0; i < rows; ++i)
     {
         transform.Push();
         for (int j = 0; j < cols; ++j)
         {
             result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
             transform.NJTranslate(0, 0, 15);
         }
         transform.Pop();
         transform.NJTranslate(15, 0, 0);
     }
     transform.Pop();
     return result;
 }
Пример #19
0
 public static void AddSETItem(int characterID, SETItem item)
 {
     setItems[characterID].Add(item);
     changes.Push("Add SET Item");
     InvalidateRenderState();
 }
Пример #20
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     ((BasicAttach)model.Children[childindex].Attach).Material[0].TextureID = itemTexs[Math.Min(Math.Max((int)item.Scale.X, 0), 8)];
     transform.Push();
     transform.NJTranslate(item.Position.ToVector3());
     result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Пример #21
0
 public static void SetOneBall(SETItem item, object value)
 {
     UpdateZScale(item, (bool)value, (ShadowType)GetShadow(item), (bool)GetChain(item), (long)GetVerticalSpeed(item));
 }
Пример #22
0
        public static void DuplicateSelection(Device d3ddevice, EditorItemSelection selection, out bool errorFlag, out string errorMsg)
        {
            if (selection.ItemCount < 0) { errorFlag = true; errorMsg = "Negative selection count... what did you do?!?"; return; }

            List<Item> newItems = new List<Item>();
            List<Item> currentItems = selection.GetSelection();

            // duplicate goes here
            for (int i = 0; i < selection.ItemCount; i++)
            {
                if (currentItems[i] is SETItem)
                {
                    SETItem originalItem = (SETItem)currentItems[i];
                    SETItem newItem = new SETItem(originalItem.GetBytes(), 0, selection);

                    SETItems[Character].Add(newItem);
                    newItems.Add(newItem);
                }
                else if (currentItems[i] is LevelItem)
                {
                    LevelItem originalItem = (LevelItem)currentItems[0];
                    LevelItem newItem = new LevelItem(d3ddevice, originalItem.CollisionData.Model.Attach, originalItem.Position, originalItem.Rotation, LevelItems.Count, selection);

                    newItem.CollisionData.SurfaceFlags = originalItem.CollisionData.SurfaceFlags;
                    newItems.Add(newItem);
                }
                else if (currentItems[i] is CAMItem)
                {
                    CAMItem originalItem = (CAMItem)currentItems[i];
                    CAMItem newItem = new CAMItem(originalItem.GetBytes(), 0, selection);

                    CAMItems[Character].Add(newItem);
                    newItems.Add(newItem);
                }
            }

            selection.Clear();
            selection.Add(newItems);

            InvalidateRenderState();

            errorFlag = false;
            errorMsg = "";
        }
Пример #23
0
 private void objectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SETItem item = new SETItem(selectedItems);
     Vector3 pos = cam.Position + (-20 * cam.Look);
     item.Position = new Vertex(pos.X, pos.Y, pos.Z);
     LevelData.SETItems[LevelData.Character].Add(item);
     selectedItems.Clear();
     selectedItems.Add(item);
     LevelData_StateChanged();
 }
 public override BoundingSphere GetBounds(SETItem item, NJS_OBJECT model = null)
 {
     return base.GetBounds(item, this.model);
 }
Пример #25
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            #if !DEBUG
            try
            {
            #endif
                int steps = 10;
                if (d3ddevice == null)
                    ++steps;

                toolStrip1.Enabled = false;

                // HACK: Fixes Twinkle Circuit's geometry lingering if loaded before Sky Chase.
                // I'm sure the real problem is somewhere below, but this is sort of an all around cleanup.
                if (isStageLoaded)
                    LevelData.Clear();

                isStageLoaded = false;

                using (ProgressDialog progress = new ProgressDialog("Loading stage: " + levelName, steps))
                {
                    IniLevelData level = ini.Levels[levelID];

                    string syspath = Path.Combine(Environment.CurrentDirectory, ini.SystemPath);
                    string modpath = ini.ModPath;

                    SA1LevelAct levelact = new SA1LevelAct(level.LevelID);
                    LevelData.leveltexs = null;
                    cam = new EditorCamera(EditorOptions.RenderDrawDistance);

                    Invoke((Action<IWin32Window>)progress.Show, this);

                    if (d3ddevice == null)
                    {
                        progress.SetTask("Initializing Direct3D...");
                        Invoke((Action)InitializeDirect3D);
                        progress.StepProgress();
                    }

                    progress.SetTaskAndStep("Loading level data:", "Geometry");

                    if (string.IsNullOrEmpty(level.LevelGeometry))
                        LevelData.geo = null;
                    else
                    {
                        LevelData.geo = LandTable.LoadFromFile(level.LevelGeometry);
                        LevelData.LevelItems = new List<LevelItem>();
                        for (int i = 0; i < LevelData.geo.COL.Count; i++)
                            LevelData.LevelItems.Add(new LevelItem(LevelData.geo.COL[i], d3ddevice, i, selectedItems));
                    }

                    progress.StepProgress();
                    progress.SetStep("Textures");

                    LevelData.TextureBitmaps = new Dictionary<string, BMPInfo[]>();
                    LevelData.Textures = new Dictionary<string, Texture[]>();
                    if (LevelData.geo != null && !string.IsNullOrEmpty(LevelData.geo.TextureFileName))
                    {
                        BMPInfo[] TexBmps =
                            TextureArchive.GetTextures(Path.Combine(syspath, LevelData.geo.TextureFileName) + ".PVM");
                        Texture[] texs = new Texture[TexBmps.Length];
                        for (int j = 0; j < TexBmps.Length; j++)
                            texs[j] = new Texture(d3ddevice, TexBmps[j].Image, Usage.None, Pool.Managed);
                        if (!LevelData.TextureBitmaps.ContainsKey(LevelData.geo.TextureFileName))
                            LevelData.TextureBitmaps.Add(LevelData.geo.TextureFileName, TexBmps);
                        if (!LevelData.Textures.ContainsKey(LevelData.geo.TextureFileName))
                            LevelData.Textures.Add(LevelData.geo.TextureFileName, texs);
                        LevelData.leveltexs = LevelData.geo.TextureFileName;
                    }

                    progress.StepProgress();

                    #region Start Positions

                    progress.SetTaskAndStep("Setting up start positions...");

                    LevelData.StartPositions = new StartPosItem[LevelData.Characters.Length];
                    for (int i = 0; i < LevelData.StartPositions.Length; i++)
                    {
                        progress.SetStep(string.Format("{0}/{1}", (i + 1), LevelData.StartPositions.Length));

                        IniCharInfo character;
                        if (i == 0 && levelact.Level == SA1LevelIDs.PerfectChaos)
                            character = ini.Characters["SuperSonic"];
                        else
                            character = ini.Characters[LevelData.Characters[i]];

                        Dictionary<SA1LevelAct, SA1StartPosInfo> posini =
                            SA1StartPosList.Load(character.StartPositions);

                        Vertex pos = new Vertex();
                        int rot = 0;

                        if (posini.ContainsKey(levelact))
                        {
                            pos = posini[levelact].Position;
                            rot = posini[levelact].YRotation;
                        }
                        LevelData.StartPositions[i] = new StartPosItem(new ModelFile(character.Model).Model,
                            character.Textures, character.Height, pos, rot, d3ddevice, selectedItems);

                        LoadTextureList(character.TextureList, syspath);
                    }

                    progress.StepProgress();

                    #endregion

                    #region Death Zones

                    progress.SetTaskAndStep("Death Zones:", "Initializing...");

                    if (string.IsNullOrEmpty(level.DeathZones))
                        LevelData.DeathZones = null;
                    else
                    {
                        LevelData.DeathZones = new List<DeathZoneItem>();
                        DeathZoneFlags[] dzini = DeathZoneFlagsList.Load(level.DeathZones);
                        string path = Path.GetDirectoryName(level.DeathZones);
                        for (int i = 0; i < dzini.Length; i++)
                        {
                            progress.SetStep(String.Format("Loading model {0}/{1}", (i + 1), dzini.Length));

                            LevelData.DeathZones.Add(new DeathZoneItem(
                                new ModelFile(Path.Combine(path, i.ToString(System.Globalization.NumberFormatInfo.InvariantInfo) + ".sa1mdl"))
                                    .Model,
                                dzini[i].Flags, d3ddevice, selectedItems));
                        }
                    }

                    progress.StepProgress();

                    #endregion

                    #region Textures and Texture Lists

                    progress.SetTaskAndStep("Loading textures for:");

                    progress.SetStep("Common objects");
                    // Loads common object textures (e.g OBJ_REGULAR)
                    LoadTextureList(ini.ObjectTextureList, syspath);

                    progress.SetTaskAndStep("Loading stage texture lists...");

                    // Loads the textures in the texture list for this stage (e.g BEACH01)
                    foreach (string file in Directory.GetFiles(ini.LevelTextureLists))
                    {
                        LevelTextureList texini = LevelTextureList.Load(file);
                        if (texini.Level != levelact)
                            continue;

                        LoadTextureList(texini.TextureList, syspath);
                    }

                    progress.SetTaskAndStep("Loading textures for:", "Objects");
                    // Object texture list(s)
                    LoadTextureList(level.ObjectTextureList, syspath);

                    progress.SetStep("Stage");
                    // The stage textures... again? "Extra"?
                    if (level.Textures != null && level.Textures.Length > 0)
                        foreach (string tex in level.Textures)
                        {
                            LoadPVM(tex, syspath);

                            if (string.IsNullOrEmpty(LevelData.leveltexs))
                                LevelData.leveltexs = tex;
                        }

                    progress.StepProgress();

                    #endregion

                    #region Object Definitions / SET Layout

                    progress.SetTaskAndStep("Loading Object Definitions:", "Parsing...");

                    LevelData.ObjDefs = new List<ObjectDefinition>();
                    Dictionary<string, ObjectData> objdefini =
                        IniSerializer.Deserialize<Dictionary<string, ObjectData>>(ini.ObjectDefinitions);

                    if (!string.IsNullOrEmpty(level.ObjectList) && File.Exists(level.ObjectList))
                    {
                        List<ObjectData> objectErrors = new List<ObjectData>();
                        ObjectListEntry[] objlstini = ObjectList.Load(level.ObjectList, false);
                        Directory.CreateDirectory("dllcache").Attributes |= FileAttributes.Hidden;

                        for (int ID = 0; ID < objlstini.Length; ID++)
                        {
                            string codeaddr = objlstini[ID].CodeString;

                            if (!objdefini.ContainsKey(codeaddr))
                                codeaddr = "0";

                            ObjectData defgroup = objdefini[codeaddr];
                            ObjectDefinition def;

                            if (!string.IsNullOrEmpty(defgroup.CodeFile))
                            {
                                progress.SetStep("Compiling: " + defgroup.CodeFile);

                                // TODO: Split this out to a function
                                #region Compile object code files

                                string ty = defgroup.CodeType;
                                string dllfile = Path.Combine("dllcache", ty + ".dll");
                                DateTime modDate = DateTime.MinValue;
                                if (File.Exists(dllfile))
                                    modDate = File.GetLastWriteTime(dllfile);
                                string fp = defgroup.CodeFile.Replace('/', Path.DirectorySeparatorChar);
                                if (modDate >= File.GetLastWriteTime(fp) && modDate > File.GetLastWriteTime(Application.ExecutablePath))
                                    def =
                                        (ObjectDefinition)
                                            Activator.CreateInstance(
                                                Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, dllfile))
                                                    .GetType(ty));
                                else
                                {
                                    string ext = Path.GetExtension(fp);
                                    CodeDomProvider pr = null;
                                    switch (ext.ToLowerInvariant())
                                    {
                                        case ".cs":
                                            pr = new Microsoft.CSharp.CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
                                            break;
                                        case ".vb":
                                            pr = new Microsoft.VisualBasic.VBCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
                                            break;
                                    }
                                    if (pr != null)
                                    {
                                        CompilerParameters para =
                                            new CompilerParameters(new string[]
                                            {
                                                "System.dll", "System.Core.dll", "System.Drawing.dll", Assembly.GetAssembly(typeof (Vector3)).Location,
                                                Assembly.GetAssembly(typeof (Texture)).Location, Assembly.GetAssembly(typeof (D3DX)).Location,
                                                Assembly.GetExecutingAssembly().Location, Assembly.GetAssembly(typeof (LandTable)).Location,
                                                Assembly.GetAssembly(typeof (EditorCamera)).Location, Assembly.GetAssembly(typeof (SA1LevelAct)).Location,
                                                Assembly.GetAssembly(typeof (ObjectDefinition)).Location
                                            })
                                            {
                                                GenerateExecutable = false,
                                                GenerateInMemory = false,
                                                IncludeDebugInformation = true,
                                                OutputAssembly = Path.Combine(Environment.CurrentDirectory, dllfile)
                                            };
                                        CompilerResults res = pr.CompileAssemblyFromFile(para, fp);
                                        if (res.Errors.HasErrors)
                                        {
                                            // TODO: Merge with existing object error handler. I add too many ToDos.
                                            string errors = null;
                                            foreach (CompilerError item in res.Errors)
                                                errors += String.Format("\n\n{0}, {1}: {2}", item.Line, item.Column, item.ErrorText);

                                            MessageBox.Show("Failed to compile object code file:\n" + defgroup.CodeFile + errors,
                                                "Object compilation failure", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                            def = new DefaultObjectDefinition();
                                        }
                                        else
                                        {
                                            def = (ObjectDefinition)Activator.CreateInstance(res.CompiledAssembly.GetType(ty));
                                        }
                                    }
                                    else
                                        def = new DefaultObjectDefinition();
                                }

                                #endregion
                            }
                            else
                            {
                                def = new DefaultObjectDefinition();
                            }

                            LevelData.ObjDefs.Add(def);

                            // The only reason .Model is checked for null is for objects that don't yet have any
                            // models defined for them. It would be annoying seeing that error all the time!
                            if (string.IsNullOrEmpty(defgroup.CodeFile) && !string.IsNullOrEmpty(defgroup.Model))
                            {
                                progress.SetStep("Loading: " + defgroup.Model);
                                // Otherwise, if the model file doesn't exist and/or no texture file is defined,
                                // load the "default object" instead ("?").
                                if (!File.Exists(defgroup.Model) || string.IsNullOrEmpty(defgroup.Texture) ||
                                    !LevelData.Textures.ContainsKey(defgroup.Texture))
                                {
                                    ObjectData error = new ObjectData { Name = defgroup.Name, Model = defgroup.Model, Texture = defgroup.Texture };
                                    objectErrors.Add(error);
                                    defgroup.Model = null;
                                }
                            }

                            def.Init(defgroup, objlstini[ID].Name, d3ddevice);
                            def.SetInternalName(objlstini[ID].Name);
                        }

                        // Loading SET Layout
                        progress.SetTaskAndStep("Loading SET items", "Initializing...");

                        if (LevelData.ObjDefs.Count > 0)
                        {
                            LevelData.SETName = level.SETName ?? level.LevelID;
                            string setstr = Path.Combine(syspath, "SET" + LevelData.SETName + "{0}.bin");
                            LevelData.SETItems = new List<SETItem>[LevelData.SETChars.Length];
                            for (int i = 0; i < LevelData.SETChars.Length; i++)
                            {
                                List<SETItem> list = new List<SETItem>();
                                byte[] setfile = null;

                                string formatted = string.Format(setstr, LevelData.SETChars[i]);

                                if (modpath != null && File.Exists(Path.Combine(modpath, formatted)))
                                    setfile = File.ReadAllBytes(Path.Combine(modpath, formatted));
                                else if (File.Exists(formatted))
                                    setfile = File.ReadAllBytes(formatted);

                                if (setfile != null)
                                {
                                    progress.SetTask("SET: " + formatted.Replace(Environment.CurrentDirectory, ""));

                                    int count = BitConverter.ToInt32(setfile, 0);
                                    int address = 0x20;
                                    for (int j = 0; j < count; j++)
                                    {
                                        progress.SetStep(string.Format("{0}/{1}", (j + 1), count));

                                        SETItem ent = new SETItem(setfile, address, selectedItems);
                                        list.Add(ent);
                                        address += 0x20;
                                    }
                                }
                                LevelData.SETItems[i] = list;
                            }
                        }
                        else
                        {
                            LevelData.SETItems = null;
                        }

                        // Checks if there have been any errors added to the error list and does its thing
                        // This thing is a mess. If anyone can think of a cleaner way to do this, be my guest.
                        if (objectErrors.Count > 0)
                        {
                            int count = objectErrors.Count;
                            List<string> errorStrings = new List<string> { "The following objects failed to load:" };

                            foreach (ObjectData o in objectErrors)
                            {
                                bool texEmpty = string.IsNullOrEmpty(o.Texture);
                                bool texExists = (!string.IsNullOrEmpty(o.Texture) && LevelData.Textures.ContainsKey(o.Texture));
                                errorStrings.Add("");
                                errorStrings.Add("Object:\t\t" + o.Name);
                                errorStrings.Add("\tModel:");
                                errorStrings.Add("\t\tName:\t" + o.Model);
                                errorStrings.Add("\t\tExists:\t" + File.Exists(o.Model));
                                errorStrings.Add("\tTexture:");
                                errorStrings.Add("\t\tName:\t" + ((texEmpty) ? "(N/A)" : o.Texture));
                                errorStrings.Add("\t\tExists:\t" + texExists);
                            }

                            // TODO: Proper logging. Who knows where this file may end up
                            File.WriteAllLines("SADXLVL2.log", errorStrings.ToArray());

                            MessageBox.Show(count + ((count == 1) ? " object" : " objects") + " failed to load their model(s).\n"
                                            +
                                            "\nThe level will still display, but the objects in question will not display their proper models." +
                                            "\n\nPlease check the log for details.",
                                "Error loading models", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        LevelData.SETItems = null;
                    }

                    progress.StepProgress();

                    #endregion

                    #region CAM Layout

                    progress.SetTaskAndStep("Loading CAM items", "Initializing...");

                    string camstr = Path.Combine(syspath, "CAM" + LevelData.SETName + "{0}.bin");

                    LevelData.CAMItems = new List<CAMItem>[LevelData.SETChars.Length];
                    for (int i = 0; i < LevelData.SETChars.Length; i++)
                    {
                        List<CAMItem> list = new List<CAMItem>();
                        byte[] camfile = null;

                        string formatted = string.Format(camstr, LevelData.SETChars[i]);

                        if (modpath != null && File.Exists(Path.Combine(modpath, formatted)))
                            camfile = File.ReadAllBytes(Path.Combine(modpath, formatted));
                        else if (File.Exists(formatted))
                            camfile = File.ReadAllBytes(formatted);

                        if (camfile != null)
                        {
                            progress.SetTask("CAM: " + formatted.Replace(Environment.CurrentDirectory, ""));

                            int count = BitConverter.ToInt32(camfile, 0);
                            int address = 0x40;
                            for (int j = 0; j < count; j++)
                            {
                                progress.SetStep(string.Format("{0}/{1}", (j + 1), count));

                                CAMItem ent = new CAMItem(camfile, address, selectedItems);
                                list.Add(ent);
                                address += 0x40;
                            }
                        }

                        LevelData.CAMItems[i] = list;
                    }

                    CAMItem.Init(d3ddevice);

                    progress.StepProgress();

                    #endregion

                    #region Loading Level Effects

                    LevelData.leveleff = null;
                    if (!string.IsNullOrEmpty(level.Effects))
                    {
                        progress.SetTaskAndStep("Loading Level Effects...");

                        LevelDefinition def = null;
                        string ty = "SADXObjectDefinitions.Level_Effects." + Path.GetFileNameWithoutExtension(level.Effects);
                        string dllfile = Path.Combine("dllcache", ty + ".dll");
                        DateTime modDate = DateTime.MinValue;

                        if (File.Exists(dllfile))
                            modDate = File.GetLastWriteTime(dllfile);

                        string fp = level.Effects.Replace('/', Path.DirectorySeparatorChar);
                        if (modDate >= File.GetLastWriteTime(fp) && modDate > File.GetLastWriteTime(Application.ExecutablePath))
                        {
                            def =
                                (LevelDefinition)
                                    Activator.CreateInstance(
                                        Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory, dllfile)).GetType(ty));
                        }
                        else
                        {
                            string ext = Path.GetExtension(fp);
                            CodeDomProvider pr = null;
                            switch (ext.ToLowerInvariant())
                            {
                                case ".cs":
                                    pr = new Microsoft.CSharp.CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
                                    break;
                                case ".vb":
                                    pr = new Microsoft.VisualBasic.VBCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
                                    break;
                            }
                            if (pr != null)
                            {
                                CompilerParameters para =
                                    new CompilerParameters(new string[]
                                {
                                    "System.dll", "System.Core.dll", "System.Drawing.dll", Assembly.GetAssembly(typeof (Vector3)).Location,
                                    Assembly.GetAssembly(typeof (Texture)).Location, Assembly.GetAssembly(typeof (D3DX)).Location,
                                    Assembly.GetExecutingAssembly().Location, Assembly.GetAssembly(typeof (LandTable)).Location,
                                    Assembly.GetAssembly(typeof (EditorCamera)).Location, Assembly.GetAssembly(typeof (SA1LevelAct)).Location,
                                    Assembly.GetAssembly(typeof (Item)).Location
                                })
                                    {
                                        GenerateExecutable = false,
                                        GenerateInMemory = false,
                                        IncludeDebugInformation = true,
                                        OutputAssembly = Path.Combine(Environment.CurrentDirectory, dllfile)
                                    };
                                CompilerResults res = pr.CompileAssemblyFromFile(para, fp);
                                if (!res.Errors.HasErrors)
                                    def = (LevelDefinition)Activator.CreateInstance(res.CompiledAssembly.GetType(ty));
                            }
                        }

                        if (def != null)
                            def.Init(level, levelact.Act, d3ddevice);

                        LevelData.leveleff = def;
                    }

                    progress.StepProgress();

                    #endregion

                    #region Loading Splines

                    LevelData.LevelSplines = new List<SplineData>();
                    SplineData.Init();

                    if (!string.IsNullOrEmpty(ini.Paths))
                    {
                        progress.SetTaskAndStep("Reticulating splines...");

                        String splineDirectory = Path.Combine(Path.Combine(Environment.CurrentDirectory, ini.Paths),
                            levelact.ToString());

                        if (Directory.Exists(splineDirectory))
                        {
                            List<string> pathFiles = new List<string>();

                            for (int i = 0; i < int.MaxValue; i++)
                            {
                                string path = string.Concat(splineDirectory, string.Format("/{0}.ini", i));
                                if (File.Exists(path))
                                {
                                    pathFiles.Add(path);
                                }
                                else
                                    break;
                            }

                            foreach (string pathFile in pathFiles) // looping through path files
                            {
                                SplineData newSpline = new SplineData(PathData.Load(pathFile), selectedItems);

                                newSpline.RebuildMesh(d3ddevice);

                                LevelData.LevelSplines.Add(newSpline);
                            }
                        }
                    }

                    progress.StepProgress();

                    #endregion

                    #region Stage Lights
                    progress.SetTaskAndStep("Loading lights...");

                    if ((stageLightList != null) && (stageLightList.Count > 0))
                    {
                        List<SA1StageLightData> lightList = new List<SA1StageLightData>();

                        foreach (SA1StageLightData lightData in stageLightList)
                        {
                            if ((lightData.Level == levelact.Level) && (lightData.Act == levelact.Act))
                                lightList.Add(lightData);
                        }

                        if (lightList.Count > 0)
                        {
                            for (int i = 0; i < d3ddevice.Lights.Count; i++) // clear all default lights
                            {
                                d3ddevice.Lights[i].Enabled = false;
                            }

                            for (int i = 0; i < lightList.Count; i++)
                            {
                                SA1StageLightData lightData = lightList[i];

                                d3ddevice.Lights[i].Enabled = true;
                                d3ddevice.Lights[i].Type = (lightData.UseDirection) ? LightType.Directional : LightType.Point;
                                d3ddevice.Lights[i].Diffuse = lightData.RGB.ToColor();
                                d3ddevice.Lights[i].DiffuseColor = new ColorValue(lightData.RGB.X, lightData.RGB.Y, lightData.RGB.Z, 1.0f);
                                d3ddevice.Lights[i].Ambient = lightData.AmbientRGB.ToColor();
                                d3ddevice.Lights[i].Specular = Color.Black;
                                d3ddevice.Lights[i].Direction = lightData.Direction.ToVector3();
                                d3ddevice.Lights[i].Range = lightData.Dif; // guessing here
                            }
                        }
                        else
                        {
                            MessageBox.Show("No lights were found for this stage. Using default lights instead.", "No lights found",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }

                    progress.StepProgress();
                    #endregion

                    transformGizmo = new TransformGizmo();

                    Invoke((Action)progress.Close);
                }
            #if !DEBUG
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    ex.GetType().Name + ": " + ex.Message + "\nLog file has been saved to " + Path.Combine(Environment.CurrentDirectory, "SADXLVL2.log") + ".\nSend this to MainMemory on the Sonic Retro forums.",
                    "SADXLVL2 Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                File.WriteAllText("SADXLVL2.log", ex.ToString());
                initerror = true;
            }
            #endif
        }
Пример #26
0
 public abstract HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform);
Пример #27
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     for (int i = 0; i < Math.Min(item.Scale.X + 1, 8); i++)
     {
         transform.Push();
         if (item.Scale.Z == 1) // circle
         {
             double v4 = i * 360.0;
             Vector3 v7 = new Vector3(
                 ObjectHelper.ConvertBAMS((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y,
                 0,
                 ObjectHelper.ConvertBAMSInv((int)(v4 / item.Scale.X * 65536.0 * 0.002777777777777778)) * item.Scale.Y);
             transform.Push();
             transform.NJTranslate(item.Position);
             transform.NJRotateObject(item.Rotation);
             Vector3 pos = Vector3.TransformCoordinate(v7, transform.Top);
             transform.Pop();
             transform.NJTranslate(pos);
             result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
             if (item.Selected)
                 result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
         }
         else // line
         {
             transform.Push();
             transform.NJTranslate(item.Position);
             transform.NJRotateObject(item.Rotation);
             double v5;
             if (i % 2 == 1)
                 v5 = i * item.Scale.Y * -0.5;
             else
                 v5 = Math.Ceiling(i * 0.5) * item.Scale.Y;
             Vector3 pos = Vector3.TransformCoordinate(new Vector3(0, 0, (float)v5), transform.Top);
             transform.Pop();
             transform.NJTranslate(pos);
             result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
             if (item.Selected)
                 result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
         }
         transform.Pop();
     }
     return result;
 }
Пример #28
0
        public override BoundingSphere GetBounds(SETItem item, NJS_OBJECT model)
        {
            BoundingSphere bounds = new BoundingSphere(item.Position, item.Scale.X);

            return bounds;
        }
Пример #29
0
 public object GetValue(SETItem item)
 {
     return getMethod(item);
 }
Пример #30
0
 public void SetValue(SETItem item, object value)
 {
     setMethod(item, value);
 }
Пример #31
0
 public abstract List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform);
Пример #32
0
 public static void RemoveSETItem(int characterID, SETItem item)
 {
     setItems[characterID].Remove(item);
     changes.Push("Remove SET Item");
     InvalidateRenderState();
 }