|
polygone
|
|
Reply #16 Posted on: January 12, 2011, 12:34:30 pm |
|
|
Location: England Joined: Mar 2009
Posts: 794
|
Actually, I have no idea why the fuck Ism's implementation works. direction.rval.d is in degrees. Or at least it's supposed to be. There is the possibility that it is only in degrees when it is the last variable set.
Funny you said that to me when I mentioned it. But then Ism quite rightly pointed out that you were actually the one who used that code first: I'm actually too tired and lazy right now to do the trivial amount of text insertion required to put that to code. >.<
-sigh-
const double dir = ((enigma::object_planar*)enigma::instance_event_iterator->inst)->direction.dval = chosendirs[choices]; ((enigma::object_planar*)enigma::instance_event_iterator->inst)->speed.dval = chosendirs[choices] == -1 ? 0 : argspeed; hspeed.dval = speed.dval * cos(dir), vspeed.dval = speed.dval * sin(dir);
Assuming all the rest of your code is right, and that I'm remembering the name of my own class member correctly.
She doesn't know why the fuck it works either
|
|
« Last Edit: January 15, 2011, 07:10:57 am by polygone »
|
Logged
|
I honestly don't know wtf I'm talking about but hopefully I can muddle my way through.
|
|
|
MrGriggs
|
|
Reply #17 Posted on: January 14, 2011, 08:10:35 pm |
|
|
Joined: Dec 2010
Posts: 128
|
All of these make it run away from the position rather than move towards as it's supposed to. Here's a corrected version. void motion_set(double newdir, double newspd) { enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst); inst->direction.rval.d = newdir; inst->speed.rval.d = newspd; inst->hspeed.rval.d = newspd * cos(degtorad(newdir)); inst->vspeed.rval.d = -newspd * sin(degtorad(newdir)); }
inline void move_towards_point(double x, double y, double spd) { motion_set(point_direction( ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x, ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y, x,y),spd); }
void motion_add(double newdir, double newspd) { enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst); inst->hspeed.rval.d += newspd * cos(degtorad(newdir)); inst->vspeed.rval.d += newspd * sin(degtorad(newdir)); inst->direction.rval.d = point_direction(0, 0, inst->hspeed.rval.d, inst->vspeed.rval.d); inst->speed.rval.d = abs(hypot(inst->hspeed.rval.d, inst->vspeed.rval.d)); } "inst->vspeed.rval.d = -newspd * sin(degtorad(newdir));" making it negative corrects the issue.
|
|
|
Logged
|
|
|
|
|
IsmAvatar
|
|
Reply #19 Posted on: January 20, 2011, 02:05:35 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
When you introduce the inst variable, you shouldn't keep it inline anymore I don't think, and it's redundant to return void to a void returning function. Also, indentation. This would be more likely:
void move_point_stop(double x, double y, double spd) { enigma::object_planar* const inst = ((enigma::object_planar*)enigma::instance_event_iterator->inst); if (inst->x!=x || inst->y!=y) motion_set(point_direction(inst->x,inst->y,x,y),spd); } Or this:
inline void move_point_stop(double x, double y, double spd) { if (((enigma::object_planar*)enigma::instance_event_iterator->inst)->x!=x || ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y!=y) motion_set(point_direction( ((enigma::object_planar*)enigma::instance_event_iterator->inst)->x, ((enigma::object_planar*)enigma::instance_event_iterator->inst)->y, x,y),spd); } In addition, this doesn't stop when it has reached the point. It only ceases to set the motion. Recall that an object in motion continues to stay in motion until acted upon.
Append this prior to the last closing curly brace:
else ((enigma::object_planar*)enigma::instance_event_iterator->inst)->speed = 0; Or if you already have inst defined:
else inst->speed = 0;
|
|
« Last Edit: January 20, 2011, 02:08:44 pm by IsmAvatar »
|
Logged
|
|
|
|
|
Post made January 21, 2011, 10:44:44 am was deleted at the author's request.
|
|
|
Post made January 24, 2011, 09:50:10 am was deleted at the author's request.
|
|
IsmAvatar
|
|
Reply #26 Posted on: January 24, 2011, 12:13:44 pm |
|
|
LateralGM Developer
Location: Pennsylvania/USA Joined: Apr 2008
Posts: 877
|
I don't see a reason to disable motion_set while keeping move_towards_point. It seems to me that if you want to disable one, you'll want to disable the other as well (e.g. bulk removal of motion-related functions). That said, if you still wanted to disable motion_set but keep move_towards_point, you might be able to set motion_set to be private access, so that it's not visible to outside files (this might just be Java rubbing off on me)... but there's not much use in that, because the function is still there, it's just not visible anymore - in which case you might as well just keep the function and not use it. Point is, move_towards_point needs motion_set one way or the other, whether it's in a function called motion_set, or unrolled. The benefit of using motion_set is that it eliminates duplicate code.
|
|
|
Logged
|
|
|
|
RetroX
|
|
Reply #27 Posted on: January 24, 2011, 04:49:03 pm |
|
|
Master of all things Linux
Location: US Joined: Apr 2008
Posts: 1055
|
IsmAvatar - C++ doesn't allow setting access to globals. All globals are public. Only members of structs and classes can be set with access specifiers.
What could be done is merely not including the code for that header in the game, or just not linking the object. If the header provides a declaration and no implementation is provided, it will still compile as long as the function isn't being used. Alternatively, you can add these flags to the GCC: -fdata-sections -ffunction-sections which compiles everything into separate sections in the actual object, and: -Wl,-gc-sections which will remove unused sections from the program upon linking.
On that matter, for debugging purposes, it would be nice to be able to add -g -O0, which will provide C++ debugging symbols, which GDB can use. It's extraordinarily useful.
|
|
« Last Edit: January 24, 2011, 04:56:08 pm 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)Why do all the pro-Microsoft people have troll avatars?
|
|
|
Post made January 25, 2011, 04:54:29 am was deleted at the author's request.
|
|
|