It is currently 12 Sep 2025, 04:59
   
Text Size

thread-driven changes of input

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

thread-driven changes of input

Postby Max mtg » 02 Mar 2013, 21:34

as a method to eliminate that huge stacktraces, i have launched a separate thread to update input for all players.

Thread checks if input needs to be validated for current game state and does set input in a moment.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: thread-driven changes of input

Postby myk » 10 Mar 2013, 12:54

In light of the recent input- and performance-related troubles, it might be better if we rethink this decision. Could we instead use an event queue to reset the stack without resorting to threading?
myk
 
Posts: 439
Joined: 17 Jan 2013, 02:39
Location: California
Has thanked: 38 times
Been thanked: 57 times

Re: thread-driven changes of input

Postby Max mtg » 10 Mar 2013, 13:45

myk wrote:In light of the recent input- and performance-related troubles, it might be better if we rethink this decision. Could we instead use an event queue to reset the stack without resorting to threading?
What other problems except being unable to pay any 'unless' costs exist at the moment?
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: thread-driven changes of input

Postby myk » 10 Mar 2013, 14:10

there has been fairly severe performance degradation, as noted by Agetian in the bugs thread. I've noticed it as well. But more than that, by introducing threads, we're playing with fire. Threading is such a can of worms unless the architecture is specifically designed for it, and the forge architecture most certainly is not. If the purpose of the thread is to simplify the stacks, I think we can do that with a queue just as easily without the dangers of threading. In this case, we can use SwingUtililties.invokeLater() as the queue. Game state checking could happen in the passed Runnable.
myk
 
Posts: 439
Joined: 17 Jan 2013, 02:39
Location: California
Has thanked: 38 times
Been thanked: 57 times

Re: thread-driven changes of input

Postby Agetian » 10 Mar 2013, 14:13

It looks like both the significantly slower input ("lag") issue and the "occasional empty card selection window when running on Java 7" issue are related to this change (in r19990).

- Agetian
Last edited by Agetian on 10 Mar 2013, 14:24, edited 3 times in total.
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: thread-driven changes of input

Postby myk » 10 Mar 2013, 14:16

I'm assuming "ищер" means "both" : )
myk
 
Posts: 439
Joined: 17 Jan 2013, 02:39
Location: California
Has thanked: 38 times
Been thanked: 57 times

Re: thread-driven changes of input

Postby Agetian » 10 Mar 2013, 14:18

myk wrote:I'm assuming "ищер" means "both" : )
Yes, yes it does. :-) Fixed the mistype btw.

- Agetian
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: thread-driven changes of input

Postby Max mtg » 10 Mar 2013, 14:26

How nice, how many people speak Russian here? or have that keyboard layout at least...
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: thread-driven changes of input

Postby Agetian » 10 Mar 2013, 14:27

Max mtg wrote:How nice, how many people speak Russian here? or have that keyboard layout at least...
Hehe I speak Russian, it's my first language, actually. :-)

- Agetian
Agetian
Programmer
 
Posts: 3489
Joined: 14 Mar 2011, 05:58
Has thanked: 684 times
Been thanked: 572 times

Re: thread-driven changes of input

Postby Max mtg » 10 Mar 2013, 17:40

I have disabled the thread and made code synchronous again... per your joined request.


Myk still has not confessed, how he managed to guess the right keyboard layout conversion. ;)
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: thread-driven changes of input

Postby Max mtg » 20 Mar 2013, 08:41

Despite of a recent setback, I still want to change how the input works.

Some operations like paying mana or selecting target cards of players requires the routine (that was called to play a certain ability) to set input and return, passing some Command instance to the Input to execute them as soon as player reacts.

To my mind tracking all these continuations in commands and having different branches of code for AI and human (since AI reacts in no time and callers get the required data immediatelly) is making the project harder to mantain and develop.

I would like the routine (that needs some data from user) to wait at all cases, like it does wait when GuiChoose.one() window pops up. All the code ATM is executed from EDT (event dispatch thread) that cannot be just put on hold until we choose some targets from InputPayMana, because that is the same thread that reacts to user input.

So my idea is: as soon as we recieve a command from user, grab a thread (from a special pool, for instance) and have it execute all those spellabilities asynchronously. As that thread realizes it needs any data from human, it creates an object to synchronize on, assigns new Input state to UI and calls wait() method of that object. When the Input is finished, the caller thread awakes (from notify() method over the synchronization object) and continues its execution flow.

In this fashion a thread could wait for any source of data (yes, I hint at network) keeping the code cleaner and with less duplicates.
Attachments
forge-sync.gif
a possible interaction scheme
Last edited by Max mtg on 20 Mar 2013, 17:40, edited 1 time in total.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Re: thread-driven changes of input

Postby moomarc » 20 Mar 2013, 09:29

It sounds like a great idea and is probably something we'd have to do eventually anyway. But because the scope is so wide, I think it should be developed in a branch because as we saw last time, if something isn't quite right, Forge becomes very unstable. That way you can develop your idea until you're ready for more of us to test it, while the other devs can continue their own development without wondering whether an issue is due to the thread-driven changes or something in their own code.
-Marc
User avatar
moomarc
Pixel Commander
 
Posts: 2091
Joined: 04 Jun 2010, 15:22
Location: Johannesburg, South Africa
Has thanked: 371 times
Been thanked: 372 times

Re: thread-driven changes of input

Postby Sloth » 20 Mar 2013, 13:03

An input system that does not delay the inputs is something i've wanted for as long as i've been working on Forge. It would be really great if you can get this to work Max.

I'm willing to help as much as i can, when you need it (I imagine that most of the cost classes and some of the hardcoded cards need to be updated).
User avatar
Sloth
Programmer
 
Posts: 3498
Joined: 23 Jun 2009, 19:40
Has thanked: 125 times
Been thanked: 507 times

Re: thread-driven changes of input

Postby slapshot5 » 23 Mar 2013, 14:17

I'm willing to help with this also. Probably more from a testing and reporting bugs perspective. I synced up the new branch and did a couple quick run-throughs. Not sure if you're ready for crash reports or bugs at this point.

-slapshot5
slapshot5
Programmer
 
Posts: 1391
Joined: 03 Jan 2010, 17:47
Location: Mac OS X
Has thanked: 25 times
Been thanked: 68 times

Re: thread-driven changes of input

Postby Max mtg » 23 Mar 2013, 16:10

Thanks for the help you offer!
Testing is the most anticipated thing.

Right now I am heavily modifying the input system in a branch. Shall let you know when it's ready for tests.
Single class for single responsibility.
Max mtg
Programmer
 
Posts: 1997
Joined: 02 Jul 2011, 14:26
Has thanked: 173 times
Been thanked: 334 times

Next

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 36 guests

Main Menu

User Menu

Our Partners


Who is online

In total there are 36 users online :: 0 registered, 0 hidden and 36 guests (based on users active over the past 10 minutes)
Most users ever online was 7967 on 09 Sep 2025, 23:08

Users browsing this forum: No registered users and 36 guests

Login Form