Beispiel #1
0
 public override void Tick()
 {
     if (curState != null)
     {
         GState.Tick(curState, Now);
     }
 }
 public void Load(GState state)
 {
     foreach (var i in BattlePlayers.Values)
     {
         CreateUser(i, state);
     }
 }
Beispiel #3
0
        private void GraphCreator_MouseDown(object sender, MouseEventArgs e)
        {
            if (Status.mode == Misc.Mode.Line)
            {
                Point p = FindNear(e.X, e.Y, 10);
                if (p != null && (p.N == lpn || lpn == -1))
                {
                    drawLine = true;
                    GState prevstate = state;
                    state = GState.RouteDraw;
                    s     = p;
                    x1    = p.X;
                    y1    = p.Y;
                    if (crs == "")
                    {
                        crs += "" + p.N;
                    }
                }
            }

            if (Status.mode == Misc.Mode.Select)
            {
                Point p = FindNear(e.X, e.Y, 10);
                selectedPoint = p;
                if (selectedPoint != null)
                {
                    movePoint = true;
                    Console.WriteLine("movePoint true");
                    //MouseMove+=//OnPaint(new PaintEventArgs(this.CreateGraphics(),new Rectangle(this.Left,this.Top, this.Width, this.Height)));
                }
            }
        }
Beispiel #4
0
        private void Awake()
        {
            if (m_instance != null && m_instance != this)
            {
                throw new InvalidOperationException();
            }

            m_instance = this;

            m_serializer = new ProtobufSerializer();

            m_persistentDataPath = Application.streamingAssetsPath;
            Debug.Log(m_persistentDataPath);

            m_stats = GState.GetValue <ServerStats>("LocalGameServer.m_stats");
            if (m_stats == null)
            {
                m_stats = new ServerStats();
                GState.SetValue("LocalGameServer.m_stats", m_stats);
            }


            m_loggedInPlayers = GState.GetValue <HashSet <Guid> >("LocalGameServer.m_loggedInPlayers");
            if (m_loggedInPlayers == null)
            {
                m_loggedInPlayers = new HashSet <Guid>();
                GState.SetValue("LocalGameServer.m_loggedInPlayers", m_loggedInPlayers);
            }

            LoadPlayers();
            GState.SetValue("LocalGameServer.m_players", m_players);
        }
Beispiel #5
0
 /// <summary>
 /// Retrieves the set of starting contexts for this node. The starting contexts are the set of Unit[] with a size
 /// equal to the maximum right context size.
 /// </summary>
 /// <returns>the set of starting contexts across nodes.</returns>
 private HashSet <UnitContext> GetStartingContexts()
 {
     if (_startingContexts == null)
     {
         _startingContexts = new HashSet <UnitContext>();
         // if this is an empty node, the starting context is the set of starting contexts for all successor
         // nodes, otherwise, it is built up from each pronunciation of this word
         if (_node.IsEmpty)
         {
             GrammarArc[] arcs = GetSuccessors();
             foreach (GrammarArc arc in arcs)
             {
                 GState gstate = _parent.GetGState(arc.GrammarNode);
                 _startingContexts.AddAll(gstate.GetStartingContexts());
             }
         }
         else
         {
             //                    int maxSize = getRightContextSize();
             Word            word  = _node.GetWord();
             Pronunciation[] prons = word.GetPronunciations(null);
             foreach (Pronunciation pron in prons)
             {
                 UnitContext startingContext = GetStartingContext(pron);
                 _startingContexts.Add(startingContext);
             }
         }
     }
     return(_startingContexts);
 }
Beispiel #6
0
 /// <summary>
 /// Connect up all of the GStates. Each state now has a table of exit points. These exit points represent tail
 /// states for the node. Each of these tail states is tagged with a ContextPair, that indicates what the left
 /// context is (the exiting context) and the right context (the entering context) for the transition. To connect
 /// up a state, the connect does the following:
 /// 1) Iterate through all of the grammar successors for this state
 /// 2) Get the 'entry points' for the successor that match the exit points.
 /// 3) Hook them up.
 ///
 /// Note that for a task with 1000 words this will involve checking on the order of 35,000,000 connections and
 /// making about 2,000,000 connections
 /// </summary>
 public void Connect()
 {
     // T("Connecting " + node.getWord());
     foreach (GrammarArc arc in GetSuccessors())
     {
         GState gstate = _parent.GetGState(arc.GrammarNode);
         if (!gstate.GetNode().IsEmpty &&
             gstate.GetNode().GetWord().Spelling.Equals(IDictionary.SentenceStartSpelling))
         {
             continue;
         }
         float probability = arc.Probability;
         // adjust the language probability by the number of
         // pronunciations. If there are 3 ways to say the
         // word, then each pronunciation gets 1/3 of the total
         // probability.
         if (_parent._spreadWordProbabilitiesAcrossPronunciations && !gstate.GetNode().IsEmpty)
         {
             int numPronunciations = gstate.GetNode().GetWord().GetPronunciations(null).Length;
             probability -= _parent.LogMath.LinearToLog(numPronunciations);
         }
         float fprob = probability;
         foreach (var entry in _exitPoints)
         {
             List <ISearchState> destEntryPoints = gstate.GetEntryPoints(entry.Key);
             if (destEntryPoints != null)
             {
                 List <ISearchState> srcExitPoints = entry.Value;
                 Connect(srcExitPoints, destEntryPoints, fprob);
             }
         }
     }
 }
Beispiel #7
0
 public BattlePerception(GState state, IBattlePerception view) : base(state)
 {
     View = view;
     BattleCharacterControllor = new BattleCharacterControllor(this);
     ReleaserControllor        = new MagicReleaserControllor(this);
     BattleMissileControllor   = new BattleMissileControllor(this);
     AIControllor = new BattleCharacterAIBehaviorTreeControllor(this);
 }
        //创建角色
        private void CreateUser(BattlePlayer user, GState state)
        {
            var per   = state.Perception as BattlePerception;
            var data  = ExcelToJSONConfigManager.Current.GetConfigByID <CharacterData>(user.GetHero().HeroID);
            var magic = ExcelToJSONConfigManager.Current.GetConfigs <CharacterMagicData>(t =>
            {
                return(t.CharacterID == data.ID);
            });

            //处理装备加成
            var battleCharacte = per.CreateCharacter(
                user.GetHero().Level, data, magic.ToList(), 1,
                GetBornPos(), new UVector3(0, 0, 0), user.User.UserID);

            foreach (var i in user.GetHero().Equips)
            {
                var equipconfig = ExcelToJSONConfigManager.Current.GetConfigByID <EquipmentData>(i.EquipID);
                if (equipconfig == null)
                {
                    continue;
                }
                Equip equip   = user.GetEquipByGuid(i.GUID);
                float addRate = 0f;
                if (equip != null)
                {
                    var equipLevelUp = ExcelToJSONConfigManager
                                       .Current
                                       .FirstConfig <EquipmentLevelUpData>(t => t.Level == equip.Level && t.Quility == equipconfig.Quility);
                    if (equipLevelUp != null)
                    {
                        addRate = (float)equipLevelUp.AppendRate / 10000f;
                    }
                }
                //基础加成
                var properties = equipconfig.Properties.SplitToInt();
                var values     = equipconfig.PropertyValues.SplitToInt();
                for (var index = 0; index < properties.Count; index++)
                {
                    var p = (HeroPropertyType)properties[index];
                    var v = battleCharacte[p].BaseValue + (float)values[index] * (1 + addRate);
                    battleCharacte[p].SetBaseValue((int)v);
                }

                //附加加成
                if (equip != null)
                {
                    foreach (var property in equip.Properties)
                    {
                        var v = battleCharacte[property.Property]
                                .BaseValue + property.Value;
                        battleCharacte[property.Property].SetBaseValue((int)v);
                    }
                }
            }
            battleCharacte.ModifyValue(HeroPropertyType.ViewDistance, AddType.Append, 1000 * 100); //修改玩家AI视野
            UserCharacters.Add(user.User.UserID, battleCharacte);
            per.ChangeCharacterAI(data.AIResourcePath, battleCharacte);
        }
