游戏的优化_不仅仅是帧速率.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
* * * /~tveldhui/papers * * * * * * * * * * Vc 7.1 每个node要消耗 14字节 参考:《effctive c++》 Lua 的 map * * VC 里 100 次 push_back 会引起 13 次内存重新分配 * * * * * * 更进一步的讨论超出了本次的讨论范围 * 多种分配方式。 * * * * * * * * * * * * * * * * * * * * * 滚动优化 更大的back buffer 破碎的分格 覆盖优化 C++的高级特性 天使还是恶魔? Template 避免重复的代码 void _blit(pixel *dst,const pixel *src,size_t s,bool mask_blit) { for (size_t i=s;i!=0;--i,++dst,++src) { if (!mask_blit || *src!=mask_color) *dst=*src; } } template bool mask_blit void _blit(pixel *dst,const pixel *src,size_t s) { for (size_t i=s;i!=0;--i,++dst,++src) { if (!mask_blit || *src!=mask_color) *dst=*src; } } void blit(pixel *dst,const pixel *src,size_t s) { _blitfalse(dst,src,s); } void mask_blit(pixel *dst,const pixel *src,size_t s) { _blittrue(dst,src,s); } 矩阵运算 Matrix A,B,C; A=B+C; Matrix operator+(const Matrix lhs,const Matrix rhs); Matrix my_type::operator=(const Matrix v); 如何避免临时对象的返回? 转化为 A=B; A+=C; Expression Templates templatetypename T class add_type { const T _lhs; const T _rhs; public: add_type(const T lhs,const T rhs) :_lhs(lhs),_rhs(rhs) {} T calculate(T result) const { result=_lhs; result+=_rhs; return result; } }; template typename T add_typeT operator+(const T a,const T b) { return add_typeT(a,b); } class Matrix { /* ... */ Matrix operator+=(const Matrix v); Matrix operator=(const add_typeMatrix v) { return v.calculate(*this); } /* ... */ } 编译时计算 templateint N class factorial { public: enum { value = N * factorialN-1::value }; }; template class factorial1 { public: enum { value = 1 }; }; 冒泡排序 inline void compare_swap(int a,int b) { if (ab) { int t=a; a=b; b=t; } } void sort(int *data,int n) { for (int i=0;in-1;i++) { for (int j=i+1;jn;j++) { compare_swap(data[i],data[j]); } } } templateint N struct inner_loop { static inline void expand(int* data) { compare_swap(*data, data[N]); inner_loopN-1::expand(data); }

文档评论(0)

benzei244572 + 关注
实名认证
内容提供者

建筑工程师持证人

没啥好说的额

领域认证该用户于2024年10月16日上传了建筑工程师

1亿VIP精品文档

相关文档