feat(autogen): analyze instance flags
This commit is contained in:
parent
febde86430
commit
10c78cd647
5 changed files with 56 additions and 7 deletions
|
@ -80,7 +80,8 @@ bool findInstanceAnnotation(CXCursor cur) {
|
|||
if (kind != CXCursor_AnnotateAttr) return CXChildVisit_Continue;
|
||||
|
||||
std::string annString = x_clang_toString(clang_getCursorDisplayName(cur));
|
||||
if (annString == "OB::INSTANCE") found = true;
|
||||
// if (annString == "OB::INSTANCE") found = true;
|
||||
if (annString == "OB::def_inst") found = true;
|
||||
|
||||
return CXChildVisit_Break;
|
||||
});
|
||||
|
@ -155,6 +156,19 @@ void processClass(CXCursor cur, AnalysisState* state, std::string className) {
|
|||
anly.name = className;
|
||||
anly.baseClass = baseClass;
|
||||
|
||||
// Add misc flags and options
|
||||
auto instanceDef = findAnnotation(cur, "OB::def_inst");
|
||||
auto result = parseAnnotationString(instanceDef.value());
|
||||
|
||||
if (result.count("service"))
|
||||
anly.flags = anly.flags | ClassFlag_Service | ClassFlag_NotCreatable;
|
||||
if (result.count("not_creatable"))
|
||||
anly.flags = anly.flags | ClassFlag_NotCreatable;
|
||||
if (result.count("hidden"))
|
||||
anly.flags = anly.flags | ClassFlag_Hidden;
|
||||
|
||||
anly.explorerIcon = result["explorer_icon"];
|
||||
|
||||
// Find annotated fields
|
||||
x_clang_visitChildren(cur, [&](CXCursor cur, CXCursor parent) {
|
||||
CXCursorKind kind = clang_getCursorKind(cur);
|
||||
|
|
|
@ -10,10 +10,23 @@ struct PropertyAnalysis {
|
|||
std::string backingFieldType;
|
||||
};
|
||||
|
||||
enum ClassFlags {
|
||||
ClassFlag_NotCreatable = 1<<0,
|
||||
ClassFlag_Service = 1<<1,
|
||||
ClassFlag_Hidden = 1<<2,
|
||||
};
|
||||
|
||||
// https://stackoverflow.com/a/1448478/16255372
|
||||
inline ClassFlags operator|(ClassFlags a, ClassFlags b) {
|
||||
return static_cast<ClassFlags>(static_cast<int>(a) | static_cast<int>(b));
|
||||
}
|
||||
|
||||
struct ClassAnalysis {
|
||||
std::string name;
|
||||
std::string baseClass;
|
||||
std::vector<PropertyAnalysis> properties;
|
||||
ClassFlags flags = (ClassFlags)0;
|
||||
std::string explorerIcon;
|
||||
};
|
||||
|
||||
struct AnalysisState {
|
||||
|
|
|
@ -44,6 +44,16 @@ int main(int argc, char** argv) {
|
|||
printf("Class: %s\n", clazz.name.c_str());
|
||||
if (clazz.baseClass != "")
|
||||
printf("==> Base class: %s\n", clazz.baseClass.c_str());
|
||||
if (clazz.explorerIcon != "")
|
||||
printf("==> Explorer icon: %s\n", clazz.explorerIcon.c_str());
|
||||
printf("==> Flags (%x): ", clazz.flags);
|
||||
if (clazz.flags & ClassFlag_Service)
|
||||
printf("INSTANCE_SERVICE ");
|
||||
if (clazz.flags & ClassFlag_NotCreatable)
|
||||
printf("INSTANCE_NOT_CREATABLE ");
|
||||
if (clazz.flags & ClassFlag_Hidden)
|
||||
printf("INSTANCE_HIDDEN");
|
||||
printf("\n");
|
||||
|
||||
if (!clazz.properties.empty())
|
||||
printf("==> Properties:\n");
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
// Markers for the autogen engine to generate getters, setters, lua, etc.
|
||||
|
||||
#define INSTANCE [[clang::annotate("OB::INSTANCE")]]
|
||||
#define def_inst(...) clang::annotate("OB::def_inst", #__VA_ARGS__)
|
||||
|
||||
#define def_prop(...) clang::annotate("OB::def_prop", #__VA_ARGS__)
|
||||
|
||||
#define cframe_position_prop(...) clang::annotate("OB::cframe_position_prop", #__VA_ARGS__)
|
||||
#define cframe_rotation_prop(...) clang::annotate("OB::cframe_rotation_prop", #__VA_ARGS__)
|
|
@ -28,7 +28,7 @@ struct PartConstructParams {
|
|||
|
||||
class Snap;
|
||||
|
||||
class INSTANCE Part : public Instance {
|
||||
class [[ def_inst(explorer_icon="part") ]] Part : public Instance {
|
||||
protected:
|
||||
// Joints where this part is Part0
|
||||
std::vector<std::weak_ptr<JointInstance>> primaryJoints;
|
||||
|
@ -51,24 +51,33 @@ public:
|
|||
const static InstanceType TYPE;
|
||||
|
||||
Vector3 velocity;
|
||||
[[ def_prop(name="cframe"), cframe_position_prop(name="Position"), cframe_rotation_prop(name="Rotation") ]]
|
||||
CFrame cframe;
|
||||
[[ def_prop(name="Size") ]]
|
||||
[[ def_prop(name="Size", category=PART) ]]
|
||||
glm::vec3 size;
|
||||
[[ def_prop(name="Color") ]]
|
||||
[[ def_prop(name="Color", category=APPEARANCE) ]]
|
||||
Color3 color;
|
||||
[[ def_prop(name="Transparency") ]]
|
||||
[[ def_prop(name="Transparency", category=APPEARANCE) ]]
|
||||
float transparency = 0.f;
|
||||
bool selected = false;
|
||||
|
||||
[[ def_prop(name="Anchored", category=BEHAVIOR) ]]
|
||||
bool anchored = false;
|
||||
[[ def_prop(name="Locked", category=BEHAVIOR) ]]
|
||||
bool locked = false;
|
||||
rp::RigidBody* rigidBody = nullptr;
|
||||
|
||||
[[ def_prop(name="TopSurface", category=SURFACE) ]]
|
||||
SurfaceType topSurface = SurfaceType::SurfaceStuds;
|
||||
[[ def_prop(name="BottomSurface", category=SURFACE) ]]
|
||||
SurfaceType bottomSurface = SurfaceType::SurfaceInlets;
|
||||
[[ def_prop(name="LeftSurface", category=SURFACE) ]]
|
||||
SurfaceType leftSurface = SurfaceType::SurfaceSmooth;
|
||||
[[ def_prop(name="RightSurface", category=SURFACE) ]]
|
||||
SurfaceType rightSurface = SurfaceType::SurfaceSmooth;
|
||||
[[ def_prop(name="FrontSurface", category=SURFACE) ]]
|
||||
SurfaceType frontSurface = SurfaceType::SurfaceSmooth;
|
||||
[[ def_prop(name="BackSurface", category=SURFACE) ]]
|
||||
SurfaceType backSurface = SurfaceType::SurfaceSmooth;
|
||||
|
||||
Part();
|
||||
|
|
Loading…
Add table
Reference in a new issue