syncronising changes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

syncronising changes

squid_daddy
I have a question regarding changes to game data.

example here we have.

Change change = ChangeFactory.addUnits(m_player, totalUnits);
changes.add(change);

is it equally valid to do?

Change change = new AddUnits(m_player.getUnits(), totalUnits);
changes.add(change);

i'm just curious if it is possible to avoid writing a new method in ChangeFactory or not.
Do i need to care how/why clients are notified about changes?

Edit: ok so realise AddUnits class is inside changefactory now. but i suppose the question still
stands, if i made my own Addunits or made a call with and annonymous class for some crazy reason.
Reply | Threaded
Open this post in threaded view
|

Re: syncronising changes

Sean Bridges
Administrator
They are the same, but for consistency it is better to add a method to ChangeFactory.

The more interesting bit is IDelegateBridge.addChange(..), this sends the change to other players, puts in the history, etc.
Reply | Threaded
Open this post in threaded view
|

Re: syncronising changes

squid_daddy
cool ta. so another related question

public void setMaxProduction(String value)
    {
    m_unitProduction += getInt(value); //realise this is not correct.
               m_maxProduction = getInt(value);
    }

for example would be bad, because inverting the change (which is how undo is done?)
would not return to the original state?

we also have
public int getMaxProduction(){}

does this require that I also need an Integer version of the setter or that the getter returns string?
public void setMaxProduction(Integer value)
or
public String getMaxProduction(){}

   
Reply | Threaded
Open this post in threaded view
|

Re: syncronising changes

Sean Bridges
Administrator
squid_daddy wrote
cool ta. so another related question

public void setMaxProduction(String value)
    {
    m_unitProduction += getInt(value); //realise this is not correct.
               m_maxProduction = getInt(value);
    }

for example would be bad, because inverting the change (which is how undo is done?)
would not return to the original state?

we also have
public int getMaxProduction(){}

does this require that I also need an Integer version of the setter or that the getter returns string?
public void setMaxProduction(Integer value)
or
public String getMaxProduction(){}

   
Are those methods on TerritoryAttachment?  You don't want the IDelegate to call those methods directly, make a Change subclass that stores the delta, and which can then be properly inverted.


Inverting changes is a lot of how undos are done, but there is often some other stuff to do as well.  Inverting changes is also how you can walk through the history.

For more background:

State in TripleA is divided into two parts, most state is in GameData components, GameMap, UnitList, PlayerList etc, all the way down to Unit and Territory.  All changes to these objects must be done from within a IDelegate, and the IDelegate must make the changes through an IDelegateBridge.addChange.  State stored in the GameData is kept in sycn on the clients, and as you walk through the history.  UI rendering needs to rely on state in GameData.


TripleA also stores state in the IDelegates.  Look at BattleDelegate.m_currentBattle.  The data stored in the IDelegates is not sent to the clients, and is saved/loaded when the game saves through the IDelegate.loadState(...)/saveState() methods.


State stored in Delegates is awkward for the UI to access while rendering the client, and can't be accessed at all while we are displaying the game in the history.  For example, we track where the pending battles are in MoveDelegate, but when we are drawing the map, we do a simpler check to see if units from more than one alliance are in the same country, and use that to draw the battle overlay.  
Reply | Threaded
Open this post in threaded view
|

Re: syncronising changes

squid_daddy
ah yeah i assumed i could use
ChangeFactory.attachmentPropertyChange(TerritoryAttachment.get(at), new Integer(i).toString(), "maxProduction");

to make the changes and it would take care of everything for me.
it seems like I can at first glance. though As i mentioned I think i need a getter with return type
that exactly matches a setter, not sure to be honest.
if this isn't cool I'll add my own.
thanks for clearing that whole thing up.