-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Chapter 5: Object Management
In the NoahGameFrame world, everything is an NFCObject/NFIObject, this object can include any props and can be used as an object such as NPC, monster, item or player, therefore you don't need to design your business class/struct such as the dog, cat and so on, sometimes we can compare the NFIObject to the model of MVC.
Additionally, all objects must exist in a group unit. Each group unit is like an instance dungeon/room in your game, and you can create a new room by creating a new group.
A scene unit is like a high building with many stories, and a group unit is like one floor of this building. More remarkable, all groups in one scene have the same data besides objects within (NPC, monster, player).
When the application starts, the scene management will create one group (group 0, non-removable) as the base group for each scene, and all players who want to switch to this scene must switch to the base group first, then switch to the desired group (maybe allocate a new group every time). Correspondingly, when a player wants to leave from one scene, the player must switch to the base group of their current scene, then switch the new scene.
Here's a diagram of the relationship between groups & scenes:
NF's base object class NFIObject inherits class NFIKernelModule which provides many interfaces for operating on the object, such as:
virtual bool ExistObject(const NFGUID& ident);
virtual bool ExistObject(const NFGUID& ident, const int nSceneID, const int nGroupID);
virtual NF_SHARE_PTR<NFIObject> GetObject(const NFGUID& ident);
virtual NF_SHARE_PTR<NFIObject> CreateObject(const NFGUID& self, const int nSceneID, const int nGroupID, const std::string& strClassName, const std::string& strConfigIndex, const NFDataList& arg);
virtual bool DestroyAll();
virtual bool DestroySelf(const NFGUID& self);
virtual bool DestroyObject(const NFGUID& self);
virtual bool FindProperty(const NFGUID& self, const std::string& strPropertyName);
virtual bool SetPropertyInt(const NFGUID& self, const std::string& strPropertyName, const NFINT64 nValue);
virtual bool SetPropertyFloat(const NFGUID& self, const std::string& strPropertyName, const double dValue);
virtual bool SetPropertyString(const NFGUID& self, const std::string& strPropertyName, const std::string& strValue);
virtual bool SetPropertyObject(const NFGUID& self, const std::string& strPropertyName, const NFGUID& objectValue);
virtual bool SetPropertyVector2(const NFGUID& self, const std::string& strPropertyName, const NFVector2& value);
virtual bool SetPropertyVector3(const NFGUID& self, const std::string& strPropertyName, const NFVector3& value);
virtual NFINT64 GetPropertyInt(const NFGUID& self, const std::string& strPropertyName);
virtual int GetPropertyInt32(const NFGUID& self, const std::string& strPropertyName); //equal to (int)GetPropertyInt(...), to remove C4244 warning
virtual double GetPropertyFloat(const NFGUID& self, const std::string& strPropertyName);
virtual const std::string& GetPropertyString(const NFGUID& self, const std::string& strPropertyName);
virtual const NFGUID& GetPropertyObject(const NFGUID& self, const std::string& strPropertyName);
virtual const NFVector2& GetPropertyVector2(const NFGUID& self, const std::string& strPropertyName);
virtual const NFVector3& GetPropertyVector3(const NFGUID& self, const std::string& strPropertyName);
Below is a diagram of what happens when you want to create an instance of your logic class: