官术网_书友最值得收藏!

The benefits of the monolithic game object

It is worth noting that even if you choose this approach, you can still have your core engines decoupled from the game object. When writing the graphics engine, for example, instead of passing in a game object as a parameter to a Draw function, we could pass in the members that the graphics engine needs:

void Graphics::SetTexture(int textureID); 
void Graphics::SetTextureCoords(const float* coordArray);
void Graphics::Draw(const M5Mtx44& worldMtx);
vs
void Graphics::Draw(const Object& obj);

Another argument for creating objects like this is that we know exactly what is in our game object. Compared with other approaches, we never need to cast our object or search for properties within the object. These operations make the code more complicated and have a slight performance cost. By using a simple struct, we have direct access to the variables and the code is easier to understand.

The only time we might use this approach is if we know 100% that the number of object types won't be large, for example, if you are making a puzzle game and the only game objects are sheep and walls. Puzzle games are often very simple and use the same mechanics over and over. In this case, this is a good approach because it is easy and doesn't require any time building a complicated system.

主站蜘蛛池模板: 独山县| 常熟市| 秭归县| 昌乐县| 石城县| 武平县| 正定县| 米泉市| 澄江县| 旺苍县| 阿合奇县| 通辽市| 伊春市| 香港| 阿克陶县| 宾阳县| 清水河县| 宜川县| 杨浦区| 江孜县| 喀喇沁旗| 永丰县| 宝兴县| 乌兰县| 连江县| 内黄县| 万州区| 禄劝| 双鸭山市| 钟山县| 搜索| 光泽县| 沅江市| 昭觉县| 合作市| 吕梁市| 集贤县| 泗水县| 惠东县| 平凉市| 曲松县|