Beispiel #9
0
 /// <summary>
 /// Visit all of the successor states, and gather their starting contexts into this gstates right context
 /// </summary>
 private void PullRightContexts()
 {
     GrammarArc[] arcs = GetSuccessors();
     foreach (GrammarArc arc in arcs)
     {
         GState gstate = _parent.GetGState(arc.GrammarNode);
         _rightContexts.AddAll(gstate.GetStartingContexts());
     }
 }
        // Creates some content (3 images) and associate them with the image layer
        static Obj CreateGroup1(PDFDoc doc, Obj layer)
        {
            using (ElementWriter writer = new ElementWriter())
                using (ElementBuilder builder = new ElementBuilder())
                {
                    writer.Begin(doc);

                    // Create an Image that can be reused in the document or on the same page.
                    Image img = Image.Create(doc.GetSDFDoc(), (input_path + "peppers.jpg"));

                    Element element = builder.CreateImage(img, new Matrix2D(img.GetImageWidth() / 2, -145, 20, img.GetImageHeight() / 2, 200, 150));
                    writer.WritePlacedElement(element);

                    GState gstate = element.GetGState();                // use the same image (just change its matrix)
                    gstate.SetTransform(200, 0, 0, 300, 50, 450);
                    writer.WritePlacedElement(element);

                    // use the same image again (just change its matrix).
                    writer.WritePlacedElement(builder.CreateImage(img, 300, 600, 200, -150));

                    Obj grp_obj = writer.End();

                    // Indicate that this form (content group) belongs to the given layer (OCG).
                    grp_obj.PutName("Subtype", "Form");
                    grp_obj.Put("OC", layer);
                    grp_obj.PutRect("BBox", 0, 0, 1000, 1000);              // Set the clip box for the content.

                    // As an example of further configuration, set the image layer to
                    // be visible on screen, but not visible when printed...

                    // The AS entry is an auto state array consisting of one or more usage application
                    // dictionaries that specify how conforming readers shall automatically set the
                    // state of optional content groups based on external factors.
                    Obj cfg        = doc.GetOCGConfig().GetSDFObj();
                    Obj auto_state = cfg.FindObj("AS");
                    if (auto_state == null)
                    {
                        auto_state = cfg.PutArray("AS");
                    }
                    Obj print_state = auto_state.PushBackDict();
                    print_state.PutArray("Category").PushBackName("Print");
                    print_state.PutName("Event", "Print");
                    print_state.PutArray("OCGs").PushBack(layer);

                    Obj layer_usage = layer.PutDict("Usage");

                    Obj view_setting = layer_usage.PutDict("View");
                    view_setting.PutName("ViewState", "ON");

                    Obj print_setting = layer_usage.PutDict("Print");
                    print_setting.PutName("PrintState", "OFF");

                    return(grp_obj);
                }
        }
Beispiel #11
0
 public void GetNextPlayerState()
 {
     if (playerState != PState.Wait)
     {
         playerState += 1;
     }
     else
     {
         playerState = PState.CheckArrow;
         gameState   = GState.EnemyTurn;
     }
 }
 void EndGame_Lost()
 {
     GameData.score    = score;
     GameData.health   = health;
     GameData.finished = false;
     GameData.outcome  = "Lost!";
     GameData.oneword  = "Next Time!";
     GameData.winLevel = 0;
     m_state           = GState.End;
     m_maestro.End();
     SceneManager.LoadScene("GameOver");
 }
 void StartGame()
 {
     m_state = GState.Start;
     m_startText.SetActive(true);
     m_startText.transform.localScale = new Vector3(2.0f, 2.0f, 1.0f);
     iTween.ScaleTo(m_startText, new Vector3(1.0f, 1.0f, 1.0f), 0.4f);
     iTween.MoveTo(m_startText, iTween.Hash(
                       "position", new Vector3(12.0f, 4.0f, 0.0f), "time", 0.5f, "delay", 1.0f, "easeType", iTween.EaseType.easeInCirc,
                       "oncomplete", "PlayGame", "oncompletetarget", gameObject
                       ));
     GameData.score    = 0;
     GameData.health   = 1.0f;
     GameData.finished = false;
 }
Beispiel #14
0
    public void GetNextEnemyState()
    {
        if (enemyState != EState.Wait)
        {
            enemyState += 1;
        }
        else
        {
            enemyState = EState.Attack;
            gameState  = GState.PlayerTurn;

            Transform player = GameObject.FindGameObjectWithTag("Player").transform;
            transform.position = new Vector3(player.position.x, player.position.y, -10);
        }
    }
Beispiel #15
0
 ///<summary>Constructor! 'doh'!.</summary>
 public GameScreen(Color c, float GF = 0.6f, byte MB = 20)
 {
     r        = new System.Random();
     BGColor  = c; GroundFriction = GF;
     MaxBalls = MB;
     G.Dimensions(out Width, out Height);
     MidScreen    = new Vector2(Width / 2, Height / 2);
     bouncers     = new Rectangle[4];
     bl           = new Ball[MaxBalls];
     bd           = new Board[4]; timer = i = j = 0;
     currentstate = GState.Play1H; CurrentBalls = 0;
     Pause        = false;
     Player.PlayerInit(out Home, out Away);
     ll = rr = Vector2.Zero;
     G.Dimensions(out Width, out Height);
     AddBall();
 }
        // Creates some content (a path in the shape of a heart) and associate it with the vector layer
        static Obj CreateGroup2(PDFDoc doc, Obj layer)
        {
            using (ElementWriter writer = new ElementWriter())
                using (ElementBuilder builder = new ElementBuilder())
                {
                    writer.Begin(doc);

                    // Create a path object in the shape of a heart.
                    builder.PathBegin();                        // start constructing the path
                    builder.MoveTo(306, 396);
                    builder.CurveTo(681, 771, 399.75, 864.75, 306, 771);
                    builder.CurveTo(212.25, 864.75, -69, 771, 306, 396);
                    builder.ClosePath();
                    Element element = builder.PathEnd();             // the path geometry is now specified.

                    // Set the path FILL color space and color.
                    element.SetPathFill(true);
                    GState gstate = element.GetGState();
                    gstate.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
                    gstate.SetFillColor(new ColorPt(1, 0, 0, 0));              // cyan

                    // Set the path STROKE color space and color.
                    element.SetPathStroke(true);
                    gstate.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
                    gstate.SetStrokeColor(new ColorPt(1, 0, 0));              // red
                    gstate.SetLineWidth(20);

                    gstate.SetTransform(0.5, 0, 0, 0.5, 280, 300);

                    writer.WriteElement(element);

                    Obj grp_obj = writer.End();


                    // Indicate that this form (content group) belongs to the given layer (OCG).
                    grp_obj.PutName("Subtype", "Form");
                    grp_obj.Put("OC", layer);
                    grp_obj.PutRect("BBox", 0, 0, 1000, 1000);                  // Set the clip box for the content.

                    return(grp_obj);
                }
        }
Beispiel #17
0
 internal static int all_gtrans_match(GState a, GState b, int use_scc)
 {
     /* decides if the states are equivalent */
       GTrans s, t;
       for (s = a.trans.nxt; s != a.trans; s = s.nxt) {
                                     /* all transitions from a appear in b */
         copy_gtrans(s, b.trans);
         t = b.trans.nxt;
         while(same_gtrans(a, s, b, t, use_scc) == 0) t = t.nxt;
         if(t == b.trans) return 0;
       }
       for (t = b.trans.nxt; t != b.trans; t = t.nxt) {
                                     /* all transitions from b appear in a */
         copy_gtrans(t, a.trans);
         s = a.trans.nxt;
         while(same_gtrans(a, s, b, t, use_scc) == 0) s = s.nxt;
         if(s == a.trans) return 0;
       }
       return 1;
 }
 private void GraphCreator_MouseDown(object sender, MouseEventArgs e)
 {
     if (Status.mode == Misc.Mode.Line)
     {
         Point p = FindNear(e.X, e.Y, 10);
         if (p != null && (p.N == lpn || lpn == -1))
         {
             drawLine = true;
             GState prevstate = state;
             state = GState.RouteDraw;
             s     = p;
             x1    = p.X;
             y1    = p.Y;
             if (crs == "")
             {
                 crs += "" + p.N;
             }
         }
     }
 }
Beispiel #19
0
        public void computeRowCards()
        {
            CardCtrl cardCtrl;

            int index = 0;

            for (int i = 0; i < U.config.rowCardLimitNum; i++)
            {
                cardCtrl = rowCardCtrls[i];
                if (cardCtrl == null)
                {
                    continue;
                }
                rowCardCtrls[i] = null;
                if (cardCtrl.card.state != CardState.INROW)
                {
                    continue;
                }

                if (i < U.config.removeCardNum)
                {
                    U.hideCard(cardCtrl);
                    continue;
                }

                rowCardCtrls[index++] = cardCtrl;
            }

            for (int i = index; i < U.config.rowCardLimitNum; i++)
            {
                cardCtrl = getANewCard();
                if (cardCtrl == null)
                {
                    state = GState.OVER;
                    break;
                }
                rowCardCtrls[i] = cardCtrl;
            }
        }
