diff --git a/binding/bitmap-binding.cpp b/binding/bitmap-binding.cpp index b2ce998a..66186032 100644 --- a/binding/bitmap-binding.cpp +++ b/binding/bitmap-binding.cpp @@ -426,6 +426,24 @@ RB_METHOD(bitmapSaveToFile) { return RUBY_Qnil; } +RB_METHOD(bitmapGetMega){ + RB_UNUSED_PARAM; + + rb_check_argc(argc, 0); + + Bitmap *b = getPrivateData(self); + + return rb_bool_new(b->isMega()); +} + +RB_METHOD(bitmapGetMaxSize){ + RB_UNUSED_PARAM; + + rb_check_argc(argc, 0); + + return INT2NUM(Bitmap::maxSize()); +} + RB_METHOD(bitmapInitializeCopy) { rb_check_argc(argc, 1); VALUE origObj = argv[0]; @@ -480,5 +498,8 @@ void bitmapBindingInit() { _rb_define_method(klass, "blur", bitmapBlur); _rb_define_method(klass, "radial_blur", bitmapRadialBlur); + _rb_define_method(klass, "mega?", bitmapGetMega); + rb_define_singleton_method(klass, "max_size", RUBY_METHOD_FUNC(bitmapGetMaxSize), 0); + INIT_PROP_BIND(Bitmap, Font, "font"); } diff --git a/scripts/EssentialsTilemapHack.rb b/scripts/EssentialsTilemapHack.rb index 6de1d946..c3d46ffd 100644 --- a/scripts/EssentialsTilemapHack.rb +++ b/scripts/EssentialsTilemapHack.rb @@ -24,14 +24,14 @@ # but that's work for another day. # # For now, I'm just happy I can finally test whatever game I like. -# -$GL_TEX_CAP = 16384 # << This should be automatically set at some point. -# # ~Zoro #======================================================================= module VWrap + MAX_TEX_SIZE = Bitmap.max_size + TILESET_WIDTH = 0x100 + def self.clamp(val, min, max) val = max if val > max val = min if val < min @@ -41,16 +41,16 @@ module VWrap def self.makeVWrappedTileset(originalbmp) width = originalbmp.width height = originalbmp.height - if width == 256 && height > $GL_TEX_CAP - columns = (height / $GL_TEX_CAP.to_f).ceil + if width == TILESET_WIDTH && originalbmp.mega? + columns = (height / MAX_TEX_SIZE.to_f).ceil - return nil if columns * 256 > $GL_TEX_CAP - bmp = Bitmap.new(256*columns, $GL_TEX_CAP) - remainder = height % $GL_TEX_CAP + return nil if columns * TILESET_WIDTH > MAX_TEX_SIZE + bmp = Bitmap.new(TILESET_WIDTH*columns, MAX_TEX_SIZE) + remainder = height % MAX_TEX_SIZE columns.times{|col| - srcrect = Rect.new(0, col * $GL_TEX_CAP, width, (col + 1 == columns) ? remainder : $GL_TEX_CAP) - bmp.blt(col*256, 0, originalbmp, srcrect) + srcrect = Rect.new(0, col * MAX_TEX_SIZE, width, (col + 1 == columns) ? remainder : MAX_TEX_SIZE) + bmp.blt(col*TILESET_WIDTH, 0, originalbmp, srcrect) } return bmp end @@ -59,22 +59,22 @@ module VWrap end def self.blitVWrappedPixels(destX, destY, dest, src, srcrect) - merge = (srcrect.y % $GL_TEX_CAP) > ((srcrect.y + srcrect.height) % $GL_TEX_CAP) + merge = (srcrect.y % MAX_TEX_SIZE) > ((srcrect.y + srcrect.height) % MAX_TEX_SIZE) - srcrect.x = clamp(srcrect.x, 0,256) - srcrect.width = clamp(srcrect.width, 0, 256 - srcrect.x) - col = (srcrect.y / $GL_TEX_CAP.to_f).floor - srcX = col * 256 + srcrect.x - srcY = srcrect.y % $GL_TEX_CAP + srcrect.x = clamp(srcrect.x, 0,TILESET_WIDTH) + srcrect.width = clamp(srcrect.width, 0, TILESET_WIDTH - srcrect.x) + col = (srcrect.y / MAX_TEX_SIZE.to_f).floor + srcX = col * TILESET_WIDTH + srcrect.x + srcY = srcrect.y % MAX_TEX_SIZE if !merge dest.blt(destX, destY, src, Rect.new(srcX, srcY, srcrect.width, srcrect.height)) else #FIXME won't work on heights longer than two columns, but nobody should need # more than 32k pixels high at once anyway - side = {:a => $GL_TEX_CAP - srcY, :b => srcrect.height - ($GL_TEX_CAP - srcY)} + side = {:a => MAX_TEX_SIZE - srcY, :b => srcrect.height - (MAX_TEX_SIZE - srcY)} dest.blt(destX, destY, src, Rect.new(srcX, srcY, srcrect.width, side[:a])) - dest.blt(destX, destY + side[:a], src, Rect.new(srcX + 256, 0, srcrect.width, side[:b])) + dest.blt(destX, destY + side[:a], src, Rect.new(srcX + TILESET_WIDTH, 0, srcrect.width, side[:b])) end end end @@ -83,7 +83,7 @@ end if $MKXP == true class CustomTilemap def tileset=(value) - if value.height > $GL_TEX_CAP || value.width > $GL_TEX_CAP + if value.mega? @tileset = VWrap::makeVWrappedTileset(value) else @tileset = value @@ -93,7 +93,7 @@ if $MKXP == true alias old_getRegularTile getRegularTile def getRegularTile(sprite, id) - return old_getRegularTile(sprite, id) if @tileset.width <= 256 + return old_getRegularTile(sprite, id) if @tileset.width <= VWrap::TILESET_WIDTH bitmap = @regularTileInfo[id] if !bitmap diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 18dcb14c..4c962775 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -389,6 +389,12 @@ int Bitmap::height() const return p->gl.height; } +bool Bitmap::isMega() const{ + guardDisposed(); + + return p->megaSurface; +} + IntRect Bitmap::rect() const { guardDisposed(); @@ -1407,6 +1413,10 @@ void Bitmap::taintArea(const IntRect &rect) p->addTaintedArea(rect); } +int Bitmap::maxSize(){ + return glState.caps.maxTexSize; +} + void Bitmap::releaseResources() { if (p->megaSurface) diff --git a/src/bitmap.h b/src/bitmap.h index 687dc125..9c2ffea4 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -47,6 +47,8 @@ public: int width() const; int height() const; + bool isMega() const; + IntRect rect() const; void blt(int x, int y, @@ -124,6 +126,8 @@ public: sigc::signal modified; + static int maxSize(); + private: void releaseResources(); const char *klassName() const { return "bitmap"; }