public async Task <ForgelightActor> CreateActor(string name, Transform parent)
        {
            ForgelightActor actorSource;

            if (!cachedActors.TryGetValue(name, out actorSource))
            {
                Adr actorDefinition = actorDefinitionManager.GetDefinition(name);

                if (actorDefinition != null)
                {
                    actorSource = await LoadNewActor(actorDefinition);
                }
                else
                {
                    actorSource = CreateMissingPlaceholder(name);
                }

                actorSource.name = name;
                actorSource.Init(actorDefinition);
                actorSource.transform.SetParent(actorPoolParent.transform);

                cachedActors[name] = actorSource;
            }

            ForgelightActor actorInstance = Object.Instantiate(actorSource, parent);

            return(actorInstance);
        }
        public void LoadZoneObjects(ForgelightGame forgelightGame, string zoneName, List <Object> objects, float progressMin, float progressMax)
        {
            Parent.name += " - " + zoneName;

            //Begin processing the file
            for (int i = 0; i < objects.Count; i++)
            {
                Object zoneObject = objects[i];

                if (zoneObject.Instances.Count > 0)
                {
                    Adr actorDef = forgelightGame.GetActorDefinition(zoneObject.ActorDefinition);

                    if (actorDef == null)
                    {
                        Debug.LogWarning("Could not find Actor Definition: " + zoneObject.ActorDefinition + "!");
                        continue;
                    }

                    foreach (Object.Instance instance in zoneObject.Instances)
                    {
                        TransformData correctedTransform = MathUtils.ConvertTransform(instance.Position, instance.Rotation, instance.Scale, true, TransformMode.Standard);

                        CreateForgelightObject(forgelightGame, actorDef, correctedTransform.Position, Quaternion.Euler(correctedTransform.Rotation), correctedTransform.Scale, zoneObject.RenderDistance, instance.LODMultiplier, instance.DontCastShadows, instance.ID);
                    }
                }

                EditorUtility.DisplayProgressBar("Loading Zone: " + zoneName, "Loading Objects: " + zoneObject.ActorDefinition, MathUtils.Remap01((float)i / objects.Count, progressMin, progressMax));
            }
        }
Example #3
0
 public ProgramState(Adr pc, IEnumerable <Mem> program) :
     this(pc, 0,
          program.Aggregate(
              ImmutableSortedDictionary <Adr, Mem> .Empty,
              (accu, current) => accu.Add(accu.Count(), current)),
          ImmutableQueue <Mem> .Empty, ImmutableStack <Mem> .Empty, false)
 {
 }
        private GameObject InitializeActor(ForgelightGame forgelightGame, Adr actorDef)
        {
            GameObject basePrefab = GetForgelightObject(forgelightGame, actorDef.Base);
            GameObject baseModel  = InstantiateModel(basePrefab);

            if (baseModel == null)
            {
                return(null);
            }

            //LODs
            //TODO Unity has a hard limit for LODs. Re-enable when fixed.
            //LODGroup lodGroup = baseModel.AddComponent<LODGroup>();

            ////This adds the base model, and the "culled" LOD.
            //int levelsOfDetail = actorDef.Lods.Count + 2;
            //float max = Mathf.Pow(levelsOfDetail, cullPower);

            //List<LOD> unityLods = new List<LOD>(levelsOfDetail);

            //LOD lod0 = new LOD();
            //lod0.renderers = baseModel.GetComponentsInChildren<Renderer>();
            //lod0.screenRelativeTransitionHeight = Mathf.Pow(levelsOfDetail - 1, cullPower).Remap(0, max, 0, 1.0f);

            //unityLods.Add(lod0);

            //for (int i = 0; i < actorDef.Lods.Count; i++)
            //{
            //    Lod lod = actorDef.Lods[i];
            //    GameObject lodPrefab = GetForgelightObject(forgelightGame, lod.FileName);
            //    GameObject lodModel = InstantiateModel(lodPrefab);

            //    if (lodModel == null)
            //    {
            //        continue;
            //    }

            //    lodModel.transform.SetParent(baseModel.transform);

            //    float cullDist = Mathf.Pow(levelsOfDetail - i - 2, cullPower).Remap(0, max, 0, 1.0f);

            //    unityLods.Add(new LOD(cullDist, lodModel.GetComponentsInChildren<Renderer>()));
            //}

            //lodGroup.SetLODs(unityLods.ToArray());

            int layer = LayerMask.NameToLayer("ForgelightZoneObject");

            baseModel.layer = layer;

            foreach (Transform child in baseModel.transform)
            {
                child.gameObject.layer = layer;
            }

            return(baseModel);
        }
        public GameObject CreateForgelightObject(ForgelightGame forgelightGame, Adr actorDefinition, Vector3 position, Quaternion rotation, Vector3 scale, float renderDistance, float lodMultiplier, bool dontCastShadows, uint id)
        {
            GameObject instance = InitializeActor(forgelightGame, actorDefinition);

            if (instance != null)
            {
                InitializeInstance(instance, position, rotation, scale, actorDefinition, renderDistance, lodMultiplier, dontCastShadows, id);
            }

            return(instance);
        }
 private void vider()
 {
     Nom1.Clear();
     Prenom1.Clear();
     Adr.Clear();
     Email.Clear();
     tel.Clear();
     date.Text      = null;
     comboSexe.Text = null;
     comboSG.Text   = null;
 }
