예제 #1
0
        public void Unify(RootEnvironment rootEnv, StackEntryState other, BoolRef changed)
        {
            var type = Type.Lub(rootEnv, other.Type, changed);

            var upperBound = default(TypeRef);

            if (UpperBound != null && other.UpperBound != null)
            {
                upperBound = UpperBound.Glb(rootEnv, other.UpperBound, changed);
            }
            else if (other.UpperBound != null)
            {
                upperBound = other.UpperBound;
                changed.Set();
            }
            else
            {
                upperBound = UpperBound;
            }

            if (upperBound != null && !type.IsAssignableTo(rootEnv, upperBound))
            {
                throw new InvalidOperationException("stack entries are not unifiable");
            }

            var pointsTo = PointsTo.Lub(other.PointsTo, changed);

            UpperBound = upperBound;
            Type       = type;
            PointsTo   = pointsTo;
        }
예제 #2
0
        public VariableEffects Lub(VariableEffects other, BoolRef changed)
        {
            var lubVars = new Map <Identifier, ReadWriteDomain>();

            foreach (var kv in vars)
            {
                var rw = default(ReadWriteDomain);
                if (other.vars.TryGetValue(kv.Key, out rw))
                {
                    lubVars.Add(kv.Key, kv.Value.Lub(rw, changed));
                }
                else
                {
                    lubVars.Add(kv.Key, kv.Value);
                }
            }
            foreach (var kv in other.vars)
            {
                if (!vars.ContainsKey(kv.Key))
                {
                    lubVars.Add(kv.Key, kv.Value);
                    changed.Set();
                }
            }
            return(new VariableEffects(lubVars));
        }
예제 #3
0
 public TypeRef Glb(RootEnvironment rootEnv, TypeRef other, BoolRef changed)
 {
     if (IsAssignableTo(rootEnv, other))
     {
         return(this);
     }
     else if (other.IsAssignableTo(rootEnv, this))
     {
         changed.Set();
         return(other);
     }
     else
     {
         // NOTE: As above
         if (rootEnv.Global.NullRef.IsAssignableTo(rootEnv, this) &&
             rootEnv.Global.NullRef.IsAssignableTo(rootEnv, other))
         {
             changed.Set();
             return(rootEnv.Global.NullRef);
         }
         else
         {
             throw new InvalidOperationException("types have no glb");
         }
     }
 }
예제 #4
0
        public void Unify(LogicVar <T> other, Action <T, T, BoolRef> unifyValues, BoolRef changed)
        {
            var thislv = Follow();

            other = other.Follow();

            if (thislv.id == other.id)
            {
                return;
            }

            if (thislv.value != null && other.value != null)
            {
                unifyValues(thislv.value, other.value, changed);
                other.value   = null;
                other.chained = thislv;
            }
            else if (thislv.value != null)
            {
                other.chained = thislv;
            }
            else
            {
                thislv.chained = other;
            }
        }
예제 #5
0
    internal VehicleDirection12 BestNewDirection(int dirVehicleDirection12Flags, bool turnleft, bool turnright, BoolRef retFound)
    {
        retFound.value = true;
        if (turnright)
        {
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0)
            {
                return VehicleDirection12.DownRightRight;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0)
            {
                return VehicleDirection12.UpRightUp;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0)
            {
                return VehicleDirection12.UpLeftLeft;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0)
            {
                return VehicleDirection12.DownLeftDown;
            }
        }
        if (turnleft)
        {
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0)
            {
                return VehicleDirection12.DownRightDown;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0)
            {
                return VehicleDirection12.UpRightRight;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0)
            {
                return VehicleDirection12.UpLeftUp;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0)
            {
                return VehicleDirection12.DownLeftLeft;
            }
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0) { return VehicleDirection12.DownLeftDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0) { return VehicleDirection12.DownLeftLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0) { return VehicleDirection12.DownRightDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0) { return VehicleDirection12.DownRightRight; }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalLeft) != 0) { return VehicleDirection12.HorizontalLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalRight) != 0) { return VehicleDirection12.HorizontalRight; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0) { return VehicleDirection12.UpLeftLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0) { return VehicleDirection12.UpLeftUp; }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0) { return VehicleDirection12.UpRightRight; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0) { return VehicleDirection12.UpRightUp; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalDown) != 0) { return VehicleDirection12.VerticalDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalUp) != 0) { return VehicleDirection12.VerticalUp; }

        retFound.value = false;
        return VehicleDirection12.DownLeftDown; // return null
    }
예제 #6
0
        // ----------------------------------------------------------------------
        // Stack type constraints
        // ----------------------------------------------------------------------

        private void SetUpperBound(int n, TypeRef type, BoolRef changed)
        {
            if (n >= Depth)
            {
                throw new InvalidOperationException("stack is too shallow");
            }
            innerState.Value.Stack[n].SetUpperBound(RootEnv, type.ToRunTimeType(RootEnv, true), changed);
        }
예제 #7
0
        // Return instruction to evaluate test to its boolean result, leaving an int32 on the stack.
        //  - beforeState has test operands on stack.
        //  - afterState has the test evaluated AND the resulting int32 consumed.
        // (These states came from the original brtrue, etc instruction).
        public CompareInstruction ToCompareInstruction(int offset, MachineState beforeState, MachineState afterState, PointsTo bottom)
        {
            var state1 = beforeState.PopPushType(Pops, beforeState.RootEnv.Global.Int32Ref, bottom);
            var dummy  = new BoolRef();

            state1.PropogateBackwards(afterState, dummy);
            beforeState.PropogateBackwards(state1, dummy);

            var op = default(CompareOp);

            switch (Op)
            {
            case TestOp.True:
                op = CompareOp.CtruePseudo;
                break;

            case TestOp.False:
                op = CompareOp.CfalsePseudo;
                break;

            case TestOp.Equal:
                op = CompareOp.Ceq;
                break;

            case TestOp.NotEqual:
                op = CompareOp.CnePseudo;
                break;

            case TestOp.LessThanOrEqual:
                op = CompareOp.ClePseudo;
                break;

            case TestOp.LessThan:
                op = CompareOp.Clt;
                break;

            case TestOp.GreaterThanOrEqual:
                op = CompareOp.CgePseudo;
                break;

            case TestOp.GreaterThan:
                op = CompareOp.Cgt;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(new CompareInstruction(offset, op, IsUnsigned)
            {
                Type = Type, BeforeState = beforeState, AfterState = state1
            });
        }
예제 #8
0
        public override int GetHashCode()
        {
            var hash = base.GetHashCode();

            hash ^= Readonly.GetHashCode();
            hash ^= IntId.GetHashCode();
            hash ^= UIntId.GetHashCode();
            hash ^= LongId.GetHashCode();
            hash ^= ULongId.GetHashCode();
            hash ^= ShortId.GetHashCode();
            hash ^= UShortId.GetHashCode();
            hash ^= DoulbeId.GetHashCode();
            hash ^= ByteId.GetHashCode();
            hash ^= CharId.GetHashCode();
            hash ^= SByteId.GetHashCode();
            hash ^= CharRef.GetHashCode();
            hash ^= ByteRef.GetHashCode();
            hash ^= SByteRef.GetHashCode();
            hash ^= Int16Id.GetHashCode();
            hash ^= UInt16Id.GetHashCode();
            hash ^= Int32Id.GetHashCode();
            hash ^= UInt32Id.GetHashCode();
            hash ^= Int64Id.GetHashCode();
            hash ^= UInt64Id.GetHashCode();
            hash ^= DateTime.GetHashCode();
            hash ^= TitleEnum.GetHashCode();
            hash ^= ATitleEnum.GetHashCode();
            hash ^= FirstName.GetHashCode();
            hash ^= LastName.GetHashCode();
            hash ^= Bool.GetHashCode();
            hash ^= BoolRef.GetHashCode();
            if (Array != null)
            {
                hash ^= Array.GetHashCode();
            }
            if (Enumerable != null)
            {
                hash ^= Enumerable.GetHashCode();
            }
            if (Father != null)
            {
                hash ^= Father.GetHashCode();
            }
            if (Mother != null)
            {
                hash ^= Mother.GetHashCode();
            }
            if (Hidden != null)
            {
                hash ^= Hidden.GetHashCode();
            }
            return(hash);
        }
예제 #9
0
 internal int GetTexture(string name)
 {
     if (!textures.Contains(name))
     {
         BoolRef  found   = new BoolRef();
         BitmapCi bmp     = p.BitmapCreateFromPng(GetFile(name), GetFileLength(name));
         int      texture = p.LoadTextureFromBitmap(bmp);
         textures.Set(name, texture);
         p.BitmapDelete(bmp);
     }
     return(textures.Get(name));
 }
예제 #10
0
 // This and other must always be the same state. Throw if no lub. Otherwise return true if this state changed.
 public void Unify(MachineState other, BoolRef changed)
 {
     if (RootEnv != other.RootEnv)
     {
         throw new InvalidOperationException("states must share same environment");
     }
     if (nArgs != other.nArgs || nLocals != other.nLocals)
     {
         throw new InvalidOperationException("states must have the same number of arguments and locals");
     }
     innerState.Unify(other.innerState, (l, r, c) => l.Unify(RootEnv, r, c), changed);
 }
예제 #11
0
        public void ReadPointer(ArgsLocalsState other, PointsTo pointsTo, BoolRef changed)
        {
            var newArgsAlive = other.argsAlive.Clone();

            foreach (var argIndex in pointsTo.Args.Members)
            {
                newArgsAlive[argIndex] = true;
            }
            argsAlive.UnionInPlace(newArgsAlive, changed);
            var newLocalsAlive = other.localsAlive.Clone();

            foreach (var localIndex in pointsTo.Locals.Members)
            {
                newLocalsAlive[localIndex] = true;
            }
            localsAlive.UnionInPlace(newLocalsAlive, changed);
        }
예제 #12
0
        void drawWindow1_MouseClick(MouseEventArgs e)
        {
            var oldSelected = m_selectedItem;

            m_selectedItem = null;
            float y = -greyScrollBar1.Value;

            foreach (var item in m_items)
            {
                if (e.Y >= y && e.Y <= y + item.Height)
                {
                    m_selectedItem = item;
                    break;
                }
                y += item.Height;
            }
            drawWindow1.Invalidate(true);

            if (m_selectedItem != oldSelected)
            {
                if (m_selectedItem != null)
                {
                    m_nodeIterator = m_selectedItem.Error.MakeEnumerator();
                    if (m_nodeIterator != null)
                    {
                        m_nodeIterator.MoveNext();
                    }
                }
                else
                {
                    m_nodeIterator = null;
                }
            }
            else if (m_nodeIterator != null)
            {
                m_nodeIterator.MoveNext();
            }

            if (m_nodeIterator != null && m_nodeIterator.Current != null)
            {
                BoolRef success = true;
                HightlightNode.Execute(m_nodeIterator.Current.Item1, m_nodeIterator.Current.Item2, success);
            }
        }
예제 #13
0
        public void Unify(RootEnvironment rootEnv, InnerMachineState other, BoolRef changed)
        {
            if (Stack.Count != other.Stack.Count)
            {
                throw new InvalidOperationException("stacks must have the same depth");
            }

            for (var i = 0; i < Stack.Count; i++)
            {
                Stack[i].Unify(rootEnv, other.Stack[i], changed);
            }

            if (Ids != null || other.Ids != null)
            {
                throw new InvalidOperationException("stack slot identifiers cannot be unified");
            }

            ArgsLocalsState.Unify(other.ArgsLocalsState, changed);
        }
예제 #14
0
        public void PeekBoxedType(int n, TypeRef expType, BoolRef changed)
        {
            var type = PeekType(n);
            var s    = type.Style(RootEnv);

            if (s is NullTypeStyle)
            {
                // No-op.
                // Will fail at runtime, but still ok.
                // If stack entry is generalized, it must go directly to Object.
            }
            else if (s is ReferenceTypeStyle)
            {
                if (s is ObjectTypeStyle)
                {
                    // This stack entry can never be refined away from object
                    return;
                }
                if (!(s is BoxTypeStyle))
                {
                    // Parameter types not allowed
                    throw new InvalidOperationException("stack entry is not object or a boxed type");
                }
                if (expType.Style(RootEnv) is NullableTypeStyle)
                {
                    // Account for null -> no-value coercion
                    expType = expType.Arguments[0];
                }
                expType = expType.ToRunTimeType(RootEnv, false);
                if (!type.Arguments[0].IsEquivalentTo(RootEnv, expType))
                {
                    throw new InvalidOperationException("boxed element type is not equivalent to expected type");
                }
                // Box types are NOT invariant, so need to impose upper bound
                SetUpperBound(n, RootEnv.Global.BoxTypeConstructorRef.ApplyTo(expType), changed);
            }
            else
            {
                // Parameter types not allowed
                throw new InvalidOperationException("stack entry is not object or a boxed type");
            }
        }
예제 #15
0
        public PointsTo Lub(PointsTo other, BoolRef changed)
        {
            var thisChanged = new BoolRef();
            var args        = Args.Lub(other.Args, thisChanged);
            var locals      = Locals.Lub(other.Locals, thisChanged);
            var heap        = Heap.Lub(other.Heap, thisChanged);

            if (args == null || locals == null || heap == null)
            {
                return(null);
            }
            else if (thisChanged.Value)
            {
                changed.Set();
                return(new PointsTo(args, locals, heap));
            }
            else
            {
                return(this);
            }
        }
예제 #16
0
 public void Unify(ArgsLocalsState other, BoolRef changed)
 {
     foreach (var kv in other.argLocalToPointsTo)
     {
         var pt = default(PointsTo);
         if (!kv.Value.IsBottom)
         {
             if (argLocalToPointsTo.TryGetValue(kv.Key, out pt))
             {
                 argLocalToPointsTo[kv.Key] = pt.Lub(kv.Value, changed);
             }
             else
             {
                 changed.Set();
                 argLocalToPointsTo.Add(kv.Key, kv.Value);
             }
         }
     }
     argsAlive.UnionInPlace(other.argsAlive, changed);
     localsAlive.UnionInPlace(other.localsAlive, changed);
 }
예제 #17
0
        public Effects Lub(Effects other, BoolRef changed)
        {
            var thisChanged = new BoolRef();
            var vars        = Vars.Lub(other.Vars, thisChanged);
            var heap        = Heap.Lub(other.Heap, thisChanged);
            var mayThrow    = MayThrow.Lub(other.MayThrow, thisChanged);

            if (vars == null || heap == null || mayThrow == null)
            {
                return(null);
            }
            if (thisChanged.Value)
            {
                changed.Set();
                return(new Effects(vars, heap, mayThrow));
            }
            else
            {
                return(this);
            }
        }
예제 #18
0
        public Effects Lub(Effects other, BoolRef changed)
        {
            var thisChanged = new BoolRef();
            var args        = Args.Lub(other.Args, thisChanged);
            var locals      = Locals.Lub(other.Locals, thisChanged);
            var heap        = Heap.Lub(other.Heap, thisChanged);
            var mayThrow    = MayThrow.Lub(other.MayThrow, thisChanged);

            if (args == null || locals == null || heap == null || mayThrow == null)
            {
                return(null);
            }
            else if (thisChanged.Value)
            {
                changed.Set();
                return(new Effects(args, locals, heap, mayThrow));
            }
            else
            {
                return(this);
            }
        }
예제 #19
0
 public void SourceToTargetTransition(ArgsLocalsState other, BoolRef changed)
 {
     // Any pointers in source are pointers in target
     foreach (var kv in argLocalToPointsTo)
     {
         var pt = default(PointsTo);
         if (!kv.Value.IsBottom)
         {
             if (other.argLocalToPointsTo.TryGetValue(kv.Key, out pt))
             {
                 other.argLocalToPointsTo[kv.Key] = pt.Lub(kv.Value, changed);
             }
             else
             {
                 changed.Set();
                 other.argLocalToPointsTo.Add(kv.Key, kv.Value);
             }
         }
     }
     // Anything alive in target is alive in source
     argsAlive.UnionInPlace(other.argsAlive, changed);
     localsAlive.UnionInPlace(other.localsAlive, changed);
 }
예제 #20
0
        public void SetUpperBound(RootEnvironment rootEnv, TypeRef type, BoolRef changed)
        {
            var s = type.Style(rootEnv);

            if (s is ValueTypeStyle || s is PointerTypeStyle || s is CodePointerTypeStyle)
            {
                // These types are only assignable to themselves, so no need to remember
                // the upper bound, just check it
                if (!Type.IsAssignableTo(rootEnv, type))
                {
                    if (s is UnmanagedPointerTypeStyle)
                    {
                        throw new InvalidOperationException("unmanaged pointer");
                    }
                    else
                    {
                        throw new InvalidOperationException("stack entry cannot be generalized");
                    }
                }
            }
            else
            {
                var upperBound = UpperBound == null ? type : UpperBound.Glb(rootEnv, type, changed);
                if (!Type.IsAssignableTo(rootEnv, upperBound))
                {
                    throw new InvalidOperationException("stack entry cannot be generalized");
                }
                if (!upperBound.IsEquivalentTo(rootEnv, rootEnv.Global.ObjectRef))
                {
                    if (UpperBound == null)
                    {
                        changed.Set();
                    }
                    UpperBound = upperBound;
                }
            }
        }
예제 #21
0
    public void Update(EntityPosition_ stateplayerposition, Controls move, float dt, BoolRef soundnow, Vector3Ref push, float modelheight)
    {
        if (game.stopPlayerMove)
        {
            movedz = 0;
            game.stopPlayerMove = false;
        }

        // No air control
        if (!isplayeronground)
        {
            acceleration.acceleration1 = 0.99f;
            acceleration.acceleration2 = 0.2f;
            acceleration.acceleration3 = 70;
        }

        // Trampoline
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if (blockunderplayer != -1 && blockunderplayer == game.d_Data.BlockIdTrampoline()
                && (!isplayeronground) && !game.controls.shiftkeydown)
            {
                game.controls.wantsjump = true;
                jumpstartacceleration = 20.666f * constGravity;
            }
        }

        // Slippery walk on ice and when swimming
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if ((blockunderplayer != -1 && game.d_Data.IsSlipperyWalk()[blockunderplayer]) || game.SwimmingBody())
            {
                acceleration.acceleration1 = 0.99f;
                acceleration.acceleration2 = 0.2f;
                acceleration.acceleration3 = 70;
            }
        }

        soundnow.value = false;
        Vector3Ref diff1ref = new Vector3Ref();
        VectorTool.ToVectorInFixedSystem
            (move.movedx * movespeednow * dt,
            0,
            move.movedy * movespeednow * dt, stateplayerposition.rotx, stateplayerposition.roty, diff1ref);
        Vector3Ref diff1 = new Vector3Ref();
        diff1.X = diff1ref.X;
        diff1.Y = diff1ref.Y;
        diff1.Z = diff1ref.Z;
        if (MiscCi.Vec3Length(push.X, push.Y, push.Z) > 0.01f)
        {
            push.Normalize();
            push.X *= 5;
            push.Y *= 5;
            push.Z *= 5;
        }
        diff1.X += push.X * dt;
        diff1.Y += push.Y * dt;
        diff1.Z += push.Z * dt;

        bool loaded = false;
        int cx = game.platform.FloatToInt(game.player.position.x / Game.chunksize);
        int cy = game.platform.FloatToInt(game.player.position.z / Game.chunksize);
        int cz = game.platform.FloatToInt(game.player.position.y / Game.chunksize);
        if (game.map.IsValidChunkPos(cx, cy, cz))
        {
            if (game.map.chunks[MapUtilCi.Index3d(cx, cy, cz,
                game.map.MapSizeX / Game.chunksize,
                game.map.MapSizeY / Game.chunksize)] != null)
            {
                loaded = true;
            }
        }
        else
        {
            loaded = true;
        }
        if ((!(move.freemove)) && loaded)
        {
            if (!game.SwimmingBody())
            {
                movedz += -constGravity;//gravity
            }
            else
            {
                movedz += -constGravity * constWaterGravityMultiplier; //more gravity because it's slippery.
            }
        }
        game.movedz = movedz;
        if (constEnableAcceleration)
        {
            curspeed.X *= acceleration.acceleration1;
            curspeed.Y *= acceleration.acceleration1;
            curspeed.Z *= acceleration.acceleration1;
            curspeed.X = MakeCloserToZero(curspeed.X, acceleration.acceleration2 * dt);
            curspeed.Y = MakeCloserToZero(curspeed.Y, acceleration.acceleration2 * dt);
            curspeed.Z = MakeCloserToZero(curspeed.Z, acceleration.acceleration2 * dt);
            diff1.Y += move.moveup ? 2 * movespeednow * dt : 0;
            diff1.Y -= move.movedown ? 2 * movespeednow * dt : 0;
            curspeed.X += diff1.X * acceleration.acceleration3 * dt;
            curspeed.Y += diff1.Y * acceleration.acceleration3 * dt;
            curspeed.Z += diff1.Z * acceleration.acceleration3 * dt;
            if (curspeed.Length() > movespeednow)
            {
                curspeed.Normalize();
                curspeed.X *= movespeednow;
                curspeed.Y *= movespeednow;
                curspeed.Z *= movespeednow;
            }
        }
        else
        {
            if (MiscCi.Vec3Length(diff1.X, diff1.Y, diff1.Z) > 0)
            {
                diff1.Normalize();
            }
            curspeed.X = diff1.X * movespeednow;
            curspeed.Y = diff1.Y * movespeednow;
            curspeed.Z = diff1.Z * movespeednow;
        }
        Vector3Ref newposition = Vector3Ref.Create(0, 0, 0);
        if (!(move.freemove))
        {
            newposition.X = stateplayerposition.x + curspeed.X;
            newposition.Y = stateplayerposition.y + curspeed.Y;
            newposition.Z = stateplayerposition.z + curspeed.Z;
            if (!game.SwimmingBody())
            {
                newposition.Y = stateplayerposition.y;
            }
            // Fast move when looking at the ground
            float diffx = newposition.X - stateplayerposition.x;
            float diffy = newposition.Y - stateplayerposition.y;
            float diffz = newposition.Z - stateplayerposition.z;
            float difflength = MiscCi.Vec3Length(diffx, diffy, diffz);
            if (difflength > 0)
            {
                diffx /= difflength;
                diffy /= difflength;
                diffz /= difflength;
                diffx *= curspeed.Length();
                diffy *= curspeed.Length();
                diffz *= curspeed.Length();
            }
            newposition.X = stateplayerposition.x + diffx * dt;
            newposition.Y = stateplayerposition.y + diffy * dt;
            newposition.Z = stateplayerposition.z + diffz * dt;
        }
        else
        {
            newposition.X = stateplayerposition.x + (curspeed.X) * dt;
            newposition.Y = stateplayerposition.y + (curspeed.Y) * dt;
            newposition.Z = stateplayerposition.z + (curspeed.Z) * dt;
        }
        newposition.Y += movedz * dt;
        Vector3Ref previousposition = Vector3Ref.Create(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z);
        if (!move.noclip)
        {
            float[] v = WallSlide(
                Vec3.FromValues(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z),
                Vec3.FromValues(newposition.X, newposition.Y, newposition.Z),
                modelheight);
            stateplayerposition.x = v[0];
            stateplayerposition.y = v[1];
            stateplayerposition.z = v[2];
        }
        else
        {
            stateplayerposition.x = newposition.X;
            stateplayerposition.y = newposition.Y;
            stateplayerposition.z = newposition.Z;
        }
        if (!(move.freemove))
        {
            if ((isplayeronground) || game.SwimmingBody())
            {
                jumpacceleration = 0;
                movedz = 0;
            }
            if ((move.wantsjump || move.wantsjumphalf) && (((jumpacceleration == 0 && isplayeronground) || game.SwimmingBody()) && loaded) && (!game.SwimmingEyes()))
            {
                jumpacceleration = move.wantsjumphalf ? jumpstartaccelerationhalf : jumpstartacceleration;
                soundnow.value = true;
            }

            if (jumpacceleration > 0)
            {
                isplayeronground = false;
                jumpacceleration = jumpacceleration / 2;
            }

            //if (!this.reachedceiling)
            {
                movedz += jumpacceleration * constJump;
            }
        }
        else
        {
            isplayeronground = true;
        }
        game.isplayeronground = isplayeronground;
    }
