Ejemplo n.º 1
0
void CaelumEnvironment::Calendar_Updated()
{
	Eris::DateTime now = mCalendar.now();
	if (now.valid()) {
		if (mCaelumSystem) {
			mCaelumSystem->getUniversalClock()->setGregorianDateTime(now.year(), now.month(), now.dayOfMonth(), now.hours(), now.minutes(), now.seconds());
		}
	}
}
Ejemplo n.º 2
0
void CaelumEnvironment::setTime(int seconds)
{
	if (mCaelumSystem && mCaelumSystem->getUniversalClock()) {
		Eris::DateTime currentServerTime = mCalendar.now();
		if (currentServerTime.valid()) {
			mCaelumSystem->getUniversalClock()->setGregorianDateTime(currentServerTime.year(), currentServerTime.month(), currentServerTime.dayOfMonth(), 0, 0, seconds);
		} else {
			int year, month, day, hour, minute, _second;
			Ember::Time::getLocalTime(year, month, day, hour, minute, _second);
			mCaelumSystem->getUniversalClock()->setGregorianDateTime(year, month, day, 0, 0, seconds);
		}
	}
}
Ejemplo n.º 3
0
bool TimeImpl::getServerTime(int& year, int& month, int& day, int& hour, int& minute, int& second)
{
	//try to get the server time, and if not possible fall back to the local time
	if (mCalendar.get()) {
		Eris::DateTime dt = mCalendar->now();
		if (dt.valid()) {
			year = dt.year();
			month = dt.month();
			day = dt.dayOfMonth();
			hour = dt.hours();
			minute = dt.minutes();
			second = dt.seconds();
			return true;
		}
	}
	::Ember::Time::getLocalTime(year, month, day, hour, minute, second);
	return false;
}
Ejemplo n.º 4
0
int main()
{
    Eris::Logged.connect(sigc::ptr_fun(writeLog));
    Eris::setLogLevel(Eris::LOG_DEBUG);

    /////////////////////////// DateTime ///////////////////////////

    // Test constructor and destructor
    {
        Eris::DateTime dt;
    }

    // Test valid()
    {
        Eris::DateTime dt;

        assert(!dt.valid());
    }

    // Test year()
    {
        Eris::DateTime dt;

        dt.year();
    }

    // Test month()
    {
        Eris::DateTime dt;

        dt.month();
    }

    // Test dayOfMonth()
    {
        Eris::DateTime dt;

        dt.dayOfMonth();
    }

    // Test seconds()
    {
        Eris::DateTime dt;

        dt.seconds();
    }

    // Test minutes()
    {
        Eris::DateTime dt;

        dt.minutes();
    }

    // Test hours()
    {
        Eris::DateTime dt;

        dt.hours();
    }

    // Test year()
    {
        Eris::DateTime dt;

        dt.year();
    }

    /////////////////////////// Calendar ///////////////////////////

    // Test constructor
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);
        Eris::Calendar ec(ea);
    }

    // FIXME Can't set the toplevel on the view, which is required to
    // test all paths through the constructor.

    // Test topLevelEntityChanged()
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_topLevelEntityChanged();
    }

    /// Test overflow of 32bit seconds

    // Test calendar process time at the origin of time
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = 0;

        Eris::DateTime dt = ec.now();

        assert(dt.year() == 0);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);
    }

    // Test calendar process time at the origin of time plus some time
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = 1LL * MPY * DPM * HPD * MPH * SPM;

        Eris::DateTime dt = ec.now();

        assert(dt.year() == 1);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);

        stub_worldtime = 1000LL * MPY * DPM * HPD * MPH * SPM;

        dt = ec.now();

        assert(dt.year() == 1000);
        assert(dt.month() == 0);
        assert(dt.dayOfMonth() == 0);
        assert(dt.hours() == 0);
        assert(dt.minutes() == 0);
        assert(dt.seconds() == 0);
    }

    // Test calendar process time at the limit of an unsigned 32bit int seconds
    {
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);

        ec.test_setSaneDefault();

        stub_worldtime = std::numeric_limits<unsigned int>::max() + 10LL;

        Eris::DateTime dt = ec.now();

        // std::cout << dt.year() << ":" << dt.month() << ":" << dt.dayOfMonth() << ":" << dt.hours() << ":" << dt.minutes() << ":" << dt.seconds() << std::endl;

        assert(dt.year() > 0);
    }

    // Test event emitted
    {
        SignalFlagger flagger;
        std::string fake_char_id("1");
		std::string fake_mind_id("12");
        Eris::Avatar * ea = new TestAvatar(nullptr, fake_mind_id, fake_char_id);

        TestCalendar ec(ea);
        ec.Updated.connect(sigc::mem_fun(flagger,
                &SignalFlagger::set));

        ec.test_setSaneDefault();

        assert(flagger.flagged());
    }


    return 0;
}
Ejemplo n.º 5
0
void CaelumEnvironment::setupCaelum(::Ogre::SceneManager *sceneMgr, ::Ogre::RenderWindow* window, ::Ogre::Camera&)
{

	Ogre::Root* root = Ogre::Root::getSingletonPtr();

	mCaelumSystem = new Caelum::CaelumSystem(root, sceneMgr, Caelum::CaelumSystem::CAELUM_COMPONENTS_NONE);

	try {
		mCaelumSystem->setSkyDome(new Caelum::SkyDome(mSceneMgr, mCaelumSystem->getCaelumCameraNode()));
	} catch (const Caelum::UnsupportedException& ex) {
		S_LOG_WARNING("Error when creating Caelum sky dome." << ex);
	}
	try {
		mCaelumSystem->setSun(new Caelum::SphereSun(mSceneMgr, mCaelumSystem->getCaelumCameraNode()));
		mSun = new CaelumSun(*this, mCaelumSystem->getSun());
	} catch (const Caelum::UnsupportedException& ex) {
		//TODO: use a simple sun object
		S_LOG_WARNING("Error when creating Caelum sun." << ex);
	}
	try {
		mCaelumSystem->setMoon(new Caelum::Moon(mSceneMgr, mCaelumSystem->getCaelumCameraNode()));
	} catch (const Caelum::UnsupportedException& ex) {
		S_LOG_WARNING("Error when creating Caelum moon." << ex);
	}
	try {
		mCaelumSystem->setCloudSystem(new Caelum::CloudSystem(mSceneMgr, mCaelumSystem->getCaelumGroundNode()));
	} catch (const Caelum::UnsupportedException& ex) {
		S_LOG_WARNING("Error when creating Caelum clouds." << ex);
	}
	try {
		mCaelumSystem->setPointStarfield(new Caelum::PointStarfield(mSceneMgr, mCaelumSystem->getCaelumCameraNode()));
	} catch (const Caelum::UnsupportedException& ex) {
		S_LOG_WARNING("Error when creating Caelum point star field." << ex);
		try {
			mCaelumSystem->setImageStarfield(new Caelum::ImageStarfield(mSceneMgr, mCaelumSystem->getCaelumCameraNode()));
		} catch (const Caelum::UnsupportedException& ex) {
			S_LOG_WARNING("Error when creating Caelum image star field." << ex);
		}
	}

	mCaelumSystem->setManageSceneFog(true);
	mCaelumSystem->setManageAmbientLight(true);
	mCaelumSystem->setGlobalFogDensityMultiplier(0.005);
	mCaelumSystem->setMinimumAmbientLight(Ogre::ColourValue(0.2, 0.2, 0.2, 1.0));

	mCaelumSystem->setEnsureSingleShadowSource(true); //we want to use only one shadow caster source, for now at least
	mCaelumSystem->setEnsureSingleLightSource(true); //We want to only use the brightest light source only, even if another is closer. This is to make sure the main light is taken from the sun instead of the moon (which will result in a dark landscape).

	mSky = new CaelumSky(*this);

	// Register all to the render window
	mCaelumSystem->attachViewport(window->getViewport(0));
	window->addListener(mCaelumSystem);

	// Set time acceleration to fit with real world time
	mCaelumSystem->getUniversalClock()->setTimeScale(1);

	Eris::DateTime currentServerTime = mCalendar.now();
	if (currentServerTime.valid()) {
		mCaelumSystem->getUniversalClock()->setGregorianDateTime(currentServerTime.year(), currentServerTime.month(), currentServerTime.dayOfMonth(), currentServerTime.hours(), currentServerTime.minutes(), currentServerTime.seconds());
	} else {
		S_LOG_WARNING("Could not get server time, using local time for environment.");
		int year, month, day, hour, minute, second;
		Ember::Time::getLocalTime(year, month, day, hour, minute, second);
		mCaelumSystem->getUniversalClock()->setGregorianDateTime(year, month, day, hour, minute, second);
	}

	//little hack here. We of course want to use the server time, but currently when you log in when it's dark, you won't see much, so in order to show the world in it's full glory we'll try to set the time to day time
	/*
	 if (hour < 6) {
	 hour = 6;
	 } else if (hour > 16) {
	 hour = 15;
	 }
	 */

	//advance it one second to force it to do initial updating, since other subsystems such as the terrain rendering depends on the sun postions etc.
	mCaelumSystem->updateSubcomponents(1);

	//This will make caelum update itself automatically each frame
	Ogre::Root::getSingleton().addFrameListener(mCaelumSystem);
}