现在的位置: 首页 > 综合 > 正文

gamebryo笔记

2012年08月27日 ⁄ 综合 ⁄ 共 22757字 ⁄ 字号 评论关闭
AcotrManager 取当前动画播放时间的长度. 可以有2中办法.
NiAnimationConstants::GetEndTextKey() 返回字符串 "end"
 float fEndTime = m_spActorManager->GetNextEventTime(
            NiActorManager::TEXT_KEY_EVENT,
            m_spActorManager->GetTargetAnimation(),
            NiAnimationConstants::GetEndTextKey());
 
//这种写法更明确一点. END_OF_SEQUENCE 标识。The end of the sequence was reached. This is equivalent to a TEXT_KEY_EVENT for the string "end".
  NiFixedString kTextKey;
  float fEndTime = m_spActorManager->GetNextEventTime(
           NiActorManager::END_OF_SEQUENCE,
           m_spActorManager->GetTargetAnimation(),kTextKey);

NiApplication 用来隐藏和显示图标。
     void HidePointer();
    void ShowPointer();

如果抽象工厂产生的类对象不能互相替换,则不能使用这个工厂。 

服务器是否需要NiApplication或者其中的某些工程如实体?? 

NiApplication 工程包含winmain 可以设计成主程序。对于window窗口则使用NiWindows类。这样窗口显示注定不能使用wxWidget. 引入太多无用的东西,命名冲突,编译速度等等。如果修改wxWidget又要引入wxWidget工程进入到整个程序工程中。更容易混乱,而且修改wxWidget之后,和服务器的wxWidget又不兼容,出现2套不同的dll。 

gb 2.5 对于一个地形最多4个材质 

默认Input 输入 NiSample 工程设置 m_bUseNavSystem 属性为 true 即可

后台加载

NiGeometryData::STATIC

    The data never changes.

NiGeometryData::MUTABLE

    The data changes infrequently.

NiGeometryData::VOLATILE

    The data changes every frame.

 

NiTriBasedGeom

Abstract base class for all geometry subclasses that base their geometry upon triangles. 

m_bMultiThread  NiApplication 后台成员设置设备为多线程设备,对于2.3 版本及以下是必须的。但指定多线程设备不利于性能。
似乎2.5 有所改善,使用后台加载不再需要多线程设备。有待确定

BackgroundLoad Demo Code Overview

The following NiStream functions are used to perform the background load in this sample:
如下的NiStream 函数展示了如何进行后台加载:
void NiStream::BackgroundLoadBegin(const char* pcFileName);

BackgroundLoadBegin is used to launch the background load.
BackgroundLoadBegin 用来启动后台加载。

NiStream::ThreadStatus NiStream::BackgroundLoadPoll(LoadState* pkState);

BackgroundLoadPoll is used to poll the status of the background load. It returns NiStream::IDLE when the background load has finished. It returns NiStream::LOADING while the background load is in progress. If a non-NULL pointer is passed as the pkState argument to BackgroundLoadPoll and BackgroundLoadPoll returns NiStream::LOADING, the structure pointed to by pkState is filled in with values that indicate the progress of the background load. These values are used in this sample to calculate the values displayed on the screen that indicate the progress of the background load.
BackgroundLoadPoll 用来查询后台加载的情况. 当后台加载完成的时候返回NiStream::IDLE。当后台加载还在进行的时候返回NiStream::LOADING 如果一个非NULL的pkState参数传入BackgroundLoadPoll 并且BackgroundLoadPoll 返回NiStream::LOADING, pkState指向的结构被填充后台加载进度的值。 

bool NiStream::BackgroundLoadGetExitStatus() const;

After BackgroundLoadPoll indicates that the background load has finished, BackgroundLoadGetExitStatus is used to determine whether the background load succeeded. It returns true if the load succeeded and false if it failed.
在BackgroundLoadPoll指示后台加载已经完成。BackgroundLoadExitStatus 用来决定后台加载是否成功,true 代表加载成功,false 表示失败.
加载结束后BackgroundLoadOnExit 函数被调用可以在里面确定是否加载成功.     assert(BackgroundLoadGetExitStatus());

bool NiStream::BackgroundLoadFinish();

BackgroundLoadFinish blocks until a background load runs to completion. In this sample, we call it before allowing the application to exit. If the user quits the application before the background load finishes, calling BackgroundLoadFinish is necessary. It is an error to destroy an NiStream object while a background load is in progress. If the background load has already finished before BackgroundLoadFinish is called, BackgroundLoadFinish will return immediately.
BackgroundLoadFinish 用来阻塞直到后台加载完成。我们可以在应用程序退出前调用这个函数。如果用户在后台加载完成前退出应用程序,调用BackgroundLoadFinish 是必须的。在后台加载正在进行的时候摧毁 NiStream 对象是错误的行为。当后台加载完成时。BackgroundLoadFinish 将马上返回。

On most platforms, a background load will not receive any cycles unless the foreground thread yields the processor by calling NiSleep, a global function declared in NiSystem.h:
在大部分平台 ,后台加载线程不会执行除非前台线程通过调用NiSleep让出处理器,在NiSystem.h 中有一个全局函数NiSleep

void NiSleep(unsigned int uiMilliseconds);

NiSleep puts the calling thread to sleep for the number of milliseconds specified by its uiMilliseconds argument. If a background load has been launched, it will wake up and run while the foreground thread is asleep.

The BackgroundLoad sample loads its NIF files using an NiStream-derived class called CallbackStream. CallbackStream overloads the virtual NiStream function BackgroundLoadOnExit. BackgroundLoadOnExit is called by the background loading code in NiStream when a background load completes. The default implementation, NiStream::BackgroundLoadOnExit, does nothing. The purpose of the function is to allow applications to override it in classes derived from NiStream and do work that should be done in the background thread to avoid frame rate hits that would happen if the work was done in the application's main thread. CallbackStream::BackgroundLoadOnExit creates property states and effect states for the objects extracted from ROOM.NIF and precaches the geometry objects.

性能测试工具

NiVisualTracker(float fMaxValue, unsigned int uiNumDecimalPlaces, NiRect<float> kWindowRect, const char* pcName, bool bShow = true, unsigned int uiNumGraphs = 5)
fMaxValue 设置测量工具Y轴最大值。uiNumDecimalPlaces 右侧标尺数字包含的小数位数。kWindowRect 测量图矩形位置. pcName测量图名称, bShow 是否显示
uiNumGraphs 曲线图初始的个数。如果 AddGraph 个数超过这个数,会自动增加曲线图个数

unsigned int AddGraph(GraphCallbackObject* pkObject, const char* pcName, const NiColor& kColor, unsigned int uiNumSamplesToKeep, float fMinSampleTime, bool bShow);

This adds a GraphCalbackObject to the list of graphs maintained by the NiVisualTracker.  A GraphCalbackObject is the class that maintains the current state of a tracked statistic. pcName is the name of the object as it is to be displayed below the graph.  kColor is the color for both the lines drawn and the displayed name.  uiNumSamplesToKeep is the number of samples to keep in the history for that statistic.  fMinSampleTime is the minimum time that must elapse between samples. bShow is the initial show/hide status for that particular graph.

向NiVisualTracker维护的图形列表添加一个GraphCallbackObject对象。一个GraphCallbackObject 负责维护tracked当前状态的统计信息。pcName 是在图形列表下面显示的曲线图名称。kColor 是统计曲线和显示名称使用的颜色。uiNumSamplesTokeep 统计保存的历史数据包含的采样个数。fMinSampleTime 在2次采样之间流逝的时间。bShow 初始化某个曲线图的显示/隐藏状态。

NiVisualTrackerOutput
This class is a metrics output module designed for easily adding instrumented metrics to an NiVisualTracker graph.
为简化向NiVisualTracker图添加测量工具

//构造函数
NiVisualTrackerOutput(unsigned int uiFramePeriod)

Constructs a visual tracker with the specified frame period. The frame period is how many frames each metric will be calculated for before being displayed to the tracker. This number must be greater than zero.
创建一个执行周期为uiFramePeriod的visual tracker. 这个周期指每次测量之间的帧数。这个数必须大于0

//添加曲线图函数
void AddGraph(NiVisualTracker* pkTracker, const char* pcMetricName, MetricsFunction eFunction = FUNC_MEAN, const NiColor& kColor = NiColor::WHITE, unsigned int uiNumSamplesToKeep = 100, float fMinSampleTime = 0.1f, bool bShow = true, float fScale = 1.0f, bool bAddFunctionSuffix = true, const char* pcAlternateName = NULL)

This function adds a metric by name to an existing visual tracker. eFunction is an enumeration (defined in NiCalculatingOutput) that defines which function of the metric should be graphed (mean, sum, min, max, or count.) kColor, uiNumSamplesToKeep, fMinSampleTime, bShow, and fScale are all passed directly to the NiVisualTracker::AddGraph function.

通过测量名称(如NiApplicationMetrics::ms_acNames[NiApplicationMetrics::FRAMERATE] 存储的帧速率的名称)为一个存在的visual tracker 添加测量信息, eFunction 是在NiCalculatingOutput中的一个枚举,定义采用那个函数处理数据(mean,sum,min,max.count 平均值、总和、最大值、最小值、计数,指一个uiFramePeriod 周期内数据)。

NIMETRICS_ADDVALUE(ms_pcMetricName, 100 * NiUnitRandom());  添加某个测量名称对应的测量数据

//例子
NiVisualTrackerOutput* pkVTOutput = NiNew NiVisualTrackerOutput(uiVTFramePeriod);
NiMetricsLayer::AddOutputModule(pkVTOutput);
pkVTOutput->AddGraph(m_kTrackers.GetAt(0), NiParticleMetrics::ms_acNames[NiParticleMetrics::UPDATED_PARTICLES],
        NiVisualTrackerOutput::FUNC_SUM_PER_FRAME, NiColor(0.0f, 1.0f, 0.0f),100, 0.1f, true, 1.0f, false, "Particles");

使用xml记录数据
const char* pcFilename = "ProfileSampleXMLOutput.xml";

// Add XML output module to metrics layer
NiXMLMetricsOutput* pkXML = NiNew NiXMLMetricsOutput(uiFramePeriod, pcFilename);
NiMetricsLayer::AddOutputModule(pkXML);

NiXMLMetricsOutput
This class calculates instrumented metrics over some user-specified number of frames. It will calculate the mean, sum, min, max, and count for each metric and output them in an XML file. (Count is the number of values that were used to calculate the other four values.)

Labels: NiVisualTracker, NiVisualTrackerOutput

Programming for a Scene Graph

Scene Graph Basics
场景图形基础
A hierarchical scene graph is a rooted, directed, acyclic graph (DAG), consisting of objects that represent the drawable and audible parts of an application's 3D world.  Such a hierarchical scene graph forms the basis of a Gamebryo scene database.
一个分级场景图是包含根、方向、无循环的图形,包含应用程序3d世界中可听或可视的部分。如此的分类场景图形成gamebryo场景数据基础。

All objects in a scene graph are subclasses of NiAVObject, each of which specialize and extend the abstract base class.
场景图中所有对象都是抽象类NiAVObject经过特化或者扩展的子类

A scene graph consists of a root node that has zero or more "children".  Applications may have any number of scene graphs.  The leaves of the tree represent geometric objects, while the internal nodes serve to group and manage parts of the scene graph.  The NiAVObject base class itself does not support the notion of children.  Instead, the NiNode class and its subclasses add this capability.
一个场景图可以包含0个或者更多孩子,应用程序可以有人一个场景图。树叶代表几何图形对象,而其他内在的节点负责场景图的组织和维护。NiAVObject 基类自己并不支持子树的概念,代替的是使用NiNode类和它的子类
Note that the scene graph's geometric parent-child hierarchy should not be confused with the class hierarchy structure that Gamebryo uses.  These two hierarchies are completely independent.  The children of a NiNode in a scene graph may not be a child class (subclass) of NiNode.
注意不要弄混场景几何体父子层次和gamebryo类派生层次。这是2个完全独立的概念。场景图中NiNode的孩子不一定就是NiNode的子类

 

