Mission Statement: The purpose of this section is to show a programmer how to make sense of the blender game engine source code. It is not intended for those who cannot code in C++. If you're one of the people who have a basic understanding, I'm being careful to use keywords that if you google, should provide enough information to understand.
::任务声明:本部分的目的是向程序员展示如何理解混动游戏引擎源代码.它不适用于那些无法用C++编码的人.如果你是那些基本理解的人之一,我会小心使用关键字,如果你google,应该提供足够的信息来理解.


When you press P, several things are sent to the GE before anything can be done. What might these be?
::您可以在下面的图中看到,

StartKetsjiShell(struct ScrArea *area,
		      char* scenename,
		      struct Main* maggie1,
		      struct SpaceIpo *sipo,
		      int always_use_expand_framing)


Blender uses a lot of structs and classes. You need to have a working understanding of these as well as inheritance before we can move on. For a refresher:  http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/inheritance.html
::混器使用了很多结构和类. 在我们继续前进之前,您需要对这些以及继承有工作理解. 为了刷新: http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/inheritance.html

The SCA_IObject class   source/gameengine/GameLogic/SCA_IObject.cpp
::源/游戏引擎/游戏逻辑/SCA_IObject.cpp 的 SCA_IObject 类

and SCA_IObject.h


This class encapsulates a lot of other things, so we can start here and move downwards to the things that it controls. First off it uses vectors to store all the different Sensors, Controllers and Actuators that are linked to the object.  A vector is like an array, but it is dynamic and has built in functions.
We will begin by examining how sensors are added.
::这个类包含了很多其他东西,所以我们可以从这里开始,然后向下移动到它控制的东西.首先它使用矢量来存储与对象相关的所有不同的传感器,控制器和执行器.矢量就像一个数组,但它是动态的,并且内置了功能.我们将从检查传感器如何添加开始.


typedef std::vector<SCA_ISensor *> SCA_SensorList;
SCA_SensorList m_sensors;

::类型def std:: 矢量<SCA_ISensor *> SCA_SensorList;SCA_SensorList m_传感器;

The first line here is a typedef so it just tells us that we can create a vector of SCA_ISensor by using the name SCA_Sensor list.
The second line creates the vector with the name, m_sensors
::这里的第一行是一个typedef,它告诉我们我们可以使用名字SCA_ISensor列表创建一个SCA_ISensor的向量.第二行创建一个名字为m_sensors的向量


void SCA_IObject::AddSensor(SCA_ISensor* act)<br />
{   m_sensors.push_back(act);   }

This function allows the parents of an SCA_IObject to add new sensors by calling: SCA_IObject.AddSensor(keyboard);  pseudocode

So now you know how Objects in the GE create sensors (and actuators and controllers, its the same smile So lets look at how Sensors are grabbed! Since they are dynamically added the program can't make assumptions about how many are there or what they will be. Thus there is this helper function:

::这个函数允许SCA_IObject的父通过调用:SCA_IObject.AddSensor(keyboard); 伪代码来添加新的传感器. 现在你知道GE中的对象如何创建传感器 (以及执行器和控制器,它是相同的smile 所以让我们看看传感器是如何抓取的! 因为它们是动态添加的,程序不能对有多少或它们将是什么做出假设. 因此有这个辅助函数:

1''SCA_ISensor* SCA_IObject::FindSensor(const STR_String& sensorname)
2{
3	SCA_ISensor* foundsensor = NULL;
4
5	for (SCA_SensorList::iterator its = m_sensors.begin();!(its==m_sensors.end());its++)
6	{
7		if ((*its)->GetName() == sensorname)
8		{<br />
9			foundsensor = (*its);
10			break;
11		}
12	}
13	return foundsensor;
14}''

Put simply, you give this the name of a sensor and it returns a pointer to the sensor.

for the newbies: I know you learned all about classes when i asked you to, but just in casesmile the first word, "SCA_ISensor*" this tells us that the function will return a pointer to a SCA_ISensor. And based on the functions arguments, we know that when you call FindSensor you must give it a string between the parenthesis.
in line 3 you create an empty pointer which you will use to store the sensor that you find. Then you loop and go through each sensor in the vector of sensors (remember, it was named m_sensors) until you find the one that matches the name. If you don't find one, you return NULL.
::简单地说,你给这个一个传感器的名字,它会返回一个指针.对于新手来说:我知道你在我问你的时候已经了解了所有关于类的知识,但只是为了防范smile 第一个词",SCA_ISensor*"告诉我们,这个函数将返回一个指针到一个SCA_ISensor.根据函数参数,我们知道当你调用FindSensor时,你必须在括号之间给它一个字符串.在第3行中,你创建一个空指针,你将使用它来存储你找到的传感器.然后你循环并通过每个传感器在传感器向量 (记住,它被命名为m_sensors) 直到你找到与名字匹配的传感器.如果你没有找到一个,你返回NULL.


void SCA_IObject::Suspend(void)  What this does is it loops through all of the sensors and sends each one a "suspend" call. What this does is change a variable named, "m_suspended" which makes stops the sensors from running when they are called with their Activate() function.
::这样做是通过所有传感器循环并发送每个"暂停"调用. 这样做是改变一个变量, "m_suspended"使得当传感器被调用时停止运行.


Last modified: Tuesday, 18 March 2025, 9:07 PM