Пример #1
0
string ComboVertical::Emboiter()
{
	string texte_="";
	istringstream iss(a_.GetTexteBrut());
	for (string temp; getline(iss, temp);)
	{
		if (temp == string(temp.length(), '-'))
			texte_ += CoucheMillieu(Largeur_);
		else
			texte_ += temp + string(Largeur_ - temp.length(), ' ') + "\n";
	}

	texte_ += CoucheMillieu(Largeur_);

	iss = istringstream(b_.GetTexteBrut());
	for (string temp; getline(iss, temp);)
	{
		if (temp == string(temp.length(), '-'))
			texte_ += CoucheMillieu(Largeur_);
		else
			texte_ += temp + string(Largeur_ - temp.length(), ' ') + "\n";
	}

	return texte_;
}
Пример #2
0
int DataPreprocessor::addIndicators(string fileName)
{
	ifstream inputStream;
	inputStream.open(fileName);

	ofstream outputStream;
	outputStream.open(fileName + string("_preprocessed.csv"));

	if (inputStream.is_open() && outputStream.is_open())
	{
		int closePriceIndex = 4;
		int volumeIndex = 5;
		int storedPricesCount = 200;
		closePrices = list<double>();

		string token;
		string line;

		istringstream ss;

		int i;
		getline(inputStream, line);
		addHeaders(line, indicators, outputStream);

		while (getline(inputStream, line))
		{
			ss = istringstream(line);
			i = 0;
			outputStream << line;
			while (getline(ss, token, ','))
			{
				if (i == closePriceIndex)
				{
					if (closePrices.size() == storedPricesCount)
					{
						closePrices.pop_front();
					}
					closePrices.push_back(stod(token));
				}
				i++;
			}
			addIndicatorValues(outputStream);
		}
		return 0;
	}
	else
	{
		return -1;
	}
}
Пример #3
0
vector<string> DialogueTree::dialogueOptionChosen(int index)
{
	vector<string> ret = current->getMessagesForOption(index);
	//read through messages: switch to new dialogue if prompted

	int i = -1;

	for (int c = 0; c < ret.size(); c++)
	{
		istringstream ss = istringstream(ret[c]);
		string token;
		ss >> token;
		if (token == "GIVE")
		{
			string varName;
			ss >> varName;
			int val;
			ss >> token;
			val = atoi(token.c_str());
			Storyline::increaseVariable(varName, val);
		}
		else if (token == "GOTO")
Пример #4
0
bool ofxPFMImage::loadPFMImage(string fileName) {

	ifstream file;
	file.open(ofToDataPath(fileName, true), ios::binary | ios::in);

	char lineBuffer[2048];
	
	try {
		////
		//HEADER line 1
		file.getline(lineBuffer, 2048);
		bool colour;
		if (lineBuffer[0] == 'P' && lineBuffer[1] == 'F')
			colour = true;
		else if (lineBuffer[0] == 'P' && lineBuffer[1] == 'f')
			colour = false;
		else
			throw(0);
		//
		////
		
		////
		//HEADER line 2
		file.getline(lineBuffer, 2048);
		int width, height;
		istringstream line(lineBuffer);
		
		line >> width;
		line >> height;

		if (width <= 0 || height <= 0)
			throw(0);

		this->allocate(width, height, colour ? ofImageType::OF_IMAGE_COLOR : ofImageType::OF_IMAGE_GRAYSCALE);
		//
		/////

		////
		//HEADER line 3
		file.getline(lineBuffer, 2048);
		float scale;
		line = istringstream(lineBuffer);

		line >> scale;
		scale = abs(scale);

		/**HACK**/
		//for the time being we ignore endianness
		//
		////

		////
		//BODY
		float* pix = this->getPixels();
		float value;
				
		int expectedPixels = this->getWidth() * this->getHeight() * this->getPixelsRef().getNumChannels();
		
		for (int i=0; i<expectedPixels; i++) {
			file.read((char*)&value, sizeof(float));
			*pix++ = value * scale;
		}
		//
		////

		this->update();
		return true;

	} catch (...) {
		this->pixels.clear();
		return false;
	}
}
Пример #5
0
void World::loadLevel(const char* filename, Camera* camera)
{
    level.initializeLevel();
    enemies.clear();

    string line;
    ifstream file(filename);
    istringstream ssf;
    int done = 0;
    string layerfile[NUM_LAYERS];

    if (file.is_open())
    {
        getline(file, line);
        if (line.compare(0, 3, "\xEF\xBB\xBF") == 0)
            line.erase(0, 3);
        ssf = istringstream(line);

        ssf >> layerfile[0] >> layerfile[1] >> layerfile[2] >> layerfile[3];

        for (int i = 0; i < NUM_LAYERS; i++)
        {
            if (layerfile[i] != "null")
            {
                switch (i)
                {
                case 0: case 1:
                    level.layer[i].load(layerfile[i].c_str(), &game.atlases.bgs, camera);
                    break;
                case 2: case 3:
                    level.layer[i].load(layerfile[i].c_str(), &game.atlases.tiles, camera);
                    break;
                }
            }
            else
            {
                level.layer[i].initialize(0, 0, 0, 0, 0, 0, 0, NULL, 0);
            }
        }

        getline(file, line);
        ssf = istringstream(line);
        ssf >> level.ambientLighting >> level.musicID >> level.reverb;

        getline(file, line);
        ssf = istringstream(line);
        ssf >> level.playerSpawn.position.x
            >> level.playerSpawn.position.y
            >> level.playerSpawn.type
            >> level.playerSpawn.direction;

        //TODO portals/items

        EnemySpawn spawn;
        while (getline(file, line))
        {
            istringstream ss(line);
            ss >> spawn.type >> spawn.position.x >> spawn.position.y >> spawn.direction;
            if (spawn.type == -1)
                break;
            level.enemySpawns.push_back(spawn);
        }

        int t, w, h, mf;
        float x, y, tw, th;
        TileMap dobject;
        while (getline(file, line))
        {
            istringstream ss(line);
            ss >> mf >> t >> x >> y >> w >> h >> tw >> th;
            dobject.initialize(x, y, w, h, tw, th, 0.0f, &game.atlases.tiles, true, t, 1);
            switch (mf)
            {
            case 0:
                level.dynTileMaps.Add(dobject, [](unsigned int frame)
                {
                    float ftime = ((float)frame)*S_PER_GAME_UPDATE;
                    return Vector2((int)(2 * sgn(sinf((2 * PI / 2)*ftime))), (int)(-1 * sgn(sinf((2 * PI / 8)*ftime))));
                });
                break;
            case 1:
                level.dynTileMaps.Add(dobject, [](unsigned int frame)
                {
                    float ftime = ((float)frame)*S_PER_GAME_UPDATE;
                    return Vector2((int)2 * sgn(sinf((2 * PI / 40)*ftime)), (int)0.0f);
                });
                break;
            }
        }
        file.close();
    }
Пример #6
0
int main(int argc, char* argv[]) {
	vector<string> args; for (int i = 1; i < argc; ++i) args.push_back(argv[i]);

	// !! we should probably move this code somewhere that is not main, but otoh it's kinda nice to have it here
	// !! also where else would it go anyways?

	// ***** this is still preliminary, and will probably change significatly *****
	int argi = 0;

	// a little silly REPL loop so that it's easier to test urn
	// perhaps one day this will happen after it loads the scene so that you can modify that
	if(args[argi] == "/i") {
		argi++;
		urn::eval_context cx;
		cx.create_std_funcs();
		while (true) {
			string s;
			cout << "urn> ";
			getline(cin, s);
			auto ts = urn::token_stream(istringstream(s));
			auto v = urn::value(ts);
			if (v.type == urn::value::Val) {
				auto cmd = v.get_val();
				if (cmd == "!q") break;
				else if (cmd == "!x") return 42;
			}
			cout << cx.eval(v) << endl;
		}
	}

	auto init_start = chrono::high_resolution_clock::now();

	auto ts = urn::token_stream(ifstream(args[argi]));
	urn::value scene_tlv = urn::value(ts); //requires first cmdline argument to be path to scene file for now

	auto resolu_b = scene_tlv.named_block_val("resolution");
	auto resolution = resolu_b.is_null() ? uvec2(1280, 960) : uvec2(resolu_b[0].get<int64_t>(), resolu_b[1].get<int64_t>());
	shared_ptr<plu::texture2d> tx = make_shared<plu::texture2d>( resolution );

	auto cam_b = scene_tlv.named_block_val("camera");
	auto cam = plu::camera(bk2v3(cam_b.named_block_val("position")), bk2v3(cam_b.named_block_val("target")));

	auto smp_cnt = scene_tlv.named_block_val("antialiasing-samples").get<int64_t>();
	
	map<string, shared_ptr<plu::material>> mats;
	vector<shared_ptr<plu::surface>> surfs;


	urn::eval_context cx;
	cx.create_std_funcs();

	auto matvs = scene_tlv.named_block_val("materials").get<vector<urn::value>>();
	for (int i = 0; i < matvs.size(); ++i) {
		if (matvs[i].type != urn::value::Def) throw;
		auto d = matvs[i].get<pair<string, urn::value>>();
		mats[d.first] = make_material(cx, d.second);
	}


	auto objvs = cx.eval1(scene_tlv.named_block_val("objects")).get<vector<urn::value>>();
	for (int i = 0; i < objvs.size();) {
		auto ot = objvs[i].get_var();
		if (ot == "sphere") {
			auto m = objvs[i + 3];
			auto M = m.type == urn::value::Block ? make_material(cx, m) : m.type == urn::value::Id ? mats[m.get_id()] : nullptr;
			surfs.push_back(make_shared<plu::surfaces::sphere>(bk2v3(cx, objvs[i+1]), cx.eval(objvs[i+2]).get_num(), M));
			i += 4;
		}
		else if (ot == "box") {
			auto m = objvs[i + 3];
			auto M = m.type == urn::value::Block ? make_material(cx, m) : m.type == urn::value::Id ? mats[m.get_id()] : nullptr;
			surfs.push_back(make_shared<plu::surfaces::box>(bk2v3(cx, objvs[i + 1]), bk2v3(cx, objvs[i + 2]), M));
			i += 4;
		}
	}

	auto s = //new plu::group(surfs);
		new plu::surfaces::bvh_tree(surfs);
	plu::renderer r(s, cam, uvec2(64), smp_cnt);
	
	auto init_end = chrono::high_resolution_clock::now();

	auto render_start = chrono::high_resolution_clock::now();
	r.render(tx);
	auto render_end = chrono::high_resolution_clock::now();

	auto init_time = chrono::duration_cast<chrono::milliseconds>(init_end - init_start); // convert to milliseconds b/c humans are bad at big numbers
	auto render_time = chrono::duration_cast<chrono::milliseconds>(render_end - render_start);
	ostringstream watermark;
	watermark
		<< "scene: " << args[0] << endl
		<< "init took: " << init_time.count() << "ms" << endl
		<< "render took: " << render_time.count() << "ms" << endl;
#ifdef _DEBUG
	watermark << "DEBUG" << endl;
#else
	watermark << "RELEASE" << endl;
#endif
	cout << watermark.str();

	tx->draw_text(watermark.str(), uvec2(9, 10), vec3(0.2f)); // make a snazzy drop shadow
	tx->draw_text(watermark.str(), uvec2(8, 8), vec3(1.f, 0.6f, 0)); //draw some text
	
	// generate a somewhat unique filename so that we can see our progress
	ostringstream fns;
	fns << "image_" << chrono::system_clock::now().time_since_epoch().count() << ".bmp";
	tx->write_bmp(fns.str()); //write to image.bmp
	getchar();

	delete s;

	return 0;
}