RegionPtr Session::create_region_from_node(TiXmlElement* element){ assert(element); TiXmlElement * basicInfoElement = element->FirstChildElement("BasicInfo"); assert(basicInfoElement); int start = 0; basicInfoElement->QueryIntAttribute("start", &start); int duration = 0; basicInfoElement->QueryIntAttribute("duration", &duration); int offset = 0; basicInfoElement->QueryIntAttribute("offset", &offset); int lanenum = 0; basicInfoElement->QueryIntAttribute("lanenum", &lanenum); int extension = 0; basicInfoElement->QueryIntAttribute("extension", &extension); int reverseState =0; basicInfoElement->QueryIntAttribute("reversestate",&reverseState); int muteState = 0; basicInfoElement->QueryIntAttribute("mutestate",&muteState); std::string path = basicInfoElement->Attribute("path"); fsom::DebugStream << "Loading, working directory = "<< m_workingDirectory<<std::endl; regionCreationStruct cs(start, duration,offset,lanenum,extension, path,m_workingDirectory,bool(reverseState)); TiXmlElement * meta = element->FirstChildElement("MetaData"); RegionPtr pRegion = RegionManager::get_instance().create(meta->Attribute("RegionType"),cs); pRegion->set_mute_state(muteState); assert(pRegion); load_region_parameters(element,pRegion.get()); pRegion->register_meta("RegionType"); pRegion->register_meta("Tip"); pRegion->set_meta("RegionType", meta->Attribute("RegionType")); pRegion->set_meta("Tip", meta->Attribute("Tip")); std::string image = meta->Attribute("image"); std::string managerId = meta->Attribute("managerId"); pRegion->register_meta("image"); pRegion->register_meta("managerId"); pRegion->set_meta("image",image); pRegion->set_meta("managerId",managerId); fsom::DebugStream << "Metadata read, image = " <<image<<std::endl; TiXmlElement * effectChild = element->FirstChildElement("Effect"); while(effectChild){ DSPEffectPtr e = create_effect_from_node(effectChild,pRegion.get()); pRegion->attach_effect(e); effectChild = effectChild->NextSiblingElement("Effect"); } fsom::DebugStream << "Loaded region:" << path << std::endl; if(pRegion->get_meta("RegionType") == std::string("AdditiveSynthesis")){ fsom::DebugStream << "Synthesis region found"<<std::endl; SynthesisRegionPtr synthregion = boost::dynamic_pointer_cast<fsom::SynthesisRegion>(pRegion); //Remove the automatic generators synthregion->remove_all_generators(); //remove the automatic modules synthregion->remove_all_modules(); TiXmlElement* generatorElement = element->FirstChildElement("Generator"); while(generatorElement){ GeneratorPtr gen = create_generator_from_node(generatorElement,pRegion.get()); synthregion->add_generatorPtr(gen); generatorElement = generatorElement->NextSiblingElement("Generator"); } fsom::DebugStream << "No of generators spawned = "<< synthregion->get_generator_stack().size()<<std::endl; TiXmlElement* moduleElement = element->FirstChildElement("Module"); while(moduleElement){ SynthesisModulePtr mod = create_module_from_node(moduleElement,pRegion.get()); synthregion->add_modulePtr(mod); moduleElement = moduleElement->NextSiblingElement("Module"); } // pRegion = synthregion; }else if(pRegion->get_meta("RegionType")==std::string("GranularSynthesis") ){ boost::shared_ptr<fsom::GranularRegion> gran_region = boost::dynamic_pointer_cast<fsom::GranularRegion>(pRegion); if(!path.empty()){ gran_region->load_soundfile( m_workingDirectory + path ); }else{ gran_region->fill_table_sin(); } } return RegionPtr(pRegion); }
void BiomeView::drawChunk(int a_ChunkX, int a_ChunkZ) { if (!hasData()) { return; } // Fetch the region: int regionX; int regionZ; Region::chunkToRegion(a_ChunkX, a_ChunkZ, regionX, regionZ); RegionPtr region = m_Cache.fetch(regionX, regionZ); // Figure out where on the screen this chunk should be drawn: // first find the center chunk int centerchunkx = floor(m_X / 16); int centerchunkz = floor(m_Z / 16); // and the center chunk screen coordinates int centerx = m_Image.width() / 2; int centery = m_Image.height() / 2; // which need to be shifted to account for panning inside that chunk centerx -= (m_X - centerchunkx * 16) * m_Zoom; centery -= (m_Z - centerchunkz * 16) * m_Zoom; // centerx,y now points to the top left corner of the center chunk // so now calculate our x,y in relation double chunksize = 16 * m_Zoom; centerx += (a_ChunkX - centerchunkx) * chunksize; centery += (a_ChunkZ - centerchunkz) * chunksize; uchar * bits = m_Image.bits(); int imgstride = m_Image.bytesPerLine(); int skipx = 0, skipy = 0; int blockwidth = chunksize, blockheight = chunksize; // now if we're off the screen we need to crop if (centerx < 0) { skipx = -centerx; centerx = 0; } if (centery < 0) { skipy = -centery; centery = 0; } // or the other side, we need to trim if (centerx + blockwidth > m_Image.width()) { blockwidth = m_Image.width() - centerx; } if (centery + blockheight > m_Image.height()) { blockheight = m_Image.height() - centery; } if ((blockwidth <= 0) || (skipx >= blockwidth)) { return; } int imgoffset = centerx * 4 + centery * imgstride; // If the chunk is valid, use its data; otherwise use the empty placeholder: const short * src = m_EmptyChunkBiomes; if (region.get() != nullptr) { int relChunkX = a_ChunkX - regionX * 32; int relChunkZ = a_ChunkZ - regionZ * 32; Chunk & chunk = region->getRelChunk(relChunkX, relChunkZ); if (chunk.isValid()) { src = chunk.getBiomes(); } } // Scale-blit the image: for (int z = skipy; z < blockheight; z++, imgoffset += imgstride) { size_t srcoffset = static_cast<size_t>(std::floor((double)z / m_Zoom)) * 16; int imgxoffset = imgoffset; for (int x = skipx; x < blockwidth; x++) { short biome = src[srcoffset + static_cast<size_t>(std::floor((double)x / m_Zoom))]; const uchar * color; if (biome < 0) { static const uchar emptyBiome1[] = { 0x44, 0x44, 0x44, 0xff }; static const uchar emptyBiome2[] = { 0x88, 0x88, 0x88, 0xff }; color = ((x & 8) ^ (z & 8)) ? emptyBiome1 : emptyBiome2; } else { if (biome * 4 >= ARRAYCOUNT(biomeToColor)) { static const uchar errorImage[] = { 0xff, 0x00, 0x00, 0xff }; color = errorImage; } else { color = biomeToColor + biome * 4; } } bits[imgxoffset] = color[0]; bits[imgxoffset + 1] = color[1]; bits[imgxoffset + 2] = color[2]; bits[imgxoffset + 3] = color[3]; imgxoffset += 4; } // for x } // for z }