Example #7
0
 private ProgramState(Adr ip, Adr relativeBase,
                      ImmutableSortedDictionary <Adr, Mem> program,
                      ImmutableQueue <Mem> input, ImmutableStack <Mem> output,
                      bool stopped)
 {
     this.IP           = ip;
     this.RelativeBase = relativeBase;
     this.Program      = program;
     this.Input        = input;
     this.Output       = output;
     this.Stopped      = stopped;
 }
        public void UpdateActors(float progress0, float progress100)
        {
            ProgressBar(progress0, "Updating Actors List...");

            List <AssetRef> actors = AssetsByType[AssetRef.Types.ADR];

            AvailableActors = new List <Asset>(actors.Count);

            int    assetsProcessed    = 0;
            string lastAssetProcessed = "";
            object listLock           = new object();

            Parallel.AsyncForEach <AssetRef> parallelTask = System.Threading.Tasks.Parallel.ForEach;

            IAsyncResult result = parallelTask.BeginInvoke(actors, asset =>
            {
                Interlocked.Increment(ref assetsProcessed);

                if (asset == null)
                {
                    return;
                }

                //Names
                string assetName        = asset.Name;
                string assetDisplayName = BuildAssetName(assetName, asset.Pack.Name);

                //De-serialize
                using (MemoryStream memoryStream = asset.Pack.CreateAssetMemoryStreamByName(assetName))
                {
                    Adr adr = Adr.LoadFromStream(assetName, assetDisplayName, memoryStream);

                    if (adr == null)
                    {
                        return;
                    }

                    lock (listLock)
                    {
                        AvailableActors.Add(adr);
                        lastAssetProcessed = assetName;
                    }
                }
            }, null, null);

            while (!result.IsCompleted)
            {
                ProgressBar(MathUtils.Remap01(assetsProcessed / (float)actors.Count, progress0, progress100), "Updating Actors List: " + lastAssetProcessed);
            }

            parallelTask.EndInvoke(result);
            AvailableActors.Sort();
        }
        /// <summary>
        /// Creates the DragAndDrop object's references, and begins the drag operation.
        /// </summary>
        /// <param name="forgelightGame">The forgelight game containing "actor"</param>
        /// <param name="actor">The selected actor</param>
        private void BeginDrag(ForgelightGame forgelightGame, Adr actor)
        {
            ActorDefinition actorDefinition = new ActorDefinition
            {
                forgelightGame  = forgelightGame,
                actorDefinition = actor
            };

            DragAndDrop.objectReferences = new Object[0];
            DragAndDrop.PrepareStartDrag();
            DragAndDrop.SetGenericData("ActorDefinition", actorDefinition);
            DragAndDrop.StartDrag("ActorDrag");

            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
        }
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Fn?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (Email?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Url?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Org?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Adr?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Tel?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (XTwitter?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (XGithub?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Photo?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (VCard?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
 /// <summary>
 /// Serves as a hash function for a particular type.
 /// </summary>
 /// <returns>
 /// A hash code for the current <see cref="T:System.Object"/>.
 /// </returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Fn != null ? Fn.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Email != null ? Email.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Url != null ? Url.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Org != null ? Org.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Adr != null ? Adr.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Tel != null ? Tel.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (XTwitter != null ? XTwitter.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (XGithub != null ? XGithub.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Photo != null ? Photo.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (VCard != null ? VCard.GetHashCode() : 0);
         return(hashCode);
     }
 }
        public async Task LoadSystem(StatusReporter reporter)
        {
            await new WaitForBackgroundThread();
            actorDefinitions.Clear();

            AssetRef[] actorDefs = assetManager.GetAssetsByType(AssetType.ADR);

            for (int i = 0; i < actorDefs.Length; i++)
            {
                AssetRef assetRef = actorDefs[i];
                Adr      adr      = assetManager.CreateAsset <Adr>(assetRef);
                if (adr != null)
                {
                    actorDefinitions.Add(adr.Name, adr);
                }

                reporter.ReportProgress("Loading Actor Definitions", i, actorDefs.Length);
            }
        }
Example #13
0
        public void Indicators_Adr_equals_to_one()
        {
            List <Bar> bars = new List <Bar>();

            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 130, 135, 129, 133, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 131, 136, 130, 134, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 132, 137, 131, 135, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 133, 138, 132, 136, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 134, 139, 133, 137, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 133, 131, 128, 130, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 132, 132, 127, 129, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 131, 130, 126, 128, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 130, 129, 125, 127, 10));
            bars.Add(new Bar("RTS-9.13_FT", 60, BrokerDateTime.Make(DateTime.Now), 129, 128, 124, 126, 10));

            double adrValue = Adr.Make(bars, 10);

            Assert.AreEqual(1, adrValue);
        }
        /// <summary>
        /// Retrieves the available actors from the game factory, creating a list of actors, and checks if they have been clicked this frame.
        /// Triggers the "BeginDrag" operation on a double click.
        /// </summary>
        private void DrawAvailableActors()
        {
            scrollTop = GUILayout.BeginScrollView(scrollTop, GUILayout.Height(splitterPos), GUILayout.MaxHeight(splitterPos), GUILayout.MinHeight(splitterPos));
            ForgelightGame forgelightGame = ForgelightExtension.Instance.ForgelightGameFactory.ActiveForgelightGame;

            if (forgelightGame != null)
            {
                List <Asset> availableActors = forgelightGame.AvailableActors;

                foreach (Asset asset in availableActors)
                {
                    if (searchString != null && !asset.DisplayName.ToLower().Contains(searchString.ToLower()))
                    {
                        continue;
                    }

                    Adr actor = (Adr)asset;

                    Rect rect = GUILayoutUtility.GetRect(40f, 40f, 16f, 16f, EditorStyles.label);

                    if (Event.current.type == EventType.MouseDown)
                    {
                        if (rect.Contains(Event.current.mousePosition))
                        {
                            BeginDrag(forgelightGame, actor);
                            DestroyImmediate(previewWindowEditor);
                            selectedActor = ForgelightExtension.Instance.ZoneManager.ZoneObjectFactory.GetForgelightObject(forgelightGame, actor.Base);
                        }
                    }

                    GUIStyle style = EditorStyles.label;
                    style.fixedWidth   = 0;
                    style.stretchWidth = true;
                    style.clipping     = TextClipping.Overflow;

                    EditorGUI.Foldout(rect, false, asset.DisplayName, true, style);
                }
            }

            GUILayout.EndScrollView();
        }
        /// <summary>
        /// Attempts to find a compatible DME associated with the actor definition.
        /// </summary>
        private Dme GetActorDme(Adr actorDefinition)
        {
            Dme modelDef = assetManager.LoadPackAsset <Dme>(actorDefinition.Base);

            if (modelDef != null)
            {
                return(modelDef);
            }

            Debug.LogWarningFormat("Could not use base model for actor \"{0}\". Attempting to use LOD model instead.", actorDefinition.DisplayName);
            foreach (Lod lod in actorDefinition.Lods)
            {
                modelDef = assetManager.LoadPackAsset <Dme>(lod.FileName);
                if (modelDef != null)
                {
                    break;
                }
            }

            return(modelDef);
        }
Example #16
0
 public ProgramState WithIP(Adr ip)
 => new ProgramState(ip, this.RelativeBase, this.Program, this.Input,
                     this.Output, this.Stopped);
        private async Task <ForgelightActor> LoadNewActor(Adr actorDefinition)
        {
            await new WaitForBackgroundThread();

            ForgelightActor actor;

            // Attempt to find the model's Dme.
            Dme modelDef = GetActorDme(actorDefinition);

            if (modelDef == null)
            {
                actor = CreateMissingPlaceholder(actorDefinition.Name);
            }
            else
            {
                // Deserialization
                MeshData meshData;
                try
                {
                    meshData = actorMeshFactory.GenerateMeshData(modelDef);
                }
                catch (Exception e)
                {
                    Debug.LogError($"Could not create mesh {modelDef.Name}. {e}");

                    await new WaitForUpdate();

                    return(CreateMissingPlaceholder(actorDefinition.Name));
                }

                await new WaitForUpdate();

                UnityEngine.Mesh mesh      = actorMeshFactory.CreateMeshFromData(modelDef.Name, meshData);
                Material[]       materials = materialFactory.GetActorMaterials(modelDef);

                assetManager.Dispose(modelDef);

                Assert.IsNotNull(mesh);
                Assert.IsNotNull(materials);

                // GameObject "Prefab"
                GameObject actorSource = new GameObject();
                actor = actorSource.AddComponent <ForgelightActor>();

                MeshFilter   meshFilter   = actorSource.AddComponent <MeshFilter>();
                MeshRenderer meshRenderer = actorSource.AddComponent <MeshRenderer>();

                // Assign deserialized data
                meshFilter.sharedMesh        = mesh;
                meshRenderer.sharedMaterials = materials;

                // LODs
                if (actorDefinition.Lods.Count > 0)
                {
                    float cullDist = actorDefinition.Lods.Max(lod => lod.Distance);

                    LODGroup lodGroup = actorSource.AddComponent <LODGroup>();
                    LOD      lod0     = new LOD(1.0f, new Renderer[] { meshRenderer });
                    lodGroup.SetLODs(new [] { lod0 });

                    lod0.screenRelativeTransitionHeight = LODGroupExtensions.DistanceToRelativeHeight(cameraManager.UnityCamera, cullDist, lodGroup.GetWorldSpaceSize());

                    lodGroup.SetLODs(new [] { lod0 });
                }
            }

            return(actor);
        }
