Object sockets work now, but only the new Object Transforms and the Particle Mesh Emitter node use it. The emitter does not actually use the mesh surface yet. Instead, new particles are just emitted around the origin of the object. Internally, handles to object data blocks are passed around in the network, instead of raw object pointers. Using handles has a couple of benefits: * The caller of the function has control over which handles can be resolved and therefore limit access to specific data. The set of data blocks that is accessed by a node tree should be known statically. This is necessary for a proper integration with the dependency graph. * When the pointer to an object changes (e.g. after restarting Blender), all handles are still valid. * When an object is deleted, the handle is invalidated without causing crashes. * The handle is just an integer that can be stored per particle and can be cached easily. The mapping between handles and their corresponding data blocks is stored in the Simulation data block.
71 lines
2.0 KiB
C++
71 lines
2.0 KiB
C++
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#ifndef __FN_MULTI_FUNCTION_CONTEXT_HH__
|
|
#define __FN_MULTI_FUNCTION_CONTEXT_HH__
|
|
|
|
/** \file
|
|
* \ingroup fn
|
|
*
|
|
* An #MFContext is passed along with every call to a multi-function. Right now it does nothing,
|
|
* but it can be used for the following purposes:
|
|
* - Pass debug information up and down the function call stack.
|
|
* - Pass reusable memory buffers to sub-functions to increase performance.
|
|
* - Pass cached data to called functions.
|
|
*/
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
#include "BLI_map.hh"
|
|
|
|
namespace blender::fn {
|
|
|
|
class MFContext;
|
|
|
|
class MFContextBuilder {
|
|
private:
|
|
Map<std::string, const void *> global_contexts_;
|
|
|
|
friend MFContext;
|
|
|
|
public:
|
|
template<typename T> void add_global_context(std::string name, const T *context)
|
|
{
|
|
global_contexts_.add_new(std::move(name), (const void *)context);
|
|
}
|
|
};
|
|
|
|
class MFContext {
|
|
private:
|
|
MFContextBuilder &builder_;
|
|
|
|
public:
|
|
MFContext(MFContextBuilder &builder) : builder_(builder)
|
|
{
|
|
}
|
|
|
|
template<typename T> const T *get_global_context(StringRef name) const
|
|
{
|
|
const void *context = builder_.global_contexts_.lookup_default_as(name, nullptr);
|
|
/* TODO: Implement type checking. */
|
|
return (const T *)context;
|
|
}
|
|
};
|
|
|
|
} // namespace blender::fn
|
|
|
|
#endif /* __FN_MULTI_FUNCTION_CONTEXT_HH__ */
|