예제 #22
0
    public Game()
    {
        one = 1;
        map = new Map();
        performanceinfo = new DictionaryStringString();
        AudioEnabled = true;
        AutoJumpEnabled = false;
        playerPositionSpawnX = 15 + one / 2;
        playerPositionSpawnY = 64;
        playerPositionSpawnZ = 15 + one / 2;

        TextureId = new int[MaxBlockTypes][];
        for (int i = 0; i < MaxBlockTypes; i++)
        {
            TextureId[i] = new int[6];
        }
        TextureIdForInventory = new int[MaxBlockTypes];
        language = new Language();
        lastplacedblockX = -1;
        lastplacedblockY = -1;
        lastplacedblockZ = -1;
        mLightLevels = new float[16];
        sunlight_ = 15;
        mvMatrix = new StackMatrix4();
        pMatrix = new StackMatrix4();
        mvMatrix.Push(Mat4.Create());
        pMatrix.Push(Mat4.Create());
        whitetexture = -1;
        cachedTextTexturesMax = 1024;
        cachedTextTextures = new CachedTextTexture[cachedTextTexturesMax];
        for (int i = 0; i < cachedTextTexturesMax; i++)
        {
            cachedTextTextures[i] = null;
        }
        packetLen = new IntRef();
        ENABLE_DRAW2D = true;
        AllowFreemove = true;
        enableCameraControl = true;
        textures = new DictionaryStringInt1024();
        ServerInfo = new ServerInformation();
        menustate = new MenuState();
        mouseleftclick = false;
        mouseleftdeclick = false;
        wasmouseleft = false;
        mouserightclick = false;
        mouserightdeclick = false;
        wasmouseright = false;
        ENABLE_LAG = 0;
        znear = one / 10;
        CameraMatrix = new GetCameraMatrix();
        ENABLE_ZFAR = true;
        TotalAmmo = new int[GlobalVar.MAX_BLOCKTYPES];
        LoadedAmmo = new int[GlobalVar.MAX_BLOCKTYPES];
        AllowedFontsCount = 1;
        AllowedFonts = new string[AllowedFontsCount];
        AllowedFonts[0] = "Verdana";
        fov = Game.GetPi() / 3;
        cameratype = CameraType.Fpp;
        ENABLE_TPP_VIEW = false;
        basemovespeed = 5;
        movespeed = 5;
        RadiusWhenMoving = one * 3 / 10;
        playervelocity = new Vector3Ref();
        LocalPlayerId = -1;
        dialogs = new VisibleDialog[512];
        dialogsCount = 512;
        blockHealth = new DictionaryVector3Float();
        playertexturedefault = -1;
        a = new AnimationState();
        constRotationSpeed = one * 180 / 20;
        modmanager = new ClientModManager1();
        particleEffectBlockBreak = new ModDrawParticleEffectBlockBreak();
        PICK_DISTANCE = 4.1f;
        selectedmodelid = -1;
        grenadetime = 3;
        rotationspeed = one * 15 / 100;
        entities = new Entity[entitiesMax];
        for (int i = 0; i < entitiesMax; i++)
        {
            entities[i] = null;
        }
        entitiesCount = 512;
        PlayerPushDistance = 2;
        const int KeysMax = 256;
        keyboardState = new bool[KeysMax];
        for (int i = 0; i < KeysMax; i++)
        {
            keyboardState[i] = false;
        }
        keyboardStateRaw = new bool[KeysMax];
        for (int i = 0; i < KeysMax; i++)
        {
            keyboardStateRaw[i] = false;
        }
        overheadcameradistance = 10;
        tppcameradistance = 3;
        TPP_CAMERA_DISTANCE_MIN = 1;
        TPP_CAMERA_DISTANCE_MAX = 10;
        options = new OptionsCi();
        overheadcameraK = new Kamera();
        fillAreaLimit = 200;
        speculativeCount = 0;
        speculative = new Speculative[speculativeMax];
        typinglog = new string[1024 * 16];
        typinglogCount = 0;
        NewBlockTypes = new Packet_BlockType[GlobalVar.MAX_BLOCKTYPES];
        localplayeranim = new AnimationState();
        localplayeranimationhint = new AnimationHint();
        enable_move = true;
        handTexture = -1;
        modelViewInverted = new float[16];
        GLScaleTempVec3 = Vec3.Create();
        GLRotateTempVec3 = Vec3.Create();
        GLTranslateTempVec3 = Vec3.Create();
        identityMatrix = Mat4.Identity_(Mat4.Create());
        Set3dProjectionTempMat4 = Mat4.Create();
        getAsset = new string[1024 * 2];
        PlayerStats = new Packet_ServerPlayerStats();
        mLightLevels = new float[16];
        for (int i = 0; i < 16; i++)
        {
            mLightLevels[i] = one * i / 15;
        }
        soundnow = new BoolRef();
        camera = Mat4.Create();
        packetHandlers = new ClientPacketHandler[256];
        player = new Entity();
        player.position = new EntityPosition_();
        currentlyAttackedEntity = -1;
        ChatLinesMax = 1;
        ChatLines = new Chatline[ChatLinesMax];
        ChatLineLength = 64;
        audio = new AudioControl();
        CameraEyeX = -1;
        CameraEyeY = -1;
        CameraEyeZ = -1;
        controls = new Controls();
        movedz = 0;
        taskScheduler = new TaskScheduler();
        commitActions = ListAction.Create(16 * 1024);
        constWallDistance = 0.3f;
        mouseSmoothing = true;
    }
예제 #23
0
    internal void RailOnNewFrame(Game game, float dt)
    {
        if (localMinecart == null)
        {
            localMinecart = new Entity();
            localMinecart.minecart = new Minecart();
            game.EntityAddLocal(localMinecart);
        }
        localMinecart.minecart.enabled = railriding;
        if (railriding)
        {
            Minecart m = localMinecart.minecart;
            m.positionX = game.player.position.x;
            m.positionY = game.player.position.y;
            m.positionZ = game.player.position.z;
            m.direction = currentdirection;
            m.lastdirection = lastdirection;
            m.progress = currentrailblockprogress;
        }

        game.localplayeranimationhint.InVehicle = railriding;
        game.localplayeranimationhint.DrawFixX = 0;
        game.localplayeranimationhint.DrawFixY = railriding ? (-one * 7 / 10) : 0;
        game.localplayeranimationhint.DrawFixZ = 0;

        bool turnright = game.keyboardState[game.GetKey(GlKeys.D)];
        bool turnleft = game.keyboardState[game.GetKey(GlKeys.A)];
        RailSound(game);
        if (railriding)
        {
            game.controls.freemove = true;
            game.enable_move = false;
            Vector3Ref railPos = CurrentRailPos(game);
            game.player.position.x = railPos.X;
            game.player.position.y = railPos.Y;
            game.player.position.z = railPos.Z;
            currentrailblockprogress += currentvehiclespeed * dt;
            if (currentrailblockprogress >= 1)
            {
                lastdirection = currentdirection;
                currentrailblockprogress = 0;
                TileEnterData newenter = new TileEnterData();
                Vector3IntRef nexttile = NextTile(currentdirection, currentrailblockX, currentrailblockY, currentrailblockZ);
                newenter.BlockPositionX = nexttile.X;
                newenter.BlockPositionY = nexttile.Y;
                newenter.BlockPositionZ = nexttile.Z;
                //slope
                if (GetUpDownMove(game, currentrailblockX, currentrailblockY, currentrailblockZ,
                    DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Up)
                {
                    newenter.BlockPositionZ++;
                }
                if (GetUpDownMove(game, newenter.BlockPositionX,
                    newenter.BlockPositionY,
                    newenter.BlockPositionZ - 1,
                    DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Down)
                {
                    newenter.BlockPositionZ--;
                }

                newenter.EnterDirection = DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection));
                BoolRef newdirFound = new BoolRef();
                VehicleDirection12 newdir = BestNewDirection(PossibleRails(game, newenter), turnleft, turnright, newdirFound);
                if (!newdirFound.value)
                {
                    //end of rail
                    currentdirection = DirectionUtils.Reverse(currentdirection);
                }
                else
                {
                    currentdirection = newdir;
                    currentrailblockX = game.platform.FloatToInt(newenter.BlockPositionX);
                    currentrailblockY = game.platform.FloatToInt(newenter.BlockPositionY);
                    currentrailblockZ = game.platform.FloatToInt(newenter.BlockPositionZ);
                }
            }
        }
        if (game.keyboardState[game.GetKey(GlKeys.W)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed += 1 * dt;
        }
        if (game.keyboardState[game.GetKey(GlKeys.S)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed -= 5 * dt;
        }
        if (currentvehiclespeed < 0)
        {
            currentvehiclespeed = 0;
        }
        //todo fix
        //if (viewport.keypressed != null && viewport.keypressed.Key == GlKeys.Q)
        if (!wasqpressed && game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing)
        {
            Reverse();
        }
        if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && !railriding && !game.controls.freemove && game.GuiTyping != TypingState.Typing)
        {
            currentrailblockX = game.platform.FloatToInt(game.player.position.x);
            currentrailblockY = game.platform.FloatToInt(game.player.position.z);
            currentrailblockZ = game.platform.FloatToInt(game.player.position.y) - 1;
            if (!game.map.IsValidPos(currentrailblockX, currentrailblockY, currentrailblockZ))
            {
                ExitVehicle(game);
            }
            else
            {
                int railunderplayer = game.d_Data.Rail()[game.map.GetBlock(currentrailblockX, currentrailblockY, currentrailblockZ)];
                railriding = true;
                originalmodelheight = game.GetCharacterEyesHeight();
                game.SetCharacterEyesHeight(minecartheight());
                currentvehiclespeed = 0;
                if ((railunderplayer & RailDirectionFlags.Horizontal) != 0)
                {
                    currentdirection = VehicleDirection12.HorizontalRight;
                }
                else if ((railunderplayer & RailDirectionFlags.Vertical) != 0)
                {
                    currentdirection = VehicleDirection12.VerticalUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpLeft) != 0)
                {
                    currentdirection = VehicleDirection12.UpLeftUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpRight) != 0)
                {
                    currentdirection = VehicleDirection12.UpRightUp;
                }
                else if ((railunderplayer & RailDirectionFlags.DownLeft) != 0)
                {
                    currentdirection = VehicleDirection12.DownLeftLeft;
                }
                else if ((railunderplayer & RailDirectionFlags.DownRight) != 0)
                {
                    currentdirection = VehicleDirection12.DownRightRight;
                }
                else
                {
                    ExitVehicle(game);
                }
                lastdirection = currentdirection;
            }
        }
        else if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && railriding && game.GuiTyping != TypingState.Typing)
        {
            ExitVehicle(game);
            game.player.position.y += one * 7 / 10;
        }
        wasqpressed = game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing;
        wasepressed = game.keyboardState[game.GetKey(GlKeys.E)] && game.GuiTyping != TypingState.Typing;
    }
