refactor(enum): made SurfaceType an enum class and added support for enum class in autogen

This commit is contained in:
maelstrom 2025-06-05 00:54:14 +02:00
parent 6a58aa7fbd
commit 5f3bed1c58
6 changed files with 38 additions and 38 deletions

View file

@ -146,7 +146,7 @@ static void writePropertyGetHandler(std::ofstream& out, ClassAnalysis state) {
} else if (prop.cframeMember == CFrameMember_Rotation) { } else if (prop.cframeMember == CFrameMember_Rotation) {
out << "\n return Variant(" << prop.fieldName << ".ToEulerAnglesXYZ());"; out << "\n return Variant(" << prop.fieldName << ".ToEulerAnglesXYZ());";
} else if (prop.backingFieldType == "EnumItem") { } else if (prop.backingFieldType == "EnumItem") {
out << "\n return Variant(EnumType::" << prop.backingFieldEnum << ".FromValueInternal(" << prop.fieldName << "));"; out << "\n return Variant(EnumType::" << prop.backingFieldEnum << ".FromValueInternal((int)" << prop.fieldName << "));";
} else { } else {
out << "\n return Variant(" << castToVariant(prop.fieldName, prop.backingFieldType) << ");"; out << "\n return Variant(" << castToVariant(prop.fieldName, prop.backingFieldType) << ");";
} }

View file

@ -12,15 +12,15 @@ enum DEF_ENUM NormalId {
Front = 5 Front = 5
}; };
enum DEF_ENUM SurfaceType { enum class DEF_ENUM SurfaceType {
SurfaceSmooth = 0, Smooth = 0,
SurfaceGlue = 1, Glue = 1,
SurfaceWeld = 2, Weld = 2,
SurfaceStuds = 3, Studs = 3,
SurfaceInlets = 4, Inlet = 4,
SurfaceUniversal = 5, Universal = 5,
SurfaceHinge = 6, Hinge = 6,
SurfaceMotor = 7, Motor = 7,
}; };
namespace EnumType { namespace EnumType {

View file

@ -120,7 +120,7 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
case Front: return frontSurface; case Front: return frontSurface;
case Back: return backSurface; case Back: return backSurface;
} }
return SurfaceSmooth; // Unreachable return SurfaceType::Smooth; // Unreachable
} }
float Part::GetSurfaceParamA(Vector3 face) { float Part::GetSurfaceParamA(Vector3 face) {
@ -199,14 +199,14 @@ bool Part::checkSurfacesTouching(CFrame surfaceFrame, Vector3 size, Vector3 myFa
} }
std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType a, SurfaceType b) { std::optional<std::shared_ptr<JointInstance>> makeJointFromSurfaces(SurfaceType a, SurfaceType b) {
if (a == SurfaceWeld || b == SurfaceWeld || a == SurfaceGlue || b == SurfaceGlue) return Weld::New(); if (a == SurfaceType::Weld || b == SurfaceType::Weld || a == SurfaceType::Glue || b == SurfaceType::Glue) return Weld::New();
if ((a == SurfaceStuds && (b == SurfaceInlets || b == SurfaceUniversal)) if ((a == SurfaceType::Studs && (b == SurfaceType::Inlet || b == SurfaceType::Universal))
|| (a == SurfaceInlets && (b == SurfaceStuds || b == SurfaceUniversal)) || (a == SurfaceType::Inlet && (b == SurfaceType::Studs || b == SurfaceType::Universal))
|| (a == SurfaceUniversal && (b == SurfaceStuds || b == SurfaceInlets || b == SurfaceUniversal))) || (a == SurfaceType::Universal && (b == SurfaceType::Studs || b == SurfaceType::Inlet || b == SurfaceType::Universal)))
return Snap::New(); return Snap::New();
if (a == SurfaceHinge) if (a == SurfaceType::Hinge)
return Rotate::New(); return Rotate::New();
if (a == SurfaceMotor) if (a == SurfaceType::Motor)
return RotateV::New(); return RotateV::New();
return std::nullopt; return std::nullopt;
} }
@ -251,7 +251,7 @@ void Part::MakeJoints() {
SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace)); SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace));
// If it is a hinge, only attach if actually touching the "hinge" // If it is a hinge, only attach if actually touching the "hinge"
if ((mySurface == SurfaceHinge || mySurface == SurfaceMotor) && !checkSurfacesTouching(surfaceFrame, Vector3(0.4, 0.4, 0.4), myFace, otherFace, otherPart)) continue; if ((mySurface == SurfaceType::Hinge || mySurface == SurfaceType::Motor) && !checkSurfacesTouching(surfaceFrame, Vector3(0.4, 0.4, 0.4), myFace, otherFace, otherPart)) continue;
// Create contacts // Create contacts
// Contact always occurs at the center of Part0's surface (even if that point does not overlap both surfaces) // Contact always occurs at the center of Part0's surface (even if that point does not overlap both surfaces)

View file

@ -70,12 +70,12 @@ public:
DEF_PROP bool locked = false; DEF_PROP bool locked = false;
DEF_PROP_CATEGORY(SURFACE) DEF_PROP_CATEGORY(SURFACE)
DEF_PROP SurfaceType topSurface = SurfaceType::SurfaceStuds; DEF_PROP SurfaceType topSurface = SurfaceType::Studs;
DEF_PROP SurfaceType bottomSurface = SurfaceType::SurfaceInlets; DEF_PROP SurfaceType bottomSurface = SurfaceType::Inlet;
DEF_PROP SurfaceType leftSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType leftSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType rightSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType rightSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType frontSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType frontSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType backSurface = SurfaceType::SurfaceSmooth; DEF_PROP SurfaceType backSurface = SurfaceType::Smooth;
DEF_PROP_CATEGORY(SURFACE_INPUT) DEF_PROP_CATEGORY(SURFACE_INPUT)
DEF_PROP float topParamA = -0.5; DEF_PROP float topParamA = -0.5;

View file

@ -154,12 +154,12 @@ void renderParts() {
shader->set("texScale", part->size); shader->set("texScale", part->size);
shader->set("transparency", part->transparency); shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface); shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface); shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface); shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface); shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface); shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface); shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
CUBE_MESH->bind(); CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount); glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -184,12 +184,12 @@ void renderParts() {
shader->set("texScale", part->size); shader->set("texScale", part->size);
shader->set("transparency", part->transparency); shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface); shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface); shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface); shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface); shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface); shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface); shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
CUBE_MESH->bind(); CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount); glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -233,7 +233,7 @@ void renderSurfaceExtras() {
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
NormalId face = (NormalId)i; NormalId face = (NormalId)i;
SurfaceType type = part->GetSurfaceFromFace(face); SurfaceType type = part->GetSurfaceFromFace(face);
if (type <= SurfaceType::SurfaceUniversal) continue; if (type <= SurfaceType::Universal) continue;
Vector3 surfaceCenter = part->cframe * (normalFromFace(face) * part->size / 2.f); Vector3 surfaceCenter = part->cframe * (normalFromFace(face) * part->size / 2.f);

View file

@ -131,7 +131,7 @@ void PlaceDocument::init() {
// part1->frontSurface = SurfaceWeld; // part1->frontSurface = SurfaceWeld;
// part0->backSurface = SurfaceHinge; // part0->backSurface = SurfaceHinge;
part0->backSurface = SurfaceMotor; part0->backSurface = SurfaceType::Motor;
// part1->frontSurface = SurfaceHinge; // part1->frontSurface = SurfaceHinge;
std::shared_ptr<Script> script = Script::New(); std::shared_ptr<Script> script = Script::New();