sp_foo(bar, -1);
I was just thinking about how lame the "-1" method for retriving sprite properies is, and I wondered if anyone was thinking of adding some other method to any of these dink modification/rewrite projects.
You caught my attention. One thing, what does -1 do in Dink? It's not proper in C++ to return a negative integer.
Like Paul said, -1 returns a value. For example, like this:
int &sp_x = sp_x(¤t_sprite, -1);
would return the x-coordinate of the current sprite.
int &sp_x = sp_x(¤t_sprite, -1);
would return the x-coordinate of the current sprite.
Er, why the heck wouldn't you just do:
int &sp_x = sp_x(¤t_sprite);
int &sp_x = sp_x(¤t_sprite);
cause it requires you to set something, although -1 tells it to set itself to what it currently is. Afaik.
See? It's pretty wierd how it works now, isn't it? And the worst part is that means you can't set sprite most attributs to -1. And for some attributs, eg sp_mx and sp_my, -1 would be a perfectly reasonable value. The tricky thing would be keeping backwards compatable if you changed it (I think).
If I were going to do it (which I'm not) I'd probably do either of these:
1. Allow omiting the -1 but still treat is as a special value if the result of the sp command is being asigned to something [&x = sp_y(1, -1);] but if it's just used as a straight statment [sp_y(1, -1);] then really set it to -1.
2. Keep the sp commands for compatibility by add a new set of functions that work in a cleaner way.
If I were going to do it (which I'm not) I'd probably do either of these:
1. Allow omiting the -1 but still treat is as a special value if the result of the sp command is being asigned to something [&x = sp_y(1, -1);] but if it's just used as a straight statment [sp_y(1, -1);] then really set it to -1.
2. Keep the sp commands for compatibility by add a new set of functions that work in a cleaner way.
Merlin is the guy to talk to. I think that's a good idea. Keep old crappy commands for back.comp and create new one that rock! Give me an ATAN2 function too so I can make sprites automatically track Dink across the screen.
From the manual page for atan2:
ATAN2(3) Linux Programmer's Manual ATAN2(3)
NAME
atan2 - arc tangent function of two variables
SYNOPSIS
#include <math.h>
double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
DESCRIPTION
The atan2() function calculates the arc tangent of the two
variables x and y. It is similar to calculating the arc
tangent of y / x, except that the signs of both arguments
are used to determine the quadrant of the result.
RETURN VALUE
The atan2() function returns the result in radians, which
is between -PI and PI (inclusive).
ATAN2(3) Linux Programmer's Manual ATAN2(3)
NAME
atan2 - arc tangent function of two variables
SYNOPSIS
#include <math.h>
double atan2(double y, double x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
DESCRIPTION
The atan2() function calculates the arc tangent of the two
variables x and y. It is similar to calculating the arc
tangent of y / x, except that the signs of both arguments
are used to determine the quadrant of the result.
RETURN VALUE
The atan2() function returns the result in radians, which
is between -PI and PI (inclusive).