Ejemplo n.º 1
0
void SectorPersistenceGenerator::SetExplored(Sector::System* sys, StarSystem::ExplorationState e, double time)
{
	Sint32 date;
	if (e != StarSystem::eUNEXPLORED) {
		int year, month, day;
		Time::DateTime dt = Time::DateTime(3200,1,1,0,0,0) + Time::TimeDelta(time, Time::Second);
		dt.GetDateParts(&year, &month, &day);
		date = day | month << 5 | year << 9;
	}
	m_exploredSystems.Set(SystemPath(sys->sx, sys->sy, sys->sz, sys->idx), (e == StarSystem::eUNEXPLORED) ? -1 : date);
}
Ejemplo n.º 2
0
static void push_date_time(lua_State *l, const Time::DateTime &dt) {
	int year, month, day, hour, minute, second;
	dt.GetDateParts(&year, &month, &day);
	dt.GetTimeParts(&hour, &minute, &second);

	lua_newtable(l);
	pi_lua_settable(l, "year", year);
	pi_lua_settable(l, "month", month);
	pi_lua_settable(l, "day", day);
	pi_lua_settable(l, "hour", hour);
	pi_lua_settable(l, "minute", minute);
	pi_lua_settable(l, "second", second);
	pi_lua_settable(l, "timestamp", dt.ToGameTime());
}
Ejemplo n.º 3
0
void SectorPersistenceGenerator::SetExplored(Sector::System* sys, StarSystem::ExplorationState e, double time)
{
	if (e == StarSystem::eUNEXPLORED) {
		m_exploredSystems.erase(sys->GetPath());
	} else if (e == StarSystem::eEXPLORED_AT_START) {
		m_exploredSystems[sys->GetPath()] = 0;
	} else {
		assert(e == StarSystem::eEXPLORED_BY_PLAYER);
		Time::DateTime dt = Time::DateTime(3200,1,1,0,0,0) + Time::TimeDelta(time, Time::Second);
		int year, month, day;
		dt.GetDateParts(&year, &month, &day);
		Sint32 date = day | month << 5 | year << 9;
		m_exploredSystems[sys->GetPath()] = date;
	}
}
Ejemplo n.º 4
0
void test_datetime() {
	const Time::DateTime EPOCH;

	std::cout << "Microsecond: " << std::setw(12) << Sint64(Time::Microsecond) << "\n";
	std::cout << "Millisecond: " << std::setw(12) << Sint64(Time::Millisecond) << "\n";
	std::cout << "     Second: " << std::setw(12) << Sint64(Time::Second) << "\n";
	std::cout << "     Minute: " << std::setw(12) << Sint64(Time::Minute) << "\n";
	std::cout << "       Hour: " << std::setw(12) << Sint64(Time::Hour) << "\n";
	std::cout << "        Day: " << std::setw(12) << Sint64(Time::Day) << "\n";
	std::cout << "       Week: " << std::setw(12) << Sint64(Time::Week) << "\n";

	std::cout << "epoch: " << EPOCH.ToStringISO8601() << "\n";

	for (int i = -10; i <= 10; ++i) {
		const Time::DateTime t = EPOCH + TimeDelta(i, Time::Hour);
		std::cout << "epoch + " << i << " hours = " << t.ToStringISO8601() << "\n";
	}

	for (int i = -10; i <= 10; ++i) {
		const Time::DateTime t = EPOCH + TimeDelta(i, Time::Day);
		std::cout << "epoch + " << i << " days = " << t.ToStringISO8601() << "\n";
	}

	for (int i = 0; CHECK_AROUND_TIMES[i][3] != -1; ++i) {
		const int *x = CHECK_AROUND_TIMES[i];
		check_datetime_round_trip(x[0],x[1],x[2], x[3],x[4],x[5], true);
	}

	Time::DateTime t = DateTime(1600,1,1, 0,0,0);
	std::cout << "Checking round trips for *many* timestamps...\n";
	std::cout << "  beginning at " << t.ToDateString() << "  " << t.ToTimeString() << "\n";
	std::cout << "  (checking round-trip every 6 hours)\n";
	for (int i = 0; i <= 4000000; ++i) {
		int year, month, day, hour, minute, second;
		t.GetDateParts(&year, &month, &day);
		t.GetTimeParts(&hour, &minute, &second);
		check_datetime_round_trip(year, month, day, hour, minute, second, false);

		t = t + TimeDelta(6, Time::Hour);
	}
	std::cout << "  ending at " << t.ToDateString() << "  " << t.ToTimeString() << "\n";
}