Skip to content

velcrome/vvvv-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vvvv-Game

This pack is a framework for quickly patching and developing Behavior Trees in vvvv.

A central piece of this development is the Agent, a custom dynamic c# type.

Background

Conceived during development of commercial games this breed of Behavior Tree (BT) proved itself helpful when designing AIs competing against players (halo) or coexisting with the player(spore).

The AIs were called Autonomous Agents or short Agents. These BTs offered a similar freedom as HFSM (what vvvv can clumsily model as a patch of framedelayed Automata), but were a lot easier to modularize and kept stable even at more complex forms of behavior, in realtime and in teams of interacting Agents. Also, timed character motion could be streamlined with the Agents decisions and actions.

Alex J. Champandard has had nice overviews on them for quite some time. Björn Knafla has another good series on them.

This implementation strives to make game development in vvvv easier by providing a proper base for developing your own custom behavior nodes. It solves a lot of the challenges presented in this thread

To allow for all that high-level functionality, the framework is purley CPU-based, so do not expect the same scalability you might get from GPU based particle systems. Be smart about it, and use the GPU for gloss, and vvvv-Game for interactive and complex rule-based behavior.

Getting Started

Every BT starts at its root called Store (Game), because it stores all the Agents that inhabit the BT. You can add new Agents to it (for example with Birth (Game)), sniper individual Agents, and add behavior nodes.

The primary plan groups Selector ?, Sequence ?, Parallel ? are fully functional as compiled plugins. Depending on the Agent's ReturnCode, it might or might not traverse up a pin (every Agent always has its own way in the tree, thats why they called them autonomous).

There are plugin templates such as ActionTemplate (Game), ConditionTemplate (Game), DecoratorTemplate (Game) ?. If you feel like patching, you can clone TemplatePatch (Game).

Agent with many Faces

Each Agent basically has its own mind in this Game

It can be metaphored with a peculiar blackboard to scribble data freely on it, all to maintain its own physical state (int Health, Vector3Dd Position), its prior perception of the current world (Vector3D EnemyTarget, double DangerLevel) and its memory on decisions of what to strive for next (Vector3D[] PathToTarget, Time NextTimeToCheckForEnemies).

You can see the blackboard with ToString (object), ToString (Json) or Split (Agent), with Set (Agent) you can modify the properties. In good tradition with vvvv, any data you add as a property can be one or many items, taking full advantage of spreading. Possible items are basic types such as double, bool, int, float and string, but also more advanced ones like Raw, Color, Vector2D, Vector3D, Vector4D, Transform, and Time

In C# terms, Agent is a fully dynamic class. This means you can use c# to script really quick, if you are okay with loosing Code Completion and safe type handling.

The implemented Agent in this framework can adopt to any mask, or what I call a Face, from the very simple (just a name) to the almost physical (IGravityAgent). With vvvv you can apply a custom Face to any Agent during runtime. The agent stays the same dynamic, it is just the mask, the Face, and the mindset that comes with the mask. As with any good agent, you can reapply a new Face anytime you want, it is done in a blitz.

To make a new custom Face, simply clone TemplateFace (Game) with Ctrl + Shift + Enter and edit the provided interface. It must inherit IAgent to be found by the framework, but can inherit any number of other Faces, if you want to make use of ready-made modular functionality.

As a bonus you can also extend the skillset of the Agent by writing extension methods in your part of public static partial class AgentAPI

Best Practise

  1. Any complex behavior is only as good as the individual actions.
  2. When cloning save all your plugins in packs/vvvv-Game/Nodes/plugins and all patches in packs/vvvv-Game/Nodes/modules
  3. Test your actions thoroughly, and keep the test as a help patch to demonstrate its purpose in packs/vvvv-Game/Nodes/modules
  4. If you choose to patch your actions, use only stateless nodes between Pot and Lid. write potential states on the Agents blackboard. No Damper!
  5. Make use of Faces. It will shorten development time in the long run, give you code completion and compiler errors.
  6. If you make a bunch of plugins all relating to the same Face, start to make additions to AgentAPI whenever you duplicate code that relates to the Agent
  7. When you make a nice and modular set of behaviors, don't be shy to share.

Last Words about Graph Evaluation

While the multipurpose toolkit is a great way to enable rapid development of BTs, its node evaluation model does not allow for BTs directly. At this stage of development I tried to make the black box fit by making critical use of the Pin.Sync() method. Relevant spreads of Agents however get pushed into their children upwards, so there is no need for FrameDelay loops of values or even Agent instances within a tree.

It is a tree grown on the condition that a node's Evaluate() will not be called until the BehaviorLink pin is synced. This condition seems fulfilled, as long as plugins can be indefinitely prevented from being evaluated.

  1. all the plugins input pins should be on AutoValidate = false to prevent top-down evaluation.
  2. all their output pins should be on AutoFlush = false to maintain data integrity .
  3. Also the first Sync into the node should be the BehaviorLink pin.

Unfortuately BTs are upside down now (mathematically it does not matter at all, but now it feels more like a scene graph of behaviors than the flow of Agents I would have preferred).

This situation is not ideal, because it can create strange effects in more convoluted scenarios. However, there are potential rewrites that keep any custom node compatible. For example the framework could be made to traverse the tree in a separate thread (building up some kind of secondary shadow graphs) and doublebuffering the pins, which means the Debug View will not provide proper timings for the individual nodes. Or devvvvs add a possiblility to microcontrol the Evaluate() call. Anyway, for now I consider this pack a solid 0.9

Libraries

Additional external libraries are available via Nuget.org.

Impromptu-Interface under Apache License 2.0

for Duck Typing and Schönfinkeling

Json.NET under MIT License

for serializing Agents. Useful for saving Agents to disc.

License

CC 4.0BY NC SAt

Marko Ritter (www.intolight.de)

This software is distributed under the CC Attribution-NonCommercial-ShareAlike 4.0 license.

If you want to use it commercially or have any other reason why this license does not fit your need, write a quick email to license@intolight.de for a different license. Usually you will get away with either a flattr or a useful addition to the framework (Faces, API extensions, help patches, nodes, docu). This pack is for the community, really, and hand-crafted commercial work is a valued part of our community.

Of course intolight does provide official billing, too.

If your product contains parts of this framework and has an annual net revenue in excess of €100.000 (or any other currency, international exchange market rates apply) contact us immediately and please tell us more about the nature of your product so intolight can decide about licensing.

About

This pack is a framework for quickly patching and developing Behavior Trees in vvvv

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages