Skip to content

Instantly share code, notes, and snippets.

@mobius
mobius / value_semantics.cxx
Created July 7, 2016 12:51
value_semantics.cxx
#include "stdafx.h"
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <thread>
#include <future>
@mobius
mobius / bloated_code.cc
Last active July 15, 2016 09:50
c++ seasoning
auto f = begin(expanded_panels_) + fixed_index;
// 发现其实expanded_panels其实是根据cur_panel_center已经排好序了
auto p = lower_bound(begin(expanded_panels_), f,
[&](const ref_ptr<Panel>& e){ return center_x <= e->cur_panel_center(); });
rotate(p, f, f + 1);
// 总结
// 上面代码更加高效
// 更加清楚表达含义,review代码的人不用去考虑边界条件因为算法都保证好了
// 以上代码只是选择单个panel移动,但是非常容易扩展成多个panel向右移动
bool PatchManager::GetMD5(const u8 *pBuffer, u32 uBufLen, u8 *rgbHash)
{
BOOL bResult = FALSE;
HCRYPTPROV hProv = 0;
HCRYPTHASH hHash = 0;
DWORD cbRead = 0;
DWORD cbHash = 0;
CHAR rgbDigits[] = "0123456789ABCDEF";
// Get handle to the crypto provider
@mobius
mobius / links.md
Last active July 22, 2021 02:52 — forked from Leandros/links.md
Writing a Modern Rendering Engine
@mobius
mobius / reflect_inputlayout.cpp
Created March 23, 2018 08:19
Reflect DX11 Vertex shader to create input layout
HRESULT CreateInputLayoutDescFromVertexShaderSignature( ID3DBlob* pShaderBlob, ID3D11Device* pD3DDevice, ID3D11InputLayout** pInputLayout )
{
// Reflect shader info
ID3D11ShaderReflection* pVertexShaderReflection = NULL;
if ( FAILED( D3DReflect( pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**) &pVertexShaderReflection ) ) )
{
return S_FALSE;
}
// Get shader info
@mobius
mobius / cloudSettings
Last active March 3, 2020 01:10
vscode setting
{"lastUpload":"2020-03-03T01:09:57.408Z","extensionVersion":"v3.4.3"}