UE and VR Development Technical Notes

平时随笔写下的一些UE4和VR开发中的技术笔记,以及一些相关资料的收录,之前零零散散放在imzlp.com/notes中,今天整理了一下,后续的笔记都会放到这篇文章中。

阅读全文 »

Pass Actor To Next Level Through Seamless Travel

因为UnrealEngine在切换关卡(OpenLevel)时会把当前关卡的所有对象全部销毁,但是常常我们需要保存某些对象到下一关卡中,今天读了一下相关的代码,本篇文章讲一下如何来实现。
其实Unreal的文档是有说明的(Travelling in Multiplayer),实现起来也并不麻烦,但是UE文档的一贯风格是资料是不详细的,中文资料更是十分匮乏(多是机翻,而且版本很老),在搜索中也没有查到相关的靠谱的东西,我自己在读代码实现的过程中就随手记了一下,就当做笔记了。

阅读全文 »

Why can't we override && and || and , (comma)?

C++的基础语法里提供了||&&两个逻辑操作符还有,(comma)运算符。在类中我们也可以重载这些操作符,但是不要这样做,我会在这篇文章中写出标准描述以及不能重载的原因。
概括来说,因为内置的||和&&具有短路求值语义,如果你自己重载了他们就变成了普通的函数调用,会具有与built-in ||&&完全不同的语义。
而,操作符具有从左到右求值的语义,所以如果自己重载,会变成函数调用,也会具有不同于built-in的语义。

阅读全文 »

operator new: void* to T* conversion

在C++14标准(C++98/11也一样)中,在Annex C Compatibility里有这么一条:

Change: Converting void* to a pointer-to-object type requires casting

1
2
3
4
5
char a[10];
void* b=a;
void foo() {
char* c=b;
}

ISO C will accept this usage of pointer to void being assigned to a pointer to object type. C ++ will not.

但是为什么operator new()会返回void*且不用显式转换为T*就能赋值给T*呢?

阅读全文 »

How lambda is implemented in the compiler

在C++中lambda-expression的结果叫做闭包对象(closure object)。本篇文章并非是介绍C++ lambda的用法的(这一点《TC++PL》、《C++ Primer》中都十分详细,或者看我之前的总结C++11的语法糖#lambda表达式),而是从LLVM-IR来分析在Clang中是如何实现lambda-expression的。

阅读全文 »

Visibility and accessibility of access control mechanisms

在上一篇文章突破C++类的访问控制机制中简略提到了C++类的成员访问控制(public/protected/private)只是限制了成员名字的可访问性(accessable)**而非可见性(visable)**。在这篇文章中主要分析这种性质带来的后果以及如何避免。

阅读全文 »

Breaking through the access control mechanism of C++ classes

众所周知,在C++中类成员能够具有三种访问权限,分别为public/protected/private
[ISO/IEC 14882:2014]A member of a class can be

  • private: that is, its name can be used only by members and friends of the class in which it is declared.
  • protected: that is, its name can be used only by members and friends of the class in which it is declared, by classes derived from that class, and by their friends (see 11.4).
  • public: that is, its name can be used anywhere without access restriction.

从标准意图上来看,是希望隐藏类的实现细节和底层数据,即为封装。但是我们也可以通过一些特殊的方式来突破访问权限的限制。

阅读全文 »