Author |
Message |
Arnk Kilo Dylie Seasoned Helper
Age:36 Gender: Joined: Jul 14 2006 Posts: 108 Offline
|
Posted: Sat Jul 10, 2010 3:28 am Post subject: |
|
|
|
|
When you call EndFaked you should no longer be keeping the pointer anywhere.
|
|
Back to top |
|
|
JoWie Server Help Squatter
Gender: Joined: Feb 25 2004 Posts: 215 Offline
|
Posted: Sat Jul 10, 2010 7:11 am Post subject: |
|
|
|
|
CB_NEWPLAYER is right after a player gets allocated and right before the freeing
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sat Jul 10, 2010 4:32 pm Post subject: |
|
|
|
|
JoWie wrote: | CB_NEWPLAYER is right after a player gets allocated and right before the freeing |
i should have looked in player.h first right? lol -_-
thanks
Arnk Kilo Dylie wrote: | When you call EndFaked you should no longer be keeping the pointer anywhere. |
but what if its not me calling it? :P _________________ SSC Distension Owner
SSCU Trench Wars Developer
|
|
Back to top |
|
|
JoWie Server Help Squatter
Gender: Joined: Feb 25 2004 Posts: 215 Offline
|
Posted: Mon Jul 12, 2010 7:16 pm Post subject: |
|
|
|
|
Personally, I almost always watch for CB_NEWPLAYER when creating or dealing with fake players. It feels less error prone and I like playing with ?killfake
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 02, 2011 2:06 am Post subject: |
|
|
|
|
so im trying to move a fake player
it has a speed and thrust, which if i recall is pixels per 10s.
however, when placed in the middle of a square it currently moves to a corner as fast as it moves to a side.
//dt=change in time
//tp=target pos
//md=fake pos
while(dt)
{
dt--;
int dx=tp->position.x - md->pos.x;
int dy=tp->position.y - md->pos.y;
md->pos.xspeed+=(dx > md->thr) ? md->thr : dx;
md->pos.yspeed+=(dy > md->thr) ? md->thr : dy;
if(md->pos.xspeed > md->spd) md->pos.xspeed=md->spd;
if(md->pos.xspeed < -md->spd) md->pos.xspeed=-md->spd;
if(md->pos.yspeed > md->spd) md->pos.yspeed=md->spd;
if(md->pos.yspeed < -md->spd) md->pos.yspeed=-md->spd;
md->pos.x+=md->pos.xspeed;
md->pos.y+=md->pos.yspeed;
}
|
i am pretty bad at math, and i think i might be needing sin and cos somewhere, because the speed/time locus should be a circle and not a square
edit:
im thinking its something close to this: -oldcode-
edit2:
but now i think i might have it:
if(dx == 0) dx++;
double dir=atan(dy/dx);
md->pos.xspeed+=md->thr*sin(dir);
md->pos.yspeed-=md->thr*cos(dir);
int spd=sqrt(pow(md->pos.xspeed,2)+pow(md->pos.yspeed,2));
if(spd > md->spd)
{
int excess=spd-md->spd;
md->pos.xspeed-=excess*sin(dir);
md->pos.yspeed+=excess*cos(dir);
}
|
edit3:
but now it only moves up vertically :(
i think somethings wrong with atan?
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 02, 2011 8:05 am Post subject: |
|
|
|
|
That looks like an infinite loop. That can't be a good thing.
EDIT: look at atan2 if you're having trouble with atan. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 02, 2011 11:08 am Post subject: |
|
|
|
|
having dir=atan(dy/dx); or dir=atan2(dy,dx); both produce the same strange result where the bot circles me at an odd radius, so its probably very close to being correct
i know this is the last line i need to fix but i am terrible at math and have no idea how to fix it
Last edited by Cheese on Sun Jan 02, 2011 11:42 am, edited 1 time in total |
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 02, 2011 11:32 am Post subject: |
|
|
|
|
I'm rather unclear on what you're trying to accomplish.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Jan 02, 2011 12:54 pm Post subject: |
|
|
|
|
1) atan2 will work no matter in which quadrant the angle is (or if you prefer, no matter what's the sign of x and y)... i.e. if x is negative and y is positive, the angle output will be from pi/2 to pi. atan always returns an angle between -pi/2 and pi/2.
So you want to use atan2.
2)md->pos.xspeed+=md->thr*sin(dir);
md->pos.yspeed-=md->thr*cos(dir);
cos applies to x, and sin applies to y
3) just an optimization, but:
sqrt(pow(md->pos.xspeed,2)+pow(md->pos.yspeed,2))
should be
sqrt(md->pos.xspeed*md->pos.xspeed + md->pos.yspeed*md->pos.yspeed)
it's much more efficient
4) You can calculate the max speed in both x and y , instead of removing excess speed...
maxspeedx = <max ship speed> * cos(dir)
maxspeedy = <max ship speed> * sin(dir)
however... if the ship is going left, maxspeedx will be NEGATIVE, so you would need to check the absolute value to compare, probably... _________________ (Insert a bunch of dead links here)
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Jan 09, 2011 3:39 am Post subject: |
|
|
|
|
hmmm
setflag(int oldflag, int newflag)
{
oldstate |= newflag; //this is equivalent to: oldstate = oldsate|newflag;
}
clearflag(int oldflag, int newflag)
{
oldstate = oldstate & (~newflag);
}
|
i.e.
setflag(oldstate, STATE_A);
clearflag(oldstate, STATE_B);
OR
following the structure you have in your example:
setflags(int newflags, BOOL value) //falue is true to add flags, false to remove
{
if(value)
oldstate |= newflags; //or 'oldstate = (oldstate | newflags);'
else
oldstate = (oldstate & (~newflags));
}
|
And I suggest you define your flags in a typedef enum
Last edited by Samapico on Sun Jan 09, 2011 11:59 am, edited 1 time in total |
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 09, 2011 8:43 am Post subject: |
|
|
|
|
The "!" is a logical not, you want the "~" for bitwise not.
Set:
val |= flags;
Clear:
val &= ~flags;
I do this all the time for my work in embedded controllers. It's much more common to make two inline functions for set and clear than to make one function taking an option.
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Jan 09, 2011 12:00 pm Post subject: |
|
|
|
|
Dr Brain wrote: | The "!" is a logical not, you want the "~" for bitwise not.
| Oops, you're right... edited post to avoid confusion.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 09, 2011 2:27 pm Post subject: |
|
|
|
|
yay i was getting close :D
also, it looks like it will be able to do sending it a combination of flags added together?
or should they be &'d together?
Samapico wrote: | And I suggest you define your flags in a typedef enum |
why?
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 09, 2011 3:11 pm Post subject: |
|
|
|
|
Don't use + or &. You want |.
As far as I'm aware, an enum has no advantages over a define for flags and masks.
Last edited by Dr Brain on Sun Jan 09, 2011 3:13 pm, edited 1 time in total |
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sun Jan 09, 2011 3:11 pm Post subject: |
|
|
|
|
Well it depends on how you use them I guess, but you could have functions that take a 'somethingFlag' as an argument, or variables of type 'somethingFlag', which is more explicit than 'int'. Much like using BOOL is clearer than using ints, even though they're the same thing.
And you can set multiple flags at once if you call like: set(flag1 | flag2)
Or clear multiple flags the same way: clear(flag1 | flag2)
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Sun Jan 09, 2011 7:16 pm Post subject: |
|
|
|
|
You'll note that it says it doesn't help in C.
It doesn't hurt you, but like I said, there's no advantage.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Sun Jan 09, 2011 7:17 pm Post subject: |
|
|
|
|
meh i guess its just good practice anyways :<
|
|
Back to top |
|
|
Arnk Kilo Dylie Seasoned Helper
Age:36 Gender: Joined: Jul 14 2006 Posts: 108 Offline
|
Posted: Tue Jan 11, 2011 2:01 pm Post subject: |
|
|
|
|
Using enums in function declarations instead of ints tends to make certain python integration things more headachy ;)
Of course that never stopped me.
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Fri Jan 14, 2011 3:22 am Post subject: |
|
|
|
|
what might cause this?
scrn.png - 169.01 KB
File downloaded or viewed 173 time(s)
|
|
Back to top |
|
|
Dr Brain Flip-flopping like a wind surfer
Age:38 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Fri Jan 14, 2011 7:01 am Post subject: |
|
|
|
|
Posting all of your topics in a single thread.
Did you try recovering the database?
|
|
Back to top |
|
|
Cheese Wow Cheese is so helpful!
Joined: Mar 18 2007 Posts: 1017 Offline
|
Posted: Fri Jan 14, 2011 9:10 pm Post subject: |
|
|
|
|
how would i do that
it seems i am forced to do this, because now the module wont load
and i dont want to disable persist
been poking at this dbtool.exe
not seeing anything
|
|
Back to top |
|
|
Samapico No, these DO NOT look like penises, ok?
Joined: May 08 2003 Posts: 1252 Offline
|
Posted: Sat Jan 15, 2011 12:21 am Post subject: |
|
|
|
|
That green/black theme suggests you know how to get things done.
And if you don't, hack in from a public telephone.
|
|
Back to top |
|
|
|