hkzorman / advanced_npc

Advanced NPC for Minetest, using mobs_redo API
Other
18 stars 5 forks source link

Unify action/tasks into Execution API #44

Closed hkzorman closed 6 years ago

hkzorman commented 6 years ago

This PR is a complete re-write of the actions/tasks functionality into the Execution API.

The API follows a simple OS-based model where tasks performed by NPCs are encapsulated in the concepts of instructions and programs. Instructions are "small", "atomic" actions performed by a NPC (like rotating, standing, etc.) and programs are a "collection" of instructions with logic on what to execute and what not (for example, walking to a specific position). The NPC executes different programs in order to be able to perform tasks (e.g. going to sleep on a bed).

The execution environment of Advanced NPC is based on processes, which are instances of a program. Processes have an internal instruction queue and execution context for storing variables; they can be interrupted and their state upon interruption is stored for later restoration. Processes can also be enqueued into a process queue which is managed by a process scheduler (which runs roughly each second). The process scheduler has the responsibility of determining what is the next process to be executed.

hkzorman commented 6 years ago

@BrunoMine Have you found any further issues with the newest code? If not, I think I will merge this into master by tomorrow.

BrunoMine commented 6 years ago

I have not tested everything consistently, I'm running tests, I'll still go a little deeper in creating programs (I intend to do this now)and maybe improve documentation, but I think the most important part is okay.

hkzorman commented 6 years ago

Cool! I can postpone the merge until Sunday or Monday, that is fine!

To complete the OS metaphor, I have added timers and callbacks (wrapped in a Monitor API). Examples are in idle.lua

BrunoMine commented 6 years ago

Apparently these two problems persist. Pause the action queue when attacking lock the use of the bed Do you want to fix them before you merge it?

hkzorman commented 6 years ago

33 will be addressed in the near future. I intend to implement an attack program.

35 same goes for this, will address in near future, only idea I can come up with is to override the beds node to check for NPC usage.

hkzorman commented 6 years ago

@BrunoMine from this comment https://github.com/hkzorman/advanced_npc/pull/48#issuecomment-385223075 is then this good to merge?

hkzorman commented 6 years ago

The log cleanup is not complete but this can wait. Will merge this tomorrow.

BrunoMine commented 6 years ago

Yeah, sounds great.

hkzorman commented 6 years ago

Merged!