Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Motion Sensor Component #22

Open
CoderCow opened this issue Oct 11, 2012 · 6 comments
Open

Motion Sensor Component #22

CoderCow opened this issue Oct 11, 2012 · 6 comments

Comments

@CoderCow
Copy link
Member

If a player, npc, mob comes into range, the component sends 1, if there are no more players closeby it sends 0.
I think the Crystal Ball would be a good sprite to represent this component.

Suggested Modifiers:
1 - The component will only react on players comming closeby.
2 - The component will only react on NPCs comming closeby.
3 - The component will only react on mobs comming closeby.

The range of the sensor should be configurable. Also, since this component can take up quite some performance for the checking, a limit per player should be configuable.

Though, I'm not sure on how useful this component will be in the end. Especially because this is quite a lot of work to implement.

@ghost ghost assigned CoderCow Oct 11, 2012
@Ijwu
Copy link
Collaborator

Ijwu commented Oct 11, 2012

Wouldn't this cause a large amount of work on the server? The motion sensor would have to constantly check each npc/player/mob to tell if they're within its range. The amount of entities to check could get ridiculously high.

@CoderCow
Copy link
Member Author

That depends on how tricky the implementation is.

Players, due to their "small" amount are not much to worry about in general. For the mobs/npcs (I like to differ them usually but they are technically all just NPCs - same array), their array is limited to 200 at most, so each Motion Sensor would actually have to iterate 200 NPCs which is not much at all.

Proably the best fitting hook here is GameUpdate with a frame counter, let's say we want Motion Sensors to update on every second.
I could easy peasy just let all Motion Sensors check the NPCs in range on every second, though if we had 10 Motion Sensors that would technically end up in 2000 iterations - that's still not much to worry about but it could become ugly with let's say 30 Sensors since they're all processed within one game frame - especially if we consider that there might be other plugins that might do some things on that frame.

So better to spread the performance over more than one frame, like checking NPCs 0-50 after the first 10 frames passed, 50-100 after the next 10 frames etc.
If even this really leads to performance lacks though, one could also pimp up the in-range check itself in several ways, like simply forming a rectangle on Motion Sensor placement, covering the ranges of ALL Motion Sensors (that do NPC checks at all) which are currently placed on the map, if an NPC is not even in this rectangle, it would already be unnecessary to iterate through the Sensors for that NPC at all. And there are more ways to boost performance, if necessary.

@zaqen
Copy link

zaqen commented Oct 15, 2012

Would it be possible to arrange it so that these sensors could be turned off and on by a timer next to it? So that it check every time the timer send a pulse and the pulse will pass once the mobs are cleared.

@CoderCow
Copy link
Member Author

Good idea, but this would indeed cause performance trouble.

@zaqen
Copy link

zaqen commented Oct 15, 2012

I might be wrong but i assumed that the sensor would sense NPCs in a larger area, lets say 50x10. Would tat cause a lot of performance issues? Because with this it's possible to make sort of a "tower defense" mode. I'm really exited about this working or not.

@CoderCow
Copy link
Member Author

The size of the area to check makes pretty much no difference in matter of performance.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants