open source

This commit is contained in:
lvfulong
2020-11-11 16:17:13 +08:00
parent 4d989f3ecb
commit bc4ca748de
2441 changed files with 623057 additions and 2 deletions
@@ -0,0 +1,51 @@
/**
@file JCWebGLPlus.cpp
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#include "JCWebGLPlus.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "Log.h"
#include "JSWebGLPlus.h"
#include "JSArrayBufferRef.h"
#include "JSKeyframeNode.h"
#include "JSFloatKeyframe.h"
#include "JSKeyframeNodeList.h"
#include "JSCUtil.h"
namespace laya
{
void JCWebGLPlus::exportJS(void* ctx, void* object)
{
JSWebGLPlus::getInstance()->exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSArrayBufferRef::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSFloatKeyframe::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSFloatArrayKeyframe::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSKeyframeNode::exportJS((JSContextRef)ctx, (JSObjectRef)object);
JSKeyframeNodeList::exportJS((JSContextRef)ctx, (JSObjectRef)object);
}
void JCWebGLPlus::clean()
{
//JSWebGLPlus::getInstance()->releaseInstance();
JSCBinder<JSWebGLPlus>::ReleaseInstance();
JSCBinder<JSArrayBufferRef>::ReleaseInstance();
JSCBinder<JSFloatKeyframe>::ReleaseInstance();
JSCBinder<JSFloatArrayKeyframe>::ReleaseInstance();
JSCBinder<JSKeyframeNode>::ReleaseInstance();
JSCBinder<JSKeyframeNodeList>::ReleaseInstance();
}
void JCWebGLPlus::clearAll()
{
m_pJSArrayBufferManager->clearAll();
m_pJSABManagerSyncToRender->clearAll();
m_pRArrayBufferManager->clearAll();
clean();
}
}
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,81 @@
/**
@file JSArrayBufferRef.cpp
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#include "JSArrayBufferRef.h"
#include "../JCWebGLPlus.h"
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSArrayBufferRef, JSObjNode);
JSArrayBufferRef::JSArrayBufferRef()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
m_nID = 0;
m_bSyncToRender = false;
}
JSArrayBufferRef::~JSArrayBufferRef()
{
callManagerRemoveArrayBuffer();
}
void JSArrayBufferRef::callManagerRemoveArrayBuffer()
{
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
{
if (m_bSyncToRender)
{
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->prepareRemoveArrayBuffer(m_nID);
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->removeArrayBuffer(m_nID);
}
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->removeArrayBuffer(m_nID);
}
}
int JSArrayBufferRef::getID()
{
return m_nID;
}
bool JSArrayBufferRef::getIsSyncToRender()
{
return m_bSyncToRender;
}
static JSValueRef _GetID(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSArrayBufferRef* self = (JSArrayBufferRef*)JSObjectGetPrivate(object);
int v = self->getID();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef IsSyncToRender(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSArrayBufferRef *pObj = (JSArrayBufferRef*)JSObjectGetPrivate(thisObject);
bool value = pObj->getIsSyncToRender();
return JSValueMakeBoolean(ctx, value);
}
void JSArrayBufferRef::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSArrayBufferRef>* binder = JSCBinder<JSArrayBufferRef>::GetInstance();
binder->begin(ctx);
binder->addProperty("id", _GetID);
binder->addMethod("isSyncToRender", IsSyncToRender);
binder->end(object, "ArrayBufferRef");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,48 @@
/**
@file JSArrayBufferRef.h
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#ifndef __JSArrayBufferRef_H__
#define __JSArrayBufferRef_H__
#include <stdio.h>
#include "../JSObjBase.h"
#include <JavaScriptCore/JavaScriptCore.h>
/**
* @brief
*/
namespace laya
{
class JSArrayBufferRef : public JCListNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSArrayBufferRef();
~JSArrayBufferRef();
void callManagerRemoveArrayBuffer();
int getID();
bool getIsSyncToRender();
public:
int m_nID;
bool m_bSyncToRender;
};
}
//------------------------------------------------------------------------------
#endif //__JSArrayBufferRef_H__
//-----------------------------END FILE--------------------------------
+64
View File
@@ -0,0 +1,64 @@
/**
@file JSCUtil.cpp
@brief
@author James
@version 1.0
@date 2017_11_29
*/
#include "JSCUtil.h"
#include <JavaScriptCore/JavaScriptCore.h>
#include <vector>
namespace laya
{
JSContextRef JSCUtil::s_ctx = NULL;
char* JSCUtil::toCString(JSContextRef ctx,JSStringRef value)
{
int len = JSStringGetMaximumUTF8CStringSize(value);
static std::vector<char> utf8str;
utf8str.resize(len);
JSStringGetUTF8CString(value, &utf8str[0], len);
return &utf8str[0];
}
char* JSCUtil::toCString(JSContextRef ctx,JSValueRef value)
{
assert(JSValueIsString(ctx, value));
JSStringRef str = JSValueToStringCopy(ctx, value, nullptr);
char* ret = toCString(ctx, str);
JSStringRelease(str);
return ret;
}
bool JSCUtil::extractJSAB(JSContextRef ctx,JSValueRef ab, char*& data, int& len)
{
JSObjectRef arrayObj = JSValueToObject(ctx, ab, NULL);
JSTypedArrayType arrayType = JSValueGetTypedArrayType(ctx, ab, NULL);
switch (arrayType)
{
case kJSTypedArrayTypeNone:
{
data = NULL;
len = 0;
return false;
}
break;
case kJSTypedArrayTypeArrayBuffer:
{
data = (char*)JSObjectGetArrayBufferBytesPtr(ctx, arrayObj, NULL);
len = (int)JSObjectGetArrayBufferByteLength(ctx, arrayObj, NULL);
return true;
}
break;
default:
{
data = (char*)JSObjectGetTypedArrayBytesPtr(ctx, arrayObj, NULL) + JSObjectGetTypedArrayByteOffset(ctx, arrayObj, NULL);
len = (int)JSObjectGetTypedArrayByteLength(ctx, arrayObj, NULL);
return true;
}
break;
}
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
+344
View File
@@ -0,0 +1,344 @@
#ifndef _JSCUtil_h
#define _JSCUtil_h
#include <unordered_map>
#include <string>
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSCUtil
{
public:
static JSContextRef s_ctx;
static bool extractJSAB(JSContextRef ctx,JSValueRef jsval, char*& data, int& len);
static char* toCString(JSContextRef ctx,JSValueRef value);
static char* toCString(JSContextRef ctx,JSStringRef value);
};
template<typename T>
class JSCBinder
{
public:
inline unsigned int __hash_BKDR(const char *p_str)
{
if(0 == p_str)
return 0;
unsigned int seed = 131; // 31 131 1313 13131 131313 etc..
unsigned int hash = 0;
for(;0!=*p_str;)
{
hash = hash * seed + (*p_str++);
}
return (hash & 0x7FFFFFFF);
}
JSCBinder()
{
m_bIsGlobal = false;
m_ClassDefine = kJSClassDefinitionEmpty;
m_ClassObject = nullptr;
m_iTypeID = __hash_BKDR(typeid(T).name());
}
~JSCBinder()
{
_reset();
}
unsigned int getTypeID()
{
return m_iTypeID;
}
void addProperty(const std::string& name, JSObjectGetPropertyCallback getter, JSObjectSetPropertyCallback setter = NULL)
{
assert(!name.empty());
if (getter)
{
GetPropertyMapRes rs = m_GetPropertyMap.insert(GetPropertyMapValue(name, getter));
assert(rs.second);
}
if (setter)
{
SetPropertyMapRes rs = m_SetPropertyMap.insert(SetPropertyMapValue(name, setter));
assert(rs.second);
}
}
void begin(JSContextRef ctx)
{
JSCUtil::s_ctx = ctx;
}
void addMethod(const std::string& name, JSObjectCallAsFunctionCallback method)
{
JSStringRef pName = JSStringCreateWithUTF8CString(name.c_str());
JSContextRef pCtx = JSCUtil::s_ctx;
JSValueRef callAsFunction = JSObjectMakeFunctionWithCallback(pCtx, pName, method);
JSStringRelease(pName);
JSValueProtect(pCtx, callAsFunction);
FunctionMapRes rsf = m_FunctionMap.insert(FunctionMapValue(name, callAsFunction));
assert(rsf.second);
}
void end(JSObjectRef object, const std::string& name)
{
m_bIsGlobal = false;
endImpl(object, name, nullptr);
}
void endToGlobal(JSObjectRef object, const std::string& name, T* pIns)
{
assert(pIns != nullptr);
m_bIsGlobal = false;
endImpl(object, name, pIns);
m_bIsGlobal = true;
}
JSObjectRef transferObjPtrToJS(JSContextRef pCtx, T* p_pIns)
{
assert( !m_bIsGlobal );
JSObjectRef pRet = JSObjectMake(pCtx, m_ClassObject, p_pIns);
JSValueRef pProperty = JSValueMakeNumber(pCtx, (double)getTypeID());
JSStringRef pszName = JSStringCreateWithUTF8CString("jsc__cppclstypeid");
JSObjectSetProperty(pCtx, pRet, pszName, pProperty, kJSPropertyAttributeReadOnly|kJSPropertyAttributeDontDelete, 0);
JSStringRelease(pszName);
return pRet;
}
static JSCBinder<T>* GetInstance()
{
if (!s_instance)
{
s_instance = new JSCBinder<T>();
}
return s_instance;
}
static void ReleaseInstance()
{
if (s_instance)
{
delete s_instance;
s_instance = NULL;
}
}
private:
static JSObjectRef newWrap(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if( JSCBinder<T>::GetInstance()->m_bIsGlobal )
{
return NULL;
}
return JSCBinder<T>::GetInstance()->transferObjPtrToJS(ctx, new T);
}
static void destroyWrap(JSObjectRef object)
{
T *p = (T *)JSObjectGetPrivate(object);
delete p;
}
static bool isInstanceOf(JSContextRef ctx, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
{
if(!JSValueIsObject(ctx, possibleInstance))
{
return false;
}
JSObjectRef p_pObj = JSValueToObject(ctx, possibleInstance ,NULL);
JSStringRef pszName = JSStringCreateWithUTF8CString("jsc__cppclstypeid");
JSValueRef pProperty = JSObjectGetProperty(ctx, p_pObj, pszName, 0);
JSStringRelease(pszName);
if(0 == pProperty)
{
return false;
}
else
{
int nID = (int)JSValueToNumber(ctx,pProperty, 0);
return (nID == (JSCBinder<T>::GetInstance()->getTypeID()));
}
}
static bool hasProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
if (JSCBinder<T>::GetInstance()->findFunction(strPropertyName))
{
return true;
}
if (JSCBinder<T>::GetInstance()->findGetProperty(strPropertyName))
{
return true;
}
if (JSCBinder<T>::GetInstance()->findSetProperty(strPropertyName))
{
return true;
}
return false;
}
static JSValueRef getProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
T* pThis = (T*)JSObjectGetPrivate(object);
if(NULL == pThis )
{
return NULL;
}
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
JSObjectGetPropertyCallback callAsFunction = JSCBinder<T>::GetInstance()->findGetProperty(strPropertyName);
if(callAsFunction)
{
return callAsFunction(ctx, object, propertyName, exception);
}
return JSCBinder<T>::GetInstance()->findFunction(strPropertyName);
}
static bool setProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
T* pThis = (T*)JSObjectGetPrivate(object);
if(0 == pThis)
{
return false;
}
char* strPropertyName = JSCUtil::toCString(ctx, propertyName);
JSObjectSetPropertyCallback callAsFunction = JSCBinder<T>::GetInstance()->findSetProperty(strPropertyName);
if( NULL == callAsFunction)
{
return false;
}
JSValueRef arguments[1];
arguments[0] = value;
callAsFunction(ctx, object, propertyName, value, exception);
return true;
}
private:
void _reset()
{
JSContextRef ctx = JSCUtil::s_ctx;
for (FunctionMapItr itr = m_FunctionMap.begin(); itr != m_FunctionMap.end(); itr++)
{
JSValueUnprotect(ctx, itr->second);
}
m_FunctionMap.clear();
m_SetPropertyMap.clear();
m_GetPropertyMap.clear();
m_bIsGlobal = false;
m_ClassDefine = kJSClassDefinitionEmpty;
if (m_ClassObject != nullptr)
{
JSClassRelease(m_ClassObject);
m_ClassObject = nullptr;
}
}
void endImpl(JSObjectRef object, const std::string& name, T *p_pIns)
{
assert(!name.empty());
m_ClassDefine = kJSClassDefinitionEmpty;
m_ClassDefine.attributes = kJSClassAttributeNone;
m_ClassDefine.className = name.c_str();
m_ClassDefine.callAsConstructor = JSCBinder<T>::newWrap;
m_ClassDefine.finalize = JSCBinder<T>::destroyWrap;
m_ClassDefine.hasProperty = JSCBinder<T>::hasProperty;
m_ClassDefine.hasInstance = JSCBinder<T>::isInstanceOf;
m_ClassDefine.getProperty = JSCBinder<T>::getProperty;
m_ClassDefine.setProperty = JSCBinder<T>::setProperty;
//m_ClassDefine.callAsFunction = JSCBinder<T>::callAsFunctionCallback;
m_ClassObject = JSClassCreate(&m_ClassDefine);
JSContextRef pCtx = JSCUtil::s_ctx;
JSStringRef jsName = JSStringCreateWithUTF8CString(name.c_str());
JSObjectRef myObject;
if( 0 != p_pIns )
{
myObject = transferObjPtrToJS(pCtx, p_pIns);
}
else
{
myObject = JSObjectMake(pCtx, m_ClassObject, 0);
}
JSObjectSetProperty( pCtx, object, jsName, myObject, kJSPropertyAttributeNone, NULL );
JSStringRelease(jsName);
}
JSValueRef findFunction(const std::string& name)
{
FunctionMapItr iter = m_FunctionMap.find(name);
if(iter == m_FunctionMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
JSObjectGetPropertyCallback findGetProperty(const std::string& name)
{
GetPropertyMapItr iter = m_GetPropertyMap.find(name);
if(iter == m_GetPropertyMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
JSObjectSetPropertyCallback findSetProperty(const std::string& name)
{
SetPropertyMapItr iter = m_SetPropertyMap.find(name);
if(iter == m_SetPropertyMap.end())
{
return nullptr;
}
else
{
return (*iter).second;
}
}
private:
typedef std::unordered_map<std::string, JSObjectGetPropertyCallback> GetPropertyMap;
typedef typename GetPropertyMap::value_type GetPropertyMapValue;
typedef typename GetPropertyMap::iterator GetPropertyMapItr;
typedef std::pair<GetPropertyMapItr, bool> GetPropertyMapRes;
GetPropertyMap m_GetPropertyMap;
typedef std::unordered_map<std::string, JSObjectSetPropertyCallback> SetPropertyMap;
typedef typename SetPropertyMap::value_type SetPropertyMapValue;
typedef typename SetPropertyMap::iterator SetPropertyMapItr;
typedef std::pair<SetPropertyMapItr, bool> SetPropertyMapRes;
SetPropertyMap m_SetPropertyMap;
typedef std::unordered_map<std::string, JSValueRef> FunctionMap;
typedef typename FunctionMap::value_type FunctionMapValue;
typedef typename FunctionMap::iterator FunctionMapItr;
typedef std::pair<FunctionMapItr, bool> FunctionMapRes;
FunctionMap m_FunctionMap;
bool m_bIsGlobal;
JSClassDefinition m_ClassDefine;
JSClassRef m_ClassObject;
unsigned int m_iTypeID;
static JSCBinder<T>* s_instance;
};
template<typename T> JSCBinder<T>* JSCBinder<T>::s_instance = NULL;
}
#endif
@@ -0,0 +1,138 @@
/**
@file JSFloatArrayKeyframe.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSFloatArrayKeyframe.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSFloatArrayKeyframe, JSObjNode);
//------------------------------------------------------------------------------
JSFloatArrayKeyframe::JSFloatArrayKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//AdjustAmountOfExternalAllocatedMemory(1024);
//JCMemorySurvey::GetInstance()->newClass("conchFloatArrayKeyframe", 1024, this);
}
//------------------------------------------------------------------------------
JSFloatArrayKeyframe::~JSFloatArrayKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//JCMemorySurvey::GetInstance()->releaseClass("conchFloatArrayKeyframe", this);
}
static JSValueRef SetInTangent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nInTangent.data = pArrayBuffer;
pObj->m_nInTangent.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOutTangent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nOutTangent.data = pArrayBuffer;
pObj->m_nOutTangent.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetValue(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_nValue.data = pArrayBuffer;
pObj->m_nValue.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
pObj->m_pData.data = pArrayBuffer;
pObj->m_pData.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe* pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
float value = JSValueToNumber(ctx, arguments[0], 0);
pObj->setTime(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatArrayKeyframe *pObj = (JSFloatArrayKeyframe*)JSObjectGetPrivate(thisObject);
float value = pObj->getTime();
return JSValueMakeNumber(ctx, value);
}
void JSFloatArrayKeyframe::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSFloatArrayKeyframe>* binder = JSCBinder<JSFloatArrayKeyframe>::GetInstance();
binder->begin(ctx);
binder->addMethod("setTime", SetTime);
binder->addMethod("getTime", GetTime);
binder->addMethod("setInTangent", SetInTangent);
binder->addMethod("setOutTangent", SetOutTangent);
binder->addMethod("setValue", SetValue);
binder->addMethod("setData", SetData);
binder->end(object, "_conchFloatArrayKeyframe");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,38 @@
/**
@file JSFloatArrayKeyframe.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JSFloatArrayKeyframe_H__
#define __JSFloatArrayKeyframe_H__
#include <stdio.h>
#include <string>
#include <map>
#include "../JSObjBase.h"
#include "../Animation/JCFloatArrayKeyframe.h"
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSFloatArrayKeyframe : public JCFloatArrayKeyframe, public JCListNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSFloatArrayKeyframe();
~JSFloatArrayKeyframe();
};
}
//------------------------------------------------------------------------------
#endif //__JSFloatArrayKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,136 @@
/**
@file JSFloatKeyframe.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSFloatKeyframe.h"
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSFloatKeyframe, JSObjNode);
//------------------------------------------------------------------------------
JSFloatKeyframe::JSFloatKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
/*m_nTime = 0;
m_nInTangent = 0;
m_nOutTangent = 0;
m_nValue = 0;
AdjustAmountOfExternalAllocatedMemory(16);
JCMemorySurvey::GetInstance()->newClass("conchFloatKeyframe", 16, this);*/
}
JSFloatKeyframe::~JSFloatKeyframe()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//JCMemorySurvey::GetInstance()->releaseClass("conchFloatKeyframe", this);
}
static JSValueRef Clone(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(thisObject);
JSFloatKeyframe* pKeyframe = new JSFloatKeyframe();
self->_cloneTo(pKeyframe);
return JSCBinder<JSFloatKeyframe>::GetInstance()->transferObjPtrToJS(ctx, pKeyframe);
}
static JSValueRef CloneTo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(thisObject);
JSValueRef destObj = arguments[0];
if (JSValueIsObject(ctx, destObj))
{
JSFloatKeyframe* pKeyFrame = (JSFloatKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, destObj, NULL));
if (pKeyFrame)
{
self->_cloneTo(pKeyFrame);
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef _GetTime(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getTime();
return JSValueMakeNumber(ctx, v);
}
static bool _SetTime(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setTime(v);
return true;
}
static JSValueRef _GetInTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getInTangent();
return JSValueMakeNumber(ctx, v);
}
static bool _SetInTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setInTangent(v);
return true;
}
static JSValueRef _GetOutTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getOutTangent();
return JSValueMakeNumber(ctx, v);
}
static bool _SetOutTangent(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setOutTangent(v);
return true;
}
static JSValueRef _GetValue(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
float v = self->getValue();
return JSValueMakeNumber(ctx, v);
}
static bool _SetValue(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSFloatKeyframe* self = (JSFloatKeyframe*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
float v = JSValueToNumber(ctx, value, 0);
self->setValue(v);
return true;
}
void JSFloatKeyframe::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSFloatKeyframe>* binder = JSCBinder<JSFloatKeyframe>::GetInstance();
binder->begin(ctx);
binder->addProperty("time", _GetTime, _SetTime);
binder->addProperty("inTangent", _GetInTangent, _SetInTangent);
binder->addProperty("outTangent", _GetOutTangent, _SetOutTangent);
binder->addProperty("value", _GetValue, _SetValue);
binder->addMethod("clone", Clone);
binder->addMethod("cloneTo", CloneTo);
binder->end(object, "conchFloatKeyframe");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,38 @@
/**
@file JSFloatKeyframe.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JSFloatKeyframe_H__
#define __JSFloatKeyframe_H__
#include <stdio.h>
#include <string>
#include <map>
#include "../Animation/JCKeyframeNode.h"
#include "../JSObjBase.h"
#include <JavaScriptCore/JavaScriptCore.h>
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSFloatKeyframe : public JCListNode, public JCFloatKeyframe
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSFloatKeyframe();
~JSFloatKeyframe();
};
}
//------------------------------------------------------------------------------
#endif //__JSFloatKeyframe_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,406 @@
/**
@file JSKeyframeNode.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSKeyframeNode.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
std::string JCKeyframeNode::s_sTempString = "";//TODO
//ADDJSCLSINFO(JSKeyframeNode, JSObjNode);
//------------------------------------------------------------------------------
JSKeyframeNode::JSKeyframeNode()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
/*m_nIndexInList = 0;
m_nType = 0;
m_nDataType = 0;
m_pDataFloat = 0;
AdjustAmountOfExternalAllocatedMemory(4096);
JCMemorySurvey::GetInstance()->newClass("JSKeyframeNode", 4096, this);*/
}
//------------------------------------------------------------------------------
JSKeyframeNode::~JSKeyframeNode()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
/* m_vOwnerPath.clear();
m_vPropertys.clear();
m_vKeyFrames.clear();
JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNode", this); */
}
static JSValueRef SetFloat32ArrayData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[0], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
self->m_pDataFloatArray.data = pArrayBuffer;
self->m_pDataFloatArray.byteSize = nABLen;
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOwnerPathCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setOwnerPathCount(index);
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetOwnerPathByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setOwnerPathByIndex(index, JSCUtil::toCString(ctx, arguments[1]));
return JSValueMakeUndefined(ctx);
}
static JSValueRef JoinOwnerPath(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
const char* v = self->_joinOwnerPath(JSCUtil::toCString(ctx, arguments[0]));
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef SetPropertyCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setPropertyCount(index);
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetPropertyByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
self->_setPropertyByIndex(index, JSCUtil::toCString(ctx, arguments[1]));
return JSValueMakeUndefined(ctx);
}
static JSValueRef JoinProperty(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
const char* v = self->_joinProperty(JSCUtil::toCString(ctx, arguments[0]));
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef SetKeyframeByIndex0(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframe = arguments[1];
if (JSValueIsObject(ctx, keyframe))
{
JSFloatKeyframe* pNode = (JSFloatKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, keyframe, NULL));
if (pNode)
{
self->m_vKeyFrames[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetKeyframeByIndex1(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframe = arguments[1];
if (JSValueIsObject(ctx, keyframe))
{
JSFloatArrayKeyframe* pNode = (JSFloatArrayKeyframe*)JSObjectGetPrivate(JSValueToObject(ctx, keyframe, NULL));
if (pNode)
{
self->m_vKeyFrames[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef SetKeyframeCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int value = JSValueToNumber(ctx, arguments[0], 0);
self->_setKeyframeCount(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetOwnerPathByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
const char* v = self->getOwnerPathByIndex(index);
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef GetPropertyByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
const char* v = self->getPropertyByIndex(index);
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static JSValueRef GetKeyframeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
return JSValueMakeNull(ctx);
}
static JSValueRef GetFloatData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode *pObj = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
float v = pObj->getFloatData();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetDataType(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode *pObj = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = pObj->getDataType();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetKeyFramesCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getKeyFramesCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetOwnerPathCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getOwnerPathCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef GetPropertyCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
laya::JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(thisObject);
int v = self->getPropertyCount();
return JSValueMakeNumber(ctx, v);
}
static JSValueRef _GetIndexInList(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getIndexInList();
return JSValueMakeNumber(ctx, v);
}
static bool _SetIndexInList(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->setIndexInList(v);
return true;
}
static JSValueRef _GetType(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getType();
return JSValueMakeNumber(ctx, v);
}
static bool _SetType(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->setType(v);
return true;
}
static JSValueRef _GetOwnerPathCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getOwnerPathCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetOwnerPathCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setOwnerPathCount(v);
return true;
}
static JSValueRef _GetKeyFramesCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getKeyFramesCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetKeyframeCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setKeyframeCount(v);
return true;
}
static JSValueRef _GetPropertyCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
int v = self->getPropertyCount();
return JSValueMakeNumber(ctx, v);
}
static bool _SetPropertyCount(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
assert(JSValueIsNumber(ctx, value));
int v = JSValueToNumber(ctx, value, 0);
self->_setPropertyCount(v);
return true;
}
static JSValueRef _GetPropertyOwner(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
const char* v = self->getPropertyOwner();
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static bool _SetPropertyOwner(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
self->setPropertyOwner(JSCUtil::toCString(ctx, value));
return true;
}
static JSValueRef _GetFullPath(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
const char* v = self->getFullPath();
JSStringRef pStr = JSStringCreateWithUTF8CString(v);
JSValueRef pRet = JSValueMakeString(ctx, pStr);
JSStringRelease(pStr);
return pRet;
}
static bool _SetFullPath(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
JSKeyframeNode* self = (JSKeyframeNode*)JSObjectGetPrivate(object);
self->setFullPath(JSCUtil::toCString(ctx, value));
return true;
}
void JSKeyframeNode::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSKeyframeNode>* binder = JSCBinder<JSKeyframeNode>::GetInstance();
binder->begin(ctx);
binder->addProperty("_indexInList", _GetIndexInList, _SetIndexInList);
binder->addProperty("type", _GetType, _SetType);
binder->addProperty("fullPath", _GetFullPath, _SetFullPath);
binder->addProperty("propertyOwner", _GetPropertyOwner, _SetPropertyOwner);
binder->addProperty("ownerPathCount", _GetOwnerPathCount, _SetOwnerPathCount);
binder->addProperty("keyFramesCount", _GetKeyFramesCount, _SetKeyframeCount);
binder->addProperty("propertyCount", _GetPropertyCount, _SetPropertyCount);
binder->addMethod("getOwnerPathCount", GetOwnerPathCount);
binder->addMethod("getPropertyCount", GetPropertyCount);
binder->addMethod("getKeyFramesCount", GetKeyFramesCount);
binder->addMethod("_setOwnerPathCount", SetOwnerPathCount);
binder->addMethod("_setOwnerPathByIndex", SetOwnerPathByIndex);
binder->addMethod("_joinOwnerPath", JoinOwnerPath);
binder->addMethod("_setPropertyCount", SetPropertyCount);
binder->addMethod("_setPropertyByIndex", SetPropertyByIndex);
binder->addMethod("_joinProperty", JoinProperty);
binder->addMethod("_setKeyframeCount", SetKeyframeCount);
binder->addMethod("_setKeyframeByIndex0", SetKeyframeByIndex0);
binder->addMethod("_setKeyframeByIndex1", SetKeyframeByIndex1);
binder->addMethod("getOwnerPathByIndex", GetOwnerPathByIndex);
binder->addMethod("getPropertyByIndex", GetPropertyByIndex);
binder->addMethod("getKeyframeByIndex", GetKeyframeByIndex);
binder->addMethod("getDataType", GetDataType);
binder->addMethod("getFloatData", GetFloatData);
binder->addMethod("setFloat32ArrayData", SetFloat32ArrayData);
binder->end(object, "_conchKeyframeNode");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,41 @@
/**
@file JSKeyframeNode.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JSKeyframeNode_H__
#define __JSKeyframeNode_H__
#include <stdio.h>
#include <string>
#include <map>
#include "../JSObjBase.h"
#include <vector>
#include "JSFloatKeyframe.h"
#include "JSFloatArrayKeyframe.h"
#include "../Animation/JCKeyframeNode.h"
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSKeyframeNode : public JCListNode, public JCKeyframeNode
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSKeyframeNode();
~JSKeyframeNode();
};
}
//------------------------------------------------------------------------------
#endif //__JSKeyframeNode_H__
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,101 @@
/**
@file JSKeyframeNodeList.cpp
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#include "JSKeyframeNodeList.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
namespace laya
{
//ADDJSCLSINFO(JSKeyframeNodeList, JSObjNode);
//------------------------------------------------------------------------------
JSKeyframeNodeList::JSKeyframeNodeList()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//AdjustAmountOfExternalAllocatedMemory(8192);
//JCMemorySurvey::GetInstance()->newClass("JSKeyframeNodeList", 8192, this);
}
//------------------------------------------------------------------------------
JSKeyframeNodeList::~JSKeyframeNodeList()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//m_vNodes.clear();
//JCMemorySurvey::GetInstance()->releaseClass("JSKeyframeNodeList", this);
}
static JSValueRef SetCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNodeList *pObj = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int value = JSValueToNumber(ctx, arguments[0], 0);
pObj->setCount(value);
return JSValueMakeUndefined(ctx);
}
static JSValueRef GetCount(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
JSKeyframeNodeList *pObj = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
int value = pObj->getCount();
return JSValueMakeNumber(ctx, value);
}
static JSValueRef GetNodeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 1)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList* self = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSKeyframeNode* pNode = (JSKeyframeNode*)self->m_vNodes[index];
return JSCBinder<JSKeyframeNode>::GetInstance()->transferObjPtrToJS(ctx, pNode);
}
static JSValueRef SetNodeByIndex(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList* self = (JSKeyframeNodeList*)JSObjectGetPrivate(thisObject);
assert(JSValueIsNumber(ctx, arguments[0]));
int index = JSValueToNumber(ctx, arguments[0], 0);
JSValueRef keyframeNode = arguments[1];
if (JSValueIsObject(ctx, keyframeNode))
{
JSKeyframeNode* pNode = (JSKeyframeNode*)JSObjectGetPrivate(JSValueToObject(ctx, keyframeNode, NULL));
if (pNode)
{
self->m_vNodes[index] = pNode;
}
}
return JSValueMakeUndefined(ctx);
}
void JSKeyframeNodeList::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSKeyframeNodeList>* binder = JSCBinder<JSKeyframeNodeList>::GetInstance();
binder->begin(ctx);
binder->addMethod("setNodeByIndex", SetNodeByIndex);
binder->addMethod("getNodeByIndex", GetNodeByIndex);
binder->addMethod("getCount", GetCount);
binder->addMethod("setCount", SetCount);
binder->end(object, "_conchKeyframeNodeList");
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
@@ -0,0 +1,40 @@
/**
@file JSKeyframeNodeList.h
@brief
@author James
@version 1.0
@date 2018_7_12
*/
#ifndef __JSKeyframeNodeList_H__
#define __JSKeyframeNodeList_H__
#include <stdio.h>
#include <string>
#include <map>
#include "../JSObjBase.h"
#include "JSKeyframeNode.h"
#include <vector>
#include "../Animation/JCKeyframeNodeList.h"
#include <JavaScriptCore/JavaScriptCore.h>
namespace laya
{
class JSKeyframeNodeList : public JCListNode, public JCKeyframeNodeList
{
public:
static void exportJS(JSContextRef ctx, JSObjectRef object);
JSKeyframeNodeList();
~JSKeyframeNodeList();
};
}
//------------------------------------------------------------------------------
#endif //__JSKeyframeNodeList_H__
//-----------------------------END FILE--------------------------------
+499
View File
@@ -0,0 +1,499 @@
/**
@file JSWebGLPlus.cpp
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#include "JSWebGLPlus.h"
#include "../JCWebGLPlus.h"
#include "JSArrayBufferRef.h"
#include "JSKeyframeNodeList.h"
#include "../Log.h"
#define NDEBUG
#include <assert.h>
#include "JSCUtil.h"
//------------------------------------------------------------------------------
namespace laya
{
JSWebGLPlus* JSWebGLPlus::s_pWebGLPlus = NULL;
//ADDJSCLSINFO(JSWebGLPlus, JSObjNode);
JSWebGLPlus::JSWebGLPlus()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->push_back(this);
}
//AdjustAmountOfExternalAllocatedMemory(8192);
//JCMemorySurvey::GetInstance()->newClass("webglPlus", 8192, this);
}
JSWebGLPlus::~JSWebGLPlus()
{
if (JSObjNode::s_pListJSObj)
{
JSObjNode::s_pListJSObj->delNode(this);
}
//JCMemorySurvey::GetInstance()->releaseClass("webglPlus", this);
s_pWebGLPlus = NULL;
}
JSWebGLPlus* JSWebGLPlus::getInstance()
{
if (s_pWebGLPlus == NULL)
{
s_pWebGLPlus = new JSWebGLPlus();
}
return s_pWebGLPlus;
}
static JSValueRef Culling(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus Culling");
if (argumentCount < 4)
{
return JSValueMakeNumber(ctx, 0);
}
JSValueRef boundFrustumBuffer = arguments[0];
JSValueRef cullingBuffer = arguments[1];
JSValueRef cullingBufferIndices = arguments[2];
assert(JSValueIsNumber(ctx, arguments[3]));
int cullingCount = JSValueToNumber(ctx, arguments[3], 0);
JSValueRef cullingBufferResult = arguments[4];
char* pFrustumBuffer;
char* pCullingBuffer;
char* pCullingBufferIndices;
char* pCullingBufferResult;
int nFrustumLen = 0;
int nCullingBufferLen = 0;
int nCullingBufferIndicesLen = 0;
int nCullingBufferResultLen = 0;
if (JSCUtil::extractJSAB(ctx, boundFrustumBuffer, pFrustumBuffer, nFrustumLen) == false)
{
LOGE("culling culling frustum error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBuffer, pCullingBuffer, nCullingBufferLen) == false)
{
LOGE("culling culling buffer error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBufferIndices, pCullingBufferIndices, nCullingBufferIndicesLen) == false)
{
LOGE("culling culling buffer indices error");
return JSValueMakeNumber(ctx, 0);
}
if (JSCUtil::extractJSAB(ctx, cullingBufferResult, pCullingBufferResult, nCullingBufferResultLen) == false)
{
LOGE("culling result error");
return JSValueMakeNumber(ctx, 0);
}
int count = JCWebGLPlus::getInstance()->culling3D(cullingCount, pFrustumBuffer, nFrustumLen, pCullingBuffer, nCullingBufferLen, pCullingBufferIndices, nCullingBufferIndicesLen, pCullingBufferResult, nCullingBufferResultLen);
return JSValueMakeNumber(ctx, count);
}
static JSValueRef UpdateAnimationNodeWorldMatix(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UpdateAnimationNodeWorldMatix");
if (argumentCount < 5)
{
return JSValueMakeBoolean(ctx, false);
}
JSValueRef locPosition = arguments[0];
JSValueRef locRotation = arguments[1];
JSValueRef locScaling = arguments[2];
JSValueRef parentIndices = arguments[3];
JSValueRef outWorldMatrix = arguments[4];
char* pLocPosition;
char* pLocRotation;
char* pLocScaling;
char* pParentIndices;
char* pOutWorldMatrix;
int nLocPosLen = 0;
int nLocRotLen = 0;
int nLocScaLen = 0;
int nLocParentLen = 0;
int nOutWorldLen = 0;
if (JSCUtil::extractJSAB(ctx, locPosition, pLocPosition, nLocPosLen) == false)
{
LOGE("updateAnimationNodeWorldMatix postion error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, locRotation, pLocRotation, nLocRotLen) == false)
{
LOGE("updateAnimationNodeWorldMatix rotateion error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, locScaling, pLocScaling, nLocScaLen) == false)
{
LOGE("updateAnimationNodeWorldMatix scaling error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, parentIndices, pParentIndices, nLocParentLen) == false)
{
LOGE("updateAnimationNodeWorldMatix parent index error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, outWorldMatrix, pOutWorldMatrix, nOutWorldLen) == false)
{
LOGE("updateAnimationNodeWorldMatix world marix error");
return JSValueMakeBoolean(ctx, false);
}
bool value = JCWebGLPlus::getInstance()->updateAnimationNodeWorldMatix3D(pLocPosition, nLocPosLen, pLocRotation, nLocRotLen, pLocScaling, nLocScaLen,
pParentIndices, nLocParentLen, pOutWorldMatrix, nOutWorldLen);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef ComputeSubSkinnedData(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus ComputeSubSkinnedData");
if (argumentCount < 6)
{
return JSValueMakeBoolean(ctx, false);
}
JSValueRef worldMatrixs = arguments[0];
JSValueRef worldMatrixIndex = arguments[1];
JSValueRef inverseBindPoses = arguments[2];
JSValueRef boneIndices = arguments[3];
JSValueRef bindPoseInices = arguments[4];
JSValueRef resultData = arguments[5];
char* pWorldMatrixs;
char* pWorldMatrixIndex;
char* pInverseBindPoses;
char* pBoneIndices;
char* pBindPoseIndices;
char* pResultData;
int nWorldMatLen = 0;
int nWorldMatIndeLen = 0;
int nInverseBindPosesLen = 0;
int nBoneIndicesLen = 0;
int nBindPoseIndicesLen = 0;
int nResultDataLen = 0;
if (JSCUtil::extractJSAB(ctx, worldMatrixs, pWorldMatrixs, nWorldMatLen) == false)
{
LOGE("computeSubSkinnedDataNative world matrix error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, worldMatrixIndex, pWorldMatrixIndex, nWorldMatIndeLen) == false)
{
LOGE("computeSubSkinnedDataNative world matrix index error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, inverseBindPoses, pInverseBindPoses, nInverseBindPosesLen) == false)
{
LOGE("computeSubSkinnedDataNative inverse bind poses error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, boneIndices, pBoneIndices, nBoneIndicesLen) == false)
{
LOGE("computeSubSkinnedDataNative bone indices error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, bindPoseInices, pBindPoseIndices, nBindPoseIndicesLen) == false)
{
LOGE("computeSubSkinnedDataNative bind pose indices error");
return JSValueMakeBoolean(ctx, false);
}
if (JSCUtil::extractJSAB(ctx, resultData, pResultData, nResultDataLen) == false)
{
LOGE("computeSubSkinnedDataNative data error");
return JSValueMakeBoolean(ctx, false);
}
bool value = JCWebGLPlus::getInstance()->computeSubSkinnedData3D(pWorldMatrixs, nWorldMatLen, pWorldMatrixIndex, nWorldMatIndeLen,
pInverseBindPoses, nInverseBindPosesLen, pBoneIndices, nBoneIndicesLen,
pBindPoseIndices, nBindPoseIndicesLen, pResultData, nResultDataLen);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef CreateArrayBufferRef(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus CreateArrayBufferRef");
if (argumentCount < 4)
{
return JSValueMakeNull(ctx);
}
JSValueRef pArrayBuffer = arguments[0];
assert(JSValueIsNumber(ctx, arguments[1]));
int nType = JSValueToNumber(ctx, arguments[1], 0);
assert(JSValueIsBoolean(ctx, arguments[2]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[2]);
assert(JSValueIsNumber(ctx, arguments[3]));
int nRefType = JSValueToNumber(ctx, arguments[3], 0);
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, pArrayBuffer, pBuffer, nABLen);
if (bIsArrayBuffer)
{
JSArrayBufferRef* pArrayBufferRef = new JSArrayBufferRef();
pArrayBufferRef->m_bSyncToRender = bSyncToRender;
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
{
if (bSyncToRender)
{
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
}
else
{
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
}
}
else
{
pArrayBufferRef->m_nID = JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->createArrayBuffer(pBuffer, nABLen, (JCArrayBufferManager::ARRAY_BUFFER_TYPE)nType, (JCArrayBufferManager::ARRAY_BUFFER_REF_TYPE)nRefType);
}
return JSCBinder<JSArrayBufferRef>::GetInstance()->transferObjPtrToJS(ctx, pArrayBufferRef);
}
LOGE("JSLayaGL::createArrayBufferRef type error");
return JSValueMakeNull(ctx);
}
bool JSWebGLPlus::updateArrayBufferRef(int nID, bool bSyncToRender, JSValueRef pArrayBuffer)
{
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(JSCUtil::s_ctx, pArrayBuffer, pBuffer, nABLen);
if (bIsArrayBuffer)
{
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
{
if (bSyncToRender)
{
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->updateArrayBuffer(nID, pBuffer, nABLen);
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->updateArrayBuffer(nID, pBuffer, nABLen);
}
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->updateArrayBuffer(nID, pBuffer, nABLen);
}
return true;
}
LOGE("JSLayaGL::updateArrayBufferRef type error");
return false;
}
static JSValueRef UpdateArrayBufferRef(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UpdateArrayBufferRef");
JSWebGLPlus* self = (JSWebGLPlus*)JSObjectGetPrivate(thisObject);
if (argumentCount < 3)
{
return JSValueMakeBoolean(ctx, false);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[1]);
JSValueRef pArrayBuffer = arguments[2];
bool value = self->updateArrayBufferRef(nID, bSyncToRender, pArrayBuffer);
return JSValueMakeBoolean(ctx, value);
}
static JSValueRef SyncArrayBufferDataToRuntime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus SyncArrayBufferDataToRuntime");
if (argumentCount < 3)
{
return JSValueMakeBoolean(ctx, false);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
bool bSyncToRender = JSValueToBoolean(ctx, arguments[1]);
JSValueRef pArrayBuffer = arguments[2];
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, pArrayBuffer, pBuffer, nABLen);
if (bIsArrayBuffer)
{
if (JCWebGLPlus::getInstance()->m_nThreadMODE == THREAD_MODE_DOUBLE)
{
if (bSyncToRender)
{
JCWebGLPlus::getInstance()->m_pJSABManagerSyncToRender->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
}
}
else
{
JCWebGLPlus::getInstance()->m_pJSArrayBufferManager->syncArrayBufferDataToRuntime(nID, pBuffer, nABLen);
}
return JSValueMakeBoolean(ctx, true);
}
LOGE("JSLayaGL::syncArrayBufferDataToRuntime type error");
return JSValueMakeBoolean(ctx, false);
}
static JSValueRef EvaluateClipDatasRealTime(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus EvaluateClipDatasRealTime");
if (argumentCount < 5)
{
return JSValueMakeUndefined(ctx);
}
JSValueRef nodes = arguments[0];
assert(JSValueIsNumber(ctx, arguments[1]));
float playCurTime = JSValueToNumber(ctx, arguments[1], 0);
JSValueRef realTimeCurrentFrameIndexs = arguments[2];
assert(JSValueIsBoolean(ctx, arguments[3]));
bool addtive = JSValueToBoolean(ctx, arguments[3]);
assert(JSValueIsBoolean(ctx, arguments[4]));
bool frontPlay = JSValueToBoolean(ctx, arguments[4]);
char* pBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, realTimeCurrentFrameIndexs, pBuffer, nABLen);
if (!bIsArrayBuffer)
{
LOGE("evaluateClipDatasRealTime index type error");
return JSValueMakeUndefined(ctx);
}
if (JSValueIsObject(ctx, nodes))
{
JSKeyframeNodeList* pNodes = (JSKeyframeNodeList*)JSObjectGetPrivate(JSValueToObject(ctx, nodes, NULL));
if (!pNodes)
{
LOGE("evaluateClipDatasRealTime nodes type error");
return JSValueMakeUndefined(ctx);
}
JSKeyframeNodeList::evaluateClipDatasRealTime(pNodes, playCurTime, (short*)pBuffer, nABLen / sizeof(unsigned short), addtive, frontPlay);
}
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix2fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix2fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix2fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix3fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix3fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix3fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UniformMatrix4fvEx(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UniformMatrix4fvEx");
if (argumentCount < 3)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
GLuint location = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsBoolean(ctx, arguments[1]));
GLboolean transpose = JSValueToBoolean(ctx, arguments[1]);
assert(JSValueIsNumber(ctx, arguments[2]));
int id = JSValueToNumber(ctx, arguments[2], 0);
JCWebGLPlus::getInstance()->uniformMatrix4fvEx(location, transpose, id);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UploadShaderUniforms(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniforms");
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nCmdID = JSValueToNumber(ctx, arguments[0], 0);
assert(JSValueIsNumber(ctx, arguments[1]));
int nDataID = JSValueToNumber(ctx, arguments[1], 0);
JCWebGLPlus::getInstance()->uploadShaderUniforms(nCmdID, nDataID);
return JSValueMakeUndefined(ctx);
}
static JSValueRef UploadShaderUniformsBuffer(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
TEST_WEBGLPLUS_LOG("webglplus UploadShaderUniformsBuffer");
if (argumentCount < 2)
{
return JSValueMakeUndefined(ctx);
}
assert(JSValueIsNumber(ctx, arguments[0]));
int nCmdID = JSValueToNumber(ctx, arguments[0], 0);
char* pArrayBuffer = NULL;
int nABLen = 0;
bool bIsArrayBuffer = JSCUtil::extractJSAB(ctx, arguments[1], pArrayBuffer, nABLen);
if (bIsArrayBuffer)
{
JCWebGLPlus::getInstance()->uploadShaderUniformsBuffer(nCmdID, pArrayBuffer, nABLen);
}
return JSValueMakeUndefined(ctx);
}
void JSWebGLPlus::exportJS(JSContextRef ctx, JSObjectRef object)
{
JSCBinder<JSWebGLPlus>* binder = JSCBinder<JSWebGLPlus>::GetInstance();
binder->begin(ctx);
binder->addMethod("uploadShaderUniforms", UploadShaderUniforms);
binder->addMethod("uploadShaderUniformsBuffer", UploadShaderUniformsBuffer);
binder->addMethod("uniformMatrix2fvEx", UniformMatrix2fvEx);
binder->addMethod("uniformMatrix3fvEx", UniformMatrix3fvEx);
binder->addMethod("uniformMatrix4fvEx", UniformMatrix4fvEx);
binder->addMethod("createArrayBufferRef", CreateArrayBufferRef);
binder->addMethod("updateArrayBufferRef", UpdateArrayBufferRef);
binder->addMethod("syncArrayBufferDataToRuntime", SyncArrayBufferDataToRuntime);
binder->addMethod("evaluateClipDatasRealTime", EvaluateClipDatasRealTime);
binder->addMethod("updateAnimationNodeWorldMatix", UpdateAnimationNodeWorldMatix);
binder->addMethod("computeSubSkinnedData", ComputeSubSkinnedData);
binder->addMethod("culling", Culling);
binder->endToGlobal(object, "webglPlus", JSWebGLPlus::getInstance());
}
}
//------------------------------------------------------------------------------
//-----------------------------END FILE--------------------------------
+45
View File
@@ -0,0 +1,45 @@
/**
@file JSWebGLPlus.h
@brief
@author James
@version 1.0
@date 2019_8_24
*/
#ifndef __JSWebGLPlus_H__
#define __JSWebGLPlus_H__
#include "../JSObjBase.h"
#include <JavaScriptCore/JavaScriptCore.h>
/**
* @brief
*/
namespace laya
{
class JSWebGLPlus : public JCListNode
{
public:
void exportJS(JSContextRef ctx, JSObjectRef object);
static JSWebGLPlus* getInstance();
JSWebGLPlus();
~JSWebGLPlus();
public:
bool updateArrayBufferRef(int nID, bool bSyncToRender, JSValueRef pArrayBuffer);
public:
static JSWebGLPlus* s_pWebGLPlus;
};
}
//------------------------------------------------------------------------------
#endif //__JSWebGLPlus_H__
//-----------------------------END FILE--------------------------------