Esempio n. 1
0
    protected override void copyData()
    {
        base.copyData();
        PosData nowPosTemp = nowPos;

        if (nowPosTemp != null)
        {
            this.nowPos = (PosData)BytesControl.createData(PosData.dataID);
            this.nowPos.copy(nowPosTemp);
        }
        else
        {
            this.nowPos = null;
        }

        PosData targetPosTemp = targetPos;

        if (targetPosTemp != null)
        {
            this.targetPos = (PosData)BytesControl.createData(PosData.dataID);
            this.targetPos.copy(targetPosTemp);
        }
        else
        {
            this.targetPos = null;
            nullObjError("targetPos");
        }
    }
Esempio n. 2
0
    /// <summary>
    /// 读取字节流(简版)
    /// </summary>
    protected override void toReadBytesSimple(BytesReadStream stream)
    {
        this.type = stream.readInt();

        this.targetInstanceID = stream.readInt();

        if (stream.readBoolean())
        {
            this.pos = (PosData)stream.createData(PosData.dataID);
            this.pos.readBytesSimple(stream);
        }
        else
        {
            this.pos = null;
        }

        if (stream.readBoolean())
        {
            this.dir = (DirData)stream.createData(DirData.dataID);
            this.dir.readBytesSimple(stream);
        }
        else
        {
            this.dir = null;
        }

        this.arg = stream.readInt();
    }
Esempio n. 3
0
        /// <summary>
        /// Determines whether the given PhraseNode overlaps with the given word.
        /// The two overlap if the last word of the phrase is the same as the given word,
        /// or if the second-to-last word of the phrase is the same as the given word and the last word of the phrase is ignorable.
        /// </summary>
        /// <param name="name">The phrase to check for overlap.</param>
        /// <param name="word">The word to check for overlap with.</param>
        /// <returns>True if the phrase and word overlap, False otherwise.</returns>
        private bool HasOverlap(PhraseNode name, string word)
        {
            if (name == null || name.Size() == 0 || string.IsNullOrEmpty(word))
            {
                return(false);
            }

            bool hasOverlap = false;

            if (string.Equals(name.LastWord().Text, word, StringComparison.InvariantCultureIgnoreCase))
            {
                //last word of name is same as given word
                hasOverlap = true;
            }
            else if (name.Size() > 1)
            {
                if (string.Equals(name[name.Size() - 2].Text, word, StringComparison.InvariantCultureIgnoreCase) &&
                    PosData.IsIgnorableHeadWord(name.LastWord().Text))
                {
                    //second-to-last word of name is same as given word, and the last word of name is ignorable
                    hasOverlap = true;
                }
            }

            return(hasOverlap);
        }
Esempio n. 4
0
        public override void getRandomWalkablePos(int moveType, PosData re, PosData from, float radius)
        {
            if (!_g13)
            {
                _m13 = instance.Type.GetMethod("getRandomWalkablePos", 4);
                _g13 = true;
            }

            if (_m13 != null && !_b13)
            {
                _b13   = true;
                _p4[0] = moveType;
                _p4[1] = re;
                _p4[2] = from;
                _p4[3] = radius;
                appdomain.Invoke(_m13, instance, _p4);
                _p4[0] = null;
                _p4[1] = null;
                _p4[2] = null;
                _p4[3] = null;
                _b13   = false;
            }
            else
            {
                base.getRandomWalkablePos(moveType, re, from, radius);
            }
        }
Esempio n. 5
0
    /// <summary>
    /// 复制(深拷贝)
    /// </summary>
    protected override void toCopy(BaseData data)
    {
        if (!(data is SkillTargetData))
        {
            return;
        }

        SkillTargetData mData = (SkillTargetData)data;

        this.type = mData.type;

        this.targetInstanceID = mData.targetInstanceID;

        if (mData.pos != null)
        {
            this.pos = (PosData)BytesControl.createData(PosData.dataID);
            this.pos.copy(mData.pos);
        }
        else
        {
            this.pos = null;
        }

        if (mData.dir != null)
        {
            this.dir = (DirData)BytesControl.createData(DirData.dataID);
            this.dir.copy(mData.dir);
        }
        else
        {
            this.dir = null;
        }

        this.arg = mData.arg;
    }
Esempio n. 6
0
        public override void findRayPos(int moveType, PosData re, PosData from, float direction, float length)
        {
            if (!_g11)
            {
                _m11 = instance.Type.GetMethod("findRayPos", 5);
                _g11 = true;
            }

            if (_m11 != null && !_b11)
            {
                _b11   = true;
                _p5[0] = moveType;
                _p5[1] = re;
                _p5[2] = from;
                _p5[3] = direction;
                _p5[4] = length;
                appdomain.Invoke(_m11, instance, _p5);
                _p5[0] = null;
                _p5[1] = null;
                _p5[2] = null;
                _p5[3] = null;
                _p5[4] = null;
                _b11   = false;
            }
            else
            {
                base.findRayPos(moveType, re, from, direction, length);
            }
        }
Esempio n. 7
0
        public override void findPath(int moveType, SList <PosData> list, PosData from, PosData target)
        {
            if (!_g12)
            {
                _m12 = instance.Type.GetMethod("findPath", 4);
                _g12 = true;
            }

            if (_m12 != null && !_b12)
            {
                _b12   = true;
                _p4[0] = moveType;
                _p4[1] = list;
                _p4[2] = from;
                _p4[3] = target;
                appdomain.Invoke(_m12, instance, _p4);
                _p4[0] = null;
                _p4[1] = null;
                _p4[2] = null;
                _p4[3] = null;
                _b12   = false;
            }
            else
            {
                base.findPath(moveType, list, from, target);
            }
        }
Esempio n. 8
0
 public void setAnchorPos(PosData pos, float radius)
 {
     _anchorPos.copyPos(pos);
     _anchorRadius    = radius;
     _isAnchorUseUnit = false;
     _anchorUnit.clear();
 }
Esempio n. 9
0
    private void toPursue(PosData pos)
    {
        //没有追击技能
        if (_pursueSkill == null)
        {
            return;
        }

        if (checkNeedBack())
        {
            return;
        }

        float d;

        //距离够了
        if ((d = _unit.pos.calculateDistanceSq(pos)) <= _pursueDistanceSq)
        {
            pursueAttack();
        }
        else
        {
            //没有移动中
            if (!_unit.move.isMoving())
            {
                //向目标移动
                _unit.move.moveTo(pos);
            }
            else
            {
                //TODO:根据位置改变路线
            }
        }
    }
Esempio n. 10
0
    //pos data
    public List <PosData> GetPosData()
    {
        List <PosData> list     = new List <PosData>();
        DataTable      DataList = new DataTable();

        cmd.CommandText = "SELECT * FROM PosELP";
        adapter         = new SqlDataAdapter(cmd);
        adapter.Fill(DataList);

        foreach (DataRow item in DataList.Rows)
        {
            PosData data = new PosData();
            data.PointNo  = item["PointNo"].ToString();
            data.Station  = item["Station"].ToString();
            data.Area     = item["Area"].ToString();
            data.Factor1  = (item["Factor1"]).ToString();
            data.Factor2  = (item["Factor2"]).ToString();
            data.Factor3  = (item["Factor3"]).ToString();
            data.IniRead1 = (item["IniRead1"]).ToString();
            data.IniRead2 = (item["IniRead2"]).ToString();
            data.IniRead3 = (item["IniRead3"]).ToString();
            data.InsDate  = item["InsDate"].ToString();
            data.IniDate  = item["IniDate"].ToString();
            data.Alert    = (item["Alert"]).ToString();
            data.Alarm    = (item["Alarm"]).ToString();
            data.Action   = (item["Action"]).ToString();
            data.Rem1     = item["Rem1"].ToString();
            data.Rem2     = item["Rem2"].ToString();
            data.Rem3     = item["Rem3"].ToString();
            list.Add(data);
        }

        return(list);
    }
Esempio n. 11
0
    /// <summary>
    /// 读取字节流(简版)
    /// </summary>
    protected override void toReadBytesSimple(BytesReadStream stream)
    {
        base.toReadBytesSimple(stream);

        this.pos = (PosData)stream.createData(PosData.dataID);
        this.pos.readBytesSimple(stream);
    }
Esempio n. 12
0
    /// <summary>
    /// 回池
    /// </summary>
    protected override void toRelease(DataPool pool)
    {
        base.toRelease(pool);

        this.type = 0;
        if (this.nowPos != null)
        {
            this.nowPos.release(pool);
            this.nowPos = null;
        }
        if (this.targets != null)
        {
            if (!this.targets.isEmpty())
            {
                PosData[] targetsVValues = this.targets.getValues();
                for (int targetsVI = 0, targetsVLen = this.targets.length(); targetsVI < targetsVLen; ++targetsVI)
                {
                    PosData targetsV = targetsVValues[targetsVI];
                    targetsV.release(pool);
                    targetsV = null;
                    targetsVValues[targetsVI] = null;
                }
            }
            this.targets.justClearSize();
        }
    }
Esempio n. 13
0
        public static void LoadCategoriesView(TreeView target, PosData.CategoriesDataTable source)
        {
            var roots = from p in source
                        select p;
            target.BeginUpdate();
            TreeNode currentNode = null;
            foreach (PosData.CategoriesRow row in roots)
            {
                if (row.ParentId == 0)//root nodes only
                {
                    currentNode = new TreeNode(row.CategoryName, 0, 0);
                    currentNode.Tag = row.CategoryId;
                    target.Nodes.Add(currentNode);
                }

                var current = from c in source
                              where c.ParentId == row.CategoryId && c.ParentId != 0L
                              select c;
                if (current != null && current.Count<PosData.CategoriesRow>() > 0)
                {
                    _LoadCategoriesView(currentNode, current, source);
                }

            }
            target.EndUpdate();
        }
Esempio n. 14
0
 /** 单位更改位置 */
 public virtual void onSetPos(PosData pos)
 {
     if (_bullet != null && _transform != null)
     {
         _transform.position = pos.getVector();
     }
 }
    /// <summary>
    /// 回池
    /// </summary>
    protected override void toRelease(DataPool pool)
    {
        base.toRelease(pool);

        this.pos.release(pool);
        this.pos = null;
    }
Esempio n. 16
0
    public bool UpdateDataPos(PosData data)
    {
        bool isOk = false;

        cmd.CommandText = "UPDATE PosELP " +
                          "SET [Station] = '" + data.Station +
                          "',[Area] = '" + data.Area +
                          "',[Factor1] = '" + data.Factor1 +
                          "',[Factor2] = '" + data.Factor2 +
                          "',[Factor3] = '" + data.Factor3 +
                          "',[IniRead1] = '" + data.IniRead1 +
                          "',[IniRead2] = '" + data.IniRead2 +
                          "',[IniRead3] = '" + data.IniRead3 +
                          "',[InsDate] = '" + data.InsDate +
                          "',[IniDate] = '" + data.IniDate +
                          "',[Alert] = '" + data.Alert +
                          "',[Alarm] = '" + data.Alarm +
                          "',[Action] = '" + data.Action +
                          "',[ReM1] = '" + data.Rem1 +
                          "',[ReM2] = '" + data.Rem2 +
                          "',[ReM3] = '" + data.Rem3 +
                          "' WHERE [PointNo] = '" + data.PointNo + "'";

        con.Open();
        read = cmd.ExecuteReader();
        isOk = read.HasRows ? true : isOk;
        read.Close();
        con.Close();
        return(isOk);
    }
