All Projects → bitdotgames → bhl

bitdotgames / bhl

Licence: other
bhl is a strictly typed programming language specifically tailored for gameplay logic scripting.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to bhl

SparForte
Bourne shell, template engine, scripting language mission-critical, scalable projects. Based a ISO standard proven effective for large, mission-critical projects, SparForte is designed for fast development while, at the same time, providing easier designing, maintenance and bug removal. About 120.000 lines of code.
Stars: ✭ 47 (+135%)
Mutual labels:  interpreted-programming-language, strongly-typed
QuietVR
A Quiet Place in VR: Generate any 3D object with your voice. It's magic!
Stars: ✭ 17 (-15%)
Mutual labels:  unity-3d
cepathfind
a path find for tilebase game in unity
Stars: ✭ 30 (+50%)
Mutual labels:  unity-3d
metrica-plugin-unity
Unity plugin for Yandex AppMetrica SDK
Stars: ✭ 24 (+20%)
Mutual labels:  unity-3d
Unity3D-Cars
A project built for a Renaissance Coders tutorial to introduce vehicle physics.
Stars: ✭ 60 (+200%)
Mutual labels:  unity-3d
UnityGlobalTextSystem
Allow the user to 'change' the default font in Unity from "Arial" to a font of their liking.
Stars: ✭ 21 (+5%)
Mutual labels:  unity-3d
GuneyOzsanOutThereMusicVideo
Procedurally generated, real-time, demoscene style, open source music video made with Unity 3D for Out There by Guney Ozsan.
Stars: ✭ 26 (+30%)
Mutual labels:  unity-3d
Velocity
Weird jumping game
Stars: ✭ 32 (+60%)
Mutual labels:  unity-3d
Mage
Mage is a 3D Game Engine, built on top of THREE.js. It features Unity-like scripting, AMMO.js powered physics workers, an Infernojs powered UI and a clean API. Under (very) active development.
Stars: ✭ 76 (+280%)
Mutual labels:  unity-3d
graphql-ts-client
Typescript DSL for GraphQL.
Stars: ✭ 124 (+520%)
Mutual labels:  strongly-typed
UnityGameTemplate
Template with all necessary stuff taken care, just create your games main features.
Stars: ✭ 221 (+1005%)
Mutual labels:  unity-3d
WebsocketPromisify
Makes websocket's API just like REST with Promise-like API, with native Promises.
Stars: ✭ 18 (-10%)
Mutual labels:  strongly-typed
Own-Programming-Language-Tutorial
Репозиторий курса "Как создать свой язык программирования"
Stars: ✭ 95 (+375%)
Mutual labels:  interpreted-programming-language
TanksNetworkingInAzure
Tanks Networking demo project from Unity Store that can be deployed in Azure Cloud and scaled using Kubernetes
Stars: ✭ 20 (+0%)
Mutual labels:  unity-3d
strong type
C++ implementation of strong types
Stars: ✭ 46 (+130%)
Mutual labels:  strongly-typed
ImpossibleOdds-TacticalCamera
Camera system for tactical world overviews in Unity games.
Stars: ✭ 14 (-30%)
Mutual labels:  unity-3d
Streaming Map Demo
Demo of Streaming Binary Data format in a Unity Application for Streaming Maps in realtime
Stars: ✭ 24 (+20%)
Mutual labels:  unity-3d
streamdeck-unity
Enables Stream Deck integration with Unity.
Stars: ✭ 22 (+10%)
Mutual labels:  unity-3d
com.unity.netcode.gameobjects
Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
Stars: ✭ 1,678 (+8290%)
Mutual labels:  unity-3d
Game-Assets-And-Resources
Free and paid game assets and game resources for 2D games, 3D games, mobile games, Steam games, Unity games, and other games.
Stars: ✭ 164 (+720%)
Mutual labels:  unity-3d

BeHavior Language

CI

bhl is a strictly typed programming language specifically tailored for gameplay logic scripting. It combines Behaviour Trees(BT) primitives with familiar imperative coding style.

First time it was presented at the nucl.ai conference in 2016. Here's the presentation slides.

Please note that bhl is in alpha state and currently targets only C# platform. Nonetheless it has been battle tested in the real world projects and heavily used by BIT.GAMES for mobile games development built with Unity.

bhl features

  • ANTLR based: C# frontend + C# interpreting backend
  • Statically typed
  • Built-in support for pseudo parallel code orchestration
  • Golang alike defer
  • Basic types: float, int, bool, string, enums, arrays, classes
  • Supports imperative style control constructs: if/else, while, break, return
  • Allows user defined: functions, lambdas, classes
  • Supports C# bindings to user types and functions
  • Passing arguments to function by ref like in C#
  • Multiple returned values like in Golang
  • Hot code reload
  • Strict control over memory allocations

Quick example

