Exemple #1
0
 public void UpdatePS1Stream()
 {
     if (controller.playAnimations && playAnimation && currentCinematic > 0 && ps1Streams != null)
     {
         updateCounter += Time.deltaTime * animationSpeed;
         // If the camera is not inside a sector, animations will only update 1 out of 2 times (w/ frameskip) to avoid lag
         if (updateCounter >= 1f)
         {
             uint passedFrames = (uint)Mathf.FloorToInt(updateCounter);
             updateCounter %= 1;
             currentFrame  += passedFrames;
             OpenSpace.PS1.PS1Stream s = ps1Streams[currentCinematic - 1];
             if (s != null && currentFrame >= s.num_frames)
             {
                 currentFrame = (uint)(currentFrame % s.num_frames);
                 UpdatePS1StreamFrame();
             }
             else
             {
                 UpdatePS1StreamFrame();
             }
         }
     }
 }
Exemple #2
0
    public void UpdatePS1StreamFrame()
    {
        ClearCurrentNTTO();
        if (Camera.main.orthographic)
        {
            CinematicIndex = 0;
            return;
        }
        if (ps1Streams != null && currentCinematic > 0)
        {
            OpenSpace.PS1.PS1Stream      s = ps1Streams[currentCinematic - 1];
            OpenSpace.PS1.PS1StreamFrame f = s.frames.FirstOrDefault(fr => fr.num_frame == currentFrame);
            if (f != null)
            {
                Dictionary <int, int> nttoForFrame = new Dictionary <int, int>();
                R2PS1Loader           l            = MapLoader.Loader as R2PS1Loader;
                Camera cam = Camera.main;
                for (int i = 0; i < f.channels.Length; i++)
                {
                    OpenSpace.PS1.PS1StreamFrameChannel c = f.channels[i];
                    if (c.HasFlag(OpenSpace.PS1.PS1StreamFrameChannel.StreamFlags.Camera))
                    {
                        cam.transform.position = c.GetPosition();
                        cam.transform.rotation = c.quaternion * Quaternion.Euler(0, 180, 0);
                    }
                    else
                    {
                        GameObject gao  = null;
                        int        ntto = c.NTTO;
                        if (ntto >= 0)
                        {
                            if (!nttoForFrame.ContainsKey(ntto))
                            {
                                nttoForFrame[ntto] = 0;
                            }
                            if (objectPool.ContainsKey(ntto))
                            {
                                gao = objectPool[ntto][nttoForFrame[ntto]];
                            }
                            if (gao != null)
                            {
                                gao.SetActive(true);
                                currentNTTO.Add(gao);
                                nttoForFrame[ntto]++;
                            }
                        }

                        /*if (c.NTTO > 0) {
                         *      gao = l.levelHeader.geometricObjectsDynamic.GetGameObject(c.NTTO);
                         *      if (gao == null) gao = new GameObject("Empty 2");
                         * } else {
                         *      gao = new GameObject("Empty");
                         * }*/

                        /*if (c.HasFlag(PS1StreamFrameChannel.StreamFlags.Parent)) {
                         *      Debug.Log(string.Format("{0:X4}", c.flags));
                         * }*/
                        if (gao != null)
                        {
                            Vector3 scale = new Vector3(1f, 1f, 1f);
                            gao.transform.localPosition = cam.transform.localPosition + c.GetPosition();
                            gao.transform.localRotation = c.quaternion;
                            if (c.HasFlag(OpenSpace.PS1.PS1StreamFrameChannel.StreamFlags.Scale))
                            {
                                scale = c.GetScale(0x1000);
                                //gao.name = string.Format("{0:X4}", c.sx) + string.Format("{0:X4}", c.sy) + string.Format("{0:X4}", c.sz) + " - " + gao.name;
                            }
                            if (c.HasFlag(OpenSpace.PS1.PS1StreamFrameChannel.StreamFlags.FlipX))
                            {
                                gao.transform.localScale = new Vector3(-scale.x, scale.y, scale.z);
                            }
                            else
                            {
                                gao.transform.localScale = scale;
                            }
                            //gao.transform.localScale = c.GetScale();
                            currentNTTO.Add(gao);
                        }
                    }
                }
            }
        }
    }
Exemple #3
0
    public void InitPS1Stream()
    {
        DeinitPS1Stream();
        currentFrame = 0;
        if (currentCinematic > 0 && ps1Streams != null)
        {
            Camera cam = Camera.main;
            if (cam.orthographic)
            {
                controller.SetCameraPosition(WebJSON.CameraPos.Initial);
            }
            OpenSpace.PS1.PS1Stream s = ps1Streams[currentCinematic - 1];
            R2PS1Loader             l = MapLoader.Loader as R2PS1Loader;
            l.gao_dynamicWorld.SetActive(false);
            foreach (PS1StreamFrame f in s.frames)
            {
                Dictionary <int, int> nttoForFrame = new Dictionary <int, int>();
                for (int i = 0; i < f.num_channels; i++)
                {
                    PS1StreamFrameChannel c = f.channels[i];
                    int ntto = c.NTTO;

                    /*if (c.HasFlag(PS1StreamFrameChannel.StreamFlags.Parent)) {
                     *      Debug.Log(string.Format("{0:X4}", c.flags));
                     * }*/
                    if (ntto >= 0)
                    {
                        /*if (nttoPerChannel[i] == null) nttoPerChannel[i] = new Dictionary<int, GameObject>();
                         *
                         * if (!nttoPerChannel[i].ContainsKey(ntto)) {
                         *      GameObject gao = l.levelHeader.geometricObjectsDynamic.GetGameObject(ntto);
                         *      if (gao == null) gao = new GameObject("Empty 2");
                         *      gao.name = string.Format("{0:X4}", c.flags) + " - " + gao.name;
                         *      gao.transform.SetParent(transform);
                         *      gao.SetActive(false);
                         * }*/
                        if (!nttoForFrame.ContainsKey(ntto))
                        {
                            nttoForFrame[ntto] = 0;
                        }
                        nttoForFrame[ntto]++;
                        if (!objectPool.ContainsKey(ntto) || objectPool[ntto].Count < nttoForFrame[ntto])
                        {
                            GameObject gao = l.levelHeader.geometricObjectsDynamic.GetGameObject(ntto, null, out _);
                            //if (gao == null) gao = new GameObject("Empty 2");
                            if (gao != null)
                            {
                                gao.name = string.Format("{0:X4}", c.flags) + " - " + gao.name;
                                gao.transform.SetParent(transform);
                                gao.SetActive(false);
                                allNTTO.Add(gao);
                                if (!objectPool.ContainsKey(ntto))
                                {
                                    objectPool[ntto] = new List <GameObject>();
                                }
                                objectPool[ntto].Add(gao);
                            }
                        }
                    }
                }
            }
        }
    }