Sync-async (about flow control)
Post MTG Forge Related Programming Questions Here
	Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
			1 post
			 • Page 1 of 1
		
	
Sync-async (about flow control)
 by Max mtg » 25 Oct 2012, 00:11
by Max mtg » 25 Oct 2012, 00:11 
Imagine an Input class instance from our project
it's the following line:
This code and many other pieces have to be rewritten... I guess there should be a state related to each player on server side, so that it expects a limited set of actions from each player each time. While player has no priority they may only send messages to chat, while the for active one there should be a set of allowed actions - such as "play a spell or ability" , "special action" or "pass". After setting a certain state on player's controller server returns from the method to be instead of showMessage() and waits for remote player's response. When the answer arrives, server resumes the execution of actions related to that input or spellability resolution.
What I mean to say: every method will have to be cut into pieces in places where input is required. The second part should wait in a stack until the response arrives. EVERY interactive method has to changes.
Secondly, the events on actual server are invoked from UI. User presses a button => a few phases advance when AI responds. Imagine there is no GUI... then game server has to work in a separate thread and expect messages in a loop. That means that a layer of abstraction is needed between forge.control.input.InputPassPriority.selectButtonOK() and Singletons.getModel().getGame().getPhaseHandler().passPriority() - a GUI handler just cannot call that method directly, yet it might call something like Singletons.getPlayerInterface().passPriority(), which in turn will send a message over network or call that method on a local server.
Technically, I am not sure about a chat protocol as siutable transport already. Need some kind of RPC protocol that would allow to easily map commands to class methods, be easy to implement even on non-java client side and transfer minimum excessive data (don't like xml containers for that). It also should be able to notify a client. I am looking for a solution now... leaning toward jetty and its websockets implementation.
			- forge.card.cost.CostExile.exileFrom(SpellAbility, CostExile, String, CostPayment, int) | Open
- Code: Select all
- @Override
 public void showMessage() {
 if (nNeeded == 0) {
 this.done();
 }
 this.typeList = sa.getActivatingPlayer().getCardsIn(part.getFrom());
 this.typeList = CardLists.getValidCards(this.typeList, type.split(";"), sa.getActivatingPlayer(), sa.getSourceCard());
 for (int i = 0; i < nNeeded; i++) {
 if (this.typeList.size() == 0) {
 this.cancel();
 }
 final Card c = GuiChoose.oneOrNone("Exile from " + part.getFrom(), this.typeList);
 if (c != null) {
 this.typeList.remove(c);
 part.addToList(c);
 Singletons.getModel().getGame().getAction().exile(c);
 if (i == (nNeeded - 1)) {
 this.done();
 }
 } else {
 this.cancel();
 break;
 }
 }
 }
 
it's the following line:
- Code: Select all
- final Card c = GuiChoose.oneOrNone("Exile from " + part.getFrom(), this.typeList);
This code and many other pieces have to be rewritten... I guess there should be a state related to each player on server side, so that it expects a limited set of actions from each player each time. While player has no priority they may only send messages to chat, while the for active one there should be a set of allowed actions - such as "play a spell or ability" , "special action" or "pass". After setting a certain state on player's controller server returns from the method to be instead of showMessage() and waits for remote player's response. When the answer arrives, server resumes the execution of actions related to that input or spellability resolution.
What I mean to say: every method will have to be cut into pieces in places where input is required. The second part should wait in a stack until the response arrives. EVERY interactive method has to changes.
Secondly, the events on actual server are invoked from UI. User presses a button => a few phases advance when AI responds. Imagine there is no GUI... then game server has to work in a separate thread and expect messages in a loop. That means that a layer of abstraction is needed between forge.control.input.InputPassPriority.selectButtonOK() and Singletons.getModel().getGame().getPhaseHandler().passPriority() - a GUI handler just cannot call that method directly, yet it might call something like Singletons.getPlayerInterface().passPriority(), which in turn will send a message over network or call that method on a local server.
Technically, I am not sure about a chat protocol as siutable transport already. Need some kind of RPC protocol that would allow to easily map commands to class methods, be easy to implement even on non-java client side and transfer minimum excessive data (don't like xml containers for that). It also should be able to notify a client. I am looking for a solution now... leaning toward jetty and its websockets implementation.
Single class for single responsibility.
		- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
			1 post
			 • Page 1 of 1
		
	
Who is online
Users browsing this forum: No registered users and 13 guests
