示例#1
0
        public void CallOnRefReturn()
        {
            // Both direct calls:
            GetRef <NormalStruct>().Method();
            GetRef <ReadOnlyStruct>().Method();

            // call on a copy, not the original ref:
            NormalStruct @ref = GetRef <NormalStruct>();

            @ref.Method();

            ReadOnlyStruct ref2 = GetRef <ReadOnlyStruct>();

            ref2.Method();
        }
    // Use this for initialization
    void Start()
    {
        animator     = GetComponent <Animator>();
        dmg          = GetComponent <Damage>();
        PlayerSprite = GetComponent <SpriteRenderer>();
        cam          = Camera.main.gameObject;
        //st = cam.GetComponent<samplestruct>();
        switch (SceneManager.GetActiveScene().name)
        {
        case "Tutorial Full":
            scene = 1;
            GameObject item0 = GameObject.Find("Items_Tutorial");
            st = item0.GetComponent <samplestruct>();
            break;

        case "Normal Full":
            scene = 2;
            Debug.Log("Normal Full");
            GameObject item1 = GameObject.Find("Items_Normal");
            ns = item1.GetComponent <NormalStruct>();
            break;

        case "Hard Full":
            scene = 3;
            GameObject item2 = GameObject.Find("Items_Hard");
            hs = item2.GetComponent <HardStruct>();
            sw = GameObject.Find("Room 2").GetComponent <StageWall>();
            ss = GameObject.Find("Switch").GetComponent <StageSwitch>();
            break;
        }

        /*
         * GameObject item = GameObject.Find("Items");
         * st = item.GetComponent<samplestruct>();
         */
        pp = GetComponent <PlayerParameter>();
        GameObject canvas = GameObject.Find("Canvas");

        mw = canvas.GetComponent <MessageWindow>();


        //Debug.Log(st.Items);
    }
示例#3
0
    Upcall.ccn_upcall_res WriteCallback(IntPtr selfp, Upcall.ccn_upcall_kind kind, IntPtr info)
    {
        print("WriteCallback... " + kind);
        Upcall.ccn_upcall_res ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_OK;

        Egal.ccn_upcall_info Info = new Egal.ccn_upcall_info();
        Info = (Egal.ccn_upcall_info)Marshal.PtrToStructure(info, typeof(Egal.ccn_upcall_info));
        IntPtr h = Info.h;

        Egal.ccn_closure Selfp = new Egal.ccn_closure();
        Selfp = (Egal.ccn_closure)Marshal.PtrToStructure(selfp, typeof(Egal.ccn_closure));
        NormalStruct Data = new NormalStruct();

        Data = (NormalStruct)Marshal.PtrToStructure(Selfp.data, typeof(NormalStruct));

        switch (kind)
        {
        case Upcall.ccn_upcall_kind.CCN_UPCALL_FINAL:
            // Marshal.FreeHGlobal(selfp); // this again, will make Unity crash
            break;

        case Upcall.ccn_upcall_kind.CCN_UPCALL_INTEREST:


            PutContent(h, Data);             // publish content
            ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_INTEREST_CONSUMED;
            break;

        case Upcall.ccn_upcall_kind.CCN_UPCALL_CONTENT:
            // repo first returns a content...
            // this is info of the repo...
            break;

        default:
            ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_ERR;
            break;
        }

        // print ("ref count: " + Selfp.refcount);
        // print ("WriteCallback returnning..." + ret);
        return(ret);
    }
示例#4
0
    void WriteToRepo(IntPtr h, System.String name, System.String content)
    {
        print("Writing " + name + " to repo: " + content);

        int res;

        IntPtr cb  = Egal.ccn_charbuf_create();
        IntPtr nm  = Egal.ccn_charbuf_create();
        IntPtr cmd = Egal.ccn_charbuf_create();

        Egal.ccn_name_from_uri(nm, name);
        Egal.ccn_create_version(h, nm, VersioningFlags.CCN_V_NOW, 0, 0);

        NormalStruct Data  = new NormalStruct(nm, cb, h, content.Length, content);
        IntPtr       pData = Marshal.AllocHGlobal(Marshal.SizeOf(Data));

        Marshal.StructureToPtr(Data, pData, true);

        IntPtr template = Egal.SyncGenInterest(IntPtr.Zero, 1, 4, -1, -1, IntPtr.Zero);

        Egal.ccn_closure Action = new Egal.ccn_closure(WriteCallback, pData, 0);
        IntPtr           pnt    = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pnt, true);

        res = Egal.ccn_set_interest_filter(h, nm, pnt);         // listen: interest

        res = Egal.ccn_charbuf_append_charbuf(cmd, nm);
        res = Egal.ccn_name_from_uri(cmd, "%C1.R.sw");
        Egal.ccn_name_append_nonce(cmd);

        counter_for_run++;
        res = Egal.ccn_set_run_timeout(h, 0);
        Egal.ccn_express_interest(h, cmd, pnt, template);         // express interest
        counter_for_run--;

        return;
    }
示例#5
0
    int RegisterInterestFilter(IntPtr h, string name)
    {
        int    res = 0;
        IntPtr nm  = Egal.ccn_charbuf_create();

        res = Egal.ccn_name_from_uri(nm, name);
        if (res < 0)
        {
            return(res);
        }

        NormalStruct State  = new NormalStruct(nm, IntPtr.Zero, h, 0, "");
        IntPtr       pState = Marshal.AllocHGlobal(Marshal.SizeOf(State));

        Marshal.StructureToPtr(State, pState, true);

        Egal.ccn_closure Action  = new Egal.ccn_closure(PublishState, pState, 0);
        IntPtr           pAction = Marshal.AllocHGlobal(Marshal.SizeOf(Action));

        Marshal.StructureToPtr(Action, pAction, true);

        res = Egal.ccn_set_interest_filter(h, nm, pAction);
        return(res);
    }
示例#6
0
    int PutContent(IntPtr h, NormalStruct Data)
    {
        int res = 0;

        Egal.ccn_charbuf Nm = new Egal.ccn_charbuf();
        Nm = (Egal.ccn_charbuf)Marshal.PtrToStructure(Data.nm, typeof(Egal.ccn_charbuf));

        IntPtr uri = Egal.ccn_charbuf_create();

        Egal.ccn_uri_append(uri, Nm.buf, Nm.length, 0);

        IntPtr name = Egal.SyncCopyName(Data.nm);
        IntPtr cb   = Egal.ccn_charbuf_create();
        IntPtr cob  = Egal.ccn_charbuf_create();

        Egal.ccn_charbuf_append(cb, Data.value, Data.vSize);
        Egal.ccn_charbuf Cb = new Egal.ccn_charbuf();
        Cb = (Egal.ccn_charbuf)Marshal.PtrToStructure(cb, typeof(Egal.ccn_charbuf));

        Egal.ccn_signing_params Sp = new Egal.ccn_signing_params(CCN.CCN_API_VERSION);
        Sp.sp_flags |= SP.signingparameters.CCN_SP_FINAL_BLOCK;
        IntPtr pSp = Marshal.AllocHGlobal(Marshal.SizeOf(Sp));

        Marshal.StructureToPtr(Sp, pSp, true);

        /*
         * // test zone
         * Egal.ccn_signing_params Test = new Egal.ccn_signing_params(CCN.CCN_API_VERSION);
         * IntPtr pTest = Marshal.AllocHGlobal(Marshal.SizeOf(Test));
         * Marshal.StructureToPtr(Test, pTest, true);
         * IntPtr a = IntPtr.Zero;
         * IntPtr b = IntPtr.Zero;
         * IntPtr c = IntPtr.Zero;
         * res = Egal.ccn_chk_signing_params(h, pSp, pTest, ref a, ref b, ref c);
         * print ("check result: " + res);
         * // test zone end
         */

        // Data.ccn, Cb.buf, Data.vSize is correct
        res |= Egal.ccn_sign_content(h, cob, name, pSp, Cb.buf, Data.vSize);
        if (res < 0)
        {
            print("sign content error.");
        }

        Egal.ccn_charbuf Cob = new Egal.ccn_charbuf();
        Cob  = (Egal.ccn_charbuf)Marshal.PtrToStructure(cob, typeof(Egal.ccn_charbuf));
        res |= Egal.ccn_put(Data.ccn, Cob.buf, Cob.length);
        if (res < 0)
        {
            print("ccn_put error.");
        }

        // cleanup
        Egal.ccn_charbuf_destroy(ref uri);
        Egal.ccn_charbuf_destroy(ref name);
        Egal.ccn_charbuf_destroy(ref cb);
        Egal.ccn_charbuf_destroy(ref cob);
        Marshal.FreeHGlobal(pSp);

        return(res);
    }
示例#7
0
    void WriteToRepo(System.String name, System.String content)
    {
        print ("Writing " + name + " to repo: " + content);

        int res;
        IntPtr h = GetHandle();
        IntPtr cb = Egal.ccn_charbuf_create();
        IntPtr nm = Egal.ccn_charbuf_create();
        IntPtr cmd = Egal.ccn_charbuf_create();

        Egal.ccn_name_from_uri(nm, name);
        Egal.ccn_create_version(h, nm, VersioningFlags.CCN_V_NOW, 0, 0);

        NormalStruct Data = new NormalStruct(nm, cb, h, content.Length, content);
        IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(Data));
        Marshal.StructureToPtr(Data, pData, true);

        IntPtr template = Egal.SyncGenInterest(IntPtr.Zero, 1, 4, -1, -1, IntPtr.Zero);

        Egal.ccn_closure Action = new Egal.ccn_closure(WriteCallback, pData, 0);
        IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(Action));
        Marshal.StructureToPtr(Action, pnt, true);

        res = Egal.ccn_set_interest_filter(h, nm, pnt); // listen: interest

        res = Egal.ccn_charbuf_append_charbuf(cmd, nm);
        res = Egal.ccn_name_from_uri(cmd, "%C1.R.sw");
        Egal.ccn_name_append_nonce(cmd);

        Egal.ccn_express_interest(h, cmd, pnt, template); // express interest

        Egal.ccn_run(h,-1);

        Egal.ccn_destroy(ref h);
    }
示例#8
0
    Upcall.ccn_upcall_res WriteCallback(IntPtr selfp, Upcall.ccn_upcall_kind kind, IntPtr info)
    {
        print("WriteCallback... " + kind);
        Upcall.ccn_upcall_res ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_OK;

        Egal.ccn_upcall_info Info = new Egal.ccn_upcall_info();
        Info = (Egal.ccn_upcall_info)Marshal.PtrToStructure(info, typeof(Egal.ccn_upcall_info));
        IntPtr h = Info.h;

        Egal.ccn_closure Selfp = new Egal.ccn_closure();
        Selfp = (Egal.ccn_closure)Marshal.PtrToStructure(selfp, typeof(Egal.ccn_closure));
        NormalStruct Data = new NormalStruct();
        Data = (NormalStruct) Marshal.PtrToStructure(Selfp.data, typeof(NormalStruct));

        switch(kind)
        {
        case Upcall.ccn_upcall_kind.CCN_UPCALL_FINAL:
           	// Marshal.FreeHGlobal(selfp); // this again, will make Unity crash
            break;

        case Upcall.ccn_upcall_kind.CCN_UPCALL_INTEREST:
            // print ("put content handle: " + h + ", content: " + Data.value);
            int res = PutContent(h, Data);
            if(res >= 0)
            {
                ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_INTEREST_CONSUMED;
                Egal.ccn_set_run_timeout(h, 0);
            }
            else
                print("put content error");

            break;

        case Upcall.ccn_upcall_kind.CCN_UPCALL_CONTENT:
            // repo first returns a content...
            // this is info of the repo...
            break;

        default:
            ret = Upcall.ccn_upcall_res.CCN_UPCALL_RESULT_ERR;
            break;
        }

        // print ("ref count: " + Selfp.refcount);
        // print ("WriteCallback returnning..." + ret);

        return ret;
    }