Beispiel #20
0
            /// <summary>
            /// Pushes the given left context into the successor states. If a successor state is empty, continue to push into
            /// this empty states successors
            /// </summary>
            /// <param name="visitedSet"></param>
            /// <param name="leftContext">leftContext the context to push</param>
            void PushLeftContexts(HashSet <GrammarNode> visitedSet, List <UnitContext> leftContext)
            {
                if (visitedSet.Contains(GetNode()))
                {
                    return;
                }
                else
                {
                    visitedSet.Add(GetNode());
                }

                foreach (GrammarArc arc in GetSuccessors())
                {
                    GState gstate = _parent.GetGState(arc.GrammarNode);
                    gstate.AddLeftContext(leftContext);
                    // if our successor state is empty, also push our
                    // ending context into the empty nodes successors
                    if (gstate.GetNode().IsEmpty)
                    {
                        gstate.PushLeftContexts(visitedSet, leftContext);
                    }
                }
            }
Beispiel #21
0
        public void SetReplay(Guid clientId, Guid id, ServerEventHandler callback)
        {
            Error      error  = new Error(StatusCode.OK);
            ReplayData replay = GetReplayData(id);

            if (replay == null)
            {
                error.Code = StatusCode.NotFound;
            }
            else
            {
                GState.SetValue("LocalGameServer.m_replay", replay);
            }

            if (m_lag == 0)
            {
                callback(error);
            }
            else
            {
                Job.Submit(() => { Thread.Sleep(m_lag); return(null); }, result => callback(error));
            }
        }
        static Obj CreateHighlightAppearance(List <Rect> boxes, ColorPt highlightColor, double highlightOpacity, Document document)
        {
            var elementBuilder = new ElementBuilder();

            elementBuilder.PathBegin();

            boxes.ForEach(box => elementBuilder.Rect(box.x1 - 2, box.y1, box.x2 - box.x1, box.y2 - box.y1));

            Element element = elementBuilder.PathEnd();

            element.SetPathFill(true);
            element.SetPathStroke(false);

            GState elementGraphicState = element.GetGState();

            elementGraphicState.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
            elementGraphicState.SetFillColor(highlightColor);
            elementGraphicState.SetFillOpacity(highlightOpacity);
            elementGraphicState.SetBlendMode(GState.BlendMode.e_bl_multiply);

            var elementWriter = new ElementWriter();

            elementWriter.Begin(document);

            elementWriter.WriteElement(element);
            Obj highlightAppearance = elementWriter.End();

            elementBuilder.Dispose();
            elementWriter.Dispose();

            Rect boundingBox = RectangleUnion(boxes);

            highlightAppearance.PutRect("BBox", boundingBox.x1, boundingBox.y1, boundingBox.x2, boundingBox.y2);
            highlightAppearance.PutName("Subtype", "Form");

            return(highlightAppearance);
        }
Beispiel #23
0
        internal static GState find_gstate(int[] set, GState s)
        {
            /* finds the corresponding state, or creates it */

              if(ltl2ba.set.same_sets(set, s.nodes_set, 0) != 0) return s; /* same state */

              s = gstack.nxt; /* in the stack */
              gstack.nodes_set = set;
              while (ltl2ba.set.same_sets(set, s.nodes_set, 0) == 0)
                s = s.nxt;
              if(s != gstack) return s;

              s = gstates.nxt; /* in the solved states */
              gstates.nodes_set = set;
              while (ltl2ba.set.same_sets(set, s.nodes_set, 0) == 0)
                s = s.nxt;
              if(s != gstates) return s;

              s = gremoved.nxt; /* in the removed states */
              gremoved.nodes_set = set;
              while (ltl2ba.set.same_sets(set, s.nodes_set, 0) == 0)
                s = s.nxt;
              if(s != gremoved) return s;

              s = new GState(); /* creates a new state */
              s.id = (ltl2ba.set.empty_set(set, 0)) != 0 ? 0 : gstate_id++;
            //   printf("%d \n", gstate_id);
            //   fflush(stdout);
              s.incoming = 0;
              s.nodes_set = ltl2ba.set.dup_set(set, 0);
              s.trans = mem.emalloc_gtrans(); /* sentinel */
              s.trans.nxt = s.trans;
              s.nxt = gstack.nxt;
              gstack.nxt = s;
              return s;
        }
    void EndGame_Finished()
    {
        GameData.score    = score;
        GameData.health   = health;
        GameData.finished = true;
        GameData.outcome  = "You've Done It!";
        string oneword = "Great!";

        GameData.winLevel = 1;
        if (score >= m_maestro.estimateAllScore)
        {
            oneword           = "Awesome!";
            GameData.winLevel = 2;
        }
        else if (score >= m_maestro.estimatePerfectScore)
        {
            oneword           = "Perfection!";
            GameData.winLevel = 3;
        }
        GameData.oneword = oneword;
        m_state          = GState.End;
        m_maestro.End();
        SceneManager.LoadScene("GameOver");
    }
 void Awake()
 {
     m_state = GState.Init;
     m_score = 0;
 }
Beispiel #26
0
 /* removes a state */
 internal static GState remove_gstate(GState s, GState s1)
 {
     GState prv = s.prv;
       s.prv.nxt = s.nxt;
       s.nxt.prv = s.prv;
       mem.free_gtrans(s.trans.nxt, s.trans, 0);
       s.trans = null;
       mem.tfree(s.nodes_set);
       s.nodes_set = null;
       s.nxt = gremoved.nxt;
       gremoved.nxt = s;
       s.prv = s1;
       for(s1 = gremoved.nxt; s1 != gremoved; s1 = s1.nxt)
         if(s1.prv == s)
           s1.prv = s.prv;
       return prv;
 }
