Slick Forums

Discuss the Slick 2D Library
It is currently Tue Jun 18, 2013 6:30 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Mar 18, 2009 3:07 pm 
Offline

Joined: Tue Mar 17, 2009 7:39 pm
Posts: 7
Here is a simple demo that causes slick "freeze" on my computer:

Code:
public class ThingleTestState extends BasicGameState {
   /** The UI page being displayed */
   private Page page;
   /** The image to display in the background */
   private Image image;
   
   int id = 1;
   
   ThingleController thingleController = null;
   
   public ThingleTestState() {
   }
   

   @Override
   public int getID() {
      // TODO Auto-generated method stub
      return id;
   }

   @Override
   public void init(GameContainer container, StateBasedGame game)
         throws SlickException {
      Thingle.init(new SlickThinletFactory(container));
      
      container.setShowFPS(false);
      //container.setVSync(true);
      //container.setTargetFrameRate(100);
      
      image = new Image("resources/logo.png");
      container.getGraphics().setBackground(Color.white);
      
      try {
         page = new Page("resources/login.xml", new LoginController("resources/login.xml"));
      } catch (ThingleException e) {
         e.printStackTrace();
      }
      
      Theme theme = new Theme();
      theme.setBackground(Thingle.createColor(0.6f,0.6f,1f,1f));
      theme.setBorder(Thingle.createColor(0,0,0.5f));
      theme.setFocus(Thingle.createColor(0,0,0));
      page.setTheme(theme);
      page.setDrawDesktop(false);
      page.enable();
      
      
      Widget loginName = page.getWidget("login_name");
      System.out.println(loginName);
      loginName.setText("Test");
      
   }

   @Override
   public void render(GameContainer container, StateBasedGame game, Graphics g)
         throws SlickException {
      image.draw(100,200);
      page.render();
      
      g.setColor(Color.black);
      g.drawString("FPS: "+container.getFPS(), 530, 2);
      
   }

   @Override
   public void update(GameContainer container, StateBasedGame game, int delta)
         throws SlickException {
      
      
   }
   
   
   @Override
   public void keyPressed(int key, char c) {
      if(c == 'w') {
         System.out.println("enabled");
         page.enable();
      } else if(c == 'e') {
         System.out.println("disabled");
         page.disable();
      }
      
   }

}


The bug occurs when page is disabled.

I am trying to use thingle for ingame menu that is shown when the player presses esc button. Simply adding and removing the diaglog doesn't work, because then input isn't let through to the game itself.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 6:45 am 
Offline

Joined: Tue Mar 17, 2009 7:39 pm
Posts: 7
There's simple solution to this problem: you need to add synchronized to some of to add/remove listeners in Slick's Input class. This still doesn't solve the problem of a listener getting added twice, but stops the program from crashing.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 10:17 pm 
Offline

Joined: Thu Nov 20, 2008 5:16 am
Posts: 76
Instead of enabling and disabling the page, have you considered hiding the component?

You can change the visibility to false and enabled to false.

Alternatively, you can remove the dialog component from the page- leaving an empty page (instead of disabling input handling to the page).

I think this might take care of your needs, but this does not solve all the problems you might have. For example, more complex layouts where your in game menu is supposed to be on top of other thingle components in the UI seem to complicate things. Having and rendering multiple pages does work, but focus issues, and problems around enabling and disabling the pages make that more difficult than it is worth, in my experience.

I am a bit surprised that you had a problem when adding and removing the dialog blocked input to the game itself. That has not been my experience, but I am not using slick gamestate stuff, I rolled my own.

(Right now I am still stuck on the multiple panel issue (because I no longer use more than one page at once). This issue is here: http://slick.javaunlimited.net/viewtopic.php?t=1565 )


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 11:55 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
synchronized shouldn't have any effect since both slick and thingle are single threaded (and arn't thread safe). Does your demo (or your game) spawn it's own threads?

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 23, 2009 6:16 am 
Offline

Joined: Tue Mar 17, 2009 7:39 pm
Posts: 7
AndyKorth wrote:
Instead of enabling and disabling the page, have you considered hiding the component?

You can change the visibility to false and enabled to false.

Alternatively, you can remove the dialog component from the page- leaving an empty page (instead of disabling input handling to the page).

I think this might take care of your needs, but this does not solve all the problems you might have. For example, more complex layouts where your in game menu is supposed to be on top of other thingle components in the UI seem to complicate things. Having and rendering multiple pages does work, but focus issues, and problems around enabling and disabling the pages make that more difficult than it is worth, in my experience.

I am a bit surprised that you had a problem when adding and removing the dialog blocked input to the game itself. That has not been my experience, but I am not using slick gamestate stuff, I rolled my own.

(Right now I am still stuck on the multiple panel issue (because I no longer use more than one page at once). This issue is here: http://slick.javaunlimited.net/viewtopic.php?t=1565 )


Hiding the components doesn't work either, since Thingle registers primary listener that blocks other input. Making function calls synchronized doesn't solve the solution either, which makes kevglass correct in his post.

However, what did to solve the problem was to create boolean variable enabled, and then change that variable in the listener and in render function enable/disable the page according to that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group