Pages: 1 2 »
  Print  
Author Topic: move_wrap  (Read 25855 times)
Offline (Male) polygone
Posted on: February 28, 2011, 05:47:52 am

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
Code: (C++) [Select]
void move_wrap(bool hor, bool vert, double margin)
{
  enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst);
  if (hor)
  {
    const double wdis = room_width + margin*2;
    if (inst->x < -margin)
    {
      inst->x += wdis*ceil(((-margin) - inst->x)/wdis);
    }
    if (inst->x > room_width + margin)
    {
      inst->x -= wdis*ceil((inst->x - (room_width + margin))/wdis);
    }
  }
  if (vert)
  {
    const double hdis = room_height + margin*2;
    if (inst->y < -margin)
    {
      inst->y += hdis*ceil(((-margin) - inst->y)/hdis);
    }
    if (inst->y > room_height + margin)
    {
      inst->y -= hdis*ceil((inst->y - (room_height + margin))/hdis);
    }
  }
}
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Post made March 01, 2011, 09:47:03 am was deleted at the author's request.
Offline (Male) polygone
Reply #2 Posted on: March 01, 2011, 01:32:01 pm

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
I. Did. This. One. FFS.

And more efficiently.

Code: (Something that looks like C++ and is easily portable) [Select]
//int move_wrap(double hor,double vert,double margin)
int move_wrap(double hor,double vert,double margin) {
  //not sure whether two IFs are faster than one big calculation in a single IF
  if (hor) {
    if (X < -margin || X > room_width+margin) {
      X = -(X-room_width);
    }
  }
  if (vert) {
    if (Y < -margin || Y > room_height+margin) {
      Y = -(Y-room_height);
    }
  }
  return (int)0;
}

Since Josh fails to remember or care (<_<), I post this code.
a) That's not more efficient, it's different. And by being different it does not behave how the function behaves in GM. I don't just stick shit into code randomly :)
b) It's not written properly. Wtf are X and Y going to do?
« Last Edit: March 01, 2011, 03:04:23 pm by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) RetroX
Reply #3 Posted on: March 01, 2011, 10:44:47 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Dear Fede-lasse,

Please do not complain that you have already done functions when you posted them months ago and we don't know where they are.

If you wish to have them actually looked at, please post them or point out where you posted them.

Sincerely,
RetroX and everyone else.

P.S.: (int)0 is redundant because 0 is an int, and it would have been auto-casted either way.
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Post made March 06, 2011, 03:05:42 pm was deleted at the author's request.
Offline (Male) polygone
Reply #5 Posted on: March 06, 2011, 03:10:19 pm

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
I never said it was less efficient, I said it was different. My code is 'less efficient' for a reason: because it works better.
Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Post made March 08, 2011, 03:54:57 am was deleted at the author's request.
Offline (Male) polygone
Reply #7 Posted on: March 08, 2011, 05:34:48 am

Contributor
Location: England
Joined: Mar 2009
Posts: 794

View Profile
My version mimics the behaviour in GM, so I don't see the problem.
It doesn't mimic the behaviour in GM. Try moving an instance's x position 3*room_width and see if it wraps correctly using your code. If you actually read what code I use you will see I am specifically catering for this.

Though actually my code doesn't completely mimic GM's, it in fact works better. I believe GM's code goes more like this:

Code: [Select]
  if (hor)
  {
    const double wdis = room_width + margin*2;
    if (inst->x > room_width + margin)
    {
      inst->x -= wdis*ceil((inst->x - (room_width + margin))/wdis);
    }
    else if (inst->x < -margin)
    {
      inst->x += wdis*ceil(((-margin) - inst->x)/wdis);
    }
  }
  if (vert)
  {
    const double hdis = room_height + margin*2;
    if (inst->y > room_height + margin)
    {
      inst->y -= hdis*ceil((inst->y - (room_height + margin))/hdis);
    }
    else if (inst->y < -margin)
    {
      inst->y += hdis*ceil(((-margin) - inst->y)/hdis);
    }
This means that when the margin is set to a high negative value, ie more than half the room_width or something and both if statements are true it doesn't actually wrap and just moves the instance continuously left/up. By leaving the else out it wraps correctly mirrored which is a better way to handle things.
« Last Edit: March 08, 2011, 05:38:52 am by polygone » Logged
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
Offline (Male) RetroX
Reply #8 Posted on: March 08, 2011, 04:09:56 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Also @Retro, I once sent Josh all the functions I had done. He probably forgot about them.
Josh != everyone else
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Post made March 09, 2011, 09:14:31 am was deleted at the author's request.
Offline (Male) RetroX
Reply #10 Posted on: March 09, 2011, 06:51:19 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Also @Retro, I once sent Josh all the functions I had done. He probably forgot about them.
Josh != everyone else
Sincerely,
RetroX and everyone else.
Yes, thank you for enforcing my point.  Please post them if you want them to be reviewed by everyone else.
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Post made March 10, 2011, 11:40:42 am was deleted at the author's request.
Offline (Male) RetroX
Reply #12 Posted on: March 10, 2011, 08:50:11 pm

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
Also @Retro, I once sent Josh all the functions I had done. He probably forgot about them.
Josh != everyone else
Sincerely,
RetroX and everyone else.
Yes, thank you for enforcing my point.  Please post them if you want them to be reviewed by everyone else.
I didn't reinforce your point, silly. Your own post was against the point that you made. By saying "sincerely RetroX and everyone else," you say that no one but me knows of them. That is not true.

Either way, polygone seems more interested than I am in coding these functions.
Yes, and only you and Josh know.
Josh != everyone else
Logged
My Box: Phenom II 3.4GHz X4 | ASUS ATI RadeonHD 5770, 1GB GDDR5 RAM | 1x4GB DDR3 SRAM | Arch Linux, x86_64 (Cube) / Windows 7 x64 (Blob)
Quote from: Fede-lasse
Why do all the pro-Microsoft people have troll avatars? :(
Post made March 11, 2011, 05:18:24 am was deleted at the author's request.
Offline (Male) Josh @ Dreamland
Reply #14 Posted on: March 11, 2011, 09:01:49 am

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2950

View Profile Email
...
His point is, if you have functions, post them here. I'm not going to do anything with them, and no one else gives a shit about your functions unless they're posted here. So post them, or drop them.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Pages: 1 2 »
  Print