Beispiel #27
0
 public Cursor(GState g, STable klass, int from, int pos, CapInfo captures, P6any ast, string reduced)
 {
     this.global = g;
     this.captures = captures;
     this.pos = pos;
     this.ast = ast;
     this.from = from;
     this.mo = Kernel.MatchMO;
     this.save_klass = klass;
     this.reduced = reduced;
 }
        static void Main(string[] args)
        {
            PDFNet.Initialize();
            try
            {
                using (PDFDoc doc = new PDFDoc())
                    using (ElementWriter writer = new ElementWriter())
                        using (ElementBuilder eb = new ElementBuilder())
                        {
                            // The following sample illustrates how to create and use tiling patterns
                            Page page = doc.PageCreate();
                            writer.Begin(page);

                            Element element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_bold), 1);
                            writer.WriteElement(element);              // Begin the text block

                            element = eb.CreateTextRun("G");
                            element.SetTextMatrix(720, 0, 0, 720, 20, 240);
                            GState gs = element.GetGState();
                            gs.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text);
                            gs.SetLineWidth(4);

                            // Set the fill color space to the Pattern color space.
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateTilingPattern(doc));

                            writer.WriteElement(element);
                            writer.WriteElement(eb.CreateTextEnd()); // Finish the text block

                            writer.End();                            // Save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            /// The following sample illustrates how to create and use image tiling pattern
                            page = doc.PageCreate();
                            writer.Begin(page);

                            eb.Reset();
                            element = eb.CreateRect(0, 0, 612, 794);

                            // Set the fill color space to the Pattern color space.
                            gs = element.GetGState();
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateImageTilingPattern(doc));
                            element.SetPathFill(true);

                            writer.WriteElement(element);

                            writer.End();               // Save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            /// The following sample illustrates how to create and use PDF shadings
                            page = doc.PageCreate();
                            writer.Begin(page);

                            eb.Reset();
                            element = eb.CreateRect(0, 0, 612, 794);

                            // Set the fill color space to the Pattern color space.
                            gs = element.GetGState();
                            gs.SetFillColorSpace(ColorSpace.CreatePattern());
                            gs.SetFillColor(CreateAxialShading(doc));
                            element.SetPathFill(true);

                            writer.WriteElement(element);

                            writer.End();               // save the page
                            doc.PagePushBack(page);
                            //-----------------------------------------------

                            doc.Save(output_path + "patterns.pdf", SDFDoc.SaveOptions.e_remove_unused);
                            Console.WriteLine("Done. Result saved in patterns.pdf...");
                        }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        private void GraphCreator_MouseDown(object sender, MouseEventArgs e)
        {
            if (Status.mode == Misc.Mode.Line)
            {

                Point p = FindNear(e.X, e.Y, 10);
                if (p != null && (p.N == lpn || lpn == -1))
                {

                    drawLine = true;
                    GState prevstate = state;
                    state = GState.RouteDraw;
                    s = p;
                    x1 = p.X;
                    y1 = p.Y;
                    if (crs == "") { crs += "" + p.N;  }
                }
            }

            if (Status.mode == Misc.Mode.Select)
            {

                Point p = FindNear(e.X, e.Y, 10);
                selectedPoint = p;
                if (selectedPoint != null)
                {
                    movePoint = true;
                    Console.WriteLine("movePoint true");
                    //MouseMove+=//OnPaint(new PaintEventArgs(this.CreateGraphics(),new Rectangle(this.Left,this.Top, this.Width, this.Height)));
                }

            }
        }
        public override void OnListPlayers(List<CPlayerInfo> Players, CPlayerSubset Subset)
        {
            PlayerList = Players;

            if (ZombieModeEnabled == false)
                return;

            if (Players.Count + JoinQueue.Count > 0 && GetState() != GState.Idle) DebugWrite("OnListPlayers: " + Players.Count + " players, " + JoinQueue.Count + " joining", 5);

            if (OldGameState != GetState()) DebugWrite("OnListPlayers: GameState = " + GetState(), 3);
            OldGameState = GetState();

            if (CheckIdle(Players))
            {
                // We kicked some idle players, so update the player list again
                RequestPlayersList();
                return;
            }

            List<String> HumanCensus = new List<String>();
            List<String> ZombieCensus = new List<String>();

            foreach (CPlayerInfo Player in Players)
            {
                KillTracker.AddPlayer(Player.SoldierName.ToString());

                // Team tracking
                if (Player.TeamID == 1)
                {
                    HumanCensus.Add(Player.SoldierName);
                    DebugWrite("OnListPlayers: counted " + Player.SoldierName + " as human (" + HumanCensus.Count + ")", 6);
                }
                else if (Player.TeamID == 2)
                {
                    // Othewise, add
                    ZombieCensus.Add(Player.SoldierName);
                    DebugWrite("OnListPlayers: counted " + Player.SoldierName + " as zombie (" + ZombieCensus.Count + ")", 6);
                }
                else
                {
                    DebugWrite("OnListPlayers: unknown team " + Player.TeamID + " for player " + Player.SoldierName, 5);
                }

                RemoveJoinQueue(Player.SoldierName);
            }

            // Check for differences

            KnownPlayerCount = HumanCensus.Count + ZombieCensus.Count;

            bool SomeoneMoved = false;

            lock (TeamHuman)
            {
                if (Players.Count > 0) DebugWrite("OnListPlayers: human count " + TeamHuman.Count + " vs " + HumanCensus.Count + ", zombie count " + TeamZombie.Count + " vs " + ZombieCensus.Count, 6);

                SomeoneMoved = (TeamHuman.Count != HumanCensus.Count);
                SomeoneMoved |= (TeamZombie.Count != ZombieCensus.Count);
            }

            if (GetState() != GState.Idle && (HumanCensus.Count+ZombieCensus.Count) == 0)
            {
                Reset();
                return;
            }

            if (GetState() == GState.Playing)
            {
                if (SomeoneMoved)
                {
                    DebugWrite("OnListPlayers: playing, checking victory conditions", 5);
                }
                CheckVictoryConditions(false);
            }
            else if (GetState() == GState.BetweenRounds)
            {
                DebugWrite("OnListPlayers: between rounds", 5);
            }
            else if (GetState() == GState.Idle || GetState() == GState.Waiting || GetState() == GState.RoundStarting)
            {
                // force update when not playing a match
                if (SomeoneMoved)
                {
                    DebugWrite("OnListPlayers: teams updated, not playing yet", 5);

                    lock (TeamHuman)
                    {
                        TeamHuman.Clear();
                        TeamHuman.AddRange(HumanCensus);
                        TeamZombie.Clear();
                        TeamZombie.AddRange(ZombieCensus);
                    }
                }
            }
        }
        private void GraphCreator_MouseDown(object sender, MouseEventArgs e)
        {
            if (Status.mode == Misc.Mode.Line)
            {

                Point p = FindNear(e.X, e.Y, 10);
                if (p != null && (p.N == lpn || lpn == -1))
                {

                    drawLine = true;
                    GState prevstate = state;
                    state = GState.RouteDraw;
                    s = p;
                    x1 = p.X;
                    y1 = p.Y;
                    if (crs == "") { crs += "" + p.N;  }
                }
            }
        }
Beispiel #32
0
 void Win()
 {
     tree.GetComponent <SpriteRenderer>().color = Color.white;
     currentState = GState.win;
     winMenu.SetActive(true);
 }
Beispiel #33
0
 public Cursor(GState g, DynMetaObject klass, int from, int pos, CapInfo captures)
 {
     this.global = g;
     this.captures = captures;
     this.pos = pos;
     this.from = from;
     this.mo = Kernel.MatchMO;
     this.save_klass = klass;
 }
 void PlayGame()
 {
     m_state = GState.Playing;
     m_maestro.Begin();
 }
Beispiel #35
0
        internal static int gdfs(GState s)
        {
            GTrans t;
              GScc c;
              GScc scc = new GScc();
              scc.gstate = s;
              scc.rank = rank;
              scc.theta = rank++;
              scc.nxt = scc_stack;
              scc_stack = scc;

              s.incoming = 1;

              for (t = s.trans.nxt; t != s.trans; t = t.nxt) {
                if (t.to.incoming == 0) {
                  int result = gdfs(t.to);
                  scc.theta = Math.Min(scc.theta, result);
                }
                else {
                  for(c = scc_stack.nxt; c != null; c = c.nxt)
                if(c.gstate == t.to) {
                  scc.theta = Math.Min(scc.theta, c.rank);
                  break;
                }
                }
              }
              if(scc.rank == scc.theta) {
                while(scc_stack != scc) {
                  scc_stack.gstate.incoming = scc_id;
                  scc_stack = scc_stack.nxt;
                }
                scc.gstate.incoming = scc_id++;
                scc_stack = scc.nxt;
              }
              return scc.theta;
        }
Beispiel #36
0
 internal static int same_gtrans(GState a, GTrans s, GState b, GTrans t, int use_scc)
 {
     /* returns 1 if the transitions are identical */
       if((s.to != t.to) ||
           set.same_sets(s.pos, t.pos, 1) == 0 ||
           set.same_sets(s.neg, t.neg, 1) == 0)
         return 0; /* transitions differ */
       if(set.same_sets(s.final, t.final, 0) != 0)
         return 1; /* same transitions exactly */
       /* next we check whether acceptance conditions may be ignored */
       if( use_scc != 0 &&
           ( set.in_set(bad_scc, a.incoming) != 0 ||
             set.in_set(bad_scc, b.incoming) != 0 ||
             (a.incoming != s.to.incoming) ||
             (b.incoming != t.to.incoming) ) )
         return 1;
       return 0;
       /* below is the old test to check whether acceptance conditions may be ignored */
       //if(use_scc == 0)
         //return 0; /* transitions differ */
       //if( (a.incoming == b.incoming) && (a.incoming == s.to.incoming) )
         //return 0; /* same scc: acceptance conditions must be taken into account */
       /* if scc(a)=scc(b)>scc(s.to) then acceptance conditions need not be taken into account */
       /* if scc(a)>scc(b) and scc(a) is non-trivial then all_gtrans_match(a,b,use_scc) will fail */
       /* if scc(a) is trivial then acceptance conditions of transitions from a need not be taken into account */
       return 1; /* same transitions up to acceptance conditions */
 }
