Ejemplo n.º 1
0
bool CKLBSplineNode::setParamCount(u8 splineCount, u8 maxKeyCount) {
	m_uiTotalTime	= 0;
	m_uiMaxKeyCount	= maxKeyCount;

	stop();
	cleanSplines();

	m_allKeys		= KLBNEWA(s32, maxKeyCount * splineCount * 4 * sizeof(s32));	// Time, Left, Right, Value
	m_target		= KLBNEWA(u8 , splineCount);
	m_splinesKeyCount= KLBNEWA(u32 , splineCount);
	m_splines		= KLBNEWA(s32* , splineCount);
//	m_splineLocalTime= KLBNEWA(s32 , splineCount);
	m_splineLastKey	= KLBNEWA(u16, splineCount);

	if (m_allKeys	&& m_target 
					&& m_splinesKeyCount 
					&& m_splines 
					// && m_splineLocalTime 
					&& m_splineLastKey) {
		m_uiSplineCount	= splineCount;

		for (int n = 0; n < splineCount; n++) {
			m_splinesKeyCount[n]	= 0;
			m_splines[n]			= &m_allKeys[n * maxKeyCount * 4];
			m_target[n]				= 0;
			// m_splineLocalTime[n]	= 0;
			m_splineLastKey[n]		= 0;
		}

		return true;
	} else {
		return false;
	}
}
Ejemplo n.º 2
0
// ベクトル配列にマトリクスをかける
int
CKLBLuaLibMatrix::luaMulMatVecArray(lua_State * L)
{
	CLuaState lua(L);
	int nums;
	MATRIX * mat = getMatPointer(lua, 1);
	if(!mat) {
		lua.retNil();
		return 1;
	}
	VECTOR * arrVec;
	VECTOR * retVec;

	// Luaのvector配列要素数を取得
	lua.retValue(2);
	nums = getVectorNums(lua);

	// 取得した数だけの要素を持つvector配列を、
	// 取得用と結果用の二つ作る。
	arrVec = KLBNEWA(VECTOR, nums);
	retVec = KLBNEWA(VECTOR, nums);

	// 取得用の側に、vector配列の内容を取得する
	getVectorArray(lua, arrVec, nums);
	lua.pop(1);

	// 取得したvector群にマトリクスをかける
	mulMatVecArray(nums, retVec, arrVec, mat);

	// 計算結果のベクトル配列をLuaテーブルに変換し、Luaスタックに積む
	setVectorArray(lua, retVec, nums);

	// バッファはもう用済み
	KLBDELETEA(retVec);
	KLBDELETEA(arrVec);

	// 積んだベクトル配列を戻り値とする。
	return 1;
}
Ejemplo n.º 3
0
// TODO C# - check this method.
bool 
CKLBUIMultiImgItem::changeAssets(const char** pArrayAsset, u32* pArrayIndexes, u32 assetCount)
{
	getNode()->setRender(NULL,0);
	CKLBRenderingManager& rdr = CKLBRenderingManager::getInstance();
	for(u32 i = 0; i < m_cntImg; i++) {
		CKLBDataHandler::releaseHandle(m_items[i].handle);
		rdr.releaseCommand(m_items[i].sprite);
	}
	KLBDELETEA(m_items);

	u32 max = 0;
	for(u32 idx = 0; idx < assetCount; idx++) {
		u32 idxImg = pArrayIndexes[idx];
		if (max < idxImg) max = idxImg;
	}
	
	max++;

	IMGITEM* items = KLBNEWA(IMGITEM, max);
	if(!items) { return false; }

	// Reset all handle to 0
	for(u32 idx = 0; idx < max; idx++) {
		items[idx].handle = 0;
		items[idx].sprite = NULL;
	}

	for(u32 i=0; i < assetCount; i++) {
		const char* name = pArrayAsset[i];
		u32 idxImg = pArrayIndexes[i];
		u32 handle;
		CKLBAsset * pAsset = CKLBUtility::loadAsset(name, &handle, NULL);
		if (pAsset->getAssetType() == ASSET_IMAGE) {
			CKLBSprite*	pRender	= rdr.allocateCommandSprite((CKLBImageAsset*)pAsset,m_order);

			items[idxImg].handle = handle;
			items[idxImg].sprite = pRender;
		}
	}

	m_cntImg    = max;
	m_items     = items;
	m_idxMax    = m_cntImg - 1;	// 最大index値を追加する

	REFRESH_A;
	REFRESH_B;

	return true;
}
Ejemplo n.º 4
0
bool CKLBUIMultiImgItem::init(CKLBUITask* pParent, CKLBNode* pNode, u32 order, float x, float y, u32 idx, const char** pArrayAsset, u32* pArrayIndexes, u32 assetCount) {
	if(!setupNode()) return false;

	//
	// Create array and load resources.
	//
	u32 max = 0;
	for(u32 i = 0; i < assetCount; i++) {
		u32 idxImg = pArrayIndexes[i];
        if(max < idxImg) { max = idxImg; }
	}
	
	max++;

	IMGITEM* items = KLBNEWA(IMGITEM, max);
	if(!items) { return false; }

	// Reset all handle to NULL
	for(u32 i=0; i < max; i++) {
		items[i].handle	= 0;
		items[i].sprite = NULL;
	}

	CKLBRenderingManager& rdr = CKLBRenderingManager::getInstance();
	for(u32 i = 0; i < assetCount; i++) {
		const char* name = pArrayAsset[i];
		u32 idxImg = pArrayIndexes[i];
		u32 handle;
		CKLBAsset * pAsset = CKLBUtility::loadAsset(name, &handle, NULL);
		if(pAsset->getAssetType() == ASSET_IMAGE) {
			CKLBSprite*	pRender	= rdr.allocateCommandSprite((CKLBImageAsset*)pAsset,order);

			items[idxImg].handle = handle;
			items[idxImg].sprite = pRender;
		}
	}

	bool bResult = initCore(order,x,y,idx,items,max);
	bResult = registUI(pParent, bResult);
	if(pNode) {
		pParent->getNode()->removeNode(getNode());
		pNode->addNode(getNode());
	}
	return bResult;
}
Ejemplo n.º 5
0
bool JSonDB::allocateRecord	() {
	if (m_record != 0) {
		RecordListHeader* pRecord = (RecordListHeader*)KLBNEWA(u8, sizeof(RecordListHeader) + 4 + (m_recordEntry * sizeof(Field)));
		if (pRecord) {
			// Init new record.
			pRecord->pNextRecord	= NULL;
			pRecord->fields			= (Field*)&pRecord[1];	// Trick : use field after record header in memory.

			// Connect to link list and go to next element.
			m_currRecord->pNextRecord	= pRecord;
			m_currRecord				= pRecord;
		} else {
			return false;
		}
	} else {
		m_currRecord = &m_baseRecordHeader;
	}
	return true;
}
Ejemplo n.º 6
0
bool
CKLBUIMultiImgItem::initUI(CLuaState& lua)
{
	int argc = lua.numArgs();
	if(argc < ARG_REQUIRE || argc > ARG_NUMS) return false;

	float x     = lua.getFloat(ARG_X);
	float y     = lua.getFloat(ARG_Y);
	u32 order   = lua.getInt(ARG_ORDER);
	u32 idxImg  = (argc >= ARG_INDEX) ? lua.getInt(ARG_INDEX) : 0;
	
	// asset list を取得
	lua.retValue(ARG_ASSET_LIST);

	// 要素の数を数える
	int max = 0;
	lua.retNil();

	// Read indexes and count entries.
	while(lua.tableNext()) {
		lua.retValue(-2);
		int idx = lua.getInt(-1);
		if(max < idx) max = idx;
		lua.pop(2);
	}

	IMGITEM* items = KLBNEWA(IMGITEM, max);

    if(!items) { return false; }

	// Reset all handle to NULL
	for(int idx = 0; idx < max; idx++) {
		items[idx].handle = 0;
		items[idx].sprite = NULL;
	}

	m_order = order; // Needed for getImgList
    if(!getImgList(lua,items,max)) { return false; }
	return initCore(order, x,y,idxImg,items,max);
}
// Shaders.
CShader*	CKLBOGLWrapper::createShader		(const char* source, SHADER_TYPE type, const SParam* listParam) {
    CShader* pNewShader = KLBNEW(CShader);
    if (pNewShader) {
        GLuint shaderID = dglCreateShader(type == VERTEX_SHADER ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
        if (shaderID != 0) {
            GLint compiled;

            dglShaderSource(shaderID, 1, &source, null);
            // Compile the shader
            dglCompileShader(shaderID);
            // Check the compile status
            dglGetShaderiv(shaderID, GL_COMPILE_STATUS, &compiled);

            if (compiled) {
                //
                // Parse the list of parameters
                //
                const SParam* parser = listParam;

                bool type;

                if (parser) {
                    s32 uniCount = 0;
                    s32 verCount = 0;
                    while (parser->dType != END_LIST) {
                        if (parser->isUniform) {
                            uniCount++;
                        } else {
                            verCount++;
                        }
                        if (parser->dType & TEXTURE) {
                            pNewShader->enableTexture = true;
                        }
                        if (parser->dType & COLOR) {
                            pNewShader->enableColor = true;
                        }
                        parser++;
                    }

                    pNewShader->countUniform		= uniCount;
                    pNewShader->countStreamInfo		= verCount;

                    pNewShader->arrayParam			= KLBNEWA(CShader::SInternalParam,uniCount + verCount);

                    if (pNewShader->arrayParam) {
                        CShader::SInternalParam* pUniParam = pNewShader->arrayParam;
                        CShader::SInternalParam* pVerParam = &pNewShader->arrayParam[uniCount];
                        parser = listParam;

                        while (parser->dType != END_LIST) {
                            if (parser->isUniform) {
                                pUniParam->param = *parser++;
                                pUniParam++;
                            } else {
                                pVerParam->param = *parser++;
                                pVerParam++;
                            }
                        }

                    }

                    type							= true;
                } else {
                    pNewShader->countUniform		= 0;
                    pNewShader->countStreamInfo		= 0;
                    pNewShader->arrayParam			= null;
                    type							= false;
                }


                if ((pNewShader->arrayParam && type) || (!type)) {
                    pNewShader->refCount	= 0;
                    pNewShader->shaderObj	= shaderID;
                    pNewShader->pNext		= this->shaderList;
                    this->shaderList		= pNewShader;

                    return pNewShader;
                }
            }
            dglDeleteShader(shaderID);
        }

        KLBDELETE(pNewShader);
        pNewShader = null;
    }
    return pNewShader;
}
// Rendering Shader.
CShaderSet*	CKLBOGLWrapper::createShaderSet	(CShader* pVertexShader, CShader* pPixelShader) {
    CShaderSet* pNewShaderSet = KLBNEW(CShaderSet);
    if (pNewShaderSet) {
        s32 size = pVertexShader->countUniform + pPixelShader->countUniform;
        if (size) {
            pNewShaderSet->locationArray = KLBNEWA(s32,size);
        } else {
            pNewShaderSet->locationArray = null;
        }

        if ((pNewShaderSet->locationArray) || (size == 0)) {
            GLuint progID = dglCreateProgram();
            if (progID) {
                // Attach
                dglAttachShader(progID, pVertexShader->shaderObj);
                dglAttachShader(progID, pPixelShader->shaderObj);

                pNewShaderSet->pInstances	= null;
                pNewShaderSet->pMgr			= this;

                //
                // Iterate through vertex shader attribute
                //
                s32 iterator = 0;
                CShader::SInternalParam* pParam = &pVertexShader->arrayParam[pVertexShader->countUniform];
                while (iterator < pVertexShader->countStreamInfo) {
                    dglBindAttribLocation(progID, iterator, pParam->param.name);	// Actually only associated with vertex.
                    iterator++;
                    pParam++;
                }

                dglLinkProgram(progID);

                GLint success = 0;
                dglGetProgramiv(progID, GL_LINK_STATUS, &success);
                if (success)
                {
                    s32 uniformIndex = 0;
                    for (s32 n=0; n < 2; n++) {
                        CShader* pShader;
                        if (n==0) {
                            pShader = pVertexShader;
                        }
                        else {
                            pShader = pPixelShader;
                        }

                        CShader::SInternalParam* pParam = pShader->arrayParam;
                        iterator = 0;
                        while (iterator < pShader->countUniform) {
                            // Becomes UniformID
                            pNewShaderSet->locationArray[uniformIndex++] = dglGetUniformLocation(progID, pParam->param.name);
                            iterator++;
                            pParam++;
                        }
                    }

                    pNewShaderSet->programObj	= progID;
                    pNewShaderSet->pNext		= this->shaderSetList;
                    this->shaderSetList			= pNewShaderSet;

                    pVertexShader->refCount++;
                    pPixelShader->refCount++;

                    pNewShaderSet->pixelShader	= pPixelShader;
                    pNewShaderSet->vertexShader	= pVertexShader;

                    pNewShaderSet->enableTexture	= pPixelShader->enableTexture | pVertexShader->enableTexture;
                    pNewShaderSet->enableColor		= pPixelShader->enableColor   | pVertexShader->enableColor;

                    return pNewShaderSet;
                }
                dglDeleteProgram(progID);
            }

            if (pNewShaderSet->locationArray) {
                KLBDELETE(pNewShaderSet->locationArray);
            }
        }
        KLBDELETE(pNewShaderSet);
    }
    return null;
}