/** * htmlNodeDumpFormat: * @buf: the HTML buffer output * @doc: the document * @cur: the current node * @format: should formatting spaces been added * * Dump an HTML node, recursive behaviour,children are printed too. * * Returns the number of byte written or -1 in case of error */ static int htmlNodeDumpFormat(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int format) { unsigned int use; int ret; xmlOutputBufferPtr outbuf; if (cur == KD_NULL) { return (-1); } if (buf == KD_NULL) { return (-1); } outbuf = (xmlOutputBufferPtr) xmlMalloc(sizeof(xmlOutputBuffer)); if (outbuf == KD_NULL) { htmlSaveErrMemory("allocating HTML output buffer"); return (-1); } kdMemset ( outbuf, 0, sizeof(xmlOutputBuffer) ); outbuf->buffer = buf; outbuf->encoder = KD_NULL; outbuf->writecallback = KD_NULL; outbuf->closecallback = KD_NULL; outbuf->context = KD_NULL; outbuf->written = 0; use = buf->use; htmlNodeDumpFormatOutput(outbuf, doc, cur, KD_NULL, format); xmlFree(outbuf); ret = buf->use - use; return (ret); }
NS_CC_BEGIN CCAccelerometer::CCAccelerometer ( KDvoid ) { m_pAccelDelegate = KD_NULL; kdMemset ( &m_tAccelerationValue, 0, sizeof ( m_tAccelerationValue ) ); }
void mtx4_identity(float* dm) { if(!dm){ return; } kdMemset(dm, 0, (sizeof(float)*16)); dm[0] = dm[5] = dm[10] = dm[15] = 1.0f; }
KDvoid CCTextureAtlas::fillWithEmptyQuadsFromIndex ( KDuint uIndex, KDuint uAmount ) { ccV3F_C4B_T2F_Quad tQuad; kdMemset ( &tQuad, 0, sizeof ( tQuad ) ); KDuint uTo = uIndex + uAmount; for ( KDuint i = uIndex; i < uTo ; i++ ) { m_pQuads [ i ] = tQuad; } }
KDvoid CCTextureAtlas::setupVBO ( KDvoid ) { if ( m_pBuffersVBO[0] ) { glDeleteBuffers ( 2, &m_pBuffersVBO[0] ); kdMemset ( m_pBuffersVBO, 0, sizeof ( m_pBuffersVBO ) ); } glGenBuffers ( 2, &m_pBuffersVBO[0] ); mapBuffers ( ); }
std::string CWin32InputBox::AnsiToUtf8(std::string strAnsi) { std::string ret; if (strAnsi.length() > 0) { int nWideStrLength = MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, NULL, 0); WCHAR* pwszBuf = (WCHAR*)malloc((nWideStrLength+1)*sizeof(WCHAR)); kdMemset(pwszBuf, 0, (nWideStrLength+1)*sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, strAnsi.c_str(), -1, pwszBuf, (nWideStrLength+1)*sizeof(WCHAR)); int nUtf8Length = WideCharToMultiByte( CP_UTF8,0,pwszBuf,-1,NULL,0,NULL,FALSE ); char* pszUtf8Buf = (char*)malloc((nUtf8Length+1)*sizeof(char)); kdMemset(pszUtf8Buf, 0, (nUtf8Length+1)*sizeof(char)); WideCharToMultiByte(CP_UTF8, 0, pwszBuf, -1, pszUtf8Buf, (nUtf8Length+1)*sizeof(char), NULL, FALSE); ret = pszUtf8Buf; free(pszUtf8Buf); free(pwszBuf); } return ret; }
// Message handler for about box. LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLong(hDlg, GWL_USERDATA); WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : 0; switch (message) { case WM_INITDIALOG: { ::SetWindowLong(hDlg, GWL_USERDATA, (LONG) lParam); _this = (CWin32InputBox *) lParam; _this->_param->hDlg = hDlg; _this->InitDialog(); return TRUE; } case WM_COMMAND: { #ifdef _MY_DEBUG CHAR buf[1024]; static int i=0; sprintf(buf, "WM_COMMAND: %09d wParam=%08X lParam=%08X\n", i++, wParam, lParam); OutputDebugString(buf); #endif INT_PTR buttonId = LOWORD(wParam); for (size_t i=0; i<sizeof(definputbox_buttonids)/sizeof(definputbox_buttonids[0]); i++) { if (buttonId == definputbox_buttonids[i]) { ::GetWindowTextA( _this->_hwndEditCtrl, _this->_param->szResult, _this->_param->nResultSize); std::string strUtf8 = AnsiToUtf8(_this->_param->szResult); kdMemset(_this->_param->szResult, 0, _this->_param->nResultSize); strncpy(_this->_param->szResult, strUtf8.c_str(), _this->_param->nResultSize-1); ::EndDialog(hDlg, buttonId); return TRUE; } } } break; } return FALSE; }
b2DynamicTree::b2DynamicTree() { m_root = b2_nullNode; m_nodeCapacity = 16; m_nodeCount = 0; m_nodes = (b2TreeNode*)b2Alloc(m_nodeCapacity * sizeof(b2TreeNode)); kdMemset(m_nodes, 0, m_nodeCapacity * sizeof(b2TreeNode)); // Build a linked list for the free list. for (int32 i = 0; i < m_nodeCapacity - 1; ++i) { m_nodes[i].next = i + 1; m_nodes[i].height = -1; } m_nodes[m_nodeCapacity-1].next = b2_nullNode; m_nodes[m_nodeCapacity-1].height = -1; m_freeList = 0; m_path = 0; m_insertionCount = 0; }
KDvoid M3GVertexArray::init ( KDint numVertices, KDint numComponents, KDint componentSize ) { if ( numVertices < 1 || numVertices > 65535 ) { M3GException ( "IllegalArgumentException", __FUNCTION__ , "Vertex count is invalid, numVertices = %d.", numVertices ); } if ( numComponents < 2 || numComponents > 4 ) { M3GException ( "IllegalArgumentException", __FUNCTION__ , "Component count is invalid, numComponents = %d.", numComponents ); } if ( componentSize != 1 && componentSize != 2 && componentSize != 4 ) { M3GException ( "IllegalArgumentException", __FUNCTION__ , "Component size is invalid, componentSize = %d.", componentSize ); } KDsize nSize = numVertices * numComponents * componentSize; m_nVertexCount = numVertices; m_nComponentCount = numComponents; m_nComponentSize = componentSize; m_pValues8 = new KDubyte [ nSize ]; kdMemset ( m_pValues8, 0, nSize ); glGenBuffers ( 1, &m_uID ); glBindBuffer ( GL_ARRAY_BUFFER, m_uID ); glBufferData ( GL_ARRAY_BUFFER, nSize, 0, GL_STATIC_DRAW ); GLenum nErr = glGetError ( ); if ( nErr != GL_NO_ERROR ) { M3GException ( "OpenGLException", __FUNCTION__ , "Can't make vertex buffer object, err = %d", nErr ); } }
KDvoid M3GImage2D::init ( KDint format, KDint width, KDint height, KDubyte* pixels, KDubyte* palette ) { m_nFormat = format; m_nWidth = width; m_nHeight = height; KDint nBpp = m3gGetBpp ( format ); KDint nLength = height * width * nBpp; m_pImage = new KDubyte [ nLength ]; if ( pixels ) { m_bImmutable = KD_TRUE; if ( palette ) { for ( KDint y = 0; y < height; y++ ) { for ( KDint x = 0; x < width; x++ ) { KDint nIndex = pixels [ y * width + x ]; kdMemcpy ( m_pImage + ( y * width + x ) * nBpp, (KDubyte*) palette + nIndex * nBpp, nBpp ); } } } else { kdMemcpy ( m_pImage, pixels, nLength ); } } else { kdMemset ( m_pImage, 0, nLength ); } }
// TextureAtlas - Resize KDbool CCTextureAtlas::resizeCapacity ( KDuint uNewCapacity ) { if ( uNewCapacity == m_uCapacity ) { return KD_TRUE; } KDuint uOldCapacity = m_uCapacity; // update capacity and totolQuads m_uTotalQuads = KD_MIN ( m_uTotalQuads, uNewCapacity ); m_uCapacity = uNewCapacity; ccV3F_C4B_T2F_Quad* pTempQuads = KD_NULL; GLushort* pTempIndices = KD_NULL; // when calling initWithTexture(fileName, 0) on bada device, calloc(0, 1) will fail and return NULL, // so here must judge whether m_pQuads and m_pIndices is NULL. if ( m_pQuads == KD_NULL ) { pTempQuads = (ccV3F_C4B_T2F_Quad*) kdCalloc ( 1, m_uCapacity * sizeof ( m_pQuads[0] ) ); } else { pTempQuads = (ccV3F_C4B_T2F_Quad*) kdRealloc ( m_pQuads, sizeof ( m_pQuads[0] ) * m_uCapacity ); if ( pTempQuads != KD_NULL && m_uCapacity > uOldCapacity ) { kdMemset ( pTempQuads + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * sizeof ( m_pQuads[0] ) ); } } if ( m_pIndices == KD_NULL ) { pTempIndices = (GLushort*) kdCalloc ( 1, m_uCapacity * 6 * sizeof ( m_pIndices[0] ) ); } else { pTempIndices = (GLushort*) kdRealloc ( m_pIndices, sizeof ( m_pIndices[0] ) * m_uCapacity * 6 ); if ( pTempIndices != KD_NULL && m_uCapacity > uOldCapacity ) { kdMemset ( pTempIndices + uOldCapacity, 0, ( m_uCapacity - uOldCapacity ) * 6 * sizeof ( m_pIndices[0] ) ); } } if ( !( pTempQuads && pTempIndices ) ) { CCLOG ( "XMCocos2D : CCTextureAtlas - not enough memory"); CC_SAFE_FREE ( pTempQuads ); CC_SAFE_FREE ( pTempIndices ); CC_SAFE_FREE ( m_pQuads ); CC_SAFE_FREE ( m_pIndices ); m_uCapacity = m_uTotalQuads = 0; return KD_FALSE; } m_pQuads = pTempQuads; m_pIndices = pTempIndices; setupIndices ( ); mapBuffers ( ); m_bDirty = KD_TRUE; return KD_TRUE; }
/** * xmlMemFree: * @ptr: the memory block pointer * * a kdFree() equivalent, with error checking. */ void xmlMemFree(void *ptr) { MEMHDR *p; char *target; #ifdef DEBUG_MEMORY KDsize size; #endif if (ptr == KD_NULL) return; if (ptr == (void *) -1) { xmlGenericError(xmlGenericErrorContext, "trying to kdFree pointer from kdFreed area\n"); goto error; } if (xmlMemTraceBlockAt == ptr) { xmlGenericError(xmlGenericErrorContext, "%p : Freed()\n", xmlMemTraceBlockAt); xmlMallocBreakpoint(); } TEST_POINT target = (char *) ptr; p = CLIENT_2_HDR(ptr); if (p->mh_tag != MEMTAG) { Mem_Tag_Err(p); goto error; } if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint(); p->mh_tag = ~MEMTAG; kdMemset(target, -1, p->mh_size); xmlMutexLock(xmlMemMutex); debugMemSize -= p->mh_size; debugMemBlocks--; #ifdef DEBUG_MEMORY size = p->mh_size; #endif #ifdef MEM_LIST debugmem_list_delete(p); #endif xmlMutexUnlock(xmlMemMutex); kdFree(p); TEST_POINT #ifdef DEBUG_MEMORY xmlGenericError(xmlGenericErrorContext, "Freed(%d) Ok\n", size); #endif return; error: xmlGenericError(xmlGenericErrorContext, "xmlMemFree(%lX) error\n", (unsigned long) ptr); xmlMallocBreakpoint(); return; }
KDint M3GMorphingMesh::animate ( KDint time ) { M3GMesh::animate ( time ); KDbool isWeightsModefied = KD_FALSE; KDfloat* fWeights = new KDfloat [ m_vMorphWeights.size ( ) ]; kdMemset ( fWeights, 0, sizeof ( KDfloat ) * m_vMorphWeights.size ( ) ); for ( KDint i = 0; i < getAnimationTrackCount ( ); i++ ) { M3GAnimationTrack* pTrack = getAnimationTrack ( i ); M3GKeyframeSequence* pKeyframe = pTrack->getKeyframeSequence ( ); M3GAnimationController* pController = pTrack->getController ( ); if ( !pController || !pController->isActive ( time ) ) { continue; } KDfloat fWeight = pController->getWeight ( ); KDfloat fSequence = pController->getPosition ( time ); switch ( pTrack->getTargetProperty ( ) ) { case M3GAnimationTrack::MORPH_WEIGHTS : { KDint nNumber = KD_MAX ( (KDint) m_vMorphWeights.size ( ), pKeyframe->getComponentCount ( ) ); KDfloat* fValue = new KDfloat [ nNumber ]; kdMemset ( fValue, 0, sizeof ( KDfloat ) * nNumber ); pKeyframe->sample ( (KDint) fSequence, fValue ); for ( KDuint i = 0; i < m_vMorphWeights.size ( ); i++ ) { fWeights [i] += fValue [i] * fWeight; } isWeightsModefied = KD_TRUE; delete [] fValue; break; } default : { // Unknown target should be ignored. // animate() of Base class handle it. } } } if ( isWeightsModefied ) { for ( KDuint i = 0; i < m_vMorphWeights.size ( ); i++ ) { m_vMorphWeights [ i ] = fWeights [ i ]; } updateMorphedVertices ( ); } delete [] fWeights; return 0; }