Pages: 1
  Print  
Author Topic: median[1..4] + action_set_gravity + action_move_contact  (Read 14218 times)
Offline (Unknown gender) YellowAfterlife
Posted on: April 23, 2011, 09:23:28 am

Member
Joined: Apr 2011
Posts: 4

View Profile
Code: [Select]
// Median functions @ mathhnc.cpp ; mathhnc.h
double median(double x)           { return x; }
double median(double x,double y)  { return fmin(x,y); }
double median(double x,double y,double z) { return x > y ? x > z ? y > z ? y : z : x : y > z ? x > z ? x : z : y; }
double median(double w,double x,double y,double z) { return w > x ? w > y ? w > z ? median(x,y,z) : median(w,x,y) : y > z ? median(w,x,z) : median(w,x,y) : x > y ? x > z ? median(w,y,z) : median(w,x,y) : y > z ? median(w,x,z) : median(w,x,y) }
// { D&D functions @ actions.h
#define itype enigma::object_planar* const
#define ithis ((enigma::object_planar*)enigma::instance_event_iterator->inst)
// Gravity action. Tested; works
inline void action_set_gravity(double d, double g) {
itype me = ithis;
if (argument_relative) {
me->gravity += g;
me->gravity_direction += d;
} else {
me->gravity = g;
me->gravity_direction = d;
}
}
// Move Contact Solid action. Concept, might not work as intended for <1 values
inline void action_move_contact(double d, double m, int o) {
itype me = ithis;
double pr = 1; // precision
double dx = lengthdir_x(pr, d);
double dy = lengthdir_y(pr, d);
for (int i = m; i > 0; i -= (m != -1 ? 1 : 0))
{
if (!(o > 0 ? place_free(me->x+dx, me->y+dy) : place_empty(me->x+dx, me->y+dy))) return;
me->x += dx;
me->y += dy;
}
}
// }
As mentioned, action_move_contact might not work exactly like in GM, but its clearly better than nothing.
Logged
Offline (Male) RetroX
Reply #1 Posted on: April 23, 2011, 10:26:45 am

Master of all things Linux
Contributor
Location: US
Joined: Apr 2008
Posts: 1055
MSN Messenger - classixretrox@gmail.com
View Profile Email
action_move_contact with your method is extremely inefficient for what could be done with it (however, identical to GM's), considering how it's faster to iteratively check distances between the object and the rectangles around it.  Much fewer calculations with that method, and fewer calculations means faster games.

I tried doing this once and failed, but you can try it out if you like:
http://enigma-dev.org/forums/index.php?topic=721.0

(read further into the topic for the latest attempts)
« Last Edit: April 23, 2011, 10:28:21 am by RetroX » 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? :(
Offline (Unknown gender) YellowAfterlife
Reply #2 Posted on: April 24, 2011, 10:48:07 am

Member
Joined: Apr 2011
Posts: 4

View Profile
While that method is more efficient and fast, it already causes troubles with implementation, and will cause a lot more problems once the 'pixel-perfect' collisions will be implemented (if they ever will be).
Logged
Pages: 1
  Print