Nightinggale
Deity
- Joined
- Feb 2, 2009
- Messages
- 5,281
I just pushed a change, which is the first step in making CMC network safe.
Full log entry here: http://sourceforge.net/p/colonizati.../ci/13c8354d2bd434b87814187a3f8d0d3def1acd64/
When the human player clicks on a button, it creates a popup or python event. Those events leads to CvPlayer::setCurrentResearch(). This function then change something inside CvPlayer.
The problem is the trigger. It only happen when the user clicks something. If we have two computers in a network, only one of them have the click event.
The solution is actually pretty simple. Instead of calling CvPlayer::setCurrentResearch(), we should call gDLL->sendPlayerAction(ePlayer, PLAYER_ACTION_CHANGE_CIVIC, eNewResearch, 0, 0);
This will trigger CvPlayer::doAction(), which gains the arguments from sendPlayerAction(). This function then calls CvPlayer::setCurrentResearch().
The reason why this works in network games is that gDLL->sendPlayerAction() is triggered on one computer, then it is transmitted on the network and afterwards all computers execute CvPlayer::doAction() in sync.
The rule for then to use this is simple: if it is a user input, which changes something important (like everything in savegames), then it should be transmitted though the network.
CvDLLUtilityIFaceBase.h is full of network transmitting functions. The most likely to be used by our code will be
class|send|receive
city|sendDoTask()|CvCity::doTask()
player|sendPlayerAction()|CvPlayer::doAction()
unit|sendDoCommand()|CvUnit::doCommand()
I don't think we will gain network support anytime soon, but writing this will hopefully help preventing more code from being written, which will have to be rewritten later.
Maybe it will be easier to understand if the codechange is viewed in smartGIT's log rather than in a browser.
EDIT: reading the post after I posted made me realize it makes it look more complex than it really is
Coding network safe code isn't complex if you know how it works. Sadly Firaxis didn't document this feature, which is what I have to make up for.
Full log entry here: http://sourceforge.net/p/colonizati.../ci/13c8354d2bd434b87814187a3f8d0d3def1acd64/
When the human player clicks on a button, it creates a popup or python event. Those events leads to CvPlayer::setCurrentResearch(). This function then change something inside CvPlayer.
The problem is the trigger. It only happen when the user clicks something. If we have two computers in a network, only one of them have the click event.
The solution is actually pretty simple. Instead of calling CvPlayer::setCurrentResearch(), we should call gDLL->sendPlayerAction(ePlayer, PLAYER_ACTION_CHANGE_CIVIC, eNewResearch, 0, 0);
This will trigger CvPlayer::doAction(), which gains the arguments from sendPlayerAction(). This function then calls CvPlayer::setCurrentResearch().
The reason why this works in network games is that gDLL->sendPlayerAction() is triggered on one computer, then it is transmitted on the network and afterwards all computers execute CvPlayer::doAction() in sync.
The rule for then to use this is simple: if it is a user input, which changes something important (like everything in savegames), then it should be transmitted though the network.
CvDLLUtilityIFaceBase.h is full of network transmitting functions. The most likely to be used by our code will be
city|sendDoTask()|CvCity::doTask()
player|sendPlayerAction()|CvPlayer::doAction()
unit|sendDoCommand()|CvUnit::doCommand()
I don't think we will gain network support anytime soon, but writing this will hopefully help preventing more code from being written, which will have to be rewritten later.
Maybe it will be easier to understand if the codechange is viewed in smartGIT's log rather than in a browser.
EDIT: reading the post after I posted made me realize it makes it look more complex than it really is
Coding network safe code isn't complex if you know how it works. Sadly Firaxis didn't document this feature, which is what I have to make up for.