Slick Forums

Discuss the Slick 2D Library
It is currently Fri Aug 17, 2018 5:46 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Mar 09, 2012 8:49 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
We have a lot of topics about the question on "how to pass data between states". my suggestion: Simple object passing on the StateBasedGame and a receiver on the BasicGameState (overrideabe if needed).

in BasicGameState
Code:
protected void receivedData(int fromState, Object data) { }


in StateBasedGame
Code:
public void sendData(int state, Object data) {
     states.get(state).receivedData(currentState.getId(), data);
}


Somehting like that should work. I would not make abstract since you might not need it.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 2:40 am 
Nice! I'm in favour


Top
  
 
PostPosted: Sat Mar 10, 2012 4:53 am 
Offline
Oldbie
User avatar

Joined: Thu Jan 13, 2011 4:42 pm
Posts: 349
My gut reaction is to say that it's a bad idea, but then I realized... that would make my code much easier and cleaner.

_________________
"Artificial intelligence will never be a match for human stupidity" - "Jamos Kennedynos"


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 4:59 am 
I'd be willing to implement this right now, just a few more questions. Would it be more suitable to implement this in the enter method of states? I don't see the benefit in providing data to other states BEFORE we have entered them (If that is how it was working in your example)

EDIT: Just looked at how I would do this without breaking existing methods, kinda hard.


Top
  
 
PostPosted: Sat Mar 10, 2012 7:53 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
IMO this encourages bad coding practices. It's not very object-oriented (requires ugly instanceof and type casting), and a game designer could easily implement this on their own using generics, interfaces, or something else cleaner.

Maybe it's just me, but I feel like we should be removing clutter in Slick rather than adding more of it. This is just my two cents of course.


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 10:02 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
What davedes says.

Let's offer possible solutions in the Wiki and we're fine.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 10:33 am 
Offline
Regular

Joined: Sun Oct 30, 2011 4:47 pm
Posts: 184
Location: Mittweida, Saxony, Germany
I'm with davedes here.

I can't see the need for something like this. Passing informations between states should happen using the common element of all states. The StateBasedGame. You can implement your own version of the stated based game and use it to access your "common" data.

This method could be encouraged by implementing the GameState with a generic that has to overload StatedBasedGame and hand over this generic to the different functions.
We have generics now ;) Lets use them!

My 2 cents,
Nitram

_________________
http://illarion.org


Top
 Profile  
 
PostPosted: Sat Mar 10, 2012 2:56 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Well I don't need it too, I have my interfaces working for stuff like that. But I thought some people might needed.

btw. casting could be avoided by making the object generic kinda... never did that but it might work :D

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB® Forum Software © phpBB Group