Allow CNAT_* constants in VertexCNAT definition of DefCore (#1307)

Also fix decompiling of none-values in bitfields.
stable-6.1
Sven Eberhardt 2015-04-28 00:18:20 +02:00 committed by Maikel de Vries
parent b1b8fedb25
commit 6699cd3712
2 changed files with 23 additions and 3 deletions

View File

@ -426,6 +426,9 @@ struct StdArrayDefaultArrayAdapt
template <class T, class D>
inline StdArrayDefaultArrayAdapt<T, D> mkArrayAdaptDefArr(T *pArray, size_t iSize, const D &rDefault) { return StdArrayDefaultArrayAdapt<T, D>(pArray, iSize, rDefault); }
#define mkArrayAdaptDMA(A, D) mkArrayAdaptDefArr(A, sizeof(A) / sizeof(*(A)), D)
template <class T, class D, class M>
inline StdArrayDefaultArrayAdapt<T, D, M> mkArrayAdaptDefArrMap(T *pArray, size_t iSize, const D &rDefault, const M &map) { return StdArrayDefaultArrayAdapt<T, D, M>(pArray, iSize, rDefault, map); }
#define mkArrayAdaptDMAM(A, D, M) mkArrayAdaptDefArrMap(A, sizeof(A) / sizeof(*(A)), D, M)
// * Insertion Adaptor
// Compile a value before / after another
@ -934,12 +937,14 @@ struct StdBitfieldAdapt
// writing?
if (!pComp->isCompiler())
{
T val = rVal;
T val = rVal, orig_val = rVal;
// Write until value is comsumed
bool fFirst = true;
for (const Entry *pName = pNames; val && pName->Name; pName++)
for (const Entry *pName = pNames; pName->Name; pName++)
if ((pName->Val & val) == pName->Val)
{
// Avoid writing meaningless none-values (e.g. Category=C4D_None|C4D_Object)
if (orig_val && !pName->Val) continue;
// Put "|"
if (!fFirst) pComp->Separator(StdCompiler::SEP_VLINE);
// Put name

View File

@ -528,6 +528,21 @@ void C4Shape::CreateOwnOriginalCopy(C4Shape &rFrom)
void C4Shape::CompileFunc(StdCompiler *pComp, const C4Shape *default_shape)
{
const StdBitfieldEntry<int32_t> ContactDirections[] =
{
{ "CNAT_None", CNAT_None },
{ "CNAT_Left", CNAT_Left },
{ "CNAT_Right", CNAT_Right },
{ "CNAT_Top", CNAT_Top },
{ "CNAT_Bottom", CNAT_Bottom },
{ "CNAT_Center", CNAT_Center },
{ "CNAT_MultiAttach", CNAT_MultiAttach },
{ "CNAT_NoCollision", CNAT_NoCollision },
{ NULL, 0 }
};
// a default shape is given in object compilation context only
bool fRuntime = !!default_shape;
C4Shape default_def_shape;
@ -540,7 +555,7 @@ void C4Shape::CompileFunc(StdCompiler *pComp, const C4Shape *default_shape)
pComp->Value(mkNamingAdapt( VtxNum, "Vertices", default_shape->VtxNum));
pComp->Value(mkNamingAdapt( mkArrayAdaptDMA(VtxX, default_shape->VtxX), "VertexX", default_shape->VtxX));
pComp->Value(mkNamingAdapt( mkArrayAdaptDMA(VtxY, default_shape->VtxY), "VertexY", default_shape->VtxY));
pComp->Value(mkNamingAdapt( mkArrayAdaptDMA(VtxCNAT, default_shape->VtxCNAT), "VertexCNAT", default_shape->VtxCNAT));
pComp->Value(mkNamingAdapt( mkArrayAdaptDMAM(VtxCNAT, default_shape->VtxCNAT, [&](decltype(*VtxCNAT) &elem){ return mkBitfieldAdapt<int32_t>(elem, ContactDirections); }), "VertexCNAT", default_shape->VtxCNAT));
pComp->Value(mkNamingAdapt( mkArrayAdaptDMA(VtxFriction, default_shape->VtxFriction), "VertexFriction", default_shape->VtxFriction));
pComp->Value(mkNamingAdapt( ContactDensity, "ContactDensity", default_shape->ContactDensity));
pComp->Value(mkNamingAdapt( FireTop, "FireTop", default_shape->FireTop));