Transformations and Coordinate Systems
变换和坐标系

Conventions
Gamebryo uses a right-handed coordinate system.
No axis is required to be up, although NiCamera defaults to Y as up.
NiMatrix3 rotations are clockwise about an axis, when looking down the axis toward the origin. Also translation vectors are column vectors.
NiQuaternion rotations are counter-clockwise about an axis, when looking down the axis toward the origin.

协定

Gamebryo 采用右手坐标系系统.
没有要求那个轴一定向上,尽管NiCamera 默认Y轴向上.
NiMatrix3 旋转为顺时针为正方向,当由正轴看向原点时。变换矩阵为列向量
NiQuaternion 当由正轴看向原点时,绕轴旋转逆时针为正。
Each NiAVObject has its own set of modeling space to world space transforms, and all direct children of a NiAVObject are defined in their parent's coordinate system.  This organization forms a hierarchy of coordinate systems, useful for articulated bodies and a wealth of other types of object representations.
相对于世界空间变换每个NiAVObject 都有自己的模型空间,所有NiAVObject的直接孩子都定义在其父坐标系中。这样组织形成了坐标系继承关系。对于关节和许多对象表示都很有用。(骨骼动画组织方式就是这样。父坐标改变才能影响子坐标)
More specifically, the transformation from the model space of a given NiAVObject O with parent P to world space is given by:

OM®W = PM®W [ OT OR OS ]  //由模型空间变换到世界坐标系的矩阵表示

where:

PM®W

is the parent object's model to world space transform

OT

is O's translation matrix (which is a pure translation matrix)

OR 

is O's rotation matrix (which is a pure rotation matrix - i.e. orthonormal)

OS

is O's scaling matrix (which is a pure uniform scaling matrix)

                    

Note that each of the three transformation components is not stored as a separate matrix, but rather is stored using as little information as possible.  Specifically, a 3 by 3 matrix for rotation, a vector for translation, and a scalar for scale are used.
注意这三种变换并没有存放成3个分离的矩阵,而是本着占用空间尽可能少的原则。一个3×3矩阵代表旋转,一个矢量代表平移,一个标量代表缩放
This set of transforms defines three distinct coordinate systems for each object:  a Model coordinate system, which is defined by the set of all transforms from the root of the scene graph to the object; a Local coordinate system, which is equivalent to the object's parent's Model coordinate system (i.e. it is the object's Model coordinate system without the object's own transforms); and the World coordinate system, which is the same for all objects in a given scene graph.
这组变换包含三个截然不同的坐标系:模型坐标行。
So, points transform in the following way:
所以点变换如下

vL = [ OT OR OS ] vM

vW = PM®W vL

vM is the point in the given object's Model coordinate system. 给定对象模型坐标系中的点
vL is the point in the given object's Local coordinate system. 给定对象局部坐标系中的点
vW is the point in the world coordinate system, 世界坐标系中的点

Scene Graph Hierarchy and Hierarchical Coordinate Systems

In order to render an object in world space, it is necessary to transform into additional coordinate systems. For more information on this, including the camera's coordinate system, please see Viewing Geometry.

 

Class Descriptions

NiCamera

NiCamera objects represent virtual cameras for imaging the geometry represented by a scene graph. It is important to note that NiCamera is a descendant of NiAVObject. As a result, a camera may have a parent object that affects the camera's position and orientation. This approach enables cameras to be attached as children of objects in the scene, in order to follow them automatically, as they move. The camera object may operate on a portion of the scene graph that is an ancestor of itself.

For example, a flight simulator scene may contain terrain and several fighter planes. The game may choose to attach a "chase camera" as a child of one of those airplanes, enabling the camera to follow the airplane automatically. This same camera may have as its focus the entire scene graph, enabling the camera to render the terrain and the fighter plane to which the camera is attached.