예제 #24
0
 internal int GetTextureOrLoad(string name, BitmapCi bmp)
 {
     if (!textures.Contains(name))
     {
         BoolRef found = new BoolRef();
         textures.Set(name, platform.LoadTextureFromBitmap(bmp));
     }
     return textures.Get(name);
 }
예제 #25
0
    public void Update(EntityPosition_ stateplayerposition, Controls move, float dt, BoolRef soundnow, Vector3Ref push, float modelheight)
    {
        if (game.stopPlayerMove)
        {
            movedz = 0;
            game.stopPlayerMove = false;
        }

        // No air control
        if (!isplayeronground)
        {
            acceleration.acceleration1 = 0.99f;
            acceleration.acceleration2 = 0.2f;
            acceleration.acceleration3 = 70;
        }

        // Trampoline
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if (blockunderplayer != -1 && blockunderplayer == game.d_Data.BlockIdTrampoline() &&
                (!isplayeronground) && !game.controls.shiftkeydown)
            {
                game.controls.wantsjump = true;
                jumpstartacceleration   = 20.666f * constGravity;
            }
        }

        // Slippery walk on ice and when swimming
        {
            int blockunderplayer = game.BlockUnderPlayer();
            if ((blockunderplayer != -1 && game.d_Data.IsSlipperyWalk()[blockunderplayer]) || game.SwimmingBody())
            {
                acceleration.acceleration1 = 0.99f;
                acceleration.acceleration2 = 0.2f;
                acceleration.acceleration3 = 70;
            }
        }

        soundnow.value = false;
        Vector3Ref diff1ref = new Vector3Ref();

        VectorTool.ToVectorInFixedSystem
            (move.movedx * movespeednow * dt,
            0,
            move.movedy * movespeednow * dt, stateplayerposition.rotx, stateplayerposition.roty, diff1ref);
        Vector3Ref diff1 = new Vector3Ref();

        diff1.X = diff1ref.X;
        diff1.Y = diff1ref.Y;
        diff1.Z = diff1ref.Z;
        if (MiscCi.Vec3Length(push.X, push.Y, push.Z) > 0.01f)
        {
            push.Normalize();
            push.X *= 5;
            push.Y *= 5;
            push.Z *= 5;
        }
        diff1.X += push.X * dt;
        diff1.Y += push.Y * dt;
        diff1.Z += push.Z * dt;

        bool loaded = false;
        int  cx     = game.platform.FloatToInt(game.player.position.x / Game.chunksize);
        int  cy     = game.platform.FloatToInt(game.player.position.z / Game.chunksize);
        int  cz     = game.platform.FloatToInt(game.player.position.y / Game.chunksize);

        if (game.map.IsValidChunkPos(cx, cy, cz))
        {
            if (game.map.chunks[MapUtilCi.Index3d(cx, cy, cz,
                                                  game.map.MapSizeX / Game.chunksize,
                                                  game.map.MapSizeY / Game.chunksize)] != null)
            {
                loaded = true;
            }
        }
        else
        {
            loaded = true;
        }
        if ((!(move.freemove)) && loaded)
        {
            if (!game.SwimmingBody())
            {
                movedz += -constGravity;//gravity
            }
            else
            {
                movedz += -constGravity * constWaterGravityMultiplier; //more gravity because it's slippery.
            }
        }
        game.movedz = movedz;
        if (constEnableAcceleration)
        {
            curspeed.X *= acceleration.acceleration1;
            curspeed.Y *= acceleration.acceleration1;
            curspeed.Z *= acceleration.acceleration1;
            curspeed.X  = MakeCloserToZero(curspeed.X, acceleration.acceleration2 * dt);
            curspeed.Y  = MakeCloserToZero(curspeed.Y, acceleration.acceleration2 * dt);
            curspeed.Z  = MakeCloserToZero(curspeed.Z, acceleration.acceleration2 * dt);
            diff1.Y    += move.moveup ? 2 * movespeednow * dt : 0;
            diff1.Y    -= move.movedown ? 2 * movespeednow * dt : 0;
            curspeed.X += diff1.X * acceleration.acceleration3 * dt;
            curspeed.Y += diff1.Y * acceleration.acceleration3 * dt;
            curspeed.Z += diff1.Z * acceleration.acceleration3 * dt;
            if (curspeed.Length() > movespeednow)
            {
                curspeed.Normalize();
                curspeed.X *= movespeednow;
                curspeed.Y *= movespeednow;
                curspeed.Z *= movespeednow;
            }
        }
        else
        {
            if (MiscCi.Vec3Length(diff1.X, diff1.Y, diff1.Z) > 0)
            {
                diff1.Normalize();
            }
            curspeed.X = diff1.X * movespeednow;
            curspeed.Y = diff1.Y * movespeednow;
            curspeed.Z = diff1.Z * movespeednow;
        }
        Vector3Ref newposition = Vector3Ref.Create(0, 0, 0);

        if (!(move.freemove))
        {
            newposition.X = stateplayerposition.x + curspeed.X;
            newposition.Y = stateplayerposition.y + curspeed.Y;
            newposition.Z = stateplayerposition.z + curspeed.Z;
            if (!game.SwimmingBody())
            {
                newposition.Y = stateplayerposition.y;
            }
            // Fast move when looking at the ground
            float diffx      = newposition.X - stateplayerposition.x;
            float diffy      = newposition.Y - stateplayerposition.y;
            float diffz      = newposition.Z - stateplayerposition.z;
            float difflength = MiscCi.Vec3Length(diffx, diffy, diffz);
            if (difflength > 0)
            {
                diffx /= difflength;
                diffy /= difflength;
                diffz /= difflength;
                diffx *= curspeed.Length();
                diffy *= curspeed.Length();
                diffz *= curspeed.Length();
            }
            newposition.X = stateplayerposition.x + diffx * dt;
            newposition.Y = stateplayerposition.y + diffy * dt;
            newposition.Z = stateplayerposition.z + diffz * dt;
        }
        else
        {
            newposition.X = stateplayerposition.x + (curspeed.X) * dt;
            newposition.Y = stateplayerposition.y + (curspeed.Y) * dt;
            newposition.Z = stateplayerposition.z + (curspeed.Z) * dt;
        }
        newposition.Y += movedz * dt;
        Vector3Ref previousposition = Vector3Ref.Create(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z);

        if (!move.noclip)
        {
            float[] v = WallSlide(
                Vec3.FromValues(stateplayerposition.x, stateplayerposition.y, stateplayerposition.z),
                Vec3.FromValues(newposition.X, newposition.Y, newposition.Z),
                modelheight);
            stateplayerposition.x = v[0];
            stateplayerposition.y = v[1];
            stateplayerposition.z = v[2];
        }
        else
        {
            stateplayerposition.x = newposition.X;
            stateplayerposition.y = newposition.Y;
            stateplayerposition.z = newposition.Z;
        }
        if (!(move.freemove))
        {
            if ((isplayeronground) || game.SwimmingBody())
            {
                jumpacceleration = 0;
                movedz           = 0;
            }
            if ((move.wantsjump || move.wantsjumphalf) && (((jumpacceleration == 0 && isplayeronground) || game.SwimmingBody()) && loaded) && (!game.SwimmingEyes()))
            {
                jumpacceleration = move.wantsjumphalf ? jumpstartaccelerationhalf : jumpstartacceleration;
                soundnow.value   = true;
            }

            if (jumpacceleration > 0)
            {
                isplayeronground = false;
                jumpacceleration = jumpacceleration / 2;
            }

            //if (!this.reachedceiling)
            {
                movedz += jumpacceleration * constJump;
            }
        }
        else
        {
            isplayeronground = true;
        }
        game.isplayeronground = isplayeronground;
    }
