The document is about a 2017 developer day hosted by iFunFactory. It discusses iFunFactory's technology for powering games. The technology provides flexibility for different types of games, high performance through optimizations, and tools to help developers build and monitor their games. The event aimed to help developers learn how to create great games using iFunFactory's technology.
The document is about a 2017 developer day hosted by iFunFactory. It discusses iFunFactory's technology for powering games. The technology provides flexibility for different types of games, high performance through optimizations, and tools to help developers build and monitor their games. The event aimed to help developers learn how to create great games using iFunFactory's technology.
The document discusses techniques for reducing repetitive code using C/C++ preprocessor programming. It covers macros like X-Macro for generating repeating code structures, horizontal and vertical repetition using chaining and recursion of macros, and Boost Preprocessor library which provides optimized macros for tasks like repetition and token pasting that support high levels of reentrancy. The goal is to avoid duplicating code and generate boilerplate code at compile-time through clever use of the preprocessor.
This chapter discusses techniques for synchronizing concurrent threads in C++, including condition variables, futures/promises, packaged tasks, and chrono time utilities. Condition variables allow threads to wait for some condition to be met or signaled by another thread. Futures and promises are used to return values from asynchronous operations. Packaged tasks separate function execution from result retrieval. Chrono defines types for measuring time and time points. The chapter also briefly mentions message passing between actors as another concurrency method.
The omega design document outlines the objectives, functions, architecture, and user interface of the omega project. It includes a project management system for managing various resources, a publishing article system, and SVN management features. The architecture is based on the MVC model, and the user interface combines blue and white with specific design elements.
4. Network
觜襯 豌襴襯 觜蠍 IO
4
var socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.IPv4);
// preprocess socket
var buffer = new byte[4096];
socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None,
result => {
var received = socket.EndReceive(result);
// process packet
}, null /* state */);
5. TaskCompletionSource
C++ Future + C# Task Awaitable Future
5
Network
static Task<int> ReceiveAsync(this Socket sock, byte[] buf, int off, int size)
{
var source = new TaskCompletionSource<int>(sock);
sock.BeginReceive(buf, off, size, SocketFlags.None, state =>
{
try
{
source.SetResult(socket.EndReceive(state));
}
catch (Exception e)
{
source.SetException(e);
}
}, source);
return source.Task;
}
6. async, await
Task.Result 觜蠍 蠍(await), 蠏碁 貊螳 (async)
6
Network
static async Task<byte[]> ReceiveAsync(this Socket socket, int count)
{
var buffer = new byte[count];
var length = 0;
do
{
var num = await ReceiveAsync(socket, buffer, length, count);
if (num == 0)
break;
length += num;
count -= num;
} while (count > 0);
if (length != buffer.Length) throw new IOException("packet is truncated.");
return buffer;
}
7. async, await
7
Network
async void ReceiveLoop(Socket socket)
{
while (true)
{
var lengthBytes = await socket.ReceiveAsync(sizeof (int));
var packetBytes = await socket.ReceiveAsync(
BitConverter.ToInt32(lengthBytes, 0));
// process packet
var packet = ReadPacket(packetBytes);
_handlerMap[packet.GetType()](packet);
}
}
await 讌 讌 IO signal る, 企 Task 覃豢螻,
螳 るジ Task襯 谿場
8. Listener (Server)
ClientSocket 觜蠍磯 Accept伎,
螳 Socket襷 觜蠍磯 Packet 蠍壱伎 豌襴
8
Network
var listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
var localEndPoint = new IPEndPoint(IPAddress.Any, Port);
listener.Bind(localEndPoint);
listener.Listen(100);
while (true)
{
var clientSocket = await listener.AcceptAsync();
ReceiveLoop(clientSocket);
}
async method
25. How much faster is C++ than C#?
25
C# may not be faster, but it makes
YOU/ME faster. That's the most
important measure for what I do. :)
http://stackoverflow.com/questions/138361/how-much-faster-is-c-than-c