NiCamera 代表一个虚拟的摄像机。注意:NiCamera 是一个NiAVObject 子类,这很重要。所以一个摄像机可能有父节点影响摄像机的位置和方向。这能够使摄像机可以attach到一个场景中的对象上成为子节点,这样摄像机可以跟随他们自动移动。
例如:例如一个飞行模拟场景包含地形还有战斗机。游戏可以选择这些战斗机中一个attach一个chase camera 到它上面。这使摄像机自动跟随战斗机。

NiDynamicEffect

The subclasses of the abstract class NiDynamicEffect represent time- and geometry-dependent visual effects, such as per-vertex lighting, texture-based fogging, shadows, projected images, etc. These effects fall into two major categories:  per-vertex lights and texture-based effects.

NiDynamicEffect is a subclass of NiAVObject, so objects of this type have a concept of a model space coordinate system. The positions and directions of subclassed effects are defined in the object's model coordinate system, so effects may be attached as children of other scene graph objects. This approach enables the effects to be attached to characters or objects in the scene, such as headlights being attached to a car.

NiDynamicEffectList contains a list of affected objects – objects whose appearances are modified by the effect. This list of affected objects enables effects to have fixed "scope". Applications can increase performance greatly by adding only objects that need to be modified by an effect to that effect's scope list. All other objects will avoid any computations required by the effect.

抽象类NiDynamicEffect 子类描述随时间和几何相关的效果,如 per-vertex lighting,texture-based fogging, shadows, projected images 等等,这些效果分为2个主要的范畴:per-vertex lights 和 texture-base effects

NiDynamicEffect 是NiAVObject 的子类,所以这个类型的对象也有模型空间坐标系的概念。子类effects的位置和方向定义在对象的模型坐标系中,所以effects可以attach到其他的场景图对象上作为子节点。这样effect可以attach到角色上或者场景中的其他对象上。

NiLight

The subclasses of the abstract NiLight are used to create dynamic, per vertex lighting effects on objects in the scene graph. Because NiLights are themselves NiDynamicEffects, they may be "attached" to other objects in the scene graph, in order to move with them, automatically. Also, by virtue of being children of NiDynamicEffect, they have "scope" – i.e., the specific set of scene graph objects that they affect. Dynamic lighting and the subclasses of NiLight are described in more detail later in this manual.
抽象类NiLight的子类用来为场景图中对象创建动态的、逐顶点光照效果。他们可能attached到场景图的其他对象上,由于做为NiDynamicEffect的子类。他们拥有范围,如他们影响的场景图对象的集合。在手册后面动态光和NiLight的子类有更详细的描述

NiTextureEffect

The subclasses of the abstract NiTextureEffect are used to create texture-based effects. These effects may be striking and eye-catching. The effects include complex spotlights, slide projectors, shadows, overhead clouding, and fogging. Texture-based effects are described in detail in Texturing Basics.

抽象类NiTextureEffect用来创建纹理效果. 这些效果比较显著和吸引眼球。效果包括复杂的聚光灯、幻灯片效果、阴影、云、雾。这些在Texturing Basics里面有详细描述。

NiGeometry

NiGeometry objects contain the vertex coordinates, normals, vertex colors and texture coordinates that describe geometric shapes. NiGeometry is an abstract class because it does not contain any information about how vertices are organized into drawable objects.

NiGeometry 对象用顶点坐标、法线、顶点颜色、纹理坐标来描述几何图形数据。NiGeometry 是一个抽象类因为他不包含任何顶点被组织到渲染对象的信息

NiLines

NiLines objects add vertex colors and texture coordinates to the data contained in a NiGeometry object, as well as the notion of a line-segment basis for the representation. NiLines also include an array of Boolean values that represent whether or not each pair of adjacent points in the array is connected by a line segment.

