Jump to content

Photo

Solid FFCs

Edges

  • Please log in to reply
31 replies to this topic

#16 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 20 April 2014 - 09:31 AM

I've run into my fair share of problems because of Waitdraw() placement. I think that we could use a good tutorial on when, how, and why to implement things either before, or after, Waitdraw().

Do you think you might be up to that Zecora?

#17 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 20 April 2014 - 10:14 AM


Waitdraw only runs the internal code allowing things to update for this frame up to drawing which is the last thing that happens. If you want to incorporate changes that happen the current frame such as Link's Movement and current Action you'll need make your changes after calling Waitdraw and still call Waitframe at the end of the loop; or at the beginning, since it actually doesn't matter. Just don't do this unless your using a do loop.

while(true); //Always cause ZC to freeze with the exclusion of do loops.

A do loop? I didn't even know zscript had do-while, but how should that make a difference anyway?

#18 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 21 April 2014 - 12:22 PM

I tried putting a Waitdraw in an it says Waitdraw can only be called in an active global script.

Does someone have an example of a solid FFC?

Edited by anikom15, 21 April 2014 - 12:22 PM.


#19 Saffith

Saffith

    IPv7 user

  • Members

Posted 21 April 2014 - 01:05 PM

I made one a while ago. It's an FFC script, but easy enough to adapt.
The idea is that when Link steps onto an FFC, you can determine whether he moved vertically or horizontally based on the proportions of the intersecting rectangle (i.e. whether its width or height is greater) and reposition him accordingly.
 
// Set this to 1 if you're using the big Link hitbox, 0 if not.
const int SOLIDFFC_BIG_LINK = 0;

ffc script SolidFFC
{
    void run()
    {
        int hitboxAdjustment=0;
        float xOverlap;
        float yOverlap;
        if(SOLIDFFC_BIG_LINK==0)
            hitboxAdjustment=8;
        
        while(true)
        {
            if(Link->X+16>this->X && Link->X<this->X+16*this->TileWidth &&
               Link->Y+16>this->Y && Link->Y+hitboxAdjustment<this->Y+16*this->TileHeight)
            {
                if(Link->X<this->X)
                    xOverlap=Link->X+16-this->X;
                else
                    xOverlap=this->X+16*this->TileWidth-Link->X;
                
                if(Link->Y<this->Y)
                    yOverlap=Link->Y+16-this->Y;
                else
                    yOverlap=this->Y+16*this->TileHeight-(Link->Y+hitboxAdjustment);
                
                if(xOverlap<yOverlap)
                {
                    if(Link->X<this->X)
                        Link->X=this->X-16;
                    else
                        Link->X=this->X+16*this->TileWidth;
                }
                else
                {
                    if(Link->Y<this->Y)
                        Link->Y=this->Y-16;
                    else
                        Link->Y=this->Y+16*this->TileHeight-hitboxAdjustment;
                }
            }
            Waitframe();
        }
    }
}


#20 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 22 April 2014 - 08:29 AM

I love you Saffith, just marry me already damn it.

Ultimate-CZ-Platinum-over-Silver-Cubic-Z



#21 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 22 April 2014 - 10:49 PM

I tried it Saffith, and it doesn't seem to work any better than my procedure. Actually it has some weird behaviors, and Link still jitters.

#22 Saffith

Saffith

    IPv7 user

  • Members

Posted 22 April 2014 - 10:55 PM

Yeah, you'd have to change it to a function that runs after Waitdraw.

#23 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 22 April 2014 - 11:12 PM

So I am going in circles here. How could I delay the ffc script until after waitdraw? I tried to use a signal, but since ffc's can't be stored in a global, I seem to have no way of passing the ffc to the global script.

#24 Saffith

Saffith

    IPv7 user

  • Members

Posted 22 April 2014 - 11:27 PM

I mean you'd have to change the whole thing to a function that checks each FFC every frame rather than an FFC script.

