Beispiel #1
0
        public UltraSprite()
        {
            this.graphics.beginFill(0xffffff);
            this.graphics.drawRect(0, 0, DefaultWidth, DefaultHeight);
            this.graphics.lineStyle(2, 0xa0, 1);
            this.graphics.beginFill(0xffffff, 0);
            this.graphics.drawRect(0, 0, DefaultWidth, DefaultHeight);

            t = new TextField
            {
                width  = DefaultWidth,
                height = DefaultHeight
            };

            t.AttachTo(this);

            this.AppendLine("This is flash.display.Sprite (version 101)");

            var Button1 = new Sprite();

            Button1.graphics.beginFill(0xff00);
            Button1.graphics.drawRect(0, 0, 64, 24);
            Button1.useHandCursor = true;
            Button1.buttonMode    = true;

            Button1.AttachTo(this).MoveTo(DefaultWidth - 64 - 8, 8);

            Button1.click +=
                delegate
            {
                // jsc.meta should use Convert type for us
                if (Convert.ToBoolean(this.WebServiceEnabled.IsEnabled))
                {
                    this.WebService.GetTime("[flash client time]: " + DateTime.Now + " [server time]",
                                            x =>
                    {
                        this.AppendLine(x);
                    }
                                            );
                }
                else
                {
                    this.AppendLine("WebService is disabled!");
                }
            };
        }
Beispiel #2
0
        public UltraSprite()
        {
            this.graphics.beginFill(0xffffff);
            this.graphics.drawRect(0, 0, DefaultWidth, DefaultHeight);
            this.graphics.lineStyle(2, 0xa0, 1);
            this.graphics.beginFill(0xffffff, 0);
            this.graphics.drawRect(0, 0, DefaultWidth, DefaultHeight);

            t = new TextField
            {
                width  = DefaultWidth,
                height = DefaultHeight
            };

            t.AttachTo(this);

            this.AppendLine("This is flash.display.Sprite (version 101)");
        }
        // X:\jsc.svn\examples\actionscript\FlashWorkerExperiment\FlashWorkerExperiment\ApplicationSprite.cs
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201403/20140301

        public ApplicationSprite()
        {
            // when can we do this?

            //BCL needs another method, please define it.
            //Cannot call type without script attribute :
            //System.Threading.Tasks.Task for System.Threading.Tasks.TaskFactory get_Factory() used at
            //AsyncWorkerTask.ApplicationSprite..ctor at offset 0010.

            var a = Task.Factory.StartNew(
                state: new { goo = "foo " },
                function: scope =>
            {
                // notice that jsc might need to inject serialization logic here
                return("hello " + new { scope.goo });
            }
                );

            a.ContinueWithResult(
                r =>
            {
                var t = new TextField
                {
                    text = new
                    {
                        r,

                        WorkerDomain = WorkerDomain.isSupported,
                        Worker       = Worker.isSupported,
                        Worker.current.isPrimordial,

                        this.loaderInfo.bytes.length
                    }.ToString(),

                    autoSize = TextFieldAutoSize.LEFT
                };

                t.AttachTo(this);
            }
                );
        }
Beispiel #4
0
        public ApplicationSprite()
        {
            //__Thread.InternalWorkerInvoke_4ebbe596_06000030(this);
            //this.__out_Method_6d788eff_06000003();

            // "X:\jsc.svn\examples\actionscript\async\AsyncWorkerTask\AsyncWorkerTask.sln"
            // X:\jsc.svn\examples\actionscript\async\AsyncWorkerTask\AsyncWorkerTask\ApplicationSprite.cs
            // X:\jsc.svn\examples\actionscript\FlashWorkerExperiment\FlashWorkerExperiment\ApplicationSprite.cs


            // https://forums.adobe.com/thread/1164500

            // this looks like chrome context capture
            #region worker
            if (!Worker.current.isPrimordial)
            {
                var sw = Stopwatch.StartNew();

                // iOS workers is still on the roadmap.  I don't have a release date, but I know it'll be an extended beta type of feature.
                // Most of the concurrency work was gated on the new AOT compiler work, which is still being actively worked on.
                // Lots of bug and performance fixes were added to AIR 15 and we're not stopping there.

                var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker");

                var FunctionToken_TypeFullName = (string)Worker.current.getSharedProperty("FunctionToken_TypeFullName");
                var FunctionToken_MethodName   = (string)Worker.current.getSharedProperty("FunctionToken_MethodName");
                var arg0 = (string)Worker.current.getSharedProperty("arg0");

                //               enter click
                //{ { data = message from worker { { FunctionToken_TypeFullName = TestThreadStart.TheOtherClass, FunctionToken_MethodName = Invoke_6d788eff_0600001c } }, ElapsedMilliseconds = 1713 } }


                IntPtr pp = __IntPtr.OfFunctionToken(null,
                                                     FunctionToken_TypeFullName,
                                                     FunctionToken_MethodName
                                                     );


                MethodInfo mm = new __MethodInfo {
                    _Method = pp
                };

                //    t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds };

                //xfromWorker.send("message from worker " + new { FunctionToken_TypeFullName, FunctionToken_MethodName });

                //throw null;



                mm.Invoke(null, new object[] { arg0 });

                //               enter click
                //{ { ElapsedMilliseconds = 3103, data = message from worker { { ElapsedMilliseconds = 3057, SharedField = { { data = null, i = 65534, j = 3 } } } } } }
                // {{ ElapsedMilliseconds = 3399, data = message from worker {{ ElapsedMilliseconds = 3352, SharedField = {{ data = hello world, i = 65534, j = 3 }} }} }}

                xfromWorker.send("message from worker " + new { sw.ElapsedMilliseconds, TheOtherClass.SharedField });

                return;
            }
            #endregion

            // {{ os = Windows 7, version = WIN 15,0,0,189, length = 333983, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = , FunctionToken = function Function() {}, ClassToken =  } } }}
            // start0 = new __ParameterizedThreadStart(null, __IntPtr.op_Explicit_4ebbe596_06001686(TheOtherClass.Invoke_6d788eff_0600000c));
            //      start0 = new __ParameterizedThreadStart(null, __IntPtr.OfFunctionToken_4ebbe596_06001687(TheOtherClass.Invoke_6d788eff_0600000c,"TestThreadStart.TheOtherClass","Invoke_6d788eff_0600000c"));
            ParameterizedThreadStart y = TheOtherClass.Invoke;

            // can we call the method
            //            0007 0200034c ScriptCoreLib::ScriptCoreLib.ActionScript.Extensions.ZipFileEntry + Cookie`1

            //Unhandled Exception: System.AggregateException: One or more errors occurred. --->System.InvalidOperationException: internal compiler error at method
            // assembly: X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\bin\Debug\ScriptCoreLib.dll at
            // type: ScriptCoreLib.ActionScript.BCLImplementation.System.__Single, ScriptCoreLib, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null
            // method: CompareTo
            // Object reference not set to an instance of an object.
            //    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
            //   at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
            //   at jsc.Script.CompilerBase.  .    (Type , MethodBase , LocalVariableInfo , CompilerBase )
            //   at jsc.Script.CompilerBase.<WriteVariableName>b__0(Type , MethodBase , LocalVariableInfo )

            //           Unhandled Exception: System.AggregateException: One or more errors occurred. --->System.InvalidOperationException: internal compiler error at method
            //assembly: X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\bin\Debug\ScriptCoreLib.dll at
            //type: ScriptCoreLib.ActionScript.BCLImplementation.System.__BitConverter, ScriptCoreLib, Version=4.5.0.0, Culture=neutral, PublicKeyToken=null
            //method: GetBytes
            //Object reference not set to an instance of an object.
            //   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
            //  at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
            //  at jsc.Script.CompilerBase.  .    (Type , MethodBase , LocalVariableInfo , CompilerBase )


            //{{ os = Windows 7, version = WIN 15,0,0,189, length = 334356, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = , FunctionToken = function Function() {}, ClassToken =  } }, z = Type { TypeDescription =
            // <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true">
            //  <extendsClass type="Class"/>
            //  <extendsClass type="Object"/>
            //  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
            //  <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void">
            //    <parameter index="1" type="Object" optional="false"/>
            //  </method>
            //  <factory type="TestThreadStart::TheOtherClass">
            //    <extendsClass type="Object"/>
            //  </factory>
            //</type> } }}

            //          {{ os = Windows 7, version = WIN 15,0,0,189, length = 334570, Target = null, Method = { _Target = , _Method = IntPtr { StringToken = ,
            //FunctionToken = function Function() {}, ClassToken =  } }, FullName = TestThreadStart::TheOtherClass, z = Type { TypeDescription = <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true">
            //  <extendsClass type="Class"/>
            //  <extendsClass type="Object"/>
            //  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
            //  <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void">
            //    <parameter index="1" type="Object" optional="false"/>
            //  </method>
            //  <factory type="TestThreadStart::TheOtherClass">
            //    <extendsClass type="Object"/>
            //  </factory>
            //</type> }, zz = Type { TypeDescription = <type name="TestThreadStart::TheOtherClass" base="Class" isDynamic="true" isFinal="true" isStatic="true">
            //  <extendsClass type="Class"/>
            //  <extendsClass type="Object"/>
            //  <accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
            //  <method name="Invoke_6d788eff_0600000c" declaredBy="TestThreadStart::TheOtherClass" returnType="void">
            //    <parameter index="1" type="Object" optional="false"/>
            //  </method>
            //  <factory type="TestThreadStart::TheOtherClass">
            //    <extendsClass type="Object"/>
            //  </factory>
            //</type> } }}

            //var z = typeof(TheOtherClass);
            //var zz = Type.GetType("TestThreadStart::TheOtherClass");
            //var zz = Type.GetType("TestThreadStart.TheOtherClass");

            //var zMethod = z.GetMethods();

            __MethodInfo p = y.Method;

            //{ { os = Windows 7, version = WIN 15,0,0,189, length = 335268,
            // FunctionToken_TypeFullName = TestThreadStart.TheOtherClass,
            // FunctionToken_MethodName = Invoke_6d788eff_0600000c
            // } }

            //var pt = Type.GetType(p._Method.FunctionToken_TypeFullName);



            //new ParameterizedThreadStart(null, pp);

            //new Delegate();



            var t = new TextField
            {
                multiline = true,
                //wordWrap = true,

                // {{ InternalPrimordialSprite = null, os = Windows 7, version = WIN 15,0,0,189, length = 353988, FunctionToken_TypeFullName = TestThreadStart.TheOtherClass, FunctionToken_MethodName = Invoke_6d788eff_06000016 }}

                text = new
                {
                    // did the compiler set it yet?
                    __Thread.InternalPrimordialSprite,

                    // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html
                    Capabilities.os,
                    Capabilities.version,

                    //WorkerDomain = WorkerDomain.isSupported,
                    //Worker = Worker.isSupported,
                    //Worker.current.isPrimordial,

                    this.loaderInfo.bytes.length,

                    // {{ os = Windows 7, version = WIN 15,0,0,189, length = 333411, Target = null, Method = { InternalFunctionPointer = function Function() {} } }}

                    //y.Target,

                    // first step is to call a static method on the other side of thread
                    //y.Method,
                    //y.Method,
                    //y.Method.DeclaringType


                    //z.FullName,

                    //z,

                    p._Method.FunctionToken_TypeFullName,
                    p._Method.FunctionToken_MethodName,
                }.ToString(),

                autoSize = TextFieldAutoSize.LEFT
            };

            t.AttachTo(this);

            t.click += delegate
            {
                var sw = Stopwatch.StartNew();

                t.text = "enter click";

                var w = WorkerDomain.current.createWorker(
                    this.loaderInfo.bytes
                    );

                //p._Method.FunctionToken_TypeFullName,
                //p._Method.FunctionToken_MethodName

                w.setSharedProperty("FunctionToken_TypeFullName", p._Method.FunctionToken_TypeFullName);
                w.setSharedProperty("FunctionToken_MethodName", p._Method.FunctionToken_MethodName);
                w.setSharedProperty("arg0", "hello world");

                var fromWorker = w.createMessageChannel(Worker.current);
                w.setSharedProperty("fromWorker", fromWorker);

                fromWorker.channelMessage +=
                    e =>
                {
                    var data = (string)fromWorker.receive();

                    t.appendText(

                        "\n " + new { sw.ElapsedMilliseconds, data }.ToString()

                        );
                };

                t.text = "enter click";
                w.start();


                //try
                //{
                //    // catch {{ err = ArgumentError: Error #1063: Argument count mismatch on TestThreadStart::TheOtherClass$/Invoke_6d788eff_06000013(). Expected 1, got 0. }}

                //    mm.Invoke(null, new object[1]);
                //    t.text = "after invoke " + new { TheOtherClass.SharedField, sw.ElapsedMilliseconds };
                //}
                //catch (Exception err)
                //{
                //    t.text = "catch " + new { err };
                //}
            };
        }
        public ApplicationSprite()
        {
            // http://www.yeahbutisitflash.com/?p=5469

            // http://forums.adobe.com/message/5745066

            // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2013/201310/20131006-air

            //System.ArgumentException: Parameter count does not match passed in argument value count.

            //        ReferenceError: Error #1065: Variable flash.system::WorkerDomain is not defined.
            //at FlashWorkerExperiment::ApplicationSprite()[S:\web\FlashWorkerExperiment\ApplicationSprite.as:31]

            //{ isSupported = true }
            // http://esdot.ca/site/2012/intro-to-as3-workers-hello-world


            //   The swf version should be 22 and above.



            // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Worker.html
            //  For mobile platforms, concurrency is supported in AIR on Android but not in AIR on iOS.
            // You can use the static isSupported property to check whether concurrency is supported before attempting to use it.
            if (Worker.current.isPrimordial)
            {
                //{ os = Windows 7, version = WIN 13,0,0,133, WorkerDomain = true, Worker = true, isPrimordial = true, length = 519498 }
                // before start
                // after start { w = [object Worker] }
                // main: { i = 0, isPrimordial = true, current = true }
                // { data = ready?
                // in worker: { i = 0, isPrimordial = false, current = true }
                // in worker: { i = 1, isPrimordial = true, current = false } }click!
                // { data = hi from worker { data = hi from UI } }

                // http://forums.adobe.com/thread/1171498

                var t = new TextField
                {
                    text = new
                    {
                        // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html
                        Capabilities.os,
                        Capabilities.version,

                        WorkerDomain = WorkerDomain.isSupported,
                        Worker       = Worker.isSupported,
                        Worker.current.isPrimordial,

                        this.loaderInfo.bytes.length
                    }.ToString(),

                    autoSize = TextFieldAutoSize.LEFT
                };

                t.AttachTo(this);

                //this.stage.loaderInfo.uncaughtErrorEvents.uncaughtError +=
                this.loaderInfo.uncaughtErrorEvents.uncaughtError +=

                    e =>
                {
                    // http://www.adobe.com/support/flashplayer/downloads.html

                    t.appendText(

                        new { e.errorID, e.text, e.error }.ToString()

                        );
                };

                if (WorkerDomain.isSupported)
                {
                    // http://jacksondunstan.com/articles/1968
                    // "C:\util\flex_sdk_4.6\frameworks\libs\player\11.9\playerglobal.swc"
                    // "C:\util\air3-9_sdk_sa_win\frameworks\libs\player\11.9\playerglobal.swc"
                    // "C:\util\air13_sdk_win\frameworks\libs\player\13.0\playerglobal.swc"
                    // can we create natives of it yet?
                    // call c:\util\jsc\bin\jsc.meta.exe RewriteToActionScriptNatives /SWCFiles:"C:\util\flex_sdk_4.6\frameworks\libs\player\11.1\playerglobal.swc" /SWCFiles:"C:\util\flex_sdk_4.6\frameworks\libs\framework.swc"  /SWCFiles:"C:\util\flex_sdk_4.6\frameworks\libs\mx\mx.swc" /OutputAssembly:c:\util\jsc\bin\ScriptCoreLib.ActionScript.Natives.dll  /DisableResolveExternalType:true  /DisableWorkerDomain
                    // call c:\util\jsc\bin\jsc.meta.exe RewriteToActionScriptNatives /SWCFiles:"C:\util\air13_sdk_win\frameworks\libs\player\13.0\playerglobal.swc" /SWCFiles:"C:\util\flex_sdk_4.6\frameworks\libs\framework.swc"  /SWCFiles:"C:\util\flex_sdk_4.6\frameworks\libs\mx\mx.swc" /OutputAssembly:c:\util\jsc\bin\ScriptCoreLib.ActionScript.AIRNatives.dll  /DisableResolveExternalType:true  /DisableWorkerDomain

                    // should flash natives gen get a copy of the playerglobal and use it instead?

                    // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/WorkerDomain.html
                    var w = WorkerDomain.current.createWorker(
                        this.loaderInfo.bytes
                        );

                    // http://jacksondunstan.com/articles/2401

                    //  channel1 = WorkerDomain.current.createMessageChannel(worker0);
                    var toWorker   = Worker.current.createMessageChannel(w);
                    var fromWorker = w.createMessageChannel(Worker.current);

                    // http://esdot.ca/site/2012/intro-to-as3-workers-hello-world
                    w.setSharedProperty("toWorker", toWorker);
                    w.setSharedProperty("fromWorker", fromWorker);

                    // http://jcward.com/AIR+3.9+Workers+Beta
                    fromWorker.channelMessage +=
                        e =>
                    {
                        var data = (string)fromWorker.receive();

                        t.appendText(

                            "\n " + new { data }.ToString()

                            );
                    };

                    t.appendText(
                        "\n before start"
                        );

                    // { isSupported = true, isPrimordial = true, length = 485141 }
                    w.start();


                    t.appendText(
                        "\n after start " + new { w }
                        );

                    var list = WorkerDomain.current.listWorkers();

                    for (int i = 0; i < list.length; i++)
                    {
                        t.appendText(
                            "\n main: " + new
                        {
                            i,
                            list[i].isPrimordial,
                            current = list[i] == Worker.current
                        }
                            );
                    }

                    t.click +=
                        delegate
                    {
                        t.appendText(

                            "click!"


                            );

                        toWorker.send("hi from UI");
                    };
                }
            }
            else
            {
                var toWorker = (MessageChannel)Worker.current.getSharedProperty("toWorker");

                // VerifyError: Error #1014: Class flash.system::Worker could not be found.

                //WorkerDomain = true, Worker = true, isPrimordial = true, length = 517003 }
                //before start
                //after start { w = [object Worker] }{ data = ready? }click!{ data = hi from worker { data = hi from UI } }


                // http://forums.adobe.com/thread/1411606?tstart=0
                //Mobile Workers (concurrency) - Android
                //Introduced as a beta feature in AIR 3.9, we've continued to improve this feature based on your feedback for its official release in AIR 4.



                // what about automagic sync, jsc detects and marks such properties?
                var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker");

                if (xfromWorker != null)
                {
                    var w = new StringBuilder();


                    //{ WorkerDomain = true, Worker = true, isPrimordial = true, length = 519030 }
                    // before start
                    // after start { w = [object Worker] }
                    // main: { i = 0, isPrimordial = true, current = true }
                    // { data = ready?
                    // in worker: { i = 0, isPrimordial = false, current = true }
                    // in worker: { i = 1, isPrimordial = true, current = false } }click!
                    // { data = hi from worker { data = hi from UI } }click!
                    // { data = hi from worker { data = hi from UI } }

                    var list = WorkerDomain.current.listWorkers();

                    for (int i = 0; i < list.length; i++)
                    {
                        w.Append(
                            "\n in worker: " + new
                        {
                            i,
                            list[i].isPrimordial,
                            current = list[i] == Worker.current
                        }
                            );
                    }

                    xfromWorker.send("ready? " + w.ToString());
                }


                toWorker.channelMessage +=
                    e =>
                {
                    var data = (string)toWorker.receive();
                    // now what?

                    xfromWorker.send("hi from worker " + new { data });
                };
            }
        }
        // X:\util\air17_sdk_sa_win
        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201409/20140911

        public ApplicationSprite()
        {
            // X:\jsc.svn\examples\actionscript\air\AIRStageWebViewExperiment\AIRStageWebViewExperiment\ApplicationSprite.cs

            // http://stackoverflow.com/questions/3170585/get-ip-address-with-adobe-air-2

            var t = new TextField
            {
                text = new
                {
                    // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Capabilities.html
                    Capabilities.os,
                    Capabilities.version,
                    Capabilities.playerType,


                    //Error   CS0117  'Capabilities' does not contain a definition for 'cpuArchitecture'  AIRServerSocketExperiment   X:\jsc.svn\examples\actionscript\air\AIRServerSocketExperiment\AIRServerSocketExperiment\ApplicationSprite.cs   29

#if FPARTIAL
                    Capabilities.cpuArchitecture,
                    Capabilities.touchscreenType,
#endif

                    // why is this commented out?
                    //WorkerDomain = WorkerDomain.isSupported,

                    // http://na5.brightidea.com/ct/ct_a_view_idea.bix?c=9D564F43-979A-4E35-AA21-85A61B6AB8DE&idea_id=F353B3CC-5F05-45E7-9A73-1093E0A1F9DD

                    NetworkInfo = NetworkInfo.isSupported,
                    //Worker.current.isPrimordial,

                    this.loaderInfo.bytes.length
                }.ToString(),

                                            autoSize = TextFieldAutoSize.LEFT
            };

            t.AttachTo(this);



            //V:\web\AIRServerSocketExperiment\ApplicationSprite.as(46): col: 127 Error: Implicit coercion of a value of type __AS3__.vec:Vector.<flash.net:NetworkInterface> to an unrelated type __AS3__.vec:Vector.<*>.

            //            LinqExtensions.WithEach_f7a1155f_06000027(CommonExtensions.AsEnumerable_4ebbe596_06001850(NetworkInfo.networkInfo.findInterfaces()), new __Action_1(class21, __IntPtr.op_Explicit_4ebbe596_06001412("__ctor_b__1_f7a1155f_06000005")));
            //                                                                                                                              ^

            //{ os = Windows 7, version = WIN 13,0,0,133, playerType = Desktop, length = 489435 }
            // { name = {84D54A45-2ACC-42B2-A59B-E01D43897D2D}, displayName = Local Area Connection, active = false }
            // address { address = 169.254.45.8, broadcast = 169.254.255.255 }
            // { name = {978F5176-96B4-49D4-A14D-6CEA5CB3D505}, displayName = Bluetooth Network Connection, active = false }
            // address { address = 169.254.6.204, broadcast = 169.254.255.255 }
            // { name = {CE7A76DF-BCB0-4C3B-8466-D712A03F10A0}, displayName = Wireless Network Connection, active = true }
            // address { address = 192.168.43.252, broadcast = 192.168.43.255 }
            // { name = {846EE342-7039-11DE-9D20-806E6F6E6963}, displayName = Loopback Pseudo-Interface 1, active = true }
            // address { address = ::1, broadcast =  }
            // address { address = 127.0.0.1, broadcast =  }
            // { name = {A5178906-144E-433A-9103-B2EB62A4C21E}, displayName = Teredo Tunneling Pseudo-Interface, active = true }
            // address { address = 2001:0:9d38:6abd:28d1:36ea:3f57:d403, broadcast =  }

            if (Capabilities.playerType == "Desktop")
            {
                // we dont want to crash flash player!
                // http://help.adobe.com/en_US/air/build/WS144092a96ffef7cc16ddeea2126bb46b82f-8000.html

                // VerifyError: Error #1014: Class flash.net::NetworkInterface could not be found.

                var ii = NetworkInfo.networkInfo.findInterfaces();
                for (int ij = 0; ij < ii.length; ij++)
                {
                    var i = ii[ij];

                    t.appendText("\n " + new { i.name, i.displayName, i.active });

                    var aa = i.addresses;

                    for (int aj = 0; aj < aa.length; aj++)
                    {
                        var a = aa[aj];

                        t.appendText("\n address " + new { a.address, a.broadcast, a.ipVersion });
                    }
                }
            }

            //V:\web\AIRServerSocketExperiment\ApplicationSprite___c__DisplayClass3.as(28): col: 105 Error:
            // Implicit coercion of a value of type __AS3__.vec:Vector.<flash.net:InterfaceAddress>
            // to an unrelated type __AS3__.vec:Vector.<*>.

            //            LinqExtensions.WithEach_f7a1155f_06000022(CommonExtensions.AsEnumerable_4ebbe596_06001850(i.addresses), new __Action_1(this, __IntPtr.op_Explicit_4ebbe596_06001413(this.__ctor_b__2_f7a1155f_06000006)));
            //                                                                                                        ^



            //i.addresses.AsEnumerable().WithEach(
            //    a =>
            //    {
            //    }
            //);



            ////if (Capabilities.playerType == CapabilitiesPlayerType)
            //var s = new ServerSocket();
            //s.bind(8080);


            //s.connect +=
            //    e =>
            //    {

            //    };

            //s.listen(30);
        }