NiLines 对象添加顶点颜色和纹理坐标到NiGeoMetry对象数据中。用来表示线段的概念,NiLines 还包含一个Boolean数组用来表示是否每对邻接点连接成为一个线段

NiTriBasedGeom

NiTriBasedGeom objects add the notion of triangles to the representation of geometry. All subclasses of NiTriBasedGeom are drawn using triangles. NiTriBasedGeom is still an abstract class because it does not contain any information about how the vertices are actually organized into triangles.

NiTriBasedGeom 对象为几何体表示添加三角形的概念。所有NiTriBasedGeom子类使用三角形来渲染。NiTriBasedGeom 是一个抽象类因为他不包含顶点如何组织成三角形的信息

Note that all triangles in Gamebryo are assumed to be single-sided and oriented counter-clockwise.
注意gamebryo中所有的三角形都是单边逆时针导向的

NiParticles

NiParticles are a subclass of NiGeometry, which treats its list of vertices as independent points. This capability is useful for dynamic particle systems, as well as other effects.
NiParticles 是NiGeometry 的子类,他视顶点的集合为独立的点。这个能力对动态粒子系统很有用。

 

Updating the Scene Graph Geometry

更新场景图几何数据

An application may change the local transformations of a node as needed. The computation of the world transformation for the node and any transformations of descendants of that node are deferred until the application makes a call to an update routine.

应用程序可以改变一个节点的的本地变换。计算节点的世界变化以及其子孙的变换知道应用程序调用update时才执行

The update is efficient in that it does a single depth-first traversal of the subgraph to compute world transformations and world bounding spheres, thereby minimizing the number of nodes visited. While recursing down a path, the transformations are updated. Once a node's transformations are updated, the recursion continues to each child of the node. After updating the matrices, the world bounding spheres are updated on the upward return from the recursive calls.

update 执行过程:它沿子图进行深度优先访问,计算世界变换矩阵和包围球,因子最小化可视节点的数量。在更新完矩阵之后。沿着递归调用返回,更新世界包围球

In summary, transformations are updated while recursing down a path, and bounding spheres are updated while returning up a path.
总的来说,递归一个路径时变换操作被更新,而返回时包围球被更新
 
Usually most objects in a world are not moving, so the updates are restricted to only a few moving objects. To initialize the processing of a scene graph, the update routine must be called at least once at the root of the graph before an application uses the scene graph.  This approach guarantees that all the local and world information at the nodes is up-to-date.

通常世界中大部分对象并不移动,所以更新至限制在少数移动的对象上面。为了初始化场景图处理。update必须在应用程序使用场景图之前在root上调用一次。这个操作保证节点上本地信息和世界信息都被更新

During frame-to-frame application runtime, applications must call Update on an object "O" if any of the following criteria are met:

  • O is attached to or detached from a parent (direct parent only – not a "grandparent", etc)

  • O has a new child attached or a current child detached (direct children only – not "grandchildren", etc)

  • Any of O's transforms are changed

在应用程序每2帧中间,如果一个对象o发生下面的变化必须调用Update
    O 从一个父节点(直接父节点不是祖父节点等等)attached 或者 detached
    O 有一个子节点 attached 或者 detached (直系子节点而不是孙节点)
    任何O的变换矩阵被改变
Note that a call to Update on the current parent or any current ancestor can substitute for a call to Update on the object itself. For example, if object A attaches children B and C, then a call to A->Update will suffice. It is not necessary to call Update on all three objects. Applications can and should "batch" calls to update in this way.

注意任何在父节点或者祖节点的Update调用,可以代替对象自己的Update调用。例如一个对象A attach 子B 和 C,然后调用A->Update即可。不需要对三个对象调用Update操作,应用程序调用Update时能执行批次更新

For example, if an application makes changes to all of the "joint" transforms of an articulated character, it should defer calling update until all changes are made. It can then call Update once, at the root node of the character.

例如:如果一个应用程序改变了有关节的角色所有连接点变换矩阵,他应该推迟update的调用知道所有改变完成。可以在角色的root节点调用一次Update即可

However, note that Update should be called as low on the scene graph as possible.  Calling Update on the root of the scene graph every frame when only a single leaf has changed is excessive, and will lower performance.

但是,注意在场景图中Update应该尽量少调用。仅仅因为一个叶节点变化每帧都在场景图上调用Update将会降低性能

2008-06-05

Cloning Internals
Cloning是产生对象的拷贝的一种方法。应用程序调用下面的的函数来克隆对象。第一个函数使用缺省值来克隆对象名称,这在后面讨论。第二个版本允许通过NiClonigProcess来实现局部控制,这是为多线程情况下设计的函数。
NiObject* NiObject::Clone();
NiObject* NiObject::Clone(NiCloningProcess& kCloning);
使用克隆而不是通过例如从NIF文件中重复加载场景图的优点是这一类型的对象往往要耗费很多的内存,通过克隆来像NiGeometryData中的顶点数据可以被多个克隆对相共享,而通过单个NIF文件加载多次时她的顶点数组却是重复的。
为了得到一个对象的一个彻底的深拷贝可以使用
NiObjectPtr NiObject::CreateDeepCopy
这个调用使用流系统将对象保存到一个内存块中,然后加载这个内存快到一个新的对象。请小心使用深拷贝。有大量模型数据和纹理关联的对象应该尽可能使用共享数据。深拷贝不共享任何的东西。
下面的一些静态NiObjectNet中的静态函数用来决定存储在NiObjectNET中的对象名称在克隆的时候得缺省设置。
static void SetDefaultCopyType(CopyType eCopyType);
static CopyType GetDefaultCopyType();
static void SetDefaultAppendCharacter(char cAppendCharacter);
static char GetDefaultAppendCharacter();
The possible values of NiObjectNET::CopyType, the enumerated type that specifies the copy mode, are:
指定复制模式的NiObjectNET::CopyType枚举类型的可能值如下:
枚举 描述
COPY_NONE 不复制名字字符串,新的克隆对象的名字设置为NULL。
COPY_EXACT 新的克隆对象的名字字符串直接从原来的对象的名字中复制过来。
COPY_UNIQUE 新的克隆对象的名字字符串是原来对象的名字添加一个字符。添加的字符通过NiObjectNET的静态函数SetAppendCharacter和GetAppendCharacter来访问。
通过SetDefaultCopyType和GetDefaultCopyType访问的变量的缺省值是COPY_NONE。通过SetDefaultAppendCharacter和GetDefaultAppendCharacter访问的变量的缺省值是‘$’。

多线程时的克隆

单线程程序调用NiObject的Clone()成员不用考虑其他线程的影响。而多线程时,从GetDefaultCopyType和GetDefaultAppendCharacter的返回值可能在另外的一个线程通过调用SetDefaultCopyType和SetDefaultAppendCharacter时发生变化。这个函数不是线程安全的。在多线程应用程序中应用程序克隆的时候应该在NiCloningProcess对象中设置一个局部的复制类型和添加字符,如下所示:
NiCloningProcess kCloning;
kCloning.m_eCopyType = NiObjectNET::COPY_EXACT;
kCloning.m_cAppendChar = '%';
NiObject* pkClone = pkNode->Clone(kCloning);

Names

The class NiObjectNET supports character string names to facilitate identifying objects and searching for objects in a hierarchy. The following functions are used to access the name of an object:
类NiObjectNET 支持字符串名字来鉴别对象,下面的函数用来访问名字

void SetName(const NiFixedString& kName);

const NiFixedString& GetName() const;

SetName increments the reference to kName.

The function NiAVObject::GetObjectByName can be used to recursively traverse scene graphs in search of an object with a specific name. Its prototype is as follows:

NiAVObject::GetObjectByName 用来递归访问场景图来查找拥有指定名字的对象。函数如下:

NiAVObject* GetObjectByName(const NiFixedString& kName);

Note that when cloning an NiObjectNET, the clone's objects will have NULL names by default. This behavior can be changed, and is described in the cloning section of this manual. 

注意:当我们cloneing 一个NiObjectNET 的时候,克隆对象默认名字为NULL,这个行为可以改变

模板类
Gamebryo提供了一序列基本的模版容器类。在Gamebryo内部这些容器类在库的内部普遍使用。这些基本的容器类在下面描述;特们的特定用处和成员函数将在后面的章节中描述。

列表
NiTPointerList对象用来可以用来容纳和管理指针、智能指针或者其他等于指针类型大小或更小的元素。这个类允许在任意的位置有效地插入或删除元素,以及有效地前向和后向迭代所有元素。这个类也可用来查找给定值的元素的存在和位置。NiTPointerList的项从共享内存池中按块分配,这使得这个类快速和内存高效。NiTList已经不赞成使用,应用程序应该使用NiTPointerList代替。对于大小大于指针大小的对象,可以使用NiTObjectList。

数组
NiTArray对象实现动态数据的功能,几乎可以容纳任意类型的对象。数组可以增长和收缩,还可以根据需求进行压缩(通过转移元素来删除空的空间)。对于基本类型(char*,float,int等)请使用NiTPrimitiveArray。对于从NiMemObject派生的类型,请使用NiTObjectArray。注意NiTArray有65535个元素的限制,对于更大数目的数组请使用NiTLargeArray派生的类,例如:NiTLargePrimitiveArray或NiTLargeObjectArray。

映射
NiTPointMap对象实现哈希表(也叫“字典”)的功能,允许任意类的键映射到一个指针、智能指针或者其他等于指针类型大小或更小的元素。它们能够进行键/值对的快速存储和查找。不要使用它来作为字符串键的哈希表,对于这样的哈希表请使用专门为之设计的NiTStringPointerMap对象。NiTPointerMap和NiTStringPointerMap的项从共享内存池中按块分配,这使得这些类快速和高效。对于大小大于指针大小的对象可以使用NiTMap和NiTStringMap。

StringMap
字符串映射
NiTStringMap和NiTStringPointerMap对象在某种程度上功能上类似于NiTMap和NiTPointerMap对象,但是它们接受字符串作为键并使用字符串比较作为键哈希。
FixedStringMap
固定字符串映射
NiTFixedStringMap对象的功能在某种程度上类似于NiTMap对象,但它接受NiFixedString对象作为键。

Queue
队列
NiTQueue为几乎任何类型的对象实现一个先进先出(FIFO)的队列。但不支持智能指针。

集合
NiTSet为几乎任何类型的对象实现一个无序的集合。但不支持智能指针。对于基本类型(char*,float,int等)请使用NiTPrimitiveSet。对于NiMemObject派生的对象请使用NiTObjectSet。对于对象的智能指针请使用NiTObjectPtrSet和NiPrimitivePtrSet,它们能正确地处理引用计数。

内存池
NiTPool实现小对象的内存池。使得应用程序可以一次分配大量小对象并通过内存池重用它们,而不是单个地分配和释放小对象。
 

在任何可能的情况下,Gamebryo都避免使用全局常量和枚举类型,取而代之是使用类的枚举类型。类的枚举类型都使用大写加下划线分割词的方式,例如:NiAlphaProperty::ALPHA_SRCALPHA 

Type

Prefix

Example

character

c

char cVariable;

short

s

short sVariable;

integer

i

int iVariable;

long

l

long lVariable;

unsigned character

uc

unsigned char ucVariable;

unsigned short

us

unsigned short usVariable;

unsigned integer

ui

unsigned int uiVariable;

unsigned long

ul

unsigned long ulVariable;

enumeration

e

NiFogProperty::FogFunction eFunction;

float

f

float fVariable;

double

d

double dVariable;

class, struct

k

NiPoint3 kVariable;

array

a

unsigned int auiVariable[2];

pointer

p

float* pfVariable;

pointer to pointer

pp

float** ppfVariable;

pointer to void

pv

void* pvVariable;

pointer to function

pfn

int (*pfnVariable)();

size_t

st

size_t stVariable;

抱歉!评论已关闭.