func GoToTarget(Unit u, Unit t) {
  NavPath path
  defer {
    PathRelease(path)
  }
  
  paral {
   yield while(!IsDead(u) && !IsDead(t) && !IsInRange(u, t))
   
   {
     path = FindPathTo(u, t)
     Wait(1)
   }
   
   {
     FollowPath(u, path)
   }
}

Code samples

Structs

class Color3 {
  float r
  float g
  float b
}

class Color4 : Color3 {
  float a
}

Color4 c = {}
c.r = 0.9
c.g = 0.5
c.b = 0.7
c.a = 1.0

Enums

enum Status {
  None       = 0
  Connecting = 1
  Connected  = 2
}

Status s = Status.Connected

Generic initializers

class Vec3 {
  float x
  float y
  float z
}

Vec3[] vs = [{x: 10}, {y: 100, z: 100}, {y: 1}]

Passing by ref

Unit FindTarget(Unit self, ref float dist_to_target) {
...
  dist_to_target = u.position.Sub(self.position).length
  return u
}

float dist_to_target = 0
Unit u = FindTarget(self, ref dist_to_target)

Multiple returned values

Unit,float FindTarget(Unit self) {
...
  float dist_to_target = u.position.Sub(self.position).length
  return u,dist_to_target
}

Unit u,float dist_to_target = FindTarget(self)

Closures

Unit u = FindTarget()
float distance = 4
u.InjectScript(func() {
  paral_all {
    PushBack(distance: distance)
    Stun(time: 0.4, intensity: 0.15)
  }
})

Function pointers

func bool(int) p = func bool(int b) { return b > 1 }
return p(10)

defer support

{
  RimColorSet(color: {r:  0.65, a: 1.0}, power: 1.1)
  defer { RimColorSet(color: {a: 0}, power: 0) }
     ... 
}

Pseudo parallel code execution

func Attack(Unit u) {
  Unit t = TargetInRange(u)
  Check(t != null)
  paral_all {
   PlayAnim(u, trigger: "Attack")
   SoundPlay(u, sound: "Swoosh")
   seq {
     WaitAnimEvent(u, event: "Hit")
     SoundPlay(u, sound: "Damage")
     HitTarget(u, t, damage: RandRange(1,16))
  }
}

Example of some unit's top behavior

func Selector([]func bool() fns) {
  foreach(func bool() fn in fns) {
    if(!fn()) {
      continue
    } else {
      break
    }
  }
}

func UnitScript(Unit u) {
  while(true) {
    paral {
      WaitStateChanged(u)
      Selector(
            [
              func bool() { return FindTarget(u) },
              func bool() { return AttackTarget(u) },
              func bool() { return Idle(u) }
            ]
       )
    }
    yield()
  }
}

Architecture

bhl architecture

bhl utilizes a standard interpreter architecture with a frontend and a backend. Frontend is responsible for reading input files, static type checking and bytecode generation. Binary bytecode is post-processed and optimized in a separate stage. Processed byte code can be used by the backend. Backend is a interpreter responsible for runtime bytecode evaluation. Backend can be nicely integrated with Unity.

Frontend

In order to use the frontend you can use the bhl tool which ships with the code. See the quick build example below for instructions.

Backend

Before using the backend you have to compile the bhl_back.dll and somehow integrate it into your build pipeline. See the quick build example below for instructions.

Quick build example

Currently bhl assumes that you have mono installed and its binaries are in your PATH.

In the example directory you can find a simple illustration of gluing together frontend and backend.

Just try running run.sh script:

cd example && ./run.sh

This example executes the following simple script

Unit starts...
No target in range
Idling 3 sec...
State changed!
Idle interrupted!
Found new target 703! Approaching it.
Attacking target 703
Target 703 is dead!
Found new target 666! Approaching it.
State changed!
Found new target 902! Approaching it.
...

Please note that while bhl works fine under Windows the example assumes you are using *nix platform.

Unity engine integration

The example script has also a special Unity compatibility mode. It illustrates how you can build a bhl backend dll (bhl_back.dll) for Unity. After that you can put it into Assets/Plugins directory and use bhl for your Unity game development. You can run the example script in this mode just as follows:

cd example && ./run.sh -unity

Building

bhl comes with its own simple build tool bhl. bhl tool is written in C# and should work just fine both on *nix and Windows platforms.

It allows you to build frontend dll, backend dll, compile bhl sources into a binary, run unit tests etc.

You can view all available build tasks with the following command:

$ bhl help

Tests

For now there is no any documentation for bhl except presentation slides. However, there are many unit tests which cover all bhl features.

You can run unit tests by executing the following command:

$ bhl test

Roadmap

Version 3.0

  1. Generics support
  2. More optimal byte code
  3. More optimal runtime memory storage layout

Version 2.0

  1. Byte code optimization
  2. More optimal executor (VM)
  3. Better runtime errors reporting
  4. More robust type system
  5. User class methods
  6. Interfaces support
  7. Namespaces support
  8. Polymorphic class methods
  9. Nested classes
  10. Nested in classes enums
  11. Static class members support
  12. Variadic function arguments
  13. Maps support
  14. Implicit variable types using 'var'
  15. Debugger support
  16. LSP integration

Version 1.0

  1. ref semantics similar to C#
  2. Generic functors support
  3. Generic initializers
  4. Multiple return values support
  5. while syntax sugar: for(...) {} support
  6. while syntax sugar: foreach(...) {} support
  7. Ternary operator support
  8. User defined structs
  9. User defined enums
  10. Postfix increment/decrement
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].