Пример #1
0
EngineClient::EngineClient(	ds::App& app, const ds::cfg::Settings& settings,
							ds::EngineData& ed, const ds::RootList& roots)
		: inherited(app, settings, ed, roots)
		, mLoadImageService(*this, mIpFunctions)
		, mRenderTextService(mRenderTextThread)
		, mSender(mSendConnection)
		, mReceiver(mReceiveConnection)
		, mBlobReader(mReceiver.getData(), *this)
		, mSessionId(0)
		, mConnectionRenewed(false)
		, mServerFrame(-1)
		, mState(nullptr)
		, mIoInfo(*this)
{

	// NOTE:  Must be EXACTLY the same items as in EngineServer, in same order,
	// so that the BLOB ids match.
	HEADER_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveHeader(r.mDataBuffer);});
	COMMAND_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveCommand(r.mDataBuffer);});
	DELETE_SPRITE_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveDeleteSprite(r.mDataBuffer);});
	CLIENT_STATUS_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveClientStatus(r.mDataBuffer); });
	CLIENT_INPUT_BLOB = mBlobRegistry.add([this](BlobReader& r) {receiveClientInput(r.mDataBuffer); });
	mReceiver.setHeaderAndCommandIds(HEADER_BLOB, COMMAND_BLOB);
	
	try {
		if (settings.getBool("server:connect", 0, true)) {
			mSendConnection.initialize(true, settings.getText("server:ip"), ds::value_to_string(settings.getInt("server:listen_port")));
			mReceiveConnection.initialize(false, settings.getText("server:ip"), ds::value_to_string(settings.getInt("server:send_port")));
		}
	} catch(std::exception &e) {
		DS_LOG_ERROR_M("EngineClient::EngineClient() initializing UDP: " << e.what(), ds::ENGINE_LOG);
	}

	setState(mClientStartedState);
}
Пример #2
0
void Environment::loadSettings(const std::string& filename, ds::cfg::Settings& settings) {
	settings.readFrom(ds::Environment::getAppFolder(ds::Environment::SETTINGS(), filename), false);
	settings.readFrom(ds::Environment::getLocalSettingsPath(filename), true);
	if (!ds::EngineSettings::getConfigurationFolder().empty()) {
		const std::string		app = ds::Environment::expand("%APP%/settings/%CFG_FOLDER%/" + filename);
		const std::string		local = ds::Environment::expand("%LOCAL%/settings/%PP%/%CFG_FOLDER%/" + filename);
		settings.readFrom(app, true);
		settings.readFrom(local, true);
	}
}
Пример #3
0
static void interpret_text_settings(const ds::cfg::Settings &s, std::unordered_map<std::string, ds::cfg::Text>& out) {
	// Do the name first, because that determines whether an entry exists.
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && right == "name") {
			std::string		v = s.getText(key, 0, ds::EMPTY_SZ);
			if (!v.empty()) {
				if (out.empty()) {
					out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
				} else {
					auto	found = out.find(left);
					if (found != out.end()) {
						found->second.mFont = v;
					} else {
						out[left] = ds::cfg::Text(v, left, 10.0f, 1.0f, ci::ColorA(1.0f, 1.0f, 1.0f, 1.0f));
					}
				}
			}
		}
	});

	// Floats (size, leading)
	s.forEachFloatKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "size") found->second.mSize = s.getFloat(key, 0, found->second.mSize);
				else if (right == "leading") found->second.mLeading = s.getFloat(key, 0, found->second.mLeading);
			}
		}
	});

	// Color (color)
	s.forEachColorAKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "color") found->second.mColor = s.getColorA(key, 0, found->second.mColor);
			}
		}
	});

	// Text (alignment)
	s.forEachTextKey([&s, &out](const std::string& key) {
		std::string			left, right;
		if (split_key(key, left, right) && !out.empty()) {
			auto			found = out.find(left);
			if (found != out.end()) {
				if (right == "alignment") {
					found->second.mAlignment = ds::ui::Alignment::fromString(s.getText(key, 0, ""));
				}
			}
		}
	});

}
Пример #4
0
DrawTouchView::DrawTouchView(ds::ui::SpriteEngine& e, const ds::cfg::Settings &settings, ds::ui::TouchManager& tm)
	: ds::ui::Sprite(e)
	, mTouchTrailsUse(false)
	, mTouchTrailsLength(5)
	, mTouchTrailsIncrement(5.0f) {
	mTouchTrailsUse = settings.getBool("touch_overlay:trails:use", 0, mTouchTrailsUse);
	mTouchTrailsLength = settings.getInt("touch_overlay:trails:length", 0, mTouchTrailsLength);
	mTouchTrailsIncrement = settings.getFloat("touch_overlay:trails:increment", 0, mTouchTrailsIncrement);

	if(mTouchTrailsUse){
		setTransparent(false); 
		setColor(settings.getColor("touch_color", 0, ci::Color(1.0f, 1.0f, 1.0f)));
	}

	tm.setCapture(this);
}
Пример #5
0
void Environment::saveSettings(const std::string& filename, ds::cfg::Settings& settings) {
	if(!ds::EngineSettings::getConfigurationFolder().empty()) {
		const std::string		local = ds::Environment::expand("%LOCAL%/settings/%PP%/%CFG_FOLDER%/" + filename);
		settings.writeTo(local);
	}
}