CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cugl::physics2::distrib::ObstacleFactory Class Reference

#include <CUObstacleFactory.h>

Public Member Functions

static ::std::shared_ptr< ObstacleFactoryalloc ()
 
virtual ObstacleScene createObstacle (const std::vector< std::byte > &params)
 

Detailed Description

A factory for creating shared obstacles.

This class provides a standard template for an shareable creation of obstacles. These factories can be attached to the provided net physics controller so that creation of obstacles can be synchronized across devices without the need to send texture and body information.

In order for every client to be updated when a new obstacle is created, they must have a uniform way to share info about the obstacle to be created. However, syncing the texture and body data is very costly, so this class is a template for creating an obstacle and (optionally) a scene node from serialized parameters.

Member Function Documentation

◆ alloc()

static ::std::shared_ptr< ObstacleFactory > cugl::physics2::distrib::ObstacleFactory::alloc ( )
inline

Returns a newly allocated obstacle factory.

◆ createObstacle()

virtual ObstacleScene cugl::physics2::distrib::ObstacleFactory::createObstacle ( const std::vector< std::byte > &  params)
inlinevirtual

Returns a new obstacle from the serialized parameters

If you want the obstacle to be accompanied by a scene node, you must return a pair of the obstacle and the scene node. You must also call the NetEventController#enablePhysics() method and provide it a function for linking the obstacle and scene node.

It is possible for the SceneNode in the returned part to be nullptr. In that case, the obstacle will be created without a scene node.

The actual parameters are up to your network protocol. Some typical parameters include:

  • The texture name
  • The size of the obstacle
  • The position/velocity of the obstacle
  • Any metadata about the obstacle
Parameters
paramsThe serialized parameters for the obstacle

The documentation for this class was generated from the following file: