Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatbuffers #30

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
26d2531
Add flatcc and a rudimentary schema
nevyn Jan 24, 2022
4ecbdd0
wip use flatbuffers for wire proto
nevyn Jan 31, 2022
3d790be
I think we need to embed flatcc headers in our release
nevyn Feb 15, 2022
804ab56
flatbuffer binary schema
nevyn Feb 15, 2022
9a87274
libflatccrt as static so we don't have to bundle so
nevyn Feb 16, 2022
14bac7c
reflection schema
nevyn Feb 16, 2022
f7fd53d
store alloverse binary schema in binary, and read it on initialize()
nevyn Feb 16, 2022
bc9113d
some cleanup of HEAD~1
nevyn Feb 16, 2022
c17cc25
giving up on this approach
nevyn Feb 16, 2022
e572c47
split state.h into separate files
nevyn Feb 16, 2022
3cf50ae
Continue splitting state.c into separate files
nevyn Feb 16, 2022
2c64fc1
WIP start converting to actually using flatbuffers
nevyn Feb 16, 2022
ae5a79a
Add C++ flatbuffers
nevyn Feb 17, 2022
09b5c43
WIP Use a mutable tree for in-progress server state...
nevyn Feb 17, 2022
6260b0e
extern C cleanup + mutable_state
nevyn Feb 17, 2022
146b9cf
WIP convert standalone_Server to mutable_state
nevyn Feb 22, 2022
ec5df2c
flatify allocate_track
nevyn Feb 23, 2022
451ffb9
WIP
nevyn Feb 23, 2022
5f0e6ad
more flatifying standalone (3 methods remaining)
nevyn Feb 23, 2022
3e2d96c
cleaning up flatbuffer-related warnings
nevyn Feb 23, 2022
cc27095
fix a bunch of warnings (this should go on main...)
nevyn Feb 23, 2022
f21d1eb
flatbuff'd client and clientproxy
nevyn Feb 23, 2022
dc59766
flat setServerTime()
nevyn Feb 24, 2022
6f01c9b
flatify simulation.c
nevyn Feb 24, 2022
fef37b6
simulation > cpp
nevyn Feb 25, 2022
1eebbf1
flatify stick_movement and related files
nevyn Mar 1, 2022
5dd96ad
flatify pose_movement
nevyn Mar 3, 2022
cae98ae
WIP flatifying animation by adding simulation cache
nevyn Mar 3, 2022
f87d5d1
working on c++ifying animation_prop... this is about as far as I'll g…
nevyn Mar 4, 2022
22a1f24
WIP flatify animation prop
nevyn Mar 7, 2022
2bdfc87
more wip animation
nevyn Mar 7, 2022
f593458
just trying to make things compile...
nevyn Mar 8, 2022
2219fc1
fix anim compile errors so we can put it on hold
nevyn Mar 10, 2022
8b2ec12
compile as c++11 + various other compile fixes
nevyn Mar 10, 2022
0ed56ce
fix some more warnings, e g standalone
nevyn Mar 11, 2022
1cdb699
Remove Lua API
nevyn Mar 15, 2022
4d7fc15
Fix a bunch of C++ linker errors
nevyn Mar 15, 2022
f13a04c
Make state_diff duplicatable
nevyn Mar 23, 2022
2a3119b
state_get_entity, entity_get_parent, entity_get_transform
nevyn Mar 23, 2022
a36e485
StateT: switch from unique_ptr to shared_ptr
nevyn Mar 23, 2022
b5405b7
fail to make addEntity and findNextEntity more efficient
nevyn Mar 23, 2022
74fe495
mock out add/change
nevyn Mar 23, 2022
f94af33
Cmake: pretty please give me debug symbols in xcode.
nevyn Mar 24, 2022
f338e14
all entities must have 'components' and 'transform'
nevyn Mar 24, 2022
2be7792
Implement addEntityFromSpec as a ComponentsT
nevyn Mar 24, 2022
527ecda
spawn/change: parse json into ComponentsT
nevyn Mar 24, 2022
6f91dbc
remove flex from components for now
nevyn Mar 28, 2022
fe75f8f
ugly hack impl of changeComponents
nevyn Mar 28, 2022
ec80a75
WIP removeEntities
nevyn Mar 28, 2022
35c8b23
Merge remote-tracking branch 'origin/main' into flatbuffers
nevyn Apr 27, 2022
1c808db
Start implementing allo_state_diff_compute
nevyn Apr 27, 2022
5b0a304
didn't I already add an editorconfig?
nevyn Apr 28, 2022
e6e767d
make diff.cpp compile
nevyn Apr 28, 2022
ed756ee
new_components and removed_components
nevyn Apr 28, 2022
005c620
diff: Use UnPack to compare components
nevyn Apr 28, 2022
b131a05
diff: deleted_entities
nevyn Apr 28, 2022
2aa707c
hexdump text version of schema
Voxar Apr 28, 2022
11464e2
server: assert flatbuffer ops
Voxar Apr 28, 2022
73ba69f
fix alloverse_schema_text_size
nevyn May 5, 2022
7583dc0
Add comps: geometry, ui, collider, grabbable
nevyn May 5, 2022
d4d0b55
typo in pose_movement
nevyn May 5, 2022
2d2c221
less shouting
nevyn May 5, 2022
264e8ef
don't reuse `flat` between buffers
nevyn May 5, 2022
13f2e67
fix crash when computing statediff
nevyn May 5, 2022
bf7743b
actually compute diff
nevyn May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
root = true
[*]
indent_style = space
indent_size = 4
insert_final_newline = true
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
[submodule "lib/tinycthread"]
path = lib/tinycthread
url = https://github.com/tinycthread/tinycthread
[submodule "lib/flatcc"]
path = lib/flatcc
url = https://github.com/dvidelabs/flatcc.git
[submodule "lib/flatbuffers"]
path = lib/flatbuffers
url = https://github.com/google/flatbuffers.git
97 changes: 86 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
cmake_minimum_required(VERSION 3.10.0)

