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) {
out << "\n return Variant(" << prop.fieldName << ".ToEulerAnglesXYZ());";
} 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 {
out << "\n return Variant(" << castToVariant(prop.fieldName, prop.backingFieldType) << ");";
}

View file

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

View file

@ -120,7 +120,7 @@ SurfaceType Part::surfaceFromFace(NormalId face) {
case Front: return frontSurface;
case Back: return backSurface;
}
return SurfaceSmooth; // Unreachable
return SurfaceType::Smooth; // Unreachable
}
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) {
if (a == SurfaceWeld || b == SurfaceWeld || a == SurfaceGlue || b == SurfaceGlue) return Weld::New();
if ((a == SurfaceStuds && (b == SurfaceInlets || b == SurfaceUniversal))
|| (a == SurfaceInlets && (b == SurfaceStuds || b == SurfaceUniversal))
|| (a == SurfaceUniversal && (b == SurfaceStuds || b == SurfaceInlets || b == SurfaceUniversal)))
if (a == SurfaceType::Weld || b == SurfaceType::Weld || a == SurfaceType::Glue || b == SurfaceType::Glue) return Weld::New();
if ((a == SurfaceType::Studs && (b == SurfaceType::Inlet || b == SurfaceType::Universal))
|| (a == SurfaceType::Inlet && (b == SurfaceType::Studs || b == SurfaceType::Universal))
|| (a == SurfaceType::Universal && (b == SurfaceType::Studs || b == SurfaceType::Inlet || b == SurfaceType::Universal)))
return Snap::New();
if (a == SurfaceHinge)
if (a == SurfaceType::Hinge)
return Rotate::New();
if (a == SurfaceMotor)
if (a == SurfaceType::Motor)
return RotateV::New();
return std::nullopt;
}
@ -251,7 +251,7 @@ void Part::MakeJoints() {
SurfaceType otherSurface = surfaceFromFace(faceFromNormal(otherFace));
// 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
// 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_CATEGORY(SURFACE)
DEF_PROP SurfaceType topSurface = SurfaceType::SurfaceStuds;
DEF_PROP SurfaceType bottomSurface = SurfaceType::SurfaceInlets;
DEF_PROP SurfaceType leftSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType rightSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType frontSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType backSurface = SurfaceType::SurfaceSmooth;
DEF_PROP SurfaceType topSurface = SurfaceType::Studs;
DEF_PROP SurfaceType bottomSurface = SurfaceType::Inlet;
DEF_PROP SurfaceType leftSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType rightSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType frontSurface = SurfaceType::Smooth;
DEF_PROP SurfaceType backSurface = SurfaceType::Smooth;
DEF_PROP_CATEGORY(SURFACE_INPUT)
DEF_PROP float topParamA = -0.5;

View file

@ -154,12 +154,12 @@ void renderParts() {
shader->set("texScale", part->size);
shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -184,12 +184,12 @@ void renderParts() {
shader->set("texScale", part->size);
shader->set("transparency", part->transparency);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", part->frontSurface);
shader->set("surfaces[" + std::to_string(NormalId::Right) + "]", (int)part->rightSurface);
shader->set("surfaces[" + std::to_string(NormalId::Top) + "]", (int)part->topSurface);
shader->set("surfaces[" + std::to_string(NormalId::Back) + "]", (int)part->backSurface);
shader->set("surfaces[" + std::to_string(NormalId::Left) + "]", (int)part->leftSurface);
shader->set("surfaces[" + std::to_string(NormalId::Bottom) + "]", (int)part->bottomSurface);
shader->set("surfaces[" + std::to_string(NormalId::Front) + "]", (int)part->frontSurface);
CUBE_MESH->bind();
glDrawArrays(GL_TRIANGLES, 0, CUBE_MESH->vertexCount);
@ -233,7 +233,7 @@ void renderSurfaceExtras() {
for (int i = 0; i < 6; i++) {
NormalId face = (NormalId)i;
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);

View file

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