GXBOOL RenderTargetImpl::Initialize(GXFormat eColorFormat, GXFormat eDepthStencilFormat) { GXUINT nWidth = m_nWidth; GXUINT nHeight = m_nHeight; if(m_nWidth < 0 || m_nHeight < 0) { GXGRAPHICSDEVICE_DESC sDesc; m_pGraphics->GetDesc(&sDesc); nWidth = SizeRatioToDimension(m_nWidth, sDesc.BackBufferWidth, 0); nHeight = SizeRatioToDimension(m_nHeight, sDesc.BackBufferHeight, 0); } // // 检查 // ID3D11Device* pD3D11Device = m_pGraphics->D3DGetDevice(); UINT uColorSupport = 0; UINT uDepthStencilSupport = 0; pD3D11Device->CheckFormatSupport(GrapXToDX11::FormatFrom(eColorFormat), &uColorSupport); if(TEST_FLAG_NOT(uColorSupport, D3D11_FORMAT_SUPPORT_RENDER_TARGET)) { CLOG_ERROR("RenderTarget: %s 格式不能作为渲染纹理", GrapXToDX11::FormatToString(eColorFormat)); return FALSE; } if(eDepthStencilFormat != Format_Unknown) { pD3D11Device->CheckFormatSupport(GrapXToDX11::FormatFrom(eDepthStencilFormat), &uDepthStencilSupport); if(TEST_FLAG_NOT(uDepthStencilSupport, D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) { CLOG_ERROR("RenderTarget: %s 格式不能作为渲染模板深度缓冲", GrapXToDX11::FormatToString(eDepthStencilFormat)); return FALSE; } } m_pColorTexture = new TextureImpl_RenderTarget(m_pGraphics, eColorFormat, nWidth, nHeight); if(InlIsFailedToNewObject(m_pColorTexture)) { return FALSE; } if(_CL_NOT_(m_pColorTexture->InitRenderTexture(NULL))) { SAFE_RELEASE(m_pColorTexture); return FALSE; } if(eDepthStencilFormat != Format_Unknown) { return InitDepthStencil(eDepthStencilFormat, nWidth, nHeight); } return TRUE; }
ActorID World::CreateActorID() { if (NextActorID == 0) { CLOG_ERROR("Unable to generate new actor id (next is 0/ERR)"); return 0; } if (NextActorID == std::numeric_limits<ActorID>::max()) { CLOG_ERROR("Unable to generate new actor id (limit reached)"); return 0; } return NextActorID++; }
static void curve_undosys_step_decode(struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir)) { CurveUndoStep *us = (CurveUndoStep *)us_p; /* Load all our objects into edit-mode, clear everything else. */ ED_undo_object_editmode_restore_helper( C, &us->elems[0].obedit_ref.ptr, us->elems_len, sizeof(*us->elems)); BLI_assert(curve_undosys_poll(C)); for (uint i = 0; i < us->elems_len; i++) { CurveUndoStep_Elem *elem = &us->elems[i]; Object *obedit = elem->obedit_ref.ptr; Curve *cu = obedit->data; if (cu->editnurb == NULL) { /* Should never fail, may not crash but can give odd behavior. */ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", us_p->name, obedit->id.name); continue; } undocurve_to_editcurve(bmain, &elem->data, obedit->data, &obedit->shapenr); DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); } /* The first element is always active */ ED_undo_object_set_active_or_warn( CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); }
/* This is a Mesh-based copy of the same function in DerivedMesh.c */ static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int actshape_uid) { KeyBlock *kb; int i, j, tot; if (!mesh_dst->key) { return; } tot = CustomData_number_of_layers(&mesh_src->vdata, CD_SHAPEKEY); for (i = 0; i < tot; i++) { CustomDataLayer *layer = &mesh_src->vdata.layers[CustomData_get_layer_index_n(&mesh_src->vdata, CD_SHAPEKEY, i)]; float(*cos)[3], (*kbcos)[3]; for (kb = mesh_dst->key->block.first; kb; kb = kb->next) { if (kb->uid == layer->uid) { break; } } if (!kb) { kb = BKE_keyblock_add(mesh_dst->key, layer->name); kb->uid = layer->uid; } if (kb->data) { MEM_freeN(kb->data); } cos = CustomData_get_layer_n(&mesh_src->vdata, CD_SHAPEKEY, i); kb->totelem = mesh_src->totvert; kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, 3 * sizeof(float), __func__); if (kb->uid == actshape_uid) { MVert *mvert = mesh_src->mvert; for (j = 0; j < mesh_src->totvert; j++, kbcos++, mvert++) { copy_v3_v3(*kbcos, mvert->co); } } else { for (j = 0; j < kb->totelem; j++, cos++, kbcos++) { copy_v3_v3(*kbcos, *cos); } } } for (kb = mesh_dst->key->block.first; kb; kb = kb->next) { if (kb->totelem != mesh_src->totvert) { if (kb->data) { MEM_freeN(kb->data); } kb->totelem = mesh_src->totvert; kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), __func__); CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", kb->name); } } }
static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src) { KeyBlock *kb; Key *key = mesh_src->key; int i; if (!mesh_src->key) { return; } /* ensure we can use mesh vertex count for derived mesh custom data */ if (mesh_src->totvert != mesh_dest->totvert) { CLOG_ERROR(&LOG, "vertex size mismatch (mesh/dm) '%s' (%d != %d)", mesh_src->id.name + 2, mesh_src->totvert, mesh_dest->totvert); return; } for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) { int ci; float *array; if (mesh_src->totvert != kb->totelem) { CLOG_ERROR(&LOG, "vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)", mesh_src->id.name + 2, mesh_src->totvert, kb->name, kb->totelem); array = MEM_calloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); } else { array = MEM_malloc_arrayN((size_t)mesh_src->totvert, 3 * sizeof(float), __func__); memcpy(array, kb->data, (size_t)mesh_src->totvert * 3 * sizeof(float)); } CustomData_add_layer_named( &mesh_dest->vdata, CD_SHAPEKEY, CD_ASSIGN, array, mesh_dest->totvert, kb->name); ci = CustomData_get_layer_index_n(&mesh_dest->vdata, CD_SHAPEKEY, i); mesh_dest->vdata.layers[ci].uid = kb->uid; } }
SocketResult TCPServer::OpenPort(CLUSHORT port) { //WSADATA Data; SOCKADDR_IN serverSockAddr; ASSERT(net_sockets::IsStartup()); // // int status = 0; //int status = WSAStartup(CLMAKEWORD(1, 1), &Data); //if (status != 0) { // CLOG_ERROR("ERROR: WSAStartup unsuccessful\r\n"); //} // zero the sockaddr_in structure memset(&serverSockAddr, 0, sizeof(serverSockAddr)); // specify the port portion of the address serverSockAddr.sin_port = htons(port); // specify the address family as Internet serverSockAddr.sin_family = AF_INET; // specify that the address does not matter serverSockAddr.sin_addr.s_addr = htonl(INADDR_ANY); // create a socket socket(通信发生的区域,套接字的类型,套接字使用的特定协议) m_ServerSocket = socket(AF_INET, SOCK_STREAM, 0); if (m_ServerSocket == INVALID_SOCKET) { //_ChkWSACleanup(status); CLOG_ERROR("ERROR: socket unsuccessful\r\n"); return SocketResult_CreateFailed; } // associate the socket with the address status = bind(m_ServerSocket, (LPSOCKADDR)&serverSockAddr, sizeof(serverSockAddr)); if (status == SOCKET_ERROR) { //_ChkWSACleanup(status); CLOG_ERROR("ERROR: bind unsuccessful\r\n"); return SocketResult_CanotBind; } //FD_ISSET return SocketResult_Ok; }
SocketResult UDPSocket::OpenPort(PropertyFlags dwFlags, u32 port) { //WSADATA Data; m_dwFlags = dwFlags; ASSERT(net_sockets::IsStartup()); int status = 0; //int status = WSAStartup(CLMAKEWORD(1, 1), &Data); //if (status != 0) { // CLOG_ERROR("ERROR: WSAStartup unsuccessful\r\n"); //} m_Socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (m_Socket == INVALID_SOCKET) { //_ChkWSACleanup(status); CLOG_ERROR("ERROR: socket unsuccessful\r\n"); return SocketResult_CreateFailed; } if(TEST_FLAG(m_dwFlags, PM_Broadcast)) { char bOpt = true; status = setsockopt(m_Socket, SOL_SOCKET, SO_BROADCAST, &bOpt, sizeof(bOpt)); } if(TEST_FLAG(dwFlags, PM_Recv)) { SOCKADDR_IN RecvSockAddr; InlSetZeroT(RecvSockAddr); RecvSockAddr.sin_port = htons(port); RecvSockAddr.sin_family = AF_INET; RecvSockAddr.sin_addr.s_addr = htonl(INADDR_ANY); status = bind(m_Socket, (LPSOCKADDR)&RecvSockAddr, sizeof(RecvSockAddr)); if (status == SOCKET_ERROR) { //_ChkWSACleanup(status); CLOG_ERROR("ERROR: bind unsuccessful\r\n"); return SocketResult_CanotBind; } } return SocketResult_Ok; }
i32 UDPSocket::Send(IPAddr uIPAddress, u32 wPort, CLLPCVOID pData, u32 nLen) { if(TEST_FLAG_NOT(m_dwFlags, PM_Send)) { CLOG_ERROR("UDP Socket didn't has send flag."); return -1; } if(uIPAddress == BroadcastAddress && TEST_FLAG_NOT(m_dwFlags, PM_Broadcast)) { CLOG_ERROR("UDP Socket didn't has broadcast flag."); return -1; } sockaddr_in RecvAddr; RecvAddr.sin_family = AF_INET; RecvAddr.sin_port = htons((u_short)wPort); RecvAddr.sin_addr.s_addr = (unsigned long)uIPAddress; int result = sendto(m_Socket, (const char*)pData, nLen, 0, (SOCKADDR*) &RecvAddr, sizeof(RecvAddr)); return result; }
i32 TCPServer::StartRoutine() { int status; // allow the socket to take connections listen(已建立、尚未连接的套接字号,连接队列的最大长度) status = listen(m_ServerSocket, 1); if(status == SOCKET_ERROR) { CLOG_ERROR("ERROR: listen unsuccessful\r\n"); return (i32)SocketResult_CanotListen; } CLOG("Waiting for connection...\r\n"); MainLoop(); return 0; }
/* This function should be used for getting the appropriate type-info when only * a F-Curve modifier type is known */ const FModifierTypeInfo *get_fmodifier_typeinfo(const int type) { /* initialize the type-info list? */ if (FMI_INIT) { fmods_init_typeinfo(); FMI_INIT = 0; } /* only return for valid types */ if ((type >= FMODIFIER_TYPE_NULL) && (type < FMODIFIER_NUM_TYPES)) { /* there shouldn't be any segfaults here... */ return fmodifiersTypeInfo[type]; } else { CLOG_ERROR(&LOG, "No valid F-Curve Modifier type-info data available. Type = %i", type); } return NULL; }
GXBOOL SceneContext::LoadTextureFromFile(GXLPCWSTR szFilename, GTexture** ppTexture) { if(szFilename == NULL || clstd::strlenT(szFilename) == 0) return FALSE; GXGraphics* pGraphics = m_pMOScene->GetGraphicsUnsafe(); if(SUCCEEDED(pGraphics->CreateTextureFromFileW(ppTexture, szFilename))) { return TRUE; } clsize nPath = clpathfile::FindFileName(m_FileName); clsize nFile = clpathfile::FindFileName(szFilename); clStringW strFilename(m_FileName, nPath); strFilename += &szFilename[nFile]; if(FAILED(pGraphics->CreateTextureFromFileW(ppTexture, strFilename))) { CLOG_ERROR(__FUNCTION__": Can't load texture from:\"%s\" or \"%s\".\n", szFilename, strFilename); return FALSE; } return TRUE; }
/* Bake modifiers for given F-Curve to curve sample data, in the frame range defined * by start and end (inclusive). */ void fcurve_bake_modifiers(FCurve *fcu, int start, int end) { ChannelDriver *driver; /* sanity checks */ /* TODO: make these tests report errors using reports not CLOG's */ if (ELEM(NULL, fcu, fcu->modifiers.first)) { CLOG_ERROR(&LOG, "No F-Curve with F-Curve Modifiers to Bake"); return; } /* temporarily, disable driver while we sample, so that they don't influence the outcome */ driver = fcu->driver; fcu->driver = NULL; /* bake the modifiers, by sampling the curve at each frame */ fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve); /* free the modifiers now */ free_fmodifiers(&fcu->modifiers); /* restore driver */ fcu->driver = driver; }
int BKE_fcm_envelope_find_index(FCM_EnvelopeData array[], float frame, int arraylen, bool *r_exists) { int start = 0, end = arraylen; int loopbreaker = 0, maxloop = arraylen * 2; /* initialize exists-flag first */ *r_exists = false; /* sneaky optimizations (don't go through searching process if...): * - keyframe to be added is to be added out of current bounds * - keyframe to be added would replace one of the existing ones on bounds */ if ((arraylen <= 0) || (array == NULL)) { CLOG_WARN(&LOG, "encountered invalid array"); return 0; } else { /* check whether to add before/after/on */ float framenum; /* 'First' Point (when only one point, this case is used) */ framenum = array[0].time; if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) { *r_exists = true; return 0; } else if (frame < framenum) { return 0; } /* 'Last' Point */ framenum = array[(arraylen - 1)].time; if (IS_EQT(frame, framenum, BINARYSEARCH_FRAMEEQ_THRESH)) { *r_exists = true; return (arraylen - 1); } else if (frame > framenum) { return arraylen; } } /* most of the time, this loop is just to find where to put it * - 'loopbreaker' is just here to prevent infinite loops */ for (loopbreaker = 0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) { /* compute and get midpoint */ int mid = start + ((end - start) / 2); /* we calculate the midpoint this way to avoid int overflows... */ float midfra = array[mid].time; /* check if exactly equal to midpoint */ if (IS_EQT(frame, midfra, BINARYSEARCH_FRAMEEQ_THRESH)) { *r_exists = true; return mid; } /* repeat in upper/lower half */ if (frame > midfra) { start = mid + 1; } else if (frame < midfra) { end = mid - 1; } } /* print error if loop-limit exceeded */ if (loopbreaker == (maxloop - 1)) { CLOG_ERROR(&LOG, "binary search was taking too long"); // include debug info CLOG_ERROR(&LOG, "\tround = %d: start = %d, end = %d, arraylen = %d", loopbreaker, start, end, arraylen); } /* not found, so return where to place it */ return start; }
GXHWND GXDLLAPI gxCreateWindowExW(GXDWORD dwExStyle,GXLPCWSTR lpClassName,GXLPCWSTR lpWindowName,GXDWORD dwStyle, GXINT x,GXINT y,GXINT nWidth,GXINT nHeight,GXHWND hWndParent,GXHMENU hMenu,GXHINSTANCE hInstance,GXLPVOID lpParam) { GXWnd*pNewWnd; GXPOINT ptTopLeft; GXWNDCLASSEX WndClassEx; if(TEST_FLAG(dwStyle, GXWS_CHILD) && hWndParent == NULL) { // 这个判断是刚加的,防止之前写的有问题这里加个中断用来对以前的错误写法进行排查 CLBREAK; return NULL; } GXDWORD lpClsAtom = gxGetClassInfoExW(NULL, lpClassName, &WndClassEx); if(lpClsAtom == NULL) { ASSERT(FALSE); return NULL; } // 对于32位系统, 额外的储存空间等于cbWndExtra // 对于64位系统额外的储存空间是cbWndExtra的2倍, 这样保证储存空间里可以保存8字节的指针 const GXSIZE_T cbWndClassSize = sizeof(GXWnd) + WndClassEx.cbWndExtra * (sizeof(void*) / sizeof(GXDWORD)); // 创建窗口类和额外的数据储存空间 pNewWnd = new(new GXBYTE[cbWndClassSize]) GXWnd; if( ! pNewWnd) { CLOG_ERROR("%s : Out of memory.\n", __FUNCTION__); return NULL; } GXHWND hNewWnd = GXWND_HANDLE(pNewWnd); pNewWnd->m_hSelf = hNewWnd; GXMEMSET((GXLPBYTE)pNewWnd + sizeof(GXWnd), 0, cbWndClassSize - sizeof(GXWnd)); pNewWnd->m_lpWndProc = WndClassEx.lpfnWndProc; pNewWnd->m_uStyle = dwStyle; pNewWnd->m_uExStyle = dwExStyle; pNewWnd->m_uState = NULL; pNewWnd->m_lpClsAtom = (GXLPWNDCLSATOM)(GXDWORD_PTR)lpClsAtom; pNewWnd->m_lpClsAtom->nRefCount++; GXLPSTATION lpStation = GXLPWND_STATION_PTR(pNewWnd); GXDWORD dwThreadId = gxGetCurrentThreadId(); if(lpStation->dwUIThreadId == NULL) { CLOG_WARNING("%s : User doesn't set UI thread Id, set to default.\n" "Call GXUIMakeCurrent() first in UI message processing thread.\n", __FUNCTION__); lpStation->dwUIThreadId = dwThreadId; } else if(lpStation->dwUIThreadId != dwThreadId) { CLOG_ERROR("%s : GXUI can not create window out of UI thread.\n", __FUNCTION__); CLBREAK; delete pNewWnd; return NULL; } lpStation->Enter(); // 设置父窗体 ptTopLeft.x = x; ptTopLeft.y = y; pNewWnd->SetParent(hWndParent); if(hWndParent != NULL) { GXWND_PTR(hWndParent)->ClientToScreen(&ptTopLeft, 1); } // 设置 Wnd 尺寸 pNewWnd->rectWindow.left = ptTopLeft.x; pNewWnd->rectWindow.top = ptTopLeft.y; pNewWnd->rectWindow.right = ptTopLeft.x + nWidth; pNewWnd->rectWindow.bottom = ptTopLeft.y + nHeight; if(lpWindowName != NULL) { // Win32 在窗口创建时是不发送WM_SETTEXT消息的, 这里直接设置 DEFWNDPROC_SetText(hNewWnd, lpWindowName); //gxSendMessage(hNewWnd, GXWM_SETTEXT, NULL, (GXLPARAM)lpWindowName); } //if(hWndParent == NULL) //{ // //ASSERT(IS_IDENTIFY(hMenu)); // //TODO: 这里有内存泄露,但是由于WineMenu采用了gxHeapAlloc分配内存,因此无法检测 // //pNewWnd->m_pMenu = gxLoadMenuW(hInstance, (GXLPCWSTR)hMenu); // pNewWnd->m_pMenu = hMenu; //} //else //{ // //ASSERT(hMenu != NULL && dwStyle & WS_CHILD); // pNewWnd->m_pMenu = hMenu; //} if(TEST_FLAG(dwStyle, GXWS_CHILD) && ! IS_IDENTIFY(hMenu)) { new (&pNewWnd->m_pMenu) clStringW((GXLPCWSTR)hMenu); } else { pNewWnd->m_pMenu = hMenu; } // FIXME: WS_CHILD模式下, 字符串形式的Control Id应该单独分配内存保存, 不应该直接引用指针. if(IntSendCreateMessage(hNewWnd, hWndParent, lpClassName, dwExStyle, dwStyle, x, y, nWidth, nHeight, hMenu, lpParam) == FALSE) { ASSERT(0); // 创建控件初始化失败 gxDestroyWindow(hNewWnd); lpStation->Leave(); return NULL; } // WM_SIZE Message { GXRECT rcClient; gxGetClientRect(hNewWnd, &rcClient); gxSendMessage(hNewWnd, GXWM_SIZE, GXSIZE_RESTORED, GXMAKELPARAM(rcClient.right, rcClient.bottom)); } //lpStation->m_pDesktopWindowsMgr->ManageWindowSurface(hNewWnd, GXWM_CREATE); if((dwStyle & GXWS_VISIBLE) != NULL) { gxShowWindow(hNewWnd, GXSW_SHOWNORMAL); } lpStation->Leave(); return hNewWnd; }
/* This is a Mesh-based copy of DM_to_mesh() */ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, const CustomData_MeshMasks *mask, bool take_ownership) { /* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */ /* TODO(Sybren): the above claim came from DM_to_mesh(); * check whether it is still true with Mesh */ Mesh tmp = *mesh_dst; int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; int did_shapekeys = 0; eCDAllocType alloctype = CD_DUPLICATE; if (take_ownership /* && dm->type == DM_TYPE_CDDM && dm->needsFree */) { bool has_any_referenced_layers = CustomData_has_referenced(&mesh_src->vdata) || CustomData_has_referenced(&mesh_src->edata) || CustomData_has_referenced(&mesh_src->ldata) || CustomData_has_referenced(&mesh_src->fdata) || CustomData_has_referenced(&mesh_src->pdata); if (!has_any_referenced_layers) { alloctype = CD_ASSIGN; } } CustomData_reset(&tmp.vdata); CustomData_reset(&tmp.edata); CustomData_reset(&tmp.fdata); CustomData_reset(&tmp.ldata); CustomData_reset(&tmp.pdata); BKE_mesh_ensure_normals(mesh_src); totvert = tmp.totvert = mesh_src->totvert; totedge = tmp.totedge = mesh_src->totedge; totloop = tmp.totloop = mesh_src->totloop; totpoly = tmp.totpoly = mesh_src->totpoly; tmp.totface = 0; CustomData_copy(&mesh_src->vdata, &tmp.vdata, mask->vmask, alloctype, totvert); CustomData_copy(&mesh_src->edata, &tmp.edata, mask->emask, alloctype, totedge); CustomData_copy(&mesh_src->ldata, &tmp.ldata, mask->lmask, alloctype, totloop); CustomData_copy(&mesh_src->pdata, &tmp.pdata, mask->pmask, alloctype, totpoly); tmp.cd_flag = mesh_src->cd_flag; tmp.runtime.deformed_only = mesh_src->runtime.deformed_only; if (CustomData_has_layer(&mesh_src->vdata, CD_SHAPEKEY)) { KeyBlock *kb; int uid; if (ob) { kb = BLI_findlink(&mesh_dst->key->block, ob->shapenr - 1); if (kb) { uid = kb->uid; } else { CLOG_ERROR(&LOG, "could not find active shapekey %d!", ob->shapenr - 1); uid = INT_MAX; } } else { /* if no object, set to INT_MAX so we don't mess up any shapekey layers */ uid = INT_MAX; } shapekey_layers_to_keyblocks(mesh_src, mesh_dst, uid); did_shapekeys = 1; } /* copy texture space */ if (ob) { BKE_mesh_texspace_copy_from_object(&tmp, ob); } /* not all DerivedMeshes store their verts/edges/faces in CustomData, so * we set them here in case they are missing */ /* TODO(Sybren): we could probably replace CD_ASSIGN with alloctype and * always directly pass mesh_src->mxxx, instead of using a ternary operator. */ if (!CustomData_has_layer(&tmp.vdata, CD_MVERT)) { CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN, (alloctype == CD_ASSIGN) ? mesh_src->mvert : MEM_dupallocN(mesh_src->mvert), totvert); } if (!CustomData_has_layer(&tmp.edata, CD_MEDGE)) { CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, (alloctype == CD_ASSIGN) ? mesh_src->medge : MEM_dupallocN(mesh_src->medge), totedge); } if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) { /* TODO(Sybren): assignment to tmp.mxxx is probably not necessary due to the * BKE_mesh_update_customdata_pointers() call below. */ tmp.mloop = (alloctype == CD_ASSIGN) ? mesh_src->mloop : MEM_dupallocN(mesh_src->mloop); tmp.mpoly = (alloctype == CD_ASSIGN) ? mesh_src->mpoly : MEM_dupallocN(mesh_src->mpoly); CustomData_add_layer(&tmp.ldata, CD_MLOOP, CD_ASSIGN, tmp.mloop, tmp.totloop); CustomData_add_layer(&tmp.pdata, CD_MPOLY, CD_ASSIGN, tmp.mpoly, tmp.totpoly); } /* object had got displacement layer, should copy this layer to save sculpted data */ /* NOTE: maybe some other layers should be copied? nazgul */ if (CustomData_has_layer(&mesh_dst->ldata, CD_MDISPS)) { if (totloop == mesh_dst->totloop) { MDisps *mdisps = CustomData_get_layer(&mesh_dst->ldata, CD_MDISPS); CustomData_add_layer(&tmp.ldata, CD_MDISPS, alloctype, mdisps, totloop); } } /* yes, must be before _and_ after tessellate */ BKE_mesh_update_customdata_pointers(&tmp, false); /* since 2.65 caller must do! */ // BKE_mesh_tessface_calc(&tmp); CustomData_free(&mesh_dst->vdata, mesh_dst->totvert); CustomData_free(&mesh_dst->edata, mesh_dst->totedge); CustomData_free(&mesh_dst->fdata, mesh_dst->totface); CustomData_free(&mesh_dst->ldata, mesh_dst->totloop); CustomData_free(&mesh_dst->pdata, mesh_dst->totpoly); /* ok, this should now use new CD shapekey data, * which should be fed through the modifier * stack */ if (tmp.totvert != mesh_dst->totvert && !did_shapekeys && mesh_dst->key) { CLOG_ERROR(&LOG, "YEEK! this should be recoded! Shape key loss!: ID '%s'", tmp.id.name); if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) { id_us_min(&tmp.key->id); } tmp.key = NULL; } /* Clear selection history */ MEM_SAFE_FREE(tmp.mselect); tmp.totselect = 0; BLI_assert(ELEM(tmp.bb, NULL, mesh_dst->bb)); if (mesh_dst->bb) { MEM_freeN(mesh_dst->bb); tmp.bb = NULL; } /* skip the listbase */ MEMCPY_STRUCT_AFTER(mesh_dst, &tmp, id.prev); if (take_ownership) { if (alloctype == CD_ASSIGN) { CustomData_free_typemask(&mesh_src->vdata, mesh_src->totvert, ~mask->vmask); CustomData_free_typemask(&mesh_src->edata, mesh_src->totedge, ~mask->emask); CustomData_free_typemask(&mesh_src->ldata, mesh_src->totloop, ~mask->lmask); CustomData_free_typemask(&mesh_src->pdata, mesh_src->totpoly, ~mask->pmask); } BKE_id_free(NULL, mesh_src); } }
static void fcm_fn_generator_evaluate( FCurve *UNUSED(fcu), FModifier *fcm, float *cvalue, float evaltime, void *UNUSED(storage)) { FMod_FunctionGenerator *data = (FMod_FunctionGenerator *)fcm->data; double arg = data->phase_multiplier * evaltime + data->phase_offset; double (*fn)(double v) = NULL; /* get function pointer to the func to use: * WARNING: must perform special argument validation hereto guard against crashes */ switch (data->type) { /* simple ones */ case FCM_GENERATOR_FN_SIN: /* sine wave */ fn = sin; break; case FCM_GENERATOR_FN_COS: /* cosine wave */ fn = cos; break; case FCM_GENERATOR_FN_SINC: /* normalized sine wave */ fn = sinc; break; /* validation required */ case FCM_GENERATOR_FN_TAN: /* tangent wave */ { /* check that argument is not on one of the discontinuities (i.e. 90deg, 270 deg, etc) */ if (IS_EQ(fmod((arg - M_PI_2), M_PI), 0.0)) { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) { *cvalue = 0.0f; /* no value possible here */ } } else { fn = tan; } break; } case FCM_GENERATOR_FN_LN: /* natural log */ { /* check that value is greater than 1? */ if (arg > 1.0) { fn = log; } else { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) { *cvalue = 0.0f; /* no value possible here */ } } break; } case FCM_GENERATOR_FN_SQRT: /* square root */ { /* no negative numbers */ if (arg > 0.0) { fn = sqrt; } else { if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) { *cvalue = 0.0f; /* no value possible here */ } } break; } default: CLOG_ERROR(&LOG, "Invalid Function-Generator for F-Modifier - %d", data->type); break; } /* execute function callback to set value if appropriate */ if (fn) { float value = (float)(data->amplitude * (float)fn(arg) + data->value_offset); if (data->flag & FCM_GENERATOR_ADDITIVE) { *cvalue += value; } else { *cvalue = value; } } }
int TCPServer::MainLoop() { fd_set ReadSet; fd_set ExceptSet; int result = 0; while(1) { FD_ZERO(&ReadSet); FD_SET(m_ServerSocket, &ReadSet); FD_ZERO(&ExceptSet); FD_SET(m_ServerSocket, &ExceptSet); ASSERT(m_ClientList.size() < FD_SETSIZE - 1); // ServerSocket 要占用一个 for(SocketList::iterator it = m_ClientList.begin(); it != m_ClientList.end(); ++it) { ASSERT(*it != NULL); FD_SET(*it, &ReadSet); FD_SET(*it, &ExceptSet); } result = select(0, &ReadSet, 0, &ExceptSet, 0); if(result == 0) { // Time Out ASSERT(ExceptSet.fd_count == 0); } else if(result == SOCKET_ERROR) { if(FD_ISSET(m_ServerSocket, &ReadSet)) { break; } CLBREAK; } else if(result != 0) { ASSERT(ExceptSet.fd_count == 0); if(FD_ISSET(m_ServerSocket, &ReadSet)) { SOCKADDR_IN clientSockAddr; int addrLen = sizeof(SOCKADDR_IN); // accept the connection request when one is received SOCKET client = accept(m_ServerSocket, (LPSOCKADDR)&clientSockAddr, &addrLen); if(client != INVALID_SOCKET) { if(m_ClientList.size() < FD_SETSIZE - 1) { CLOG("Got the connection(%d)...\r\n", client); OnEvent(client, SE_ACCEPT); m_ClientList.push_back(client); } else { ::closesocket(client); } } } for(SocketList::iterator it = m_ClientList.begin(); it != m_ClientList.end();) { if(FD_ISSET(*it, &ReadSet)) { u32 dwPeek; result = recv(*it, (char*)&dwPeek, sizeof(u32), MSG_PEEK); if(result == 0) // 端口已经关闭 { // 这种方式下 // 如果客户端在Debug下出现断点并关闭,这里会无法收到close消息 OnEvent(*it, SE_CLOSE); result = ::closesocket(*it); CLOG("Close socket(%d).\r\n", *it); it = m_ClientList.erase(it); continue; } else { OnEvent(*it, SE_READ); } } ++it; } // for } } // 退出时清理客户端端口 for(SocketList::iterator it = m_ClientList.begin(); it != m_ClientList.end(); ++it) { result = closesocket(*it); if(result == SOCKET_ERROR) { CLOG_ERROR("Error for closing socket(%d)...\r\n", *it); } } m_ClientList.clear(); return result; }