310 likes | 457 Views
Programming Basics. Tae Soo, Yun Division of Internet Engineering Dongseo University. Introduction to NetImmerse. NetImmerse is an object-oriented C++ 3D game engine for the following platforms: Windows(9x, Me,NT,2000,XP) Playstation2, Xbox, GameCube
E N D
Programming Basics Tae Soo, Yun Division of Internet Engineering Dongseo University
Introduction to NetImmerse • NetImmerse is an object-oriented C++ 3D game engine for the following platforms: • Windows(9x, Me,NT,2000,XP) • Playstation2, Xbox, GameCube • NetImmerse consists of 3 main component: • A set of plugins • A set of tools • C++ run-time library
Introduction to NetImmerse • Functions • Hierarchical scene graph representaion • Integration with major 3D modeling tools • Efficient visible object culling • Support for advanced 3D h/w acceleration on all platforms • High-end texturing and rendering effects • Integration with the Havok physics engine • Dynamic collision detection • Support for 3D Audio • LOD representation • Flexible rendering, sorting, and culling methods
Introduction to Object Systems • NiRefObject is a base class • The [derived] classes support smart pointers, RTTI, cloning, streaming and viewer string, names, extra data, and time controllers • The hierarchy of NiObject-derived classes
Inheritance Structure • Most of classes are inherited form NiObject • NiObject supports referencing counting • Allows NetImmerse to use a hierarchical scene graph,which allows app. to create nested coordinate sys.(for articulated objects,etc) and specify rendering properties(e.g. texture mapping, fogging) • The HSG allows NetImmerse to do automatic run-time culling of geometry
Object System: RTTI • RTTI: runtime type information • determine the exact type(e.g. given type or any subclass) of object that is referenced by a given pointer. • The RTTI Information for each class is stored as static data which includes a pointer to the RTTI data for the class’s based class or the name of the class.
Object System: RTTI(2) • Basic Operations • Testing if an object’s class is exactly a specified class is accomplished by a macro “NiIsExactKindOf” • Testing if an object’s class is derived from a specified class, “NiIsKindOf” • Dynamic typecasting
Object System: RTTI(3) NiNode* pkNode = new NiNode; bool bResult; bResult = NiIsExactKindOf(NiNode, pkNode); // bResult is true bResult = NiIsExactKindOf(NiAVObject, pkNode); // bResult is false bResult = NiIsKindOf(NiAVObject, pkNode); // bResult is true bResult = NiIsKindOf(NiSwitchNode, pkNode); // bResult is false NiObject* pkObject = pkNode; NiAVObject* pkDynAVObj = NiDynamicCast(NiAVObject, pkObject); // pkDynAVObj == pkNode NiNode* pkDynNode = NiDynamicCast(NiNode, pkObject); // pkDynNode == pkNode NiSwitchNode* pkDynSw = NiDynamicCast(NiSwitchNode, pkObject); // pkDynSw == 0
Object System: Smart pointers • maintains a count of the # of reference to object. • They automatically increment and decrement the reference counts of objects • All NetImmerse Objects derived from NiRefObject are reference-counted. • Declaration of sp(smart pointer) : ??Ptr
Object System: Smart pointers(2)A simple example: NiNodePtr spParent = <some node>; NiNodePtr spChild = new NiNode; // spChild points to new object. Reference count is 1. spParent->AttachChild(spChild); // Reference count of object pointed to by spChild is now // 2, since NiNode objects use smart pointers to refer their children. spParent->DetachChild(spChild); // Reference count of object pointed to by spChild decreases to 1. spChild = 0; // Reference count of object decreases to 0. Object is deleted.
Object System : Streaming • Streaming provides a way of saving and loading scene graphs and other Ni Object to and from disk or memory buffers. • File streams support standard load and save op. • Memory streams support loading of files and transfer of content across networks • It can provides a streaming with a Stream group
Object System : Streaming(2) • Stream Saving void InsertObject(NiObject* pkObject); void RemoveObject(NiObject* pkObject); void RemoveAllObjects(); NiObject* GetObjectAt(unsigned int i) const; unsigned int GetObjectCount() const; NiCamera* pkCamera = <some camera>; NiLight* pkLight = <some light>; NiNode* pkScene = <some scene graph>; NiStream kStream; kStream.InsertObject(pkCamera); kStream.InsertObject(pkLight); kStream.InsertObject(pkScene); kStream.Save(“myfile.nif”);
Object System : Streaming(3) • Stream Loading NiTArray<NiObjectPtr> kObjects; NiStream kStream; kStream.Load(“myfile.nif”); for (unsigned int i = 0; i < kStream.GetObjectCount(); i++) { NiObject* pkObject = kStream.GetObjectAt(i); kObjects.Add(pkObject); }
Object System: Cloning • Is a method by which copies of objects are made. • An app. Calls the funtions • NiObject* NiObject::Clone();
Object System : Extra data • NiObjectNet class support for attaching extra data. • It supports RTTI and streaming • NiObjectNET support for NiTimeControllers
Object System : Extra data(2) The relevant member functions ofNiObjectNETare void PrependExtraData(NiExtraData* pkExtra); void SetExtraData(NiExtraData* pkExtra); NiExtraData* GetExtraData() const; void RemoveExtraData(NiExtraData* pkExtra); void RemoveAllExtraData();
Static NetImmerse Objects& Object Lifetime • App. should avoid creating statically NetImmerse objects. • Smart pointers declared statically are fine, (but it must be set to null prior to the end of the app)
Naming Conventions • All NI class type names are prefaced with the Ni prefix and use capitalization to separate words (e.g. NiSwitchNode ) • Avoids using global-scope constants and enumerated types, prefer to use class-local enumerated types • (e.g. NiAlphaProperty::ALPAH_SRCALPHA)
Naming conventions : Variable prefixes • Type Prefix Example Float f fValue (unsigned) int (u)i (u)iValue (unsigned) short (u)s (u)sValue (unsigned) long (u)l (u)lValue Enum e eFlag Class k kWorld Pointer(+type) p piValue Pointer to pointer pp ppkWorld Pointer to void pv pvData Smart pointer sp spValue Function pointer pfn pfnCallback Double d dValue Array( +type) a aiValue Member data m_ m_fValue Static member data ms_ ms_kSingleton
Template Classes • List : NiTLists. • SimpleList : NiTSimpleLists • Array : NiTArrays • Map : NiTMaps, NiTStringMaps • Queue : NiTQueue • Set : NiTSet
Programming with VC++ • NetImmerse Lib are shipped with VC++6.0 dws files • All of the NetImmerse Lib are compiled with VC++ and Visual Studio SP #5( it is available athttp://msdn.microsoft.com/visualc/downloads/updates.asp)
Application Build Settings (1) • Link Object Library Modules • NiMain.lib NiSystem.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib • The library search path for the project file should include the path to the NetImmerse libraries, including thesdk\Win32\ReleaseLib, sdk\Win32\ReleaseDLL, etc.
Application Build Settings (2) • C/C++ Preprocessor Definitions • NetImmerse applications must also define STRICT ( + WIN32, NDEBUG or _DEBUG, _WINDOWS ) • C/C++ Code Generation and Choosing the Right Set of NetImmerse Libraries • Processor: Pentium • Use Runtime Library: Multithreaded DLL • Calling Convention: __cdecl • Struct Member Alignment: 8 Bytes
Application Build Settings (3) • Renderer • the Link Object Library Modules setting of applications using the DX8 renderer should include: NiDX8Renderer.lib • Applications using the DX7 renderer should include: NiDX7Renderer.lib ddraw.lib dxguid.lib • Applications using the OpenGL renderer should include: NiOglRenderer.lib opengl32.lib glu32.lib • Miles Sound Module • NiAudio.lib mss32.lib
Application Build Settings (4) • Havok Physics Module • hkactions.lib hkdefaultvehicle.lib hkdisplayclasses.lib hkdisplayobject.lib hkdisplay.lib hkbase.lib hkdynamics.lib hkexport.lib hkgeometry.lib hkmath.lib hktoolkit.lib hkvehicle.lib hkcollide.lib NiHavokImportKit.lib NiHavok.lib • Please note that currently, only the Havok physics demo (Samples\NiHavokImporter) and the MaxImmerse plug-in (PlugIns\MaxImmerse) actually link these libraries.