Esempio n. 17
0
        // We use the column at world center to paint nearby tiles based on the player's proximity to the nearest entry in the map.
        // In this case, the nearest entry should correspond to the player's depth.
        public void UpdateFromNearestInMap(Player player)
        {
            // Get player position in tile coordinates
            Point z = player.position.ToTileCoordinates();

            // Search for an entry within 32 tiles of our player
            if (PosData.NearbySearchOrderedPosMap(myMap, z, 32, out var entry))
            {
                // If found, we grab the data from the corresponding output index
                var data = entry.value;

                // We then proceed to paint a 5x2 area around the player position with our locational custom values.
                for (int i = -2; i < 3; i++)
                {
                    for (int j = 0; j < 2; j++)
                    {
                        Tile tile = Main.tile[z.X + i, z.Y + j];
                        if (tile.IsActive)
                        {
                            tile.Color = data;
                        }
                    }
                }
            }
        }
Esempio n. 18
0
    public bool InsertDataPos(PosData data)
    {
        bool isOk = false;

        cmd.CommandText = "INSERT INTO PosELP VALUES('" +
                          data.PointNo + "'" +
                          ",'" + data.Station +
                          "', '" + data.Area +
                          "', '" + data.Factor1 +
                          "', '" + data.Factor2 +
                          "', '" + data.Factor3 + "', NULL, NULL, NULL" +
                          ", '" + data.IniRead1 +
                          "', '" + data.IniRead2 +
                          "', '" + data.IniRead3 +
                          "', '" + data.InsDate +
                          "', '" + data.IniDate +
                          "', '" + data.Alert +
                          "', '" + data.Alarm +
                          "', '" + data.Action +
                          "', '" + data.Rem1 +
                          "', '" + data.Rem2 +
                          "', '" + data.Rem3 +
                          "',NULL)";

        con.Open();
        read = cmd.ExecuteReader();
        isOk = read.HasRows ? true : isOk;
        read.Close();
        con.Close();
        return(isOk);
    }
Esempio n. 19
0
 /// <summary>
 /// 初始化初值
 /// </summary>
 public override void initDefault()
 {
     this.pos = new PosData();
     this.pos.initDefault();
     this.dir = new DirData();
     this.dir.initDefault();
 }
Esempio n. 20
0
    /// <summary>
    /// 复制(深拷贝)
    /// </summary>
    protected override void toCopy(BaseData data)
    {
        if (!(data is UnitPosData))
        {
            return;
        }

        UnitPosData mData = (UnitPosData)data;

        if (mData.pos != null)
        {
            this.pos = (PosData)BytesControl.createData(PosData.dataID);
            this.pos.copy(mData.pos);
        }
        else
        {
            this.pos = null;
            nullObjError("pos");
        }

        if (mData.dir != null)
        {
            this.dir = (DirData)BytesControl.createData(DirData.dataID);
            this.dir.copy(mData.dir);
        }
        else
        {
            this.dir = null;
            nullObjError("dir");
        }
    }
