Thx!

I was testing the getHTML and setHTML and it worked good, the CPU is
going up to ~40% when it's redrawing now and not max everytime. The
memory is very very slowly gaining but it's not a problem now as it
was befoure. It's running much smoother.

Just some code how I'm doing this.

        private OhtelloImageBundle oImageBoundle = (OhtelloImageBundle)
GWT.create(OhtelloImageBundle.class);
        private String black = oImageBoundle.blackIcon().getHTML();
        private String white = oImageBoundle.whiteIcon().getHTML();
        private String green = oImageBoundle.greenIcon().getHTML();


  private void doGameUpdate() {
          if (ohtelloSvc == null) {
                  ohtelloSvc = GWT.create(OhtelloService.class);
          }
          AsyncCallback<GamePlan> callback = new AsyncCallback<GamePlan>() {
                        public void onFailure(Throwable caught) {
                            // do something with errors
                                GWT.log("onFailure: " + caught, null);
                        }

                        public void onSuccess(GamePlan result) {

                                for (int i = 0; i < gamePlan.getColumnCount(); 
i++) {
                                        for (int j = 0; j < 
gamePlan.getRowCount(); j++) {
                                                if 
(result.getGamePlan()[i][j].equals("B")) {
                                                        gamePlan.setHTML(i, j, 
black);
                                                } else if 
(result.getGamePlan()[i][j].equals("W")) {
                                                        gamePlan.setHTML(i, j, 
white);
                                                } else {
                                                        gamePlan.setHTML(i, j, 
green);
                                                }
                                        }
                                }
                        }
          };
          ohtelloSvc.doGameUpdate(callback);
  }


Thx for the help.


On 20 Mar, 01:42, Vitali Lovich <[email protected]> wrote:
> Also, make sure that the stall is actually because you're swapping memory &
> not because your trying to repaint a large board (look at your OS resource
> monitor).  You should see almost no CPU usage in user-space if it's memory
> swapping.
>
> If it's the CPU, you'll want to do the traditional trick of doing your work
> in multiple steps:
>
> private static final STEP_SIZE = 100;
>
> Timer repainter = new Timer() {
>     public GameResult result;
>     private GameResult current;
>     private int row = 0;
>     private int col = 0;
>     public void run() {
>            int steps = 0;
>            if (current != result) {
>                 row = col = 0;
>                 current = result;
>            }
>            ResultGamePlan rGamePlan = current.getGamePlan();
>            for (; steps < STEP_SIZE && row < gamePlan.getRowCount(); row++)
> {
>                 for (; steps < STEP_SIZE && col < gamePlan.getColumnCount();
> col++, steps++) {
>                       if (rGamePlan[col][row].equals("B"))
>                               //paint black
>                       else if (rGamePlan[col][row].equals("W"))
>                              // paint white
>                       else
>                              // paint green
>                 }
>     }
>             if (row == gamePlan.getRowCount() && col ==
> gamePlan.getColumnCount) {
>                   // finished painting
>                   cancel();
>                   current = null;
>             }
>
> };
>
> /// when you get an update from server
> repainter.result = serverResult;
> repainter.scheduleRepeating(10);
>
> That'll actually make things slower in terms of throughput, but the UI will
> remain responsive, so it'll seem faster.
>
> Another thing you can try is to use initialize like in my previous e-mail,
> except use HTML instead of Image.
>
> Then cache the HTML representation of the images in 3 global variables
> (getHTML of AbstractImagePrototype).  Then when you iterate, simple call
> setHTML - that should be even faster & should give you pretty good memory
> savings.
>
> On Thu, Mar 19, 2009 at 8:24 PM, Vitali Lovich <[email protected]> wrote:
> > Try doing an initialization first:
> >        for (int i = 0; i < gamePlan.getColumnCount(); i++)
> >                                        for (int j = 0; j <
> > gamePlan.getRowCount(); j++)
>
> >  gamePlan.setWidget(i,j, new Image());
>
> > Then in your actual paint do:
> > imagePrototype.applyTo(gamePlan.getWidget(i, j))
>
> > On Thu, Mar 19, 2009 at 6:30 PM, GhostNr1 <[email protected]> wrote:
>
> >> Hi!
>
> >> I'm trying to use ImageBundle to paint all my images. That's work very
> >> good except from one thing.
>
> >> Every 3 secound I poll the server to check if an ohtello plan have
> >> changed and then I try to paint it
>
> >>                                for (int i = 0; i <
> >> gamePlan.getColumnCount(); i++) {
> >>                                        for (int j = 0; j <
> >> gamePlan.getRowCount(); j++) {
> >>                                                if
> >> (result.getGamePlan()[i][j].equals("B")) {
>
> >>  gamePlan.setWidget(i,j, blackImgPrototype.createImage());
> >>                                                } else if
> >> (result.getGamePlan()[i][j].equals("W")) {
>
> >>  gamePlan.setWidget(i,j, whiteImgPrototype.createImage());
> >>                                                } else {
>
> >>  gamePlan.setWidget(i,j, greenImgPrototype.createImage());
> >>                                                }
> >>                                        }
> >>                                }
>
> >> I use that one, the problem is I use blackImgPrototype.createImage()
> >> so it create 64 new images every 3:rd secound and the memory stall.
> >> Any suggestion how I can fix this.
>
> >>                                Image black =
> >> blackImgPrototype.createImage();
> >>                                Image white =
> >> whiteImgPrototype.createImage();
> >>                                Image green =
> >> greenImgPrototype.createImage();
> >>                                for (int i = 0; i <
> >> gamePlan.getColumnCount(); i++) {
> >>                                        for (int j = 0; j <
> >> gamePlan.getRowCount(); j++) {
> >>                                                if
> >> (result.getGamePlan()[i][j].equals("B")) {
>
> >>  gamePlan.setWidget(i,j, black);
> >>                                                } else if
> >> (result.getGamePlan()[i][j].equals("W")) {
>
> >>  gamePlan.setWidget(i,j, white);
> >>                                                } else {
>
> >>  gamePlan.setWidget(i,j, green);
> >>                                                }
> >>                                        }
> >>                                }
>
> >> I have tryed that but then it only paint one black one white and one
> >> green image.
>
> >> Thx for help
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to