Beispiel #37
0
        internal static void mk_generalized()
        {
            /* generates a generalized Buchi automaton from the alternating automaton */
              ATrans t;
              GState s;
              int i;

              //if(tl_stats) getrusage(RUSAGE_SELF, &tr_debut);

              fin = set.new_set(0);
              bad_scc = null; /* will be initialized in simplify_gscc */
              final = set.list_set(alternating.final_set, 0);

              gstack        = new GState(); /* sentinel */
              gstack.nxt   = gstack;
              gremoved      = new GState(); /* sentinel */
              gremoved.nxt = gremoved;
              gstates       = new GState(); /* sentinel */
              gstates.nxt  = gstates;
              gstates.prv  = gstates;

              for(t = alternating.transition[0]; t != null; t = t.nxt) { /* puts initial states in the stack */
                s = new GState();
                s.id = (set.empty_set(t.to, 0)) != 0 ? 0 : gstate_id++;
                s.incoming = 1;
                s.nodes_set = set.dup_set(t.to, 0);
                s.trans = mem.emalloc_gtrans(); /* sentinel */
                s.trans.nxt = s.trans;
                s.nxt = gstack.nxt;
                gstack.nxt = s;
                init_size++;
              }

              if(init_size != 0) init = new GState[init_size];
              init_size = 0;
              for(s = gstack.nxt; s != gstack; s = s.nxt)
                init[init_size++] = s;

              while(gstack.nxt != gstack) { /* solves all states in the stack until it is empty */
                s = gstack.nxt;
                gstack.nxt = gstack.nxt.nxt;
                if(s.incoming == 0) {
                  free_gstate(s);
                  continue;
                }
                make_gtrans(s);
              }

              retarget_all_gtrans();
            /*
              if(tl_stats) {
                getrusage(RUSAGE_SELF, &tr_fin);
                timeval_subtract (&t_diff, &tr_fin.ru_utime, &tr_debut.ru_utime);
                fprintf(tl_out, "\nBuilding the generalized Buchi automaton : %i.%06is",
                    t_diff.tv_sec, t_diff.tv_usec);
                fprintf(tl_out, "\n%i states, %i transitions\n", gstate_count, gtrans_count);
              }*/

              mem.tfree(gstack);
              /*for(i = 0; i < node_id; i++) /* frees the data from the alternating automaton */
              /*free_atrans(transition[i], 1);*/
              //mem.free_all_atrans();
              mem.tfree(alternating.transition);

              //if(tl_verbose) {
              //  fprintf(tl_out, "\nGeneralized Buchi automaton before simplification\n");
              //  print_generalized();
              //}

              if(main.tl_simp_diff != 0) {
                if (main.tl_simp_scc != 0) simplify_gscc();
                simplify_gtrans();
                if (main.tl_simp_scc != 0) simplify_gscc();
                while(simplify_gstates() != 0) { /* simplifies as much as possible */
                  if (main.tl_simp_scc != 0) simplify_gscc();
                  simplify_gtrans();
                  if (main.tl_simp_scc != 0) simplify_gscc();
                }
            //
            //     if(tl_verbose) {
            //       fprintf(tl_out, "\nGeneralized Buchi automaton after simplification\n");
            //       print_generalized();
            //     }
              }
        }
Beispiel #38
0
 public RxFrame(string name, Cursor csr, bool passcut)
 {
     global = csr.global;
     orig = global.orig_a;
     end = orig.Length;
     rootf = bt = csr.xact;
     this.name = name;
     st.ns = passcut ? csr.nstate :
         new NState(rootf, name, csr.nstate);
     if (Cursor.Trace) {
         Console.WriteLine("Entering subrule {0} at {1}/{2}", name, csr.pos,
                 end);
     }
     st.ns.klass = csr.mo;
     st.pos = csr.pos;
     from = csr.pos;
 }
 public void ResetRouteInfo()
 {
     lpn = -1;
     crs = "";
     tempedges.Clear();
     state = GState.NodesAndRoutes;
 }