#25 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 22 April 2014 - 11:37 PM

I mean you'd have to change the whole thing to a function that checks each FFC every frame rather than an FFC script.

bVHmcrm.jpg



#26 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 23 April 2014 - 05:47 AM

You don't have to check them all, only the solid ones.
int globalSolidFFCs[32];
int gSolidFFCCount;

void MakeFFCSolidThisFrame(int ffcID)
{
  globalSolidFFCs[gSolidFFCCount]=ffcID;
  gSolidFFCCount++;
}

void DoSolidFFCs()
{
  ffc f;
  for(int i=0;i<gSolidFFCCount;++i) {
    f = Screen->LoadFFC(globalSolidFFCs[i]);
    SolidFFC(f);
  }
  gSolidFFCCount = 0; //reset
}
Simply call "MakeFFCSolidThisFrame()" from the ffc script, and "DoSolidFFCs()" from the global script. "SolidFFC" is simply the function that Saffith posted as a global function that takes the ffc as an argument instead of an ffc script.

With this setup all FFCs can be mad solid at will with a single function from any other script.

Improvement: I can't remember if you can make an ffc array global or not. If so just make the array hold ffc pointers instead of ids.


On the topic of pixel rendering that is not quite right: This can actually be tested by disabling blending, setting all Matrix transformations to Identity and creating a projection that maps all texels to pixels with a ratio of 1:1 (eg; orthographic). If you were to draw a repeating 16x16 image, treating the screen as a 16x16 grid of tiles, using rectangle coordinates of x,y,+15,+15, there would be single pixel gaps between them, and rightfully so. What's worse is you would be 'smooshing' 16 pixels worth of texels into 15 pixels worth of space which would look very bad. Even if you tried using a translation between 0..1 it would still look bad even at 0.5.

#27 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 23 April 2014 - 11:06 AM

I've run into my fair share of problems because of Waitdraw() placement. I think that we could use a good tutorial on when, how, and why to implement things either before, or after, Waitdraw().

Do you think you might be up to that Zecora?

 

Sure, I'll work on it once I get home.



#28 anikom15

anikom15

    Dictator

  • Banned
  • Real Name:Westley
  • Location:California, United States

Posted 23 April 2014 - 11:31 AM

On the topic of pixel rendering that is not quite right: This can actually be tested by disabling blending, setting all Matrix transformations to Identity and creating a projection that maps all texels to pixels with a ratio of 1:1 (eg; orthographic). If you were to draw a repeating 16x16 image, treating the screen as a 16x16 grid of tiles, using rectangle coordinates of x,y,+15,+15, there would be single pixel gaps between them, and rightfully so. What's worse is you would be 'smooshing' 16 pixels worth of texels into 15 pixels worth of space which would look very bad. Even if you tried using a translation between 0..1 it would still look bad even at 0.5.


In that case you are using a different model for drawing. You are now specifying points (i.e. the cartesian coordinates of a surface) as opposed to pixels directly. OpenGL or any 3D system uses points which makes sense in that context, but in traditional 2D rendering (that is, before 3D cards and in the case of Allegro, SDL, etc.) graphics are drawn by the pixel in the manner I described earlier.

Edited by anikom15, 23 April 2014 - 11:33 AM.


#29 Mero

Mero

    Touch Fluffy Tail

  • Banned
  • Real Name:Tamamo No Mae
  • Location:Rainbow Factory

Posted 24 April 2014 - 09:19 AM

I believe Gleeok was talking about Pixel Rendering in the case of modern libraries not ZC itself. Also I'm currently swamped and will not be able to write a tutorial on Waitdraw for some time. Sorry guys :(



#30 ZeldaPlayer

ZeldaPlayer

    What's up my playas

  • Members
  • Location:USA

Posted 03 June 2014 - 06:19 PM

Moosh used Solid FFCs in his Link's Quest for the Hookshot 2. It's actually a creative thing to use.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users