示例#9
0
    int PutContent(IntPtr h, NormalStruct Data)
    {
        int res = 0;

        Egal.ccn_charbuf Nm = new Egal.ccn_charbuf();
        Nm = (Egal.ccn_charbuf)Marshal.PtrToStructure(Data.nm, typeof(Egal.ccn_charbuf));
        IntPtr uri = Egal.ccn_charbuf_create();
        Egal.ccn_uri_append(uri, Nm.buf, Nm.length, 0);

        IntPtr name = Egal.SyncCopyName(Data.nm);

        // test probe //
        Egal.ccn_charbuf Name = new Egal.ccn_charbuf();
        Name = (Egal.ccn_charbuf)Marshal.PtrToStructure(name, typeof(Egal.ccn_charbuf));
        //print("Name length before numeric: " + Name.length);
        // end test probe //

        res = Egal.ccn_name_append_numeric(name, Marker.ccn_marker.CCN_MARKER_SEQNUM, 0);

        // test probe //
        Name = (Egal.ccn_charbuf)Marshal.PtrToStructure(name, typeof(Egal.ccn_charbuf));
        //print("Name length after numeric: " + Name.length);
        //print ("size of enum type is: " + sizeof(Marker.ccn_marker));
        // end test probe //

        //print("append numeric returns: " + res);
        //print(Marker.ccn_marker.CCN_MARKER_SEQNUM);

        IntPtr cb = Egal.ccn_charbuf_create();
        Egal.ccn_charbuf_append(cb, Data.value, Data.vSize);
        Egal.ccn_charbuf Cb = new Egal.ccn_charbuf();
        Cb = (Egal.ccn_charbuf)Marshal.PtrToStructure(cb, typeof(Egal.ccn_charbuf));

        Egal.ccn_signing_params Sp = new Egal.ccn_signing_params(CCN.CCN_API_VERSION);
        Sp.sp_flags |= SP.signingparameters.CCN_SP_FINAL_BLOCK;
        IntPtr pSp = Marshal.AllocHGlobal(Marshal.SizeOf(Sp));
        Marshal.StructureToPtr(Sp, pSp, true);

        // Data.ccn, Cb.buf, Data.vSize is correct

        IntPtr cob = Egal.ccn_charbuf_create();

        res = Egal.ccn_sign_content(h, cob, name, pSp, Cb.buf, Data.vSize);
        if(res<0) print ("sign content error.");

        Egal.ccn_charbuf Cob = new Egal.ccn_charbuf();
        Cob = (Egal.ccn_charbuf)Marshal.PtrToStructure(cob, typeof(Egal.ccn_charbuf));

        res = Egal.ccn_put(Data.ccn, Cob.buf, Cob.length);
        if (res<0) print ("ccn_put error.");

        // cleanup
        Egal.ccn_charbuf_destroy(ref uri);
        Egal.ccn_charbuf_destroy(ref name);
        Egal.ccn_charbuf_destroy(ref cb);
        Egal.ccn_charbuf_destroy(ref cob);
        Marshal.FreeHGlobal(pSp);

        return res;
    }
示例#10
0
    static void ReadFromRepo(string dst)
    {
        print("Reading from the repo.");
        IntPtr ccn = GetHandle();

        IntPtr nm = Egal.ccn_charbuf_create();
        Egal.ccn_name_from_uri(nm,dst);
        Egal.ccn_create_version(ccn, nm, VersioningFlags.CCN_V_LOW, 0, 0); // without version, Unity crashes!
        //CCN_V_LOW might be right, might not!

        NormalStruct Data = new NormalStruct(nm, IntPtr.Zero, IntPtr.Zero, 0, "");
        IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(Data));
        Marshal.StructureToPtr(Data, pData, true);

        IntPtr template = Egal.SyncGenInterest(IntPtr.Zero, 1, 4, -1, -1, IntPtr.Zero);

        Egal.ccn_closure Action = new Egal.ccn_closure(ReadCallback, pData, 0);
        IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(Action));
        Marshal.StructureToPtr(Action, pnt, true);

        Egal.ccn_express_interest(ccn,nm,pnt,template);
        Egal.ccn_run(ccn,-1);

        Egal.ccn_destroy(ref ccn);
    }
示例#11
0
 public void Method(NormalStruct f)
 {
 }