Bind Bitmap mega+maxsize detection functions

This commit is contained in:
Roza 2020-04-23 04:18:25 -04:00
parent 2775a5a8e2
commit ad5fb9d08e
4 changed files with 55 additions and 20 deletions

View file

@ -426,6 +426,24 @@ RB_METHOD(bitmapSaveToFile) {
return RUBY_Qnil;
}
RB_METHOD(bitmapGetMega){
RB_UNUSED_PARAM;
rb_check_argc(argc, 0);
Bitmap *b = getPrivateData<Bitmap>(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");
}

View file

@ -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

View file

@ -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)

View file

@ -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<void> modified;
static int maxSize();
private:
void releaseResources();
const char *klassName() const { return "bitmap"; }