Example #18
0
 public Mem Read(Adr adr)
 => this.Program.TryGetValue(adr, out var value) ? value : 0L;
Example #19
0
 public ProgramState Write(Adr adr, Mem value)
 => this.WithProgram(this.Program.SetItem(adr, value));
        public GameObject CreateForgelightObject(ForgelightGame forgelightGame, Adr actorDefinition, Vector3 position, Quaternion rotation)
        {
            uint randID = GenerateUID();

            return(CreateForgelightObject(forgelightGame, actorDefinition, position, rotation, Vector3.one, 1000, 1.0f, false, randID));
        }
Example #21
0
 public ProgramState WithIncrementIP(Adr step = 4)
 => new ProgramState(this.IP + step, this.RelativeBase,
                     this.Program, this.Input, this.Output, this.Stopped);
        private void InitializeInstance(GameObject instance, Vector3 position, Quaternion rotation, Vector3 scale, Adr actorDef, float renderDistance, float lodBias, bool dontCastShadows, long id)
        {
            //Set our position, scale and rotation values to the ones defined in the zone file.
            instance.transform.position   = position;
            instance.transform.rotation   = rotation;
            instance.transform.localScale = scale;

            //We attach ourselves to a common parent to improve undo performance.
            if (!actorParents.ContainsKey(actorDef.Name))
            {
                GameObject actorParent = new GameObject(actorDef.Name);
                actorParent.transform.SetParent(Parent, false);

                actorParents[actorDef.Name] = actorParent.transform;
            }

            //Attach ourselves to the master object parent.
            instance.transform.parent = actorParents[actorDef.Name];

            //Attach our ZoneObject script, and update its variables
            ZoneObject zoneObject = instance.GetComponent <ZoneObject>();

            if (zoneObject == null)
            {
                zoneObject = instance.AddComponent <ZoneObject>();
            }

            zoneObject.actorDefinition = actorDef.Name;
            zoneObject.renderDistance  = renderDistance;
            zoneObject.lodMultiplier   = lodBias;
            zoneObject.DontCastShadows = dontCastShadows;
            zoneObject.ID = id;

            //Apply any changes we may have made.
            zoneObject.OnValidate();

            //instance.isStatic = true;

            //Add the ID to our used list.
            usedIDs.Add(id);
        }
Example #23
0
 public ProgramState WithAdjust(Adr value)
 => new ProgramState(this.IP, this.RelativeBase + value,
                     this.Program, this.Input, this.Output, this.Stopped);
 public void Init(Adr actorDef)
 {
     this.ActorDefinition = actorDef;
 }