├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CONTRIBUTING ├── LICENSE ├── README ├── README.md ├── cmake └── find_fplutil.cmake ├── disttools ├── config.json └── push_package.py ├── docs ├── generate_docs.py └── src │ ├── api_reference.md │ ├── contributing.md │ ├── doxyfile │ ├── doxygen_layout.xml │ ├── groups │ ├── index.md │ └── programmers_guide │ ├── building │ ├── building.md │ ├── building_android.md │ ├── building_linux.md │ ├── building_osx.md │ └── building_windows.md │ ├── howto │ ├── events.md │ ├── graphs.md │ ├── modules.md │ └── nodes.md │ └── overview.md ├── include └── breadboard │ ├── base_node.h │ ├── event.h │ ├── graph.h │ ├── graph_factory.h │ ├── graph_state.h │ ├── log.h │ ├── memory_buffer.h │ ├── module.h │ ├── module_registry.h │ ├── modules │ ├── common.h │ ├── debug.h │ ├── logic.h │ ├── math.h │ └── string.h │ ├── node.h │ ├── node_arguments.h │ ├── node_signature.h │ ├── type.h │ ├── type_registry.h │ └── version.h ├── jni ├── Android.mk ├── Application.mk ├── android_config.mk └── find_fplutil.mk ├── module_library ├── include │ └── module_library │ │ ├── animation.h │ │ ├── audio.h │ │ ├── default_graph_factory.h │ │ ├── default_graph_factory.inc │ │ ├── entity.h │ │ ├── physics.h │ │ ├── rendermesh.h │ │ ├── transform.h │ │ └── vec.h ├── jni │ ├── Android.mk │ ├── Application.mk │ └── android_config.mk ├── schemas │ ├── common_modules.fbs │ ├── corgi_module.fbs │ ├── mathfu_module.fbs │ └── pindrop_module.fbs └── src │ ├── animation.cpp │ ├── audio.cpp │ ├── entity.cpp │ ├── physics.cpp │ ├── rendermesh.cpp │ ├── transform.cpp │ └── vec.cpp ├── samples ├── CMakeLists.txt ├── README_BUILDING.txt └── event_counter │ ├── AndroidManifest.xml │ ├── CMakeLists.txt │ ├── event_counter.cpp │ ├── jni │ ├── Android.mk │ └── Application.mk │ └── res │ └── values │ └── strings.xml └── src ├── breadboard ├── event.cpp ├── graph.cpp ├── graph_factory.cpp ├── graph_state.cpp ├── log.cpp ├── module.cpp ├── module_registry.cpp ├── node.cpp ├── node_arguments.cpp ├── node_signature.cpp ├── type_registry.cpp └── version.cpp └── modules ├── common.cpp ├── debug.cpp ├── logic.cpp ├── math.cpp └── string.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles/ 3 | Makefile 4 | assets/ 5 | bin/ 6 | cmake_install.cmake 7 | gen/ 8 | module_library/gen/ 9 | obj/ 10 | docs/html/ 11 | docs/linklint_results/ 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dependencies/vectorial"] 2 | path = dependencies/vectorial 3 | url = http://github.com/scoopr/vectorial.git 4 | [submodule "dependencies/mathfu"] 5 | path = dependencies/mathfu 6 | url = http://github.com/google/mathfu.git 7 | [submodule "dependencies/cardboard-java"] 8 | path = dependencies/cardboard-java 9 | url = https://github.com/googlesamples/cardboard-java 10 | [submodule "dependencies/motive"] 11 | path = dependencies/motive 12 | url = http://github.com/google/motive.git 13 | [submodule "dependencies/libvorbis"] 14 | path = dependencies/libvorbis 15 | url = https://git.xiph.org/mirrors/vorbis.git 16 | [submodule "dependencies/bulletphysics"] 17 | path = dependencies/bulletphysics 18 | url = http://github.com/bulletphysics/bullet3.git 19 | [submodule "dependencies/pindrop"] 20 | path = dependencies/pindrop 21 | url = http://github.com/google/pindrop.git 22 | [submodule "dependencies/sdl"] 23 | path = dependencies/sdl 24 | url = http://github.com/google/fplbase.git 25 | [submodule "dependencies/webp"] 26 | path = dependencies/webp 27 | url = https://chromium.googlesource.com/webm/libwebp 28 | [submodule "dependencies/corgi"] 29 | path = dependencies/corgi 30 | url = http://github.com/google/corgi.git 31 | [submodule "dependencies/libogg"] 32 | path = dependencies/libogg 33 | url = https://git.xiph.org/mirrors/ogg.git 34 | [submodule "dependencies/fplbase"] 35 | path = dependencies/fplbase 36 | url = http://github.com/google/fplbase.git 37 | [submodule "dependencies/sdl_mixer"] 38 | path = dependencies/sdl_mixer 39 | url = http://github.com/google/pindrop.git 40 | [submodule "dependencies/fplutil"] 41 | path = dependencies/fplutil 42 | url = http://github.com/google/fplutil.git 43 | [submodule "dependencies/flatbuffers"] 44 | path = dependencies/flatbuffers 45 | url = http://github.com/google/flatbuffers.git 46 | [submodule "dependencies/googletest"] 47 | path = dependencies/googletest 48 | url = http://github.com/google/googletest.git 49 | [submodule "dependencies/stb"] 50 | path = dependencies/stb 51 | url = https://github.com/nothings/stb.git 52 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Contributing {#contributing} 2 | ============ 3 | 4 | Want to contribute? Great! First, read this page (including the small print at 5 | the end). 6 | 7 | ### Before you contribute 8 | 9 | Before we can use your code, you must sign the 10 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1) 11 | (CLA), which you can do online. The CLA is necessary mainly because you own the 12 | copyright to your changes, even after your contribution becomes part of our 13 | codebase, so we need your permission to use and distribute your code. We also 14 | need to be sure of various other things—for instance that you'll tell us if you 15 | know that your code infringes on other people's patents. You don't have to sign 16 | the CLA until after you've submitted your code for review and a member has 17 | approved it, but you must do it before we can put your code into our codebase. 18 | Before you start working on a larger contribution, you should get in touch with 19 | us first through the issue tracker with your idea so that we can help out and 20 | possibly guide you. Coordinating up front makes it much easier to avoid 21 | frustration later on. 22 | 23 | ### Code reviews 24 | 25 | All submissions, including submissions by project members, require review. We 26 | use Github pull requests for this purpose. 27 | 28 | ### The small print 29 | 30 | Contributions made by corporations are covered by a different agreement than 31 | the one above, the Software Grant and Corporate Contributor License Agreement. 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Breadboard {#breadboard_readme} 2 | ========== 3 | 4 | ## Overview 5 | 6 | The Breadboard scripting library is a graph based scripting system designed with 7 | games in mind. Complex behvaiors for game entities can be organized by 8 | interlinking nodes representing game actions. 9 | 10 | ## Features 11 | 12 | * Graph based scripting: Set up complex game behaviors without needing to use 13 | code. Just arrange nodes in a graph and connect them together. 14 | * Extensible: Breadboard can be extended with user-defined Nodes that interact 15 | with your game 16 | * Cross-platform: Breadboard can be incorperated in to projects on all major 17 | platforms. 18 | 19 | ## Dependencies 20 | 21 | Breadboard depends on the following library: 22 | 23 | * [fplutil][] 24 | 25 | fplutil provides a number of useful utilities. Breadboard makes use of 26 | `fplutil::intrusive_list` internally to build lists to track various structures 27 | without doing unnecessary allocations. 28 | 29 | Additionally, Breadboard ships with some example Modules. These additional 30 | modules in the `module_library` folder depend on the following libraries: 31 | 32 | * [Bullet Physics][] 33 | * [CORGI][] 34 | * [Flatbuffers][] 35 | * [MathFu][] 36 | * [Pindrop][] 37 | 38 | These libraries are all optional and can be conditionally compiled based on 39 | your needs. See the options at the top of the root level CMakeLists.txt to see 40 | how to configure the module library to include just what you need. 41 | 42 | ## Notes 43 | 44 | For applications on Google Play that integrate this tool, usage is tracked. 45 | This tracking is done automatically using the embedded version string (see 46 | `src/breadboard/version.cpp`), and helps us continue to optimize it. Aside from 47 | consuming a few extra bytes in your application binary, it shouldn't affect your 48 | application at all. We use this information to let us know if Pindrop is useful 49 | and if we should continue to invest in it. Since this is open source, you are 50 | free to remove the version string but we would appreciate if you would leave it 51 | in. 52 | 53 | [Bullet Physics]: http://bulletphysics.org/ 54 | [CORGI]: http://google.github.io/corgi/ 55 | [fplutil]: http://google.github.io/fplutil/ 56 | [FlatBuffers]: http://google.github.io/flatbuffers/ 57 | [MathFu]: http://google.github.io/mathfu/ 58 | [Pindrop]: http://google.github.io/pindrop/ 59 | -------------------------------------------------------------------------------- /cmake/find_fplutil.cmake: -------------------------------------------------------------------------------- 1 | # Find the fplutil directory and set it in `fplutil_dir`. 2 | # 3 | # We search some standard locations, such as 4 | # (1) the cached variable ${dependencies_fplutil_dir}, which can be specified 5 | # on the command line, 6 | # cmake -Ddependencies_fplutil_dir=your_fplutil_directory 7 | # (2) under ${fpl_root}, which is another cached variable that can be 8 | # specified on the command line, 9 | # cmake -Dfpl_root=your_fpl_root_directory 10 | # (3) the "dependencies" directory that gets created when cloning from GitHub, 11 | # (4) several levels up in the directory tree. 12 | # 13 | # Notes 14 | # ----- 15 | # - fplutil is the project where we keep all our shared code, so the code in 16 | # this file (which locates fplutil) can unfortunately not be shared. 17 | # - Since this file is duplicated in all FPL projects (except fplutil itself), 18 | # please copy new versions to all FPL projects whenever you make a change. 19 | 20 | set(fplutil_dir_possibilities 21 | "${dependencies_fplutil_dir}" 22 | "${fpl_root}/fplutil" 23 | "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/fplutil" 24 | "${CMAKE_CURRENT_LIST_DIR}/../../fplutil" 25 | "${CMAKE_CURRENT_LIST_DIR}/../../../fplutil" 26 | "${CMAKE_CURRENT_LIST_DIR}/../../../../fplutil" 27 | "${CMAKE_CURRENT_LIST_DIR}/../../../../../fplutil") 28 | 29 | foreach(dir ${fplutil_dir_possibilities}) 30 | if(EXISTS ${dir}) 31 | set(fplutil_dir ${dir}) 32 | return() 33 | endif() 34 | endforeach(dir) 35 | 36 | # Define this cached variable so that cmake GUIs can expose it to the user. 37 | set(dependencies_fplutil_dir "" 38 | CACHE PATH "Directory containing the fplutil library.") 39 | 40 | MESSAGE(ERROR 41 | "Can't find fplutil directory. Try cmake -Ddependencies_fplutil_dir=your_location.") 42 | -------------------------------------------------------------------------------- /disttools/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "package": { 3 | "name": "breadboard", 4 | "url": "http://github.com/google/breadboard.git", 5 | "branch": "develop", 6 | "is_library": 1, 7 | "third_party": 0, 8 | "push": 1 9 | }, 10 | "dependencies": [ 11 | { 12 | "name": "fplutil", 13 | "url": "http://github.com/google/fplutil.git", 14 | "branch": "develop", 15 | "is_library": 1, 16 | "third_party": 0, 17 | "push": 0 18 | }, 19 | { 20 | "name": "flatbuffers", 21 | "url": "http://github.com/google/flatbuffers.git", 22 | "branch": "master", 23 | "is_library": 1, 24 | "third_party": 0, 25 | "push": 0 26 | }, 27 | { 28 | "name": "mathfu", 29 | "url": "http://github.com/google/mathfu.git", 30 | "branch": "develop", 31 | "is_library": 1, 32 | "third_party": 0, 33 | "push": 0, 34 | "fetch_dependencies": 1 35 | }, 36 | { 37 | "name": "motive", 38 | "url": "http://github.com/google/motive.git", 39 | "branch": "develop", 40 | "is_library": 1, 41 | "third_party": 0, 42 | "push": 0, 43 | "fetch_dependencies": 1 44 | }, 45 | { 46 | "name": "fplbase", 47 | "url": "http://github.com/google/fplbase.git", 48 | "branch": "develop", 49 | "is_library": 1, 50 | "third_party": 0, 51 | "push": 0, 52 | "fetch_dependencies": 1 53 | }, 54 | { 55 | "name": "pindrop", 56 | "url": "http://github.com/google/pindrop.git", 57 | "branch": "develop", 58 | "is_library": 1, 59 | "third_party": 0, 60 | "push": 0, 61 | "fetch_dependencies": 1 62 | }, 63 | { 64 | "name": "corgi", 65 | "url": "http://github.com/google/corgi.git", 66 | "branch": "develop", 67 | "is_library": 1, 68 | "third_party": 0, 69 | "push": 0, 70 | "fetch_dependencies": 1 71 | }, 72 | { 73 | "name": "bulletphysics", 74 | "url": "http://github.com/bulletphysics/bullet3.git", 75 | "branch": "master", 76 | "revision": "30ebb322285809bde98959e10e73e5acb9981efc", 77 | "is_library": 1, 78 | "third_party": 1, 79 | "push": 0 80 | } 81 | ] 82 | } 83 | -------------------------------------------------------------------------------- /disttools/push_package.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2015 Google Inc. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Push this project and its dependencies to another git repo. 17 | 18 | Uses fplutil/disttools/push_package.py to push the remote of 19 | this git repository and its dependencies (defined by config.json) 20 | to another git repository. 21 | """ 22 | 23 | import os 24 | import sys 25 | sys.path.extend(( 26 | os.path.realpath(os.path.join( 27 | os.path.dirname(__file__), os.path.pardir, 'dependencies', 'fplutil')), 28 | os.path.realpath(os.path.join( 29 | os.path.dirname(__file__), os.path.pardir, os.path.pardir, 30 | 'fplutil')))) 31 | import disttools.push_package # pylint: disable=g-import-not-at-top 32 | 33 | ## The directory containing this file. 34 | THIS_DIR = os.path.realpath(os.path.dirname(__file__)) 35 | 36 | ## Default root directory of the project. 37 | PROJECT_DIR = os.path.realpath(os.path.join(THIS_DIR, os.path.pardir)) 38 | 39 | ## Default package configuration file. 40 | CONFIG_JSON = os.path.realpath(os.path.join(THIS_DIR, 'config.json')) 41 | 42 | 43 | def main(): 44 | """See fplutil/disttools/push_package.py. 45 | 46 | Returns: 47 | 0 if successful, non-zero otherwise. 48 | """ 49 | return disttools.push_package.main(disttools.push_package.parse_arguments( 50 | project_dir=PROJECT_DIR, config_json=CONFIG_JSON)) 51 | 52 | 53 | if __name__ == '__main__': 54 | sys.exit(main()) 55 | -------------------------------------------------------------------------------- /docs/generate_docs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright 2014 Google Inc. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Generate html documentation from markdown and doxygen comments.""" 17 | 18 | import os 19 | import sys 20 | 21 | THIS_DIR = os.path.realpath(os.path.dirname(__file__)) 22 | PROJECT_DIR = os.path.realpath(os.path.join(THIS_DIR, os.pardir)) 23 | sys.path.extend( 24 | [os.path.realpath(os.path.join(PROJECT_DIR, os.pardir, 'fplutil')), 25 | os.path.realpath(os.path.join(PROJECT_DIR, 'dependencies', 'fplutil'))]) 26 | import docs # pylint: disable=C6204 27 | 28 | 29 | def main(): 30 | """Generate html documentation from markdown and doxygen comments. 31 | 32 | Returns: 33 | 0 if successful, 1 otherwise. 34 | """ 35 | sys.argv.extend(('--linklint-dir', THIS_DIR, 36 | '--source-dir', os.path.join(THIS_DIR, 'src'), 37 | '--project-dir', PROJECT_DIR)) 38 | return docs.generate_docs.main() 39 | 40 | if __name__ == '__main__': 41 | sys.exit(main()) 42 | -------------------------------------------------------------------------------- /docs/src/api_reference.md: -------------------------------------------------------------------------------- 1 | API Reference {#breadboard_api_reference} 2 | ============= 3 | 4 | This document describes all classes, functions, macros and files that make 5 | up the [Breadboard][] library. This is intended to be used as a reference for 6 | C++ programmers who have made themselves familiar with the 7 | [Programmer's Guide][]. 8 | 9 | [Breadboard]: @ref breadboard_index 10 | [Programmer's Guide]: @ref breadboard_guide_overview 11 | -------------------------------------------------------------------------------- /docs/src/contributing.md: -------------------------------------------------------------------------------- 1 | ../../CONTRIBUTING -------------------------------------------------------------------------------- /docs/src/doxygen_layout.xml: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 20 | 21 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | -------------------------------------------------------------------------------- /docs/src/groups: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/breadboard/45537cea0d6cdee70ed91d86cc6114465c351325/docs/src/groups -------------------------------------------------------------------------------- /docs/src/index.md: -------------------------------------------------------------------------------- 1 | Breadboard {#breadboard_index} 2 | ========== 3 | 4 | [Breadboard][] is a scripting system designed to be easy to use for both 5 | programmers and game designers. Once a library of nodes has been defined, anyone 6 | can take those nodes and connect them together to form more complex behaviors 7 | for their game. 8 | 9 | ## Features 10 | 11 | * Graph based scripting: Set up complex game behaviors without needing to use 12 | code. Just arrange nodes in a graph and connect them together. 13 | * Extensible: Breadboard can be extended with user-defined Nodes that interact 14 | with your game 15 | * Cross-platform: Breadboard can be incoperated in to projects on all major 16 | platforms. 17 | 18 | ## Dependencies 19 | 20 | Breadboard depends on the following libraries: 21 | 22 | * [FPLUtil][] 23 | 24 | Additionally, Breadboard ships with some example Modules. These additional 25 | modules in the `module_library` folder depend on the following libraries: 26 | 27 | * [Bullet Physics][] 28 | * [CORGI][] 29 | * [Flatbuffers][] 30 | * [Mathfu][] 31 | * [Pindrop][] 32 | 33 | ## Download 34 | 35 | [Breadboard][] can be downloaded from: 36 | 37 | * [GitHub][] (source) 38 | * [GitHub Releases Page][] (source) 39 | 40 | **Important**: Breadboard uses submodules to reference other components it 41 | depends upon, so download the source from [GitHub][] using: 42 | 43 | ~~~{.sh} 44 | git clone --recursive https://github.com/google/breadboard.git 45 | ~~~ 46 | 47 | ## Feedback and Reporting Bugs 48 | 49 | * Discuss Breadboard with other developers and users on the 50 | [Breadboard Google Group][]. 51 | * File issues on the [Breadboard Issues Tracker][]. 52 | * Post your questions to [stackoverflow.com][] with a mention of 53 | **fpl breadboard**. 54 | 55 |
56 | 57 | [Breadboard]: http://github.com/google/breadboard 58 | [Breadboard Google Group]: http://groups.google.com/group/breadboard-scripting 59 | [Breadboard Issues Tracker]: http://github.com/google/breadboard/issues 60 | [Bullet Physics]: http://bulletphysics.org/ 61 | [CORGI]: http://google.github.io/corgi/ 62 | [FPLUtil]: http://google.github.io/fplutil/ 63 | [FlatBuffers]: http://google.github.io/flatbuffers/ 64 | [GitHub Releases Page]: http://github.com/google/breadboard/releases 65 | [GitHub]: http://github.com/google/breadboard 66 | [Mathfu]: http://google.github.io/mathfu/ 67 | [Pindrop]: http://google.github.io/pindrop/ 68 | [stackoverflow.com]: http://stackoverflow.com/search?q=fpl+breadboard 69 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/building/building.md: -------------------------------------------------------------------------------- 1 | Building {#breadboard_guide_building} 2 | ======== 3 | 4 | Developers can build the library from source for [Android][], [Linux][], 5 | [OS X][] and [Windows][]. 6 | 7 | * [Building for Android][] 8 | * [Building for Linux][] 9 | * [Building for OS X][] 10 | * [Building for Windows][] 11 | 12 |
13 | 14 | [Android]: http://www.android.com 15 | [Building for Android]: @ref breadboard_guide_building_android 16 | [Building for Linux]: @ref breadboard_guide_building_linux 17 | [Building for OS X]: @ref breadboard_guide_building_osx 18 | [Building for Windows]: @ref breadboard_guide_building_windows 19 | [Linux]: http://en.m.wikipedia.org/wiki/Linux 20 | [OS X]: http://www.apple.com/osx/ 21 | [Windows]: http://windows.microsoft.com/ 22 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/building/building_android.md: -------------------------------------------------------------------------------- 1 | Building for Android {#breadboard_guide_building_android} 2 | ==================== 3 | 4 | ## Version Requirements 5 | 6 | Following are the minimum tested versions for the tools and libraries you 7 | need for building [Breadboard][] for Android: 8 | 9 | * [Android SDK][]: Android 4.1 (API Level 16) 10 | * [ADT][]: 20140702 11 | * [Android NDK][]: android-ndk-r10e 12 | * [cmake][]: 2.8.12 or newer 13 | * [Python][]: 2.7.x 14 | 15 | ## Before Building 16 | 17 | * Install prerequisites for the developer machine's operating system. 18 | * [Linux prerequisites](@ref building_linux_prerequisites) 19 | * [OS X prerequisites](@ref building_osx_prerequisites) 20 | * [Windows prerequisites](@ref building_windows_prerequisites) 21 | * Install [fplutil prerequisites][] 22 | * Install the [Android SDK][]. 23 | * Install the [Android NDK][]. 24 | 25 | ## Building 26 | 27 | To include [Breadboard][] in your project you will need to make the following 28 | changes to your Android.mk 29 | 30 | * Ensure that the variable `DEPENDENCIES_BREADBOARD_DIR` is defined and points 31 | to the directory containing the Breadboard library. 32 | * Add `libbreadboard` to your list of `LOCAL_STATIC_LIBRARIES` 33 | * Run `$(call import-add-path,$(DEPENDENCIES_BREADBOARD_DIR)/..)` near the end 34 | of Android.mk, after you call `include $(BUILD_SHARED_LIBRARY)` 35 | * Lastly, run `$(call import-module,breadboard/jni)` 36 | 37 | Your project should now build and link against Breadboard. 38 | 39 |
40 | 41 | [ADT]: http://developer.android.com/tools/sdk/eclipse-adt.html 42 | [Android NDK]: http://developer.android.com/tools/sdk/ndk/index.html 43 | [Android SDK]: http://developer.android.com/sdk/index.html 44 | [cmake]: http://www.cmake.org/ 45 | [fplutil prerequisites]: http://google.github.io/fplutil/fplutil_prerequisites.html 46 | [fplutil]: http://google.github.io/fplutil 47 | [Breadboard]: @ref breadboard_guide_overview 48 | [Python]: http://www.python.org/download/releases/2.7/ 49 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/building/building_linux.md: -------------------------------------------------------------------------------- 1 | Building for Linux {#breadboard_guide_building_linux} 2 | ================== 3 | 4 | ## Version Requirements 5 | 6 | Following are the minimum required versions for the tools and libraries you 7 | need for building [Breadboard][] for Linux: 8 | 9 | * [cmake][]: 2.8.12 or newer 10 | * [Python][]: 2.7.x 11 | 12 | ## Before Building {#building_linux_prerequisites} 13 | 14 | Prior to building, install the following components using the [Linux][] 15 | distribution's package manager: 16 | 17 | * [cmake][]: You can also manually install from [cmake.org](http://cmake.org). 18 | * [Python][]: 2.7.x 19 | 20 | For example, on Ubuntu: 21 | 22 | sudo apt-get install cmake python 23 | 24 | ## Building 25 | 26 | When building Breadboard, you can either build the library as part of another 27 | project, or you can build it as a stand-alone library. To simply build the 28 | library (and the sample project) do the following: 29 | 30 | * Generate makefiles from the [cmake][] project in the `breadboard` directory. 31 | * Execute `make` to build the library and sample. 32 | 33 | For example: 34 | 35 | cd breadboard 36 | cmake -G'Unix Makefiles' . 37 | make 38 | 39 | To build Breadboard from another project, add the following to your project's 40 | CMakeLists.txt: 41 | 42 | add_subdirectory("${path_to_breadboard}" breadboard) 43 | include_directories(${path_to_breadboard}/include) 44 | 45 | Additionally, if you are making use of the `module_library` packaged with 46 | [Breadboard][], you will need to include additional directories, both the 47 | `module_library`'s include folder as well as the generated include folder if you 48 | are making use of the Flatbuffer-based GraphFactory. 49 | 50 | include_directories(${path_to_breadboard}/module_library/include) 51 | get_property(BREADBOARD_MODULE_LIBRARY_FLATBUFFERS_GENERATED_INCLUDES_DIR 52 | TARGET breadboard_module_library_generated_includes 53 | PROPERTY GENERATED_INCLUDES_DIR) 54 | include_directories(${BREADBOARD_MODULE_LIBRARY_FLATBUFFERS_GENERATED_INCLUDES_DIR}) 55 | 56 | Additionally, ensure that you are linking the library and it's dependencies when 57 | running `target_link_libraries`: 58 | 59 | target_link_libraries(breadboard) 60 | 61 |
62 | 63 | [Breadboard]: @ref breadboard_guide_overview 64 | [Linux]: http://en.wikipedia.org/wiki/Linux 65 | [Python]: http://www.python.org/download/releases/2.7/ 66 | [cmake]: http://www.cmake.org/ 67 | 68 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/building/building_osx.md: -------------------------------------------------------------------------------- 1 | Building for OS X {#breadboard_guide_building_osx} 2 | ================= 3 | 4 | You can use [cmake][] to generate an [Xcode][] project for Breadboard on [OS X][]. 5 | 6 | # Version Requirements 7 | 8 | These are the minimum required versions for building Breadboard on OS X: 9 | 10 | * [OS X][]: Mavericks 10.9.1. 11 | * [Xcode][]: 5.1.1 or newer 12 | * [cmake][]: 2.8.12 or newer 13 | * [Python][]: 2.7.x 14 | 15 | # Before Building {#building_osx_prerequisites} 16 | 17 | Prior to building, install the following software: 18 | 19 | * [cmake][]: You can also manually install from [cmake.org](http://cmake.org). 20 | * [Python][]: 2.7.x 21 | 22 | # Creating the Xcode project using cmake 23 | 24 | The [Xcode][] project is generated using [cmake][]. 25 | 26 | For example, the following generates the [Xcode][] project in the `breadboard` 27 | directory. 28 | 29 | ~~~{.sh} 30 | cd breadboard 31 | cmake -G "Xcode" 32 | ~~~ 33 | 34 | # Building with Xcode 35 | 36 | * Double-click on `breadboard/breadboard.xcodeproj` to open the project in 37 | [Xcode][]. 38 | * Select "Product-->Build" from the menu. 39 | 40 | You can also build the game from the command-line. 41 | 42 | * Run `xcodebuild` after generating the Xcode project to build all targets. 43 | * You may need to force the `generated_includes` target to be built first. 44 | 45 | For example, in the breadboard directory: 46 | 47 | ~~~{.sh} 48 | xcodebuild -target generated_includes 49 | xcodebuild 50 | ~~~ 51 | 52 |
53 | 54 | [cmake]: http://www.cmake.org 55 | [OS X]: http://www.apple.com/osx/ 56 | [Breadboard]: @ref breadboard_guide_overview 57 | [Python]: http://www.python.org/download/releases/2.7/ 58 | [Xcode]: http://developer.apple.com/xcode/ 59 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/building/building_windows.md: -------------------------------------------------------------------------------- 1 | Building for Windows {#breadboard_guide_building_windows} 2 | ==================== 3 | 4 | You can use [CMake][] to generate a [Visual Studio][] project for 5 | [Breadboard][] on [Windows][]. 6 | 7 | # Version Requirements 8 | 9 | These are the minimum required versions for building [Breadboard][] for Windows: 10 | 11 | * [Windows][]: 7 12 | * [Visual Studio][]: 2010 or newer 13 | * [CMake][]: 2.8.12 or newer. 14 | * [Python][]: 2.7.x 15 | 16 | # Before Building {#building_windows_prerequisites} 17 | 18 | * Install [CMake][] 19 | * Install [Python][] 20 | 21 | # Creating the Visual Studio Solution using CMake 22 | 23 | Use [CMake][] to generate the [Visual Studio][] solution and project files. 24 | 25 | The following example generates the [Visual Studio][] 2010 solution in the 26 | `breadboard` directory: 27 | 28 | cd breadboard 29 | cmake -G "Visual Studio 10" 30 | 31 | # Building with Visual Studio 32 | 33 | * Double-click on `breadboard/breadboard.sln` to open the solution. 34 | * Select "Build-->Build Solution" from the menu. 35 | 36 | It's also possible to build from the command line using msbuild after using 37 | vsvars32.bat to setup the [Visual Studio][] build environment. For example, 38 | assuming [Visual Studio][] is installed in 39 | `c:\Program Files (x86)\Microsoft Visual Studio 10.0`. 40 | 41 | cd breadboard 42 | "c:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat" 43 | cmake -G "Visual Studio 10" 44 | msbuild breadboard.sln 45 | 46 |
47 | 48 | [CMake]: http://www.cmake.org 49 | [Breadboard]: @ref breadboard_guide_overview 50 | [Python]: http://www.python.org/download/releases/2.7/ 51 | [Visual Studio]: http://www.visualstudio.com/ 52 | [Windows]: http://windows.microsoft.com/ 53 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/howto/events.md: -------------------------------------------------------------------------------- 1 | Events {#breadboard_guide_events} 2 | ====== 3 | 4 | ## Overview 5 | 6 | Events are what drive Graph execution. Most nodes will have some set of inputs 7 | and outputs, but without getting updates from the game state that exists outside 8 | the graph, the graph nodes will never execute. 9 | 10 | To broadcast events to nodes in a graph, two structures are needed, a 11 | NodeEventListener and a NodeEventBroadcaster. 12 | 13 | ## NodeEventBroadcaster 14 | 15 | A NodeEventBroadcaster is an object that can be included on any game object that 16 | makes sense for your game. They can exist on world objects, players, entities, 17 | or anything else. Typically a specific Broadcaster will be associated with the 18 | object that holds it. That way you can do things like have an event that 19 | triggers when your entity collides with something. In that case, you would 20 | broadcast a collision event from the broadcaster which that specific entity 21 | owns. That event would then be broadcast to only the graphs that are listening 22 | to that broadcaster. 23 | 24 | A broadcaster can be registered to any number of listeners, and can broadcast 25 | any kind of event. 26 | 27 | Events may be broadcast by calling 28 | `NodeEventBroadcaster::BroadcastEvent(event_id)`. 29 | 30 | ## NodeEventListener 31 | 32 | NodeEventListeners exist on the Node and are not instantiated directly. Instead, 33 | during the OnRegistration step, as many listeners as needed may be added to your 34 | node. For example: 35 | 36 | ~~~{.cpp} 37 | // ... 38 | static void OnRegister(NodeSignature* signature) { 39 | signature->AddInput(); 40 | signature->AddListener(kCollisionEventId); 41 | } 42 | virtual void Initialize(NodeArguments* args) { 43 | GameActor* actor = args->GetInput(0); 44 | args->BindBroadcaster(0, actor->broadcaster); 45 | } 46 | // ... 47 | ~~~ 48 | 49 | In this example this node registers a single NodeEventListener that is listening 50 | for the event kCollisionEventId. During initialization, the actor associated 51 | with this node has it's broadcaster bound to that listener. Now any time that 52 | the actor fires a kCollisionEventId, this node will be marked dirty and have its 53 | Execute function (not shown here) called. 54 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/howto/graphs.md: -------------------------------------------------------------------------------- 1 | Graphs {#breadboard_guide_graphs} 2 | ====== 3 | 4 | ## Overview 5 | 6 | Graphs are split up into two main classes, the Graph and GraphState. The Graph 7 | class defines the set of nodes that make up the Graph, as well as the 8 | connections between them and any default values. You can think of the Graph as 9 | the immutable definition of the set of behavior. The GraphState is a stateful 10 | object backed by a Graph. You can have any number of instances of GraphStates 11 | that all point at the same Graph. This is useful for when you have, for example, 12 | many duplicates of the same kind of actor in your game. 13 | 14 | ### Limitations 15 | 16 | In the initial release of Breadboard, Graphs are implemented such that they may 17 | not contain cycles. That is, if node A has an input edge pointing at node B, 18 | then node B can not have an input edge pointing at node A. This restriction may 19 | be lifted in a future update. 20 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/howto/modules.md: -------------------------------------------------------------------------------- 1 | Modules {#breadboard_guide_modules} 2 | ======= 3 | 4 | ## Overview 5 | 6 | Modules are collections of related nodes. Modules exist primarily as a 7 | convenient way to organize nodes and also help avoid name collisions. 8 | 9 | ## Creating a Module 10 | 11 | Modules are created by calling `ModuleRegistry::RegisterModule(name)`. Once a 12 | module is registered, any number of nodes may be added to it. 13 | 14 | A number of examples can be seen in the `src/modules` directory. Here is a 15 | typical example of the process of registering a Module as well as the nodes that 16 | go with it: 17 | 18 | ~~~{.cpp} 19 | void InitializeStringModule(ModuleRegistry* module_registry) { 20 | Module* module = module_registry->RegisterModule("string"); 21 | module->RegisterNode("equals"); 22 | module->RegisterNode("int_to_string"); 23 | module->RegisterNode("float_to_string"); 24 | module->RegisterNode("concat"); 25 | } 26 | ~~~ 27 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/howto/nodes.md: -------------------------------------------------------------------------------- 1 | Nodes {#breadboard_guide_nodes} 2 | ===== 3 | 4 | ## Overview 5 | 6 | Nodes are the basic building blocks of a graph. Most nodes define an `Execute` 7 | function in C++ code which can take any number of arguments, process them, and 8 | then provide any number of outputs which other nodes may then consume. 9 | 10 | ## Basic Example 11 | 12 | As a simple example, see `src/modules/string.cpp`. This file defines the node 13 | ConcatNode, shown below: 14 | 15 | ~~~{.cpp} 16 | // Concatenates the given strings. 17 | class ConcatNode : public BaseNode { 18 | public: 19 | virtual ~ConcatNode() {} 20 | 21 | static void OnRegister(NodeSignature* node_sig) { 22 | node_sig->AddInput(); 23 | node_sig->AddInput(); 24 | node_sig->AddOutput(); 25 | } 26 | 27 | virtual void Execute(NodeArguments* args) { 28 | auto str_a = args->GetInput(0); 29 | auto str_b = args->GetInput(1); 30 | args->SetOutput(0, *str_a + *str_b); 31 | } 32 | }; 33 | ~~~ 34 | 35 | When this node is registered with Breadboard, it's OnRegister function is run. 36 | OnRegister is given a NodeSignature object that is used to define the number of 37 | inputs and outputs to this node. In this example, two `std::string` inputs and a 38 | single string output are declared. 39 | 40 | Execute is where the behavior for this node is run. In this example, our node 41 | takes its two inputs by calling `args->GetInput(index);`. This 42 | function returns the value in the input edge by pointer. When writing nodes you 43 | must take care to match the expected return type for the given edge index with 44 | the signature defined in OnRegister or else the call to `GetInput` will assert. 45 | 46 | Finally, the result of the operation (in this case, concatenating two strings) 47 | is passed to `args->SetOutput`. In this case there is only a single output, so 48 | we pass 0 as the first argument, but if there were additional outputs we might 49 | also pass values to other indexes as well. As with input edges, make sure that 50 | the type being passed in matches the type declared in the NodeSignature in 51 | OnRegister. 52 | 53 | In some cases you don't need to pass data around but you still want to trigger 54 | execution of a node. This can be achieved by assigning inputs or outputs 55 | with the type `void`. Rather than getting a pointer to the value using 56 | `args->GetInput(index)`, you would simply call `args->IsInputDirty(index)` 57 | (Note: This function can be used on input edges of any type). For output edges 58 | that are declared void, simple call `args->SetOutput(index)` without a value 59 | argument to mark it as dirty. 60 | 61 | ## Node Inputs 62 | 63 | Node inputs can be specified in two ways: Either by pointing at the output of 64 | some other node, or by supplying a default value. 65 | 66 | ## Node Execution 67 | 68 | Nodes have three main functions declared on BaseNode. You will always need to 69 | implement OnRegister to define your node's interface. You may additionally 70 | override the `Initialize` and `Execute` functions. Without implementing at least 71 | one of these functions, your node will do nothing. 72 | 73 | Nodes execute if one of two conditions is met. 74 | 75 | * The node has a NodeEventListener associated with it, and an event that the 76 | node is listening for has been broadcast. 77 | * As a result of another executing, one of the input edges on this node has 78 | been updated. 79 | 80 | Any time an input edge of a node is changed as the result of a call to SetOutput 81 | it is considered dirty, and will have its Evaluate function called. 82 | 83 | ## BaseNode interface 84 | 85 | ### OnRegister 86 | 87 | OnRegister is a static method, but it must be defined for your type. You do not 88 | technically override it, but you must still supply a copy of this function. 89 | OnRegister is called automatically when your node is registered with a Module. 90 | 91 | ### Initialize 92 | 93 | Initialize is called once when the GraphState itself is initialized. This can be 94 | a useful place to do any special set up for your node, or to set the value of 95 | output edges that only need to be set once and will never change. Initialize 96 | recieves a NodeArguments structure containing the default values for the inputs. 97 | You may set outputs as well from Initialize, but during the initialization step 98 | nodes that depend on those outputs are not marked as dirty. 99 | 100 | ### Execute 101 | 102 | Execute is where most of the heavy lifting will be done. This would be where you 103 | implement most behaviors. Using the NodeArguments structure you can get any 104 | values your node needs to operate and perform actions such as updating UI, 105 | playing audio, printing debug logs to the console, or responding to phsyics 106 | events. Nodes can be set up for just about any type of behavior that would want 107 | to script. 108 | 109 | ## Node Registration 110 | 111 | To register a node so that it can be used by Breadboard, simply call 112 | `Module::RegisterNode(name)`. You must specify a node name that is 113 | unique to this module. 114 | 115 | By default, when constructing nodes the default constructor is used. However, 116 | this is not always ideal (or possible). In these cases, you may additionally 117 | provide custom constructor and destuctor callbacks. 118 | 119 | For example, if you are writing a PlaySound node that requires a pointer to the 120 | audio engine, you could write it like this: 121 | 122 | ~~~{.cpp} 123 | class PlaySoundNode : public BaseNode { 124 | public: 125 | PlaySoundNode(AudioEngine* audio_engine) : audio_engine_(audio_engine) {} 126 | // ... 127 | 128 | private: 129 | AudioEngine* audio_engine_; 130 | }; 131 | 132 | // ... 133 | 134 | void InitializeAudioModule(ModuleRegistry* module_registry, 135 | AudioEngine* audio_engine) { 136 | Module* module = module_registry->RegisterModule("audio"); 137 | // Custom constructor for PlaySoundNode since it cannot be constructed 138 | // with the default constructor. 139 | auto play_sound_ctor = [audio_engine]() { 140 | return new PlaySoundNode(audio_engine); 141 | }; 142 | module->RegisterNode("play_sound", play_sound_ctor); 143 | } 144 | ~~~ 145 | -------------------------------------------------------------------------------- /docs/src/programmers_guide/overview.md: -------------------------------------------------------------------------------- 1 | Overview {#breadboard_guide_overview} 2 | ======== 3 | 4 | ## Downloading 5 | 6 | [Breadboard][] can be downloaded from [GitHub][] or the [Releases Page][]. 7 | 8 | ~~~{.sh} 9 | git clone --recursive https://github.com/google/breadboard.git 10 | ~~~ 11 | 12 | ## Important Concepts 13 | 14 | The Breadboard API contains the following important concepts: 15 | * [Nodes][] - Individual bits of logic or behavior that can be activated. 16 | * [Modules][] - Collections of related nodes. 17 | * [Graphs][] - An arrangement of nodes to form more complex behaviors. 18 | * [Events][] - How graph actions are triggered. 19 | 20 | ## Source Layout 21 | 22 | The following bullets describe the directory structure of the library. 23 | 24 | | Path | Description | 25 | |-------------------------------|----------------------------------------------| 26 | | `breadboard` base directory | Project build files and run script. | 27 | | `jni` | The android makefile for the library. | 28 | | `samples` | Sample projects to demonstrate usage. | 29 | | `src/breadboard` | The library's souce code. | 30 | | `src/modules` | The source code for the default modules. | 31 | | `module_library` | Additional modules using external libraries. | 32 | 33 |
34 | 35 | [Breadboard]: @ref breadboard_guide_overview 36 | [Events]: @ref breadboard_guide_events 37 | [GitHub]: http://github.com/google/breadboard 38 | [Graphs]: @ref breadboard_guide_graphs 39 | [Modules]: @ref breadboard_guide_modules 40 | [Nodes]: @ref breadboard_guide_nodes 41 | [Releases Page]: http://github.com/google/breadboard/releases 42 | -------------------------------------------------------------------------------- /include/breadboard/base_node.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_BASE_NODE_H_ 16 | #define BREADBOARD_BASE_NODE_H_ 17 | 18 | #include 19 | 20 | #include "breadboard/event.h" 21 | #include "breadboard/node_arguments.h" 22 | #include "breadboard/node_signature.h" 23 | 24 | /// @file breadboard/base_node.h 25 | /// 26 | /// @brief A BaseNode is the common class that all nodes that are to be used in 27 | /// a graph must extend. 28 | 29 | namespace breadboard { 30 | 31 | /// @class BaseNode 32 | /// 33 | /// @brief A BaseNode is the common class that all nodes that are to be used in 34 | /// a graph must extend. 35 | /// 36 | /// Each class that implements BaseNode must be registered in a Module before it 37 | /// may be used in a graph. 38 | /// 39 | /// Nodes are the primary method of performing actions in Breadboard. Nodes can 40 | /// take any number of input edge parameters and perform actions based on those 41 | /// parameters. They in turn provide various output arguments which may be 42 | /// consumed by other nodes. The connnections between nodes can be used to 43 | /// script complex behavior. 44 | class BaseNode { 45 | public: 46 | /// @brief Destructor for a BaseNode. 47 | virtual ~BaseNode() {} 48 | 49 | /// @brief When this node is registered, the input edges, output edges and 50 | /// active listeners for this node are defined by this function. 51 | /// 52 | /// Although this is a static function, all classes inheriting from BaseNode 53 | /// must implement an OnRegister function. This function is used to define the 54 | /// inputs, outputs, and listeners that this node requires. 55 | /// 56 | /// @param[in,out] signature An object that represents the input edge 57 | /// parameters, output edge parameters, and active 58 | /// listeners for this kind of node. 59 | static void OnRegister(NodeSignature* signature) { 60 | (void)signature; 61 | assert(false); // This function should be implemented in the derived class 62 | } 63 | 64 | /// @brief Initialize is called once upon when an instance of a GraphState is 65 | /// initiazlized. This function can be used to set output edge arguments that 66 | /// are guaranteed to never change or do other one-time setup. 67 | /// 68 | /// Initialize is called once when a GraphState object is being initialized. 69 | /// You can use this to do any special set up. For example, if this is a node 70 | /// that has no inputs and only outputs that are unchanging, you can set them 71 | /// once here and not need to worry about doing anything in Execute. This is 72 | /// also a useful place to bind listeners with broadcasters. 73 | virtual void Initialize(NodeArguments* args) { (void)args; } 74 | 75 | /// @brief Execute is called any time the node is marked dirty in the graph. 76 | /// 77 | /// Execute is called any time this node in the graph is marked dirty. This 78 | /// can happen in two ways. One way is that this node has a listener that has 79 | /// had an event broadcast to it. The other is that another node updated an 80 | /// output edge that this node is observing. 81 | /// 82 | /// This function is where the bulk of the interesting logic should occur in a 83 | /// node. 84 | virtual void Execute(NodeArguments* args) { (void)args; } 85 | }; 86 | 87 | } // namespace breadboard 88 | 89 | #endif // BREADBOARD_BASE_NODE_H_ 90 | -------------------------------------------------------------------------------- /include/breadboard/event.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_EVENT_H_ 16 | #define BREADBOARD_EVENT_H_ 17 | 18 | #include 19 | 20 | #include "breadboard/node.h" 21 | #include "fplutil/intrusive_list.h" 22 | 23 | /// @file breadboard/event.h 24 | /// 25 | /// @brief NodeEventListener and NodeEventBroadcaster are classes that are used 26 | /// to notify GraphState instances when events they care about have 27 | /// occured. 28 | 29 | namespace breadboard { 30 | 31 | class BaseNode; 32 | class GraphState; 33 | 34 | /// @typedef Timestamp 35 | /// 36 | /// @brief Timestamp is a type used internally by Breadboard to keep track of 37 | /// which nodes in a graph require a call to Evaluate. 38 | typedef uint32_t Timestamp; 39 | 40 | /// @typedef EventId 41 | /// 42 | /// @brief An EventID is an opaque pointer that is used as a unique identifier 43 | /// for node events. 44 | typedef const char** EventId; 45 | 46 | /// @class NodeEventListener 47 | /// 48 | /// @brief A NodeEventListener ensures a node is marked dirty for reevaluation 49 | /// when events it cares about has been broadcast to it. 50 | /// 51 | /// NodeEventListeners are registered on the node via the NodeSignature when 52 | /// BaseNode::OnRegister is called. The library user should never need to 53 | /// construct a NodeEventListener manually. 54 | /// 55 | /// Typical usage is as follows: 56 | /// 57 | /// ~~~{.cpp} 58 | /// class ExampleNode : public breadboard::BaseNode { 59 | /// public: 60 | /// static void OnRegister(NodeSignature* signature) { 61 | /// signature->AddInput(); 62 | /// // The NodeEventListener is created and tracked internally here. 63 | /// signature->AddListener(kMyEventId); 64 | /// } 65 | /// virtual void Initialize(NodeArguments* args) { 66 | /// GameEntity* entity = args->GetInput(0); 67 | /// // This GameEntity's broadcaster can now broadcast to this node. 68 | /// args->BindBroadcaster(0, &entity->broadcaster); 69 | /// } 70 | /// }; 71 | /// ~~~ 72 | /// 73 | /// If you would like a node to respond to more than one kind of event, you may 74 | /// place multiple listeners on it. 75 | /// 76 | /// @note You should never need to instantiate this type directly. Instead you 77 | /// should use NodeSignature::AddListener to create NodeEventListeners. 78 | class NodeEventListener { 79 | public: 80 | /// @cond BREADBOARD_INTERNAL 81 | /// @brief Construct a NodeEventListener for the given GraphState and EventId. 82 | /// 83 | /// @param[in] graph_state The GraphState that owns the node that this 84 | /// NodeEventListener belongs to. 85 | /// 86 | /// @param[in] event_id The EventId this listener is listening for. 87 | NodeEventListener(GraphState* graph_state, EventId event_id) 88 | : node(), graph_state_(graph_state), timestamp_(0), event_id_(event_id) {} 89 | 90 | /// @brief Returns the EventId this listener is listening for. 91 | /// 92 | /// @return The EventId this listener is listening for. 93 | EventId event_id() const { return event_id_; } 94 | 95 | /// @brief Returns the EventId this listener is listening for. 96 | /// 97 | /// @return The EventId this listener is listening for. 98 | GraphState* graph_state() const { return graph_state_; } 99 | 100 | /// @brief Returns the current Timestamp, used for marking a node as dirty. 101 | /// 102 | /// @return The current Timestamp. 103 | Timestamp timestamp() const { return timestamp_; } 104 | 105 | /// @brief Mark the node this Listener is associated with as dirty. 106 | void MarkDirty(); 107 | 108 | fplutil::intrusive_list_node node; 109 | /// @endcond 110 | 111 | private: 112 | GraphState* graph_state_; 113 | Timestamp timestamp_; 114 | EventId event_id_; 115 | }; 116 | 117 | /// @class NodeEventBroadcaster 118 | /// 119 | /// @brief A NodeEventBroadcaster is used to notify NodeEventListeners that a 120 | /// specific event has occured so that the appropriate nodes can be 121 | /// marked dirty for re-evaluation. 122 | /// 123 | /// The broadcaster keeps different lists internally for each type of event. 124 | /// A NodeEventListener must be registered with a given broadcaster before the 125 | /// listener will be able to respond to events. 126 | /// 127 | /// A typical use case would be to add a NodeEventBroadcaster as a field on some 128 | /// kind of game object class. When that object is mutated in a way that a graph 129 | /// node would care about, call BroadcastEvent and specify an event_id. All 130 | /// nodes that are registered to that event_id on the broadcaster will be marked 131 | /// dirty. 132 | /// 133 | /// For example, when the game object moves, it would broadcast a kEntityMoved 134 | /// event (where kEntityMoved is an EventId object). All nodes observing that 135 | /// event would then execute the next time the graph itself is executed. 136 | class NodeEventBroadcaster { 137 | public: 138 | /// Associate the given listener with this NodeEventBroadcaster and the given 139 | /// event_id. 140 | void RegisterListener(NodeEventListener* listener); 141 | 142 | /// For each listener registered with the given event_id on this broadcaster, 143 | /// mark the node associated with the listener dirty so that it will execute 144 | /// the next time the graph is executed. 145 | void BroadcastEvent(EventId event_id); 146 | 147 | private: 148 | typedef fplutil::intrusive_list ListenerList; 149 | 150 | std::map event_listener_lists_; 151 | }; 152 | 153 | } // namespace breadboard 154 | 155 | /// @def BREADBOARD_DECLARE_EVENT(event_id) 156 | /// 157 | /// Whenever you want to declare a new event ID, the preferred way is to use 158 | /// these macros. In you header file you would put: 159 | /// 160 | /// ~~~{.cpp} 161 | /// BREADBOARD_DECLARE_EVENT(kMyEventId); 162 | /// ~~~ 163 | /// 164 | /// And then in your cpp file you would put this: 165 | /// 166 | /// ~~~{.cpp} 167 | /// BREADBOARD_DEFINE_EVENT(kMyEventId); 168 | /// ~~~ 169 | /// 170 | /// Once the event has been declared and defined, you can use it to broadcast 171 | /// events to graphs that are listening for those events 172 | #define BREADBOARD_DECLARE_EVENT(event_id) \ 173 | extern ::breadboard::EventId event_id; 174 | 175 | /// @cond BREADBOARD_INTERNAL 176 | /// We need two of each of these macros to ensure that they expand in the 177 | /// right order becuase of quirks in how the C preprocessor works. 178 | /// See http://stackoverflow.com/a/1597129/63791 179 | #define BREADBOARD_STRINGIZE(x) #x 180 | #define BREADBOARD_STRINGIZE2(x) BREADBOARD_STRINGIZE(x) 181 | #define BREADBOARD_CONCAT(x, y) x##y 182 | #define BREADBOARD_CONCAT2(x, y) BREADBOARD_CONCAT(x, y) 183 | /// @endcond 184 | 185 | /// @def BREADBOARD_DEFINE_EVENT(event_id) 186 | /// 187 | /// Whenever you want to declare a new event ID, the preferred way is to use 188 | /// these macros. In you header file you would put: 189 | /// 190 | /// ~~~{.cpp} 191 | /// BREADBOARD_DECLARE_EVENT(kMyEventId); 192 | /// ~~~ 193 | /// 194 | /// And then in your cpp file you would put this: 195 | /// 196 | /// ~~~{.cpp} 197 | /// BREADBOARD_DEFINE_EVENT(kMyEventId); 198 | /// ~~~ 199 | /// 200 | /// Once the event has been declared and defined, you can use it to broadcast 201 | /// events to graphs that are listening for those events 202 | #define BREADBOARD_DEFINE_EVENT(event_id) \ 203 | static const char* BREADBOARD_CONCAT2(BREADBOARD_VAR_, __LINE__) = \ 204 | __FILE__ ":" BREADBOARD_STRINGIZE2(__LINE__); \ 205 | ::breadboard::EventId event_id = \ 206 | &BREADBOARD_CONCAT2(BREADBOARD_VAR_, __LINE__); 207 | 208 | #endif // BREADBOARD_EVENT_H_ 209 | -------------------------------------------------------------------------------- /include/breadboard/graph_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_GRAPH_FACTORY_H_ 16 | #define BREADBOARD_GRAPH_FACTORY_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "breadboard/graph.h" 23 | #include "breadboard/module_registry.h" 24 | 25 | /// @file breadboard/graph_factory.h 26 | /// 27 | /// @brief The GraphFactory is a base class that can be used to load Graphs. 28 | 29 | namespace breadboard { 30 | 31 | /// Different platforms have different ways to load files, so a callback must be 32 | /// supplied to actually load data. 33 | typedef bool (*LoadFileCallback)(const char* filename, std::string* output); 34 | 35 | /// @class GraphFactory 36 | /// 37 | /// @brief The GraphFactory is a base class that can be used to load Graphs. 38 | /// 39 | /// This is a utility class that simplifies the process of loading graphs. It 40 | /// handles loading the file into memory and caching previously loaded files. If 41 | /// the same file is requested multiple times, the cached graph is returned. To 42 | /// use this class ParseData must be overridden to translate the data into nodes 43 | /// and edges, and to parse default values. 44 | class GraphFactory { 45 | public: 46 | /// @brief Construct a graph factory using the given modules. 47 | /// 48 | /// @param[in] module_registry The ModuleRegistry that contains the set of 49 | /// available nodes for the graph. 50 | /// @param[in] load_file_callback The function to use to load the file from 51 | /// disk. 52 | GraphFactory(ModuleRegistry* module_registry, 53 | LoadFileCallback load_file_callback) 54 | : module_registry_(module_registry), 55 | load_file_callback_(load_file_callback) {} 56 | 57 | /// @brief Destructor for a GraphFactory. 58 | virtual ~GraphFactory() {} 59 | 60 | /// @brief Load a graph given its filename. 61 | /// 62 | /// If this file has already been loaded, a cached copy of the graph is 63 | /// returned. 64 | /// 65 | /// @param[in] filename The name of the file to load. 66 | /// 67 | /// @return The loaded Graph. 68 | Graph* LoadGraph(const char* filename); 69 | 70 | private: 71 | typedef std::unordered_map> GraphMap; 72 | 73 | /// Parse the data loaded from a file. The data is passed to this function as a 74 | /// std::string. This function is responsible for filling in the graph (both 75 | /// the edges and the nodes) using the nodes registered with the 76 | /// module_registry. 77 | virtual bool ParseData(ModuleRegistry* module_registry, Graph* graph, 78 | const std::string* data) = 0; 79 | 80 | ModuleRegistry* module_registry_; 81 | LoadFileCallback load_file_callback_; 82 | GraphMap loaded_graphs_; 83 | }; 84 | 85 | } // namespace breadboard 86 | 87 | #endif // BREADBOARD_GRAPH_FACTORY_H_ 88 | -------------------------------------------------------------------------------- /include/breadboard/graph_state.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_GRAPH_STATE_H_ 16 | #define BREADBOARD_GRAPH_STATE_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "breadboard/graph.h" 23 | #include "breadboard/memory_buffer.h" 24 | #include "breadboard/node.h" 25 | 26 | /// @file breadboard/graph_state.h 27 | /// 28 | /// @brief A GraphState represents an instance of a Graph, and can be connected 29 | /// to game objects to script and execute behaviors. 30 | 31 | namespace breadboard { 32 | 33 | /// @class GraphState 34 | /// 35 | /// @brief A GraphState represents an instance of a Graph, and can be connected 36 | /// to game objects to script and execute behaviors. 37 | /// 38 | /// Once a GraphState has been initialized with a Graph, it can be used to 39 | /// execute various scripted behaviors. 40 | class GraphState { 41 | public: 42 | /// @brief The default constructor for an empty GraphState object. 43 | GraphState() : graph_(nullptr), output_buffer_(), timestamp_(0) {} 44 | 45 | /// @brief Destructor for a BaseNode. 46 | ~GraphState(); 47 | 48 | /// @brief Initialize the GraphState with a graph. 49 | /// 50 | /// All nodes in the graph will have their Initialize function run. The order 51 | /// the nodes run Initialize is not specified except that nodes that have a 52 | /// dependency on other nodes will always run after their dependencies. 53 | /// 54 | /// @param[in] graph The Graph that defines this GraphState's nodes and edges. 55 | void Initialize(Graph* graph); 56 | 57 | /// @brief Check if this GraphState has been initialized. 58 | /// 59 | /// @return Whether or not the Graph has been initialized. 60 | bool IsInitialized() const { return graph_ != nullptr; } 61 | 62 | /// @cond BREADBOARD_INTERNAL 63 | 64 | /// @brief Execute all Nodes that are considered 'dirty'. 65 | /// 66 | /// A dirty node is any node that has been updated since the last time Execute 67 | /// was called, or one that has an input edge pointing at data that has 68 | /// changed. Nodes that do not meet either of these requirements do not have 69 | /// their Execute function called. 70 | /// 71 | /// The order the nodes run Execute is not specified except that nodes that 72 | /// have a dependency on other nodes will always run after their dependencies. 73 | /// 74 | /// @note This is for internal use only. 75 | void Execute(); 76 | 77 | /// @brief Return the current timestamp. 78 | /// 79 | /// @note This is for internal use only. 80 | /// 81 | /// @return the current timestamp. 82 | Timestamp timestamp() const { return timestamp_; } 83 | 84 | /// @brief Returns the internal memory buffer for output edge objects. 85 | /// 86 | /// @note This is for internal use only. 87 | /// 88 | /// @return the internal memory buffer for output edge objects. 89 | MemoryBuffer* output_buffer() { return &output_buffer_; } 90 | 91 | /// @brief Returns the internal memory buffer for output edge objects. 92 | /// 93 | /// @note This is for internal use only. 94 | /// 95 | /// @return the internal memory buffer for output edge objects. 96 | const MemoryBuffer* output_buffer() const { return &output_buffer_; } 97 | 98 | /// @endcond 99 | 100 | private: 101 | // Disallow copying. 102 | GraphState(GraphState&); 103 | GraphState& operator=(GraphState&); 104 | GraphState(GraphState&&); 105 | GraphState& operator=(GraphState&&); 106 | 107 | // Return true if any of the input edges on this node point to data that has 108 | // been updated. 109 | bool IsDirty(const Node& node) const; 110 | 111 | Graph* graph_; 112 | MemoryBuffer output_buffer_; 113 | Timestamp timestamp_; 114 | }; 115 | 116 | } // namespace breadboard 117 | 118 | #endif // BREADBOARD_GRAPH_STATE_H_ 119 | -------------------------------------------------------------------------------- /include/breadboard/log.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_LOG_H_ 16 | #define BREADBOARD_LOG_H_ 17 | 18 | #include 19 | 20 | /// @file breadboard/log.h 21 | /// 22 | /// @brief This file contains functions to register and call logging function. 23 | /// The log function is used for various debug logging. 24 | 25 | namespace breadboard { 26 | 27 | /// @typedef LogFunc 28 | /// 29 | /// @brief The function signature of the logging function. 30 | /// 31 | /// In order to perform logging, the library needs to be provided with a logging 32 | /// function that fits this type signature. 33 | typedef void (*LogFunc)(const char* fmt, va_list args); 34 | 35 | /// @brief Register a logging function with the library. 36 | /// 37 | /// @param[in] The function to use for logging. 38 | void RegisterLogFunc(LogFunc log_func); 39 | 40 | /// @brief Call the registered log function with the provided format string. 41 | /// 42 | /// This does nothing if no logging function has been registered. 43 | /// 44 | /// @param[in] format The format string to print. 45 | /// @param[in] ... The arguments to format. 46 | void CallLogFunc(const char* format, ...); 47 | 48 | } // namespace breadboard 49 | 50 | #endif // BREADBOARD_LOG_H_ 51 | -------------------------------------------------------------------------------- /include/breadboard/memory_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MEMORY_BUFFER_H_ 16 | #define BREADBOARD_MEMORY_BUFFER_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | /// @file breadboard/memory_buffer.h 24 | /// 25 | /// @brief MemoryBuffer is a simple buffer for holding and accessing raw bytes. 26 | /// 27 | /// @note This is for internal use only. 28 | 29 | namespace breadboard { 30 | 31 | /// @cond BREADBOARD_INTERNAL 32 | 33 | /// @class MemoryBuffer 34 | /// 35 | /// @brief MemoryBuffer is a simple wrapper around a vector of bytes that makes 36 | /// it easy to convert offsets into concrete types. 37 | /// 38 | /// The buffer size may only be set once. Once the buffer is initialized, 39 | /// functions are provided to get at the memory at given offsets and cast it 40 | /// to the desired type. This is not guarenteed to work if bad offsets are 41 | /// supplied, so it is up to the caller to make sure they are keeping track of 42 | /// offset values. This class only provides convenience, not safety. 43 | /// 44 | /// @note This is for internal use only. 45 | class MemoryBuffer { 46 | public: 47 | /// @class Construct an uninitialized MemoryBuffer. 48 | MemoryBuffer() : buffer_() {} 49 | 50 | /// @brief Sets the buffer to the desired size. 51 | /// 52 | /// For the sake of simplicity, this is only allowed to happen once. There 53 | /// are no use cases currently where resizing would be allowed, so to prevent 54 | /// misuse any attempt to resize it again will assert. 55 | /// 56 | /// @note This is for internal use only. 57 | /// 58 | /// @note This may only be called once. 59 | /// 60 | /// @param[in] size The size in bytes bytes of the buffer. 61 | void Initialize(size_t size) { 62 | assert(buffer_.size() == 0); 63 | buffer_.resize(size); 64 | } 65 | 66 | /// @brief Returns a raw pointer to the desired offset in the buffer. 67 | /// 68 | /// @return A raw pointer to the desired offset in the buffer. 69 | uint8_t* GetObjectPtr(ptrdiff_t offset) { 70 | assert(buffer_.size() > 0 && 71 | offset < static_cast(buffer_.size())); 72 | return buffer_.data() + offset; 73 | } 74 | 75 | /// @brief Returns a raw pointer to the desired offset in the buffer. 76 | /// 77 | /// @return A raw pointer to the desired offset in the buffer. 78 | const uint8_t* GetObjectPtr(ptrdiff_t offset) const { 79 | assert(buffer_.size() > 0 && 80 | offset < static_cast(buffer_.size())); 81 | return buffer_.data() + offset; 82 | } 83 | 84 | /// @brief Returns a pointer to an object located at the given offset. 85 | /// 86 | /// This does no static or run time type checking, so the caller must be sure 87 | /// the memory they're accessing is the type they expect. 88 | /// 89 | /// @return A pointer to the object at the given offset. 90 | template 91 | T* GetObject(ptrdiff_t offset) { 92 | return reinterpret_cast(GetObjectPtr(offset)); 93 | } 94 | 95 | /// @brief Returns a pointer to an object located at the given offset. 96 | /// 97 | /// This does no static or run time type checking, so the caller must be sure 98 | /// the memory they're accessing is the type they expect. 99 | /// 100 | /// @return A pointer to the object at the given offset. 101 | template 102 | const T* GetObject(ptrdiff_t offset) const { 103 | return reinterpret_cast(GetObjectPtr(offset)); 104 | } 105 | 106 | private: 107 | std::vector buffer_; 108 | }; 109 | 110 | /// @endcond 111 | 112 | } // namespace breadboard 113 | 114 | #endif // BREADBOARD_MEMORY_BUFFER_H_ 115 | -------------------------------------------------------------------------------- /include/breadboard/module.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULE_H_ 16 | #define BREADBOARD_MODULE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "breadboard/base_node.h" 22 | #include "breadboard/log.h" 23 | #include "breadboard/node_signature.h" 24 | 25 | /// @file breadboard/module.h 26 | /// 27 | /// @brief A module represents a collection of nodes with a related purpose. 28 | 29 | namespace breadboard { 30 | 31 | /// @class Module 32 | /// 33 | /// A module is a collection of related NodeSignatures. For example, it may make 34 | /// sense to make a Math module for basic math operations, or an Entity module 35 | /// for entity operations. 36 | class Module { 37 | public: 38 | /// @brief Create a Module with the given name. 39 | explicit Module(const std::string& module_name) : module_name_(module_name) {} 40 | 41 | /// @brief Register a node of type DerivedNode. 42 | /// 43 | /// The template argument to this function should be a class that implements 44 | /// BaseNode. Each BaseNode registered should have one NodeSignature 45 | /// associated with it. The NodeSignature defines how many input and output 46 | /// edges and the types of those edges. 47 | /// 48 | /// @param[in] node_name The name of the new node. 49 | /// 50 | /// @param[in] constructor A function used to construct a new DerivedNode. 51 | /// 52 | /// @param[in] destructor A function used to destruct a DerivedNode object. 53 | template 54 | void RegisterNode(const std::string& node_name, 55 | const NodeConstructor& constructor, 56 | const NodeDestructor& destructor) { 57 | auto result = signatures_.insert(std::make_pair( 58 | node_name, 59 | NodeSignature(&module_name_, node_name, constructor, destructor))); 60 | NodeDictionary::iterator iter = result.first; 61 | 62 | bool success = result.second; 63 | if (!success) { 64 | CallLogFunc( 65 | "A node named \"%s\" has already been registered in module \"%s\".", 66 | node_name.c_str(), module_name_.c_str()); 67 | return; 68 | } 69 | NodeSignature* signature = &iter->second; 70 | DerivedNode::OnRegister(signature); 71 | } 72 | 73 | /// @brief Register a node of type DerivedNode. 74 | /// 75 | /// The template argument to this function should be a class that implements 76 | /// BaseNode. Each BaseNode registered should have one NodeSignature 77 | /// associated with it. The NodeSignature defines how many input and output 78 | /// edges and the types of those edges. 79 | /// 80 | /// @note This version of the function assumes that DerivedNode needs no 81 | /// special tear down logic. Instances of DerivedNode are deleted by calling 82 | /// `delete obj;`. If the type requires any special or tear down consider 83 | /// using one of the other variations of this function and supply a destructor 84 | /// callback. 85 | /// 86 | /// @param[in] node_name The name of the new node. 87 | /// 88 | /// @param[in] constructor A function used to construct a new DerivedNode. 89 | template 90 | void RegisterNode(const std::string& node_name, 91 | const NodeConstructor& constructor) { 92 | return RegisterNode(node_name, constructor, DefaultDelete); 93 | } 94 | 95 | /// @brief Register a node of type DerivedNode. 96 | /// 97 | /// The template argument to this function should be a class that implements 98 | /// BaseNode. Each BaseNode registered should have one NodeSignature 99 | /// associated with it. The NodeSignature defines how many input and output 100 | /// edges and the types of those edges. 101 | /// 102 | /// @note This version of the function assumes that DerivedNode needs no 103 | /// special set up or tear down logic. Instances of DerivedNode are created 104 | /// with a by calling `new DerivedNode()` and deleted by calling `delete 105 | /// obj;`. If the type requires any special set up or tear down consider using 106 | /// one of the other variations of this function and supply a constructor 107 | /// and/or destructor callback. 108 | /// 109 | /// @param[in] node_name The name of the new node. 110 | template 111 | void RegisterNode(const std::string& node_name) { 112 | return RegisterNode(node_name, DefaultNew); 113 | } 114 | 115 | /// @brief Returns a pointer to the NodeSignature for a registered node. 116 | /// 117 | /// @param[in] node_name The name of the node. 118 | /// 119 | /// @return A pointer to the NodeSignature for the given node. 120 | NodeSignature* GetNodeSignature(const std::string& node_name); 121 | 122 | /// @brief Returns a pointer to the NodeSignature for a registered node. 123 | /// 124 | /// @param[in] node_name The name of the node. 125 | /// 126 | /// @return A pointer to the NodeSignature for the given node. 127 | const NodeSignature* GetNodeSignature(const std::string& node_name) const; 128 | 129 | private: 130 | typedef std::unordered_map NodeDictionary; 131 | 132 | template 133 | static BaseNode* DefaultNew() { 134 | return new DerivedNode(); 135 | } 136 | 137 | static void DefaultDelete(BaseNode* object) { delete object; } 138 | 139 | std::string module_name_; 140 | NodeDictionary signatures_; 141 | }; 142 | 143 | } // namespace breadboard 144 | 145 | #endif // BREADBOARD_MODULE_H_ 146 | -------------------------------------------------------------------------------- /include/breadboard/module_registry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULE_REGISTRY_H_ 16 | #define BREADBOARD_MODULE_REGISTRY_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "breadboard/module.h" 22 | #include "breadboard/version.h" 23 | 24 | /// @file breadboard/module_registry.h 25 | /// @brief The ModuleRegistry is a collection of Modules. 26 | 27 | namespace breadboard { 28 | 29 | /// @class ModuleRegistry 30 | /// 31 | /// @brief The ModuleRegistry is a collection of Modules. 32 | /// 33 | /// This acts as a central repository for all modules used in your project. 34 | class ModuleRegistry { 35 | public: 36 | /// Construct a ModuleRegistry. 37 | ModuleRegistry(); 38 | 39 | /// @brief Adds a new module with the given name to the ModuleRegistry. 40 | /// 41 | /// @param[in] module_name The name of the new Module. 42 | /// 43 | /// @return The new Module. Returns null if the module could not be created. 44 | Module* RegisterModule(const std::string& module_name); 45 | 46 | /// @brief Returns a pointer to a module given its name. 47 | /// 48 | /// @param[in] module_name The name of the Module. 49 | /// 50 | /// @return a pointer to a module given its name. 51 | const Module* GetModule(const std::string& module_name) const; 52 | 53 | /// @brief Returns the current Breadboard version structure. 54 | /// 55 | /// @return The current Breadboard version structure. 56 | const BreadboardVersion* version() const { return version_; } 57 | 58 | private: 59 | typedef std::unordered_map ModuleDictionary; 60 | 61 | // The dictionary of modules, keyed by name. 62 | ModuleDictionary modules_; 63 | 64 | // Current version of Breadboard. 65 | const BreadboardVersion* version_; 66 | }; 67 | 68 | } // namespace breadboard 69 | 70 | #endif // BREADBOARD_MODULE_REGISTRY_H_ 71 | -------------------------------------------------------------------------------- /include/breadboard/modules/common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULES_COMMON_H_ 16 | #define BREADBOARD_MODULES_COMMON_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | /// @file breadboard/modules/common.h 21 | /// 22 | /// @brief Initialize the common modules (debug, logic, math, and string). 23 | 24 | namespace breadboard { 25 | 26 | /// @brief Initialize the common modules (debug, logic, math, and string). 27 | /// 28 | /// @param[in,out] module_registry The ModuleRegistry that will hold the modules 29 | /// registered by this function. 30 | void InitializeCommonModules(ModuleRegistry* module_registry); 31 | 32 | } // namespace breadboard 33 | 34 | #endif // BREADBOARD_MODULES_COMMON_H_ 35 | -------------------------------------------------------------------------------- /include/breadboard/modules/debug.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULES_DEBUG_H_ 16 | #define BREADBOARD_MODULES_DEBUG_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | /// @file breadboard/modules/debug.h 21 | /// 22 | /// @brief Initialize the debug modules. 23 | 24 | namespace breadboard { 25 | 26 | /// @brief Initialize the debug module. 27 | /// 28 | /// @param[in,out] module_registry The ModuleRegistry that will hold the module 29 | /// registered by this function. 30 | void InitializeDebugModule(ModuleRegistry* module_registry); 31 | 32 | } // namespace breadboard 33 | 34 | #endif // BREADBOARD_MODULES_DEBUG_H_ 35 | -------------------------------------------------------------------------------- /include/breadboard/modules/logic.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULES_LOGIC_H_ 16 | #define BREADBOARD_MODULES_LOGIC_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | /// @file breadboard/modules/logic.h 21 | /// 22 | /// @brief Initialize the logic module. 23 | 24 | namespace breadboard { 25 | 26 | /// @brief Initialize the logic module. 27 | /// 28 | /// @param[in,out] module_registry The ModuleRegistry that will hold the module 29 | /// registered by this function. 30 | void InitializeLogicModule(ModuleRegistry* module_registry); 31 | 32 | } // namespace breadboard 33 | 34 | #endif // BREADBOARD_MODULES_LOGIC_H_ 35 | -------------------------------------------------------------------------------- /include/breadboard/modules/math.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULES_MATH_H_ 16 | #define BREADBOARD_MODULES_MATH_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | /// @file breadboard/modules/math.h 21 | /// 22 | /// @brief Initialize the integer and floating point math modules. 23 | 24 | namespace breadboard { 25 | 26 | /// @brief Initialize the integer math module. 27 | /// 28 | /// @param[in,out] module_registry The ModuleRegistry that will hold the module 29 | /// registered by this function. 30 | void InitializeIntegerMathModule(ModuleRegistry* module_registry); 31 | 32 | /// @brief Initialize the floating point math module. 33 | /// 34 | /// @param[in,out] module_registry The ModuleRegistry that will hold the module 35 | /// registered by this function. 36 | void InitializeFloatMathModule(ModuleRegistry* module_registry); 37 | 38 | } // namespace breadboard 39 | 40 | #endif // BREADBOARD_MODULES_MATH_H_ 41 | -------------------------------------------------------------------------------- /include/breadboard/modules/string.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_MODULES_STRING_H_ 16 | #define BREADBOARD_MODULES_STRING_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | /// @file breadboard/modules/string.h 21 | /// 22 | /// @brief Initialize the string module. 23 | 24 | namespace breadboard { 25 | 26 | /// @brief Initialize the string module. 27 | /// 28 | /// @param[in,out] module_registry The ModuleRegistry that will hold the module 29 | /// registered by this function. 30 | void InitializeStringModule(ModuleRegistry* module_registry); 31 | 32 | } // namespace breadboard 33 | 34 | #endif // BREADBOARD_MODULES_STRING_H_ 35 | -------------------------------------------------------------------------------- /include/breadboard/type.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_TYPE_H_ 16 | #define BREADBOARD_TYPE_H_ 17 | 18 | #include 19 | #include 20 | 21 | /// @file breadboard/type.h 22 | /// 23 | /// @brief Metadata about types that are used as input and output edge 24 | /// parameters on nodes. 25 | 26 | namespace breadboard { 27 | 28 | /// @typedef PlacementNewFunc 29 | /// 30 | /// @brief A typedef for a function pointer that allocates a type at the given 31 | /// memory address. 32 | typedef void (*PlacementNewFunc)(uint8_t*); 33 | 34 | /// @typedef OperatorDeleteFunc 35 | /// 36 | /// @brief A typedef for a function pointer that deletes an object at the given 37 | /// memory address. 38 | typedef void (*OperatorDeleteFunc)(uint8_t*); 39 | 40 | /// @struct Type 41 | /// 42 | /// @brief Metadata about types that are used as input and output edge 43 | /// parameters on nodes. 44 | /// 45 | /// Type specifies the size and alignment of a given type, as well as how 46 | /// to construct them using placement new in a buffer. By default they use 47 | /// DefaultPlacementNew, which simply constucts an object at the given address. 48 | /// If the default constructor can not be used, custom a PlacementNewFunc may be 49 | /// supplied. 50 | /// 51 | /// @note This class should not be instantiated directly. Instead, Types should 52 | /// be registered through the TypeRegistry. 53 | struct Type { 54 | Type() {} 55 | 56 | /// @brief Construct a Type object with the given metadata. 57 | /// 58 | /// @param[in] name_ The name of the type. 59 | /// 60 | /// @param[in] size_ The size of the type in bytes. 61 | /// 62 | /// @param[in] alignment_ The byte alignment of the type. 63 | /// 64 | /// @param[in] placement_new_func_ The function used to construct an instance 65 | /// of the type. 66 | /// 67 | /// @param[in] operator_delete_func_ The function used to delete and instance 68 | /// of the Type. 69 | Type(const char* name_, size_t size_, size_t alignment_, 70 | PlacementNewFunc placement_new_func_, 71 | OperatorDeleteFunc operator_delete_func_) 72 | : name(name_), 73 | size(size_), 74 | alignment(alignment_), 75 | placement_new_func(placement_new_func_), 76 | operator_delete_func(operator_delete_func_) {} 77 | 78 | /// @brief The name of the type. 79 | const char* name; 80 | 81 | /// @brief The size of the type in bytes. 82 | size_t size; 83 | 84 | /// @brief The byte alignment of the type. 85 | size_t alignment; 86 | 87 | /// @brief The function used to construct an instance of the type. 88 | PlacementNewFunc placement_new_func; 89 | 90 | /// @brief The function used to delete and instance of the Type. 91 | OperatorDeleteFunc operator_delete_func; 92 | }; 93 | 94 | } // namespace breadboard 95 | 96 | #endif // BREADBOARD_TYPE_H_ 97 | -------------------------------------------------------------------------------- /include/breadboard/type_registry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_TYPE_REGISTRY_H_ 16 | #define BREADBOARD_TYPE_REGISTRY_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "breadboard/type.h" 22 | 23 | /// @file breadboard/type_registry.h 24 | /// 25 | /// @brief The TypeRegistry class acts as a static type id storage. 26 | 27 | namespace breadboard { 28 | 29 | /// @class TypeRegistry 30 | /// 31 | /// @brief Types that are to be used as input and output edge parameters on 32 | /// nodes must be registered with the TypeRegistry. 33 | /// 34 | /// Typical registration is as follows: 35 | /// 36 | /// ~~~{.cpp} 37 | /// TypeRegistry::RegisterType("CustomType"); 38 | /// ~~~ 39 | /// 40 | /// Once a type is registered it can be used in Breadboard nodes on input and 41 | /// output parameters. All types, even primitives like ints and floats must be 42 | /// registered or nodes may not use them as parameters. 43 | /// 44 | /// @note The TypeRegistry class a static consisting entirely of static fucntions 45 | /// and is not meant to be instantiated. 46 | template 47 | struct TypeRegistry { 48 | /// @brief Register a type with Breadboard so that it may be used as input and 49 | /// output edge parameters. 50 | /// 51 | /// @note By default, placement new with the default constructor is used to 52 | /// create an instance of the type, while a direct call to the constructor 53 | /// is used to destroy an instance of the type. If a custom constructor 54 | /// or destructor call is required, you may supply a PlacementNewFunc and 55 | /// OperatorDeleteFunc. 56 | /// 57 | /// @param[in] name The name of the type 58 | /// 59 | /// @param[in] placement_new_func The function to use to create a new EdgeType 60 | /// object 61 | /// 62 | /// @param[in] operator_delete_func The function to use to destroy a EdgeType 63 | /// object 64 | static void RegisterType(const char* name, 65 | const PlacementNewFunc& placement_new_func, 66 | const OperatorDeleteFunc& operator_delete_func) { 67 | assert(!initialized_); 68 | initialized_ = true; 69 | type_ = Type(name, sizeof(EdgeType), std::alignment_of::value, 70 | placement_new_func, operator_delete_func); 71 | } 72 | 73 | /// @brief Register a type with Breadboard so that it may be used as input and 74 | /// output edge parameters. 75 | /// 76 | /// @note By default, placement new with the default constructor is used to 77 | /// create an instance of the type, while a direct call to the constructor 78 | /// is used to destroy an instance of the type. If a custom constructor 79 | /// or destructor call is required, you may supply a PlacementNewFunc and 80 | /// OperatorDeleteFunc. 81 | /// 82 | /// @param[in] name The name of the type 83 | /// 84 | /// @param[in] placement_new_func The function to use to create a new EdgeType 85 | /// object 86 | static void RegisterType(const char* name, 87 | const PlacementNewFunc& placement_new_func) { 88 | RegisterType(name, placement_new_func, DefaultOperatorDelete); 89 | } 90 | 91 | /// @brief Register a type with Breadboard so that it may be used as input and 92 | /// output edge parameters. 93 | /// 94 | /// @note By default, placement new with the default constructor is used to 95 | /// create an instance of the type, while a direct call to the constructor 96 | /// is used to destroy an instance of the type. If a custom constructor 97 | /// or destructor call is required, you may supply a PlacementNewFunc and 98 | /// OperatorDeleteFunc. 99 | /// 100 | /// @param[in] name The name of the type 101 | static void RegisterType(const char* name) { 102 | RegisterType(name, DefaultPlacementNew); 103 | } 104 | 105 | /// @brief Return the Type object that represents EdgeType. 106 | /// 107 | /// @return The Type object that represents EdgeType. 108 | static const Type* GetType() { return &type_; } 109 | 110 | private: 111 | static Type type_; 112 | static bool initialized_; 113 | 114 | static void DefaultPlacementNew(uint8_t* ptr) { new (ptr) EdgeType(); } 115 | 116 | static void DefaultOperatorDelete(uint8_t* ptr) { 117 | (void)ptr; 118 | reinterpret_cast(ptr)->~EdgeType(); 119 | } 120 | 121 | TypeRegistry(); 122 | }; 123 | 124 | template 125 | Type TypeRegistry::type_; 126 | 127 | template 128 | bool TypeRegistry::initialized_ = false; 129 | 130 | /// @class TypeRegistry 131 | /// 132 | /// @brief A specialization of TypeRegistry for implementing the `void` type. 133 | /// 134 | /// There are cases where one might want to force a node to to be marked dirty 135 | /// without passing any data to it. Registering a void type and using that as 136 | /// an input to a node would allow that. However, as void has no sizeof or 137 | /// alignment and should not be allocated or deleted, it needs to be handled 138 | /// specially. 139 | /// 140 | /// See TypeRegistry for more details. 141 | template <> 142 | struct TypeRegistry { 143 | /// Register the `void` type with the TypeRegistry so that it may be used to 144 | /// pass data from one node to another. No custom placement new or operator 145 | /// delete functions may be specified. 146 | static void RegisterType(const char* name) { 147 | assert(!initialized_); 148 | static const size_t kVoidSize = 0; 149 | static const size_t kVoidAlignment = 1; 150 | initialized_ = true; 151 | type_ = Type(name, kVoidSize, kVoidAlignment, VoidPlacementNew, 152 | VoidOperatorDelete); 153 | } 154 | 155 | /// @brief Return the Type object that represents the type `void`. 156 | /// 157 | /// @return The Type object that represents the type `void`. 158 | static const Type* GetType() { return &type_; } 159 | 160 | private: 161 | static Type type_; 162 | static bool initialized_; 163 | 164 | // Do nothing. 165 | static void VoidPlacementNew(uint8_t*) {} 166 | static void VoidOperatorDelete(uint8_t*) {} 167 | 168 | TypeRegistry(); 169 | }; 170 | 171 | } // namespace breadboard 172 | 173 | #endif // BREADBOARD_TYPE_REGISTRY_H_ 174 | -------------------------------------------------------------------------------- /include/breadboard/version.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BREADBOARD_VERSION_H_ 16 | #define BREADBOARD_VERSION_H_ 17 | 18 | /// @file breadboard/version.h 19 | /// @brief A structure containing the version number of the Breadboard library. 20 | 21 | namespace breadboard { 22 | 23 | /// @struct BreadboardVersion 24 | /// 25 | /// @brief A structure containing the version number of the Breadboard library. 26 | struct BreadboardVersion { 27 | /// @brief Version number, updated only on major releases. 28 | unsigned char major; 29 | 30 | /// @brief Version number, updated for point releases. 31 | unsigned char minor; 32 | 33 | /// @brief Version number, updated for tiny releases, for example, bug fixes. 34 | unsigned char revision; 35 | 36 | /// @brief Text string holding the name and version of library. 37 | const char* text; 38 | }; 39 | 40 | /// @brief Returns the version struct. 41 | /// 42 | /// @return The version struct. 43 | const BreadboardVersion& Version(); 44 | 45 | } // namespace breadboard 46 | 47 | #endif // BREADBOARD_VERSION_H_ 48 | -------------------------------------------------------------------------------- /jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # TODO: Remove when the LOCAL_PATH expansion bug in the NDK is fixed. 16 | # Portable version of $(realpath) that omits drive letters on Windows. 17 | realpath-portable = $(join $(filter %:,$(subst :,: ,$1)),\ 18 | $(realpath $(filter-out %:,$(subst :,: ,$1)))) 19 | 20 | LOCAL_PATH := $(call realpath-portable,$(call my-dir)/..) 21 | 22 | BREADBOARD_DIR := $(LOCAL_PATH) 23 | include $(BREADBOARD_DIR)/jni/android_config.mk 24 | 25 | include $(CLEAR_VARS) 26 | LOCAL_MODULE := breadboard 27 | LOCAL_ARM_MODE := arm 28 | 29 | LOCAL_EXPORT_C_INCLUDES := $(BREADBOARD_DIR)/include 30 | 31 | LOCAL_C_INCLUDES := \ 32 | $(DEPENDENCIES_FPLUTIL_DIR)/libfplutil/include \ 33 | $(BREADBOARD_DIR)/src \ 34 | $(LOCAL_EXPORT_C_INCLUDES) 35 | 36 | LOCAL_SRC_FILES := \ 37 | src/breadboard/event.cpp \ 38 | src/breadboard/graph.cpp \ 39 | src/breadboard/graph_factory.cpp \ 40 | src/breadboard/graph_state.cpp \ 41 | src/breadboard/log.cpp \ 42 | src/breadboard/module.cpp \ 43 | src/breadboard/module_registry.cpp \ 44 | src/breadboard/node.cpp \ 45 | src/breadboard/node_arguments.cpp \ 46 | src/breadboard/node_signature.cpp \ 47 | src/breadboard/type_registry.cpp \ 48 | src/breadboard/version.cpp \ 49 | src/modules/common.cpp \ 50 | src/modules/debug.cpp \ 51 | src/modules/logic.cpp \ 52 | src/modules/math.cpp \ 53 | src/modules/string.cpp 54 | 55 | include $(BUILD_STATIC_LIBRARY) 56 | -------------------------------------------------------------------------------- /jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | APP_STL:=c++_static 16 | APP_ABI := armeabi-v7a x86 armeabi 17 | 18 | APP_CPPFLAGS += -std=c++11 -Wno-literal-suffix 19 | 20 | APP_MODULES:=libbreadboard 21 | 22 | APP_PLATFORM := android-15 23 | -------------------------------------------------------------------------------- /jni/android_config.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | include $(call my-dir)/find_fplutil.mk 16 | include $(FPLUTIL_DIR)/buildutil/android_common.mk 17 | -------------------------------------------------------------------------------- /jni/find_fplutil.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Find the fplutil directory and set it in `FPLUTIL_DIR`. 16 | # 17 | # We search some standard locations, such as 18 | # (1) the variable $(DEPENDENCIES_ROOT), which can be specified 19 | # in an environment variable, 20 | # (2) the "dependencies" directory that gets created when cloning from GitHub, 21 | # (3) several levels up in the directory tree. 22 | # 23 | # Notes 24 | # ----- 25 | # - fplutil is the project where we keep all our shared code, so the code in 26 | # this file (which locates fplutil) can unfortunately not be shared. 27 | # - Since this file is duplicated in all FPL projects (except fplutil itself), 28 | # please copy new versions to all FPL projects whenever you make a change. 29 | 30 | FIND_FPLUTIL_DIR:=$(call my-dir) 31 | 32 | $(foreach dir,$(wildcard $(DEPENDENCIES_ROOT)) \ 33 | $(wildcard $(FIND_FPLUTIL_DIR)/../dependencies/fplutil) \ 34 | $(wildcard $(FIND_FPLUTIL_DIR)/../../dependencies/fplutil) \ 35 | $(wildcard $(FIND_FPLUTIL_DIR)/../fplutil) \ 36 | $(wildcard $(FIND_FPLUTIL_DIR)/../../fplutil) \ 37 | $(wildcard $(FIND_FPLUTIL_DIR)/../../../fplutil) \ 38 | $(wildcard $(FIND_FPLUTIL_DIR)/../../../../fplutil),\ 39 | $(eval FPLUTIL_DIR?=$(dir))) 40 | 41 | ifeq ($(FPLUTIL_DIR),) 42 | ifndef (FIND_FPLUTIL_OK_IF_NOT_FOUND) 43 | $(error "Cannot file fplutil project.") 44 | endif 45 | endif 46 | -------------------------------------------------------------------------------- /module_library/include/module_library/animation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_ANIMATION_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_ANIMATION_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/animation.h" 20 | #include "corgi_component_library/graph.h" 21 | #include "corgi_component_library/transform.h" 22 | #include "module_library/entity.h" 23 | 24 | namespace breadboard { 25 | namespace module_library { 26 | 27 | void InitializeAnimationModule( 28 | breadboard::ModuleRegistry* module_registry, 29 | corgi::component_library::GraphComponent* graph_component, 30 | corgi::component_library::AnimationComponent* anim_component, 31 | corgi::component_library::TransformComponent* transform_component); 32 | 33 | } // namespace module_library 34 | } // namespace breadboard 35 | 36 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_ANIMATION_H_ 37 | -------------------------------------------------------------------------------- /module_library/include/module_library/audio.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_AUDIO_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_AUDIO_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "pindrop/pindrop.h" 20 | 21 | namespace breadboard { 22 | namespace module_library { 23 | 24 | void InitializeAudioModule(breadboard::ModuleRegistry* module_registry, 25 | pindrop::AudioEngine* audio_engine); 26 | 27 | } // namespace module_library 28 | } // namespace breadboard 29 | 30 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_AUDIO_H_ 31 | -------------------------------------------------------------------------------- /module_library/include/module_library/default_graph_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_DEFAULT_GRAPH_FACTORY_H_ 16 | #define FPL_BREADBOARD_DEFAULT_GRAPH_FACTORY_H_ 17 | 18 | #include 19 | 20 | #include "breadboard/graph.h" 21 | #include "breadboard/graph_factory.h" 22 | #include "breadboard/module_registry.h" 23 | #include "pindrop/pindrop.h" 24 | 25 | namespace breadboard { 26 | namespace module_library { 27 | 28 | class DefaultGraphFactory : public breadboard::GraphFactory { 29 | public: 30 | DefaultGraphFactory(breadboard::ModuleRegistry* module_registry, 31 | breadboard::LoadFileCallback load_file_callback) 32 | : breadboard::GraphFactory(module_registry, load_file_callback) {} 33 | virtual ~DefaultGraphFactory() {} 34 | 35 | #ifdef BREADBOARD_MODULE_LIBRARY_BUILD_PINDROP 36 | void set_audio_engine(pindrop::AudioEngine* audio_engine) { 37 | audio_engine_ = audio_engine; 38 | } 39 | pindrop::AudioEngine* audio_engine() { 40 | return audio_engine_; 41 | } 42 | #endif // BREADBOARD_MODULE_LIBRARY_BUILD_PINDROP 43 | 44 | private: 45 | virtual bool ParseData(breadboard::ModuleRegistry* module_registry, 46 | breadboard::Graph* graph, const std::string* data); 47 | 48 | #ifdef BREADBOARD_MODULE_LIBRARY_BUILD_PINDROP 49 | pindrop::AudioEngine* audio_engine_; 50 | #endif // BREADBOARD_MODULE_LIBRARY_BUILD_PINDROP 51 | }; 52 | 53 | } // module_library 54 | } // breadboard 55 | 56 | #endif // FPL_BREADBOARD_DEFAULT_GRAPH_FACTORY_H_ 57 | -------------------------------------------------------------------------------- /module_library/include/module_library/entity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_ENTITY_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_ENTITY_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/graph.h" 20 | #include "corgi_component_library/meta.h" 21 | #include "corgi/entity_manager.h" 22 | 23 | namespace breadboard { 24 | namespace module_library { 25 | 26 | void SetGraphEntity(::corgi::EntityRef entity); 27 | 28 | void InitializeEntityModule( 29 | breadboard::ModuleRegistry* module_registry, 30 | ::corgi::EntityManager* entity_manager, 31 | ::corgi::component_library::MetaComponent* meta_component, 32 | ::corgi::component_library::GraphComponent* graph_component); 33 | 34 | } // namespace module_library 35 | } // namespace breadboard 36 | 37 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_ENTITY_H_ 38 | -------------------------------------------------------------------------------- /module_library/include/module_library/physics.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_PHYSICS_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_PHYSICS_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/graph.h" 20 | #include "corgi_component_library/physics.h" 21 | #include "module_library/entity.h" 22 | 23 | namespace breadboard { 24 | namespace module_library { 25 | 26 | void InitializePhysicsModule( 27 | breadboard::ModuleRegistry* module_registry, 28 | corgi::component_library::PhysicsComponent* physics_component, 29 | corgi::component_library::GraphComponent* graph_component); 30 | 31 | } // namespace module_library 32 | } // namespace breadboard 33 | 34 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_PHYSICS_H_ 35 | -------------------------------------------------------------------------------- /module_library/include/module_library/rendermesh.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_RENDERMESH_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_RENDERMESH_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/rendermesh.h" 20 | 21 | namespace breadboard { 22 | namespace module_library { 23 | 24 | void InitializeRenderMeshModule( 25 | breadboard::ModuleRegistry* module_registry, 26 | ::corgi::component_library::RenderMeshComponent* render_mesh_component); 27 | 28 | } // namespace module_library 29 | } // namespace breadboard 30 | 31 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_RENDERMESH_H_ 32 | -------------------------------------------------------------------------------- /module_library/include/module_library/transform.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_TRANSFORM_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_TRANSFORM_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/transform.h" 20 | #include "module_library/entity.h" 21 | 22 | namespace breadboard { 23 | namespace module_library { 24 | 25 | void InitializeTransformModule( 26 | breadboard::ModuleRegistry* module_registry, 27 | corgi::component_library::TransformComponent* transform_component); 28 | 29 | } // namespace module_library 30 | } // namespace breadboard 31 | 32 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_TRANSFORM_H_ 33 | -------------------------------------------------------------------------------- /module_library/include/module_library/vec.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef FPL_BREADBOARD_MODULE_LIBRARY_VEC_H_ 16 | #define FPL_BREADBOARD_MODULE_LIBRARY_VEC_H_ 17 | 18 | #include "breadboard/module_registry.h" 19 | 20 | namespace breadboard { 21 | namespace module_library { 22 | 23 | void InitializeVecModule(breadboard::ModuleRegistry* module_registry); 24 | 25 | } // namespace module_library 26 | } // namespace breadboard 27 | 28 | #endif // FPL_BREADBOARD_MODULE_LIBRARY_VEC_H_ 29 | -------------------------------------------------------------------------------- /module_library/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir)/.. 16 | 17 | BREADBOARD_MODULE_LIBRARY_DIR := $(LOCAL_PATH) 18 | 19 | include $(BREADBOARD_MODULE_LIBRARY_DIR)/jni/android_config.mk 20 | include $(DEPENDENCIES_FLATBUFFERS_DIR)/android/jni/include.mk 21 | 22 | # realpath-portable From flatbuffers/android/jni/include.mk 23 | LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH)) 24 | BREADBOARD_MODULE_LIBRARY_DIR := $(LOCAL_PATH) 25 | 26 | include $(CLEAR_VARS) 27 | 28 | LOCAL_MODULE := breadboard_module_library 29 | LOCAL_ARM_MODE := arm 30 | LOCAL_STATIC_LIBRARIES := \ 31 | libcorgi_component_library \ 32 | libpindrop \ 33 | libbreadboard \ 34 | libmathfu 35 | LOCAL_SHARED_LIBRARIES := 36 | 37 | LOCAL_CPPFLAGS := \ 38 | -DBREADBOARD_MODULE_LIBRARY_BUILD_MATHFU \ 39 | -DBREADBOARD_MODULE_LIBRARY_BUILD_CORGI_COMPONENT_LIBRARY \ 40 | -DBREADBOARD_MODULE_LIBRARY_BUILD_PINDROP 41 | 42 | LOCAL_EXPORT_CPPFLAGS := $(LOCAL_CPPFLAGS) 43 | 44 | BREADBOARD_MODULE_LIBRARY_GENERATED_OUTPUT_DIR := \ 45 | $(BREADBOARD_MODULE_LIBRARY_DIR)/gen/include 46 | 47 | LOCAL_EXPORT_C_INCLUDES := \ 48 | $(DEPENDENCIES_FPLUTIL_DIR)/libfplutil/include \ 49 | $(BREADBOARD_MODULE_LIBRARY_DIR)/include \ 50 | $(BREADBOARD_MODULE_LIBRARY_GENERATED_OUTPUT_DIR) 51 | 52 | LOCAL_C_INCLUDES := \ 53 | $(LOCAL_EXPORT_C_INCLUDES) \ 54 | $(DEPENDENCIES_BULLETPHYSICS_DIR)/src \ 55 | $(DEPENDENCIES_CORGI_DIR)/include \ 56 | $(DEPENDENCIES_CORGI_DIR)/component_library/include \ 57 | $(DEPENDENCIES_FLATBUFFERS_DIR)/include \ 58 | $(DEPENDENCIES_MATHFU_DIR)/include \ 59 | $(DEPENDENCIES_MOTIVE_DIR)/include \ 60 | $(DEPENDENCIES_PINDROP_DIR)/include \ 61 | $(DEPENDENCIES_FPLBASE_DIR)/include 62 | 63 | LOCAL_SRC_FILES := \ 64 | src/animation.cpp \ 65 | src/audio.cpp \ 66 | src/entity.cpp \ 67 | src/physics.cpp \ 68 | src/rendermesh.cpp \ 69 | src/transform.cpp \ 70 | src/vec.cpp 71 | 72 | BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR := \ 73 | $(BREADBOARD_MODULE_LIBRARY_DIR)/schemas 74 | BREADBOARD_MODULE_LIBRARY_SCHEMA_INCLUDE_DIRS := \ 75 | $(DEPENDENCIES_FPLBASE_DIR)/schemas 76 | 77 | BREADBOARD_MODULE_LIBRARY_SCHEMA_FILES := \ 78 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR)/common_modules.fbs \ 79 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR)/corgi_module.fbs \ 80 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR)/mathfu_module.fbs \ 81 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR)/pindrop_module.fbs 82 | 83 | ifeq (,$(BREADBOARD_MODULE_LIBRARY_RUN_ONCE)) 84 | BREADBOARD_MODULE_LIBRARY_RUN_ONCE := 1 85 | $(call flatbuffers_header_build_rules,\ 86 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_FILES),\ 87 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_DIR),\ 88 | $(BREADBOARD_MODULE_LIBRARY_GENERATED_OUTPUT_DIR),\ 89 | $(BREADBOARD_MODULE_LIBRARY_SCHEMA_INCLUDE_DIRS),\ 90 | $(LOCAL_SRC_FILES),\ 91 | breadboard_module_library_generated_includes,\ 92 | corgi_component_library_generated_includes \ 93 | fplbase_generated_includes) 94 | endif 95 | 96 | include $(BUILD_STATIC_LIBRARY) 97 | 98 | $(call import-add-path,$(DEPENDENCIES_BREADBOARD_DIR)/..) 99 | $(call import-add-path,$(DEPENDENCIES_FPLBASE_DIR)/..) 100 | $(call import-add-path,$(DEPENDENCIES_FLATBUFFERS_DIR)/..) 101 | $(call import-add-path,$(DEPENDENCIES_MATHFU_DIR)/..) 102 | $(call import-add-path,$(DEPENDENCIES_PINDROP_DIR)/..) 103 | $(call import-add-path,$(DEPENDENCIES_CORGI_DIR)/..) 104 | 105 | $(call import-module,fplbase/jni) 106 | $(call import-module,flatbuffers/android/jni) 107 | $(call import-module,mathfu/jni) 108 | $(call import-module,breadboard/jni) 109 | $(call import-module,corgi/component_library/jni) 110 | $(call import-module,android/cpufeatures) 111 | -------------------------------------------------------------------------------- /module_library/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | APP_STL:=c++_static 16 | APP_ABI := armeabi-v7a x86 armeabi 17 | 18 | APP_CPPFLAGS += -std=c++11 -Wno-literal-suffix 19 | 20 | APP_MODULES:=libbreadboard_module_library 21 | 22 | APP_PLATFORM := android-15 23 | -------------------------------------------------------------------------------- /module_library/jni/android_config.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Locations of 3rd party and FPL libraries. 16 | BREADBOARD_DIR:=$(BREADBOARD_MODULE_LIBRARY_DIR)/.. 17 | FPL_ROOT:=$(BREADBOARD_MODULE_LIBRARY_DIR)/../../../libs 18 | # If the dependencies directory exists either as a subdirectory or as the 19 | # container of this project directory, assume the dependencies directory is 20 | # the root directory for all libraries required by this project. 21 | $(foreach dep_dir,\ 22 | $(wildcard $(BREADBOARD_DIR)/dependencies) \ 23 | $(wildcard $(BREADBOARD_DIR)/../../dependencies),\ 24 | $(eval DEPENDENCIES_ROOT?=$(dep_dir))) 25 | ifneq ($(DEPENDENCIES_ROOT),) 26 | THIRD_PARTY_ROOT:=$(DEPENDENCIES_ROOT) 27 | FPL_ROOT:=$(DEPENDENCIES_ROOT) 28 | else 29 | THIRD_PARTY_ROOT:=$(FPL_ROOT)/../../../external 30 | endif 31 | 32 | # Location of the Flatbuffers library. 33 | DEPENDENCIES_FLATBUFFERS_DIR?=$(FPL_ROOT)/flatbuffers 34 | # Location of the fplutil library. 35 | DEPENDENCIES_FPLUTIL_DIR?=$(FPL_ROOT)/fplutil 36 | # Location of the googletest library. 37 | DEPENDENCIES_GTEST_DIR?=$(FPL_ROOT)/fplutil/libfplutil/jni/libs/googletest 38 | # Location of the fplbase library. 39 | DEPENDENCIES_FPLBASE_DIR?=$(FPL_ROOT)/fplbase 40 | # Location of the MathFu library. 41 | DEPENDENCIES_MATHFU_DIR?=$(FPL_ROOT)/mathfu 42 | # Location of the Breadboard library. 43 | DEPENDENCIES_BREADBOARD_DIR?=$(BREADBOARD_DIR) 44 | # Location of the Pindrop library. 45 | DEPENDENCIES_PINDROP_DIR?=$(FPL_ROOT)/pindrop 46 | # Location of the Motive library. 47 | DEPENDENCIES_MOTIVE_DIR?=$(FPL_ROOT)/motive 48 | # Location of the CORGI library. 49 | DEPENDENCIES_CORGI_DIR?=$(FPL_ROOT)/corgi 50 | # Location of the Bullet Physics library. 51 | DEPENDENCIES_BULLETPHYSICS_DIR?=$(THIRD_PARTY_ROOT)/bulletphysics 52 | -------------------------------------------------------------------------------- /module_library/schemas/common_modules.fbs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace breadboard.module_library; 16 | 17 | table OutputEdgeTarget { 18 | node_index:int; 19 | edge_index:int; 20 | } 21 | 22 | table Pulse { 23 | } 24 | 25 | table Bool { 26 | value:bool; 27 | } 28 | 29 | table Int { 30 | value:int; 31 | } 32 | 33 | table Float { 34 | value:float; 35 | } 36 | 37 | table String { 38 | value:string; 39 | } 40 | -------------------------------------------------------------------------------- /module_library/schemas/corgi_module.fbs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace breadboard.module_library; 16 | 17 | table Entity { 18 | } 19 | -------------------------------------------------------------------------------- /module_library/schemas/mathfu_module.fbs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | include "common.fbs"; 16 | 17 | namespace breadboard.module_library; 18 | 19 | table Vec3 { 20 | value:fplbase.Vec3; 21 | } 22 | 23 | table Vec4 { 24 | value:fplbase.Vec4; 25 | } 26 | -------------------------------------------------------------------------------- /module_library/schemas/pindrop_module.fbs: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | namespace breadboard.module_library; 16 | 17 | table SoundHandle { 18 | value:string; 19 | } 20 | 21 | table AudioChannel { 22 | } 23 | -------------------------------------------------------------------------------- /module_library/src/animation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/animation.h" 16 | 17 | #include 18 | 19 | #include "breadboard/base_node.h" 20 | #include "breadboard/module_registry.h" 21 | #include "corgi/entity_manager.h" 22 | #include "corgi_component_library/animation.h" 23 | #include "corgi_component_library/meta.h" 24 | #include "corgi_component_library/transform.h" 25 | 26 | namespace breadboard { 27 | namespace module_library { 28 | 29 | using breadboard::BaseNode; 30 | using breadboard::ModuleRegistry; 31 | using breadboard::Module; 32 | using breadboard::NodeArguments; 33 | using breadboard::NodeSignature; 34 | using corgi::EntityRef; 35 | using corgi::component_library::AnimationComponent; 36 | using corgi::component_library::GraphComponent; 37 | using corgi::component_library::kAnimationCompleteEventId; 38 | using corgi::component_library::TransformComponent; 39 | 40 | static inline EntityRef ChildAnimEntity(TransformComponent* transform_component, 41 | const EntityRef& entity) { 42 | EntityRef anim_entity = transform_component->ChildWithComponent( 43 | entity, AnimationComponent::GetComponentId()); 44 | assert(anim_entity.IsValid()); 45 | return anim_entity; 46 | } 47 | 48 | // Executes when the animation on the given entity is complete. 49 | class AnimationCompleteNode : public BaseNode { 50 | public: 51 | enum { kInputEntity }; 52 | enum { kOutputAnimationComplete }; 53 | enum { kListenerAnimationComplete }; 54 | 55 | explicit AnimationCompleteNode(GraphComponent* graph_component) 56 | : graph_component_(graph_component) {} 57 | 58 | static void OnRegister(NodeSignature* node_sig) { 59 | node_sig->AddInput(kInputEntity, "Entity"); 60 | node_sig->AddOutput(kOutputAnimationComplete, "Animation Complete"); 61 | node_sig->AddListener(kListenerAnimationComplete, 62 | kAnimationCompleteEventId); 63 | } 64 | 65 | virtual void Initialize(NodeArguments* args) { 66 | EntityRef entity = *args->GetInput(kInputEntity); 67 | if (entity) { 68 | args->BindBroadcaster(kListenerAnimationComplete, 69 | graph_component_->GetCreateBroadcaster(entity)); 70 | } 71 | } 72 | 73 | virtual void Execute(NodeArguments* args) { 74 | Initialize(args); 75 | if (args->IsListenerDirty(kListenerAnimationComplete)) { 76 | args->SetOutput(kOutputAnimationComplete); 77 | } 78 | } 79 | 80 | private: 81 | GraphComponent* graph_component_; 82 | }; 83 | 84 | // Starts the requested animation on the requested entity. 85 | class PlayAnimationNode : public BaseNode { 86 | public: 87 | enum { kInputTrigger, kInputEntity, kInputAnimIndex }; 88 | enum { kOutputTrigger }; 89 | 90 | PlayAnimationNode(AnimationComponent* anim_component, 91 | TransformComponent* transform_component) 92 | : anim_component_(anim_component), 93 | transform_component_(transform_component) {} 94 | 95 | static void OnRegister(NodeSignature* node_sig) { 96 | // Void to trigger the animation, 97 | // the entity to be animated, 98 | // and the index into the AnimTable for this entity. 99 | node_sig->AddInput(kInputTrigger, "Trigger", "Trigger the animation"); 100 | node_sig->AddInput(kInputEntity, "Entity", 101 | "The entity to animate"); 102 | node_sig->AddInput(kInputAnimIndex, "Animation Index", 103 | "The animation index to play"); 104 | node_sig->AddOutput(kOutputTrigger); 105 | } 106 | 107 | virtual void Execute(NodeArguments* args) { 108 | if (args->IsInputDirty(kInputTrigger)) { 109 | EntityRef entity = *args->GetInput(kInputEntity); 110 | EntityRef anim_entity = ChildAnimEntity(transform_component_, entity); 111 | const int current_anim_idx = anim_component_->LastAnimIdx(anim_entity); 112 | int anim_idx = *args->GetInput(kInputAnimIndex); 113 | if (current_anim_idx != anim_idx) { 114 | anim_component_->AnimateFromTable(anim_entity, anim_idx); 115 | } 116 | args->SetOutput(kOutputTrigger); 117 | } 118 | } 119 | 120 | private: 121 | AnimationComponent* anim_component_; 122 | TransformComponent* transform_component_; 123 | }; 124 | 125 | // Returns the index of the last animation played. 126 | class AnimationIndexNode : public breadboard::BaseNode { 127 | public: 128 | enum { kInputTrigger, kInputEntity }; 129 | enum { kOutputAnimIndex }; 130 | 131 | AnimationIndexNode(AnimationComponent* anim_component, 132 | TransformComponent* transform_component) 133 | : anim_component_(anim_component), 134 | transform_component_(transform_component) {} 135 | 136 | static void OnRegister(breadboard::NodeSignature* node_sig) { 137 | // Void to trigger the animation, 138 | // the entity to be animated, 139 | // and the index into the AnimTable for this entity. 140 | node_sig->AddInput(kInputTrigger, "Trigger"); 141 | node_sig->AddInput(kInputEntity, "Entity"); 142 | node_sig->AddOutput(kOutputAnimIndex, "Trigger"); 143 | } 144 | 145 | virtual void Execute(breadboard::NodeArguments* args) { 146 | if (args->IsInputDirty(kInputTrigger)) { 147 | EntityRef entity = *args->GetInput(kInputEntity); 148 | EntityRef anim_entity = ChildAnimEntity(transform_component_, entity); 149 | const int anim_idx = anim_component_->LastAnimIdx(anim_entity); 150 | args->SetOutput(kOutputAnimIndex, anim_idx); 151 | } 152 | } 153 | 154 | private: 155 | AnimationComponent* anim_component_; 156 | TransformComponent* transform_component_; 157 | }; 158 | 159 | void InitializeAnimationModule(ModuleRegistry* module_registry, 160 | GraphComponent* graph_component, 161 | AnimationComponent* anim_component, 162 | TransformComponent* transform_component) { 163 | auto animation_complete_ctor = [graph_component]() { 164 | return new AnimationCompleteNode(graph_component); 165 | }; 166 | auto play_animation_ctor = [anim_component, transform_component]() { 167 | return new PlayAnimationNode(anim_component, transform_component); 168 | }; 169 | auto animation_index_ctor = [anim_component, transform_component]() { 170 | return new AnimationIndexNode(anim_component, transform_component); 171 | }; 172 | 173 | Module* module = module_registry->RegisterModule("animation"); 174 | module->RegisterNode("animation_complete", 175 | animation_complete_ctor); 176 | module->RegisterNode("play_animation", 177 | play_animation_ctor); 178 | module->RegisterNode("animation_index", 179 | animation_index_ctor); 180 | } 181 | 182 | } // namespace module_library 183 | } // namespace breadboard 184 | -------------------------------------------------------------------------------- /module_library/src/audio.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/audio.h" 16 | 17 | #include "breadboard/base_node.h" 18 | #include "breadboard/module_registry.h" 19 | #include "breadboard/type_registry.h" 20 | #include "mathfu/glsl_mappings.h" 21 | #include "pindrop/pindrop.h" 22 | 23 | using breadboard::BaseNode; 24 | using breadboard::ModuleRegistry; 25 | using breadboard::Module; 26 | using breadboard::NodeArguments; 27 | using breadboard::NodeSignature; 28 | using breadboard::TypeRegistry; 29 | using mathfu::vec3; 30 | using pindrop::AudioEngine; 31 | using pindrop::Channel; 32 | using pindrop::SoundHandle; 33 | 34 | namespace breadboard { 35 | namespace module_library { 36 | 37 | // Plays the given sound. Also takes a gain and location arguments. 38 | // Returns the channel the sound is playing on as an output. 39 | class PlaySoundNode : public BaseNode { 40 | public: 41 | enum { kInputPlay, kInputSoundHandle, kInputLocation, kInputGain }; 42 | enum { kOutputChannel }; 43 | 44 | PlaySoundNode(AudioEngine* audio_engine) : audio_engine_(audio_engine) {} 45 | 46 | static void OnRegister(NodeSignature* node_sig) { 47 | node_sig->AddInput(kInputPlay, "Play"); 48 | node_sig->AddInput(kInputSoundHandle, "Sound"); 49 | node_sig->AddInput(kInputLocation, "Location"); 50 | node_sig->AddInput(kInputGain, "Gain"); 51 | node_sig->AddOutput(kOutputChannel, "Channel"); 52 | } 53 | 54 | virtual void Execute(NodeArguments* args) { 55 | if (args->IsInputDirty(kInputPlay)) { 56 | auto handle = args->GetInput(kInputSoundHandle); 57 | auto location = args->GetInput(kInputLocation); 58 | auto gain = args->GetInput(kInputGain); 59 | Channel channel = audio_engine_->PlaySound(*handle, *location, *gain); 60 | args->SetOutput(kOutputChannel, channel); 61 | } 62 | } 63 | 64 | private: 65 | AudioEngine* audio_engine_; 66 | }; 67 | 68 | // Checks if a given audio channel is playing. 69 | class PlayingNode : public BaseNode { 70 | public: 71 | enum { kInputChannel }; 72 | enum { kOutputChannel, kOutputPlaying }; 73 | 74 | static void OnRegister(NodeSignature* node_sig) { 75 | node_sig->AddInput(kInputChannel, "Channel"); 76 | node_sig->AddOutput(kOutputChannel, "Channel"); 77 | node_sig->AddOutput(kOutputPlaying, "Result"); 78 | } 79 | 80 | virtual void Execute(NodeArguments* args) { 81 | auto channel = args->GetInput(kInputChannel); 82 | args->SetOutput(kOutputChannel, *channel); 83 | args->SetOutput(kOutputPlaying, channel->Playing()); 84 | } 85 | }; 86 | 87 | // Stops the given audio channel. 88 | class StopNode : public BaseNode { 89 | public: 90 | enum { kInputChannel }; 91 | enum { kOutputChannel }; 92 | 93 | static void OnRegister(NodeSignature* node_sig) { 94 | node_sig->AddInput(kInputChannel, "Channel"); 95 | node_sig->AddOutput(kOutputChannel, "Channel"); 96 | } 97 | 98 | virtual void Execute(NodeArguments* args) { 99 | auto channel = args->GetInput(kInputChannel); 100 | channel->Stop(); 101 | args->SetOutput(kOutputChannel, *channel); 102 | } 103 | }; 104 | 105 | // Set the gain on the given audio channel. 106 | class SetGainNode : public BaseNode { 107 | public: 108 | enum { kInputChannel, kInputGain }; 109 | enum { kOutputChannel }; 110 | 111 | static void OnRegister(NodeSignature* node_sig) { 112 | node_sig->AddInput(kInputChannel, "Channel"); 113 | node_sig->AddInput(kInputGain, "Gain"); 114 | node_sig->AddOutput(kOutputChannel, "Channel"); 115 | } 116 | 117 | virtual void Execute(NodeArguments* args) { 118 | auto channel = args->GetInput(kInputChannel); 119 | auto gain = args->GetInput(kInputGain); 120 | channel->SetGain(*gain); 121 | args->SetOutput(kOutputChannel, *channel); 122 | } 123 | }; 124 | 125 | // Returns the gain of the given audio channel. 126 | class GainNode : public BaseNode { 127 | public: 128 | enum { kInputChannel }; 129 | enum { kOutputChannel, kOutputGain }; 130 | 131 | static void OnRegister(NodeSignature* node_sig) { 132 | node_sig->AddInput(kInputChannel, "Channel"); 133 | node_sig->AddOutput(kOutputChannel, "Channel"); 134 | node_sig->AddOutput(kOutputGain, "Gain"); 135 | } 136 | 137 | virtual void Execute(NodeArguments* args) { 138 | auto channel = args->GetInput(kInputChannel); 139 | args->SetOutput(kOutputChannel, *channel); 140 | args->SetOutput(kOutputGain, channel->Gain()); 141 | } 142 | }; 143 | 144 | // Sets the location of the given sound channel. 145 | class SetLocationNode : public BaseNode { 146 | public: 147 | enum { kInputChannel, kInputLocation }; 148 | enum { kOutputChannel }; 149 | 150 | static void OnRegister(NodeSignature* node_sig) { 151 | node_sig->AddInput(kInputChannel); 152 | node_sig->AddInput(kInputLocation); 153 | node_sig->AddOutput(kOutputChannel); 154 | } 155 | 156 | virtual void Execute(NodeArguments* args) { 157 | auto channel = args->GetInput(kInputChannel); 158 | auto location = args->GetInput(kInputChannel); 159 | channel->SetLocation(*location); 160 | args->SetOutput(kOutputChannel, *channel); 161 | } 162 | }; 163 | 164 | // Returns the location of the given audio channel. 165 | class LocationNode : public BaseNode { 166 | public: 167 | enum { kInputChannel }; 168 | enum { kOutputChannel, kOutputLocation }; 169 | 170 | static void OnRegister(NodeSignature* node_sig) { 171 | node_sig->AddInput(kInputChannel, "Channel"); 172 | node_sig->AddOutput(kOutputChannel, "Channel"); 173 | node_sig->AddOutput(kOutputLocation, "Location"); 174 | } 175 | 176 | virtual void Execute(NodeArguments* args) { 177 | auto channel = args->GetInput(0); 178 | args->SetOutput(0, *channel); 179 | args->SetOutput(1, channel->Location()); 180 | } 181 | }; 182 | 183 | void InitializeAudioModule(ModuleRegistry* module_registry, 184 | AudioEngine* audio_engine) { 185 | auto play_sound_ctor = [audio_engine]() { 186 | return new PlaySoundNode(audio_engine); 187 | }; 188 | TypeRegistry::RegisterType("Channel"); 189 | TypeRegistry::RegisterType("SoundHandle"); 190 | Module* module = module_registry->RegisterModule("audio"); 191 | module->RegisterNode("play_sound", play_sound_ctor); 192 | module->RegisterNode("playing"); 193 | module->RegisterNode("stop"); 194 | module->RegisterNode("set_gain"); 195 | module->RegisterNode("gain"); 196 | module->RegisterNode("set_location"); 197 | module->RegisterNode("location"); 198 | } 199 | 200 | } // namespace module_library 201 | } // namespace breadboard 202 | -------------------------------------------------------------------------------- /module_library/src/entity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/entity.h" 16 | 17 | #include "breadboard/base_node.h" 18 | #include "breadboard/module_registry.h" 19 | #include "corgi_component_library/meta.h" 20 | #include "corgi/entity_manager.h" 21 | #include "mathfu/glsl_mappings.h" 22 | 23 | using breadboard::BaseNode; 24 | using breadboard::ModuleRegistry; 25 | using breadboard::Module; 26 | using breadboard::NodeArguments; 27 | using breadboard::NodeSignature; 28 | using breadboard::TypeRegistry; 29 | using corgi::component_library::GraphComponent; 30 | using corgi::component_library::MetaComponent; 31 | using corgi::EntityManager; 32 | using corgi::EntityRef; 33 | 34 | namespace breadboard { 35 | namespace module_library { 36 | 37 | // Given an input string, return the named entity. 38 | class EntityNode : public BaseNode { 39 | public: 40 | enum { kInputTrigger, kInputEntityId }; 41 | enum { kOutputEntity }; 42 | 43 | EntityNode(MetaComponent* meta_component) : meta_component_(meta_component) {} 44 | static void OnRegister(NodeSignature* node_sig) { 45 | node_sig->AddInput(kInputTrigger, "Trigger"); 46 | node_sig->AddInput(kInputEntityId, "Entity ID"); 47 | node_sig->AddOutput(kOutputEntity, "Entity"); 48 | } 49 | 50 | virtual void Execute(NodeArguments* args) { 51 | auto entity_id = args->GetInput(kInputEntityId); 52 | EntityRef entity = 53 | meta_component_->GetEntityFromDictionary(entity_id->c_str()); 54 | assert(entity.IsValid()); 55 | args->SetOutput(kOutputEntity, entity); 56 | } 57 | 58 | private: 59 | MetaComponent* meta_component_; 60 | }; 61 | 62 | // Return the entity that owns this graph. 63 | class GraphEntityNode : public BaseNode { 64 | public: 65 | enum { kOutputEntity }; 66 | 67 | GraphEntityNode(GraphComponent* graph_component) 68 | : graph_component_(graph_component) {} 69 | 70 | static void OnRegister(NodeSignature* node_sig) { 71 | node_sig->AddOutput(kOutputEntity, "Entity"); 72 | } 73 | 74 | virtual void Initialize(NodeArguments* args) { 75 | args->SetOutput(kOutputEntity, graph_component_->graph_entity()); 76 | } 77 | 78 | private: 79 | GraphComponent* graph_component_; 80 | }; 81 | 82 | // Delete the given entity. 83 | class DeleteEntityNode : public BaseNode { 84 | public: 85 | enum { kInputTrigger, kInputEntity }; 86 | 87 | DeleteEntityNode(::EntityManager* entity_manager) 88 | : entity_manager_(entity_manager) {} 89 | 90 | static void OnRegister(NodeSignature* node_sig) { 91 | node_sig->AddInput(kInputTrigger, "Trigger"); 92 | node_sig->AddInput(kInputEntity, "Entity"); 93 | } 94 | 95 | virtual void Execute(NodeArguments* args) { 96 | if (args->IsInputDirty(kInputTrigger)) { 97 | auto entity_ref = args->GetInput(kInputEntity); 98 | entity_manager_->DeleteEntity(*entity_ref); 99 | } 100 | } 101 | 102 | private: 103 | EntityManager* entity_manager_; 104 | }; 105 | 106 | void InitializeEntityModule(ModuleRegistry* module_registry, 107 | EntityManager* entity_manager, 108 | MetaComponent* meta_component, 109 | GraphComponent* graph_component) { 110 | auto entity_ctor = [meta_component]() { 111 | return new EntityNode(meta_component); 112 | }; 113 | auto graph_entity_ctor = [graph_component]() { 114 | return new GraphEntityNode(graph_component); 115 | }; 116 | auto delete_entity_ctor = [entity_manager]() { 117 | return new DeleteEntityNode(entity_manager); 118 | }; 119 | TypeRegistry::RegisterType("Entity"); 120 | Module* module = module_registry->RegisterModule("entity"); 121 | module->RegisterNode("entity", entity_ctor); 122 | module->RegisterNode("graph_entity", graph_entity_ctor); 123 | module->RegisterNode("delete_entity", delete_entity_ctor); 124 | } 125 | 126 | } // namespace module_library 127 | } // namespace breadboard 128 | -------------------------------------------------------------------------------- /module_library/src/physics.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/physics.h" 16 | 17 | #include 18 | 19 | #include "breadboard/base_node.h" 20 | #include "breadboard/module_registry.h" 21 | #include "corgi/entity_manager.h" 22 | #include "corgi_component_library/physics.h" 23 | 24 | using breadboard::BaseNode; 25 | using breadboard::Module; 26 | using breadboard::ModuleRegistry; 27 | using breadboard::NodeArguments; 28 | using breadboard::NodeSignature; 29 | using corgi::component_library::CollisionData; 30 | using corgi::component_library::GraphComponent; 31 | using corgi::component_library::PhysicsComponent; 32 | using corgi::component_library::kCollisionEventId; 33 | using corgi::EntityRef; 34 | 35 | namespace breadboard { 36 | namespace module_library { 37 | 38 | class OnCollisionNode : public BaseNode { 39 | public: 40 | enum { kInputEntity }; 41 | enum { kOutputCollision }; 42 | enum { kListenerOnCollision }; 43 | 44 | OnCollisionNode(GraphComponent* graph_component) 45 | : graph_component_(graph_component) {} 46 | 47 | static void OnRegister(NodeSignature* node_sig) { 48 | node_sig->AddInput(kInputEntity, "Entity"); 49 | node_sig->AddOutput(kOutputCollision, "Collision"); 50 | node_sig->AddListener(kCollisionEventId); 51 | } 52 | 53 | virtual void Initialize(NodeArguments* args) { 54 | auto entity = args->GetInput(kInputEntity); 55 | args->BindBroadcaster(kListenerOnCollision, 56 | graph_component_->GetCreateBroadcaster(*entity)); 57 | } 58 | 59 | virtual void Execute(NodeArguments* args) { 60 | Initialize(args); 61 | if (args->IsListenerDirty(kListenerOnCollision)) { 62 | args->SetOutput(kOutputCollision); 63 | } 64 | } 65 | 66 | private: 67 | GraphComponent* graph_component_; 68 | }; 69 | 70 | class CollisionDataNode : public BaseNode { 71 | public: 72 | enum { kInputTrigger }; 73 | enum { 74 | kOutputEntityA, 75 | kOutputPositionA, 76 | kOutputTagA, 77 | kOutputEntityB, 78 | kOutputPositionB, 79 | kOutputTagB 80 | }; 81 | 82 | CollisionDataNode(PhysicsComponent* physics_component) 83 | : physics_component_(physics_component) {} 84 | 85 | static void OnRegister(NodeSignature* node_sig) { 86 | // Fetch the collision data when triggered 87 | node_sig->AddInput(kInputTrigger); 88 | 89 | // One of the entities involved in the collision, the location of the 90 | // entity, and an arbitrary tag. 91 | node_sig->AddOutput(kOutputEntityA, "Entity A"); 92 | node_sig->AddOutput(kOutputPositionA, "Position A"); 93 | node_sig->AddOutput(kOutputTagA, "Tag A"); 94 | 95 | // The other entity involved in the collision, the location of the entity, 96 | // and an arbitrary tag. 97 | node_sig->AddOutput(kOutputEntityB, "Entity B"); 98 | node_sig->AddOutput(kOutputPositionB, "Position B"); 99 | node_sig->AddOutput(kOutputTagB, "Tag B"); 100 | } 101 | 102 | virtual void Initialize(NodeArguments* args) { 103 | CollisionData& collision_data = physics_component_->collision_data(); 104 | args->SetOutput(kOutputEntityA, collision_data.this_entity); 105 | args->SetOutput(kOutputPositionA, collision_data.this_position); 106 | args->SetOutput(kOutputTagA, collision_data.this_tag); 107 | args->SetOutput(kOutputEntityB, collision_data.other_entity); 108 | args->SetOutput(kOutputPositionB, collision_data.other_position); 109 | args->SetOutput(kOutputTagB, collision_data.other_tag); 110 | } 111 | 112 | virtual void Execute(NodeArguments* args) { Initialize(args); } 113 | 114 | private: 115 | PhysicsComponent* physics_component_; 116 | }; 117 | 118 | class VelocityNode : public BaseNode { 119 | public: 120 | enum { kInputTrigger, kInputEntity }; 121 | enum { kOutputVelocity }; 122 | 123 | VelocityNode(PhysicsComponent* physics_component) 124 | : physics_component_(physics_component) {} 125 | 126 | static void OnRegister(NodeSignature* node_sig) { 127 | node_sig->AddInput(kInputTrigger, "Trigger"); 128 | node_sig->AddInput(kInputEntity, "Entity"); 129 | node_sig->AddOutput(kOutputVelocity, "Velocity"); 130 | } 131 | 132 | virtual void Execute(NodeArguments* args) { 133 | if (args->IsInputDirty(kInputTrigger)) { 134 | auto entity = args->GetInput(kInputEntity); 135 | auto physics_data = physics_component_->GetComponentData(*entity); 136 | args->SetOutput(kOutputVelocity, physics_data->Velocity()); 137 | } 138 | } 139 | 140 | private: 141 | PhysicsComponent* physics_component_; 142 | }; 143 | 144 | void InitializePhysicsModule(ModuleRegistry* module_registry, 145 | PhysicsComponent* physics_component, 146 | GraphComponent* graph_component) { 147 | Module* module = module_registry->RegisterModule("physics"); 148 | auto on_collision_ctor = [graph_component]() { 149 | return new OnCollisionNode(graph_component); 150 | }; 151 | auto collision_data_ctor = [physics_component]() { 152 | return new CollisionDataNode(physics_component); 153 | }; 154 | auto velocity_ctor = [physics_component]() { 155 | return new VelocityNode(physics_component); 156 | }; 157 | module->RegisterNode("on_collision", on_collision_ctor); 158 | module->RegisterNode("collision_data", 159 | collision_data_ctor); 160 | module->RegisterNode("velocity", velocity_ctor); 161 | } 162 | 163 | } // namespace module_library 164 | } // namespace breadboard 165 | -------------------------------------------------------------------------------- /module_library/src/rendermesh.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/rendermesh.h" 16 | 17 | #include "breadboard/base_node.h" 18 | #include "breadboard/module_registry.h" 19 | 20 | using breadboard::BaseNode; 21 | using breadboard::ModuleRegistry; 22 | using breadboard::Module; 23 | using breadboard::NodeArguments; 24 | using breadboard::NodeSignature; 25 | using corgi::component_library::RenderMeshComponent; 26 | using corgi::component_library::RenderMeshData; 27 | using corgi::EntityRef; 28 | 29 | namespace breadboard { 30 | namespace module_library { 31 | 32 | // Sets the visibility of RenderMesh recursively. 33 | class SetVisibleNode : public BaseNode { 34 | public: 35 | enum { kInputEntity, kInputVisible }; 36 | SetVisibleNode(RenderMeshComponent* render_mesh_component) 37 | : render_mesh_component_(render_mesh_component) {} 38 | 39 | static void OnRegister(NodeSignature* node_sig) { 40 | node_sig->AddInput(kInputEntity, "Entity"); 41 | node_sig->AddInput(kInputVisible, "Visible"); 42 | } 43 | 44 | virtual void Initialize(NodeArguments* args) { 45 | auto entity = args->GetInput(kInputEntity); 46 | if (entity->IsValid()) { 47 | render_mesh_component_->SetVisibilityRecursively( 48 | *entity, *args->GetInput(kInputVisible)); 49 | } 50 | } 51 | 52 | virtual void Execute(NodeArguments* args) { Initialize(args); } 53 | 54 | private: 55 | RenderMeshComponent* render_mesh_component_; 56 | }; 57 | 58 | // Sets the tint color of RenderMesh. 59 | class SetTintNode : public BaseNode { 60 | public: 61 | enum { kInputTrigger, kInputEntity, kInputTint }; 62 | SetTintNode(RenderMeshComponent* render_mesh_component) 63 | : render_mesh_component_(render_mesh_component) {} 64 | 65 | static void OnRegister(NodeSignature* node_sig) { 66 | node_sig->AddInput(kInputTrigger, "Trigger"); 67 | node_sig->AddInput(kInputEntity, "Entity"); 68 | node_sig->AddInput(kInputTint, "Tint"); 69 | } 70 | 71 | virtual void Initialize(NodeArguments* args) { 72 | if (args->IsInputDirty(kInputTrigger)) { 73 | auto entity = args->GetInput(kInputEntity); 74 | if (entity->IsValid()) { 75 | RenderMeshData* render_mesh_data = 76 | render_mesh_component_->GetComponentData(*entity); 77 | render_mesh_data->tint = *args->GetInput(kInputTint); 78 | } 79 | } 80 | } 81 | 82 | virtual void Execute(NodeArguments* args) { Initialize(args); } 83 | 84 | private: 85 | RenderMeshComponent* render_mesh_component_; 86 | }; 87 | 88 | void InitializeRenderMeshModule(ModuleRegistry* module_registry, 89 | RenderMeshComponent* render_mesh_component) { 90 | auto set_visible_ctor = [render_mesh_component]() { 91 | return new SetVisibleNode(render_mesh_component); 92 | }; 93 | auto set_tint_ctor = [render_mesh_component]() { 94 | return new SetTintNode(render_mesh_component); 95 | }; 96 | Module* module = module_registry->RegisterModule("rendermesh"); 97 | module->RegisterNode("set_visible", set_visible_ctor); 98 | module->RegisterNode("set_tint", set_tint_ctor); 99 | } 100 | 101 | } // namespace module_library 102 | } // namespace breadboard 103 | -------------------------------------------------------------------------------- /module_library/src/transform.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "module_library/transform.h" 16 | 17 | #include 18 | 19 | #include "breadboard/base_node.h" 20 | #include "breadboard/module_registry.h" 21 | #include "corgi/entity_manager.h" 22 | #include "corgi_component_library/transform.h" 23 | #include "mathfu/glsl_mappings.h" 24 | 25 | using breadboard::BaseNode; 26 | using breadboard::ModuleRegistry; 27 | using breadboard::Module; 28 | using breadboard::NodeArguments; 29 | using breadboard::NodeSignature; 30 | using corgi::component_library::TransformComponent; 31 | using corgi::component_library::TransformData; 32 | using corgi::EntityRef; 33 | using mathfu::vec3; 34 | 35 | namespace breadboard { 36 | namespace module_library { 37 | 38 | // Returns the child at the given index. 39 | class ChildNode : public BaseNode { 40 | public: 41 | enum { kInputParent, kInputChildIndex }; 42 | enum { kOutputChild }; 43 | 44 | ChildNode(TransformComponent* transform_component) 45 | : transform_component_(transform_component) {} 46 | 47 | static void OnRegister(NodeSignature* node_sig) { 48 | node_sig->AddInput(kInputParent, "Parent"); 49 | node_sig->AddInput(kInputChildIndex, "Child Index"); 50 | node_sig->AddOutput(kOutputChild, "Child"); 51 | } 52 | 53 | virtual void Initialize(NodeArguments* args) { 54 | auto entity = args->GetInput(kInputParent); 55 | if (entity->IsValid()) { 56 | auto child_index = *args->GetInput(kInputChildIndex); 57 | TransformData* transform_data = 58 | transform_component_->GetComponentData(*entity); 59 | // Find the child at the given index. 60 | auto iter = transform_data->children.begin(); 61 | while (child_index && iter != transform_data->children.end()) { 62 | ++iter; 63 | --child_index; 64 | } 65 | args->SetOutput(kOutputChild, iter != transform_data->children.end() 66 | ? iter->owner 67 | : EntityRef()); 68 | } else { 69 | args->SetOutput(kOutputChild, EntityRef()); 70 | } 71 | } 72 | 73 | virtual void Execute(NodeArguments* args) { Initialize(args); } 74 | 75 | private: 76 | TransformComponent* transform_component_; 77 | }; 78 | 79 | // Returns the position of the entity in world space. 80 | class WorldPositionNode : public BaseNode { 81 | public: 82 | enum { kInputTrigger, kInputEntity }; 83 | enum { kOutputPosition }; 84 | WorldPositionNode(TransformComponent* transform_component) 85 | : transform_component_(transform_component) {} 86 | 87 | static void OnRegister(NodeSignature* node_sig) { 88 | node_sig->AddInput(kInputTrigger, "Trigger"); 89 | node_sig->AddInput(kInputEntity, "Entity"); 90 | node_sig->AddOutput(kOutputPosition, "Position"); 91 | } 92 | 93 | virtual void Initialize(NodeArguments* args) { 94 | if (args->IsInputDirty(kInputTrigger)) { 95 | auto entity = args->GetInput(kInputEntity); 96 | vec3 position = transform_component_->WorldPosition(*entity); 97 | args->SetOutput(kOutputPosition, position); 98 | } 99 | } 100 | 101 | virtual void Execute(NodeArguments* args) { Initialize(args); } 102 | 103 | private: 104 | TransformComponent* transform_component_; 105 | }; 106 | 107 | class SetScaleNode : public BaseNode { 108 | public: 109 | enum { kInputEntity, kInputScale }; 110 | SetScaleNode(TransformComponent* transform_component) 111 | : transform_component_(transform_component) {} 112 | 113 | static void OnRegister(NodeSignature* node_sig) { 114 | node_sig->AddInput(kInputEntity, "Entity"); 115 | node_sig->AddInput(kInputScale, "Scale"); 116 | } 117 | 118 | virtual void Initialize(NodeArguments* args) { 119 | auto entity = args->GetInput(kInputEntity); 120 | if (entity->IsValid()) { 121 | TransformData* transform_data = 122 | transform_component_->GetComponentData(*entity); 123 | transform_data->scale = *args->GetInput(kInputScale); 124 | } 125 | } 126 | 127 | virtual void Execute(NodeArguments* args) { Initialize(args); } 128 | 129 | private: 130 | TransformComponent* transform_component_; 131 | }; 132 | 133 | void InitializeTransformModule(ModuleRegistry* module_registry, 134 | TransformComponent* transform_component) { 135 | auto world_position_ctor = [transform_component]() { 136 | return new WorldPositionNode(transform_component); 137 | }; 138 | auto set_scale_ctor = [transform_component]() { 139 | return new SetScaleNode(transform_component); 140 | }; 141 | auto child_ctor = [transform_component]() { 142 | return new ChildNode(transform_component); 143 | }; 144 | Module* module = module_registry->RegisterModule("transform"); 145 | module->RegisterNode("child", child_ctor); 146 | module->RegisterNode("world_position", 147 | world_position_ctor); 148 | module->RegisterNode("set_scale", set_scale_ctor); 149 | } 150 | 151 | } // namespace module_library 152 | } // namespace breadboard 153 | -------------------------------------------------------------------------------- /samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | cmake_minimum_required(VERSION 2.8.12) 15 | 16 | project(breadboard-samples) 17 | 18 | add_subdirectory(event_counter) 19 | 20 | -------------------------------------------------------------------------------- /samples/README_BUILDING.txt: -------------------------------------------------------------------------------- 1 | To build these samples, simply build the root breadboard CMakeLists.txt: 2 | for Mac OS Xcode: cmake -Dbreadboard_build_samples=ON -GXcode 3 | open breadboard.xcodeproj 4 | for Mac/Linux terminal: cmake -Dbreadboard_build_samples=ON; make 5 | 6 | 7 | For more information, see "Building" in the documentation. 8 | 9 | -------------------------------------------------------------------------------- /samples/event_counter/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 19 | 20 | 21 | 22 | 25 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/event_counter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | cmake_minimum_required(VERSION 2.8.12) 15 | 16 | project(breadboard-event-counter) 17 | 18 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../../bin) 19 | add_executable(breadboard-event-counter event_counter.cpp) 20 | 21 | target_link_libraries(breadboard-event-counter breadboard) 22 | -------------------------------------------------------------------------------- /samples/event_counter/event_counter.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include "breadboard/base_node.h" 21 | #include "breadboard/graph_state.h" 22 | #include "breadboard/module_registry.h" 23 | #include "breadboard/modules/common.h" 24 | #include "fplutil/main.h" 25 | #include "fplutil/print.h" 26 | 27 | 28 | // This is a sample that counts an event occurrence. 29 | // 30 | // It demonstrates usage of: 31 | // - breadboard::Node to create and configure nodes. 32 | // - breadboard::Graph to build a graph of event counter. 33 | // - breadboard::NodeEventBroadcaster && breadboard::NodeEventListener. 34 | // - inter-operations of the above graph elements 35 | namespace sample { 36 | using namespace breadboard; 37 | const char *kCounterEventName = "graph-sample-event"; 38 | const char *kModuleName = "sample_module"; 39 | const char *kCaptureNodeName = "capture_event"; 40 | const char *kCountNodeName = "count_event"; 41 | const char *kPrintNodeName = "print_event"; 42 | const EventId kCounterEvent = &kCounterEventName; 43 | 44 | // CaptureEvent Node: 45 | // No Input; 1 Integer Output(increment value to add into counter) 46 | // Listen to kCounterEvent. Event binding happens at node creation time 47 | class CaptureEvent : public BaseNode { 48 | public: 49 | CaptureEvent(breadboard::NodeEventBroadcaster *broadcaster) 50 | : broadcaster_(broadcaster) {} 51 | virtual ~CaptureEvent() {} 52 | 53 | static void OnRegister(NodeSignature *node_sig) { 54 | node_sig->AddOutput(); 55 | node_sig->AddListener(kCounterEvent); 56 | } 57 | 58 | virtual void Initialize(NodeArguments *args) { 59 | args->BindBroadcaster(0, broadcaster_); 60 | } 61 | 62 | // Send an incremental value to next node for each event 63 | virtual void Execute(NodeArguments *args) { args->SetOutput(0, 1); } 64 | 65 | private: 66 | breadboard::NodeEventBroadcaster *broadcaster_; 67 | }; 68 | 69 | // CountEvent Node: 70 | // One integer input, one std::string output 71 | // Accept input and add it into internal counter, 72 | // pass counter value to output as std::string 73 | class CountEvent : public BaseNode { 74 | public: 75 | CountEvent() : count_(0) {} 76 | virtual ~CountEvent() {} 77 | 78 | static void OnRegister(NodeSignature *node_sig) { 79 | node_sig->AddInput(); 80 | node_sig->AddOutput(); 81 | } 82 | 83 | virtual void Execute(NodeArguments *args) { 84 | count_ += *args->GetInput(0); 85 | std::stringstream ss; 86 | ss << count_; 87 | args->SetOutput(0, ss.str()); 88 | } 89 | 90 | private: 91 | int count_; 92 | }; 93 | 94 | // PrintEvent Node: 95 | // One std::string input, no output 96 | // Print string from input to debug window 97 | class PrintEvent : public BaseNode { 98 | public: 99 | virtual ~PrintEvent() {} 100 | 101 | static void OnRegister(NodeSignature *node_sig) { 102 | node_sig->AddInput(); 103 | } 104 | 105 | virtual void Execute(NodeArguments *args) { 106 | auto str = args->GetInput(0); 107 | CallLogFunc("Event Counter = %s\n", str->c_str()); 108 | } 109 | }; 110 | 111 | // Build up our node reservoir into a sample module (kModuleName) 112 | // then it could be used to create a graph 113 | void InitializeSampleModule(ModuleRegistry *module_registry, 114 | breadboard::NodeEventBroadcaster *broadcaster) { 115 | // Register the types we need for our module 116 | TypeRegistry::RegisterType("Int"); 117 | TypeRegistry::RegisterType("String"); 118 | 119 | auto capture_event_ctor = [broadcaster]() { 120 | return new CaptureEvent(broadcaster); 121 | }; 122 | 123 | Module *module = module_registry->RegisterModule(kModuleName); 124 | module->RegisterNode(kCaptureNodeName, capture_event_ctor); 125 | module->RegisterNode(kCountNodeName); 126 | module->RegisterNode(kPrintNodeName); 127 | } 128 | 129 | // CreateGraph(): 130 | // Build a simple graph of 3 nodes: CaptureEvent -> CountEvent -> PrintEvent 131 | breadboard::Graph *CreateGraph(const breadboard::ModuleRegistry *mod_registry) { 132 | auto graph = new breadboard::Graph("graph_sample"); 133 | if (!graph) { 134 | return nullptr; 135 | } 136 | 137 | // create node index 0: event catcher node 138 | auto module = mod_registry->GetModule(kModuleName); 139 | auto node_sig = module->GetNodeSignature(kCaptureNodeName); 140 | auto node = graph->AddNode(node_sig); 141 | 142 | // create node index 1: event counter node 143 | // connect the only input to node 0's output 0 144 | node_sig = module->GetNodeSignature(kCountNodeName); 145 | node = graph->AddNode(node_sig); 146 | node->input_edges().push_back(breadboard::InputEdge()); 147 | node->input_edges().back().SetTarget(0, 0); 148 | 149 | // create node index 2: event printer node 150 | // connect the only input to node 1's output 0 151 | node_sig = module->GetNodeSignature(kPrintNodeName); 152 | node = graph->AddNode(node_sig); 153 | node->input_edges().push_back(breadboard::InputEdge()); 154 | node->input_edges().back().SetTarget(1, 0); 155 | 156 | // validate our graph 157 | if (!graph->FinalizeNodes()) { 158 | delete graph; 159 | graph = nullptr; 160 | } 161 | 162 | return graph; 163 | } 164 | 165 | // a helper function to support logging for breadboard 166 | void BreadboardLogFunc(const char *fmt, va_list args) { vprintf(fmt, args); } 167 | 168 | } // namespace sample 169 | 170 | extern "C" int main(int /*argc*/, char **argv) { 171 | // declare our event broadcaster, needed for node creation 172 | breadboard::NodeEventBroadcaster broadcaster; 173 | 174 | breadboard::ModuleRegistry module_registry; 175 | breadboard::RegisterLogFunc(sample::BreadboardLogFunc); 176 | sample::InitializeSampleModule(&module_registry, &broadcaster); 177 | 178 | auto graph = sample::CreateGraph(&module_registry); 179 | if (!graph) { 180 | printf("Failed to build graph\n"); 181 | return -1; 182 | } 183 | 184 | { 185 | breadboard::GraphState graph_state; 186 | graph_state.Initialize(graph); 187 | 188 | breadboard::NodeEventListener listener(&graph_state, sample::kCounterEvent); 189 | broadcaster.RegisterListener(&listener); 190 | 191 | int loop = 0; 192 | while (loop++ < 500) { 193 | broadcaster.BroadcastEvent(sample::kCounterEvent); 194 | } 195 | } 196 | 197 | delete graph; 198 | printf("Success: %s completed\n", argv[0]); 199 | 200 | return 0; 201 | } 202 | -------------------------------------------------------------------------------- /samples/event_counter/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | LOCAL_PATH := $(call my-dir)/.. 16 | 17 | BREADBOARD_DIR := $(LOCAL_PATH)/../.. 18 | 19 | # Pull in depedency config for fplutil. 20 | include $(BREADBOARD_DIR)/jni/android_config.mk 21 | 22 | include $(CLEAR_VARS) 23 | LOCAL_MODULE := breadboard_event_counter 24 | LOCAL_SRC_FILES := event_counter.cpp 25 | LOCAL_STATIC_LIBRARIES := breadboard 26 | LOCAL_WHOLE_STATIC_LIBRARIES:=android_native_app_glue libfplutil_main \ 27 | libfplutil_print 28 | LOCAL_EXPORT_C_INCLUDES:=$(DEPENDENCIES_FPLUTIL_DIR)/libfplutil/include 29 | LOCAL_LDLIBS:=-llog -landroid 30 | LOCAL_ARM_MODE := arm 31 | include $(BUILD_SHARED_LIBRARY) 32 | 33 | $(call import-add-path,$(DEPENDENCIES_FPLUTIL_DIR)/..) 34 | $(call import-add-path,$(DEPENDENCIES_BREADBOARD_DIR)/..) 35 | $(call import-module,android/native_app_glue) 36 | $(call import-module,breadboard/jni) 37 | $(call import-module,fplutil/libfplutil/jni) 38 | -------------------------------------------------------------------------------- /samples/event_counter/jni/Application.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2015 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | APP_PLATFORM := android-9 16 | APP_ABI:=armeabi armeabi-v7a mips x86 x86_64 17 | APP_STL:=c++_static 18 | APP_MODULES := breadboard_event_counter 19 | 20 | APP_CPPFLAGS += -std=c++11 -Wno-literal-suffix 21 | 22 | 23 | -------------------------------------------------------------------------------- /samples/event_counter/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | breadboard_event_counter 18 | 19 | -------------------------------------------------------------------------------- /src/breadboard/event.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "breadboard/event.h" 18 | #include "breadboard/graph_state.h" 19 | #include "breadboard/node_arguments.h" 20 | 21 | namespace breadboard { 22 | 23 | void NodeEventListener::MarkDirty() { timestamp_ = graph_state_->timestamp(); } 24 | 25 | void NodeEventBroadcaster::RegisterListener(NodeEventListener* listener) { 26 | auto list_iter = event_listener_lists_.find(listener->event_id()); 27 | if (list_iter == event_listener_lists_.end()) { 28 | auto insert_result = event_listener_lists_.insert(std::make_pair( 29 | listener->event_id(), ListenerList(&NodeEventListener::node))); 30 | list_iter = insert_result.first; 31 | } 32 | 33 | // We don't want to insert this node into more than one list, so if its in a 34 | // list we remove it before adding it to the new list. If its already in the 35 | // list we're going to add it to, we don't need to do anything. 36 | ListenerList& listener_list = list_iter->second; 37 | bool in_list = listener->node.in_list(); 38 | if (in_list) { 39 | bool found = false; 40 | for (auto listener_iter = listener_list.begin(); 41 | listener_iter != listener_list.end(); ++listener_iter) { 42 | if (&*listener_iter == listener) { 43 | found = true; 44 | break; 45 | } 46 | } 47 | if (!found) { 48 | listener->node.remove(); 49 | in_list = false; 50 | } 51 | } 52 | if (!in_list) { 53 | listener_list.push_back(*listener); 54 | } 55 | } 56 | 57 | void NodeEventBroadcaster::BroadcastEvent(EventId event_id) { 58 | auto list_iter = event_listener_lists_.find(event_id); 59 | if (list_iter != event_listener_lists_.end()) { 60 | ListenerList& listener_list = list_iter->second; 61 | for (auto listener_iter = listener_list.begin(); 62 | listener_iter != listener_list.end(); ++listener_iter) { 63 | listener_iter->MarkDirty(); 64 | listener_iter->graph_state()->Execute(); 65 | } 66 | } 67 | } 68 | 69 | } // namespace breadboard 70 | -------------------------------------------------------------------------------- /src/breadboard/graph_factory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/graph_factory.h" 16 | 17 | #include 18 | 19 | #include "breadboard/graph.h" 20 | #include "breadboard/module_registry.h" 21 | 22 | namespace breadboard { 23 | 24 | Graph* GraphFactory::LoadGraph(const char* filename) { 25 | // Have we loaded this flatbuffer already? 26 | auto iter = loaded_graphs_.find(filename); 27 | if (iter != loaded_graphs_.end()) { 28 | // If so, return the cached graph. 29 | return iter->second.get(); 30 | } else { 31 | // If not, load it and return it. 32 | std::string data; 33 | if (!load_file_callback_(filename, &data)) { 34 | return nullptr; 35 | } 36 | Graph* graph = new Graph(filename); 37 | if (!ParseData(module_registry_, graph, &data)) { 38 | return nullptr; 39 | } 40 | loaded_graphs_[filename].reset(graph); 41 | return graph; 42 | } 43 | } 44 | 45 | } // namespace breadboard 46 | -------------------------------------------------------------------------------- /src/breadboard/graph_state.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/graph_state.h" 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "breadboard/base_node.h" 22 | 23 | namespace breadboard { 24 | 25 | GraphState::~GraphState() { 26 | // Destruct the per-graph values. 27 | if (graph_) { 28 | for (auto node = graph_->nodes().begin(); node != graph_->nodes().end(); 29 | ++node) { 30 | const NodeSignature* signature = node->signature(); 31 | for (size_t i = 0; i < signature->output_parameters().size(); ++i) { 32 | const OutputEdge& output_edge = node->output_edges()[i]; 33 | if (output_edge.connected()) { 34 | // If connected, it has a per-graph value. 35 | const Type* type = signature->output_parameters()[i].type; 36 | 37 | // Destruct timestamp. 38 | Timestamp* timestamp = output_buffer_.GetObject( 39 | output_edge.timestamp_offset()); 40 | timestamp->~Timestamp(); 41 | (void)timestamp; // Avoid erroneous "not referenced" warning in VS. 42 | 43 | // Destruct object. 44 | // Only do this on non-void objects. Attempting to access a void edge 45 | // can be troublesome in the case where the last edge listed is of 46 | // type void. 47 | if (type->size > 0) { 48 | uint8_t* ptr = 49 | output_buffer_.GetObjectPtr(output_edge.data_offset()); 50 | type->operator_delete_func(ptr); 51 | } 52 | } 53 | } 54 | for (size_t i = 0; i < node->listener_offsets().size(); ++i) { 55 | ptrdiff_t listener_offset = node->listener_offsets()[i]; 56 | NodeEventListener* listener = 57 | output_buffer_.GetObject(listener_offset); 58 | listener->~NodeEventListener(); 59 | } 60 | } 61 | } 62 | } 63 | 64 | void GraphState::Initialize(Graph* graph) { 65 | assert(graph->nodes_finalized()); 66 | graph_ = graph; 67 | output_buffer_.Initialize(graph_->output_buffer_size()); 68 | for (auto node = graph_->nodes().begin(); node != graph_->nodes().end(); 69 | ++node) { 70 | uint8_t* ptr; 71 | const NodeSignature* signature = node->signature(); 72 | 73 | // Initialize the memory for the output edges. 74 | for (size_t i = 0; i < signature->output_parameters().size(); ++i) { 75 | const OutputEdge& output_edge = node->output_edges()[i]; 76 | if (output_edge.connected()) { 77 | const Type* type = signature->output_parameters()[i].type; 78 | 79 | // Initialize timestamp. 80 | ptr = output_buffer_.GetObjectPtr(output_edge.timestamp_offset()); 81 | new (ptr) Timestamp(0); 82 | 83 | // Initialize object. 84 | // Only do this on non-void objects. Attempting to access a void edge 85 | // can be troublesome in the case where the last edge listed is of 86 | // type void. 87 | if (type->size > 0) { 88 | ptr = output_buffer_.GetObjectPtr(output_edge.data_offset()); 89 | type->placement_new_func(ptr); 90 | } 91 | } 92 | } 93 | 94 | // Initialize the memory for the listeners. 95 | for (size_t i = 0; i < signature->event_listeners().size(); ++i) { 96 | EventId event_id = signature->event_listeners()[i].event_id; 97 | ptr = output_buffer_.GetObjectPtr(node->listener_offsets()[i]); 98 | new (ptr) NodeEventListener(this, event_id); 99 | } 100 | } 101 | 102 | for (size_t i = 0; i < graph_->sorted_nodes().size(); ++i) { 103 | Node* node = graph_->sorted_nodes()[i]; 104 | NodeArguments args(node, &graph_->nodes(), &graph_->input_buffer(), 105 | &output_buffer_, timestamp_); 106 | node->base_node()->Initialize(&args); 107 | } 108 | ++timestamp_; 109 | } 110 | 111 | void GraphState::Execute() { 112 | assert(graph_); 113 | for (size_t i = 0; i < graph_->sorted_nodes().size(); ++i) { 114 | Node* node = graph_->sorted_nodes()[i]; 115 | if (IsDirty(*node)) { 116 | NodeArguments args(node, &graph_->nodes(), &graph_->input_buffer(), 117 | &output_buffer_, timestamp_); 118 | node->base_node()->Execute(&args); 119 | } 120 | } 121 | ++timestamp_; 122 | } 123 | 124 | bool GraphState::IsDirty(const Node& node) const { 125 | const Timestamp* node_timestamp = 126 | output_buffer_.GetObject(node.timestamp_offset()); 127 | if (*node_timestamp == timestamp_) { 128 | return true; 129 | } 130 | for (size_t i = 0; i < node.listener_offsets().size(); ++i) { 131 | const NodeEventListener* listener = 132 | output_buffer_.GetObject(node.listener_offsets()[i]); 133 | if (listener->timestamp() == timestamp_) { 134 | return true; 135 | } 136 | } 137 | for (size_t i = 0; i < node.input_edges().size(); ++i) { 138 | const InputEdge& input_edge = node.input_edges()[i]; 139 | if (input_edge.connected()) { 140 | const OutputEdge& output_edge = 141 | input_edge.target().GetTargetEdge(&graph_->nodes()); 142 | const Timestamp* timestamp = 143 | output_buffer_.GetObject(output_edge.timestamp_offset()); 144 | if (*timestamp == timestamp_) { 145 | return true; 146 | } 147 | } 148 | } 149 | return false; 150 | } 151 | 152 | } // namespace breadboard 153 | -------------------------------------------------------------------------------- /src/breadboard/log.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/log.h" 16 | 17 | namespace breadboard { 18 | 19 | LogFunc g_log_func; 20 | 21 | // Register a logging function with the library. 22 | void RegisterLogFunc(LogFunc log_func) { g_log_func = log_func; } 23 | 24 | // Call the registered log function with the provided format string. This does 25 | // nothing if no logging function has been registered. 26 | void CallLogFunc(const char* format, ...) { 27 | if (g_log_func) { 28 | va_list args; 29 | va_start(args, format); 30 | g_log_func(format, args); 31 | va_end(args); 32 | } 33 | } 34 | 35 | } // namespace breadboard 36 | -------------------------------------------------------------------------------- /src/breadboard/module.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/module.h" 16 | 17 | namespace breadboard { 18 | 19 | NodeSignature* Module::GetNodeSignature(const std::string& name) { 20 | auto iter = signatures_.find(name); 21 | if (iter == signatures_.end()) { 22 | CallLogFunc("A node named \"%s\" has not been registered in module \"%s\".", 23 | name.c_str(), module_name_.c_str()); 24 | return nullptr; 25 | } 26 | return &iter->second; 27 | } 28 | 29 | const NodeSignature* Module::GetNodeSignature(const std::string& name) const { 30 | auto iter = signatures_.find(name); 31 | if (iter == signatures_.end()) { 32 | CallLogFunc("A node named \"%s\" has not been registered in module \"%s\".", 33 | name.c_str(), module_name_.c_str()); 34 | return nullptr; 35 | } 36 | return &iter->second; 37 | } 38 | 39 | } // namespace breadboard 40 | -------------------------------------------------------------------------------- /src/breadboard/module_registry.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/module_registry.h" 16 | #include "breadboard/log.h" 17 | #include "breadboard/version.h" 18 | 19 | namespace breadboard { 20 | 21 | ModuleRegistry::ModuleRegistry() : version_(&Version()) {} 22 | 23 | Module* ModuleRegistry::RegisterModule(const std::string& module_name) { 24 | auto result = 25 | modules_.insert(std::make_pair(module_name, Module(module_name))); 26 | ModuleDictionary::iterator iter = result.first; 27 | 28 | bool success = result.second; 29 | if (!success) { 30 | CallLogFunc("A module named \"%s\" has already been registered.", 31 | module_name.c_str()); 32 | return nullptr; 33 | } 34 | 35 | Module* module = &iter->second; 36 | return module; 37 | } 38 | 39 | const Module* ModuleRegistry::GetModule(const std::string& module_name) const { 40 | auto iter = modules_.find(module_name); 41 | if (iter == modules_.end()) { 42 | CallLogFunc("No module named \"%s\" has been registered.", 43 | module_name.c_str()); 44 | return nullptr; 45 | } 46 | return &iter->second; 47 | } 48 | 49 | } // namespace breadboard 50 | -------------------------------------------------------------------------------- /src/breadboard/node.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "breadboard/node.h" 18 | #include "breadboard/node_signature.h" 19 | 20 | namespace breadboard { 21 | 22 | void OutputEdgeTarget::Initialize(unsigned int node_index, 23 | unsigned int edge_index) { 24 | node_index_ = node_index; 25 | edge_index_ = edge_index; 26 | } 27 | 28 | Node& OutputEdgeTarget::GetTargetNode(std::vector* nodes) const { 29 | assert(node_index_ < nodes->size()); 30 | return (*nodes)[node_index_]; 31 | } 32 | 33 | const Node& OutputEdgeTarget::GetTargetNode( 34 | const std::vector* nodes) const { 35 | assert(node_index_ < nodes->size()); 36 | return (*nodes)[node_index_]; 37 | } 38 | 39 | OutputEdge& OutputEdgeTarget::GetTargetEdge(std::vector* nodes) const { 40 | return GetTargetNode(nodes).output_edges()[edge_index_]; 41 | } 42 | 43 | const OutputEdge& OutputEdgeTarget::GetTargetEdge( 44 | const std::vector* nodes) const { 45 | return GetTargetNode(nodes).output_edges()[edge_index_]; 46 | } 47 | 48 | Node::Node(const NodeSignature* signature) 49 | : signature_(signature), 50 | base_node_(signature->Constructor()), 51 | input_edges_(), 52 | output_edges_(), 53 | timestamp_offset_(0), 54 | inserted_(false), 55 | visited_(false) {} 56 | 57 | const Type* GetInputEdgeType(const Node* node, std::size_t index) { 58 | return node->signature()->input_parameters()[index].type; 59 | } 60 | 61 | const Type* GetOutputEdgeType(const Node* node, std::size_t index) { 62 | return node->signature()->output_parameters()[index].type; 63 | } 64 | 65 | } // namespace breadboard 66 | -------------------------------------------------------------------------------- /src/breadboard/node_arguments.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/node_arguments.h" 16 | #include "breadboard/node_signature.h" 17 | 18 | namespace breadboard { 19 | 20 | // Check to make sure the argument index is in range and the type being 21 | // retrieved is the type expected. 22 | void NodeArguments::VerifyInputPreconditions(size_t argument_index, 23 | const Type* requested_type) const { 24 | const NodeSignature* signature = node_->signature(); 25 | if (argument_index >= node_->input_edges().size()) { 26 | CallLogFunc( 27 | "%s:%s: Attempting to get argument %d when node only has %d input " 28 | "edges.", 29 | signature->module_name()->c_str(), signature->node_name().c_str(), 30 | argument_index, static_cast(node_->input_edges().size())); 31 | assert(0); 32 | } 33 | const Type* expected_type = GetInputEdgeType(node_, argument_index); 34 | if (requested_type != expected_type) { 35 | CallLogFunc( 36 | "%s:%s: Attempting to get input argument %d as type \"%s\" when it " 37 | "expects type \"%s\".", 38 | signature->module_name()->c_str(), signature->node_name().c_str(), 39 | argument_index, requested_type->name, expected_type->name); 40 | assert(0); 41 | } 42 | } 43 | 44 | // Check to make sure the argument index is in range and the type being set is 45 | // the type expected. 46 | void NodeArguments::VerifyOutputPreconditions( 47 | size_t argument_index, const Type* requested_type) const { 48 | const NodeSignature* signature = node_->signature(); 49 | if (argument_index >= node_->output_edges().size()) { 50 | CallLogFunc( 51 | "%s:%s: Attempting to get argument %d when node only has %d output " 52 | "edges.", 53 | signature->module_name()->c_str(), signature->node_name().c_str(), 54 | argument_index, static_cast(node_->input_edges().size())); 55 | assert(0); 56 | } 57 | const Type* expected_type = GetOutputEdgeType(node_, argument_index); 58 | if (requested_type != expected_type) { 59 | CallLogFunc( 60 | "%s:%s: Attempting to set output argument %d as type \"%s\" when it " 61 | "expects type \"%s\".", 62 | signature->module_name()->c_str(), signature->node_name().c_str(), 63 | argument_index, requested_type->name, expected_type->name); 64 | assert(0); 65 | } 66 | } 67 | 68 | bool NodeArguments::IsInputDirty(size_t argument_index) const { 69 | const InputEdge& input_edge = node_->input_edges()[argument_index]; 70 | if (input_edge.connected()) { 71 | // If this edge is connected, look at the timestamp on the output edge it's 72 | // connected to and see if it matches the current timestamp. 73 | const OutputEdgeTarget& target_edge = input_edge.target(); 74 | const OutputEdge& output_edge = target_edge.GetTargetEdge(nodes_); 75 | Timestamp* input_edge_timestamp = 76 | output_memory_->GetObject(output_edge.timestamp_offset()); 77 | return *input_edge_timestamp == timestamp_; 78 | } else { 79 | // If this edge is not connected, it's a default value that never changes 80 | // and thus is never considered dirty. 81 | return false; 82 | } 83 | } 84 | 85 | void NodeArguments::VerifyListenerPreconditions(size_t listener_index) const { 86 | if (listener_index >= node_->listener_offsets().size()) { 87 | const NodeSignature* signature = node_->signature(); 88 | CallLogFunc( 89 | "%s:%s: Attempting to get listener %d when node only has %d listeners.", 90 | signature->module_name()->c_str(), signature->node_name().c_str(), 91 | listener_index, static_cast(node_->listener_offsets().size())); 92 | assert(0); 93 | } 94 | } 95 | 96 | bool NodeArguments::IsListenerDirty(size_t listener_index) const { 97 | VerifyListenerPreconditions(listener_index); 98 | 99 | ptrdiff_t listener_offset = node_->listener_offsets()[listener_index]; 100 | NodeEventListener* listener = 101 | output_memory_->GetObject(listener_offset); 102 | return listener->timestamp() == timestamp_; 103 | } 104 | 105 | } // namespace breadboard 106 | -------------------------------------------------------------------------------- /src/breadboard/node_signature.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/node_signature.h" 16 | 17 | namespace breadboard { 18 | 19 | BaseNode* NodeSignature::Constructor() const { return constructor_(); } 20 | 21 | void NodeSignature::Destructor(BaseNode* base_node) const { 22 | return destructor_(base_node); 23 | } 24 | 25 | } // namespace breadboard 26 | -------------------------------------------------------------------------------- /src/breadboard/type_registry.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/type_registry.h" 16 | 17 | namespace breadboard { 18 | 19 | // template <> 20 | Type TypeRegistry::type_; 21 | 22 | // template <> 23 | bool TypeRegistry::initialized_ = false; 24 | 25 | } // breadboard 26 | -------------------------------------------------------------------------------- /src/breadboard/version.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/version.h" 16 | 17 | namespace breadboard { 18 | 19 | #define BREADBOARD_VERSION_MAJOR 1 20 | #define BREADBOARD_VERSION_MINOR 0 21 | #define BREADBOARD_VERSION_REVISION 2 22 | 23 | // Turn X into a string literal. 24 | #define BREADBOARD_STRING_EXPAND(X) #X 25 | #define BREADBOARD_STRING(X) BREADBOARD_STRING_EXPAND(X) 26 | 27 | /// @var kVersion 28 | /// @brief String which identifies the current version of MathFu. 29 | /// 30 | /// @ref kVersion is used by Google developers to identify which applications 31 | /// uploaded to Google Play are using this library. This allows the development 32 | /// team at Google to determine the popularity of the library. 33 | /// How it works: Applications that are uploaded to the Google Play Store are 34 | /// scanned for this version string. We track which applications are using it 35 | /// to measure popularity. You are free to remove it (of course) but we would 36 | /// appreciate if you left it in. 37 | /// 38 | static const BreadboardVersion kVersion = { 39 | BREADBOARD_VERSION_MAJOR, 40 | BREADBOARD_VERSION_MINOR, 41 | BREADBOARD_VERSION_REVISION, 42 | "Breadboard " 43 | BREADBOARD_STRING(BREADBOARD_VERSION_MAJOR) "." 44 | BREADBOARD_STRING(BREADBOARD_VERSION_MINOR) "." 45 | BREADBOARD_STRING(BREADBOARD_VERSION_REVISION) 46 | }; 47 | 48 | const BreadboardVersion& Version() { return kVersion; } 49 | 50 | } // namespace breadboard 51 | -------------------------------------------------------------------------------- /src/modules/common.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include "breadboard/module_registry.h" 18 | #include "breadboard/modules/debug.h" 19 | #include "breadboard/modules/logic.h" 20 | #include "breadboard/modules/math.h" 21 | #include "breadboard/modules/string.h" 22 | #include "breadboard/type_registry.h" 23 | 24 | namespace breadboard { 25 | 26 | void InitializeCommonModules(ModuleRegistry* module_registry) { 27 | TypeRegistry::RegisterType("Pulse"); 28 | TypeRegistry::RegisterType("Bool"); 29 | TypeRegistry::RegisterType("Int"); 30 | TypeRegistry::RegisterType("Float"); 31 | TypeRegistry::RegisterType("String"); 32 | 33 | InitializeDebugModule(module_registry); 34 | InitializeLogicModule(module_registry); 35 | InitializeIntegerMathModule(module_registry); 36 | InitializeFloatMathModule(module_registry); 37 | InitializeStringModule(module_registry); 38 | } 39 | 40 | } // namespace breadboard 41 | -------------------------------------------------------------------------------- /src/modules/debug.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/modules/debug.h" 16 | 17 | #include 18 | 19 | #include "breadboard/base_node.h" 20 | #include "breadboard/log.h" 21 | #include "breadboard/module_registry.h" 22 | 23 | namespace breadboard { 24 | 25 | // Prints a string to the logger. 26 | class ConsolePrintNode : public BaseNode { 27 | public: 28 | enum { kInputTrigger, kInputString }; 29 | enum { kOutputString }; 30 | 31 | virtual ~ConsolePrintNode() {} 32 | 33 | static void OnRegister(NodeSignature* node_sig) { 34 | node_sig->AddInput(kInputTrigger, "Trigger"); 35 | node_sig->AddInput(kInputString, "String"); 36 | 37 | node_sig->AddOutput(kOutputString, "String"); 38 | } 39 | 40 | virtual void Execute(NodeArguments* args) { 41 | auto str = args->GetInput(kInputString); 42 | CallLogFunc("%s\n", str->c_str()); 43 | args->SetOutput(kOutputString, *str); 44 | } 45 | }; 46 | 47 | void InitializeDebugModule(ModuleRegistry* module_registry) { 48 | Module* module = module_registry->RegisterModule("debug"); 49 | module->RegisterNode("console_print"); 50 | } 51 | 52 | } // namespace breadboard 53 | -------------------------------------------------------------------------------- /src/modules/logic.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/modules/logic.h" 16 | 17 | #include "breadboard/base_node.h" 18 | #include "breadboard/module_registry.h" 19 | 20 | namespace breadboard { 21 | 22 | // clang-format off 23 | #define LOGICAL_NODE(name, op) \ 24 | class name : public BaseNode { \ 25 | public: \ 26 | enum { kInputA, kInputB }; \ 27 | enum { kOutputResult }; \ 28 | \ 29 | static void OnRegister(NodeSignature* node_sig) { \ 30 | node_sig->AddInput(kInputA); \ 31 | node_sig->AddInput(kInputB); \ 32 | node_sig->AddOutput(kOutputResult); \ 33 | } \ 34 | \ 35 | virtual void Initialize(NodeArguments* args) { \ 36 | auto a = args->GetInput(kInputA); \ 37 | auto b = args->GetInput(kInputB); \ 38 | bool result = *a op *b; \ 39 | args->SetOutput(kOutputResult, result); \ 40 | } \ 41 | \ 42 | virtual void Execute(NodeArguments* args) { \ 43 | Initialize(args); \ 44 | } \ 45 | } 46 | 47 | LOGICAL_NODE(AndNode, &&); 48 | LOGICAL_NODE(OrNode, ||); 49 | LOGICAL_NODE(XorNode, ^); 50 | // clang-format on 51 | 52 | // Convert a boolean value to a pulse. The first edge is triggered when the 53 | // result evaluates true, the second is triggered when the result evaluates 54 | // false. 55 | class IfNode : public BaseNode { 56 | public: 57 | enum { kInputCondition }; 58 | enum { kOutputTrue, kOutputFalse }; 59 | 60 | static void OnRegister(NodeSignature* node_sig) { 61 | node_sig->AddInput(kInputCondition, "Condition"); 62 | node_sig->AddOutput(kOutputTrue, "True"); 63 | node_sig->AddOutput(kOutputFalse, "False"); 64 | } 65 | 66 | virtual void Execute(NodeArguments* args) { 67 | auto value = args->GetInput(kInputCondition); 68 | args->SetOutput(*value ? kOutputTrue : kOutputFalse); 69 | } 70 | }; 71 | 72 | // Convert a boolean value to a pulse. The result is only propagated when the 73 | // first argument is pulsed. The first edge is triggered when the result 74 | // evaluates true, the second is triggered when the result evaluates false. 75 | class IfGateNode : public BaseNode { 76 | public: 77 | enum { kInputTrigger, kInputCondition }; 78 | enum { kOutputTrue, kOutputFalse }; 79 | 80 | static void OnRegister(NodeSignature* node_sig) { 81 | node_sig->AddInput(kInputTrigger, "Trigger"); 82 | node_sig->AddInput(kInputCondition, "Condition"); 83 | node_sig->AddOutput(kOutputTrue, "True"); 84 | node_sig->AddOutput(kOutputFalse, "False"); 85 | } 86 | 87 | virtual void Execute(NodeArguments* args) { 88 | if (args->IsInputDirty(kInputTrigger)) { 89 | auto value = args->GetInput(kInputCondition); 90 | args->SetOutput(*value ? kOutputTrue : kOutputFalse); 91 | } 92 | } 93 | }; 94 | 95 | // Logical Not. 96 | class NotNode : public BaseNode { 97 | public: 98 | enum { kInput }; 99 | enum { kOutput }; 100 | 101 | static void OnRegister(NodeSignature* node_sig) { 102 | node_sig->AddInput(kInput, "In"); 103 | node_sig->AddOutput(kOutput, "Out"); 104 | } 105 | 106 | virtual void Initialize(NodeArguments* args) { 107 | auto value = args->GetInput(kInput); 108 | bool result = !*value; 109 | args->SetOutput(kOutput, result); 110 | } 111 | 112 | virtual void Execute(NodeArguments* args) { Initialize(args); } 113 | }; 114 | 115 | // Stay Latch, to store boolean results. 116 | class StayLatchNode : public BaseNode { 117 | public: 118 | enum { kInputTrue, kInputFalse }; 119 | enum { kOutputBoolean }; 120 | 121 | static void OnRegister(NodeSignature* node_sig) { 122 | node_sig->AddInput(kInputTrue, "True"); 123 | node_sig->AddInput(kInputFalse, "False"); 124 | node_sig->AddOutput(kOutputBoolean, "Boolean"); 125 | } 126 | 127 | virtual void Initialize(NodeArguments* args) { 128 | args->SetOutput(kOutputBoolean, false); 129 | } 130 | 131 | virtual void Execute(NodeArguments* args) { 132 | if (args->IsInputDirty(kInputTrue)) { 133 | args->SetOutput(kOutputBoolean, true); 134 | } else if (args->IsInputDirty(kInputFalse)) { 135 | args->SetOutput(kOutputBoolean, false); 136 | } 137 | } 138 | }; 139 | 140 | void InitializeLogicModule(ModuleRegistry* module_registry) { 141 | Module* module = module_registry->RegisterModule("logic"); 142 | module->RegisterNode("if"); 143 | module->RegisterNode("if_gate"); 144 | module->RegisterNode("and"); 145 | module->RegisterNode("or"); 146 | module->RegisterNode("xor"); 147 | module->RegisterNode("not"); 148 | module->RegisterNode("stay_latch"); 149 | } 150 | 151 | } // namespace breadboard 152 | -------------------------------------------------------------------------------- /src/modules/string.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "breadboard/modules/string.h" 16 | 17 | #include 18 | #include 19 | 20 | #include "breadboard/base_node.h" 21 | #include "breadboard/module_registry.h" 22 | 23 | namespace breadboard { 24 | 25 | // Compares two strings. 26 | class EqualsNode : public BaseNode { 27 | public: 28 | enum { kInputA, kInputB }; 29 | enum { kOutputResult }; 30 | 31 | static void OnRegister(NodeSignature* node_sig) { 32 | node_sig->AddInput(kInputA, "A"); 33 | node_sig->AddInput(kInputB, "B"); 34 | node_sig->AddOutput(kOutputResult, "Result"); 35 | } 36 | 37 | virtual void Initialize(NodeArguments* args) { 38 | auto str_a = args->GetInput(kInputA); 39 | auto str_b = args->GetInput(kInputB); 40 | args->SetOutput(kOutputResult, *str_a == *str_b); 41 | } 42 | 43 | virtual void Execute(NodeArguments* args) { Initialize(args); } 44 | }; 45 | 46 | // Converts the given int to a string. 47 | class IntToStringNode : public BaseNode { 48 | public: 49 | enum { kInputInt }; 50 | enum { kOutputString }; 51 | 52 | static void OnRegister(NodeSignature* node_sig) { 53 | node_sig->AddInput(kInputInt, "Int"); 54 | node_sig->AddOutput(kOutputString, "String"); 55 | } 56 | 57 | virtual void Execute(NodeArguments* args) { 58 | auto i = args->GetInput(kInputInt); 59 | std::stringstream stream; 60 | stream << *i; 61 | args->SetOutput(kOutputString, stream.str()); 62 | } 63 | }; 64 | 65 | // Converts the given float to a string. 66 | class FloatToStringNode : public BaseNode { 67 | public: 68 | enum { kInputFloat }; 69 | enum { kOutputString }; 70 | 71 | static void OnRegister(NodeSignature* node_sig) { 72 | node_sig->AddInput(kInputFloat, "Float"); 73 | node_sig->AddOutput(kOutputString, "String"); 74 | } 75 | 76 | virtual void Execute(NodeArguments* args) { 77 | auto f = args->GetInput(kInputFloat); 78 | std::stringstream stream; 79 | stream << *f; 80 | args->SetOutput(kOutputString, stream.str()); 81 | } 82 | }; 83 | 84 | // Concatenates the given strings. 85 | class ConcatNode : public BaseNode { 86 | public: 87 | enum { kInputA, kInputB }; 88 | enum { kOutputResult }; 89 | 90 | static void OnRegister(NodeSignature* node_sig) { 91 | node_sig->AddInput(kInputA, "A"); 92 | node_sig->AddInput(kInputB, "B"); 93 | node_sig->AddOutput(kOutputResult, "Result"); 94 | } 95 | 96 | virtual void Execute(NodeArguments* args) { 97 | auto str_a = args->GetInput(kInputA); 98 | auto str_b = args->GetInput(kInputB); 99 | args->SetOutput(kOutputResult, *str_a + *str_b); 100 | } 101 | }; 102 | 103 | void InitializeStringModule(ModuleRegistry* module_registry) { 104 | Module* module = module_registry->RegisterModule("string"); 105 | module->RegisterNode("equals"); 106 | module->RegisterNode("int_to_string"); 107 | module->RegisterNode("float_to_string"); 108 | module->RegisterNode("concat"); 109 | } 110 | 111 | } // namespace breadboard 112 | --------------------------------------------------------------------------------