//構築したルールを音声認識エンジンにコミットします。 xreturn::r<bool> JuliusPlus::CommitRule() { if (! this->IsNeedUpdateRule ) {//アップデートする必要なし return true; } //マイクから入力用 std::ofstream dfa("__temp__regexp_test.dfa"); std::ofstream dict("__temp__regexp_test.dict"); this->MakeJuliusRule(this->Grammer,false, &dfa,&dict); //ディクテーションフィルター用 std::ofstream dfaFile("__temp__regexp_test_file.dfa"); std::ofstream dictFile("__temp__regexp_test_file.dict"); this->MakeJuliusRule(this->YobikakeRuleHandle,true,&dfaFile,&dictFile); this->JuliusStop(); this->JuliusFileStart(); this->JuliusStart(); //アップデートが終わったので再びルールに変更が加わるまではアップデートしない。 this->IsNeedUpdateRule = false; return true; }
const std::vector<Texture> &TextureManager::getTextures( const std::string &filename, const std::string &paletteName) { // This method deals with animations and movies, so it will check filenames // for ".CFA", ".CIF", ".DFA", ".FLC", ".SET", etc.. // Use this name when interfacing with the texture sets map. const std::string fullName = filename + paletteName; // See if the file has already been loaded with the palette. auto setIter = this->textureSets.find(fullName); if (setIter != this->textureSets.end()) { // The requested texture set exists. return setIter->second; } // Do not use a built-in palette for texture sets. Debug::check(!this->paletteIsBuiltIn(paletteName), "Texture Manager", "Image sets (i.e., .SET files) do not have built-in palettes."); // See if the palette hasn't already been loaded. if (this->palettes.find(paletteName) == this->palettes.end()) { this->loadPalette(paletteName); } // The file hasn't been loaded with the palette yet, so make a new entry. auto iter = this->textureSets.emplace(std::make_pair( fullName, std::vector<Texture>())).first; std::vector<Texture> &textureSet = iter->second; const Palette &palette = this->palettes.at(paletteName); const std::string extension = String::getExtension(filename); const bool isCFA = extension.compare(".CFA") == 0; const bool isCIF = extension.compare(".CIF") == 0; const bool isCEL = extension.compare(".CEL") == 0; const bool isDFA = extension.compare(".DFA") == 0; const bool isFLC = extension.compare(".FLC") == 0; const bool isRCI = extension.compare(".RCI") == 0; const bool isSET = extension.compare(".SET") == 0; if (isCFA) { // Load the CFA file. CFAFile cfaFile(filename, palette); // Create an SDL_Texture for each image in the CFA. const int imageCount = cfaFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, cfaFile.getWidth(), cfaFile.getHeight()); const uint32_t *pixels = cfaFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, cfaFile.getWidth() * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else if (isCIF) { // Load the CIF file. CIFFile cifFile(filename, palette); // Create an SDL_Texture for each image in the CIF. const int imageCount = cifFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, cifFile.getWidth(i), cifFile.getHeight(i)); const uint32_t *pixels = cifFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, cifFile.getWidth(i) * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else if (isDFA) { // Load the DFA file. DFAFile dfaFile(filename, palette); // Create an SDL_Texture for each image in the DFA. const int imageCount = dfaFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, dfaFile.getWidth(), dfaFile.getHeight()); const uint32_t *pixels = dfaFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, dfaFile.getWidth() * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else if (isFLC || isCEL) { // Load the FLC file. CELs are basically identical to FLCs. FLCFile flcFile(filename); // Create an SDL_Texture for each frame in the FLC. const int imageCount = flcFile.getFrameCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, flcFile.getWidth(), flcFile.getHeight()); const uint32_t *pixels = flcFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, flcFile.getWidth() * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else if (isRCI) { // Load the RCI file. RCIFile rciFile(filename, palette); // Create an SDL_Texture for each image in the RCI. const int imageCount = rciFile.getCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, RCIFile::FRAME_WIDTH, RCIFile::FRAME_HEIGHT); const uint32_t *pixels = rciFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, RCIFile::FRAME_WIDTH * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else if (isSET) { // Load the SET file. SETFile setFile(filename, palette); // Create an SDL_Texture for each image in the SET. const int imageCount = setFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { SDL_Texture *texture = this->renderer.createTexture( Renderer::DEFAULT_PIXELFORMAT, SDL_TEXTUREACCESS_STATIC, SETFile::CHUNK_WIDTH, SETFile::CHUNK_HEIGHT); const uint32_t *pixels = setFile.getPixels(i); SDL_UpdateTexture(texture, nullptr, pixels, SETFile::CHUNK_WIDTH * sizeof(*pixels)); textureSet.push_back(Texture(texture)); } } else { Debug::crash("Texture Manager", "Unrecognized texture list \"" + filename + "\"."); } // Set alpha transparency on for each texture. for (auto &texture : textureSet) { SDL_SetTextureBlendMode(texture.get(), SDL_BLENDMODE_BLEND); } return textureSet; }
const std::vector<SDL_Surface*> &TextureManager::getSurfaces( const std::string &filename, const std::string &paletteName) { // This method deals with animations and movies, so it will check filenames // for ".CFA", ".CIF", ".DFA", ".FLC", ".SET", etc.. // Use this name when interfacing with the surface sets map. const std::string fullName = filename + paletteName; // See if the file has already been loaded with the palette. auto setIter = this->surfaceSets.find(fullName); if (setIter != this->surfaceSets.end()) { // The requested texture set exists. return setIter->second; } // Do not use a built-in palette for surface sets. Debug::check(!this->paletteIsBuiltIn(paletteName), "Texture Manager", "Image sets (i.e., .SET files) do not have built-in palettes."); // See if the palette hasn't already been loaded. if (this->palettes.find(paletteName) == this->palettes.end()) { this->loadPalette(paletteName); } // The file hasn't been loaded with the palette yet, so make a new entry. auto iter = this->surfaceSets.emplace(std::make_pair( fullName, std::vector<SDL_Surface*>())).first; std::vector<SDL_Surface*> &surfaceSet = iter->second; const Palette &palette = this->palettes.at(paletteName); const std::string extension = String::getExtension(filename); const bool isCFA = extension.compare(".CFA") == 0; const bool isCIF = extension.compare(".CIF") == 0; const bool isCEL = extension.compare(".CEL") == 0; const bool isDFA = extension.compare(".DFA") == 0; const bool isFLC = extension.compare(".FLC") == 0; const bool isRCI = extension.compare(".RCI") == 0; const bool isSET = extension.compare(".SET") == 0; if (isCFA) { // Load the CFA file. CFAFile cfaFile(filename, palette); // Create an SDL_Surface for each image in the CFA. const int imageCount = cfaFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = cfaFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( cfaFile.getWidth(), cfaFile.getHeight(), Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else if (isCIF) { // Load the CIF file. CIFFile cifFile(filename, palette); // Create an SDL_Surface for each image in the CIF. const int imageCount = cifFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = cifFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( cifFile.getWidth(i), cifFile.getHeight(i), Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else if (isDFA) { // Load the DFA file. DFAFile dfaFile(filename, palette); // Create an SDL_Surface for each image in the DFA. const int imageCount = dfaFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = dfaFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( dfaFile.getWidth(), dfaFile.getHeight(), Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else if (isFLC || isCEL) { // Load the FLC file. CELs are basically identical to FLCs. FLCFile flcFile(filename); // Create an SDL_Surface for each frame in the FLC. const int imageCount = flcFile.getFrameCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = flcFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( flcFile.getWidth(), flcFile.getHeight(), Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else if (isRCI) { // Load the RCI file. RCIFile rciFile(filename, palette); // Create an SDL_Surface for each image in the RCI. const int imageCount = rciFile.getCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = rciFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( RCIFile::FRAME_WIDTH, RCIFile::FRAME_HEIGHT, Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else if (isSET) { // Load the SET file. SETFile setFile(filename, palette); // Create an SDL_Surface for each image in the SET. const int imageCount = setFile.getImageCount(); for (int i = 0; i < imageCount; ++i) { uint32_t *pixels = setFile.getPixels(i); SDL_Surface *surface = Surface::createSurfaceWithFormat( SETFile::CHUNK_WIDTH, SETFile::CHUNK_HEIGHT, Renderer::DEFAULT_BPP, Renderer::DEFAULT_PIXELFORMAT); SDL_memcpy(surface->pixels, pixels, surface->pitch * surface->h); surfaceSet.push_back(surface); } } else { Debug::crash("Texture Manager", "Unrecognized surface list \"" + filename + "\"."); } return surfaceSet; }