예제 #26
0
 public TransitionBool(T owner, ref BoolRef value1, bool condition = true) : base(owner)
 {
     m_value     = value1;
     m_condition = condition;
 }
예제 #27
0
    internal VehicleDirection12 BestNewDirection(int dirVehicleDirection12Flags, bool turnleft, bool turnright, BoolRef retFound)
    {
        // 0-- x
        // |
        // y

        // y is down, x is right
        // Naming: first the 2 connected directions followed by the preferred exit direction

        retFound.value = true;
        if (turnright)
        {
            // steering right
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0)
            {
                return(VehicleDirection12.DownRightRight);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0)
            {
                return(VehicleDirection12.UpRightUp);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0)
            {
                return(VehicleDirection12.UpLeftLeft);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0)
            {
                return(VehicleDirection12.DownLeftDown);
            }
        }
        if (turnleft)
        {
            // steering left
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0)
            {
                return(VehicleDirection12.DownRightDown);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0)
            {
                return(VehicleDirection12.UpRightRight);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0)
            {
                return(VehicleDirection12.UpLeftUp);
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0)
            {
                return(VehicleDirection12.DownLeftLeft);
            }
        }

        // Handle driving straight first
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalDown) != 0)
        {
            return(VehicleDirection12.VerticalDown);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalUp) != 0)
        {
            return(VehicleDirection12.VerticalUp);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalLeft) != 0)
        {
            return(VehicleDirection12.HorizontalLeft);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalRight) != 0)
        {
            return(VehicleDirection12.HorizontalRight);
        }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0)
        {
            return(VehicleDirection12.DownLeftDown);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0)
        {
            return(VehicleDirection12.DownLeftLeft);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0)
        {
            return(VehicleDirection12.DownRightDown);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0)
        {
            return(VehicleDirection12.DownRightRight);
        }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0)
        {
            return(VehicleDirection12.UpLeftLeft);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0)
        {
            return(VehicleDirection12.UpLeftUp);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0)
        {
            return(VehicleDirection12.UpRightRight);
        }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0)
        {
            return(VehicleDirection12.UpRightUp);
        }

        retFound.value = false;
        return(VehicleDirection12.DownLeftDown); // return null
    }
예제 #28
0
 public abstract void TcpConnect(string ip, int port, BoolRef connected);
예제 #29
0
    internal VehicleDirection12 BestNewDirection(int dirVehicleDirection12Flags, bool turnleft, bool turnright, BoolRef retFound)
    {
        // 0-- x
        // |
        // y

        // y is down, x is right
        // Naming: first the 2 connected directions followed by the preferred exit direction

        retFound.value = true;
        if (turnright)
        {
            // steering right
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0)
            {
                return VehicleDirection12.DownRightRight;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0)
            {
                return VehicleDirection12.UpRightUp;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0)
            {
                return VehicleDirection12.UpLeftLeft;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0)
            {
                return VehicleDirection12.DownLeftDown;
            }
        }
        if (turnleft)
        {
            // steering left
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0)
            {
                return VehicleDirection12.DownRightDown;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0)
            {
                return VehicleDirection12.UpRightRight;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0)
            {
                return VehicleDirection12.UpLeftUp;
            }
            if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0)
            {
                return VehicleDirection12.DownLeftLeft;
            }
        }

        // Handle driving straight first
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalDown) != 0) { return VehicleDirection12.VerticalDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.VerticalUp) != 0) { return VehicleDirection12.VerticalUp; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalLeft) != 0) { return VehicleDirection12.HorizontalLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.HorizontalRight) != 0) { return VehicleDirection12.HorizontalRight; }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftDown) != 0){ return VehicleDirection12.DownLeftDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownLeftLeft) != 0) { return VehicleDirection12.DownLeftLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightDown) != 0) { return VehicleDirection12.DownRightDown; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.DownRightRight) != 0) { return VehicleDirection12.DownRightRight; }

        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftLeft) != 0) { return VehicleDirection12.UpLeftLeft; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpLeftUp) != 0) { return VehicleDirection12.UpLeftUp; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightRight) != 0) { return VehicleDirection12.UpRightRight; }
        if ((dirVehicleDirection12Flags & VehicleDirection12Flags.UpRightUp) != 0) { return VehicleDirection12.UpRightUp; }

        retFound.value = false;
        return VehicleDirection12.DownLeftDown; // return null
    }
예제 #30
0
 public TypeRef PeekExpectedType(int n, TypeRef expType, BoolRef changed)
 {
     SetUpperBound(n, expType, changed);
     return(innerState.Value.Stack[n].Type);
 }
예제 #31
0
 internal int GetTexture(string p)
 {
     if (!textures.Contains(p))
     {
         BoolRef found = new BoolRef();
         BitmapCi bmp = platform.BitmapCreateFromPng(GetFile(p), GetFileLength(p));
         int texture = platform.LoadTextureFromBitmap(bmp);
         textures.Set(p, texture);
         platform.BitmapDelete(bmp);
     }
     return textures.Get(p);
 }
예제 #32
0
 public override void TcpConnect(string ip, int port, BoolRef connected)
 {
     this.connected = connected;
     sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     sock.NoDelay = true;
     sock.BeginConnect(ip, port, OnConnect, sock);
 }
예제 #33
0
        public void PropogateBackwards(ArgsLocalsState other, ArgLocal argLocal, int index, bool isAlive, BoolRef changed)
        {
            var newArgsAlive   = other.argsAlive.Clone();
            var newLocalsAlive = other.localsAlive.Clone();

            if (index >= 0)
            {
                switch (argLocal)
                {
                case ArgLocal.Arg:
                    newArgsAlive[index] = isAlive;
                    break;

                case ArgLocal.Local:
                    newLocalsAlive[index] = isAlive;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("argLocal");
                }
            }
            argsAlive.UnionInPlace(newArgsAlive, changed);
            localsAlive.UnionInPlace(newLocalsAlive, changed);
        }
예제 #34
0
        public bool PeekDereferencableExpectedType(int n, TypeRef expType, bool canBeStruct, BoolRef changed)
        {
            expType = expType.ToRunTimeType(RootEnv, false);
            var type = PeekType(n);
            var s    = type.Style(RootEnv);

            if (s is NullTypeStyle)
            {
                // Stack entry will remain a referece type (and thus never a pointer).
                // 'null' can be statically dereferenced if we are expecting a reference type, though
                // of course this will cause a null reference exception at runtime
                if (!(expType.Style(RootEnv) is ReferenceTypeStyle))
                {
                    throw new InvalidOperationException("expected type is not a referece type");
                }
                // Stack type cannot be refined above expected reference type
                SetUpperBound(n, expType, changed);
                // Not dereferencing a pointer
                return(false);
            }
            else if (s is UnmanagedPointerTypeStyle)
            {
                throw new InvalidOperationException("unmananaged pointer");
            }
            else if (s is ManagedPointerTypeStyle)
            {
                // Stack entry will remain a pointer of this type, so no need to impose upper bound
                if (!type.Arguments[0].IsAssignableTo(RootEnv, expType))
                {
                    throw new InvalidOperationException
                              ("managed pointer element type is not assignable to expected type");
                }
                // Dereferencing a pointer
                return(true);
            }
            else
            {
                // If stack entry is a value type it will remain a value type, so test is stable under generalization
                if (!canBeStruct && s is ValueTypeStyle)
                {
                    throw new InvalidOperationException
                              ("stack entry is a value type, but value types cannot be the target of field pointers");
                }
                // Values and objects can be dereferenced if they are compatible with expected type
                // Parameter types are not allowed
                if (!(s is ReferenceTypeStyle) && !(s is ValueTypeStyle))
                {
                    throw new InvalidOperationException("stack entry is not a value or reference type");
                }
                // Stack type cannot be refined above expected type
                SetUpperBound(n, expType, changed);
                // Not dereferencing a pointer
                return(false);
            }
        }
예제 #35
0
파일: ObjReader.cs 프로젝트: ADuc/Dress
    private IEnumerator GetTexturesAsync(string mtlFile, LinesRef linesRef, string filePath, Dictionary<string, Texture2D> textures, ObjData objData, BoolRef loadError)
    {
        Texture2D diffuseTexture = null;
        string[] lines = mtlFile.Split ('\n');

        int numberOfTextures = 0;

        // See how many textures there are (to use for progress)
        for (int i = 0; i < lines.Length; i++) {
            var line = lines[i];
            CleanLine (ref line);
            lines[i] = line;

            if (line.Length < 7 || line[0] == '#') {
                continue;
            }

            if (IsTextureLine (line) && filePath != "") {
                numberOfTextures++;
            }
        }

        float progress = .5f;
        for (int i = 0; i < lines.Length; i++) {
            if (lines[i].Length < 7 || lines[i][0] == '#') {
                continue;
            }

            // Get diffuse/bump texture
            if (IsTextureLine (lines[i]) && filePath != "") {
                var textureFilePath = GetFileName (lines[i], GetToken (lines[i]));
                if (textureFilePath != "") {
                    var completeFilePath = filePath + textureFilePath;
                    var www = new WWW(completeFilePath);
                    while (!www.isDone) {
                        objData.SetProgress (progress + (www.progress / numberOfTextures) * .5f);
                        if (objData.cancel) {
                            loadError.b = true;
                            yield break;
                        }
                        yield return null;
                    }
                    if (www.error != null) {
                        Debug.LogError ("Error loading " + completeFilePath + ": " + www.error);
                        loadError.b = true;
                        objData.SetDone();
                        yield break;
                    }
                    progress += (1.0f / numberOfTextures) * .5f;
                    diffuseTexture = new Texture2D (4, 4);
                    www.LoadImageIntoTexture (diffuseTexture);
                    if (lines[i].StartsWith ("map_bump") || lines[i].StartsWith ("bump")) {
                        ConvertToNormalmap (diffuseTexture);
                    }
                    textures[textureFilePath] = diffuseTexture;
                }
            }
        }
        linesRef.lines = lines;
    }
예제 #36
0
 public void ReadPointer(MachineState nextState, PointsTo pointsTo, BoolRef changed)
 {
     innerState.Value.ArgsLocalsState.ReadPointer(nextState.innerState.Value.ArgsLocalsState, pointsTo, changed);
 }
예제 #37
0
파일: ObjReader.cs 프로젝트: ADuc/Dress
    private IEnumerator GetWWWFiles(string objFilePath, bool useMtl, Material standardMaterial, Material transparentMaterial, ObjData objData)
    {
        var www = new WWW(objFilePath);
        while (!www.isDone) {
            objData.SetProgress (www.progress * (useMtl? .5f : 1.0f));
            if (objData.cancel) {
                yield break;
            }
            yield return null;
        }
        if (www.error != null) {
            Debug.LogError ("Error loading " + objFilePath + ": " + www.error);
            objData.SetDone();
            yield break;
        }

        string objFile = www.text;
        string filePath = "";
        Dictionary<string, Material> materials = null;

        if (useMtl) {
            string mtlFileName = GetMTLFileName (ref objFilePath, ref objFile, ref filePath);
            if (mtlFileName != "") {
                // Read in mtl file
                www = new WWW(filePath + mtlFileName);
                while (!www.isDone) {
                    if (objData.cancel) {
                        yield break;
                    }
                    yield return null;
                }
                if (www.error != null) {
                    if (!useMTLFallback) {
                        Debug.LogError ("Error loading " + (filePath + mtlFileName) + ": " + www.error);
                        objData.SetDone();
                        yield break;
                    }
                    else {
                        useMtl = false;
                    }
                }
                if (useMtl && www.text != "") {
                    // Get textures and parse MTL file
                    var linesRef = new LinesRef();
                    var textures = new Dictionary<string, Texture2D>();
                    var loadError = new BoolRef(false);
                    yield return StartCoroutine (GetTexturesAsync (www.text, linesRef, filePath, textures, objData, loadError));
                    if (loadError.b == true) {
                        yield break;
                    }
                    materials = ParseMTL (linesRef.lines, standardMaterial, transparentMaterial, filePath, textures);
                    if (materials == null) {
                        useMtl = false;
                    }
                }
            }
            else {
                useMtl = false;
            }
        }

        CreateObjects (ref objFile, useMtl, materials, standardMaterial, objData, Path.GetFileNameWithoutExtension (objFilePath));
    }
예제 #38
0
 internal int GetTexture(string name)
 {
     if (!textures.Contains(name))
     {
         BoolRef found = new BoolRef();
         BitmapCi bmp = p.BitmapCreateFromPng(GetFile(name), GetFileLength(name));
         int texture = p.LoadTextureFromBitmap(bmp);
         textures.Set(name, texture);
         p.BitmapDelete(bmp);
     }
     return textures.Get(name);
 }
예제 #39
0
        // ----------------------------------------------------------------------
        // Exceptional transitions
        // ----------------------------------------------------------------------

        // Exceptional control flow may take this source machine state to other target machine state.
        // Account for forward and backward propogation of non-stack related state.
        public void SourceToTargetTransition(MachineState other, BoolRef changed)
        {
            innerState.Value.ArgsLocalsState.SourceToTargetTransition(other.innerState.Value.ArgsLocalsState, changed);
        }
예제 #40
0
        // ----------------------------------------------------------------------
        // Backward propogation of args and locals liveness
        // (we clone and mutate the existing args and locals state)
        // ----------------------------------------------------------------------

        // Ensure any argument or local which is alive in nextState is alive in this state. Return true if this state changed.
        public void PropogateBackwards(MachineState nextState, BoolRef changed)
        {
            innerState.Value.ArgsLocalsState.PropogateBackwards(nextState.innerState.Value.ArgsLocalsState, default(ArgLocal), -1, false, changed);
        }
예제 #41
0
 public TcpNetClient()
 {
     incoming = new QueueByte();
     data = new byte[dataLength];
     connected = new BoolRef();
 }
예제 #42
0
    internal void RailOnNewFrame(Game game, float dt)
    {
        if (localMinecart == null)
        {
            localMinecart          = new Entity();
            localMinecart.minecart = new Minecart();
            game.EntityAddLocal(localMinecart);
        }
        localMinecart.minecart.enabled = railriding;
        if (railriding)
        {
            Minecart m = localMinecart.minecart;
            m.positionX     = game.player.position.x;
            m.positionY     = game.player.position.y;
            m.positionZ     = game.player.position.z;
            m.direction     = currentdirection;
            m.lastdirection = lastdirection;
            m.progress      = currentrailblockprogress;
        }

        game.localplayeranimationhint.InVehicle = railriding;
        game.localplayeranimationhint.DrawFixX  = 0;
        game.localplayeranimationhint.DrawFixY  = railriding ? (-one * 7 / 10) : 0;
        game.localplayeranimationhint.DrawFixZ  = 0;

        bool turnright = game.keyboardState[game.GetKey(GlKeys.D)];
        bool turnleft  = game.keyboardState[game.GetKey(GlKeys.A)];

        RailSound(game);
        if (railriding)
        {
            game.controls.SetFreemove(FreemoveLevelEnum.Freemove);
            game.enable_move = false;
            Vector3Ref railPos = CurrentRailPos(game);
            game.player.position.x    = railPos.X;
            game.player.position.y    = railPos.Y;
            game.player.position.z    = railPos.Z;
            currentrailblockprogress += currentvehiclespeed * dt;
            if (currentrailblockprogress >= 1)
            {
                lastdirection            = currentdirection;
                currentrailblockprogress = 0;
                TileEnterData newenter = new TileEnterData();
                Vector3IntRef nexttile = NextTile(currentdirection, currentrailblockX, currentrailblockY, currentrailblockZ);
                newenter.BlockPositionX = nexttile.X;
                newenter.BlockPositionY = nexttile.Y;
                newenter.BlockPositionZ = nexttile.Z;
                //slope
                if (GetUpDownMove(game, currentrailblockX, currentrailblockY, currentrailblockZ,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Up)
                {
                    newenter.BlockPositionZ++;
                }
                if (GetUpDownMove(game, newenter.BlockPositionX,
                                  newenter.BlockPositionY,
                                  newenter.BlockPositionZ - 1,
                                  DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection))) == UpDown.Down)
                {
                    newenter.BlockPositionZ--;
                }

                newenter.EnterDirection = DirectionUtils.ResultEnter(DirectionUtils.ResultExit(currentdirection));
                BoolRef            newdirFound = new BoolRef();
                VehicleDirection12 newdir      = BestNewDirection(PossibleRails(game, newenter), turnleft, turnright, newdirFound);
                if (!newdirFound.value)
                {
                    //end of rail
                    currentdirection = DirectionUtils.Reverse(currentdirection);
                }
                else
                {
                    currentdirection  = newdir;
                    currentrailblockX = game.platform.FloatToInt(newenter.BlockPositionX);
                    currentrailblockY = game.platform.FloatToInt(newenter.BlockPositionY);
                    currentrailblockZ = game.platform.FloatToInt(newenter.BlockPositionZ);
                }
            }
        }
        if (game.keyboardState[game.GetKey(GlKeys.W)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed += 1 * dt;
        }
        if (game.keyboardState[game.GetKey(GlKeys.S)] && game.GuiTyping != TypingState.Typing)
        {
            currentvehiclespeed -= 5 * dt;
        }
        if (currentvehiclespeed < 0)
        {
            currentvehiclespeed = 0;
        }
        //todo fix
        //if (viewport.keypressed != null && viewport.keypressed.Key == GlKeys.Q)
        if (!wasqpressed && game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing)
        {
            Reverse();
        }
        if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && !railriding && (game.controls.GetFreemove() == FreemoveLevelEnum.None) && game.GuiTyping != TypingState.Typing)
        {
            currentrailblockX = game.platform.FloatToInt(game.player.position.x);
            currentrailblockY = game.platform.FloatToInt(game.player.position.z);
            currentrailblockZ = game.platform.FloatToInt(game.player.position.y) - 1;
            if (!game.map.IsValidPos(currentrailblockX, currentrailblockY, currentrailblockZ))
            {
                ExitVehicle(game);
            }
            else
            {
                int railunderplayer = game.d_Data.Rail()[game.map.GetBlock(currentrailblockX, currentrailblockY, currentrailblockZ)];
                railriding          = true;
                originalmodelheight = game.GetCharacterEyesHeight();
                game.SetCharacterEyesHeight(minecartheight());
                currentvehiclespeed = 0;
                if ((railunderplayer & RailDirectionFlags.Horizontal) != 0)
                {
                    currentdirection = VehicleDirection12.HorizontalRight;
                }
                else if ((railunderplayer & RailDirectionFlags.Vertical) != 0)
                {
                    currentdirection = VehicleDirection12.VerticalUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpLeft) != 0)
                {
                    currentdirection = VehicleDirection12.UpLeftUp;
                }
                else if ((railunderplayer & RailDirectionFlags.UpRight) != 0)
                {
                    currentdirection = VehicleDirection12.UpRightUp;
                }
                else if ((railunderplayer & RailDirectionFlags.DownLeft) != 0)
                {
                    currentdirection = VehicleDirection12.DownLeftLeft;
                }
                else if ((railunderplayer & RailDirectionFlags.DownRight) != 0)
                {
                    currentdirection = VehicleDirection12.DownRightRight;
                }
                else
                {
                    ExitVehicle(game);
                }
                lastdirection = currentdirection;
            }
        }
        else if (!wasepressed && game.keyboardState[game.GetKey(GlKeys.E)] && railriding && game.GuiTyping != TypingState.Typing)
        {
            ExitVehicle(game);
            game.player.position.y += one * 7 / 10;
        }
        wasqpressed = game.keyboardState[game.GetKey(GlKeys.Q)] && game.GuiTyping != TypingState.Typing;
        wasepressed = game.keyboardState[game.GetKey(GlKeys.E)] && game.GuiTyping != TypingState.Typing;
    }
예제 #43
0
 public void ReadArgLocal(MachineState nextState, ArgLocal argLocal, int index, BoolRef changed)
 {
     innerState.Value.ArgsLocalsState.PropogateBackwards(nextState.innerState.Value.ArgsLocalsState, argLocal, index, true, changed);
 }