Giter VIP home page Giter VIP logo

peng-eie-capi-onsite's Introduction

SpatialOS C example project

Dependencies

This project contains workers written in both C and C++ and use CMake as their build system. Your system needs to satisfy the C++ prerequisites. In practice, this just means having a fairly recent compiler that supports C++11 or later.

Quick start

Build the project and start it with the default launch configuration:

spatial worker build --target windows
spatial local launch

(Replacing windows with macos on macOS, or linux on Linux).

This will launch SpatialOS locally with a single C++ "physics" worker that updates the position of a single entity. You may also see a 2nd entity called "physics-worker" created. This entity represents the managed worker itself.

Note: If you run spatial worker build without a --target parameter (or with the wrong target parameter), then the CMake cache for each worker (workers/<worker>/cmake_build) may end up in a corrupt state. To recover, just run spatial worker clean to delete the CMake caches.

Now, you can connect either one of the two C client workers (one implemented using "direct" serialization, the other implemented using "vtable" serialization). These workers can be launched with the following commands:

  • Client (direct): spatial local worker launch client_direct local
  • Client (vtable): spatial local worker launch client_vtable local

Scenario

This project is used to showcase the C API and how it can be used to implement a simple client worker which visualizes the state of a single entity whose position is updated by a "physics" worker. As serialization in the C API can be implemented in two different ways, we provide two implementations of the same worker in workers/c_client_direct and workers/c_client_vtable. Either one of these can be used as a basis for further experimentation, and the client worker that's not being used can easily be deleted without breaking any other functionality.

When a client worker connects, it sends a command to the C++ worker (on the sample.Login component). The C++ worker then modifies the entity's write ACLs to delegate component 1001 (sample.ClientData) to the client, using the CallerWorkerAttributes field of the CommandRequestOp. This causes the entity to be checked out by the client worker, and the client worker will begin to receive component updates for position changes. The physics worker will also begin to send a simple command to the client every few seconds.

Snapshot

The snapshot exists in both text and binary format in the snapshots folder. There is no script to generate the snapshot as the snapshot was written by hand in the text format, but it's possible to make simple changes to the text format and regenerate the binary snapshot from it. To update the binary snapshot after making a change, run the following command:

spatial project history snapshot convert --input-format=text --input=snapshots/default.txt --output-format=binary --output=snapshots/default.snapshot

peng-eie-capi-onsite's People

Contributors

danielimprobable avatar mend-for-github-com[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.