- 1
data[idata].io_data[i % 4].data
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+4
data[idata].io_data[i % 4].data
Когда процессишь данные данных для данных
0
void Canvas::drawText(const char* text, SDL_Color sdlColor, int x, int y) const noexcept
{
if (!font)
throw std::runtime_error{"TTF_Font* is null"};
SDL_Surface* const sdlSurface =
::TTF_RenderText_Solid(const_cast<TTF_Font*>(font->getTtfFont()), text, sdlColor);
if (!sdlSurface)
throw std::runtime_error{"SDL_Surface* is null"};
SDL_Texture* const sdlTexture =
::SDL_CreateTextureFromSurface(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlSurface);
if (!sdlTexture)
throw std::runtime_error{"SDL_Texture* is null"};
const SDL_Rect srcrect{0, 0, sdlSurface->w, sdlSurface->h};
const SDL_Rect dstrect{x, y, sdlSurface->w, sdlSurface->h};
::SDL_FreeSurface(sdlSurface);
::SDL_RenderCopy(const_cast<SDL_Renderer*>(renderer->getSdlRenderer()), sdlTexture,
&srcrect, &dstrect);
::SDL_DestroyTexture(sdlTexture);
}
+5
template<typename T>
T* sanitize(T* p)
{
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) & ~(alignof(T)-1));
}
template<typename T>
constexpr size_t avaliable_width()
{
switch(alignof(T))
{
case 1: return 0;
case 2: return 1;
case 4: return 2;
case 8: return 3;
case 16: return 4;
case 32: return 5;
case 64: return 6;
case 128: return 7;
case 256: return 8;
default: return 0;
}
}
template<size_t bit, typename T>
T* set_tag(T* p, bool tagged = true)
{
static_assert(bit < avaliable_width<T>(), "bad_width");
if(tagged) {
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) | 1 << bit);
}
return reinterpret_cast<T*>(
reinterpret_cast<uintptr_t>(p) & ~(uintptr_t(1) << bit));
}
template<size_t bit, typename T>
bool get_tag(T* p)
{
static_assert(bit < avaliable_width<T>(), "bad_width");
return reinterpret_cast<uintptr_t>(p) >> bit & 1;
}
Младшие биты указателей на выравненные типы всегда нулевые. Из за этого (по формуле Шеннона) указатель несёт в себе меньше информации, оставаясь того же размера. Битоёбов это расстраивает.
+3
#define ROOSTER "?"
#define CONDENSED_MILK "."
string kokoko = string(ROOSTER, 1) + string(CONDENSED_MILK);
ЧТО блять мешает написать
string kudkudah(".?");
ЧТО?
+9
if(buf_modem[cntfrommodem] == 'S')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem ] == 'R')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'I')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'N')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'G')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == ':')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == ' ')
{
cnt_comma = 0;
while(cnt_comma < 2)
{
cntfrommodem = cntfrommodem + 1;
if(buf_modem[cntfrommodem] == ',')
cnt_comma = cnt_comma + 1;
}
cntfrommodem = cntfrommodem + 1 ;
}
}
}else
cntfrommodem -= 4;
}else cntfrommodem -= 3;
}else cntfrommodem -= 2;
}else cntfrommodem--;
}
buf_modem[tmpcntr] = buf_modem[cntfrommodem];
cntfrommodem++;
tmpcntr++;
}
cntfrommodem = 0;
while(1)
{
/// ищем мэдэ5
if(buf_modem[cntfrommodem] == '#')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'S')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem ] == 'E')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'R')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'V')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'A')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'N')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'S')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == 'W')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == ':')
{
cntfrommodem = cntfrommodem + 1 ;
if(buf_modem[cntfrommodem] == ' ')
{
Парсинг ответа от GSM-модема. Код из реального проекта для STM32.
+3
void CRenderer::renderToTexture(CTexture &dest, CTexture &src, TRANSFORM tr)
{
int w = src.width();
Concurrency::parallel_for(0, w, [&] (int i)
{
int h = src.height();
for(int j = 0; j < h; j++)
{
COLOR temp = src.pixel(i, j);
if(temp == TRANSPARENT_COLOR) continue;
//scale
float dx = (i-(w/2) + 0.5f)*tr.scale[0];
float dy = (j-(h/2) + 0.5f)*tr.scale[1];
//rotate
float dx2 = dx*tr.cosRot - dy*tr.sinRot;
float dy2 = dx*tr.sinRot + dy*tr.cosRot;
//translate
dx2 += tr.trans[0];
dy2 += tr.trans[1];
//update pixels
float xMin = dx2 - 0.5f*tr.scale[0] + w/2; if(xMin < 0) xMin = 0;
float yMin = dy2 - 0.5f*tr.scale[1] + w/2; if(yMin < 0) yMin = 0;
float xMax = xMin + tr.scale[0]; if(xMax-(int)xMax > 0) xMax++; if(xMax >= dest.width()) xMax = dest.width()-1;
float yMax = yMin + tr.scale[1]; if(yMax-(int)yMax > 0) yMax++; if(yMax >= dest.height()) yMax = dest.height()-1;
for(float ki = xMin; ki <= xMax; ki++) for(float kj = yMin; kj <= yMax; kj++) dest.pixel(ki, kj) = temp;
}
});
}
Писал ручками трансформацию картинок в 2д, вышло без искажений пропорций, но с дырками, уродливо, и просадило фпс в самую жопень!
+2
#include "Node.h"
CMonom* CNode::GetMonomPtr() const
{
return _MonomPtr;
}
CNode* CNode::GetNext() const
{
return _NextPtr;
}
bool CNode::GetSign() const
{
return _MonomPtr->GetSign();
}
int CNode::GetCoeff() const
{
return _MonomPtr->GetCoeff();
}
unsigned CNode::GetDegree() const
{
return _MonomPtr->GetDegree();
}
void CNode::SetNext(CNode* Node)
{
_NextPtr = Node;
}
void CNode::SetCoeff(int iCoeff)
{
_MonomPtr->SetCoeff(iCoeff);
}
void CNode::SetDegree(unsigned uDegree)
{
_MonomPtr->SetDegree(uDegree);
}
CNode::CNode(char* szStr) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(szStr);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(int iCoeff, unsigned uDegree) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(iCoeff, uDegree);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(const CMonom& Monom) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(Monom);
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode::CNode(const CNode& Node) : _NextPtr(nullptr)
{
try
{
_MonomPtr = new CMonom(*Node.GetMonomPtr());
}
catch (const bad_alloc& exc)
{
std::cout << exc.what();
}
}
CNode& CNode::operator=(const CNode& Node)
{
SetCoeff(Node.GetCoeff());
SetDegree(Node.GetDegree());
return *this;
}
CNode CNode::operator-() const
{
return CNode(-*_MonomPtr);
+2
connector* getConnector( int id )
{
autolock_read<lock_rw_t> alr( _lock );
return _getConnector(id);
}
П-потокобезопасность
−2
namespace spine {
static SkeletonBatch* instance = nullptr;
void SkeletonBatch::setBufferSize (int vertexCount) {
if (instance) delete instance;
instance = new SkeletonBatch(vertexCount);
}
SkeletonBatch* SkeletonBatch::getInstance () {
if (!instance) instance = new SkeletonBatch(8192);
return instance;
}
SkeletonBatch::SkeletonBatch (int capacity) :
_capacity(capacity), _position(0)
{
_buffer = new V3F_C4B_T2F[capacity];
_firstCommand = new Command();
_command = _firstCommand;
Director::getInstance()->getScheduler()->scheduleUpdate(this, -1, false);
}
SkeletonBatch::~SkeletonBatch () {
Director::getInstance()->getScheduler()->unscheduleUpdate(this);
Command* command = _firstCommand;
while (command) {
Command* next = command->next;
delete command;
command = next;
}
delete [] _buffer;
}
https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-cocos2dx/3/src/spine/SkeletonBatch.cpp
Это просто шедевЕр! Течет как ссаные тряпки...
+4
#define key \
keySequence.keys[i]
#define read_helper(val_) \
file.read( \
reinterpret_cast<char*>(&key.val_), \
sizeof(decltype(key.val_)) \
)
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(RotationQuaternion);
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(TimeValue);
for (DWORD i = 0; i < keyPointer.Count; i++)
read_helper(PositionValue),
key.SwapBytes();
#undef read_helper
#undef key