コード例 #1
0
        public override int DrawBatch(int maxBlocksToDraw)
        {
            // Ignoring maxBlocksToDraw.
            int exCount = 0;

            Count = 0;

            for (Coords.X = Bounds.XMin; Coords.X <= Bounds.XMax && MathCommands.MaxCalculationExceptions >= exCount; ++Coords.X)
            {
                for (Coords.Y = Bounds.YMin; Coords.Y <= Bounds.YMax && MathCommands.MaxCalculationExceptions >= exCount; ++Coords.Y)
                {
                    for (Coords.Z = Bounds.ZMin; Coords.Z <= Bounds.ZMax; ++Coords.Z)
                    {
                        try {
                            // 1.0 means true.
                            if (_Expression.Evaluate(_Scaler.ToFuncParam(Coords.X, Bounds.XMin, Bounds.XMax),
                                                     _Scaler.ToFuncParam(Coords.Y, Bounds.YMin, Bounds.YMax),
                                                     _Scaler.ToFuncParam(Coords.Z, Bounds.ZMin, Bounds.ZMax)) > 0)
                            {
                                if (DrawOneBlock())
                                {
                                    ++Count;
                                }
                            }

                            // if(TimeToEndBatch) {
                            //	 return _count;
                            // }
                        } catch (Exception) {
                            // The exception here is kinda of normal, for functions(especially interesting ones)
                            // may have eg punctured points; we just have to keep an eye on the number, since producing 10000
                            // exceptions in the multiclient application is not the best idea.
                            if (++exCount > MathCommands.MaxCalculationExceptions)
                            {
                                Player.Message("Drawing is interrupted: too many(>" +
                                               MathCommands.MaxCalculationExceptions +
                                               ") calculation exceptions.");

                                break;
                            }
                        }
                    }
                }
            }

            IsDone = true;

            return(Count);
        }
コード例 #2
0
        // This method exists to box coords nicely as ref params.
        private int InternalDraw(ref int arg1, ref int arg2, ref int val, int min1, int max1, int min2, int max2, int minV, int maxV, int maxBlocksToDraw)
        {
            int exCount = 0;

            Count = 0;

            DrawFasePrepare(min1, max1, min2, max2);

            for (arg1 = min1; arg1 <= max1 && MathCommands.MaxCalculationExceptions >= exCount; ++arg1)
            {
                for (arg2 = min2; arg2 <= max2; ++arg2)
                {
                    try {
                        int fval =
                            _Scaler.FromFuncResult(
                                _Expression.Evaluate(_Scaler.ToFuncParam(arg1, min1, max1),
                                                     _Scaler.ToFuncParam(arg2, min2, max2)),
                                minV, maxV);

                        DrawFase1(fval, ref arg1, ref arg2, ref val, min1, max1, min2, max2, minV, maxV, maxBlocksToDraw);

                        // if(TimeToEndBatch) {
                        //	 return _count;
                        // }
                    } catch (Exception) {
                        // The exception here is kinda of normal, for functions(especially interesting ones)
                        // may have eg punctured points; we just have to keep an eye on the number, since producing 10000
                        // exceptions in the multiclient application is not the best idea.
                        if (++exCount > MathCommands.MaxCalculationExceptions)
                        {
                            Player.Message("Function drawing is interrupted: too many(>" +
                                           MathCommands.MaxCalculationExceptions +
                                           ") calculation exceptions.");

                            break;
                        }
                    }
                }
            }

            // The real drawing for the surface variant.
            DrawFase2(ref arg1, ref arg2, ref val, min1, max1, min2, max2, minV, maxV, maxBlocksToDraw);

            return(Count);
        }
コード例 #3
0
        // This method exists to box coords nicely as ref params, note that the set of {arg1, arg2, arg3} must be the same with {
        //	 xArg, yArg, zArg
        // }
        private int InternalDraw(ref int arg1, ref int arg2, ref int arg3,
                                 int min1, int max1, int min2, int max2, int min3, int max3,
                                 ref int argX, ref int argY, ref int argZ,
                                 int minX, int maxX, int minY, int maxY, int minZ, int maxZ,
                                 int maxBlocksToDraw)
        {
            int exCount = 0;

            Count = 0;

            for (arg1 = min1; arg1 <= max1 && MathCommands.MaxCalculationExceptions >= exCount; ++arg1)
            {
                for (arg2 = min2; arg2 <= max2 && MathCommands.MaxCalculationExceptions >= exCount; ++arg2)
                {
                    double prevDiff = 0;
                    double prevComp = 0;

                    for (int arg3Iterator = min3; arg3Iterator <= max3; ++arg3Iterator)
                    {
                        try {
                            arg3 = arg3Iterator;

                            Tuple <double, double> res =
                                _Expression.EvaluateAsEquality(_Scaler.ToFuncParam(argX, minX, maxX),
                                                               _Scaler.ToFuncParam(argY, minY, maxY),
                                                               _Scaler.ToFuncParam(argZ, minZ, maxZ));

                            // Decision: we cant only take points with 0 as comparison result as it will happen almost never.
                            // We are reacting on the changes of the comparison result sign.
                            arg3 = int.MaxValue;

                            // Exactly equal, wow, such a surprise.
                            if (res.Item1 == 0)
                            {
                                arg3 = arg3Iterator;
                                //i.e. different signs, but not the prev==0
                            }
                            else if (res.Item1 * prevComp < 0)
                            {
                                arg3 = res.Item2 < prevDiff ? arg3Iterator : arg3Iterator - 1;                                 //then choose the closest to 0 difference
                            }

                            if (DrawOneBlock())
                            {
                                ++Count;
                            }

                            // if(TimeToEndBatch) {
                            //	 return _count;
                            // }

                            prevComp = res.Item1;
                            prevDiff = res.Item2;
                        } catch (Exception) {
                            // The exception here is kinda of normal, for functions(especially interesting ones)
                            // may have eg punctured points; we just have to keep an eye on the number, since producing 10000
                            // exceptions in the multiclient application is not the best idea.
                            if (++exCount > MathCommands.MaxCalculationExceptions)
                            {
                                Player.Message("Surface drawing is interrupted: too many(>" +
                                               MathCommands.MaxCalculationExceptions +
                                               ") calculation exceptions.");

                                break;
                            }
                        }
                    }
                }
            }

            return(Count);
        }