# HG changeset patch # User thib # Date 1240079739 0 # Node ID 15a18fbe6f212ec96a2ebc8c2fa7baf3d8894a21 # Parent cbb301016a4ee559f90a4ea48589e54dd9b1d32a * Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...) diff --git a/README b/README --- a/README +++ b/README @@ -62,3 +62,15 @@ In-game keys: ALT+ENTER, F11: Toggle fullscreen + + +Known bugs: +----------- + +* The stack state is inconsistent in some saves. So, DO NOT SAVE RIGHT + AFTER A SCENE IN THE ILUSIONARY WORLD. Just read one more dialog before + saving. + +* You cannot change your name yet (the text input boxes are not implemented yet) + + diff --git a/font/codeconv.cc b/font/codeconv.cc --- a/font/codeconv.cc +++ b/font/codeconv.cc @@ -28,157 +28,147 @@ #include "codeconv.h" #include "codeconv_tbl.h" -static unsigned int -codeconv_euc_to_jis(unsigned int euc) +unsigned int codeconv_euc_to_jis(unsigned int euc) { - unsigned int hi, low; + unsigned int hi, low; - hi = (euc >> 8) & 0xff; - low = euc & 0xff; + hi = (euc >> 8) & 0xff; + low = euc & 0xff; - if (hi < 0x81) { - hi = 0; - } else if (low == 0x8e) - hi = 0; - else { - hi -= 0x80; - low -= 0x80; - } + if (hi < 0x81) { + hi = 0; + } else if (low == 0x8e) + hi = 0; + else { + hi -= 0x80; + low -= 0x80; + } - return (hi << 8) | low; + return (hi << 8) | low; } -static unsigned int -codeconv_jis_to_unicode(unsigned int jis) +static unsigned int codeconv_jis_to_unicode(unsigned int jis) { - int k0, k1; + int k0, k1; + + if (jis < 0x80) return jis; // ASCII + + k0 = (jis >> 8) - 0x20; - if (jis < 0x80) return jis; // ASCII - k0 = (jis >> 8) - 0x20; - if (k0 < 1 || k0 > 92) - return 0; + if (k0 < 1 || k0 > 92) + return 0; - k1 = (jis % 0x100) - 0x20; - if (k1 < 1 || k1 > 94) - return 0; + k1 = (jis % 0x100) - 0x20; + if (k1 < 1 || k1 > 94) + return 0; - return unicode_tbl[k0 - 1][k1 - 1]; + return unicode_tbl[k0 - 1][k1 - 1]; } -unsigned int -codeconv_euc_to_unicode(unsigned int euc) +unsigned int codeconv_euc_to_unicode(unsigned int euc) { - unsigned int jis, unicode; + unsigned int jis, unicode; - jis = codeconv_euc_to_jis(euc); - unicode = codeconv_jis_to_unicode(jis); + jis = codeconv_euc_to_jis(euc); + unicode = codeconv_jis_to_unicode(jis); - return unicode; + return unicode; } -static unsigned int -codeconv_unicode_to_jis(unsigned int unicode) +static unsigned int codeconv_unicode_to_jis(unsigned int unicode) { - int k0, k1; - unsigned int jis; + int k0, k1; + unsigned int jis; - k0 = (unicode >> 8) & 0xff; - k1 = unicode & 0xff; - jis = unicode_rev_table[k0][k1]; - - return jis; + k0 = (unicode >> 8) & 0xff; + k1 = unicode & 0xff; + jis = unicode_rev_table[k0][k1]; + + return jis; } -static unsigned int -codeconv_jis_to_euc(unsigned int jis) +static unsigned int codeconv_jis_to_euc(unsigned int jis) { - unsigned int hi, low; + unsigned int hi, low; - hi = (jis >> 8) & 0x7f | 0x80; - low = jis & 0x7f | 0x80; + hi = (jis >> 8) & 0x7f | 0x80; + low = jis & 0x7f | 0x80; - return (hi << 8) | low; + return (hi << 8) | low; } -unsigned int -codeconv_unicode_to_euc(unsigned int unicode) +unsigned int codeconv_unicode_to_euc(unsigned int unicode) { - unsigned int jis, euc; + unsigned int jis, euc; + + if (unicode >= 0xff61 && unicode <= 0xff9f) + return unicode - 0xff61 + 0x8ea1; - if (unicode >= 0xff61 && unicode <= 0xff9f) - return unicode - 0xff61 + 0x8ea1; + jis = codeconv_unicode_to_jis(unicode); + if (jis == 0) + return 0x7878; + euc = codeconv_jis_to_euc(jis); - jis = codeconv_unicode_to_jis(unicode); - if (jis == 0) - return 0x7878; - euc = codeconv_jis_to_euc(jis); - - return euc; + return euc; } -static unsigned int -codeconv_jis_to_sjis(unsigned int jis) +static unsigned int codeconv_jis_to_sjis(unsigned int jis) { - unsigned int hi, low; + unsigned int hi, low; - hi = (jis >> 8) & 0xff; - low = jis & 0xff; + hi = (jis >> 8) & 0xff; + low = jis & 0xff; - low += (hi & 0x01) ? 0x1f : 0x7d; - if (low >= 0x7f) - low++; - hi = ((hi - 0x21) >> 1) + 0x81; - if (hi > 0x9f) - hi += 0x40; + low += (hi & 0x01) ? 0x1f : 0x7d; + if (low >= 0x7f) + low++; + hi = ((hi - 0x21) >> 1) + 0x81; + if (hi > 0x9f) + hi += 0x40; - return (hi << 8) | low; + return (hi << 8) | low; } -unsigned int -codeconv_euc_to_sjis(unsigned int euc) +unsigned int codeconv_euc_to_sjis(unsigned int euc) { - unsigned int jis, sjis; + unsigned int jis, sjis; - jis = codeconv_euc_to_jis(euc); - sjis = codeconv_jis_to_sjis(jis); + jis = codeconv_euc_to_jis(euc); + sjis = codeconv_jis_to_sjis(jis); - return sjis; + return sjis; } -static unsigned int -codeconv_sjis_to_jis(unsigned int sjis) +static unsigned int codeconv_sjis_to_jis(unsigned int sjis) { - unsigned int hi, low; + unsigned int hi, low; - hi = (sjis >> 8) & 0xff; - low = sjis & 0xff; + hi = (sjis >> 8) & 0xff; + low = sjis & 0xff; - hi -= (hi <= 0x9f) ? 0x71 : 0xb1; - hi = (hi << 1) + 1; - if (low > 0x7f) - low--; - if (low >= 0x9e) { - low -= 0x7d; - hi++; - } else - low -= 0x1f; - - return (hi << 8) | low; + hi -= (hi <= 0x9f) ? 0x71 : 0xb1; + hi = (hi << 1) + 1; + if (low > 0x7f) + low--; + if (low >= 0x9e) { + low -= 0x7d; + hi++; + } else low -= 0x1f; + + return (hi << 8) | low; } -unsigned int -codeconv_sjis_to_euc(unsigned int sjis) +unsigned int codeconv_sjis_to_euc(unsigned int sjis) { - unsigned int jis, euc; + unsigned int jis, euc; - jis = codeconv_sjis_to_jis(sjis); - euc = codeconv_jis_to_euc(jis); + jis = codeconv_sjis_to_jis(sjis); + euc = codeconv_jis_to_euc(jis); - return euc; + return euc; } -unsigned int -codeconv_euc_to_latin1(unsigned int euc) +unsigned int codeconv_euc_to_latin1(unsigned int euc) { int high = (euc>>8) & 0xff; if (high) return 0; diff --git a/font/codeconv.h b/font/codeconv.h --- a/font/codeconv.h +++ b/font/codeconv.h @@ -40,6 +40,8 @@ unsigned int codeconv_unicode_to_euc(uns unsigned int codeconv_euc_to_sjis(unsigned int); unsigned int codeconv_sjis_to_euc(unsigned int); +unsigned int codeconv_euc_to_jis(unsigned int); + #ifdef __cplusplus } #endif diff --git a/font/font.h b/font/font.h --- a/font/font.h +++ b/font/font.h @@ -7,12 +7,12 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -33,81 +33,85 @@ # include "config.h" #endif -#include +#include class TextHorizLayout; class TextStream; class TextGlyphStream; namespace XKFont { -class Font; -class Face; -class Peer; -class Glyph; -class Cache; + class Font; + class Face; + class Peer; + class Glyph; + class Cache; -struct Font { -public: - Font(const char* fontname, int size); - ~Font(); - Face* FaceLoad(double scale); - int vsize; -private: - class FontImpl* pimpl; -}; + struct Font { + public: + Font(const char* fontname, int size); + ~Font(); + Face* FaceLoad(double scale); + int vsize; + private: + class FontImpl* pimpl; + }; -struct Face { -public: - Face(const char *name, int index, int hsize, int vsize); - ~Face(); - Glyph* GlyphLoad(unsigned int code); + struct Face { + public: + Face(const char *name, int index, int hsize, int vsize); + ~Face(); + Glyph* GlyphLoad(unsigned int code); -private: - Cache* cache; - typedef std::vector::iterator iterator; - std::vector peer; -}; + private: + Cache* cache; + typedef std::vector::iterator iterator; + std::vector peer; + }; -struct Peer { - Peer(void) {} - virtual ~Peer() {}; - virtual bool GlyphCreate(unsigned int code, Glyph* glyph) = 0; -}; + struct Peer { + public: + Peer(void) {} + virtual ~Peer() {}; + virtual bool GlyphCreate(unsigned int code, Glyph* glyph) = 0; + }; -struct Glyph { - int bitmap_left; - int bitmap_top; - struct _bitmap { - int width; - int rows; - unsigned char *buffer; - _bitmap() : buffer(0) {} - ~_bitmap() { delete[] buffer;} - } bitmap; + struct Glyph { + public: + struct _bitmap { + int width; + int rows; + unsigned char *buffer; + _bitmap() : buffer(0) {} + ~_bitmap() { delete[] buffer;} + } bitmap; #if 0 - struct _metrics { - int ascender; - int descender; - } metrics; + struct _metrics { + int ascender; + int descender; + } metrics; #endif - struct _advance { - int x; - int y; - } advance; - Glyph() : bitmap() {} - ~Glyph() {} -}; + struct _advance { + int x; + int y; + } advance; + + Glyph() : bitmap() {} + ~Glyph() {} + int bitmap_left; + int bitmap_top; + }; -struct HorizLayout { - HorizLayout(const char* fontname, int size); - ~HorizLayout(); - void Layout(::TextStream& stream, ::TextGlyphStream& glyph, std::vector& lineheights, int width); - ::TextGlyphStream Layout(const char* str, int width, int r=0xff, int g=0xff, int b=0xff); -private: - Font* font; - class ::TextHorizLayout* pimpl; -}; + struct HorizLayout { + public: + HorizLayout(const char* fontname, int size); + ~HorizLayout(); + void Layout(::TextStream& stream, ::TextGlyphStream& glyph, std::vector& lineheights, int width); + ::TextGlyphStream Layout(const char* str, int width, int r=0xff, int g=0xff, int b=0xff); + private: + Font* font; + class ::TextHorizLayout* pimpl; + }; -}; /* end of namespace XKFont */ +} /* end of namespace XKFont */ #endif diff --git a/font/font_face.cc b/font/font_face.cc --- a/font/font_face.cc +++ b/font/font_face.cc @@ -27,135 +27,135 @@ #include #include -#include"font.h" -#include"font_peer.h" +#include "font.h" +#include "font_peer.h" #include #include #include namespace XKFont { -class Cache : public std::map { -public: - Cache() {} - ~Cache() { - iterator it; - for (it = begin(); it != end(); it++) - delete (it->second); + class Cache : public std::map { + public: + Cache() {} + ~Cache() { + iterator it; + for (it = begin(); it != end(); it++) + delete (it->second); + } + }; + + Face::Face(const char *name_orig, int index, int hsize, int vsize) + { + cache = new Cache; + + /* name: ';' 区切りで複数指定可能 */ + char* name = new char[strlen(name_orig)+1]; + while(*name_orig != 0) { + const char* next_name = strchr(name_orig, ';'); + if (next_name) { + strncpy(name, name_orig, next_name - name_orig); + name[next_name-name_orig] = 0; + name_orig = next_name + 1; + } else { + strcpy(name, name_orig); + name_orig += strlen(name_orig); + } + if (strstr(name, "fn.dat")) { + peer.push_back(new PeerFn(name, index, hsize, vsize)); + } else if (strstr(name, ".ttf") || strstr(name, ".ttc")) { + peer.push_back(new PeerFt2(name, index, hsize, vsize)); +#if USE_X11 + } else { + peer.push_back(new PeerX11(name, index, hsize, vsize)); +#endif + } + } + delete[] name; + return; } -}; -Face::Face(const char *name_orig, int index, int hsize, int vsize) -{ - cache = new Cache; + Face::~Face() { + delete cache; + } + + Glyph* Face::GlyphLoad(unsigned int code) { + if (cache->count(code)) + return (*cache)[code]; - /* name: ';' 区切りで複数指定可能 */ - char* name = new char[strlen(name_orig)+1]; - while(*name_orig != 0) { - const char* next_name = strchr(name_orig, ';'); - if (next_name) { - strncpy(name, name_orig, next_name - name_orig); - name[next_name-name_orig] = 0; - name_orig = next_name + 1; - } else { - strcpy(name, name_orig); - name_orig += strlen(name_orig); + Glyph* g = new Glyph; + iterator it; + for (it=peer.begin(); it != peer.end(); it++) { + if ( (*it)->GlyphCreate(code, g)) break; + } + if (it == peer.end()) { + fprintf(stderr,"Cannot find glyph, code %04x\n",code); + g->bitmap_left = 0; + g->bitmap_top = 0; + g->bitmap.width = 0; + g->bitmap.rows = 0; + g->bitmap.buffer = new unsigned char[1]; + g->bitmap.buffer[0] = 0; + g->advance.x = 0; + g->advance.y = 0; } - if (strstr(name, "fn.dat")) { - peer.push_back(new PeerFn(name, index, hsize, vsize)); - } else if (strstr(name, ".ttf") || strstr(name, ".ttc")) { - peer.push_back(new PeerFt2(name, index, hsize, vsize)); -#if USE_X11 - } else { - peer.push_back(new PeerX11(name, index, hsize, vsize)); -#endif + (*cache)[code] = g; + return g; + } + + class FontImpl { + public: + std::map cache; + std::string fontname; + int size; + ~FontImpl(); + }; + + FontImpl::~FontImpl() { + std::map::iterator it; + for (it=cache.begin(); it!=cache.end(); it++) delete it->second; + } + + Font::Font(const char* name, int size) { + pimpl = new FontImpl; + pimpl->fontname = name; + pimpl->size = size; + vsize = size; + }; + + Font::~Font() { + delete pimpl; + } + + Face* Font::FaceLoad(double scale) { + std::map& cache = pimpl->cache; + int size = int(scale * pimpl->size); + if (cache.find(size) != cache.end()) return cache[size]; + try { + Face* face = new Face(pimpl->fontname.c_str(), 0, size, size); + cache[size] = face; + return face; + } catch(...) { + std::cerr << "Cannot create font face; font "<fontname<<", size "<fontname.c_str(), 0, size-i, size-i); + cache[size-i] = face; + return face; + } catch(...) {}; + try { + Face* face = new Face(pimpl->fontname.c_str(), 0, size+i, size+i); + cache[size+i] = face; + return face; + } catch(...) {}; + } + /* 見つからない */ + throw; } } - delete[] name; - return; -} - -Face::~Face() { - delete cache; -} - -Glyph* -Face::GlyphLoad(unsigned int code) { - if (cache->count(code)) - return (*cache)[code]; - - Glyph* g = new Glyph; - iterator it; - for (it=peer.begin(); it != peer.end(); it++) { - if ( (*it)->GlyphCreate(code, g)) break; - } - if (it == peer.end()) { - fprintf(stderr,"Cannot find glyph, code %04x\n",code); - g->bitmap_left = 0; - g->bitmap_top = 0; - g->bitmap.width = 0; - g->bitmap.rows = 0; - g->bitmap.buffer = new unsigned char[1]; - g->bitmap.buffer[0] = 0; - g->advance.x = 0; - g->advance.y = 0; - } - (*cache)[code] = g; - return g; -} - -class FontImpl { -public: - std::map cache; - std::string fontname; - int size; - ~FontImpl(); -}; - -FontImpl::~FontImpl() { - std::map::iterator it; - for (it=cache.begin(); it!=cache.end(); it++) delete it->second; -} - -Font::Font(const char* name, int size) { - pimpl = new FontImpl; - pimpl->fontname = name; - pimpl->size = size; - vsize = size; -}; -Font::~Font() { - delete pimpl; -} -Face* -Font::FaceLoad(double scale) { - std::map& cache = pimpl->cache; - int size = int(scale * pimpl->size); - if (cache.find(size) != cache.end()) return cache[size]; - try { - Face* face = new Face(pimpl->fontname.c_str(), 0, size, size); - cache[size] = face; - return face; - } catch(...) { - std::cerr << "Cannot create font face; font "<fontname<<", size "<fontname.c_str(), 0, size-i, size-i); - cache[size-i] = face; - return face; - } catch(...) {}; - try { - Face* face = new Face(pimpl->fontname.c_str(), 0, size+i, size+i); - cache[size+i] = face; - return face; - } catch(...) {}; - } - /* 見つからない */ - throw; - } -} } /* namespace XKFont */ diff --git a/font/font_layout.cc b/font/font_layout.cc --- a/font/font_layout.cc +++ b/font/font_layout.cc @@ -28,14 +28,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include +#include +#include +#include using namespace std; -#include"font.h" -#include"text.h" +#include "font.h" +#include "text.h" const int line_skip = 1; // 行と行の間の間隔 const int ruby_textskip = 0; // 文字とルビの間の間隔 @@ -78,28 +78,29 @@ inline int Kinsoku(int code) { } class TextGlyphStreamHelper { - typedef TextStream::Iterator Iterator; - typedef TextGlyphStream::iterator iterator; + private: + typedef TextStream::Iterator Iterator; + typedef TextGlyphStream::iterator iterator; - TextGlyphStream* data; + TextGlyphStream* data; - // information for rendering - unsigned char r, g, b; - XKFont::Face* face; - XKFont::Face* ruby_face; - XKFont::Font* font; + // information for rendering + unsigned char r, g, b; + XKFont::Face* face; + XKFont::Face* ruby_face; + XKFont::Font* font; -public: - int min_lineheight; - TextGlyphStreamHelper(XKFont::Font* font); - // helper functions - void Init(TextGlyphStream* data); - Iterator Add(int& x, Iterator begin, Iterator end, int max_x = 0); - Iterator AddRuby(int& x, Iterator begin, Iterator end); - int CharWidth(int code); - void SetGroup(iterator begin, iterator end); - void CalcHeight(int& ascent, int& descent, iterator begin, iterator end); - void AdjustPosition(int xstart_add, int xend_add, int y_add, iterator begin, iterator end); + public: + int min_lineheight; + TextGlyphStreamHelper(XKFont::Font* font); + // helper functions + void Init(TextGlyphStream* data); + Iterator Add(int& x, Iterator begin, Iterator end, int max_x = 0); + Iterator AddRuby(int& x, Iterator begin, Iterator end); + int CharWidth(int code); + void SetGroup(iterator begin, iterator end); + void CalcHeight(int& ascent, int& descent, iterator begin, iterator end); + void AdjustPosition(int xstart_add, int xend_add, int y_add, iterator begin, iterator end); }; TextGlyphStreamHelper::TextGlyphStreamHelper(XKFont::Font* __font) { @@ -492,28 +493,29 @@ void TextHorizLayout::MakeLine(int line_ namespace XKFont { -HorizLayout::HorizLayout(const char* fontname, int size) { - font = new Font(fontname, size); - pimpl = new ::TextHorizLayout(font); -} + HorizLayout::HorizLayout(const char* fontname, int size) { + font = new Font(fontname, size); + pimpl = new ::TextHorizLayout(font); + } -HorizLayout::~HorizLayout() { - delete pimpl; - delete font; -} + HorizLayout::~HorizLayout() { + delete pimpl; + delete font; + } -void HorizLayout::Layout(TextStream& stream, TextGlyphStream& glyph, vector& lineheights, int width) { - pimpl->Layout(stream, glyph, lineheights, width); -}; -TextGlyphStream HorizLayout::Layout(const char* str, int width, int r, int gc, int b) { - TextStream s; - s.SetColor(r,gc,b); - s.Add(str); - TextGlyphStream g; - vector h; - Layout(s, g, h, width); - return g; -} + void HorizLayout::Layout(TextStream& stream, TextGlyphStream& glyph, vector& lineheights, int width) { + pimpl->Layout(stream, glyph, lineheights, width); + }; + + TextGlyphStream HorizLayout::Layout(const char* str, int width, int r, int gc, int b) { + TextStream s; + s.SetColor(r,gc,b); + s.Add(str); + TextGlyphStream g; + vector h; + Layout(s, g, h, width); + return g; + } }; diff --git a/font/font_peer.h b/font/font_peer.h --- a/font/font_peer.h +++ b/font/font_peer.h @@ -6,12 +6,12 @@ * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. + * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -32,14 +32,14 @@ namespace XKFont { -class PeerFn : public Peer { -public: - PeerFn(const char* name, int index, int hsize, int vsize); - ~PeerFn(); - bool GlyphCreate(unsigned int code, Glyph* g); -private: - unsigned char *buffer; -}; + class PeerFn : public Peer { + public: + PeerFn(const char* name, int index, int hsize, int vsize); + ~PeerFn(); + bool GlyphCreate(unsigned int code, Glyph* g); + private: + unsigned char *buffer; + }; } @@ -47,16 +47,18 @@ private: #include FT_FREETYPE_H namespace XKFont { -typedef unsigned int (*FontCodeConverter)(unsigned int); -class PeerFt2 : public Peer { -public: - PeerFt2(const char *name, int index, int hsize, int vsize); - ~PeerFt2(); - bool GlyphCreate(unsigned int code, Glyph* glyph); -private: - FT_Face face; - FontCodeConverter conv_func; -}; + + typedef unsigned int (*FontCodeConverter)(unsigned int); + + class PeerFt2 : public Peer { + public: + PeerFt2(const char *name, int index, int hsize, int vsize); + ~PeerFt2(); + bool GlyphCreate(unsigned int code, Glyph* glyph); + private: + FT_Face face; + FontCodeConverter conv_func; + }; } @@ -65,28 +67,28 @@ private: #include namespace XKFont { -class PeerX11 : public Peer { -public: - PeerX11(const char *name, int index, int hsize, int vsize); - ~PeerX11(); - bool GlyphCreate(unsigned int code, Glyph* g); - static void InitDisplay(Display*); - static void OpenDisplay(void); -private: - static Display* display; + class PeerX11 : public Peer { + public: + PeerX11(const char *name, int index, int hsize, int vsize); + ~PeerX11(); + bool GlyphCreate(unsigned int code, Glyph* g); + static void InitDisplay(Display*); + static void OpenDisplay(void); + private: + static Display* display; - XFontSet fontset; - GC gc; - Visual* visual; - unsigned long white, black; - Pixmap canvas; - XShmSegmentInfo x_shm_info; - bool use_shm; - XImage* image; - int width, height, ascent; - int mask, shift; - int* colortable; -}; + XFontSet fontset; + GC gc; + Visual* visual; + unsigned long white, black; + Pixmap canvas; + XShmSegmentInfo x_shm_info; + bool use_shm; + XImage* image; + int width, height, ascent; + int mask, shift; + int* colortable; + }; }; /* namespace XKFont */ #endif /* USE_X11 */ diff --git a/font/font_peer_fn.cc b/font/font_peer_fn.cc --- a/font/font_peer_fn.cc +++ b/font/font_peer_fn.cc @@ -34,6 +34,7 @@ using namespace std; +#include "codeconv.h" #include "font.h" #include "font_peer.h" @@ -43,20 +44,20 @@ namespace XKFont { PeerFn::PeerFn(const char *name, int index, int hsize, int vsize) : buffer(0) { - FILE *fp = 0; + FILE *fp = 0; - buffer = new unsigned char[FN_DAT_SIZE]; - fp = fopen(name, "rb"); - if (!fp) { - delete[] buffer; - buffer = 0; - string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name; - throw std::invalid_argument(err); - } - fread(buffer, 1, FN_DAT_SIZE, fp); - fclose(fp); - - return; + buffer = new unsigned char[FN_DAT_SIZE]; + fp = fopen(name, "rb"); + if (!fp) { + delete[] buffer; + buffer = 0; + string err = string("XKFont::PeerFn::PeerFn : Cannot open font file ")+name; + throw std::invalid_argument(err); + } + fread(buffer, 1, FN_DAT_SIZE, fp); + fclose(fp); + + return; } @@ -64,67 +65,48 @@ PeerFn::~PeerFn() { delete[] buffer; } -static unsigned int -font_glyph_fn_codeconv_euc_to_jis(unsigned int euc) -{ - unsigned int h, l; - - h = (euc >> 8) & 0xff; - l = euc & 0xff; - - if (h < 0x81) { - l = h; - h = 0; - } else if (l == 0x8e) - h = 0; - else { - h -= 0x80; - l -= 0x80; - } - - return (h << 8) | l; -} - bool PeerFn::GlyphCreate(unsigned int code, Glyph* glyph) { - unsigned char *p1, *p2; - unsigned int h, l, offset; - int x, y; + unsigned char *p1, *p2; + unsigned int h, l, offset; + int x, y; - l = font_glyph_fn_codeconv_euc_to_jis(code); - l -= 0x2121; - h = l >> 8; - l &= 0xff; - offset = (h * 0x5e + l) * 12 * 24; - if (offset > FN_DAT_SIZE - 12 * 24) - offset = 0; + l = codeconv_euc_to_jis(code); + l -= 0x2121; + h = l >> 8; + l &= 0xff; + offset = (h * 0x5e + l) * 12 * 24; + if (offset > FN_DAT_SIZE - 12 * 24) + offset = 0; - glyph->bitmap_left = 0; - glyph->bitmap_top = 21; - glyph->bitmap.width = 24; - glyph->bitmap.rows = 24; + glyph->bitmap_left = 0; + glyph->bitmap_top = 21; + glyph->bitmap.width = 24; + glyph->bitmap.rows = 24; #if 0 - glyph->metrics.ascender = private->vsize - 4; - glyph->metrics.descender = -4; + glyph->metrics.ascender = private->vsize - 4; + glyph->metrics.descender = -4; #endif - glyph->advance.x = 24 + 1; - glyph->advance.y = 24 + 1; + glyph->advance.x = 24 + 1; + glyph->advance.y = 24 + 1; - glyph->bitmap.buffer = new unsigned char[24*24]; + glyph->bitmap.buffer = new unsigned char[24*24]; - p1 = glyph->bitmap.buffer; - p2 = buffer + offset; - for (y = 0; y < 24; y++) { - for (x = 0; x < 12; x++) { - unsigned char c = ~*p2++; - unsigned char c1; - c1 = (c) & 0x0f; *p1++ = (c1<<4) | c1; - c1 = (c>>4)& 0x0f; *p1++ = (c1<<4) | c1; - } - } - return true; + p1 = glyph->bitmap.buffer; + p2 = buffer + offset; + for (y = 0; y < 24; y++) { + for (x = 0; x < 12; x++) { + unsigned char c = ~*p2++; + unsigned char c1; + c1 = (c) & 0x0f; + *p1++ = (c1<<4) | c1; + c1 = (c>>4)& 0x0f; + *p1++ = (c1<<4) | c1; + } + } + return true; } } /* end of namespace XKFont */ diff --git a/font/font_peer_ft2.cc b/font/font_peer_ft2.cc --- a/font/font_peer_ft2.cc +++ b/font/font_peer_ft2.cc @@ -41,10 +41,10 @@ using namespace std; namespace XKFont { typedef struct _FontLibrary { - FT_Library super; - int ref_count; - char **paths; - int num_paths; + FT_Library super; + int ref_count; + char **paths; + int num_paths; } FontLibrary; static FontLibrary *library = NULL; @@ -64,87 +64,79 @@ static void font_library_ft2_remove_path static void font_library_ft2_add_path(const char *path); static char *font_library_ft2_build_path(const char *base, const char *name); -static int -font_library_ft2_alloc() +static int font_library_ft2_alloc() { - int i; - - if (!library) { - library = (FontLibrary*) calloc(sizeof(FontLibrary), 1); - if (library) { - if (FT_Init_FreeType(&library->super)) - goto _1; - fprintf(stderr, "XKFont::font_library_ft2_alloc : FreeType allocated successfully.\n"); - for (i = 0; default_paths[i]; i++) - font_library_ft2_add_path(default_paths[i]); - } - } + int i; - library->ref_count++; - return 1; + if (!library) { + library = (FontLibrary*) calloc(sizeof(FontLibrary), 1); + if (library) { + if (FT_Init_FreeType(&library->super)) { + free(library); + library = NULL; + fprintf(stderr, "XKFont::font_library_ft2_alloc: Couldn't allocate FreeType.\n"); + return 0; + } + fprintf(stderr, "XKFont::font_library_ft2_alloc : FreeType allocated successfully.\n"); + for (i = 0; default_paths[i]; i++) + font_library_ft2_add_path(default_paths[i]); + } + } - _1: - free(library); - library = NULL; - fprintf(stderr, "XKFont::font_library_ft2_alloc: Couldn't allocate FreeType.\n"); - return 0; + library->ref_count++; + return 1; } -static void -font_library_ft2_free() +static void font_library_ft2_free() { - int i; - - if (!library || library->ref_count <= 0) - return; - if (--library->ref_count == 0) { - FT_Done_FreeType(library->super); - for (i = 0; i < library->num_paths; i++) - free(library->paths[i]); - free(library->paths); - free(library); - library = NULL; - fprintf(stderr, "XKFont::font_library_ft2_free : FreeType done.\n"); - } + int i; + + if (!library || library->ref_count <= 0) + return; + if (--library->ref_count == 0) { + FT_Done_FreeType(library->super); + for (i = 0; i < library->num_paths; i++) + free(library->paths[i]); + free(library->paths); + free(library); + library = NULL; + fprintf(stderr, "XKFont::font_library_ft2_free : FreeType done.\n"); + } } -static void -font_library_ft2_add_path(const char *path) +static void font_library_ft2_add_path(const char *path) { - library->num_paths++; - if (!library->paths) - library->paths = (char**) malloc(sizeof(char *)); - else - library->paths = (char**) realloc( (void*)library->paths, - library->num_paths * sizeof(char *)); - library->paths[library->num_paths - 1] = strdup(path); + library->num_paths++; + if (!library->paths) + library->paths = (char**) malloc(sizeof(char *)); + else + library->paths = (char**) realloc( (void*)library->paths, library->num_paths * sizeof(char *)); + library->paths[library->num_paths - 1] = strdup(path); } -static void -font_library_ft2_remove_path(const char *path) +static void font_library_ft2_remove_path(const char *path) { - int i, j; + int i, j; - for (i = 0; i < library->num_paths; i++) { - if (!strcmp(path, library->paths[i])) { - library->num_paths--; - for (j = i; j < library->num_paths; j++) - library->paths[j] = library->paths[j + 1]; - if (library->num_paths > 0) - library->paths = (char**) realloc(library->paths, - library->num_paths * sizeof(char *)); - else { - free(library->paths); - library->paths = NULL; - } - } - } + for (i = 0; i < library->num_paths; i++) { + if (!strcmp(path, library->paths[i])) { + library->num_paths--; + for (j = i; j < library->num_paths; j++) + library->paths[j] = library->paths[j + 1]; + if (library->num_paths > 0) + library->paths = (char**) realloc(library->paths, library->num_paths * sizeof(char *)); + else { + free(library->paths); + library->paths = NULL; + } + } + } } typedef struct _FontEncoding { - FT_UShort platform_id; - FT_Encoding encoding; - FontCodeConverter conv_func; + FT_UShort platform_id; + FT_Encoding encoding; + FontCodeConverter conv_func; } FontEncoding; static FontEncoding encodings[] = { @@ -154,66 +146,65 @@ static FontEncoding encodings[] = { { (FT_UShort)-1, (FT_Encoding)-1, NULL } }; -static char * -font_library_ft2_build_path(const char *base, const char *name) +static char * font_library_ft2_build_path(const char *base, const char *name) { - char *path; - const char *strs[] = { base, "/", name, NULL }; - int i = 0; - - path = (char*) calloc(sizeof(char), strlen(base) + strlen(name) + 2); - if (path) - while (strs[i]) - strcat(path, strs[i++]); - - return path; + char *path; + const char *strs[] = { base, "/", name, NULL }; + int i = 0; + + path = (char*) calloc(sizeof(char), strlen(base) + strlen(name) + 2); + if (path) + while (strs[i]) + strcat(path, strs[i++]); + + return path; } PeerFt2::PeerFt2(const char *name, int index, int hsize, int vsize) { - int i,j; + int i,j; + + font_library_ft2_alloc(); + + for (i = 0; i < library->num_paths; i++) { + char *path = font_library_ft2_build_path(library->paths[i], name); + if (path) { + if (FT_New_Face(library->super, path, index, &face)) + face = NULL; + free(path); + } + if (face) break; + } + + if (!face) { + string err = string("XKFont::PeerFt2::PeerFt : Cannot open font(TrueType) : ")+name; + throw std::invalid_argument(err); + } - font_library_ft2_alloc(); - - for (i = 0; i < library->num_paths; i++) { - char *path = font_library_ft2_build_path(library->paths[i], name); - if (path) { - if (FT_New_Face(library->super, path, index, &face)) - face = NULL; - free(path); - } - if (face) - break; - } - - if (!face) { - string err = string("XKFont::PeerFt2::PeerFt : Cannot open font(TrueType) : ")+name; - throw std::invalid_argument(err); - } - - conv_func = 0; - for (i=0; encodings[i].conv_func != 0; i++) { - FT_UShort platform_id = encodings[i].platform_id; - FT_Encoding encoding = encodings[i].encoding; - for (j = 0; j < face->num_charmaps; j++) { - FT_CharMap cmap = face->charmaps[j]; - if (cmap->platform_id == platform_id && cmap->encoding == encoding) { - if (FT_Set_Charmap(face, cmap) == 0) { - conv_func = encodings[i].conv_func; - break; - } - } - } - if (conv_func) break; - } - if (conv_func == 0) { - FT_Done_Face(face); - fprintf(stderr,"cannot find charmap\n"); - string err = string("XKFont::PeerFt2::PeerFt : No supported code converter of font (TrueType) ")+name; - throw std::invalid_argument(err); - } - FT_Set_Pixel_Sizes(face, hsize, vsize); + conv_func = 0; + for (i=0; encodings[i].conv_func != 0; i++) { + FT_UShort platform_id = encodings[i].platform_id; + FT_Encoding encoding = encodings[i].encoding; + for (j = 0; j < face->num_charmaps; j++) { + FT_CharMap cmap = face->charmaps[j]; + if (cmap->platform_id == platform_id && cmap->encoding == encoding) { + if (FT_Set_Charmap(face, cmap) == 0) { + conv_func = encodings[i].conv_func; + break; + } + } + } + if (conv_func) break; + } + if (conv_func == 0) { + FT_Done_Face(face); + fprintf(stderr,"cannot find charmap\n"); + string err = string("XKFont::PeerFt2::PeerFt : No supported code converter of font (TrueType) ")+name; + throw std::invalid_argument(err); + } + + FT_Set_Pixel_Sizes(face, hsize, vsize); } PeerFt2::~PeerFt2() { @@ -221,71 +212,70 @@ PeerFt2::~PeerFt2() { font_library_ft2_free(); } -bool -PeerFt2::GlyphCreate(unsigned int code, Glyph* glyph) +bool PeerFt2::GlyphCreate(unsigned int code, Glyph* glyph) { - FT_GlyphSlot slot; - FT_UInt index; - int bmsize; + FT_GlyphSlot slot; + FT_UInt index; + int bmsize; - if (face == 0) return false; - code = conv_func(code); - if (code == 0) return false; - index = FT_Get_Char_Index(face, code); - if (index == 0) return false; + if (face == 0) return false; + code = conv_func(code); + if (code == 0) return false; + index = FT_Get_Char_Index(face, code); + if (index == 0) return false; - /* Don't consider error */ - slot = face->glyph; - if (slot) { - // if (! FT_Load_Glyph(face, index, FT_LOAD_DEFAULT)) { -// BITMAP だと なぜか render してくれない…… -// LOAD_DEFAULT でも、下に対応コードを付けたので一応は大丈夫 - if (! FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP)) { - FT_Render_Glyph(slot, ft_render_mode_normal); - } - } - - glyph->bitmap_left = slot->bitmap_left; - glyph->bitmap_top = slot->bitmap_top; - glyph->bitmap.width = slot->bitmap.width; - glyph->bitmap.rows = slot->bitmap.rows; + /* Don't consider error */ + slot = face->glyph; + if (slot) { + // if (! FT_Load_Glyph(face, index, FT_LOAD_DEFAULT)) { + // BITMAP だと なぜか render してくれない…… + // LOAD_DEFAULT でも、下に対応コードを付けたので一応は大丈夫 + if (! FT_Load_Glyph(face, index, FT_LOAD_NO_BITMAP)) + FT_Render_Glyph(slot, ft_render_mode_normal); + } + + glyph->bitmap_left = slot->bitmap_left; + glyph->bitmap_top = slot->bitmap_top; + glyph->bitmap.width = slot->bitmap.width; + glyph->bitmap.rows = slot->bitmap.rows; /* - glyph->metrics.ascender = private->face->size->metrics.ascender >> 6; - glyph->metrics.descender = private->face->size->metrics.descender >> 6; + glyph->metrics.ascender = private->face->size->metrics.ascender >> 6; + glyph->metrics.descender = private->face->size->metrics.descender >> 6; */ - glyph->advance.x = slot->advance.x >> 6; - glyph->advance.y = slot->advance.y >> 6; + glyph->advance.x = slot->advance.x >> 6; + glyph->advance.y = slot->advance.y >> 6; - bmsize = glyph->bitmap.width * glyph->bitmap.rows; - if (bmsize > 0) { - glyph->bitmap.buffer = new unsigned char[bmsize]; - memcpy(glyph->bitmap.buffer, slot->bitmap.buffer, bmsize); - } + bmsize = glyph->bitmap.width * glyph->bitmap.rows; + if (bmsize > 0) { + glyph->bitmap.buffer = new unsigned char[bmsize]; + memcpy(glyph->bitmap.buffer, slot->bitmap.buffer, bmsize); + } // なぜか Render したのに MONO なことがある…… /* for freetype < 2.1.3, use ``ft_pixel_mode_mono'' */ -if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) {int i,j; + if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) { + int i, j; // if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {int i,j; - char* d = (char*)slot->bitmap.buffer; - for (i=0; ibitmap.rows; i++) { - int flag = *d++; int len = 8; - unsigned char* buf = glyph->bitmap.buffer + i*slot->bitmap.width; - for (j=0; jbitmap.width; j++) { - if (len == 0) { - flag = *d++; - len = 8; + char* d = (char*)slot->bitmap.buffer; + for (i=0; i < glyph->bitmap.rows; i++) { + int flag = *d++; + int len = 8; + unsigned char* buf = glyph->bitmap.buffer + i*slot->bitmap.width; + for (j=0; j < glyph->bitmap.width; j++) { + if (len == 0) { + flag = *d++; + len = 8; + } + if (flag & 0x80) *buf++ = 0xff; + else *buf++ = 0; + flag <<= 1; + len--; } - if (flag & 0x80) *buf++ = 0xff; - else *buf++ = 0; - flag <<= 1; - len--; } } -} - return true; - + return true; } } /* end of namespace XKFont */ diff --git a/font/font_peer_x11.cc b/font/font_peer_x11.cc --- a/font/font_peer_x11.cc +++ b/font/font_peer_x11.cc @@ -40,12 +40,12 @@ #include #include #include -#include +#include -#include -#include -//#include -#include +#include +#include + +#include #include #include @@ -86,7 +86,9 @@ FontInfo::FontInfo(Display* display, con /* フォントの大きさ関係の情報を消去 */ int i; char* fontname = new char[strlen(fontname_orig)+50]; - int minus_count = 0; bool is_skip = false; int fc = 0; + int minus_count = 0; + bool is_skip = false; + int fc = 0; for (i=0; fontname_orig[i]!=0; i++) { if (fontname_orig[i] == '-') { minus_count++; @@ -107,7 +109,8 @@ FontInfo::FontInfo(Display* display, con for (i=0; iSearch(pixsize); } - s<xdisplay; */ display = _d; } void PeerX11::OpenDisplay(void) { - if (display) return; + if (display != NULL) return; const char* display_name = getenv("DISPLAY"); - if (display_name == 0) display_name = ":0"; + if (display_name == NULL) display_name = ":0"; display = XOpenDisplay(display_name); - if (display == 0) { + if (display == NULL) { string err = string("XKFont::PeerX11:OpenDisplay() : Cannot open X display ") + display_name; throw std::invalid_argument(err); } @@ -254,15 +259,19 @@ PeerX11::PeerX11(const char* fontname, i int tablesize = mask+1; colortable = new int[tablesize]; - int i; for (i=0; i< tablesize; i++) { + int i; + for (i=0; i< tablesize; i++) { colortable[i] = i*255/tablesize; } -XSupportsLocale(); + + XSupportsLocale(); //FIXME: er... yes? /* font 読み込み */ FontSetInfo fsinfo(display,fontname); string fontset_name = fsinfo.Search(fontsize); - char** missing_cl; int missing_cc; char* def_s; + char** missing_cl; + int missing_cc; + char* def_s; printf("fontset %s\n",fontset_name.c_str()); fontset = XCreateFontSet(display, fontset_name.c_str(), &missing_cl, &missing_cc, &def_s); @@ -298,7 +307,8 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC } /* 描画用の pixmap を作成 */ - XGCValues gc_values; unsigned int gc_values_mask; + XGCValues gc_values; + unsigned int gc_values_mask; gc_values.function = GXcopy; gc_values.fill_style = FillSolid; gc_values.arc_mode = ArcPieSlice; @@ -318,11 +328,11 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC x_shm_info.shmid = -1; x_shm_info.shmaddr = (char*)-1; image = XShmCreateImage(display, visual, DefaultDepth(display, scr), ZPixmap, NULL, &x_shm_info, width, height); - if (image) { + if (image != NULL) { x_shm_info.shmid = shmget(IPC_PRIVATE, image->bytes_per_line*image->height, IPC_CREAT | 0600); if (x_shm_info.shmid == -1) { XDestroyImage(image); - image = 0; + image = NULL; goto no_shm; } x_shm_info.readOnly = False; @@ -340,20 +350,21 @@ printf("locale %s\n",XLocaleOfOM(XOMOfOC use_shm = true; } } -no_shm: +no_shm: //TODO: Understand why he did it, and supress it if needed if (image == 0) { use_shm = false; image = XCreateImage(display, visual, DefaultDepth(display, scr), ZPixmap, 0, 0, width, height, 32, 0); image->data = (char*)malloc(image->bytes_per_line * image->height); - if (image->data == 0) { + if (image->data == NULL) { XDestroyImage(image); - image = 0; + image = NULL; throw bad_alloc(); } } -Glyph g; -GlyphCreate(0xa1a2,&g); -GlyphCreate(0xa4a3,&g); + + Glyph g; + GlyphCreate(0xa1a2, &g); //FIXME: Two calls? Huh? + GlyphCreate(0xa4a3, &g); } PeerX11::~PeerX11() { @@ -397,7 +408,7 @@ bool PeerX11::GlyphCreate(unsigned int c unsigned char* dest = glyph->bitmap.buffer; int bpp = image->bytes_per_line/width; int bpl = image->bytes_per_line; - for (i=0; i>shift) & mask]; diff --git a/font/text.h b/font/text.h --- a/font/text.h +++ b/font/text.h @@ -28,8 +28,8 @@ #ifndef __TEXT_H__ #define __TEXT_H__ -#include -#include +#include +#include struct TextElem { typedef enum {glyph, escape, color, size} ElemType; @@ -82,7 +82,7 @@ struct TextStream { namespace XKFont { class Glyph; class Font; -}; +} struct TextGlyph { int x,y; diff --git a/font/text_stream.cc b/font/text_stream.cc --- a/font/text_stream.cc +++ b/font/text_stream.cc @@ -27,8 +27,8 @@ #include "text.h" #include "codeconv.h" -#include -#include +#include +#include /************************************************************************ ** @@ -39,12 +39,14 @@ TextStream::TextStream(void) { kanji_type = euc; } + void TextStream::SetSize(double scale) { TextElem elem; elem.type = TextElem::size; elem.impl.Size.scale = scale; container.push_back(elem); } + void TextStream::SetColor(unsigned char r, unsigned char g, unsigned char b) { TextElem elem; elem.type = TextElem::color; @@ -53,6 +55,7 @@ void TextStream::SetColor(unsigned char elem.impl.Color.b = b; container.push_back(elem); } + void TextStream::InsertColor(int begin_pos, int end_pos, unsigned char r, unsigned char g, unsigned char b) { TextElem elem; if (begin_pos < 0) begin_pos = 0; @@ -83,9 +86,11 @@ void TextStream::InsertColor(int begin_p } } } + void TextStream::Clear(void) { container.clear(); } + void TextStream::Add(const char* str) { TextElem elem; for (; *str; str++) { @@ -130,12 +135,14 @@ void TextStream::Add(const char* str) { container.push_back(elem); } } + void TextStream::AddReturn(void) { TextElem elem; elem.type = TextElem::escape; elem.impl.Escape.type = TextElem::ret; container.push_back(elem); } + void TextStream::AddName(const char* str) { TextElem elem; elem.type = TextElem::escape; diff --git a/music2/koedec.cc b/music2/koedec.cc --- a/music2/koedec.cc +++ b/music2/koedec.cc @@ -25,15 +25,15 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include +#include +#include +#include #include #include #include -#include"music.h" -#include"system/file.h" -#include"system/file_impl.h" +#include "music.h" +#include "system/file.h" +#include "system/file_impl.h" using namespace std; @@ -64,6 +64,7 @@ struct AvgKoeTable { return koe_num == to; } }; + struct AvgKoeHead { FILE* stream; int file_number; @@ -77,19 +78,23 @@ struct AvgKoeHead { bool operator !=(int num) const { return file_number != num; } bool operator ==(int num) const { return file_number == num; } }; + struct AvgKoeCache { list cache; AvgKoeInfo Find(int file_number, int index); }; + static AvgKoeCache koe_cache; AvgKoeInfo FindKoe(int file_number, int index) { return koe_cache.Find(file_number, index); -}; +} AvgKoeInfo AvgKoeCache::Find(int file_number, int index) { AvgKoeInfo info; - info.stream = 0; info.length = 0; info.offset = 0; + info.stream = NULL; + info.length = 0; + info.offset = 0; list::iterator it; it = find(cache.begin(), cache.end(), file_number); @@ -99,18 +104,18 @@ AvgKoeInfo AvgKoeCache::Find(int file_nu KoeType type = koe_unknown; sprintf(fname, "z%03d.koe", file_number); ARCINFO* arcinfo = file_searcher.Find(FILESEARCH::KOE,fname,".koe"); - if (arcinfo == 0) { + if (arcinfo == NULL) { type = koe_nwk; sprintf(fname, "z%04d.nwk", file_number); arcinfo = file_searcher.Find(FILESEARCH::KOE,fname,".nwk"); } - if (arcinfo == 0) { + if (arcinfo == NULL) { type = koe_ovk; sprintf(fname, "z%04d.ovk", file_number); arcinfo = file_searcher.Find(FILESEARCH::KOE,fname,".ovk"); } #if HAVE_LIBVORBISFILE || HAVE_LIBVORBISIDEC - if (arcinfo == 0) { + if (arcinfo == NULL) { //FIXME: OMG that's ugly, improve it as soon as you can! DIRFILE* koedir = (DIRFILE*) file_searcher.MakeARCFILE((FILESEARCH::ARCTYPE)0, "koe"); sprintf(fname, "%04d", file_number); @@ -122,7 +127,7 @@ AvgKoeInfo AvgKoeCache::Find(int file_nu arcinfo = koedir->Find(fname, ".ogg"); delete koedir; - if (arcinfo == 0) return info; + if (arcinfo == NULL) return info; FILE* stream = arcinfo->OpenFile(&info.length); delete arcinfo; info.type = koe_ogg; @@ -130,16 +135,17 @@ AvgKoeInfo AvgKoeCache::Find(int file_nu return info; } #endif - if (arcinfo == 0) return info; + if (arcinfo == NULL) return info; FILE* stream = arcinfo->OpenFile(); delete arcinfo; - if (stream == 0) return info; + if (stream == NULL) return info; cache.push_front(AvgKoeHead(stream, file_number, type)); if (cache.size() >= koe_cache_size) cache.pop_back(); it = cache.begin(); } if (it->file_number != file_number) return info; // 番号がおかしい AvgKoeTable* table = it->Find(index); + //FIXME: table == NULL ? if (table == 0) return info; // index が見付からない // info を作成する info.length = table->length; @@ -147,7 +153,7 @@ AvgKoeInfo AvgKoeCache::Find(int file_nu info.rate = it->rate; info.type = it->type; int new_fd = dup(fileno(it->stream)); - if (new_fd == -1) info.stream = 0; + if (new_fd == -1) info.stream = NULL; else info.stream = fdopen(new_fd, "rb"); return info; } @@ -155,7 +161,7 @@ AvgKoeInfo AvgKoeCache::Find(int file_nu AvgKoeHead::AvgKoeHead(const AvgKoeHead& from) { if (from.stream) { int new_fd = dup(fileno(from.stream)); - if (new_fd == -1) stream = 0; + if (new_fd == -1) stream = NULL; else stream = fdopen(new_fd, "rb"); } file_number = from.file_number; @@ -170,7 +176,7 @@ AvgKoeHead::AvgKoeHead(FILE* _s, int _fi //int offset = ftell(stream); rate = 22050; type = _type; - if (stream == 0) return; + if (stream == NULL) return; /* header 読み込み */ if (type == koe_nwk) { // 新しい形式 : .nwk file rate = 44100; @@ -201,7 +207,7 @@ AvgKoeHead::AvgKoeHead(FILE* _s, int _fi } else { // .koe file fread(head, 0x20, 1, stream); if (strncmp(head, "KOEPAC", 7) != 0) { // invalid header - stream = 0; + stream = NULL; return; } int table_len = read_little_endian_int(head+0x10); @@ -223,13 +229,14 @@ AvgKoeHead::AvgKoeHead(FILE* _s, int _fi AvgKoeHead::~AvgKoeHead(void) { if (stream) fclose(stream); - stream = 0; + stream = NULL; } + AvgKoeTable* AvgKoeHead::Find(int koe_num) { - if (table.empty()) return 0; + if (table.empty()) return NULL; vector::iterator it; it = lower_bound(table.begin(), table.end(), koe_num); - if (it == table.end() || it->koe_num != koe_num) return 0; + if (it == table.end() || it->koe_num != koe_num) return NULL; return &table[it-table.begin()]; } @@ -342,29 +349,30 @@ extern int is_koe_ogg(char* head); extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len); char* decode_koe(AvgKoeInfo info, int* dest_len) { - char buf[1024]; char* table; + char buf[1024]; + char* table; unsigned char* src_orig, *src; unsigned short* dest_orig, *dest; - int all_len; int i,j; + int all_len, i, j; if (info.stream == NULL) { return NULL; } - fseek(info.stream, info.offset, 0); + fseek(info.stream, info.offset, SEEK_SET); if (info.type == koe_nwk) { return decode_koe_nwa(info, dest_len); } fread(buf, 1, 0x20, info.stream); if (is_koe_ogg(buf)) { - fseek(info.stream, -20, 1); + fseek(info.stream, -20, SEEK_CUR); return decode_koe_ogg(info, dest_len); } /* avg32 の声データ展開 */ table = (char*)malloc(info.length*2); - fseek(info.stream, info.offset, 0); + fseek(info.stream, info.offset, SEEK_SET); fread(table, 2, info.length, info.stream); all_len = 0; - for (i=0; i -#include -#include -#include"music.h" -#include"wavfile.h" +#include +#include +#include +#include "music.h" +#include "wavfile.h" extern int is_koe_ogg(char* head); extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len); @@ -45,19 +45,19 @@ extern int is_koe_ogg(char* head) { #if HAVE_LIBVORBISFILE || HAVE_LIBVORBISIDEC #if HAVE_LIBVORBISFILE -#include +#include #else /* HAVE_LIBVORBISIDEC */ -#include -#include +#include +#include #endif #define INITSIZE 65536 static int cur_size = 0; -static char* out = 0; +static char* out = NULL; static void Resize(void) { char* new_out = (char*)realloc(out, cur_size+INITSIZE); - if (new_out == 0) { + if (new_out == NULL) { new_out = (char*)malloc(cur_size+INITSIZE); memcpy(new_out, out, cur_size); free(out); @@ -71,6 +71,7 @@ struct OggInfo { int length; int offset; }; + /* ogg stream 読み込み用の dummy callback */ static size_t ogg_readfunc(void* ptr, size_t size, size_t nmemb, void* datasource) { OggInfo* info = (OggInfo*)datasource; @@ -80,35 +81,38 @@ static size_t ogg_readfunc(void* ptr, si } return fread(ptr, size, nmemb, info->stream); } + static int ogg_seekfunc(void* datasource, ogg_int64_t new_offset, int whence) { int pt; OggInfo* info = (OggInfo*)datasource; if (whence == SEEK_SET) pt = info->offset + new_offset; else if (whence == SEEK_CUR) pt = ftell(info->stream) + new_offset; else if (whence == SEEK_END) pt = info->offset + info->length + new_offset; - int r = fseek(info->stream, pt, 0); + int r = fseek(info->stream, pt, SEEK_SET); return r; } + static long ogg_tellfunc(void* datasource) { OggInfo* info = (OggInfo*)datasource; int pos = ftell(info->stream); if (pos == -1) return -1; return pos-info->offset; } + static int ogg_closefunc(void* datasource) { return 0; } static int fseek_wrap(FILE *f,ogg_int64_t off,int whence){ - if(f==NULL)return(-1); - return fseek(f,off,whence); + if (f == NULL) return(-1); + return fseek(f, off, whence); } extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len) { - if (info.stream == 0) return 0; + if (info.stream == NULL) return NULL; // Voice ファイルを直接指定すると全ストリームを再生してしまうので // 必要な部分だけ切り出して callback 経由で帰す - fseek(info.stream, info.offset, 0); + fseek(info.stream, info.offset, SEEK_SET); ov_callbacks callback; callback.read_func = &ogg_readfunc; @@ -125,7 +129,7 @@ extern char* decode_koe_ogg(AvgKoeInfo i int r = ov_open_callbacks((void*)&oinfo, &vf, 0, 0, callback); if (r != 0) { fprintf(stderr,"ogg stream err: %d\n",r); - return 0; + return NULL; } vorbis_info* vinfo = ov_info(&vf, 0); info.rate = vinfo->rate; @@ -152,10 +156,11 @@ extern char* decode_koe_ogg(AvgKoeInfo i memcpy(out, header, 0x2c); char* ret = out; - out = 0; + out = NULL; return ret; } + struct OggFILE_impl { OggVorbis_File vf; ov_callbacks callback; @@ -178,7 +183,7 @@ OggFILE::OggFILE(FILE* stream, int len) int r = ov_open_callbacks( (void*)&(pimpl->oinfo), &(pimpl->vf), 0, 0, pimpl->callback); if (r != 0) { delete pimpl; - pimpl = 0; + pimpl = NULL; return; } vorbis_info* vinfo = ov_info(&(pimpl->vf), 0); @@ -186,15 +191,17 @@ OggFILE::OggFILE(FILE* stream, int len) wavinfo.Channels = vinfo->channels; wavinfo.DataBits = 16; } + OggFILE::~OggFILE() { - if (pimpl) { + if (pimpl != NULL) { ov_clear(&(pimpl->vf)); fclose(pimpl->oinfo.stream); delete pimpl; } } + int OggFILE::Read(char* buf, int blksize, int blklen) { - if (pimpl == 0) return -1; + if (pimpl == NULL) return -1; #if HAVE_LIBVORBISFILE int r = ov_read( &(pimpl->vf), buf, blksize*blklen, 0, 2, 1, NULL); #else /* HAVE_LIBVORBISIDEC */ @@ -214,15 +221,18 @@ int OggFILE::Read(char* buf, int blksize } return r / blksize; } + void OggFILE::Seek(int count) { ov_pcm_seek(&(pimpl->vf), count); return; } + #else extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len) { - return 0; + return NULL; } -OggFILE::OggFILE(FILE* stream, int a) {pimpl = 0;} + +OggFILE::OggFILE(FILE* stream, int a) {pimpl = NULL;} OggFILE::~OggFILE(){} void OggFILE::Seek(int count){} int OggFILE::Read(char* buf, int blksize, int blklen){return -1;} diff --git a/music2/movie.cc b/music2/movie.cc --- a/music2/movie.cc +++ b/music2/movie.cc @@ -30,18 +30,18 @@ * */ -#include -#include"music.h" -#include -#include -#include -#include -#include -#include"system/file.h" -#include"window/system.h" +#include +#include "music.h" +#include +#include +#include +#include +#include +#include "system/file.h" +#include "window/system.h" #if USE_SMPEG -#include +#include static SMPEG* smpeg_handle = 0; const char* FindMovieFile(const char* path); @@ -50,7 +50,7 @@ void MuSys::PlayMovie(const char* path, FinalizeMusic(); SMPEG_Info info; const char* find_path = FindMovieFile(path); - if (find_path == 0) return; + if (find_path == NULL) return; smpeg_handle = SMPEG_new(find_path, &info, true); //SMPEG_enableaudio(smpeg_handle, true); //SMPEG_enablevideo(smpeg_handle, true); @@ -58,7 +58,7 @@ void MuSys::PlayMovie(const char* path, SMPEG_enablevideo(smpeg_handle, true); SDL_Surface* surface = SDL_GetVideoSurface(); System::Main::DisableVideo(); - SMPEG_setdisplay(smpeg_handle,surface,0,0); + SMPEG_setdisplay(smpeg_handle, surface, 0, 0); // if (loop_c > 1) SMPEG_loop(smpeg_handle, true); //if (x1 != 0 || x2 != 0) SMPEG_setdisplayregion(smpeg_handle,x1, y1, x2-x1, y1-y2); SMPEG_play(smpeg_handle); @@ -68,15 +68,13 @@ void MuSys::PlayMovie(const char* path, } #endif return; -err: - StopMovie(); - return; } + const char* FindMovieFile(const char* path) { - ARCINFO* info = file_searcher.Find(FILESEARCH::MOV,path,"avi"); - if (info == 0) + ARCINFO* info = file_searcher.Find(FILESEARCH::MOV, path, "avi"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::MOV,path,"mpg"); - if (info == 0) return 0; + if (info == NULL) return NULL; const char* file = info->Path(); delete info; return file; diff --git a/music2/music.cc b/music2/music.cc --- a/music2/music.cc +++ b/music2/music.cc @@ -37,13 +37,13 @@ #include"system/system_config.h" #include"system/file.h" #include "music.h" -#include -#include -#include"wavfile.h" +#include +#include +#include "wavfile.h" using namespace std; -int pcm_enable = 0; +int pcm_enable = 0; Mix_Chunk *play_chunk[MIX_PCM_SIZE]; MuSys::MuSys(AyuSysConfig& _config) : config(_config), movie_id(-1), music_enable(1) { @@ -63,7 +63,10 @@ void bgm_fadeout(int time); void MuSys::PlayCDROM(char* name, int play_count) { config.GetParam("#VOLMOD", 4, &volmod[0], &volmod[1], &volmod[2], &volmod[3]); - char wave[128]; wave[127] = '\0'; wave[0] = '\0'; + + char wave[128]; + wave[127] = '\0'; + wave[0] = '\0'; strcpy(cdrom_track, name); @@ -73,9 +76,9 @@ void MuSys::PlayCDROM(char* name, int pl /* name -> track */ int track =config.track_name.CDTrack(name); if (track == -1) track = atoi(name); - if (config.track_name.WaveTrack(name) != 0) strncpy(wave, config.track_name.WaveTrack(name), 127); + if (config.track_name.WaveTrack(name) != NULL) strncpy(wave, config.track_name.WaveTrack(name), 127); if (wave[0] == 0 && track != 0) { /* DSTRACK が見つからない場合、CDTRACKを使用する */ - sprintf(wave, "audio_%02d",track); + sprintf(wave, "audio_%02d", track); } if (wave == 0) return; // BGM 再生 @@ -95,7 +98,7 @@ void MuSys::StopCDROM(int time) } void MuSys::PlaySE(const char* se, int loop_flag, int channel) { - if (! pcm_enable) return; + if (!pcm_enable) return; if (loop_flag) effec_start(MIX_PCM_EFFEC, se, 10000, 0, volmod); else @@ -105,25 +108,25 @@ void MuSys::PlaySE(const char* se, int l void MuSys::PlaySE(int number) { if (! pcm_enable) return; const char* se_name = config.track_name.SETrack(number); - if (se_name == 0) return; + if (se_name == NULL) return; effec_start(MIX_PCM_EFFEC, se_name, 0, 0, volmod); return; } void MuSys::StopSE(int time) { - if (! pcm_enable) return; + if (!pcm_enable) return; if (time == 0) Mix_HaltChannel(MIX_PCM_EFFEC); else Mix_FadeOutChannel(MIX_PCM_EFFEC, time); } bool MuSys::IsStopSE(void) { - if (! pcm_enable) return true; + if (!pcm_enable) return true; if (Mix_Playing(MIX_PCM_EFFEC) != 0) return false; return true; } void MuSys::StopKoe(int time) { - if (! pcm_enable) return; + if (!pcm_enable) return; if (time == 0) Mix_HaltChannel(MIX_PCM_KOE); else Mix_FadeOutChannel(MIX_PCM_KOE, time); } @@ -176,6 +179,7 @@ struct WavChunk { int *volmod; static void callback(void* userdata, Uint8* stream, int len); }; + WavChunk wav_playing; static int fadetime_total; static int fadecount; @@ -235,14 +239,14 @@ void bgm_start(const char* path, int loo if (! pcm_enable) return; fprintf(stderr,"bgm start %s\n",path); WAVFILE* wav = OpenWaveFile(path); - if (wav == 0) return; + if (wav == NULL) return; Mix_PauseMusic(); Mix_HaltMusic(); Mix_HookMusic(0,0); /* 前に再生していたのを終了 */ - if (wav_playing.wav) { + if (wav_playing.wav != NULL) { delete wav_playing.wav; - wav_playing.wav = 0; + wav_playing.wav = NULL; } wav_playing.wav = wav; wav_playing.loop_pt = loop_pt; @@ -250,13 +254,12 @@ fprintf(stderr,"bgm start %s\n",path); fadetime_total = 0; fadecount = 0; Mix_HookMusic( &(WavChunk::callback), (void*)&wav_playing); - return; } void effec_start(int chn, const char* path, int loop, int fadein_time, int * volmod) { if (! pcm_enable) return; SDL_RWops* op = OpenSDLRW(path); - if (op == 0) { // ファイルが見付からない + if (op == NULL) { // ファイルが見付からない return; } Mix_Pause(chn); @@ -267,17 +270,16 @@ void effec_start(int chn, const char* pa play_chunk[chn] = Mix_LoadWAV_RW(op, 1); if (fadein_time <= 0) { Mix_Volume(chn, volmod[3]*SDL_MIX_MAXVOLUME/255); - Mix_PlayChannel(chn, play_chunk[chn],loop); + Mix_PlayChannel(chn, play_chunk[chn], loop); } else { Mix_Volume(chn, volmod[3]*SDL_MIX_MAXVOLUME/255); - Mix_FadeInChannel(chn, play_chunk[chn],loop,fadein_time); + Mix_FadeInChannel(chn, play_chunk[chn], loop, fadein_time); } - return; } void MuSys::PlayKoe(const char* path) { - if (! pcm_enable) return; - static char* playing_koedata = 0; + if (!pcm_enable) return; + static char* playing_koedata = NULL; int len = 0; AvgKoeInfo koeinfo; int chn = MIX_PCM_KOE; @@ -296,23 +298,25 @@ void MuSys::PlayKoe(const char* path) { koeinfo = OpenKoeFile(path); - if (koeinfo.stream == 0) return; + if (koeinfo.stream == NULL) return; playing_koedata = decode_koe(koeinfo, &len); fclose(koeinfo.stream); - if (playing_koedata == 0) { + if (playing_koedata == NULL) { return; } Mix_Volume(chn, volmod[1]*SDL_MIX_MAXVOLUME/255); play_chunk[chn] = Mix_LoadWAV_RW(SDL_RWFromMem(playing_koedata, len+0x2c), 1); - Mix_PlayChannel(chn, play_chunk[chn],0); - return; + Mix_PlayChannel(chn, play_chunk[chn], 0); } + AvgKoeInfo OpenKoeFile(const char* path) { int radix = 10000; /* if (global_system.Version() >= 2) */ radix *= 10; AvgKoeInfo info; - info.stream = 0; info.length = 0; info.offset = 0; - if (isdigit(path[0]) && strchr(path,'.') == 0) { // 数値 (拡張子等なし) + info.stream = NULL; + info.length = 0; + info.offset = 0; + if (isdigit(path[0]) && strchr(path,'.') == NULL) { // 数値 (拡張子等なし) /* avg32 形式の音声アーカイブのキャッシュを検索 */ int pointer = atoi(path); int file_no = pointer / radix; @@ -320,8 +324,8 @@ AvgKoeInfo OpenKoeFile(const char* path) info = FindKoe(file_no, index); } else { // ファイル int length; - ARCINFO* arcinfo = file_searcher.Find(FILESEARCH::KOE,path,".WPD"); - if (arcinfo == 0) return info; + ARCINFO* arcinfo = file_searcher.Find(FILESEARCH::KOE, path, ".WPD"); + if (arcinfo == NULL) return info; info.stream = arcinfo->OpenFile(&length); info.rate = 22050; info.length = length; @@ -334,12 +338,11 @@ AvgKoeInfo OpenKoeFile(const char* path) static SDL_RWops* OpenSDLRW(const char* path) { /* まず wav ファイルを探す */ - ARCINFO* info = file_searcher.Find(FILESEARCH::WAV,path,".wav"); - if (info == 0) { - info = file_searcher.Find(FILESEARCH::WAV,path,".nwa"); - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"nwa"); - if (info) { // read NWA file - + ARCINFO* info = file_searcher.Find(FILESEARCH::WAV, path, ".wav"); + if (info == NULL) { + info = file_searcher.Find(FILESEARCH::WAV, path, ".nwa"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "nwa"); + if (info != NULL) { // read NWA file int dummy; FILE* f = info->OpenFile(&dummy); static char* d = 0; @@ -349,72 +352,72 @@ static SDL_RWops* OpenSDLRW(const char* return SDL_RWFromMem(d, sz); } } - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"wav"); - if (info == 0) info = file_searcher.Find(FILESEARCH::WAV,path,".ogg"); - if (info) { + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "wav"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::WAV, path, ".ogg"); + if (info != NULL) { int dummy; FILE* f = info->OpenFile(&dummy); delete info; - if (f == 0) return 0; + if (f == NULL) return NULL; SDL_RWops* op = SDL_RWFromFP(f, 1); return op; } - return 0; + return NULL; } static WAVFILE* OpenWaveFile(const char* path) { /* まず wav ファイルを探す */ - ARCINFO* info = file_searcher.Find(FILESEARCH::WAV,path,".wav"); - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"wav"); - if (info) { + ARCINFO* info = file_searcher.Find(FILESEARCH::WAV, path, ".wav"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "wav"); + if (info != NULL) { int size; FILE* f = info->OpenFile(&size); delete info; - if (f == 0) return 0; + if (f == NULL) return NULL; WAVFILE* w = WAVFILE::MakeConverter(new WAVFILE_Stream(f, size)); return w; } /* 次に nwa ファイル */ - info = file_searcher.Find(FILESEARCH::WAV,path,".nwa"); - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"nwa"); - if (info) { + info = file_searcher.Find(FILESEARCH::WAV, path, ".nwa"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "nwa"); + if (info != NULL) { int size; FILE* f = info->OpenFile(&size); delete info; - if (f == 0) return 0; + if (f == NULL) return NULL; WAVFILE* w = WAVFILE::MakeConverter(new NWAFILE(f)); return w; } /* 次に mp3 ファイル */ - info = file_searcher.Find(FILESEARCH::WAV,path,".mp3"); - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"mp3"); - if (info) { + info = file_searcher.Find(FILESEARCH::WAV, path, ".mp3"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "mp3"); + if (info != NULL) { int size; FILE* f = info->OpenFile(&size); delete info; - if (f == 0) return 0; + if (f == NULL) return NULL; MP3FILE* w = new MP3FILE(f, size); - if (w->pimpl) { + if (w->pimpl != NULL) { return WAVFILE::MakeConverter(w); } delete w; } /* 次に ogg ファイル */ - info = file_searcher.Find(FILESEARCH::WAV,path,".ogg"); - if (info == 0) info = file_searcher.Find(FILESEARCH::BGM,path,"ogg"); - if (info) { + info = file_searcher.Find(FILESEARCH::WAV, path, ".ogg"); + if (info == NULL) info = file_searcher.Find(FILESEARCH::BGM, path, "ogg"); + if (info != NULL) { int size; FILE* f = info->OpenFile(&size); delete info; - if (f == 0) return 0; + if (f == NULL) return NULL; OggFILE* w = new OggFILE(f, size); - if (w->pimpl) { + if (w->pimpl != NULL) { return WAVFILE::MakeConverter(w); } delete w; } - return 0; + return NULL; } diff --git a/music2/music.h b/music2/music.h --- a/music2/music.h +++ b/music2/music.h @@ -44,13 +44,14 @@ #define DEFAULT_AUDIOBUF 4096 enum KoeType { koe_unknown, koe_nwk, koe_ovk, koe_ogg}; + typedef struct { FILE* stream; int length; int offset; int rate; KoeType type; -}AvgKoeInfo; +} AvgKoeInfo; extern int pcm_enable; diff --git a/music2/nwatowav.cc b/music2/nwatowav.cc --- a/music2/nwatowav.cc +++ b/music2/nwatowav.cc @@ -163,11 +163,11 @@ // #define NDEBUG /* なぜか assertが入った方が速い、、、 */ -#include -#include -#include // for isatty() function -#include -#include +#include +#include +#include // for isatty() function +#include +#include #ifdef WORDS_BIGENDIAN @@ -229,25 +229,26 @@ const char* make_wavheader(int size, int /* NWA の bitstream展開に必要となる情報 */ class NWAInfo { - int channels; - int bps; - int complevel; - bool use_runlength; -public: - NWAInfo(int c,int b,int cl) { - channels=c; - bps=b; - complevel=cl; - use_runlength = false; - if (cl == 5) { - use_runlength = true; // Tomoyo After (.nwk koe file) - if (channels == 2) use_runlength = false; // BGM*.nwa in Little Busters! + private: + int channels; + int bps; + int complevel; + bool use_runlength; + public: + NWAInfo(int c,int b,int cl) { + channels=c; + bps=b; + complevel=cl; + use_runlength = false; + if (cl == 5) { + use_runlength = true; // Tomoyo After (.nwk koe file) + if (channels == 2) use_runlength = false; // BGM*.nwa in Little Busters! + } } - } - int Channels(void) const{return channels;} - int Bps(void) const { return bps;} - int CompLevel(void) const { return complevel;} - int UseRunLength(void) const { return use_runlength; } + int Channels(void) const{return channels;} + int Bps(void) const { return bps;} + int CompLevel(void) const { return complevel;} + int UseRunLength(void) const { return use_runlength; } }; template void NWADecode(const NWAI& info,const char* data, char* outdata, int datasize, int outdatasize) { @@ -334,54 +335,54 @@ template void NWADecode(cons if (info.Channels() == 2) flip_flag ^= 1; /* channel 切り替え */ } return; -}; +} class NWAData { -public: - int channels; - int bps; /* bits per sample */ - int freq; /* samples per second */ -private: - int complevel; /* compression level */ - int dummy; /* ? : 0x00 */ -public: - int blocks; /* block count */ - int datasize; /* all data size */ -private: - int compdatasize; /* compressed data size */ - int samplecount; /* all samples */ - int blocksize; /* samples per block */ - int restsize; /* samples of the last block */ - int dummy2; /* ? : 0x89 */ - int curblock; - int* offsets; - int offset_start; - int filesize; - char* tmpdata; -public: - void ReadHeader(FILE* in, int file_size=-1); - int CheckHeader(void); /* false: invalid true: valid */ - NWAData(void) { - offsets = 0; - tmpdata = 0; - } - ~NWAData(void) { - if (offsets) delete[] offsets; - if (tmpdata) delete[] tmpdata; - } - int BlockLength(void) { - if (complevel != -1) { - if (offsets == 0) return false; - if (tmpdata == 0) return false; + public: + int channels; + int bps; /* bits per sample */ + int freq; /* samples per second */ + private: + int complevel; /* compression level */ + int dummy; /* ? : 0x00 */ + public: + int blocks; /* block count */ + int datasize; /* all data size */ + private: + int compdatasize; /* compressed data size */ + int samplecount; /* all samples */ + int blocksize; /* samples per block */ + int restsize; /* samples of the last block */ + int dummy2; /* ? : 0x89 */ + int curblock; + int* offsets; + int offset_start; + int filesize; + char* tmpdata; + public: + void ReadHeader(FILE* in, int file_size=-1); + int CheckHeader(void); /* false: invalid true: valid */ + NWAData(void) { + offsets = NULL; + tmpdata = NULL; } - return blocksize * (bps/8); - } - /* data は BlockLength 以上の長さを持つこと - ** 返り値は作成したデータの長さ。終了時は 0。 - ** エラー時は -1 - */ - int Decode(FILE* in, char* data, int& skip_count); - void Rewind(FILE* in); + ~NWAData(void) { + if (offsets) delete[] offsets; + if (tmpdata) delete[] tmpdata; + } + int BlockLength(void) { + if (complevel != -1) { + if (offsets == NULL) return false; + if (tmpdata == NULL) return false; + } + return blocksize * (bps/8); + } + /* data は BlockLength 以上の長さを持つこと + ** 返り値は作成したデータの長さ。終了時は 0。 + ** エラー時は -1 + */ + int Decode(FILE* in, char* data, int& skip_count); + void Rewind(FILE* in); }; void NWAData::ReadHeader(FILE* in, int _file_size) { @@ -390,15 +391,15 @@ void NWAData::ReadHeader(FILE* in, int _ int i; if (offsets) delete[] offsets; if (tmpdata) delete[] tmpdata; - offsets = 0; - tmpdata = 0; + offsets = NULL; + tmpdata = NULL; filesize = 0; offset_start = ftell(in); if (offset_start == -1) offset_start = 0; if (_file_size != -1) filesize = _file_size; curblock = -1; /* header 読み込み */ - if (in == 0 || feof(in) || ferror(in)) { + if (in == NULL || feof(in) || ferror(in)) { fprintf(stderr,"invalid stream\n"); return; } @@ -433,9 +434,9 @@ void NWAData::ReadHeader(FILE* in, int _ /* regular file なら filesize 読み込み */ if (filesize == 0 && fstat(fileno(in), &sb)==0 && (sb.st_mode&S_IFMT) == S_IFREG) { int pos = ftell(in); - fseek(in, 0, 2); + fseek(in, 0, SEEK_END); filesize = ftell(in); - fseek(in, pos, 0); + fseek(in, pos, SEEK_SET); if (pos+blocks*4 >= filesize) { fprintf(stderr,"offset block is not exist\n"); return; @@ -451,18 +452,19 @@ void NWAData::ReadHeader(FILE* in, int _ if (feof(in) || ferror(in)) { fprintf(stderr,"invalid stream\n"); delete[] offsets; - offsets = 0; + offsets = NULL; return; } - return; } + void NWAData::Rewind(FILE* in) { curblock = -1; - fseek(in, 0x2c, 0); - if (offsets) fseek(in, blocks*4, 1); + fseek(in, 0x2c, SEEK_SET); + if (offsets) fseek(in, blocks*4, SEEK_CUR); } + int NWAData::CheckHeader(void) { - if (complevel != -1 && offsets == 0) return false; + if (complevel != -1 && offsets == NULL) return false; /* データそのもののチェック */ if (channels != 1 && channels != 2) { fprintf(stderr,"This program only supports mono / stereo data : data have %d channels.\n",channels); @@ -513,12 +515,13 @@ int NWAData::CheckHeader(void) { } class NWAInfo_sw2 { -public: - int Channels(void) const{return 2;} - int Bps(void) const { return 16;} - int CompLevel(void) const { return 2;} - int UseRunLength(void) const { return false; } + public: + int Channels(void) const{return 2;} + int Bps(void) const { return 16;} + int CompLevel(void) const { return 2;} + int UseRunLength(void) const { return false; } }; + int NWAData::Decode(FILE* in, char* data, int& skip_count) { if (complevel == -1) { /* 無圧縮時の処理 */ if (feof(in) || ferror(in)) return -1; @@ -548,7 +551,7 @@ int NWAData::Decode(FILE* in, char* data } return -1; } - if (offsets == 0 || tmpdata == 0) return -1; + if (offsets == NULL || tmpdata == NULL) return -1; if (blocks == curblock) return 0; if (feof(in) || ferror(in)) return -1; if (curblock == -1) { @@ -610,6 +613,7 @@ void conv(FILE* in, FILE* out, int skip_ } return; } + int main(int argc, char** argv) { int skip_count = 0; @@ -623,20 +627,20 @@ int main(int argc, char** argv) { fprintf(stderr,"usage : nwatowav [inputfile [outputfile]]\n"); return -1; } - if (strstr(argv[1], ".nwk") != 0 || strstr(argv[1], ".ovk") != 0) { + if (strstr(argv[1], ".nwk") != NULL || strstr(argv[1], ".ovk") != NULL) { bool is_ovk; int headblk_sz; - char* out_ext; + const char* out_ext; char* outpath = new char[strlen(argv[1])+10]; char buf[1024]; memset(buf, 0, 1024); FILE* in = fopen(argv[1], "rb"); - if (in == 0) { + if (in == NULL) { fprintf(stderr,"Cannot open file : %s\n",argv[1]); return -1; } - if (strstr(argv[1], ".ovk") != 0) { + if (strstr(argv[1], ".ovk") != NULL) { is_ovk = true; headblk_sz = 16; out_ext = "ogg"; @@ -666,7 +670,7 @@ int main(int argc, char** argv) { tbl_cnt[i] = read_little_endian_int(buf+8); tbl_origsiz[i] = read_little_endian_int(buf+12); } - fseek(in, 0, 2); + fseek(in, 0, SEEK_END); int fsize = ftell(in); for (i=0; i fsize) { @@ -678,12 +682,12 @@ int main(int argc, char** argv) { else sprintf(outpath, "%s-%d.%s", argv[2], tbl_cnt[i],out_ext); FILE* out = fopen(outpath, "wb"); - if (out == 0) { + if (out == NULL) { fprintf(stderr,"Cannot open output file %s\n",outpath); continue; } fprintf(stderr,"Writing file %s...\n",outpath); - fseek(in, tbl_off[i], 0); + fseek(in, tbl_off[i], SEEK_SET); if (is_ovk) { // copy file int sz = tbl_siz[i]; char buf[32*1024]; @@ -705,7 +709,7 @@ int main(int argc, char** argv) { return 0; } FILE* in = fopen(argv[1],"rb"); - if (in == 0) { + if (in == NULL) { fprintf(stderr,"Cannot open file : %s\n",argv[1]); return -1; } @@ -717,7 +721,7 @@ int main(int argc, char** argv) { sprintf(outpath, "%s.wav",argv[1]); if (argc == 3) outpath = argv[2]; out = fopen(outpath, "wb"); - if (out == 0) { + if (out == NULL) { fprintf(stderr,"Cannot open file : %s\n",outpath); return -1; } @@ -732,7 +736,7 @@ int main(int argc, char** argv) { #include"wavfile.h" void NWAFILE::Seek(int count) { - if (data == 0) data = new char[block_size]; + if (data == NULL) data = new char[block_size]; nwa->Rewind(stream); int dmy = 0; nwa->Decode(stream, data, dmy); // skip wav header @@ -741,7 +745,7 @@ void NWAFILE::Seek(int count) { } NWAFILE::NWAFILE(FILE* _stream) { skip_count = 0; - data = 0; + data = NULL; stream = _stream; nwa = new NWAData; nwa->ReadHeader(stream); @@ -766,8 +770,9 @@ NWAFILE::~NWAFILE() { if (data) delete[] data; if (nwa) delete nwa; } + int NWAFILE::Read(char* buf, int blksize, int blklen) { - if (data == 0) return -1; // end of file + if (data == NULL) return -1; // end of file if (data_len > blksize * blklen) { int len = blksize * blklen; @@ -780,12 +785,13 @@ int NWAFILE::Read(char* buf, int blksize int copied_length = data_len; data_len = 0; - if (stream == 0) { + if (stream == NULL) { delete[] data; - data = 0; + data = NULL; return copied_length / blksize; } + //TODO: Rewrite this joke // read do { int err; @@ -793,7 +799,7 @@ retry: err = nwa->Decode(stream, data, skip_count); if (err == 0 || err == -1) { // eof or error delete[] data; - data = 0; + data = NULL; return copied_length / blksize; } if (err == -2) goto retry; // EAGAIN @@ -820,7 +826,7 @@ retry: char* NWAFILE::ReadAll(FILE* in, int& total_size) { NWAData h; - if (in == 0) return 0; + if (in == NULL) return NULL; h.ReadHeader(in); h.CheckHeader(); int bs = h.BlockLength(); @@ -837,14 +843,14 @@ char* NWAFILE::ReadAll(FILE* in, int& to return d; } -#include"music.h" +#include "music.h" char* decode_koe_nwa(AvgKoeInfo info, int* data_len) { NWAData h; - if (info.stream == 0) return 0; - fseek(info.stream, info.offset, 0); + if (info.stream == NULL) return NULL; + fseek(info.stream, info.offset, SEEK_SET); h.ReadHeader(info.stream, info.length); - if (h.CheckHeader() == false) return 0; + if (h.CheckHeader() == false) return NULL; int bs = h.BlockLength(); int total = h.datasize + 0x2c; char* d = new char[total + bs*2]; diff --git a/music2/wavfile.cc b/music2/wavfile.cc --- a/music2/wavfile.cc +++ b/music2/wavfile.cc @@ -23,19 +23,19 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include "wavfile.h" -#include "system/file.h" -#include "music.h" +#include +#include +#include +#include +#include +#include +#include +#include "wavfile.h" +#include "system/file.h" +#include "music.h" -#define BUFFERSIZE 1024 -#define PCM_WAVE_FORMAT 1 +#define BUFFERSIZE 1024 +#define PCM_WAVE_FORMAT 1 /******************************************************* ** @@ -74,7 +74,8 @@ inline void LittleEndian_putW(int num, c num %= 65536; c0 = num % 256; c1 = num / 256; - b[index] = c0; b[index+1] = c1; + b[index] = c0; + b[index+1] = c1; } typedef struct @@ -85,7 +86,7 @@ typedef struct u_long dwAvgBytesPerSec ; u_short wBlockAlign ; u_short wBitsPerSample ; -} WAVEFORMAT ; +} WAVEFORMAT; typedef struct { char RiffID [4] ; @@ -101,31 +102,31 @@ typedef struct u_short wBitsPerSample ; char DataID [4] ; u_long nDataBytes ; -} WAVE_HEADER ; +} WAVE_HEADER; -static void waveFormatCopy( WAVEFORMAT* wav, char *ptr ); -static char* findchunk (char* s1, const char* s2, size_t n) ; +static void waveFormatCopy(WAVEFORMAT* wav, char *ptr ); +static char* findchunk(char* s1, const char* s2, size_t n) ; -static int WaveHeaderCheck (char *wave_buf,int* channels, u_long* samplerate, int* samplebits, u_long* samples,u_long* datastart) -{ - static WAVEFORMAT waveformat ; - char* ptr ; - u_long databytes ; +static int WaveHeaderCheck(char *wave_buf,int* channels, u_long* samplerate, int* samplebits, u_long* samples,u_long* datastart) +{ + static WAVEFORMAT waveformat; + char* ptr; + u_long databytes; - if (findchunk (wave_buf, "RIFF", BUFFERSIZE) != wave_buf) { + if (findchunk(wave_buf, "RIFF", BUFFERSIZE) != wave_buf) { fprintf(stderr, "Bad format: Cannot find RIFF file marker"); return WR_BADRIFF ; } - if (! findchunk (wave_buf, "WAVE", BUFFERSIZE)) { + if (findchunk(wave_buf, "WAVE", BUFFERSIZE) == NULL) { fprintf(stderr, "Bad format: Cannot find WAVE file marker"); return WR_BADWAVE ; } - ptr = findchunk (wave_buf, "fmt ", BUFFERSIZE) ; + ptr = findchunk(wave_buf, "fmt ", BUFFERSIZE) ; - if (! ptr) { + if (ptr == NULL) { fprintf(stderr, "Bad format: Cannot find 'fmt' file marker"); return WR_BADFORMAT ; } @@ -143,9 +144,9 @@ static int WaveHeaderCheck (char *wave return WR_NOTPCMFORMAT ; } - ptr = findchunk (wave_buf, "data", BUFFERSIZE) ; + ptr = findchunk(wave_buf, "data", BUFFERSIZE) ; - if (! ptr) { + if (ptr == NULL) { fprintf(stderr,"Bad format: unable to find 'data' file marker"); return WR_NODATACHUNK ; } @@ -172,30 +173,30 @@ static int WaveHeaderCheck (char *wave return WR_BADFORMATDATA ; } - return 0 ; -} ; /* WaveHeaderCheck*/ + return 0; +} /* WaveHeaderCheck*/ -static char* findchunk (char* pstart, const char* fourcc, size_t n) -{ char *pend ; - int k, test ; +static char* findchunk(char* pstart, const char* fourcc, size_t n) { + char *pend; + int k, test; - pend = pstart + n ; + pend = pstart + n; while (pstart < pend) { - if (*pstart == *fourcc) /* found match for first char*/ - { test = 1 ; - for (k = 1 ; fourcc [k] != 0 ; k++) - test = (test ? ( pstart [k] == fourcc [k] ) : 0) ; + if (*pstart == *fourcc) { /* found match for first char*/ + test = 1 ; + for (k = 1 ; fourcc[k] != 0 ; k++) + test = (test ? ( pstart[k] == fourcc[k] ) : 0) ; if (test) return pstart ; - } ; /* if*/ - pstart ++ ; - } ; /* while lpstart*/ + } ; /* if*/ + pstart++; + } /* while lpstart*/ - return NULL ; -} ; /* findchuck*/ + return NULL; +} /* findchuck*/ static void waveFormatCopy( WAVEFORMAT* wav, char *ptr ) { wav->dwSize = LittleEndian_getDW( ptr, 0 ); @@ -219,9 +220,9 @@ static char* WavGetInfo(WAVFILE* wfile, &channels,&samplerate, &sample_bits,&samples,&datastart) != 0 )) { fprintf(stderr,"WavGetInfo(): Reading WAV header\n"); - return 0; + return NULL; } - + /* * Copy WAV data over to WAVFILE struct: */ @@ -238,11 +239,11 @@ static char* WavGetInfo(WAVFILE* wfile, ** WAVFILE stream reader */ -#include +#include WAVFILE::WAVFILE(void) { - wavinfo.SamplingRate=0; - wavinfo.Channels=1; - wavinfo.DataBits=0; + wavinfo.SamplingRate = 0; + wavinfo.Channels = 1; + wavinfo.DataBits = 0; } int WAVFILE_Stream::Read(char* in_buf, int blksize, int length) { @@ -271,14 +272,16 @@ int WAVFILE_Stream::Read(char* in_buf, i data_length = 0; return blklen; } + void WAVFILE_Stream::Seek(int count) { int blksize = 1; /* block size の設定 */ blksize *= wavinfo.Channels * (wavinfo.DataBits/8); data_length = 0; stream_length = stream_length_orig - stream_top - count*blksize; - fseek(stream, count*blksize+stream_top, 0); + fseek(stream, count*blksize+stream_top, SEEK_SET); } + WAVFILE_Stream::WAVFILE_Stream(FILE* _stream, int _length) { stream = _stream; stream_length = _length; @@ -300,13 +303,13 @@ WAVFILE_Stream::WAVFILE_Stream(FILE* _st } stream_top = data - data_orig; data_length -= data - data_orig; - return; } + WAVFILE_Stream::~WAVFILE_Stream() { if (data_orig) delete data_orig; if (stream) fclose(stream); - return; } + /************************************************************: ** ** WAVE format converter with SDL_audio @@ -338,6 +341,7 @@ WAVFILE* WAVFILE::MakeConverter(WAVFILE* WAVFILE_Converter* conv = new WAVFILE_Converter(new_reader, cvt); return conv; } + WAVFILE_Converter::WAVFILE_Converter(WAVFILE* _orig, SDL_AudioCVT* _cvt) { original = _orig; cvt = _cvt; @@ -347,21 +351,22 @@ WAVFILE_Converter::WAVFILE_Converter(WAV cvt->len = 0; tmpbuf = new char[datasize*cvt->len_mult + 1024]; memset(tmpbuf, 0, datasize*cvt->len_mult+1024); -}; +} static int conv_wave_rate(short* in_buf, int length, int in_rate, int out_rate, char* tmpbuf); WAVFILE_Converter::~WAVFILE_Converter() { - if (cvt) { + if (cvt != NULL) { if (cvt->buf) delete[] cvt->buf; delete cvt; - cvt = 0; + cvt = NULL; } delete[] tmpbuf; if (original) delete original; - original = 0; + original = NULL; } + int WAVFILE_Converter::Read(char* buf, int blksize, int blklen) { - if (original == 0 || cvt == 0) return -1; + if (original == NULL || cvt == NULL) return -1; int copied_length = 0; if (cvt->len < blksize*blklen) { memcpy(buf, cvt->buf, cvt->len); @@ -406,7 +411,7 @@ static int conv_wave_rate(short* in_buf, double input_rate_d = input_rate, output_rate_d = output_rate; double dtime; int outlen; short* out, * out_orig; int next_sample1, next_sample2; short* in_buf_orig = in_buf; - int i; int time; + int i, time; if (input_rate == output_rate) return length; if (length <= 0) return 0; @@ -436,10 +441,10 @@ static int conv_wave_rate(short* in_buf, } dtime -= input_rate_d*outlen; /* 次の prev_time */ - time=0; + time = 0; next_sample1 = short(read_little_endian_short((char*)(in_buf++))); next_sample2 = short(read_little_endian_short((char*)(in_buf++))); - for (i=0; i +#include #define MPEG_BUFSZ 40000 /* 2.5 s at 128 kbps; 1 s at 320 kbps */ struct MP3FILE_impl { enum { PREPARE, RUN, WRITE, DONE} status; @@ -506,7 +511,7 @@ MP3FILE_impl::MP3FILE_impl(FILE* _stream data = new char[MPEG_BUFSZ]; data_len = 0; src_pointer = 0; - write_data = 0; + write_data = NULL; write_data_len = 0; write_pointer = 0; @@ -529,7 +534,6 @@ MP3FILE_impl::~MP3FILE_impl() { free(decoder.sync); mad_decoder_finish(&decoder); delete[] data; - return; } void MP3FILE_impl::run(void) { @@ -639,6 +643,7 @@ enum mad_flow MP3FILE_impl::callback_err /* return MAD_FLOW_BREAK here to stop decoding (and propagate an error) */ return MAD_FLOW_CONTINUE; } + signed int scale(mad_fixed_t sample) { /* round */ @@ -653,11 +658,13 @@ signed int scale(mad_fixed_t sample) /* quantize */ return sample >> (MAD_F_FRACBITS + 1 - 16); } + enum mad_flow MP3FILE_impl::callback_write(void *data, struct mad_header const *header, struct mad_pcm *pcm) { MP3FILE_impl* pimpl = (MP3FILE_impl*)data; return pimpl->callback_write_impl(pcm); } + enum mad_flow MP3FILE_impl::callback_write_impl(struct mad_pcm *pcm) { if (write_data_len == 0) return MAD_FLOW_IGNORE; @@ -671,7 +678,7 @@ enum mad_flow MP3FILE_impl::callback_wri } write_data_len &= ~(nchannels*2-1); /* write_data_len はあらかじめ丸めておく */ src_pointer += nsamples; - if (write_data == 0) { // skip data write + if (write_data == NULL) { // skip data write write_pointer += nsamples*2*2; } else while(nsamples--) { signed int sample = scale(*left_ch++); @@ -691,7 +698,7 @@ MP3FILE::MP3FILE(FILE* stream, int len) pimpl = new MP3FILE_impl(stream); if (pimpl->status == MP3FILE_impl::DONE) { delete pimpl; - pimpl = 0; + pimpl = NULL; fclose(stream); return; } @@ -699,16 +706,18 @@ MP3FILE::MP3FILE(FILE* stream, int len) wavinfo.Channels = 2; wavinfo.DataBits = 16; } + MP3FILE::~MP3FILE() { if (pimpl) { FILE* s = pimpl->stream; delete pimpl; fclose(s); } - pimpl = 0; + pimpl = NULL; } + int MP3FILE::Read(char* buf, int blksize, int blklen) { - if (pimpl == 0) return -1; + if (pimpl == NULL) return -1; pimpl->write_data = buf; pimpl->write_data_len = blksize*blklen; pimpl->write_pointer = 0; @@ -720,17 +729,17 @@ int MP3FILE::Read(char* buf, int blksize void MP3FILE::Seek(int count) { FILE* stream = pimpl->stream; delete pimpl; - fseek(stream,0,0); + fseek(stream, 0, SEEK_SET); pimpl = new MP3FILE_impl(stream); if (pimpl->status == MP3FILE_impl::DONE) { delete pimpl; - pimpl = 0; + pimpl = NULL; fclose(stream); return; } int blksize = 1; blksize *= wavinfo.Channels * (wavinfo.DataBits/8); - pimpl->write_data = 0; + pimpl->write_data = NULL; pimpl->write_data_len = count * blksize; pimpl->write_pointer = 0; do { @@ -738,8 +747,9 @@ void MP3FILE::Seek(int count) { } while(pimpl->status != MP3FILE_impl::DONE && pimpl->write_pointer < pimpl->write_data_len); return; } + #elif USE_SMPEG -#include +#include struct MP3FILE_impl { SMPEG* info; @@ -751,7 +761,7 @@ MP3FILE_impl::MP3FILE_impl(FILE* _stream stream = _stream; info = SMPEG_new_descr(fileno(stream), NULL, 0); fprintf(stderr,"mp3 %p\n",info); - if (info && SMPEG_error(info) ) info = 0; + if (info != NULL && SMPEG_error(info) ) info = NULL; SMPEG_enableaudio(info, 0); SMPEG_enableaudio(info, 1); SMPEG_play(info); @@ -759,7 +769,7 @@ fprintf(stderr,"mp3 %p\n",info); MP3FILE::MP3FILE(FILE* stream, int len) { pimpl = new MP3FILE_impl(stream); - if (pimpl->info == 0) { + if (pimpl->info == NULL) { delete pimpl; fclose(stream); return; @@ -770,6 +780,7 @@ MP3FILE::MP3FILE(FILE* stream, int len) wavinfo.Channels = fmt.channels; wavinfo.DataBits = (fmt.format == AUDIO_S8) ? 8:16; } + MP3FILE::~MP3FILE() { if (pimpl && pimpl->info) { if (SMPEG_status(pimpl->info) == SMPEG_PLAYING) SMPEG_stop(pimpl->info); @@ -778,19 +789,21 @@ MP3FILE::~MP3FILE() { if (pimpl) { fclose(pimpl->stream); delete pimpl; - pimpl = 0; + pimpl = NULL; } } + int MP3FILE::Read(char* buf, int blksize, int blklen) { - if (pimpl == 0 || pimpl->info == 0) return -1; + if (pimpl == NULL || pimpl->info == NULL) return -1; int r = SMPEG_playAudio(pimpl->info, (Uint8*)buf, blksize*blklen); if (r <= 0) { // end of file return -1; } return r / blksize; } + void MP3FILE::Seek(int count) { - if (pimpl == 0 || pimpl->info == 0) return; + if (pimpl == NULL || pimpl->info == NULL) return; SMPEG_stop(pimpl->info); SMPEG_rewind(pimpl->info); SMPEG_play(pimpl->info); @@ -801,8 +814,9 @@ void MP3FILE::Seek(int count) { delete[] d; return; } + #else /* SMPEG */ -MP3FILE::MP3FILE(FILE* stream, int len) {pimpl = 0;} +MP3FILE::MP3FILE(FILE* stream, int len) {pimpl = NULL;} MP3FILE::~MP3FILE(){} void MP3FILE::Seek(int count){} int MP3FILE::Read(char* buf, int blksize, int blklen){return -1;} diff --git a/music2/wavfile.h b/music2/wavfile.h --- a/music2/wavfile.h +++ b/music2/wavfile.h @@ -43,13 +43,13 @@ * WAV file. */ typedef struct { - unsigned int SamplingRate; /* Sampling rate in Hz */ - int Channels; /* Mono or Stereo */ - unsigned short DataBits; /* Sample bit size (8/12/16) */ + unsigned int SamplingRate; /* Sampling rate in Hz */ + int Channels; /* Mono or Stereo */ + unsigned short DataBits; /* Sample bit size (8/12/16) */ } WAVINF; struct WAVFILE{ - WAVINF wavinfo; /* WAV file hdr info */ + WAVINF wavinfo; /* WAV file hdr info */ WAVFILE(void); static int freq; static int format; diff --git a/scn2k/gandump.cc b/scn2k/gandump.cc --- a/scn2k/gandump.cc +++ b/scn2k/gandump.cc @@ -25,37 +25,43 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include +#include char* ganname[6] = {"ptn", "x", "y", "time", "alpha", "?"}; int main(int argc, char** argv) { - if (argc != 2) return 0; + if (argc != 2) return NULL; FILE* f = fopen(argv[1],"rb"); - if (f==0) return 0; - fseek(f,0,2); int sz=ftell(f); fseek(f,0,0); + if (f == NULL) return NULL; + fseek(f, 0, 2); + int sz = ftell(f); + fseek(f, 0, SEEK_SET); char* buf = new char[sz]; char* bufo = buf; - fread(buf,1,sz,f); + fread(buf, 1, sz, f); fclose(f); int i; for (i=0; i<16; i++) { printf("%02x ",int(buf[i])&0xff); } + printf("\n"); - buf+=16; + buf += 16; printf("file '%s'\n",buf); buf += strlen(buf)+1; - printf("N1 = %3d\n", *(int*)buf); buf+=4; - int ptns = *(int*)buf; buf += 4; + printf("N1 = %3d\n", *(int*)buf); + buf += 4; + int ptns = *(int*)buf; + buf += 4; for (i=0; i -#include -#include -#include +#include +#include +#include +#include /* namespace Widget { @@ -43,15 +43,17 @@ namespace Widget { class AnmTime; } */ - class WidText; - class WidButton; - class WidTextButton; - class WidLabel; - class WidDialog; - class WidAnmTime; +class WidText; +class WidButton; +class WidTextButton; +class WidLabel; +class WidDialog; +class WidAnmTime; + namespace Event { class Container; } + class PicBase; class PicContainer; class AyuSysConfig; @@ -93,35 +95,36 @@ class Flags { ** type 78-84, 103 : 4-bit access to 0-6, 25 ** type 104-110, 129 : 8-bit access to 0-6, 25 */ - typedef unsigned int uint; - int sys; - int var[TYPE_VARMAX+1][2000]; - std::string str[2000]; - std::string sys_str[2000]; - std::string loc_str[3]; -public: - Flags(void); - int operator () () const; - int operator () (VarInfo info) const; - void Str(int type, unsigned int number, char* buf, int sz) const; - std::string Str(int type, unsigned int number) const; - std::set cgm_data; + private: + typedef unsigned int uint; + int sys; + int var[TYPE_VARMAX+1][2000]; + std::string str[2000]; + std::string sys_str[2000]; + std::string loc_str[3]; + public: + Flags(void); + int operator () () const; + int operator () (VarInfo info) const; + void Str(int type, unsigned int number, char* buf, int sz) const; + std::string Str(int type, unsigned int number) const; + std::set cgm_data; - bool IsInt(int type) const; - int MaxIndex(int type) const; + bool IsInt(int type) const; + int MaxIndex(int type) const; - void Set(VarInfo info, int value); - int Get(int type, int number) const; - void SetSys(int value); - void SetStr(VarInfo info, std::string val); + void Set(VarInfo info, int value); + int Get(int type, int number) const; + void SetSys(int value); + void SetStr(VarInfo info, std::string val); - bool Exec(class Cmd& cmd); + bool Exec(class Cmd& cmd); - void Save(std::string& str); - void Load(const char* str); + void Save(std::string& str); + void Load(const char* str); - void SaveSys(std::string& str); - void LoadSys(const char* str); + void SaveSys(std::string& str); + void LoadSys(const char* str); }; /* commands */ @@ -135,6 +138,7 @@ enum Cmdtype { CMD_MENUREQ, CMD_BACKLOGREQ, CMD_BACKLOGREQ_FWD, CMD_END}; + struct CmdSimplified { // Cmd 保存用 int type, cmd1, cmd2, cmd3, cmd4, argc; char* args; @@ -142,73 +146,66 @@ struct CmdSimplified { // Cmd 保存用 void Load(const char* save, char*& args_buffer); void copy(const CmdSimplified& from, char*& args_buffer); }; + class Cmd { -public: - Cmdtype cmd_type; - int cmd1, cmd2, cmd3, cmd4; - int argc; - int pos, scn; - const char* rawdata; - char cmdstr[1024]; - std::vector args; + public: + Cmdtype cmd_type; + int cmd1, cmd2, cmd3, cmd4; + int argc; + int pos, scn; + const char* rawdata; + char cmdstr[1024]; + std::vector args; -private: - const Flags& flags; - bool errorflag; - int system_version; + private: + const Flags& flags; + bool errorflag; + int system_version; - int GetArgs(const char*& d); - int GetArgsSpecial(int normal_args,const char*& d); - void GetSelection(const char*& d); - int GetSwitch(const char*& d); - int GetSimpleSwitch(const char*& d); - int GetExpression(const char*& d, struct VarInfo* info = 0); - int GetExpressionCond(const char*& d); - int GetLeftToken(const char*& d, struct VarInfo& info); - int GetString(const char*& d); - int CopyString(const char* d); - int StrVar(int type, int number); - static char strtype[256]; - static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} -public: - const char* Str(const VarInfo& info) const { - if (info.type != TYPE_STR && info.type != TYPE_VARSTR && info.type != TYPE_VARLOCSTR && info.type != TYPE_VARSYSSTR) return ""; - int pt = info.value; - if (pt < 0 || pt >= STRHEAP_SIZE) return ""; - return strheap + pt; - } - int AddStr(char* s) { - // 1-0a-0064 はこういうものが必要らしい - int start = strend; - while (*s) strheap[strend++] = *s++; - strheap[strend++] = 0; - return start; - } -private: - char strheap[STRHEAP_SIZE]; - int strend; - void SetError(void) { errorflag = true;} - void ResetString(void) { - strend = 0; - } -public: - void GetCmd(Flags& f, const char*& d); - void SetSysvar(int n, int v); - void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } - void SetFlagvar(VarInfo info, int v); - void SetStrvar(VarInfo info, const std::string& s); - bool IsError() { return errorflag;} - void clear(void); - virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } - Cmd(const Flags& f, int _sys_ver) : flags(f), system_version(_sys_ver) { cmd_type = CMD_NOP; argc = 0; errorflag = false; cmdstr[0] = 0; strend = 0; pos = -1;} - void read(const CmdSimplified& cmd); - void write(CmdSimplified& cmd, char*& args_buffer) const; + int GetArgs(const char*& d); + int GetArgsSpecial(int normal_args,const char*& d); + void GetSelection(const char*& d); + int GetSwitch(const char*& d); + int GetSimpleSwitch(const char*& d); + int GetExpression(const char*& d, struct VarInfo* info = 0); + int GetExpressionCond(const char*& d); + int GetLeftToken(const char*& d, struct VarInfo& info); + int GetString(const char*& d); + int CopyString(const char* d); + int StrVar(int type, int number); + static char strtype[256]; + static int StrType(const char* d) { return strtype[*(unsigned const char*)d];} + + public: + const char* Str(const VarInfo& info) const; + int AddStr(char* s); + private: + char strheap[STRHEAP_SIZE]; + int strend; + void SetError(void) { errorflag = true;} + void ResetString(void) { + strend = 0; + } + public: + void GetCmd(Flags& f, const char*& d); + void SetSysvar(int n, int v); + void SetSysvar(int v) { SetSysvar(TYPE_SYS_SYS, v); } + void SetFlagvar(VarInfo info, int v); + void SetStrvar(VarInfo info, const std::string& s); + bool IsError() { return errorflag;} + void clear(void); + virtual const char * CmdDescr(int, int, int, int) { return "Not supported"; } + Cmd(const Flags& f, int _sys_ver); + void read(const CmdSimplified& cmd); + void write(CmdSimplified& cmd, char*& args_buffer) const; }; -enum SkipMode {SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, - SKIP_IN_MENU=1024}; +enum SkipMode { + SKIP_NO=0, SKIP_TEXT=1, SKIP_GRP_FAST=16, SKIP_GRP_NOEFFEC=32, + SKIP_GRP_NODRAW=64, SKIPEND_TEXT=256, SKIPEND_KEY=512, SKIP_IN_MENU=1024 +}; -#include"font/text.h" +#include "font/text.h" struct BacklogItem { enum {SaveSelect = -2}; @@ -223,40 +220,43 @@ struct BacklogItem { void SetSavepos(int pos); BacklogItem& operator =(const BacklogItem&); }; + class Text { - class TextImpl* pimpl; -public: - std::vector backlog; - BacklogItem backlog_item; - Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config); - ~Text(); - void InitWindow(void); - void Exec(Cmd& cmd); - bool Wait(unsigned int current_time, Cmd& cmd); - void SetSkipMode(SkipMode mode); - void hide(void); - void show(void); - void show(int num); - void Save(std::string& str, bool rollback_save); - void Load(const char* str); - void DrawBacklog(BacklogItem& item, Cmd& cmd); + private: + class TextImpl* pimpl; + public: + std::vector backlog; + BacklogItem backlog_item; + Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config); + ~Text(); + void InitWindow(void); + void Exec(Cmd& cmd); + bool Wait(unsigned int current_time, Cmd& cmd); + void SetSkipMode(SkipMode mode); + void hide(void); + void show(void); + void show(int num); + void Save(std::string& str, bool rollback_save); + void Load(const char* str); + void DrawBacklog(BacklogItem& item, Cmd& cmd); }; -#include"../window/rect.h" +#include "../window/rect.h" class Grp { - class GrpImpl* pimpl; -public: - Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, std::set& _cgm_data, class MuSys& mu, AyuSysConfig& config); - ~Grp(); - bool Wait(unsigned int current_time, Cmd& cmd); - void Exec(Cmd& cmd); - void SetSkipMode(SkipMode mode); - void InitSel(AyuSysConfig& config); - void Save(std::string& str); - void Load(const char* str); - void SaveSys(std::string& str); - void LoadSys(const char* str); + private: + class GrpImpl* pimpl; + public: + Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, std::set& _cgm_data, class MuSys& mu, AyuSysConfig& config); + ~Grp(); + bool Wait(unsigned int current_time, Cmd& cmd); + void Exec(Cmd& cmd); + void SetSkipMode(SkipMode mode); + void InitSel(AyuSysConfig& config); + void Save(std::string& str); + void Load(const char* str); + void SaveSys(std::string& str); + void LoadSys(const char* str); }; void dprintf(const char* fmt, ...); // debug 用 diff --git a/scn2k/scn2k_cmd.cc b/scn2k/scn2k_cmd.cc --- a/scn2k/scn2k_cmd.cc +++ b/scn2k/scn2k_cmd.cc @@ -26,14 +26,14 @@ */ -#include"scn2k.h" +#include "scn2k.h" -#include -#include -#include -#include -#include -#include"system/file.h" +#include +#include +#include +#include +#include +#include "system/file.h" using namespace std; @@ -47,7 +47,8 @@ using namespace std; bool debug_flag = false; void dprintf(const char* fmt, ...) { if (debug_flag) { - va_list ap; va_start(ap, fmt); + va_list ap; + va_start(ap, fmt); vprintf(fmt, ap); va_end(ap); } @@ -162,40 +163,42 @@ void Flags::Set(VarInfo info, int value) void Flags::SetSys(int value) { sys = value; } + void Flags::SetStr(VarInfo info, string val) { switch(info.type) { - case TYPE_VARLOCSTR: - if (info.number >= 3) return; - loc_str[info.number] = val; - break; - case TYPE_VARSYSSTR: - if (info.number >= 2000) return; - sys_str[info.number] = val; - break; - case TYPE_VARSTR: - if (info.number >= 2000) return; - str[info.number] = val; - break; + case TYPE_VARLOCSTR: + if (info.number >= 3) return; + loc_str[info.number] = val; + break; + case TYPE_VARSYSSTR: + if (info.number >= 2000) return; + sys_str[info.number] = val; + break; + case TYPE_VARSTR: + if (info.number >= 2000) return; + str[info.number] = val; + break; } return; } + void Flags::Str(int type, unsigned int number, char* buf, int sz) const { if (sz <= 0) return; buf[0] = 0; const string* sptr; switch(type) { - case TYPE_VARLOCSTR: - if (number >= 3) return; - sptr = &loc_str[number]; - break; - case TYPE_VARSYSSTR: - if (number >= 2000) return; - sptr = &sys_str[number]; - break; - case TYPE_VARSTR: - if (number >= 2000) return; - sptr = &str[number]; - break; + case TYPE_VARLOCSTR: + if (number >= 3) return; + sptr = &loc_str[number]; + break; + case TYPE_VARSYSSTR: + if (number >= 2000) return; + sptr = &sys_str[number]; + break; + case TYPE_VARSTR: + if (number >= 2000) return; + sptr = &str[number]; + break; } int len = sptr->length(); @@ -204,6 +207,7 @@ void Flags::Str(int type, unsigned int n buf[sz] = 0; return; } + string Flags::Str(int type, unsigned int number) const { switch(type) { case TYPE_VARLOCSTR: @@ -238,6 +242,7 @@ void Flags::Save(string& save) { } } } + void Flags::Load(const char* save) { int i,j; for (i=0; i<=TYPE_NONSYSVARMAX; i++) { @@ -281,10 +286,9 @@ void Flags::Load(const char* save) { if (save) save++; } while (save); } - return; } -void Flags::SaveSys(string& save) { +void Flags::SaveSys(string& save) { //FIXME: see how to factorize with Save char buf[1024]; int j; save = "\n[Flags]\n"; @@ -307,7 +311,8 @@ void Flags::SaveSys(string& save) { } } } -void Flags::LoadSys(const char* save) { + +void Flags::LoadSys(const char* save) { //FIXME: Same as Save and SaveSys int i,j; for (i=6; i<=7; i++) { for (j=0; j<2000; j++) { @@ -352,7 +357,6 @@ void Flags::LoadSys(const char* save) { if (save) save++; } while (save); } - return; } bool Flags::Exec(Cmd& cmd) { @@ -365,230 +369,176 @@ bool Flags::Exec(Cmd& cmd) { if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0a) { // 文字列演算 VarInfo arg1 = cmd.args[0]; switch(cmd.cmd3) { - case 0: - if (cmd.cmd4 == 0) { - SetStr(arg1, cmd.Str(cmd.args[1])); - } else if (cmd.cmd4 == 1) { - string s = cmd.Str(cmd.args[1]); - const char* sc = s.c_str(); - int len = cmd.args[2].value; - int i; - for (i=0; i < sc[i] && len != 0; i++, len--) { - if (sc[i]<0 && sc[i+1]!=0) i++; + case 0: + if (cmd.cmd4 == 0) { + SetStr(arg1, cmd.Str(cmd.args[1])); + } else if (cmd.cmd4 == 1) { + string s = cmd.Str(cmd.args[1]); + const char* sc = s.c_str(); + int len = cmd.args[2].value; + int i; + for (i=0; i < sc[i] && len != 0; i++, len--) { + if (sc[i]<0 && sc[i+1]!=0) i++; + } + s.erase(i); // 全角で len 文字まで切り詰める + SetStr(arg1, s); + // fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str()); + } else break; + cmd.clear(); + break; + case 1: + if (cmd.cmd4 == 0) { + SetStr(arg1, ""); + cmd.clear(); + } else if (cmd.cmd4 == 1) { + // 領域指定で文字列クリア + VarInfo v1 = cmd.args[0]; + VarInfo v2 = cmd.args[1]; + eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); + if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) { + eprintf(" error: bad args\n"); + } else { + if (v1.number < 0) v1.number = 0; + if (v2.number > 2000) v2.number = 2000; + for (; v1.number <= v2.number; v1.number++) { + SetStr(v1, ""); + } + } + cmd.clear(); } - s.erase(i); // 全角で len 文字まで切り詰める - SetStr(arg1, s); -// fprintf(stderr,"Set[%d,%d]<-%s\n",arg1.type,arg1.number,s.c_str()); - } else break; - cmd.clear(); - break; - case 1: - if (cmd.cmd4 == 0) { - SetStr(arg1, ""); + case 2: + SetStr(arg1, Str(arg1.type,arg1.number) + cmd.Str(cmd.args[1])); + // fprintf(stderr,"Append[%d,%d]<-%s(%d:%d)\n",arg1.type,arg1.number,Str(arg1.type,arg1.number).c_str(),cmd.args[1].type,cmd.args[1].number); + cmd.clear(); + break; + case 3: + SetSys(strlen(cmd.Str(cmd.args[0]))); + cmd.clear(); + break; + case 4: + { int v = strcmp(cmd.Str(cmd.args[0]), cmd.Str(cmd.args[1])); + // string s1=cmd.Str(cmd.args[0]); + // string s2=cmd.Str(cmd.args[1]); + // fprintf(stderr,"Cmp %s(%d:%d):%s(%d:%d):%d\n",s1.c_str(),cmd.args[0].type,cmd.args[0].number,s2.c_str(),cmd.args[1].type,cmd.args[1].number,v); + if (v < 0) SetSys(-1); + else if (v > 0) SetSys(1); + else SetSys(0); cmd.clear(); - } else if (cmd.cmd4 == 1) { - // 領域指定で文字列クリア - VarInfo v1 = cmd.args[0]; - VarInfo v2 = cmd.args[1]; - eprintf("memclear(str). Var[%d]<%d> - Var[%d]<%d>\n",v1.type, v1.number, v2.type, v2.number); - if (v1.type != v2.type || (v1.type != TYPE_VARSTR && v1.type != TYPE_VARSYSSTR && v1.type != TYPE_VARLOCSTR)) { - eprintf(" error: bad args\n"); - } else { - if (v1.number < 0) v1.number = 0; - if (v2.number > 2000) v2.number = 2000; - for (; v1.number <= v2.number; v1.number++) { - SetStr(v1, ""); + break; } + case 5: // substring, index from left + case 6: // substring, index from right + // 全角対応らしい + //FIXME: Make sure it works properly + { int offset = cmd.args[2].value; + int len = strlen(cmd.Str(cmd.args[1])); + string str = cmd.Str(cmd.args[1]); + const char* s = str.c_str(); + if (cmd.cmd3 == 6) offset = len - offset; + if (offset < 0) offset = 0; + // 先頭 N 文字を読み飛ばす + int i; + int offset_top = 0; + for (i=0; i 0) SetSys(1); - else SetSys(0); - cmd.clear(); - break; } - case 5: // substring, index from left - case 6: // substring, index from right - // 全角対応らしい - //FIXME: Make sure it works properly - { int offset = cmd.args[2].value; - int len = strlen(cmd.Str(cmd.args[1])); - string str = cmd.Str(cmd.args[1]); - const char* s = str.c_str(); - if (cmd.cmd3 == 6) offset = len - offset; - if (offset < 0) offset = 0; - // 先頭 N 文字を読み飛ばす - int i; - int offset_top = 0; - for (i=0; i[0](=0) - -47408 : 0x23 - cmd 01-0a:0004:00[ 2] - args:V<18>[0](=0),"岡崎さん" -47437 : expr: V<0>[1000](=0)=V -47451 : 0x23 - cmd 01-0a:0004:00[ 2] - args:V<18>[0](=0),"朋也くん" -47480 : expr: V<0>[1001](=0)=V -47494 : V<0>[1000](=0)==0(=true)-> 47589 -47526 : 0x23 - cmd 01-04:0514:00[ 2] - args:0,V<18>[0](=0) /* NAME.A を帰す */ -47552 : 0x23 - cmd 01-0a:0002:00[ 2] - args:V<18>[0](=0),"さん" -47577 : jmp -> 47672 -47589 : V<0>[1001](=0)==0(=true)-> 47672 -47621 : 0x23 - cmd 01-04:0514:00[ 2] - args:1,V<18>[0](=0) /* NAME.B を帰す */ -47647 : 0x23 - cmd 01-0a:0002:00[ 2] - args:V<18>[0](=0),"くん" -47672 : pos. 279 -47675 : 0x23 - cmd 01-0a:0064:00[ 1] - args:V<18>[0](=0) - -#endif - cmd.cmd_type = CMD_TEXT; - break; + break; + case 0x0f: case 0x11: // itoa (0x11 の方は zero padding するっぽい) + if (cmd.cmd4 == 0) { + int arg1 = cmd.args[0].value; + char buf[1024]; sprintf(buf, "%d", arg1); + SetStr(cmd.args[1], buf); + cmd.clear(); + } else if (cmd.cmd4 == 1) { + // 漢字(SJIS) : 82 [4f+N] + // やはり漢字じゃない? + int arg1 = cmd.args[0].value; + char buf[1024]; char fmt[1024]; + if (cmd.cmd3 == 0x0f) { + sprintf(fmt, "%%%dd",cmd.args[2].value); /* 空白でパディング */ + } else { + sprintf(fmt, "%%0%dd",cmd.args[2].value); + } + sprintf(buf, fmt, arg1); + SetStr(cmd.args[1], buf); + cmd.clear(); + } + break; + case 0x64: // 文字列の表示 : 引数をテキストウィンドウに表示 + if (cmd.cmd4 == 1) { + char buf[256]; + snprintf(buf, 255, "%d", Get(cmd.args[0].type, cmd.args[0].number)); + cmd.args[0].type = TYPE_STR; + cmd.args[0].value = cmd.AddStr(buf); + cmd.cmd4 = 0; + } + cmd.cmd_type = CMD_TEXT; + break; } } if (cmd.cmd1 == 1 && cmd.cmd2 == 0x0b) { // 数値変数演算 @@ -773,6 +723,15 @@ inline int eval(int v1, int op, int v2) return v2; } +Cmd::Cmd(const Flags& f, int _sys_ver) : flags(f), system_version(_sys_ver) { + cmd_type = CMD_NOP; + argc = 0; + errorflag = false; + cmdstr[0] = 0; + strend = 0; + pos = -1; +} + /* 演算子 op := 0x5c */ /* 数式 exp: [op] [op [...]] */ int Cmd::GetExpression(const char*& d, VarInfo* info_ptr) { @@ -1217,11 +1176,10 @@ void Cmd::GetSelection(const char*& d) { /* 一致しない場合があるのでコメントアウト */ // if (arg_count != argc) SetError(); dprintf("\n}\n"); - return; } void Cmd::GetCmd(Flags& flags_orig, const char*& d ) { - if (d == 0) { SetError(); return;} + if (d == NULL) { SetError(); return;} if (cmd_type != CMD_NOP) return; cmdstr[0] = 0; @@ -1368,8 +1326,8 @@ retry: } else { SetError(); } - return; } + void Cmd::clear(void) { cmd_type = CMD_NOP; ResetString(); @@ -1474,6 +1432,24 @@ void Cmd::SetStrvar(VarInfo info, const args.push_back(info); } + +const char* Cmd::Str(const VarInfo& info) const { + if (info.type != TYPE_STR && info.type != TYPE_VARSTR && info.type != TYPE_VARLOCSTR && info.type != TYPE_VARSYSSTR) + return ""; + int pt = info.value; + if (pt < 0 || pt >= STRHEAP_SIZE) return ""; + return strheap + pt; +} + +int Cmd::AddStr(char* s) { + // 1-0a-0064 はこういうものが必要らしい + int start = strend; + while (*s) strheap[strend++] = *s++; + strheap[strend++] = 0; + return start; +} + + void Cmd::read(const CmdSimplified& from) { errorflag = false; ResetString(); @@ -1487,7 +1463,7 @@ void Cmd::read(const CmdSimplified& from /* args の読み込み */ args.clear(); char* d = from.args; - if (d == 0) return; + if (d == NULL) return; while(*d != TYPE_END) { VarInfo info; switch(*d) { @@ -1511,8 +1487,8 @@ void Cmd::read(const CmdSimplified& from *d = TYPE_END; } } - return; } + void Cmd::write(CmdSimplified& to, char*& buffer) const { /* if (cmd_type != CMD_OTHER) { @@ -1529,7 +1505,7 @@ void Cmd::write(CmdSimplified& to, char* to.argc = argc; /* args の書き込み */ if (args.empty()) { - to.args = 0; + to.args = NULL; } else { to.args = buffer; char* d = to.args; @@ -1554,9 +1530,10 @@ void Cmd::write(CmdSimplified& to, char* buffer = d; } } + void CmdSimplified::copy(const CmdSimplified& from, char*& args_buffer) { *this = from; - if (args == 0) return; + if (args == NULL) return; char* args_old = from.args; /* args のコピー */ while(*args_old != TYPE_END) { @@ -1572,6 +1549,7 @@ void CmdSimplified::copy(const CmdSimpli args = args_buffer; args_buffer += args_len; } + void CmdSimplified::Save(string& saveret) { char buf[1024]; sprintf(buf, "%02x-%02x:%04x:%02x(%02d),", cmd1, cmd2, cmd3, cmd4, argc); @@ -1609,7 +1587,7 @@ void CmdSimplified::Load(const char* sav type = CMD_OTHER; sscanf(save, "%02x-%02x:%04x:%02x(%02d),", &cmd1, &cmd2, &cmd3, &cmd4, &argc); save = strchr(save, ','); - if (save == 0) { + if (save == NULL) { *args_buffer++ = TYPE_END; return; } @@ -1639,7 +1617,6 @@ void CmdSimplified::Load(const char* sav } } *args_buffer++ = TYPE_END; - return; } #ifdef SCN_DUMP @@ -1653,17 +1630,22 @@ int main(int argc, char** argv) { /* determine file names */ bool verbose = false; char* inname = "seen.txt"; - char* outname = 0; + char* outname = NULL; if (argc > 2 && strcmp(argv[1],"-v") == 0) { int i; for (i=1; iCopyRead(); char* d = data; char* dend = d + info->Size(); diff --git a/scn2k/scn2k_grp.cc b/scn2k/scn2k_grp.cc --- a/scn2k/scn2k_grp.cc +++ b/scn2k/scn2k_grp.cc @@ -25,12 +25,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include"scn2k.h" -#include"window/widget.h" -#include"system/file.h" -#include"system/system_config.h" -#include"font/text.h" -#include +#include "scn2k.h" +#include "window/widget.h" +#include "system/file.h" +#include "system/system_config.h" +#include "font/text.h" +#include using namespace std; @@ -60,7 +60,7 @@ struct GrpObj { PicBase* picture; WidAnmTime* anm; int _posx, _posy; - int posx[9],posy[9]; + int posx[9], posy[9]; Rect clip_area; unsigned char alpha; int order; @@ -138,74 +138,77 @@ struct GrpObjMap : std::map class GrpImpl { #define MAXPDT 256 #define WORKPDT 255 - Event::Container& event; - const Flags& flags; - PicBase* screen; - PicBase* screen_front; - Surface* surface, *surface_update; + private: + Event::Container& event; + const Flags& flags; + PicBase* screen; + PicBase* screen_front; + Surface* surface, *surface_update; - Surface* dsurface[MAXPDT]; // 書き込み可能な Surface - Surface* ssurface[MAXPDT]; // ファイルの内容等、読み込みのみ可能な状態の Surface - PicContainer& parent; + Surface* dsurface[MAXPDT]; // 書き込み可能な Surface + Surface* ssurface[MAXPDT]; // ファイルの内容等、読み込みのみ可能な状態の Surface + PicContainer& parent; - // 画像効果の保存用 - WidAnmTime* anm1, *anm2; - typedef enum { NORMAL, WAIT_ANM, WAIT_SHAKE, WAIT_SE, WAIT_MOVIE} Status; - Status status; - SkipMode skip_mode; + // 画像効果の保存用 + WidAnmTime* anm1, *anm2; + typedef enum { NORMAL, WAIT_ANM, WAIT_SHAKE, WAIT_SE, WAIT_MOVIE} Status; + Status status; + SkipMode skip_mode; - std::string bg_name; - std::map anmtype; - GrpObjMap grpobj; - GrpObjMap bs_obj; - void CreateObj(int number); - void ZMoveObj(int number); - void SetObjChanged(int number); - void SetObjChangedGroup(int number); - void SwapObj(int a1, int a2); - void DeleteObjPic(int num);// object の surface のみ削除 - void DeleteObj(int num); - void DeleteObjRange(int num_b, int num_e); + std::string bg_name; + std::map anmtype; + GrpObjMap grpobj; + GrpObjMap bs_obj; + void CreateObj(int number); + void ZMoveObj(int number); + void SetObjChanged(int number); + void SetObjChangedGroup(int number); + void SwapObj(int a1, int a2); + void DeleteObjPic(int num);// object の surface のみ削除 + void DeleteObj(int num); + void DeleteObjRange(int num_b, int num_e); - std::set changed_obj; - string reserved_load_surface0; - vector deleted_pic; - void RefreshObj(void); + std::set changed_obj; + string reserved_load_surface0; + vector deleted_pic; + void RefreshObj(void); - Surface* Dsurface(int pdt); - Surface* Ssurface(int pdt); + Surface* Dsurface(int pdt); + Surface* Ssurface(int pdt); - // cgmode 用画像処理関連 - void LoadCgm(AyuSysConfig& config); - std::map cgm_info; - set& cgm_data; - int cgm_size; - - class MuSys& music; + // cgmode 用画像処理関連 + void LoadCgm(AyuSysConfig& config); + std::map cgm_info; + set& cgm_data; + int cgm_size; + + class MuSys& music; + + public: + AyuSysConfig& config; + void LoadSurface(const char* str, int pdt); -public: - AyuSysConfig& config; - void LoadSurface(const char* str, int pdt); -private: - void LoadSurface(const char* str); - void LoadSurface(void); - void AddSurface(const char* str); + private: + void LoadSurface(const char* str); + void LoadSurface(void); + void AddSurface(const char* str); + + void StartAnm(int type); + void StartShake(int total, const int* pattern); + void AbortAnm(void); + static bool Pressed(int x, int y, void* pointer); - void StartAnm(int type); - void StartShake(int total, const int* pattern); - void AbortAnm(void); - static bool Pressed(int x, int y, void* pointer); -public: - GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& _flag, set& _cgm_data, class MuSys& mu, AyuSysConfig& config); - ~GrpImpl(); - bool Wait(unsigned int current_time, Cmd& cmd); - void Exec(Cmd& cmd); - void InitSel(AyuSysConfig& config); - void Save(std::string& str); - void Load(const char* str); - void SaveSys(std::string& str); - void LoadSys(const char* str); - void SetSkipMode(SkipMode _mode); + public: + GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& _flag, set& _cgm_data, class MuSys& mu, AyuSysConfig& config); + ~GrpImpl(); + bool Wait(unsigned int current_time, Cmd& cmd); + void Exec(Cmd& cmd); + void InitSel(AyuSysConfig& config); + void Save(std::string& str); + void Load(const char* str); + void SaveSys(std::string& str); + void LoadSys(const char* str); + void SetSkipMode(SkipMode _mode); }; /******************************************************************* ** GrpObj(implementation) @@ -222,22 +225,27 @@ GrpObj::GrpObj(void) : posx[i] = posy[i] = 0; } } + GrpObj::~GrpObj() { if (picture) delete picture; if (parent_pimpl == 0) { fprintf(stderr,"\n**************\nFATAL : UNINITIALIZED GrpObj IS FOUND!!! \n**************\n"); } } + int GrpObj::PosX() { return _posx; } + int GrpObj::PosY() { return _posy; } + void GrpObj::SetUpdate(void) { attr = Attribute (attr | UPDATE_PICTURE); //Update(); //FIXME } + void GrpObj::SetPos(int index, int x,int y) { if (index < 0 || index > 8) { fprintf(stderr,"GrpObj::SetPos: Invalid index %d <- %d,%d\n",index,x,y); @@ -250,6 +258,7 @@ void GrpObj::SetPos(int index, int x,int posx[index] = x; posy[index] = y; } + void GrpObj::GetPos(int index, int& x, int& y) { if (index < 0 || index > 8) { fprintf(stderr,"GrpObj::GetPos: Invalid index %d\n",index); @@ -260,12 +269,14 @@ void GrpObj::GetPos(int index, int& x, i y = posy[index]; return; } + void GrpObj::SetAlpha(int new_alpha) { if (alpha == new_alpha) return; alpha = new_alpha; attr = Attribute(attr | UPDATE_ALPHA); return; } + void GrpObj::SetSurfaceNum(int num) { if (num != -1) { if (surface_num == num) return; @@ -282,6 +293,7 @@ void GrpObj::SetClipArea(int x, int y, i attr = Attribute(attr | UPDATE_CLIP); return; } + PicBase* GrpObj::DeletePic(void) { PicBase* p = picture; anm = 0; @@ -290,6 +302,7 @@ PicBase* GrpObj::DeletePic(void) { attr = Attribute(attr & (HIDDEN | HIDDEN_GROUP)); return p; } + void GrpObj::GetSrcGeom(int& width, int& height) { if (src_pos.empty()) { width = 0; height = 0; @@ -301,12 +314,12 @@ void GrpObj::GetSrcGeom(int& width, int& string path(name); path += ".g00"; ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, path.c_str(), "g00"); - if (info == 0) { // ファイルが見つからない - fprintf(stderr,"GrpObj::GetSrcGeom : Cannot find file %s\n", path.c_str()); + if (info == NULL) { // ファイルが見つからない + fprintf(stderr, "GrpObj::GetSrcGeom : Cannot find file %s\n", path.c_str()); return; } const char* data = info->Read(); - if (data && *data == 2) { // 画像ファイル内にボタン情報が存在する + if (data != NULL && *data == 2) { // 画像ファイル内にボタン情報が存在する int srclen = read_little_endian_int(data+5); int i; for (i=0; iSetSurface( (Surface*)0,0,0); + picture->SetSurface( (Surface*)0, 0, 0); // 回転、縮小拡大は座標原点が画像の中心になる string path(name); path += ".g00"; Surface* surface_orig = pic_parent->Root().NewSurface(path.c_str()); - if (surface_orig == 0) return; + if (surface_orig == NULL) return; Surface* zoom_surface = pic_parent->Root().RotZoomSurface(surface_orig, double(zoom)/256.0, rotate); Rect zoom_r (*zoom_surface); @@ -450,8 +466,10 @@ static char* wstrchr(const char* s, unsi if (wc == chr) return (char*)s; s += ws; } - return 0; + 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; @@ -461,7 +479,7 @@ TextStream GrpObj::ParseMoji(const char* str, int def_r ,int def_g, int def_b, int def_size) { // 制御シーケンス付き文字列をparse char* retptr; int var; - while( (next_str = wstrchr(str, '#')) != 0) { + while( (next_str = wstrchr(str, '#')) != NULL) { int len = next_str - str; strncpy(copy_str, str, len); copy_str[len] = 0; @@ -487,7 +505,7 @@ TextStream GrpObj::ParseMoji(const char* str, int def_r ,int def_g, int def_b, int def_size) { // 制御シーケンス付き文字列をparse if (parent_pimpl->config.GetParam(key, 3, &r, &g, &b)) { // color not found r = g = b = 0; } - ts.SetColor(r,g,b); + ts.SetColor(r, g, b); str = next_str; } break; @@ -513,6 +531,7 @@ TextStream GrpObj::ParseMoji(const char* str, int def_r ,int def_g, int def_b, int def_size) { // 制御シーケンス付き文字列をparse delete[] copy_str; return ts; } + void GrpObj::UpdateMoji(void) { // 文字の大きさ、色などを変更 if (print_moji.length() == 0 || print_size <= 2) return; if (pic_parent == 0) return; @@ -539,6 +558,7 @@ void GrpObj::UpdateMoji(void) { // 文字の大きさ、色などを変更 picture->SetSurfaceRect(Rect(0,0,width,height)); picture->SetSurfaceFreeFlag(); } + void GrpObj::UpdateDigit(void) { // 画像表示の数値文字列を表示する if (name.length() == 0) return; @@ -546,7 +566,7 @@ void GrpObj::UpdateDigit(void) { string path(name); path += ".g00"; Surface* surface_orig = pic_parent->Root().NewSurface(path.c_str()); - if (surface_orig == 0) return; + if (surface_orig == NULL) return; int width, height; int i; @@ -612,8 +632,9 @@ void GrpObj::UpdateDigit(void) { pic_parent->Root().DeleteSurface(surface_orig); } + void GrpObj::CreateGan(Event::Container& event, int event_number) { - if (picture == 0) { + if (picture == NULL) { fprintf(stderr,"GrpObj::CreateGan() is called before Create()\n"); return; } @@ -626,7 +647,7 @@ void GrpObj::CreateGan(Event::Container& string path(gan_name); path += ".gan"; ARCINFO* info = file_searcher.Find(FILESEARCH::GAN, path.c_str(), "gan"); - if (info == 0) { + if (info == NULL) { fprintf(stderr,"GrpObj::CreateGan: Cannot Find 'GAN' file %s\n", path.c_str()); return; } @@ -678,9 +699,10 @@ void GrpObj::CreateGan(Event::Container& wid->SetPtn(); // パターン登録終了 attr = Attribute(attr | ANM_PLAYSTART); anm = wid; -}; +} + void GrpObj::CreateGanSpecial(Event::Container& event, int event_number, int time) { - if (picture == 0) { + if (picture == NULL) { fprintf(stderr,"GrpObj::CreateGan() is called before Create()\n"); return; } @@ -694,19 +716,18 @@ void GrpObj::CreateGanSpecial(Event::Con int i; switch(event_number) { - case 0: // pattern を 0 から最後まで変化させる - for (i=0; iptns.push_back(AnmAlphaMove::Ptn(Rect(PosX(), PosY()), src_pos[i], 255, time*i)); - } - wid->SetPtn(); // パターン登録終了 - anm = wid; - attr = Attribute(attr | ANM_PLAYSTART); - break; - default: - break; + case 0: // pattern を 0 から最後まで変化させる + for (i=0; iptns.push_back(AnmAlphaMove::Ptn(Rect(PosX(), PosY()), src_pos[i], 255, time*i)); + } + wid->SetPtn(); // パターン登録終了 + anm = wid; + attr = Attribute(attr | ANM_PLAYSTART); + break; + default: + break; } - return; -}; +} void GrpObj::SetZoomRotate(int new_zoom, int new_rotate) { if (zoom == new_zoom && rotate == new_rotate) return; @@ -720,7 +741,6 @@ void GrpObj::SetZoomRotate(int new_zoom, else if (rotate > 360) rotate %= 360; attr = Attribute(attr | UPDATE_PICTURE); - return; } /****************************************************************** ** @@ -746,6 +766,7 @@ ScnGrpMove::ScnGrpMove(Event::Container& if (dx == 0) dx = 1; SetAllCount(dx); } + void ScnGrpMove::Exec(int count) { Rect r(0,0,dest_r.width(),dest_r.height()); int dx = to.lx - from.lx; @@ -766,6 +787,7 @@ struct ScnGrpAnmAtom { int time; ScnGrpAnmAtom(const char* _n, int _t) : name(_n), time(_t) {} }; + struct ScnGrpAnm : public WidAnmTime, vector { GrpImpl& owner; ScnGrpAnm(Event::Container& container, PicBase* _pic, GrpImpl& _owner) : @@ -774,6 +796,7 @@ struct ScnGrpAnm : public WidAnmTime, ve void CalcTotal(void); void Exec(int count); }; + void ScnGrpAnm::CalcTotal(void) { /* total time を計算 */ if (empty()) return; @@ -783,6 +806,7 @@ void ScnGrpAnm::CalcTotal(void) { total_time = tm; SetAllCount(tm); } + void ScnGrpAnm::Exec(int count) { int tm = 0; vector::iterator it; for (it=begin(); it != end(); it++) { @@ -800,7 +824,7 @@ void ScnGrpAnm::Exec(int count) { * */ -#include"music2/music.h" +#include "music2/music.h" GrpImpl::GrpImpl(Event::Container& _event, PicContainer& _parent, const Flags& f, set& _cgm_data, class MuSys& _mu, AyuSysConfig& _config) : event(_event), @@ -869,7 +893,8 @@ Surface* GrpImpl::Dsurface(int pdt) { } return dsurface[pdt]; } -#include + +#include Surface* GrpImpl::Ssurface(int pdt) { if (pdt == 0) return surface; if (ssurface[pdt]) { @@ -884,7 +909,7 @@ void GrpImpl::LoadSurface(const char* st cgm_data.insert(cgm_info[s]); } Surface* bg = parent.Root().NewSurface(s.c_str()); - if (bg == 0) { + if (bg == NULL) { s += ".g00"; bg = parent.Root().NewSurface(s.c_str()); } @@ -899,7 +924,7 @@ void GrpImpl::LoadSurface(const char* st int y = (dr.height()-r.height())/2; DSurfaceMove(ssurface[0], r, surface, Rect(x,y)); parent.Root().DeleteSurface(ssurface[0]); - ssurface[0] = 0; + ssurface[0] = NULL; screen->SetSurface(surface, 0, 0); } } else { @@ -908,8 +933,11 @@ void GrpImpl::LoadSurface(const char* st } return; } + void GrpImpl::InitSel(AyuSysConfig& config) { - int i; int args[16]; char key[1024]; + 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], @@ -930,8 +958,8 @@ void GrpImpl::InitSel(AyuSysConfig& conf s.sel_no = args[7]; int j; for (j=0; j<8; j++) s.args[j] = args[8+j]; } - return; } + void GrpImpl::SetSkipMode(SkipMode _mode) { if ( (skip_mode & SKIP_IN_MENU) && (_mode & SKIP_IN_MENU) == 0) { RefreshObj(); @@ -939,9 +967,11 @@ void GrpImpl::SetSkipMode(SkipMode _mode } skip_mode = _mode; } + void GrpImpl::SetObjChanged(int num) { changed_obj.insert(num); } + void GrpImpl::SetObjChangedGroup(int num) { if (num % 1000 != 0) { SetObjChanged(num); @@ -954,6 +984,7 @@ void GrpImpl::SetObjChangedGroup(int num changed_obj.insert(it->first); } } + void GrpImpl::RefreshObj(void) { if (!deleted_pic.empty()) { vector::iterator it; @@ -990,7 +1021,7 @@ void GrpImpl::RefreshObj(void) { } -#include +#include void GrpImpl::StartAnm(int type) { SEL sel; @@ -1006,11 +1037,11 @@ void GrpImpl::StartAnm(int type) { } else { sel = anmtype[type]; } - if (anm1) { + if (anm1 != NULL) { fprintf(stderr,"Warning: StartAnm() called before anm1 finished\n"); anm1->Abort(); delete anm1; - anm1 = 0; + anm1 = NULL; } map::iterator it; // 現在表示中のobjectを消去 @@ -1073,16 +1104,18 @@ void GrpImpl::StartAnm(int type) { if (anm1) anm1->Play(); if (skip_mode & SKIP_GRP_NOEFFEC) AbortAnm(); } + void GrpImpl::StartShake(int total, const int* pattern) { if (anm2) { fprintf(stderr,"Warning: StartShake() called before another animation finished\n"); anm2->Abort(); delete anm2; - anm2 = 0; + anm2 = NULL; } if (skip_mode & SKIP_GRP_NOEFFEC) return; AnmAlphaMove* new_anm = new AnmAlphaMove(event, &parent); // shake screen では元画面の座標を揺らす - int i; int tm = 0; + int i; + int tm = 0; for (i=0; iPlay(); anm2 = new_anm; } + void GrpImpl::AbortAnm(void) { - if (anm1 == 0) return; + if (anm1 == NULL) return; anm1->Abort(); delete anm1; - anm1 = 0; + anm1 = NULL; /* 画像効果終了 */ /* 古い画面への画像効果があれば消去 */ if (anm2 && anm2->pic[0] != screen) { anm2->Abort(); delete anm2; - anm2 = 0; + anm2 = NULL; } /* pdt1 -> pdt0 へコピー */ DSurfaceMove(dsurface[1], Rect(*dsurface[1]), surface, Rect(0,0)); @@ -1114,26 +1148,29 @@ void GrpImpl::AbortAnm(void) { RefreshObj(); return; } + void GrpImpl::LoadSurface(const char* str) { if (anm1) AbortAnm(); // 前の描画が終わってなければ強制終了 LoadSurface(str, 1); bg_name = str; } + void GrpImpl::LoadSurface(void) { if (anm1) AbortAnm(); // 前の描画が終わってなければ強制終了 LoadSurface(bg_name.c_str(), 1); } + void GrpImpl::AddSurface(const char* str) { if (anm1) AbortAnm(); // 前の描画が終わってなければ強制終了 LoadSurface(bg_name.c_str()); string s = str; Surface* front = parent.Root().NewSurface(s.c_str()); - if (front == 0) { + if (front == NULL) { s += ".g00"; front = parent.Root().NewSurface(s.c_str()); } - if (front) { + if (front != NULL) { parent.Root().BlitSurface(front, Rect(*front), Dsurface(1), Rect(0,0)); parent.Root().DeleteSurface(front); } else { @@ -1147,24 +1184,24 @@ void GrpImpl::CreateObj(int index) { GrpObj& g = grpobj[index]; g.CreateSurface(&parent); g.order = index; - if (g.picture == 0) return; // エラー:surface が存在しない + if (g.picture == NULL) return; // エラー:surface が存在しない g.picture->hide(); SetObjChanged(index); ZMoveObj(index); - return; } + void GrpImpl::ZMoveObj(int index) { std::map::iterator cur = grpobj.find(index); if (cur == grpobj.end()) return; GrpObj& g = grpobj[index]; - if (g.picture == 0) return; + if (g.picture == NULL) return; // 自分より前に object があれば、その前に表示 // そうでなければ screen の前に表示 std::map::iterator cur_backobj = grpobj.end(); std::map::iterator it; for (it = grpobj.begin(); it != grpobj.end(); it++) { if (it == cur) continue; - if (it->second.picture == 0) continue; + if (it->second.picture == NULL) continue; if (it->second.order < g.order) { if (cur_backobj == grpobj.end()) { cur_backobj = it; @@ -1178,8 +1215,8 @@ void GrpImpl::ZMoveObj(int index) { } else { g.picture->ZMove(cur_backobj->second.picture); } - return; } + void GrpImpl::SwapObj(int index1, int index2) { // デフォルト値から order が変更されていた場合のみ、order は保存される // まずは両方のobjectをswap @@ -1221,10 +1258,10 @@ bool GrpImpl::Pressed(int x, int y, void* pointer) { // マウスクリックでキャンセル g->music.StopMovie(); if (g->status == WAIT_ANM) g->AbortAnm(); - if (g->status == WAIT_SHAKE && g->anm2 != 0) { + if (g->status == WAIT_SHAKE && g->anm2 != NULL) { g->anm2->Abort(); delete g->anm2; - g->anm2 = 0; + g->anm2 = NULL; } return false; // event deleted } @@ -1268,9 +1305,9 @@ static unsigned char decode_char[256] = void GrpImpl::LoadCgm(AyuSysConfig& config) { /* cgm ファイル読み込み */ const char* fname = config.GetParaStr("#CGTABLE_FILE"); - if (fname == 0) return; + if (fname == NULL) return; ARCINFO* info = file_searcher.Find(FILESEARCH::ALL, fname, ""); - if (info == 0) return; + if (info == NULL) return; char* data = info->CopyRead(); int sz = info->Size(); delete info; @@ -1282,9 +1319,9 @@ void GrpImpl::LoadCgm(AyuSysConfig& conf } cgm_size = read_little_endian_int(data+0x10); - int i,j; + int i, j; // xor 解除 - for (i=0;iAbort(); delete anm2; - anm2 = 0; + anm2 = NULL; } map::iterator it; for (it=grpobj.begin(); it!=grpobj.end(); it++) { @@ -1330,6 +1368,7 @@ void GrpImpl::Load(const char* str) { bg_name = ""; music.StopCDROM(100); } + void GrpImpl::SaveSys(string& save) { char buf[1024]; save = "\n[Graphics]\n"; @@ -1342,6 +1381,7 @@ void GrpImpl::SaveSys(string& save) { } save += "\n"; } + void GrpImpl::LoadSys(const char* save) { cgm_data.clear(); save = strstr(save, "\n[Graphics]\n"); @@ -1435,15 +1475,15 @@ bool GrpImpl::Wait(unsigned int current_ } #endif if (status == WAIT_ANM) { - if (anm1) { + if (anm1 != NULL) { if (!anm1->IsEnd()) return true; AbortAnm(); } } else if (status == WAIT_SHAKE) { - if (anm2) { + if (anm2 != NULL) { if (!anm2->IsEnd()) return true; delete anm2; - anm2 = 0; + anm2 = NULL; } status = NORMAL; } else if (status == WAIT_SE) { @@ -1457,10 +1497,10 @@ bool GrpImpl::Wait(unsigned int current_ } return true; } - if (anm2) { + if (anm2 != NULL) { if (anm2->IsEnd()) { delete anm2; - anm2 = 0; + anm2 = NULL; } } return false; @@ -1470,11 +1510,13 @@ void GrpImpl::DeleteObjPic(int num) { // object の surface のみ削除 if (grpobj.find(num) == grpobj.end()) return; deleted_pic.push_back(grpobj[num].DeletePic()); } + void GrpImpl::DeleteObj(int num) { if (grpobj.find(num) == grpobj.end()) return; deleted_pic.push_back(grpobj[num].DeletePic()); grpobj.erase(num); } + void GrpImpl::DeleteObjRange(int num_first, int num_end) { std::map::iterator begin,end,it; begin = grpobj.lower_bound(num_first); @@ -1484,6 +1526,7 @@ void GrpImpl::DeleteObjRange(int num_fir } grpobj.erase(begin, end); } + void GrpImpl::Exec(Cmd& cmd) { if (cmd.cmd_type == CMD_TEXTEND) { music.StopKoe(500); // テキスト終了で声を止める @@ -1926,11 +1969,11 @@ void GrpImpl::Exec(Cmd& cmd) { } else if (cmd.cmd2 == 0x49) { if (cmd.cmd3 == 0) { // アニメーションを強制終了 GrpObj& g = grpobj[cmd.args[0].value]; - if (g.anm == 0 || g.anm->IsEnd()) ; + if (g.anm == NULL || g.anm->IsEnd()) ; else g.anm->Abort(); } else if (cmd.cmd3 == 3) { // アニメーション中か? GrpObj& g = grpobj[cmd.args[0].value]; - if (g.anm == 0 || g.anm->IsEnd()) { + if (g.anm == NULL || g.anm->IsEnd()) { cmd.SetSysvar(0); } else { cmd.SetSysvar(1); @@ -1938,7 +1981,7 @@ void GrpImpl::Exec(Cmd& cmd) { } else if (cmd.cmd3 == 1000) { // アニメーションを途中で停止した状態にする GrpObj& g = grpobj[cmd.args[0].value]; - if (g.anm == 0 || g.anm->IsEnd()) { + if (g.anm == NULL || g.anm->IsEnd()) { // fprintf(stderr,"AnimPause : no animation in %d (%d)\n",cmd.args[0].value, cmd.args[1].value); g.SetSurfaceNum(cmd.args[1].value); } else { @@ -2277,7 +2320,8 @@ 487 / 8047 : unsupported command; 0x23 - Grp::Grp(Event::Container& _event, PicContainer& _parent, const Flags& f, set& _cgm,class MuSys& mu, AyuSysConfig& config) { pimpl = new GrpImpl(_event, _parent, f, _cgm, mu, config); -}; +} + Grp::~Grp() { delete pimpl; } @@ -2285,15 +2329,19 @@ Grp::~Grp() { bool Grp::Wait(unsigned int current_time, Cmd& cmd) { return pimpl->Wait(current_time, cmd); } + void Grp::Exec(Cmd& cmd) { pimpl->Exec(cmd); } + void Grp::SetSkipMode(SkipMode mode) { pimpl->SetSkipMode(mode); } + void Grp::InitSel(AyuSysConfig& config) { pimpl->InitSel(config); } + void Grp::Save(std::string& str) { pimpl->Save(str); } diff --git a/scn2k/scn2k_impl.cc b/scn2k/scn2k_impl.cc --- a/scn2k/scn2k_impl.cc +++ b/scn2k/scn2k_impl.cc @@ -26,11 +26,11 @@ */ #include -#include"scn2k_impl.h" -#include"system/file.h" -#include"system/system_config.h" -#include"window/picture.h" -#include"window/system.h" +#include "scn2k_impl.h" +#include "system/file.h" +#include "system/system_config.h" +#include "window/picture.h" +#include "window/system.h" // #define DEBUG 1 @@ -56,13 +56,13 @@ Scn2k::Scn2k(Event::Container& _event, P system_version = 0; skip_mode = SKIP_NO; - script_start = 0; - script = 0; - script_end = 0; + script_start = NULL; + script = NULL; + script_end = NULL; backlog_script_scn = -1; - backlog_script_start = 0; - backlog_script_end = 0; + backlog_script_start = NULL; + backlog_script_end = NULL; save_scn = 0; save_point = 0; @@ -70,14 +70,14 @@ Scn2k::Scn2k(Event::Container& _event, P scn_point = 0; cmd_stack_str = cmd_stack_str_orig; - dialog = 0; + dialog = NULL; dialog_type = CMD_NOP; - menu = 0; + menu = NULL; menu_mouseshown = false; /* マウスカーソルを作成 */ mouse_type = 0; - mouse_surface = 0; + mouse_surface = NULL; mouse_pressed = 0; ShowCursor(); @@ -101,7 +101,7 @@ char* Scn2k::OpenScript(int new_scn_numb sprintf(fname, "SEEN%04d.TXT", new_scn_number); ARCINFO* info = file_searcher.Find(FILESEARCH::SCN, fname, ""); - if (info == 0) goto err; + if (info == NULL) goto err; data = info->Read(); /* version 確認 */ @@ -141,15 +141,16 @@ err: return false; } + bool Scn2k::ChangeScript(int new_scn_number, int call_no) { int old_scn_number = scn_number; int old_scn_pt = script - script_start; int scn_pt = 0; if (script_start) delete[] script_start; - script_start = 0; - script = 0; - script_end = 0; + script_start = NULL; + script = NULL; + script_end = NULL; int call_vec[100]; @@ -176,9 +177,10 @@ bool Scn2k::ChangeScript(int new_scn_num fprintf(stderr,"scn %d pt %d: Cannot jump to %d:%d; fall back to the top\n",old_scn_number, old_scn_pt, scn_number, scn_pt); return true; } + bool Scn2k::ReadCmdAt(Cmd& cmd, int scn, int pt) { const char* d; - if (scn ==scn_number) { + if (scn == scn_number) { d = script_start + pt; if (d < script_start || d >= script_end) { fprintf(stderr,"Cannot read script at current scn %d pt %d\n", scn, pt); @@ -205,7 +207,7 @@ extern bool pressAreq; void Scn2k::Elapsed(unsigned int current_time) { SetWakeup(current_time + 10); // 10msに一回シナリオスクリプト解釈 - if (script == 0) return; + if (script == NULL) return; //VarInfo info; info.type = 6; info.number = 0; // PB の「一回ゲームを開始したことがある」フラグ //flag.Set(info,1); //info.type = 0; info.number = 604; // Princess Bride: クリア対象設定フラグ (聖) @@ -276,7 +278,8 @@ if (0) { fprintf(stderr,"%d / %d : 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", scn_point, script_end-script_start, cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); - int i; for (i=0; i fall back to %d\n",s } break; } + if (cmd.cmd_type == CMD_NOP) continue; if (cmd.cmd_type == CMD_TEXT && cmd.pos != -1) { @@ -366,7 +370,8 @@ fprintf(stderr," -> fall back to %d\n",s fprintf(stderr,"%d-%d / %d : unsupported command; 0x23 - cmd %02x-%02x:%04x:%02x[%2d] \n", cmd.scn, script - script_start, script_end-script_start, cmd.cmd1,cmd.cmd2,cmd.cmd3,cmd.cmd4,cmd.argc); - int i; for (i=0; i fall back to %d\n",s cmd.clear(); } } - return; } void Scn2k::ShowCursor(void) { @@ -387,11 +391,11 @@ void Scn2k::ShowCursor(void) { char key[1024]; sprintf(key, "#MOUSE_CURSOR.%03d.NAME",mouse_type); const char* name = config.GetParaStr(key); - if (name == 0 || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR; + if (name == NULL || name[0] == 0) mouse_surface = DEFAULT_MOUSECURSOR; else { mouse_surface = parent.Root().NewSurface(name, COLOR_MASK); } - if (mouse_surface == 0) mouse_surface = DEFAULT_MOUSECURSOR; + if (mouse_surface == NULL) mouse_surface = DEFAULT_MOUSECURSOR; System::Main::SetCursor(mouse_surface, Rect(8, 8, 8+32, 8+32)); } @@ -400,18 +404,16 @@ void Scn2k::HideCursor(void) { System::Main::SetCursor(0, Rect(0,0)); if (mouse_surface != DEFAULT_MOUSECURSOR) parent.Root().DeleteSurface(mouse_surface); - mouse_surface = 0; + mouse_surface = NULL; } - return; } bool Scn2k::SysWait(Cmd& cmd) { - if (menu) { menu->Exec(cmd); - if (menu->status & Scn2kMenu::MENU_DELETE || menu->pimpl == 0) { + if (menu->status & Scn2kMenu::MENU_DELETE || menu->pimpl == NULL) { delete menu; - menu = 0; + menu = NULL; if (! menu_mouseshown) HideCursor(); else ShowCursor(); SetSkipMode(SkipMode(skip_mode & (~SKIP_IN_MENU) )); @@ -700,7 +702,7 @@ void Scn2k::SysExec(Cmd& cmd) { } } else if (cmd.cmd1 == 2 && cmd.cmd2 == 1 && cmd.cmd3 == 12) { // DLL Call const char* regname = config.GetParaStr("#REGNAME"); - const char key_lb[] = "KEY\\LittleBusters"; + const char key_lb[] = "KEY\\LittleBusters";//FIXME: too specific to be here? if (strcmp(regname, key_lb) == 0) { DllCall_LB(cmd, flag); cmd.clear(); @@ -715,10 +717,10 @@ void Scn2k::SysExec(Cmd& cmd) { } else if (cmd.cmd1 == 1 && cmd.cmd2 == 0x04) { if (cmd.cmd3 == 0 && cmd.cmd4 == 0) { // タイトル名設定 const char* name = cmd.Str(cmd.args[0]); - if (name == 0) name = ""; + if (name == NULL) name = ""; window_title = name; const char* config_name = config.GetParaStr("#CAPTION"); - if (config_name == 0) config_name = ""; + if (config_name == NULL) config_name = ""; string setname = kconv(string(config_name) + " " + window_title); parent.Root().SetWindowCaption(setname.c_str()); cmd.clear(); @@ -751,7 +753,7 @@ void Scn2k::SysExec(Cmd& cmd) { cmd.clear(); } else if (cmd.cmd3 == 0x4b0) { // 終了 System::Main::Quit(); - //script = 0; script_start = 0; script_end = 0; + //script = NULL; script_start = NULL; script_end = NULL; cmd.clear(); cmd.cmd_type = CMD_WAITFRAMEUPDATE; } else if (cmd.cmd3 == 0x4b4 || cmd.cmd3 == 0x4b5) { // 選択肢巻き戻し @@ -824,10 +826,10 @@ fprintf(stderr,"StatSave %d:",cmd.args[0 } -#include -#include -#include -#include +#include +#include +#include +#include // セーブファイルの名前をつくる string Scn2k::MakeSaveFile(void) const { @@ -836,7 +838,7 @@ string Scn2k::MakeSaveFile(void) const { if (dir.c_str()[0] == '~' && dir.c_str()[1] == '/') { char* home = getenv("HOME"); - if (home != 0) { + if (home != NULL) { string new_dir = string(home) + (dir.c_str()+1); dir = new_dir; } @@ -871,6 +873,7 @@ string Scn2k::MakeSaveFile(void) const { delete[] fname; return dir; } + // セーブファイルの名前をつくる string Scn2kSaveTitle::operator() (int number) const { int y,m,d,wd,h,min,sec,msec; @@ -882,14 +885,15 @@ string Scn2kSaveTitle::operator() (int n sprintf(buf, "%2d/%2d %2d:%2d ",m,d,h,min); return string(buf) + title; } -}; +} void Scn2k::SaveSys(void) { char buf[1024]; string save; string path = MakeSaveFile(); - sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); save += buf; + sprintf(buf, "KEY=%s\n", config.GetParaStr("#REGNAME")); + save += buf; string save_config; config.DiffOriginal(save_config); save += "CONFIG="; @@ -917,7 +921,7 @@ void Scn2k::SaveSys(void) { path += ".0"; FILE* f = fopen(path.c_str(), "w"); - if (f == 0) { + if (f == NULL) { fprintf(stderr,"Cannot open save file %s\n",path.c_str()); return; } @@ -931,12 +935,12 @@ void Scn2k::LoadSys(void) { string path = MakeSaveFile(); path += ".0"; FILE* f = fopen(path.c_str(), "r"); - if (f == 0) { + if (f == NULL) { fprintf(stderr, "Cannot open save file %s\n",path.c_str()); } else { - fseek(f,0,2); + fseek(f, 0, SEEK_END); int sz = ftell(f); - fseek(f,0,0); + fseek(f, 0, SEEK_SET); char* savedata = new char[sz+1]; fread(savedata, sz, 1, f); savedata[sz] = 0; @@ -1027,7 +1031,7 @@ bool Scn2k::StatSaveFile(int num, int& y msec = 0; /* タイトルの取得 */ FILE* savefile = fopen(path.c_str(), "rb"); - if (savefile == 0) return false; + if (savefile == NULL) return false; char regname[1024]; sprintf(regname, "KEY=%s\n", config.GetParaStr("#REGNAME")); fgets(buf,1000,savefile); @@ -1090,7 +1094,7 @@ void Scn2k::LoadRollback(Cmd& cmd) { void Scn2k::Save(Cmd& cmd) { if (cmd.cmd_type == CMD_SAVEREQ) { - if (menu == 0) { + if (menu == NULL) { SetSkipMode(SKIP_IN_MENU); // テキストスキップ等はここで中断 menu = new Scn2kMenu(Scn2kMenu::MENU_SAVE, *this, flag, text_exec, system_version); menu->InitPanel(event, parent); @@ -1103,7 +1107,7 @@ void Scn2k::Save(Cmd& cmd) { } char buf[1024]; string save; - FILE* f = 0; + FILE* f = NULL; if (save_scn == 0) { fprintf(stderr,"Cannot decide save point\n"); return; // セーブ位置が保存されてない @@ -1138,7 +1142,7 @@ void Scn2k::Save(Cmd& cmd) { } f = fopen(path.c_str(), "w"); - if (f == 0) { + if (f == NULL) { fprintf(stderr,"Cannot open save file %s\n",path.c_str()); return; } @@ -1146,12 +1150,11 @@ void Scn2k::Save(Cmd& cmd) { fclose(f); config.SetParam("#LASTSAVE", 1, file_number); cmd.clear(); - return; } void Scn2k::Load(Cmd& cmd) { if (cmd.cmd_type == CMD_LOADREQ) { - if (menu == 0) { + if (menu == NULL) { menu = new Scn2kMenu(Scn2kMenu::MENU_LOAD, *this, flag, text_exec, system_version); menu->InitPanel(event, parent); menu->InitTitle(Scn2kSaveTitle(*this)); @@ -1169,16 +1172,16 @@ void Scn2k::Load(Cmd& cmd) { file_number = cmd.args[0].value + 1; sprintf(buf, ".%d",file_number); path += buf; - FILE* f = 0; + FILE* f = NULL; if (file_number > 0) f = fopen(path.c_str(), "r"); - if (f == 0) { + if (f == NULL) { fprintf(stderr, "Cannot open save file %s\n",path.c_str()); return; } - fseek(f,0,2); + fseek(f, 0, SEEK_END); int sz = ftell(f); - fseek(f,0,0); + fseek(f, 0, SEEK_SET); char* savedata = new char[sz+1]; fread(savedata, sz, 1, f); savedata[sz] = 0; @@ -1197,10 +1200,10 @@ void Scn2k::Load(Cmd& cmd) { rollback_save.clear(); new_rollback_save = ""; char* rollback_data = savedata; - while( (rollback_data = strstr(rollback_data,"[Rollback Data]\n")) != 0) { + while( (rollback_data = strstr(rollback_data,"[Rollback Data]\n")) != NULL) { rollback_data += strlen("[Rollback Data]\n"); char* rollback_end = strstr(rollback_data, "[Rollback End]\n"); - if (rollback_end == 0) rollback_end = rollback_data + strlen(rollback_data); + if (rollback_end == NULL) rollback_end = rollback_data + strlen(rollback_data); string s(rollback_data, rollback_end); rollback_save.push_back(s); rollback_data = rollback_end; @@ -1219,7 +1222,6 @@ void Scn2k::Load(Cmd& cmd) { cmd.clear(); delete[] savedata; - return; } void Scn2k::SaveImpl(string& save) { @@ -1261,7 +1263,7 @@ void Scn2k::LoadImpl(const char* save) { cmd_stack_str = cmd_stack_str_orig; save = strstr(save, "\n[SCENARIO]\n"); - if (save == 0) return; + if (save == NULL) return; save += strlen("\n[SCENARIO]\n"); while(save[0] != 0 && save[0] != '[') { // while next section start if (strncmp(save, "Scn=", 4) == 0) { @@ -1271,10 +1273,10 @@ void Scn2k::LoadImpl(const char* save) { } else if (strncmp(save, "Title=", 6) == 0) { save += 6; char* s = strchr(save, '\n'); - if (s == 0) window_title = save; + if (s == NULL) window_title = save; else window_title.assign(save, s-save); const char* config_name = config.GetParaStr("#CAPTION"); - if (config_name == 0) config_name = ""; + if (config_name == NULL) config_name = ""; string setname = kconv(string(config_name)+" "+window_title); parent.Root().SetWindowCaption(setname.c_str()); } else if (strncmp(save, "MouseType=", 10) == 0) { @@ -1291,7 +1293,7 @@ void Scn2k::LoadImpl(const char* save) { } else if (strncmp(save, "StackStr=", 9) == 0) { save += 9; char* s = strchr(save, '\n'); - if (s == 0) stack_strbuffer.push_back(""); + if (s == NULL) stack_strbuffer.push_back(""); else stack_strbuffer.push_back(string(save, s-save)); } else if (strncmp(save, "Cmd=", 4) == 0) { CmdSimplified cmd; @@ -1304,12 +1306,12 @@ void Scn2k::LoadImpl(const char* save) { cmd_stack.push_back(cmd); } save = strchr(save, '\n'); - if (save != 0) save++; + if (save != NULL) save++; } ChangeScript(save_scn, 0); script = script_start + save_point; - return; } + void Scn2k::SetSkipMode(SkipMode mode) { if (skip_mode != mode) { skip_mode = mode; @@ -1349,12 +1351,14 @@ void DLLCall_LB_EF00_0(Cmd& cmd, Flags& flags) { // エフェクトの設定 } } if (cmd.args[5].value != 1) return; -static int random_dirtable[] = { + + static int random_dirtable[] = { 0, 2, 1, 3, 0, 2, 1, 3, 1, 3, 2, 0, 1, 3, 2, 0, 0, 0, 0, 0, 3, 1, 2, 0, 3, 1, 3, 1, 0, 2, 3, 1 }; + int* dir = &random_dirtable[(random()&3) * 8]; for (i=0; i<8; i++) { double* param = lb_ef_param + i*0x60; @@ -1394,6 +1398,7 @@ static int random_dirtable[] = { } return; } + void DLLCall_LB_EF00_1(Cmd& cmd, Flags& flags) { // 計算を行う if (lb_ef_param == 0) { fprintf(stderr,"Warning : DLLCall_LB_EF00_1 : Script error : effect calculation was called before setting\n"); @@ -1457,8 +1462,8 @@ void DllCall_LB(Cmd& cmd, Flags& flags) { // リトルバスターズ!の EF00.dll をエミュレート ** */ -#include"window/widget.h" -#include"window/menuitem.h" +#include "window/widget.h" +#include "window/menuitem.h" void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a = 0xff); @@ -1473,13 +1478,13 @@ struct Scn2kMenuImpl { virtual void Cancel(void) = 0; virtual void Exec(Cmd& cmd) = 0; Scn2kMenuImpl(Scn2kMenu& _interface) : interface(_interface) { - menu = 0; - pevent = 0; - pparent = 0; + menu = NULL; + pevent = NULL; + pparent = NULL; } virtual ~Scn2kMenuImpl() { if (menu) delete menu; - menu = 0; + menu = NULL; } }; @@ -1509,13 +1514,13 @@ struct LoadMenu : Scn2kMenuImpl { void PressOk(void); }; LoadMenu::LoadMenu(Scn2kMenu& _interface) : Scn2kMenuImpl(_interface) { - btn_local = 0; - btn_scale = 0; - btn_set = 0; + btn_local = NULL; + btn_scale = NULL; + btn_set = NULL; btn_page_val = 0; btn_set_val = -1; btn_local_val = -1; - awk_dialog = 0; + awk_dialog = NULL; in_setpage = false; select_page = 0; select_value = -1; @@ -1528,7 +1533,7 @@ void LoadMenu::InitPanel(Event::Containe pparent = &parent; if (menu) delete menu; - menu = 0; + menu = NULL; menu = new MenuItem(&parent, Rect(80,30,560, 450), 1, 3, 0); Surface* surface = parent.Root().NewSurface(menu->Pic()->Width(), menu->Pic()->Height(), ALPHA_MASK); if (interface.type == Scn2kMenu::MENU_LOAD) { @@ -1674,16 +1679,16 @@ void LoadMenu::SetPage(int new_page) { btn_local->item[i]->Pic()->Move(old_x, i*30-new_point*3); } } - if (btn_page) { + if (btn_page != NULL) { if (select_page%100 == 0) btn_page->SetValue(select_page/100); else btn_page->SetValue(-1); } - if (btn_scale) { + if (btn_scale != NULL) { btn_scale->SetValue(select_page); } in_setpage = false; - return; } + void LoadMenu::SetValue(int new_value) { if (in_setpage) return; in_setpage = true; @@ -1706,8 +1711,8 @@ void LoadMenu::SetValue(int new_value) { } in_setpage = false; - return; } + void LoadMenu::PressOk(void) { if (select_value == -1) { btn_set->SetValue(-1); // なにもしない @@ -1732,26 +1737,31 @@ void LoadMenu::PressOk(void) { } } } + void LoadMenu::Cancel(void) { - if (awk_dialog) { // ダイアログのキャンセル + if (awk_dialog != NULL) { // ダイアログのキャンセル awk_dialog->status = Dialog::CANCEL; ChangeDialog(this, awk_dialog); } else { // 一般キャンセル btn_set->SetValue(1); } } + void LoadMenu::Exec(Cmd& cmd) { } + void LoadMenu::ChangeBtnPage(void* pointer, MenuItem* widget) { LoadMenu* instance = (LoadMenu*)pointer; if (instance->btn_page_val == -1) return; instance->SetPage(instance->btn_page_val*100); } + void LoadMenu::ChangeBtnScale(void* pointer, Scale* from) { LoadMenu* instance = (LoadMenu*)pointer; int value = from->GetValue(); instance->SetPage(value); } + void LoadMenu::ChangeBtnSet(void* pointer, MenuItem* widget) { LoadMenu* instance = (LoadMenu*)pointer; if (instance->btn_set_val == 1) { // cancel @@ -1761,12 +1771,13 @@ void LoadMenu::ChangeBtnSet(void* pointe instance->PressOk(); } } + void LoadMenu::ChangeDialog(void* pointer, Dialog* widget) { LoadMenu* instance = (LoadMenu*)pointer; if (widget->status == Dialog::CANCEL) { // ダイアログ消去、OK ボタン復帰 delete instance->awk_dialog; - instance->awk_dialog = 0; + instance->awk_dialog = NULL; instance->menu->activate(); instance->btn_set->SetValue(-1); return; @@ -1775,6 +1786,7 @@ void LoadMenu::ChangeDialog(void* pointe return; } } + void LoadMenu::ChangeBtnLocal(void* pointer, MenuItem* widget) { LoadMenu* instance = (LoadMenu*)pointer; if (instance->btn_local_val == -1) return; @@ -1793,21 +1805,26 @@ struct BacklogMenu : Scn2kMenuImpl { void Cancel(void); void Exec(Cmd& cmd); }; + BacklogMenu::BacklogMenu(Scn2kMenu& _interface, Scn2k& _scn, Text& parent_text_exec) : Scn2kMenuImpl(_interface), scn_impl(_scn), text_exec(parent_text_exec) { backlog_cnt = -1; backlog_update = false; } + BacklogMenu::~BacklogMenu() { } + void BacklogMenu::InitPanel(Event::Container& event, PicContainer& parent) { pevent = &event; } void BacklogMenu::InitTitle(const SaveTitle& title_op) { } + void BacklogMenu::Cancel(void) { interface.status = Scn2kMenu::MenuStatus(Scn2kMenu::MENU_DELETE); } + void BacklogMenu::Exec(Cmd& cmd) { int command_direction = 0; // forward if (cmd.cmd_type == CMD_NOP) text_exec.Wait(0xffffffffUL, cmd); @@ -1874,7 +1891,7 @@ retry: Scn2kMenu::Scn2kMenu(MenuType _type, Scn2k& scn_impl, const Flags& flags, Text& text_exec, int system_version) : cmd(flags, system_version), type(_type) { - pimpl = 0; + pimpl = NULL; status = MENU_CONTINUE; switch(type) { case MENU_LOAD: pimpl = new LoadMenu(*this); break; @@ -1885,19 +1902,23 @@ Scn2kMenu::Scn2kMenu(MenuType _type, Scn } Scn2kMenu::~Scn2kMenu() { if (pimpl) delete pimpl; - pimpl = 0; + pimpl = NULL; } + void Scn2kMenu::InitPanel(Event::Container& event, PicContainer& parent) { - if (pimpl) pimpl->InitPanel(event, parent); + if (pimpl != NULL) pimpl->InitPanel(event, parent); } + void Scn2kMenu::InitTitle(const SaveTitle& t) { - if (pimpl) pimpl->InitTitle(t); + if (pimpl != NULL) pimpl->InitTitle(t); } + void Scn2kMenu::Cancel(void) { if (pimpl) pimpl->Cancel(); } + void Scn2kMenu::Exec(Cmd& ret_cmd) { - if (pimpl == 0) return; + if (pimpl == NULL) return; pimpl->Exec(ret_cmd); if (pimpl->pevent->presscount(MOUSE_RIGHT)) { Cancel(); @@ -1911,10 +1932,12 @@ void Scn2kMenu::Exec(Cmd& ret_cmd) { ret_cmd.read(tmp_cmd); } } + void Scn2kMenu::activate(void) { - if (pimpl && pimpl->menu) pimpl->menu->activate(); -} -void Scn2kMenu::deactivate(void) { - if (pimpl && pimpl->menu) pimpl->menu->deactivate(); + if (pimpl != NULL && pimpl->menu) pimpl->menu->activate(); } +void Scn2kMenu::deactivate(void) { + if (pimpl != NULL && pimpl->menu) pimpl->menu->deactivate(); +} + diff --git a/scn2k/scn2k_impl.h b/scn2k/scn2k_impl.h --- a/scn2k/scn2k_impl.h +++ b/scn2k/scn2k_impl.h @@ -28,13 +28,13 @@ #ifndef __SCN2k_IMPL_H__ #define __SCN2k_IMPL_H__ -#include"scn2k.h" -#include"window/widget.h" -#include"window/event.h" -#include -#include -#include -#include +#include "scn2k.h" +#include "window/widget.h" +#include "window/event.h" +#include +#include +#include +#include struct StackItem { int scn_number; @@ -70,76 +70,81 @@ struct Scn2kSaveTitle : SaveTitle { }; class Scn2k : Event::Time { - Event::Container& event; - PicContainer& parent; - AyuSysConfig& config; - WidMouseCursor* mcursor; - Flags flag; - Text text_exec; - Grp grp_exec; - int system_version; - SkipMode skip_mode; - int scn_number; - int scn_point; - enum {SCN_INFO=999999, SCN_INFO_MENU=10000001, SCN_INFO_LOCALS = 10000100, SCN_INFO_LOCALSTR = 10000200, SCN_INFO_RETSTR = 10000300}; // stack に積まれる特殊な番号 - - int save_scn, save_point; + private: + Event::Container& event; + PicContainer& parent; + AyuSysConfig& config; + WidMouseCursor* mcursor; + Flags flag; + Text text_exec; + Grp grp_exec; + int system_version; + SkipMode skip_mode; + int scn_number; + int scn_point; + enum { + SCN_INFO = 999999, SCN_INFO_MENU = 10000001, + SCN_INFO_LOCALS = 10000100, SCN_INFO_LOCALSTR = 10000200, + SCN_INFO_RETSTR = 10000300 + }; // stack に積まれる特殊な番号 - char* script_start; - char* script_end; - const char* script; + int save_scn, save_point; - int backlog_script_scn; - char* backlog_script_start; - char* backlog_script_end; + char* script_start; + char* script_end; + const char* script; + + int backlog_script_scn; + char* backlog_script_start; + char* backlog_script_end; - std::string window_title; - std::vector stack; - std::vector stack_strbuffer; - std::vector cmd_stack; - std::vector rollback_save; - std::string new_rollback_save; - std::map > text_readflag; - char* cmd_stack_str; - char cmd_stack_str_orig[32768]; + std::string window_title; + std::vector stack; + std::vector stack_strbuffer; + std::vector cmd_stack; + std::vector rollback_save; + std::string new_rollback_save; + std::map > text_readflag; + char* cmd_stack_str; + char cmd_stack_str_orig[32768]; - Cmdtype dialog_type; - class WidDialog* dialog; - Scn2kMenu* menu; - bool menu_mouseshown; + Cmdtype dialog_type; + class WidDialog* dialog; + Scn2kMenu* menu; + bool menu_mouseshown; - Surface* mouse_surface; - int mouse_type; - int mouse_pressed; - void ShowCursor(); - void HideCursor(); + Surface* mouse_surface; + int mouse_type; + int mouse_pressed; + void ShowCursor(); + void HideCursor(); - void SetSkipMode(SkipMode mode); + void SetSkipMode(SkipMode mode); - virtual void Elapsed(unsigned int current_time); + virtual void Elapsed(unsigned int current_time); - // セーブ関連 - std::string MakeSaveFile(void) const; - bool StatSaveFile(int num, int& year, int& month, int& day, int& wday, int& hour,int& min, int& sec, int& msec, std::string& title) const; - void SaveImpl(std::string& s); - void LoadImpl(const char* s); - void Save(Cmd& cmd); - void Load(Cmd& cmd); - void SaveRollback(void); - void LoadRollback(Cmd& cmd); - void SaveSys(void); - void LoadSys(void); -public: - Scn2k(Event::Container& _event, PicContainer& _parent, class MuSys& mu, AyuSysConfig& config); - ~Scn2k(); - static char* OpenScript(int scn_number, char*& end, int* call_vec, int& system_version); - bool ChangeScript(int scn_number, int call_no); - bool ReadCmdAt(Cmd& cmd, int scn, int pt); - void show_textwindow(int type); - void hide_textwindow(void); - void SysExec(Cmd& cmd); - bool SysWait(Cmd& cmd); + // セーブ関連 + std::string MakeSaveFile(void) const; + bool StatSaveFile(int num, int& year, int& month, int& day, int& wday, int& hour,int& min, int& sec, int& msec, std::string& title) const; + void SaveImpl(std::string& s); + void LoadImpl(const char* s); + void Save(Cmd& cmd); + void Load(Cmd& cmd); + void SaveRollback(void); + void LoadRollback(Cmd& cmd); + void SaveSys(void); + void LoadSys(void); + public: + Scn2k(Event::Container& _event, PicContainer& _parent, class MuSys& mu, AyuSysConfig& config); + ~Scn2k(); + static char* OpenScript(int scn_number, char*& end, int* call_vec, int& system_version); + bool ChangeScript(int scn_number, int call_no); + bool ReadCmdAt(Cmd& cmd, int scn, int pt); + void show_textwindow(int type); + void hide_textwindow(void); + void SysExec(Cmd& cmd); + bool SysWait(Cmd& cmd); - friend struct Scn2kSaveTitle; + friend struct Scn2kSaveTitle; }; #endif diff --git a/scn2k/scn2k_text.cc b/scn2k/scn2k_text.cc --- a/scn2k/scn2k_text.cc +++ b/scn2k/scn2k_text.cc @@ -55,14 +55,14 @@ DONE: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include"window/event.h" -#include"window/picture.h" -#include"window/widget.h" -#include"system/file.h" -#include"system/system_config.h" -#include"scn2k.h" +#include "window/event.h" +#include "window/picture.h" +#include "window/widget.h" +#include "system/file.h" +#include "system/system_config.h" +#include "scn2k.h" -#include +#include using namespace std; // kanji conv : デバッグ表示用 @@ -95,11 +95,21 @@ struct TextWindow { PicBase* face_pics[8]; TextWindow(PicContainer& parent, Event::Container& event, int window_no, const AyuSysConfig& config, void* callback); ~TextWindow() { - if (name_container) delete name_container; - int i; for (i=0; i<8; i++) { - if (face_pics[i]) delete face_pics[i]; + if (name_container != NULL) { + delete name_container; + name_container = NULL; } - if (wid) delete wid; + int i; + for (i=0; i<8; i++) { + if (face_pics[i] != NULL) { + delete face_pics[i]; + face_pics[i] = NULL; + } + } + if (wid != NULL) { + delete wid; + wid = NULL; + } } Rect WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config); void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, const AyuSysConfig& config, void* callback); @@ -154,86 +164,88 @@ struct TextWindow { }; class TextImpl { -private: -public: - TextWindow* text; - typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2, WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5, WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7, - WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12, - WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512, - CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12), - SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15), BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17), - ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK) - } Status; - Status status, status_saved, status_mask; -private: - std::string ruby_text; - bool ruby_text_flag; - unsigned int wait_time; - unsigned int old_time; - unsigned int base_time; - int text_window_number; - bool text_parsing; - TextStream text_stream; - SkipMode skip_mode; - int save_selectcount; + public: + TextWindow* text; + typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2, + WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5, + WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7, + WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12, + WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512, + CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12), + SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15), + BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17), + ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK) + } Status; + Status status, status_saved, status_mask; + private: + std::string ruby_text; + bool ruby_text_flag; + unsigned int wait_time; + unsigned int old_time; + unsigned int base_time; + int text_window_number; + bool text_parsing; + TextStream text_stream; + SkipMode skip_mode; + int save_selectcount; - std::map timer_var; - std::vector selects; - std::vector sel_backlog_pos; - string replace_name[26]; - string replace_name2[26]; - PicContainer* sel_widget; - PicWidget* backlog_widget; + std::map timer_var; + std::vector selects; + std::vector sel_backlog_pos; + string replace_name[26]; + string replace_name2[26]; + PicContainer* sel_widget; + PicWidget* backlog_widget; - vector& backlog; - BacklogItem& backlog_item; - BacklogItem cur_backlog_item; - BacklogItem drawn_backlog_item; + vector& backlog; + BacklogItem& backlog_item; + BacklogItem cur_backlog_item; + BacklogItem drawn_backlog_item; -public: - PicContainer& parent; - Event::Container& event; - AyuSysConfig& config; -private: - TextWindow* widgets[32]; - WidTimeCursor* kcursor; - Surface* sel_bg1; - Surface* sel_bg2; - Rect sel_bg_rect; + public: + PicContainer& parent; + Event::Container& event; + AyuSysConfig& config; + private: + TextWindow* widgets[32]; + WidTimeCursor* kcursor; + Surface* sel_bg1; + Surface* sel_bg2; + Rect sel_bg_rect; - void SetCursor(int num); - VarInfo wait_savedvar[2]; + void SetCursor(int num); + VarInfo wait_savedvar[2]; -public: - void AddText(const char* str); + public: + void AddText(const char* str); - static void PressFuncSkip(void* pointer, WidButton* from); - static void PressFuncLoad(void* pointer, WidButton* from); - static void PressFuncSave(void* pointer, WidButton* from); - static void PressFuncBacklog(void* pointer, WidButton* from); - static void PressFuncBacklogFwd(void* pointer, WidButton* from); -private: - static void PressFuncButton(void* pointer, WidButton* from); - static bool PressFunc(int x, int y, void* pointer); + static void PressFuncSkip(void* pointer, WidButton* from); + static void PressFuncLoad(void* pointer, WidButton* from); + static void PressFuncSave(void* pointer, WidButton* from); + static void PressFuncBacklog(void* pointer, WidButton* from); + static void PressFuncBacklogFwd(void* pointer, WidButton* from); + private: + static void PressFuncButton(void* pointer, WidButton* from); + static bool PressFunc(int x, int y, void* pointer); -public: - TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector& parent_backlog, BacklogItem& parent_backlog_item); - ~TextImpl(); - void InitWindow(void); - void SetWindowColor(int r, int g, int b, int a, bool is_transparent); - void SetTextSpeed(int new_speed); - void SetTextWait(int new_wait); - void CreateSelect(Cmd& cmd); - void Exec(Cmd& cmd); - bool Wait(unsigned int current_time, Cmd& cmd); - void hide(void); - void show(void) { show(text_window_number); } - void show(int num); - void DrawBacklog(BacklogItem& item, Cmd& cmd); - void Save(std::string& str, bool select_save); - void Load(const char* str); - void SetSkipMode(SkipMode _mode); - void CreateSelBG(void); + public: + TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector& parent_backlog, BacklogItem& parent_backlog_item); + ~TextImpl(); + void InitWindow(void); + void SetWindowColor(int r, int g, int b, int a, bool is_transparent); + void SetTextSpeed(int new_speed); + void SetTextWait(int new_wait); + void CreateSelect(Cmd& cmd); + void Exec(Cmd& cmd); + bool Wait(unsigned int current_time, Cmd& cmd); + void hide(void); + void show(void) { show(text_window_number); } + void show(int num); + void DrawBacklog(BacklogItem& item, Cmd& cmd); + void Save(std::string& str, bool select_save); + void Load(const char* str); + void SetSkipMode(SkipMode _mode); + void CreateSelBG(void); }; /**************************************************************:: @@ -310,7 +322,7 @@ void TextImpl::SetSkipMode(SkipMode _mod if (status_mask & BACKLOG_WAIT_MASK) { // backlog mode から復帰 status_mask = Status(status_mask & (~(BACKLOG_MASK|BACKLOG_MASK_FWD|BACKLOG_MASK_KOE|BACKLOG_WAIT_MASK))); text->wid->Clear(); - if (status == WAIT_TEXT && text != 0) { + if (status == WAIT_TEXT && text != NULL) { text->StartText(text_stream); text->ShowFace(backlog_item.face.c_str()); text->wid->Flush(); @@ -337,8 +349,8 @@ void TextImpl::SetSkipMode(SkipMode _mod } /* hash_map が欲しい……*/ -#include -#include +#include +#include struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う map facetonum; typedef pair Node; @@ -389,6 +401,7 @@ struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う return ""; } }; + int SaveFaceHash::size_max = 20; void TextImpl::Save(string& str, bool rollback_save) { @@ -463,20 +476,21 @@ void TextImpl::Save(string& str, bool ro } return; } + void TextImpl::Load(const char* str) { if (text) text->wid->Clear(); hide(); text_window_number = 0; save_selectcount = 0; - if (sel_widget) { + if (sel_widget != NULL) { selects.clear(); sel_backlog_pos.clear(); delete sel_widget; - sel_widget = 0; + sel_widget = NULL; } - if (backlog_widget) { + if (backlog_widget != NULL) { delete backlog_widget; - backlog_widget = 0; + backlog_widget = NULL; } status = NORMAL; status_mask = NORMAL; @@ -499,7 +513,7 @@ void TextImpl::Load(const char* str) { str = strend; strend = strchr(str, '\n'); - if (strend == 0) strend = str + strlen(str); + if (strend == NULL) strend = str + strlen(str); else strend++; if (str[0] == '[') break; // next section @@ -524,15 +538,15 @@ void TextImpl::Load(const char* str) { int n = -1; sscanf(str+8, "%d", &n); /* not used */ const char* next_str = strchr(str, ';'); - while(next_str != 0 && next_str < strend) { + while(next_str != NULL && next_str < strend) { str = next_str + 1; next_str = strchr(str, ';'); - if (next_str == 0) next_str = strend; + if (next_str == NULL) next_str = strend; BacklogItem item; if (str[0] == '"') { const char* send = strchr(str+1, '"'); - if (send == 0 || send > next_str) continue; + if (send == NULL || send > next_str) continue; string tmp_str; tmp_str.assign(str+1, send-str-1); item.DeleteTextPos(); item.text.Load(tmp_str); @@ -550,14 +564,14 @@ void TextImpl::Load(const char* str) { sscanf(str, "%d", &item.pos); } str = strchr(str, ','); - if (str == 0 || str > next_str) goto backlog_store; + if (str == NULL || str > next_str) goto backlog_store; str++; if (str[0] == ';' || str[0] == ',') item.koe = -1; else sscanf(str, "%d", &item.koe); str = strchr(str, ','); - if (str == 0 || str > next_str) goto backlog_store; + if (str == NULL || str > next_str) goto backlog_store; str++; if (*str == '"') { const char* send = strchr(str+1, '"'); @@ -589,13 +603,12 @@ void TextImpl::Load(const char* str) { backlog.swap(new_backlog); } // backlog.clear(); - return; } void TextImpl::hide(void) { if (text) text->hide(); if (kcursor) kcursor->hide(); - text = 0; + text = NULL; } void TextImpl::show(int num) { if (num != text_window_number) { @@ -619,6 +632,7 @@ void TextImpl::show(int num) { kcursor->Pic()->Move(kx, ky); } } + void TextImpl::DrawBacklog(BacklogItem& item, Cmd& cmd) { show(); text->wid->deactivate(); @@ -641,27 +655,26 @@ void TextImpl::DrawBacklog(BacklogItem& } void TextImpl::CreateSelBG(void) { - if (sel_bg1 != 0 || sel_bg2 != 0) return; + if (sel_bg1 != NULL || sel_bg2 != NULL) return; const char* btnfile1 = config.GetParaStr("#SELBTN.000.NAME"); const char* btnfile2 = config.GetParaStr("#SELBTN.000.BACK"); char path[1024]; strcpy(path, btnfile1); sel_bg1 = parent.Root().NewSurface(path); - if (sel_bg1 == 0) { + if (sel_bg1 == NULL) { sprintf(path,"%s.g00",btnfile1); sel_bg1 = parent.Root().NewSurface(path); } strcpy(path, btnfile2); sel_bg2 = parent.Root().NewSurface(path); - if (sel_bg2 == 0) { + if (sel_bg2 == NULL) { sprintf(path,"%s.g00",btnfile2); sel_bg2 = parent.Root().NewSurface(path); } sel_bg_rect = Rect(0,0,0,0); if (sel_bg1) sel_bg_rect.join(Rect(*sel_bg1)); if (sel_bg2) sel_bg_rect.join(Rect(*sel_bg2)); - return; } void TextImpl::CreateSelect(Cmd& cmd) { @@ -755,7 +768,7 @@ External_select: Color seled(0xff,0xff,0xff); show(); - if (text == 0) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする + if (text == NULL) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする text->wid->Clear(); if (kcursor) kcursor->hide(); /* ウィジット作成 : テキスト表示範囲と同じ*/ @@ -787,7 +800,7 @@ External_select: void TextImpl::AddText(const char* str_o) { char str[10001]; - if (text == 0) return; + if (text == NULL) return; /* まず、replace string を変換 */ int i; int cnt = 0; @@ -848,12 +861,11 @@ void TextImpl::AddText(const char* str_o } else if (*s < 0 && s[1] != 0) s++; } text_stream.Add(str_top); - return; } void TextImpl::Exec(Cmd& cmd) { if (cmd.cmd_type == CMD_TEXT) { - if (text == 0) { + if (text == NULL) { show(); } if (cmd.args.size() != 1) return; @@ -920,7 +932,7 @@ void TextImpl::Exec(Cmd& cmd) { cur_backlog_item.DeleteTextPos(); cmd.clear(); } else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更 - if (text == 0) { + if (text == NULL) { show(); } if (cmd.cmd3 == 0x3e8) { @@ -935,7 +947,7 @@ void TextImpl::Exec(Cmd& cmd) { cmd.cmd_type = CMD_SAVECMD_ONCE; } } else if (cmd.cmd3 == 0x78) { // ルビ関連 - if (text == 0) { + if (text == NULL) { show(); } if (cmd.cmd4 == 1) { @@ -1325,12 +1337,11 @@ else fprintf(stderr,"AUTO %d,%d <- wait } } } +} - return; -} extern int print_blit; bool TextImpl::Wait(unsigned int current_time, Cmd& cmd) { - if (current_time != 0xffffffffUL) old_time = current_time; + if (current_time != Event::Time::NEVER_WAKE) old_time = current_time; /* if (event.presscount(MOUSE_UP)) { if (text) text->Pic()->ReBlit(); @@ -1341,16 +1352,16 @@ print_blit^=1; */ if (status == NORMAL && status_mask == NORMAL) return false; - + if (status_mask & WAIT_EXTRN_MASK) return true; if (status_mask & (BACKLOG_MASK|BACKLOG_MASK_FWD) ) { if (status_mask & BACKLOG_WAIT_MASK) ; else { - if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { + if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { text->wid->Flush(); // 表示を最後の状態にする } - if (status == WAIT_TEXT && text != 0 && kcursor) kcursor->show(); + if (status == WAIT_TEXT && text != NULL && kcursor != NULL) kcursor->show(); } } if (status_mask & BACKLOG_MASK) { @@ -1409,7 +1420,7 @@ print_blit^=1; return false; } if (event.presscount(MOUSE_RIGHT)) { - if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { + if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { text->wid->Flush(); // 表示を最後の状態にする } @@ -1424,7 +1435,7 @@ print_blit^=1; } } if (event.presscount(MOUSE_UP)) { - if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { + if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { text->wid->Flush(); // 表示を最後の状態にする } @@ -1437,17 +1448,17 @@ print_blit^=1; } } if (status_mask & CLEARSCR_MASK) { - if ( (status == WAIT_TEXT && text != 0 ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { + if ( (status == WAIT_TEXT && text != NULL ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { if (skip_mode) skip_mode = SKIP_NO; if (text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { text->wid->Flush(); // 表示を最後の状態にする return true; } status_mask = Status(status_mask & (~CLEARSCR_MASK) | CLEARSCR_WAIT_MASK); - if (text) text->hide(); - if (kcursor) kcursor->hide(); - if (sel_widget) sel_widget->hide(); - if (backlog_widget) backlog_widget->hide(); + if (text != NULL) text->hide(); + if (kcursor != NULL) kcursor->hide(); + if (sel_widget != NULL) sel_widget->hide(); + if (backlog_widget != NULL) backlog_widget->hide(); return true; } status_mask = Status(status_mask & (~CLEARSCR_MASK)); @@ -1457,12 +1468,15 @@ print_blit^=1; return true; } if (status == WAIT_TEXT) { - if (text == 0) { status = NORMAL; return false;} + if (text == NULL) { + status = NORMAL; + return false; + } if (skip_mode & SKIP_TEXT) { } else if (text->wid->status != WidText::PREPARE) { return true; } - if (kcursor) kcursor->hide(); + if (kcursor != NULL) kcursor->hide(); text_stream.Clear(); status = NORMAL; cmd.cmd_type = CMD_TEXTEND; @@ -1500,7 +1514,7 @@ print_blit^=1; cmd.SetSysvar(sel_val); selects.clear(); delete sel_widget; - sel_widget = 0; + sel_widget = NULL; status = NORMAL; // CreateSelect() で作成された cur_backlog_item を backlog_item へ反映させる cur_backlog_item.text.InsertColor(sel_backlog_pos[sel_val], sel_backlog_pos[sel_val+1], 0xff, 0, 0); @@ -1511,45 +1525,46 @@ print_blit^=1; } void clearbtn_press(void* pointer, WidButton* button) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::CLEARSCR_MASK); return; } void TextImpl::PressFuncSkip(void* pointer, WidButton* from) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SKIPMASK); return; } void TextImpl::PressFuncLoad(void* pointer, WidButton* from) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::LOADMASK); return; } void TextImpl::PressFuncSave(void* pointer, WidButton* from) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SAVEMASK); return; } void TextImpl::PressFuncBacklog(void* pointer, WidButton* from) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK); return; } void TextImpl::PressFuncBacklogFwd(void* pointer, WidButton* from) { - if (pointer == 0) return; + if (pointer == NULL) return; TextImpl* t = (TextImpl*)pointer; t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK_FWD); return; } void movebtn_drag(int from_x, int from_y, int x, int y, void* pointer, WidButton* button) { - if (pointer == 0) return; + if (pointer == NULL) return; fprintf(stderr,"drag.\n"); } + #define BTNCNT 10 static const char* btnname[BTNCNT] = { "MOVE", @@ -1563,13 +1578,16 @@ static const char* btnname[BTNCNT] = { "EXBTN_001", "EXBTN_002" }; + static int btnpos[BTNCNT] = { // g00 ファイル内のボタン情報の位置 // 0, 1, 13, 12, 2, 3, 4, 5, 6, 7 // princess bride? 0, 1, 13, 14, 2, 3, 4, 5, 6, 7 // tomoyo after? }; + static WidButton::PressFunc btnpress[BTNCNT] = { 0, clearbtn_press, &TextImpl::PressFuncSkip,0,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncBacklog,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncSave,&TextImpl::PressFuncLoad,0 }; + static WidButton::DragFunc btndrag[BTNCNT] = { movebtn_drag, 0,0,0,0, 0,0,0,0, 0 }; @@ -1585,6 +1603,7 @@ void TextImpl::SetTextSpeed(int speed) { for (i=0; i<32; i++) if (widgets[i]) widgets[i]->wid->SetSpeed(speed); } + void TextImpl::SetTextWait(int wait) { int i; for (i=0; i<32; i++) @@ -1596,13 +1615,13 @@ void TextImpl::SetWindowColor(int r, int int w; for (w=0; w<32; w++) { - if (widgets[w] == 0) continue; + if (widgets[w] == NULL) continue; sprintf(key, "#WAKU.%03d.000.BACK", w); const char* back = config.GetParaStr(key); - if (back == 0 || back[0] == 0) continue; + if (back == NULL || back[0] == 0) continue; sprintf(key, "%s.g00", back); Surface* back_s = parent.Root().NewSurface(key); - if (back_s == 0) continue; + if (back_s == NULL) continue; Rect rect(*back_s); Surface* new_s = parent.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); DSurfaceMove(back_s, rect, new_s, rect); @@ -1613,7 +1632,6 @@ void TextImpl::SetWindowColor(int r, int widgets[w]->wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY); parent.Root().DeleteSurface(back_s); } - return; } void TextImpl::SetCursor(int cursor_no) { @@ -1631,7 +1649,7 @@ void TextImpl::SetCursor(int cursor_no) config.GetParam(key, 1, &speed); // speed で1周、cont 回変化 - if (kcursor) delete kcursor; + if (kcursor != NULL) delete kcursor; kcursor = new WidTimeCursor(event, speed/cont, &parent, path.c_str(), 0, 0, w, 0, cont, Rect(0,0,w,h)); int i; @@ -1640,7 +1658,7 @@ void TextImpl::SetCursor(int cursor_no) } } -void kconv(const unsigned char* src, unsigned char* dest) { +void kconv(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication? /* input : sjis output: euc */ while(*src) { unsigned int high = *src++; @@ -1673,7 +1691,8 @@ void kconv(const unsigned char* src, uns } *dest = 0; } -void kconv_rev(const unsigned char* src, unsigned char* dest) { + +void kconv_rev(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication? /* input : euc output: sjis */ while(*src) { unsigned int high = *src++; @@ -1701,6 +1720,7 @@ void kconv_rev(const unsigned char* src, } *dest = 0; } + string kconv(const string& s) { char* out = new char[s.length()*2+100]; kconv((const unsigned char*)s.c_str(), (unsigned char*)out); @@ -1708,6 +1728,7 @@ string kconv(const string& s) { delete[] out; return ret; } + string kconv_rev(const string& s) { char* out = new char[s.length()*2+100]; kconv_rev((const unsigned char*)s.c_str(), (unsigned char*)out); @@ -1723,24 +1744,32 @@ string kconv_rev(const string& s) { Text::Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config) { pimpl = new TextImpl(_event, _parent, config, backlog, backlog_item); } + Text::~Text() { delete pimpl; + pimpl = NULL; } + void Text::InitWindow(void) { pimpl->InitWindow(); } + void Text::Exec(Cmd& cmd) { pimpl->Exec(cmd); } + bool Text::Wait(unsigned int current_time, Cmd& cmd) { return pimpl->Wait(current_time, cmd); } + void Text::SetSkipMode(SkipMode mode) { pimpl->SetSkipMode(mode); } + void Text::Save(std::string& str, bool select_save) { pimpl->Save(str, select_save); } + void Text::Load(const char* str) { pimpl->Load(str); } @@ -1748,15 +1777,19 @@ void Text::Load(const char* str) { void Text::hide(void) { pimpl->hide(); } + void Text::show(void) { pimpl->show(); } + void Text::show(int num) { pimpl->show(num); } + void Text::DrawBacklog(BacklogItem& item, Cmd& cmd) { pimpl->DrawBacklog(item, cmd); } + /**************************************************************:: ** ** BacklogItem @@ -1769,12 +1802,14 @@ BacklogItem::BacklogItem(void) { face = ""; text.kanji_type = TextStream::sjis; } + void BacklogItem::Clear(void) { scn = -1; pos = -1; koe = -1; text.Clear(); } + void BacklogItem::AddTextPos(Cmd& cmd) { if (scn == -1 && pos == -1) { scn = cmd.scn; @@ -1783,10 +1818,12 @@ void BacklogItem::AddTextPos(Cmd& cmd) { } DeleteTextPos(); } + void BacklogItem::DeleteTextPos(void) { scn = 0; pos = -1; } + BacklogItem& BacklogItem::operator =(const BacklogItem& p) { scn = p.scn; pos = p.pos; @@ -1794,6 +1831,7 @@ BacklogItem& BacklogItem::operator =(con face = p.face; text = p.text; } + void BacklogItem::SetSavepos(int p) { Clear(); scn = SaveSelect; @@ -1804,41 +1842,42 @@ Rect TextWindow::WakuSize(PicContainer& char key[1024]; sprintf(key, "#WAKU.%03d.000.NAME", waku_no); const char* name = config.GetParaStr(key); - if (!name) return Rect(0,0,0,0); + if (name == NULL) return Rect(0,0,0,0); std::string str = name; str += ".g00"; Surface* s = pic.Root().NewSurface(str.c_str()); - if (!s) return Rect(0,0,0,0); + if (s == NULL) return Rect(0,0,0,0); Rect r(*s); pic.Root().DeleteSurface(s); return r; } + void TextWindow::MakeWaku(PicContainer& pic, Event::Container& event, int waku_no, int window_no, bool* use_btn, const AyuSysConfig& config, void* callback) { char key[1024]; std::string str; /* 枠を作成 */ sprintf(key, "#WAKU.%03d.000.NAME", waku_no); const char* name = config.GetParaStr(key); - if (name && name[0] == 0) name = 0; + if (name != NULL && name[0] == 0) name = NULL; sprintf(key, "#WAKU.%03d.000.BACK", waku_no); const char* back = config.GetParaStr(key); - if (back && back[0] == 0) back = 0; + if (back != NULL && back[0] == 0) back = NULL; sprintf(key, "#WAKU.%03d.000.BTN", waku_no); const char* btn = config.GetParaStr(key); - if (btn && btn[0] == 0) btn = 0; + if (btn != NULL && btn[0] == 0) btn = NULL; - if (name == 0 && back == 0 && btn == 0) return; + if (name == NULL && back == NULL && btn == NULL) return; /* まず、テキスト背景を設定 */ - if (back) { + if (back != NULL) { str = back; str += ".g00"; - int rc,gc,bc,ac, flag; + int rc, gc, bc, ac, flag; char key[1024]; sprintf(key, "#WINDOW.%03d.ATTR", window_no); if (config.GetParam(key, 5, &rc, &gc, &bc, &ac, &flag) == -1) { config.GetParam("#WINDOW_ATTR", 5, &rc, &gc, &bc, &ac, &flag); } Surface* back_s = pic.Root().NewSurface(str.c_str()); - if (back_s) { + if (back_s != NULL) { Rect rect(*back_s); Surface* s = pic.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); DSurfaceMove(back_s, rect, s, rect); @@ -1850,7 +1889,7 @@ void TextWindow::MakeWaku(PicContainer& } } /* その前に枠飾りを設定 */ - if (name) { + if (name != NULL) { str = name; str += ".g00"; Surface* s = pic.Root().NewSurface(str.c_str()); if (s) { @@ -1862,19 +1901,19 @@ void TextWindow::MakeWaku(PicContainer& p->show(); } } - if (btn == 0) return; - if (use_btn == 0) return; + if (btn == NULL) return; + if (use_btn == NULL) return; // ボタンの作成 // 使用するボタンについては、必要に応じて show() すること /* ボタンの位置情報を求める */ str = btn; str += ".g00"; ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, str.c_str(), "g00"); - if (info == 0) return; // cannot find file + if (info == NULL) return; // cannot find file const char* data = info->Read(); /* g00 ファイルのヘッダ部分に位置情報は入っている */ /* 存在しなければボタン画像ではない */ - if (data == 0 || *data != 2) { + if (data == NULL || *data != 2) { delete info; return; } @@ -1901,7 +1940,6 @@ void TextWindow::MakeWaku(PicContainer& if (btndrag[i]) { wid->drag_func = btndrag[i]; wid->drag_pointer = callback;} } delete info; - return; } TextWindow::TextWindow(PicContainer& parent, Event::Container& event, int win_no, const AyuSysConfig& config, void* callback) : @@ -1987,16 +2025,17 @@ TextWindow::TextWindow(PicContainer& par name_r.rmove(r.lx, r.ty); name_r.rmove(name_posx, name_posy-name_size); name_container = parent.create_node(name_r, 0); - name = new WidLabel(name_container, Rect(0,0,w,h), true, 0, name_size); + name = new WidLabel(name_container, Rect(0, 0, w, h), true, 0, name_size); name->show(); name_container->show(); } } else { // name_mod == 2 or 3 - name_container = parent.create_node( Rect(0,0,1,1), 0); + name_container = parent.create_node( Rect(0, 0, 1, 1), 0); } } MakeWaku(*wid->PicNode(), event,waku_no, win_no, use_btn, config, callback); } + void TextImpl::InitWindow(void) { int i; int w; @@ -2006,7 +2045,7 @@ void TextImpl::InitWindow(void) { widgets[w] = new TextWindow(parent, event, w, config, (void*)this); if (widgets[w]->wid == 0) { delete widgets[w]; - widgets[w] = 0; + widgets[w] = NULL; } } SetCursor(0); @@ -2014,16 +2053,16 @@ void TextImpl::InitWindow(void) { char buf[1024]; sprintf(buf, "#NAME.%c", i+'A'); const char* s = config.GetParaStr(buf); - if (s) replace_name[i] = s; + if (s != NULL) replace_name[i] = s; } // replace_name2 : 初期設定 // 渚、秋生、渚 (CLANNAD) - char name_nagisa[3] = {0x8f,0x8d,0}; - char name_akio[5] = {0x8f, 0x48, 0x90, 0xb6, 0}; + char name_nagisa[3] = {'\x8f', '\x8d', '\0'}; + char name_akio[5] = {'\x8f', '\x48', '\x90', '\xb6', '\0'}; replace_name2[0] = name_nagisa; replace_name2[1] = name_akio; replace_name2[2] = name_nagisa; - text = 0; + text = NULL; /* テキスト速度の設定 */ int speed, mod, wait, auto_mod; config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed); diff --git a/scn2k/scn2kdump.cc b/scn2k/scn2kdump.cc --- a/scn2k/scn2kdump.cc +++ b/scn2k/scn2kdump.cc @@ -18,18 +18,18 @@ * */ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include using namespace std; -#include"system/file.h" -#include"system/file_impl.h" +#include "system/file.h" +#include "system/file_impl.h" #include "scn2k.h" @@ -118,8 +118,8 @@ int main(int argc, char** argv) { char* fname; fprintf(stderr,"Dump start\n"); while( (fname = archive.ListItem()) != 0) { - ARCINFO* info = archive.Find(fname,""); - if (info == 0) continue; + ARCINFO* info = archive.Find(fname, ""); + if (info == NULL) continue; char* data = info->CopyRead(); char* d = data; char* dend = d + info->Size(); diff --git a/system/file.cc b/system/file.cc --- a/system/file.cc +++ b/system/file.cc @@ -47,7 +47,7 @@ bool init_end=false; #include #include #if HAVE_MMAP -#include +#include #endif /* HAVE_MMAP */ #if HAVE_DIRENT_H # include @@ -67,14 +67,14 @@ bool init_end=false; #endif #if HAVE_LIBZ -#include +#include #endif #if HAVE_LIBPNG -#include +#include #endif #if HAVE_LIBJPEG extern "C" { -#include +#include } #endif @@ -111,10 +111,10 @@ const char* FILESEARCH::default_dirnames ARCFILE::ARCFILE(const char* aname) { struct stat sb; /* 変数初期化 */ - arcname = 0; + arcname = NULL; list_point = 0; - filenames_orig = 0; - next = 0; + filenames_orig = NULL; + next = NULL; if (aname[0] == '\0') {arcname=new char[1]; arcname[0]='\0';return;} // NULFILE /* ディレクトリか否かのチェック */ if (stat(aname,&sb) == -1) { /* error */ @@ -133,12 +133,11 @@ ARCFILE::ARCFILE(const char* aname) { if (arcname[strlen(arcname)-1] == DIR_SPLIT) arcname[strlen(arcname)-1] = '\0'; } - return; } void ARCFILE::Init(void) { if (! arc_atom.empty()) return; - if (arcname == 0) return; + if (arcname == NULL) return; /* ファイル数を得る */ int slen = CheckFileDeal(); /* ファイル名のセット */ @@ -156,7 +155,7 @@ ARCFILE::iterator ARCFILE::SearchName(co char buf[1024]; char buf_ext[1024]; iterator it; Init(); - if (f == 0) return arc_atom.end(); + if (f == NULL) return arc_atom.end(); if (arc_atom.empty()) return arc_atom.end(); /* エラーチェック */ if (strlen(f)>500) return arc_atom.end(); @@ -171,7 +170,7 @@ ARCFILE::iterator ARCFILE::SearchName(co if (ext) { strcpy(buf_ext, buf); char* ext_pt = strrchr(buf_ext, '.'); - if (ext_pt == 0 || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext); + if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext); *ext_pt++ = '.'; while(*ext=='.') ext++; strcat(buf_ext, ext); @@ -189,10 +188,10 @@ ARCFILE::iterator ARCFILE::SearchName(co if (it != arc_atom.end() && strcmp(it->filename_lower, buf) == 0) return it; // 拡張子をつけて検索 - if (ext == 0) return arc_atom.end(); + if (ext == NULL) return arc_atom.end(); strcpy(buf_ext, buf); char* ext_pt = strrchr(buf_ext, '.'); - if (ext_pt == 0 || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext); + if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext); *ext_pt++ = '.'; /* 拡張子の長さを得る */ l = strlen(ext); @@ -209,7 +208,7 @@ ARCINFO* ARCFILE::Find(const char* fname iterator atom = SearchName(fname,ext); if (atom == arc_atom.end()) { if (next) return next->Find(fname, ext); - else return 0; + else return NULL; } return MakeARCINFO(*atom); } @@ -243,7 +242,7 @@ FILE* DIRFILE::Open(const char* fname) { char* new_path = new char[strlen(arcname)+strlen(name)+1]; strcpy(new_path,arcname); strcat(new_path, name); FILE* ret = fopen(new_path, "rb+"); - fseek(ret, 0, 0); + fseek(ret, 0, SEEK_SET); delete[] new_path; return ret; } @@ -283,10 +282,10 @@ void ARCFILE::InitList(void) { list_point = 0; } char* ARCFILE::ListItem(void) { - if (list_point < 0) return 0; - if (list_point >= arc_atom.size()) return 0; + if (list_point < 0) return NULL; + if (list_point >= arc_atom.size()) return NULL; char* fname = arc_atom[list_point].filename; - if (fname == 0) return 0; + if (fname == NULL) return NULL; char* ret = new char[strlen(fname)+1]; strcpy(ret, fname); list_point++; @@ -297,12 +296,13 @@ int ARCFILE::CheckFileDeal(void) { char buf[0x20]; /* ヘッダのチェック */ FILE* stream = fopen(arcname, "rb"); - if (stream == 0) { + if (stream == NULL) { fprintf(stderr, "Cannot open archive file : %s\n",arcname); return 0; } - fseek(stream, 0, 2); size_t arc_size = ftell(stream); - fseek(stream, 0, 0); + fseek(stream, 0, SEEK_END); + size_t arc_size = ftell(stream); + fseek(stream, 0, SEEK_SET); if (arc_size < 0x20) { fclose(stream); return 0; @@ -330,7 +330,7 @@ void ARCFILE::ListupFiles(int fname_len) fname_len *= 2; char* buf = new char[fname_len]; FILE* stream = fopen(arcname, "rb"); - if (stream == 0) { + if (stream == NULL) { fprintf(stderr, "Cannot open archive file : %s\n",arcname); return; } @@ -363,7 +363,7 @@ int DIRFILE::CheckFileDeal(void) { DIR* dir; struct dirent* ent; int flen = 0; dir = opendir(arcname); - if (dir == 0) { + if (dir == NULL) { fprintf(stderr, "Cannot open dir file : %s\n",arcname); return 0; } @@ -379,7 +379,7 @@ void DIRFILE::ListupFiles(int fname_len) DIR* dir; fname_len *= 2; dir = opendir(arcname); - if (dir == 0) { + if (dir == NULL) { fprintf(stderr, "Cannot open dir file : %s\n",arcname); return; } @@ -394,8 +394,8 @@ void DIRFILE::ListupFiles(int fname_len) closedir(dir); close(old_dir_fd); return; - }; - + } + char* buf = new char[fname_len]; ARCFILE_ATOM atom; struct stat sb; @@ -427,11 +427,12 @@ void DIRFILE::ListupFiles(int fname_len) /* chdir() したのを元に戻る */ closedir(dir); fchdir(old_dir_fd); close(old_dir_fd); - return; } + int NULFILE::CheckFileDeal(void) { return 20; } + void NULFILE::ListupFiles(int fname_len) { char* s = new char[40]; ARCFILE_ATOM atom; @@ -441,15 +442,17 @@ void NULFILE::ListupFiles(int fname_len) atom.filename_lower = s; arc_atom.push_back(atom); } + int SCN2kFILE::CheckFileDeal(void) { /* ヘッダのチェック */ FILE* stream = fopen(arcname, "rb"); - if (stream == 0) { + if (stream == NULL) { fprintf(stderr, "Cannot open archive file : %s\n",arcname); return 0; } - fseek(stream, 0, 2); size_t arc_size = ftell(stream); - fseek(stream, 0, 0); + fseek(stream, 0, SEEK_END); + size_t arc_size = ftell(stream); + fseek(stream, 0, SEEK_SET); if (arc_size < 10000*8) { fclose(stream); return 0; @@ -468,16 +471,18 @@ int SCN2kFILE::CheckFileDeal(void) { delete[] buf; return count*13; /* ファイル名は seenXXXX.txt だから、一つ12文字+null */ } + void SCN2kFILE::ListupFiles(int fname_len) { FILE* stream = fopen(arcname, "rb"); - if (stream == 0) { + if (stream == NULL) { fprintf(stderr, "Cannot open archive file : %s\n",arcname); return; } char* sbuf = new char[fname_len]; char* buf = new char[10000*8]; fread(buf, 10000, 8, stream); - fseek(stream, 0, 2); size_t arc_size = ftell(stream); + fseek(stream, 0, SEEK_END); + size_t arc_size = ftell(stream); ARCFILE_ATOM atom; int i; for (i=0; i<10000; i++) { char header[0x200]; @@ -485,7 +490,7 @@ void SCN2kFILE::ListupFiles(int fname_le int tmp_size = read_little_endian_int(buf+i*8+4); if (tmp_size <= 0 || tmp_offset < 0 || tmp_offset+tmp_size > int(arc_size) ) continue; /* header を得て圧縮形式などを調べる */ - fseek(stream, tmp_offset, 0); + fseek(stream, tmp_offset, SEEK_SET); fread(header, 0x200, 1, stream); int header_top = read_little_endian_int(header+0); int file_version = read_little_endian_int(header+4); @@ -528,7 +533,6 @@ void SCN2kFILE::ListupFiles(int fname_le } delete[] buf; fclose(stream); - return; } /******************************************************** @@ -589,9 +593,10 @@ const char * KEYHOLDER::GetKey(void) FILESEARCH::FILESEARCH(void) { int i; - root_dir = 0; dat_dir = 0; + root_dir = NULL; + dat_dir = NULL; for (i=0; iInit(); /* dat/ を検索 */ char* dat_path = root_dir->SearchFile("dat"); - if (dat_path == 0) { + if (dat_path == NULL) { /* 見つからなかったら root を dat の代わりにつかう */ dat_dir = root_dir; } else { @@ -654,34 +659,34 @@ int FILESEARCH::InitRoot(char* root) { void FILESEARCH::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) { int type = tp; if (type < 0 || type >= TYPEMAX) return; - ARCFILE* next_arc = 0; + ARCFILE* next_arc = NULL; /* すでに searcher が存在すれば解放 */ - if (searcher[type] != 0 && + if (searcher[type] != NULL && searcher[type] != root_dir && searcher[type] != dat_dir) { next_arc = searcher[type]->Next(); delete searcher[type]; } - searcher[type] = 0; + searcher[type] = NULL; /* 適当に初期化 */ - if (filenames[type] != 0 && + if (filenames[type] != NULL && filenames[type] != default_dirnames[type]) delete[] filenames[type]; filenames[type] = filename; is_archived[type] = is_arc; searcher[type] = MakeARCFILE(is_arc, filename); - if (searcher[type] && next_arc) + if (searcher[type] != NULL && next_arc) searcher[type]->SetNext(next_arc); - return; } + void FILESEARCH::AppendFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) { int type = tp; if (type < 0 || type >= TYPEMAX) return; /* searcher がまだ割り当てられてない場合 */ - if (searcher[type] == 0 || + if (searcher[type] == NULL || searcher[type] == root_dir || searcher[type] == dat_dir) { searcher[type] = MakeARCFILE(is_archived[type], filenames[type]); - if (searcher[type] == 0) { /* 作成できなかった場合 */ + if (searcher[type] == NULL) { /* 作成できなかった場合 */ /* この型情報を FileInformation とする */ SetFileInformation(tp, is_arc, filename); return; @@ -691,29 +696,28 @@ void FILESEARCH::AppendFileInformation(F ARCFILE* arc = MakeARCFILE(is_arc, filename); /* append */ ARCFILE* cur; - for (cur=searcher[type]; cur->Next() != 0; cur = cur->Next()) ; + for (cur=searcher[type]; cur->Next() != NULL; cur = cur->Next()) ; cur->SetNext(arc); - return; } ARCFILE* FILESEARCH::MakeARCFILE(ARCTYPE tp, const char* filename) { - ARCFILE* arc = 0; + ARCFILE* arc = NULL; char* file; - if (filename == 0) goto err; + if (filename == NULL) goto err; if (tp == ATYPE_DIR) { file = root_dir->SearchFile(filename); } else { file = dat_dir->SearchFile(filename); - if (file == 0) + if (file == NULL) file = root_dir->SearchFile(filename); } - if (file == 0) goto err; + if (file == NULL) goto err; switch(tp) { case ATYPE_DIR: arc = new DIRFILE(file); break; case ATYPE_SCN2k: case ATYPE_ARC: { FILE* f = fopen(file, "rb"); - if (f == 0) goto err; + if (f == NULL) goto err; char header[32]; memset(header, 0, 32); fread(header, 32, 1, f); @@ -732,19 +736,18 @@ ARCFILE* FILESEARCH::MakeARCFILE(ARCTYPE err: arc = new NULFILE; return arc; - } ARCINFO* FILESEARCH::Find(FILETYPE type, const char* fname, const char* ext) { - if (searcher[type] == 0) { + if (searcher[type] == NULL) { /* searcher 作成 */ - if (filenames[type] == 0) { + if (filenames[type] == NULL) { searcher[type] = dat_dir; } else { searcher[type] = MakeARCFILE(is_archived[type], filenames[type]); - if (searcher[type] == 0) { + if (searcher[type] == NULL) { fprintf(stderr,"FILESEARCH::Find : invalid archive type; type %d name %s\n",type,fname); - return 0; + return NULL; } } } @@ -754,16 +757,16 @@ ARCINFO* FILESEARCH::Find(FILETYPE type, char** FILESEARCH::ListAll(FILETYPE type) { /* とりあえず searcher を初期化 */ Find(type, "THIS FILENAME MAY NOT EXIST IN THE FILE SYSTEM !!!"); - if (searcher[type] == 0) return 0; + if (searcher[type] == NULL) return NULL; /* 全ファイルのリストアップ */ int deal = 0; ARCFILE* file; - for (file = searcher[type]; file != 0; file = file->Next()) + for (file = searcher[type]; file != NULL; file = file->Next()) deal += file->Deal(); - if (deal <= 0) return 0; + if (deal <= 0) return NULL; char** ret_list = new char*[deal+1]; int count = 0; - for (file = searcher[type]; file != 0; file = file->Next()) { + for (file = searcher[type]; file != NULL; file = file->Next()) { file->InitList(); char* f; while( (f = file->ListItem() ) != 0) { @@ -772,7 +775,7 @@ char** FILESEARCH::ListAll(FILETYPE type count++; } } - ret_list[count] = 0; + ret_list[count] = NULL; return ret_list; } @@ -780,8 +783,8 @@ ARCINFO::ARCINFO(const char* __arcname, arcfile = new char[strlen(__arcname)+1]; strcpy(arcfile, __arcname); use_mmap = false; - mmapped_memory = 0; - data = 0; + mmapped_memory = NULL; + data = NULL; fd = -1; } @@ -801,19 +804,20 @@ int ARCINFO::Size(void) const { /* コピーを返す */ char* ARCINFO::CopyRead(void) { const char* d = Read(); - if (d == 0) return 0; + if (d == NULL) return NULL; int s = Size(); - if (s <= 0) return 0; + if (s <= 0) return NULL; char* ret = new char[s]; memcpy(ret, d, s); return ret; } const char* ARCINFO::Path(void) const { - if (info.offset != 0) return 0; /* archive file なのでパスを帰せない */ + if (info.offset != 0) return NULL; /* archive file なのでパスを帰せない */ char* ret = new char[strlen(arcfile)+1]; strcpy(ret, arcfile); return ret; } + /* 互換性専用 */ FILE* ARCINFO::OpenFile(int* length) const { FILE* f = fopen(arcfile, "rb"); @@ -826,25 +830,28 @@ FILE* ARCINFO::OpenFile(int* length) con bool ARCINFO::ExecExtract(void) { return true; } + /* 読み込みを開始する */ const char* ARCINFO::Read(void) { // すでにデータを読み込み済みなら何もしない - if (data) return data; + if (data != NULL) return data; if (info.offset < 0 || info.arcsize <= 0) { - return 0; + return NULL; } /* ファイルを開く */ fd = open(arcfile, O_RDONLY); if (fd < 0) { - return 0; + return NULL; } - if (lseek(fd, info.offset, 0) != info.offset) { - close(fd); fd = -1; return 0; + if (lseek(fd, info.offset, SEEK_SET) != info.offset) { + close(fd); + fd = -1; + return NULL; } /* mmap を試みる */ #ifdef HAVE_MMAP - mmapped_memory = (char*)mmap(0, info.arcsize, PROT_READ, MAP_SHARED, fd, info.offset); + mmapped_memory = (char*)mmap(NULL, info.arcsize, PROT_READ, MAP_SHARED, fd, info.offset); if (mmapped_memory != MAP_FAILED) { use_mmap = true; data = (const char*)mmapped_memory; @@ -865,13 +872,13 @@ const char* ARCINFO::Read(void) { #ifdef HAVE_MMAP if (use_mmap) { munmap(mmapped_memory, info.arcsize); - if (data == (const char*)mmapped_memory) data = 0; + if (data == (const char*)mmapped_memory) data = NULL; } #endif /* HAVE_MMAP */ delete[] (char*)data; close(fd); - fd = -1; data = 0; - return 0; + fd = -1; data = NULL; + return NULL; } #ifdef HAVE_MMAP if (use_mmap && data != (const char*)mmapped_memory) { @@ -892,15 +899,17 @@ const char* ARCINFO::Read(void) { *********************************************** */ GRPCONV::GRPCONV(void) { - filename = 0; - data = 0; + filename = NULL; + data = NULL; } + GRPCONV::~GRPCONV() { if (filename) delete[] filename; } + void GRPCONV::Init(const char* f, const char* d, int dlen, int w, int h, bool is_m) { if (filename) delete[] filename; - if (f == 0) { + if (f == NULL) { char* fn = new char[1]; fn[0] = 0; filename = fn; @@ -916,107 +925,127 @@ void GRPCONV::Init(const char* f, const height = h; is_mask = is_m; } + class PDTCONV : public GRPCONV { - bool Read_PDT10(char* image); - bool Read_PDT11(char* image); -public: - PDTCONV(const char* _inbuf, int inlen, const char* fname); - ~PDTCONV() {} - bool Read(char* image); + private: + bool Read_PDT10(char* image); + bool Read_PDT11(char* image); + public: + PDTCONV(const char* _inbuf, int inlen, const char* fname); + ~PDTCONV() {} + bool Read(char* image); }; + class G00CONV : public GRPCONV { - struct REGION { - int x1, y1, x2, y2; - int Width() { return x2-x1+1;} - int Height() { return y2-y1+1;} - void FixVar(int& v, int& w) { - if (v < 0) v = 0; - if (v >= w) v = w-1; - } - void Fix(int w, int h) { - FixVar(x1,w); - FixVar(x2,w); - FixVar(y1,h); - FixVar(y2,h); - if (x1 > x2) x2 = x1; - if (y1 > y2) y2 = y1; - } - }; + private: + struct REGION { + int x1, y1, x2, y2; + int Width() { return x2-x1+1;} + int Height() { return y2-y1+1;} + void FixVar(int& v, int& w) { + if (v < 0) v = 0; + if (v >= w) v = w-1; + } + void Fix(int w, int h) { + FixVar(x1,w); + FixVar(x2,w); + FixVar(y1,h); + FixVar(y2,h); + if (x1 > x2) x2 = x1; + if (y1 > y2) y2 = y1; + } + }; - void Copy_16bpp(char* image, int x, int y, const char* src, int bpl, int h); - void Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h); - bool Read_Type0(char* image); - bool Read_Type1(char* image); - bool Read_Type2(char* image); -public: - G00CONV(const char* _inbuf, int _inlen, const char* fname); - ~G00CONV() { } - bool Read(char* image); + void Copy_16bpp(char* image, int x, int y, const char* src, int bpl, int h); + void Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h); + bool Read_Type0(char* image); + bool Read_Type1(char* image); + bool Read_Type2(char* image); + public: + G00CONV(const char* _inbuf, int _inlen, const char* fname); + ~G00CONV() { } + bool Read(char* image); }; class BMPCONV : public GRPCONV { -public: - BMPCONV(const char* _inbuf, int _inlen, const char* fname); - ~BMPCONV() {}; - bool Read(char* image); + public: + BMPCONV(const char* _inbuf, int _inlen, const char* fname); + ~BMPCONV() {}; + bool Read(char* image); }; + #if HAVE_LIBPNG class PNGCONV : public GRPCONV { - const char* png_data; - static void png_read(png_structp, png_bytep, png_size_t); + private: + const char* png_data; + static void png_read(png_structp, png_bytep, png_size_t); -public: - PNGCONV(const char* _inbuf, int _inlen, const char* fname); - ~PNGCONV() {}; - bool Read(char* image); + public: + PNGCONV(const char* _inbuf, int _inlen, const char* fname); + ~PNGCONV() {}; + bool Read(char* image); }; #endif #if HAVE_LIBJPEG class JPEGCONV : public GRPCONV { - -public: - JPEGCONV(const char* _inbuf, int _inlen, const char* fname); - ~JPEGCONV() {}; - bool Read(char* image); - void SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size); - static void init_source(j_decompress_ptr cinfo); - static boolean fill_input_buffer(j_decompress_ptr cinfo); - static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); - static boolean resync_to_restart(j_decompress_ptr cinfo, int desired); - static void term_source(j_decompress_ptr cinf); + public: + JPEGCONV(const char* _inbuf, int _inlen, const char* fname); + ~JPEGCONV() {}; + bool Read(char* image); + void SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size); + static void init_source(j_decompress_ptr cinfo); + static boolean fill_input_buffer(j_decompress_ptr cinfo); + static void skip_input_data(j_decompress_ptr cinfo, long num_bytes); + static boolean resync_to_restart(j_decompress_ptr cinfo, int desired); + static void term_source(j_decompress_ptr cinf); }; #endif GRPCONV* GRPCONV::AssignConverter(const char* inbuf, int inlen, const char* fname) { /* ファイルの内容に応じたコンバーターを割り当てる */ - GRPCONV* conv = 0; - if (inlen < 10) return 0; /* invalid file */ + GRPCONV* conv = NULL; + if (inlen < 10) return NULL; /* invalid file */ if (strncmp(inbuf, "PDT10", 5) == 0 || strncmp(inbuf, "PDT11", 5) == 0) { /* PDT10 or PDT11 */ conv = new PDTCONV(inbuf, inlen, fname); - if (conv->data == 0) { delete conv; conv = 0;} + if (conv->data == NULL) { + delete conv; + conv = NULL; + } } #if HAVE_LIBPNG unsigned char png_magic[4] = {0x89, 'P', 'N', 'G'}; - if (conv == 0 && memcmp(inbuf, png_magic,4) == 0) { + if (conv == NULL && memcmp(inbuf, png_magic,4) == 0) { conv = new PNGCONV(inbuf, inlen, fname); - if (conv->data == 0) { delete conv; conv = 0;} + if (conv->data == NULL) { + delete conv; + conv = NULL; + } } #endif #if HAVE_LIBJPEG - if ( conv == 0 && *(unsigned char*)inbuf == 0xff && *(unsigned char*)(inbuf+1) == 0xd8 && + if ( conv == NULL && *(unsigned char*)inbuf == 0xff && *(unsigned char*)(inbuf+1) == 0xd8 && (strncmp(inbuf+6, "JFIF",4) == 0 || strncmp(inbuf+6,"Exif",4) == 0)) { conv = new JPEGCONV(inbuf, inlen, fname); - if (conv->data == 0) { delete conv; conv = 0;} + if (conv->data == NULL) { + delete conv; + conv = NULL; + } } #endif - if (conv == 0 && inbuf[0]=='B' && inbuf[1]=='M' && read_little_endian_int(inbuf+10)==0x36 && read_little_endian_int(inbuf+14) == 0x28) { // Windows BMP + if (conv == NULL && inbuf[0]=='B' && inbuf[1]=='M' && read_little_endian_int(inbuf+10)==0x36 && read_little_endian_int(inbuf+14) == 0x28) { // Windows BMP conv = new BMPCONV(inbuf, inlen, fname); - if (conv->data == 0) { delete conv; conv = 0;} + if (conv->data == NULL) { + delete conv; + conv = NULL; + } } - if (conv == 0 && (inbuf[0] == 0 || inbuf[0] == 1 || inbuf[0] == 2)) { /* G00 */ + if (conv == NULL && (inbuf[0] == 0 || inbuf[0] == 1 || inbuf[0] == 2)) { /* G00 */ conv = new G00CONV(inbuf, inlen, fname); - if (conv->data == 0) { delete conv; conv = 0;} + if (conv->data == NULL) { + delete conv; + conv = NULL; + } } return conv; } @@ -1050,8 +1079,6 @@ PDTCONV::PDTCONV(const char* _inbuf, int int h = read_little_endian_int(_inbuf+0x10); int mask_pt = read_little_endian_int(_inbuf + 0x1c); Init(filename, _inbuf, _inlen, w, h, mask_pt ? true : false); - - return; } @@ -1111,7 +1138,7 @@ G00CONV::G00CONV(const char* _inbuf, int } bool G00CONV::Read(char* image) { - if (data == 0) return false; + if (data == NULL) return false; /* header 識別 */ int type = *data; if (type == 0) return Read_Type0(image); @@ -1140,6 +1167,7 @@ static int bitrev_table[256] = { 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff}; + template inline int lzExtract(DataType& datatype,const char*& src, char*& dest, const char* srcend, char* destend) { int count = 0; const char* lsrcend = srcend; char* ldestend = destend; @@ -1196,6 +1224,7 @@ template dest=ldest; src=lsrc; return 0; } + /* 引数を減らすためのwrapper */ template inline int lzExtract(DataType datatype, DataSize datasize ,const char*& src, char*& dest, const char* srcend, char* destend) { return lzExtract(datatype,src,dest,srcend,destend); @@ -1203,114 +1232,119 @@ template /* 普通の PDT */ class Extract_DataType { -public: - static void ExtractData(const char*& lsrc, int& data, int& size) { - data = read_little_endian_short(lsrc) & 0xffff; - size = (data & 0x0f) + 1; - data = (data>>4)+1; - lsrc += 2; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { + public: + static void ExtractData(const char*& lsrc, int& data, int& size) { + data = read_little_endian_short(lsrc) & 0xffff; + size = (data & 0x0f) + 1; + data = (data>>4)+1; + lsrc += 2; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { #ifdef WORDS_BIGENDIAN - ldest[3] = lsrc[0]; - ldest[2] = lsrc[1]; - ldest[1] = lsrc[2]; - ldest[0] = 0; + ldest[3] = lsrc[0]; + ldest[2] = lsrc[1]; + ldest[1] = lsrc[2]; + ldest[0] = 0; #else - *(int*)ldest = read_little_endian_int(lsrc); ldest[3]=0; + *(int*)ldest = read_little_endian_int(lsrc); ldest[3]=0; #endif - lsrc += 3; ldest += 4; - } - static int IsRev(void) { return 0; } + lsrc += 3; ldest += 4; + } + static int IsRev(void) { return 0; } }; /* PDT11 の第一段階変換 */ class Extract_DataType_PDT11 { - int* index_table; -public: - Extract_DataType_PDT11(int* it) { index_table = it; } - void ExtractData(const char*& lsrc, int& data, int& size) { - data = int(*(const unsigned char*)lsrc); - size = (data>>4) + 2; - data = index_table[data&0x0f]; - lsrc++; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { - *ldest = *lsrc; - ldest++; lsrc++; - } - static int IsRev(void) { return 0; } + private: + int* index_table; + public: + Extract_DataType_PDT11(int* it) { index_table = it; } + void ExtractData(const char*& lsrc, int& data, int& size) { + data = int(*(const unsigned char*)lsrc); + size = (data>>4) + 2; + data = index_table[data&0x0f]; + lsrc++; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { + *ldest = *lsrc; + ldest++; lsrc++; + } + static int IsRev(void) { return 0; } }; + /* マスク用 */ class Extract_DataType_Mask { -public: - void ExtractData(const char*& lsrc, int& data, int& size) { - int d = read_little_endian_short(lsrc) & 0xffff; - size = (d & 0xff) + 2; - data = (d>>8)+1; - lsrc += 2; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { - *ldest = *lsrc; - ldest++; lsrc++; - } - static int IsRev(void) { return 0; } + public: + void ExtractData(const char*& lsrc, int& data, int& size) { + int d = read_little_endian_short(lsrc) & 0xffff; + size = (d & 0xff) + 2; + data = (d>>8)+1; + lsrc += 2; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { + *ldest = *lsrc; + ldest++; lsrc++; + } + static int IsRev(void) { return 0; } }; + /* 書庫用 */ class Extract_DataType_ARC { -public: - void ExtractData(const char*& lsrc, int& data, int& size) { - data = read_little_endian_short(lsrc) & 0xffff; - size = (data&0x0f) + 2; - data = (data>>4) + 1; - lsrc+= 2; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { - *ldest = *lsrc; - ldest++; lsrc++; - } - static int IsRev(void) { return 0; } + public: + void ExtractData(const char*& lsrc, int& data, int& size) { + data = read_little_endian_short(lsrc) & 0xffff; + size = (data&0x0f) + 2; + data = (data>>4) + 1; + lsrc+= 2; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { + *ldest = *lsrc; + ldest++; lsrc++; + } + static int IsRev(void) { return 0; } }; + /* avg2000 のシナリオ用 */ class Extract_DataType_SCN2k { -public: - void ExtractData(const char*& lsrc, int& data, int& size) { - data = read_little_endian_short(lsrc) & 0xffff; - size = (data&0x0f) + 2; - data = (data>>4); - lsrc+= 2; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { - *ldest = *lsrc; - ldest++; lsrc++; - } - static int IsRev(void) { return 1; } + public: + void ExtractData(const char*& lsrc, int& data, int& size) { + data = read_little_endian_short(lsrc) & 0xffff; + size = (data&0x0f) + 2; + data = (data>>4); + lsrc+= 2; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { + *ldest = *lsrc; + ldest++; lsrc++; + } + static int IsRev(void) { return 1; } }; + /* ReadLive の type0 */ class Extract_DataType_G00Type0 { -public: - static void ExtractData(const char*& lsrc, int& data, int& size) { - data = read_little_endian_short(lsrc) & 0xffff; - size = ((data & 0x0f)+ 1) * 3; - data = (data>>4) * 3; - lsrc += 2; - } - static void Copy1Pixel(const char*& lsrc, char*& ldest) { + public: + static void ExtractData(const char*& lsrc, int& data, int& size) { + data = read_little_endian_short(lsrc) & 0xffff; + size = ((data & 0x0f)+ 1) * 3; + data = (data>>4) * 3; + lsrc += 2; + } + static void Copy1Pixel(const char*& lsrc, char*& ldest) { #ifdef WORDS_BIGENDIAN - ldest[0] = lsrc[0]; - ldest[1] = lsrc[1]; - ldest[2] = lsrc[2]; + ldest[0] = lsrc[0]; + ldest[1] = lsrc[1]; + ldest[2] = lsrc[2]; #else /* LITTLE ENDIAN / intel architecture */ - *(int*)ldest = *(int*)lsrc; + *(int*)ldest = *(int*)lsrc; #endif - lsrc += 3; ldest += 3; - } - static int IsRev(void) { return 1; } + lsrc += 3; ldest += 3; + } + static int IsRev(void) { return 1; } }; bool PDTCONV::Read(char* image) { - if (data == 0) return false; + if (data == NULL) return false; if (strncmp(data, "PDT10", 5) == 0) { if (! Read_PDT10(image)) return false; @@ -1353,6 +1387,7 @@ bool PDTCONV::Read_PDT10(char* image) { while(lzExtract(Extract_DataType(), int(), src, dest, srcend, destend)) ; return true; } + bool PDTCONV::Read_PDT11(char* image) { int index_table[16]; int color_table[256]; @@ -1391,13 +1426,12 @@ void ARCINFO::Extract(char*& dest_start, const char* src = src_start; while (lzExtract(Extract_DataType_ARC(), char(), src, dest_start, src_end, dest_end)) ; src_start = (char*)src; - return; } + void ARCINFO::Extract2k(char*& dest_start, char*& src_start, char* dest_end, char* src_end) { const char* src = src_start; while (lzExtract(Extract_DataType_SCN2k(), char(), src, dest_start, src_end, dest_end)) ; src_start = (char*)src; - return; } bool ARCINFO_AVG32::ExecExtract(void) { @@ -1496,6 +1530,7 @@ bool G00CONV::Read_Type0(char* image) { delete[] uncompress_data; return true; } + bool G00CONV::Read_Type1(char* image) { int i; int uncompress_size = read_little_endian_int(data+9) + 1; @@ -1611,7 +1646,6 @@ void GRPCONV::CopyRGBA_rev(char* image, *d = (int(s[2])) | (int(s[1])<<8) | (int(s[0])<<16) | (int(s[3])<<24) | mask; d++; s += 4; } - return; } void GRPCONV::CopyRGBA(char* image, const char* buf) { @@ -1627,8 +1661,8 @@ void GRPCONV::CopyRGBA(char* image, cons *outbuf++ = read_little_endian_int(buf); buf += 4; } - return; } + void GRPCONV::CopyRGB(char* image, const char* buf) { /* 色変換を行う */ int len = width * height; @@ -1639,15 +1673,14 @@ void GRPCONV::CopyRGB(char* image, const *d = (int(s[0])) | (int(s[1])<<8) | (int(s[2])<<16) | 0xff000000; d++; s+=3; } - return; } #if HAVE_LIBPNG PNGCONV::PNGCONV(const char* _inbuf, int _inlen, const char* _filename) { int w,h,type; - png_structp png_ptr = 0; - png_infop info_ptr = 0; - png_infop end_info = 0; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + png_infop end_info = NULL; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (!png_ptr) return; @@ -1686,20 +1719,19 @@ err: else png_destroy_read_struct(&png_ptr, (png_infopp) 0,(png_infopp)0); } - return; } bool PNGCONV::Read(char* image) { - if (data == 0) return false; + if (data == NULL) return false; bool retcode = false; int bpp = is_mask ? 4 : 3; int i; char* buf; - png_bytepp row_pointers = 0; + png_bytepp row_pointers = NULL; - png_structp png_ptr = 0; - png_infop info_ptr = 0; - png_infop end_info = 0; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; + png_infop end_info = NULL; png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0); if (!png_ptr) goto err; @@ -1748,7 +1780,6 @@ void PNGCONV::png_read(png_structp png_p PNGCONV* orig = (PNGCONV*)png_get_io_ptr(png_ptr); memcpy(d, orig->png_data, sz); orig->png_data += sz; - return; } #endif /* HAVE_LIBPNG */ @@ -1765,16 +1796,16 @@ JPEGCONV::JPEGCONV(const char* _inbuf, i Init(filename, _inbuf, _inlen, cinfo.image_width, cinfo.image_height, false); } delete cinfo.src; - cinfo.src = 0; + cinfo.src = NULL; jpeg_destroy_decompress(&cinfo); - return; } bool JPEGCONV::Read(char* image) { - if (data == 0) return false; + if (data == NULL) return false; bool retcode = false; - JSAMPARRAY rows, rows_orig; int i; - char* buf = 0; + JSAMPARRAY rows, rows_orig; + int i; + char* buf = NULL; struct jpeg_decompress_struct cinfo; struct jpeg_error_mgr jerr; @@ -1807,13 +1838,14 @@ bool JPEGCONV::Read(char* image) { retcode = true; err: delete cinfo.src; - cinfo.src = 0; + cinfo.src = NULL; jpeg_destroy_decompress(&cinfo); return retcode; } void JPEGCONV::init_source(j_decompress_ptr cinfo) { } + boolean JPEGCONV::fill_input_buffer(j_decompress_ptr cinfo) { static char dummy[1024]; memset(dummy, 0, 1024); @@ -1822,15 +1854,18 @@ boolean JPEGCONV::fill_input_buffer(j_de fprintf(stderr,"JPEGCONV::fill_input_buffer: warning corrupted jpeg stream\n"); return TRUE; } + void JPEGCONV::skip_input_data(j_decompress_ptr cinfo, long num_bytes) { if (cinfo->src->bytes_in_buffer > num_bytes) { cinfo->src->next_input_byte += num_bytes; cinfo->src->bytes_in_buffer -= num_bytes; } } + boolean JPEGCONV::resync_to_restart(j_decompress_ptr cinfo, int desired) { return jpeg_resync_to_restart(cinfo, desired); } + void JPEGCONV::term_source(j_decompress_ptr cinf) { } @@ -1843,6 +1878,7 @@ void JPEGCONV::SetupSrc(struct jpeg_deco cinfo->src->resync_to_restart = resync_to_restart; cinfo->src->term_source = term_source; } + #endif /* HAVE_LIBJPEG */ BMPCONV::BMPCONV(const char* _inbuf, int _inlen, const char* _filename) { /* データから情報読み込み */ @@ -1852,11 +1888,10 @@ BMPCONV::BMPCONV(const char* _inbuf, int int bpp = read_little_endian_short(_inbuf + 0x1c); int comp = read_little_endian_int(_inbuf + 0x1e); Init(filename, _inbuf, _inlen, w, h, bpp==32 ? true : false); - return; } bool BMPCONV::Read(char* image) { - if (data == 0) return false; + if (data == NULL) return false; /* マスクのチェック */ int bpp = read_little_endian_short(data+0x1c); diff --git a/system/file.h b/system/file.h --- a/system/file.h +++ b/system/file.h @@ -34,10 +34,10 @@ // read 'KANON' compressed file -#include -#include -#include -#include +#include +#include +#include +#include #ifdef HAVE_CONFIG_H # include "config.h" @@ -107,128 +107,128 @@ class ARCINFO; class ARCFILE_ATOM; class KEYHOLDER { -public: - void SetKey(char[16]); - void SetKey2(char[33]); - void GuessKey(char*); - const char* GetKey(void); -private: - char key[16]; + public: + void SetKey(char[16]); + void SetKey2(char[33]); + void GuessKey(char*); + const char* GetKey(void); + private: + char key[16]; }; class FILESEARCH { -public: + public: #define TYPEMAX 14 - enum FILETYPE { - /* 一応、0 - 15 まで reserved */ - ALL = 1, /* dat/ 以下のファイル(デフォルトの検索先) */ - ROOT= 2, /* ゲームのインストールディレクトリ */ - PDT = 3, /* default: PDT/ */ - SCN = 4, /* default: DAT/SEEN.TXT */ - ANM = 5, /* default: DAT/ALLANM.ANL */ - ARD = 6, /* default: DAT/ALLARD.ARD */ - CUR = 7, /* default: DAT/ALLCUR.CUR */ - MID = 8, /* default: ALL */ - WAV = 9, /* default: ALL */ - KOE = 10, /* default: KOE/ */ - BGM = 11, /* default: BGM */ - MOV = 12, /* default : MOV */ - GAN = 13 /* default : MOV */ - }; - enum ARCTYPE {ATYPE_DIR, ATYPE_ARC, ATYPE_SCN2k}; -private: - /* InitRoot() の時点で初期化される変数 */ - DIRFILE* root_dir; - DIRFILE* dat_dir; - ARCFILE* searcher[TYPEMAX]; - /* ファイルの存在位置の information */ - ARCTYPE is_archived[TYPEMAX]; - const char* filenames[TYPEMAX]; - /* デフォルトの information */ - static ARCTYPE default_is_archived[TYPEMAX]; - static const char* default_dirnames[TYPEMAX]; -public: - FILESEARCH(void); - ~FILESEARCH(); - /* 初めにゲームのデータがあるディレクトリを設定する必要がある */ - int InitRoot(char* root); - /* ファイルの型ごとの情報をセットする */ - void SetFileInformation(FILETYPE type, ARCTYPE is_arc, - char* filename); - /* 複数のファイルを一つの型に関連づける */ - void AppendFileInformation(FILETYPE type, ARCTYPE is_arc, - char* filename); - ARCFILE* MakeARCFILE(ARCTYPE tp, const char* filename); - /* fname で指定された名前のファイルを検索 */ - class ARCINFO* Find(FILETYPE type, const char* fname, const char* ext=0); - /* ある種類のファイルをすべてリストアップ - ** 末尾は NULL pointer - */ - char** ListAll(FILETYPE type); + enum FILETYPE { + /* 一応、0 - 15 まで reserved */ + ALL = 1, /* dat/ 以下のファイル(デフォルトの検索先) */ + ROOT= 2, /* ゲームのインストールディレクトリ */ + PDT = 3, /* default: PDT/ */ + SCN = 4, /* default: DAT/SEEN.TXT */ + ANM = 5, /* default: DAT/ALLANM.ANL */ + ARD = 6, /* default: DAT/ALLARD.ARD */ + CUR = 7, /* default: DAT/ALLCUR.CUR */ + MID = 8, /* default: ALL */ + WAV = 9, /* default: ALL */ + KOE = 10, /* default: KOE/ */ + BGM = 11, /* default: BGM */ + MOV = 12, /* default : MOV */ + GAN = 13 /* default : MOV */ + }; + enum ARCTYPE {ATYPE_DIR, ATYPE_ARC, ATYPE_SCN2k}; + private: + /* InitRoot() の時点で初期化される変数 */ + DIRFILE* root_dir; + DIRFILE* dat_dir; + ARCFILE* searcher[TYPEMAX]; + /* ファイルの存在位置の information */ + ARCTYPE is_archived[TYPEMAX]; + const char* filenames[TYPEMAX]; + /* デフォルトの information */ + static ARCTYPE default_is_archived[TYPEMAX]; + static const char* default_dirnames[TYPEMAX]; + public: + FILESEARCH(void); + ~FILESEARCH(); + /* 初めにゲームのデータがあるディレクトリを設定する必要がある */ + int InitRoot(char* root); + /* ファイルの型ごとの情報をセットする */ + void SetFileInformation(FILETYPE type, ARCTYPE is_arc, + char* filename); + /* 複数のファイルを一つの型に関連づける */ + void AppendFileInformation(FILETYPE type, ARCTYPE is_arc, + char* filename); + ARCFILE* MakeARCFILE(ARCTYPE tp, const char* filename); + /* fname で指定された名前のファイルを検索 */ + class ARCINFO* Find(FILETYPE type, const char* fname, const char* ext=0); + /* ある種類のファイルをすべてリストアップ + ** 末尾は NULL pointer + */ + char** ListAll(FILETYPE type); }; class ARCINFO { -protected: - /* ファイルそのものの情報 */ - ARCFILE_ATOM& info; - char* arcfile; - /* mmap している場合、その情報 */ - bool use_mmap; - char* mmapped_memory; - int fd; - /* ファイル内容の入っているバッファ */ - const char* data; + protected: + /* ファイルそのものの情報 */ + ARCFILE_ATOM& info; + char* arcfile; + /* mmap している場合、その情報 */ + bool use_mmap; + char* mmapped_memory; + int fd; + /* ファイル内容の入っているバッファ */ + const char* data; -protected: - ARCINFO(const char* arcfile, ARCFILE_ATOM& from); // only from ARCFILE - friend class ARCFILE; - friend class DIRFILE; + protected: + ARCINFO(const char* arcfile, ARCFILE_ATOM& from); // only from ARCFILE + friend class ARCFILE; + friend class DIRFILE; - virtual bool ExecExtract(void); -public: - /* dest は256byte 程度の余裕があること */ - static void Extract(char*& dest, char*& src, char* destend, char* srcend); - static void Extract2k(char*& dest, char*& src, char* destend, char* srcend); - virtual ~ARCINFO(); - /* 必要なら Read 前に呼ぶことで処理を分割できる */ - int Size(void) const; - char* CopyRead(void); /* Read() して内容のコピーを返す */ - const char* Read(void); - /* ファイルが regular file の場合、ファイル名を帰す */ - /* そうでないなら 0 を帰す */ - const char* Path(void) const; - FILE* OpenFile(int* length=0) const; /* 互換性のため:raw file の場合、ファイルを開く */ + virtual bool ExecExtract(void); + public: + /* dest は256byte 程度の余裕があること */ + static void Extract(char*& dest, char*& src, char* destend, char* srcend); + static void Extract2k(char*& dest, char*& src, char* destend, char* srcend); + virtual ~ARCINFO(); + /* 必要なら Read 前に呼ぶことで処理を分割できる */ + int Size(void) const; + char* CopyRead(void); /* Read() して内容のコピーを返す */ + const char* Read(void); + /* ファイルが regular file の場合、ファイル名を帰す */ + /* そうでないなら 0 を帰す */ + const char* Path(void) const; + FILE* OpenFile(int* length=0) const; /* 互換性のため:raw file の場合、ファイルを開く */ }; class GRPCONV { -public: - int width; - int height; - bool is_mask; + public: + int width; + int height; + bool is_mask; - const char* filename; - const char* data; - int datalen; + const char* filename; + const char* data; + int datalen; - int Width(void) { return width;} - int Height(void) { return height;} - bool IsMask(void) { return is_mask;} + int Width(void) { return width;} + int Height(void) { return height;} + bool IsMask(void) { return is_mask;} - GRPCONV(void); - virtual ~GRPCONV(); - void Init(const char* fname, const char* data, int dlen, int width, int height, bool is_mask); + GRPCONV(void); + virtual ~GRPCONV(); + void Init(const char* fname, const char* data, int dlen, int width, int height, bool is_mask); - virtual bool Read(char* image) = 0; - static GRPCONV* AssignConverter(const char* inbuf, int inlen, const char* fname); - static GRPCONV* AssignConverter(ARCINFO* info) { - const char* dat = info->Read(); - if (dat == 0) return 0; - return AssignConverter(dat, info->Size(), "???"); - } - void CopyRGBA(char* image, const char* from); - void CopyRGB(char* image, const char* from); - void CopyRGBA_rev(char* image, const char* from); - void CopyRGB_rev(char* image, const char* from); + virtual bool Read(char* image) = 0; + static GRPCONV* AssignConverter(const char* inbuf, int inlen, const char* fname); + static GRPCONV* AssignConverter(ARCINFO* info) { + const char* dat = info->Read(); + if (dat == 0) return 0; + return AssignConverter(dat, info->Size(), info->Path()); //FIXME: Is it really okay? + } + void CopyRGBA(char* image, const char* from); + void CopyRGB(char* image, const char* from); + void CopyRGBA_rev(char* image, const char* from); + void CopyRGB_rev(char* image, const char* from); }; extern FILESEARCH file_searcher; diff --git a/system/file_impl.h b/system/file_impl.h --- a/system/file_impl.h +++ b/system/file_impl.h @@ -30,7 +30,7 @@ #ifndef __FILE_IMPL_H__ #define __FILE_IMPL_H__ -#include +#include struct ARCFILE_ATOM { char* filename; @@ -48,110 +48,117 @@ struct ARCFILE_ATOM { }; class ARCFILE { -protected: - char* arcname; - char* filenames_orig; - int list_point; - std::vector arc_atom; - typedef std::vector::iterator iterator; - ARCFILE* next; /* FILESEARCH の一つの型が複数の ARCFILE を持つとき、リストをつくる */ - /* arcname に指定されたファイル/ディレクトリの内容チェック */ - virtual int CheckFileDeal(void); - virtual void ListupFiles(int fname_len); - virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM&); - iterator SearchName(const char* f, const char* ext=0); -public: - ARCFILE(const char* fname); - void SetNext(ARCFILE* _next) { delete next; next = _next;} - ARCFILE* Next(void) { return next; } - void Init(void); - virtual ~ARCFILE(); - /* ファイル検索 */ - class ARCINFO* Find(const char* fname, const char* ext); - /* ファイルリストの出力 */ - int Deal(void) { Init(); return arc_atom.size(); } - void ListFiles(FILE* out); - void InitList(void); - char* ListItem(void); + protected: + char* arcname; + char* filenames_orig; + int list_point; + std::vector arc_atom; + typedef std::vector::iterator iterator; + ARCFILE* next; /* FILESEARCH の一つの型が複数の ARCFILE を持つとき、リストをつくる */ + /* arcname に指定されたファイル/ディレクトリの内容チェック */ + virtual int CheckFileDeal(void); + virtual void ListupFiles(int fname_len); + virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM&); + iterator SearchName(const char* f, const char* ext=0); + public: + ARCFILE(const char* fname); + void SetNext(ARCFILE* _next) { delete next; next = _next;} + ARCFILE* Next(void) { return next; } + void Init(void); + virtual ~ARCFILE(); + /* ファイル検索 */ + class ARCINFO* Find(const char* fname, const char* ext); + /* ファイルリストの出力 */ + int Deal(void) { Init(); return arc_atom.size(); } + void ListFiles(FILE* out); + void InitList(void); + char* ListItem(void); }; class SCN2kFILE : public ARCFILE { -protected: - virtual int CheckFileDeal(void); - virtual void ListupFiles(int fname_len); - virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); -public: - SCN2kFILE(char* fname) : ARCFILE(fname) {} - virtual ~SCN2kFILE() {} + protected: + virtual int CheckFileDeal(void); + virtual void ListupFiles(int fname_len); + virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); + public: + SCN2kFILE(char* fname) : ARCFILE(fname) {} + virtual ~SCN2kFILE() {} }; class CattleyaFILE : public ARCFILE { - bool is_compress; - /* header の Huffman 木構築用 */ - char* bitbuf; - char* bitbuf_end; - int ltree[0x400]; - int rtree[0x400]; - int treecnt; - int bitcnt; - int GetBit(void); - int GetCh(void); - void SetBuf(char* buf, int len); - int MakeTree(void); - int Decode(int seed); + private: + bool is_compress; + /* header の Huffman 木構築用 */ + char* bitbuf; + char* bitbuf_end; + int ltree[0x400]; + int rtree[0x400]; + int treecnt; + int bitcnt; + int GetBit(void); + int GetCh(void); + void SetBuf(char* buf, int len); + int MakeTree(void); + int Decode(int seed); -protected: - virtual int CheckFileDeal(void); - virtual void ListupFiles(int fname_len); - virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); -public: - CattleyaFILE(char* fname) : ARCFILE(fname) {is_compress = false;} - virtual ~CattleyaFILE() {} + protected: + virtual int CheckFileDeal(void); + virtual void ListupFiles(int fname_len); + virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); + + public: + CattleyaFILE(char* fname) : ARCFILE(fname) {is_compress = false;} + virtual ~CattleyaFILE() {} }; class NULFILE : public ARCFILE { -protected: - virtual int CheckFileDeal(void); - virtual void ListupFiles(int fname_len); - virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); -public: - NULFILE() : ARCFILE("") {} - virtual ~NULFILE() {} + protected: + virtual int CheckFileDeal(void); + virtual void ListupFiles(int fname_len); + virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); + public: + NULFILE() : ARCFILE("") {} + virtual ~NULFILE() {} }; + class DIRFILE : public ARCFILE { -protected: - virtual int CheckFileDeal(void); - virtual void ListupFiles(int fname_len); - virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); -public: - DIRFILE(char* fname) : ARCFILE(fname) {} - virtual ~DIRFILE() {} - FILE* Open(const char* fname); /* FILE* を開く */ - char* SearchFile(const char* dirname); /* ファイル検索 */ + protected: + virtual int CheckFileDeal(void); + virtual void ListupFiles(int fname_len); + virtual ARCINFO* MakeARCINFO(ARCFILE_ATOM& atom); + public: + DIRFILE(char* fname) : ARCFILE(fname) {} + virtual ~DIRFILE() {} + FILE* Open(const char* fname); /* FILE* を開く */ + char* SearchFile(const char* dirname); /* ファイル検索 */ }; + class ARCINFO_AVG32 : public ARCINFO { - ARCINFO_AVG32(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { - } - virtual bool ExecExtract(void); - friend class ARCFILE; + protected: + ARCINFO_AVG32(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { + } + virtual bool ExecExtract(void); + friend class ARCFILE; }; + class ARCINFO2k : public ARCINFO { - static char decode_seed[256]; - static char decode_seed2[16]; -protected: - ARCINFO2k(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name,atom) { - } - virtual bool ExecExtract(void); - friend class SCN2kFILE; + private: + static char decode_seed[256]; + static char decode_seed2[16]; + protected: + ARCINFO2k(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name,atom) { + } + virtual bool ExecExtract(void); + friend class SCN2kFILE; }; class ARCINFOZ : public ARCINFO { -protected: - ARCINFOZ(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { - } - virtual bool ExecExtract(void); - friend class DaemonBaneFILE; - friend class CattleyaFILE; + protected: + ARCINFOZ(const char* name, ARCFILE_ATOM& atom) : ARCINFO(name, atom) { + } + virtual bool ExecExtract(void); + friend class DaemonBaneFILE; + friend class CattleyaFILE; }; #endif /* __FILE_IMPL_H__ */ diff --git a/system/system_config.cc b/system/system_config.cc --- a/system/system_config.cc +++ b/system/system_config.cc @@ -71,8 +71,10 @@ public: } }; HashStr::HashStr(const char* s ) { - if (s == 0 || s[0] == '\0') { - str = 0; hash = 0; return; /* invalid string */ + if (s == NULL || s[0] == '\0') { + str = NULL; + hash = 0; + return; /* invalid string */ } char* new_str = new char[strlen(s)+1]; strcpy(new_str, s); @@ -86,8 +88,9 @@ HashStr::HashStr(const char* s ) { hash = (unsigned int)h; } HashStr::HashStr(const HashStr& orig) { - if (orig.str == 0 || orig.str[0] == '\0') { - str = 0; hash = 0; return; /* invalid */ + if (orig.str == NULL || orig.str[0] == '\0') { + str = NULL; + hash = 0; return; /* invalid */ } char* new_str = new char[strlen(orig.str)+1]; strcpy(new_str, orig.str); @@ -130,9 +133,9 @@ class AyuSysConfigStringItem { char* new_data; public: AyuSysConfigStringItem(void) { - original_data = 0; - old_data = 0; - new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; } ~AyuSysConfigStringItem(void) { if (original_data) delete[] original_data; @@ -140,7 +143,9 @@ public: if (new_data) delete[] new_data; } AyuSysConfigStringItem(const AyuSysConfigStringItem& o) { - original_data = 0; old_data = 0; new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; if (o.original_data) { original_data = new char[strlen(o.original_data)+1]; strcpy(original_data, o.original_data); @@ -185,11 +190,11 @@ public: ** 変化を反映 */ int DiffOriginalLen(void) { - if (new_data == 0) return 0; + if (new_data == NULL) return 0; return strlen(new_data)+1; } void DiffOriginal(string& data) { - if (new_data == 0) { /* あり得ない */ + if (new_data == NULL) { /* あり得ない */ fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n"); return; } @@ -218,9 +223,9 @@ public: } const char* PatchOriginal(const char* data) { static const char* table = "?\"',.:;=<>"; - if (new_data) delete[] new_data; - if (old_data) delete[] old_data; - new_data = 0; old_data = 0; + if (new_data != NULL) delete[] new_data; + if (old_data != NULL) delete[] old_data; + old_data = NULL; new_data = new char[1024]; int i,j = 0; for (i=0; i<1020; i++) { @@ -244,7 +249,8 @@ public: void SetOriginal(void) { if (new_data) delete[] new_data; if (old_data) delete[] old_data; - new_data = 0; old_data = 0; + new_data = NULL; + old_data = NULL; } void Dump(FILE* f) const { if (original_data) fprintf(f, "original %s ",original_data); @@ -266,9 +272,9 @@ class AyuSysConfigIntlistItem { public: AyuSysConfigIntlistItem(void) { item_deal = 0; - original_data = 0; - old_data = 0; - new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; } ~AyuSysConfigIntlistItem(void) { if (original_data) delete[] original_data; @@ -277,7 +283,9 @@ public: } AyuSysConfigIntlistItem(const AyuSysConfigIntlistItem& o) { item_deal = o.item_deal; - original_data = 0; old_data = 0; new_data = 0; + original_data = NULL; + old_data = NULL; + new_data = NULL; if (o.original_data) { original_data = new int[item_deal]; memcpy(original_data, o.original_data, sizeof(int)*item_deal); @@ -294,7 +302,7 @@ public: /* 設定:Init で初期化、Set で変更、Get で変更を優先して取り出す */ void Init(int deal, const int* list) { /* deal は無視 */ if (original_data) delete[] original_data; - original_data = 0; + original_data = NULL; if (deal <= 0) { item_deal = 0; return; } @@ -309,20 +317,20 @@ public: memcpy(new_data, list, sizeof(int)*item_deal); } const int* Get(int deal) const {/* deal は無視 */ - if (item_deal == 0) return 0; + if (item_deal == 0) return NULL; if (deal > item_deal) { fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal); - return 0; + return NULL; } if (new_data) return new_data; else if (old_data) return old_data; return original_data; } const int* GetOriginal(int deal) const {/* deal は無視 */ - if (item_deal == 0) return 0; + if (item_deal == 0) return NULL; if (deal > item_deal) { fprintf(stderr,"AyuSysConfigIntlistItem::Get : invalid items deal %d (correct: %d)\n",deal,item_deal); - return 0; + return NULL; } return original_data; } @@ -334,11 +342,11 @@ public: ** 変化を反映 */ int DiffOriginalLen(void) { - if (new_data == 0) return 0; + if (new_data == NULL) return 0; return 12 * item_deal + 1; } void DiffOriginal(string& data) { - if (new_data == 0) { /* あり得ない */ + if (new_data == NULL) { /* あり得ない */ fprintf(stderr,"AyuSysConfigStringItem::DiffOriginal : this method must not called if not required!\n"); return; } @@ -352,12 +360,12 @@ public: const char* PatchOriginal(const char* data) { if (old_data) delete[] old_data; if (new_data) delete[] new_data; - old_data = 0; new_data = 0; + old_data = NULL; new_data = new int[item_deal]; int i; for (i=0; i maptype data; public: void SetOrig(HashStr& name, int deal, const DataType* str) { - if (str == 0) return; /* 無効 */ + if (str == NULL) return; /* 無効 */ data[name].Init(deal, str); } void Set(HashStr& name, int deal, const DataType* new_data) { - if (new_data == 0) return; /* 無効 */ + if (new_data == NULL) return; /* 無効 */ /* 設定を検索 */ mapiterator it = data.find(name); /* 設定が元設定に見つからないなら失敗 */ @@ -428,17 +437,17 @@ public: /* 新しい設定を優先して返す */ const DataType* Get(int deal, HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.Get(deal); } const DataType* GetOriginal(int deal, HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.GetOriginal(deal); } int Deal(HashStr& name) const { const_mapiterator it = data.find(name); - if (it == data.end()) return 0; + if (it == data.end()) return NULL; return it->second.Deal(); } /* オリジナルからの変化の調査 : @@ -463,7 +472,7 @@ public: while(*diff_data != ';') { char name[1024]; const char* data_start = strchr(diff_data, '='); - if (data_start == 0) break; + if (data_start == NULL) break; strncpy(name, diff_data, data_start-diff_data); name[data_start-diff_data] = 0; data_start++; @@ -527,7 +536,7 @@ int AyuSysConfig::SearchParam(const char strncpy(name_copy, name, 1000); name_copy[1000] = 0; char* s; - for (s=name_copy; s != 0; s = strchr(s,'.')) { + for (s=name_copy; s != NULL; s = strchr(s,'.')) { if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) { s[1] = '0'; s[2] = '0'; s[3] = '0'; } @@ -541,7 +550,7 @@ int AyuSysConfig::SearchParam(const char const char* AyuSysConfig::GetParaStr(const char* name) const{ HashStr str(name); const char* ret = str_config->orig.Get(1,str); - if (ret == 0) { + if (ret == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); } return ret; @@ -550,7 +559,7 @@ int AyuSysConfig::GetParam(const char* n HashStr str(name); va_list va; int i; const int* vars = int_config->orig.Get(deal, str); - if (vars == 0) { + if (vars == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); va_start(va, deal); for (i=0; iorig.GetOriginal(deal, str); - if (vars == 0) { + if (vars == NULL) { // fprintf(stderr,"Cannot find config name '%s'\n",name); va_start(va, deal); for (i=0; iorig.Deal(str) == 0) { deal = 0; return 0; } + if (int_config->orig.Deal(str) == 0) { + deal = 0; + return NULL; + } deal = int_config->orig.Deal(str); const int* vars = int_config->orig.Get(deal, str); - if (vars == 0) { deal = 0; return 0; } + if (vars == NULL) { + deal = 0; + return NULL; + } return vars; } void AyuSysConfig::SetParaStr(const char* name, const char* var) { @@ -882,7 +897,7 @@ bool AyuSysConfig::LoadInitFile(void) if (info == NULL) return false; int size = info->Size(); unsigned char* buf_orig = (unsigned char*)info->Read(); - if (size <= 0 || buf_orig == 0) { + if (size <= 0 || buf_orig == NULL) { delete info; return false; } unsigned char* buf_end = buf_orig + size; @@ -907,7 +922,9 @@ bool AyuSysConfig::LoadInitFile(void) continue; } /* 初期化 */ - token_deal = 1; tokens[0] = buf; buf_ptr = 0; + token_deal = 1; + tokens[0] = buf; + buf_ptr = NULL; int in_quote = 0; while(buf_orig < buf_end && buf_ptr < 1023) { @@ -930,7 +947,8 @@ bool AyuSysConfig::LoadInitFile(void) if (c == '\n' || c == '\r') break; /* = なら次の token */ if (c == '=') { - c = 0; tokens[token_deal++] = buf+buf_ptr+1; + c = 0; + tokens[token_deal++] = buf+buf_ptr+1; if (token_deal >= MAXTOKEN) break; } else if (c == '\"') { in_quote = 1; buf_orig++; continue; @@ -1069,7 +1087,7 @@ bool AyuSysConfig::LoadInitFile(void) /* 第二トークンの3つめのパラメータを得る(繰り返しの時の再生開始位置) */ int start_pt = 0; const char* tk1 = strchr(tokens[1], '-'); - const char* tk2 = 0; + const char* tk2 = NULL; if (tk1 && *tk1) tk2 = strchr(tk1+1, '-'); if (tk2 && *tk2) start_pt = atoi(tk2+1); if (token_deal == 3) { @@ -1224,15 +1242,15 @@ const char* TrackName::WaveTrack(char* n for (i=0; name[i]!=0; i++) buf[i]=tolower(name[i]); buf[i]=0; for (i=0; i= se_deal) return 0; + if (n < 0 || n >= se_deal) return NULL; return se_track[n]; } void TrackName::AddSE(int n, char* file) { diff --git a/system/system_config.h b/system/system_config.h --- a/system/system_config.h +++ b/system/system_config.h @@ -22,29 +22,31 @@ * */ -#include +#include /* CD Track 名 <-> Track 番号の変換を行う */ class TrackName { - char** track; - int* track_num; - char** track_wave; - int* track_start; - int deal; - void Expand(void); - char** se_track; - int se_deal; - void ExpandSE(int num); -public: - TrackName(void); - ~TrackName(void); - void AddCDROM(char* name, int track); - void AddWave(char* name, char* wave, int start_pt); - void AddSE(int num, char* se); - int CDTrack(char* name); - int TrackStart(char* name); - const char* WaveTrack(char* name); - const char* SETrack(int num); + private: + char** track; + int* track_num; + char** track_wave; + int* track_start; + int deal; + void Expand(void); + char** se_track; + int se_deal; + void ExpandSE(int num); + + public: + TrackName(void); + ~TrackName(void); + void AddCDROM(char* name, int track); + void AddWave(char* name, char* wave, int start_pt); + void AddSE(int num, char* se); + int CDTrack(char* name); + int TrackStart(char* name); + const char* WaveTrack(char* name); + const char* SETrack(int num); }; /* gameexe.ini で設定されるパラメータ */ /* まず初めに、設定項目を SetOrigPara* でセットする @@ -55,54 +57,54 @@ public: */ class AyuSysConfig { - friend class Conf2; /* テスト用のクラス */ - int change_flag; - int dirty_flag; - class AyuSysConfigString* str_config; - class AyuSysConfigIntlist* int_config; + private: + int change_flag; + int dirty_flag; + class AyuSysConfigString* str_config; + class AyuSysConfigIntlist* int_config; -public: - TrackName track_name; + public: + TrackName track_name; -public: - AyuSysConfig(void); - ~AyuSysConfig(); - bool LoadInitFile(void); - /* パラメータを検索する */ - /* str なら 1, int なら 2, 見つからないなら 0 */ - int SearchParam(const char* name) const; - /* パラメータを得る */ - const char* GetParaStr(const char* name) const; /* str */ - int GetParam(const char* name, int deal, ...) const; /* int, error -> return -1, no error -> return 0 */ - int GetOriginalParam(const char* name, int deal, ...) const; /* int, error -> return -1, no error -> return 0 */ - int GetParaInt(const char* name) const { - int n; - if (GetParam(name,1,&n)) return 0; - return n; - } - const int* GetParamArray(const char* name, int& deal) const; - /* パラメータを変更する */ - void SetParaStr(const char* name, const char* var); /* str */ - void SetParam(const char* name, int deal, ...); /* int */ -private: - friend class AyuSys; - /* 元設定を行う */ - /* AyuSys からのみ可能 */ - void SetOrigParaStr(const char* name, const char* var); /* str */ - void SetOrigParam(const char* name, int para_deal, ...); /* int */ - void SetOrigParamArray(const char* name, int deal, int* array); /* 上とおなじ */ -public: + public: + AyuSysConfig(void); + ~AyuSysConfig(); + bool LoadInitFile(void); + /* パラメータを検索する */ + /* str なら 1, int なら 2, 見つからないなら 0 */ + int SearchParam(const char* name) const; + /* パラメータを得る */ + const char* GetParaStr(const char* name) const; /* str */ + int GetParam(const char* name, int deal, ...) const; /* int, error -> return -1, no error -> return 0 */ + int GetOriginalParam(const char* name, int deal, ...) const; /* int, error -> return -1, no error -> return 0 */ + int GetParaInt(const char* name) const { + int n; + if (GetParam(name,1,&n)) return 0; + return n; + } + const int* GetParamArray(const char* name, int& deal) const; + /* パラメータを変更する */ + void SetParaStr(const char* name, const char* var); /* str */ + void SetParam(const char* name, int deal, ...); /* int */ - /* オリジナルの設定関係 - ** SetOriginal : 全ての設定を初めの状態に戻す - ** DiffOriginal : 初めの状態と現在の状態の変更分を得る - ** PatchOriginal: DiffOriginal で得た文字列を引数に - ** 渡す。DiffOriginal 呼び出し時の状態に戻す - */ - void SetOriginal(void); - void DiffOriginal(std::string&); - const char* PatchOriginal(const char*); - /* config の内容を表示する */ - void Dump(FILE* f) const; + private: + /* 元設定を行う */ + /* AyuSys からのみ可能 */ + void SetOrigParaStr(const char* name, const char* var); /* str */ + void SetOrigParam(const char* name, int para_deal, ...); /* int */ + void SetOrigParamArray(const char* name, int deal, int* array); /* 上とおなじ */ + + public: + /* オリジナルの設定関係 + ** SetOriginal : 全ての設定を初めの状態に戻す + ** DiffOriginal : 初めの状態と現在の状態の変更分を得る + ** PatchOriginal: DiffOriginal で得た文字列を引数に + ** 渡す。DiffOriginal 呼び出し時の状態に戻す + */ + void SetOriginal(void); + void DiffOriginal(std::string&); + const char* PatchOriginal(const char*); + /* config の内容を表示する */ + void Dump(FILE* f) const; }; diff --git a/system/visarc.cc b/system/visarc.cc --- a/system/visarc.cc +++ b/system/visarc.cc @@ -64,7 +64,7 @@ void usage(void) { void List(char* path) { ARCFILE* file; FILE* f = fopen(path, "rb"); - if (f == 0) return; + if (f == NULL) return; char header[32]; fread(header, 32, 1, f); fclose(f); @@ -74,17 +74,16 @@ void List(char* path) { file->Init(); file->ListFiles(stdout); delete file; - return; } void ExtractOne(ARCFILE* arc, char* file) { ARCINFO* info = arc->Find(file,""); - if (info == 0) { + if (info == NULL) { fprintf(stderr, "Cannot find file %s in archive\n",file); return; } FILE* out = fopen(file, "w"); - if (out == 0) { + if (out == NULL) { delete info; fprintf(stderr, "Cannot open output file %s\n",file); return; @@ -97,13 +96,12 @@ void ExtractOne(ARCFILE* arc, char* file fclose(out); fprintf(stdout, "done\n"); delete info; - return; } void Extract(char* path, char** files, int fnum) { ARCFILE* file; FILE* f = fopen(path, "rb"); - if (f == 0) return; + if (f == NULL) return; char header[32]; fread(header, 32, 1, f); fclose(f); @@ -111,23 +109,23 @@ void Extract(char* path, char** files, i if (strncmp(header, "PACL", 4) == 0) file = new ARCFILE(path); else file = new SCN2kFILE(path); file->Init(); - if (files != 0 && fnum != 0) { + if (files != NULL && fnum != 0) { int i; for (i=0; iInitList(); - char* path; while( (path=file->ListItem()) != 0) { + char* path; + while( (path=file->ListItem()) != 0) { ExtractOne(file, path); } } delete file; - return; } void ChangeExt(char* path, char* new_ext, char* buf) { char* name = strrchr(path, DIR_SPLIT); - if (name == 0) name = path; + if (name == NULL) name = path; else name++; int path_len = name - path; @@ -142,8 +140,10 @@ void ChangeExt(char* path, char* new_ext char* ReadFile(char* fname, int* len) { FILE* in = fopen(fname, "rb"); - if (in == 0) return 0; - fseek(in,0,2); size_t s = ftell(in); fseek(in,0,0); + if (in == NULL) return 0; + fseek(in, 0, SEEK_END); + size_t s = ftell(in); + fseek(in, 0, SEEK_SET); char* buf = new char[s]; fread(buf,s,1,in); fclose(in); @@ -215,19 +215,18 @@ void create_png(FILE* stream, char* path } png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); - return; } void ExtractPngRgbaGraphic(char* path,char* outpath = 0) { char buf[1024]; char* fname = buf; int len; char* dat = ReadFile(path, &len); - if (dat == 0) { + if (dat == NULL) { fprintf(stderr, "Cannot open PDT file : %s\n",path); return; } GRPCONV* conv = GRPCONV::AssignConverter(dat, len, path); - if (conv == 0) { + if (conv == NULL) { fprintf(stderr, "Invalid format\n"); return; } @@ -243,10 +242,10 @@ void ExtractPngRgbaGraphic(char* path,ch data[4*i+3] = 0xff; // 不透明度を最大にする } } - if (outpath == 0) ChangeExt(path,".png", buf); // path をつくる + if (outpath == NULL) ChangeExt(path,".png", buf); // path をつくる else fname = outpath; FILE* out = fopen(fname, "wb"); // ファイルを開く - if (out == 0) { + if (out == NULL) { fprintf(stderr, "Cannot open raw file : %s\n",buf); delete conv; return; diff --git a/window/button.cc b/window/button.cc --- a/window/button.cc +++ b/window/button.cc @@ -348,11 +348,32 @@ static char* extract_button(int number, char* data; switch(number) { - case 0: data = buttonleft; size = buttonleft_cnt; width = 164; height = 110; break; - case 1: data = buttonright; size = buttonright_cnt; width = 164; height = 110; break; - case 2: data = buttonup; size = buttonup_cnt; width = 110; height = 164; break; - case 3: data = buttondown; size = buttondown_cnt; width = 110; height = 164; break; - default: return 0; + case 0: + data = buttonleft; + size = buttonleft_cnt; + width = 164; + height = 110; + break; + case 1: + data = buttonright; + size = buttonright_cnt; + width = 164; + height = 110; + break; + case 2: + data = buttonup; + size = buttonup_cnt; + width = 110; + height = 164; + break; + case 3: + data = buttondown; + size = buttondown_cnt; + width = 110; + height = 164; + break; + default: + return NULL; } char* out = new char[width*height]; @@ -388,6 +409,7 @@ struct ButtonColor { void SetBrightness1(int n, int c1); void SetBrightness(int c1, int c2, int c3, int c4, int c5); }; + ButtonColor::ButtonColor(int r, int g, int b) { is_gray = false; if (r == g && r == b) { @@ -436,6 +458,7 @@ ButtonColor::ButtonColor(int r, int g, i if (l < 128) s = (hd*255)/(max+min); else s = (hd*255) / (510-(max+min)); } + void ButtonColor::SetBrightness1(int n, int c1) { if (n < 1 || n > 7) return; as[n] = 255; @@ -457,9 +480,8 @@ void ButtonColor::SetBrightness1(int n, c_max[n] = m2; c_mid[n] = (hc*m2 + (hd-hc)*m1) / hd; c_min[n] = m1; +} - return; -} void ButtonColor::SetBrightness(int c1, int c2, int c3, int c4, int c5) { rs[0] = bs[0] = gs[0] = as[0] = 0; SetBrightness1(1, c1); @@ -469,9 +491,9 @@ void ButtonColor::SetBrightness(int c1, SetBrightness1(5, c5); } -#include"rect.h" -#include -#include +#include "rect.h" +#include +#include static void draw_button(char* rdata, int width, int height, char* bdata, int bwidth, int bheight, const ButtonColor& color) { const int* rs = color.rs; @@ -483,8 +505,8 @@ static void draw_button(char* rdata, int ScaleData* data = new ScaleData[width*height]; memset(data, 0, sizeof(ScaleData)*width*height); - int bx,by; - int x=0, y=0; + int bx, by; + int x = 0, y = 0; int x2 = 0, y2 = 0; int xadd = width*65536/bwidth; int yadd = height*65536/bheight; @@ -522,12 +544,12 @@ static void draw_button(char* rdata, int } } delete[] data; - return; } + char* create_button(int number, int& width, int& height, int r, int g, int b) { int bwidth, bheight; char* bdata = extract_button(number, bwidth, bheight); - if (bdata == 0) return 0; + if (bdata == NULL) return NULL; // 拡大率に合わせてwidth,heightをセット if (width == -1 && height == -1) width = bwidth, height = bheight; else if (width == -1) width = bwidth * height / bheight; @@ -550,7 +572,7 @@ char* create_button(int number, int& wid static void drawbox(char* buf, const Rect& region, int width, int r, int g, int b, int a) { buf += region.ty*width*4 + region.lx*4; - int i,j; + int i, j; int h = region.height(); int w = region.width(); int col = (b&0xff) | ((g&0xff)<<8)| ((r&0xff)<<16)| ((a&0xff)<<24); @@ -562,8 +584,8 @@ static void drawbox(char* buf, const Rec } buf += width*4; } - return; } + static void draw_box(char* buf, int width, int height, int kage_w1, int kage_w2, const ButtonColor& color) { const int* rs = color.rs; const int* gs = color.gs; @@ -587,6 +609,7 @@ static void draw_box(char* buf, int widt drawbox(buf, Rect(width-kage_w2, kage_w2, width-kage_w1, height-kage_w1), width, rs[2], gs[2], bs[2], as[2]); } } + char* create_box(int& width, int& height, int r, int g, int b) { ButtonColor color(r,g,b); // scale のカーソル diff --git a/window/event.cc b/window/event.cc --- a/window/event.cc +++ b/window/event.cc @@ -25,13 +25,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include"SDL.h" -#include"event.h" -#include -#include -#include -#include -#include +#include "SDL.h" +#include "event.h" +#include +#include +#include +#include +#include using namespace std; @@ -129,17 +129,17 @@ void ContainerImplTime::Delete(Time* del iterator it = find(begin(), end(), delete_event); if (it != end()) { it->valid = false; - it->instance = 0; + it->instance = NULL; return; } it = find(new_item.begin(), new_item.end(), delete_event); if (it != end()) { it->valid = false; - it->instance = 0; + it->instance = NULL; return; } - return; } + bool ContainerImplTime::Exec(unsigned int current_time) { if (current_time == Time::NEVER_WAKE) return true; // 呼び出しまでに作製されたitemを追加 @@ -173,51 +173,51 @@ bool ContainerImplTime::Exec(unsigned in class ContainerImplVideo : private vector { -public: - bool Exec(void); + public: + bool Exec(void); - ContainerImplVideo(void); - ~ContainerImplVideo(); - void Add(Video* item); - void Delete(Video* item); - void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer); - void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer); - void RegisterGlobalPressFunc(Container::motionfunc, void* pointer); - void DeleteGlobalPressFunc(Container::motionfunc, void* pointer); -private: - struct Motionfunc { - Container::motionfunc func; - void* pointer; - bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;} - }; - list motion_vec; - list press_vec; - typedef list::iterator MotionIterator; - bool is_sorted; -public: - int button_pressed; - int button_released; - int mouse_x, mouse_y; - int new_mouse_x, new_mouse_y; -private: - void SetChanged(void); - static bool SortLess(const Video* pos1, const Video* pos2) { - return pos1 < pos2; - } - void Sort(void); - void Motion(int x, int y); // mouse motion - void Press(void); - void TakeScreenshot(void); - iterator cur_pos; - Video* cur_item; // 現在のフォーカス位置 - int cur_pressed_x, cur_pressed_y; + ContainerImplVideo(void); + ~ContainerImplVideo(); + void Add(Video* item); + void Delete(Video* item); + void RegisterGlobalMotionFunc(Container::motionfunc, void* pointer); + void DeleteGlobalMotionFunc(Container::motionfunc, void* pointer); + void RegisterGlobalPressFunc(Container::motionfunc, void* pointer); + void DeleteGlobalPressFunc(Container::motionfunc, void* pointer); + private: + struct Motionfunc { + Container::motionfunc func; + void* pointer; + bool operator ==(const Motionfunc& m) const { return func == m.func && pointer == m.pointer;} + }; + list motion_vec; + list press_vec; + typedef list::iterator MotionIterator; + bool is_sorted; + public: + int button_pressed; + int button_released; + int mouse_x, mouse_y; + int new_mouse_x, new_mouse_y; + private: + void SetChanged(void); + static bool SortLess(const Video* pos1, const Video* pos2) { + return pos1 < pos2; + } + void Sort(void); + void Motion(int x, int y); // mouse motion + void Press(void); + void TakeScreenshot(void); + iterator cur_pos; + Video* cur_item; // 現在のフォーカス位置 + int cur_pressed_x, cur_pressed_y; }; void ContainerImplVideo::SetChanged(void) { if (is_sorted) { - if (cur_item) { + if (cur_item != NULL) { cur_pos = find(begin(), end(), cur_item); - if (cur_pos == end()) cur_item = 0; + if (cur_pos == end()) cur_item = NULL; } is_sorted = false; } @@ -225,7 +225,7 @@ void ContainerImplVideo::SetChanged(void void ContainerImplVideo::Sort(void) { sort(begin(), end(), SortLess); - if (cur_item) { + if (cur_item != NULL) { cur_pos = lower_bound(begin(), end(), cur_item, SortLess); } else { cur_pos = end(); @@ -237,16 +237,19 @@ ContainerImplVideo::ContainerImplVideo(v is_sorted = false; button_pressed = 0; button_released = 0; - cur_item = 0; + cur_item = NULL; mouse_x = 0; mouse_y = 0; new_mouse_x = 0; new_mouse_y = 0; } + ContainerImplVideo::~ContainerImplVideo(void) { }; + void ContainerImplVideo::Add(Video* event) { push_back(event); SetChanged(); } + void ContainerImplVideo::Delete(Video* delete_event) { iterator it = find(begin(), end(), delete_event); if (it != end()) { @@ -264,11 +267,11 @@ void ContainerImplVideo::Delete(Video* d } if (delete_event == cur_item) { cur_pos = end(); - cur_item = 0; + cur_item = NULL; Motion(mouse_x, mouse_y); } - return; } + void ContainerImplVideo::RegisterGlobalMotionFunc(Container::motionfunc func, void* pointer) { Motionfunc f; f.func = func; @@ -277,6 +280,7 @@ void ContainerImplVideo::RegisterGlobalM motion_vec.push_back(f); } } + void ContainerImplVideo::DeleteGlobalMotionFunc(Container::motionfunc func, void* pointer) { Motionfunc f; f.func = func; @@ -284,8 +288,8 @@ void ContainerImplVideo::DeleteGlobalMot list::iterator it = find(motion_vec.begin(), motion_vec.end(), f); if (it != motion_vec.end()) motion_vec.erase(it); - return; } + void ContainerImplVideo::RegisterGlobalPressFunc(Container::motionfunc func, void* pointer) { Motionfunc f; f.func = func; @@ -294,6 +298,7 @@ void ContainerImplVideo::RegisterGlobalP press_vec.push_back(f); } } + void ContainerImplVideo::DeleteGlobalPressFunc(Container::motionfunc func, void* pointer) { Motionfunc f; f.func = func; @@ -301,8 +306,8 @@ void ContainerImplVideo::DeleteGlobalPre list::iterator it = find(press_vec.begin(), press_vec.end(), f); if (it != press_vec.end()) press_vec.erase(it); - return; } + void ContainerImplVideo::Motion(int x, int y) { mouse_x = x; mouse_y = y; MotionIterator mit; @@ -319,7 +324,7 @@ void ContainerImplVideo::Motion(int x, i if (cur_item) cur_item->Drag(cur_pressed_x, cur_pressed_y, x, y); return; } - if (cur_item) cur_item->Motion(x,y); + if (cur_item != NULL) cur_item->Motion(x,y); int z = -1; iterator z_it; iterator it; for (it = begin(); it != end(); it++) { @@ -339,7 +344,7 @@ void ContainerImplVideo::Motion(int x, i } else { if (cur_item) cur_item->Out(); cur_pos = end(); - cur_item = 0; + cur_item = NULL; } return; } @@ -361,6 +366,7 @@ void ContainerImplVideo::Press(void) { mit = mit_next; } } + void ContainerImplVideo::TakeScreenshot(void) { int n=0; char filename[1024]; @@ -372,118 +378,134 @@ void ContainerImplVideo::TakeScreenshot( } SDL_SaveBMP(SDL_GetVideoSurface(), filename); } + bool ContainerImplVideo::Exec(void) { - bool is_mouse_motion = false; int motion_x = 0, motion_y = 0; SDL_Event event; SDL_PumpEvents(); while(SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1) { switch(event.type) { - case SDL_QUIT: return false; // @@@ なにかやらないと - case SDL_ACTIVEEVENT: // なにもしない - // cout<<"active : gain "<In(); + } else { + cur_item = NULL; + } + break; + case SDLK_LEFT: if (cur_pos != end()) (*cur_pos)->KeyLeft(); break; + case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break; + case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<In(); - } else { - cur_item = 0; + case SDL_KEYUP: + // cout << "keyup which "<Release(); + case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<KeyLeft(); break; - case SDLK_RIGHT:if (cur_pos != end()) (*cur_pos)->KeyRight(); break; - case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed |= (1<Release(); - case SDLK_LSHIFT: case SDLK_RSHIFT: button_pressed &= ~(1<Release(); - } - switch(event.button.button) { - case 1: button_pressed &= ~(1<Release(); + } + switch(event.button.button) { + case 1: + button_pressed &= ~(1<Add(item); } + void Container::Delete(Video* item) { pimpl_video->Delete(item); } + void Container::Add(Time* item) { pimpl_time->Add(item); } + void Container::Delete(Time* item) { pimpl_time->Delete(item); } + void Container::RegisterGlobalMotionFunc(Container::motionfunc f, void* pointer) { pimpl_video->RegisterGlobalMotionFunc(f, pointer); } + void Container::DeleteGlobalMotionFunc(Container::motionfunc f, void* pointer) { pimpl_video->DeleteGlobalMotionFunc(f, pointer); } + void Container::RegisterGlobalPressFunc(Container::motionfunc f, void* pointer) { pimpl_video->RegisterGlobalPressFunc(f, pointer); } + void Container::DeleteGlobalPressFunc(Container::motionfunc f, void* pointer) { pimpl_video->DeleteGlobalPressFunc(f, pointer); } + bool Container::Exec(unsigned int time) { current_time = time; bool ret = true; @@ -553,6 +585,7 @@ bool Container::pressed(int mask) { if (mask < 0 || mask >= BUTTON_MAX) return 0; return (button_pressed & (1<= BUTTON_MAX) return 0; int count = button_presscount[mask]; @@ -560,7 +593,7 @@ bool Container::presscount(int mask) { return count; } -}; /* end of namespace Container */ +} /* end of namespace Container */ // 問題: // z 軸と xy 軸の相互干渉;高速化 diff --git a/window/event.h b/window/event.h --- a/window/event.h +++ b/window/event.h @@ -28,63 +28,65 @@ #ifndef __EVENT__ #define __EVENT__ -#include"rect.h" -#include"SDL.h" +#include "rect.h" +#include "SDL.h" namespace Event { -class Video; -class Time; -class Container; + class Video; + class Time; + class Container; -/* -** マウスの press, ドラッグ、in/out を検出できる -** focus がある時の left/right/space(==press) のキーを判別できる -*/ -struct Video { - virtual void Press(void) {} - virtual void Release(void) {} - virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} - virtual void Motion(int x, int y) {} - virtual void In(void) {} - virtual void Out(void) {} - virtual void KeyLeft(void) {} - virtual void KeyRight(void) {} + /* + ** マウスの press, ドラッグ、in/out を検出できる + ** focus がある時の left/right/space(==press) のキーを判別できる + */ + struct Video { + public: + virtual void Press(void) {} + virtual void Release(void) {} + virtual void Drag(int x_from, int y_from, int x_to, int y_to) {} + virtual void Motion(int x, int y) {} + virtual void In(void) {} + virtual void Out(void) {} + virtual void KeyLeft(void) {} + virtual void KeyRight(void) {} - int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */ + int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */ - Video(Container& container); - Video(Container& container, const Rect& init_rect); - Video(Container& container, const Rect& init_rect, int z); - void SetRegion(const Rect& new_rect); - void SetZ(int new_z); - void activate(void); - void deactivate(void); - virtual ~Video(); + Video(Container& container); + Video(Container& container, const Rect& init_rect); + Video(Container& container, const Rect& init_rect, int z); + void SetRegion(const Rect& new_rect); + void SetZ(int new_z); + void activate(void); + void deactivate(void); + virtual ~Video(); - Rect Region(void) const { return region;} -private: - Rect region; - int z; - Container& parent; - bool activated; - friend bool operator <(const Video& position1, const Video& position2); -}; + Rect Region(void) const { return region;} + private: + Rect region; + int z; + Container& parent; + bool activated; + friend bool operator <(const Video& position1, const Video& position2); + }; -struct Time { - enum { NEVER_WAKE = 0xffffffff, FRAME_UPDATE = 0xfffffffe}; - virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ - void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } - unsigned Wakeup(void) const { return wakeup_time; } + struct Time { + public: + enum { NEVER_WAKE = 0xffffffffUL, FRAME_UPDATE = 0xfffffffeUL}; + virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */ + void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; } + unsigned Wakeup(void) const { return wakeup_time; } - Time(Container& container); - ~Time(); -private: - unsigned int wakeup_time; - Container& parent; -}; + Time(Container& container); + ~Time(); + private: + unsigned int wakeup_time; + Container& parent; + }; -struct Container { + struct Container { #define MOUSE_LEFT 0 #define MOUSE_MIDDLE 1 #define MOUSE_RIGHT 2 @@ -92,35 +94,36 @@ struct Container { #define MOUSE_DOWN 4 #define KEY_SHIFT 10 #define BUTTON_MAX 32 - int button_pressed; - int button_presscount[BUTTON_MAX]; - int current_time; + public: + int button_pressed; + int button_presscount[BUTTON_MAX]; + int current_time; - void MousePos(int& x, int& y); - bool Exec(unsigned int current_time); + void MousePos(int& x, int& y); + bool Exec(unsigned int current_time); - void Add(Video* item); - void Delete(Video* item); + void Add(Video* item); + void Delete(Video* item); - void Add(Time* item); - void Delete(Time* item); + void Add(Time* item); + void Delete(Time* item); - typedef bool (*motionfunc)(int x, int y, void* pointer); - void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する - void DeleteGlobalMotionFunc(motionfunc, void* pointer); - void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する - void DeleteGlobalPressFunc(motionfunc, void* pointer); + typedef bool (*motionfunc)(int x, int y, void* pointer); + void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する + void DeleteGlobalMotionFunc(motionfunc, void* pointer); + void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する + void DeleteGlobalPressFunc(motionfunc, void* pointer); - Container(void); - ~Container(void); - bool pressed(int mask); - bool presscount(int mask); -private: - class ContainerImplVideo* pimpl_video; - class ContainerImplTime* pimpl_time; -}; + Container(void); + ~Container(void); + bool pressed(int mask); + bool presscount(int mask); + private: + class ContainerImplVideo* pimpl_video; + class ContainerImplTime* pimpl_time; + }; -}; /* end of namespace Event */ +} /* end of namespace Event */ #endif diff --git a/window/menuitem.cc b/window/menuitem.cc --- a/window/menuitem.cc +++ b/window/menuitem.cc @@ -26,7 +26,7 @@ */ -#include"menuitem.h" +#include "menuitem.h" #define Button WidButton #define Scale WidScale @@ -44,12 +44,13 @@ MenuItem::MenuItem(PicContainer* parent, SetPic(parent->create_node(r_orig, 0)); menu_width = r_orig.width(); menu_height = r_orig.height(); - label = 0; + label = NULL; lb_width = 0; lb_right = 0; lb_left = -1; lb_bottom = -1; int i; for (i=0; iactivate(); } } + void MenuItem::deactivate(void) { iterator it; for (it=item.begin(); it!=item.end(); it++) { - if (*it == 0) continue; + if (*it == NULL) continue; (*it)->deactivate(); } } + void MenuItem::pack(void) { int x_min = 0, y_min = 0; if (lb_width == -1) { // 上にラベルを貼る @@ -112,14 +118,14 @@ void MenuItem::pack(void) { int* item_height = new int[y_size]; int* item_x = new int[x_size]; int* item_y = new int[y_size]; - int i,j; + int i, j; for (i=0; iPic() != 0) { + if (*it != NULL && (*it)->Pic() != NULL) { PicBase* pic = (*it)->Pic(); if (item_width[j] < pic->Width()) item_width[j] = pic->Width(); if (item_height[i] < pic->Height()) item_height[i] = pic->Height(); @@ -175,7 +181,7 @@ void MenuItem::pack(void) { it = item.begin(); for (i=0; iPic() != 0) { + if (*it != NULL && (*it)->Pic() != NULL) { PicBase* pic = (*it)->Pic(); int x0 = item_x[j]-pic->Width()/2; int y0 = item_y[i]-pic->Height()/2; @@ -195,16 +201,18 @@ void MenuItem::pack(void) { delete[] item_height; delete[] item_x; delete[] item_y; -}; +} RadioButton::RadioButton(Event::Container& _container, PicContainer* _parent, const Rect& r_orig, int _x_size, int _y_size, int* _value_ptr, const Rect& _button_r, int _text_size, const Color& _fore, const Color& _pressed, const Color& _back) : MenuItem(_parent, r_orig, _x_size, _y_size,_value_ptr), container(_container), parent(_parent), text_size(_text_size), button_rect(_button_r), buttons(0), fore_color(_fore), pressed_color(_pressed), back_color(_back) { } + void RadioButton::Add(const char* s, bool is_center) { Add(s, fore_color, pressed_color, back_color, is_center); } + void RadioButton::Add(const char* s, const Color& fore, const Color& pressed, const Color& back, bool is_center) { if (buttons >= x_size*y_size) { fprintf(stderr,"too many buttons (%d/%d) in RadioButton::Add ; text = %s\n",x_size,y_size,s); @@ -221,7 +229,8 @@ void RadioButton::Add(const char* s, con else x_pos = buttons / y_size, y_pos = buttons % y_size; item[x_pos + y_pos*x_size] = wid; buttons++; -}; +} + void RadioButton::PressCallback(void* pointer, Button* from) { RadioButton* wid = (RadioButton*)pointer; int i; @@ -231,13 +240,13 @@ void RadioButton::PressCallback(void* po return; } } - return; } + void RadioButton::SetValueImpl(int new_value) { int i; for (i=0; i(item[i]); - if (wid) { + if (wid != NULL) { if (i == new_value) wid->Toggle(true); else wid->Toggle(false); } diff --git a/window/menuitem.h b/window/menuitem.h --- a/window/menuitem.h +++ b/window/menuitem.h @@ -28,7 +28,7 @@ #ifndef __MENUITEM_H__ #define __MENUITEM_H__ -#include"widget.h" +#include "widget.h" #define MenuItem WidMenuItem #define MenuRadioButton WidMenuRadioButton diff --git a/window/picture.cc b/window/picture.cc --- a/window/picture.cc +++ b/window/picture.cc @@ -25,23 +25,23 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include +#include +#include +#include +#include -#include"rect.h" -#include"event.h" -#include"font/font.h" -#include"font/text.h" -#include -#include"system/file.h" +#include "rect.h" +#include "event.h" +#include "font/font.h" +#include "font/text.h" +#include +#include "system/file.h" -#include"picture.h" +#include "picture.h" using namespace std; -int print_blit=0; +int print_blit = 0; /* render.cc */ void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect); void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha); @@ -71,13 +71,13 @@ PicBase::PicBase(const Rect& _rel_pos, P is_hidden(true), is_hidden_now(true), is_cached(false), attribute(_attr), surface_alpha_rect(0,0) { if (parent) root = parent->root; - else root = 0; - surface_back = 0; - surface_own = 0; + else root = NULL; + surface_back = NULL; + surface_own = NULL; surface_alpha = 0; surface_x = 0; surface_y = 0; surface_w = -1; surface_h = -1; - widget = 0; + widget = NULL; attribute |= NO_PICTURE; if ( (attribute & CACHE_BACK) && root) { surface_back = root->NewSurface(rel_pos.width(), rel_pos.height(), NO_MASK); @@ -91,15 +91,16 @@ PicBase::PicBase(const Rect& _rel_pos, P distance_root = 1; } } + PicBase::~PicBase() { ClearAnm(); - if (widget) { + if (widget != NULL) { fprintf(stderr,"Warning: PicBase::~PicBase: surface is disallocated but widget is still alive.\n"); widget->deactivate(); } - if (surface_back) root->DeleteSurface(surface_back); - if (surface_own && (attribute & SURFACE_FREE)) root->DeleteSurface(surface_own); - if (surface_alpha && (attribute & ALPHA_FREE)) delete surface_alpha; + if (surface_back != NULL) root->DeleteSurface(surface_back); + if (surface_own != NULL && (attribute & SURFACE_FREE)) root->DeleteSurface(surface_own); + if (surface_alpha != NULL && (attribute & ALPHA_FREE)) delete surface_alpha; iterator it; if (parent) { // 自分を親から削除 parent->children.remove(this); @@ -111,6 +112,7 @@ PicBase::~PicBase() { parent->ReBlit(old_ppos); } } + void PicBase::Blit(const Rect& rpos_orig) { // 実際に描画する領域を得る Rect rpos = rpos_orig; @@ -141,6 +143,7 @@ void PicBase::Blit(const Rect& rpos_orig cur->BlitChildren(rpos); } } + void PicBase::SimpleBlit(Surface* screen) { // 実際に描画する領域を得る Rect rpos(0, 0, rel_pos.width(), rel_pos.height()); @@ -157,7 +160,7 @@ void PicBase::SimpleBlit(Surface* screen Rect PicBase::QueryAbsPos(Rect& rpos) { rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); - if (parent == 0) { // root container + if (parent == NULL) { // root container return rpos; } // 親の座標に変換後、Query する @@ -165,13 +168,14 @@ Rect PicBase::QueryAbsPos(Rect& rpos) { Rect apos = parent->QueryAbsPos(ppos); rpos = child_pos(ppos, this); return apos; -}; +} + void PicBase::ReBlit(const Rect& rpos_c) { Rect rpos = rpos_c; Rect apos = QueryAbsPos(rpos); - root->Update(this, rpos, apos); } + void PicBase::ExecReBlit(const Rect& rpos_c) { Rect rpos = rpos_c; Rect abs_r = QueryAbsPos(rpos); @@ -186,7 +190,7 @@ if(print_blit) fprintf(stderr,"end."); } void PicBase::ZMove(PicBase* move_to) { - if (parent == 0) { + if (parent == NULL) { fprintf(stderr,"Warning: PicBase::ZMove is called by root.\n"); return; } @@ -231,7 +235,8 @@ void PicBase::ZMove(PicBase* move_to) { parent->ReBlit(ppos); */ } -}; +} + void PicBase::RMove(int add_x, int add_y) { Rect old_ppos = rel_pos; rel_pos.rmove(add_x, add_y); @@ -239,45 +244,50 @@ void PicBase::RMove(int add_x, int add_y parent->ReBlit(old_ppos); ReBlit(); - if (widget) { + if (widget != NULL) { Rect new_ppos = rel_pos; Rect new_apos = parent->QueryAbsPos(new_ppos); widget->SetRegion(new_apos); } } + void PicBase::Move(int new_rx, int new_ry) { RMove(new_rx-rel_pos.lx, new_ry-rel_pos.ty); } + void PicBase::SetEventWidget(PicWidget* new_widget) { widget = new_widget; - if (widget) { + if (widget != NULL) { Rect new_ppos = rel_pos; Rect apos = parent->QueryAbsPos(new_ppos); widget->SetRegion(apos); } } + void PicBase::show_all(void) { PicContainer* cont = dynamic_cast(this); if (cont && (!cont->children.empty())) cont->set_showflag(); show(); } + bool PicBase::IsParent(PicBase* to) { if (parent == 0) return false; if (parent == to) return true; return parent->IsParent(to); } + void PicBase::show(void) { /* 自分の親がすべて shown か? */ PicContainer* cur; for (cur = parent; cur != 0; cur = cur->parent) if (cur->is_hidden) break; - if (cur) { // 親が隠れているので表示はしない + if (cur != NULL) { // 親が隠れているので表示はしない is_hidden = false; is_hidden_now = true; return; } if (is_hidden == false) return; // すでに表示されているのでなにもしない - if (widget) { + if (widget != NULL) { widget->activate(); } is_hidden = false; @@ -287,9 +297,10 @@ void PicBase::show(void) { if (cur && (!cur->children.empty())) cur->set_nowhiddenflag(false); ReBlit(); } + void PicBase::hide(void) { if (is_hidden) return; - if (widget) { + if (widget != NULL) { widget->deactivate(); } is_hidden = true; @@ -299,6 +310,7 @@ void PicBase::hide(void) { if (cur && (!cur->children.empty())) cur->set_nowhiddenflag(true); ReBlit(); } + void PicBase::SetSurfaceAlpha(const unsigned char* alpha, const Rect& alpha_r) { if (attribute & ALPHA_FREE) { if (surface_alpha) delete[] surface_alpha; @@ -308,6 +320,7 @@ void PicBase::SetSurfaceAlpha(const unsi surface_alpha_rect = alpha_r; if (!is_hidden) ReBlit(); } + void PicBase::SetSurfaceColorKey(int r, int g, int b) { surface_alpha = 0; surface_alpha_rect = Rect(0,0); @@ -319,17 +332,18 @@ void PicBase::SetSurfaceColorKey(int r, } if (!is_hidden) ReBlit(); } + void PicBase::SetSurfaceAlphaFile(const char* file) { /* ファイルを元に alpha 画像を作成する */ /* ファイル: パルフェの 'fil' ファイル */ ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, file,"fil"); - if (info == 0) return; + if (info == NULL) return; char* new_alpha = info->CopyRead(); int alpha_size = info->Size(); delete info; Rect sr(0,0); int w,h; - if (surface_own == 0 || new_alpha == 0) { + if (surface_own == NULL || new_alpha == NULL) { err_ret: if (new_alpha) delete[] new_alpha; SetSurfaceAlpha(0,Rect(0,0)); @@ -378,12 +392,14 @@ err_ret: attribute |= ALPHA_FREE; } } + void PicBase::SetSurface(const char* filename, int x, int y) { Surface* s = root->NewSurface(filename); SetSurface(s, x, y, SURFACE_FREE); } + void PicBase::SetSurface(Surface* new_surface, int x, int y, int new_attr) { - if (surface_own && (attribute & SURFACE_FREE)) { + if (surface_own != NULL && (attribute & SURFACE_FREE)) { root->DeleteSurface(surface_own); } attribute &= ~(SURFACE_FREE | BLIT_SATURATE | BLIT_MULTIPLY | NO_PICTURE | SOLID); @@ -408,38 +424,44 @@ void PicBase::SetSurface(Surface* new_su } rel_solid_area = Rect(0,0,0,0); - if (! surface_own) attribute |= NO_PICTURE; + if (surface_own == NULL) attribute |= NO_PICTURE; else if (root->with_mask(surface_own) == 0) { attribute |= SOLID; rel_solid_area = rel_pos; } if (!is_hidden) ReBlit(); } + void PicBase::SetSurfacePos(int x, int y) { if (surface_x == x && surface_y == y && surface_w == -1 && surface_h == -1) return; surface_x = x; surface_y = y; surface_w = -1; surface_h = -1; if (!is_hidden_now) ReBlit(); } + int PicBase::SurfacePosX(void) { return surface_x; } + int PicBase::SurfacePosY(void) { return surface_y; } + void PicBase::SetSurfaceRect(const Rect& r) { if (surface_x == r.lx && surface_y == r.ty && surface_w == r.width() && surface_h == r.height()) return; - surface_x = r.lx; surface_y = r.ty; + surface_x = r.lx; + surface_y = r.ty; surface_w = r.width(); surface_h = r.height(); parent->ReBlit(rel_pos); rel_pos = Rect(rel_pos.lx, rel_pos.ty, rel_pos.lx+surface_w, rel_pos.ty+surface_h); - if (widget) { + if (widget != NULL) { Rect new_ppos = rel_pos; Rect apos = parent->QueryAbsPos(new_ppos); widget->SetRegion(apos); } if (!is_hidden_now) ReBlit(); } + void PicBase::SetClipArea(const Rect& r) { if (clip_area == r) return; clip_area = r; @@ -453,6 +475,7 @@ void PicBase::SetSurfaceAttribute(int ne rel_solid_area = Rect(0,0); } } + void PicBase::SetSurfaceFreeFlag(bool flag) { if (flag) attribute |= SURFACE_FREE; else attribute &= ~SURFACE_FREE; @@ -465,19 +488,22 @@ void PicBase::SetSurfaceFreeFlag(bool fl PicContainer::PicContainer(const Rect& rel_pos, PicContainer* parent, int attr) : PicBase(rel_pos, parent, attr) { } + PicContainer::~PicContainer() { iterator end = children.end(); for (iterator it = children.begin(); it != end; ) { iterator it_next = it; it_next++; - if ((*it)->widget) delete (*it)->widget; // picture にwidget が付属しているなら、そちらをdelete + if ((*it)->widget != NULL) delete (*it)->widget; // picture にwidget が付属しているなら、そちらをdelete else delete (*it); it = it_next; } } + void PicContainer::BlitBack(iterator z, Rect rpos) { rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); if (rpos.empty()) return; - iterator end = children.end(), begin = children.begin(); iterator it = begin; + iterator end = children.end(), begin = children.begin(); + iterator it = begin; Rect ppos = parent_pos(rpos); if (is_hidden_now) goto parent_redraw; @@ -536,6 +562,7 @@ children_redraw: } } } + void PicContainer::BlitChildren(Rect rpos) { if (print_blit) fprintf(stderr,"bc."); iterator end = children.end(); @@ -548,10 +575,12 @@ if ( (*it)->is_hidden_now) if(print_blit } } } + void PicContainer::BlitFront(iterator z, Rect rpos) { rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); if (rpos.empty()) return; - iterator end = children.end(); iterator it; + iterator end = children.end(); + iterator it; z++; for (it = z; it != end; it++) { if ( (*it)->is_hidden_now) continue; @@ -564,7 +593,8 @@ void PicContainer::BlitFront(iterator z, Rect ppos = parent_pos(rpos); parent->BlitFront(z_pos, ppos); } -}; +} + void PicContainer::BlitSelf(Rect rpos) { // 実際に描画する領域を得る rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height())); @@ -582,7 +612,7 @@ if(print_blit) fprintf(stderr,"self-back } if(print_blit) fprintf(stderr,"self-blit."); root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute); - } else if (parent == 0) { // 親がいないなら背景消去の責任をもつ + } else if (parent == NULL) { // 親がいないなら背景消去の責任をもつ DSurfaceFill(root->surface, apos, 0, 0, 0); } } @@ -595,12 +625,13 @@ void PicContainer::set_showflag(void) { if (next && (!next->children.empty())) next->set_showflag(); } } + void PicContainer::set_nowhiddenflag(bool is_hide) { iterator end = children.end(); for (iterator it = children.begin(); it != end; it++) { if (is_hide) (*it)->is_hidden_now = true; else (*it)->is_hidden_now = (*it)->is_hidden; - if ( (*it)->widget) { + if ( (*it)->widget != NULL) { if ((*it)->is_hidden_now) (*it)->widget->deactivate(); else (*it)->widget->activate(); } @@ -608,6 +639,7 @@ void PicContainer::set_nowhiddenflag(boo if (next && (!next->children.empty())) next->set_nowhiddenflag(is_hide); } } + void PicContainer::RMove(int add_x, int add_y) { // event widget の移動があり得るので子についてもRMoveを呼び出す PicBase::RMove(add_x, add_y); iterator end = children.end(); @@ -619,6 +651,7 @@ void PicContainer::RMove(int add_x, int add_y) { // event widget の移動があり得るので子についてもRMoveを呼び出す PicBase* PicContainer::create_leaf(const Rect& rel_pos, int attr) { return new PicBase(rel_pos, this, attr); } + PicContainer* PicContainer::create_node(const Rect& rel_pos, int attr) { return new PicContainer(rel_pos, this, attr); } @@ -629,32 +662,36 @@ PicContainer* PicContainer::create_node( */ PicWidget::PicWidget(void) { - pic = 0; + pic = NULL; } + PicWidget::~PicWidget() { - if (pic) { + if (pic != NULL) { pic->SetEventWidget(0); delete pic; } - pic = 0; + pic = NULL; } + void PicWidget::SetPic(PicBase* new_pic) { - if (pic) { + if (pic != NULL) { pic->SetEventWidget(0); delete pic; } pic = new_pic; - if (pic) pic->SetEventWidget(this); + if (pic != NULL) pic->SetEventWidget(this); } + PicBase* PicWidget::Pic(void) { - if (pic == 0) { + if (pic == NULL) { fprintf(stderr,"Error: PicWidget::Pic returns zero.\n"); } return pic; } + PicContainer* PicWidget::PicNode(void) { PicContainer* node = dynamic_cast(pic); - if (node == 0) { + if (node == NULL) { fprintf(stderr,"Error: PicWidget::PicNode returns zero.\n"); } return node; @@ -664,9 +701,10 @@ PicContainer* PicWidget::PicNode(void) { ** FileToSurface */ -#include -#include -#include +#include +#include +#include + using namespace std; struct SurfaceIndex { typedef list::iterator qiterator; @@ -677,27 +715,30 @@ struct SurfaceIndex { }; class FileToSurface { - typedef list::iterator qiterator; + private: + typedef list::iterator qiterator; - list queue; - map findex; - map mindex; - int count; - int count_max; - const PicRoot& root; - bool DeleteData(SurfaceIndex* data); - Surface* LoadSurface(string name, char*& mem); -public: - FileToSurface(const PicRoot& root); - ~FileToSurface(void); - Surface* Load(string name); - bool Free(Surface* s); + list queue; + map findex; + map mindex; + int count; + int count_max; + const PicRoot& root; + bool DeleteData(SurfaceIndex* data); + Surface* LoadSurface(string name, char*& mem); + + public: + FileToSurface(const PicRoot& root); + ~FileToSurface(void); + Surface* Load(string name); + bool Free(Surface* s); }; FileToSurface::FileToSurface(const PicRoot& _root) : root(_root) { count = 0; count_max = 32; // キャッシュ量(決め打ち) }; + FileToSurface::~FileToSurface() { qiterator it; for (it=queue.begin(); it != queue.end(); it++) { @@ -708,6 +749,7 @@ FileToSurface::~FileToSurface() { delete *it; } } + inline bool FileToSurface::DeleteData(SurfaceIndex* data) { if ( data->ref_count) return false; findex.erase(data->filename); @@ -718,13 +760,17 @@ inline bool FileToSurface::DeleteData(Su count--; return true; } + inline Surface* FileToSurface::LoadSurface(string name, char*& mem) { ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, name.c_str(),"pdt"); - if (info == 0) return 0; + if (info == NULL) return NULL; GRPCONV* conv = GRPCONV::AssignConverter(info); - if (conv == 0) { delete info;return 0;} + if (conv == NULL) { + delete info; + return NULL; + } mem = (char*)malloc(conv->Width() * conv->Height() * 4 + 1024); - Surface* s = 0; + Surface* s = NULL; if (conv->Read(mem)) { MaskType is_mask = conv->IsMask() ? ALPHA_MASK : NO_MASK; if (is_mask == ALPHA_MASK) { // alpha がすべて 0xff ならマスク無しとする @@ -743,6 +789,7 @@ inline Surface* FileToSurface::LoadSurfa delete conv; delete info; // delete data; return s; } + Surface* FileToSurface::Load(string name) { if (findex.find(name) != findex.end()) { findex[name]->ref_count++; @@ -750,7 +797,7 @@ Surface* FileToSurface::Load(string name } char* mem; Surface* surface = LoadSurface(name, mem); - if (surface == 0) return 0; + if (surface == NULL) return NULL; while (count >= count_max) { // count_max 以上のデータを可能なら削除する qiterator it; @@ -770,6 +817,7 @@ Surface* FileToSurface::Load(string name count++; return surface; } + bool FileToSurface::Free(Surface* s) { if (mindex.find(s) == mindex.end()) { return false; @@ -783,9 +831,9 @@ bool FileToSurface::Free(Surface* s) { /****************************************** ** PicRoot */ -#include +#include -#include"surface.h" +#include "surface.h" #define DefaultRmask 0xff0000 #define DefaultGmask 0xff00 @@ -811,18 +859,22 @@ PicRoot::PicRoot(void) { height = surface->h; return; } + PicRoot::~PicRoot() { // if (surface) DeleteSurfaceImpl(surface); // SDL_GetVideoSurface() した surface は開放の必要がないらしい - surface = 0; + surface = NULL; delete root; delete ftosurface; } + void PicRoot::Update(PicBase* pic, const Rect& rpos, const Rect& apos) { update_rects.push_back(UpdateItem(pic, rpos, apos)); } + bool PicRoot::UpdateItem::less(const PicRoot::UpdateItem& a, const PicRoot::UpdateItem& b) { return a.pic->DistanceRoot() < b.pic->DistanceRoot(); } + void PicRoot::DeleteUpdatePic(PicBase* pic) { vector::iterator it = update_rects.begin(); while(it != update_rects.end()) { @@ -835,11 +887,13 @@ void PicRoot::DeleteUpdatePic(PicBase* p } return; } + void PicRoot::ExecUpdate(void) { /* 共通する領域を消去する */ sort(update_rects.begin(), update_rects.end(), UpdateItem::less); vector::iterator it; vector::iterator end = update_rects.end(); + if(print_blit){ fprintf(stderr,"ExecUpdate Start: \n\t"); for (it=update_rects.begin(); it != end; it++) { @@ -847,6 +901,7 @@ if(print_blit){ } fprintf(stderr,"\n"); } + for (it=update_rects.begin(); it != end; it++) { if (it->rpos.width() == 0) continue; @@ -869,6 +924,7 @@ if(print_blit){ } } } + if(print_blit){ fprintf(stderr,"->\t"); for (it=update_rects.begin(); it != end; it++) { @@ -900,7 +956,8 @@ if(print_blit)fprintf(stderr,"\n"); } if(print_blit)fprintf(stderr,"\n"); SDL_UpdateRects(hw_surface, n, r); - delete[] r; update_rects.clear(); + delete[] r; + update_rects.clear(); } Surface* PicRoot::NewSurface(int w, int h, MaskType with_mask) const { @@ -918,11 +975,12 @@ Surface* PicRoot::NewSurfaceFromRGBAData Surface* s = (Surface*)SDL_CreateRGBSurfaceFrom(data, w, h, DefaultBpp, w*4, DefaultRmask, DefaultGmask, DefaultBmask, amask); s->flags &= ~SDL_PREALLOC; return s; -}; +} + Surface* PicRoot::NewSurface(const char* f, MaskType with_mask) { - if (f == 0) return 0; + if (f == NULL) return NULL; Surface* s = ftosurface->Load(f); - if (s == 0) return 0; + if (s == NULL) return NULL; if (with_mask == COLOR_MASK) { SDL_SetColorKey( (SDL_Surface*)s, SDL_SRCCOLORKEY, *(Uint32*)s->pixels); } @@ -931,17 +989,21 @@ Surface* PicRoot::NewSurface(const char* SDL_SetColorKey(s, SDL_SRCCOLORKEY, 0x55aa66); return s; } + Surface* PicRoot::RotZoomSurface(Surface* from, double zoom, double rotate) { Surface* ret = (Surface*)rotozoomSurface( (SDL_Surface*)from, rotate, zoom, SMOOTHING_OFF); return ret; } + void PicRoot::DeleteSurfaceImpl(Surface* s) const { SDL_FreeSurface(s); } + void PicRoot::DeleteSurface(Surface* s) { if (!ftosurface->Free(s)) DeleteSurfaceImpl(s); } + inline SDL_Rect SDLed(const Rect& rect) { SDL_Rect r; r.x = rect.lx; @@ -971,7 +1033,7 @@ if (print_blit) fprintf(stderr,"S"); } if (print_blit) fprintf(stderr,"N"); - if (alpha == 0 || alpha_r.width() == 0) { // simple blit + if (alpha == NULL || alpha_r.width() == 0) { // simple blit if (print_blit) fprintf(stderr,"X"); SDL_BlitSurface(src, &sr, dest, &dr); return; @@ -1001,9 +1063,9 @@ bool PicRoot::with_mask(Surface* s) { } #if USE_X11 -#include -#include -#include +#include +#include +#include #endif /* USE_X11 */ void PicRoot::SetWindowCaption(const char* caption) { #if USE_X11 diff --git a/window/picture.h b/window/picture.h --- a/window/picture.h +++ b/window/picture.h @@ -28,8 +28,8 @@ #ifndef __PICTURE__ #define __PICTURE__ -#include -#include +#include +#include #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -46,208 +46,212 @@ namespace Event { /* PicBase の内容をイベントと連動させるためのインターフェース */ class PicAnm { -public: - typedef std::vector::iterator iterator; - std::vector pic; - PicAnm(PicBase* pic); - PicAnm(std::vector pic); - virtual ~PicAnm(); + public: + typedef std::vector::iterator iterator; + std::vector pic; + PicAnm(PicBase* pic); + PicAnm(std::vector pic); + virtual ~PicAnm(); }; class PicBase { - friend class PicContainer; - friend class PicWidget; + private: + friend class PicContainer; + friend class PicWidget; - typedef std::list List; - typedef std::list::iterator iterator; + typedef std::list List; + typedef std::list::iterator iterator; - PicContainer* parent; - class PicWidget* widget; - Rect rel_pos; // relative position to the parent - Rect rel_solid_area; // solid area(not alpha-blended) to the parent - Rect clip_area; // clip area on the parent - bool is_hidden; - bool is_hidden_now; - bool is_cached; -public: - enum { /*MOBILE=1,*/ CACHE_BACK=2, /* CACHE_SELF=4,*/ NO_PICTURE=8, SOLID = 16, SURFACE_FREE = 32, FIT_SURFACE = 64, BLIT_SATURATE = 128, BLIT_MULTIPLY = 256, ALPHA_FREE=512}; -private: - int attribute; + PicContainer* parent; + class PicWidget* widget; + Rect rel_pos; // relative position to the parent + Rect rel_solid_area; // solid area(not alpha-blended) to the parent + Rect clip_area; // clip area on the parent + bool is_hidden; + bool is_hidden_now; + bool is_cached; + public: + enum { /*MOBILE=1,*/ CACHE_BACK=2, /* CACHE_SELF=4,*/ NO_PICTURE=8, SOLID = 16, SURFACE_FREE = 32, FIT_SURFACE = 64, BLIT_SATURATE = 128, BLIT_MULTIPLY = 256, ALPHA_FREE=512}; + private: + int attribute; - PicRoot* root; - iterator z_pos; - int surface_x, surface_y, surface_w, surface_h; - Surface* surface_back; - Surface* surface_own; - const unsigned char* surface_alpha; - Rect surface_alpha_rect; - int distance_root; + PicRoot* root; + iterator z_pos; + int surface_x, surface_y, surface_w, surface_h; + Surface* surface_back; + Surface* surface_own; + const unsigned char* surface_alpha; + Rect surface_alpha_rect; + int distance_root; - void Blit(const Rect& rpos); - void Blit(void) { - is_cached = true; - Blit(Rect(0, 0, rel_pos.width(), rel_pos.height())); - } - /* - ** rpos : relative position to the widget - ** ppos : relative position to the parent - ** ppos = parent_pos(rpos) - ** rpos = child_pos(ppos, parent->this_widget) - ** cpos : relative position to a child widget - ** cpos = child_pos(rpos, a_child_widget) - ** apos : absolute position in the screen - ** apos = QueryAbsPos(rpos); - ** or - ** Rect ppos = rel_pos; - ** apos = parent->QueryAbsPos(ppos); - ** the latter form is used for 'rel_pos', - ** because rel_pos is defined as the relative position to the parent - */ - Rect QueryAbsPos(Rect& ppos); // この picture 内の rel_pos を表示するのに実際に必要な絶対座標を得る + void Blit(const Rect& rpos); + void Blit(void) { + is_cached = true; + Blit(Rect(0, 0, rel_pos.width(), rel_pos.height())); + } + /* + ** rpos : relative position to the widget + ** ppos : relative position to the parent + ** ppos = parent_pos(rpos) + ** rpos = child_pos(ppos, parent->this_widget) + ** cpos : relative position to a child widget + ** cpos = child_pos(rpos, a_child_widget) + ** apos : absolute position in the screen + ** apos = QueryAbsPos(rpos); + ** or + ** Rect ppos = rel_pos; + ** apos = parent->QueryAbsPos(ppos); + ** the latter form is used for 'rel_pos', + ** because rel_pos is defined as the relative position to the parent + */ + Rect QueryAbsPos(Rect& ppos); // この picture 内の rel_pos を表示するのに実際に必要な絶対座標を得る - static Rect child_pos(Rect rpos, PicBase* child) { /* return 'cpos' */ - rpos.intersect(child->rel_pos); - rpos.rmove( -(child->rel_pos.lx), -(child->rel_pos.ty)); - return rpos; - } - Rect parent_pos(Rect rpos) { /* return 'ppos' */ - rpos.rmove(rel_pos.lx, rel_pos.ty); - rpos.intersect(rel_pos); - return rpos; - } - void SetEventWidget(class PicWidget* widget); -public: - PicBase(const Rect& rel_pos, PicContainer* parent, int attr); - virtual ~PicBase(); - void InitRoot(PicRoot* r) { root = r;} // only called from PicRoot::PicRoot + static Rect child_pos(Rect rpos, PicBase* child) { /* return 'cpos' */ + rpos.intersect(child->rel_pos); + rpos.rmove( -(child->rel_pos.lx), -(child->rel_pos.ty)); + return rpos; + } + Rect parent_pos(Rect rpos) { /* return 'ppos' */ + rpos.rmove(rel_pos.lx, rel_pos.ty); + rpos.intersect(rel_pos); + return rpos; + } + void SetEventWidget(class PicWidget* widget); + public: + PicBase(const Rect& rel_pos, PicContainer* parent, int attr); + virtual ~PicBase(); + void InitRoot(PicRoot* r) { root = r;} // only called from PicRoot::PicRoot - void ReBlit(const Rect& rpos); - void ReBlit(void) { ReBlit(Rect(0, 0, rel_pos.width(), rel_pos.height()));} - void ExecReBlit(const Rect& rpos); - void SimpleBlit(Surface* screen); + void ReBlit(const Rect& rpos); + void ReBlit(void) { ReBlit(Rect(0, 0, rel_pos.width(), rel_pos.height()));} + void ExecReBlit(const Rect& rpos); + void SimpleBlit(Surface* screen); - virtual void RMove(int add_x, int add_y); - void Move(int new_rx, int new_ry); - #define ZMOVE_TOP ((PicBase*)0xffff00ff) /* 最前面へ */ - #define ZMOVE_BOTTOM ((PicBase*)0xffff0fff) /* 最背面へ */ - void ZMove(PicBase* back); // back の前に移動(back と自分は同じ親を持つこと) + virtual void RMove(int add_x, int add_y); + void Move(int new_rx, int new_ry); + #define ZMOVE_TOP ((PicBase*)0xffff00ff) /* 最前面へ */ + #define ZMOVE_BOTTOM ((PicBase*)0xffff0fff) /* 最背面へ */ + void ZMove(PicBase* back); // back の前に移動(back と自分は同じ親を持つこと) - void SetSurface(Surface* new_surface, int x, int y, int attribute = 0); - void SetSurface(const char* new_surface, int x, int y); - void SetSurfacePos(int x, int y); - int SurfacePosX(void); - int SurfacePosY(void); - void SetSurfaceRect(const Rect& r); - void SetSurfaceAlpha(const unsigned char* alpha, const Rect& rect); - void SetSurfaceAlphaFile(const char* file); - void SetSurfaceColorKey(int r, int g, int b); - void SetSurfaceAttribute(int attribute); - void SetSurfaceFreeFlag(bool flag=true); - void SetClipArea(const Rect& r); + void SetSurface(Surface* new_surface, int x, int y, int attribute = 0); + void SetSurface(const char* new_surface, int x, int y); + void SetSurfacePos(int x, int y); + int SurfacePosX(void); + int SurfacePosY(void); + void SetSurfaceRect(const Rect& r); + void SetSurfaceAlpha(const unsigned char* alpha, const Rect& rect); + void SetSurfaceAlphaFile(const char* file); + void SetSurfaceColorKey(int r, int g, int b); + void SetSurfaceAttribute(int attribute); + void SetSurfaceFreeFlag(bool flag=true); + void SetClipArea(const Rect& r); - void hide(void); - void show_all(void); - void show(void); + void hide(void); + void show_all(void); + void show(void); - int PosX(void) const { return rel_pos.lx;} - int PosY(void) const { return rel_pos.ty;} - int Width(void) const { return rel_pos.width();} - int Height(void) const { return rel_pos.height();} - int DistanceRoot(void) const { return distance_root; } - bool IsHidden(void) { return is_hidden_now;} - bool IsParent(PicBase* pic); + int PosX(void) const { return rel_pos.lx;} + int PosY(void) const { return rel_pos.ty;} + int Width(void) const { return rel_pos.width();} + int Height(void) const { return rel_pos.height();} + int DistanceRoot(void) const { return distance_root; } + bool IsHidden(void) { return is_hidden_now;} + bool IsParent(PicBase* pic); - std::vector anm; - void ClearAnm(void); + std::vector anm; + void ClearAnm(void); }; class PicContainer : public PicBase { - friend class PicBase; + private: + friend class PicBase; - void BlitBack(iterator z, Rect rpos); // z より後ろの領域を描画 - void BlitFront(iterator z, Rect rpos); // z を含め、zより前の領域を描画 - void BlitChildren(Rect rpos); - void BlitSelf(Rect rpos); - void BlitSelf(void) { - is_cached = true; - BlitSelf(Rect(0, 0, rel_pos.width(), rel_pos.height())); - } -public: - List children; -private: + void BlitBack(iterator z, Rect rpos); // z より後ろの領域を描画 + void BlitFront(iterator z, Rect rpos); // z を含め、zより前の領域を描画 + void BlitChildren(Rect rpos); + void BlitSelf(Rect rpos); + void BlitSelf(void) { + is_cached = true; + BlitSelf(Rect(0, 0, rel_pos.width(), rel_pos.height())); + } + public: + List children; + private: - void set_showflag(void); - void set_nowhiddenflag(bool is_hide); -public: - PicContainer(const Rect& rel_pos, PicContainer* parent, int attr); - ~PicContainer(); - PicBase* create_leaf(const Rect& rel_pos, int attr); - PicContainer* create_node(const Rect& rel_pos, int attr); - PicRoot& Root(void) { return *root;} - void RMove(int add_x, int add_y); + void set_showflag(void); + void set_nowhiddenflag(bool is_hide); + public: + PicContainer(const Rect& rel_pos, PicContainer* parent, int attr); + ~PicContainer(); + PicBase* create_leaf(const Rect& rel_pos, int attr); + PicContainer* create_node(const Rect& rel_pos, int attr); + PicRoot& Root(void) { return *root;} + void RMove(int add_x, int add_y); }; typedef enum { NO_MASK, ALPHA_MASK, COLOR_MASK} MaskType; struct PicRoot { - class PicContainer* root; -private: - class FileToSurface* ftosurface; - struct UpdateItem { - PicBase* pic; - Rect rpos; - Rect apos; - static bool less(const UpdateItem&, const UpdateItem&); - UpdateItem(PicBase* p, const Rect& _rpos, const Rect& _apos) : pic(p), rpos(_rpos), apos(_apos) {} - }; - std::vector update_rects; + public: + class PicContainer* root; + private: + class FileToSurface* ftosurface; + struct UpdateItem { + PicBase* pic; + Rect rpos; + Rect apos; + static bool less(const UpdateItem&, const UpdateItem&); + UpdateItem(PicBase* p, const Rect& _rpos, const Rect& _apos) : pic(p), rpos(_rpos), apos(_apos) {} + }; + std::vector update_rects; - friend class FileToSurface; - void DeleteSurfaceImpl(Surface* s) const; -public: - void Update(PicBase* pic, const Rect& rpos, const Rect& apos); - void DeleteUpdatePic(PicBase* pic); - void ExecUpdate(void); - void SetWindowCaption(const char* caption); + friend class FileToSurface; + void DeleteSurfaceImpl(Surface* s) const; + public: + void Update(PicBase* pic, const Rect& rpos, const Rect& apos); + void DeleteUpdatePic(PicBase* pic); + void ExecUpdate(void); + void SetWindowCaption(const char* caption); - // Surface 操作 - Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data は malloc されたものであること(SDLの内部仕様) - Surface* NewSurface(int w, int h, MaskType with_mask) const; - Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK); - Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle); - void DeleteSurface(Surface* s); - void BlitSurface(Surface* src, const Rect& src_rpos, const unsigned char* alpha, const Rect& alpha_r, Surface* dest, const Rect& dest_rpos, int attribute) const; - void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const { - BlitSurface(src, src_rpos, 0, Rect(0,0), dest, dest_rpos, 0); - } - static bool with_mask(Surface* src); + // Surface 操作 + Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data は malloc されたものであること(SDLの内部仕様) + Surface* NewSurface(int w, int h, MaskType with_mask) const; + Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK); + Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle); + void DeleteSurface(Surface* s); + void BlitSurface(Surface* src, const Rect& src_rpos, const unsigned char* alpha, const Rect& alpha_r, Surface* dest, const Rect& dest_rpos, int attribute) const; + void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const { + BlitSurface(src, src_rpos, 0, Rect(0,0), dest, dest_rpos, 0); + } + static bool with_mask(Surface* src); - Surface* surface; - Surface* hw_surface; - int width, height; - PicRoot(void); - ~PicRoot(); - PicBase* create_leaf(const Rect& apos, int attr) { - return root->create_leaf(apos, attr); - } - PicContainer* create_node(const Rect& apos, int attr) { - return root->create_node(apos, attr); - } + Surface* surface; + Surface* hw_surface; + int width, height; + PicRoot(void); + ~PicRoot(); + PicBase* create_leaf(const Rect& apos, int attr) { + return root->create_leaf(apos, attr); + } + PicContainer* create_node(const Rect& apos, int attr) { + return root->create_node(apos, attr); + } }; class PicWidget { - PicBase* pic; /* 本来継承するべきだが、遅延初期化したいので instance */ -public: - PicWidget(void); - virtual ~PicWidget(); - void SetPic(PicBase* new_pic); - PicBase* Pic(void); - PicContainer* PicNode(void); - virtual void activate(void); - virtual void deactivate(void); - virtual void SetRegion(const Rect& apos); - void show(void); - void hide(void); - void show_all(void); + private: + PicBase* pic; /* 本来継承するべきだが、遅延初期化したいので instance */ + public: + PicWidget(void); + virtual ~PicWidget(); + void SetPic(PicBase* new_pic); + PicBase* Pic(void); + PicContainer* PicNode(void); + virtual void activate(void); + virtual void deactivate(void); + virtual void SetRegion(const Rect& apos); + void show(void); + void hide(void); + void show_all(void); }; #endif /* PICTURE */ diff --git a/window/rect.cc b/window/rect.cc --- a/window/rect.cc +++ b/window/rect.cc @@ -34,6 +34,7 @@ inline int MAX(int a, int b) { if (a>b) return a; return b; } + inline int MIN(int a, int b) { if (a>b) return b; return a; @@ -43,12 +44,14 @@ Rect::Rect(int x1, int y1) { lx = rx = x1; ty = by = y1; } + Rect::Rect(int x1, int y1, int x2, int y2) { lx = MIN(x1,x2); rx = MAX(x1,x2); ty = MIN(y1,y2); by = MAX(y1,y2); } + Rect::Rect(const Rect& r) { lx = r.lx; rx = r.rx; @@ -61,6 +64,7 @@ bool Rect::is_inner(const Rect& inner_re r.intersect(inner_rect); return r == inner_rect; } + bool Rect::is_nearly_inner(const Rect& inner_rect, int delta) const { Rect r = *this; r.lx -= delta; @@ -70,11 +74,13 @@ bool Rect::is_nearly_inner(const Rect& i r.intersect(inner_rect); return r == inner_rect; } + bool Rect::is_crossed(const Rect& rect) const { Rect r = *this; r.intersect(rect); return !(r.empty()); } + void Rect::intersect(const Rect& r) { if (lx > r.rx) rx = lx; else if (rx < r.lx) lx = rx; @@ -90,18 +96,21 @@ void Rect::intersect(const Rect& r) { by = MIN(by, r.by); } } + void Rect::join(const Rect& r) { lx = MIN(lx, r.lx); rx = MAX(rx, r.rx); ty = MIN(ty, r.ty); by = MAX(by, r.by); } + void Rect::rmove(int add_x, int add_y) { lx += add_x; rx += add_x; ty += add_y; by += add_y; } + void Rect::subtract(const Rect& rect, vector& ret_array) const { Rect r = *this; r.intersect(rect); @@ -128,5 +137,4 @@ void Rect::subtract(const Rect& rect, ve if (rx != r.rx) { ret_array.push_back(Rect(r.rx, r.ty, rx, r.by)); } - return; } diff --git a/window/render.cc b/window/render.cc --- a/window/render.cc +++ b/window/render.cc @@ -25,12 +25,12 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include"font/font.h" -#include"font/text.h" -#include"rect.h" -#include"SDL.h" -#include"surface.h" -#include +#include "font/font.h" +#include "font/text.h" +#include "rect.h" +#include "SDL.h" +#include "surface.h" +#include Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect, Surface* dst, const Rect& dstrect); // 文字描画 @@ -58,9 +58,11 @@ Rect::Rect(const class Surface& so) { lx = 0; ty = 0; rx = s->w; by = s->h; } + inline Rect _Rect(const SDL_Rect& r) { return Rect(r.x, r.y, r.x+r.w, r.y+r.h); -}; +} + inline SDL_Rect SDLed(const Rect& rect) { SDL_Rect r; r.x = rect.lx; @@ -151,11 +153,11 @@ Rect DSurfaceRenderText(TextGlyphStream: drawn_rect.rmove(dif_x, dif_y); return drawn_rect; } + void DSurfaceFill(Surface* src_o, const Rect& rect, int r, int g, int b, int a) { SDL_Rect sr = SDLed(rect); SDL_Surface* src = (SDL_Surface*)src_o; SDL_FillRect( src, &sr, SDL_MapRGBA(src->format, r, g, b, a)); - return; } static void clip_rect(Rect& srcrect, Rect& dstrect, SDL_Surface* dstsurf) { @@ -212,7 +214,6 @@ void DSurfaceMove(Surface* src_o, const } SDL_UnlockSurface(dst); SDL_UnlockSurface(src); - return; } void DSurfaceFillA(Surface* dsto, const Rect& rect, int r, int g, int b, int a) { @@ -229,7 +230,7 @@ void DSurfaceFillA(Surface* dsto, const unsigned int pixel = SDL_MapRGBA(dst->format, r, g, b, 0); unsigned int pixela = SDL_MapRGBA(dst->format, r, g, b, a); a += a>>7; /* 0-256 にする */ - int i,j; + int i, j; for (i=0; i> 8)) & CMASK2; *dmem = d1 | d | 0xff000000; } + static void blit_line(Uint32* dmem, Uint32* smem, const unsigned char* amem,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { int j; int ax = ax0; @@ -351,8 +352,8 @@ void DSurfaceBlitAlpha(Surface* src_o, c } SDL_UnlockSurface(src); SDL_UnlockSurface(dst); - return; } + void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { SDL_Surface* dst = (SDL_Surface*)dst_o; SDL_Surface* src = (SDL_Surface*)src_o; @@ -407,8 +408,8 @@ void DSurfaceBlitSaturate(Surface* src_o } SDL_UnlockSurface(src); SDL_UnlockSurface(dst); - return; } + void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o) { SDL_Surface* dst = (SDL_Surface*)dst_o; SDL_Surface* src = (SDL_Surface*)src_o; @@ -470,5 +471,4 @@ void DSurfaceBlitMultiply(Surface* src_o } SDL_UnlockSurface(dst); SDL_UnlockSurface(src); - return; } diff --git a/window/system.cc b/window/system.cc --- a/window/system.cc +++ b/window/system.cc @@ -25,84 +25,88 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include"system.h" -#include -#include +#include +#include "system.h" +#include +#include using namespace std; // void SDL_SetEventFilter(SDL_EventFilter filter); // typedef int (*SDL_EventFilter)(const SDL_Event *event); namespace System { + Main* Main::instance = NULL; -Main* Main::instance = 0; + int Main::event_filter(const SDL_Event* event) { + return 1; /* throw all event */ + } -int Main::event_filter(const SDL_Event* event) { - return 1; /* throw all event */ -} + Main::Main(void) { + instance = this; + framerate = 20; + cursor = NULL; + } -Main::Main(void) { - instance = this; - framerate = 20; - cursor = 0; -} -Main::~Main() { - if (cursor) delete cursor; -} -void Main::Quit(void) { - is_exit = true; -} -void Main::EnableVideo(void) { - is_video_update = true; -} -void Main::DisableVideo(void) { - is_video_update = false; -} -bool Main::is_exit = false; -bool Main::is_video_update = true; + Main::~Main() { + if (cursor) delete cursor; + } + + void Main::Quit(void) { + is_exit = true; + } + + void Main::EnableVideo(void) { + is_video_update = true; + } + + void Main::DisableVideo(void) { + is_video_update = false; + } + + bool Main::is_exit = false; + bool Main::is_video_update = true; -void Main::Mainloop(void) { - SDL_SetEventFilter(&event_filter); - Uint32 old_time = 0; - while(!is_exit) { - Uint32 start_time = SDL_GetTicks(); - if (! event.Exec(start_time)) break; - if (start_time - old_time > 1000/framerate) { - if (is_video_update) root.ExecUpdate(); - event.Exec(Event::Time::FRAME_UPDATE); - cout.flush(); - old_time = start_time; - } + void Main::Mainloop(void) { + SDL_SetEventFilter(&event_filter); + Uint32 old_time = 0; + while(!is_exit) { + Uint32 start_time = SDL_GetTicks(); + if (! event.Exec(start_time)) break; + if (start_time - old_time > 1000/framerate) { + if (is_video_update) root.ExecUpdate(); + event.Exec(Event::Time::FRAME_UPDATE); + cout.flush(); + old_time = start_time; + } -// 問題: -// z 軸と xy 軸の相互干渉;高速化 -// 移動するウィジット描画の高速化 -// キャッシュ -// 文字列の一部のみ更新の高速化 -// 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose -/* - Uint32 end_time = SDL_GetTicks(); - Uint32 delay = (end_time-start_time); - if(delay < 1000/framerate) SDL_Delay(1000/framerate - delay); - else SDL_Delay(0); -*/ - SDL_Delay(0); - }; -} + // 問題: + // z 軸と xy 軸の相互干渉;高速化 + // 移動するウィジット描画の高速化 + // キャッシュ + // 文字列の一部のみ更新の高速化 + // 「階層 z で x なる領域無効化、y なる領域生成」で良い?>Expose + /* + Uint32 end_time = SDL_GetTicks(); + Uint32 delay = (end_time-start_time); + if(delay < 1000/framerate) SDL_Delay(1000/framerate - delay); + else SDL_Delay(0); + */ + SDL_Delay(0); + } + } -void Main::SetCursor(Surface* s, const Rect& r) { - if (instance == 0) return; - if (instance->cursor) delete instance->cursor; - if (s == 0) { // カーソル消去 - instance->cursor = 0; - } else if (s == DEFAULT_MOUSECURSOR) { - instance->cursor = 0; - SDL_ShowCursor(SDL_ENABLE); - } else { - instance->cursor = new WidMouseCursor(instance->event, instance->root.root, s, r.lx, r.ty, r.width(), r.height()); - instance->cursor->show(); - SDL_ShowCursor(SDL_DISABLE); + void Main::SetCursor(Surface* s, const Rect& r) { + if (instance == 0) return; + if (instance->cursor) delete instance->cursor; + if (s == 0) { // カーソル消去 + instance->cursor = 0; + } else if (s == DEFAULT_MOUSECURSOR) { + instance->cursor = 0; + SDL_ShowCursor(SDL_ENABLE); + } else { + instance->cursor = new WidMouseCursor(instance->event, instance->root.root, s, r.lx, r.ty, r.width(), r.height()); + instance->cursor->show(); + SDL_ShowCursor(SDL_DISABLE); + } } } -} diff --git a/window/system.h b/window/system.h --- a/window/system.h +++ b/window/system.h @@ -28,31 +28,31 @@ #ifndef __SYSTEM__ #define __SYSTEM__ -#include -#include"event.h" -#include"picture.h" -#include"widget.h" +#include +#include "event.h" +#include "picture.h" +#include "widget.h" namespace System { -struct Main { - int framerate; - static int event_filter(const SDL_Event* event); - static bool is_exit; - static bool is_video_update; - static Main* instance; - WidMouseCursor* cursor; -public: - Event::Container event; - PicRoot root; - Main(void); - ~Main(); - void Mainloop(void); - static void Quit(void); - static void DisableVideo(void); - static void EnableVideo(void); -#define DEFAULT_MOUSECURSOR (Surface*)0xffff0000 - static void SetCursor(Surface* s, const Rect& r); -}; -}; + struct Main { + int framerate; + static int event_filter(const SDL_Event* event); + static bool is_exit; + static bool is_video_update; + static Main* instance; + WidMouseCursor* cursor; + public: + Event::Container event; + PicRoot root; + Main(void); + ~Main(); + void Mainloop(void); + static void Quit(void); + static void DisableVideo(void); + static void EnableVideo(void); +#define DEFAULT_MOUSECURSOR (Surface*)0xffff0000 //FIXME: WTF?!? + static void SetCursor(Surface* s, const Rect& r); + }; +} #endif /* __SYSTEM__ */ diff --git a/window/widget.cc b/window/widget.cc --- a/window/widget.cc +++ b/window/widget.cc @@ -25,10 +25,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include"widget.h" -#include -#include -#include +#include "widget.h" +#include +#include +#include Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect, Surface* dst, const Rect& dstrect); @@ -49,6 +49,7 @@ void SetFont(const char* font) { size_to_layout.clear(); wdefault_font = font; } + // namespace Widget { #define TimeCursor WidTimeCursor #define MouseCursor WidMouseCursor @@ -72,16 +73,21 @@ XKFont::HorizLayout* DefaultLayout(int t void PicWidget::activate(void) { } + void PicWidget::deactivate(void) { } + void PicWidget::SetRegion(const Rect& apos) { } + void PicWidget::show(void) { Pic()->show(); } + void PicWidget::hide(void) { Pic()->hide(); } + void PicWidget::show_all(void) { Pic()->show_all(); } @@ -119,6 +125,7 @@ MouseCursor::MouseCursor(Event::Containe x = 0; y = 0; container.RegisterGlobalMotionFunc(&Motionfunc, (void*)this); } + MouseCursor::MouseCursor(Event::Container& _container, PicContainer* parent, Surface* s, int x, int y, int w, int h) : Event::Video(_container), container(_container) { int sx, sy; @@ -148,37 +155,42 @@ Button::Button(Event::Container& contain show(); is_in = false; is_toggled = false; - press_func = 0; - press_pointer = 0; - drag_func = 0; - drag_pointer = 0; + press_func = NULL; + press_pointer = NULL; + drag_func = NULL; + drag_pointer = NULL; is_toggle_switch = false; } + Button::Button(Event::Container& container, PicContainer* parent, Surface* s, int _sx, int _sy, int _sdx, int _sdy, int _nptn, const Rect& r, int _z) : sx(_sx), sy(_sy), sdx(_sdx), sdy(_sdy), nptn(_nptn) ,Event::Video(container,r, _z) { SetPic(parent->create_leaf(r, 0)); Pic()->SetSurface(s, _sx, _sy); show(); is_in = false; is_toggled = false; - press_func = 0; - press_pointer = 0; - drag_func = 0; - drag_pointer = 0; + press_func = NULL; + press_pointer = NULL; + drag_func = NULL; + drag_pointer = NULL; is_toggle_switch = false; } + Button::~Button() { } + void Button::In(void) { is_in = true; if (nptn > 1) if (! is_toggled) Pic()->SetSurfacePos(sx+sdx, sy+sdy); } + void Button::Out(void) { is_in = false; if (!is_toggled) Pic()->SetSurfacePos(sx, sy); } + void Button::Toggle(bool new_toggle) { if (is_toggled == new_toggle) { return; @@ -196,6 +208,7 @@ void Button::Toggle(bool new_toggle) { Pic()->SetSurfacePos(sx, sy); } } + void Button::Press(void) { is_in = true; if (is_toggled) ; @@ -206,6 +219,7 @@ void Button::Press(void) { if (press_func) press_func(press_pointer, this); if (is_toggle_switch) Toggle(!is_toggled); } + void Button::Release(void) { if (is_toggled) ; else if (nptn > 1 && is_in) @@ -213,6 +227,7 @@ void Button::Release(void) { else if (nptn > 1) Pic()->SetSurfacePos(sx, sy); } + void Button::Drag(int x_from, int y_from, int x_to, int y_to) { if (drag_func) drag_func(x_from,y_from,x_to, y_to,drag_pointer, this); } @@ -224,16 +239,17 @@ Scale::Scale(Event::Container& _containe value(0), value_add(0), value_dragstart(0), is_vertical(_is_vertical), change_func(0), change_pointer(0) { - arrow_down = 0; - arrow_up = 0; - cursor = 0; - panel = 0; + arrow_down = NULL; + arrow_up = NULL; + cursor = NULL; + panel = NULL; Init(r_orig); } extern char* create_button(int number, int& width, int& height, int r, int g, int b); extern char* create_box(int& width, int& height, int r, int g, int b); + void Scale::Init(Rect r_orig) { int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b; // 矢印 @@ -322,8 +338,8 @@ void Scale::Init(Rect r_orig) { void Scale::InitCursor(int width_ratio) { int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b; - if (cursor) delete cursor; - cursor = 0; + if (cursor != NULL) delete cursor; + cursor = NULL; Rect region(0,0); if (width_ratio < 0) width_ratio = 0; else if (width_ratio > 1024) width_ratio = 1024; @@ -359,22 +375,23 @@ void Scale::InitCursor(int width_ratio) if (bar_width <= 0) value_add = max-min; else if (cursor_width == 0) value_add = 2; else value_add = scale_max*cursor_width/bar_width; - - return; } void Scale::PressArrowDown(void* pointer, Button* from) { Scale* self = (Scale*)pointer; self->SetScaleValue(self->value + self->value_add); } + void Scale::PressArrowUp(void* pointer, Button* from){ Scale* self = (Scale*)pointer; self->SetScaleValue(self->value - self->value_add); } + void Scale::PressCursor(void* pointer, Button* from){ Scale* self = (Scale*)pointer; self->value_dragstart = self->value; } + void Scale::DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from){ Scale* self = (Scale*)pointer; int dx, w; @@ -388,6 +405,7 @@ void Scale::DragCursor(int x_from, int y if (w == 0) return; self->SetScaleValue(self->value_dragstart + dx*scale_max/w); } + int Scale::CalcValue(void) { Rect own_region = Event::Video::Region(); int x, w; @@ -403,12 +421,13 @@ int Scale::CalcValue(void) { else if (x > w) x = w; return x*scale_max/w; } + void Scale::Press(void){ int v = CalcValue(); if (v < value) SetScaleValue(value-value_add); else SetScaleValue(value+value_add); - return; } + void Scale::Motion(int x, int y){ mouse_x = x; mouse_y = y; @@ -418,8 +437,8 @@ void Scale::SetRange(int new_min, int ne min = new_min; max = new_max; SetValue(value); - return; } + void Scale::SetValue(int new_value) { if (min == max) { value = min; @@ -429,9 +448,11 @@ void Scale::SetValue(int new_value) { int scale_value = (new_value-min) * scale_max / (max-min); SetScaleValue(scale_value); } + int Scale::GetValue(void) const{ return min + value * (max-min) / scale_max; } + void Scale::SetScaleValue(int new_value) { if (new_value < 0) value = 0; else if (new_value > scale_max) value = scale_max; @@ -450,7 +471,6 @@ void Scale::SetScaleValue(int new_value) if (change_func) { (*change_func)(change_pointer, this); } - return; } TextButton::TextButton(Event::Container& container, PicContainer* parent, const char* text, int _text_size, Attribute attr, const Rect& r_orig, int _z, const Color& _fore, const Color& _pressed, const Color& _back) : @@ -462,7 +482,7 @@ TextButton::TextButton(Event::Container& // まず、テキスト領域の広さを得る Rect r(r_orig); - if (text == 0) text = ""; + if (text == NULL) text = ""; int width = r.width(); int height = r.height(); if (width == 0) width = parent->Width() - r.lx; @@ -485,12 +505,15 @@ TextButton::TextButton(Event::Container& Pic()->SetSurfaceRect(r); } - sx = 0; sy = 0; sdx = 0; sdy = r.height(); nptn = 3; + sx = 0; sy = 0; sdx = 0; + sdy = r.height(); + nptn = 3; int x = 0, y = 0; if (attribute & CENTER) x = (Pic()->Width() - gs.width()) / 2; y = (Pic()->Height() - gs.height()) / 2; + //FIXME: (back.a == NULL ?) if (back.a == 0) { // 背景なし、もしくはボタン押の状態のみ背景あり surface = root.NewSurface(r.width(), r.height()*2, ALPHA_MASK); DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0); @@ -530,11 +553,12 @@ TextButton::TextButton(Event::Container& Pic()->SetSurface(surface, 0, 0); show(); } + void TextButton::SetText(const char* text, const Color& _fore, const Color& _pressed, const Color& _back) { int width = Pic()->Width(); int height = Pic()->Height(); // まず、テキスト領域の広さを得る - if (text == 0) text = ""; + if (text == NULL) text = ""; TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width); @@ -547,8 +571,9 @@ void TextButton::SetText(const char* tex int surf_y = Pic()->SurfacePosY(); Pic()->SetSurface( (Surface*)0,0,0); root.DeleteSurface(surface); - surface = 0; + surface = NULL; + //FIXME: (back.a == NULL) ? if (back.a == 0) { // 背景なし surface = root.NewSurface(width, height*2, ALPHA_MASK); DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0); @@ -586,8 +611,7 @@ void TextButton::SetText(const char* tex TextButton::~TextButton() { if (surface) root.DeleteSurface(surface); - surface = 0; - return; + surface = NULL; } Text::Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int _fontsize) : @@ -622,6 +646,7 @@ Text::~Text() { void Text::SetSpeed(int new_speed) { speed = new_speed; } + void Text::SetWait(int new_wait) { if (new_wait < 0) new_wait = 100000000; wait_delay = new_wait; @@ -637,6 +662,7 @@ int Text::CalcScrollHeight(void) { if (i == line_number) i = line_number + 1; return i - line_number - 1; } + void Text::Elapsed(unsigned int current_time) { SetWakeup(current_time + 50); if (status == PREPARE) { @@ -710,7 +736,6 @@ label_wait2: if (cursor) cursor->hide(); } status = PREPARE; - return; } bool Text::Pressed(int x, int y, void* pointer) { @@ -776,7 +801,6 @@ void Text::DrawText(int& nChar) { Rect r = DSurfaceRenderText(cur_pos, it, srcrect, surface, Rect(0,0,0,0)); pictext->ReBlit(r); cur_pos = it; - return; } void Text::Scrollup(int& nChar) { @@ -811,7 +835,6 @@ void Text::Scrollup(int& nChar) { r.ty = r.by-cur_dy; DSurfaceFill(surface, r, 0, 0, 0, 0); pictext->ReBlit(); - return; } void Text::activate(void) { @@ -820,12 +843,14 @@ void Text::activate(void) { window_activated = true; if (cursor_activated && window_activated && cursor) cursor->show(); } + void Text::deactivate(void) { event.DeleteGlobalPressFunc(&Pressed, (void*)this); Event::Video::deactivate(); window_activated = false; if (cursor) cursor->hide(); } + void Text::SetCursor(TimeCursor* c) { cursor = c; if (c) { @@ -840,8 +865,9 @@ Label::Label(PicContainer* parent, const text_size(_text_size) { Rect r(r_orig); - if (text == 0) text = ""; - int width = r.width(); int height = r.height(); + if (text == NULL) text = ""; + int width = r.width(); + int height = r.height(); if (width == 0) width = parent->Width() - r.lx; TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width); @@ -871,11 +897,13 @@ Label::Label(PicContainer* parent, const Pic()->SetSurface(surface, 0, 0); show(); } + Label::~Label() { root.DeleteSurface(surface); } + void Label::SetText(const char* text) { - if (text == 0) text = ""; + if (text == NULL) text = ""; TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, Pic()->Width()); DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0); int x = 0, y = 0; @@ -893,8 +921,8 @@ Dialog::Dialog(Event::Container& contain int x,y; status = WAIT; - set_func = 0; - set_pointer = 0; + set_func = NULL; + set_pointer = NULL; XKFont::HorizLayout& layout = *DefaultLayout(26); int dialog_width = parent->Width() / 2; @@ -969,12 +997,12 @@ Dialog::Dialog(Event::Container& contain show_all(); } + Dialog::~Dialog() { PicRoot& root = PicNode()->Root(); - SetPic(0); + SetPic(NULL); root.DeleteSurface(surface_btn); root.DeleteSurface(surface_diag); - return; } void Dialog::press_ok(void* pointer, Button* btn) { @@ -986,6 +1014,7 @@ void Dialog::press_ok(void* pointer, But } } } + void Dialog::press_cancel(void* pointer, Button* btn) { if (pointer) { Dialog* wid = (Dialog*)pointer; @@ -1016,12 +1045,14 @@ AnmTime::AnmTime(Event::Container& conta status = FINISHED; if (total_time == 0) total_time = 1; } + AnmTime::AnmTime(Event::Container& container, std::vector _pic, int _total_time, int _all_count) : Event::Time(container), PicAnm(_pic), start_time(0), total_time(_total_time), all_count(_all_count) { status = FINISHED; if (total_time == 0) total_time = 1; } + void AnmTime::Elapsed(unsigned int current_time) { if (total_time == 0) return; if (status == FINISHED || current_time == 0) {SetWakeup(current_time+1); return;} @@ -1040,8 +1071,8 @@ void AnmTime::Elapsed(unsigned int curre Finish(); status = FINISHED; } - return; } + void AnmTime::Abort(void) { if (status == FINISHED) return; if (start_time == 0) { @@ -1053,9 +1084,11 @@ void AnmTime::Abort(void) { } status = FINISHED; } + bool AnmTime::IsEnd(void) { return status == FINISHED; } + AnmMove::AnmMove(Event::Container& container, PicBase* _pic, const Rect& _to, int total_time) : AnmTime(container, _pic, total_time), from(0,0), to(_to) { @@ -1072,14 +1105,17 @@ AnmMove::AnmMove(Event::Container& conta if (dx == 0) dx = 1; SetAllCount(dx); } + void AnmMove::Exec(int count) { Rect r(from); int dx = to.lx - from.lx; int dy = to.ty - from.ty; r.rmove(dx*count/all_count, dy*count/all_count); iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->Move(r.lx, r.ty); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->Move(r.lx, r.ty); } + AnmAlpha::AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time) : AnmTime(container, _pic, total_time), from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) { @@ -1092,6 +1128,7 @@ AnmAlpha::AnmAlpha(Event::Container& con if (c == 0) c = 1; SetAllCount(c); } + AnmAlpha::AnmAlpha(Event::Container& container, std::vector _pic, int alpha_from, int alpha_to, int total_time) : AnmTime(container, _pic, total_time), from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) { @@ -1104,15 +1141,20 @@ AnmAlpha::AnmAlpha(Event::Container& con if (c == 0) c = 1; SetAllCount(c); } + void AnmAlpha::Start(void) { iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->show(); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->show(); } + void AnmAlpha::Exec(int count) { alpha = (from * (all_count-count) + (to-from) * count) / all_count; iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(&alpha, alpha_r); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->SetSurfaceAlpha(&alpha, alpha_r); } + void AnmAlpha::Finish(void) { iterator it; for (it=pic.begin(); it!=pic.end(); it++) { @@ -1121,9 +1163,11 @@ void AnmAlpha::Finish(void) { (*it)->SetSurfaceAlpha(0,Rect(0,0)); } } + AnmAlphaMove::AnmAlphaMove(Event::Container& container, PicBase* _pic) : AnmTime(container, _pic, 0) { } + void AnmAlphaMove::SetPtn(void) { int total = 0; std::vector::iterator it; @@ -1134,6 +1178,7 @@ void AnmAlphaMove::SetPtn(void) { SetTotalTime(total); cur_count = 0; } + void AnmAlphaMove::Exec(int count) { if (ptns.empty()) return; if (cur_count != 0 && ptns[cur_count].next_tick > count) return; @@ -1161,6 +1206,7 @@ void AnmAlphaMove::Exec(int count) { else { (*p)->show(); (*p)->SetSurfaceAlpha( &(it->alpha), Rect(0,0,1,1)); } } } + void AnmAlphaMove::Finish(void) { if (ptns.empty()) return; if (cur_count >= ptns.size() - 1) return; @@ -1199,8 +1245,10 @@ void AnmPtnSolid::Exec(int count) { else alpha[i] = 0; } iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(alpha, alpha_r); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->SetSurfaceAlpha(alpha, alpha_r); } + void AnmPtnAlpha::Exec(int count) { int i; int ptn_zero = count; @@ -1216,16 +1264,22 @@ void AnmPtnAlpha::Exec(int count) { void AnmPtnSolid::Start(void) { iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->show(); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->show(); } + void AnmPtnSolid::Finish(void) { iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0)); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->SetSurfaceAlpha(0, Rect(0,0)); } + void AnmPtnAlpha::Start(void) { iterator it; - for (it=pic.begin(); it!=pic.end(); it++) (*it)->show(); + for (it=pic.begin(); it!=pic.end(); it++) + (*it)->show(); } + void AnmPtnAlpha::Finish(void) { iterator it; for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0)); diff --git a/window/widget.h b/window/widget.h --- a/window/widget.h +++ b/window/widget.h @@ -28,11 +28,11 @@ #ifndef __WIDGET_H__ #define __WIDGET_H__ -#include -#include"font/font.h" -#include"font/text.h" -#include"event.h" -#include"picture.h" +#include +#include "font/font.h" +#include "font/text.h" +#include "event.h" +#include "picture.h" #define TimeCursor WidTimeCursor #define MouseCursor WidMouseCursor @@ -51,7 +51,7 @@ // namespace Widget { struct TimeCursor : public Event::Time, PicWidget { - int x,y,dx,dy, nptn; + int x, y, dx, dy, nptn; int old_time, count, interval; TimeCursor(Event::Container& container, int _interval, PicContainer* parent, const char* fname, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r); void Elapsed(unsigned int current_time); @@ -93,52 +93,52 @@ struct Button : public Event::Video, Pic void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);} }; struct Scale : Event::Video, PicWidget { -private: - Button* arrow_down, *arrow_up; - Button* cursor; - PicContainer* panel; - Event::Container& container; - PicContainer* parent; - Color cursor_color; + private: + Button* arrow_down, *arrow_up; + Button* cursor; + PicContainer* panel; + Event::Container& container; + PicContainer* parent; + Color cursor_color; - int mouse_x, mouse_y; - enum {scale_max = 65536}; - int min, max; - int value; - int value_add; - int value_dragstart; - int cursor_width; - bool is_vertical; - -public: + int mouse_x, mouse_y; + enum {scale_max = 65536}; + int min, max; + int value; + int value_add; + int value_dragstart; + int cursor_width; + bool is_vertical; - Scale(Event::Container& container, PicContainer* parent, const Rect& r_orig, const Color& cursor_color, bool _is_vertical); - void InitCursor(int cursor_width_ratio); // 1024=max - void SetRange(int min, int max); - void SetValue(int value); - int GetValue(void) const; - typedef void (*ChangeFunc)(void* pointer, Scale* from); - ChangeFunc change_func; - void* change_pointer; -private: - void Init(Rect r_orig); - int CalcValue(void); - void SetScaleValue(int value); + public: + Scale(Event::Container& container, PicContainer* parent, const Rect& r_orig, const Color& cursor_color, bool _is_vertical); + void InitCursor(int cursor_width_ratio); // 1024=max + void SetRange(int min, int max); + void SetValue(int value); + int GetValue(void) const; + typedef void (*ChangeFunc)(void* pointer, Scale* from); + ChangeFunc change_func; + void* change_pointer; + + private: + void Init(Rect r_orig); + int CalcValue(void); + void SetScaleValue(int value); - // callback - static void PressArrowDown(void* pointer, Button* from); - static void PressArrowUp(void* pointer, Button* from); - static void PressCursor(void* pointer, Button* from); - static void DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from); + // callback + static void PressArrowDown(void* pointer, Button* from); + static void PressArrowUp(void* pointer, Button* from); + static void PressCursor(void* pointer, Button* from); + static void DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from); - // 継承:Event::Video - void Press(void); - void Motion(int x, int y); + // 継承:Event::Video + void Press(void); + void Motion(int x, int y); - /* 継承 : PicWidget */ - void activate(void) { Event::Video::activate();} - void deactivate(void) { Event::Video::deactivate();} - void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);} + /* 継承 : PicWidget */ + void activate(void) { Event::Video::activate();} + void deactivate(void) { Event::Video::deactivate();} + void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);} }; struct TextButton : public Button { @@ -159,83 +159,86 @@ struct TextButton : public Button { struct Text : public Event::Video, Event::Time, PicWidget { typedef TextGlyphStream::iterator iterator; -private: - Event::Container& event; -public: - PicBase* pictext; -private: - TimeCursor* cursor; - Surface* surface; - TextGlyphStream gstream; - std::vector bottom_pos; // 行高さ(height)の累計値 - XKFont::HorizLayout layout; - int fontsize; + private: + Event::Container& event; + public: + PicBase* pictext; + private: + TimeCursor* cursor; + Surface* surface; + TextGlyphStream gstream; + std::vector bottom_pos; // 行高さ(height)の累計値 + XKFont::HorizLayout layout; + int fontsize; - iterator cur_pos; - int line_number; - Rect srcrect; - int press_count; - int scrolled_count; - int scroll_height; - bool window_activated; - bool cursor_activated; + iterator cur_pos; + int line_number; + Rect srcrect; + int press_count; + int scrolled_count; + int scroll_height; + bool window_activated; + bool cursor_activated; - int speed; // chars / sec or -1 - int wait_delay; // msec - int old_time; - int wait_starttime; + int speed; // chars / sec or -1 + int wait_delay; // msec + int old_time; + int wait_starttime; - int CalcScrollHeight(void); - void DrawText(int& nChar); - void Scrollup(int& nChar); -public: - Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize); - ~Text(); + int CalcScrollHeight(void); + void DrawText(int& nChar); + void Scrollup(int& nChar); + + public: + Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize); + ~Text(); - TextStream stream; - enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status; + TextStream stream; + enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status; - void Clear(void); - void Start(void); - void Flush(void); + void Clear(void); + void Start(void); + void Flush(void); - void Elapsed(unsigned int current_time); - static bool Pressed(int x, int y, void* pointer); - void activate(void); - void deactivate(void); - void SetSpeed(int new_speed); - void SetWait(int new_wait); + void Elapsed(unsigned int current_time); + static bool Pressed(int x, int y, void* pointer); + void activate(void); + void deactivate(void); + void SetSpeed(int new_speed); + void SetWait(int new_wait); - void SetCursor(TimeCursor* cursor); + void SetCursor(TimeCursor* cursor); }; extern void SetFont(const char* fontname); struct Label : PicWidget{ -private: - Surface* surface; - bool is_center; - PicRoot& root; - int text_size; -public: - Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26); - ~Label(); - void SetText(const char* text); + private: + Surface* surface; + bool is_center; + PicRoot& root; + int text_size; + public: + Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26); + ~Label(); + void SetText(const char* text); }; class Dialog : public Event::Video, PicWidget { - Surface* surface_btn; - Surface* surface_diag; -public: - enum { WAIT, OK, CANCEL} status; - Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel); - ~Dialog(); - static void press_ok(void* pointer, Button* btn); - static void press_cancel(void* pointer, Button* btn); - static void DrawBox(Surface* s, const Rect& r); - typedef void (*SetFunc)(void* pointer, Dialog* from); - SetFunc set_func; - void* set_pointer; + private: + Surface* surface_btn; + Surface* surface_diag; + + public: + enum { WAIT, OK, CANCEL} status; + Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel); + ~Dialog(); + static void press_ok(void* pointer, Button* btn); + static void press_cancel(void* pointer, Button* btn); + static void DrawBox(Surface* s, const Rect& r); + typedef void (*SetFunc)(void* pointer, Dialog* from); + SetFunc set_func; + void* set_pointer; }; struct AnmTime : public Event::Time, PicAnm { @@ -267,6 +270,7 @@ struct AnmMove : public AnmTime { AnmMove(Event::Container& container, PicBase* _pic, const Rect& to, int total_time); void Exec(int count); }; + #define ALPHA_MAX 255 struct AnmAlpha : public AnmTime { int from, to; @@ -277,6 +281,7 @@ struct AnmAlpha : public AnmTime { void Exec(int count); void Finish(void); }; + struct AnmAlphaMove : public AnmTime { struct Ptn { Rect pos; @@ -293,6 +298,7 @@ struct AnmAlphaMove : public AnmTime { void Exec(int count); void Finish(void); }; + struct AnmPtnSolid : public AnmTime { AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int total_time); ~AnmPtnSolid() { delete[] alpha; } @@ -305,6 +311,7 @@ struct AnmPtnSolid : public AnmTime { void Exec(int count); void Finish(void); }; + struct AnmPtnAlpha : public AnmTime { AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int alpha_bandwidth, int total_time); ~AnmPtnAlpha() { delete[] alpha; } diff --git a/xlovesys.cc b/xlovesys.cc --- a/xlovesys.cc +++ b/xlovesys.cc @@ -31,24 +31,24 @@ /* kochi-mincho-subst.ttf あるいは -*-*-*-r-*--24-*-*-*-*-*-jisx0208.1983-* など */ /* TrueType Font は /usr/X11R6/lib/X11/fonts/TrueType/ などに存在する必要がある */ -#include -#include -#include -#include +#include +#include +#include +#include -#include -#include -#include +#include +#include +#include -#include"system/file.h" -#include"system/system_config.h" -#include"window/widget.h" -#include"window/system.h" +#include "system/file.h" +#include "system/system_config.h" +#include "window/widget.h" +#include "window/system.h" -#include"music2/music.h" +#include "music2/music.h" -#include"scn2k/scn2k.h" -#include"scn2k/scn2k_impl.h" +#include "scn2k/scn2k.h" +#include "scn2k/scn2k_impl.h" const char key_lb_orig[] = {0x4b, 0x45, 0x59, 0x5c, 0x83, 0x8a, 0x83, 0x67, 0x83, 0x8b, 0x83, 0x6f, 0x83, 0x58, 0x83, 0x5e, 0x81, 0x5b, 0x83, 0x59, 0x81, 0x49, 0}; @@ -112,7 +112,7 @@ int main(int argc, char *argv[]) { printf(" Root Path : %s\n", rootPath); printf(" Font : %s\n", font); printf("\n"); - + file_searcher.InitRoot(rootPath); config.LoadInitFile(); const char* regname = config.GetParaStr("#REGNAME"); @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) { if(SDL_Init(SDL_INIT_VIDEO)) { printf("Unable to init SDL: %s\n", SDL_GetError()); - return 1; + return 1; } config.GetParam("#SCREENSIZE_MOD", 1, &screenmode); @@ -143,18 +143,18 @@ int main(int argc, char *argv[]) { } // SDL_SetVideoMode(640, 480, 0, videoOptions); // SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE /*| SDL_FULLSCREEN */); - { - System::Main main_sys; - PicContainer* main_panel = main_sys.root.create_node(Rect(0, 0, main_sys.root.width, main_sys.root.height), 0); - main_panel->show(); - try { - Scn2k scn(main_sys.event, *main_panel, mu, config); - main_sys.Mainloop(); - } catch(...) { - fprintf(stderr,"System faulted; exit now.\n"); - } - delete main_panel; + + System::Main main_sys; + PicContainer* main_panel = main_sys.root.create_node(Rect(0, 0, main_sys.root.width, main_sys.root.height), 0); + main_panel->show(); + try { + Scn2k scn(main_sys.event, *main_panel, mu, config); + main_sys.Mainloop(); + } catch(...) { + fprintf(stderr,"System faulted; exit now.\n"); } + delete main_panel; + mu.FinalizeMusic();