Beispiel #1
0
 internal PromisePrototype(
     Engine engine,
     Realm realm,
     PromiseConstructor constructor,
     ObjectPrototype objectPrototype) : base(engine, realm)
 {
     _prototype   = objectPrototype;
     _constructor = constructor;
 }
Beispiel #2
0
 internal SetPrototype(
     Engine engine,
     Realm realm,
     SetConstructor setConstructor,
     ObjectPrototype objectPrototype) : base(engine, realm)
 {
     _prototype   = objectPrototype;
     _constructor = setConstructor;
 }
Beispiel #3
0
 internal MapPrototype(
     Engine engine,
     Realm realm,
     MapConstructor mapConstructor,
     ObjectPrototype objectPrototype) : base(engine, realm)
 {
     _prototype      = objectPrototype;
     _mapConstructor = mapConstructor;
 }
Beispiel #4
0
 internal FunctionPrototype(
     Engine engine,
     Realm realm,
     ObjectPrototype objectPrototype)
     : base(engine, realm, JsString.Empty)
 {
     _prototype = objectPrototype;
     _length    = new PropertyDescriptor(JsNumber.PositiveZero, PropertyFlag.Configurable);
 }
Beispiel #5
0
 internal JsonInstance(
     Engine engine,
     Realm realm,
     ObjectPrototype objectPrototype)
     : base(engine, objectClass: ObjectClass.JSON)
 {
     _realm     = realm;
     _prototype = objectPrototype;
 }
Beispiel #6
0
 internal WeakSetPrototype(
     Engine engine,
     Realm realm,
     WeakSetConstructor constructor,
     ObjectPrototype prototype) : base(engine, realm)
 {
     _prototype   = prototype;
     _constructor = constructor;
 }
Beispiel #7
0
        private void AddGround(VisualizerCommandSet set)
        {
            const double groundSize = 10;
            string       filename   = "dirt.jpg";

            var obj = new ObjectPrototype(new Square3D(), new TextureMaterial(filename), new Vector3D(0, 0, 0), new Vector3D(groundSize, groundSize, 1));

            set.AddCommand(new AddObject(obj, counter++));
        }
Beispiel #8
0
 internal SymbolPrototype(
     Engine engine,
     Realm realm,
     SymbolConstructor symbolConstructor,
     ObjectPrototype objectPrototype)
     : base(engine, realm)
 {
     _prototype   = objectPrototype;
     _constructor = symbolConstructor;
 }
Beispiel #9
0
 internal ArrayBufferPrototype(
     Engine engine,
     Realm realm,
     ArrayBufferConstructor constructor,
     ObjectPrototype objectPrototype) : base(engine, 0)
 {
     _prototype   = objectPrototype;
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #10
0
        private void AddParticle(Particle particle, VisualizerCommandSet set)
        {
            // Start it off in the right place
            var obj = new ObjectPrototype(new Sphere3D(), new BasicMaterial(ConvertColor(particle.Info.Color)),
                                          ConvertToVector3D(particle.Position), new Vector3D(ParticleSize, ParticleSize, ParticleSize));

            set.AddCommand(new AddObject(obj, counter));
            particleMap.Add(particle, counter);
            ++counter;
        }
Beispiel #11
0
 internal RegExpPrototype(
     Engine engine,
     Realm realm,
     RegExpConstructor constructor,
     ObjectPrototype objectPrototype) : base(engine, realm)
 {
     _defaultExec = Exec;
     _constructor = constructor;
     _prototype   = objectPrototype;
 }
Beispiel #12
0
 internal DataViewPrototype(
     Engine engine,
     Realm realm,
     DataViewConstructor constructor,
     ObjectPrototype objectPrototype) : base(engine)
 {
     _prototype   = objectPrototype;
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #13
0
 internal FunctionConstructor(
     Engine engine,
     Realm realm,
     ObjectPrototype objectPrototype)
     : base(engine, realm, _functionName)
 {
     PrototypeObject      = new FunctionPrototype(engine, realm, objectPrototype);
     _prototype           = PrototypeObject;
     _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
     _length = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable);
 }
Beispiel #14
0
 internal BooleanPrototype(
     Engine engine,
     Realm realm,
     BooleanConstructor constructor,
     ObjectPrototype objectPrototype) : base(engine)
 {
     _prototype   = objectPrototype;
     BooleanData  = JsBoolean.False;
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #15
0
 internal BigIntPrototype(
     Engine engine,
     Realm realm,
     BigIntConstructor constructor,
     ObjectPrototype objectPrototype)
     : base(engine, ObjectClass.Object, InternalTypes.BigInt)
 {
     _prototype   = objectPrototype;
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #16
0
 public StringConstructor(
     Engine engine,
     Realm realm,
     FunctionPrototype functionPrototype,
     ObjectPrototype objectPrototype)
     : base(engine, realm, _functionName, FunctionThisMode.Global)
 {
     _prototype           = functionPrototype;
     PrototypeObject      = new StringPrototype(engine, realm, this, objectPrototype);
     _length              = new PropertyDescriptor(JsNumber.PositiveOne, PropertyFlag.Configurable);
     _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
 }
Beispiel #17
0
 internal NumberPrototype(
     Engine engine,
     Realm realm,
     NumberConstructor constructor,
     ObjectPrototype objectPrototype)
     : base(engine)
 {
     _prototype   = objectPrototype;
     NumberData   = JsNumber.Create(0);
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #18
0
 internal SetConstructor(
     Engine engine,
     Realm realm,
     FunctionPrototype functionPrototype,
     ObjectPrototype objectPrototype)
     : base(engine, realm, _functionName, FunctionThisMode.Global)
 {
     _prototype           = functionPrototype;
     PrototypeObject      = new SetPrototype(engine, realm, this, objectPrototype);
     _length              = new PropertyDescriptor(0, PropertyFlag.Configurable);
     _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
 }
Beispiel #19
0
 internal WeakMapConstructor(
     Engine engine,
     Realm realm,
     FunctionPrototype prototype,
     ObjectPrototype objectPrototype)
     : base(engine, realm, _functionName)
 {
     _prototype           = prototype;
     PrototypeObject      = new WeakMapPrototype(engine, realm, this, objectPrototype);
     _length              = new PropertyDescriptor(0, PropertyFlag.Configurable);
     _prototypeDescriptor = new PropertyDescriptor(PrototypeObject, PropertyFlag.AllForbidden);
 }
Beispiel #20
0
 internal StringPrototype(
     Engine engine,
     Realm realm,
     StringConstructor constructor,
     ObjectPrototype objectPrototype)
     : base(engine)
 {
     _prototype   = objectPrototype;
     StringData   = JsString.Empty;
     _length      = PropertyDescriptor.AllForbiddenDescriptor.NumberZero;
     _realm       = realm;
     _constructor = constructor;
 }
Beispiel #21
0
        public Math(ObjectPrototype prototype, Realm realm)
        {
            this.prototype = prototype;

            DefinePropertyOrThrow("E", new PropertyDescriptor(new NumberValue(System.Math.E), false, false, false));
            DefinePropertyOrThrow("LN2", new PropertyDescriptor(new NumberValue(System.Math.Log(2)), false, false, false));

            DefinePropertyOrThrow("abs", new PropertyDescriptor(Utils.CreateBuiltinFunction(abs, realm: realm), true, false, true));
            DefinePropertyOrThrow("ceil", new PropertyDescriptor(Utils.CreateBuiltinFunction(ceil, realm: realm), true, false, true));
            DefinePropertyOrThrow("floor", new PropertyDescriptor(Utils.CreateBuiltinFunction(floor, realm: realm), true, false, true));
            DefinePropertyOrThrow("log", new PropertyDescriptor(Utils.CreateBuiltinFunction(log, realm: realm), true, false, true));
            DefinePropertyOrThrow("min", new PropertyDescriptor(Utils.CreateBuiltinFunction(min, realm: realm), true, false, true));
            DefinePropertyOrThrow("pow", new PropertyDescriptor(Utils.CreateBuiltinFunction(pow, realm: realm), true, false, true));
        }
Beispiel #22
0
        public VisualizerCommandSet Initialization()
        {
            var set = new VisualizerCommandSet();

            var box = new ObjectPrototype(new Cube3D(), new BasicMaterial(BoxColor, true),
                                          ConvertToVector3D(container.Size / 2), ConvertToVector3D(container.Size / 2 * BoxScale));

            set.AddCommand(new AddObject(box, counter));
            ++counter;

            // Add all the particles
            container.Particles.ForEach((particle) => AddParticle(particle, set));

            return(set);
        }
        public VisualizerCommandSet Initialization()
        {
            var set = new VisualizerCommandSet();

            if (Box)
            {
                AddBox(set);
            }

            foreach (var triangle in surfaces)
            {
                var tri = new Triangle3D(
                    UtilityFunctions.ConvertVector(triangle.Points[0]),
                    UtilityFunctions.ConvertVector(triangle.Points[1]),
                    UtilityFunctions.ConvertVector(triangle.Points[2]), true);
                var obj = new ObjectPrototype(tri, UtilityFunctions.ConvertColor(triangle.Color), triangle.IsTransparent);
                set.AddCommand(new AddObject(obj, counter++));
            }

            // Add all the projectiles
            foreach (var projectile in projectiles)
            {
                // Start it off in the right place
                var obj = new ObjectPrototype(projectile.Shape, new BasicMaterial(projectile.Color),
                                              projectile.Position, new Vector3D(projectile.Size, projectile.Size, projectile.Size));

                set.AddCommand(new AddObject(obj, counter));
                projectileMap.Add(counter, projectile);
                ++counter;
            }

            // Add all the connectors
            foreach (var connector in connectorMap)
            {
                // Update them first so they are in the right position
                connector.Value.Update();
                var obj = new ObjectPrototype(new VisualizerControl.Shapes.CaplessCylinder3D(),
                                              new BasicMaterial(connector.Value.Color));
                set.AddCommand(new AddObject(obj, connector.Key));
                set.AddCommand(connector.Value.GetTransformCommand(connector.Key));
            }

            return(set);
        }
Beispiel #24
0
        public CommandSet <VisualizerControl.Visualizer> Initialization()
        {
            var set     = new CommandSet <VisualizerControl.Visualizer>();
            int counter = 0;

            // Add floor
            var floor    = engine.Floor;
            var floorObj = new ObjectPrototype(new Quadrilateral3D(
                                                   new Vector3D(floor.UpperLeft.X, floor.UpperLeft.Y, 0),
                                                   new Vector3D(floor.LowerLeft.X, floor.LowerLeft.Y, 0),
                                                   new Vector3D(floor.UpperRight.X, floor.UpperRight.Y, 0),
                                                   new Vector3D(floor.LowerRight.X, floor.LowerRight.Y, 0)
                                                   ), new BasicMaterial(FloorColor, .03, .5));

            set.AddCommand(new AddObject(floorObj, counter++));

            // Add walls
            foreach (var wall in engine.Walls)
            {
                var wallObj = new ObjectPrototype(new Quadrilateral3D(
                                                      new Vector3D(wall.Endpoints.Item1.X, wall.Endpoints.Item1.Y, 0),
                                                      new Vector3D(wall.Endpoints.Item2.X, wall.Endpoints.Item2.Y, 0),
                                                      new Vector3D(wall.Endpoints.Item1.X, wall.Endpoints.Item1.Y, WallHeight),
                                                      new Vector3D(wall.Endpoints.Item2.X, wall.Endpoints.Item2.Y, WallHeight)
                                                      ), new BasicMaterial(WallColor, .03, .5));
                set.AddCommand(new AddObject(wallObj, counter++));
            }

            // Add people
            foreach (var person in engine.People)
            {
                var personObj = new ObjectPrototype(new Cylinder3D(), new BasicMaterial(person.Intelligence.Color, .03, .5));
                set.AddCommand(new AddObject(personObj, counter));
                set.AddCommand(new TransformObject(counter, new Vector(person.Position.X, person.Position.Y, PersonHeight / 2),
                                                   new Vector(person.PhysicalRadius, person.PhysicalRadius, PersonHeight / 2)));
                personMap.Add(person, counter);
                ++counter;
            }

            return(set);
        }
        public VisualizerCommandSet Initialization()
        {
            var set = new VisualizerCommandSet();

            var projectile = new ObjectPrototype(new Sphere3D(), new BasicMaterial(ProjectileColor),
                                                 ConvertVector(engine.Projectile.Position), new Vector3D(ProjectileSize, ProjectileSize, ProjectileSize));

            set.AddCommand(new AddObject(projectile, counter));
            projectileIndex = counter;
            ++counter;

            var shape = new FunctionShape3D(engine.Path)
            {
                CircleRadius = PathThickness
            };
            var path = new ObjectPrototype(shape, new BasicMaterial(PathColor));

            set.AddCommand(new AddObject(path, counter));

            return(set);
        }
        public VisualizerCommandSet Initialization()
        {
            var set = new VisualizerCommandSet();

            var box = new ObjectPrototype(new Cube3D(), new BasicMaterial(BoxColor, true),
                                          ConvertToVector3D(container.Size / 2), ConvertToVector3D(container.Size / 2 * BoxScale));

            set.AddCommand(new AddObject(box, counter));
            ++counter;

            // Add all the particles
            foreach (var particle in container.Particles)
            {
                // Start it off in the right place
                var obj = new ObjectPrototype(new Sphere3D(), new BasicMaterial(ConvertColor(particle.Info.Color)),
                                              ConvertToVector3D(particle.Position), new Vector3D(ParticleSize, ParticleSize, ParticleSize));

                set.AddCommand(new AddObject(obj, counter));
                particleMap.Add(particle, counter);
                ++counter;
            }

            return(set);
        }
Beispiel #27
0
 /// <param name="obj">The Object3D to add</param>
 /// <param name="index">An assigned index, to be used for subsequent commands.  Must be unique.</param>
 public AddObject(ObjectPrototype obj, int index)
 {
     this.obj   = obj;
     this.index = index;
 }
Beispiel #28
0
 internal MathInstance(Engine engine, ObjectPrototype objectPrototype) : base(engine, ObjectClass.Math)
 {
     _prototype = objectPrototype;
 }
Beispiel #29
0
        public static void Register(JavaScriptContext context)
        {
            JavaScriptValue ObjectPrototype;
            JavaScriptValue ObjectConstructor = Bridge.CreateConstructor(
                typeof(UnityEngine.Object),
                (args) => { throw new System.NotImplementedException(); },
                out ObjectPrototype
                );

            JavaScriptValue
            .GlobalObject
            .GetProperty("UnityEngine")
            .SetProperty("Object", ObjectConstructor);


            // Static Fields


            // Static Property Accessors


            // Static Methods

            ObjectConstructor.SetProperty(
                "Instantiate",
                Bridge.CreateFunction(
                    "Instantiate",
                    (args) => {
                switch (args.Length)
                {
                case 2:
                    return(Bridge.CreateExternalWithPrototype(UnityEngine.Object.Instantiate(Bridge.GetExternal <UnityEngine.Object>(args[1]))));

                case 3:
                    return(Bridge.CreateExternalWithPrototype(UnityEngine.Object.Instantiate(Bridge.GetExternal <UnityEngine.Object>(args[1]), Bridge.GetExternal <UnityEngine.Transform>(args[2]))));

                case 4:
                    if (args[3].ValueType == JavaScriptValueType.Boolean)
                    {
                        return(Bridge.CreateExternalWithPrototype(UnityEngine.Object.Instantiate(Bridge.GetExternal <UnityEngine.Object>(args[1]), Bridge.GetExternal <UnityEngine.Transform>(args[2]), args[3].ToBoolean())));
                    }
                    else
                    {
                        return(Bridge.CreateExternalWithPrototype(UnityEngine.Object.Instantiate(Bridge.GetExternal <UnityEngine.Object>(args[1]), Bridge.GetBoxedExternal <UnityEngine.Vector3>(args[2]).wrapped, Bridge.GetBoxedExternal <UnityEngine.Quaternion>(args[3]).wrapped)));
                    }

                case 5:
                    return(Bridge.CreateExternalWithPrototype(UnityEngine.Object.Instantiate(Bridge.GetExternal <UnityEngine.Object>(args[1]), Bridge.GetBoxedExternal <UnityEngine.Vector3>(args[2]).wrapped, Bridge.GetBoxedExternal <UnityEngine.Quaternion>(args[3]).wrapped, Bridge.GetExternal <UnityEngine.Transform>(args[4]))));

                default:
                    throw new System.Exception("no such overload");
                }
            }
                    )
                );


            /*
             * Object Instantiate
             * method has generics
             */


            /*
             * Object Instantiate
             * method has generics
             */


            /*
             * Object Instantiate
             * method has generics
             */


            /*
             * Object Instantiate
             * method has generics
             */


            /*
             * Object Instantiate
             * method has generics
             */


            ObjectConstructor.SetProperty(
                "Destroy",
                Bridge.CreateFunction(
                    "Destroy",
                    (args) => {
                if (args.Length == 2)
                {
                    UnityEngine.Object.Destroy(Bridge.GetExternal <UnityEngine.Object>(args[1]));
                }
                else
                {
                    UnityEngine.Object.Destroy(Bridge.GetExternal <UnityEngine.Object>(args[1]), (float)args[2].ToDouble());
                }
            }
                    )
                );


            ObjectConstructor.SetProperty(
                "DestroyImmediate",
                Bridge.CreateFunction(
                    "DestroyImmediate",
                    (args) => {
                if (args.Length == 2)
                {
                    UnityEngine.Object.DestroyImmediate(Bridge.GetExternal <UnityEngine.Object>(args[1]));
                }
                else
                {
                    UnityEngine.Object.DestroyImmediate(Bridge.GetExternal <UnityEngine.Object>(args[1]), args[2].ToBoolean());
                }
            }
                    )
                );


            ObjectConstructor.SetProperty(
                "FindObjectsOfType",
                Bridge.CreateFunction(
                    "FindObjectsOfType",
                    (args) => Bridge.CreateExternalWithPrototype(UnityEngine.Object.FindObjectsOfType(Bridge.GetExternal <System.Type>(args[1])))
                    )
                );


            ObjectConstructor.SetProperty(
                "DontDestroyOnLoad",
                Bridge.CreateFunction(
                    "DontDestroyOnLoad",
                    (args) => UnityEngine.Object.DontDestroyOnLoad(Bridge.GetExternal <UnityEngine.Object>(args[1]))
                    )
                );


            /*
             * Object FindObjectsOfType
             * method has generics
             */


            /*
             * Object FindObjectOfType
             * method has generics
             */


            ObjectConstructor.SetProperty(
                "FindObjectOfType",
                Bridge.CreateFunction(
                    "FindObjectOfType",
                    (args) => Bridge.CreateExternalWithPrototype(UnityEngine.Object.FindObjectOfType(Bridge.GetExternal <System.Type>(args[1])))
                    )
                );


            // Instance Fields


            // Instance Property Accessors

            Bridge.DefineGetterSetter(
                ObjectPrototype,
                "name",
                Bridge.WithExternal <UnityEngine.Object>((o, args) => JavaScriptValue.FromString(o.name)),
                Bridge.WithExternal <UnityEngine.Object>((o, args) => { o.name = args[1].ToString(); })
                );


            Bridge.DefineGetterSetter(
                ObjectPrototype,
                "hideFlags",
                Bridge.WithExternal <UnityEngine.Object>((o, args) => Bridge.CreateExternalWithPrototype(o.hideFlags)),
                Bridge.WithExternal <UnityEngine.Object>((o, args) => { o.hideFlags = Bridge.GetExternal <UnityEngine.HideFlags>(args[1]); })
                );


            // Instance Methods

            ObjectPrototype.SetProperty(
                "GetInstanceID",
                Bridge.CreateFunction(
                    "GetInstanceID",
                    Bridge.WithExternal <UnityEngine.Object>((o, args) => JavaScriptValue.FromInt32(o.GetInstanceID()))
                    )
                );


            ObjectPrototype.SetProperty(
                "GetHashCode",
                Bridge.CreateFunction(
                    "GetHashCode",
                    Bridge.WithExternal <UnityEngine.Object>((o, args) => JavaScriptValue.FromInt32(o.GetHashCode()))
                    )
                );


            ObjectPrototype.SetProperty(
                "Equals",
                Bridge.CreateFunction(
                    "Equals",
                    Bridge.WithExternal <UnityEngine.Object>((o, args) => JavaScriptValue.FromBoolean(o.Equals(Bridge.GetExternal <System.Object>(args[1]))))
                    )
                );


            ObjectPrototype.SetProperty(
                "toString",
                Bridge.CreateFunction(
                    "ToString",
                    Bridge.WithExternal <UnityEngine.Object>((o, args) => JavaScriptValue.FromString(o.ToString()))
                    )
                );
        }
Beispiel #30
0
 internal AddObject(BinaryReader br)
 {
     obj   = ObjectPrototype.ReadFromFile(br);
     index = br.ReadInt32();
 }