Beispiel #40
0
 public Cursor(GState g, STable klass, RxFrame feedback, NState ns, Choice xact, int pos, CapInfo captures)
 {
     this.mo = this.save_klass = klass;
     this.xact = xact;
     this.nstate = ns;
     this.feedback = feedback;
     this.global = g;
     this.pos = pos;
     this.captures = captures;
 }
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";


            try
            {
                using (PDFDoc doc = new PDFDoc())
                    using (ElementBuilder eb = new ElementBuilder())                    // ElementBuilder is used to build new Element objects
                        using (ElementWriter writer = new ElementWriter())              // ElementWriter is used to write Elements to the page
                        {
                            // Start a new page ------------------------------------
                            // Position an image stream on several places on the page
                            Page page = doc.PageCreate(new Rect(0, 0, 612, 794));

                            writer.Begin(page);                 // begin writing to this page

                            // Create an Image that can be reused multiple times in the document or
                            // multiple on the same page.
                            MappedFile   img_file = new MappedFile(input_path + "peppers.jpg");
                            FilterReader img_data = new FilterReader(img_file);
                            Image        img      = Image.Create(doc, img_data, 400, 600, 8, ColorSpace.CreateDeviceRGB(), Image.InputFilter.e_jpeg);

                            Element element = eb.CreateImage(img, new Matrix2D(200, -145, 20, 300, 200, 150));
                            writer.WritePlacedElement(element);

                            GState gstate = element.GetGState();                // use the same image (just change its matrix)
                            gstate.SetTransform(200, 0, 0, 300, 50, 450);
                            writer.WritePlacedElement(element);

                            // use the same image again (just change its matrix).
                            writer.WritePlacedElement(eb.CreateImage(img, 300, 600, 200, -150));

                            writer.End();              // save changes to the current page
                            doc.PagePushBack(page);

                            // Start a new page ------------------------------------
                            // Construct and draw a path object using different styles
                            page = doc.PageCreate(new Rect(0, 0, 612, 794));

                            writer.Begin(page);                 // begin writing to this page
                            eb.Reset();                         // Reset GState to default


                            eb.PathBegin();                     // start constructing the path
                            eb.MoveTo(306, 396);
                            eb.CurveTo(681, 771, 399.75, 864.75, 306, 771);
                            eb.CurveTo(212.25, 864.75, -69, 771, 306, 396);
                            eb.ClosePath();
                            element = eb.PathEnd();                             // the path is now finished
                            element.SetPathFill(true);                          // the path should be filled

                            // Set the path color space and color
                            gstate = element.GetGState();
                            gstate.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
                            gstate.SetFillColor(new ColorPt(1, 0, 0, 0));              // cyan
                            gstate.SetTransform(0.5, 0, 0, 0.5, -20, 300);
                            writer.WritePlacedElement(element);

                            // Draw the same path using a different stroke color
                            element.SetPathStroke(true);                        // this path is should be filled and stroked
                            gstate.SetFillColor(new ColorPt(0, 0, 1, 0));       // yellow
                            gstate.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
                            gstate.SetStrokeColor(new ColorPt(1, 0, 0));        // red
                            gstate.SetTransform(0.5, 0, 0, 0.5, 280, 300);
                            gstate.SetLineWidth(20);
                            writer.WritePlacedElement(element);

                            // Draw the same path with with a given dash pattern
                            element.SetPathFill(false);                  // this path is should be only stroked
                            gstate.SetStrokeColor(new ColorPt(0, 0, 1)); // blue
                            gstate.SetTransform(0.5, 0, 0, 0.5, 280, 0);
                            double[] dash_pattern = { 30 };
                            gstate.SetDashPattern(dash_pattern, 0);
                            writer.WritePlacedElement(element);

                            // Use the path as a clipping path
                            writer.WriteElement(eb.CreateGroupBegin());                 // Save the graphics state
                            // Start constructing a new path (the old path was lost when we created
                            // a new Element using CreateGroupBegin()).
                            eb.PathBegin();
                            eb.MoveTo(306, 396);
                            eb.CurveTo(681, 771, 399.75, 864.75, 306, 771);
                            eb.CurveTo(212.25, 864.75, -69, 771, 306, 396);
                            eb.ClosePath();
                            element = eb.PathEnd();             // path is now built
                            element.SetPathClip(true);          // this path is a clipping path
                            element.SetPathStroke(true);        // this path is should be filled and stroked
                            gstate = element.GetGState();
                            gstate.SetTransform(0.5, 0, 0, 0.5, -20, 0);
                            writer.WriteElement(element);
                            writer.WriteElement(eb.CreateImage(img, 100, 300, 400, 600));
                            writer.WriteElement(eb.CreateGroupEnd()); // Restore the graphics state

                            writer.End();                             // save changes to the current page
                            doc.PagePushBack(page);


                            // Start a new page ------------------------------------
                            page = doc.PageCreate(new Rect(0, 0, 612, 794));

                            writer.Begin(page);                 // begin writing to this page
                            eb.Reset();                         // Reset GState to default

                            // Begin writing a block of text
                            element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_roman), 12);
                            writer.WriteElement(element);

                            string data = "Hello World!";
                            element = eb.CreateTextRun(data);
                            element.SetTextMatrix(10, 0, 0, 10, 0, 600);
                            element.GetGState().SetLeading(15);                          // Set the spacing between lines
                            writer.WriteElement(element);

                            writer.WriteElement(eb.CreateTextNewLine());              // New line

                            element = eb.CreateTextRun(data);
                            gstate  = element.GetGState();
                            gstate.SetTextRenderMode(GState.TextRenderingMode.e_stroke_text);
                            gstate.SetCharSpacing(-1.25);
                            gstate.SetWordSpacing(-1.25);
                            writer.WriteElement(element);

                            writer.WriteElement(eb.CreateTextNewLine());              // New line

                            element = eb.CreateTextRun(data);
                            gstate  = element.GetGState();
                            gstate.SetCharSpacing(0);
                            gstate.SetWordSpacing(0);
                            gstate.SetLineWidth(3);
                            gstate.SetTextRenderMode(GState.TextRenderingMode.e_fill_stroke_text);
                            gstate.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
                            gstate.SetStrokeColor(new ColorPt(1, 0, 0));                // red
                            gstate.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
                            gstate.SetFillColor(new ColorPt(1, 0, 0, 0));               // cyan
                            writer.WriteElement(element);

                            writer.WriteElement(eb.CreateTextNewLine());              // New line

                            // Set text as a clipping path to the image.
                            element = eb.CreateTextRun(data);
                            gstate  = element.GetGState();
                            gstate.SetTextRenderMode(GState.TextRenderingMode.e_clip_text);
                            writer.WriteElement(element);

                            // Finish the block of text
                            writer.WriteElement(eb.CreateTextEnd());

                            // Draw an image that will be clipped by the above text
                            writer.WriteElement(eb.CreateImage(img, 10, 100, 1300, 720));

                            writer.End();              // save changes to the current page
                            doc.PagePushBack(page);

                            // Start a new page ------------------------------------
                            //
                            // The example illustrates how to embed the external font in a PDF document.
                            // The example also shows how ElementReader can be used to copy and modify
                            // Elements between pages.

                            using (ElementReader reader = new ElementReader())
                            {
                                // Start reading Elements from the last page. We will copy all Elements to
                                // a new page but will modify the font associated with text.
                                reader.Begin(doc.GetPage(doc.GetPageCount()));

                                page = doc.PageCreate(new Rect(0, 0, 1300, 794));

                                writer.Begin(page);                     // begin writing to this page
                                eb.Reset();                             // Reset GState to default

                                // Embed an external font in the document.
                                Font font = Font.CreateTrueTypeFont(doc, input_path + "font.ttf");

                                while ((element = reader.Next()) != null)                       // Read page contents
                                {
                                    if (element.GetType() == Element.Type.e_text)
                                    {
                                        element.GetGState().SetFont(font, 12);
                                    }

                                    writer.WriteElement(element);
                                }

                                reader.End();
                                writer.End();                  // save changes to the current page

                                doc.PagePushBack(page);


                                // Start a new page ------------------------------------
                                //
                                // The example illustrates how to embed the external font in a PDF document.
                                // The example also shows how ElementReader can be used to copy and modify
                                // Elements between pages.

                                // Start reading Elements from the last page. We will copy all Elements to
                                // a new page but will modify the font associated with text.
                                reader.Begin(doc.GetPage(doc.GetPageCount()));

                                page = doc.PageCreate(new Rect(0, 0, 1300, 794));

                                writer.Begin(page);                     // begin writing to this page
                                eb.Reset();                             // Reset GState to default

                                // Embed an external font in the document.
                                Font font2 = Font.CreateType1Font(doc, input_path + "Misc-Fixed.pfa");

                                while ((element = reader.Next()) != null)                       // Read page contents
                                {
                                    if (element.GetType() == Element.Type.e_text)
                                    {
                                        element.GetGState().SetFont(font2, 12);
                                    }

                                    writer.WriteElement(element);
                                }

                                reader.End();
                                writer.End();                  // save changes to the current page
                                doc.PagePushBack(page);


                                // Start a new page ------------------------------------
                                page = doc.PageCreate();
                                writer.Begin(page);                     // begin writing to this page
                                eb.Reset();                             // Reset GState to default

                                // Begin writing a block of text
                                element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_roman), 12);
                                element.SetTextMatrix(1.5, 0, 0, 1.5, 50, 600);
                                element.GetGState().SetLeading(15);                     // Set the spacing between lines
                                writer.WriteElement(element);

                                string para = "A PDF text object consists of operators that can show " +
                                              "text strings, move the text position, and set text state and certain " +
                                              "other parameters. In addition, there are three parameters that are " +
                                              "defined only within a text object and do not persist from one text " +
                                              "object to the next: Tm, the text matrix, Tlm, the text line matrix, " +
                                              "Trm, the text rendering matrix, actually just an intermediate result " +
                                              "that combines the effects of text state parameters, the text matrix " +
                                              "(Tm), and the current transformation matrix";

                                int para_end = para.Length;
                                int text_run = 0;
                                int text_run_end;

                                double para_width = 300;                 // paragraph width is 300 units
                                double cur_width  = 0;

                                while (text_run < para_end)
                                {
                                    text_run_end = para.IndexOf(' ', text_run);
                                    if (text_run_end < 0)
                                    {
                                        text_run_end = para_end - 1;
                                    }

                                    string text = para.Substring(text_run, text_run_end - text_run + 1);
                                    element = eb.CreateTextRun(text);
                                    if (cur_width + element.GetTextLength() < para_width)
                                    {
                                        writer.WriteElement(element);
                                        cur_width += element.GetTextLength();
                                    }
                                    else
                                    {
                                        writer.WriteElement(eb.CreateTextNewLine());                          // New line
                                        text      = para.Substring(text_run, text_run_end - text_run + 1);
                                        element   = eb.CreateTextRun(text);
                                        cur_width = element.GetTextLength();
                                        writer.WriteElement(element);
                                    }

                                    text_run = text_run_end + 1;
                                }

                                // -----------------------------------------------------------------------
                                // The following code snippet illustrates how to adjust spacing between
                                // characters (text runs).
                                element = eb.CreateTextNewLine();
                                writer.WriteElement(element); // Skip 2 lines
                                writer.WriteElement(element);

                                writer.WriteElement(eb.CreateTextRun("An example of space adjustments between inter-characters:"));
                                writer.WriteElement(eb.CreateTextNewLine());

                                // Write string "AWAY" without space adjustments between characters.
                                element = eb.CreateTextRun("AWAY");
                                writer.WriteElement(element);

                                writer.WriteElement(eb.CreateTextNewLine());

                                // Write string "AWAY" with space adjustments between characters.
                                element = eb.CreateTextRun("A");
                                writer.WriteElement(element);

                                element = eb.CreateTextRun("W");
                                element.SetPosAdjustment(140);
                                writer.WriteElement(element);

                                element = eb.CreateTextRun("A");
                                element.SetPosAdjustment(140);
                                writer.WriteElement(element);

                                element = eb.CreateTextRun("Y again");
                                element.SetPosAdjustment(115);
                                writer.WriteElement(element);

                                // Draw the same strings using direct content output...
                                writer.Flush(); // flush pending Element writing operations.

                                // You can also write page content directly to the content stream using
                                // ElementWriter.WriteString(...) and ElementWriter.WriteBuffer(...) methods.
                                // Note that if you are planning to use these functions you need to be familiar
                                // with PDF page content operators (see Appendix A in PDF Reference Manual).
                                // Because it is easy to make mistakes during direct output we recommend that
                                // you use ElementBuilder and Element interface instead.
                                writer.WriteString("T* T* ");                 // New Lines
                                // writer.WriteElement(eb.CreateTextNewLine());
                                writer.WriteString("(Direct output to PDF page content stream:) Tj  T* ");
                                writer.WriteString("(AWAY) Tj T* ");
                                writer.WriteString("[(A)140(W)140(A)115(Y again)] TJ ");

                                // Finish the block of text
                                writer.WriteElement(eb.CreateTextEnd());

                                writer.End();                  // save changes to the current page
                                doc.PagePushBack(page);

                                // Start a new page ------------------------------------

                                // Image Masks
                                //
                                // In the opaque imaging model, images mark all areas they occupy on the page as
                                // if with opaque paint. All portions of the image, whether black, white, gray,
                                // or color, completely obscure any marks that may previously have existed in the
                                // same place on the page.
                                // In the graphic arts industry and page layout applications, however, it is common
                                // to crop or 'mask out' the background of an image and then place the masked image
                                // on a different background, allowing the existing background to show through the
                                // masked areas. This sample illustrates how to use image masks.

                                page = doc.PageCreate();
                                writer.Begin(page); // begin writing to the page

                                // Create the Image Mask
                                MappedFile   imgf      = new MappedFile(input_path + "imagemask.dat");
                                FilterReader mask_read = new FilterReader(imgf);

                                ColorSpace device_gray = ColorSpace.CreateDeviceGray();
                                Image      mask        = Image.Create(doc, mask_read, 64, 64, 1, device_gray, Image.InputFilter.e_ascii_hex);

                                mask.GetSDFObj().PutBool("ImageMask", true);

                                element = eb.CreateRect(0, 0, 612, 794);
                                element.SetPathStroke(false);
                                element.SetPathFill(true);
                                element.GetGState().SetFillColorSpace(device_gray);
                                element.GetGState().SetFillColor(new ColorPt(0.8));
                                writer.WritePlacedElement(element);

                                element = eb.CreateImage(mask, new Matrix2D(200, 0, 0, -200, 40, 680));
                                element.GetGState().SetFillColor(new ColorPt(0.1));
                                writer.WritePlacedElement(element);

                                element.GetGState().SetFillColorSpace(ColorSpace.CreateDeviceRGB());
                                element.GetGState().SetFillColor(new ColorPt(1, 0, 0));
                                element = eb.CreateImage(mask, new Matrix2D(200, 0, 0, -200, 320, 680));
                                writer.WritePlacedElement(element);

                                element.GetGState().SetFillColor(new ColorPt(0, 1, 0));
                                element = eb.CreateImage(mask, new Matrix2D(200, 0, 0, -200, 40, 380));
                                writer.WritePlacedElement(element);

                                {
                                    // This sample illustrates Explicit Masking.
                                    img = Image.Create(doc, input_path + "peppers.jpg");

                                    // mask is the explicit mask for the primary (base) image
                                    img.SetMask(mask);

                                    element = eb.CreateImage(img, new Matrix2D(200, 0, 0, -200, 320, 380));
                                    writer.WritePlacedElement(element);
                                }

                                writer.End(); // save changes to the current page
                                doc.PagePushBack(page);

                                // Transparency sample ----------------------------------

                                // Start a new page -------------------------------------
                                page = doc.PageCreate();
                                writer.Begin(page);                     // begin writing to this page
                                eb.Reset();                             // Reset the GState to default

                                // Write some transparent text at the bottom of the page.
                                element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_roman), 100);

                                // Set the text knockout attribute. Text knockout must be set outside of
                                // the text group.
                                gstate = element.GetGState();
                                gstate.SetTextKnockout(false);
                                gstate.SetBlendMode(GState.BlendMode.e_bl_difference);
                                writer.WriteElement(element);

                                element = eb.CreateTextRun("Transparency");
                                element.SetTextMatrix(1, 0, 0, 1, 30, 30);
                                gstate = element.GetGState();
                                gstate.SetFillColorSpace(ColorSpace.CreateDeviceCMYK());
                                gstate.SetFillColor(new ColorPt(1, 0, 0, 0));

                                gstate.SetFillOpacity(0.5);
                                writer.WriteElement(element);

                                // Write the same text on top the old; shifted by 3 points
                                element.SetTextMatrix(1, 0, 0, 1, 33, 33);
                                gstate.SetFillColor(new ColorPt(0, 1, 0, 0));
                                gstate.SetFillOpacity(0.5);

                                writer.WriteElement(element);
                                writer.WriteElement(eb.CreateTextEnd());

                                // Draw three overlapping transparent circles.
                                eb.PathBegin();                         // start constructing the path
                                eb.MoveTo(459.223, 505.646);
                                eb.CurveTo(459.223, 415.841, 389.85, 343.04, 304.273, 343.04);
                                eb.CurveTo(218.697, 343.04, 149.324, 415.841, 149.324, 505.646);
                                eb.CurveTo(149.324, 595.45, 218.697, 668.25, 304.273, 668.25);
                                eb.CurveTo(389.85, 668.25, 459.223, 595.45, 459.223, 505.646);
                                element = eb.PathEnd();
                                element.SetPathFill(true);

                                gstate = element.GetGState();
                                gstate.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
                                gstate.SetFillColor(new ColorPt(0, 0, 1));                                     // Blue Circle

                                gstate.SetBlendMode(GState.BlendMode.e_bl_normal);
                                gstate.SetFillOpacity(0.5);
                                writer.WriteElement(element);

                                // Translate relative to the Blue Circle
                                gstate.SetTransform(1, 0, 0, 1, 113, -185);
                                gstate.SetFillColor(new ColorPt(0, 1, 0));                                     // Green Circle
                                gstate.SetFillOpacity(0.5);
                                writer.WriteElement(element);

                                // Translate relative to the Green Circle
                                gstate.SetTransform(1, 0, 0, 1, -220, 0);
                                gstate.SetFillColor(new ColorPt(1, 0, 0));                                     // Red Circle
                                gstate.SetFillOpacity(0.5);
                                writer.WriteElement(element);

                                writer.End();                  // save changes to the current page
                                doc.PagePushBack(page);

                                // End page ------------------------------------
                            }

                            doc.Save(output_path + "element_builder.pdf", SDFDoc.SaveOptions.e_remove_unused);
                            Console.WriteLine("Done. Result saved in element_builder.pdf...");
                        }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #42
0
 /* frees a state and its transitions */
 internal static void free_gstate(GState s)
 {
     mem.free_gtrans(s.trans.nxt, s.trans, 1);
     mem.tfree(s.nodes_set);
     mem.tfree(s);
 }
Beispiel #43
0
 public Cursor(GState g, DynMetaObject klass, NState ns, Choice xact, int pos, CapInfo captures)
 {
     this.mo = klass;
     this.xact = xact;
     this.nstate = ns;
     this.global = g;
     this.pos = pos;
     this.captures = captures;
 }
Beispiel #44
0
        internal static BState find_bstate(ref GState state, int final, BState s)
        {
            /* finds the corresponding state, or creates it */
            if ((s.gstate == state) && (s.final == final)) return s; /* same state */

            s = bstack.nxt; /* in the stack */
            bstack.gstate = state;
            bstack.final = final;
            while (!(s.gstate == state) || !(s.final == final))
                s = s.nxt;
            if (s != bstack) return s;

            s = bstates.nxt; /* in the solved states */
            bstates.gstate = state;
            bstates.final = final;
            while (!(s.gstate == state) || !(s.final == final))
                s = s.nxt;
            if (s != bstates) return s;

            s = bremoved.nxt; /* in the removed states */
            bremoved.gstate = state;
            bremoved.final = final;
            while (!(s.gstate == state) || !(s.final == final))
                s = s.nxt;
            if (s != bremoved) return s;

            s = new BState(); /* creates a new state */
            s.gstate = state;
            s.id = (state).id;
            s.incoming = 0;
            s.final = final;
            s.trans = mem.emalloc_btrans(); /* sentinel */
            s.trans.nxt = s.trans;
            s.nxt = bstack.nxt;
            bstack.nxt = s;
            return s;
        }
        static void ProcessElements(ElementReader reader, ElementWriter writer, XSet visited)
        {
            Element element;

            while ((element = reader.Next()) != null)             // Read page contents
            {
                switch (element.GetType())
                {
                case Element.Type.e_image:
                case Element.Type.e_inline_image:
                    // remove all images by skipping them
                    break;

                case Element.Type.e_path:
                {
                    // Set all paths to red color.
                    GState gs = element.GetGState();
                    gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
                    gs.SetFillColor(new ColorPt(1, 0, 0));
                    writer.WriteElement(element);
                    break;
                }

                case Element.Type.e_text:
                {
                    // Set all text to blue color.
                    GState gs = element.GetGState();
                    gs.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
                    gs.SetFillColor(new ColorPt(0, 0, 1));
                    writer.WriteElement(element);
                    break;
                }

                case Element.Type.e_form:
                {
                    writer.WriteElement(element);                                     // write Form XObject reference to current stream

                    Obj form_obj = element.GetXObject();
                    if (!visited.Contains(form_obj.GetObjNum()))                                     // if this XObject has not been processed
                    {
                        // recursively process the Form XObject
                        visited.Add(form_obj.GetObjNum());
                        ElementWriter new_writer = new ElementWriter();

                        reader.FormBegin();
                        new_writer.Begin(form_obj, true);

                        reader.ClearChangeList();
                        new_writer.SetDefaultGState(reader);

                        ProcessElements(reader, new_writer, visited);
                        new_writer.End();
                        reader.End();
                    }
                    break;
                }

                default:
                    writer.WriteElement(element);
                    break;
                }
            }
        }
