Beispiel #1
0
/**
 * \class layout_builder::QueryHandler
 */
QueryHandler::QueryHandler(ds::ui::SpriteEngine& se, AllData &ad)
		: mEventClient(se.getNotifier(), [this](const ds::Event* e){if (e) onAppEvent(*e); })
		, mAllData(ad)
		, mStoryQuery(se, [](){return new StoryQuery(); })
{

	// Initialize data
	mStoryQuery.setReplyHandler([this](StoryQuery& q){this->onStoryQuery(q); });
}
Beispiel #2
0
/**
 * \class ds::DirectoryWatcher
 */
DirectoryWatcher::DirectoryWatcher(ds::ui::SpriteEngine& se)
		: ds::AutoUpdate(se)
		,  mStop(0)
		, mWaiter(mStop, se.getNotifier()) {
}
Beispiel #3
0
/**
 * \class ds::physics::World
 */
World::World(ds::ui::SpriteEngine& e, ds::ui::Sprite& spriddy)
		: ds::AutoUpdate(e)
		, mSprite(spriddy)
		, mTouch(*this)
		, mContactListener(*this)
		, mContactListenerRegistered(false)
		, mGround(nullptr)
		, mBounds(nullptr)
		, mCi2BoxScale(0.02f)
		, mFriction(0.5f)
		, mLinearDampening(0.0f)
		, mAngularDampening(0.0f)
		, mFixedRotation(true) 
		, mMouseMaxForce(10000.0f)
		, mMouseDampening(1.0f)
		, mMouseFrequencyHz(25.0f)
		, mTranslateToLocalSpace(false)
{
	mWorld = std::move(std::unique_ptr<b2World>(new b2World(b2Vec2(0.0f, 0.0f))));
	if (mWorld.get() == nullptr) throw std::runtime_error("ds::physics::World() can't create b2World");
	b2BodyDef		def;
	mGround = mWorld->CreateBody(&def);
	if (!mGround) throw std::runtime_error("ds::physics::World() can't create mGround");

	ds::Environment::loadSettings("physics.xml", mSettings);
	mTranslateToLocalSpace = mSettings.getBool("use_local_translation", 0, false);
	mFriction = mSettings.getFloat("friction", 0, mFriction);
	mLinearDampening = mSettings.getFloat("dampening:linear", 0, mLinearDampening);
	mAngularDampening = mSettings.getFloat("dampening:angular", 0, mAngularDampening);
	mFixedRotation = mSettings.getBool("rotation:fixed", 0, mFixedRotation);

	mMouseMaxForce = mSettings.getFloat("mouse:max_force", 0, mMouseMaxForce);
	mMouseDampening = mSettings.getFloat("mouse:dampening", 0, mMouseDampening);
	mMouseFrequencyHz = mSettings.getFloat("mouse:frequency_hz", 0, mMouseFrequencyHz);

	mVelocityIterations = mSettings.getInt("step:velocity_iterations", 0, 6);
	mPositionIterations = mSettings.getInt("step:position_iterations", 0, 2);
	mFixedStep = mSettings.getBool("step:fixed", 0, false);
	mFixedStepAmount = mSettings.getFloat("step:fixed_amount", 0, 1.0f/60.0f);

	// Slightly complicated, but flexible: Bounds can be either fixed or unit,
	// or a combination of both, which applies the fixed as an offset.
	if (mSettings.getRectSize("bounds:fixed") > 0 && mSettings.getRectSize("bounds:unit") > 0) {
		const ci::Rectf&		unit = mSettings.getRect("bounds:unit");
		const ci::Rectf&		fixed = mSettings.getRect("bounds:fixed");
		ci::Rectf				r(	(unit.x1 * e.getWorldWidth()) + fixed.x1, (unit.y1 * e.getWorldHeight()) + fixed.y1,
									(unit.x2 * e.getWorldWidth()) + fixed.x2, (unit.y2 * e.getWorldHeight()) + fixed.y2);
		setBounds(r, mSettings.getFloat("bounds:restitution", 0, 1.0f));
	} else if (mSettings.getRectSize("bounds:fixed") > 0) {
		setBounds(	mSettings.getRect("bounds:fixed"),
					mSettings.getFloat("bounds:restitution", 0, 1.0f));
	} else if (mSettings.getRectSize("bounds:unit") > 0) {
		const ci::Rectf&		r = mSettings.getRect("bounds:unit");
		setBounds(	ci::Rectf(r.x1 * e.getWorldWidth(), r.y1 * e.getWorldHeight(), r.x2 * e.getWorldWidth(), r.y2 * e.getWorldHeight()),
					mSettings.getFloat("bounds:restitution", 0, 1.0f));
	}

	if (mSettings.getBool("draw_debug", 0, false)) {
		mDebugDraw.reset(new DebugDraw(e, *(mWorld.get()), *this));
	}
}