Beispiel #7
0
        public const uint ForegroundColor = 0x202020; //(uint)(0xffffff ^ BackgroundColor);

        /// <summary>
        /// Default constructor
        /// </summary>
        public FlashZIndex()
        {
            var c = new Sprite
            {
            };


            //c.graphics.beginFill(BackgroundColor);
            //c.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
            //c.graphics.endFill();

            Func <string, string, string> ToSize =
                (e, size) => "<font size='" + size + "'>" + e + "</font>";

            Func <string, string, string> ToColor =
                (e, color) => "<font color='#" + color + "'>" + e + "</font>";

            var keywords = new[] { "from", "this", " in", "orderby", " is", " descending", "select" };

            Func <string, string> Colorize =
                e =>
            {
                foreach (var keyword in keywords.OrderByDescending(i => i.Length))
                {
                    e = e.Replace(keyword, ToColor(keyword, "0000ff"));
                }

                return(e);
            };

            var t = new TextField
            {
                autoSize          = TextFieldAutoSize.LEFT,
                defaultTextFormat = new TextFormat
                {
                    size  = 15,
                    color = ForegroundColor
                },
                mouseEnabled  = false,
                filters       = new[] { new DropShadowFilter() },
                multiline     = true,
                condenseWhite = true,
                x             = 8,

                htmlText =

                    Colorize(

                        ToSize("flash zIndex example powered by <b>jsc</b>", "24") + "<br />"
                        + @"click on the background to create<br /> or drag to see zIndex in effect<br /><br />"
                        + ToColor(@"
                        from v in this.Children() <br />
                        orderby v is TextField descending, v.y, v.x <br />
                        select v
                    ", "000000")
                        )
            };

            c.AttachTo(this);
            t.AttachTo(this);

            c.doubleClickEnabled = true;

            Action Reorder =
                delegate
            {
                Action <DisplayObject, int> SetZIndex =
                    (k, i) => k.parent.setChildIndex(k, i);

                SetZIndex.ForEach(
                    from v in this.GetChildren()
                    orderby v is TextField descending, v.y, v.x
                    select v
                    );
            };

            Action ReorderThrottle = Reorder.ThrottleTo(500);

            c.click +=
                q =>
            {
                var x = q.stageX;
                var y = q.stageY;

                AddSprite(ReorderThrottle, x, y);

                ReorderThrottle();
            };

            10.To(90)(i => AddSprite(
                          ReorderThrottle,
                          stage.stageWidth * i / 100,
                          stage.stageHeight.Random(0.6, 0.9)
                          )
                      );

            Reorder();
        }
        public ApplicationSprite()
        {
            // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs

            // jsc should return before getting here from the worker
            if (!Worker.current.isPrimordial)
            {
                return;
            }

            var t = new TextField
            {
                multiline = true,
                text      = new
                {
                    __Thread.InternalPrimordialSprite,
                    this.loaderInfo.bytes.length,
                }.ToString(),
                autoSize = TextFieldAutoSize.LEFT
            };

            t.AttachTo(this);

            t.click += delegate
            {
                var sw = Stopwatch.StartNew();

                t.text = "enter click";

                __Thread tt = new Thread(
                    new ParameterizedThreadStart(
                        data =>
                {
                    // can we render audio on the background thread now?
                    // what else can AIR do on a background thread?
                    // physics?
                    // LAN calc?

                    // how can we report to the UI thread?

                    var nn = Stopwatch.StartNew();


                    int i = 0;

                    // keep core2 buzy for a while to be noticed on the task manager
                    while (nn.ElapsedMilliseconds < 10000)
                    {
                        SharedField = new
                        {
                            data,
                            i,
                            nn.ElapsedMilliseconds
                            //, Thread.CurrentThread.ManagedThreadId
                        }.ToString();

                        i++;
                    }

                    // i wonder, can we switch to UI thread via await and then back?



                    var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker");
                    // or are we to capture all fields modified within worker and only update those?
                    xfromWorker.send("message from worker " + new { SharedField });

                    // how do we signal our work is done?
                }
                        )
                    );

                tt.InternalBeforeStart =
                    w =>
                {
                    // how are we supposed to get data back from the worker?

                    var fromWorker = w.createMessageChannel(Worker.current);
                    w.setSharedProperty("fromWorker", fromWorker);

                    fromWorker.channelMessage += e =>
                    {
                        var data = (string)fromWorker.receive();

                        t.appendText(

                            "\n " + new { sw.ElapsedMilliseconds, data }.ToString()

                            );
                    };
                };

                //Thread.AllocateNamedDataSlot("").

                //Thread.SetData(
                tt.Start("hello world");
            };
        }
        public ApplicationSprite()
        {
            var t = new TextField
            {
                text     = "click on me to see console",
                autoSize = TextFieldAutoSize.LEFT
            };

            t.MoveTo(16, 16);
            t.AttachTo(this);

            t.click +=
                delegate
            {
                t.text += "\nclicked!";

                Console.WriteLine("clicked in flash!");
            };

            this.AtInitializeConsoleFormWriter = (
                Action <string> Console_Write,
                Action <string> Console_WriteLine
                ) =>
            {
                t.appendText("\nAtInitializeConsoleFormWriter");

                try
                {
                    var w = new __OutWriter();

                    var o = Console.Out;

                    var __reentry = false;

                    w.AtWrite =
                        x =>
                    {
                        o.Write(x);

                        if (!__reentry)
                        {
                            __reentry = true;
                            Console_Write(x);
                            __reentry = false;
                        }
                    };

                    w.AtWriteLine =
                        x =>
                    {
                        o.WriteLine(x);

                        if (!__reentry)
                        {
                            __reentry = true;
                            Console_WriteLine(x);
                            __reentry = false;
                        }
                    };

                    Console.SetOut(w);

                    Console.WriteLine("flash Console.WriteLine should now appear in JavaScript form!");
                    t.appendText("\nAtInitializeConsoleFormWriter done");
                }
                catch (Exception ex)
                {
                    t.appendText("\n error: " + new { ex, Console_Write, Console_WriteLine });
                }
            };
        }
        private void Initialize()
        {
            txtMain = new TextField
            {
                defaultTextFormat = new TextFormat
                {
                    font  = "Verdana",
                    align = TextFormatAlign.LEFT,
                    size  = 10,
                    color = 0xffffff
                },
                autoSize = TextFieldAutoSize.LEFT,
                text     = "0"
            };

            AddFullscreenMenu();



            EgoView = new ViewEngineBase(DefaultWidth, DefaultHeight)
            {
                FloorAndCeilingVisible = false,

                ViewPosition = new Point {
                    x = 4, y = 22
                },
                ViewDirection = 90.DegreesToRadians(),
            };

            var Portals = new List <PortalInfo>();

            EgoView.ViewDirectionChanged += () => Portals.ForEach(Portal => Portal.View.ViewDirection = EgoView.ViewDirection);

            #region create a dual portal
            var PortalA = new PortalInfo
            {
                Color      = 0xFF6A00,
                ViewVector = new Vector {
                    Direction = EgoView.ViewDirection, Position = new Point {
                        x = 4.5, y = 14
                    }
                },
                SpriteVector = new Vector {
                    Direction = EgoView.ViewDirection, Position = new Point {
                        x = 3.5, y = 20
                    }
                },
            }.AddTo(Portals);


            EgoView.Sprites.Add(PortalA.Sprite);


            var PortalB = new PortalInfo
            {
                Color        = 0xff00,
                ViewVector   = PortalA.SpriteVector,
                SpriteVector = PortalA.ViewVector,
            }.AddTo(Portals);


            EgoView.Sprites.Add(PortalB.Sprite);
            #endregion



            var Ego = default(SpriteInfo);


            EgoView.ViewPositionChanged +=
                delegate
            {
                foreach (var Portal in Portals)
                {
                    var p = EgoView.SpritesFromPointOfView.SingleOrDefault(i => i.Sprite == Portal.Sprite);

                    if (p != null)
                    {
                        if (p.Distance < Portal.Sprite.Range)
                        {
                            // we are going thro the portal, show it

                            new Bitmap(EgoView.Buffer.clone())
                            {
                                scaleX = DefaultScale,
                                scaleY = DefaultScale
                            }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

                            Assets.SoundFiles.teleport.ToSoundAsset().play();

                            // fixme: should use Ego.MovementDirection instead
                            // currently stepping backwards into the portal will behave recursivly
                            EgoView.ViewPosition = Portal.View.ViewPosition.MoveToArc(EgoView.ViewDirection, Portal.Sprite.Range + p.Distance);

                            break;
                        }
                    }
                }
            };

            var CameraView = new ViewEngineBase(64, 48)
            {
            };


            EgoView.RenderOverlay          += DrawMinimap;
            EgoView.FramesPerSecondChanged += () => txtMain.text = EgoView.FramesPerSecond + " fps " + new { EgoView.ViewPositionX, EgoView.ViewPositionY };

            EgoView.Image.AttachTo(this);

            txtMain.AttachTo(this);



            EgoView.Image.scaleX = DefaultScale;
            EgoView.Image.scaleY = DefaultScale;
            //this.filters = new[] { new BlurFilter() };


            KeyboardButton fKeyTurnLeft  = new uint[] { Keyboard.LEFT, 'j', 'J', };
            KeyboardButton fKeyTurnRight = new uint[] { Keyboard.RIGHT, 'l', 'L', };

            KeyboardButton fKeyStrafeLeft  = new uint[] { 'a', 'A' };
            KeyboardButton fKeyStrafeRight = new uint[] { 'd', 'D' };

            KeyboardButton fKeyUp   = new uint[] { Keyboard.UP, 'i', 'I', 'w', 'W' };
            KeyboardButton fKeyDown = new uint[] { Keyboard.DOWN, 'k', 'K', 's', 'S' };


            stage.keyDown +=
                e =>
            {
                var key = e.keyCode;

                fKeyStrafeLeft.ProcessKeyDown(key);
                fKeyStrafeRight.ProcessKeyDown(key);
                fKeyTurnLeft.ProcessKeyDown(key);
                fKeyTurnRight.ProcessKeyDown(key);

                fKeyUp.ProcessKeyDown(key);
                fKeyDown.ProcessKeyDown(key);
            };

            stage.keyUp +=
                e =>
            {
                var key = e.keyCode;


                fKeyStrafeLeft.ProcessKeyUp(key);
                fKeyStrafeRight.ProcessKeyUp(key);

                fKeyTurnLeft.ProcessKeyUp(key);
                fKeyTurnRight.ProcessKeyUp(key);

                fKeyUp.ProcessKeyUp(key);
                fKeyDown.ProcessKeyUp(key);
            };


            Action UpdateEgoPosition =
                delegate
            {
                if (Ego != null)
                {
                    Ego.Position  = EgoView.ViewPosition;
                    Ego.Direction = EgoView.ViewDirection;
                }
            };

            EgoView.ViewPositionChanged +=
                delegate
            {
                UpdateEgoPosition();
            };

            (1000 / 30).AtInterval(
                delegate
            {
                if (fKeyTurnRight.IsPressed)
                {
                    EgoView.ViewDirection += 10.DegreesToRadians();
                }
                else if (fKeyTurnLeft.IsPressed)
                {
                    EgoView.ViewDirection -= 10.DegreesToRadians();
                }

                if (fKeyUp.IsPressed || fKeyStrafeLeft.IsPressed || fKeyStrafeRight.IsPressed)
                {
                    var d = EgoView.ViewDirection;



                    if (fKeyStrafeLeft.IsPressed)
                    {
                        d -= 90.DegreesToRadians();
                    }
                    else if (fKeyStrafeRight.IsPressed)
                    {
                        d += 90.DegreesToRadians();
                    }


                    EgoView.MoveTo(
                        EgoView.ViewPositionX + Math.Cos(d) * 0.2,
                        EgoView.ViewPositionY + Math.Sin(d) * 0.2
                        );
                }
                else if (fKeyDown.IsPressed)
                {
                    EgoView.MoveTo(
                        EgoView.ViewPositionX + Math.Cos(EgoView.ViewDirection) * -0.2,
                        EgoView.ViewPositionY + Math.Sin(EgoView.ViewDirection) * -0.2
                        );
                }
            }
                );

            var UpdatePortals = true;

            stage.keyUp +=
                e =>
            {
                if (e.keyCode == Keyboard.V)
                {
                    UpdatePortals = !UpdatePortals;
                }

                if (e.keyCode == Keyboard.N)
                {
                    EgoView.RenderLowQualityWalls = !EgoView.RenderLowQualityWalls;
                }

                if (e.keyCode == Keyboard.M)
                {
                    DrawMinimapEnabled = !DrawMinimapEnabled;
                }

                if (e.keyCode == Keyboard.B)
                {
                    EgoView.SpritesVisible = !EgoView.SpritesVisible;
                }

                if (e.keyCode == Keyboard.F)
                {
                    EgoView.FloorAndCeilingVisible = !EgoView.FloorAndCeilingVisible;
                }

                if (e.keyCode == Keyboard.DELETE)
                {
                    EgoView.Sprites.RemoveAll(p => p != Ego);
                }
            };


            Action <Bitmap[]> BitmapsLoadedAction =
                Bitmaps =>
            {
                if (Bitmaps == null)
                {
                    throw new Exception("No bitmaps");
                }

                Func <Texture64[], Texture64[]> Reorder8 =
                    p =>
                    Enumerable.ToArray(
                        from i in Enumerable.Range(0, 8)
                        select p[(i + 6) % 8]
                        );

                var BitmapStream = Bitmaps.Select(i => (Texture64)i).GetEnumerator();

                Func <Texture64[]> Next8 =
                    delegate
                {
                    // keeping compiler happy with full delegate form

                    if (BitmapStream == null)
                    {
                        throw new Exception("BitmapStream is null");
                    }

                    return(Reorder8(BitmapStream.Take(8)));
                };


                var Stand = Next8();
                var Spawn = default(Func <SpriteInfo>);

                if (Bitmaps.Length == 8)
                {
                    Spawn = () => CreateWalkingDummy(Stand);
                }
                else
                {
                    var Walk = new[]
                    {
                        Next8(),
                        Next8(),
                        Next8(),
                        Next8(),
                    };



                    Spawn = () => CreateWalkingDummy(Stand, Walk);
                }

                Ego = Spawn();


                UpdateEgoPosition();



                stage.keyUp +=
                    e =>
                {
                    if (e.keyCode == Keyboard.SPACE)
                    {
                        var s = Spawn();

                        //s.Direction += 180.DegreesToRadians();

                        CameraView.ViewPosition  = s.Position;
                        CameraView.ViewDirection = s.Direction;
                    }

                    if (e.keyCode == Keyboard.INSERT)
                    {
                        var s = Spawn();

                        s.Direction += 180.DegreesToRadians();
                        s.Position   = Ego.Position.MoveToArc(Ego.Direction, 0.5);
                    }

                    if (e.keyCode == Keyboard.ENTER)
                    {
                        EgoView.ViewPosition = new Point {
                            x = 4, y = 22
                        };
                        EgoView.ViewDirection = 270.DegreesToRadians();
                    }



                    if (e.keyCode == Keyboard.BACKSPACE)
                    {
                        (1000 / 30).AtInterval(
                            t =>
                        {
                            EgoView.ViewDirection += 18.DegreesToRadians();

                            if (t.currentCount == 10)
                            {
                                t.stop();
                            }
                        }
                            );
                    }
                };
            };


            Assets.ZipFiles.MyZipFile
            .ToFiles()
            .Where(f => f.FileName.EndsWith(".png"))
            .ToBitmapArray(BitmapsLoadedAction);



            Assets.ZipFiles.MyStuff.ToFiles().ToBitmapDictionary(
                f =>
            {
                // ! important
                // ----------------------------------------------------
                // ! loading png via bytes affects pixel values
                // ! this is why map is in gif format

                EgoView.Map.WorldMap = Texture32.Of(f["Map1.gif"], false);

                Action <IEnumerator <Texture64.Entry>, Texture64, Action <SpriteInfo> > AddSpriteByTexture =
                    (SpaceForStuff, tex, handler) => SpaceForStuff.Take().Do(p => CreateDummy(tex).Do(handler).Position.To(p.XIndex + 0.5, p.YIndex + 0.5));

                var FreeSpaceForStuff = EgoView.Map.WorldMap.Entries.Where(i => i.Value == 0).Randomize().GetEnumerator();

                Action <Bitmap> AddSprite =
                    e => AddSpriteByTexture(FreeSpaceForStuff, e, null);

                Assets.ZipFiles.MySprites.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 3; i++)
                        {
                            AddSprite(s);
                        }
                    }
                }
                    );
                #region gold

                Assets.ZipFiles.MyGold.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    var GoldSprites = new List <SpriteInfo>();

                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 20; i++)
                        {
                            // compiler bug: get a delegate to BCL class
                            //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

                            AddSpriteByTexture(FreeSpaceForStuff, s,
                                               k =>
                            {
                                k.Range = 0.5;
                                GoldSprites.Add(k);
                            }
                                               );
                        }
                    }

                    var LastPosition = new Point();

                    EgoView.ViewPositionChanged +=
                        delegate
                    {
                        // only check for items each 0.5 distance travelled
                        if ((EgoView.ViewPosition - LastPosition).length < 0.5)
                        {
                            return;
                        }

                        Action Later = delegate { };


                        foreach (var Item in EgoView.SpritesFromPointOfView)
                        {
                            var Item_Sprite = Item.Sprite;

                            if (Item.Distance < Item_Sprite.Range)
                            {
                                if (GoldSprites.Contains(Item_Sprite))
                                {
                                    // ding-ding-ding!

                                    new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0xffff00))
                                    {
                                        scaleX = DefaultScale,
                                        scaleY = DefaultScale
                                    }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

                                    InternalGotGold();
                                    Later += () => EgoView.Sprites.Remove(Item_Sprite);
                                }
                            }
                        }

                        Later();

                        LastPosition = EgoView.ViewPosition;
                    };
                }
                    );
                #endregion

                #region ammo

                Assets.ZipFiles.ammo.ToFiles().ToBitmapArray(
                    sprites =>
                {
                    var AmmoSprites = new List <SpriteInfo>();

                    foreach (var s in sprites)
                    {
                        for (int i = 0; i < 20; i++)
                        {
                            // compiler bug: get a delegate to BCL class
                            //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

                            AddSpriteByTexture(FreeSpaceForStuff, s,
                                               k =>
                            {
                                k.Range = 0.5;
                                AmmoSprites.Add(k);
                            }
                                               );
                        }
                    }

                    var LastPosition = new Point();

                    EgoView.ViewPositionChanged +=
                        delegate
                    {
                        // only check for items each 0.5 distance travelled
                        if ((EgoView.ViewPosition - LastPosition).length < 0.5)
                        {
                            return;
                        }

                        Action Later = delegate { };


                        foreach (var Item in EgoView.SpritesFromPointOfView)
                        {
                            var Item_Sprite = Item.Sprite;

                            if (Item.Distance < Item_Sprite.Range)
                            {
                                if (AmmoSprites.Contains(Item_Sprite))
                                {
                                    // ding-ding-ding!

                                    new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0x8080ff))
                                    {
                                        scaleX = DefaultScale,
                                        scaleY = DefaultScale
                                    }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);


                                    InternalGotAmmo();


                                    Later += () => EgoView.Sprites.Remove(Item_Sprite);
                                }
                            }
                        }

                        Later();

                        LastPosition = EgoView.ViewPosition;
                    };
                }
                    );
                #endregion

                Func <string, Texture64> t =
                    texname => f[texname + ".png"];

                EgoView.FloorTexture   = t("floor");
                EgoView.CeilingTexture = t("roof");



                var DynamicTextureBitmap = new Bitmap(new BitmapData(Texture64.SizeConstant, Texture64.SizeConstant, false, 0));
                Texture64 DynamicTexture = DynamicTextureBitmap;
                uint DynamicTextureKey   = 0xffffff;

                EgoView.Map.WorldMap[2, 22] = DynamicTextureKey;
                EgoView.Map.WorldMap[3, 15] = DynamicTextureKey;


                EgoView.Map.Textures = new Dictionary <uint, Texture64>
                {
                    { 0xff0000, t("graywall") },
                    { 0x0000ff, t("bluewall") },
                    { 0x00ff00, t("greenwall") },
                    { 0x7F3300, t("woodwall") },

                    { DynamicTextureKey, DynamicTexture }
                };


                if (EgoView.CurrentTile != 0)
                {
                    throw new Exception("bad start position: " + new { EgoView.ViewPositionX, EgoView.ViewPositionY, EgoView.CurrentTile }.ToString());
                }



                CameraView.Map.WorldMap = EgoView.Map.WorldMap;
                CameraView.Map.Textures = EgoView.Map.Textures;
                CameraView.Sprites      = EgoView.Sprites;
                CameraView.ViewPosition = EgoView.ViewPosition;

                foreach (var Portal in Portals)
                {
                    Portal.View.Map.WorldMap = EgoView.Map.WorldMap;
                    Portal.View.Map.Textures = EgoView.Map.Textures;
                    Portal.View.Sprites      = EgoView.Sprites;
                    Portal.AlphaMask         = f["portalmask.png"];
                }


                EgoView.RenderScene();


                var MirrorFrame = f["mirror.png"];
                var counter     = 0;

                stage.enterFrame += e =>
                {
                    counter++;

                    if (UpdatePortals)
                    {
                        // updateing it too often causes framerate to drop

                        foreach (var Portal in Portals)
                        {
                            Portal.Update();
                        }

                        DynamicTextureBitmap.bitmapData.fillRect(DynamicTextureBitmap.bitmapData.rect, (uint)(counter * 8 % 256));
                        var m = new Matrix();

                        // to center
                        m.translate(0, 10);
                        // m.scale(0.3, 0.3);

                        CameraView.RenderScene();

                        DynamicTextureBitmap.bitmapData.draw(CameraView.Image.bitmapData, m);
                        DynamicTextureBitmap.bitmapData.draw(MirrorFrame.bitmapData);

                        DynamicTexture.Update();
                    }

                    EgoView.RenderScene();
                };
            }
                );

            AttachMovementInput(EgoView);
        }
        /// <summary>
        /// Creates a new control
        /// </summary>
        public FlashTextScreenSaver(Qoutes.DocumentList list)
        {
            if (list == null)
            {
                list = DefaultData;
            }

            var type = typeof(FlashTextScreenSaver);

            var name = type.Name;

            Console.WriteLine("type: " + name);

            //try
            //{
            //    IStyleSheet.Default.AddRule("*", "cursor: url('assets/TextScreenSaver/images/cursor.cur'), auto;", 0);

            //    IStyleSheet.Default.AddRule("html",
            //        r =>
            //        {
            //            r.style.overflow = IStyle.OverflowEnum.hidden;
            //        }
            //    );
            //}
            //catch (Exception exc)
            //{
            //    new IHTMLElement(IHTMLElement.HTMLElementEnum.div, "error: " + exc.Message.Replace(",", ", ")).AttachToDocument().style.width = "80em";
            //}

            Action <Qoutes.DocumentRef, Action <Qoutes.Document> > PrepareDocument =
                (doc, done) =>
            {
                if (doc.Document == null)
                {
                    //Native.Document.title = "loading...";

                    //Console.WriteLine("loading: " + doc.Source);

                    doc.Source.DownloadToXML <Qoutes.Document>(Qoutes.Settings.KnownTypes,
                                                               newdoc =>
                    {
                        doc.Document = newdoc;
                        done(newdoc);
                    }
                                                               );
                }
                else
                {
                    done(doc.Document);
                }
            };


            var current = list.Documents.Random();

            var abort = default(Action);
            //var kbd = new KeyboardEvents();

            var reset = default(Action);

            //kbd.left +=
            //    ev =>
            //    {
            //        kbd.Enabled = false;
            //        ev.PreventDefault();

            //        if (abort != null)
            //            abort();
            //        current = list.Documents.Previous(i => i == current);
            //        reset();
            //    };

            //kbd.right +=
            //    ev =>
            //    {
            //        kbd.Enabled = false;
            //        ev.PreventDefault();

            //        if (abort != null)
            //            abort();

            //        current = list.Documents.Next(i => i == current);
            //        reset();
            //    };

            //Native.Document.onkeydown += kbd;


            reset =
                () =>
                PrepareDocument(current,
                                doc =>
            {
                //Native.Document.title = doc.Topic.Trim();

                //var body = Native.Document.body;

                //body.style.overflow = IStyle.OverflowEnum.hidden;
                //body.style.width = "100%";
                //body.style.height = "100%";
                //body.style.fontFamily = IStyle.FontFamilyEnum.Verdana;
                ////body.style.backgroundImage = "url(assets/TextScreenSaver/powered_by_jsc.png)";
                //body.style.backgroundRepeat = "no-repeat";


                ////("BackgroundColor: " + doc.Style.BackgroundColor).ToConsole();
                ////("Color: " + doc.Style.Color).ToConsole();

                //doc.Style.ApplyTo(body.style);



                var lines = doc.Lines();

                var timer_handler = new Action <Timer>(delegate { });
                var timer_ref     = 100.AtInterval(timer_handler);

                var vectors = new List <TextField>();

                var abort_me = default(Action);

                abort_me =
                    delegate
                {
                    abort -= abort_me;

                    Console.WriteLine("aborting...");

                    timer_ref.stop();

                    vectors.ForEach(v => v.Orphanize());

                    abort_me = null;
                };

                abort += abort_me;

                Action <Action> SpawnVector =
                    done =>
                {
                    // we have been aborted
                    if (abort_me == null)
                    {
                        return;
                    }

                    var z = 0.5d.Random() + 0.5d;

                    var v = new TextField {
                        text = lines.Random()
                    };

                    // v.style.whiteSpace = IStyle.WhiteSpaceEnum.nowrap;

                    vectors.Add(v);

                    Action ApplyZ =
                        () =>
                    {
                        //v.style.fontSize = (z * 3) + "em";
                        //v.style.Opacity = z;
                        //v.style.zIndex = (z * 1000).Floor();
                    };


                    ApplyZ();

                    var x = 100d;
                    var y = 80.Random();

                    // v.style.position = IStyle.PositionEnum.absolute;

                    Action UpdatePosition =
                        () =>
                    {
                        v.x = stage.stageWidth * x;
                        v.y = stage.stageWidth * x;

                        //v.style.left = x + "%";
                        //v.style.top = y + "%";
                    };

                    UpdatePosition();

                    v.AttachTo(this);


                    var handler = default(Action <Timer>);


                    Action DisposeThisVector =
                        delegate
                    {
                        timer_handler -= handler;
                        v.FadeOutAndOrphanize();

                        done();
                    };

                    v.doubleClick +=
                        ev =>
                    {
                        DisposeThisVector();
                    };

                    var IsHover = false;

                    v.mouseDown +=
                        ev =>
                    {
                        //ev.PreventDefault();
                    };

                    v.mouseOver +=
                        delegate
                    {
                        //v.style.color = doc.Style.HoverColor;
                        IsHover = true;
                    };

                    v.mouseOut +=
                        delegate
                    {
                        //v.style.color = Color.None;
                        IsHover = false;
                    };

                    v.mouseWheelEnabled = true;
                    v.mouseWheel       +=
                        ev =>
                    {
                        z = (z + 0.02 * ev.WheelDirection()).Max(0.5).Min(1.0);

                        ApplyZ();
                    };

                    //var drag = new DragHelper(v);

                    //drag.Enabled = true;
                    //drag.DragMove +=
                    //    delegate
                    //    {
                    //        var w = Native.Window.Width;
                    //        var h = Native.Window.Height;


                    //        x = (drag.Position.X * 100 / w);
                    //        y = (drag.Position.Y * 100 / h);

                    //        UpdatePosition();

                    //        // v.style.SetLocation(drag.Position.X, drag.Position.Y);

                    //    };

                    handler =
                        timer =>
                    {
                        //if (drag.IsDrag)
                        //    return;

                        if (IsHover)
                        {
                            return;
                        }


                        x -= 0.4 * z;

                        UpdatePosition();

                        //drag.Position = new Point(v.offsetLeft, v.offsetTop);

                        if (v.GetOffsetRight() < 0)
                        {
                            DisposeThisVector();
                        }
                    };

                    timer_handler += handler;
                };

                var SpawnNextVector = SpawnVector.AsCyclic();


                var SpawnRandom = default(Action <int, int, Action>);

                SpawnRandom =
                    (counter, max, h) =>
                {
                    max.Random().ToInt32().AtDelay(
                        delegate
                    {
                        h();

                        counter--;

                        if (counter > 0)
                        {
                            SpawnRandom(counter, max, h);
                        }
                    }
                        );
                };


                SpawnRandom(doc.Count.ToInt32(), 3000, SpawnNextVector);

                //kbd.Enabled = true;
            }
                                );

            reset();
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        public FlashGoogleMapsExample()
        {
            var MyMap = this;

            // lets create a hyperlink
            var powered_by_jsc = new TextField
            {
                x = 72,
                y = 32,

                defaultTextFormat = new TextFormat
                {
                    size = 24
                },
                autoSize   = TextFieldAutoSize.LEFT,
                htmlText   = "<a href='http://jsc.sf.net' target='_blank'>powered by <b>jsc</b></a>",
                selectable = false,
                filters    = new[] { new BlurFilter() },
                textColor  = ColorWhite
            }.AttachTo(this);

            // based on http://code.google.com/p/gmaps-samples-flash/source/browse/trunk/samplecode/com/google/maps/examples/HelloWorld.as


            //MyMap.width = 500;
            //MyMap.height = 400;

            // This key is good for all URLs in this directory:
            // http://jsc.sourceforge.net/
            MyMap.key = "ABQIAAAAP8RnR45oCW_IQn841NsRUxTWTeJzEP4t7om06_BG8dFdNnzkzRSRwPJSLIikpLP_90z2Fvj1rJhFWw";

            CommonExtensions.CombineDelegate(MyMap,

                                             (MapEvent e) =>
            {
                MyMap.setCenter(new LatLng(40.736072, -73.992062), 14, MapType.HYBRID_MAP_TYPE);

                var status = new TextField
                {
                    x               = 64,
                    y               = 164,
                    autoSize        = TextFieldAutoSize.LEFT,
                    background      = true,
                    mouseEnabled    = false,
                    backgroundColor = ColorBlack,
                    textColor       = ColorWhite,
                    filters         = new[] { new GlowFilter(ColorBlack) }
                }.AttachTo(this);

                //MyMap.MapMoveStep += e =>
                //    {
                //        status.text = "move: " + e.latLng.ToString();
                //    };

                //MyMap.MapClick += e =>
                //    {
                //        status.text = "click: " + e.latLng.ToString();
                //    };
                powered_by_jsc.AttachTo(this);
            }

                                             , MapEvent.MAP_READY);



            MyMap.addControl(new ZoomControl());
            MyMap.addControl(new PositionControl());
            MyMap.addControl(new MapTypeControl());


            this.contextMenu = new ContextMenu();
            this.contextMenu.hideBuiltInItems();

            #region powered by jsc



            powered_by_jsc.mouseOver +=

                delegate
            {
                powered_by_jsc.textColor = ColorYellow;
                powered_by_jsc.filters   = new[] { new DropShadowFilter() };
            };

            powered_by_jsc.mouseOut +=
                delegate
            {
                powered_by_jsc.filters   = new[] { new BlurFilter() };
                powered_by_jsc.textColor = ColorWhite;
            };

            #endregion
        }
Beispiel #13
0
        public ApplicationSprite()
        {
            // X:\jsc.svn\examples\actionscript\FlashMP3PitchExperiment\FlashMP3PitchExperiment\Library\MP3Pitch.cs
            // X:\jsc.svn\examples\actionscript\Test\TestThreadStartInternalWorkerInvoke\TestThreadStartInternalWorkerInvoke\ApplicationSprite.cs

            // X:\jsc.svn\examples\actionscript\Test\TestThreadStart\TestThreadStart\ApplicationSprite.cs

            // jsc should return before getting here from the worker
            if (!Worker.current.isPrimordial)
                return;

            var t = new TextField
            {
                multiline = true,
                text = new
                {
                    __Thread.InternalPrimordialSprite,
                    this.loaderInfo.bytes.length,
                }.ToString(),
                autoSize = TextFieldAutoSize.LEFT
            };

            t.AttachTo(this);

            t.click += delegate
            {
                var sw = Stopwatch.StartNew();

                t.text = "enter click";



                __Thread tt = new Thread(
                    new ParameterizedThreadStart(
                        data =>
                        {
                            // can we render audio on the background thread now?
                            // what else can AIR do on a background thread?
                            // physics?
                            // LAN calc?

                            // how can we report to the UI thread?

                            var nn = Stopwatch.StartNew();


                            //int i = 0;

                            //// keep core2 buzy for a while to be noticed on the task manager
                            //while (nn.ElapsedMilliseconds < 10000)
                            //{
                            //    SharedField = new
                            //    {
                            //        data,
                            //        i,
                            //        nn.ElapsedMilliseconds
                            //        //, Thread.CurrentThread.ManagedThreadId 
                            //    }.ToString();

                            //    i++;
                            //}

                            // http://stackoverflow.com/questions/16483863/flash-workers-sample-application-not-working
                            // http://probertson.com/articles/2012/11/07/as3-concurrency-workers-use-cases-best-practices-links/

                            // i cant hear it
                            // http://stackoverflow.com/questions/11902863/can-actionscript-workers-be-used-to-play-generate-sounds-in-a-separate-thread
                            // http://flexmonkey.blogspot.com/2012/09/multi-threaded-sound-synthesis-in-flex.html

                            var p = new MP3Pitch("http://visit.abstractatech.com/assets/com.abstractatech.web.design1/AbstractatechPostProductionVersion7.mp3")
                            {
                                //_rate = p._rate
                            };

                            // i wonder, can we switch to UI thread via await and then back?



                            var xfromWorker = (MessageChannel)Worker.current.getSharedProperty("fromWorker");
                            // or are we to capture all fields modified within worker and only update those?
                            xfromWorker.send("message from worker " + new { SharedField });

                            // how do we signal our work is done?
                        }
                    )
                );

                tt.InternalBeforeStart =
                    w =>
                    {
                        // how are we supposed to get data back from the worker?

                        var fromWorker = w.createMessageChannel(Worker.current);
                        w.setSharedProperty("fromWorker", fromWorker);

                        fromWorker.channelMessage += e =>
                        {
                            var data = (string)fromWorker.receive();

                            t.appendText(

                                "\n " + new { sw.ElapsedMilliseconds, data }.ToString()

                                );

                        };
                    };

                //Thread.AllocateNamedDataSlot("").

                //Thread.SetData(
                tt.Start("hello world");
            };

        }
        public StarlingGameSpriteBase()
        {
            instance = this;

            gametime.Start();

            this.Content = new Sprite().AttachTo(this);

            this.Content_layer0_ground = new Sprite().AttachTo(this.Content);
            this.Content_layer0_tracks = new Sprite().AttachTo(this.Content);
            this.Content_layer2_shadows = new Sprite().AttachTo(this.Content);
            this.Content_layer3_buildings = new Sprite().AttachTo(this.Content);

            this.Content_layer10_hiddenforgoggles = new Sprite().AttachTo(this.Content);
            this.Content_layer10_hiddenforgoggles.visible = false;

            this.info = new TextField(
                800,
                400,
                "Welcome to Starling!"
                ) { hAlign = HAlign.LEFT, vAlign = VAlign.TOP };


			// i can see text, cannot see images?
			info.AttachTo(this);
            //info.MoveTo(72, 8);





			this.stagescale = internalscale;

            onresize(
                (w, h) =>
                {
                    stagex = w * 0.5;
                    stagey = h * 0.8;
                    stagescale = internalscale * (w) / (800.0);


                }
            );



            #region Source0
            var SourceBitmapData0 = new ScriptCoreLib.ActionScript.flash.display.BitmapData(
                // 28MB
                //64 * 2,
                //64 * 2,

                 // 50 MB
                 2048,
                 2048,
                 true, 0x00000000
            );
            var Source0TextureCount = 0;
            // where to start?
            var Source0TextureTop = 0;
            var Source0TextureLeft = 0;

            // fighting mipmapping
            var Source0Padding = 4;

			// ?
            var Source0 = new XLazy<TextureAtlas>(
                 delegate
                 {
                     var SourceTexture = Texture.fromBitmapData(SourceBitmapData0);
                     var Source = new TextureAtlas(SourceTexture);


                     return Source;
                 }
              );
            #endregion



            #region new_tex_crop
            this.new_tex_crop =
               (asset, alpha, flipx, innersize, adjustAlpha, filter) =>
               {

                   var shape = ScriptCoreLib.ActionScript.Extensions.KnownEmbeddedResources.Default[asset].ToSprite();

                   return new_texsprite_crop(shape, alpha, flipx, innersize, adjustAlpha, filter);
               };


            this.new_texsprite_crop =
               (shape, alpha, flipx, innersize, adjustAlpha, filter) =>
               {


                   //var innersize = 64;
                   // outer 400, inner 64

                   // do we need to wrap?
                   if ((Source0TextureLeft + innersize) >= 2048)
                   {
                       // if so, goto next line
                       Source0TextureTop = Source0TextureMaxBottom;
                       Source0TextureLeft = 0;
                   }

                   var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize);

                   {

                       if (filter != null)
                           shape.filters = new[] { filter };

                       // this does not work!
                       //shape.alpha = 0.3;



                       // next image will appear right to us + padding to prevent bleed
                       Source0TextureLeft += innersize + Source0Padding;
                       Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding);

                       var m = new Matrix();

                       // flip vertical?
                       if (flipx)
                       {
                           m.translate(-400, 0);
                           m.scale(-1, 1);
                       }

                       m.translate(
                           // where to draw? we need packer algorithm?
                           -(400 - rect.width) / 2 + rect.left,
                           -(400 - rect.height) / 2 + rect.top
                      );



                       // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap

                       if (adjustAlpha == null)
                           adjustAlpha = new ColorTransform();

                       adjustAlpha.alphaMultiplier = alpha;


                       // public void draw(IBitmapDrawable source, Matrix matrix, ColorTransform colorTransform, string blendMode, Rectangle clipRect);
                       //SourceBitmapData0.draw(shape, m, adjustAlpha, clipRect: rect);
                       SourceBitmapData0.draw(shape, m, adjustAlpha, null, rect);
                   }

                   var TextureIndex = Source0TextureCount;

                   Source0TextureCount++;

                   // Error	5	Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type	X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs	178	43	FlashHeatZeeker.UnitPed
                   var y = new XLazy<TextureAtlas>(
                       delegate
                       {
                           Source0.Content.addRegion(TextureIndex.ToString(), rect);

                           return Source0.Content;
                       }
                    );


                   // ???
                   return () => y.Content.getTexture(TextureIndex.ToString());
               };
            #endregion


            #region new_tex96
            this.new_tex96 =
               (shape, innersize) =>
               {

                   // outer 400, inner 64

                   // do we need to wrap?
                   if ((Source0TextureLeft + innersize) >= 2048)
                   {
                       // if so, goto next line
                       Source0TextureTop = Source0TextureMaxBottom;
                       Source0TextureLeft = 0;
                   }

                   var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize);

                   {

                       // this does not work!
                       //shape.alpha = 0.3;



                       // next image will appear right to us
                       Source0TextureLeft += innersize + Source0Padding;
                       Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding);

                       var m = new Matrix();
                       m.translate(
                           // where to draw? we need packer algorithm?
                           rect.left,
                           rect.top
                      );

                       //m.scale(64 / 400.0, 64 / 400.0);

                       // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap

                       var adjustAlpha = new ColorTransform();
                       adjustAlpha.alphaMultiplier = alpha;


                       SourceBitmapData0.draw(shape, m, adjustAlpha);
                   }

                   var TextureIndex = Source0TextureCount;

                   Source0TextureCount++;

                   // Error	5	Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type	X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs	178	43	FlashHeatZeeker.UnitPed
                   var y = new XLazy<TextureAtlas>(
                       delegate
                       {
                           Source0.Content.addRegion(TextureIndex.ToString(), rect);

                           return Source0.Content;
                       }
                    );

                   return () => y.Content.getTexture(TextureIndex.ToString());
               };
            #endregion


            //var __bmd = new ScriptCoreLib.ActionScript.flash.display.BitmapData(96, 96, true, 0x00000000);
            //__bmd.draw(new white_jsc());
            var LogoTexture = new_tex96(new white_jsc());

            onbeforefirstframe += delegate
            {
                //var count = 64;
                var count = DefaultLogoCount;

                for (int i = 0; i < count; i++)
                    for (int yi = 0; yi < count; yi++)
                    {
                        var logo = new Image(LogoTexture()) { }.AttachTo(Content);

                        {
                            var cm = new Matrix();
                            cm.rotate(random.NextDouble() * Math.PI);
                            cm.translate(i * 96, yi * 96);

                            logo.transformationMatrix = cm;
                        }
                    }
            };


            // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display3D/Context3D.html#driverInfo
            //Text = Starling.current.context.driverInfo;
            Text = "driverInfo missing";


            // how expensive is delegate call in a frame?
            onframe +=
                (stage, starling) =>
                {
                    if (this.frameid == 0)
                    {
                        if (this.onbeforefirstframe != null)
                            this.onbeforefirstframe(stage, starling);
                    }

                    this.frameid++;


                    if (!this.DisableDefaultContentDransformation)
                    {
                        var cm = new Matrix();
                        cm.scale(stagescale, stagescale);

                        if (autorotate)
                            cm.rotate(this.gametime.ElapsedMilliseconds * 0.001);

                        cm.translate(stagex, stagey);
                        this.Content.transformationMatrix = cm;
                    }


                    // does this cost us 40FPS??
                    //var texmem = (this.Source0TextureMaxBottom * 100 / 2048) + "%";

                    //this.info.text = new { this.frameid, texmem, this.Text }.ToString();

                };
        }
        public StarlingGameSpriteBase()
        {
            instance = this;

            gametime.Start();

            this.Content = new Sprite().AttachTo(this);

            this.Content_layer0_ground    = new Sprite().AttachTo(this.Content);
            this.Content_layer0_tracks    = new Sprite().AttachTo(this.Content);
            this.Content_layer2_shadows   = new Sprite().AttachTo(this.Content);
            this.Content_layer3_buildings = new Sprite().AttachTo(this.Content);

            this.Content_layer10_hiddenforgoggles         = new Sprite().AttachTo(this.Content);
            this.Content_layer10_hiddenforgoggles.visible = false;

            this.info = new TextField(
                800,
                400,
                "Welcome to Starling!"
                )
            {
                hAlign = HAlign.LEFT, vAlign = VAlign.TOP
            };


            // i can see text, cannot see images?
            info.AttachTo(this);
            //info.MoveTo(72, 8);



            this.stagescale = internalscale;

            onresize(
                (w, h) =>
            {
                stagex     = w * 0.5;
                stagey     = h * 0.8;
                stagescale = internalscale * (w) / (800.0);
            }
                );



            #region Source0
            var SourceBitmapData0 = new ScriptCoreLib.ActionScript.flash.display.BitmapData(
                // 28MB
                //64 * 2,
                //64 * 2,

                // 50 MB
                2048,
                2048,
                true, 0x00000000
                );
            var Source0TextureCount = 0;
            // where to start?
            var Source0TextureTop  = 0;
            var Source0TextureLeft = 0;

            // fighting mipmapping
            var Source0Padding = 4;

            // ?
            var Source0 = new XLazy <TextureAtlas>(
                delegate
            {
                var SourceTexture = Texture.fromBitmapData(SourceBitmapData0);
                var Source        = new TextureAtlas(SourceTexture);


                return(Source);
            }
                );
            #endregion



            #region new_tex_crop
            this.new_tex_crop =
                (asset, alpha, flipx, innersize, adjustAlpha, filter) =>
            {
                var shape = ScriptCoreLib.ActionScript.Extensions.KnownEmbeddedResources.Default[asset].ToSprite();

                return(new_texsprite_crop(shape, alpha, flipx, innersize, adjustAlpha, filter));
            };


            this.new_texsprite_crop =
                (shape, alpha, flipx, innersize, adjustAlpha, filter) =>
            {
                //var innersize = 64;
                // outer 400, inner 64

                // do we need to wrap?
                if ((Source0TextureLeft + innersize) >= 2048)
                {
                    // if so, goto next line
                    Source0TextureTop  = Source0TextureMaxBottom;
                    Source0TextureLeft = 0;
                }

                var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize);

                {
                    if (filter != null)
                    {
                        shape.filters = new[] { filter }
                    }
                    ;

                    // this does not work!
                    //shape.alpha = 0.3;



                    // next image will appear right to us + padding to prevent bleed
                    Source0TextureLeft     += innersize + Source0Padding;
                    Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding);

                    var m = new Matrix();

                    // flip vertical?
                    if (flipx)
                    {
                        m.translate(-400, 0);
                        m.scale(-1, 1);
                    }

                    m.translate(
                        // where to draw? we need packer algorithm?
                        -(400 - rect.width) / 2 + rect.left,
                        -(400 - rect.height) / 2 + rect.top
                        );



                    // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap

                    if (adjustAlpha == null)
                    {
                        adjustAlpha = new ColorTransform();
                    }

                    adjustAlpha.alphaMultiplier = alpha;


                    // public void draw(IBitmapDrawable source, Matrix matrix, ColorTransform colorTransform, string blendMode, Rectangle clipRect);
                    //SourceBitmapData0.draw(shape, m, adjustAlpha, clipRect: rect);
                    SourceBitmapData0.draw(shape, m, adjustAlpha, null, rect);
                }

                var TextureIndex = Source0TextureCount;

                Source0TextureCount++;

                // Error	5	Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type	X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs	178	43	FlashHeatZeeker.UnitPed
                var y = new XLazy <TextureAtlas>(
                    delegate
                {
                    Source0.Content.addRegion(TextureIndex.ToString(), rect);

                    return(Source0.Content);
                }
                    );


                // ???
                return(() => y.Content.getTexture(TextureIndex.ToString()));
            };
            #endregion


            #region new_tex96
            this.new_tex96 =
                (shape, innersize) =>
            {
                // outer 400, inner 64

                // do we need to wrap?
                if ((Source0TextureLeft + innersize) >= 2048)
                {
                    // if so, goto next line
                    Source0TextureTop  = Source0TextureMaxBottom;
                    Source0TextureLeft = 0;
                }

                var rect = new Rectangle(Source0TextureLeft, Source0TextureTop, innersize, innersize);

                {
                    // this does not work!
                    //shape.alpha = 0.3;



                    // next image will appear right to us
                    Source0TextureLeft     += innersize + Source0Padding;
                    Source0TextureMaxBottom = Source0TextureMaxBottom.Max(Source0TextureTop + innersize + Source0Padding);

                    var m = new Matrix();
                    m.translate(
                        // where to draw? we need packer algorithm?
                        rect.left,
                        rect.top
                        );

                    //m.scale(64 / 400.0, 64 / 400.0);

                    // http://stackoverflow.com/questions/8035717/actionscript-3-draw-with-transparency-on-a-bitmap

                    var adjustAlpha = new ColorTransform();
                    adjustAlpha.alphaMultiplier = alpha;


                    SourceBitmapData0.draw(shape, m, adjustAlpha);
                }

                var TextureIndex = Source0TextureCount;

                Source0TextureCount++;

                // Error	5	Cannot convert anonymous method to type 'FlashHeatZeeker.UnitPed.Library.Lazy<starling.textures.TextureAtlas>' because it is not a delegate type	X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\FlashHeatZeeker.UnitPed\Library\StarlingGameSpriteWithPed.cs	178	43	FlashHeatZeeker.UnitPed
                var y = new XLazy <TextureAtlas>(
                    delegate
                {
                    Source0.Content.addRegion(TextureIndex.ToString(), rect);

                    return(Source0.Content);
                }
                    );

                return(() => y.Content.getTexture(TextureIndex.ToString()));
            };
            #endregion


            //var __bmd = new ScriptCoreLib.ActionScript.flash.display.BitmapData(96, 96, true, 0x00000000);
            //__bmd.draw(new white_jsc());
            var LogoTexture = new_tex96(new white_jsc());

            onbeforefirstframe += delegate
            {
                //var count = 64;
                var count = DefaultLogoCount;

                for (int i = 0; i < count; i++)
                {
                    for (int yi = 0; yi < count; yi++)
                    {
                        var logo = new Image(LogoTexture())
                        {
                        }.AttachTo(Content);

                        {
                            var cm = new Matrix();
                            cm.rotate(random.NextDouble() * Math.PI);
                            cm.translate(i * 96, yi * 96);

                            logo.transformationMatrix = cm;
                        }
                    }
                }
            };


            // http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display3D/Context3D.html#driverInfo
            //Text = Starling.current.context.driverInfo;
            Text = "driverInfo missing";


            // how expensive is delegate call in a frame?
            onframe +=
                (stage, starling) =>
            {
                if (this.frameid == 0)
                {
                    if (this.onbeforefirstframe != null)
                    {
                        this.onbeforefirstframe(stage, starling);
                    }
                }

                this.frameid++;


                if (!this.DisableDefaultContentDransformation)
                {
                    var cm = new Matrix();
                    cm.scale(stagescale, stagescale);

                    if (autorotate)
                    {
                        cm.rotate(this.gametime.ElapsedMilliseconds * 0.001);
                    }

                    cm.translate(stagex, stagey);
                    this.Content.transformationMatrix = cm;
                }


                // does this cost us 40FPS??
                //var texmem = (this.Source0TextureMaxBottom * 100 / 2048) + "%";

                //this.info.text = new { this.frameid, texmem, this.Text }.ToString();
            };
        }