###################
## Settings
###################

project(allonet VERSION 0.1.0)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # for FindLibav
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # for FindLibav
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS "YES")
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET "11.0")
macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
endmacro (set_xcode_property)





option(ALLONET_BUILD_STATIC "Whether to build allonet as a static library instead of dynamic" OFF)
set(ALLONET_THREADING_STRATEGY "force_link_tinycthread" CACHE STRING "Whether to use native_if_available (native means threads.h from C11, with fallback to tinycthread), force_link_tinycthread or force_use_tinycthread (includes but does not link)")
Expand All @@ -19,6 +34,10 @@ ELSE()
FATAL_ERROR("Unsupported platform")
ENDIF()

###################
## Dependencies
###################

include_directories(
"${PROJECT_SOURCE_DIR}/include"
"lib/mathc"
Expand All @@ -41,8 +60,37 @@ add_subdirectory (lib/cJSON)

add_definitions(-DMATHC_USE_DOUBLE_FLOATING_POINT)

###################
## Schema
###################

SET(SHARED_WAS ${BUILD_SHARED_LIBS})
SET(BUILD_SHARED_LIBS Off)
SET(FLATBUFFERS_BUILD_TESTS Off)
SET(FLATBUFFERS_INSTALL Off)
add_subdirectory(lib/flatcc)
add_subdirectory(lib/flatbuffers)
SET(BUILD_SHARED_LIBS "${SHARED_WAS}")
set(GEN_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/allonet/schema")
set(GEN_PRIV_DIR "${CMAKE_CURRENT_BINARY_DIR}/include/")
set(FBS_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

include_directories("${GEN_DIR}" "${GEN_PRIV_DIR}" "lib/flatbuffers/include")

add_custom_target(gen_alloverse_fbs ALL)
add_custom_command (
TARGET gen_alloverse_fbs
COMMAND ${CMAKE_COMMAND} -E make_directory "${GEN_DIR}"
COMMAND flatcc_cli --schema -a -o "${GEN_DIR}" "${FBS_DIR}/alloverse.fbs" "${CMAKE_CURRENT_SOURCE_DIR}/lib/flatcc/reflection/reflection.fbs"
COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/generate-schema-blob.sh
COMMAND flatc --cpp --reflect-names --gen-object-api --gen-mutable --gen-json-emit --gen-name-strings --gen-compare --cpp-ptr-type "std::shared_ptr" -o "${GEN_PRIV_DIR}" "${FBS_DIR}/alloverse.fbs"
DEPENDS flatcc_cli flatc "${FBS_DIR}/alloverse.fbs"
)


# shared library
###################
## Target 'allonet'
###################

set(INCLUDE_FILES_PREFIX include/allonet)
set(INCLUDE_FILES
Expand All @@ -55,18 +103,32 @@ set(INCLUDE_FILES
${INCLUDE_FILES_PREFIX}/net.h
${INCLUDE_FILES_PREFIX}/server.h
${INCLUDE_FILES_PREFIX}/state.h
${INCLUDE_FILES_PREFIX}/threading.h
${INCLUDE_FILES_PREFIX}/schema/alloverse_builder.h
${INCLUDE_FILES_PREFIX}/schema/alloverse_reader.h
${INCLUDE_FILES_PREFIX}/schema/alloverse_verifier.h
${INCLUDE_FILES_PREFIX}/schema/flatbuffers_common_builder.h
${INCLUDE_FILES_PREFIX}/schema/flatbuffers_common_reader.h
${INCLUDE_FILES_PREFIX}/schema/reflection_builder.h
${INCLUDE_FILES_PREFIX}/schema/reflection_reader.h
${INCLUDE_FILES_PREFIX}/schema/reflection_verifier.h
${INCLUDE_FILES_PREFIX}/state/diff.h
${INCLUDE_FILES_PREFIX}/state/intent.h
${INCLUDE_FILES_PREFIX}/state/interaction.h
${INCLUDE_FILES_PREFIX}/state/state_read.h
${INCLUDE_FILES_PREFIX}/state/state_write.h
)
set(SOURCE_FILES_PREFIX src)
set(SOURCE_FILES
${SOURCE_FILES_PREFIX}/client/_client.h
${SOURCE_FILES_PREFIX}/client/client.c
${SOURCE_FILES_PREFIX}/simulation/animation.c
${SOURCE_FILES_PREFIX}/simulation/animation_prop.c
${SOURCE_FILES_PREFIX}/simulation/grabbing.c
${SOURCE_FILES_PREFIX}/simulation/pose_movement.c
${SOURCE_FILES_PREFIX}/simulation/simulation.c
${SOURCE_FILES_PREFIX}/simulation/animation.cpp
${SOURCE_FILES_PREFIX}/simulation/animation_prop.cpp
${SOURCE_FILES_PREFIX}/simulation/grabbing.cpp
${SOURCE_FILES_PREFIX}/simulation/pose_movement.cpp
${SOURCE_FILES_PREFIX}/simulation/simulation.cpp
${SOURCE_FILES_PREFIX}/simulation/simulation.h
${SOURCE_FILES_PREFIX}/simulation/stick_movement.c
${SOURCE_FILES_PREFIX}/simulation/stick_movement.cpp
${SOURCE_FILES_PREFIX}/media/media.h
${SOURCE_FILES_PREFIX}/media/media.c
${SOURCE_FILES_PREFIX}/media/audio/audio.c
Expand All @@ -91,8 +153,13 @@ set(SOURCE_FILES
${SOURCE_FILES_PREFIX}/sha1.h
${SOURCE_FILES_PREFIX}/sha256.c
${SOURCE_FILES_PREFIX}/sha256.h
${SOURCE_FILES_PREFIX}/standalone_server.c
${SOURCE_FILES_PREFIX}/state.c
${SOURCE_FILES_PREFIX}/standalone_server.cpp
${SOURCE_FILES_PREFIX}/state/diff.cpp
${SOURCE_FILES_PREFIX}/state/intent.c
${SOURCE_FILES_PREFIX}/state/interaction.c
${SOURCE_FILES_PREFIX}/state/state_read.cpp
${SOURCE_FILES_PREFIX}/state/state_write.cpp
${SOURCE_FILES_PREFIX}/state/state.c
${SOURCE_FILES_PREFIX}/util.cpp
${SOURCE_FILES_PREFIX}/util.h
lib/mathc/mathc.c
Expand All @@ -118,6 +185,8 @@ add_library(allonet ${ALLONET_BUILDTYPE})

add_library(allonet_av ${ALLONET_BUILDTYPE})

add_dependencies(allonet gen_alloverse_fbs)

# Versioning
# crazy relative-path hack courtesy of running bash on windows and having mixed path types...
file(RELATIVE_PATH GENERATE_VERSION_SH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/generate-version.sh)
Expand Down Expand Up @@ -197,7 +266,7 @@ include_directories(SYSTEM
)

target_link_libraries(allonet
enet cjson-static cjson_utils-static opus
enet cjson-static cjson_utils-static opus flatccrt flatbuffers
${PLATFORM_LIBS}
)

Expand Down Expand Up @@ -242,3 +311,9 @@ add_test(NAME allonet_jobs_test COMMAND allonet_jobs_test)
add_executable(allonet_delta_test test/delta_test.c)
target_link_libraries(allonet_delta_test allonet unity cjson)
add_test(NAME allonet_delta_test COMMAND allonet_delta_test)


# stupid cmake sets this to NO for all targets even with CMAKE_XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS set to YES??? :((
set_xcode_property(allonet GCC_GENERATE_DEBUGGING_SYMBOLS YES)
set_xcode_property(allonet_av GCC_GENERATE_DEBUGGING_SYMBOLS YES)
set_xcode_property(standalone_server GCC_GENERATE_DEBUGGING_SYMBOLS YES)
189 changes: 189 additions & 0 deletions alloverse.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
// Schema file for the Alloverse network protocol

namespace Alloverse;

///////////////////////////////////////////////////////////////
// Legacy Stucture
///////////////////////////////////////////////////////////////

table State {
revision:uint64;
entities:[Entity];
}

table Entity {
id:string (key);
owner_agent_id:string;
components:Components;
}

table Components {
transform:TransformComponent;
relationships:RelationshipsComponent;
live_media:LiveMediaComponent;
clock:ClockComponent;
intent:IntentComponent;
property_animations:PropertyAnimationsComponent;
geometry:GeometryComponent;
ui:UIComponent;
collider:ColliderComponent;
grabbable:GrabbableComponent;
// XXX: Make sure to update allo_mutable_state::changeComponents and allo_state_diff_compute when adding more fields

// todo: non-conforming components as flex or json
}

///////////////////////////////////////////////////////////////
// Hopefully the new structure, after refactors:
///////////////////////////////////////////////////////////////

/*
table State2 {
revision:uint64;
entities:[Entity2];
components:[Components2];
}

table Entity2 {
id:string;
owner_agent_id:string;
}

table Components2 {
transform:[TransformComponent];
relationships:[RelationshipsComponent];
flex:[ubyte]; // (flexbuffer) of map from compname -> comp
}

// Every Component has to start with one of these
table ComponentBase {
eid:string;
}
*/

///////////////////////////////////////////////////////////////
// Components
///////////////////////////////////////////////////////////////

table TransformComponent {
matrix:Mat4;
}

table RelationshipsComponent {
parent:string;
}

table LiveMediaMetadata {
// audio
sample_rate:int;
channel_layout:string;

// video
width:int;
height:int;
}
table LiveMediaComponent {
track_id:int;
type:string;
format:string;
metadata:LiveMediaMetadata;
}

table ClockComponent {
time:double;
}

table IntentComponent {
actuate_pose:string;
from_avatar:string;
}

table NumberAnimationValue {
number:double;
}
table VectorAnimationValue {
vector:Vec3;
}
table RotationAnimationValue {
angle:double;
axis:Vec3;
}
table TransformAnimationValue {
matrix:Mat4;
}

union AnimationValue {
number:NumberAnimationValue,
vector:VectorAnimationValue,
rotation:RotationAnimationValue,
matrix:TransformAnimationValue
}
table PropertyAnimation {
id:string (key);
path:string;
from:AnimationValue;
to:AnimationValue;
start_at:double = 0.0;
duration:double = 1.0;
easing:string;
repeats:bool = false;
autoreverses:bool = false;
}
table PropertyAnimationsComponent {
animations:[PropertyAnimation];
}

table GeometryComponent {
type:string;
// only valid if type=="asset" or type=="hardcoded-model"
name:string;

// only valid if type=="inline"
vertices:[double]; // [x1, y1, z1, x2, y2, z2, ...]
normals:[double]; // [x1, y1, z1, x2, y2, z2, ...]
uvs:[double]; // [u1, v1, u2, v2, u3, v3, ...]
triangles:[int]; // [i1, j1, k1, i2, j2, k2, ...]
}

table UIComponent {
view_id:string;
}

table ColliderComponent {
type:string;
width:double;
height:double;
depth:double;
}

table GrabbableComponent {
grabbable:bool;
actuate_on:string;
translation_constraint:[double]; // [x, y, z]
rotation_constraint:[double]; // [x, y, z]
target_hand_transform:Mat4;
}

///////////////////////////////////////////////////////////////
// Structs
///////////////////////////////////////////////////////////////

struct Mat4 {
m:[double:16];
}

struct Vec3 {
v:[double:3];
}

///////////////////////////////////////////////////////////////
// Interactions and related types
///////////////////////////////////////////////////////////////

table EntitySpec {
components:Components;
children:[EntitySpec];
}


root_type State;
21 changes: 21 additions & 0 deletions generate-schema-blob.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# Input variables
OUT_FILE="$SCRIPT_DIR/src/alloverse_binary_schema.h"
SCHEMA_FILE="$SCRIPT_DIR/alloverse.fbs"
BINARY_FILE="$SCRIPT_DIR/include/allonet/schema/alloverse.bfbs"
VAR_NAME="alloverse_schema"

# Script

# Binary rep
echo "static const unsigned char ${VAR_NAME}_bytes[] = {" > "$OUT_FILE"
hexdump -ve '1/1 "0x%02x, "' "$BINARY_FILE" >> "$OUT_FILE"
echo "0x00}; static const int ${VAR_NAME}_size = sizeof(${VAR_NAME}_bytes); " >> "$OUT_FILE"

# Text rep
echo "static const unsigned char ${VAR_NAME}_text[] = {" >> "$OUT_FILE"
hexdump -ve '1/1 "0x%02x, "' "$SCHEMA_FILE" >> "$OUT_FILE"
echo "0x00}; static const int ${VAR_NAME}_text_size = sizeof(${VAR_NAME}_text); " >> "$OUT_FILE"
8 changes: 8 additions & 0 deletions include/allonet/arr.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@
#define arr_clear(a)\
(a)->length = 0

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

extern void __arr_reserve(void** data, size_t n, size_t* capacity, size_t stride);

#ifdef __cplusplus
}
#endif // __cplusplus
Loading