Mercurial > otakunoraifu
diff scn2k/scn2k_grp.cc @ 53:ddbcbd000206
* MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
* ParseMoji moved to TextStream
* Some cleaning (0 -> NULL when needed, removal of useless returns, ...)
author | thib |
---|---|
date | Sun, 19 Apr 2009 11:44:05 +0000 |
parents | 15a18fbe6f21 |
children | d7cde171a1de |
line wrap: on
line diff
--- a/scn2k/scn2k_grp.cc +++ b/scn2k/scn2k_grp.cc @@ -101,7 +101,6 @@ struct GrpObj { void SetClipArea(int x, int y, int width, int height); void GetSrcGeom(int& width, int& height); void SetUpdate(void); - TextStream ParseMoji(const char* str, int def_r ,int def_g, int def_b, int def_size); void UpdateMoji(void); void UpdateDigit(void); void UpdateSurface(void); @@ -177,15 +176,15 @@ class GrpImpl { Surface* Ssurface(int pdt); // cgmode 用画像処理関連 - void LoadCgm(AyuSysConfig& config); + void LoadCgm(void); std::map<std::string, int> cgm_info; set<int>& cgm_data; int cgm_size; - class MuSys& music; + class MuSys *music; public: - AyuSysConfig& config; + AyuSysConfig *config; void LoadSurface(const char* str, int pdt); private: @@ -199,11 +198,11 @@ class GrpImpl { static bool Pressed(int x, int y, void* pointer); public: - GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& _flag, set<int>& _cgm_data, class MuSys& mu, AyuSysConfig& config); + GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& _flag, set<int>& _cgm_data); ~GrpImpl(); bool Wait(unsigned int current_time, Cmd& cmd); void Exec(Cmd& cmd); - void InitSel(AyuSysConfig& config); + void InitSel(void); void Save(std::string& str); void Load(const char* str); void SaveSys(std::string& str); @@ -313,7 +312,7 @@ void GrpObj::GetSrcGeom(int& width, int& /* g00 ファイルのヘッダ部分に位置情報は入っている */ string path(name); path += ".g00"; - ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, path.c_str(), "g00"); + ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::PDT, path.c_str(), "g00"); if (info == NULL) { // ファイルが見つからない fprintf(stderr, "GrpObj::GetSrcGeom : Cannot find file %s\n", path.c_str()); return; @@ -453,85 +452,6 @@ void GrpObj::ZoomRotate(void) { pic_parent->Root().DeleteSurface(surface_orig); } -static char* wstrchr(const char* s, unsigned int chr) { - int ws, wc; - while(*s != 0) { - if (*s < 0 && s[1] != 0) { - wc = int((unsigned char)(s[0]))*0x100 + int((unsigned char)(s[1])); - ws = 2; - } else { - wc = (unsigned char)(s[0]); - ws = 1; - } - if (wc == chr) return (char*)s; - s += ws; - } - return NULL; -} - -//TODO: See why it does nothing with font/text_stream.cc:98 -TextStream GrpObj::ParseMoji(const char* str, int def_r ,int def_g, int def_b, int def_size) { // 制御シーケンス付き文字列をparse - TextStream ts; - ts.kanji_type = TextStream::sjis; - ts.SetColor(def_r, def_g, def_b); - char* copy_str = new char[strlen(str)+1]; - char* next_str; - char* retptr; - int var; - - while( (next_str = wstrchr(str, '#')) != NULL) { - int len = next_str - str; - strncpy(copy_str, str, len); - copy_str[len] = 0; - ts.Add(copy_str); - str = next_str + 1; - - switch(str[0]) { - case '#': // separator - str += 1; - break; - case 'D': case 'd': // return - ts.AddReturn(); - str += 1; - break; - case 'C': case 'c': // color - str += 1; - var = strtol(str, &next_str,10); - if (var == 0 && str == next_str) { // no parameter - ts.SetColor(def_r, def_g, def_b); - } else { - int r,g,b; char key[1024]; - sprintf(key, "#COLOR_TABLE.%03d", var); - if (parent_pimpl->config.GetParam(key, 3, &r, &g, &b)) { // color not found - r = g = b = 0; - } - ts.SetColor(r, g, b); - str = next_str; - } - break; - case 'S': case 's': // size - str += 1; - var = strtol(str, &next_str, 10); - if (var == 0 && str == next_str) { // no parameter - ts.SetSize(1); - } else { - if (def_size == 0) def_size = 20; - if (var <= 0) var = 1; - ts.SetSize(double(var)/def_size); - } - break; - case 'X': case 'x': // xpos : not supported - case 'Y': case 'y': // ypos : not supported - default: - ts.Add("#"); - break; - } - } - ts.Add(str); - delete[] copy_str; - return ts; -} - void GrpObj::UpdateMoji(void) { // 文字の大きさ、色などを変更 if (print_moji.length() == 0 || print_size <= 2) return; if (pic_parent == 0) return; @@ -544,7 +464,7 @@ void GrpObj::UpdateMoji(void) { // 文字の大きさ、色などを変更 g = print_g; b = print_b; } - TextStream ts = ParseMoji(print_moji.c_str(), r, g, b, print_size); + TextStream ts = TextStream::ParseMoji(print_moji.c_str(), r, g, b, print_size); TextGlyphStream gs; vector<int> lh; // とりあえず drawable width は充分に大きく(2048)取る @@ -646,7 +566,7 @@ void GrpObj::CreateGan(Event::Container& /* アニーメション情報 (.GAN ファイル)を求める */ string path(gan_name); path += ".gan"; - ARCINFO* info = file_searcher.Find(FILESEARCH::GAN, path.c_str(), "gan"); + ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::GAN, path.c_str(), "gan"); if (info == NULL) { fprintf(stderr,"GrpObj::CreateGan: Cannot Find 'GAN' file %s\n", path.c_str()); return; @@ -826,23 +746,25 @@ void ScnGrpAnm::Exec(int count) { #include "music2/music.h" -GrpImpl::GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& f, set<int>& _cgm_data, class MuSys& _mu, AyuSysConfig& _config) : +GrpImpl::GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& f, set<int>& _cgm_data): event(_event), flags(f), parent(_parent), status(NORMAL), skip_mode(SKIP_NO), - music(_mu), cgm_data(_cgm_data), grpobj(this), - bs_obj(this), - config(_config) + bs_obj(this) { int i; for (i=0; i<MAXPDT; i++) { ssurface[i] = 0; dsurface[i] = 0; } + + music = MuSys::GetInstance(); + config = AyuSysConfig::GetInstance(); + screen = parent.create_leaf(Rect(0, 0, parent.Width(), parent.Height()), 0); screen_front = parent.create_leaf(Rect(0, 0, parent.Width(), parent.Height()), 0); surface = parent.Root().NewSurface(parent.Width(), parent.Height(), NO_MASK); @@ -854,9 +776,10 @@ GrpImpl::GrpImpl(Event::Container& _even screen_front->hide(); screen_front->ZMove(screen); - LoadCgm(config); + LoadCgm(); - anm1 = 0; anm2 = 0; + anm1 = NULL; + anm2 = NULL; } GrpImpl::~GrpImpl() { @@ -931,22 +854,21 @@ void GrpImpl::LoadSurface(const char* st if (str[0] != 0) fprintf(stderr,"Cannot find surface %d <- '%s'\n",pdt,str); } - return; } -void GrpImpl::InitSel(AyuSysConfig& config) { +void GrpImpl::InitSel(void) { int i; int args[16]; char key[1024]; for (i=0; i<999; i++) { sprintf(key, "#SEL.%03d",i); - if (config.GetParam(key, 15, &args[0], &args[1], + if (config->GetParam(key, 15, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7], &args[8], &args[9], &args[10], &args[11], &args[12], &args[13], &args[14])) { sprintf(key, "#SELR.%03d", i); - if (config.GetParam(key, 16, &args[0], &args[1], + if (config->GetParam(key, 16, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5], &args[6], &args[7], &args[8], &args[9], &args[10], &args[11], &args[12], &args[13], &args[14], &args[15])) continue; @@ -1255,7 +1177,7 @@ void GrpImpl::SwapObj(int index1, int in bool GrpImpl::Pressed(int x, int y, void* pointer) { // マウスクリックでキャンセル GrpImpl* g = (GrpImpl*)pointer; if (g->status == WAIT_MOVIE) - g->music.StopMovie(); + g->music->StopMovie(); if (g->status == WAIT_ANM) g->AbortAnm(); if (g->status == WAIT_SHAKE && g->anm2 != NULL) { @@ -1302,11 +1224,11 @@ static unsigned char decode_char[256] = 0xff, 0x00, 0x00, 0x04, 0x00, 0x6a, 0x00, 0x76 }; -void GrpImpl::LoadCgm(AyuSysConfig& config) { +void GrpImpl::LoadCgm() { /* cgm ファイル読み込み */ - const char* fname = config.GetParaStr("#CGTABLE_FILE"); + const char* fname = config->GetParaStr("#CGTABLE_FILE"); if (fname == NULL) return; - ARCINFO* info = file_searcher.Find(FILESEARCH::ALL, fname, ""); + ARCINFO* info = FileSearcher::GetInstance()->Find(FileSearcher::ALL, fname, ""); if (info == NULL) return; char* data = info->CopyRead(); int sz = info->Size(); @@ -1366,7 +1288,7 @@ void GrpImpl::Load(const char* str) { grpobj.clear(); bg_name = ""; - music.StopCDROM(100); + music->StopCDROM(100); } void GrpImpl::SaveSys(string& save) { @@ -1487,11 +1409,11 @@ bool GrpImpl::Wait(unsigned int current_ } status = NORMAL; } else if (status == WAIT_SE) { - if (music.IsStopSE()) status = NORMAL; + if (music->IsStopSE()) status = NORMAL; return true; } else if (status == WAIT_MOVIE) { - if (music.IsStopMovie()) { - music.StopMovie(); + if (music->IsStopMovie()) { + music->StopMovie(); status = NORMAL; screen->ReBlit(); } @@ -1529,7 +1451,7 @@ void GrpImpl::DeleteObjRange(int num_fir void GrpImpl::Exec(Cmd& cmd) { if (cmd.cmd_type == CMD_TEXTEND) { - music.StopKoe(500); // テキスト終了で声を止める + music->StopKoe(500); // テキスト終了で声を止める cmd.clear(); return; } @@ -1604,12 +1526,12 @@ void GrpImpl::Exec(Cmd& cmd) { // shake screen char key[1024]; sprintf(key, "#SHAKE.%03d", cmd.args[0].value); - if (config.SearchParam(key) != 2) { + if (config->SearchParam(key) != 2) { fprintf(stderr,"Cannot find shake pattern %d; use default pattern\n",cmd.args[0].value); strcpy(key, "#SHAKE.000"); // default key } int num; const int* pattern; - pattern = config.GetParamArray(key, num); + pattern = config->GetParamArray(key, num); if (pattern) { StartShake(num, pattern); status = WAIT_SHAKE; @@ -2092,7 +2014,7 @@ 487 / 8047 : unsupported command; 0x23 - /* 前景色を得る */ int cr,cg,cb; char key[1024]; sprintf(key, "#COLOR_TABLE.%03d", cmd.args[5].value); - if (config.GetParam(key, 3, &cr, &cg, &cb)) { // color not found + if (config->GetParam(key, 3, &cr, &cg, &cb)) { // color not found cr = cg = cb = 0; } g.print_r = cr; @@ -2213,26 +2135,26 @@ 487 / 8047 : unsupported command; 0x23 - if (cmd.cmd1 == 1 && cmd.cmd2 == 0x14) { if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { eprintf("play bgm %s\n",cmd.Str(cmd.args[0])); - music.PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000); + music->PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000); cmd.cmd_type = CMD_SAVECMD_ONCE; } if (cmd.cmd3 == 2 && (cmd.cmd4 == 2 || cmd.cmd4 == 0) ) { /* ??? : ことみシナリオラストの音楽再生 */ eprintf("play bgm %s\n",cmd.Str(cmd.args[0])); - music.PlayCDROM( (char*)cmd.Str(cmd.args[0]), 1); + music->PlayCDROM( (char*)cmd.Str(cmd.args[0]), 1); cmd.cmd_type = CMD_SAVECMD_ONCE; } if (cmd.cmd3 == 0 && cmd.cmd4 == 2) { eprintf("fade bgm %d? and play bgm %s; %d\n",cmd.args[1].value, cmd.Str(cmd.args[0]), cmd.args[2].value); - // music.PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000, cmd.args[2].value); - music.PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000); + // music->PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000, cmd.args[2].value); + music->PlayCDROM( (char*)cmd.Str(cmd.args[0]), 10000); cmd.cmd_type = CMD_SAVECMD_ONCE; } if ( (cmd.cmd3 == 5 || cmd.cmd3 == 0x69) && cmd.cmd4 == 0) { if (cmd.cmd3 == 5) { - music.StopCDROM(0); + music->StopCDROM(0); eprintf("stop bgm\n"); } else { - music.StopCDROM(cmd.args[0].value); + music->StopCDROM(cmd.args[0].value); eprintf("fade bgm %d\n",cmd.args[0].value); } cmd.cmd_type = CMD_SAVECMD_ONCE; @@ -2242,44 +2164,44 @@ 487 / 8047 : unsupported command; 0x23 - if ((cmd.cmd3 == 2) || (cmd.cmd3 == 0 && (cmd.cmd4 == 1 || cmd.cmd4 == 2)) || (cmd.cmd3 == 0 && cmd.cmd4 == 0)) { eprintf("play SE %s\n",cmd.Str(cmd.args[0])); if (cmd.cmd3 == 2) { - music.PlaySE(cmd.Str(cmd.args[0]),1); + music->PlaySE(cmd.Str(cmd.args[0]),1); cmd.cmd_type = CMD_SAVECMD_ONCE; } else { - music.PlaySE(cmd.Str(cmd.args[0])); + music->PlaySE(cmd.Str(cmd.args[0])); cmd.clear(); } } else if (cmd.cmd3 == 5) { eprintf("Stop SE\n"); - music.StopSE(); + music->StopSE(); cmd.cmd_type = CMD_SAVECMD_ONCE; } else if (cmd.cmd3 == 0x69) { eprintf("Stop SE with fade %d\n",cmd.args[0].value); - music.StopSE(cmd.args[0].value); + music->StopSE(cmd.args[0].value); cmd.cmd_type = CMD_SAVECMD_ONCE; } } if (cmd.cmd1 == 1 && cmd.cmd2 == 4 && (cmd.cmd3 == 0x4bb || cmd.cmd3 == 0x4bc) ) { // 音楽を待ってみる(絶対に違うが)。本来、04-803 に対応してなにかの終わりをwaitするっぽい(風子/智代Ed付近) // EnableSyscom らしいが、よくわからない (rldev) -// if (!music.IsStopSE()) status = WAIT_SE; +// if (!music->IsStopSE()) status = WAIT_SE; cmd.clear(); } // 音楽モードで音量を上げるためのコマンド (SetBgmVolume) // とりあえず未実装 if (cmd.cmd1 == 1 && cmd.cmd2 == 4 && cmd.cmd3 >= 0x8b6 && cmd.cmd3 <= 0x8b9) { // Set{Bgm,Koe,PCM,Se}VolMod - music.volmod[cmd.cmd3-0x8b6] = cmd.args[0].value; - config.SetParam("#VOLMOD", 4, music.volmod[0], music.volmod[1], music.volmod[2], music.volmod[3]); + music->volmod[cmd.cmd3-0x8b6] = cmd.args[0].value; + config->SetParam("#VOLMOD", 4, music->volmod[0], music->volmod[1], music->volmod[2], music->volmod[3]); cmd.clear(); } if (cmd.cmd1 == 1 && cmd.cmd2 == 4 && cmd.cmd3 >= 0x91a && cmd.cmd3 <= 0x91d) { // Get{Bgm,Koe,PCM,Se}VolMod - cmd.SetSysvar(music.volmod[cmd.cmd3-0x91a]); + cmd.SetSysvar(music->volmod[cmd.cmd3-0x91a]); } if (cmd.cmd1 == 1 && cmd.cmd2 == 0x16) { if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { eprintf("play SE %d\n",cmd.args[0].value); - music.PlaySE(cmd.args[0].value); + music->PlaySE(cmd.args[0].value); cmd.clear(); } } @@ -2291,7 +2213,7 @@ 487 / 8047 : unsupported command; 0x23 - } eprintf("\n"); char buf[1024]; sprintf(buf, "%d",cmd.args[0].value); - if ( !(skip_mode & SKIP_TEXT)) music.PlayKoe(buf); + if ( !(skip_mode & SKIP_TEXT)) music->PlayKoe(buf); cmd.clear(); } } @@ -2303,7 +2225,7 @@ 487 / 8047 : unsupported command; 0x23 - int x2 = cmd.args[3].value; int y2 = cmd.args[4].value; eprintf("play movie ; name %s pos %d,%d - %d,%d\n",str,x,y,x2,y2); - music.PlayMovie(str, x, y, x2, y2,1); + music->PlayMovie(str, x, y, x2, y2,1); status = WAIT_MOVIE; event.RegisterGlobalPressFunc(&Pressed, (void*)this); cmd.clear(); @@ -2318,8 +2240,8 @@ 487 / 8047 : unsupported command; 0x23 - ** class Grp */ -Grp::Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, set<int>& _cgm,class MuSys& mu, AyuSysConfig& config) { - pimpl = new GrpImpl(_event, _parent, f, _cgm, mu, config); +Grp::Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, set<int>& _cgm) { + pimpl = new GrpImpl(_event, _parent, f, _cgm); } Grp::~Grp() { @@ -2338,8 +2260,8 @@ void Grp::SetSkipMode(SkipMode mode) { pimpl->SetSkipMode(mode); } -void Grp::InitSel(AyuSysConfig& config) { - pimpl->InitSel(config); +void Grp::InitSel(void) { + pimpl->InitSel(); } void Grp::Save(std::string& str) {