Jump to content
Eternal Lands Official Forums
Sign in to follow this  
crusadingknight

Getting your own actor confusion

Recommended Posts

I was just looking around in the source today, when I noticed that there are 3 ways to get the player character, each of which is used several times:

  1. your_actor - A pointer to the player actor, which is kept up-to-date.
  2. pf_get_our_actor - A wrapper which returns your_actor.
  3. get_actor_ptr_from_id(yourself) - Parse the whole actors list to find yourself.

Now, I can understand the first two, and using the last one to update the your_actor pointer, but why are counters.c (ln. 563) and gamewin.c (ln. 1426) using get_actor_ptr_from_id(yourself)? Wouldn't it be more standard (not to mention faster) to just call either of the first two methods for those?

Share this post


Link to post
Share on other sites

I was just looking around in the source today, when I noticed that there are 3 ways to get the player character, each of which is used several times:

  1. your_actor - A pointer to the player actor, which is kept up-to-date.
  2. pf_get_our_actor - A wrapper which returns your_actor.
  3. get_actor_ptr_from_id(yourself) - Parse the whole actors list to find yourself.

Now, I can understand the first two, and using the last one to update the your_actor pointer, but why are counters.c (ln. 563) and gamewin.c (ln. 1426) using get_actor_ptr_from_id(yourself)? Wouldn't it be more standard (not to mention faster) to just call either of the first two methods for those?

 

Yeah, indeed.

In the single player version of the game I am working at, I replaced all of them to just an id (not a pointer).

Share this post


Link to post
Share on other sites

Another thing I don't understand in counters.c is this:

void increment_death_counter(actor *a)
{
actor *me = get_actor_ptr_from_id(yourself);

if (!me || !me->async_fighting) {
	return;
}

if (a != me) {
	increment_kill_counter(me, a);
} else {
	actor *me, *them;
	me = a;

What's the point of that? Did I miss something important?

Share this post


Link to post
Share on other sites

I was just looking around in the source today, when I noticed that there are 3 ways to get the player character, each of which is used several times:

  1. your_actor - A pointer to the player actor, which is kept up-to-date.
  2. pf_get_our_actor - A wrapper which returns your_actor.
  3. get_actor_ptr_from_id(yourself) - Parse the whole actors list to find yourself.

Now, I can understand the first two, and using the last one to update the your_actor pointer, but why are counters.c (ln. 563) and gamewin.c (ln. 1426) using get_actor_ptr_from_id(yourself)? Wouldn't it be more standard (not to mention faster) to just call either of the first two methods for those?

 

I think I can explain this. pf_get_our_actor() used to parse the whole actors list too. Then someone wrote get_actor_ptr_from_id() because pf_get_our_actor() was only made available to pathfinder.c. Then your_actor was added and pf_get_our_actor was made a wrapper. Then I used get_actor_ptr_from_id() in counters.c because I didn't notice that your_actor (a much better way of doing it) was added.

 

*Whew*

 

Another thing I don't understand in counters.c is this:

void increment_death_counter(actor *a)
{
actor *me = get_actor_ptr_from_id(yourself);

if (!me || !me->async_fighting) {
	return;
}

if (a != me) {
	increment_kill_counter(me, a);
} else {
	actor *me, *them;
	me = a;

What's the point of that? Did I miss something important?

 

actor *me, *them;

should be

actor *them;

 

It's not a big problem though.

 

[Edit: maybe you meant something else? I can't see any other problems though.]

Edited by Bongo

Share this post


Link to post
Share on other sites

It's not a big problem though.

 

[Edit: maybe you meant something else? I can't see any other problems though.]

 

void increment_death_counter(actor *a)
{
actor *me = get_actor_ptr_from_id(yourself);

if (!me || !me->async_fighting) {
	return;
}

if (a != me) {
	increment_kill_counter(me, a);
} else {
	actor *me, *them;
	me = a;

 

The assertion a != me means that the else clause asserts a == me. The problem is, after asserting that a == me, it assigns me = a. :D Since me is already a, why make it a again?

Edited by crusadingknight

Share this post


Link to post
Share on other sites

It's not a big problem though.

 

[Edit: maybe you meant something else? I can't see any other problems though.]

 

void increment_death_counter(actor *a)
{
actor *me = get_actor_ptr_from_id(yourself);

if (!me || !me->async_fighting) {
	return;
}

if (a != me) {
	increment_kill_counter(me, a);
} else {
	actor *me, *them;
	me = a;

 

The assertion a != me means that the else clause asserts a == me. The problem is, after asserting that a == me, it assigns me = a. :D Since me is already a, why make it a again?

 

 

Ah, yes. :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×