Esempio n. 21
0
    /** 取矩形战斗单位组 */
    public void getRectFightUnits(SList <Unit> list, PosData pos, DirData dir, float length, float width, float height, Unit selfUnit, bool[] influences)
    {
        list.clear();

        ScenePosLogic posLogic = _scene.pos;

        PosData tempPos = _tempPos2;
        DirData tempDir = _tempDir2;

        //向后延伸
        posLogic.polar2D(tempPos, Global.attackScopeBackLength, dir);
        posLogic.addPos2D(tempPos, pos);

        float halfWidth = width / 2f;

        float useLength = length + Global.attackScopeBackLength;

        float sq = halfWidth * halfWidth + useLength * useLength;

        Unit[] values;
        Unit   k;

        for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i)
        {
            if ((k = values[i]) != null)
            {
                PosData kPos = k.pos.getPos();

                //高度值合适
                if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height)
                {
                    float dq;
                    //在圆形范围内
                    if ((dq = posLogic.calculatePosDistanceSq2D(kPos, pos)) <= sq)
                    {
                        //符合影响类型
                        if (selfUnit.fight.checkTargetInfluence(k, influences))
                        {
                            float d = (float)Math.Sqrt(dq);

                            posLogic.calculateDirByPos2D(tempDir, tempPos, kPos);

                            float dirV = dir.direction - tempDir.direction;

                            float h = (float)(Math.Cos(dirV) * d);
                            float w = (float)(Math.Sin(dirV) * d);

                            if (Math.Abs(w) <= halfWidth)
                            {
                                if (h >= 0 && h <= useLength)
                                {
                                    list.add(k);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 22
0
    /** 取圆形最近的战斗单位组 */
    public void getCircleRandomFightUnits(SList <Unit> list, PosData pos, float radius, int max, float height, Unit selfUnit, bool[] influences)
    {
        getCircleFightUnits(list, pos, radius, height, selfUnit, influences);

        if (max > 0 && list.length() > max)
        {
            //随机排序
            int  len = list.length();
            Unit temp;

            for (int i = 0; i < max; ++i)
            {
                int j = MathUtils.randomRange(i, len);

                if (i != j)
                {
                    temp    = list[i];
                    list[i] = list[j];
                    list[j] = temp;
                }
            }

            list.cutToLength(max);
        }
    }
Esempio n. 23
0
 public void setPos(PosData pos)
 {
     if (_effect != null)
     {
         _effect.onSetPos(pos);
     }
 }
Esempio n. 24
0
    /** 取圆形战斗单位组 */
    public void getCircleFightUnits(SList <Unit> list, PosData pos, float radius, float height, Unit selfUnit, bool[] influences)
    {
        list.clear();

        ScenePosLogic posLogic = _scene.pos;
        float         sq       = radius * radius;

        Unit[] values;
        Unit   k;

        for (int i = (values = _scene.getFightUnitDic().getValues()).Length - 1; i >= 0; --i)
        {
            if ((k = values[i]) != null)
            {
                PosData kPos = k.pos.getPos();

                //高度合适
                if (height <= 0 || posLogic.getDHeight(kPos, pos) <= height)
                {
                    //在范围内
                    if (posLogic.calculatePosDistanceSq2D(kPos, pos) <= sq)
                    {
                        //符合影响类型
                        if (selfUnit.fight.checkTargetInfluence(k, influences))
                        {
                            list.add(k);
                        }
                    }
                }
            }
        }
    }
Esempio n. 25
0
 /** 从某点开始,向某朝向找寻第一个不是阻挡的点 */
 public virtual void findRayPos(int moveType, PosData re, PosData from, float direction, float length)
 {
     re.y = from.y;
     polar2D(re, length, direction);
     addPos2D(re, from);
     clampPos(re);
 }
Esempio n. 26
0
 /** 计算坐标和值(判定用) */
 public float calculatePosSum(PosData p0, PosData p1)
 {
     if (CommonSetting.is3D)
     {
         if (CommonSetting.sceneCalculateUse2D)
         {
             return(Math.Abs(p1.x - p0.x) + Math.Abs(p1.z - p0.z));
         }
         else
         {
             return(Math.Abs(p1.x - p0.x) + Math.Abs(p1.y - p0.y) + Math.Abs(p1.z - p0.z));
         }
     }
     else
     {
         if (CommonSetting.isZHeight)
         {
             return(Math.Abs(p1.x - p0.x) + Math.Abs(p1.y - p0.y));
         }
         else
         {
             return(Math.Abs(p1.x - p0.x) + Math.Abs(p1.z - p0.z));
         }
     }
 }
Esempio n. 27
0
    /** 执行特殊移动 */
    protected virtual void toExecuteSpecialMove(bool isNewOne)
    {
        //移动完了以后调用specialMoveOver();

        switch (_specialMoveType)
        {
        case UnitSpecialMoveType.Blink:
        {
            if (isNewOne)
            {
                _unit.fight.getCurrentSkillTargetDataPos(_d.baseMovePos = _baseMovePos);
                _d.specialMoveLastTime = 1;                      //1ms
            }
            else
            {
                _baseMovePos = _d.baseMovePos;
            }
        }
        break;

        case UnitSpecialMoveType.HitBack:
        {
            float dis = _specialMoveConfig.args[0];
            int   specialMoveTimeMax = (int)_specialMoveConfig.args[1];

            if (isNewOne && _unit.isDriveAll())
            {
                Unit attacker = _scene.getFightUnit(_d.specialMoveArgs[0]);

                if (attacker != null)
                {
                    //取攻击者朝向
                    _baseMoveDir.copyDir(attacker.pos.getDir());
                    //_scene.pos.calculateDirByPos(_baseMoveDir,attacker.pos.getPos(),_pos);
                }
                else
                {
                    _baseMoveDir.copyDir(_dir);
                    _scene.pos.inverseDir(_baseMoveDir);
                }

                _scene.pos.findRayPos(_moveType, _d.baseMovePos = _baseMovePos, _pos, _baseMoveDir.direction, dis);

                _d.specialMoveLastTime = specialMoveTimeMax;
            }
            else
            {
                _scene.pos.calculateDirByPos(_baseMoveDir, _pos, _baseMovePos = _d.baseMovePos);
            }

            _tempDir.copyDir(_baseMoveDir);
            _scene.pos.inverseDir(_tempDir);
            _unit.pos.setDir(_tempDir);

            _specialMoveSpeed = dis / specialMoveTimeMax;
            _scenePosLogic.calculateVectorByDir(_baseMoveSpeedVector, _baseMoveDir, _specialMoveSpeed);
        }
        break;
        }
    }
Esempio n. 28
0
            public void LoadData(TagCompound tag, TEntry[] savedEntryLookup)
            {
                using var reader = new BinaryReader(new MemoryStream(tag.GetByteArray(dataKey)));
                var builder = new PosData <ushort> .OrderedSparseLookupBuilder();

                for (int x = 0; x < Main.maxTilesX; x++)
                {
                    for (int y = 0; y < Main.maxTilesY; y++)
                    {
                        ushort saveType = reader.ReadUInt16();
                        if (saveType == 0)
                        {
                            continue;
                        }

                        var entry = savedEntryLookup[saveType];

                        // Set the type to either the existing type or the unloaded type
                        if (entry.IsUnloaded && !canPurgeOldData)
                        {
                            builder.Add(x, y, entry.type);
                        }

                        ReadData(Main.tile[x, y], entry, reader);
                    }
                }

                unloadedEntryLookup = builder.Build();
            }
Esempio n. 29
0
    /** 寻路移动到单位(主动) */
    public void moveToUnit(int unitMoveType, Unit unit, float dis)
    {
        if (!canMoveNow())
        {
            return;
        }

        if (dis < 0f)
        {
            return;
        }

        PosData pos = unit.pos.getPos();

        //相同点
        if (_d.baseMoveState == UnitBaseMoveState.MoveToPos && _moveTargetPos.isEquals(pos))
        {
            return;
        }

        _isMoveToUnit = true;
        _moveTargetUnit.setUnit(unit);

        toMoveToList(unitMoveType, pos, dis * dis);
    }
Esempio n. 30
0
    /** 寻路移动到(主动) */
    public void moveTo(int unitMoveType, PosData pos, float dis)
    {
        if (!canMoveNow())
        {
            return;
        }

        if (dis < 0f)
        {
            return;
        }

        //位置纠正
        BaseGameUtils.makeTerrainPos(pos);

        //相同点
        if (_d.baseMoveState == UnitBaseMoveState.MoveToPos && _moveTargetPos.isEquals(pos))
        {
            return;
        }

        _isMoveToUnit = false;
        _moveTargetUnit.clear();
        toMoveToList(unitMoveType, pos, MathUtils.floatEquals(dis, 0f) ? 0f:dis *dis);
    }
Esempio n. 31
0
    public override void dispose()
    {
        base.dispose();

        _scenePosLogic = null;
        _d             = null;
        _pos           = null;
        _dir           = null;

        _specialMoveConfig = null;

        _groundState  = UnitActGroundStateType.Ground;
        _isSpasticity = false;
        _isBlowHurt   = false;
        _isBlowDown   = true;

        _specialMoveConfig = null;
        _moveType          = MapMoveType.Land;

        if (_drive != null)
        {
            _drive.dispose();
        }

        _moveTargetPos.clear();

        _sendLastTime = 0;

        _moveType       = MapMoveType.Land;
        _walkSpeedRatio = 1f;
    }
Esempio n. 32
0
 private static void _LoadCategoriesView(TreeNode targetNode, EnumerableRowCollection<PosData.CategoriesRow> current, PosData.CategoriesDataTable source)
 {
     foreach (PosData.CategoriesRow row in current)
     {
         var newNode = from c in source
                       where c.ParentId == row.CategoryId && c.ParentId != 0L
                       select c;
         if (newNode != null && newNode.Count<PosData.CategoriesRow>() > 0)
         {
             _LoadCategoriesView(targetNode, newNode, source);
         }
         //root nodes
         TreeNode currentNode = new TreeNode(row.CategoryName, 0, 0);
         currentNode.Tag = row.CategoryId;
          targetNode.Nodes.Add(currentNode);
     }
 }
Esempio n. 33
0
    public static IEnumerable LookupData(SqlInt16 partsnap, SqlString phkeytable)
    {
        //string temp_partid_table = "#temp_partid_list";

        List<PosData> idPositionMap = new List<PosData>();
        using (SqlConnection connection = new SqlConnection("context connection=true"))
        {
            connection.Open();
            // Phkey -> (List of slots in that phkey)
            Dictionary<int, List<int>> phkeySlotMap = new Dictionary<int, List<int>>();
            string rebuildPhkeySlotMapString = "select phkey, slot from " + phkeytable.ToString();
            SqlCommand rebuildPhkeySlotMapCommand = new SqlCommand(rebuildPhkeySlotMapString, connection);
            SqlDataReader mapReader = rebuildPhkeySlotMapCommand.ExecuteReader();
            while (mapReader.Read())
            {
                int phkey = Int32.Parse(mapReader["phkey"].ToString());
                short slot = Int16.Parse(mapReader["slot"].ToString());
                List<int> slotList = null;
                if (!phkeySlotMap.TryGetValue(phkey, out slotList))
                {
                    slotList = new List<int>();
                }
                slotList.Add(slot);
                phkeySlotMap[phkey] = slotList;
            }
            mapReader.Close();

            string getActualDataString = "select distinct a.phkey, a.id, a.pos from SimulationDB.dbo.snaparr a, " + phkeytable.ToString() + " b where a.snapnum = @partsnap and a.phkey = b.phkey";
            SqlParameter partsnapParam2 = new SqlParameter("@partsnap", System.Data.SqlDbType.SmallInt);
            partsnapParam2.Value = partsnap;
            SqlCommand getActualDataCommand = new SqlCommand(getActualDataString, connection);
            getActualDataCommand.Parameters.Add(partsnapParam2);
            SqlDataReader dataReader = getActualDataCommand.ExecuteReader();
            while (dataReader.Read())
            {
                long[] ids = (new SqlBigIntArrayMax(new SqlBytes((byte[])dataReader["id"])).ToArray());
                SqlRealArrayMax positions = new SqlRealArrayMax(new SqlBytes((byte[])dataReader["pos"]));
                int phkey = Int32.Parse(dataReader["phkey"].ToString());
                //int[][] currentSlots = {(phkeySlotMap[phkey].ToArray())};
                //ids.GetItems(currentSlots);
                //int[] lengths = { ids.Length, 3 };
                //positions.Reshape(lengths);
                //int[] lengths[
                float[] posArray = positions.ToArray();
                foreach (short slot in phkeySlotMap[phkey])
                {
                    //PosData currentPosComps = new PosData(ids[slot], posArray[slot, 0], posArray[slot, 1], posArray[slot, 2]);
                    PosData currentPosComps = new PosData(ids[slot], posArray[slot * 3 + 0], posArray[slot * 3 + 1], posArray[slot * 3 + 2]);
                    idPositionMap.Add(currentPosComps);
                }
            }
            dataReader.Close();
        }
        return idPositionMap;
    }
Esempio n. 34
0
    public static IEnumerable LookupDataNoSlots(SqlInt16 partsnap, SqlString phkeytable, SqlInt32 numparts, SqlString temp_partid_table_name)
    {
        //string temp_partid_table = "#temp_partid_list";

        List<PosData> idPositionMap = new List<PosData>();
        using (SqlConnection connection = new SqlConnection("context connection=true"))
        {
            connection.Open();
            // Phkey -> (List of slots in that phkey)
            List<int> phkeyList = new List<int>();
            string rebuildPhkeySlotMapString = "select distinct phkey from " + phkeytable.ToString();
            SqlCommand rebuildPhkeySlotMapCommand = new SqlCommand(rebuildPhkeySlotMapString, connection);
            SqlDataReader mapReader = rebuildPhkeySlotMapCommand.ExecuteReader();
            while (mapReader.Read())
            {
                int phkey = Int32.Parse(mapReader["phkey"].ToString());
                //short slot = Int16.Parse(mapReader["slot"].ToString());
                phkeyList.Add(phkey);
            }
            mapReader.Close();

            string getFoFGroupIDsCommandString = "select partid from " + temp_partid_table_name.ToString();
            SqlCommand getFoFGroupIDsListCommand = new SqlCommand(getFoFGroupIDsCommandString, connection);
            SqlDataReader getFOFGroupIDsReader = getFoFGroupIDsListCommand.ExecuteReader();
            List<Int64> haloPartIDs = new List<Int64>();
            int numlines = 0;
            while (getFOFGroupIDsReader.Read())
            {
                haloPartIDs.Add(Int64.Parse(getFOFGroupIDsReader["partid"].ToString()));
                ++numlines;
            }
            getFOFGroupIDsReader.Close();

            string getActualDataString = "select a.phkey, a.id, a.pos from SimulationDB.dbo.snaparr a, " + phkeytable.ToString() + " b where a.snapnum = @partsnap and a.phkey = b.phkey";
            SqlParameter partsnapParam2 = new SqlParameter("@partsnap", System.Data.SqlDbType.SmallInt);
            partsnapParam2.Value = partsnap;
            SqlCommand getActualDataCommand = new SqlCommand(getActualDataString, connection);
            getActualDataCommand.Parameters.Add(partsnapParam2);
            SqlDataReader dataReader = getActualDataCommand.ExecuteReader();
            while (dataReader.Read())
            {
                List<Int64> ids = new List<Int64>((new SqlBigIntArrayMax(new SqlBytes((byte[])dataReader["id"])).ToArray()));

                SqlRealArrayMax positions = new SqlRealArrayMax(new SqlBytes((byte[])dataReader["pos"]));
                int phkey = Int32.Parse(dataReader["phkey"].ToString());

                float[] posArray = positions.ToArray();
                for (int i = 0; i < haloPartIDs.Count; ++i)
                {
                    int slot = ids.BinarySearch(haloPartIDs[i]);
                    if (slot >= 0)
                    {
                        PosData currentPosComps = new PosData(ids[slot], posArray[slot * 3 + 0], posArray[slot * 3 + 1], posArray[slot * 3 + 2]);
                        haloPartIDs.RemoveAt(i);
                        --i;
                        idPositionMap.Add(currentPosComps);
                    }
                }

            }
            dataReader.Read();
        }
        return idPositionMap;
    }