Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Simple updateAITasks question for entity


Frag
 Share

Recommended Posts

Hi guys,

 

is there any way to make sure that this call is not made on the entities when they are out of sight of the player ... or at a certain distance of any players.

 

It is just about saving CPU ...

 

Is there a check I can make inside that call to filter it out if my entity is far from any player?

Link to comment
Share on other sites

world.getClosestPlayer

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You could look at the existing AI functions.  AIWander I know turns off when the player is more than 32 blocks away.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I don't know that the AI actually turns off.    The logic within each AI task may check distance to the player, but it still checks every tick I think.  In other words, by the time you check the distance you're already technically executing the AI!

 

I think the main thing is to simply make the AI do as little as possible when out of range.  So it will still run, you'll still have to check range, but then you can short circuit the execution to minimize processing.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

I don't know that the AI actually turns off.    The logic within each AI task may check distance to the player, but it still checks every tick I think.  In other words, by the time you check the distance you're already technically executing the AI!

 

I think the main thing is to simply make the AI do as little as possible when out of range.  So it will still run, you'll still have to check range, but then you can short circuit the execution to minimize processing.

 

Yeah I thought about that, but I was just wondering if searching for player proximity at every tick for every entity would eat to much CPU instead of just executing the AI ...

 

I could this this, but I wanted to know from the guys who do a lot of creature in their mod (like mo's creature or something) how they handled this.

 

I wanted to make sure I was not missing a standard way to turn of the AI ...

Link to comment
Share on other sites

Like I said, it is a tradeoff.  By the time you check to see if the entity is in distance to enable/disable the AI, you're already doing some processing.

 

On a modern computer, only really crazy stuff can cause performance hits.  Think about all the checks that Minecraft is already doing every tick.  Most mods are just a drop in the bucket.

 

Note that I think you can set entities to despawn if they're out of range for a long time, and the chunk loading and unloading also help manage the overall active portion of the world.  This is the way Minecraft naturally ensures there isn't unlimited entities.

 

In my experience, while it is good to be sensitive to performance issues you only really need to get fancy if you find an actual performance issue.  Performance issues usually have a Pareto distribution, meaning that a couple issues usually cause >80% of the problem.  So just spend time on those issues, and usually you can only identify the worst offenders after you've tried it out.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Like I said, it is a tradeoff.  By the time you check to see if the entity is in distance to enable/disable the AI, you're already doing some processing.

 

On a modern computer, only really crazy stuff can cause performance hits.  Think about all the checks that Minecraft is already doing every tick.  Most mods are just a drop in the bucket.

 

Note that I think you can set entities to despawn if they're out of range for a long time, and the chunk loading and unloading also help manage the overall active portion of the world.  This is the way Minecraft naturally ensures there isn't unlimited entities.

 

In my experience, while it is good to be sensitive to performance issues you only really need to get fancy if you find an actual performance issue.  Performance issues usually have a Pareto distribution, meaning that a couple issues usually cause >80% of the problem.  So just spend time on those issues, and usually you can only identify the worst offenders after you've tried it out.

 

Thanks Jabelar,

 

very good answer here. I will just check the distance from the players. As you said, I doubt that it will kill the CPU. I will try both and do some perfmon measurement. So I will sleep better ;)

 

Thanks for the help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.