mirror of https://github.com/OpenTTD/OpenTTD
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
workaround for it)release/0.4.5
parent
0346fec1ca
commit
a69e422cdd
|
@ -1208,10 +1208,12 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||||
GoodsEntry *ge;
|
GoodsEntry *ge;
|
||||||
int t;
|
int t;
|
||||||
uint count, cap;
|
uint count, cap;
|
||||||
|
byte old_player;
|
||||||
|
|
||||||
assert((v->next_order&0x1F) == OT_LOADING);
|
assert((v->next_order&0x1F) == OT_LOADING);
|
||||||
|
|
||||||
v->cur_speed = 0;
|
v->cur_speed = 0;
|
||||||
|
old_player = _current_player;
|
||||||
_current_player = v->owner;
|
_current_player = v->owner;
|
||||||
|
|
||||||
st = DEREF_STATION(last_visited = v->last_station_visited);
|
st = DEREF_STATION(last_visited = v->last_station_visited);
|
||||||
|
@ -1318,6 +1320,7 @@ next_vehicle:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_current_player = old_player;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
misc.c
19
misc.c
|
@ -15,15 +15,20 @@ static INLINE uint32 ROR(uint32 x, int n)
|
||||||
return (x >> n) + (x << ((sizeof(x)*8)-n));
|
return (x >> n) + (x << ((sizeof(x)*8)-n));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fuck bitch code, most probably one of the loops (tileloop, vehicleloop, etc.)
|
// For multiplayer, we introduced this new way of random-seeds
|
||||||
* doesn't set up/reset _current_player so the normal random below fails #$%@$#!
|
// It is player-based, so 2 clients can do 2 commands at the same time
|
||||||
* The old code below is prune to desyncs because randoms interfere.
|
// without the game desyncing.
|
||||||
* SO FIND THE OFFENDING LOOP AND FIX IT ONCE AND FOR ALL */
|
// It is not used for non-multiplayer games
|
||||||
#undef NORMAL_RANDOM // unuseable game, desyncs way too fast
|
#ifdef ENABLE_NETWORK
|
||||||
|
#define PLAYER_SEED_RANDOM
|
||||||
|
#else
|
||||||
|
#undef PLAYER_SEED_RANDOM
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32 Random()
|
uint32 Random()
|
||||||
{
|
{
|
||||||
#ifdef NORMAL_RANDOM
|
#ifdef PLAYER_SEED_RANDOM
|
||||||
if (_current_player>=MAX_PLAYERS) {
|
if (_current_player>=MAX_PLAYERS || !_networking) {
|
||||||
uint32 s = _random_seeds[0][0];
|
uint32 s = _random_seeds[0][0];
|
||||||
uint32 t = _random_seeds[0][1];
|
uint32 t = _random_seeds[0][1];
|
||||||
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7);
|
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7);
|
||||||
|
|
|
@ -365,6 +365,7 @@ void NetworkProcessCommands()
|
||||||
{
|
{
|
||||||
CommandQueue *nq;
|
CommandQueue *nq;
|
||||||
QueuedCommand *qp;
|
QueuedCommand *qp;
|
||||||
|
byte old_player;
|
||||||
|
|
||||||
// queue mode ?
|
// queue mode ?
|
||||||
if (_networking_queuing)
|
if (_networking_queuing)
|
||||||
|
@ -380,11 +381,13 @@ void NetworkProcessCommands()
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the command
|
// run the command
|
||||||
|
old_player = _current_player;
|
||||||
_current_player = qp->cp.player;
|
_current_player = qp->cp.player;
|
||||||
memcpy(_decode_parameters, qp->cp.dp, (qp->cp.packet_length - COMMAND_PACKET_BASE_SIZE));
|
memcpy(_decode_parameters, qp->cp.dp, (qp->cp.packet_length - COMMAND_PACKET_BASE_SIZE));
|
||||||
|
|
||||||
DoCommandP(qp->cp.tile, qp->cp.p1, qp->cp.p2, qp->callback, qp->cmd | CMD_DONT_NETWORK);
|
DoCommandP(qp->cp.tile, qp->cp.p1, qp->cp.p2, qp->callback, qp->cmd | CMD_DONT_NETWORK);
|
||||||
free(qp);
|
free(qp);
|
||||||
|
_current_player = old_player;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_networking_server) {
|
if (!_networking_server) {
|
||||||
|
@ -508,7 +511,7 @@ void NetworkSendEvent(uint16 type, uint16 data_len, void * data)
|
||||||
{
|
{
|
||||||
EventPacket * ep;
|
EventPacket * ep;
|
||||||
ClientState *cs;
|
ClientState *cs;
|
||||||
|
|
||||||
// encode the event ... add its data
|
// encode the event ... add its data
|
||||||
ep=malloc(data_len+sizeof(EventPacket)-1);
|
ep=malloc(data_len+sizeof(EventPacket)-1);
|
||||||
ep->event_type = type;
|
ep->event_type = type;
|
||||||
|
|
|
@ -694,6 +694,7 @@ bool GrowTown(Town *t)
|
||||||
const TileIndexDiff *ptr;
|
const TileIndexDiff *ptr;
|
||||||
int offs;
|
int offs;
|
||||||
TileInfo ti;
|
TileInfo ti;
|
||||||
|
byte old_player;
|
||||||
|
|
||||||
static const TileIndexDiff _town_coord_mod[] = {
|
static const TileIndexDiff _town_coord_mod[] = {
|
||||||
TILE_XY(-1,0),
|
TILE_XY(-1,0),
|
||||||
|
@ -712,6 +713,7 @@ bool GrowTown(Town *t)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Current player is a town
|
// Current player is a town
|
||||||
|
old_player = _current_player;
|
||||||
_current_player = OWNER_TOWN;
|
_current_player = OWNER_TOWN;
|
||||||
|
|
||||||
// Find a road that we can base the construction on.
|
// Find a road that we can base the construction on.
|
||||||
|
@ -719,7 +721,9 @@ bool GrowTown(Town *t)
|
||||||
ptr = _town_coord_mod;
|
ptr = _town_coord_mod;
|
||||||
do {
|
do {
|
||||||
if (GetRoadBitsByTile(tile) != 0) {
|
if (GetRoadBitsByTile(tile) != 0) {
|
||||||
return GrowTownAtRoad(t, tile);
|
int r = GrowTownAtRoad(t, tile);
|
||||||
|
_current_player = old_player;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
offs = *ptr++;
|
offs = *ptr++;
|
||||||
|
|
||||||
|
@ -737,6 +741,7 @@ bool GrowTown(Town *t)
|
||||||
if (ti.tileh == 0 && !(ti.type==MP_HOUSE && ti.map5==0)) {
|
if (ti.tileh == 0 && !(ti.type==MP_HOUSE && ti.map5==0)) {
|
||||||
if (DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) {
|
if (DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR) != CMD_ERROR) {
|
||||||
DoCommandByTile(tile, GenRandomRoadBits(), 0, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
|
DoCommandByTile(tile, GenRandomRoadBits(), 0, DC_EXEC | DC_AUTO, CMD_BUILD_ROAD);
|
||||||
|
_current_player = old_player;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -744,6 +749,7 @@ bool GrowTown(Town *t)
|
||||||
tile = TILE_ADD(tile, offs);
|
tile = TILE_ADD(tile, offs);
|
||||||
} while (offs != 0);
|
} while (offs != 0);
|
||||||
|
|
||||||
|
_current_player = old_player;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue