Author Topic: A new Lemmings remake for Windows  (Read 9664 times)

0 Members and 1 Guest are viewing this topic.

zennehoy

  • Guest
Re: A new Lemmings remake for Windows
« Reply #15 on: March 31, 2008, 12:24:59 PM »
The most obvious problem I see is that you lock the image(s) much more often than you need to... try locking them once, then do the loop, and unlock when you're done.
Cheers,
Zen

0xdeadbeef

  • Guest
Re: A new Lemmings remake for Windows
« Reply #16 on: March 31, 2008, 04:55:35 PM »
Well, this most probably doesn't help, but this is how I do it in Lemmini:

Code: [Select]
// remove invisible pixels from all object frames that are "in front"
// for upside down objects, just create the upside down copy
if (o.upsideDown || inFront) {
    for (int frame = 0; frame < spr.frames; frame++) {                        
        imgSpr = ToolBox.createImage(spr.width,spr.height, Transparency.BITMASK);                // get flipped or normal version
        if (o.upsideDown) {
            // flip the image vertically
            imgSpr = op.filter(spr.img[frame], imgSpr);
        } else {
            WritableRaster rImgSpr = imgSpr.getRaster();                            
            rImgSpr.setRect(spr.img[frame].getRaster()); // just copy
        }
        // for "in front" objects the really drawn pixels have to be determined
        if (inFront) {
            for (int y = 0; y < spr.height; y++) {
                if (y + spr.y < 0 || y + spr.y >= bgHeight)
                    continue;
                int yLineStencil = (y + spr.y) * bgWidth;
                for (int x = 0; x < spr.width; x++) {
                    if (x + spr.x < 0 || x + spr.x >= bgWidth)
                        continue;
                    // now read stencil
                    int stencilVal = stencil.get(yLineStencil + spr.x+ x);
                    int stencilValMasked = stencilVal & Stencil.MSK_WALK_ON;
                    boolean paint =
                        drawFull || (stencilValMasked != 0 && drawOnVis) || (stencilValMasked == 0 && noOverwrite);
                    // hack for overlap:
                    int id = Stencil.getObjectID(stencilVal);
                    // check if a different interactive object was already entered at this pixel position
                    // however: exits must always be painted
                    // also: passive objects will always be painted
                    if ( inFront && spr.type != SpriteObject.TYPE_PASSIVE && spr.type != SpriteObject.TYPE_EXIT && id!=0 && id != n)
                        paint = false;
                    // sprite screenBuffer  pixel
                    int imgCol = imgSpr.getRGB(x,y);
                    if ((imgCol & 0xff000000) == 0)
                        continue;
                    if (!paint)
                        imgSpr.setRGB(x,y,imgCol&0xffffff); // set transparent
                }
            }                
        }
        spr.img[frame] = imgSpr;
    }
}

In short: I create an instance for each arrow object ("inFront") and remove each pixel (by making it transparent) that is not set in the underlying background stencil.

Offline Geoff

  • Posts: 33
    • View Profile
Re: A new Lemmings remake for Windows
« Reply #17 on: March 31, 2008, 11:08:22 PM »
Zenn your right about that, according to blitz you can only lock one buffer at a time, so i tried it and they are wrong. Much faster.

The arrows are sorted now.  :thumbsup:

Thanks for that piece of code Volker, I'm not that clued up on c++/Java

I did programme the old Atari 800XL in 6502 machine code in the 80's/90's had a couple of games marketed "Air rescue" and "Dawn raider" Atlantis software. I written the code raw, very time consuming.  :laugh: