Exemple #1
0
 internal LockableSlot(LockableContext context)
 {
     _context = context;
     _parent = _context.Slot;
     _context.Slot = this;
     // --
     LockSlot<Thread> lockSlot = null;
     ThreadingHelper.SpinWaitUntil(() => _context.Context.ClaimSlot(out lockSlot));
     lockSlot.Value = Thread.CurrentThread;
     _lockSlot = lockSlot;
     _needleLocks = new List<NeedleLock<Thread>>();
 }
Exemple #2
0
        internal LockableSlot(LockableContext context)
        {
            _context      = context;
            _parent       = _context.Slot;
            _context.Slot = this;
            // --
            LockSlot <Thread> lockSlot = null;

            ThreadingHelper.SpinWaitUntil(() => _context.Context.ClaimSlot(out lockSlot));
            lockSlot.Value = Thread.CurrentThread;
            _lockSlot      = lockSlot;
            _needleLocks   = new List <NeedleLock <Thread> >();
        }
Exemple #3
0
    private int invalidInstanceId = -1;                                 // lockedOnEnemyIds[] が未使用であることを表す値.

    void Start()
    {
        // ロックオン敵機.
        lockedOnEnemys   = new GameObject[MAX_LOCKON_COUNT];
        lockedOnEnemyIds = new int[MAX_LOCKON_COUNT];
        lockonLaserIds   = new int[MAX_LOCKON_COUNT];
        lockedOnSights   = new GameObject[MAX_LOCKON_COUNT];

        // ロックオンサイトのインスタンスを取得.
        lockonSights    = new GameObject[MAX_LOCKON_COUNT];
        lockonSights[0] = lockonSight1;
        lockonSights[1] = lockonSight2;
        lockonSights[2] = lockonSight3;
        lockonSights[3] = lockonSight4;
        lockonSights[4] = lockonSight5;
        lockonSights[5] = lockonSight6;

        // playerのインスタンスを取得.
        player = GameObject.FindGameObjectWithTag("Player");

        // 索敵レーザーのコリジョン補間を取得.
        scoutingLaserMesh = GameObject.FindGameObjectWithTag("ScoutingLaserMesh");

        // 索敵レーザーの前方への線のインスタンスを取得.
        scoutingLaserLine = GameObject.FindGameObjectWithTag("ScoutingLaserLine").GetComponent <MeshRenderer>();

        // ロックオンサイトの初期化.
        this.GetComponent <TrailRenderer>().enabled = isScanOn;
        scoutingLaserLine.enabled = isScanOn;

        // LockBonusのインスタンスを取得.
        lockBonus = Navi.get().GetLockBonus();

        // LockSlotのインスタンスを取得.
        lockSlot = Navi.get().GetLockSlot();

        // PrintMessage のインスタンスを取得.
        printMessage = Navi.get().GetPrintMessage();

        // lockedOnEnemyIds[] が未使用であることを表す値.
        // 自分自身はロックオンされることはないので.
        invalidInstanceId = this.gameObject.GetInstanceID();

        for (int i = 0; i < lockedOnEnemyIds.Length; i++)
        {
            lockedOnEnemyIds[i] = invalidInstanceId;
            lockonLaserIds[i]   = invalidInstanceId;
        }
    }
    private int invalidInstanceId = -1;                 // 表示lockedOnEnemyIds[] 未被使用的值

    void Start()
    {
        // 锁定敌机
        lockedOnEnemys   = new GameObject[MAX_LOCKON_COUNT];
        lockedOnEnemyIds = new int[MAX_LOCKON_COUNT];
        lockonLaserIds   = new int[MAX_LOCKON_COUNT];
        lockedOnSights   = new GameObject[MAX_LOCKON_COUNT];

        // 获取锁定瞄准器的实例
        lockonSights    = new GameObject[MAX_LOCKON_COUNT];
        lockonSights[0] = lockonSight1;
        lockonSights[1] = lockonSight2;
        lockonSights[2] = lockonSight3;
        lockonSights[3] = lockonSight4;
        lockonSights[4] = lockonSight5;
        lockonSights[5] = lockonSight6;

        // 获取player的实例
        player = GameObject.FindGameObjectWithTag("Player");

        // 获取索敌激光的碰撞补间
        scoutingLaserMesh = GameObject.FindGameObjectWithTag("ScoutingLaserMesh");

        // 获取索敌激光前方线的实例
        scoutingLaserLine = GameObject.FindGameObjectWithTag("ScoutingLaserLine").GetComponent <MeshRenderer>();

        // 锁定瞄准器的初始化
        this.GetComponent <TrailRenderer>().enabled = isScanOn;
        scoutingLaserLine.enabled = isScanOn;

        // 获取LockBonus的实例
        lockBonus = Navi.get().GetLockBonus();

        // 获取LockSlot的实例
        lockSlot = Navi.get().GetLockSlot();

        // 获取PrintMessage 的实例
        printMessage = Navi.get().GetPrintMessage();

        // 表示lockedOnEnemyIds[] 未被使用时的值
        // 自身不会被锁定
        invalidInstanceId = this.gameObject.GetInstanceID();

        for (int i = 0; i < lockedOnEnemyIds.Length; i++)
        {
            lockedOnEnemyIds[i] = invalidInstanceId;
            lockonLaserIds[i]   = invalidInstanceId;
        }
    }
Exemple #5
0
        public bool Commit()
        {
            if (_currentTransaction != this)
            {
                throw new InvalidOperationException("Cannot commit a non-current transaction.");
            }

            ThreadingHelper.MemoryBarrier();
            try
            {
                if (!CheckValue())
                {
                    //the resources has been modified by another thread
                    return(false);
                }
                try
                {
                    ThreadingHelper.SpinWaitUntil(() => Context.ClaimSlot(out LockSlot));
                    LockSlot.Value = Thread.CurrentThread;
                    if (!Capture())
                    {
                        //Nothing to commit
                        return(true);
                    }
                    ThreadingHelper.MemoryBarrier();
                    if (!CheckCapture() || !CheckValue())
                    {
                        //the resources has been claimed by another thread
                        return(false);
                    }
                    var written = false;
                    foreach (var resource in WriteLog)
                    {
                        if (resource.Key.Commit())
                        {
                            written = true;
                        }
                        else
                        {
                            //unexpected
                            if (written)
                            {
                                // TODO - the transaction was partially written, this should not be possible.
                                System.Diagnostics.Debug.Fail("unexpected - partially committed transaction");
                            }
                            return(false);
                        }
                    }
                    return(true);
                }
                finally
                {
                    if (LockSlot != null)
                    {
                        LockSlot.Close();
                        LockSlot = null;
                    }
                }
            }
            finally
            {
                Release(false);
            }
        }
Exemple #6
0
    protected PrintMessage print_message;                               // 消息窗口

    // ================================================================ //
    // 继承于MonoBehaviour

    void    Awake()
    {
        this.lock_slot     = this.GetComponent <LockSlot>();
        this.lock_bonus    = this.GetComponent <LockBonus>();
        this.print_message = this.GetComponent <PrintMessage>();
    }