SuperDex Physics C++ API
Loading...
Searching...
No Matches
mochi_async_scene.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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
17#pragma once
18
19#include "mochi_enums.h"
20#include "mochi_handle.h"
21#include "mochi_scene.h"
22#include "mochi_structs.h"
23
24/********************************************************************************
25 IMPORTANT: PLEASE KEEP HEADER INCLUDES TO A MINIMUM.
26 If you must include a mochi_core header, then please make sure that it only
27 declares the data types (not containing other implementation details).
28*********************************************************************************/
30
31#include <functional>
32#include <string_view>
33
34namespace superdex {
35
36class Actor;
37class Context;
38
40 public:
41 [[nodiscard]] virtual Context* GetContext() = 0;
42
43 virtual void QueueCommand(std::function<void(Scene*)> callback) = 0;
44
45 virtual void QueueActorCommand(ActorHandle actor, std::function<void(Actor*)> callback) = 0;
46
47 virtual void WaitForQueuedCommands() = 0;
48
50 std::string_view debugName,
51 std::function<void(StepInfo const&)> callback,
52 int priority = Scene::kDefaultCallbackPriority) = 0;
53
55 std::string_view debugName,
56 std::function<void(StepInfo const&)> callback,
57 int priority = Scene::kDefaultCallbackPriority) = 0;
58
59 virtual void CancelCallback(CallbackHandle handle) = 0;
60
61 virtual QueryHandle
62 RegisterActorQuery(ActorHandle actor, QueryType type, bool forceCompute = false) = 0;
63
64 virtual void CancelActorQuery(ActorHandle actor, QueryHandle handle) = 0;
65
66 [[nodiscard]] virtual AsyncStepParams GetAsyncStepParams() const = 0;
67
68 virtual void SetAsyncStepParams(AsyncStepParams const& params, Error& error) = 0;
69
70 virtual void Pause(bool shouldPause) = 0;
71
72 [[nodiscard]] virtual bool IsPaused() const = 0;
73
74 virtual void RequestStepThenPause() = 0;
75
76 protected:
77 /// Don't delete the AsyncScene pointer. Call @ref Context::DestroyAsyncScene.
78 virtual ~AsyncScene() = default;
79};
80
81} // namespace superdex
Represents a simulated body (actor) in a scene.
Definition mochi_actor.h:51
Manages a simulation scene that steps asynchronously using the SuperDex Physics worker pool.
virtual ~AsyncScene()=default
Don't delete the AsyncScene pointer. Call Context::DestroyAsyncScene.
virtual bool IsPaused() const =0
Check if the simulation is currently paused.
virtual void Pause(bool shouldPause)=0
Pause or unpause the simulation.
virtual CallbackHandle RegisterPreStepCallback(std::string_view debugName, std::function< void(StepInfo const &)> callback, int priority=Scene::kDefaultCallbackPriority)=0
Register a callback to execute before each simulation step.
virtual void RequestStepThenPause()=0
Advance the simulation by exactly one step, then pause.
virtual Context * GetContext()=0
Get the Context that owns this AsyncScene.
virtual void QueueActorCommand(ActorHandle actor, std::function< void(Actor *)> callback)=0
Queue a command to operate on a specific actor on the simulation thread.
virtual void CancelActorQuery(ActorHandle actor, QueryHandle handle)=0
Cancel a query previously registered with an actor.
virtual CallbackHandle RegisterPostStepCallback(std::string_view debugName, std::function< void(StepInfo const &)> callback, int priority=Scene::kDefaultCallbackPriority)=0
Register a callback to execute after each simulation step.
virtual void CancelCallback(CallbackHandle handle)=0
Cancel a previously registered callback.
virtual void SetAsyncStepParams(AsyncStepParams const &params, Error &error)=0
Set the parameters controlling async stepping behavior.
virtual void QueueCommand(std::function< void(Scene *)> callback)=0
Queue a command to execute on the simulation thread before the next step.
virtual AsyncStepParams GetAsyncStepParams() const =0
Get the parameters controlling async stepping behavior.
virtual void WaitForQueuedCommands()=0
Block the calling thread until all previously queued commands have executed.
virtual QueryHandle RegisterActorQuery(ActorHandle actor, QueryType type, bool forceCompute=false)=0
Register a query with an actor.
Main entry point for SuperDex Physics simulation.
Represents a simulation scene.
Definition mochi_scene.h:45
static constexpr int kDefaultCallbackPriority
Default priority for callback ordering.
QueryType
Type of query data to compute for an actor or constraint.
Unique identifier for an Actor within a Scene.
Parameters controlling the stepping behavior of an AsyncScene.
Unique identifier for a callback registration within a Scene.
Unique identifier for a query within a Scene.
Information passed to per-step callbacks.