Beispiel #46
0
 void Lose()
 {
     tree.GetComponent <SpriteRenderer>().color = Color.white;
     currentState = GState.lose;
     loseMenu.SetActive(true);
 }
 private void SetState(GState state)
 {
     lock (StateLock)
     {
         GameState = state;
     }
 }
Beispiel #48
0
    // Update is called once per frame
    void Update()
    {
        counter.text = ((int)timeToWin).ToString();
        if (Time.time - currentTime > timeToWin)
        {
            won = true;
        }
        switch (currentState)
        {
        case GState.zones:
            Timer();
            if (currentPattern >= 0)
            {
                if (Time.time - currentTime > timer)
                {
                    if (won)
                    {
                        Win();
                        Debug.Log("Zone TimeWIN");
                    }
                    else
                    {
                        if (hit)
                        {
                            NextPattern(currentPattern);
                            if (allPatterns[currentPattern] == "Axe")
                            {
                                currentState = GState.axe;
                                treePrompt.SetActive(true);
                                currentHits = 0;
                                tree.GetComponent <SpriteRenderer>().color = Color.white;
                            }
                        }
                        else
                        {
                            Lose();
                            Debug.Log("Zone LOSE");
                        }
                    }
                }
            }
            else
            {
                Win();
                Debug.Log("Zone Win");
            }

            break;

        case GState.axe:
            Timer();
            if (Time.time - currentTime > axeTimer)
            {
                if (won)
                {
                    Win();
                    Debug.Log("Axe TimeWIN");
                }
                else
                {
                    if (currentHits >= nHits)
                    {
                        if (currentPattern > 0)
                        {
                            currentTime  = Time.time;
                            currentState = GState.wait;
                            treePrompt.SetActive(false);

                            //SpawnSparkle();
                        }
                        else
                        {
                            Win();
                            Debug.Log("Axe Win");
                        }
                    }
                    else
                    {
                        tree.GetComponent <SpriteRenderer>().color = Color.white;
                        Lose();
                        Debug.Log("Axe Lose");
                    }
                }
            }
            break;

        case GState.win:
            break;

        case GState.lose:
            break;

        case GState.wait:
            if (Time.time - currentTime > waitAferAxe)
            {
                currentState = GState.zones;
                NextPattern(currentPattern);
            }
            break;

        default:
            break;
        }
    }
Beispiel #49
0
        internal static void make_gtrans(GState s)
        {
            /* creates all the transitions from a state */
              int i, state_trans = 0, trans_exist = 1;
              int[] list;
              GState s1;
              GTrans t;
              ATrans t1, free;
              AProd prod = new AProd(); /* initialization */
              prod.nxt = prod;
              prod.prv = prod;
              prod.prod = mem.emalloc_atrans();
              set.clear_set(prod.prod.to,  0);
              set.clear_set(prod.prod.pos, 1);
              set.clear_set(prod.prod.neg, 1);
              prod.trans = prod.prod;
              prod.trans.nxt = prod.prod;
              list = set.list_set(s.nodes_set, 0);

              for(i = 1; i < list[0]; i++) {
                AProd p = new AProd();
                p.astate = list[i];
                p.trans = alternating.transition[list[i]];
                if(p.trans == null) trans_exist = 0;
                p.prod = alternating.merge_trans(prod.nxt.prod, p.trans);
                p.nxt = prod.nxt;
                p.prv = prod;
                p.nxt.prv = p;
                p.prv.nxt = p;
              }

              while(trans_exist != 0) { /* calculates all the transitions */
                AProd p = prod.nxt;
                t1 = p.prod;
                if(t1 != null) { /* solves the current transition */
                  GTrans trans, t2;
                  set.clear_set(fin, 0);
                  for(i = 1; i < final[0]; i++)
                if(is_final(s.nodes_set, t1, final[i]) != 0)
                  set.add_set(fin, final[i]);
                  for(t2 = s.trans.nxt; t2 != s.trans;) {
                if(main.tl_simp_fly != 0 &&
                   set.included_set(t1.to, t2.to.nodes_set, 0) != 0 &&
                   set.included_set(t1.pos, t2.pos, 1) != 0 &&
                   set.included_set(t1.neg, t2.neg, 1) != 0 &&
                   set.same_sets(fin, t2.final, 0) != 0) { /* t2 is redondant */
                  GTrans free1 = t2.nxt;
                  t2.to.incoming--;
                  t2.to = free1.to;
                  set.copy_set(free1.pos, t2.pos, 1);
                  set.copy_set(free1.neg, t2.neg, 1);
                  set.copy_set(free1.final, t2.final, 0);
                  t2.nxt   = free1.nxt;
                  if(free1 == s.trans) s.trans = t2;
                  mem.free_gtrans(free1, null, 0);
                  state_trans--;
                }
                else if(main.tl_simp_fly != 0 &&
                    set.included_set(t2.to.nodes_set, t1.to, 0) != 0 &&
                    set.included_set(t2.pos, t1.pos, 1) != 0 &&
                    set.included_set(t2.neg, t1.neg, 1) != 0 &&
                    set.same_sets(t2.final, fin, 0) != 0) {/* t1 is redondant */
                  break;
                }
                else {
                  t2 = t2.nxt;
                }
                  }
                  if(t2 == s.trans) { /* adds the transition */
                trans = mem.emalloc_gtrans();
                trans.to = find_gstate(t1.to, s);
                trans.to.incoming++;
                set.copy_set(t1.pos, trans.pos, 1);
                set.copy_set(t1.neg, trans.neg, 1);
                set.copy_set(fin, trans.final, 0);
                trans.nxt = s.trans.nxt;
                s.trans.nxt = trans;
                state_trans++;
                  }
                }
                if(p.trans == null)
                  break;
                while(p.trans.nxt == null) /* calculates the next transition */
                  p = p.nxt;
                if(p == prod)
                  break;
                p.trans = p.trans.nxt;
                alternating.do_merge_trans(ref p.prod, p.nxt.prod, p.trans);
                p = p.prv;
                while(p != prod) {
                  p.trans = alternating.transition[p.astate];
                  alternating.do_merge_trans(ref (p.prod), p.nxt.prod, p.trans);
                  p = p.prv;
                }
              }

              mem.tfree(list); /* free memory */
              while(prod.nxt != prod) {
                AProd p = prod.nxt;
                prod.nxt = p.nxt;
                mem.free_atrans(p.prod, 0);
                mem.tfree(p);
              }
              mem.free_atrans(prod.prod, 0);
              mem.tfree(prod);

              if(main.tl_simp_fly != 0) {
                if(s.trans == s.trans.nxt) { /* s has no transitions */
                  mem.free_gtrans(s.trans.nxt, s.trans, 1);
                  s.trans = null;
                  s.prv = null;
                  s.nxt = gremoved.nxt;
                  gremoved.nxt = s;
                  for(s1 = gremoved.nxt; s1 != gremoved; s1 = s1.nxt)
                if(s1.prv == s)
                s1.prv = null;
                  return;
                }

                gstates.trans = s.trans;
                s1 = gstates.nxt;
                while(all_gtrans_match(s, s1, 0) == 0)
                  s1 = s1.nxt;
                if(s1 != gstates) { /* s and s1 are equivalent */
                  mem.free_gtrans(s.trans.nxt, s.trans, 1);
                  s.trans = null;
                  s.prv = s1;
                  s.nxt = gremoved.nxt;
                  gremoved.nxt = s;
                  for(s1 = gremoved.nxt; s1 != gremoved; s1 = s1.nxt)
                if(s1.prv == s)
                  s1.prv = s.prv;
                  return;
                }
              }

              s.nxt = gstates.nxt; /* adds the current state to 'gstates' */
              s.prv = gstates;
              s.nxt.prv = s;
              gstates.nxt = s;
              gtrans_count += state_trans;
              gstate_count++;
        }