[[How to make a new physical engine]]
All the descriptions of the class,
need parentheses for
namespace Spr{;
}
.(#include doesn't care)。」~
The macro to register the name is necessary in the place of the declaration of
the class.
SGOBJECTDEF(PHTestEngine);
This can specify like the above.
This is needed #include because this is declared by <FileIO/FIDocScene.h>.
+Specification of macro that registers the derivation relation in the .cpp file of the class.
SGOBJECTIMP(PHTestEngine, SGBehaviorEngine);
+Creating of member function in PHTestEngine class
At least, necessary one is Step(SGScene *s).~
+Creating of loader and saver.
Those below minimum necessary declaration.(to write it in .cpp is convenient)
class PHTestEngineLoader:public FIObjectLoader<PHTestEngine>{
public:
PHTestEngineLoader(){}
virtual bool LoadData(FILoadScene* ctx, PHTestEngine* test){}
};
class PHTestEngineSaver:public FIObjectSaver<PHTestEngine>{
virtual UTString GetType() const{ return "PHTestEngine"; }
virtual void SaveData(FISaveScene* ctx, FIDocNodeBase* doc, PHTestEngine* test){}
};
+Macro which register the loader and saver specify after the declaration~
DEF_REGISTER_BOTH(PHTestEngine);
In order to using the argument here, the name must adjust to declaration.
+The data read with .X file is defined.(The data such as Solid is described after)
~The definition is different the method in the next two cases.
-When the data of X file pairs with the member variable maintained in the classュ。
-When the member variable maintained in the class and data of X file is another
wayュ「~
In the case ュ。,define it before the variable of the member(For example, before the declaration of the class). In the case ュ「, be the declaration of the loader.
DEF_RECORD(XTestEngine,{
//In the code area; specify codes generated by ~\Microsoft Visual Studio\Common\Tools\GUIDGEN.EXE
GUID Guid(){ return WBGuid("CODE"); }
Data declaration;
});
Because data declaration should be a data type matched to X file,
typedef Vec3f Vector;
it is necessary to match the type like that.
+The definition of data is registered by the loader.
The registers is performed the constructor of the loader.
UTRef<FITypeDescDb> db = new FITypeDescDb;
db->SetPrefix("X");
db->REG_FIELD(Vector); //Matched Declare type
db->REG_RECORD_PROTO(XTestEngine); //adjust it to the first argument of DEF_RECORD
+Data is substituted for the member variable.The content of the member variable is substituted for data.~
In the case ュ。,
XTestEngine tes;
the member variable is described like above.~
In the case ュ「,the member variable is described as I am necessary.~
It substitutes it by member function LoadData() of the loader.
In the case ュ。,
virtual bool LoadData(FILoadScene* ctx, PHMTestEngine* test){
ctx->docs.Top()->GetWholeData(test->tes);
return true;
}
When you substitute it for data inversely,
virtual void SaveData(FISaveScene* ctx, FIDocNodeBase* doc, PHTestEngine* test){
doc->SetWholeData(test->tes);
}
In the case ュ「,
virtual bool LoadData(FILoadScene* ctx, PHMTestEngine* test){
XTestEngine tes;
ctx->docs.Top()->GetWholeData(test->tes);
substitute it for the member variable in your original type
return true;
}
When you substitute it for data inversely,
virtual void SaveData(FISaveScene* ctx, FIDocNodeBase* doc, PHTestEngine* test){
XTestEngine tes;
substitute it for the above structure in your original type
doc->SetWholeData(test->tes);
}
+Data such as Solid is substituted for the member variable.~
Use AddChildObject(SGObject* o, SGScene* s).~
This is declared as a member function of the PHtestEngine class.Use(method) is the following.
if (DCAST([Class name of data], o)){
[Member Var. of this Class].push_back((PHSolid*)o);
return true;
}
return false;
+At the end, the class that added it to PHRegisterLoader.cpp is registered(the registration method is just like other classes).