Exemplo n.º 1
0
scene::scene() :
	m_file_name(std::string(""))
{
	unsigned long successful_blocks = 0;

	block_tree_node_t root_node;
	root_node.node_name = "blocks";
	root_node.node_path = "./blocks";
	m_block_classification = root_node;

	log() << aspect << "Loading default Prawn blocks." << std::endl;
	load_default_blocks (m_block_classification, successful_blocks);
	log() << aspect << "Successfully loaded " << successful_blocks << " blocks." << std::endl;

	new_scene();
}
Exemplo n.º 2
0
scene::scene(i_system_functions* SystemFunctions, general_options& prefs, const std::string block_path) :
        m_system_functions (SystemFunctions),
    preferences(prefs)
{
	log() << aspect << "scene: constructor" << std::endl;

	unsigned long successful_blocks = 0;

	block_tree_node_t root_node;
	root_node.node_name = "blocks";
        root_node.node_path = block_path;
	m_block_classification = root_node;

	log() << aspect << "Loading default Shrimp blocks." << std::endl;
	load_default_blocks (m_block_classification, successful_blocks);
	log() << aspect << "Successfully loaded " << successful_blocks << " blocks." << std::endl;

	new_scene();
}
Exemplo n.º 3
0
void scene::load_default_blocks (block_tree_node_t& RootNode, unsigned long& BlockCount) {

	// read directory content
	dirent** block_files;
	const int file_count = fltk::filename_list (RootNode.node_path.c_str(), &block_files);

	// skip empty directories
	if (file_count < 0) {
		log() << error << "tried to load blocks from empty directory '" << RootNode.node_path << "'." << std::endl;
		return;
	}

	// scan directory
	typedef std::vector<std::string> names_t;
	names_t file_paths;
	names_t files;
	names_t block_paths;

	shader_block_builder builder;
	int successful_block_count = 0;
	for (int f = 0; f < file_count; ++f) {

		const std::string file = std::string (block_files[f]->d_name);
		const std::string file_path = RootNode.node_path + "/" + file;
		if (fltk::filename_isdir (file_path.c_str())) {

			if (file[0] == '.') {
				// skip default directories
			}
			else {
				// save directory
				file_paths.push_back (file_path);
				files.push_back (file);
			}
		}
		else {
			const char* extension = fltk::filename_ext (file.c_str());
			if (std::string (extension) == ".xml") {

				// save XML file
				block_paths.push_back (file_path);
			}
		}

		free (block_files[f]);
	}

	free (block_files);

	// process subdirectories
	names_t::iterator path_i = file_paths.begin();
	names_t::iterator file_i = files.begin();
	for (; path_i != file_paths.end(); ++path_i, ++file_i) {

		block_tree_node_t sub_node;
		sub_node.node_name = *file_i;
		sub_node.node_path = RootNode.node_path + "/" + *file_i;
		RootNode.child_nodes.push_back (sub_node);

		// load blocks from the subdirectory
		load_default_blocks (RootNode.child_nodes.back(), BlockCount);
	}

	// process blocks
	for (names_t::iterator path_i = block_paths.begin(); path_i != block_paths.end(); ++path_i) {

		// try loading the block
		shader_block* new_block = builder.build_block (*path_i);
		if (new_block) {

			successful_block_count++;

			if (m_default_blocks.find (new_block->name()) != m_default_blocks.end()) {

				// duplicate name
				log() << error << "couldn't load " << *path_i << " : a block named '" << new_block->name() << "' already exists." << std::endl;
			}
			else {

				default_block_t block_info;
				block_info.name = new_block->name();
				block_info.path = *path_i;
				m_default_blocks.insert (std::make_pair (new_block->name(), block_info));
				++BlockCount;

				// save block
				RootNode.blocks.push_back (block_info);
			}
		}
		else {
			log() << error << "couldn't load " << *path_i << std::endl;
		}
	}

	log() << aspect << " loaded " << RootNode.blocks.size() << " blocks from " << RootNode.node_path << std::endl;
}
Exemplo n.º 4
0
void scene::load_default_blocks (block_tree_node_t& RootNode, unsigned long& BlockCount)
{
	// read directory content
	std::vector<std::string> directory_content = m_system_functions->list_directory(RootNode.node_path);

	// skip empty directories
	if (directory_content.size() == 0)
	{
		log() << error << "tried to load blocks from empty directory '" << RootNode.node_path << "'." << std::endl;
		return;
	}

	// scan directory
	typedef std::vector<std::string> names_t;
	names_t file_paths;
	names_t files;
	names_t block_paths;

	shader_block_builder builder;
	int successful_block_count = 0;
	for (unsigned int f = 0; f < directory_content.size(); ++f)
	{
		const std::string file = directory_content[f];
		const std::string file_path = m_system_functions->combine_paths (RootNode.node_path, file);
		if (m_system_functions->is_directory (file_path))
		{
			if (file[0] == '.')
			{
				// skip default directories
			}
			else
			{
				// save directory
				file_paths.push_back (file_path);
				files.push_back (file);
			}
		}
		else
		{
			const std::string extension = m_system_functions->get_file_extension (file);
                        if (extension == "xml")
			{
				// save XML file
				block_paths.push_back (file_path);
			}
		}
	}

	// process subdirectories
	names_t::iterator path_i = file_paths.begin();
	names_t::iterator file_i = files.begin();
	for (; path_i != file_paths.end(); ++path_i, ++file_i) {

		block_tree_node_t sub_node;
		sub_node.node_name = *file_i;
		sub_node.node_path = RootNode.node_path + "/" + *file_i;
		RootNode.child_nodes.push_back (sub_node);

		// load blocks from the subdirectory
		load_default_blocks (RootNode.child_nodes.back(), BlockCount);
	}

	// process blocks
	for (names_t::iterator path_i = block_paths.begin(); path_i != block_paths.end(); ++path_i) {

		// try loading the block
		shader_block* new_block = builder.build_block (*path_i);
		if (new_block) {

			successful_block_count++;

			if (m_default_blocks.find (new_block->name()) != m_default_blocks.end()) {

				// duplicate name
				log() << error << "couldn't load " << *path_i << " : a block named '" << new_block->name() << "' already exists." << std::endl;
			}
			else {

				default_block_t block_info;
				block_info.name = new_block->name();
				block_info.path = *path_i;
				m_default_blocks.insert (std::make_pair (new_block->name(), block_info));
				++BlockCount;

				// save block
				RootNode.blocks.push_back (block_info);
			}
		}
		else {
			log() << error << "couldn't load " << *path_i << std::endl;
		}
	}

	log() << aspect << " loaded " << RootNode.blocks.size() << " blocks from " << RootNode.node_path << std::endl;
}