예제 #1
0
void TextureSource::buildMainAtlas(class IGameDef *gamedef) 
{
	assert(gamedef->tsrc() == this);
	INodeDefManager *ndef = gamedef->ndef();

	infostream<<"TextureSource::buildMainAtlas()"<<std::endl;

	//return; // Disable (for testing)
	
	video::IVideoDriver* driver = m_device->getVideoDriver();
	assert(driver);

	JMutexAutoLock lock(m_atlaspointer_cache_mutex);

	// Create an image of the right size
	core::dimension2d<u32> atlas_dim(1024,1024);
	video::IImage *atlas_img =
			driver->createImage(video::ECF_A8R8G8B8, atlas_dim);
	//assert(atlas_img);
	if(atlas_img == NULL)
	{
		errorstream<<"TextureSource::buildMainAtlas(): Failed to create atlas "
				"image; not building texture atlas."<<std::endl;
		return;
	}

	/*
		Grab list of stuff to include in the texture atlas from the
		main content features
	*/

	core::map<std::string, bool> sourcelist;

	for(u16 j=0; j<MAX_CONTENT+1; j++)
	{
		if(j == CONTENT_IGNORE || j == CONTENT_AIR)
			continue;
		const ContentFeatures &f = ndef->get(j);
		for(u32 i=0; i<6; i++)
		{
			std::string name = f.tname_tiles[i];
			sourcelist[name] = true;
		}
	}
	
	infostream<<"Creating texture atlas out of textures: ";
	for(core::map<std::string, bool>::Iterator
			i = sourcelist.getIterator();
			i.atEnd() == false; i++)
	{
		std::string name = i.getNode()->getKey();
		infostream<<"\""<<name<<"\" ";
	}
	infostream<<std::endl;

	// Padding to disallow texture bleeding
	s32 padding = 16;

	s32 column_width = 256;
	s32 column_padding = 16;

	/*
		First pass: generate almost everything
	*/
	core::position2d<s32> pos_in_atlas(0,0);
	
	pos_in_atlas.Y = padding;

	for(core::map<std::string, bool>::Iterator
			i = sourcelist.getIterator();
			i.atEnd() == false; i++)
	{
		std::string name = i.getNode()->getKey();

		// Generate image by name
		video::IImage *img2 = generate_image_from_scratch(name, m_device,
				&m_sourcecache);
		if(img2 == NULL)
		{
			errorstream<<"TextureSource::buildMainAtlas(): "
					<<"Couldn't generate image \""<<name<<"\""<<std::endl;
			continue;
		}

		core::dimension2d<u32> dim = img2->getDimension();

		// Don't add to atlas if image is large
		core::dimension2d<u32> max_size_in_atlas(32,32);
		if(dim.Width > max_size_in_atlas.Width
		|| dim.Height > max_size_in_atlas.Height)
		{
			infostream<<"TextureSource::buildMainAtlas(): Not adding "
					<<"\""<<name<<"\" because image is large"<<std::endl;
			continue;
		}

		// Wrap columns and stop making atlas if atlas is full
		if(pos_in_atlas.Y + dim.Height > atlas_dim.Height)
		{
			if(pos_in_atlas.X > (s32)atlas_dim.Width - 256 - padding){
				errorstream<<"TextureSource::buildMainAtlas(): "
						<<"Atlas is full, not adding more textures."
						<<std::endl;
				break;
			}
			pos_in_atlas.Y = padding;
			pos_in_atlas.X += column_width + column_padding;
		}
		
		/*infostream<<"TextureSource::buildMainAtlas(): Adding \""<<name
				<<"\" to texture atlas"<<std::endl;*/

		// Tile it a few times in the X direction
		u16 xwise_tiling = column_width / dim.Width;
		if(xwise_tiling > 16) // Limit to 16 (more gives no benefit)
			xwise_tiling = 16;
		for(u32 j=0; j<xwise_tiling; j++)
		{
			// Copy the copy to the atlas
			/*img2->copyToWithAlpha(atlas_img,
					pos_in_atlas + v2s32(j*dim.Width,0),
					core::rect<s32>(v2s32(0,0), dim),
					video::SColor(255,255,255,255),
					NULL);*/
			img2->copyTo(atlas_img,
					pos_in_atlas + v2s32(j*dim.Width,0),
					core::rect<s32>(v2s32(0,0), dim),
					NULL);
		}

		// Copy the borders a few times to disallow texture bleeding
		for(u32 side=0; side<2; side++) // top and bottom
		for(s32 y0=0; y0<padding; y0++)
		for(s32 x0=0; x0<(s32)xwise_tiling*(s32)dim.Width; x0++)
		{
			s32 dst_y;
			s32 src_y;
			if(side==0)
			{
				dst_y = y0 + pos_in_atlas.Y + dim.Height;
				src_y = pos_in_atlas.Y + dim.Height - 1;
			}
			else
			{
				dst_y = -y0 + pos_in_atlas.Y-1;
				src_y = pos_in_atlas.Y;
			}
			s32 x = x0 + pos_in_atlas.X;
			video::SColor c = atlas_img->getPixel(x, src_y);
			atlas_img->setPixel(x,dst_y,c);
		}

		img2->drop();

		/*
			Add texture to caches
		*/
		
		bool reuse_old_id = false;
		u32 id = m_atlaspointer_cache.size();
		// Check old id without fetching a texture
		core::map<std::string, u32>::Node *n;
		n = m_name_to_id.find(name);
		// If it exists, we will replace the old definition
		if(n){
			id = n->getValue();
			reuse_old_id = true;
			/*infostream<<"TextureSource::buildMainAtlas(): "
					<<"Replacing old AtlasPointer"<<std::endl;*/
		}

		// Create AtlasPointer
		AtlasPointer ap(id);
		ap.atlas = NULL; // Set on the second pass
		ap.pos = v2f((float)pos_in_atlas.X/(float)atlas_dim.Width,
				(float)pos_in_atlas.Y/(float)atlas_dim.Height);
		ap.size = v2f((float)dim.Width/(float)atlas_dim.Width,
				(float)dim.Width/(float)atlas_dim.Height);
		ap.tiled = xwise_tiling;

		// Create SourceAtlasPointer and add to containers
		SourceAtlasPointer nap(name, ap, atlas_img, pos_in_atlas, dim);
		if(reuse_old_id)
			m_atlaspointer_cache[id] = nap;
		else
			m_atlaspointer_cache.push_back(nap);
		m_name_to_id[name] = id;
			
		// Increment position
		pos_in_atlas.Y += dim.Height + padding * 2;
	}

	/*
		Make texture
	*/
	video::ITexture *t = driver->addTexture("__main_atlas__", atlas_img);
	assert(t);

	/*
		Second pass: set texture pointer in generated AtlasPointers
	*/
	for(core::map<std::string, bool>::Iterator
			i = sourcelist.getIterator();
			i.atEnd() == false; i++)
	{
		std::string name = i.getNode()->getKey();
		if(m_name_to_id.find(name) == NULL)
			continue;
		u32 id = m_name_to_id[name];
		//infostream<<"id of name "<<name<<" is "<<id<<std::endl;
		m_atlaspointer_cache[id].a.atlas = t;
	}

	/*
		Write image to file so that it can be inspected
	*/
	/*std::string atlaspath = porting::path_user
			+ DIR_DELIM + "generated_texture_atlas.png";
	infostream<<"Removing and writing texture atlas for inspection to "
			<<atlaspath<<std::endl;
	fs::RecursiveDelete(atlaspath);
	driver->writeImageToFile(atlas_img, atlaspath.c_str());*/
}
예제 #2
0
static inline Vec2 v2fnormalize(const Vec2 &p)
{
    Vec2 r(p.x, p.y);
    r.normalize();
    return v2f(r.x, r.y);
}
예제 #3
0
void ParticleManager::handleParticleEvent(ClientEvent *event, IGameDef *gamedef,
        scene::ISceneManager* smgr, LocalPlayer *player)
{
    if (event->type == CE_DELETE_PARTICLESPAWNER) {
        JMutexAutoLock lock(m_spawner_list_lock);
        if (m_particle_spawners.find(event->delete_particlespawner.id) !=
                m_particle_spawners.end())
        {
            delete m_particle_spawners.find(event->delete_particlespawner.id)->second;
            m_particle_spawners.erase(event->delete_particlespawner.id);
        }
        // no allocated memory in delete event
        return;
    }

    if (event->type == CE_ADD_PARTICLESPAWNER) {

        {
            JMutexAutoLock lock(m_spawner_list_lock);
            if (m_particle_spawners.find(event->add_particlespawner.id) !=
                    m_particle_spawners.end())
            {
                delete m_particle_spawners.find(event->add_particlespawner.id)->second;
                m_particle_spawners.erase(event->add_particlespawner.id);
            }
        }
        video::ITexture *texture =
            gamedef->tsrc()->getTexture(*(event->add_particlespawner.texture));

        ParticleSpawner* toadd = new ParticleSpawner(gamedef, smgr, player,
                event->add_particlespawner.amount,
                event->add_particlespawner.spawntime,
                *event->add_particlespawner.minpos,
                *event->add_particlespawner.maxpos,
                *event->add_particlespawner.minvel,
                *event->add_particlespawner.maxvel,
                *event->add_particlespawner.minacc,
                *event->add_particlespawner.maxacc,
                event->add_particlespawner.minexptime,
                event->add_particlespawner.maxexptime,
                event->add_particlespawner.minsize,
                event->add_particlespawner.maxsize,
                event->add_particlespawner.collisiondetection,
                event->add_particlespawner.vertical,
                texture,
                event->add_particlespawner.id,
                this);

        /* delete allocated content of event */
        delete event->add_particlespawner.minpos;
        delete event->add_particlespawner.maxpos;
        delete event->add_particlespawner.minvel;
        delete event->add_particlespawner.maxvel;
        delete event->add_particlespawner.minacc;
        delete event->add_particlespawner.texture;
        delete event->add_particlespawner.maxacc;

        {
            JMutexAutoLock lock(m_spawner_list_lock);
            m_particle_spawners.insert(
                std::pair<u32, ParticleSpawner*>(
                    event->add_particlespawner.id,
                    toadd));
        }

        return;
    }

    if (event->type == CE_SPAWN_PARTICLE) {
        video::ITexture *texture =
            gamedef->tsrc()->getTexture(*(event->spawn_particle.texture));

        Particle* toadd = new Particle(gamedef, smgr, player, m_env,
                                       *event->spawn_particle.pos,
                                       *event->spawn_particle.vel,
                                       *event->spawn_particle.acc,
                                       event->spawn_particle.expirationtime,
                                       event->spawn_particle.size,
                                       event->spawn_particle.collisiondetection,
                                       event->spawn_particle.vertical,
                                       texture,
                                       v2f(0.0, 0.0),
                                       v2f(1.0, 1.0));

        addParticle(toadd);

        delete event->spawn_particle.pos;
        delete event->spawn_particle.vel;
        delete event->spawn_particle.acc;

        return;
    }
}
예제 #4
0
static inline Vec2 v2fmult(const Vec2 &v, float s)
{
    return v2f(v.x * s, v.y * s);
}
예제 #5
0
static inline Vec2 v2fneg(const Vec2 &p0)
{
    return v2f(-p0.x, - p0.y);
}
예제 #6
0
static inline ccVertex2F v2fforangle(float _a_)
{
	return v2f(cosf(_a_), sinf(_a_));
}
예제 #7
0
static inline Vec2 v2fadd(const Vec2 &v0, const Vec2 &v1)
{
    return v2f(v0.x+v1.x, v0.y+v1.y);
}
static inline Vec2 v2fnormalize(const Vec2 &p)
{
	Vec2 r = Vec2(p.x, p.y).getNormalized();
	return v2f(r.x, r.y);
}
예제 #9
0
    static bool makeManifold(TheaArray<FaceT> & faces, long num_vertices, TheaArray<long> & vertex_map)
    {
      if (num_vertices <= 0 || faces.size() <= 0)
        return false;

      array_size_t nf = (array_size_t)faces.size();
      array_size_t nv = (array_size_t)num_vertices;

      // Initialize every vertex to map to itself
      vertex_map.resize(nv);
      for (array_size_t i = 0; i < nv; ++i)
        vertex_map[i] = (long)i;

      // Associate each vertex with its incident faces
      TheaArray< TheaArray<array_size_t> > v2f(nv);
      for (array_size_t i = 0; i < nf; ++i)
        for (typename FaceT::const_iterator vi = faces[i].begin(); vi != faces[i].end(); ++vi)
        {
          debugAssertM(*vi >= 0 && (long)*vi < num_vertices,
                      format("Manifold: Vertex index %ld out of range [0, %ld)", (long)*vi, num_vertices));
          v2f[(array_size_t)*vi].push_back(i);
        }

      // Queue the set of vertices
      TheaStack<array_size_t> vertex_stack;
      for (long i = (long)nv - 1; i >= 0; --i)
        vertex_stack.push((array_size_t)i);

      // Split the faces at each vertex into manifold groups
      while (!vertex_stack.empty())
      {
        array_size_t i = vertex_stack.top();
        vertex_stack.pop();

        // Set of edges (represented by their further vertices) incident at this vertex that have already been observed to be
        // shared by two faces
        TheaSet<array_size_t> shared_edges;

        // Group the faces into maximal edge-connected components
        typedef UnionFind<array_size_t> UnionFind;
        UnionFind uf(v2f[i].begin(), v2f[i].end());

        for (array_size_t j = 0; j < v2f[i].size(); ++j)
          for (array_size_t k = j + 1; k < v2f[i].size(); ++k)
            if (shareEdgeAtVertex(faces[v2f[i][j]], faces[v2f[i][k]], i, shared_edges))
              uf.merge((long)j, (long)k);

        // Retain only the faces edge-connected to the first one, assigning the rest to a copy of the vertex
        bool created_new_vertex = false;
        for (array_size_t j = 1; j < v2f[i].size(); ++j)
        {
          if (!uf.sameSet(0, j))
          {
            array_size_t face = v2f[i][j];
            array_size_t copy_index = v2f.size() - 1;

            if (!created_new_vertex) // create a copy of the vertex
            {
              copy_index++;
              v2f.push_back(TheaArray<array_size_t>());
              vertex_map.push_back(vertex_map[i]);
              vertex_stack.push(copy_index);

              created_new_vertex = true;
            }

            v2f[copy_index].push_back(face);

            // Update the vertex index of this face to point to the copy
            for (typename FaceT::iterator vi = faces[face].begin(); vi != faces[face].end(); ++vi)
              if (*vi == (typename FaceT::value_type)i)
              {
                *vi = (typename FaceT::value_type)copy_index;
                break;
              }
          }
        }

        // If we made a copy of this vertex, we can get rid of faces reassigned to the copy
        if (created_new_vertex)
        {
          TheaArray<array_size_t> nbd;
          for (array_size_t j = 0; j < v2f[i].size(); ++j)
            if (uf.sameSet(0, j))
              nbd.push_back(v2f[i][j]);

          v2f[i] = nbd;
        }
      }

      if ((long)vertex_map.size() > num_vertices)
      {
        THEA_DEBUG << "Manifold: Non-manifold vertices found and fixed";
        return true;
      }
      else
        return false;
    }
예제 #10
0
bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
{
	init_args(game_params, cmd_args);

	// List video modes if requested
	if (list_video_modes)
		return print_video_modes();

	if (!init_engine(game_params.log_level)) {
		errorstream << "Could not initialize game engine." << std::endl;
		return false;
	}

	// Create time getter
	g_timegetter = new IrrlichtTimeGetter(device);

	// Speed tests (done after irrlicht is loaded to get timer)
	if (cmd_args.getFlag("speedtests")) {
		dstream << "Running speed tests" << std::endl;
		speed_tests();
		return true;
	}

	video::IVideoDriver *video_driver = device->getVideoDriver();
	if (video_driver == NULL) {
		errorstream << "Could not initialize video driver." << std::endl;
		return false;
	}

	porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);

	/*
		This changes the minimum allowed number of vertices in a VBO.
		Default is 500.
	*/
	//driver->setMinHardwareBufferVertexCount(50);
	video_driver->setMinHardwareBufferVertexCount(100);

	// Create game callback for menus
	g_gamecallback = new MainGameCallback(device);

	device->setResizable(true);

	if (random_input)
		input = new RandomInputHandler();
	else
		input = new RealInputHandler(device, receiver);

	smgr = device->getSceneManager();
	smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);

	guienv = device->getGUIEnvironment();
	skin = guienv->getSkin();

	skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
	skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
	skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
	skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
	skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 56, 121, 65));
	skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));

	g_fontengine = new FontEngine(g_settings, guienv);
	FATAL_ERROR_IF(g_fontengine == NULL, "Font engine creation failed.");

#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
	// Irrlicht 1.8 input colours
	skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
	skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 97, 173, 109));
#endif

	// Create the menu clouds
	if (!g_menucloudsmgr)
		g_menucloudsmgr = smgr->createNewSceneManager();
	if (!g_menuclouds)
		g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
				g_menucloudsmgr, -1, rand(), 100);
	g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
	scene::ICameraSceneNode* camera;
	camera = g_menucloudsmgr->addCameraSceneNode(0,
				v3f(0, 0, 0), v3f(0, 60, 100));
	camera->setFarValue(10000);

	/*
		GUI stuff
	*/

	ChatBackend chat_backend;

	// If an error occurs, this is set to something by menu().
	// It is then displayed before the menu shows on the next call to menu()
	std::string error_message;
	bool reconnect_requested = false;

	bool first_loop = true;

	/*
		Menu-game loop
	*/
	bool retval = true;
	bool *kill = porting::signal_handler_killstatus();

	while (device->run() && !*kill && !g_gamecallback->shutdown_requested)
	{
		// Set the window caption
		const wchar_t *text = wgettext("Main Menu");
		device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) + L" [" + text + L"]").c_str());
		delete[] text;

#ifdef __ANDROID__
		porting::handleAndroidActivityEvents();
#endif

		try {	// This is used for catching disconnects

			guienv->clear();

			/*
				We need some kind of a root node to be able to add
				custom gui elements directly on the screen.
				Otherwise they won't be automatically drawn.
			*/
			guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));

			bool game_has_run = launch_game(error_message, reconnect_requested,
				game_params, cmd_args);

			// If skip_main_menu, we only want to startup once
			if (skip_main_menu && !first_loop)
				break;

			first_loop = false;

			if (!game_has_run) {
				if (skip_main_menu)
					break;
				else
					continue;
			}

			if (g_settings_path != "")
				g_settings->updateConfigFile(g_settings_path.c_str());

			// Break out of menu-game loop to shut down cleanly
			if (!device->run() || *kill) {
				break;
			}

/*
			if (current_playername.length() > PLAYERNAME_SIZE-1) {
				error_message = gettext("Player name too long.");
				playername = current_playername.substr(0, PLAYERNAME_SIZE-1);
				g_settings->set("name", playername);
				continue;
			}
*/

			device->getVideoDriver()->setTextureCreationFlag(
					video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));

#ifdef HAVE_TOUCHSCREENGUI
			receiver->m_touchscreengui = new TouchScreenGUI(device, receiver);
			g_touchscreengui = receiver->m_touchscreengui;
#endif
			int tries = simple_singleplayer_mode ? 1 : g_settings->getU16("reconnects");
			int n = 0;

			while(!*kill && ++n <= tries &&
			the_game(
				kill,
				random_input,
				input,
				device,
				worldspec.path,
				current_playername,
				current_password,
				current_address,
				current_port,
				error_message,
				chat_backend,
				&reconnect_requested,
				gamespec,
				simple_singleplayer_mode
				, autoexit
			)
			){
				smgr->clear();
				errorstream << "Reconnecting "<< n << "/" << tries << " ..." << std::endl;
			}
			smgr->clear();

#ifdef HAVE_TOUCHSCREENGUI
			delete g_touchscreengui;
			g_touchscreengui = NULL;
			receiver->m_touchscreengui = NULL;
#endif

		} //try
		catch (con::PeerNotFoundException &e) {
			error_message = _("Connection error (timed out?)");
			errorstream << error_message << std::endl;
		}

#ifdef NDEBUG
		catch (std::exception &e) {
			std::string error_message = "Some exception: \"";
			error_message += e.what();
			error_message += "\"";
			errorstream << error_message << std::endl;
		}
#endif

		// If no main menu, show error and exit
		if (skip_main_menu) {
			if (!error_message.empty()) {
				verbosestream << "error_message = "
				              << error_message << std::endl;
				retval = false;
			}
			break;
		}
	} // Menu-game loop

	g_menuclouds->drop();
	g_menucloudsmgr->drop();

#ifdef _IRR_COMPILE_WITH_LEAK_HUNTER_
	auto objects = LeakHunter::getReferenceCountedObjects();
	infostream<<"irrlicht leaked objects="<<objects.size()<<std::endl;
	for (unsigned int i = 0; i < objects.size(); ++i) {
		if (!objects[i])
			continue;
		infostream<<i<<":" <<objects[i]<< " cnt="<<objects[i]->getReferenceCount()<<" desc="<<(objects[i]->getDebugName() ? objects[i]->getDebugName() : "")<<std::endl;
	}
#endif

	return retval;
}
예제 #11
0
void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
	LocalPlayer *player)
{
	switch (event->type) {
		case CE_DELETE_PARTICLESPAWNER: {
			MutexAutoLock lock(m_spawner_list_lock);
			if (m_particle_spawners.find(event->delete_particlespawner.id) !=
					m_particle_spawners.end()) {
				delete m_particle_spawners.find(event->delete_particlespawner.id)->second;
				m_particle_spawners.erase(event->delete_particlespawner.id);
			}
			// no allocated memory in delete event
			break;
		}
		case CE_ADD_PARTICLESPAWNER: {
			{
				MutexAutoLock lock(m_spawner_list_lock);
				if (m_particle_spawners.find(event->add_particlespawner.id) !=
						m_particle_spawners.end()) {
					delete m_particle_spawners.find(event->add_particlespawner.id)->second;
					m_particle_spawners.erase(event->add_particlespawner.id);
				}
			}

			video::ITexture *texture =
				client->tsrc()->getTextureForMesh(*(event->add_particlespawner.texture));

			ParticleSpawner *toadd = new ParticleSpawner(client, player,
					event->add_particlespawner.amount,
					event->add_particlespawner.spawntime,
					*event->add_particlespawner.minpos,
					*event->add_particlespawner.maxpos,
					*event->add_particlespawner.minvel,
					*event->add_particlespawner.maxvel,
					*event->add_particlespawner.minacc,
					*event->add_particlespawner.maxacc,
					event->add_particlespawner.minexptime,
					event->add_particlespawner.maxexptime,
					event->add_particlespawner.minsize,
					event->add_particlespawner.maxsize,
					event->add_particlespawner.collisiondetection,
					event->add_particlespawner.collision_removal,
					event->add_particlespawner.object_collision,
					event->add_particlespawner.attached_id,
					event->add_particlespawner.vertical,
					texture,
					event->add_particlespawner.id,
					event->add_particlespawner.animation,
					event->add_particlespawner.glow,
					this);

			/* delete allocated content of event */
			delete event->add_particlespawner.minpos;
			delete event->add_particlespawner.maxpos;
			delete event->add_particlespawner.minvel;
			delete event->add_particlespawner.maxvel;
			delete event->add_particlespawner.minacc;
			delete event->add_particlespawner.texture;
			delete event->add_particlespawner.maxacc;

			{
				MutexAutoLock lock(m_spawner_list_lock);
				m_particle_spawners.insert(
						std::pair<u32, ParticleSpawner*>(
								event->add_particlespawner.id,
								toadd));
			}
			break;
		}
		case CE_SPAWN_PARTICLE: {
			video::ITexture *texture =
				client->tsrc()->getTextureForMesh(*(event->spawn_particle.texture));

			Particle *toadd = new Particle(client, player, m_env,
					*event->spawn_particle.pos,
					*event->spawn_particle.vel,
					*event->spawn_particle.acc,
					event->spawn_particle.expirationtime,
					event->spawn_particle.size,
					event->spawn_particle.collisiondetection,
					event->spawn_particle.collision_removal,
					event->spawn_particle.object_collision,
					event->spawn_particle.vertical,
					texture,
					v2f(0.0, 0.0),
					v2f(1.0, 1.0),
					event->spawn_particle.animation,
					event->spawn_particle.glow);

			addParticle(toadd);

			delete event->spawn_particle.pos;
			delete event->spawn_particle.vel;
			delete event->spawn_particle.acc;
			delete event->spawn_particle.texture;

			break;
		}
		default: break;
	}
}
예제 #12
0
// hud_add(self, form)
int ObjectRef::l_hud_add(lua_State *L)
{
	NO_MAP_LOCK_REQUIRED;
	ObjectRef *ref = checkobject(L, 1);
	Player *player = getplayer(ref);
	if (player == NULL)
		return 0;

	HudElement *elem = new HudElement;

	elem->type = (HudElementType)getenumfield(L, 2, "hud_elem_type",
								es_HudElementType, HUD_ELEM_TEXT);

	lua_getfield(L, 2, "position");
	elem->pos = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
	lua_pop(L, 1);

	lua_getfield(L, 2, "scale");
	elem->scale = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
	lua_pop(L, 1);

	lua_getfield(L, 2, "size");
	elem->size = lua_istable(L, -1) ? read_v2s32(L, -1) : v2s32();
	lua_pop(L, 1);

	elem->name   = getstringfield_default(L, 2, "name", "");
	elem->text   = getstringfield_default(L, 2, "text", "");
	elem->number = getintfield_default(L, 2, "number", 0);
	elem->item   = getintfield_default(L, 2, "item", 0);
	elem->dir    = getintfield_default(L, 2, "direction", 0);

	// Deprecated, only for compatibility's sake
	if (elem->dir == 0)
		elem->dir = getintfield_default(L, 2, "dir", 0);

	lua_getfield(L, 2, "alignment");
	elem->align = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
	lua_pop(L, 1);

	lua_getfield(L, 2, "offset");
	elem->offset = lua_istable(L, -1) ? read_v2f(L, -1) : v2f();
	lua_pop(L, 1);

	lua_getfield(L, 2, "world_pos");
	elem->world_pos = lua_istable(L, -1) ? read_v3f(L, -1) : v3f();
	lua_pop(L, 1);

	/* check for known deprecated element usage */
	if ((elem->type  == HUD_ELEM_STATBAR) && (elem->size == v2s32())) {
		log_deprecated(L,"Deprecated usage of statbar without size!");
	}

	u32 id = getServer(L)->hudAdd(player, elem);
	if (id == U32_MAX) {
		delete elem;
		return 0;
	}

	lua_pushnumber(L, id);
	return 1;
}
예제 #13
0
파일: o.c 프로젝트: bartgrantham/alice
draw_o() {

    bgntmesh();
	v2f(o_data[0]);
	v2f(o_data[1]);
	v2f(o_data[2]);
	v2f(o_data[3]);
	v2f(o_data[4]);
	v2f(o_data[5]);
	v2f(o_data[6]);
	v2f(o_data[7]);
	v2f(o_data[8]);
	v2f(o_data[9]);
	v2f(o_data[10]);
	v2f(o_data[11]);
	v2f(o_data[12]);
	v2f(o_data[13]);
	v2f(o_data[14]);
	v2f(o_data[15]);
	v2f(o_data[16]);
	v2f(o_data[17]);
	v2f(o_data[18]);
	v2f(o_data[19]);
	v2f(o_data[20]);
	v2f(o_data[21]);
	v2f(o_data[22]);
	v2f(o_data[23]);
	v2f(o_data[24]);
	v2f(o_data[25]);
	v2f(o_data[26]);
	v2f(o_data[27]);
	v2f(o_data[28]);
	v2f(o_data[29]);
	v2f(o_data[30]);
	v2f(o_data[31]);
	v2f(o_data[32]);
    endtmesh();

    bgnline();
	v2f(o_data[0]);
	v2f(o_data[2]);
	v2f(o_data[4]);
	v2f(o_data[6]);
	v2f(o_data[8]);
	v2f(o_data[10]);
	v2f(o_data[12]);
	v2f(o_data[14]);
	v2f(o_data[16]);
	v2f(o_data[18]);
	v2f(o_data[20]);
	v2f(o_data[22]);
	v2f(o_data[24]);
	v2f(o_data[26]);
	v2f(o_data[28]);
	v2f(o_data[30]);
	v2f(o_data[32]);
	v2f(o_data[31]);
	v2f(o_data[29]);
	v2f(o_data[27]);
	v2f(o_data[25]);
	v2f(o_data[23]);
	v2f(o_data[21]);
	v2f(o_data[19]);
	v2f(o_data[17]);
	v2f(o_data[15]);
	v2f(o_data[13]);
	v2f(o_data[11]);
	v2f(o_data[9]);
	v2f(o_data[7]);
	v2f(o_data[5]);
	v2f(o_data[3]);
	v2f(o_data[1]);
    endline();

}
v3f::	v3f ( float x1, float y1, float z1 )	
: x ( x1 ), y ( y1 ), z ( z1 )
{
}

ostream& operator<< ( ostream& s, const v3f& v )
{
	return s << "(" << v.x << "," << v.y << "," << v.z << ")";
}


//	======================================

chromaticities ChromaticitiesForACES  	= { 
	v2f(0.73470f, 0.26530f),
	v2f(0.00000f, 1.00000f),
	v2f(0.00010f,-0.07700f),
	v2f(0.32168f, 0.33767f) };	//aces

acesHeaderInfo:: acesHeaderInfo()
: 
//	initialize required attributes to required, or default, values
acesImageContainerFlag	( 1 ), 
pixelAspectRatio	( 1.0f ),
screenWindowWidth	( 1.0f ),


//	initialize optional attributes to "ignored" values
altitude			( 0.0f ),
aperture			( 0.0f ), 
예제 #15
0
static inline ccVertex2F v2fperp(const ccVertex2F &p0)
{
	return v2f(-p0.y, p0.x);
}
void TestSerialization::testBufReader()
{
	u8 u8_data;
	u16 u16_data;
	u32 u32_data;
	u64 u64_data;
	s8 s8_data;
	s16 s16_data;
	s32 s32_data;
	s64 s64_data;
	f32 f32_data, f32_data2, f32_data3, f32_data4;
	video::SColor scolor_data;
	v2s16 v2s16_data;
	v3s16 v3s16_data;
	v2s32 v2s32_data;
	v3s32 v3s32_data;
	v2f v2f_data;
	v3f v3f_data;
	std::string string_data;
	std::wstring widestring_data;
	std::string longstring_data;
	u8 raw_data[10] = {0};

	BufReader buf(test_serialized_data, sizeof(test_serialized_data));

	// Try reading data like normal
	UASSERT(buf.getU8() == 0x11);
	UASSERT(buf.getU16() == 0x2233);
	UASSERT(buf.getU32() == 0x44556677);
	UASSERT(buf.getU64() == 0x8899AABBCCDDEEFF);
	UASSERT(buf.getS8() == -128);
	UASSERT(buf.getS16() == 30000);
	UASSERT(buf.getS32() == -6);
	UASSERT(buf.getS64() == -43);
	UASSERT(buf.getF1000() == 53.534f);
	UASSERT(buf.getF1000() == -300000.32f);
	UASSERT(buf.getF1000() == F1000_MIN);
	UASSERT(buf.getF1000() == F1000_MAX);
	UASSERT(buf.getString() == "foobar!");
	UASSERT(buf.getV2S16() == v2s16(500, 500));
	UASSERT(buf.getV3S16() == v3s16(4207, 604, -30));
	UASSERT(buf.getV2S32() == v2s32(1920, 1080));
	UASSERT(buf.getV3S32() == v3s32(-400, 6400054, 290549855));
	UASSERT(buf.getV2F1000() == v2f(500.656f, 350.345f));
	UASSERT(buf.getWideString() == L"\x02~woof~\x5455");
	UASSERT(buf.getV3F1000() == v3f(500, 10024.2f, -192.54f));
	UASSERT(buf.getARGB8() == video::SColor(255, 128, 50, 128));
	UASSERT(buf.getLongString() == "some longer string here");

	// Verify the offset and data is unchanged after a failed read
	size_t orig_pos = buf.pos;
	u32_data = 0;
	UASSERT(buf.getU32NoEx(&u32_data) == false);
	UASSERT(buf.pos == orig_pos);
	UASSERT(u32_data == 0);

	// Now try the same for a failed string read
	UASSERT(buf.getStringNoEx(&string_data) == false);
	UASSERT(buf.pos == orig_pos);
	UASSERT(string_data == "");

	// Now try the same for a failed string read
	UASSERT(buf.getWideStringNoEx(&widestring_data) == false);
	UASSERT(buf.pos == orig_pos);
	UASSERT(widestring_data == L"");

	UASSERT(buf.getU16() == 0xF00D);

	UASSERT(buf.remaining() == 0);

	// Check to make sure these each blow exceptions as they're supposed to
	EXCEPTION_CHECK(SerializationError, buf.getU8());
	EXCEPTION_CHECK(SerializationError, buf.getU16());
	EXCEPTION_CHECK(SerializationError, buf.getU32());
	EXCEPTION_CHECK(SerializationError, buf.getU64());

	EXCEPTION_CHECK(SerializationError, buf.getS8());
	EXCEPTION_CHECK(SerializationError, buf.getS16());
	EXCEPTION_CHECK(SerializationError, buf.getS32());
	EXCEPTION_CHECK(SerializationError, buf.getS64());

	EXCEPTION_CHECK(SerializationError, buf.getF1000());
	EXCEPTION_CHECK(SerializationError, buf.getARGB8());

	EXCEPTION_CHECK(SerializationError, buf.getV2S16());
	EXCEPTION_CHECK(SerializationError, buf.getV3S16());
	EXCEPTION_CHECK(SerializationError, buf.getV2S32());
	EXCEPTION_CHECK(SerializationError, buf.getV3S32());
	EXCEPTION_CHECK(SerializationError, buf.getV2F1000());
	EXCEPTION_CHECK(SerializationError, buf.getV3F1000());

	EXCEPTION_CHECK(SerializationError, buf.getString());
	EXCEPTION_CHECK(SerializationError, buf.getWideString());
	EXCEPTION_CHECK(SerializationError, buf.getLongString());
	EXCEPTION_CHECK(SerializationError,
		buf.getRawData(raw_data, sizeof(raw_data)));

	// See if we can skip backwards
	buf.pos = 5;
	UASSERT(buf.getRawDataNoEx(raw_data, 3) == true);
	UASSERT(raw_data[0] == 0x66);
	UASSERT(raw_data[1] == 0x77);
	UASSERT(raw_data[2] == 0x88);

	UASSERT(buf.getU32() == 0x99AABBCC);
	UASSERT(buf.pos == 12);

	// Now let's try it all over again using the NoEx variants
	buf.pos = 0;

	UASSERT(buf.getU8NoEx(&u8_data));
	UASSERT(buf.getU16NoEx(&u16_data));
	UASSERT(buf.getU32NoEx(&u32_data));
	UASSERT(buf.getU64NoEx(&u64_data));

	UASSERT(buf.getS8NoEx(&s8_data));
	UASSERT(buf.getS16NoEx(&s16_data));
	UASSERT(buf.getS32NoEx(&s32_data));
	UASSERT(buf.getS64NoEx(&s64_data));

	UASSERT(buf.getF1000NoEx(&f32_data));
	UASSERT(buf.getF1000NoEx(&f32_data2));
	UASSERT(buf.getF1000NoEx(&f32_data3));
	UASSERT(buf.getF1000NoEx(&f32_data4));

	UASSERT(buf.getStringNoEx(&string_data));
	UASSERT(buf.getV2S16NoEx(&v2s16_data));
	UASSERT(buf.getV3S16NoEx(&v3s16_data));
	UASSERT(buf.getV2S32NoEx(&v2s32_data));
	UASSERT(buf.getV3S32NoEx(&v3s32_data));
	UASSERT(buf.getV2F1000NoEx(&v2f_data));
	UASSERT(buf.getWideStringNoEx(&widestring_data));
	UASSERT(buf.getV3F1000NoEx(&v3f_data));
	UASSERT(buf.getARGB8NoEx(&scolor_data));

	UASSERT(buf.getLongStringNoEx(&longstring_data));

	// and make sure we got the correct data
	UASSERT(u8_data == 0x11);
	UASSERT(u16_data == 0x2233);
	UASSERT(u32_data == 0x44556677);
	UASSERT(u64_data == 0x8899AABBCCDDEEFF);
	UASSERT(s8_data == -128);
	UASSERT(s16_data == 30000);
	UASSERT(s32_data == -6);
	UASSERT(s64_data == -43);
	UASSERT(f32_data == 53.534f);
	UASSERT(f32_data2 == -300000.32f);
	UASSERT(f32_data3 == F1000_MIN);
	UASSERT(f32_data4 == F1000_MAX);
	UASSERT(string_data == "foobar!");
	UASSERT(v2s16_data == v2s16(500, 500));
	UASSERT(v3s16_data == v3s16(4207, 604, -30));
	UASSERT(v2s32_data == v2s32(1920, 1080));
	UASSERT(v3s32_data == v3s32(-400, 6400054, 290549855));
	UASSERT(v2f_data == v2f(500.656f, 350.345f));
	UASSERT(widestring_data == L"\x02~woof~\x5455");
	UASSERT(v3f_data == v3f(500, 10024.2f, -192.54f));
	UASSERT(scolor_data == video::SColor(255, 128, 50, 128));
	UASSERT(longstring_data == "some longer string here");

	UASSERT(buf.remaining() == 2);
	UASSERT(buf.getRawDataNoEx(raw_data, 3) == false);
	UASSERT(buf.remaining() == 2);
	UASSERT(buf.getRawDataNoEx(raw_data, 2) == true);
	UASSERT(raw_data[0] == 0xF0);
	UASSERT(raw_data[1] == 0x0D);
	UASSERT(buf.remaining() == 0);

	// Make sure no more available data causes a failure
	UASSERT(!buf.getU8NoEx(&u8_data));
	UASSERT(!buf.getU16NoEx(&u16_data));
	UASSERT(!buf.getU32NoEx(&u32_data));
	UASSERT(!buf.getU64NoEx(&u64_data));

	UASSERT(!buf.getS8NoEx(&s8_data));
	UASSERT(!buf.getS16NoEx(&s16_data));
	UASSERT(!buf.getS32NoEx(&s32_data));
	UASSERT(!buf.getS64NoEx(&s64_data));

	UASSERT(!buf.getF1000NoEx(&f32_data));
	UASSERT(!buf.getARGB8NoEx(&scolor_data));

	UASSERT(!buf.getV2S16NoEx(&v2s16_data));
	UASSERT(!buf.getV3S16NoEx(&v3s16_data));
	UASSERT(!buf.getV2S32NoEx(&v2s32_data));
	UASSERT(!buf.getV3S32NoEx(&v3s32_data));
	UASSERT(!buf.getV2F1000NoEx(&v2f_data));
	UASSERT(!buf.getV3F1000NoEx(&v3f_data));

	UASSERT(!buf.getStringNoEx(&string_data));
	UASSERT(!buf.getWideStringNoEx(&widestring_data));
	UASSERT(!buf.getLongStringNoEx(&longstring_data));
	UASSERT(!buf.getRawDataNoEx(raw_data, sizeof(raw_data)));
}
예제 #17
0
static inline ccVertex2F v2fneg(const ccVertex2F &p0)
{
	return v2f(-p0.x, - p0.y);
}
예제 #18
0
int main(int argc, char *argv[])
{
	int retval = 0;

	/*
		Initialization
	*/

	log_add_output_maxlev(&main_stderr_log_out, LMT_ACTION);
	log_add_output_all_levs(&main_dstream_no_stderr_log_out);

	log_register_thread("main");
	/*
		Parse command line
	*/

	// List all allowed options
	std::map<std::string, ValueSpec> allowed_options;
	allowed_options.insert(std::make_pair("help", ValueSpec(VALUETYPE_FLAG,
			_("Show allowed options"))));
	allowed_options.insert(std::make_pair("version", ValueSpec(VALUETYPE_FLAG,
			_("Show version information"))));
	allowed_options.insert(std::make_pair("config", ValueSpec(VALUETYPE_STRING,
			_("Load configuration from specified file"))));
	allowed_options.insert(std::make_pair("port", ValueSpec(VALUETYPE_STRING,
			_("Set network port (UDP)"))));
	allowed_options.insert(std::make_pair("disable-unittests", ValueSpec(VALUETYPE_FLAG,
			_("Disable unit tests"))));
	allowed_options.insert(std::make_pair("enable-unittests", ValueSpec(VALUETYPE_FLAG,
			_("Enable unit tests"))));
	allowed_options.insert(std::make_pair("map-dir", ValueSpec(VALUETYPE_STRING,
			_("Same as --world (deprecated)"))));
	allowed_options.insert(std::make_pair("world", ValueSpec(VALUETYPE_STRING,
			_("Set world path (implies local game) ('list' lists all)"))));
	allowed_options.insert(std::make_pair("worldname", ValueSpec(VALUETYPE_STRING,
			_("Set world by name (implies local game)"))));
	allowed_options.insert(std::make_pair("quiet", ValueSpec(VALUETYPE_FLAG,
			_("Print to console errors only"))));
	allowed_options.insert(std::make_pair("info", ValueSpec(VALUETYPE_FLAG,
			_("Print more information to console"))));
	allowed_options.insert(std::make_pair("verbose",  ValueSpec(VALUETYPE_FLAG,
			_("Print even more information to console"))));
	allowed_options.insert(std::make_pair("trace", ValueSpec(VALUETYPE_FLAG,
			_("Print enormous amounts of information to log and console"))));
	allowed_options.insert(std::make_pair("logfile", ValueSpec(VALUETYPE_STRING,
			_("Set logfile path ('' = no logging)"))));
	allowed_options.insert(std::make_pair("gameid", ValueSpec(VALUETYPE_STRING,
			_("Set gameid (\"--gameid list\" prints available ones)"))));
	allowed_options.insert(std::make_pair("migrate", ValueSpec(VALUETYPE_STRING,
			_("Migrate from current map backend to another (Only works when using minetestserver or with --server)"))));
#ifndef SERVER
	allowed_options.insert(std::make_pair("videomodes", ValueSpec(VALUETYPE_FLAG,
			_("Show available video modes"))));
	allowed_options.insert(std::make_pair("speedtests", ValueSpec(VALUETYPE_FLAG,
			_("Run speed tests"))));
	allowed_options.insert(std::make_pair("address", ValueSpec(VALUETYPE_STRING,
			_("Address to connect to. ('' = local game)"))));
	allowed_options.insert(std::make_pair("random-input", ValueSpec(VALUETYPE_FLAG,
			_("Enable random user input, for testing"))));
	allowed_options.insert(std::make_pair("server", ValueSpec(VALUETYPE_FLAG,
			_("Run dedicated server"))));
	allowed_options.insert(std::make_pair("name", ValueSpec(VALUETYPE_STRING,
			_("Set player name"))));
	allowed_options.insert(std::make_pair("password", ValueSpec(VALUETYPE_STRING,
			_("Set password"))));
	allowed_options.insert(std::make_pair("go", ValueSpec(VALUETYPE_FLAG,
			_("Disable main menu"))));
#endif

	Settings cmd_args;

	bool ret = cmd_args.parseCommandLine(argc, argv, allowed_options);

	if (ret == false || cmd_args.getFlag("help") || cmd_args.exists("nonopt1")) {
		dstream << _("Allowed options:") << std::endl;
		for(std::map<std::string, ValueSpec>::iterator
				i = allowed_options.begin();
				i != allowed_options.end(); ++i) {
			std::ostringstream os1(std::ios::binary);
			os1 << "  --"<<i->first;
			if (i->second.type == VALUETYPE_FLAG) {
			} else
				os1 << _(" <value>");
			dstream << padStringRight(os1.str(), 24);

			if (i->second.help != NULL)
				dstream << i->second.help;
			dstream << std::endl;
		}

		return cmd_args.getFlag("help") ? 0 : 1;
	}

	if (cmd_args.getFlag("version")) {
#ifdef SERVER
		dstream << "minetestserver " << minetest_version_hash << std::endl;
#else
		dstream << "Minetest " << minetest_version_hash << std::endl;
		dstream << "Using Irrlicht " << IRRLICHT_SDK_VERSION << std::endl;
#endif
		dstream << "Build info: " << minetest_build_info << std::endl;
		return 0;
	}

	/*
		Low-level initialization
	*/

	// Quiet mode, print errors only
	if (cmd_args.getFlag("quiet")) {
		log_remove_output(&main_stderr_log_out);
		log_add_output_maxlev(&main_stderr_log_out, LMT_ERROR);
	}
	// If trace is enabled, enable logging of certain things
	if (cmd_args.getFlag("trace")) {
		dstream << _("Enabling trace level debug output") << std::endl;
		log_trace_level_enabled = true;
		dout_con_ptr = &verbosestream; // this is somewhat old crap
		socket_enable_debug_output = true; // socket doesn't use log.h
	}
	// In certain cases, output info level on stderr
	if (cmd_args.getFlag("info") || cmd_args.getFlag("verbose") ||
			cmd_args.getFlag("trace") || cmd_args.getFlag("speedtests"))
		log_add_output(&main_stderr_log_out, LMT_INFO);
	// In certain cases, output verbose level on stderr
	if (cmd_args.getFlag("verbose") || cmd_args.getFlag("trace"))
		log_add_output(&main_stderr_log_out, LMT_VERBOSE);

	porting::signal_handler_init();
	bool &kill = *porting::signal_handler_killstatus();

	porting::initializePaths();

	// Create user data directory
	fs::CreateDir(porting::path_user);

	infostream << "path_share = " << porting::path_share << std::endl;
	infostream << "path_user  = "******"gameid") && cmd_args.get("gameid") == "list") {
		std::set<std::string> gameids = getAvailableGameIds();
		for(std::set<std::string>::const_iterator i = gameids.begin();
				i != gameids.end(); i++)
			dstream<<(*i)<<std::endl;
		return 0;
	}

	// List worlds if requested
	if (cmd_args.exists("world") && cmd_args.get("world") == "list") {
		dstream << _("Available worlds:") << std::endl;
		std::vector<WorldSpec> worldspecs = getAvailableWorlds();
		print_worldspecs(worldspecs, dstream);
		return 0;
	}

	// Print startup message
	infostream<<PROJECT_NAME <<	" "<< _("with") << " SER_FMT_VER_HIGHEST_READ="
		<< (int)SER_FMT_VER_HIGHEST_READ << ", " << minetest_build_info << std::endl;

	/*
		Basic initialization
	*/

	// Initialize default settings
	set_default_settings(g_settings);

	// Initialize sockets
	sockets_init();
	atexit(sockets_cleanup);

	/*
		Read config file
	*/

	// Path of configuration file in use
	g_settings_path = "";

	if (cmd_args.exists("config")) {
		bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
		if (r == false) {
			errorstream << "Could not read configuration from \""
					<< cmd_args.get("config") << "\"" << std::endl;
			return 1;
		}
		g_settings_path = cmd_args.get("config");
	} else {
		std::vector<std::string> filenames;
		filenames.push_back(porting::path_user +
				DIR_DELIM + "minetest.conf");
		// Legacy configuration file location
		filenames.push_back(porting::path_user +
				DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
#if RUN_IN_PLACE
		// Try also from a lower level (to aid having the same configuration
		// for many RUN_IN_PLACE installs)
		filenames.push_back(porting::path_user +
				DIR_DELIM + ".." + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf");
#endif

		for(u32 i = 0; i < filenames.size(); i++) {
			bool r = g_settings->readConfigFile(filenames[i].c_str());
			if (r) {
				g_settings_path = filenames[i];
				break;
			}
		}

		// If no path found, use the first one (menu creates the file)
		if (g_settings_path == "")
			g_settings_path = filenames[0];
	}

	// Initialize debug streams
#define DEBUGFILE "debug.txt"
#if RUN_IN_PLACE
	std::string logfile = DEBUGFILE;
#else
	std::string logfile = porting::path_user+DIR_DELIM+DEBUGFILE;
#endif
	if (cmd_args.exists("logfile"))
		logfile = cmd_args.get("logfile");

	log_remove_output(&main_dstream_no_stderr_log_out);
	int loglevel = g_settings->getS32("debug_log_level");

	if (loglevel == 0) //no logging
		logfile = "";
	else if (loglevel > 0 && loglevel <= LMT_NUM_VALUES)
		log_add_output_maxlev(&main_dstream_no_stderr_log_out,
		(LogMessageLevel)(loglevel - 1));

	if (logfile != "")
		debugstreams_init(false, logfile.c_str());
	else
		debugstreams_init(false, NULL);

	infostream << "logfile = " << logfile << std::endl;

	// Initialize random seed
	srand(time(0));
	mysrand(time(0));

	// Initialize HTTP fetcher
	httpfetch_init(g_settings->getS32("curl_parallel_limit"));

	/*
		Run unit tests
	*/

	if ((ENABLE_TESTS && cmd_args.getFlag("disable-unittests") == false)
			|| cmd_args.getFlag("enable-unittests") == true) {
				run_tests();
	}
#ifdef _MSC_VER
	init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
		g_settings->get("language"), argc, argv);
#else
	init_gettext((porting::path_share + DIR_DELIM + "locale").c_str(),
		g_settings->get("language"));
#endif

	/*
		Game parameters
	*/

	// Port
	u16 port = 30000;
	if (cmd_args.exists("port"))
		port = cmd_args.getU16("port");
	else if (g_settings->exists("port"))
		port = g_settings->getU16("port");
	if (port == 0)
		port = 30000;

	// World directory
	std::string commanded_world = "";
	if (cmd_args.exists("world"))
		commanded_world = cmd_args.get("world");
	else if (cmd_args.exists("map-dir"))
		commanded_world = cmd_args.get("map-dir");
	else if (cmd_args.exists("nonopt0")) // First nameless argument
		commanded_world = cmd_args.get("nonopt0");
	else if (g_settings->exists("map-dir"))
		commanded_world = g_settings->get("map-dir");

	// World name
	std::string commanded_worldname = "";
	if (cmd_args.exists("worldname"))
		commanded_worldname = cmd_args.get("worldname");

	// Strip world.mt from commanded_world
	{
		std::string worldmt = "world.mt";
		if (commanded_world.size() > worldmt.size() &&
				commanded_world.substr(commanded_world.size() - worldmt.size())
				== worldmt) {
			dstream << _("Supplied world.mt file - stripping it off.") << std::endl;
			commanded_world = commanded_world.substr(0,
				commanded_world.size() - worldmt.size());
		}
	}

	// If a world name was specified, convert it to a path
	if (commanded_worldname != "") {
		// Get information about available worlds
		std::vector<WorldSpec> worldspecs = getAvailableWorlds();
		bool found = false;
		for(u32 i = 0; i < worldspecs.size(); i++) {
			std::string name = worldspecs[i].name;
			if (name == commanded_worldname) {
				if (commanded_world != "") {
					dstream << _("--worldname takes precedence over previously "
							"selected world.") << std::endl;
				}
				commanded_world = worldspecs[i].path;
				found = true;
				break;
			}
		}
		if (!found) {
			dstream << _("World") << " '"<<commanded_worldname << _("' not "
					"available. Available worlds:") << std::endl;
			print_worldspecs(worldspecs, dstream);
			return 1;
		}
	}

	// Gamespec
	SubgameSpec commanded_gamespec;
	if (cmd_args.exists("gameid")) {
		std::string gameid = cmd_args.get("gameid");
		commanded_gamespec = findSubgame(gameid);
		if (!commanded_gamespec.isValid()) {
			errorstream << "Game \"" << gameid << "\" not found" << std::endl;
			return 1;
		}
	}


	/*
		Run dedicated server if asked to or no other option
	*/
#ifdef SERVER
	bool run_dedicated_server = true;
#else
	bool run_dedicated_server = cmd_args.getFlag("server");
#endif
	g_settings->set("server_dedicated", run_dedicated_server ? "true" : "false");
	if (run_dedicated_server)
	{
		DSTACK("Dedicated server branch");
		// Create time getter if built with Irrlicht
#ifndef SERVER
		g_timegetter = new SimpleTimeGetter();
#endif

		// World directory
		std::string world_path;
		verbosestream << _("Determining world path") << std::endl;
		bool is_legacy_world = false;
		// If a world was commanded, use it
		if (commanded_world != "") {
			world_path = commanded_world;
			infostream << "Using commanded world path [" << world_path << "]"
				<< std::endl;
		} else { // No world was specified; try to select it automatically
			// Get information about available worlds
			std::vector<WorldSpec> worldspecs = getAvailableWorlds();
			// If a world name was specified, select it
			if (commanded_worldname != "") {
				world_path = "";
				for(u32 i = 0; i < worldspecs.size(); i++) {
					std::string name = worldspecs[i].name;
					if (name == commanded_worldname) {
						world_path = worldspecs[i].path;
						break;
					}
				}
				if (world_path == "") {
					dstream << _("World") << " '" << commanded_worldname << "' " << _("not "
						"available. Available worlds:") << std::endl;
					print_worldspecs(worldspecs, dstream);
					return 1;
				}
			}
			// If there is only a single world, use it
			if (worldspecs.size() == 1) {
				world_path = worldspecs[0].path;
				dstream <<_("Automatically selecting world at") << " ["
					<< world_path << "]" << std::endl;
			// If there are multiple worlds, list them
			} else if (worldspecs.size() > 1) {
				dstream << _("Multiple worlds are available.") << std::endl;
				dstream << _("Please select one using --worldname <name>"
						" or --world <path>") << std::endl;
				print_worldspecs(worldspecs, dstream);
				return 1;
			// If there are no worlds, automatically create a new one
			} else {
				// This is the ultimate default world path
				world_path = porting::path_user + DIR_DELIM + "worlds" +
						DIR_DELIM + "world";
				infostream << "Creating default world at ["
						<< world_path << "]" << std::endl;
			}
		}

		if (world_path == "") {
			errorstream << "No world path specified or found." << std::endl;
			return 1;
		}
		verbosestream << _("Using world path") << " [" << world_path << "]" << std::endl;

		// We need a gamespec.
		SubgameSpec gamespec;
		verbosestream << _("Determining gameid/gamespec") << std::endl;
		// If world doesn't exist
		if (!getWorldExists(world_path)) {
			// Try to take gamespec from command line
			if (commanded_gamespec.isValid()) {
				gamespec = commanded_gamespec;
				infostream << "Using commanded gameid [" << gamespec.id << "]" << std::endl;
			} else { // Otherwise we will be using "minetest"
				gamespec = findSubgame(g_settings->get("default_game"));
				infostream << "Using default gameid [" << gamespec.id << "]" << std::endl;
			}
		} else { // World exists
			std::string world_gameid = getWorldGameId(world_path, is_legacy_world);
			// If commanded to use a gameid, do so
			if (commanded_gamespec.isValid()) {
				gamespec = commanded_gamespec;
				if (commanded_gamespec.id != world_gameid) {
					errorstream << "WARNING: Using commanded gameid ["
							<< gamespec.id << "]" << " instead of world gameid ["
							<< world_gameid << "]" << std::endl;
				}
			} else {
				// If world contains an embedded game, use it;
				// Otherwise find world from local system.
				gamespec = findWorldSubgame(world_path);
				infostream << "Using world gameid [" << gamespec.id << "]" << std::endl;
			}
		}
		if (!gamespec.isValid()) {
			errorstream << "Subgame [" << gamespec.id << "] could not be found."
					<< std::endl;
			return 1;
		}
		verbosestream << _("Using gameid") << " [" << gamespec.id<<"]" << std::endl;

		// Bind address
		std::string bind_str = g_settings->get("bind_address");
		Address bind_addr(0, 0, 0, 0, port);

		if (g_settings->getBool("ipv6_server")) {
			bind_addr.setAddress((IPv6AddressBytes*) NULL);
		}
		try {
			bind_addr.Resolve(bind_str.c_str());
		} catch (ResolveError &e) {
			infostream << "Resolving bind address \"" << bind_str
			           << "\" failed: " << e.what()
		        	   << " -- Listening on all addresses." << std::endl;
		}
		if (bind_addr.isIPv6() && !g_settings->getBool("enable_ipv6")) {
			errorstream << "Unable to listen on "
			            << bind_addr.serializeString()
				    << L" because IPv6 is disabled" << std::endl;
			return 1;
		}

		// Create server
		Server server(world_path, gamespec, false, bind_addr.isIPv6());

		// Database migration
		if (cmd_args.exists("migrate")) {
			std::string migrate_to = cmd_args.get("migrate");
			Settings world_mt;
			bool success = world_mt.readConfigFile((world_path + DIR_DELIM
				+ "world.mt").c_str());
			if (!success) {
				errorstream << "Cannot read world.mt" << std::endl;
				return 1;
			}
			if (!world_mt.exists("backend")) {
				errorstream << "Please specify your current backend in world.mt file:"
					<< std::endl << "	backend = {sqlite3|leveldb|redis|dummy}" << std::endl;
				return 1;
			}
			std::string backend = world_mt.get("backend");
			Database *new_db;
			if (backend == migrate_to) {
				errorstream << "Cannot migrate: new backend is same"
					<<" as the old one" << std::endl;
				return 1;
			}
			if (migrate_to == "sqlite3")
				new_db = new Database_SQLite3(&(ServerMap&)server.getMap(), world_path);
			#if USE_LEVELDB
			else if (migrate_to == "leveldb")
				new_db = new Database_LevelDB(&(ServerMap&)server.getMap(), world_path);
			#endif
			#if USE_REDIS
			else if (migrate_to == "redis")
				new_db = new Database_Redis(&(ServerMap&)server.getMap(), world_path);
			#endif
			else {
				errorstream << "Migration to " << migrate_to
					<< " is not supported" << std::endl;
				return 1;
			}

			std::list<v3s16> blocks;
			ServerMap &old_map = ((ServerMap&)server.getMap());
			old_map.listAllLoadableBlocks(blocks);
			int count = 0;
			new_db->beginSave();
			for (std::list<v3s16>::iterator i = blocks.begin(); i != blocks.end(); i++) {
				MapBlock *block = old_map.loadBlock(*i);
				new_db->saveBlock(block);
				MapSector *sector = old_map.getSectorNoGenerate(v2s16(i->X, i->Z));
				sector->deleteBlock(block);
				++count;
				if (count % 500 == 0)
					actionstream << "Migrated " << count << " blocks "
						<< (100.0 * count / blocks.size()) << "% completed" << std::endl;
			}
			new_db->endSave();
			delete new_db;

			actionstream << "Successfully migrated " << count << " blocks" << std::endl;
			world_mt.set("backend", migrate_to);
			if (!world_mt.updateConfigFile((world_path + DIR_DELIM + "world.mt").c_str()))
				errorstream << "Failed to update world.mt!" << std::endl;
			else
				actionstream << "world.mt updated" << std::endl;

			return 0;
		}

		server.start(bind_addr);

		// Run server
		dedicated_server_loop(server, kill);

		return 0;
	}

#ifndef SERVER // Exclude from dedicated server build

	/*
		More parameters
	*/

	std::string address = g_settings->get("address");
	if (commanded_world != "")
		address = "";
	else if (cmd_args.exists("address"))
		address = cmd_args.get("address");

	std::string playername = g_settings->get("name");
	if (cmd_args.exists("name"))
		playername = cmd_args.get("name");

	bool skip_main_menu = cmd_args.getFlag("go");

	/*
		Device initialization
	*/

	// Resolution selection

	bool fullscreen = g_settings->getBool("fullscreen");
	u16 screenW = g_settings->getU16("screenW");
	u16 screenH = g_settings->getU16("screenH");

	// bpp, fsaa, vsync

	bool vsync = g_settings->getBool("vsync");
	u16 bits = g_settings->getU16("fullscreen_bpp");
	u16 fsaa = g_settings->getU16("fsaa");

	// Determine driver

	video::E_DRIVER_TYPE driverType;

	std::string driverstring = g_settings->get("video_driver");

	if (driverstring == "null")
		driverType = video::EDT_NULL;
	else if (driverstring == "software")
		driverType = video::EDT_SOFTWARE;
	else if (driverstring == "burningsvideo")
		driverType = video::EDT_BURNINGSVIDEO;
	else if (driverstring == "direct3d8")
		driverType = video::EDT_DIRECT3D8;
	else if (driverstring == "direct3d9")
		driverType = video::EDT_DIRECT3D9;
	else if (driverstring == "opengl")
		driverType = video::EDT_OPENGL;
#ifdef _IRR_COMPILE_WITH_OGLES1_
	else if (driverstring == "ogles1")
		driverType = video::EDT_OGLES1;
#endif
#ifdef _IRR_COMPILE_WITH_OGLES2_
	else if (driverstring == "ogles2")
		driverType = video::EDT_OGLES2;
#endif
	else {
		errorstream << "WARNING: Invalid video_driver specified; defaulting "
			<< "to opengl" << std::endl;
		driverType = video::EDT_OPENGL;
	}

	/*
		List video modes if requested
	*/

	MyEventReceiver receiver;

	if (cmd_args.getFlag("videomodes")) {
		IrrlichtDevice *nulldevice;

		SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
		params.DriverType    = video::EDT_NULL;
		params.WindowSize    = core::dimension2d<u32>(640, 480);
		params.Bits          = 24;
		params.AntiAlias     = fsaa;
		params.Fullscreen    = false;
		params.Stencilbuffer = false;
		params.Vsync         = vsync;
		params.EventReceiver = &receiver;
		params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");

		nulldevice = createDeviceEx(params);

		if (nulldevice == 0)
			return 1;

		dstream << _("Available video modes (WxHxD):") << std::endl;

		video::IVideoModeList *videomode_list =
				nulldevice->getVideoModeList();

		if (videomode_list == 0) {
			nulldevice->drop();
			return 1;
		}

		s32 videomode_count = videomode_list->getVideoModeCount();
		core::dimension2d<u32> videomode_res;
		s32 videomode_depth;
		for (s32 i = 0; i < videomode_count; ++i) {
			videomode_res = videomode_list->getVideoModeResolution(i);
			videomode_depth = videomode_list->getVideoModeDepth(i);
			dstream<<videomode_res.Width << "x" << videomode_res.Height
					<< "x" << videomode_depth << std::endl;
		}

		dstream << _("Active video mode (WxHxD):") << std::endl;
		videomode_res = videomode_list->getDesktopResolution();
		videomode_depth = videomode_list->getDesktopDepth();
		dstream << videomode_res.Width << "x" << videomode_res.Height
				<< "x" << videomode_depth << std::endl;

		nulldevice->drop();

		return 0;
	}

	/*
		Create device and exit if creation failed
	*/

	IrrlichtDevice *device;

	SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
	params.DriverType    = driverType;
	params.WindowSize    = core::dimension2d<u32>(screenW, screenH);
	params.Bits          = bits;
	params.AntiAlias     = fsaa;
	params.Fullscreen    = fullscreen;
	params.Stencilbuffer = false;
	params.Vsync         = vsync;
	params.EventReceiver = &receiver;
	params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");

	device = createDeviceEx(params);

	if (device == 0) {
		return 1; // could not create selected driver.
	}

	// Map our log level to irrlicht engine one.
	static const irr::ELOG_LEVEL irr_log_level[5] = {
		ELL_NONE,
		ELL_ERROR,
		ELL_WARNING,
		ELL_INFORMATION,
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
		ELL_INFORMATION
#else
		ELL_DEBUG
#endif
	};

	ILogger* irr_logger = device->getLogger();
	irr_logger->setLogLevel(irr_log_level[loglevel]);

	porting::initIrrlicht(device);

	/*
		Continue initialization
	*/

	video::IVideoDriver* driver = device->getVideoDriver();

	/*
		This changes the minimum allowed number of vertices in a VBO.
		Default is 500.
	*/
	//driver->setMinHardwareBufferVertexCount(50);

	// Create time getter
	g_timegetter = new IrrlichtTimeGetter(device);

	// Create game callback for menus
	g_gamecallback = new MainGameCallback(device);

	/*
		Speed tests (done after irrlicht is loaded to get timer)
	*/
	if (cmd_args.getFlag("speedtests"))
	{
		dstream << "Running speed tests" << std::endl;
		SpeedTests();
		device->drop();
		return 0;
	}

	device->setResizable(true);

	bool random_input = g_settings->getBool("random_input")
			|| cmd_args.getFlag("random-input");
	InputHandler *input = NULL;
	if (random_input) {
		input = new RandomInputHandler();
	} else {
		input = new RealInputHandler(device, &receiver);
	}

	scene::ISceneManager* smgr = device->getSceneManager();

	guienv = device->getGUIEnvironment();
	gui::IGUISkin* skin = guienv->getSkin();
	std::string font_path = g_settings->get("font_path");
	gui::IGUIFont *font;
	#if USE_FREETYPE
	bool use_freetype = g_settings->getBool("freetype");
	if (use_freetype) {
		std::string fallback;
		if (is_yes(gettext("needs_fallback_font")))
			fallback = "fallback_";
		u16 font_size = g_settings->getU16(fallback + "font_size");
		font_path = g_settings->get(fallback + "font_path");
		u32 font_shadow = g_settings->getU16(fallback + "font_shadow");
		u32 font_shadow_alpha = g_settings->getU16(fallback + "font_shadow_alpha");
		font = gui::CGUITTFont::createTTFont(guienv, font_path.c_str(), font_size,
			true, true, font_shadow, font_shadow_alpha);
	} else {
		font = guienv->getFont(font_path.c_str());
	}
	#else
	font = guienv->getFont(font_path.c_str());
	#endif
	if (font)
		skin->setFont(font);
	else
		errorstream << "WARNING: Font file was not found."
				<< " Using default font." << std::endl;
	// If font was not found, this will get us one
	font = skin->getFont();
	assert(font);

	u32 text_height = font->getDimension(L"Hello, world!").Height;
	infostream << "text_height=" << text_height << std::endl;

	skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
	skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 0, 0, 0));
	skin->setColor(gui::EGDC_3D_SHADOW, video::SColor(255, 0, 0, 0));
	skin->setColor(gui::EGDC_HIGH_LIGHT, video::SColor(255, 70, 100, 50));
	skin->setColor(gui::EGDC_HIGH_LIGHT_TEXT, video::SColor(255, 255, 255, 255));

#if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2
	// Irrlicht 1.8 input colours
	skin->setColor(gui::EGDC_EDITABLE, video::SColor(255, 128, 128, 128));
	skin->setColor(gui::EGDC_FOCUSED_EDITABLE, video::SColor(255, 96, 134, 49));
#endif


	// Create the menu clouds
	if (!g_menucloudsmgr)
		g_menucloudsmgr = smgr->createNewSceneManager();
	if (!g_menuclouds)
		g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
			g_menucloudsmgr, -1, rand(), 100);
	g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
	scene::ICameraSceneNode* camera;
	camera = g_menucloudsmgr->addCameraSceneNode(0,
				v3f(0, 0, 0), v3f(0, 60, 100));
	camera->setFarValue(10000);

	/*
		GUI stuff
	*/

	ChatBackend chat_backend;

	/*
		If an error occurs, this is set to something and the
		menu-game loop is restarted. It is then displayed before
		the menu.
	*/
	std::wstring error_message = L"";

	// The password entered during the menu screen,
	std::string password;

	bool first_loop = true;

	/*
		Menu-game loop
	*/
	while (device->run() && kill == false)
	{
		// Set the window caption
		wchar_t* text = wgettext("Main Menu");
		device->setWindowCaption((std::wstring(L"Minetest [") + text + L"]").c_str());
		delete[] text;

		// This is used for catching disconnects
		try
		{

			/*
				Clear everything from the GUIEnvironment
			*/
			guienv->clear();

			/*
				We need some kind of a root node to be able to add
				custom gui elements directly on the screen.
				Otherwise they won't be automatically drawn.
			*/
			guiroot = guienv->addStaticText(L"",
				core::rect<s32>(0, 0, 10000, 10000));

			SubgameSpec gamespec;
			WorldSpec worldspec;
			bool simple_singleplayer_mode = false;

			// These are set up based on the menu and other things
			std::string current_playername = "inv£lid";
			std::string current_password = "";
			std::string current_address = "does-not-exist";
			int current_port = 0;

			/*
				Out-of-game menu loop.

				Loop quits when menu returns proper parameters.
			*/
			while (kill == false) {
				// If skip_main_menu, only go through here once
				if (skip_main_menu && !first_loop) {
					kill = true;
					break;
				}
				first_loop = false;

				// Cursor can be non-visible when coming from the game
				device->getCursorControl()->setVisible(true);
				// Some stuff are left to scene manager when coming from the game
				// (map at least?)
				smgr->clear();

				// Initialize menu data
				MainMenuData menudata;
				menudata.address = address;
				menudata.name = playername;
				menudata.port = itos(port);
				menudata.errormessage = wide_to_narrow(error_message);
				error_message = L"";
				if (cmd_args.exists("password"))
					menudata.password = cmd_args.get("password");

				driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));

				menudata.enable_public = g_settings->getBool("server_announce");

				std::vector<WorldSpec> worldspecs = getAvailableWorlds();

				// If a world was commanded, append and select it
				if(commanded_world != "") {
					worldspec.gameid = getWorldGameId(commanded_world, true);
					worldspec.name = _("[--world parameter]");
					if(worldspec.gameid == "") {
						worldspec.gameid = g_settings->get("default_game");
						worldspec.name += " [new]";
					}
					worldspec.path = commanded_world;
				}

				if (skip_main_menu == false) {
					video::IVideoDriver* driver = device->getVideoDriver();

					infostream << "Waiting for other menus" << std::endl;
					while (device->run() && kill == false) {
						if (noMenuActive())
							break;
						driver->beginScene(true, true,
								video::SColor(255, 128, 128, 128));
						guienv->drawAll();
						driver->endScene();
						// On some computers framerate doesn't seem to be
						// automatically limited
						sleep_ms(25);
					}
					infostream << "Waited for other menus" << std::endl;

					GUIEngine* temp = new GUIEngine(device, guiroot,
						&g_menumgr, smgr, &menudata, kill);

					delete temp;
					//once finished you'll never end up here
					smgr->clear();
				}

				if (menudata.errormessage != "") {
					error_message = narrow_to_wide(menudata.errormessage);
					continue;
				}

				//update worldspecs (necessary as new world may have been created)
				worldspecs = getAvailableWorlds();

				if (menudata.name == "")
					menudata.name = std::string("Guest") + itos(myrand_range(1000,9999));
				else
					playername = menudata.name;

				password = translatePassword(playername, narrow_to_wide(menudata.password));
				//infostream<<"Main: password hash: '"<<password<<"'"<<std::endl;

				address = menudata.address;
				int newport = stoi(menudata.port);
				if (newport != 0)
					port = newport;

				simple_singleplayer_mode = menudata.simple_singleplayer_mode;

				// Save settings
				g_settings->set("name", playername);

				// Break out of menu-game loop to shut down cleanly
				if (device->run() == false || kill == true)
					break;

				current_playername = playername;
				current_password = password;
				current_address = address;
				current_port = port;

				// If using simple singleplayer mode, override
				if (simple_singleplayer_mode) {
					current_playername = "singleplayer";
					current_password = "";
					current_address = "";
					current_port = myrand_range(49152, 65535);
				} else if (address != "") {
					ServerListSpec server;
					server["name"] = menudata.servername;
					server["address"] = menudata.address;
					server["port"] = menudata.port;
					server["description"] = menudata.serverdescription;
					ServerList::insert(server);
				}

				if ((!skip_main_menu) &&
						(menudata.selected_world >= 0) &&
						(menudata.selected_world < (int)worldspecs.size())) {
					g_settings->set("selected_world_path",
							worldspecs[menudata.selected_world].path);
					worldspec = worldspecs[menudata.selected_world];

				}

				infostream <<"Selected world: " << worldspec.name
							<< " ["<<worldspec.path<<"]" <<std::endl;


				// If local game
				if (current_address == "") {
					if (worldspec.path == "") {
						error_message = wgettext("No world selected and no address "
								"provided. Nothing to do.");
						errorstream << wide_to_narrow(error_message) << std::endl;
						continue;
					}

					if (!fs::PathExists(worldspec.path)) {
						error_message = wgettext("Provided world path doesn't exist: ")
								+ narrow_to_wide(worldspec.path);
						errorstream << wide_to_narrow(error_message) << std::endl;
						continue;
					}

					// Load gamespec for required game
					gamespec = findWorldSubgame(worldspec.path);
					if (!gamespec.isValid() && !commanded_gamespec.isValid()) {
						error_message = wgettext("Could not find or load game \"")
								+ narrow_to_wide(worldspec.gameid) + L"\"";
						errorstream << wide_to_narrow(error_message) << std::endl;
						continue;
					}
					if (commanded_gamespec.isValid() &&
							commanded_gamespec.id != worldspec.gameid) {
						errorstream<<"WARNING: Overriding gamespec from \""
								<< worldspec.gameid << "\" to \""
								<< commanded_gamespec.id << "\"" << std::endl;
						gamespec = commanded_gamespec;
					}

					if (!gamespec.isValid()) {
						error_message = wgettext("Invalid gamespec.");
						error_message += L" (world_gameid="
								+ narrow_to_wide(worldspec.gameid) + L")";
						errorstream << wide_to_narrow(error_message) << std::endl;
						continue;
					}
				}

				// Continue to game
				break;
			}

			// Break out of menu-game loop to shut down cleanly
			if (device->run() == false || kill == true) {
				if (g_settings_path != "") {
					g_settings->updateConfigFile(g_settings_path.c_str());
				}
				break;
			}

			/*
				Run game
			*/
			the_game(
				kill,
				random_input,
				input,
				device,
				font,
				worldspec.path,
				current_playername,
				current_password,
				current_address,
				current_port,
				error_message,
				chat_backend,
				gamespec,
				simple_singleplayer_mode
			);
			smgr->clear();

		} //try
		catch(con::PeerNotFoundException &e)
		{
			error_message = wgettext("Connection error (timed out?)");
			errorstream << wide_to_narrow(error_message) << std::endl;
		}
#ifdef NDEBUG
		catch(std::exception &e)
		{
			std::string narrow_message = "Some exception: \"";
			narrow_message += e.what();
			narrow_message += "\"";
			errorstream << narrow_message << std::endl;
			error_message = narrow_to_wide(narrow_message);
		}
#endif

		// If no main menu, show error and exit
		if (skip_main_menu) {
			if (error_message != L"") {
				verbosestream << "error_message = "
						<< wide_to_narrow(error_message) << std::endl;
				retval = 1;
			}
			break;
		}
	} // Menu-game loop


	g_menuclouds->drop();
	g_menucloudsmgr->drop();

	delete input;

	/*
		In the end, delete the Irrlicht device.
	*/
	device->drop();

#if USE_FREETYPE
	if (use_freetype)
		font->drop();
#endif

#endif // !SERVER

	// Update configuration file
	if (g_settings_path != "")
		g_settings->updateConfigFile(g_settings_path.c_str());

	// Print modified quicktune values
	{
		bool header_printed = false;
		std::vector<std::string> names = getQuicktuneNames();
		for(u32 i = 0; i < names.size(); i++) {
			QuicktuneValue val = getQuicktuneValue(names[i]);
			if (!val.modified)
				continue;
			if (!header_printed) {
				dstream << "Modified quicktune values:" << std::endl;
				header_printed = true;
			}
			dstream<<names[i] << " = " << val.getString() << std::endl;
		}
	}

	// Stop httpfetch thread (if started)
	httpfetch_cleanup();

	END_DEBUG_EXCEPTION_HANDLER(errorstream)

	debugstreams_deinit();


	return retval;
}
예제 #19
0
static inline ccVertex2F v2fnormalize(const ccVertex2F &p)
{
	CCPoint r = ccpNormalize(ccp(p.x, p.y));
	return v2f(r.x, r.y);
}
예제 #20
0
void Clouds::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
	//if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
		return;

	ScopeProfiler sp(g_profiler, "Rendering of clouds, avg", SPT_AVG);
	
	bool enable_3d = g_settings->getBool("enable_3d_clouds");
	int num_faces_to_draw = enable_3d ? 6 : 1;
	
	m_material.setFlag(video::EMF_BACK_FACE_CULLING, enable_3d);

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	driver->setMaterial(m_material);
	
	/*
		Clouds move from X+ towards X-
	*/

	const s16 cloud_radius_i = 12;
	const float cloud_size = BS*64;
	const v2f cloud_speed(0, -BS*2);
	
	const float cloud_full_radius = cloud_size * cloud_radius_i;
	
	// Position of cloud noise origin in world coordinates
	v2f world_cloud_origin_pos_f = m_time*cloud_speed;
	// Position of cloud noise origin from the camera
	v2f cloud_origin_from_camera_f = world_cloud_origin_pos_f - m_camera_pos;
	// The center point of drawing in the noise
	v2f center_of_drawing_in_noise_f = -cloud_origin_from_camera_f;
	// The integer center point of drawing in the noise
	v2s16 center_of_drawing_in_noise_i(
		MYROUND(center_of_drawing_in_noise_f.X / cloud_size),
		MYROUND(center_of_drawing_in_noise_f.Y / cloud_size)
	);
	// The world position of the integer center point of drawing in the noise
	v2f world_center_of_drawing_in_noise_f = v2f(
		center_of_drawing_in_noise_i.X * cloud_size,
		center_of_drawing_in_noise_i.Y * cloud_size
	) + world_cloud_origin_pos_f;

	/*video::SColor c_top(128,b*240,b*240,b*255);
	video::SColor c_side_1(128,b*230,b*230,b*255);
	video::SColor c_side_2(128,b*220,b*220,b*245);
	video::SColor c_bottom(128,b*205,b*205,b*230);*/
	video::SColorf c_top_f(m_color);
	video::SColorf c_side_1_f(m_color);
	video::SColorf c_side_2_f(m_color);
	video::SColorf c_bottom_f(m_color);
	c_side_1_f.r *= 0.95;
	c_side_1_f.g *= 0.95;
	c_side_1_f.b *= 0.95;
	c_side_2_f.r *= 0.90;
	c_side_2_f.g *= 0.90;
	c_side_2_f.b *= 0.90;
	c_bottom_f.r *= 0.80;
	c_bottom_f.g *= 0.80;
	c_bottom_f.b *= 0.80;
	c_top_f.a = 0.9;
	c_side_1_f.a = 0.9;
	c_side_2_f.a = 0.9;
	c_bottom_f.a = 0.9;
	video::SColor c_top = c_top_f.toSColor();
	video::SColor c_side_1 = c_side_1_f.toSColor();
	video::SColor c_side_2 = c_side_2_f.toSColor();
	video::SColor c_bottom = c_bottom_f.toSColor();

	// Get fog parameters for setting them back later
	video::SColor fog_color(0,0,0,0);
	video::E_FOG_TYPE fog_type = video::EFT_FOG_LINEAR;
	f32 fog_start = 0;
	f32 fog_end = 0;
	f32 fog_density = 0;
	bool fog_pixelfog = false;
	bool fog_rangefog = false;
	driver->getFog(fog_color, fog_type, fog_start, fog_end, fog_density,
			fog_pixelfog, fog_rangefog);
	
	// Set our own fog
	driver->setFog(fog_color, fog_type, cloud_full_radius * 0.5,
			cloud_full_radius*1.2, fog_density, fog_pixelfog, fog_rangefog);

	// Read noise

	bool *grid = new bool[cloud_radius_i*2*cloud_radius_i*2];

	for(s16 zi=-cloud_radius_i; zi<cloud_radius_i; zi++)
	for(s16 xi=-cloud_radius_i; xi<cloud_radius_i; xi++)
	{
		u32 i = (zi+cloud_radius_i)*cloud_radius_i*2 + xi+cloud_radius_i;

		v2s16 p_in_noise_i(
			xi+center_of_drawing_in_noise_i.X,
			zi+center_of_drawing_in_noise_i.Y
		);

#if 0
		double noise = noise2d_perlin_abs(
				(float)p_in_noise_i.X*cloud_size/BS/200,
				(float)p_in_noise_i.Y*cloud_size/BS/200,
				m_seed, 3, 0.4);
		grid[i] = (noise >= 0.80);
#endif
#if 1
		double noise = noise2d_perlin(
				(float)p_in_noise_i.X*cloud_size/BS/200,
				(float)p_in_noise_i.Y*cloud_size/BS/200,
				m_seed, 3, 0.5);
		grid[i] = (noise >= 0.4);
#endif
	}

#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
#define INAREA(x, z, radius) \
	((x) >= -(radius) && (x) < (radius) && (z) >= -(radius) && (z) < (radius))

	for(s16 zi0=-cloud_radius_i; zi0<cloud_radius_i; zi0++)
	for(s16 xi0=-cloud_radius_i; xi0<cloud_radius_i; xi0++)
	{
		s16 zi = zi0;
		s16 xi = xi0;
		// Draw from front to back (needed for transparency)
		/*if(zi <= 0)
			zi = -cloud_radius_i - zi;
		if(xi <= 0)
			xi = -cloud_radius_i - xi;*/
		// Draw from back to front
		if(zi >= 0)
			zi = cloud_radius_i - zi - 1;
		if(xi >= 0)
			xi = cloud_radius_i - xi - 1;

		u32 i = GETINDEX(xi, zi, cloud_radius_i);

		if(grid[i] == false)
			continue;

		v2f p0 = v2f(xi,zi)*cloud_size + world_center_of_drawing_in_noise_f;

		video::S3DVertex v[4] = {
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 1),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 1, 0),
			video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
		};

		/*if(zi <= 0 && xi <= 0){
			v[0].Color.setBlue(255);
			v[1].Color.setBlue(255);
			v[2].Color.setBlue(255);
			v[3].Color.setBlue(255);
		}*/

		f32 rx = cloud_size/2;
		f32 ry = 8*BS;
		f32 rz = cloud_size/2;

		for(int i=0; i<num_faces_to_draw; i++)
		{
			switch(i)
			{
			case 0:	// top
				for(int j=0;j<4;j++){
					v[j].Normal.set(0,1,0);
				}
				v[0].Pos.set(-rx, ry,-rz);
				v[1].Pos.set(-rx, ry, rz);
				v[2].Pos.set( rx, ry, rz);
				v[3].Pos.set( rx, ry,-rz);
				break;
			case 1: // back
				if(INAREA(xi, zi-1, cloud_radius_i)){
					u32 j = GETINDEX(xi, zi-1, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_1;
					v[j].Normal.set(0,0,-1);
				}
				v[0].Pos.set(-rx, ry,-rz);
				v[1].Pos.set( rx, ry,-rz);
				v[2].Pos.set( rx,-ry,-rz);
				v[3].Pos.set(-rx,-ry,-rz);
				break;
			case 2: //right
				if(INAREA(xi+1, zi, cloud_radius_i)){
					u32 j = GETINDEX(xi+1, zi, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_2;
					v[j].Normal.set(1,0,0);
				}
				v[0].Pos.set( rx, ry,-rz);
				v[1].Pos.set( rx, ry, rz);
				v[2].Pos.set( rx,-ry, rz);
				v[3].Pos.set( rx,-ry,-rz);
				break;
			case 3: // front
				if(INAREA(xi, zi+1, cloud_radius_i)){
					u32 j = GETINDEX(xi, zi+1, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_1;
					v[j].Normal.set(0,0,-1);
				}
				v[0].Pos.set( rx, ry, rz);
				v[1].Pos.set(-rx, ry, rz);
				v[2].Pos.set(-rx,-ry, rz);
				v[3].Pos.set( rx,-ry, rz);
				break;
			case 4: // left
				if(INAREA(xi-1, zi, cloud_radius_i)){
					u32 j = GETINDEX(xi-1, zi, cloud_radius_i);
					if(grid[j])
						continue;
				}
				for(int j=0;j<4;j++){
					v[j].Color = c_side_2;
					v[j].Normal.set(-1,0,0);
				}
				v[0].Pos.set(-rx, ry, rz);
				v[1].Pos.set(-rx, ry,-rz);
				v[2].Pos.set(-rx,-ry,-rz);
				v[3].Pos.set(-rx,-ry, rz);
				break;
			case 5: // bottom
				for(int j=0;j<4;j++){
					v[j].Color = c_bottom;
					v[j].Normal.set(0,-1,0);
				}
				v[0].Pos.set( rx,-ry, rz);
				v[1].Pos.set(-rx,-ry, rz);
				v[2].Pos.set(-rx,-ry,-rz);
				v[3].Pos.set( rx,-ry,-rz);
				break;
			}

			v3f pos(p0.X, m_cloud_y, p0.Y);
			pos -= intToFloat(m_camera_offset, BS);

			for(u16 i=0; i<4; i++)
				v[i].Pos += pos;
			u16 indices[] = {0,1,2,2,3,0};
			driver->drawVertexPrimitiveList(v, 4, indices, 2,
					video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
		}
	}

	delete[] grid;
	
	// Restore fog settings
	driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,
			fog_pixelfog, fog_rangefog);
}
예제 #21
0
static inline Vec2 v2fsub(const Vec2 &v0, const Vec2 &v1)
{
    return v2f(v0.x-v1.x, v0.y-v1.y);
}
예제 #22
0
파일: farmesh.cpp 프로젝트: Neear/minetest
void FarMesh::render()
{
	video::IVideoDriver* driver = SceneManager->getVideoDriver();

	/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
		return;*/
	if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SOLID)
		return;
	/*if(SceneManager->getSceneNodeRenderPass() != scene::ESNRP_SKY_BOX)
		return;*/

	driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
	
	//const s16 grid_radius_i = 12;
	//const float grid_size = BS*50;
	const s16 grid_radius_i = m_render_range/MAP_BLOCKSIZE;
	const float grid_size = BS*MAP_BLOCKSIZE;
	const v2f grid_speed(-BS*0, 0);
	
	// Position of grid noise origin in world coordinates
	v2f world_grid_origin_pos_f(0,0);
	// Position of grid noise origin from the camera
	v2f grid_origin_from_camera_f = world_grid_origin_pos_f - m_camera_pos;
	// The center point of drawing in the noise
	v2f center_of_drawing_in_noise_f = -grid_origin_from_camera_f;
	// The integer center point of drawing in the noise
	v2s16 center_of_drawing_in_noise_i(
		MYROUND(center_of_drawing_in_noise_f.X / grid_size),
		MYROUND(center_of_drawing_in_noise_f.Y / grid_size)
	);
	// The world position of the integer center point of drawing in the noise
	v2f world_center_of_drawing_in_noise_f = v2f(
		center_of_drawing_in_noise_i.X * grid_size,
		center_of_drawing_in_noise_i.Y * grid_size
	) + world_grid_origin_pos_f;

	for(s16 zi=-grid_radius_i; zi<grid_radius_i; zi++)
	for(s16 xi=-grid_radius_i; xi<grid_radius_i; xi++)
	{
		/*// Don't draw very close to player
		s16 dd = 3;
		if(zi > -dd && zi < dd && xi > -dd && xi < dd)
			continue;*/

		v2s16 p_in_noise_i(
			xi+center_of_drawing_in_noise_i.X,
			zi+center_of_drawing_in_noise_i.Y
		);
		
		// If sector was drawn, don't draw it this way
		if(m_client->m_env.getClientMap().sectorWasDrawn(p_in_noise_i))
			continue;

		/*if((p_in_noise_i.X + p_in_noise_i.Y)%2==0)
			continue;*/
		/*if((p_in_noise_i.X/2 + p_in_noise_i.Y/2)%2==0)
			continue;*/

		v2f p0 = v2f(xi,zi)*grid_size + world_center_of_drawing_in_noise_f;
		
		/*double noise[4];
		double d = 100*BS;
		noise[0] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+0)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+0)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[1] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+0)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+1)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[2] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+1)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+1)*grid_size/BS/100,
				m_seed, 3, 0.5);
		
		noise[3] = d*noise2d_perlin(
				(float)(p_in_noise_i.X+1)*grid_size/BS/100,
				(float)(p_in_noise_i.Y+0)*grid_size/BS/100,
				m_seed, 3, 0.5);*/
		
		HeightPoint hps[5];
		hps[0] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+0)*grid_size/BS,
				(p_in_noise_i.Y+0)*grid_size/BS));
		hps[1] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+0)*grid_size/BS,
				(p_in_noise_i.Y+1)*grid_size/BS));
		hps[2] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+1)*grid_size/BS,
				(p_in_noise_i.Y+1)*grid_size/BS));
		hps[3] = ground_height(m_seed, v2s16(
				(p_in_noise_i.X+1)*grid_size/BS,
				(p_in_noise_i.Y+0)*grid_size/BS));
		v2s16 centerpoint(
				(p_in_noise_i.X+0)*grid_size/BS+MAP_BLOCKSIZE/2,
				(p_in_noise_i.Y+0)*grid_size/BS+MAP_BLOCKSIZE/2);
		hps[4] = ground_height(m_seed, centerpoint);
		
		float noise[5];
		float h_min = BS*65535;
		float h_max = -BS*65536;
		float ma_avg = 0;
		float h_avg = 0;
		u32 have_sand_count = 0;
		float tree_amount_avg = 0;
		for(u32 i=0; i<5; i++)
		{
			noise[i] = hps[i].gh + hps[i].ma;
			if(noise[i] < h_min)
				h_min = noise[i];
			if(noise[i] > h_max)
				h_max = noise[i];
			ma_avg += hps[i].ma;
			h_avg += noise[i];
			if(hps[i].have_sand)
				have_sand_count++;
			tree_amount_avg += hps[i].tree_amount;
		}
		ma_avg /= 5.0;
		h_avg /= 5.0;
		tree_amount_avg /= 5.0;

		float steepness = (h_max - h_min)/grid_size;
		
		float light_f = noise[0]+noise[1]-noise[2]-noise[3];
		light_f /= 100;
		if(light_f < -1.0) light_f = -1.0;
		if(light_f > 1.0) light_f = 1.0;
		//light_f += 1.0;
		//light_f /= 2.0;
		
		v2f p1 = p0 + v2f(1,1)*grid_size;
		
		bool ground_is_sand = false;
		bool ground_is_rock = false;
		bool ground_is_mud = false;
		video::SColor c;
		// Detect water
		if(h_avg < WATER_LEVEL*BS && h_max < (WATER_LEVEL+5)*BS)
		{
			//c = video::SColor(255,59,86,146);
			//c = video::SColor(255,82,120,204);
			c = video::SColor(255,74,105,170);

			/*// Set to water level
			for(u32 i=0; i<4; i++)
			{
				if(noise[i] < BS*WATER_LEVEL)
					noise[i] = BS*WATER_LEVEL;
			}*/
			light_f = 0;
		}
		// Steep cliffs
		else if(steepness > 2.0)
		{
			c = video::SColor(255,128,128,128);
			ground_is_rock = true;
		}
		// Basic ground
		else
		{
			if(ma_avg < 2.0*BS)
			{
				c = video::SColor(255,128,128,128);
				ground_is_rock = true;
			}
			else
			{
				if(h_avg <= 2.5*BS && have_sand_count >= 2)
				{
					c = video::SColor(255,210,194,156);
					ground_is_sand = true;
				}
				else
				{
					/*// Trees if there are over 0.01 trees per MapNode
					if(tree_amount_avg > 0.01)
						c = video::SColor(255,50,128,50);
					else
						c = video::SColor(255,107,134,51);*/
					c = video::SColor(255,107,134,51);
					ground_is_mud = true;
				}
			}
		}
		
		// Set to water level
		for(u32 i=0; i<4; i++)
		{
			if(noise[i] < BS*WATER_LEVEL)
				noise[i] = BS*WATER_LEVEL;
		}

		float b = m_brightness + light_f*0.1*m_brightness;
		if(b < 0) b = 0;
		if(b > 2) b = 2;
		
		c = video::SColor(255, b*c.getRed(), b*c.getGreen(), b*c.getBlue());
		
		driver->setMaterial(m_materials[0]);

		video::S3DVertex vertices[4] =
		{
			video::S3DVertex(p0.X,noise[0],p0.Y, 0,0,0, c, 0,1),
			video::S3DVertex(p0.X,noise[1],p1.Y, 0,0,0, c, 1,1),
			video::S3DVertex(p1.X,noise[2],p1.Y, 0,0,0, c, 1,0),
			video::S3DVertex(p1.X,noise[3],p0.Y, 0,0,0, c, 0,0),
		};
		u16 indices[] = {0,1,2,2,3,0};
		driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
				video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);

		// Add some trees if appropriate
		if(tree_amount_avg >= 0.0065 && steepness < 1.4
				&& ground_is_mud == true)
		{
			driver->setMaterial(m_materials[1]);
			
			float b = m_brightness;
			c = video::SColor(255, b*255, b*255, b*255);
			
			{
				video::S3DVertex vertices[4] =
				{
					video::S3DVertex(p0.X,noise[0],p0.Y,
							0,0,0, c, 0,1),
					video::S3DVertex(p0.X,noise[0]+BS*MAP_BLOCKSIZE,p0.Y,
							0,0,0, c, 0,0),
					video::S3DVertex(p1.X,noise[2]+BS*MAP_BLOCKSIZE,p1.Y,
							0,0,0, c, 1,0),
					video::S3DVertex(p1.X,noise[2],p1.Y,
							0,0,0, c, 1,1),
				};
				u16 indices[] = {0,1,2,2,3,0};
				driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
						video::EVT_STANDARD, scene::EPT_TRIANGLES,
						video::EIT_16BIT);
			}
			{
				video::S3DVertex vertices[4] =
				{
					video::S3DVertex(p1.X,noise[3],p0.Y,
							0,0,0, c, 0,1),
					video::S3DVertex(p1.X,noise[3]+BS*MAP_BLOCKSIZE,p0.Y,
							0,0,0, c, 0,0),
					video::S3DVertex(p0.X,noise[1]+BS*MAP_BLOCKSIZE,p1.Y,
							0,0,0, c, 1,0),
					video::S3DVertex(p0.X,noise[1],p1.Y,
							0,0,0, c, 1,1),
				};
				u16 indices[] = {0,1,2,2,3,0};
				driver->drawVertexPrimitiveList(vertices, 4, indices, 2,
						video::EVT_STANDARD, scene::EPT_TRIANGLES,
						video::EIT_16BIT);
			}
		}
	}

	//driver->clearZBuffer();
}
예제 #23
0
static inline Vec2 v2fperp(const Vec2 &p0)
{
    return v2f(-p0.y, p0.x);
}
예제 #24
0
static inline ccVertex2F v2fadd(const ccVertex2F &v0, const ccVertex2F &v1)
{
	return v2f(v0.x+v1.x, v0.y+v1.y);
}
예제 #25
0
static inline Vec2 v2fforangle(float _a_)
{
    return v2f(cosf(_a_), sinf(_a_));
}
예제 #26
0
static inline ccVertex2F v2fsub(const ccVertex2F &v0, const ccVertex2F &v1)
{
	return v2f(v0.x-v1.x, v0.y-v1.y);
}
예제 #27
0
void ParticleSpawner::step(float dtime, ClientEnvironment* env)
{
    m_time += dtime;

    if (m_spawntime != 0) // Spawner exists for a predefined timespan
    {
        for(std::vector<float>::iterator i = m_spawntimes.begin();
                i != m_spawntimes.end();)
        {
            if ((*i) <= m_time && m_amount > 0)
            {
                m_amount--;

                v3f pos = random_v3f(m_minpos, m_maxpos);
                v3f vel = random_v3f(m_minvel, m_maxvel);
                v3f acc = random_v3f(m_minacc, m_maxacc);
                float exptime = rand()/(float)RAND_MAX
                                *(m_maxexptime-m_minexptime)
                                +m_minexptime;
                float size = rand()/(float)RAND_MAX
                             *(m_maxsize-m_minsize)
                             +m_minsize;

                Particle* toadd = new Particle(
                    m_gamedef,
                    m_smgr,
                    m_player,
                    env,
                    pos,
                    vel,
                    acc,
                    exptime,
                    size,
                    m_collisiondetection,
                    m_vertical,
                    m_texture,
                    v2f(0.0, 0.0),
                    v2f(1.0, 1.0));
                m_particlemanager->addParticle(toadd);
                i = m_spawntimes.erase(i);
            }
            else
            {
                i++;
            }
        }
    }
    else // Spawner exists for an infinity timespan, spawn on a per-second base
    {
        for (int i = 0; i <= m_amount; i++)
        {
            if (rand()/(float)RAND_MAX < dtime)
            {
                v3f pos = random_v3f(m_minpos, m_maxpos);
                v3f vel = random_v3f(m_minvel, m_maxvel);
                v3f acc = random_v3f(m_minacc, m_maxacc);
                float exptime = rand()/(float)RAND_MAX
                                *(m_maxexptime-m_minexptime)
                                +m_minexptime;
                float size = rand()/(float)RAND_MAX
                             *(m_maxsize-m_minsize)
                             +m_minsize;

                new Particle(
                    m_gamedef,
                    m_smgr,
                    m_player,
                    env,
                    pos,
                    vel,
                    acc,
                    exptime,
                    size,
                    m_collisiondetection,
                    m_vertical,
                    m_texture,
                    v2f(0.0, 0.0),
                    v2f(1.0, 1.0));
            }
        }
    }
}
예제 #28
0
static inline ccVertex2F v2fmult(const ccVertex2F &v, float s)
{
	return v2f(v.x * s, v.y * s);
}
예제 #29
0
bool QTerrain::Update()
{
	if(isActiveWindow() && ds::Render::GetDevice())
	{
		ds::Render::ClearTarget(ds::Color(0));

		if(Map::Exist())
		{
			QPoint l_Mouse = mapFromGlobal(QCursor::pos());

			if(underMouse())
			{
				Map::SetMousePosition(v2<int>(l_Mouse.x(), l_Mouse.y()));
			}
			else
				m_Hold = false;

			if(m_Hold)
			{
				if(m_Tool)
					m_Tool->OnUpdate(v2<int>(l_Mouse.x() + MapXDiff, l_Mouse.y() + MapYDiff) - Map::GetTransform().GetPosition() - v2f(0.0f, sin(dsDegToRad(ISO_PROJ)) * Map::GetTransform().GetPosition().Y));
			}

			Map::Draw();
		}
	}

	return true;
}
예제 #30
0
/*
	This method generates all the textures
*/
u32 TextureSource::getTextureIdDirect(const std::string &name)
{
	//infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;

	// Empty name means texture 0
	if(name == "")
	{
		infostream<<"getTextureIdDirect(): name is empty"<<std::endl;
		return 0;
	}
	
	/*
		Calling only allowed from main thread
	*/
	if(get_current_thread_id() != m_main_thread)
	{
		errorstream<<"TextureSource::getTextureIdDirect() "
				"called not from main thread"<<std::endl;
		return 0;
	}

	/*
		See if texture already exists
	*/
	{
		JMutexAutoLock lock(m_atlaspointer_cache_mutex);

		core::map<std::string, u32>::Node *n;
		n = m_name_to_id.find(name);
		if(n != NULL)
		{
			/*infostream<<"getTextureIdDirect(): \""<<name
					<<"\" found in cache"<<std::endl;*/
			return n->getValue();
		}
	}

	/*infostream<<"getTextureIdDirect(): \""<<name
			<<"\" NOT found in cache. Creating it."<<std::endl;*/
	
	/*
		Get the base image
	*/

	char separator = '^';

	/*
		This is set to the id of the base image.
		If left 0, there is no base image and a completely new image
		is made.
	*/
	u32 base_image_id = 0;
	
	// Find last meta separator in name
	s32 last_separator_position = -1;
	for(s32 i=name.size()-1; i>=0; i--)
	{
		if(name[i] == separator)
		{
			last_separator_position = i;
			break;
		}
	}
	/*
		If separator was found, construct the base name and make the
		base image using a recursive call
	*/
	std::string base_image_name;
	if(last_separator_position != -1)
	{
		// Construct base name
		base_image_name = name.substr(0, last_separator_position);
		/*infostream<<"getTextureIdDirect(): Calling itself recursively"
				" to get base image of \""<<name<<"\" = \""
                <<base_image_name<<"\""<<std::endl;*/
		base_image_id = getTextureIdDirect(base_image_name);
	}
	
	//infostream<<"base_image_id="<<base_image_id<<std::endl;
	
	video::IVideoDriver* driver = m_device->getVideoDriver();
	assert(driver);

	video::ITexture *t = NULL;

	/*
		An image will be built from files and then converted into a texture.
	*/
	video::IImage *baseimg = NULL;
	
	// If a base image was found, copy it to baseimg
	if(base_image_id != 0)
	{
		JMutexAutoLock lock(m_atlaspointer_cache_mutex);

		SourceAtlasPointer ap = m_atlaspointer_cache[base_image_id];

		video::IImage *image = ap.atlas_img;
		
		if(image == NULL)
		{
			infostream<<"getTextureIdDirect(): WARNING: NULL image in "
					<<"cache: \""<<base_image_name<<"\""
					<<std::endl;
		}
		else
		{
			core::dimension2d<u32> dim = ap.intsize;

			baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);

			core::position2d<s32> pos_to(0,0);
			core::position2d<s32> pos_from = ap.intpos;
			
			image->copyTo(
					baseimg, // target
					v2s32(0,0), // position in target
					core::rect<s32>(pos_from, dim) // from
			);

			/*infostream<<"getTextureIdDirect(): Loaded \""
					<<base_image_name<<"\" from image cache"
					<<std::endl;*/
		}
	}
	
	/*
		Parse out the last part of the name of the image and act
		according to it
	*/

	std::string last_part_of_name = name.substr(last_separator_position+1);
	//infostream<<"last_part_of_name=\""<<last_part_of_name<<"\""<<std::endl;

	// Generate image according to part of name
	if(!generate_image(last_part_of_name, baseimg, m_device, &m_sourcecache))
	{
		errorstream<<"getTextureIdDirect(): "
				"failed to generate \""<<last_part_of_name<<"\""
				<<std::endl;
	}

	// If no resulting image, print a warning
	if(baseimg == NULL)
	{
		errorstream<<"getTextureIdDirect(): baseimg is NULL (attempted to"
				" create texture \""<<name<<"\""<<std::endl;
	}
	
	if(baseimg != NULL)
	{
		// Create texture from resulting image
		t = driver->addTexture(name.c_str(), baseimg);
	}
	
	/*
		Add texture to caches (add NULL textures too)
	*/

	JMutexAutoLock lock(m_atlaspointer_cache_mutex);
	
	u32 id = m_atlaspointer_cache.size();
	AtlasPointer ap(id);
	ap.atlas = t;
	ap.pos = v2f(0,0);
	ap.size = v2f(1,1);
	ap.tiled = 0;
	core::dimension2d<u32> baseimg_dim(0,0);
	if(baseimg)
		baseimg_dim = baseimg->getDimension();
	SourceAtlasPointer nap(name, ap, baseimg, v2s32(0,0), baseimg_dim);
	m_atlaspointer_cache.push_back(nap);
	m_name_to_id.insert(name, id);

	/*infostream<<"getTextureIdDirect(): "
			<<"Returning id="<<id<<" for name \""<<name<<"\""<<std::endl;*/
	
	return id;
}