tick.patch

ulukyn, 01/20/2012 01:15 pm

Download (1.3 kB)

/home/ulukyn/code/ryzom/common/src/game_share/persistent_data_template.h
176 176
inline uint32 saveGameCycleToSecond(NLMISC::TGameCycle tick)
177 177
{
178 178
	// Evaluate the UTC of this event (with the current date of save). Suppose that 1 second==10 tick
179
	return  sint32(NLMISC::CTime::getSecondsSince1970()) + (sint32(tick) - sint32(CTickEventHandler::getGameCycle()))/10;
179
	if (tick < CTickEventHandler::getGameCycle())
180
		return NLMISC::CTime::getSecondsSince1970();
181
	else
182
		return  NLMISC::CTime::getSecondsSince1970() + (tick - CTickEventHandler::getGameCycle())/10;
180 183
	// NB: result should be positive since no event should have been launched before 1970!
181 184
}
182 185

183 186
inline NLMISC::TGameCycle loadSecondToGameCycle(uint32 second)
184 187
{
188
	if (second < NLMISC::CTime::getSecondsSince1970())
189
		return 0;
190
	
185 191
	// Convert UTC of the event to game cycle. Suppose that 1 second==10 tick
186
	sint32	newTick= CTickEventHandler::getGameCycle() + (sint32(second) - sint32(NLMISC::CTime::getSecondsSince1970()))*10;
187
	// If game cycle is loaded on a server where current game cycle is too young, we can have here negative values => avoid them
188
	return std::max(newTick, sint32(0));
192
	return CTickEventHandler::getGameCycle() + (second - NLMISC::CTime::getSecondsSince1970())*10;
189 193
}
190 194
#endif
191 195