mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3-label-createfail
This commit is contained in:
commit
964713355b
|
@ -883,6 +883,10 @@
|
||||||
688669711AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
|
688669711AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
|
||||||
688669721AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
|
688669721AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
|
||||||
826294431AAF071500CB7CF7 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 826294421AAF071500CB7CF7 /* Security.framework */; };
|
826294431AAF071500CB7CF7 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 826294421AAF071500CB7CF7 /* Security.framework */; };
|
||||||
|
94D793D91B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */; };
|
||||||
|
94D793DA1B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */; };
|
||||||
|
94D793DB1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */; };
|
||||||
|
94D793DC1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */; };
|
||||||
A05FCACA177C124500BE600E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; };
|
A05FCACA177C124500BE600E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; };
|
||||||
A07A521E1783A1D20073F6A7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; };
|
A07A521E1783A1D20073F6A7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; };
|
||||||
A07A521F1783A1D20073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; };
|
A07A521F1783A1D20073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; };
|
||||||
|
@ -1945,6 +1949,10 @@
|
||||||
70A7F72D191D3E4900F0F206 /* shaderTest.psh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shaderTest.psh.h; sourceTree = "<group>"; };
|
70A7F72D191D3E4900F0F206 /* shaderTest.psh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shaderTest.psh.h; sourceTree = "<group>"; };
|
||||||
70A7F730191D421B00F0F206 /* ShaderTest.vsh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShaderTest.vsh.h; sourceTree = "<group>"; };
|
70A7F730191D421B00F0F206 /* ShaderTest.vsh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShaderTest.vsh.h; sourceTree = "<group>"; };
|
||||||
826294421AAF071500CB7CF7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
|
826294421AAF071500CB7CF7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
|
||||||
|
94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-CCDrawNode.cpp"; sourceTree = "<group>"; };
|
||||||
|
94D793D61B4B7A3600F60F10 /* Bug-CCDrawNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-CCDrawNode.h"; sourceTree = "<group>"; };
|
||||||
|
94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-PageViewLayout.cpp"; sourceTree = "<group>"; };
|
||||||
|
94D793D81B4B7A3600F60F10 /* Bug-PageViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-PageViewLayout.h"; sourceTree = "<group>"; };
|
||||||
A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
|
A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
|
||||||
A07A52291783A1D20073F6A7 /* cpp-tests iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
A07A52291783A1D20073F6A7 /* cpp-tests iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
A07A52B71783AE6D0073F6A7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
|
A07A52B71783AE6D0073F6A7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
|
@ -2733,6 +2741,10 @@
|
||||||
1AC3597618CECF0B00F37B72 /* BugsTest */ = {
|
1AC3597618CECF0B00F37B72 /* BugsTest */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */,
|
||||||
|
94D793D61B4B7A3600F60F10 /* Bug-CCDrawNode.h */,
|
||||||
|
94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */,
|
||||||
|
94D793D81B4B7A3600F60F10 /* Bug-PageViewLayout.h */,
|
||||||
1AC3597718CECF0B00F37B72 /* Bug-1159.cpp */,
|
1AC3597718CECF0B00F37B72 /* Bug-1159.cpp */,
|
||||||
1AC3597818CECF0B00F37B72 /* Bug-1159.h */,
|
1AC3597818CECF0B00F37B72 /* Bug-1159.h */,
|
||||||
1AC3597918CECF0B00F37B72 /* Bug-1174.cpp */,
|
1AC3597918CECF0B00F37B72 /* Bug-1174.cpp */,
|
||||||
|
@ -5388,6 +5400,7 @@
|
||||||
1AC35BEB18CECF0C00F37B72 /* CCControlSliderTest.cpp in Sources */,
|
1AC35BEB18CECF0C00F37B72 /* CCControlSliderTest.cpp in Sources */,
|
||||||
1AC35C4D18CECF0C00F37B72 /* SpineTest.cpp in Sources */,
|
1AC35C4D18CECF0C00F37B72 /* SpineTest.cpp in Sources */,
|
||||||
3E92EA821921A1400094CD21 /* Sprite3DTest.cpp in Sources */,
|
3E92EA821921A1400094CD21 /* Sprite3DTest.cpp in Sources */,
|
||||||
|
94D793DB1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */,
|
||||||
1AC35C1D18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */,
|
1AC35C1D18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */,
|
||||||
1AC35B6718CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */,
|
1AC35B6718CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */,
|
||||||
29080DB7191B595E0066F8DF /* UIListViewTest_Editor.cpp in Sources */,
|
29080DB7191B595E0066F8DF /* UIListViewTest_Editor.cpp in Sources */,
|
||||||
|
@ -5533,6 +5546,7 @@
|
||||||
1AC35B2518CECF0C00F37B72 /* ActionsProgressTest.cpp in Sources */,
|
1AC35B2518CECF0C00F37B72 /* ActionsProgressTest.cpp in Sources */,
|
||||||
1AC35B6518CECF0C00F37B72 /* EffectsTest.cpp in Sources */,
|
1AC35B6518CECF0C00F37B72 /* EffectsTest.cpp in Sources */,
|
||||||
1AC35B7118CECF0C00F37B72 /* TestHeaderLayer.cpp in Sources */,
|
1AC35B7118CECF0C00F37B72 /* TestHeaderLayer.cpp in Sources */,
|
||||||
|
94D793D91B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */,
|
||||||
29080D93191B595E0066F8DF /* CustomImageTest.cpp in Sources */,
|
29080D93191B595E0066F8DF /* CustomImageTest.cpp in Sources */,
|
||||||
1AC35B2118CECF0C00F37B72 /* ActionManagerTest.cpp in Sources */,
|
1AC35B2118CECF0C00F37B72 /* ActionManagerTest.cpp in Sources */,
|
||||||
1AC35C3D18CECF0C00F37B72 /* PhysicsTest.cpp in Sources */,
|
1AC35C3D18CECF0C00F37B72 /* PhysicsTest.cpp in Sources */,
|
||||||
|
@ -5673,6 +5687,7 @@
|
||||||
1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */,
|
1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */,
|
||||||
1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */,
|
1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */,
|
||||||
B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */,
|
B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */,
|
||||||
|
94D793DC1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */,
|
||||||
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */,
|
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */,
|
||||||
1AC35B4418CECF0C00F37B72 /* Bug-624.cpp in Sources */,
|
1AC35B4418CECF0C00F37B72 /* Bug-624.cpp in Sources */,
|
||||||
1AC35BF818CECF0C00F37B72 /* SocketIOTest.cpp in Sources */,
|
1AC35BF818CECF0C00F37B72 /* SocketIOTest.cpp in Sources */,
|
||||||
|
@ -5781,6 +5796,7 @@
|
||||||
1AC35BEA18CECF0C00F37B72 /* CCControlSceneManager.cpp in Sources */,
|
1AC35BEA18CECF0C00F37B72 /* CCControlSceneManager.cpp in Sources */,
|
||||||
182C5CBB1A95B30500C30D34 /* CocosStudio3DTest.cpp in Sources */,
|
182C5CBB1A95B30500C30D34 /* CocosStudio3DTest.cpp in Sources */,
|
||||||
1AC35B7418CECF0C00F37B72 /* TimelineCallbackTestLayer.cpp in Sources */,
|
1AC35B7418CECF0C00F37B72 /* TimelineCallbackTestLayer.cpp in Sources */,
|
||||||
|
94D793DA1B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */,
|
||||||
29080D9E191B595E0066F8DF /* CustomParticleWidgetReader.cpp in Sources */,
|
29080D9E191B595E0066F8DF /* CustomParticleWidgetReader.cpp in Sources */,
|
||||||
1AC35BFC18CECF0C00F37B72 /* NotificationCenterTest.cpp in Sources */,
|
1AC35BFC18CECF0C00F37B72 /* NotificationCenterTest.cpp in Sources */,
|
||||||
29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */,
|
29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */,
|
||||||
|
|
|
@ -40,6 +40,7 @@ Action::Action()
|
||||||
:_originalTarget(nullptr)
|
:_originalTarget(nullptr)
|
||||||
,_target(nullptr)
|
,_target(nullptr)
|
||||||
,_tag(Action::INVALID_TAG)
|
,_tag(Action::INVALID_TAG)
|
||||||
|
,_flags(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,16 @@ public:
|
||||||
* @param tag Used to identify the action easily.
|
* @param tag Used to identify the action easily.
|
||||||
*/
|
*/
|
||||||
inline void setTag(int tag) { _tag = tag; }
|
inline void setTag(int tag) { _tag = tag; }
|
||||||
|
/** Returns a flag field that is used to group the actions easily.
|
||||||
|
*
|
||||||
|
* @return A tag.
|
||||||
|
*/
|
||||||
|
inline unsigned int getFlags() const { return _flags; }
|
||||||
|
/** Changes the flag field that is used to group the actions easily.
|
||||||
|
*
|
||||||
|
* @param tag Used to identify the action easily.
|
||||||
|
*/
|
||||||
|
inline void setFlags(unsigned int flags) { _flags = flags; }
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
Action();
|
Action();
|
||||||
|
@ -159,6 +169,8 @@ protected:
|
||||||
Node *_target;
|
Node *_target;
|
||||||
/** The action tag. An identifier of the action. */
|
/** The action tag. An identifier of the action. */
|
||||||
int _tag;
|
int _tag;
|
||||||
|
/** The action flag field. To categorize action into certain groups.*/
|
||||||
|
unsigned int _flags;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CC_DISALLOW_COPY_AND_ASSIGN(Action);
|
CC_DISALLOW_COPY_AND_ASSIGN(Action);
|
||||||
|
|
|
@ -2270,6 +2270,7 @@ Animate::Animate()
|
||||||
, _executedLoops(0)
|
, _executedLoops(0)
|
||||||
, _animation(nullptr)
|
, _animation(nullptr)
|
||||||
, _frameDisplayedEvent(nullptr)
|
, _frameDisplayedEvent(nullptr)
|
||||||
|
, _currFrameIndex(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2383,7 +2384,8 @@ void Animate::update(float t)
|
||||||
float splitTime = _splitTimes->at(i);
|
float splitTime = _splitTimes->at(i);
|
||||||
|
|
||||||
if( splitTime <= t ) {
|
if( splitTime <= t ) {
|
||||||
AnimationFrame* frame = frames.at(i);
|
_currFrameIndex = i;
|
||||||
|
AnimationFrame* frame = frames.at(_currFrameIndex);
|
||||||
frameToDisplay = frame->getSpriteFrame();
|
frameToDisplay = frame->getSpriteFrame();
|
||||||
static_cast<Sprite*>(_target)->setSpriteFrame(frameToDisplay);
|
static_cast<Sprite*>(_target)->setSpriteFrame(frameToDisplay);
|
||||||
|
|
||||||
|
|
|
@ -1439,6 +1439,11 @@ public:
|
||||||
Animation* getAnimation() { return _animation; }
|
Animation* getAnimation() { return _animation; }
|
||||||
const Animation* getAnimation() const { return _animation; }
|
const Animation* getAnimation() const { return _animation; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the index of sprite frame currently displayed.
|
||||||
|
* @return int the index of sprite frame currently displayed.
|
||||||
|
*/
|
||||||
|
int getCurrentFrameIndex() { return _currFrameIndex; }
|
||||||
//
|
//
|
||||||
// Overrides
|
// Overrides
|
||||||
//
|
//
|
||||||
|
@ -1462,6 +1467,7 @@ protected:
|
||||||
std::vector<float>* _splitTimes;
|
std::vector<float>* _splitTimes;
|
||||||
int _nextFrame;
|
int _nextFrame;
|
||||||
SpriteFrame* _origFrame;
|
SpriteFrame* _origFrame;
|
||||||
|
int _currFrameIndex;
|
||||||
unsigned int _executedLoops;
|
unsigned int _executedLoops;
|
||||||
Animation* _animation;
|
Animation* _animation;
|
||||||
|
|
||||||
|
|
|
@ -315,6 +315,37 @@ void ActionManager::removeAllActionsByTag(int tag, Node *target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActionManager::removeActionsByFlags(unsigned int flags, Node *target)
|
||||||
|
{
|
||||||
|
if (flags == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CCASSERT(target != nullptr, "");
|
||||||
|
|
||||||
|
tHashElement *element = nullptr;
|
||||||
|
HASH_FIND_PTR(_targets, &target, element);
|
||||||
|
|
||||||
|
if (element)
|
||||||
|
{
|
||||||
|
auto limit = element->actions->num;
|
||||||
|
for (int i = 0; i < limit;)
|
||||||
|
{
|
||||||
|
Action *action = (Action*)element->actions->arr[i];
|
||||||
|
|
||||||
|
if ((action->getFlags() & flags) != 0 && action->getOriginalTarget() == target)
|
||||||
|
{
|
||||||
|
removeActionAtIndex(i, element);
|
||||||
|
--limit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get
|
// get
|
||||||
|
|
||||||
// FIXME: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
// FIXME: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer
|
||||||
|
|
|
@ -114,6 +114,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void removeAllActionsByTag(int tag, Node *target);
|
void removeAllActionsByTag(int tag, Node *target);
|
||||||
|
|
||||||
|
/** Removes all actions matching at least one bit in flags and the target.
|
||||||
|
*
|
||||||
|
* @param flags The flag field to match the actions' flags based on bitwise AND.
|
||||||
|
* @param target A certain target.
|
||||||
|
* @js NA
|
||||||
|
*/
|
||||||
|
void removeActionsByFlags(unsigned int flags, Node *target);
|
||||||
|
|
||||||
/** Gets an action given its tag an a target.
|
/** Gets an action given its tag an a target.
|
||||||
*
|
*
|
||||||
* @param tag The action's tag.
|
* @param tag The action's tag.
|
||||||
|
|
|
@ -374,7 +374,9 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
|
||||||
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR);
|
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR);
|
||||||
glProgram->use();
|
glProgram->use();
|
||||||
glProgram->setUniformsForBuiltins(transform);
|
glProgram->setUniformsForBuiltins(transform);
|
||||||
|
|
||||||
|
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||||
|
|
||||||
if (_dirtyGLLine)
|
if (_dirtyGLLine)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
|
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
|
||||||
|
@ -415,7 +417,9 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
|
||||||
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE);
|
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE);
|
||||||
glProgram->use();
|
glProgram->use();
|
||||||
glProgram->setUniformsForBuiltins(transform);
|
glProgram->setUniformsForBuiltins(transform);
|
||||||
|
|
||||||
|
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
|
||||||
|
|
||||||
if (_dirtyGLPoint)
|
if (_dirtyGLPoint)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
|
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
|
||||||
|
|
|
@ -796,19 +796,7 @@ void Label::updateQuads()
|
||||||
_reusedRect.size.width = letterDef.width;
|
_reusedRect.size.width = letterDef.width;
|
||||||
_reusedRect.origin.x = letterDef.U;
|
_reusedRect.origin.x = letterDef.U;
|
||||||
_reusedRect.origin.y = letterDef.V;
|
_reusedRect.origin.y = letterDef.V;
|
||||||
if (_labelHeight > 0.f)
|
|
||||||
{
|
|
||||||
if (_lettersInfo[ctr].position.y > _contentSize.height)
|
|
||||||
{
|
|
||||||
auto clipTop = _lettersInfo[ctr].position.y - _contentSize.height;
|
|
||||||
_reusedRect.origin.y += clipTop;
|
|
||||||
_lettersInfo[ctr].position.y -= clipTop;
|
|
||||||
}
|
|
||||||
if (_lettersInfo[ctr].position.y - letterDef.height < 0.f)
|
|
||||||
{
|
|
||||||
_reusedRect.size.height = _lettersInfo[ctr].position.y < 0.f ? 0.f : _lettersInfo[ctr].position.y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_reusedLetter->setTextureRect(_reusedRect,false,_reusedRect.size);
|
_reusedLetter->setTextureRect(_reusedRect,false,_reusedRect.size);
|
||||||
|
|
||||||
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
_reusedLetter->setPosition(_lettersInfo[ctr].position);
|
||||||
|
|
|
@ -316,7 +316,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
|
||||||
auto labelHeightPixel = theLabel->_labelHeight * contentScaleFactor;
|
auto labelHeightPixel = theLabel->_labelHeight * contentScaleFactor;
|
||||||
if (totalHeight > labelHeightPixel)
|
if (totalHeight > labelHeightPixel)
|
||||||
{
|
{
|
||||||
int numLines = MIN(ceil(labelHeightPixel / theLabel->_commonLineHeight), theLabel->_currNumLines);
|
int numLines = labelHeightPixel / theLabel->_commonLineHeight;
|
||||||
totalHeight = numLines * theLabel->_commonLineHeight;
|
totalHeight = numLines * theLabel->_commonLineHeight;
|
||||||
}
|
}
|
||||||
switch (theLabel->_vAlignment)
|
switch (theLabel->_vAlignment)
|
||||||
|
@ -379,7 +379,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
|
||||||
nextFontPositionY -= theLabel->_commonLineHeight;
|
nextFontPositionY -= theLabel->_commonLineHeight;
|
||||||
|
|
||||||
theLabel->recordPlaceholderInfo(i);
|
theLabel->recordPlaceholderInfo(i);
|
||||||
if(nextFontPositionY < 0.f)
|
if (nextFontPositionY < theLabel->_commonLineHeight)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
lineStart = true;
|
lineStart = true;
|
||||||
|
|
|
@ -1576,6 +1576,14 @@ void Node::stopAllActionsByTag(int tag)
|
||||||
_actionManager->removeAllActionsByTag(tag, this);
|
_actionManager->removeAllActionsByTag(tag, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Node::stopActionsByFlags(unsigned int flags)
|
||||||
|
{
|
||||||
|
if (flags > 0)
|
||||||
|
{
|
||||||
|
_actionManager->removeActionsByFlags(flags, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Action * Node::getActionByTag(int tag)
|
Action * Node::getActionByTag(int tag)
|
||||||
{
|
{
|
||||||
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
CCASSERT( tag != Action::INVALID_TAG, "Invalid tag");
|
||||||
|
|
|
@ -1228,6 +1228,13 @@ public:
|
||||||
*/
|
*/
|
||||||
void stopAllActionsByTag(int tag);
|
void stopAllActionsByTag(int tag);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all actions from the running action list by its flags.
|
||||||
|
*
|
||||||
|
* @param flags A flag field that removes actions based on bitwise AND.
|
||||||
|
*/
|
||||||
|
void stopActionsByFlags(unsigned int flags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an action from the running action list by its tag.
|
* Gets an action from the running action list by its tag.
|
||||||
*
|
*
|
||||||
|
|
|
@ -288,7 +288,7 @@ Sprite::Sprite(void)
|
||||||
, _insideBounds(true)
|
, _insideBounds(true)
|
||||||
{
|
{
|
||||||
#if CC_SPRITE_DEBUG_DRAW
|
#if CC_SPRITE_DEBUG_DRAW
|
||||||
debugDraw(true)
|
debugDraw(true);
|
||||||
#endif //CC_SPRITE_DEBUG_DRAW
|
#endif //CC_SPRITE_DEBUG_DRAW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -454,7 +454,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
|
||||||
// Y
|
// Y
|
||||||
int y = attributeDict["y"].asInt();
|
int y = attributeDict["y"].asInt();
|
||||||
|
|
||||||
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().x - attributeDict["height"].asInt());
|
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt());
|
||||||
p = CC_POINT_PIXELS_TO_POINTS(p);
|
p = CC_POINT_PIXELS_TO_POINTS(p);
|
||||||
dict["x"] = Value(p.x);
|
dict["x"] = Value(p.x);
|
||||||
dict["y"] = Value(p.y);
|
dict["y"] = Value(p.y);
|
||||||
|
|
|
@ -216,73 +216,24 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
|
||||||
else
|
else
|
||||||
mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1).c_str();
|
mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1).c_str();
|
||||||
|
|
||||||
ObjLoader::shapes_t shapes;
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtlPath.c_str());
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
auto ret = tinyobj::LoadObj(shapes, materials, fullPath.c_str(), mtlPath.c_str());
|
||||||
if (ret.empty())
|
if (ret.empty())
|
||||||
{
|
{
|
||||||
//fill data
|
//fill data
|
||||||
MeshData* meshdata = new (std::nothrow) MeshData();
|
//convert material
|
||||||
MeshVertexAttrib attrib;
|
|
||||||
attrib.size = 3;
|
|
||||||
attrib.type = GL_FLOAT;
|
|
||||||
if (shapes.positions.size())
|
|
||||||
{
|
|
||||||
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
|
|
||||||
attrib.attribSizeBytes = attrib.size * sizeof(float);
|
|
||||||
meshdata->attribs.push_back(attrib);
|
|
||||||
|
|
||||||
}
|
|
||||||
bool hasnormal = false, hastex = false;
|
|
||||||
if (shapes.normals.size())
|
|
||||||
{
|
|
||||||
hasnormal = true;
|
|
||||||
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
|
|
||||||
attrib.attribSizeBytes = attrib.size * sizeof(float);;
|
|
||||||
meshdata->attribs.push_back(attrib);
|
|
||||||
}
|
|
||||||
if (shapes.texcoords.size())
|
|
||||||
{
|
|
||||||
hastex = true;
|
|
||||||
attrib.size = 2;
|
|
||||||
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
|
|
||||||
attrib.attribSizeBytes = attrib.size * sizeof(float);
|
|
||||||
meshdata->attribs.push_back(attrib);
|
|
||||||
}
|
|
||||||
auto vertexNum = shapes.positions.size() / 3;
|
|
||||||
for(unsigned int i = 0; i < vertexNum; i++)
|
|
||||||
{
|
|
||||||
meshdata->vertex.push_back(shapes.positions[i * 3]);
|
|
||||||
meshdata->vertex.push_back(shapes.positions[i * 3 + 1]);
|
|
||||||
meshdata->vertex.push_back(shapes.positions[i * 3 + 2]);
|
|
||||||
|
|
||||||
if (hasnormal)
|
|
||||||
{
|
|
||||||
meshdata->vertex.push_back(shapes.normals[i * 3]);
|
|
||||||
meshdata->vertex.push_back(shapes.normals[i * 3 + 1]);
|
|
||||||
meshdata->vertex.push_back(shapes.normals[i * 3 + 2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hastex)
|
|
||||||
{
|
|
||||||
meshdata->vertex.push_back(shapes.texcoords[i * 2]);
|
|
||||||
meshdata->vertex.push_back(shapes.texcoords[i * 2 + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
meshdatas.meshDatas.push_back(meshdata);
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char str[20];
|
char str[20];
|
||||||
std::string dir = "";
|
std::string dir = "";
|
||||||
auto last = fullPath.rfind("/");
|
auto last = fullPath.rfind("/");
|
||||||
if (last != -1)
|
if (last != -1)
|
||||||
dir = fullPath.substr(0, last + 1);
|
dir = fullPath.substr(0, last + 1);
|
||||||
|
for (auto& material : materials) {
|
||||||
for (const auto& it : shapes.shapes)
|
|
||||||
{
|
|
||||||
NMaterialData materialdata;
|
NMaterialData materialdata;
|
||||||
|
|
||||||
NTextureData tex;
|
NTextureData tex;
|
||||||
tex.filename = it.material.diffuse_texname.empty() ? it.material.diffuse_texname : dir + it.material.diffuse_texname;
|
tex.filename = material.diffuse_texname.empty() ? material.diffuse_texname : dir + material.diffuse_texname;
|
||||||
tex.type = NTextureData::Usage::Diffuse;
|
tex.type = NTextureData::Usage::Diffuse;
|
||||||
tex.wrapS = GL_CLAMP_TO_EDGE;
|
tex.wrapS = GL_CLAMP_TO_EDGE;
|
||||||
tex.wrapT = GL_CLAMP_TO_EDGE;
|
tex.wrapT = GL_CLAMP_TO_EDGE;
|
||||||
|
@ -290,19 +241,91 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
|
||||||
sprintf(str, "%d", i++);
|
sprintf(str, "%d", i++);
|
||||||
materialdata.textures.push_back(tex);
|
materialdata.textures.push_back(tex);
|
||||||
materialdata.id = str;
|
materialdata.id = str;
|
||||||
|
material.name = str;
|
||||||
materialdatas.materials.push_back(materialdata);
|
materialdatas.materials.push_back(materialdata);
|
||||||
|
|
||||||
meshdata->subMeshIndices.push_back(it.mesh.indices);
|
|
||||||
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), it.mesh.indices));
|
|
||||||
meshdata->subMeshIds.push_back(str);
|
|
||||||
auto node = new (std::nothrow) NodeData();
|
|
||||||
auto modelnode = new (std::nothrow) ModelData();
|
|
||||||
modelnode->matrialId = str;
|
|
||||||
modelnode->subMeshId = str;
|
|
||||||
node->id = it.name;
|
|
||||||
node->modelNodeDatas.push_back(modelnode);
|
|
||||||
nodedatas.nodes.push_back(node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//convert mesh
|
||||||
|
i = 0;
|
||||||
|
for (auto& shape : shapes) {
|
||||||
|
auto mesh = shape.mesh;
|
||||||
|
MeshData* meshdata = new (std::nothrow) MeshData();
|
||||||
|
MeshVertexAttrib attrib;
|
||||||
|
attrib.size = 3;
|
||||||
|
attrib.type = GL_FLOAT;
|
||||||
|
|
||||||
|
if (mesh.positions.size())
|
||||||
|
{
|
||||||
|
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
|
||||||
|
attrib.attribSizeBytes = attrib.size * sizeof(float);
|
||||||
|
meshdata->attribs.push_back(attrib);
|
||||||
|
|
||||||
|
}
|
||||||
|
bool hasnormal = false, hastex = false;
|
||||||
|
if (mesh.normals.size())
|
||||||
|
{
|
||||||
|
hasnormal = true;
|
||||||
|
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
|
||||||
|
attrib.attribSizeBytes = attrib.size * sizeof(float);;
|
||||||
|
meshdata->attribs.push_back(attrib);
|
||||||
|
}
|
||||||
|
if (mesh.texcoords.size())
|
||||||
|
{
|
||||||
|
hastex = true;
|
||||||
|
attrib.size = 2;
|
||||||
|
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
|
||||||
|
attrib.attribSizeBytes = attrib.size * sizeof(float);
|
||||||
|
meshdata->attribs.push_back(attrib);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vertexNum = mesh.positions.size() / 3;
|
||||||
|
for(unsigned int k = 0; k < vertexNum; k++)
|
||||||
|
{
|
||||||
|
meshdata->vertex.push_back(mesh.positions[k * 3]);
|
||||||
|
meshdata->vertex.push_back(mesh.positions[k * 3 + 1]);
|
||||||
|
meshdata->vertex.push_back(mesh.positions[k * 3 + 2]);
|
||||||
|
|
||||||
|
if (hasnormal)
|
||||||
|
{
|
||||||
|
meshdata->vertex.push_back(mesh.normals[k * 3]);
|
||||||
|
meshdata->vertex.push_back(mesh.normals[k * 3 + 1]);
|
||||||
|
meshdata->vertex.push_back(mesh.normals[k * 3 + 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hastex)
|
||||||
|
{
|
||||||
|
meshdata->vertex.push_back(mesh.texcoords[k * 2]);
|
||||||
|
meshdata->vertex.push_back(mesh.texcoords[k * 2 + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//split into submesh according to material
|
||||||
|
std::map<int, std::vector<unsigned short> > subMeshMap;
|
||||||
|
for (size_t k = 0; k < mesh.material_ids.size(); k++) {
|
||||||
|
int id = mesh.material_ids[k];
|
||||||
|
size_t idx = k * 3;
|
||||||
|
subMeshMap[id].push_back(mesh.indices[idx]);
|
||||||
|
subMeshMap[id].push_back(mesh.indices[idx + 1]);
|
||||||
|
subMeshMap[id].push_back(mesh.indices[idx + 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto node = new (std::nothrow) NodeData();
|
||||||
|
node->id = shape.name;
|
||||||
|
for (auto& submesh : subMeshMap) {
|
||||||
|
meshdata->subMeshIndices.push_back(submesh.second);
|
||||||
|
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), submesh.second));
|
||||||
|
sprintf(str, "%d", i++);
|
||||||
|
meshdata->subMeshIds.push_back(str);
|
||||||
|
|
||||||
|
auto modelnode = new (std::nothrow) ModelData();
|
||||||
|
modelnode->matrialId = submesh.first == -1 ? "" : materials[submesh.first].name;
|
||||||
|
modelnode->subMeshId = str;
|
||||||
|
node->modelNodeDatas.push_back(modelnode);
|
||||||
|
}
|
||||||
|
nodedatas.nodes.push_back(node);
|
||||||
|
meshdatas.meshDatas.push_back(meshdata);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
CCLOG("warning: load %s file error: %s", fullPath.c_str(), ret.c_str());
|
CCLOG("warning: load %s file error: %s", fullPath.c_str(), ret.c_str());
|
||||||
|
|
|
@ -273,6 +273,9 @@ void Mesh::setTexture(Texture2D* tex)
|
||||||
// Texture must be saved for future use
|
// Texture must be saved for future use
|
||||||
// it doesn't matter if the material is already set or not
|
// it doesn't matter if the material is already set or not
|
||||||
// This functionality is added for compatibility issues
|
// This functionality is added for compatibility issues
|
||||||
|
if (tex == nullptr)
|
||||||
|
tex = getDummyTexture();
|
||||||
|
|
||||||
if (tex != _texture)
|
if (tex != _texture)
|
||||||
{
|
{
|
||||||
CC_SAFE_RETAIN(tex);
|
CC_SAFE_RETAIN(tex);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,40 +1,19 @@
|
||||||
//
|
//
|
||||||
// Copyright 2012-2013, Syoyo Fujita.
|
// Copyright 2012-2015, Syoyo Fujita.
|
||||||
//
|
//
|
||||||
// Licensed under 2-clause BSD liecense.
|
// Licensed under 2-clause BSD liecense.
|
||||||
//
|
//
|
||||||
// copied from Syoyo Fujita
|
//https://github.com/syoyo/tinyobjloader
|
||||||
// https://github.com/syoyo/tinyobjloader
|
#ifndef _TINY_OBJ_LOADER_H
|
||||||
|
#define _TINY_OBJ_LOADER_H
|
||||||
#ifndef __CCOBJLOADER_H__
|
|
||||||
#define __CCOBJLOADER_H__
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "base/ccTypes.h"
|
|
||||||
|
|
||||||
NS_CC_BEGIN
|
namespace tinyobj {
|
||||||
|
|
||||||
/**
|
typedef struct {
|
||||||
* @addtogroup _3d
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief .obj file Loader
|
|
||||||
* @js NA
|
|
||||||
* @lua NA
|
|
||||||
**/
|
|
||||||
class ObjLoader
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* model's material struct
|
|
||||||
**/
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
float ambient[3];
|
float ambient[3];
|
||||||
|
@ -43,8 +22,8 @@ public:
|
||||||
float transmittance[3];
|
float transmittance[3];
|
||||||
float emission[3];
|
float emission[3];
|
||||||
float shininess;
|
float shininess;
|
||||||
float ior; // index of refraction
|
float ior; // index of refraction
|
||||||
float dissolve; // 1 == opaque; 0 == fully transparent
|
float dissolve; // 1 == opaque; 0 == fully transparent
|
||||||
// illumination model (see http://www.fileformat.info/format/material/)
|
// illumination model (see http://www.fileformat.info/format/material/)
|
||||||
int illum;
|
int illum;
|
||||||
|
|
||||||
|
@ -55,61 +34,62 @@ public:
|
||||||
std::map<std::string, std::string> unknown_parameter;
|
std::map<std::string, std::string> unknown_parameter;
|
||||||
} material_t;
|
} material_t;
|
||||||
|
|
||||||
/**
|
typedef struct {
|
||||||
* model's indices struct
|
std::vector<float> positions;
|
||||||
**/
|
std::vector<float> normals;
|
||||||
typedef struct
|
std::vector<float> texcoords;
|
||||||
{
|
std::vector<unsigned short> indices;
|
||||||
std::vector<unsigned short> indices;
|
std::vector<int> material_ids; // per-mesh material ID
|
||||||
} mesh_t;
|
} mesh_t;
|
||||||
|
|
||||||
/**
|
typedef struct {
|
||||||
* model's shape struct
|
std::string name;
|
||||||
**/
|
mesh_t mesh;
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
material_t material;
|
|
||||||
mesh_t mesh;
|
|
||||||
} shape_t;
|
} shape_t;
|
||||||
|
|
||||||
/**
|
class MaterialReader {
|
||||||
* model's shapes struct
|
public:
|
||||||
**/
|
MaterialReader() {}
|
||||||
typedef struct
|
virtual ~MaterialReader() {}
|
||||||
{
|
|
||||||
std::vector<float> positions;
|
|
||||||
std::vector<float> normals;
|
|
||||||
std::vector<float> texcoords;
|
|
||||||
|
|
||||||
std::vector<shape_t> shapes;
|
virtual std::string operator()(const std::string &matId,
|
||||||
|
std::vector<material_t> &materials,
|
||||||
void reset()
|
std::map<std::string, int> &matMap) = 0;
|
||||||
{
|
};
|
||||||
positions.clear();
|
|
||||||
normals.clear();
|
|
||||||
texcoords.clear();
|
|
||||||
shapes.clear();
|
|
||||||
}
|
|
||||||
}shapes_t;
|
|
||||||
|
|
||||||
/**
|
class MaterialFileReader : public MaterialReader {
|
||||||
* Loads .obj from a file.
|
public:
|
||||||
* @param shapes will be filled with parsed shape data
|
MaterialFileReader(const std::string &mtl_basepath)
|
||||||
* @param filename the .obj file path .
|
: m_mtlBasePath(mtl_basepath) {}
|
||||||
* @param mtl_basepath It's optional, and used for base path for .mtl file
|
virtual ~MaterialFileReader() {}
|
||||||
* @return The function returns error string, return empty string when loading .obj success.
|
virtual std::string operator()(const std::string &matId,
|
||||||
*/
|
std::vector<material_t> &materials,
|
||||||
static std::string LoadObj(
|
std::map<std::string, int> &matMap);
|
||||||
shapes_t& shapes, // [output]
|
|
||||||
const char* filename,
|
private:
|
||||||
const char* mtl_basepath = NULL);
|
std::string m_mtlBasePath;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Loads .obj from a file.
|
||||||
|
/// 'shapes' will be filled with parsed shape data
|
||||||
|
/// The function returns error string.
|
||||||
|
/// Returns empty string when loading .obj success.
|
||||||
|
/// 'mtl_basepath' is optional, and used for base path for .mtl file.
|
||||||
|
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
||||||
|
std::vector<material_t> &materials, // [output]
|
||||||
|
const char *filename, const char *mtl_basepath = NULL);
|
||||||
|
|
||||||
|
/// Loads object from a std::istream, uses GetMtlIStreamFn to retrieve
|
||||||
|
/// std::istream for materials.
|
||||||
|
/// Returns empty string when loading .obj success.
|
||||||
|
std::string LoadObj(std::vector<shape_t> &shapes, // [output]
|
||||||
|
std::vector<material_t> &materials, // [output]
|
||||||
|
std::istream &inStream, MaterialReader &readMatFn);
|
||||||
|
|
||||||
|
/// Loads materials into std::map
|
||||||
|
/// Returns an empty string if successful
|
||||||
|
std::string LoadMtl(std::map<std::string, int> &material_map,
|
||||||
|
std::vector<material_t> &materials, std::istream &inStream);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
#endif // _TINY_OBJ_LOADER_H
|
||||||
|
|
||||||
// end of 3d group
|
|
||||||
/// @}
|
|
||||||
|
|
||||||
NS_CC_END
|
|
||||||
|
|
||||||
#endif // _TINY_OBJ_LOADER_H
|
|
||||||
|
|
|
@ -352,8 +352,7 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
|
||||||
if (modeldata->matrialId == "" && materialdatas.materials.size())
|
if (modeldata->matrialId == "" && materialdatas.materials.size())
|
||||||
{
|
{
|
||||||
const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||||
if (!textureData->filename.empty())
|
mesh->setTexture(textureData->filename);
|
||||||
mesh->setTexture(textureData->filename);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -361,9 +360,10 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
|
||||||
if(materialData)
|
if(materialData)
|
||||||
{
|
{
|
||||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||||
if(textureData && !textureData->filename.empty())
|
if(textureData)
|
||||||
{
|
{
|
||||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
mesh->setTexture(textureData->filename);
|
||||||
|
auto tex = mesh->getTexture();
|
||||||
if(tex)
|
if(tex)
|
||||||
{
|
{
|
||||||
Texture2D::TexParams texParams;
|
Texture2D::TexParams texParams;
|
||||||
|
@ -372,10 +372,8 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c
|
||||||
texParams.wrapS = textureData->wrapS;
|
texParams.wrapS = textureData->wrapS;
|
||||||
texParams.wrapT = textureData->wrapT;
|
texParams.wrapT = textureData->wrapT;
|
||||||
tex->setTexParameters(texParams);
|
tex->setTexParameters(texParams);
|
||||||
mesh->setTexture(tex);
|
|
||||||
mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
|
mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -506,9 +504,10 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
||||||
if(materialData)
|
if(materialData)
|
||||||
{
|
{
|
||||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||||
if(textureData && !textureData->filename.empty())
|
if(textureData)
|
||||||
{
|
{
|
||||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
mesh->setTexture(textureData->filename);
|
||||||
|
auto tex = mesh->getTexture();
|
||||||
if(tex)
|
if(tex)
|
||||||
{
|
{
|
||||||
Texture2D::TexParams texParams;
|
Texture2D::TexParams texParams;
|
||||||
|
@ -517,10 +516,8 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
||||||
texParams.wrapS = textureData->wrapS;
|
texParams.wrapS = textureData->wrapS;
|
||||||
texParams.wrapT = textureData->wrapT;
|
texParams.wrapT = textureData->wrapT;
|
||||||
tex->setTexParameters(texParams);
|
tex->setTexParameters(texParams);
|
||||||
mesh->setTexture(tex);
|
|
||||||
mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
|
mesh->_isTransparent = (materialData->getTextureData(NTextureData::Usage::Transparency) != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -982,7 +979,10 @@ static GLProgramState* getGLProgramStateForAttribs(MeshVertexData* meshVertexDat
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shader = GLProgram::SHADER_3D_POSITION;
|
if (hasNormal && usesLight)
|
||||||
|
shader = GLProgram::SHADER_3D_POSITION_NORMAL;
|
||||||
|
else
|
||||||
|
shader = GLProgram::SHADER_3D_POSITION;
|
||||||
}
|
}
|
||||||
|
|
||||||
CCASSERT(shader, "Couldn't find shader for sprite");
|
CCASSERT(shader, "Couldn't find shader for sprite");
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "platform/CCPlatformConfig.h"
|
#include "platform/CCPlatformConfig.h"
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||||
|
|
||||||
|
@ -61,8 +62,110 @@ AudioEngine::ProfileHelper* AudioEngine::_defaultProfileHelper = nullptr;
|
||||||
std::unordered_map<int, AudioEngine::AudioInfo> AudioEngine::_audioIDInfoMap;
|
std::unordered_map<int, AudioEngine::AudioInfo> AudioEngine::_audioIDInfoMap;
|
||||||
AudioEngineImpl* AudioEngine::_audioEngineImpl = nullptr;
|
AudioEngineImpl* AudioEngine::_audioEngineImpl = nullptr;
|
||||||
|
|
||||||
|
AudioEngine::AudioEngineThreadPool* AudioEngine::s_threadPool = nullptr;
|
||||||
|
|
||||||
|
class AudioEngine::AudioEngineThreadPool
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AudioEngineThreadPool(bool detach)
|
||||||
|
: _numThread(6)
|
||||||
|
, _detach(detach)
|
||||||
|
{
|
||||||
|
s_threadPool = this;
|
||||||
|
|
||||||
|
_threads.reserve(_numThread);
|
||||||
|
_tasks.reserve(_numThread);
|
||||||
|
|
||||||
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
|
_tasks.push_back(nullptr);
|
||||||
|
_threads.push_back(std::thread(std::bind(&AudioEngineThreadPool::threadFunc, this, index)));
|
||||||
|
if (_detach)
|
||||||
|
{
|
||||||
|
_threads[index].detach();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTask(const std::function<void()> &task){
|
||||||
|
_taskMutex.lock();
|
||||||
|
int targetIndex = -1;
|
||||||
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
|
if (_tasks[index] == nullptr) {
|
||||||
|
targetIndex = index;
|
||||||
|
_tasks[index] = task;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (targetIndex == -1) {
|
||||||
|
_tasks.push_back(task);
|
||||||
|
_threads.push_back(std::thread(std::bind(&AudioEngineThreadPool::threadFunc, this, _numThread)));
|
||||||
|
if (_detach)
|
||||||
|
{
|
||||||
|
_threads[_numThread].detach();
|
||||||
|
}
|
||||||
|
_numThread++;
|
||||||
|
}
|
||||||
|
_taskMutex.unlock();
|
||||||
|
_sleepCondition.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroy()
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lk(_sleepMutex);
|
||||||
|
_sleepCondition.notify_all();
|
||||||
|
|
||||||
|
if (!_detach)
|
||||||
|
{
|
||||||
|
for (int index = 0; index < _numThread; ++index) {
|
||||||
|
_threads[index].join();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::thread> _threads;
|
||||||
|
std::vector< std::function<void()> > _tasks;
|
||||||
|
|
||||||
|
void threadFunc(int index)
|
||||||
|
{
|
||||||
|
while (s_threadPool == this) {
|
||||||
|
std::function<void()> task = nullptr;
|
||||||
|
_taskMutex.lock();
|
||||||
|
task = _tasks[index];
|
||||||
|
_taskMutex.unlock();
|
||||||
|
|
||||||
|
if (nullptr == task)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lk(_sleepMutex);
|
||||||
|
_sleepCondition.wait(lk);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
task();
|
||||||
|
|
||||||
|
_taskMutex.lock();
|
||||||
|
_tasks[index] = nullptr;
|
||||||
|
_taskMutex.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int _numThread;
|
||||||
|
|
||||||
|
std::mutex _taskMutex;
|
||||||
|
std::mutex _sleepMutex;
|
||||||
|
std::condition_variable _sleepCondition;
|
||||||
|
bool _detach;
|
||||||
|
};
|
||||||
|
|
||||||
void AudioEngine::end()
|
void AudioEngine::end()
|
||||||
{
|
{
|
||||||
|
if (s_threadPool)
|
||||||
|
{
|
||||||
|
s_threadPool->destroy();
|
||||||
|
delete s_threadPool;
|
||||||
|
s_threadPool = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
delete _audioEngineImpl;
|
delete _audioEngineImpl;
|
||||||
_audioEngineImpl = nullptr;
|
_audioEngineImpl = nullptr;
|
||||||
|
|
||||||
|
@ -82,6 +185,18 @@ bool AudioEngine::lazyInit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||||
|
if (_audioEngineImpl && s_threadPool == nullptr)
|
||||||
|
{
|
||||||
|
s_threadPool = new (std::nothrow) AudioEngineThreadPool(true);
|
||||||
|
}
|
||||||
|
#elif CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID
|
||||||
|
if (_audioEngineImpl && s_threadPool == nullptr)
|
||||||
|
{
|
||||||
|
s_threadPool = new (std::nothrow) AudioEngineThreadPool(false);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,4 +530,28 @@ AudioProfile* AudioEngine::getProfile(const std::string &name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngine::preload(const std::string& filePath)
|
||||||
|
{
|
||||||
|
lazyInit();
|
||||||
|
|
||||||
|
if (_audioEngineImpl)
|
||||||
|
{
|
||||||
|
if (!FileUtils::getInstance()->isFileExist(filePath)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_audioEngineImpl->preload(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AudioEngine::addTask(const std::function<void()> &task)
|
||||||
|
{
|
||||||
|
lazyInit();
|
||||||
|
|
||||||
|
if (_audioEngineImpl && s_threadPool)
|
||||||
|
{
|
||||||
|
s_threadPool->addTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2014 Chukong Technologies Inc.
|
Copyright (c) 2014-2015 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
@ -432,4 +432,9 @@ void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void (i
|
||||||
_audioPlayers[audioID]._finishCallback = callback;
|
_audioPlayers[audioID]._finishCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioEngineImpl::preload(const std::string& filePath)
|
||||||
|
{
|
||||||
|
CCLOG("Preload not support on Anroid");
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
Copyright (c) 2014 Chukong Technologies Inc.
|
Copyright (c) 2014-2015 Chukong Technologies Inc.
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
http://www.cocos2d-x.org
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ public:
|
||||||
|
|
||||||
void uncache(const std::string& filePath){}
|
void uncache(const std::string& filePath){}
|
||||||
void uncacheAll(){}
|
void uncacheAll(){}
|
||||||
|
void preload(const std::string& filePath);
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -38,8 +38,6 @@ NS_CC_BEGIN
|
||||||
namespace experimental{
|
namespace experimental{
|
||||||
#define MAX_AUDIOINSTANCES 24
|
#define MAX_AUDIOINSTANCES 24
|
||||||
|
|
||||||
class AudioEngineThreadPool;
|
|
||||||
|
|
||||||
class AudioEngineImpl : public cocos2d::Ref
|
class AudioEngineImpl : public cocos2d::Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -61,14 +59,12 @@ public:
|
||||||
|
|
||||||
void uncache(const std::string& filePath);
|
void uncache(const std::string& filePath);
|
||||||
void uncacheAll();
|
void uncacheAll();
|
||||||
|
AudioCache* preload(const std::string& filePath);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _play2d(AudioCache *cache, int audioID);
|
void _play2d(AudioCache *cache, int audioID);
|
||||||
|
|
||||||
AudioEngineThreadPool* _threadPool;
|
|
||||||
|
|
||||||
ALuint _alSources[MAX_AUDIOINSTANCES];
|
ALuint _alSources[MAX_AUDIOINSTANCES];
|
||||||
|
|
||||||
//source,used
|
//source,used
|
||||||
|
|
|
@ -42,93 +42,6 @@ using namespace cocos2d::experimental;
|
||||||
static ALCdevice *s_ALDevice = nullptr;
|
static ALCdevice *s_ALDevice = nullptr;
|
||||||
static ALCcontext *s_ALContext = nullptr;
|
static ALCcontext *s_ALContext = nullptr;
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
namespace experimental {
|
|
||||||
class AudioEngineThreadPool
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AudioEngineThreadPool()
|
|
||||||
: _running(true)
|
|
||||||
, _numThread(6)
|
|
||||||
{
|
|
||||||
_threads.reserve(_numThread);
|
|
||||||
_tasks.reserve(_numThread);
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_tasks.push_back(nullptr);
|
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addTask(const std::function<void()> &task){
|
|
||||||
_taskMutex.lock();
|
|
||||||
int targetIndex = -1;
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
if (_tasks[index] == nullptr) {
|
|
||||||
targetIndex = index;
|
|
||||||
_tasks[index] = task;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetIndex == -1) {
|
|
||||||
_tasks.push_back(task);
|
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) );
|
|
||||||
|
|
||||||
_numThread++;
|
|
||||||
}
|
|
||||||
_taskMutex.unlock();
|
|
||||||
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy()
|
|
||||||
{
|
|
||||||
_running = false;
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_threads[index].join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool _running;
|
|
||||||
std::vector<std::thread> _threads;
|
|
||||||
std::vector< std::function<void ()> > _tasks;
|
|
||||||
|
|
||||||
void threadFunc(int index)
|
|
||||||
{
|
|
||||||
while (_running) {
|
|
||||||
std::function<void ()> task = nullptr;
|
|
||||||
_taskMutex.lock();
|
|
||||||
task = _tasks[index];
|
|
||||||
_taskMutex.unlock();
|
|
||||||
|
|
||||||
if (nullptr == task)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
||||||
_sleepCondition.wait(lk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
task();
|
|
||||||
|
|
||||||
_taskMutex.lock();
|
|
||||||
_tasks[index] = nullptr;
|
|
||||||
_taskMutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int _numThread;
|
|
||||||
|
|
||||||
std::mutex _taskMutex;
|
|
||||||
std::mutex _sleepMutex;
|
|
||||||
std::condition_variable _sleepCondition;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||||
@interface AudioEngineSessionHandler : NSObject
|
@interface AudioEngineSessionHandler : NSObject
|
||||||
{
|
{
|
||||||
|
@ -220,8 +133,7 @@ static id s_AudioEngineSessionHandler = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
AudioEngineImpl::AudioEngineImpl()
|
AudioEngineImpl::AudioEngineImpl()
|
||||||
: _threadPool(nullptr)
|
: _lazyInitLoop(true)
|
||||||
, _lazyInitLoop(true)
|
|
||||||
, _currentAudioID(0)
|
, _currentAudioID(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -240,10 +152,7 @@ AudioEngineImpl::~AudioEngineImpl()
|
||||||
if (s_ALDevice) {
|
if (s_ALDevice) {
|
||||||
alcCloseDevice(s_ALDevice);
|
alcCloseDevice(s_ALDevice);
|
||||||
}
|
}
|
||||||
if (_threadPool) {
|
|
||||||
_threadPool->destroy();
|
|
||||||
delete _threadPool;
|
|
||||||
}
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||||
[s_AudioEngineSessionHandler release];
|
[s_AudioEngineSessionHandler release];
|
||||||
#endif
|
#endif
|
||||||
|
@ -275,7 +184,6 @@ bool AudioEngineImpl::init()
|
||||||
_alSourceUsed[_alSources[i]] = false;
|
_alSourceUsed[_alSources[i]] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_threadPool = new (std::nothrow) AudioEngineThreadPool();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}while (false);
|
}while (false);
|
||||||
|
@ -283,6 +191,24 @@ bool AudioEngineImpl::init()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioCache* AudioEngineImpl::preload(const std::string& filePath)
|
||||||
|
{
|
||||||
|
AudioCache* audioCache = nullptr;
|
||||||
|
|
||||||
|
auto it = _audioCaches.find(filePath);
|
||||||
|
if (it == _audioCaches.end()) {
|
||||||
|
audioCache = &_audioCaches[filePath];
|
||||||
|
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||||
|
|
||||||
|
AudioEngine::addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
audioCache = &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return audioCache;
|
||||||
|
}
|
||||||
|
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||||
{
|
{
|
||||||
if (s_ALDevice == nullptr) {
|
if (s_ALDevice == nullptr) {
|
||||||
|
@ -303,16 +229,9 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
return AudioEngine::INVALID_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = preload(filePath);
|
||||||
auto it = _audioCaches.find(filePath);
|
if (audioCache == nullptr) {
|
||||||
if (it == _audioCaches.end()) {
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
audioCache = &_audioCaches[filePath];
|
|
||||||
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
|
||||||
|
|
||||||
_threadPool->addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audioCache = &it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = &_audioPlayers[_currentAudioID];
|
auto player = &_audioPlayers[_currentAudioID];
|
||||||
|
|
|
@ -281,8 +281,14 @@ public:
|
||||||
*/
|
*/
|
||||||
static AudioProfile* getProfile(const std::string &profileName);
|
static AudioProfile* getProfile(const std::string &profileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preload audio file.
|
||||||
|
* @param filePath The file path of an audio.
|
||||||
|
*/
|
||||||
|
static void preload(const std::string& filePath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
static void addTask(const std::function<void()> &task);
|
||||||
static void remove(int audioID);
|
static void remove(int audioID);
|
||||||
|
|
||||||
struct ProfileHelper
|
struct ProfileHelper
|
||||||
|
@ -335,6 +341,9 @@ protected:
|
||||||
static ProfileHelper* _defaultProfileHelper;
|
static ProfileHelper* _defaultProfileHelper;
|
||||||
|
|
||||||
static AudioEngineImpl* _audioEngineImpl;
|
static AudioEngineImpl* _audioEngineImpl;
|
||||||
|
|
||||||
|
class AudioEngineThreadPool;
|
||||||
|
static AudioEngineThreadPool* s_threadPool;
|
||||||
|
|
||||||
friend class AudioEngineImpl;
|
friend class AudioEngineImpl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||||
|
|
||||||
#include "AudioEngine-win32.h"
|
#include "AudioEngine-win32.h"
|
||||||
#include <condition_variable>
|
|
||||||
#ifdef OPENAL_PLAIN_INCLUDES
|
#ifdef OPENAL_PLAIN_INCLUDES
|
||||||
#include "alc.h"
|
#include "alc.h"
|
||||||
#include "alext.h"
|
#include "alext.h"
|
||||||
|
@ -47,95 +47,9 @@ static ALCdevice *s_ALDevice = nullptr;
|
||||||
static ALCcontext *s_ALContext = nullptr;
|
static ALCcontext *s_ALContext = nullptr;
|
||||||
static bool MPG123_LAZYINIT = true;
|
static bool MPG123_LAZYINIT = true;
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
namespace experimental {
|
|
||||||
class AudioEngineThreadPool
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AudioEngineThreadPool()
|
|
||||||
: _running(true)
|
|
||||||
, _numThread(6)
|
|
||||||
{
|
|
||||||
_threads.reserve(_numThread);
|
|
||||||
_tasks.reserve(_numThread);
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_tasks.push_back(nullptr);
|
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,index) ) );
|
|
||||||
_threads[index].detach();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addTask(const std::function<void()> &task){
|
|
||||||
_taskMutex.lock();
|
|
||||||
int targetIndex = -1;
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
if (_tasks[index] == nullptr) {
|
|
||||||
targetIndex = index;
|
|
||||||
_tasks[index] = task;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetIndex == -1) {
|
|
||||||
_tasks.push_back(task);
|
|
||||||
_threads.push_back( std::thread( std::bind(&AudioEngineThreadPool::threadFunc,this,_numThread) ) );
|
|
||||||
_threads[_numThread].detach();
|
|
||||||
_numThread++;
|
|
||||||
}
|
|
||||||
_taskMutex.unlock();
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy()
|
|
||||||
{
|
|
||||||
_running = false;
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_threads[index].join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
bool _running;
|
|
||||||
std::vector<std::thread> _threads;
|
|
||||||
std::vector< std::function<void ()> > _tasks;
|
|
||||||
|
|
||||||
void threadFunc(int index)
|
|
||||||
{
|
|
||||||
while (_running) {
|
|
||||||
std::function<void ()> task = nullptr;
|
|
||||||
_taskMutex.lock();
|
|
||||||
task = _tasks[index];
|
|
||||||
_taskMutex.unlock();
|
|
||||||
|
|
||||||
if (nullptr == task)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
||||||
_sleepCondition.wait(lk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
task();
|
|
||||||
|
|
||||||
_taskMutex.lock();
|
|
||||||
_tasks[index] = nullptr;
|
|
||||||
_taskMutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int _numThread;
|
|
||||||
|
|
||||||
std::mutex _taskMutex;
|
|
||||||
std::mutex _sleepMutex;
|
|
||||||
std::condition_variable _sleepCondition;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioEngineImpl::AudioEngineImpl()
|
AudioEngineImpl::AudioEngineImpl()
|
||||||
: _lazyInitLoop(true)
|
: _lazyInitLoop(true)
|
||||||
, _currentAudioID(0)
|
, _currentAudioID(0)
|
||||||
, _threadPool(nullptr)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -155,10 +69,6 @@ AudioEngineImpl::~AudioEngineImpl()
|
||||||
alcCloseDevice(s_ALDevice);
|
alcCloseDevice(s_ALDevice);
|
||||||
s_ALDevice = nullptr;
|
s_ALDevice = nullptr;
|
||||||
}
|
}
|
||||||
if (_threadPool) {
|
|
||||||
_threadPool->destroy();
|
|
||||||
delete _threadPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
mpg123_exit();
|
mpg123_exit();
|
||||||
MPG123_LAZYINIT = true;
|
MPG123_LAZYINIT = true;
|
||||||
|
@ -186,7 +96,6 @@ bool AudioEngineImpl::init()
|
||||||
_alSourceUsed[_alSources[i]] = false;
|
_alSourceUsed[_alSources[i]] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_threadPool = new (std::nothrow) AudioEngineThreadPool();
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
}while (false);
|
}while (false);
|
||||||
|
@ -194,6 +103,54 @@ bool AudioEngineImpl::init()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioCache* AudioEngineImpl::preload(const std::string& filePath)
|
||||||
|
{
|
||||||
|
AudioCache* audioCache = nullptr;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
auto it = _audioCaches.find(filePath);
|
||||||
|
if (it != _audioCaches.end())
|
||||||
|
{
|
||||||
|
audioCache = &it->second;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto ext = strchr(filePath.c_str(), '.');
|
||||||
|
AudioCache::FileFormat fileFormat = AudioCache::FileFormat::UNKNOWN;
|
||||||
|
|
||||||
|
if (_stricmp(ext, ".ogg") == 0){
|
||||||
|
fileFormat = AudioCache::FileFormat::OGG;
|
||||||
|
}
|
||||||
|
else if (_stricmp(ext, ".mp3") == 0){
|
||||||
|
fileFormat = AudioCache::FileFormat::MP3;
|
||||||
|
|
||||||
|
if (MPG123_LAZYINIT){
|
||||||
|
auto error = mpg123_init();
|
||||||
|
if (error == MPG123_OK){
|
||||||
|
MPG123_LAZYINIT = false;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
log("Basic setup goes wrong: %s", mpg123_plain_strerror(error));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
log("unsupported media type:%s\n", ext);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
audioCache = &_audioCaches[filePath];
|
||||||
|
audioCache->_fileFormat = fileFormat;
|
||||||
|
|
||||||
|
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||||
|
AudioEngine::addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
||||||
|
} while (false);
|
||||||
|
|
||||||
|
return audioCache;
|
||||||
|
}
|
||||||
|
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||||
{
|
{
|
||||||
bool availableSourceExist = false;
|
bool availableSourceExist = false;
|
||||||
|
@ -209,48 +166,10 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
return AudioEngine::INVALID_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = preload(filePath);
|
||||||
auto it = _audioCaches.find(filePath);
|
if (audioCache == nullptr)
|
||||||
if (it == _audioCaches.end()) {
|
{
|
||||||
audioCache = &_audioCaches[filePath];
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
auto ext = strchr(filePath.c_str(), '.');
|
|
||||||
bool eraseCache = true;
|
|
||||||
|
|
||||||
if (_stricmp(ext, ".ogg") == 0){
|
|
||||||
audioCache->_fileFormat = AudioCache::FileFormat::OGG;
|
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
else if (_stricmp(ext, ".mp3") == 0){
|
|
||||||
audioCache->_fileFormat = AudioCache::FileFormat::MP3;
|
|
||||||
|
|
||||||
if (MPG123_LAZYINIT){
|
|
||||||
auto error = mpg123_init();
|
|
||||||
if(error == MPG123_OK){
|
|
||||||
MPG123_LAZYINIT = false;
|
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
log("Basic setup goes wrong: %s", mpg123_plain_strerror(error));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
log("unsupported media type:%s\n", ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eraseCache){
|
|
||||||
_audioCaches.erase(filePath);
|
|
||||||
return AudioEngine::INVALID_AUDIO_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
|
||||||
_threadPool->addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audioCache = &it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = &_audioPlayers[_currentAudioID];
|
auto player = &_audioPlayers[_currentAudioID];
|
||||||
|
|
|
@ -38,8 +38,6 @@ NS_CC_BEGIN
|
||||||
namespace experimental{
|
namespace experimental{
|
||||||
#define MAX_AUDIOINSTANCES 32
|
#define MAX_AUDIOINSTANCES 32
|
||||||
|
|
||||||
class AudioEngineThreadPool;
|
|
||||||
|
|
||||||
class CC_DLL AudioEngineImpl : public cocos2d::Ref
|
class CC_DLL AudioEngineImpl : public cocos2d::Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -61,14 +59,13 @@ public:
|
||||||
|
|
||||||
void uncache(const std::string& filePath);
|
void uncache(const std::string& filePath);
|
||||||
void uncacheAll();
|
void uncacheAll();
|
||||||
|
AudioCache* preload(const std::string& filePath);
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _play2d(AudioCache *cache, int audioID);
|
void _play2d(AudioCache *cache, int audioID);
|
||||||
|
|
||||||
AudioEngineThreadPool* _threadPool;
|
|
||||||
|
|
||||||
ALuint _alSources[MAX_AUDIOINSTANCES];
|
ALuint _alSources[MAX_AUDIOINSTANCES];
|
||||||
|
|
||||||
//source,used
|
//source,used
|
||||||
|
|
|
@ -21,101 +21,13 @@
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
||||||
|
|
||||||
#include "AudioEngine-winrt.h"
|
#include "AudioEngine-winrt.h"
|
||||||
#include <condition_variable>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace cocos2d;
|
using namespace cocos2d;
|
||||||
using namespace cocos2d::experimental;
|
using namespace cocos2d::experimental;
|
||||||
|
|
||||||
|
|
||||||
namespace cocos2d {
|
|
||||||
namespace experimental {
|
|
||||||
class AudioEngineThreadPool
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AudioEngineThreadPool()
|
|
||||||
: _running(true)
|
|
||||||
, _numThread(6)
|
|
||||||
{
|
|
||||||
_threads.reserve(_numThread);
|
|
||||||
_tasks.reserve(_numThread);
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_tasks.push_back(nullptr);
|
|
||||||
_threads.push_back(std::thread(std::bind(&AudioEngineThreadPool::threadFunc, this, index)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addTask(const std::function<void()> &task){
|
|
||||||
_taskMutex.lock();
|
|
||||||
int targetIndex = -1;
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
if (_tasks[index] == nullptr) {
|
|
||||||
targetIndex = index;
|
|
||||||
_tasks[index] = task;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (targetIndex == -1) {
|
|
||||||
_tasks.push_back(task);
|
|
||||||
_threads.push_back(std::thread(std::bind(&AudioEngineThreadPool::threadFunc, this, _numThread)));
|
|
||||||
|
|
||||||
_numThread++;
|
|
||||||
}
|
|
||||||
_taskMutex.unlock();
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroy()
|
|
||||||
{
|
|
||||||
_running = false;
|
|
||||||
_sleepCondition.notify_all();
|
|
||||||
|
|
||||||
for (int index = 0; index < _numThread; ++index) {
|
|
||||||
_threads[index].join();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
bool _running;
|
|
||||||
std::vector<std::thread> _threads;
|
|
||||||
std::vector< std::function<void()> > _tasks;
|
|
||||||
|
|
||||||
void threadFunc(int index)
|
|
||||||
{
|
|
||||||
while (_running) {
|
|
||||||
std::function<void()> task = nullptr;
|
|
||||||
_taskMutex.lock();
|
|
||||||
task = _tasks[index];
|
|
||||||
_taskMutex.unlock();
|
|
||||||
|
|
||||||
if (nullptr == task)
|
|
||||||
{
|
|
||||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
||||||
_sleepCondition.wait(lk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
task();
|
|
||||||
|
|
||||||
_taskMutex.lock();
|
|
||||||
_tasks[index] = nullptr;
|
|
||||||
_taskMutex.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int _numThread;
|
|
||||||
|
|
||||||
std::mutex _taskMutex;
|
|
||||||
std::mutex _sleepMutex;
|
|
||||||
std::condition_variable _sleepCondition;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioEngineImpl::AudioEngineImpl()
|
AudioEngineImpl::AudioEngineImpl()
|
||||||
: _lazyInitLoop(true)
|
: _lazyInitLoop(true)
|
||||||
, _currentAudioID(0)
|
, _currentAudioID(0)
|
||||||
, _threadPool(nullptr)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -123,64 +35,63 @@ AudioEngineImpl::AudioEngineImpl()
|
||||||
AudioEngineImpl::~AudioEngineImpl()
|
AudioEngineImpl::~AudioEngineImpl()
|
||||||
{
|
{
|
||||||
_audioCaches.clear();
|
_audioCaches.clear();
|
||||||
|
|
||||||
if (_threadPool) {
|
|
||||||
_threadPool->destroy();
|
|
||||||
delete _threadPool;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioEngineImpl::init()
|
bool AudioEngineImpl::init()
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (nullptr == _threadPool) {
|
|
||||||
_threadPool = new (std::nothrow) AudioEngineThreadPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath, bool loop, float volume)
|
AudioCache* AudioEngineImpl::preload(const std::string& filePath)
|
||||||
{
|
{
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = nullptr;
|
||||||
auto it = _audioCaches.find(filePath);
|
do
|
||||||
if (it == _audioCaches.end()) {
|
{
|
||||||
audioCache = &_audioCaches[filePath];
|
auto it = _audioCaches.find(filePath);
|
||||||
|
if (it == _audioCaches.end()) {
|
||||||
|
FileFormat fileFormat = FileFormat::UNKNOWN;
|
||||||
|
|
||||||
auto ext = filePath.substr(filePath.rfind('.'));
|
auto ext = filePath.substr(filePath.rfind('.'));
|
||||||
transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||||
|
|
||||||
bool eraseCache = true;
|
if (ext.compare(".wav") == 0){
|
||||||
|
fileFormat = FileFormat::WAV;
|
||||||
|
}
|
||||||
|
else if (ext.compare(".ogg") == 0){
|
||||||
|
fileFormat = FileFormat::OGG;
|
||||||
|
}
|
||||||
|
else if (ext.compare(".mp3") == 0){
|
||||||
|
fileFormat = FileFormat::MP3;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
log("unsupported media type:%s\n", ext.c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (ext.compare(".wav") == 0){
|
audioCache = &_audioCaches[filePath];
|
||||||
audioCache->_fileFormat = FileFormat::WAV;
|
audioCache->_fileFormat = fileFormat;
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
else if (ext.compare(".ogg") == 0){
|
|
||||||
audioCache->_fileFormat = FileFormat::OGG;
|
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
else if (ext.compare(".mp3") == 0){
|
|
||||||
audioCache->_fileFormat = FileFormat::MP3;
|
|
||||||
eraseCache = false;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
log("unsupported media type:%s\n", ext.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eraseCache){
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||||
_audioCaches.erase(filePath);
|
audioCache->_fileFullPath = fullPath;
|
||||||
return AudioEngine::INVALID_AUDIO_ID;
|
AudioEngine::addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
audioCache = &it->second;
|
||||||
|
}
|
||||||
|
} while (false);
|
||||||
|
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
return audioCache;
|
||||||
audioCache->_fileFullPath = fullPath;
|
}
|
||||||
_threadPool->addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
|
||||||
}
|
int AudioEngineImpl::play2d(const std::string &filePath, bool loop, float volume)
|
||||||
else {
|
{
|
||||||
audioCache = &it->second;
|
auto audioCache = preload(filePath);
|
||||||
|
if (audioCache == nullptr)
|
||||||
|
{
|
||||||
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = &_audioPlayers[_currentAudioID];
|
auto player = &_audioPlayers[_currentAudioID];
|
||||||
|
|
|
@ -35,9 +35,6 @@ NS_CC_BEGIN
|
||||||
namespace experimental{
|
namespace experimental{
|
||||||
#define MAX_AUDIOINSTANCES 32
|
#define MAX_AUDIOINSTANCES 32
|
||||||
|
|
||||||
|
|
||||||
class AudioEngineThreadPool;
|
|
||||||
|
|
||||||
class CC_DLL AudioEngineImpl : public cocos2d::Ref
|
class CC_DLL AudioEngineImpl : public cocos2d::Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -58,6 +55,7 @@ NS_CC_BEGIN
|
||||||
void setFinishCallback(int audioID, const std::function<void(int, const std::string &)> &callback);
|
void setFinishCallback(int audioID, const std::function<void(int, const std::string &)> &callback);
|
||||||
void uncache(const std::string& filePath);
|
void uncache(const std::string& filePath);
|
||||||
void uncacheAll();
|
void uncacheAll();
|
||||||
|
AudioCache* preload(const std::string& filePath);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -72,7 +70,6 @@ NS_CC_BEGIN
|
||||||
std::vector<int> _toRemoveAudioIDs;
|
std::vector<int> _toRemoveAudioIDs;
|
||||||
bool _lazyInitLoop;
|
bool _lazyInitLoop;
|
||||||
int _currentAudioID;
|
int _currentAudioID;
|
||||||
AudioEngineThreadPool* _threadPool;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ Configuration::Configuration()
|
||||||
, _maxDirLightInShader(1)
|
, _maxDirLightInShader(1)
|
||||||
, _maxPointLightInShader(1)
|
, _maxPointLightInShader(1)
|
||||||
, _maxSpotLightInShader(1)
|
, _maxSpotLightInShader(1)
|
||||||
, _animate3DQuality(Animate3DQuality::QUALITY_HIGH)
|
, _animate3DQuality(Animate3DQuality::QUALITY_LOW)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,12 +123,12 @@ static bool isFloat( std::string myString ) {
|
||||||
static ssize_t mydprintf(int sock, const char *format, ...)
|
static ssize_t mydprintf(int sock, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char buf[16386];
|
char buf[16386];
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
vsnprintf(buf, sizeof(buf), format, args);
|
vsnprintf(buf, sizeof(buf), format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return send(sock, buf, strlen(buf),0);
|
return send(sock, buf, strlen(buf),0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendPrompt(int fd)
|
static void sendPrompt(int fd)
|
||||||
|
@ -235,20 +235,53 @@ void SendLogToWindow(const char *log)
|
||||||
|
|
||||||
static void _log(const char *format, va_list args)
|
static void _log(const char *format, va_list args)
|
||||||
{
|
{
|
||||||
char buf[MAX_LOG_LENGTH];
|
int bufferSize = MAX_LOG_LENGTH;
|
||||||
|
char* buf = nullptr;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
buf = new (std::nothrow) char[bufferSize];
|
||||||
|
if (buf == nullptr)
|
||||||
|
return; // not enough memory
|
||||||
|
|
||||||
|
int ret = vsnprintf(buf, bufferSize - 3, format, args);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
bufferSize *= 2;
|
||||||
|
|
||||||
|
delete [] buf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
|
||||||
|
} while (true);
|
||||||
|
|
||||||
vsnprintf(buf, MAX_LOG_LENGTH-3, format, args);
|
|
||||||
strcat(buf, "\n");
|
strcat(buf, "\n");
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||||
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
|
__android_log_print(ANDROID_LOG_DEBUG, "cocos2d-x debug info", "%s", buf);
|
||||||
|
|
||||||
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
||||||
WCHAR wszBuf[MAX_LOG_LENGTH] = {0};
|
|
||||||
MultiByteToWideChar(CP_UTF8, 0, buf, -1, wszBuf, sizeof(wszBuf));
|
int pos = 0;
|
||||||
OutputDebugStringW(wszBuf);
|
int len = strlen(buf);
|
||||||
WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, buf, sizeof(buf), nullptr, FALSE);
|
char tempBuf[MAX_LOG_LENGTH + 1] = { 0 };
|
||||||
printf("%s", buf);
|
WCHAR wszBuf[MAX_LOG_LENGTH + 1] = { 0 };
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
std::copy(buf + pos, buf + pos + MAX_LOG_LENGTH, tempBuf);
|
||||||
|
|
||||||
|
tempBuf[MAX_LOG_LENGTH] = 0;
|
||||||
|
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, tempBuf, -1, wszBuf, sizeof(wszBuf));
|
||||||
|
OutputDebugStringW(wszBuf);
|
||||||
|
WideCharToMultiByte(CP_ACP, 0, wszBuf, -1, tempBuf, sizeof(tempBuf), nullptr, FALSE);
|
||||||
|
printf("%s", tempBuf);
|
||||||
|
|
||||||
|
pos += MAX_LOG_LENGTH;
|
||||||
|
|
||||||
|
} while (pos < len);
|
||||||
SendLogToWindow(buf);
|
SendLogToWindow(buf);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#else
|
#else
|
||||||
|
@ -258,7 +291,7 @@ static void _log(const char *format, va_list args)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Director::getInstance()->getConsole()->log(buf);
|
Director::getInstance()->getConsole()->log(buf);
|
||||||
|
delete [] buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Deprecated
|
// FIXME: Deprecated
|
||||||
|
@ -290,7 +323,7 @@ Console::Console()
|
||||||
, _bindAddress("")
|
, _bindAddress("")
|
||||||
{
|
{
|
||||||
// VS2012 doesn't support initializer list, so we create a new array and assign its elements to '_command'.
|
// VS2012 doesn't support initializer list, so we create a new array and assign its elements to '_command'.
|
||||||
Command commands[] = {
|
Command commands[] = {
|
||||||
{ "allocator", "Display allocator diagnostics for all allocators", std::bind(&Console::commandAllocator, this, std::placeholders::_1, std::placeholders::_2) },
|
{ "allocator", "Display allocator diagnostics for all allocators", std::bind(&Console::commandAllocator, this, std::placeholders::_1, std::placeholders::_2) },
|
||||||
{ "config", "Print the Configuration object", std::bind(&Console::commandConfig, this, std::placeholders::_1, std::placeholders::_2) },
|
{ "config", "Print the Configuration object", std::bind(&Console::commandConfig, this, std::placeholders::_1, std::placeholders::_2) },
|
||||||
{ "debugmsg", "Whether or not to forward the debug messages on the console. Args: [on | off]", [&](int fd, const std::string& args) {
|
{ "debugmsg", "Whether or not to forward the debug messages on the console. Args: [on | off]", [&](int fd, const std::string& args) {
|
||||||
|
@ -326,10 +359,10 @@ Console::Console()
|
||||||
};
|
};
|
||||||
|
|
||||||
;
|
;
|
||||||
for (int i = 0; i < sizeof(commands)/sizeof(commands[0]); ++i)
|
for (int i = 0; i < sizeof(commands)/sizeof(commands[0]); ++i)
|
||||||
{
|
{
|
||||||
_commands[commands[i].name] = commands[i];
|
_commands[commands[i].name] = commands[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Console::~Console()
|
Console::~Console()
|
||||||
|
@ -1190,7 +1223,7 @@ void Console::loop()
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
||||||
closesocket(_listenfd);
|
closesocket(_listenfd);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
#else
|
#else
|
||||||
close(_listenfd);
|
close(_listenfd);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,6 +28,7 @@ THE SOFTWARE.
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "base/CCDirector.h"
|
#include "base/CCDirector.h"
|
||||||
|
#include "base/CCAsyncTaskPool.h"
|
||||||
#include "renderer/CCCustomCommand.h"
|
#include "renderer/CCCustomCommand.h"
|
||||||
#include "renderer/CCRenderer.h"
|
#include "renderer/CCRenderer.h"
|
||||||
#include "platform/CCImage.h"
|
#include "platform/CCImage.h"
|
||||||
|
@ -49,22 +50,39 @@ int ccNextPOT(int x)
|
||||||
namespace utils
|
namespace utils
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Capture screen implementation, don't use it directly.
|
* Capture screen implementation, don't use it directly.
|
||||||
*/
|
*/
|
||||||
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
|
void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterCaptured, const std::string& filename)
|
||||||
{
|
{
|
||||||
|
static bool startedCapture = false;
|
||||||
|
|
||||||
|
if (startedCapture)
|
||||||
|
{
|
||||||
|
CCLOG("Screen capture is already working");
|
||||||
|
if (afterCaptured)
|
||||||
|
{
|
||||||
|
afterCaptured(false, filename);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startedCapture = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto glView = Director::getInstance()->getOpenGLView();
|
auto glView = Director::getInstance()->getOpenGLView();
|
||||||
auto frameSize = glView->getFrameSize();
|
auto frameSize = glView->getFrameSize();
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
|
||||||
frameSize = frameSize * glView->getFrameZoomFactor() * glView->getRetinaFactor();
|
frameSize = frameSize * glView->getFrameZoomFactor() * glView->getRetinaFactor();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int width = static_cast<int>(frameSize.width);
|
int width = static_cast<int>(frameSize.width);
|
||||||
int height = static_cast<int>(frameSize.height);
|
int height = static_cast<int>(frameSize.height);
|
||||||
|
|
||||||
bool succeed = false;
|
bool succeed = false;
|
||||||
std::string outputFile = "";
|
std::string outputFile = "";
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::shared_ptr<GLubyte> buffer(new GLubyte[width * height * 4], [](GLubyte* p){ CC_SAFE_DELETE_ARRAY(p); });
|
std::shared_ptr<GLubyte> buffer(new GLubyte[width * height * 4], [](GLubyte* p){ CC_SAFE_DELETE_ARRAY(p); });
|
||||||
|
@ -72,10 +90,10 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
|
||||||
|
|
||||||
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
|
||||||
if (!flippedBuffer)
|
if (!flippedBuffer)
|
||||||
{
|
{
|
||||||
|
@ -87,7 +105,7 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
||||||
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Image> image(new Image);
|
Image* image = new (std::nothrow) Image;
|
||||||
if (image)
|
if (image)
|
||||||
{
|
{
|
||||||
image->initWithRawData(flippedBuffer.get(), width * height * 4, width, height, 8);
|
image->initWithRawData(flippedBuffer.get(), width * height * 4, width, height, 8);
|
||||||
|
@ -100,15 +118,36 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
|
||||||
CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!");
|
CCASSERT(filename.find("/") == std::string::npos, "The existence of a relative path is not guaranteed!");
|
||||||
outputFile = FileUtils::getInstance()->getWritablePath() + filename;
|
outputFile = FileUtils::getInstance()->getWritablePath() + filename;
|
||||||
}
|
}
|
||||||
succeed = image->saveToFile(outputFile);
|
|
||||||
|
// Save image in AsyncTaskPool::TaskType::TASK_IO thread, and call afterCaptured in mainThread
|
||||||
|
static bool succeedSaveToFile = false;
|
||||||
|
std::function<void(void*)> mainThread = [afterCaptured, outputFile](void* param)
|
||||||
|
{
|
||||||
|
if (afterCaptured)
|
||||||
|
{
|
||||||
|
afterCaptured(succeedSaveToFile, outputFile);
|
||||||
|
}
|
||||||
|
startedCapture = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_IO, mainThread, (void*)NULL, [image, outputFile]()
|
||||||
|
{
|
||||||
|
succeedSaveToFile = image->saveToFile(outputFile);
|
||||||
|
delete image;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}while(0);
|
else
|
||||||
|
{
|
||||||
if (afterCaptured)
|
CCLOG("Malloc Image memory failed!");
|
||||||
{
|
if (afterCaptured)
|
||||||
afterCaptured(succeed, outputFile);
|
{
|
||||||
}
|
afterCaptured(succeed, outputFile);
|
||||||
|
}
|
||||||
|
startedCapture = false;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Capture screen interface
|
* Capture screen interface
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -238,15 +238,12 @@ namespace cocostudio
|
||||||
setPropsWithFlatBuffers(tmx, (Table*)gameMapOptions);
|
setPropsWithFlatBuffers(tmx, (Table*)gameMapOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// Node* node = Node::create();
|
Node* node = Node::create();
|
||||||
// setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
|
setPropsWithFlatBuffers(node, (Table*)gameMapOptions);
|
||||||
// auto label = Label::create();
|
return node;
|
||||||
// label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
|
}
|
||||||
// node->addChild(label);
|
|
||||||
// return node;
|
|
||||||
//}
|
|
||||||
|
|
||||||
return tmx;
|
return tmx;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,11 +153,11 @@ namespace cocostudio
|
||||||
void ParticleReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
void ParticleReader::setPropsWithFlatBuffers(cocos2d::Node *node,
|
||||||
const flatbuffers::Table *particleOptions)
|
const flatbuffers::Table *particleOptions)
|
||||||
{
|
{
|
||||||
auto particle = static_cast<ParticleSystemQuad*>(node);
|
auto particle = dynamic_cast<ParticleSystemQuad*>(node);
|
||||||
auto options = (ParticleSystemOptions*)particleOptions;
|
auto options = (ParticleSystemOptions*)particleOptions;
|
||||||
|
|
||||||
auto f_blendFunc = options->blendFunc();
|
auto f_blendFunc = options->blendFunc();
|
||||||
if (f_blendFunc)
|
if (particle && f_blendFunc)
|
||||||
{
|
{
|
||||||
cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED;
|
cocos2d::BlendFunc blendFunc = cocos2d::BlendFunc::ALPHA_PREMULTIPLIED;
|
||||||
blendFunc.src = f_blendFunc->src();
|
blendFunc.src = f_blendFunc->src();
|
||||||
|
@ -208,15 +208,12 @@ namespace cocostudio
|
||||||
particle->setPositionType(ParticleSystem::PositionType::GROUPED);
|
particle->setPositionType(ParticleSystem::PositionType::GROUPED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else
|
else
|
||||||
//{
|
{
|
||||||
// Node* node = Node::create();
|
Node* node = Node::create();
|
||||||
// setPropsWithFlatBuffers(node, (Table*)particleOptions);
|
setPropsWithFlatBuffers(node, (Table*)particleOptions);
|
||||||
// auto label = Label::create();
|
return node;
|
||||||
// label->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
|
}
|
||||||
// node->addChild(label);
|
|
||||||
// return node;
|
|
||||||
//}
|
|
||||||
|
|
||||||
return particle;
|
return particle;
|
||||||
}
|
}
|
||||||
|
|
|
@ -466,7 +466,7 @@ namespace cocostudio
|
||||||
auto options = (SliderOptions*)sliderOptions;
|
auto options = (SliderOptions*)sliderOptions;
|
||||||
|
|
||||||
int percent = options->percent();
|
int percent = options->percent();
|
||||||
slider->setPercent(percent);
|
//slider->setPercent(percent);
|
||||||
|
|
||||||
bool imageFileExist = false;
|
bool imageFileExist = false;
|
||||||
std::string imageErrorFilePath = "";
|
std::string imageErrorFilePath = "";
|
||||||
|
@ -798,7 +798,7 @@ namespace cocostudio
|
||||||
|
|
||||||
auto widgetReader = WidgetReader::getInstance();
|
auto widgetReader = WidgetReader::getInstance();
|
||||||
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
|
||||||
|
slider->setPercent(percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Node* SliderReader::createNodeWithFlatBuffers(const flatbuffers::Table *sliderOptions)
|
Node* SliderReader::createNodeWithFlatBuffers(const flatbuffers::Table *sliderOptions)
|
||||||
|
|
|
@ -125,6 +125,7 @@ namespace cocostudio
|
||||||
else if(value == "USER1") cameraFlag = 1 << 1;
|
else if(value == "USER1") cameraFlag = 1 << 1;
|
||||||
else if(value == "USER2") cameraFlag = 1 << 2;
|
else if(value == "USER2") cameraFlag = 1 << 2;
|
||||||
else if(value == "USER3") cameraFlag = 1 << 3;
|
else if(value == "USER3") cameraFlag = 1 << 3;
|
||||||
|
else if(value == "USER4") cameraFlag = 1 << 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
attribute = attribute->Next();
|
attribute = attribute->Next();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -54,11 +54,11 @@ public:
|
||||||
* Destroys the instance of FileUtils.
|
* Destroys the instance of FileUtils.
|
||||||
*/
|
*/
|
||||||
static void destroyInstance();
|
static void destroyInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* You can inherit from platform dependent implementation of FileUtils, such as FileUtilsAndroid,
|
* You can inherit from platform dependent implementation of FileUtils, such as FileUtilsAndroid,
|
||||||
* and use this function to set delegate, then FileUtils will invoke delegate's implementation.
|
* and use this function to set delegate, then FileUtils will invoke delegate's implementation.
|
||||||
* Fox example, your resources are encrypted, so you need to decrypt it after reading data from
|
* Fox example, your resources are encrypted, so you need to decrypt it after reading data from
|
||||||
* resources, then you can implement all getXXX functions, and engine will invoke your own getXX
|
* resources, then you can implement all getXXX functions, and engine will invoke your own getXX
|
||||||
* functions when reading data of resources.
|
* functions when reading data of resources.
|
||||||
*
|
*
|
||||||
|
@ -82,23 +82,23 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual ~FileUtils();
|
virtual ~FileUtils();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purges full path caches.
|
* Purges full path caches.
|
||||||
*/
|
*/
|
||||||
virtual void purgeCachedEntries();
|
virtual void purgeCachedEntries();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets string from a file.
|
* Gets string from a file.
|
||||||
*/
|
*/
|
||||||
virtual std::string getStringFromFile(const std::string& filename);
|
virtual std::string getStringFromFile(const std::string& filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates binary data from a file.
|
* Creates binary data from a file.
|
||||||
* @return A data object.
|
* @return A data object.
|
||||||
*/
|
*/
|
||||||
virtual Data getDataFromFile(const std::string& filename);
|
virtual Data getDataFromFile(const std::string& filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets resource file data
|
* Gets resource file data
|
||||||
*
|
*
|
||||||
|
@ -120,59 +120,59 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual unsigned char* getFileDataFromZip(const std::string& zipFilePath, const std::string& filename, ssize_t *size);
|
virtual unsigned char* getFileDataFromZip(const std::string& zipFilePath, const std::string& filename, ssize_t *size);
|
||||||
|
|
||||||
|
|
||||||
/** Returns the fullpath for a given filename.
|
/** Returns the fullpath for a given filename.
|
||||||
|
|
||||||
First it will try to get a new filename from the "filenameLookup" dictionary.
|
First it will try to get a new filename from the "filenameLookup" dictionary.
|
||||||
If a new filename can't be found on the dictionary, it will use the original filename.
|
If a new filename can't be found on the dictionary, it will use the original filename.
|
||||||
Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths.
|
Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths.
|
||||||
The file search is based on the array element order of search paths and resolution directories.
|
The file search is based on the array element order of search paths and resolution directories.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,
|
We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,
|
||||||
and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")
|
and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")
|
||||||
to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".
|
to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".
|
||||||
|
|
||||||
If we have a file named 'sprite.png', the mapping in fileLookup dictionary contains `key: sprite.png -> value: sprite.pvr.gz`.
|
If we have a file named 'sprite.png', the mapping in fileLookup dictionary contains `key: sprite.png -> value: sprite.pvr.gz`.
|
||||||
Firstly, it will replace 'sprite.png' with 'sprite.pvr.gz', then searching the file sprite.pvr.gz as follows:
|
Firstly, it will replace 'sprite.png' with 'sprite.pvr.gz', then searching the file sprite.pvr.gz as follows:
|
||||||
|
|
||||||
/mnt/sdcard/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/resources-ipad/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/resources-ipad/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
internal_dir/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/resources-ipad/sprite.pvr.gz (if not found, search next)
|
internal_dir/resources-ipad/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
internal_dir/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/sprite.pvr.gz (if not found, return "sprite.png")
|
internal_dir/sprite.pvr.gz (if not found, return "sprite.png")
|
||||||
|
|
||||||
If the filename contains relative path like "gamescene/uilayer/sprite.png",
|
If the filename contains relative path like "gamescene/uilayer/sprite.png",
|
||||||
and the mapping in fileLookup dictionary contains `key: gamescene/uilayer/sprite.png -> value: gamescene/uilayer/sprite.pvr.gz`.
|
and the mapping in fileLookup dictionary contains `key: gamescene/uilayer/sprite.png -> value: gamescene/uilayer/sprite.pvr.gz`.
|
||||||
The file search order will be:
|
The file search order will be:
|
||||||
|
|
||||||
/mnt/sdcard/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
||||||
/mnt/sdcard/gamescene/uilayer/sprite.pvr.gz (if not found, search next)
|
/mnt/sdcard/gamescene/uilayer/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
internal_dir/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
|
internal_dir/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
internal_dir/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
|
||||||
internal_dir/gamescene/uilayer/sprite.pvr.gz (if not found, return "gamescene/uilayer/sprite.png")
|
internal_dir/gamescene/uilayer/sprite.pvr.gz (if not found, return "gamescene/uilayer/sprite.png")
|
||||||
|
|
||||||
If the new file can't be found on the file system, it will return the parameter filename directly.
|
If the new file can't be found on the file system, it will return the parameter filename directly.
|
||||||
|
|
||||||
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable,
|
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable,
|
||||||
you might need to load different resources for a given file in the different platforms.
|
you might need to load different resources for a given file in the different platforms.
|
||||||
|
|
||||||
@since v2.1
|
@since v2.1
|
||||||
*/
|
*/
|
||||||
virtual std::string fullPathForFilename(const std::string &filename) const;
|
virtual std::string fullPathForFilename(const std::string &filename) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the filenameLookup dictionary from the contents of a filename.
|
* Loads the filenameLookup dictionary from the contents of a filename.
|
||||||
*
|
*
|
||||||
* @note The plist file name should follow the format below:
|
* @note The plist file name should follow the format below:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* <?xml version="1.0" encoding="UTF-8"?>
|
* <?xml version="1.0" encoding="UTF-8"?>
|
||||||
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
@ -202,15 +202,15 @@ public:
|
||||||
* @lua loadFilenameLookup
|
* @lua loadFilenameLookup
|
||||||
*/
|
*/
|
||||||
virtual void loadFilenameLookupDictionaryFromFile(const std::string &filename);
|
virtual void loadFilenameLookupDictionaryFromFile(const std::string &filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the filenameLookup dictionary.
|
* Sets the filenameLookup dictionary.
|
||||||
*
|
*
|
||||||
* @param pFilenameLookupDict The dictionary for replacing filename.
|
* @param pFilenameLookupDict The dictionary for replacing filename.
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);
|
virtual void setFilenameLookupDictionary(const ValueMap& filenameLookupDict);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets full path from a file name and the path of the relative file.
|
* Gets full path from a file name and the path of the relative file.
|
||||||
* @param filename The file name.
|
* @param filename The file name.
|
||||||
|
@ -222,7 +222,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual std::string fullPathFromRelativeFile(const std::string &filename, const std::string &relativeFile);
|
virtual std::string fullPathFromRelativeFile(const std::string &filename, const std::string &relativeFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the array that contains the search order of the resources.
|
* Sets the array that contains the search order of the resources.
|
||||||
*
|
*
|
||||||
* @param searchResolutionsOrder The source array that contains the search order of the resources.
|
* @param searchResolutionsOrder The source array that contains the search order of the resources.
|
||||||
|
@ -240,7 +240,7 @@ public:
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
virtual void addSearchResolutionsOrder(const std::string &order,const bool front=false);
|
virtual void addSearchResolutionsOrder(const std::string &order,const bool front=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the array that contains the search order of the resources.
|
* Gets the array that contains the search order of the resources.
|
||||||
*
|
*
|
||||||
|
@ -249,19 +249,19 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual const std::vector<std::string>& getSearchResolutionsOrder() const;
|
virtual const std::vector<std::string>& getSearchResolutionsOrder() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the array of search paths.
|
* Sets the array of search paths.
|
||||||
*
|
*
|
||||||
* You can use this array to modify the search path of the resources.
|
* You can use this array to modify the search path of the resources.
|
||||||
* If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
|
* If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
|
||||||
*
|
*
|
||||||
* @note This method could access relative path and absolute path.
|
* @note This method could access relative path and absolute path.
|
||||||
* If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.
|
* If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.
|
||||||
* For instance:
|
* For instance:
|
||||||
* On Android, the default resource root path is "assets/".
|
* On Android, the default resource root path is "assets/".
|
||||||
* If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,
|
* If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,
|
||||||
* "resources-large" will be converted to "assets/resources-large" since it was a relative path.
|
* "resources-large" will be converted to "assets/resources-large" since it was a relative path.
|
||||||
*
|
*
|
||||||
* @param searchPaths The array contains search paths.
|
* @param searchPaths The array contains search paths.
|
||||||
* @see fullPathForFilename(const char*)
|
* @see fullPathForFilename(const char*)
|
||||||
|
@ -270,7 +270,7 @@ public:
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
virtual void setSearchPaths(const std::vector<std::string>& searchPaths);
|
virtual void setSearchPaths(const std::vector<std::string>& searchPaths);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default resource root path.
|
* Set default resource root path.
|
||||||
*/
|
*/
|
||||||
|
@ -282,10 +282,10 @@ public:
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
void addSearchPath(const std::string & path, const bool front=false);
|
void addSearchPath(const std::string & path, const bool front=false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the array of search paths.
|
* Gets the array of search paths.
|
||||||
*
|
*
|
||||||
* @return The array of search paths.
|
* @return The array of search paths.
|
||||||
* @see fullPathForFilename(const char*).
|
* @see fullPathForFilename(const char*).
|
||||||
* @lua NA
|
* @lua NA
|
||||||
|
@ -297,7 +297,7 @@ public:
|
||||||
* @return The path that can be write/read a file in
|
* @return The path that can be write/read a file in
|
||||||
*/
|
*/
|
||||||
virtual std::string getWritablePath() const = 0;
|
virtual std::string getWritablePath() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets writable path.
|
* Sets writable path.
|
||||||
*/
|
*/
|
||||||
|
@ -307,8 +307,8 @@ public:
|
||||||
* Sets whether to pop-up a message box when failed to load an image.
|
* Sets whether to pop-up a message box when failed to load an image.
|
||||||
*/
|
*/
|
||||||
virtual void setPopupNotify(bool notify);
|
virtual void setPopupNotify(bool notify);
|
||||||
|
|
||||||
/** Checks whether to pop up a message box when failed to load an image.
|
/** Checks whether to pop up a message box when failed to load an image.
|
||||||
* @return True if pop up a message box when failed to load an image, false if not.
|
* @return True if pop up a message box when failed to load an image, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool isPopupNotify() const;
|
virtual bool isPopupNotify() const;
|
||||||
|
@ -321,15 +321,58 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ValueMap getValueMapFromFile(const std::string& filename);
|
virtual ValueMap getValueMapFromFile(const std::string& filename);
|
||||||
|
|
||||||
// Converts the contents of a file to a ValueMap.
|
|
||||||
// This method is used internally.
|
|
||||||
virtual ValueMap getValueMapFromData(const char* filedata, int filesize);
|
|
||||||
|
|
||||||
|
|
||||||
// Write a ValueMap to a plist file.
|
/** Converts the contents of a file to a ValueMap.
|
||||||
// This method is used internally.
|
* This method is used internally.
|
||||||
|
*/
|
||||||
|
virtual ValueMap getValueMapFromData(const char* filedata, int filesize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a ValueMap into a plist file
|
||||||
|
*
|
||||||
|
*@param dict the ValueMap want to save
|
||||||
|
*@param fullPath The full path to the file you want to save a string
|
||||||
|
*@return bool
|
||||||
|
*/
|
||||||
virtual bool writeToFile(ValueMap& dict, const std::string& fullPath);
|
virtual bool writeToFile(ValueMap& dict, const std::string& fullPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a string into a file
|
||||||
|
*
|
||||||
|
* @param dataStr the string want to save
|
||||||
|
* @param fullPath The full path to the file you want to save a string
|
||||||
|
* @return bool True if write success
|
||||||
|
*/
|
||||||
|
virtual bool writeStringToFile(std::string dataStr, const std::string& fullPath);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write Data into a file
|
||||||
|
*
|
||||||
|
*@param retData the data want to save
|
||||||
|
*@param fullPath The full path to the file you want to save a string
|
||||||
|
*@return bool
|
||||||
|
*/
|
||||||
|
virtual bool writeDataToFile(Data retData, const std::string& fullPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write ValueMap into a plist file
|
||||||
|
*
|
||||||
|
*@param dict the ValueMap want to save
|
||||||
|
*@param fullPath The full path to the file you want to save a string
|
||||||
|
*@return bool
|
||||||
|
*/
|
||||||
|
virtual bool writeValueMapToFile(ValueMap& dict, const std::string& fullPath);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write ValueVector into a plist file
|
||||||
|
*
|
||||||
|
*@param vecData the ValueVector want to save
|
||||||
|
*@param fullPath The full path to the file you want to save a string
|
||||||
|
*@return bool
|
||||||
|
*/
|
||||||
|
virtual bool writeValueVectorToFile(ValueVector vecData, const std::string& fullPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows fopen can't support UTF-8 filename
|
* Windows fopen can't support UTF-8 filename
|
||||||
* Need convert all parameters fopen and other 3rd-party libs
|
* Need convert all parameters fopen and other 3rd-party libs
|
||||||
|
@ -338,11 +381,11 @@ public:
|
||||||
* @return std::string ansi filename in current locale
|
* @return std::string ansi filename in current locale
|
||||||
*/
|
*/
|
||||||
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const;
|
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const;
|
||||||
|
|
||||||
// Converts the contents of a file to a ValueVector.
|
// Converts the contents of a file to a ValueVector.
|
||||||
// This method is used internally.
|
// This method is used internally.
|
||||||
virtual ValueVector getValueVectorFromFile(const std::string& filename);
|
virtual ValueVector getValueVectorFromFile(const std::string& filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a file exists.
|
* Checks whether a file exists.
|
||||||
*
|
*
|
||||||
|
@ -351,7 +394,7 @@ public:
|
||||||
* @return True if the file exists, false if not.
|
* @return True if the file exists, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool isFileExist(const std::string& filename) const;
|
virtual bool isFileExist(const std::string& filename) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the path is an absolute path.
|
* Checks whether the path is an absolute path.
|
||||||
*
|
*
|
||||||
|
@ -362,7 +405,7 @@ public:
|
||||||
* @return True if it's an absolute path, false if not.
|
* @return True if it's an absolute path, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool isAbsolutePath(const std::string& path) const;
|
virtual bool isAbsolutePath(const std::string& path) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the path is a directory.
|
* Checks whether the path is a directory.
|
||||||
*
|
*
|
||||||
|
@ -370,7 +413,7 @@ public:
|
||||||
* @return True if the directory exists, false if not.
|
* @return True if the directory exists, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool isDirectoryExist(const std::string& dirPath) const;
|
virtual bool isDirectoryExist(const std::string& dirPath) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a directory.
|
* Creates a directory.
|
||||||
*
|
*
|
||||||
|
@ -378,7 +421,7 @@ public:
|
||||||
* @return True if the directory have been created successfully, false if not.
|
* @return True if the directory have been created successfully, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool createDirectory(const std::string& dirPath);
|
virtual bool createDirectory(const std::string& dirPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a directory.
|
* Removes a directory.
|
||||||
*
|
*
|
||||||
|
@ -386,7 +429,7 @@ public:
|
||||||
* @return True if the directory have been removed successfully, false if not.
|
* @return True if the directory have been removed successfully, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool removeDirectory(const std::string& dirPath);
|
virtual bool removeDirectory(const std::string& dirPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a file.
|
* Removes a file.
|
||||||
*
|
*
|
||||||
|
@ -394,7 +437,7 @@ public:
|
||||||
* @return True if the file have been removed successfully, false if not.
|
* @return True if the file have been removed successfully, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool removeFile(const std::string &filepath);
|
virtual bool removeFile(const std::string &filepath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renames a file under the given directory.
|
* Renames a file under the given directory.
|
||||||
*
|
*
|
||||||
|
@ -404,7 +447,7 @@ public:
|
||||||
* @return True if the file have been renamed successfully, false if not.
|
* @return True if the file have been renamed successfully, false if not.
|
||||||
*/
|
*/
|
||||||
virtual bool renameFile(const std::string &path, const std::string &oldname, const std::string &name);
|
virtual bool renameFile(const std::string &path, const std::string &oldname, const std::string &name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the file size.
|
* Retrieve the file size.
|
||||||
*
|
*
|
||||||
|
@ -422,7 +465,7 @@ protected:
|
||||||
* The default constructor.
|
* The default constructor.
|
||||||
*/
|
*/
|
||||||
FileUtils();
|
FileUtils();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the instance of FileUtils. It will set _searchPathArray and _searchResolutionsOrderArray to default values.
|
* Initializes the instance of FileUtils. It will set _searchPathArray and _searchResolutionsOrderArray to default values.
|
||||||
*
|
*
|
||||||
|
@ -432,7 +475,7 @@ protected:
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the new filename from the filename lookup dictionary.
|
* Gets the new filename from the filename lookup dictionary.
|
||||||
* It is possible to have a override names.
|
* It is possible to have a override names.
|
||||||
|
@ -441,21 +484,21 @@ protected:
|
||||||
* If the original filename wasn't in the dictionary, it will return the original filename.
|
* If the original filename wasn't in the dictionary, it will return the original filename.
|
||||||
*/
|
*/
|
||||||
virtual std::string getNewFilename(const std::string &filename) const;
|
virtual std::string getNewFilename(const std::string &filename) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a file exists without considering search paths and resolution orders.
|
* Checks whether a file exists without considering search paths and resolution orders.
|
||||||
* @param filename The file (with absolute path) to look up for
|
* @param filename The file (with absolute path) to look up for
|
||||||
* @return Returns true if the file found at the given absolute path, otherwise returns false
|
* @return Returns true if the file found at the given absolute path, otherwise returns false
|
||||||
*/
|
*/
|
||||||
virtual bool isFileExistInternal(const std::string& filename) const = 0;
|
virtual bool isFileExistInternal(const std::string& filename) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a directory exists without considering search paths and resolution orders.
|
* Checks whether a directory exists without considering search paths and resolution orders.
|
||||||
* @param dirPath The directory (with absolute path) to look up for
|
* @param dirPath The directory (with absolute path) to look up for
|
||||||
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||||
*/
|
*/
|
||||||
virtual bool isDirectoryExistInternal(const std::string& dirPath) const;
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets full path for filename, resolution directory and search path.
|
* Gets full path for filename, resolution directory and search path.
|
||||||
*
|
*
|
||||||
|
@ -465,7 +508,7 @@ protected:
|
||||||
* @return The full path of the file. It will return an empty string if the full path of the file doesn't exist.
|
* @return The full path of the file. It will return an empty string if the full path of the file doesn't exist.
|
||||||
*/
|
*/
|
||||||
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const;
|
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets full path for the directory and the filename.
|
* Gets full path for the directory and the filename.
|
||||||
*
|
*
|
||||||
|
@ -477,7 +520,7 @@ protected:
|
||||||
* @return The full path of the file, if the file can't be found, it will return an empty string.
|
* @return The full path of the file, if the file can't be found, it will return an empty string.
|
||||||
*/
|
*/
|
||||||
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const;
|
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const;
|
||||||
|
|
||||||
/** Dictionary used to lookup filenames based on a key.
|
/** Dictionary used to lookup filenames based on a key.
|
||||||
* It is used internally by the following methods:
|
* It is used internally by the following methods:
|
||||||
*
|
*
|
||||||
|
@ -486,19 +529,19 @@ protected:
|
||||||
* @since v2.1
|
* @since v2.1
|
||||||
*/
|
*/
|
||||||
ValueMap _filenameLookupDict;
|
ValueMap _filenameLookupDict;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The vector contains resolution folders.
|
* The vector contains resolution folders.
|
||||||
* The lower index of the element in this vector, the higher priority for this resolution directory.
|
* The lower index of the element in this vector, the higher priority for this resolution directory.
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> _searchResolutionsOrderArray;
|
std::vector<std::string> _searchResolutionsOrderArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The vector contains search paths.
|
* The vector contains search paths.
|
||||||
* The lower index of the element in this vector, the higher priority for this search path.
|
* The lower index of the element in this vector, the higher priority for this search path.
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> _searchPathArray;
|
std::vector<std::string> _searchPathArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default root path of resources.
|
* The default root path of resources.
|
||||||
* If the default root path of resources needs to be changed, do it in the `init` method of FileUtils's subclass.
|
* If the default root path of resources needs to be changed, do it in the `init` method of FileUtils's subclass.
|
||||||
|
@ -507,13 +550,13 @@ protected:
|
||||||
* Similarly on Blackberry, we assign "app/native/Resources/" to this variable in FileUtilsBlackberry::init().
|
* Similarly on Blackberry, we assign "app/native/Resources/" to this variable in FileUtilsBlackberry::init().
|
||||||
*/
|
*/
|
||||||
std::string _defaultResRootPath;
|
std::string _defaultResRootPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full path cache. When a file is found, it will be added into this cache.
|
* The full path cache. When a file is found, it will be added into this cache.
|
||||||
* This variable is used for improving the performance of file search.
|
* This variable is used for improving the performance of file search.
|
||||||
*/
|
*/
|
||||||
mutable std::unordered_map<std::string, std::string> _fullPathCache;
|
mutable std::unordered_map<std::string, std::string> _fullPathCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writable path.
|
* Writable path.
|
||||||
*/
|
*/
|
||||||
|
@ -523,7 +566,7 @@ protected:
|
||||||
* The singleton pointer of FileUtils.
|
* The singleton pointer of FileUtils.
|
||||||
*/
|
*/
|
||||||
static FileUtils* s_sharedFileUtils;
|
static FileUtils* s_sharedFileUtils;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of support group
|
// end of support group
|
||||||
|
|
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
||||||
#include "android/asset_manager_jni.h"
|
#include "android/asset_manager_jni.h"
|
||||||
#include "jni/CocosPlayClient.h"
|
#include "jni/CocosPlayClient.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define LOG_TAG "CCFileUtils-android.cpp"
|
#define LOG_TAG "CCFileUtils-android.cpp"
|
||||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||||
|
@ -86,7 +87,7 @@ bool FileUtilsAndroid::init()
|
||||||
{
|
{
|
||||||
_defaultResRootPath = "assets/";
|
_defaultResRootPath = "assets/";
|
||||||
}
|
}
|
||||||
|
|
||||||
return FileUtils::init();
|
return FileUtils::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +131,7 @@ std::string FileUtilsAndroid::getNewFilename(const std::string &filename) const
|
||||||
}
|
}
|
||||||
idx = pos + 1;
|
idx = pos + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change)
|
if (change)
|
||||||
{
|
{
|
||||||
newFileName.clear();
|
newFileName.clear();
|
||||||
|
@ -155,7 +156,7 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bFound = false;
|
bool bFound = false;
|
||||||
|
|
||||||
// Check whether file exists in apk.
|
// Check whether file exists in apk.
|
||||||
if (strFilePath[0] != '/')
|
if (strFilePath[0] != '/')
|
||||||
{
|
{
|
||||||
|
@ -187,6 +188,59 @@ bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
|
||||||
return bFound;
|
return bFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileUtilsAndroid::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
|
{
|
||||||
|
if (dirPath.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* s = dirPath.c_str();
|
||||||
|
bool startWithAssets = (dirPath.find("assets/") == 0);
|
||||||
|
int lenOfAssets = 7;
|
||||||
|
|
||||||
|
std::string tmpStr;
|
||||||
|
if (cocosplay::isEnabled() && !cocosplay::isDemo())
|
||||||
|
{
|
||||||
|
// redirect assets/*** path to cocosplay resource dir
|
||||||
|
tmpStr.append(_defaultResRootPath);
|
||||||
|
if ('/' != tmpStr[tmpStr.length() - 1])
|
||||||
|
{
|
||||||
|
tmpStr += '/';
|
||||||
|
}
|
||||||
|
tmpStr.append(s + lenOfAssets);
|
||||||
|
}
|
||||||
|
|
||||||
|
// find absolute path in flash memory
|
||||||
|
if (s[0] == '/')
|
||||||
|
{
|
||||||
|
CCLOG("find in flash memory dirPath(%s)", s);
|
||||||
|
struct stat st;
|
||||||
|
if (stat(s, &st) == 0)
|
||||||
|
{
|
||||||
|
return S_ISDIR(st.st_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// find it in apk's assets dir
|
||||||
|
// Found "assets/" at the beginning of the path and we don't want it
|
||||||
|
CCLOG("find in apk dirPath(%s)", s);
|
||||||
|
if (startWithAssets)
|
||||||
|
{
|
||||||
|
s += lenOfAssets;
|
||||||
|
}
|
||||||
|
if (FileUtilsAndroid::assetmanager)
|
||||||
|
{
|
||||||
|
AAssetDir* aa = AAssetManager_openDir(FileUtilsAndroid::assetmanager, s);
|
||||||
|
if (aa && AAssetDir_getNextFileName(aa))
|
||||||
|
{
|
||||||
|
AAssetDir_close(aa);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
bool FileUtilsAndroid::isAbsolutePath(const std::string& strPath) const
|
||||||
{
|
{
|
||||||
// On Android, there are two situations for full path.
|
// On Android, there are two situations for full path.
|
||||||
|
@ -206,7 +260,7 @@ Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
return Data::Null;
|
return Data::Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* data = nullptr;
|
unsigned char* data = nullptr;
|
||||||
ssize_t size = 0;
|
ssize_t size = 0;
|
||||||
string fullPath = fullPathForFilename(filename);
|
string fullPath = fullPathForFilename(filename);
|
||||||
|
@ -271,7 +325,7 @@ Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
|
||||||
|
|
||||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||||
CC_BREAK_IF(!fp);
|
CC_BREAK_IF(!fp);
|
||||||
|
|
||||||
long fileSize;
|
long fileSize;
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
fileSize = ftell(fp);
|
fileSize = ftell(fp);
|
||||||
|
@ -287,11 +341,11 @@ Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
|
||||||
}
|
}
|
||||||
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
size = fileSize;
|
size = fileSize;
|
||||||
} while (0);
|
} while (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Data ret;
|
Data ret;
|
||||||
if (data == nullptr || size == 0)
|
if (data == nullptr || size == 0)
|
||||||
{
|
{
|
||||||
|
@ -317,21 +371,21 @@ std::string FileUtilsAndroid::getStringFromFile(const std::string& filename)
|
||||||
std::string ret((const char*)data.getBytes());
|
std::string ret((const char*)data.getBytes());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data FileUtilsAndroid::getDataFromFile(const std::string& filename)
|
Data FileUtilsAndroid::getDataFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
return getData(filename, false);
|
return getData(filename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const char* mode, ssize_t * size)
|
unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const char* mode, ssize_t * size)
|
||||||
{
|
{
|
||||||
unsigned char * data = 0;
|
unsigned char * data = 0;
|
||||||
|
|
||||||
if ( filename.empty() || (! mode) )
|
if ( filename.empty() || (! mode) )
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
string fullPath = fullPathForFilename(filename);
|
string fullPath = fullPathForFilename(filename);
|
||||||
cocosplay::updateAssets(fullPath);
|
cocosplay::updateAssets(fullPath);
|
||||||
|
|
||||||
|
@ -383,7 +437,7 @@ unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const
|
||||||
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
//CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
|
||||||
FILE *fp = fopen(fullPath.c_str(), mode);
|
FILE *fp = fopen(fullPath.c_str(), mode);
|
||||||
CC_BREAK_IF(!fp);
|
CC_BREAK_IF(!fp);
|
||||||
|
|
||||||
long fileSize;
|
long fileSize;
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
fileSize = ftell(fp);
|
fileSize = ftell(fp);
|
||||||
|
@ -391,14 +445,14 @@ unsigned char* FileUtilsAndroid::getFileData(const std::string& filename, const
|
||||||
data = (unsigned char*) malloc(fileSize);
|
data = (unsigned char*) malloc(fileSize);
|
||||||
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
{
|
{
|
||||||
*size = fileSize;
|
*size = fileSize;
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! data)
|
if (! data)
|
||||||
{
|
{
|
||||||
std::string msg = "Get data from file(";
|
std::string msg = "Get data from file(";
|
||||||
|
|
|
@ -81,7 +81,8 @@ public:
|
||||||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||||
Data getData(const std::string& filename, bool forString);
|
Data getData(const std::string& filename, bool forString);
|
||||||
|
|
||||||
static AAssetManager* assetmanager;
|
static AAssetManager* assetmanager;
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -36,271 +36,271 @@ import android.view.MotionEvent;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
|
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Constants
|
// Constants
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
private final static String TAG = GameControllerActivity.class.getSimpleName();
|
private final static String TAG = GameControllerActivity.class.getSimpleName();
|
||||||
|
|
||||||
public static final int DRIVERTYPE_NIBIRU = 0;
|
public static final int DRIVERTYPE_NIBIRU = 0;
|
||||||
public static final int DRIVERTYPE_MOGA = 1;
|
public static final int DRIVERTYPE_MOGA = 1;
|
||||||
public static final int DRIVERTYPE_OUYA = 2;
|
public static final int DRIVERTYPE_OUYA = 2;
|
||||||
public static final int DRIVERTYPE_STANDARD = 3;
|
public static final int DRIVERTYPE_STANDARD = 3;
|
||||||
public static final int DRIVERTYPE_UNKNOWN = 4;
|
public static final int DRIVERTYPE_UNKNOWN = 4;
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Fields
|
// Fields
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
private static GameControllerActivity sGameControllerActivity;
|
private static GameControllerActivity sGameControllerActivity;
|
||||||
private InputManagerCompat mInputManager = null;
|
private InputManagerCompat mInputManager = null;
|
||||||
|
|
||||||
protected GameControllerHelper mControllerHelper = null;
|
protected GameControllerHelper mControllerHelper = null;
|
||||||
|
|
||||||
protected GameControllerDelegate mControllerNibiru = null;
|
protected GameControllerDelegate mControllerNibiru = null;
|
||||||
protected GameControllerDelegate mControllerMoga = null;
|
protected GameControllerDelegate mControllerMoga = null;
|
||||||
protected GameControllerDelegate mControllerOuya = null;
|
protected GameControllerDelegate mControllerOuya = null;
|
||||||
|
|
||||||
public void connectController(int driveType){
|
public void connectController(int driveType){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ClassLoader loader = sGameControllerActivity.getClassLoader();
|
ClassLoader loader = sGameControllerActivity.getClassLoader();
|
||||||
Class<?> controllerDelegate = null;
|
Class<?> controllerDelegate = null;
|
||||||
if (driveType == DRIVERTYPE_MOGA) {
|
if (driveType == DRIVERTYPE_MOGA) {
|
||||||
if (mControllerMoga != null) {
|
if (mControllerMoga != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
|
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
|
||||||
} else if (driveType == DRIVERTYPE_NIBIRU) {
|
} else if (driveType == DRIVERTYPE_NIBIRU) {
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
mControllerNibiru.onCreate(sGameControllerActivity);
|
mControllerNibiru.onCreate(sGameControllerActivity);
|
||||||
mControllerNibiru.onResume();
|
mControllerNibiru.onResume();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
|
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
|
||||||
} else if (driveType == DRIVERTYPE_OUYA) {
|
} else if (driveType == DRIVERTYPE_OUYA) {
|
||||||
if (mControllerOuya != null) {
|
if (mControllerOuya != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
|
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
|
||||||
}
|
}
|
||||||
|
|
||||||
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
|
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
|
||||||
sGameControllerActivity.setGameControllerInstance(instance, driveType);
|
sGameControllerActivity.setGameControllerInstance(instance, driveType);
|
||||||
|
|
||||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||||
Method method = controllerDelegate.getDeclaredMethod("onResume");
|
Method method = controllerDelegate.getDeclaredMethod("onResume");
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
|
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
|
||||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||||
mControllerNibiru = controllerDelegate;
|
mControllerNibiru = controllerDelegate;
|
||||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||||
mControllerMoga = controllerDelegate;
|
mControllerMoga = controllerDelegate;
|
||||||
}
|
}
|
||||||
else if (driveType == DRIVERTYPE_OUYA) {
|
else if (driveType == DRIVERTYPE_OUYA) {
|
||||||
mControllerOuya = controllerDelegate;
|
mControllerOuya = controllerDelegate;
|
||||||
}
|
}
|
||||||
controllerDelegate.setControllerEventListener(mControllerEventListener);
|
controllerDelegate.setControllerEventListener(mControllerEventListener);
|
||||||
controllerDelegate.onCreate(sGameControllerActivity);
|
controllerDelegate.onCreate(sGameControllerActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameControllerDelegate getGameControllerDelegate(int driveType){
|
public GameControllerDelegate getGameControllerDelegate(int driveType){
|
||||||
if (driveType == DRIVERTYPE_NIBIRU) {
|
if (driveType == DRIVERTYPE_NIBIRU) {
|
||||||
return mControllerNibiru;
|
return mControllerNibiru;
|
||||||
}else if (driveType == DRIVERTYPE_MOGA) {
|
}else if (driveType == DRIVERTYPE_MOGA) {
|
||||||
return mControllerMoga;
|
return mControllerMoga;
|
||||||
}
|
}
|
||||||
else if (driveType == DRIVERTYPE_OUYA) {
|
else if (driveType == DRIVERTYPE_OUYA) {
|
||||||
return mControllerOuya;
|
return mControllerOuya;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
|
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onButtonEvent(String vendorName, int controller, int button,
|
public void onButtonEvent(String vendorName, int controller, int button,
|
||||||
boolean isPressed, float value, boolean isAnalog) {
|
boolean isPressed, float value, boolean isAnalog) {
|
||||||
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
|
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAxisEvent(String vendorName, int controller, int axisID,
|
public void onAxisEvent(String vendorName, int controller, int axisID,
|
||||||
float value, boolean isAnalog) {
|
float value, boolean isAnalog) {
|
||||||
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
|
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnected(String vendorName, int controller) {
|
public void onConnected(String vendorName, int controller) {
|
||||||
GameControllerAdapter.onConnected(vendorName, controller);
|
GameControllerAdapter.onConnected(vendorName, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnected(String vendorName, int controller) {
|
public void onDisconnected(String vendorName, int controller) {
|
||||||
GameControllerAdapter.onDisconnected(vendorName, controller);
|
GameControllerAdapter.onDisconnected(vendorName, controller);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Constructors
|
// Constructors
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
sGameControllerActivity = this;
|
sGameControllerActivity = this;
|
||||||
mInputManager = InputManagerCompat.Factory.getInputManager(this);
|
mInputManager = InputManagerCompat.Factory.getInputManager(this);
|
||||||
mInputManager.registerInputDeviceListener(this, null);
|
mInputManager.registerInputDeviceListener(this, null);
|
||||||
|
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
mControllerNibiru.onCreate(this);
|
mControllerNibiru.onCreate(this);
|
||||||
}
|
}
|
||||||
if (mControllerMoga != null) {
|
if (mControllerMoga != null) {
|
||||||
mControllerMoga.onCreate(this);
|
mControllerMoga.onCreate(this);
|
||||||
}
|
}
|
||||||
if (mControllerOuya != null) {
|
if (mControllerOuya != null) {
|
||||||
mControllerOuya.onCreate(this);
|
mControllerOuya.onCreate(this);
|
||||||
}
|
}
|
||||||
if (mControllerHelper == null) {
|
if (mControllerHelper == null) {
|
||||||
mControllerHelper = new GameControllerHelper(this);
|
mControllerHelper = new GameControllerHelper(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Getter & Setter
|
// Getter & Setter
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Methods for/from SuperClass/Interfaces
|
// Methods for/from SuperClass/Interfaces
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
handled |= mControllerNibiru.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
if (handled == false && mControllerMoga != null) {
|
if (handled == false && mControllerMoga != null) {
|
||||||
handled |= mControllerMoga.dispatchKeyEvent(event);
|
handled |= mControllerMoga.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
if (handled == false && mControllerOuya != null) {
|
if (handled == false && mControllerOuya != null) {
|
||||||
handled |= mControllerOuya.dispatchKeyEvent(event);
|
handled |= mControllerOuya.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled == false) {
|
if (handled == false) {
|
||||||
handled |= mControllerHelper.dispatchKeyEvent(event);
|
handled |= mControllerHelper.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled || super.dispatchKeyEvent(event);
|
return handled || super.dispatchKeyEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
|
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
if (handled == false && mControllerMoga != null) {
|
if (handled == false && mControllerMoga != null) {
|
||||||
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
if (handled == false && mControllerOuya != null) {
|
if (handled == false && mControllerOuya != null) {
|
||||||
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled == false) {
|
if (handled == false) {
|
||||||
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled || super.dispatchGenericMotionEvent(event);
|
return handled || super.dispatchGenericMotionEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceAdded(int deviceId) {
|
public void onInputDeviceAdded(int deviceId) {
|
||||||
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
|
||||||
|
|
||||||
mControllerHelper.onInputDeviceAdded(deviceId);
|
mControllerHelper.onInputDeviceAdded(deviceId);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* This is an unusual case. Input devices don't typically change, but they
|
* This is an unusual case. Input devices don't typically change, but they
|
||||||
* certainly can --- for example a device may have different modes. We use
|
* certainly can --- for example a device may have different modes. We use
|
||||||
* this to make sure that the ship has an up-to-date InputDevice.
|
* this to make sure that the ship has an up-to-date InputDevice.
|
||||||
*
|
*
|
||||||
* @see
|
* @see
|
||||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||||
* #onInputDeviceChanged(int)
|
* #onInputDeviceChanged(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
public void onInputDeviceChanged(int deviceId) {
|
||||||
Log.w(TAG,"onInputDeviceChanged:" + deviceId);
|
Log.w(TAG,"onInputDeviceChanged:" + deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove any ship associated with the ID.
|
* Remove any ship associated with the ID.
|
||||||
*
|
*
|
||||||
* @see
|
* @see
|
||||||
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
|
||||||
* #onInputDeviceRemoved(int)
|
* #onInputDeviceRemoved(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceRemoved(int deviceId) {
|
public void onInputDeviceRemoved(int deviceId) {
|
||||||
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
|
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
|
||||||
|
|
||||||
mControllerHelper.onInputDeviceRemoved(deviceId);
|
mControllerHelper.onInputDeviceRemoved(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
mControllerNibiru.onResume();
|
mControllerNibiru.onResume();
|
||||||
}
|
}
|
||||||
if (mControllerMoga != null) {
|
if (mControllerMoga != null) {
|
||||||
mControllerMoga.onResume();
|
mControllerMoga.onResume();
|
||||||
}
|
}
|
||||||
if (mControllerOuya != null) {
|
if (mControllerOuya != null) {
|
||||||
mControllerOuya.onResume();
|
mControllerOuya.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameControllerHelper.gatherControllers(mControllerHelper.mGameController);
|
GameControllerHelper.gatherControllers(mControllerHelper.mGameController);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
mControllerNibiru.onPause();
|
mControllerNibiru.onPause();
|
||||||
}
|
}
|
||||||
if (mControllerMoga != null) {
|
if (mControllerMoga != null) {
|
||||||
mControllerMoga.onPause();
|
mControllerMoga.onPause();
|
||||||
}
|
}
|
||||||
if (mControllerOuya != null) {
|
if (mControllerOuya != null) {
|
||||||
mControllerOuya.onPause();
|
mControllerOuya.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
if (mControllerNibiru != null) {
|
if (mControllerNibiru != null) {
|
||||||
mControllerNibiru.onDestroy();
|
mControllerNibiru.onDestroy();
|
||||||
}
|
}
|
||||||
if (mControllerMoga != null) {
|
if (mControllerMoga != null) {
|
||||||
mControllerMoga.onDestroy();
|
mControllerMoga.onDestroy();
|
||||||
}
|
}
|
||||||
if (mControllerOuya != null) {
|
if (mControllerOuya != null) {
|
||||||
mControllerOuya.onDestroy();
|
mControllerOuya.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -10,248 +10,248 @@ import android.view.MotionEvent;
|
||||||
|
|
||||||
public class GameControllerHelper {
|
public class GameControllerHelper {
|
||||||
|
|
||||||
public static final String StandardControllerName = "Standard";
|
public static final String StandardControllerName = "Standard";
|
||||||
|
|
||||||
SparseIntArray ControllerKeyMap;
|
SparseIntArray ControllerKeyMap;
|
||||||
|
|
||||||
private static final int AXIS_X = 0;
|
private static final int AXIS_X = 0;
|
||||||
private static final int AXIS_Y = 1;
|
private static final int AXIS_Y = 1;
|
||||||
private static final int AXIS_Z = 11;
|
private static final int AXIS_Z = 11;
|
||||||
private static final int AXIS_RZ = 14;
|
private static final int AXIS_RZ = 14;
|
||||||
private static final int AXIS_LTRIGGER = 17;
|
private static final int AXIS_LTRIGGER = 17;
|
||||||
private static final int AXIS_RTRIGGER = 18;
|
private static final int AXIS_RTRIGGER = 18;
|
||||||
public static final int AXIS_GAS = 22;
|
public static final int AXIS_GAS = 22;
|
||||||
private static final int AXIS_BRAKE = 23;
|
private static final int AXIS_BRAKE = 23;
|
||||||
private static final int AXIS_THROTTLE = 19;
|
private static final int AXIS_THROTTLE = 19;
|
||||||
|
|
||||||
public GameControllerHelper(GameControllerActivity activity){
|
public GameControllerHelper(GameControllerActivity activity){
|
||||||
|
|
||||||
ControllerKeyMap = new SparseIntArray(25);
|
ControllerKeyMap = new SparseIntArray(25);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
|
||||||
|
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_UP, GameControllerDelegate.BUTTON_DPAD_UP);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_CENTER, GameControllerDelegate.BUTTON_DPAD_CENTER);
|
||||||
|
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL, GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||||
|
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1, GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1, GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||||
|
|
||||||
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
|
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
|
||||||
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
|
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
|
||||||
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
|
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
|
||||||
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
|
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
|
||||||
|
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
|
||||||
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
|
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float mOldLeftThumbstickX = 0.0f;
|
private float mOldLeftThumbstickX = 0.0f;
|
||||||
private float mOldLeftThumbstickY = 0.0f;
|
private float mOldLeftThumbstickY = 0.0f;
|
||||||
private float mOldRightThumbstickX = 0.0f;
|
private float mOldRightThumbstickX = 0.0f;
|
||||||
private float mOldRightThumbstickY = 0.0f;
|
private float mOldRightThumbstickY = 0.0f;
|
||||||
|
|
||||||
private float mOldLeftTrigger = 0.0f;
|
private float mOldLeftTrigger = 0.0f;
|
||||||
private float mOldRightTrigger = 0.0f;
|
private float mOldRightTrigger = 0.0f;
|
||||||
private float mOldThrottle = 0.0f;
|
private float mOldThrottle = 0.0f;
|
||||||
private float mOldBrake = 0.0f;
|
private float mOldBrake = 0.0f;
|
||||||
private float mOldGas = 0.0f;
|
private float mOldGas = 0.0f;
|
||||||
|
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
|
||||||
int eventSource = event.getSource();
|
int eventSource = event.getSource();
|
||||||
|
|
||||||
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||||
{
|
{
|
||||||
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
int deviceId = event.getDeviceId();
|
int deviceId = event.getDeviceId();
|
||||||
String deviceName = event.getDevice().getName();
|
String deviceName = event.getDevice().getName();
|
||||||
if(mGameController.get(deviceId) == null){
|
if(mGameController.get(deviceId) == null){
|
||||||
gatherControllers(mGameController);
|
gatherControllers(mGameController);
|
||||||
mGameController.append(deviceId, deviceName);
|
mGameController.append(deviceId, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
float newAXIS_LX = event.getAxisValue(AXIS_X);
|
||||||
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
|
||||||
mOldLeftThumbstickX = newAXIS_LX;
|
mOldLeftThumbstickX = newAXIS_LX;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_LY = event.getAxisValue(AXIS_Y);
|
float newAXIS_LY = event.getAxisValue(AXIS_Y);
|
||||||
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
|
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
|
||||||
mOldLeftThumbstickY = newAXIS_LY;
|
mOldLeftThumbstickY = newAXIS_LY;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_RX = event.getAxisValue(AXIS_Z);
|
float newAXIS_RX = event.getAxisValue(AXIS_Z);
|
||||||
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
|
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
|
||||||
mOldRightThumbstickX = newAXIS_RX;
|
mOldRightThumbstickX = newAXIS_RX;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
|
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
|
||||||
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
|
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
|
||||||
mOldRightThumbstickY = newAXIS_RY;
|
mOldRightThumbstickY = newAXIS_RY;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
|
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
|
||||||
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
|
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_LTRIGGER, true);
|
||||||
mOldLeftTrigger = newAXIS_LTRIGGER;
|
mOldLeftTrigger = newAXIS_LTRIGGER;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
|
||||||
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_RTRIGGER, true);
|
||||||
mOldRightTrigger = newAXIS_RTRIGGER;
|
mOldRightTrigger = newAXIS_RTRIGGER;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
|
||||||
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newAXIS_BRAKE, true);
|
||||||
mOldBrake = newAXIS_BRAKE;
|
mOldBrake = newAXIS_BRAKE;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
|
||||||
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_THROTTLE, true);
|
||||||
mOldThrottle = newAXIS_THROTTLE;
|
mOldThrottle = newAXIS_THROTTLE;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
|
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
|
||||||
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
|
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
|
||||||
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true);
|
GameControllerAdapter.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newAXIS_GAS, true);
|
||||||
mOldGas = newAXIS_GAS;
|
mOldGas = newAXIS_GAS;
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SparseArray<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
private static SparseArray<ArrayList<Integer>> mControllerExtendKey = new SparseArray<ArrayList<Integer>>();
|
||||||
|
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
|
||||||
int eventSource = event.getSource();
|
int eventSource = event.getSource();
|
||||||
int keyCode = event.getKeyCode();
|
int keyCode = event.getKeyCode();
|
||||||
int controllerKey = ControllerKeyMap.get(keyCode);
|
int controllerKey = ControllerKeyMap.get(keyCode);
|
||||||
|
|
||||||
if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
if (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||||
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||||
{
|
{
|
||||||
int deviceId = event.getDeviceId();
|
int deviceId = event.getDeviceId();
|
||||||
String deviceName = event.getDevice().getName();
|
String deviceName = event.getDevice().getName();
|
||||||
|
|
||||||
if(mGameController.get(deviceId) == null){
|
if(mGameController.get(deviceId) == null){
|
||||||
gatherControllers(mGameController);
|
gatherControllers(mGameController);
|
||||||
mGameController.append(deviceId, deviceName);
|
mGameController.append(deviceId, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controllerKey == 0) {
|
if (controllerKey == 0) {
|
||||||
if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) {
|
if (mControllerExtendKey.get(deviceId) != null && mControllerExtendKey.get(deviceId).contains(keyCode)) {
|
||||||
controllerKey = keyCode;
|
controllerKey = keyCode;
|
||||||
}else {
|
}else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
if (action == KeyEvent.ACTION_DOWN) {
|
if (action == KeyEvent.ACTION_DOWN) {
|
||||||
handled = true;
|
handled = true;
|
||||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false);
|
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,true, 1.0f, false);
|
||||||
}else if (action == KeyEvent.ACTION_UP) {
|
}else if (action == KeyEvent.ACTION_UP) {
|
||||||
handled = true;
|
handled = true;
|
||||||
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false);
|
GameControllerAdapter.onButtonEvent(deviceName, deviceId, controllerKey,false, 0.0f, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) {
|
||||||
|
if (receive) {
|
||||||
|
if (mControllerExtendKey.get(deviceId) == null) {
|
||||||
|
mControllerExtendKey.put(deviceId, new ArrayList<Integer>());
|
||||||
|
}
|
||||||
|
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
||||||
|
} else {
|
||||||
|
if (mControllerExtendKey.get(deviceId) != null) {
|
||||||
|
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SparseArray<String> mGameController = new SparseArray<String>();
|
||||||
|
|
||||||
|
void onInputDeviceAdded(int deviceId){
|
||||||
|
try {
|
||||||
|
InputDevice device = InputDevice.getDevice(deviceId);
|
||||||
|
int deviceSource = device.getSources();
|
||||||
|
|
||||||
|
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
||||||
|
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
||||||
|
{
|
||||||
|
String deviceName = device.getName();
|
||||||
|
mGameController.append(deviceId, deviceName);
|
||||||
|
GameControllerAdapter.onConnected(deviceName, deviceId);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void onInputDeviceChanged(int deviceId){
|
||||||
|
gatherControllers(mGameController);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onInputDeviceRemoved(int deviceId) {
|
||||||
|
if (mGameController.get(deviceId) != null) {
|
||||||
|
GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId);
|
||||||
|
mGameController.delete(deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void gatherControllers(SparseArray<String> controllers){
|
||||||
|
int controllerCount = controllers.size();
|
||||||
|
for (int i = 0; i < controllerCount; i++) {
|
||||||
|
try {
|
||||||
|
int controllerDeveceId = controllers.keyAt(i);
|
||||||
|
InputDevice device = InputDevice.getDevice(controllerDeveceId);
|
||||||
|
if (device == null) {
|
||||||
|
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||||
|
controllers.delete(controllerDeveceId);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
int controllerDeveceId = controllers.keyAt(i);
|
||||||
|
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
||||||
|
controllers.delete(controllerDeveceId);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void receiveExternalKeyEvent(int deviceId,int externalKeyCode,boolean receive) {
|
|
||||||
if (receive) {
|
|
||||||
if (mControllerExtendKey.get(deviceId) == null) {
|
|
||||||
mControllerExtendKey.put(deviceId, new ArrayList<Integer>());
|
|
||||||
}
|
|
||||||
mControllerExtendKey.get(deviceId).add(externalKeyCode);
|
|
||||||
} else {
|
|
||||||
if (mControllerExtendKey.get(deviceId) != null) {
|
|
||||||
mControllerExtendKey.get(deviceId).remove(Integer.valueOf(externalKeyCode));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SparseArray<String> mGameController = new SparseArray<String>();
|
|
||||||
|
|
||||||
void onInputDeviceAdded(int deviceId){
|
|
||||||
try {
|
|
||||||
InputDevice device = InputDevice.getDevice(deviceId);
|
|
||||||
int deviceSource = device.getSources();
|
|
||||||
|
|
||||||
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|
|
||||||
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
|
|
||||||
{
|
|
||||||
String deviceName = device.getName();
|
|
||||||
mGameController.append(deviceId, deviceName);
|
|
||||||
GameControllerAdapter.onConnected(deviceName, deviceId);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onInputDeviceChanged(int deviceId){
|
|
||||||
gatherControllers(mGameController);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onInputDeviceRemoved(int deviceId) {
|
|
||||||
if (mGameController.get(deviceId) != null) {
|
|
||||||
GameControllerAdapter.onDisconnected(mGameController.get(deviceId), deviceId);
|
|
||||||
mGameController.delete(deviceId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gatherControllers(SparseArray<String> controllers){
|
|
||||||
int controllerCount = controllers.size();
|
|
||||||
for (int i = 0; i < controllerCount; i++) {
|
|
||||||
try {
|
|
||||||
int controllerDeveceId = controllers.keyAt(i);
|
|
||||||
InputDevice device = InputDevice.getDevice(controllerDeveceId);
|
|
||||||
if (device == null) {
|
|
||||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
|
||||||
controllers.delete(controllerDeveceId);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
int controllerDeveceId = controllers.keyAt(i);
|
|
||||||
GameControllerAdapter.onDisconnected(controllers.get(controllerDeveceId), controllerDeveceId);
|
|
||||||
controllers.delete(controllerDeveceId);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,205 +14,205 @@ import com.bda.controller.StateEvent;
|
||||||
|
|
||||||
public class GameControllerMoga implements ControllerListener, GameControllerDelegate {
|
public class GameControllerMoga implements ControllerListener, GameControllerDelegate {
|
||||||
|
|
||||||
private static final String mVendorName = "Moga";
|
private static final String mVendorName = "Moga";
|
||||||
|
|
||||||
private float mOldLeftThumbstickX = 0.0f;
|
private float mOldLeftThumbstickX = 0.0f;
|
||||||
private float mOldLeftThumbstickY = 0.0f;
|
private float mOldLeftThumbstickY = 0.0f;
|
||||||
private float mOldRightThumbstickX = 0.0f;
|
private float mOldRightThumbstickX = 0.0f;
|
||||||
private float mOldRightThumbstickY = 0.0f;
|
private float mOldRightThumbstickY = 0.0f;
|
||||||
|
|
||||||
private float mOldLeftTrigger = 0.0f;
|
private float mOldLeftTrigger = 0.0f;
|
||||||
private float mOldRightTrigger = 0.0f;
|
private float mOldRightTrigger = 0.0f;
|
||||||
|
|
||||||
private SparseIntArray mKeyMap = null;
|
private SparseIntArray mKeyMap = null;
|
||||||
|
|
||||||
public GameControllerMoga() {
|
public GameControllerMoga() {
|
||||||
mKeyMap = new SparseIntArray(20);
|
mKeyMap = new SparseIntArray(20);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||||
|
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L1,
|
||||||
GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
GameControllerDelegate.BUTTON_LEFT_SHOULDER);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R1,
|
||||||
GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
GameControllerDelegate.BUTTON_RIGHT_SHOULDER);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_L2,
|
||||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
GameControllerDelegate.BUTTON_LEFT_TRIGGER);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2,
|
||||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
|
||||||
|
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP,
|
mKeyMap.put(KeyEvent.KEYCODE_DPAD_UP,
|
||||||
GameControllerDelegate.BUTTON_DPAD_UP);
|
GameControllerDelegate.BUTTON_DPAD_UP);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN,
|
mKeyMap.put(KeyEvent.KEYCODE_DPAD_DOWN,
|
||||||
GameControllerDelegate.BUTTON_DPAD_DOWN);
|
GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT,
|
mKeyMap.put(KeyEvent.KEYCODE_DPAD_LEFT,
|
||||||
GameControllerDelegate.BUTTON_DPAD_LEFT);
|
GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT,
|
mKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT,
|
||||||
GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||||
|
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||||
GameControllerDelegate.BUTTON_START);
|
GameControllerDelegate.BUTTON_START);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT,
|
||||||
GameControllerDelegate.BUTTON_SELECT);
|
GameControllerDelegate.BUTTON_SELECT);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_START,
|
||||||
GameControllerDelegate.BUTTON_START);
|
GameControllerDelegate.BUTTON_START);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBL,
|
||||||
GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||||
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR,
|
mKeyMap.put(KeyEvent.KEYCODE_BUTTON_THUMBR,
|
||||||
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onKeyEvent(KeyEvent event) {
|
public void onKeyEvent(KeyEvent event) {
|
||||||
int keycode = event.getKeyCode();
|
int keycode = event.getKeyCode();
|
||||||
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|
||||||
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
|
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
|
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
|
||||||
boolean isAnalog = false;
|
boolean isAnalog = false;
|
||||||
|
|
||||||
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
|
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
|
||||||
|| keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
|
|| keycode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
|
||||||
isAnalog = true;
|
isAnalog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) {
|
if (mKeyMap.get(keycode, Integer.MIN_VALUE) != Integer.MIN_VALUE && mControllerEventListener != null) {
|
||||||
mControllerEventListener.onButtonEvent(mVendorName,
|
mControllerEventListener.onButtonEvent(mVendorName,
|
||||||
event.getControllerId(), mKeyMap.get(keycode), isPressed,
|
event.getControllerId(), mKeyMap.get(keycode), isPressed,
|
||||||
isPressed ? 1.0f : 0.0f, isAnalog);
|
isPressed ? 1.0f : 0.0f, isAnalog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMotionEvent(MotionEvent event) {
|
public void onMotionEvent(MotionEvent event) {
|
||||||
if (mControllerEventListener == null) {
|
if (mControllerEventListener == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int controllerId = event.getControllerId();
|
int controllerId = event.getControllerId();
|
||||||
|
|
||||||
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
|
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
|
||||||
if (newLeftThumbstickX != mOldLeftThumbstickX) {
|
if (newLeftThumbstickX != mOldLeftThumbstickX) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.THUMBSTICK_LEFT_X,
|
GameControllerDelegate.THUMBSTICK_LEFT_X,
|
||||||
newLeftThumbstickX, true);
|
newLeftThumbstickX, true);
|
||||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
|
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
|
||||||
if (newLeftThumbstickY != mOldLeftThumbstickY) {
|
if (newLeftThumbstickY != mOldLeftThumbstickY) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.THUMBSTICK_LEFT_Y,
|
GameControllerDelegate.THUMBSTICK_LEFT_Y,
|
||||||
newLeftThumbstickY, true);
|
newLeftThumbstickY, true);
|
||||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
|
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
|
||||||
if (newRightThumbstickX != mOldRightThumbstickX) {
|
if (newRightThumbstickX != mOldRightThumbstickX) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.THUMBSTICK_RIGHT_X,
|
GameControllerDelegate.THUMBSTICK_RIGHT_X,
|
||||||
newRightThumbstickX, true);
|
newRightThumbstickX, true);
|
||||||
mOldRightThumbstickX = newRightThumbstickX;
|
mOldRightThumbstickX = newRightThumbstickX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
|
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
|
||||||
if (newRightThumbstickY != mOldRightThumbstickY) {
|
if (newRightThumbstickY != mOldRightThumbstickY) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
|
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
|
||||||
newRightThumbstickY, true);
|
newRightThumbstickY, true);
|
||||||
mOldRightThumbstickY = newRightThumbstickY;
|
mOldRightThumbstickY = newRightThumbstickY;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
|
||||||
if (newLeftTrigger != mOldLeftTrigger) {
|
if (newLeftTrigger != mOldLeftTrigger) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
|
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
|
||||||
newLeftTrigger, true);
|
newLeftTrigger, true);
|
||||||
mOldLeftTrigger = newLeftTrigger;
|
mOldLeftTrigger = newLeftTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
|
||||||
if (newRightTrigger != mOldRightTrigger) {
|
if (newRightTrigger != mOldRightTrigger) {
|
||||||
mControllerEventListener.onAxisEvent(mVendorName,
|
mControllerEventListener.onAxisEvent(mVendorName,
|
||||||
controllerId,
|
controllerId,
|
||||||
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
|
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
|
||||||
newRightTrigger, true);
|
newRightTrigger, true);
|
||||||
mOldRightTrigger = newRightTrigger;
|
mOldRightTrigger = newRightTrigger;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateEvent(StateEvent event) {
|
public void onStateEvent(StateEvent event) {
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
switch (event.getState()) {
|
switch (event.getState()) {
|
||||||
case StateEvent.STATE_CONNECTION:
|
case StateEvent.STATE_CONNECTION:
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case StateEvent.ACTION_DISCONNECTED:
|
case StateEvent.ACTION_DISCONNECTED:
|
||||||
// disconnected from controller
|
// disconnected from controller
|
||||||
mControllerEventListener.onDisconnected(mVendorName,
|
mControllerEventListener.onDisconnected(mVendorName,
|
||||||
event.getControllerId());
|
event.getControllerId());
|
||||||
break;
|
break;
|
||||||
case StateEvent.ACTION_CONNECTED:
|
case StateEvent.ACTION_CONNECTED:
|
||||||
// connected to controller
|
// connected to controller
|
||||||
mControllerEventListener.onConnected(mVendorName,
|
mControllerEventListener.onConnected(mVendorName,
|
||||||
event.getControllerId());
|
event.getControllerId());
|
||||||
break;
|
break;
|
||||||
case StateEvent.ACTION_CONNECTING:
|
case StateEvent.ACTION_CONNECTING:
|
||||||
// attempting to connect to controller
|
// attempting to connect to controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case StateEvent.STATE_POWER_LOW:
|
case StateEvent.STATE_POWER_LOW:
|
||||||
if (event.getAction() == StateEvent.ACTION_TRUE) {
|
if (event.getAction() == StateEvent.ACTION_TRUE) {
|
||||||
// controller has entered low power state
|
// controller has entered low power state
|
||||||
} else {
|
} else {
|
||||||
// controller has entered normal power state
|
// controller has entered normal power state
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Controller mController = null;
|
private Controller mController = null;
|
||||||
|
|
||||||
public void onCreate(Context context) {
|
public void onCreate(Context context) {
|
||||||
mController = Controller.getInstance(context);
|
mController = Controller.getInstance(context);
|
||||||
|
|
||||||
mController.init();
|
mController.init();
|
||||||
mController.setListener(this, new Handler());
|
mController.setListener(this, new Handler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mController.onPause();
|
mController.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
mController.onResume();
|
mController.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
mController.exit();
|
mController.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControllerEventListener mControllerEventListener;
|
private ControllerEventListener mControllerEventListener;
|
||||||
@Override
|
@Override
|
||||||
public void setControllerEventListener(ControllerEventListener listener) {
|
public void setControllerEventListener(ControllerEventListener listener) {
|
||||||
mControllerEventListener = listener;
|
mControllerEventListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
|
public boolean dispatchKeyEvent(android.view.KeyEvent event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
|
public boolean dispatchGenericMotionEvent(android.view.MotionEvent event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,16 +26,16 @@ import android.view.MotionEvent;
|
||||||
public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyListener,
|
public class GameControllerNibiru implements OnControllerSeviceListener, OnKeyListener,
|
||||||
OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate {
|
OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameControllerDelegate {
|
||||||
|
|
||||||
private static final String TAG = "NibiruTag";
|
private static final String TAG = "NibiruTag";
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SparseIntArray mKeyMap;
|
private SparseIntArray mKeyMap;
|
||||||
private ControllerEventListener mControllerEventListener = null;
|
private ControllerEventListener mControllerEventListener = null;
|
||||||
private ControllerService mControllerService = null;
|
private ControllerService mControllerService = null;
|
||||||
|
|
||||||
public GameControllerNibiru() {
|
public GameControllerNibiru() {
|
||||||
mKeyMap = new SparseIntArray(20);
|
mKeyMap = new SparseIntArray(20);
|
||||||
|
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_A , GameControllerDelegate.BUTTON_A);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_A , GameControllerDelegate.BUTTON_A);
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_B , GameControllerDelegate.BUTTON_B);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_B , GameControllerDelegate.BUTTON_B);
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_X , GameControllerDelegate.BUTTON_X);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_X , GameControllerDelegate.BUTTON_X);
|
||||||
|
@ -52,188 +52,188 @@ OnSimpleStickListener, OnAccListener, OnGyroListener, OnStateListener, GameContr
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_SELECT , GameControllerDelegate.BUTTON_SELECT);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_SELECT , GameControllerDelegate.BUTTON_SELECT);
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBL , GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBL , GameControllerDelegate.BUTTON_LEFT_THUMBSTICK);
|
||||||
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBR , GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
mKeyMap.put(ControllerKeyEvent.KEYCODE_BUTTON_THUMBR , GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setControllerEventListener(ControllerEventListener listener) {
|
public void setControllerEventListener(ControllerEventListener listener) {
|
||||||
mControllerEventListener = listener;
|
mControllerEventListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreate(Context context) {
|
public void onCreate(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
|
||||||
mControllerService = Controller.getControllerService();
|
mControllerService = Controller.getControllerService(context);
|
||||||
if (mControllerService != null) {
|
if (mControllerService != null) {
|
||||||
mControllerService.setControllerServiceListener(this);
|
mControllerService.setControllerServiceListener(this);
|
||||||
mControllerService.setStateListener(this);
|
mControllerService.setStateListener(this);
|
||||||
mControllerService.setKeyListener(this);
|
mControllerService.setKeyListener(this);
|
||||||
mControllerService.setSimpleStickListener(this);
|
mControllerService.setSimpleStickListener(this);
|
||||||
//mControllerService.setAccListener(this);
|
//mControllerService.setAccListener(this);
|
||||||
//mControllerService.setGyroListener(this);
|
//mControllerService.setGyroListener(this);
|
||||||
mControllerService.setEnableLR2(true);
|
mControllerService.setEnableL2R2(true);
|
||||||
mControllerService.setAutoKeyUpMode(false);
|
mControllerService.setAutoKeyUpMode(false);
|
||||||
|
|
||||||
mControllerService.checkNibiruInstall(mContext, false);
|
mControllerService.checkNibiruInstall(mContext, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (mControllerService != null) {
|
if (mControllerService != null) {
|
||||||
mControllerService.setEnable(false);
|
mControllerService.setEnable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
if (mControllerService != null) {
|
if (mControllerService != null) {
|
||||||
if (mControllerService.isServiceEnable()) {
|
if (mControllerService.isServiceEnable()) {
|
||||||
//onControllerServiceReady(true);
|
//onControllerServiceReady(true);
|
||||||
} else {
|
} else {
|
||||||
if (mControllerService.checkNibiruInstall(mContext, false)) {
|
if (mControllerService.checkNibiruInstall(mContext, false)) {
|
||||||
try {
|
try {
|
||||||
mControllerService.register(mContext);
|
mControllerService.register(mContext);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mControllerService.setEnable(true);
|
mControllerService.setEnable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if( mControllerService != null ){
|
if( mControllerService != null ){
|
||||||
mControllerService.unregister();
|
mControllerService.unregister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerServiceReady(boolean isSucc) {
|
public void onControllerServiceReady(boolean isSucc) {
|
||||||
if( isSucc )
|
if( isSucc )
|
||||||
{
|
{
|
||||||
if( !mControllerService.hasDeviceConnected() ){
|
if( !mControllerService.hasDeviceConnected() ){
|
||||||
Bundle bun = new Bundle();
|
Bundle bun = new Bundle();
|
||||||
bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false);
|
bun.putBoolean(ControllerService.FLAG_IS_SHOW_GAMEPAD_TIP, false);
|
||||||
try {
|
/*try {
|
||||||
mControllerService.showDeviceManagerUI(mContext, bun);
|
mControllerService.showDeviceManagerUI(mContext, bun);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
public void onControllerKeyDown(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||||
if (mKeyMap.get(keyCode) == 0) {
|
if (mKeyMap.get(keyCode) == 0) {
|
||||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
try {
|
try {
|
||||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||||
|
|
||||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||||
mKeyMap.get(keyCode), true, 1.0f, false);
|
mKeyMap.get(keyCode), true, 1.0f, false);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
public void onControllerKeyUp(int playerOrder, int keyCode, ControllerKeyEvent event) {
|
||||||
if (mKeyMap.get(keyCode) == 0) {
|
if (mKeyMap.get(keyCode) == 0) {
|
||||||
Log.e(TAG, "Didn't map the key: " + keyCode);
|
Log.e(TAG, "Didn't map the key: " + keyCode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
try {
|
try {
|
||||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||||
|
|
||||||
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
mControllerEventListener.onButtonEvent(controllerDevice.getDeviceName(), controllerDevice.getDeviceId(),
|
||||||
mKeyMap.get(keyCode), false, 0.0f, false);
|
mKeyMap.get(keyCode), false, 0.0f, false);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLeftStickChanged(int playerOrder, float x, float y) {
|
public void onLeftStickChanged(int playerOrder, float x, float y) {
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
try {
|
try {
|
||||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||||
|
|
||||||
String deviceName = controllerDevice.getDeviceName();
|
String deviceName = controllerDevice.getDeviceName();
|
||||||
int deviceId = controllerDevice.getDeviceId();
|
int deviceId = controllerDevice.getDeviceId();
|
||||||
|
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||||
GameControllerDelegate.THUMBSTICK_LEFT_X, x, true);
|
GameControllerDelegate.THUMBSTICK_LEFT_X, x, true);
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||||
GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true);
|
GameControllerDelegate.THUMBSTICK_LEFT_Y, y, true);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRightStickChanged(int playerOrder, float x, float y) {
|
public void onRightStickChanged(int playerOrder, float x, float y) {
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
try {
|
try {
|
||||||
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
ControllerDevice controllerDevice = mControllerService.getDeviceByPlayerOrder(playerOrder);
|
||||||
|
|
||||||
String deviceName = controllerDevice.getDeviceName();
|
String deviceName = controllerDevice.getDeviceName();
|
||||||
int deviceId = controllerDevice.getDeviceId();
|
int deviceId = controllerDevice.getDeviceId();
|
||||||
|
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||||
GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true);
|
GameControllerDelegate.THUMBSTICK_RIGHT_X, x, true);
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
mControllerEventListener.onAxisEvent(deviceName, deviceId,
|
||||||
GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true);
|
GameControllerDelegate.THUMBSTICK_RIGHT_Y, y, true);
|
||||||
} catch (ControllerServiceException e) {
|
} catch (ControllerServiceException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) {
|
public void onControllerStateChanged(int playerOrder, int state, ControllerDevice device) {
|
||||||
if (mControllerEventListener != null) {
|
if (mControllerEventListener != null) {
|
||||||
if (state == ControllerDevice.STATE_CONN)
|
if (state == ControllerDevice.STATE_CONN)
|
||||||
{
|
{
|
||||||
mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId());
|
mControllerEventListener.onConnected(device.getDeviceName(), device.getDeviceId());
|
||||||
}
|
}
|
||||||
else if (state == ControllerDevice.STATE_DISCONN)
|
else if (state == ControllerDevice.STATE_DISCONN)
|
||||||
{
|
{
|
||||||
mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId());
|
mControllerEventListener.onDisconnected(device.getDeviceName(), device.getDeviceId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event){
|
public boolean dispatchGenericMotionEvent(MotionEvent event){
|
||||||
return mControllerService.handleExternalInput(event);
|
return mControllerService.handleExternalInput(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dispatchKeyEvent(KeyEvent event){
|
public boolean dispatchKeyEvent(KeyEvent event){
|
||||||
return mControllerService.handleExternalInput(event);
|
return mControllerService.handleExternalInput(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerAccEvent(int playerOrder, AccEvent event) {
|
public void onControllerAccEvent(int playerOrder, AccEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onControllerGyroEvent(int playerOrder, GyroEvent event) {
|
public void onControllerGyroEvent(int playerOrder, GyroEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBluetoothStateChanged(int state) {
|
public void onBluetoothStateChanged(int state) {
|
||||||
Log.d(TAG, "onBluetoothStateChanged:"+state);
|
Log.d(TAG, "onBluetoothStateChanged:"+state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,17 +11,17 @@ import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
public class GameControllerOuya implements GameControllerDelegate{
|
public class GameControllerOuya implements GameControllerDelegate{
|
||||||
|
|
||||||
private SparseIntArray mKeyMap;
|
|
||||||
|
|
||||||
private SparseArray<String> mGameController = new SparseArray<String>();
|
private SparseIntArray mKeyMap;
|
||||||
|
|
||||||
public GameControllerOuya(){
|
private SparseArray<String> mGameController = new SparseArray<String>();
|
||||||
mKeyMap = new SparseIntArray(20);
|
|
||||||
mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B);
|
public GameControllerOuya(){
|
||||||
mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A);
|
mKeyMap = new SparseIntArray(20);
|
||||||
mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X);
|
mKeyMap.put(OuyaController.BUTTON_A, GameControllerDelegate.BUTTON_B);
|
||||||
mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
mKeyMap.put(OuyaController.BUTTON_O, GameControllerDelegate.BUTTON_A);
|
||||||
|
mKeyMap.put(OuyaController.BUTTON_U, GameControllerDelegate.BUTTON_X);
|
||||||
|
mKeyMap.put(OuyaController.BUTTON_Y, GameControllerDelegate.BUTTON_Y);
|
||||||
mKeyMap.put(OuyaController.BUTTON_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
mKeyMap.put(OuyaController.BUTTON_DPAD_DOWN, GameControllerDelegate.BUTTON_DPAD_DOWN);
|
||||||
mKeyMap.put(OuyaController.BUTTON_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
mKeyMap.put(OuyaController.BUTTON_DPAD_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
|
||||||
mKeyMap.put(OuyaController.BUTTON_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
mKeyMap.put(OuyaController.BUTTON_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
|
||||||
|
@ -34,150 +34,142 @@ public class GameControllerOuya implements GameControllerDelegate{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCreate(Context context) {
|
public void onCreate(Context context) {
|
||||||
OuyaController.init(context);
|
OuyaController.init(context);
|
||||||
/*GameControllerAdapter.addRunnableToFrameStartList(new Runnable() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
OuyaController.startOfFrame();
|
|
||||||
}
|
|
||||||
|
|
||||||
});*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private float mOldLeftThumbstickX = 0.0f;
|
private float mOldLeftThumbstickX = 0.0f;
|
||||||
private float mOldLeftThumbstickY = 0.0f;
|
private float mOldLeftThumbstickY = 0.0f;
|
||||||
private float mOldRightThumbstickX = 0.0f;
|
private float mOldRightThumbstickX = 0.0f;
|
||||||
private float mOldRightThumbstickY = 0.0f;
|
private float mOldRightThumbstickY = 0.0f;
|
||||||
|
|
||||||
private float mOldLeftTrigger = 0.0f;
|
private float mOldLeftTrigger = 0.0f;
|
||||||
private float mOldRightTrigger = 0.0f;
|
private float mOldRightTrigger = 0.0f;
|
||||||
|
|
||||||
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
public boolean dispatchGenericMotionEvent(MotionEvent event) {
|
||||||
boolean handled = OuyaController.onGenericMotionEvent(event);
|
boolean handled = OuyaController.onGenericMotionEvent(event);
|
||||||
|
|
||||||
if (handled && mControllerEventListener != null)
|
if (handled && mControllerEventListener != null)
|
||||||
{
|
{
|
||||||
int deviceId = event.getDeviceId();
|
int deviceId = event.getDeviceId();
|
||||||
String deviceName = event.getDevice().getName();
|
String deviceName = event.getDevice().getName();
|
||||||
OuyaController c = OuyaController.getControllerByDeviceId(deviceId);
|
OuyaController c = OuyaController.getControllerByDeviceId(deviceId);
|
||||||
if (mGameController.get(deviceId) == null) {
|
if (mGameController.get(deviceId) == null) {
|
||||||
GameControllerHelper.gatherControllers(mGameController);
|
GameControllerHelper.gatherControllers(mGameController);
|
||||||
mGameController.append(deviceId, deviceName);
|
mGameController.append(deviceId, deviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2);
|
float newLeftTrigger = c.getAxisValue(OuyaController.AXIS_L2);
|
||||||
if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) {
|
if (Float.compare(newLeftTrigger, mOldLeftTrigger) != 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, newLeftTrigger, true);
|
||||||
mOldLeftTrigger = newLeftTrigger;
|
mOldLeftTrigger = newLeftTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2);
|
float newRightTrigger = c.getAxisValue(OuyaController.AXIS_R2);
|
||||||
if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) {
|
if (Float.compare(newRightTrigger, mOldRightTrigger) != 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, newRightTrigger, true);
|
||||||
mOldRightTrigger = newRightTrigger;
|
mOldRightTrigger = newRightTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X);
|
float newLeftThumbstickX = c.getAxisValue(OuyaController.AXIS_LS_X);
|
||||||
if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) {
|
if (Float.compare(newLeftThumbstickX, mOldLeftThumbstickX) != 0) {
|
||||||
if (Float.compare(newLeftThumbstickX, 0.0f) == 0) {
|
if (Float.compare(newLeftThumbstickX, 0.0f) == 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, 0.0f, true);
|
||||||
}else {
|
}else {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_X, newLeftThumbstickX, true);
|
||||||
}
|
}
|
||||||
mOldLeftThumbstickX = newLeftThumbstickX;
|
mOldLeftThumbstickX = newLeftThumbstickX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y);
|
float newLeftThumbstickY = c.getAxisValue(OuyaController.AXIS_LS_Y);
|
||||||
if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) {
|
if (Float.compare(newLeftThumbstickY, mOldLeftThumbstickY) != 0) {
|
||||||
if (Float.compare(newLeftThumbstickY, 0.0f) == 0) {
|
if (Float.compare(newLeftThumbstickY, 0.0f) == 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, 0.0f, true);
|
||||||
}else {
|
}else {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newLeftThumbstickY, true);
|
||||||
}
|
}
|
||||||
mOldLeftThumbstickY = newLeftThumbstickY;
|
mOldLeftThumbstickY = newLeftThumbstickY;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X);
|
float newRightThumbstickX = c.getAxisValue(OuyaController.AXIS_RS_X);
|
||||||
if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) {
|
if (Float.compare(newRightThumbstickX, mOldRightThumbstickX) != 0) {
|
||||||
if (Float.compare(newRightThumbstickX, 0.0f) == 0) {
|
if (Float.compare(newRightThumbstickX, 0.0f) == 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, 0.0f, true);
|
||||||
}else {
|
}else {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newRightThumbstickX, true);
|
||||||
}
|
}
|
||||||
mOldRightThumbstickX = newRightThumbstickX;
|
mOldRightThumbstickX = newRightThumbstickX;
|
||||||
}
|
}
|
||||||
|
|
||||||
float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y);
|
float newRightThumbstickY = c.getAxisValue(OuyaController.AXIS_RS_Y);
|
||||||
if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) {
|
if (Float.compare(newRightThumbstickY, mOldRightThumbstickY) != 0) {
|
||||||
if (Float.compare(newRightThumbstickY, 0.0f) == 0) {
|
if (Float.compare(newRightThumbstickY, 0.0f) == 0) {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, 0.0f, true);
|
||||||
}else {
|
}else {
|
||||||
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true);
|
mControllerEventListener.onAxisEvent(deviceName, deviceId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newRightThumbstickY, true);
|
||||||
}
|
}
|
||||||
mOldRightThumbstickY = newRightThumbstickY;
|
mOldRightThumbstickY = newRightThumbstickY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
boolean handled = false;
|
boolean handled = false;
|
||||||
|
|
||||||
int action = event.getAction();
|
int action = event.getAction();
|
||||||
int keyCode = event.getKeyCode();
|
int keyCode = event.getKeyCode();
|
||||||
|
|
||||||
if (action == KeyEvent.ACTION_DOWN) {
|
if (action == KeyEvent.ACTION_DOWN) {
|
||||||
handled = OuyaController.onKeyDown(keyCode, event);
|
handled = OuyaController.onKeyDown(keyCode, event);
|
||||||
}
|
}
|
||||||
else if (action == KeyEvent.ACTION_UP) {
|
else if (action == KeyEvent.ACTION_UP) {
|
||||||
handled = OuyaController.onKeyUp(keyCode, event);
|
handled = OuyaController.onKeyUp(keyCode, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled && mControllerEventListener != null) {
|
if (handled && mControllerEventListener != null) {
|
||||||
boolean isAnalog = false;
|
boolean isAnalog = false;
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){
|
if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL || keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR){
|
||||||
isAnalog = true;
|
isAnalog = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int deviceId = event.getDeviceId();
|
int deviceId = event.getDeviceId();
|
||||||
String deviceName = event.getDevice().getName();
|
String deviceName = event.getDevice().getName();
|
||||||
|
|
||||||
if (mGameController.get(deviceId) == null) {
|
if (mGameController.get(deviceId) == null) {
|
||||||
GameControllerHelper.gatherControllers(mGameController);
|
GameControllerHelper.gatherControllers(mGameController);
|
||||||
mGameController.append(deviceId, deviceName);
|
mGameController.append(deviceId, deviceName);
|
||||||
}
|
}
|
||||||
if (action == KeyEvent.ACTION_DOWN) {
|
if (action == KeyEvent.ACTION_DOWN) {
|
||||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog);
|
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), true, 1.0f, isAnalog);
|
||||||
}else {
|
}else {
|
||||||
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog);
|
mControllerEventListener.onButtonEvent(deviceName, deviceId, mKeyMap.get(keyCode), false, 0.0f, isAnalog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
// show the mouse cursor
|
// show the mouse cursor
|
||||||
OuyaController.showCursor(true);
|
OuyaController.showCursor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
// hide the mouse cursor
|
// hide the mouse cursor
|
||||||
OuyaController.showCursor(false);
|
OuyaController.showCursor(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControllerEventListener mControllerEventListener;
|
private ControllerEventListener mControllerEventListener;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setControllerEventListener(ControllerEventListener listener) {
|
public void setControllerEventListener(ControllerEventListener listener) {
|
||||||
mControllerEventListener = listener;
|
mControllerEventListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ import android.preference.PreferenceManager.OnActivityResultListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.opengl.GLSurfaceView;
|
|
||||||
|
|
||||||
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
@ -213,7 +212,7 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// Constructors
|
// Constructors
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -252,17 +251,25 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
}
|
||||||
Cocos2dxHelper.onResume();
|
|
||||||
this.mGLSurfaceView.onResume();
|
@Override
|
||||||
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
|
||||||
|
if (hasFocus) {
|
||||||
|
Cocos2dxHelper.onResume();
|
||||||
|
mGLSurfaceView.onResume();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Cocos2dxHelper.onPause();
|
||||||
|
mGLSurfaceView.onPause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
Cocos2dxHelper.onPause();
|
|
||||||
this.mGLSurfaceView.onPause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -49,7 +49,7 @@ import android.util.DisplayMetrics;
|
||||||
import android.util.Log; //Enhance API modification
|
import android.util.Log; //Enhance API modification
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.content.ServiceConnection; //Enhance API modification
|
import android.content.ServiceConnection; //Enhance API modification
|
||||||
|
|
||||||
import com.enhance.gameservice.IGameTuningService; //Enhance API modification
|
import com.enhance.gameservice.IGameTuningService; //Enhance API modification
|
||||||
|
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class Cocos2dxHttpURLConnection
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add header
|
//Add header
|
||||||
static void addRequestHeader(HttpURLConnection urlConnection, String key, String value) {
|
static void addRequestHeader(HttpURLConnection urlConnection, String key, String value) {
|
||||||
urlConnection.setRequestProperty(key, value);
|
urlConnection.setRequestProperty(key, value);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ public class Cocos2dxHttpURLConnection
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getResponseHeaders(HttpURLConnection http) {
|
static String getResponseHeaders(HttpURLConnection http) {
|
||||||
Map<String, List<String>> headers = http.getHeaderFields();
|
Map<String, List<String>> headers = http.getHeaderFields();
|
||||||
if (null == headers) {
|
if (null == headers) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,5 @@
|
||||||
package org.cocos2dx.lib;
|
package org.cocos2dx.lib;
|
||||||
|
|
||||||
public class Cocos2dxJavascriptJavaBridge {
|
public class Cocos2dxJavascriptJavaBridge {
|
||||||
public static native int evalString(String value);
|
public static native int evalString(String value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,12 +147,12 @@ public class Cocos2dxRenderer implements GLSurfaceView.Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleOnPause() {
|
public void handleOnPause() {
|
||||||
/**
|
/**
|
||||||
* onPause may be invoked before onSurfaceCreated,
|
* onPause may be invoked before onSurfaceCreated,
|
||||||
* and engine will be initialized correctly after
|
* and engine will be initialized correctly after
|
||||||
* onSurfaceCreated is invoked. Can not invoke any
|
* onSurfaceCreated is invoked. Can not invoke any
|
||||||
* native method before onSurfaceCreated is invoked
|
* native method before onSurfaceCreated is invoked
|
||||||
*/
|
*/
|
||||||
if (! mNativeInitCompleted)
|
if (! mNativeInitCompleted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class Cocos2dxWebViewHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
Cocos2dxWebView webView = webViews.get(index);
|
Cocos2dxWebView webView = webViews.get(index);
|
||||||
if (webView != null) {
|
if (webView != null) {
|
||||||
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
|
webView.loadDataWithBaseURL(baseURL, data, mimeType, encoding, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -138,7 +138,7 @@ public class Cocos2dxWebViewHelper {
|
||||||
public void run() {
|
public void run() {
|
||||||
Cocos2dxWebView webView = webViews.get(index);
|
Cocos2dxWebView webView = webViews.get(index);
|
||||||
if (webView != null) {
|
if (webView != null) {
|
||||||
webView.loadDataWithBaseURL(baseUrl, data, null, null, null);
|
webView.loadDataWithBaseURL(baseUrl, data, null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
void setBundle(NSBundle* bundle);
|
void setBundle(NSBundle* bundle);
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
virtual bool isFileExistInternal(const std::string& filePath) const override;
|
||||||
|
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
NSBundle* getBundle() const;
|
NSBundle* getBundle() const;
|
||||||
NSBundle* _bundle;
|
NSBundle* _bundle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,6 +27,8 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "CCFileUtils-apple.h"
|
#include "CCFileUtils-apple.h"
|
||||||
|
|
||||||
|
#include <ftw.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
|
@ -392,6 +394,31 @@ bool FileUtilsApple::isFileExistInternal(const std::string& filePath) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
||||||
|
{
|
||||||
|
auto ret = remove(fpath);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
log("Fail to remove: %s ",fpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtilsApple::removeDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
if (path.size() > 0 && path[path.size() - 1] != '/')
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail to remove directory, path must termniate with '/': %s", path.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nftw(path.c_str(),unlink_cb, 64, FTW_DEPTH | FTW_PHYS))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const
|
std::string FileUtilsApple::getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename) const
|
||||||
{
|
{
|
||||||
if (directory[0] != '/')
|
if (directory[0] != '/')
|
||||||
|
@ -439,9 +466,9 @@ ValueMap FileUtilsApple::getValueMapFromData(const char* filedata, int filesize)
|
||||||
NSPropertyListFormat format;
|
NSPropertyListFormat format;
|
||||||
NSError* error;
|
NSError* error;
|
||||||
NSDictionary* dict = [NSPropertyListSerialization propertyListWithData:file options:NSPropertyListImmutable format:&format error:&error];
|
NSDictionary* dict = [NSPropertyListSerialization propertyListWithData:file options:NSPropertyListImmutable format:&format error:&error];
|
||||||
|
|
||||||
ValueMap ret;
|
ValueMap ret;
|
||||||
|
|
||||||
if (dict != nil)
|
if (dict != nil)
|
||||||
{
|
{
|
||||||
for (id key in [dict allKeys])
|
for (id key in [dict allKeys])
|
||||||
|
@ -455,21 +482,41 @@ ValueMap FileUtilsApple::getValueMapFromData(const char* filedata, int filesize)
|
||||||
|
|
||||||
bool FileUtilsApple::writeToFile(ValueMap& dict, const std::string &fullPath)
|
bool FileUtilsApple::writeToFile(ValueMap& dict, const std::string &fullPath)
|
||||||
{
|
{
|
||||||
|
return writeValueMapToFile(dict, fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeValueMapToFile(ValueMap& dict, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
|
||||||
//CCLOG("iOS||Mac Dictionary %d write to file %s", dict->_ID, fullPath.c_str());
|
//CCLOG("iOS||Mac Dictionary %d write to file %s", dict->_ID, fullPath.c_str());
|
||||||
NSMutableDictionary *nsDict = [NSMutableDictionary dictionary];
|
NSMutableDictionary *nsDict = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
|
for (auto iter = dict.begin(); iter != dict.end(); ++iter)
|
||||||
{
|
{
|
||||||
addObjectToNSDict(iter->first, iter->second, nsDict);
|
addObjectToNSDict(iter->first, iter->second, nsDict);
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *file = [NSString stringWithUTF8String:fullPath.c_str()];
|
NSString *file = [NSString stringWithUTF8String:fullPath.c_str()];
|
||||||
// do it atomically
|
// do it atomically
|
||||||
[nsDict writeToFile:file atomically:YES];
|
[nsDict writeToFile:file atomically:YES];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileUtils::writeValueVectorToFile(ValueVector vecData, const std::string& fullPath)
|
||||||
|
{
|
||||||
|
NSString* path = [NSString stringWithUTF8String:fullPath.c_str()];
|
||||||
|
NSMutableArray* array = [NSMutableArray array];
|
||||||
|
|
||||||
|
for (const auto &e : vecData)
|
||||||
|
{
|
||||||
|
addObjectToNSArray(e, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
[array writeToFile:path atomically:YES];
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
ValueVector FileUtilsApple::getValueVectorFromFile(const std::string& filename)
|
ValueVector FileUtilsApple::getValueVectorFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
// NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
// NSString* pPath = [NSString stringWithUTF8String:pFileName];
|
||||||
|
|
|
@ -35,6 +35,7 @@ THE SOFTWARE.
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifndef CC_RESOURCE_FOLDER_LINUX
|
#ifndef CC_RESOURCE_FOLDER_LINUX
|
||||||
#define CC_RESOURCE_FOLDER_LINUX ("/Resources/")
|
#define CC_RESOURCE_FOLDER_LINUX ("/Resources/")
|
||||||
|
@ -116,7 +117,7 @@ bool FileUtilsLinux::isFileExistInternal(const std::string& strFilePath) const
|
||||||
{ // Not absolute path, add the default root path at the beginning.
|
{ // Not absolute path, add the default root path at the beginning.
|
||||||
strPath.insert(0, _defaultResRootPath);
|
strPath.insert(0, _defaultResRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat sts;
|
struct stat sts;
|
||||||
return (stat(strPath.c_str(), &sts) != -1) ? true : false;
|
return (stat(strPath.c_str(), &sts) != -1) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
bool init();
|
bool init();
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const;
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -30,6 +30,7 @@ THE SOFTWARE.
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
#include <Shlobj.h>
|
#include <Shlobj.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -56,6 +57,81 @@ static inline std::string convertPathFormatToUnixStyle(const std::string& path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::wstring StringUtf8ToWideChar(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::wstring ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
int nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, nullptr, 0);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
WCHAR* wideCharString = new WCHAR[nNum + 1];
|
||||||
|
wideCharString[0] = 0;
|
||||||
|
|
||||||
|
nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, wideCharString, nNum + 1);
|
||||||
|
|
||||||
|
ret = wideCharString;
|
||||||
|
delete[] wideCharString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to WideChar code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string StringWideCharToUtf8(const std::wstring& strWideChar)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strWideChar.empty())
|
||||||
|
{
|
||||||
|
int nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* utf8String = new char[nNum + 1];
|
||||||
|
utf8String[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, utf8String, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = utf8String;
|
||||||
|
delete[] utf8String;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Utf8 code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
||||||
|
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* ansiString = new char[nNum + 1];
|
||||||
|
ansiString[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = ansiString;
|
||||||
|
delete[] ansiString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void _checkPath()
|
static void _checkPath()
|
||||||
{
|
{
|
||||||
if (0 == s_resourcePath.length())
|
if (0 == s_resourcePath.length())
|
||||||
|
@ -99,23 +175,36 @@ bool FileUtilsWin32::init()
|
||||||
return FileUtils::init();
|
return FileUtils::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileUtilsWin32::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
|
{
|
||||||
|
unsigned long fAttrib = GetFileAttributes(StringUtf8ToWideChar(dirPath).c_str());
|
||||||
|
if (fAttrib != INVALID_FILE_ATTRIBUTES &&
|
||||||
|
(fAttrib & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FileUtilsWin32::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
return UTF8StringToMultiByte(filenameUtf8);
|
||||||
|
}
|
||||||
|
|
||||||
bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
||||||
{
|
{
|
||||||
if (0 == strFilePath.length())
|
if (0 == strFilePath.length())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string strPath = strFilePath;
|
std::string strPath = strFilePath;
|
||||||
if (!isAbsolutePath(strPath))
|
if (!isAbsolutePath(strPath))
|
||||||
{ // Not absolute path, add the default root path at the beginning.
|
{ // Not absolute path, add the default root path at the beginning.
|
||||||
strPath.insert(0, _defaultResRootPath);
|
strPath.insert(0, _defaultResRootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
WCHAR utf16Buf[CC_MAX_PATH] = {0};
|
DWORD attr = GetFileAttributesW(StringUtf8ToWideChar(strPath).c_str());
|
||||||
MultiByteToWideChar(CP_UTF8, 0, strPath.c_str(), -1, utf16Buf, sizeof(utf16Buf)/sizeof(utf16Buf[0]));
|
|
||||||
|
|
||||||
DWORD attr = GetFileAttributesW(utf16Buf);
|
|
||||||
if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
|
if(attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
|
||||||
return false; // not a file
|
return false; // not a file
|
||||||
return true;
|
return true;
|
||||||
|
@ -123,7 +212,7 @@ bool FileUtilsWin32::isFileExistInternal(const std::string& strFilePath) const
|
||||||
|
|
||||||
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
bool FileUtilsWin32::isAbsolutePath(const std::string& strPath) const
|
||||||
{
|
{
|
||||||
if ( (strPath.length() > 2
|
if ( (strPath.length() > 2
|
||||||
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
|
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
|
||||||
&& strPath[1] == ':') || (strPath[0] == '/' && strPath[1] == '/'))
|
&& strPath[1] == ':') || (strPath[0] == '/' && strPath[1] == '/'))
|
||||||
{
|
{
|
||||||
|
@ -139,9 +228,9 @@ static bool checkFileName(const std::string& fullPath, const std::string& filena
|
||||||
size_t len = tmpPath.length();
|
size_t len = tmpPath.length();
|
||||||
size_t nl = filename.length();
|
size_t nl = filename.length();
|
||||||
std::string realName;
|
std::string realName;
|
||||||
|
|
||||||
while (tmpPath.length() >= len - nl && tmpPath.length()>2)
|
while (tmpPath.length() >= len - nl && tmpPath.length()>2)
|
||||||
{
|
{
|
||||||
//CCLOG("%s", tmpPath.c_str());
|
//CCLOG("%s", tmpPath.c_str());
|
||||||
WIN32_FIND_DATAA data;
|
WIN32_FIND_DATAA data;
|
||||||
HANDLE h = FindFirstFileA(tmpPath.c_str(), &data);
|
HANDLE h = FindFirstFileA(tmpPath.c_str(), &data);
|
||||||
|
@ -158,11 +247,10 @@ static bool checkFileName(const std::string& fullPath, const std::string& filena
|
||||||
{
|
{
|
||||||
std::string msg = "File path error: \"";
|
std::string msg = "File path error: \"";
|
||||||
msg.append(filename).append("\" the real name is: ").append(realName);
|
msg.append(filename).append("\" the real name is: ").append(realName);
|
||||||
|
|
||||||
CCLOG("%s", msg.c_str());
|
CCLOG("%s", msg.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -174,7 +262,7 @@ static bool checkFileName(const std::string& fullPath, const std::string& filena
|
||||||
tmpPath = tmpPath.substr(0, tmpPath.rfind("/"));
|
tmpPath = tmpPath.substr(0, tmpPath.rfind("/"));
|
||||||
} while (tmpPath.back() == '.');
|
} while (tmpPath.back() == '.');
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Data getData(const std::string& filename, bool forString)
|
static Data getData(const std::string& filename, bool forString)
|
||||||
|
@ -193,14 +281,11 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filename);
|
||||||
|
|
||||||
// check if the filename uses correct case characters
|
// check if the filename uses correct case characters
|
||||||
CC_BREAK_IF(!checkFileName(fullPath, filename));
|
checkFileName(fullPath, filename);
|
||||||
|
|
||||||
WCHAR wszBuf[CC_MAX_PATH] = {0};
|
HANDLE fileHandle = ::CreateFile(StringUtf8ToWideChar(fullPath).c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
|
||||||
MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
|
|
||||||
|
|
||||||
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
|
|
||||||
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
|
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
size = ::GetFileSize(fileHandle, nullptr);
|
size = ::GetFileSize(fileHandle, nullptr);
|
||||||
|
|
||||||
if (forString)
|
if (forString)
|
||||||
|
@ -224,10 +309,10 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
buffer = nullptr;
|
buffer = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
Data ret;
|
Data ret;
|
||||||
|
|
||||||
if (buffer == nullptr || size == 0)
|
if (buffer == nullptr || size == 0)
|
||||||
|
@ -254,15 +339,15 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
std::string FileUtilsWin32::getStringFromFile(const std::string& filename)
|
std::string FileUtilsWin32::getStringFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
Data data = getData(filename, true);
|
Data data = getData(filename, true);
|
||||||
if (data.isNull())
|
if (data.isNull())
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ret((const char*)data.getBytes());
|
std::string ret((const char*)data.getBytes());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
Data FileUtilsWin32::getDataFromFile(const std::string& filename)
|
Data FileUtilsWin32::getDataFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
return getData(filename, false);
|
return getData(filename, false);
|
||||||
|
@ -278,14 +363,11 @@ unsigned char* FileUtilsWin32::getFileData(const std::string& filename, const ch
|
||||||
std::string fullPath = fullPathForFilename(filename);
|
std::string fullPath = fullPathForFilename(filename);
|
||||||
|
|
||||||
// check if the filename uses correct case characters
|
// check if the filename uses correct case characters
|
||||||
CC_BREAK_IF(!checkFileName(fullPath, filename));
|
checkFileName(fullPath, filename);
|
||||||
|
|
||||||
WCHAR wszBuf[CC_MAX_PATH] = {0};
|
HANDLE fileHandle = ::CreateFile(StringUtf8ToWideChar(fullPath).c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
|
||||||
MultiByteToWideChar(CP_UTF8, 0, fullPath.c_str(), -1, wszBuf, sizeof(wszBuf)/sizeof(wszBuf[0]));
|
|
||||||
|
|
||||||
HANDLE fileHandle = ::CreateFileW(wszBuf, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, nullptr);
|
|
||||||
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
|
CC_BREAK_IF(fileHandle == INVALID_HANDLE_VALUE);
|
||||||
|
|
||||||
*size = ::GetFileSize(fileHandle, nullptr);
|
*size = ::GetFileSize(fileHandle, nullptr);
|
||||||
|
|
||||||
pBuffer = (unsigned char*) malloc(*size);
|
pBuffer = (unsigned char*) malloc(*size);
|
||||||
|
@ -300,7 +382,7 @@ unsigned char* FileUtilsWin32::getFileData(const std::string& filename, const ch
|
||||||
pBuffer = nullptr;
|
pBuffer = nullptr;
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (! pBuffer)
|
if (! pBuffer)
|
||||||
{
|
{
|
||||||
std::string msg = "Get data from file(";
|
std::string msg = "Get data from file(";
|
||||||
|
@ -328,7 +410,7 @@ std::string FileUtilsWin32::getFullPathForDirectoryAndFilename(const std::string
|
||||||
{
|
{
|
||||||
std::string unixDirectory = convertPathFormatToUnixStyle(strDirectory);
|
std::string unixDirectory = convertPathFormatToUnixStyle(strDirectory);
|
||||||
std::string unixFilename = convertPathFormatToUnixStyle(strFilename);
|
std::string unixFilename = convertPathFormatToUnixStyle(strFilename);
|
||||||
|
|
||||||
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,49 +422,191 @@ string FileUtilsWin32::getWritablePath() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe
|
// Get full path of executable, e.g. c:\Program Files (x86)\My Game Folder\MyGame.exe
|
||||||
char full_path[CC_MAX_PATH + 1];
|
WCHAR full_path[CC_MAX_PATH + 1] = { 0 };
|
||||||
::GetModuleFileNameA(nullptr, full_path, CC_MAX_PATH + 1);
|
::GetModuleFileName(nullptr, full_path, CC_MAX_PATH + 1);
|
||||||
|
|
||||||
// Debug app uses executable directory; Non-debug app uses local app data directory
|
// Debug app uses executable directory; Non-debug app uses local app data directory
|
||||||
//#ifndef _DEBUG
|
//#ifndef _DEBUG
|
||||||
// Get filename of executable only, e.g. MyGame.exe
|
// Get filename of executable only, e.g. MyGame.exe
|
||||||
char *base_name = strrchr(full_path, '\\');
|
WCHAR *base_name = wcsrchr(full_path, '\\');
|
||||||
|
wstring retPath;
|
||||||
|
if(base_name)
|
||||||
|
{
|
||||||
|
WCHAR app_data_path[CC_MAX_PATH + 1];
|
||||||
|
|
||||||
if(base_name)
|
// Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data
|
||||||
|
if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, app_data_path)))
|
||||||
{
|
{
|
||||||
char app_data_path[CC_MAX_PATH + 1];
|
wstring ret(app_data_path);
|
||||||
|
|
||||||
// Get local app data directory, e.g. C:\Documents and Settings\username\Local Settings\Application Data
|
// Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe
|
||||||
if (SUCCEEDED(SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, SHGFP_TYPE_CURRENT, app_data_path)))
|
ret += base_name;
|
||||||
|
|
||||||
|
// Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame
|
||||||
|
ret = ret.substr(0, ret.rfind(L"."));
|
||||||
|
|
||||||
|
ret += L"\\";
|
||||||
|
|
||||||
|
// Create directory
|
||||||
|
if (SUCCEEDED(SHCreateDirectoryEx(nullptr, ret.c_str(), nullptr)))
|
||||||
{
|
{
|
||||||
string ret((char*)app_data_path);
|
retPath = ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (retPath.empty())
|
||||||
|
//#endif // not defined _DEBUG
|
||||||
|
{
|
||||||
|
// If fetching of local app data directory fails, use the executable one
|
||||||
|
retPath = full_path;
|
||||||
|
|
||||||
// Adding executable filename, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame.exe
|
// remove xxx.exe
|
||||||
ret += base_name;
|
retPath = retPath.substr(0, retPath.rfind(L"\\") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Remove ".exe" extension, e.g. C:\Documents and Settings\username\Local Settings\Application Data\MyGame
|
return convertPathFormatToUnixStyle(StringWideCharToUtf8(retPath));
|
||||||
ret = ret.substr(0, ret.rfind("."));
|
}
|
||||||
|
|
||||||
ret += "\\";
|
bool FileUtilsWin32::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
||||||
|
{
|
||||||
|
CCASSERT(!path.empty(), "Invalid path");
|
||||||
|
std::string oldPath = path + oldname;
|
||||||
|
std::string newPath = path + name;
|
||||||
|
|
||||||
// Create directory
|
std::regex pat("\\/");
|
||||||
if (SUCCEEDED(SHCreateDirectoryExA(nullptr, ret.c_str(), nullptr)))
|
std::string _old = std::regex_replace(oldPath, pat, "\\");
|
||||||
|
std::string _new = std::regex_replace(newPath, pat, "\\");
|
||||||
|
|
||||||
|
std::wstring _wNew = StringUtf8ToWideChar(_new);
|
||||||
|
|
||||||
|
if (FileUtils::getInstance()->isFileExist(_new))
|
||||||
|
{
|
||||||
|
if (!DeleteFile(_wNew.c_str()))
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail to delete file %s !Error code is 0x%x", newPath.c_str(), GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MoveFile(StringUtf8ToWideChar(_old).c_str(), _wNew.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail to rename file %s to %s !Error code is 0x%x", oldPath.c_str(), newPath.c_str(), GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FileUtilsWin32::createDirectory(const std::string& dirPath)
|
||||||
|
{
|
||||||
|
CCASSERT(!dirPath.empty(), "Invalid path");
|
||||||
|
|
||||||
|
if (isDirectoryExist(dirPath))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
std::wstring path = StringUtf8ToWideChar(dirPath);
|
||||||
|
|
||||||
|
// Split the path
|
||||||
|
size_t start = 0;
|
||||||
|
size_t found = path.find_first_of(L"/\\", start);
|
||||||
|
std::wstring subpath;
|
||||||
|
std::vector<std::wstring> dirs;
|
||||||
|
|
||||||
|
if (found != std::wstring::npos)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
subpath = path.substr(start, found - start + 1);
|
||||||
|
if (!subpath.empty())
|
||||||
|
dirs.push_back(subpath);
|
||||||
|
start = found + 1;
|
||||||
|
found = path.find_first_of(L"/\\", start);
|
||||||
|
if (found == std::wstring::npos)
|
||||||
|
{
|
||||||
|
if (start < path.length())
|
||||||
{
|
{
|
||||||
return convertPathFormatToUnixStyle(ret);
|
dirs.push_back(path.substr(start));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((GetFileAttributes(path.c_str())) == INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
subpath = L"";
|
||||||
|
for (unsigned int i = 0; i < dirs.size(); ++i)
|
||||||
|
{
|
||||||
|
subpath += dirs[i];
|
||||||
|
|
||||||
|
std::string utf8Path = StringWideCharToUtf8(subpath);
|
||||||
|
if (!isDirectoryExist(utf8Path))
|
||||||
|
{
|
||||||
|
BOOL ret = CreateDirectory(subpath.c_str(), NULL);
|
||||||
|
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail create directory %s !Error code is 0x%x", utf8Path.c_str(), GetLastError());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endif // not defined _DEBUG
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// If fetching of local app data directory fails, use the executable one
|
bool FileUtilsWin32::removeFile(const std::string &filepath)
|
||||||
string ret((char*)full_path);
|
{
|
||||||
|
std::regex pat("\\/");
|
||||||
|
std::string win32path = std::regex_replace(filepath, pat, "\\");
|
||||||
|
|
||||||
// remove xxx.exe
|
if (DeleteFile(StringUtf8ToWideChar(win32path).c_str()))
|
||||||
ret = ret.substr(0, ret.rfind("\\") + 1);
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOGERROR("Fail remove file %s !Error code is 0x%x", filepath.c_str(), GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = convertPathFormatToUnixStyle(ret);
|
bool FileUtilsWin32::removeDirectory(const std::string& dirPath)
|
||||||
|
{
|
||||||
return ret;
|
std::wstring wpath = StringUtf8ToWideChar(dirPath);
|
||||||
|
std::wstring files = wpath + L"*.*";
|
||||||
|
WIN32_FIND_DATA wfd;
|
||||||
|
HANDLE search = FindFirstFileEx(files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
|
||||||
|
bool ret = true;
|
||||||
|
if (search != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
BOOL find = true;
|
||||||
|
while (find)
|
||||||
|
{
|
||||||
|
//. ..
|
||||||
|
if (wfd.cFileName[0] != '.')
|
||||||
|
{
|
||||||
|
std::wstring temp = wpath + wfd.cFileName;
|
||||||
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
temp += '/';
|
||||||
|
ret = ret && this->removeDirectory(StringWideCharToUtf8(temp));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
|
||||||
|
ret = ret && DeleteFile(temp.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
find = FindNextFile(search, &wfd);
|
||||||
|
}
|
||||||
|
FindClose(search);
|
||||||
|
}
|
||||||
|
if (ret && RemoveDirectory(wpath.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -49,11 +49,53 @@ class CC_DLL FileUtilsWin32 : public FileUtils
|
||||||
public:
|
public:
|
||||||
/* override funtions */
|
/* override funtions */
|
||||||
bool init();
|
bool init();
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const override;
|
||||||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
virtual bool isAbsolutePath(const std::string& strPath) const override;
|
||||||
|
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames a file under the given directory.
|
||||||
|
*
|
||||||
|
* @param path The parent directory path of the file, it must be an absolute path.
|
||||||
|
* @param oldname The current name of the file.
|
||||||
|
* @param name The new name of the file.
|
||||||
|
* @return True if the file have been renamed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool renameFile(const std::string &path, const std::string &oldname, const std::string &name) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a directory exists without considering search paths and resolution orders.
|
||||||
|
* @param dirPath The directory (with absolute path) to look up for
|
||||||
|
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||||
|
*/
|
||||||
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a file.
|
||||||
|
*
|
||||||
|
* @param filepath The full path of the file, it must be an absolute path.
|
||||||
|
* @return True if the file have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeFile(const std::string &filepath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been created successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool createDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The full path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets resource file data
|
* Gets resource file data
|
||||||
|
@ -64,7 +106,7 @@ protected:
|
||||||
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
||||||
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
||||||
*/
|
*/
|
||||||
virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override;
|
CC_DEPRECATED_ATTRIBUTE virtual unsigned char* getFileData(const std::string& filename, const char* mode, ssize_t * size) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets string from a file.
|
* Gets string from a file.
|
||||||
|
|
|
@ -23,9 +23,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "CCFileUtilsWinRT.h"
|
#include "CCFileUtilsWinRT.h"
|
||||||
|
#include <regex>
|
||||||
#include "CCWinRTUtils.h"
|
#include "CCWinRTUtils.h"
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -47,13 +47,87 @@ static inline std::string convertPathFormatToUnixStyle(const std::string& path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::wstring StringUtf8ToWideChar(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::wstring ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
int nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, nullptr, 0);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
WCHAR* wideCharString = new WCHAR[nNum + 1];
|
||||||
|
wideCharString[0] = 0;
|
||||||
|
|
||||||
|
nNum = MultiByteToWideChar(CP_UTF8, 0, strUtf8.c_str(), -1, wideCharString, nNum + 1);
|
||||||
|
|
||||||
|
ret = wideCharString;
|
||||||
|
delete[] wideCharString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to WideChar code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string StringWideCharToUtf8(const std::wstring& strWideChar)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strWideChar.empty())
|
||||||
|
{
|
||||||
|
int nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* utf8String = new char[nNum + 1];
|
||||||
|
utf8String[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_UTF8, 0, strWideChar.c_str(), -1, utf8String, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = utf8String;
|
||||||
|
delete[] utf8String;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Utf8 code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string UTF8StringToMultiByte(const std::string& strUtf8)
|
||||||
|
{
|
||||||
|
std::string ret;
|
||||||
|
if (!strUtf8.empty())
|
||||||
|
{
|
||||||
|
std::wstring strWideChar = StringUtf8ToWideChar(strUtf8);
|
||||||
|
int nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, nullptr, 0, nullptr, FALSE);
|
||||||
|
if (nNum)
|
||||||
|
{
|
||||||
|
char* ansiString = new char[nNum + 1];
|
||||||
|
ansiString[0] = 0;
|
||||||
|
|
||||||
|
nNum = WideCharToMultiByte(CP_ACP, 0, strWideChar.c_str(), -1, ansiString, nNum + 1, nullptr, FALSE);
|
||||||
|
|
||||||
|
ret = ansiString;
|
||||||
|
delete[] ansiString;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCLOG("Wrong convert to Ansi code:0x%x", GetLastError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void _checkPath()
|
static void _checkPath()
|
||||||
{
|
{
|
||||||
if (s_pszResourcePath.empty())
|
if (s_pszResourcePath.empty())
|
||||||
{
|
{
|
||||||
// TODO: needs to be tested
|
// TODO: needs to be tested
|
||||||
s_pszResourcePath = convertPathFormatToUnixStyle(CCFileUtilsWinRT::getAppPath() + '\\' + "Assets\\Resources" + '\\');
|
s_pszResourcePath = convertPathFormatToUnixStyle(CCFileUtilsWinRT::getAppPath() + '\\' + "Assets\\Resources" + '\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +146,6 @@ FileUtils* FileUtils::getInstance()
|
||||||
return s_sharedFileUtils;
|
return s_sharedFileUtils;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CCFileUtilsWinRT::CCFileUtilsWinRT()
|
CCFileUtilsWinRT::CCFileUtilsWinRT()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -100,6 +173,11 @@ std::string CCFileUtilsWinRT::getFullPathForDirectoryAndFilename(const std::stri
|
||||||
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
return FileUtils::getFullPathForDirectoryAndFilename(unixDirectory, unixFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CCFileUtilsWinRT::getSuitableFOpen(const std::string& filenameUtf8) const
|
||||||
|
{
|
||||||
|
return UTF8StringToMultiByte(filenameUtf8);
|
||||||
|
}
|
||||||
|
|
||||||
bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -121,9 +199,113 @@ bool CCFileUtilsWinRT::isFileExistInternal(const std::string& strFilePath) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::isDirectoryExistInternal(const std::string& dirPath) const
|
||||||
|
{
|
||||||
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||||
|
std::wstring wdirPath(dirPath.begin(), dirPath.end());
|
||||||
|
if (GetFileAttributesEx(wdirPath.c_str(), GetFileExInfoStandard, &wfad))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::createDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
CCASSERT(!path.empty(), "Invalid path");
|
||||||
|
|
||||||
|
if (isDirectoryExist(path))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// Split the path
|
||||||
|
size_t start = 0;
|
||||||
|
size_t found = path.find_first_of("/\\", start);
|
||||||
|
std::string subpath;
|
||||||
|
std::vector<std::string> dirs;
|
||||||
|
|
||||||
|
if (found != std::string::npos)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
subpath = path.substr(start, found - start + 1);
|
||||||
|
if (!subpath.empty())
|
||||||
|
dirs.push_back(subpath);
|
||||||
|
start = found + 1;
|
||||||
|
found = path.find_first_of("/\\", start);
|
||||||
|
if (found == std::string::npos)
|
||||||
|
{
|
||||||
|
if (start < path.length())
|
||||||
|
{
|
||||||
|
dirs.push_back(path.substr(start));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WIN32_FILE_ATTRIBUTE_DATA wfad;
|
||||||
|
std::wstring wpath(path.begin(), path.end());
|
||||||
|
if (!(GetFileAttributesEx(wpath.c_str(), GetFileExInfoStandard, &wfad)))
|
||||||
|
{
|
||||||
|
subpath = "";
|
||||||
|
for (unsigned int i = 0; i < dirs.size(); ++i)
|
||||||
|
{
|
||||||
|
subpath += dirs[i];
|
||||||
|
if (i > 0 && !isDirectoryExist(subpath))
|
||||||
|
{
|
||||||
|
std::wstring wsubpath(subpath.begin(), subpath.end());
|
||||||
|
BOOL ret = CreateDirectory(wsubpath.c_str(), NULL);
|
||||||
|
if (!ret && ERROR_ALREADY_EXISTS != GetLastError())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::removeDirectory(const std::string& path)
|
||||||
|
{
|
||||||
|
std::wstring wpath = std::wstring(path.begin(), path.end());
|
||||||
|
std::wstring files = wpath + L"*.*";
|
||||||
|
WIN32_FIND_DATA wfd;
|
||||||
|
HANDLE search = FindFirstFileEx(files.c_str(), FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0);
|
||||||
|
bool ret = true;
|
||||||
|
if (search != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
|
BOOL find = true;
|
||||||
|
while (find)
|
||||||
|
{
|
||||||
|
//. ..
|
||||||
|
if (wfd.cFileName[0] != '.')
|
||||||
|
{
|
||||||
|
std::wstring temp = wpath + wfd.cFileName;
|
||||||
|
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
|
{
|
||||||
|
temp += '/';
|
||||||
|
ret = ret && this->removeDirectory(std::string(temp.begin(), temp.end()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetFileAttributes(temp.c_str(), FILE_ATTRIBUTE_NORMAL);
|
||||||
|
ret = ret && DeleteFile(temp.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
find = FindNextFile(search, &wfd);
|
||||||
|
}
|
||||||
|
FindClose(search);
|
||||||
|
}
|
||||||
|
if (ret && RemoveDirectory(wpath.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||||
{
|
{
|
||||||
if ( strPath.length() > 2
|
if ( strPath.length() > 2
|
||||||
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
|
&& ( (strPath[0] >= 'a' && strPath[0] <= 'z') || (strPath[0] >= 'A' && strPath[0] <= 'Z') )
|
||||||
&& strPath[1] == ':')
|
&& strPath[1] == ':')
|
||||||
{
|
{
|
||||||
|
@ -132,19 +314,47 @@ bool CCFileUtilsWinRT::isAbsolutePath(const std::string& strPath) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::removeFile(const std::string &path)
|
||||||
|
{
|
||||||
|
std::wstring wpath(path.begin(), path.end());
|
||||||
|
if (DeleteFile(wpath.c_str()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCFileUtilsWinRT::renameFile(const std::string &path, const std::string &oldname, const std::string &name)
|
||||||
|
{
|
||||||
|
CCASSERT(!path.empty(), "Invalid path");
|
||||||
|
std::string oldPath = path + oldname;
|
||||||
|
std::string newPath = path + name;
|
||||||
|
|
||||||
|
std::regex pat("\\/");
|
||||||
|
std::string _old = std::regex_replace(oldPath, pat, "\\");
|
||||||
|
std::string _new = std::regex_replace(newPath, pat, "\\");
|
||||||
|
if (MoveFileEx(std::wstring(_old.begin(), _old.end()).c_str(),
|
||||||
|
std::wstring(_new.begin(), _new.end()).c_str(),
|
||||||
|
MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static Data getData(const std::string& filename, bool forString)
|
static Data getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
if (filename.empty())
|
if (filename.empty())
|
||||||
{
|
{
|
||||||
CCASSERT(!filename.empty(), "Invalid filename!");
|
CCASSERT(!filename.empty(), "Invalid filename!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Data ret;
|
Data ret;
|
||||||
unsigned char* buffer = nullptr;
|
unsigned char* buffer = nullptr;
|
||||||
ssize_t size = 0;
|
ssize_t size = 0;
|
||||||
const char* mode = nullptr;
|
const char* mode = nullptr;
|
||||||
mode = "rb";
|
mode = "rb";
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Read the file from hardware
|
// Read the file from hardware
|
||||||
|
@ -154,7 +364,7 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
fseek(fp,0,SEEK_END);
|
fseek(fp,0,SEEK_END);
|
||||||
size = ftell(fp);
|
size = ftell(fp);
|
||||||
fseek(fp,0,SEEK_SET);
|
fseek(fp,0,SEEK_SET);
|
||||||
|
|
||||||
if (forString)
|
if (forString)
|
||||||
{
|
{
|
||||||
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (size + 1));
|
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (size + 1));
|
||||||
|
@ -164,11 +374,11 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
|
buffer = (unsigned char*)malloc(sizeof(unsigned char) * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = fread(buffer, sizeof(unsigned char), size, fp);
|
size = fread(buffer, sizeof(unsigned char), size, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (nullptr == buffer || 0 == size)
|
if (nullptr == buffer || 0 == size)
|
||||||
{
|
{
|
||||||
std::string msg = "Get data from file(";
|
std::string msg = "Get data from file(";
|
||||||
|
@ -179,31 +389,31 @@ static Data getData(const std::string& filename, bool forString)
|
||||||
{
|
{
|
||||||
ret.fastSet(buffer, size);
|
ret.fastSet(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CCFileUtilsWinRT::getStringFromFile(const std::string& filename)
|
std::string CCFileUtilsWinRT::getStringFromFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
Data data = getData(filename, true);
|
Data data = getData(filename, true);
|
||||||
if (data.isNull())
|
if (data.isNull())
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
std::string ret((const char*)data.getBytes());
|
std::string ret((const char*)data.getBytes());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
string CCFileUtilsWinRT::getWritablePath() const
|
string CCFileUtilsWinRT::getWritablePath() const
|
||||||
{
|
{
|
||||||
auto localFolderPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
|
auto localFolderPath = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
|
||||||
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(localFolderPath)) + '\\');
|
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(localFolderPath)) + '\\');
|
||||||
}
|
}
|
||||||
|
|
||||||
string CCFileUtilsWinRT::getAppPath()
|
string CCFileUtilsWinRT::getAppPath()
|
||||||
{
|
{
|
||||||
Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
|
Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
|
||||||
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(package->InstalledLocation->Path)));
|
return convertPathFormatToUnixStyle(std::string(PlatformStringToString(package->InstalledLocation->Path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -49,13 +49,55 @@ public:
|
||||||
bool init();
|
bool init();
|
||||||
virtual std::string getWritablePath() const;
|
virtual std::string getWritablePath() const;
|
||||||
virtual bool isAbsolutePath(const std::string& strPath) const;
|
virtual bool isAbsolutePath(const std::string& strPath) const;
|
||||||
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const override;
|
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath) const override;
|
||||||
virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) const override;
|
virtual std::string getFullPathForDirectoryAndFilename(const std::string& strDirectory, const std::string& strFilename) const override;
|
||||||
virtual std::string getStringFromFile(const std::string& filename) override;
|
virtual std::string getStringFromFile(const std::string& filename) override;
|
||||||
|
virtual std::string getSuitableFOpen(const std::string& filenameUtf8) const override;
|
||||||
static std::string getAppPath();
|
static std::string getAppPath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool isFileExistInternal(const std::string& strFilePath) const;
|
virtual bool isFileExistInternal(const std::string& strFilePath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renames a file under the given directory.
|
||||||
|
*
|
||||||
|
* @param path The parent directory path of the file, it must be an absolute path.
|
||||||
|
* @param oldname The current name of the file.
|
||||||
|
* @param name The new name of the file.
|
||||||
|
* @return True if the file have been renamed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool renameFile(const std::string &path, const std::string &oldname, const std::string &name) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a directory exists without considering search paths and resolution orders.
|
||||||
|
* @param dirPath The directory (with absolute path) to look up for
|
||||||
|
* @return Returns true if the directory found at the given absolute path, otherwise returns false
|
||||||
|
*/
|
||||||
|
virtual bool isDirectoryExistInternal(const std::string& dirPath) const override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a file.
|
||||||
|
*
|
||||||
|
* @param filepath The full path of the file, it must be an absolute path.
|
||||||
|
* @return True if the file have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeFile(const std::string &filepath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been created successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool createDirectory(const std::string& dirPath) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a directory.
|
||||||
|
*
|
||||||
|
* @param dirPath The full path of the directory, it must be an absolute path.
|
||||||
|
* @return True if the directory have been removed successfully, false if not.
|
||||||
|
*/
|
||||||
|
virtual bool removeDirectory(const std::string& dirPath) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of platform group
|
// end of platform group
|
||||||
|
|
|
@ -61,8 +61,6 @@ TextureCache * TextureCache::getInstance()
|
||||||
|
|
||||||
TextureCache::TextureCache()
|
TextureCache::TextureCache()
|
||||||
: _loadingThread(nullptr)
|
: _loadingThread(nullptr)
|
||||||
, _asyncStructQueue(nullptr)
|
|
||||||
, _imageInfoQueue(nullptr)
|
|
||||||
, _needQuit(false)
|
, _needQuit(false)
|
||||||
, _asyncRefCount(0)
|
, _asyncRefCount(0)
|
||||||
{
|
{
|
||||||
|
@ -96,6 +94,43 @@ std::string TextureCache::getDescription() const
|
||||||
return StringUtils::format("<TextureCache | Number of textures = %d>", static_cast<int>(_textures.size()));
|
return StringUtils::format("<TextureCache | Number of textures = %d>", static_cast<int>(_textures.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct TextureCache::AsyncStruct
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AsyncStruct(const std::string& fn, std::function<void(Texture2D*)> f) : filename(fn), callback(f), loadSuccess(false) {}
|
||||||
|
|
||||||
|
std::string filename;
|
||||||
|
std::function<void(Texture2D*)> callback;
|
||||||
|
Image image;
|
||||||
|
bool loadSuccess;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
The addImageAsync logic follow the steps:
|
||||||
|
- find the image has been add or not, if not add an AsyncStruct to _requestQueue (GL thread)
|
||||||
|
- get AsyncStruct from _requestQueue, load res and fill image data to AsyncStruct.image, then add AsyncStruct to _responseQueue (Load thread)
|
||||||
|
- on schedule callback, get AsyncStruct from _responseQueue, convert image to texture, then delete AsyncStruct (GL thread)
|
||||||
|
|
||||||
|
the Critical Area include these members:
|
||||||
|
- _requestQueue: locked by _requestMutex
|
||||||
|
- _responseQueue: locked by _responseMutex
|
||||||
|
|
||||||
|
the object's life time:
|
||||||
|
- AsyncStruct: construct and destruct in GL thread
|
||||||
|
- image data: new in Load thread, delete in GL thread(by Image instance)
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- all AsyncStruct referenced in _asyncStructQueue, for unbind function use.
|
||||||
|
|
||||||
|
How to deal add image many times?
|
||||||
|
- At first, this situation is abnormal, we only ensure the logic is correct.
|
||||||
|
- If the image has been loaded, the after load image call will return immediately.
|
||||||
|
- If the image request is in queue already, there will be have more than one request in queue,
|
||||||
|
- In addImageAsyncCallback, will deduplacated the request to ensure only create one texture.
|
||||||
|
|
||||||
|
Does process all response in addImageAsyncCallback consume more time?
|
||||||
|
- Convert image to texture faster than load image from disk, so this isn't a problem.
|
||||||
|
*/
|
||||||
void TextureCache::addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback)
|
void TextureCache::addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback)
|
||||||
{
|
{
|
||||||
Texture2D *texture = nullptr;
|
Texture2D *texture = nullptr;
|
||||||
|
@ -119,14 +154,10 @@ void TextureCache::addImageAsync(const std::string &path, const std::function<vo
|
||||||
}
|
}
|
||||||
|
|
||||||
// lazy init
|
// lazy init
|
||||||
if (_asyncStructQueue == nullptr)
|
if (_loadingThread == nullptr)
|
||||||
{
|
{
|
||||||
_asyncStructQueue = new (std::nothrow) deque<AsyncStruct*>();
|
|
||||||
_imageInfoQueue = new (std::nothrow) deque<ImageInfo*>();
|
|
||||||
|
|
||||||
// create a new thread to load images
|
// create a new thread to load images
|
||||||
_loadingThread = new std::thread(&TextureCache::loadImage, this);
|
_loadingThread = new std::thread(&TextureCache::loadImage, this);
|
||||||
|
|
||||||
_needQuit = false;
|
_needQuit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,213 +170,152 @@ void TextureCache::addImageAsync(const std::string &path, const std::function<vo
|
||||||
|
|
||||||
// generate async struct
|
// generate async struct
|
||||||
AsyncStruct *data = new (std::nothrow) AsyncStruct(fullpath, callback);
|
AsyncStruct *data = new (std::nothrow) AsyncStruct(fullpath, callback);
|
||||||
|
|
||||||
// add async struct into queue
|
// add async struct into queue
|
||||||
_asyncMutex.lock();
|
_asyncStructQueue.push_back(data);
|
||||||
_asyncStructQueue->push_back(data);
|
_requestMutex.lock();
|
||||||
_asyncMutex.unlock();
|
_requestQueue.push_back(data);
|
||||||
|
_requestMutex.unlock();
|
||||||
|
|
||||||
_sleepCondition.notify_one();
|
_sleepCondition.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::unbindImageAsync(const std::string& filename)
|
void TextureCache::unbindImageAsync(const std::string& filename)
|
||||||
{
|
{
|
||||||
|
if (_asyncStructQueue.empty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename);
|
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(filename);
|
||||||
|
for (auto it = _asyncStructQueue.begin(); it != _asyncStructQueue.end(); ++it)
|
||||||
_asyncMutex.lock();
|
|
||||||
|
|
||||||
if (_asyncStructQueue && !_asyncStructQueue->empty())
|
|
||||||
{
|
{
|
||||||
for (auto it = _asyncStructQueue->begin(); it != _asyncStructQueue->end(); ++it)
|
if ((*it)->filename == fullpath)
|
||||||
{
|
|
||||||
if ((*it)->filename == fullpath)
|
|
||||||
{
|
|
||||||
(*it)->callback = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_imageInfoQueue && !_imageInfoQueue->empty())
|
|
||||||
{
|
|
||||||
for (auto it = _imageInfoQueue->begin(); it != _imageInfoQueue->end(); ++it)
|
|
||||||
{
|
|
||||||
if ((*it)->asyncStruct->filename == fullpath)
|
|
||||||
{
|
|
||||||
(*it)->asyncStruct->callback = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_asyncMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextureCache::unbindAllImageAsync()
|
|
||||||
{
|
|
||||||
_asyncMutex.lock();
|
|
||||||
if (_asyncStructQueue && !_asyncStructQueue->empty())
|
|
||||||
{
|
|
||||||
for (auto it = _asyncStructQueue->begin(); it != _asyncStructQueue->end(); ++it)
|
|
||||||
{
|
{
|
||||||
(*it)->callback = nullptr;
|
(*it)->callback = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_imageInfoQueue && !_imageInfoQueue->empty())
|
}
|
||||||
|
|
||||||
|
void TextureCache::unbindAllImageAsync()
|
||||||
|
{
|
||||||
|
if (_asyncStructQueue.empty())
|
||||||
{
|
{
|
||||||
for (auto it = _imageInfoQueue->begin(); it != _imageInfoQueue->end(); ++it)
|
return;
|
||||||
{
|
|
||||||
(*it)->asyncStruct->callback = nullptr;
|
}
|
||||||
}
|
for (auto it = _asyncStructQueue.begin(); it != _asyncStructQueue.end(); ++it)
|
||||||
|
{
|
||||||
|
(*it)->callback = nullptr;
|
||||||
}
|
}
|
||||||
_asyncMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::loadImage()
|
void TextureCache::loadImage()
|
||||||
{
|
{
|
||||||
AsyncStruct *asyncStruct = nullptr;
|
AsyncStruct *asyncStruct = nullptr;
|
||||||
|
std::mutex signalMutex;
|
||||||
while (true)
|
std::unique_lock<std::mutex> signal(signalMutex);
|
||||||
|
while (!_needQuit)
|
||||||
{
|
{
|
||||||
_asyncMutex.lock();
|
// pop an AsyncStruct from request queue
|
||||||
if (_asyncStructQueue->empty())
|
_requestMutex.lock();
|
||||||
|
if(_requestQueue.empty())
|
||||||
{
|
{
|
||||||
_asyncMutex.unlock();
|
asyncStruct = nullptr;
|
||||||
if (_needQuit) {
|
}else
|
||||||
break;
|
{
|
||||||
}
|
asyncStruct = _requestQueue.front();
|
||||||
else {
|
_requestQueue.pop_front();
|
||||||
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
||||||
_sleepCondition.wait(lk);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
_requestMutex.unlock();
|
||||||
{
|
|
||||||
asyncStruct = _asyncStructQueue->front();
|
if (nullptr == asyncStruct) {
|
||||||
_asyncMutex.unlock();
|
_sleepCondition.wait(signal);
|
||||||
}
|
continue;
|
||||||
|
|
||||||
Image *image = nullptr;
|
|
||||||
bool generateImage = false;
|
|
||||||
|
|
||||||
auto it = _textures.find(asyncStruct->filename);
|
|
||||||
if( it == _textures.end() )
|
|
||||||
{
|
|
||||||
ImageInfo *imageInfo;
|
|
||||||
size_t pos = 0;
|
|
||||||
_asyncMutex.lock();
|
|
||||||
size_t infoSize = _imageInfoQueue->size();
|
|
||||||
for (; pos < infoSize; pos++)
|
|
||||||
{
|
|
||||||
imageInfo = (*_imageInfoQueue)[pos];
|
|
||||||
if(imageInfo->asyncStruct->filename.compare(asyncStruct->filename) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_asyncMutex.unlock();
|
|
||||||
if(infoSize == 0 || pos == infoSize)
|
|
||||||
generateImage = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load image
|
||||||
|
asyncStruct->loadSuccess = asyncStruct->image.initWithImageFileThreadSafe(asyncStruct->filename);
|
||||||
|
|
||||||
if (generateImage)
|
// push the asyncStruct to response queue
|
||||||
{
|
_responseMutex.lock();
|
||||||
const std::string& filename = asyncStruct->filename;
|
_responseQueue.push_back(asyncStruct);
|
||||||
// generate image
|
_responseMutex.unlock();
|
||||||
image = new (std::nothrow) Image();
|
|
||||||
if (image && !image->initWithImageFileThreadSafe(filename))
|
|
||||||
{
|
|
||||||
CC_SAFE_RELEASE(image);
|
|
||||||
CCLOG("can not load %s", filename.c_str());
|
|
||||||
_asyncMutex.lock();
|
|
||||||
_asyncStructQueue->pop_front();
|
|
||||||
_asyncMutex.unlock();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate image info
|
|
||||||
ImageInfo *imageInfo = new (std::nothrow) ImageInfo();
|
|
||||||
imageInfo->asyncStruct = asyncStruct;
|
|
||||||
imageInfo->image = image;
|
|
||||||
|
|
||||||
// put the image info into the queue
|
|
||||||
_asyncMutex.lock();
|
|
||||||
_asyncStructQueue->pop_front();
|
|
||||||
_imageInfoQueue->push_back(imageInfo);
|
|
||||||
_asyncMutex.unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_asyncStructQueue != nullptr)
|
|
||||||
{
|
|
||||||
delete _asyncStructQueue;
|
|
||||||
_asyncStructQueue = nullptr;
|
|
||||||
delete _imageInfoQueue;
|
|
||||||
_imageInfoQueue = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextureCache::addImageAsyncCallBack(float dt)
|
void TextureCache::addImageAsyncCallBack(float dt)
|
||||||
{
|
{
|
||||||
// the image is generated in loading thread
|
Texture2D *texture = nullptr;
|
||||||
std::deque<ImageInfo*> *imagesQueue = _imageInfoQueue;
|
AsyncStruct *asyncStruct = nullptr;
|
||||||
|
while (true)
|
||||||
_asyncMutex.lock();
|
|
||||||
if (imagesQueue->empty())
|
|
||||||
{
|
{
|
||||||
_asyncMutex.unlock();
|
// pop an AsyncStruct from response queue
|
||||||
}
|
_responseMutex.lock();
|
||||||
else
|
if(_responseQueue.empty())
|
||||||
{
|
|
||||||
ImageInfo *imageInfo = imagesQueue->front();
|
|
||||||
imagesQueue->pop_front();
|
|
||||||
_asyncMutex.unlock();
|
|
||||||
|
|
||||||
AsyncStruct *asyncStruct = imageInfo->asyncStruct;
|
|
||||||
Image *image = imageInfo->image;
|
|
||||||
|
|
||||||
const std::string& filename = asyncStruct->filename;
|
|
||||||
|
|
||||||
Texture2D *texture = nullptr;
|
|
||||||
if (image)
|
|
||||||
{
|
{
|
||||||
// generate texture in render thread
|
asyncStruct = nullptr;
|
||||||
texture = new (std::nothrow) Texture2D();
|
}else
|
||||||
|
{
|
||||||
texture->initWithImage(image);
|
asyncStruct = _responseQueue.front();
|
||||||
//parse 9-patch info
|
_responseQueue.pop_front();
|
||||||
this->parseNinePatchImage(image, texture, filename);
|
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
// the asyncStruct's sequence order in _asyncStructQueue must equal to the order in _responseQueue
|
||||||
// cache the texture file name
|
CC_ASSERT(asyncStruct == _asyncStructQueue.front());
|
||||||
VolatileTextureMgr::addImageTexture(texture, filename);
|
_asyncStructQueue.pop_front();
|
||||||
#endif
|
}
|
||||||
// cache the texture. retain it, since it is added in the map
|
_responseMutex.unlock();
|
||||||
_textures.insert( std::make_pair(filename, texture) );
|
|
||||||
texture->retain();
|
if (nullptr == asyncStruct) {
|
||||||
|
break;
|
||||||
texture->autorelease();
|
}
|
||||||
|
|
||||||
|
// check the image has been convert to texture or not
|
||||||
|
auto it = _textures.find(asyncStruct->filename);
|
||||||
|
if(it != _textures.end())
|
||||||
|
{
|
||||||
|
texture = it->second;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto it = _textures.find(asyncStruct->filename);
|
// convert image to texture
|
||||||
if(it != _textures.end())
|
if (asyncStruct->loadSuccess)
|
||||||
texture = it->second;
|
{
|
||||||
|
Image* image = &(asyncStruct->image);
|
||||||
|
// generate texture in render thread
|
||||||
|
texture = new (std::nothrow) Texture2D();
|
||||||
|
|
||||||
|
texture->initWithImage(image);
|
||||||
|
//parse 9-patch info
|
||||||
|
this->parseNinePatchImage(image, texture, asyncStruct->filename);
|
||||||
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
|
// cache the texture file name
|
||||||
|
VolatileTextureMgr::addImageTexture(texture, asyncStruct->filename);
|
||||||
|
#endif
|
||||||
|
// cache the texture. retain it, since it is added in the map
|
||||||
|
_textures.insert( std::make_pair(asyncStruct->filename, texture) );
|
||||||
|
texture->retain();
|
||||||
|
|
||||||
|
texture->autorelease();
|
||||||
|
} else {
|
||||||
|
texture = nullptr;
|
||||||
|
CCLOG("cocos2d: failed to call TextureCache::addImageAsync(%s)", asyncStruct->filename.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// call callback function
|
||||||
if (asyncStruct->callback)
|
if (asyncStruct->callback)
|
||||||
{
|
{
|
||||||
asyncStruct->callback(texture);
|
(asyncStruct->callback)(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(image)
|
|
||||||
{
|
|
||||||
image->release();
|
|
||||||
}
|
|
||||||
delete asyncStruct;
|
|
||||||
delete imageInfo;
|
|
||||||
|
|
||||||
|
// release the asyncStruct
|
||||||
|
delete asyncStruct;
|
||||||
--_asyncRefCount;
|
--_asyncRefCount;
|
||||||
if (0 == _asyncRefCount)
|
}
|
||||||
{
|
|
||||||
Director::getInstance()->getScheduler()->unschedule(CC_SCHEDULE_SELECTOR(TextureCache::addImageAsyncCallBack), this);
|
if (0 == _asyncRefCount)
|
||||||
}
|
{
|
||||||
|
Director::getInstance()->getScheduler()->unschedule(CC_SCHEDULE_SELECTOR(TextureCache::addImageAsyncCallBack), this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,30 +209,18 @@ private:
|
||||||
void loadImage();
|
void loadImage();
|
||||||
void parseNinePatchImage(Image* image, Texture2D* texture, const std::string& path);
|
void parseNinePatchImage(Image* image, Texture2D* texture, const std::string& path);
|
||||||
public:
|
public:
|
||||||
struct AsyncStruct
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AsyncStruct(const std::string& fn, std::function<void(Texture2D*)> f) : filename(fn), callback(f) {}
|
|
||||||
|
|
||||||
std::string filename;
|
|
||||||
std::function<void(Texture2D*)> callback;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef struct _ImageInfo
|
struct AsyncStruct;
|
||||||
{
|
|
||||||
AsyncStruct *asyncStruct;
|
|
||||||
Image *image;
|
|
||||||
} ImageInfo;
|
|
||||||
|
|
||||||
std::thread* _loadingThread;
|
std::thread* _loadingThread;
|
||||||
|
|
||||||
std::deque<AsyncStruct*>* _asyncStructQueue;
|
std::deque<AsyncStruct*> _asyncStructQueue;
|
||||||
std::deque<ImageInfo*>* _imageInfoQueue;
|
std::deque<AsyncStruct*> _requestQueue;
|
||||||
|
std::deque<AsyncStruct*> _responseQueue;
|
||||||
|
|
||||||
std::mutex _asyncMutex;
|
std::mutex _requestMutex;
|
||||||
|
std::mutex _responseMutex;
|
||||||
std::mutex _sleepMutex;
|
|
||||||
std::condition_variable _sleepCondition;
|
std::condition_variable _sleepCondition;
|
||||||
|
|
||||||
bool _needQuit;
|
bool _needQuit;
|
||||||
|
|
|
@ -896,6 +896,16 @@ func
|
||||||
{
|
{
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method stopActionsByFlags
|
||||||
|
* @param {unsigned int} arg0
|
||||||
|
*/
|
||||||
|
stopActionsByFlags : function (
|
||||||
|
int
|
||||||
|
)
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method setNormalizedPosition
|
* @method setNormalizedPosition
|
||||||
* @param {vec2_object} arg0
|
* @param {vec2_object} arg0
|
||||||
|
@ -3244,6 +3254,16 @@ getTarget : function (
|
||||||
return cc.Node;
|
return cc.Node;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method getFlags
|
||||||
|
* @return {unsigned int}
|
||||||
|
*/
|
||||||
|
getFlags : function (
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method step
|
* @method step
|
||||||
* @param {float} arg0
|
* @param {float} arg0
|
||||||
|
@ -3264,6 +3284,16 @@ int
|
||||||
{
|
{
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method setFlags
|
||||||
|
* @param {unsigned int} arg0
|
||||||
|
*/
|
||||||
|
setFlags : function (
|
||||||
|
int
|
||||||
|
)
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getTag
|
* @method getTag
|
||||||
* @return {int}
|
* @return {int}
|
||||||
|
@ -5173,6 +5203,18 @@ ReverseTime : function (
|
||||||
*/
|
*/
|
||||||
cc.Animate = {
|
cc.Animate = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method initWithAnimation
|
||||||
|
* @param {cc.Animation} arg0
|
||||||
|
* @return {bool}
|
||||||
|
*/
|
||||||
|
initWithAnimation : function (
|
||||||
|
animation
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getAnimation
|
* @method getAnimation
|
||||||
* @return {cc.Animation|cc.Animation}
|
* @return {cc.Animation|cc.Animation}
|
||||||
|
@ -5184,15 +5226,13 @@ getAnimation : function(
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method initWithAnimation
|
* @method getCurrentFrameIndex
|
||||||
* @param {cc.Animation} arg0
|
* @return {int}
|
||||||
* @return {bool}
|
|
||||||
*/
|
*/
|
||||||
initWithAnimation : function (
|
getCurrentFrameIndex : function (
|
||||||
animation
|
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return false;
|
return 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6085,6 +6125,18 @@ str
|
||||||
return map_object;
|
return map_object;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method getFileSize
|
||||||
|
* @param {String} arg0
|
||||||
|
* @return {long}
|
||||||
|
*/
|
||||||
|
getFileSize : function (
|
||||||
|
str
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getValueMapFromData
|
* @method getValueMapFromData
|
||||||
* @param {char} arg0
|
* @param {char} arg0
|
||||||
|
@ -6122,15 +6174,17 @@ array
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method getFileSize
|
* @method writeStringToFile
|
||||||
* @param {String} arg0
|
* @param {String} arg0
|
||||||
* @return {long}
|
* @param {String} arg1
|
||||||
|
* @return {bool}
|
||||||
*/
|
*/
|
||||||
getFileSize : function (
|
writeStringToFile : function (
|
||||||
|
str,
|
||||||
str
|
str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return 0;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6167,6 +6221,20 @@ bool
|
||||||
{
|
{
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method writeValueVectorToFile
|
||||||
|
* @param {Array} arg0
|
||||||
|
* @param {String} arg1
|
||||||
|
* @return {bool}
|
||||||
|
*/
|
||||||
|
writeValueVectorToFile : function (
|
||||||
|
array,
|
||||||
|
str
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method isFileExist
|
* @method isFileExist
|
||||||
* @param {String} arg0
|
* @param {String} arg0
|
||||||
|
@ -6213,6 +6281,20 @@ str
|
||||||
return ;
|
return ;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method writeValueMapToFile
|
||||||
|
* @param {map_object} arg0
|
||||||
|
* @param {String} arg1
|
||||||
|
* @return {bool}
|
||||||
|
*/
|
||||||
|
writeValueMapToFile : function (
|
||||||
|
map,
|
||||||
|
str
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method setWritablePath
|
* @method setWritablePath
|
||||||
* @param {String} arg0
|
* @param {String} arg0
|
||||||
|
@ -9491,6 +9573,18 @@ node
|
||||||
{
|
{
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method removeActionsByFlags
|
||||||
|
* @param {unsigned int} arg0
|
||||||
|
* @param {cc.Node} arg1
|
||||||
|
*/
|
||||||
|
removeActionsByFlags : function (
|
||||||
|
int,
|
||||||
|
node
|
||||||
|
)
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method removeAllActions
|
* @method removeAllActions
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2385,6 +2385,26 @@ bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp
|
||||||
JS_ReportError(cx, "js_cocos2dx_Node_setOnEnterCallback : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_Node_setOnEnterCallback : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_Node_stopActionsByFlags(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::Node* cobj = (cocos2d::Node *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Node_stopActionsByFlags : Invalid Native Object");
|
||||||
|
if (argc == 1) {
|
||||||
|
unsigned int arg0;
|
||||||
|
ok &= jsval_to_uint32(cx, args.get(0), &arg0);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Node_stopActionsByFlags : Error processing arguments");
|
||||||
|
cobj->stopActionsByFlags(arg0);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_Node_stopActionsByFlags : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -4909,6 +4929,7 @@ void js_register_cocos2dx_Node(JSContext *cx, JS::HandleObject global) {
|
||||||
JS_FN("setSkewX", js_cocos2dx_Node_setSkewX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setSkewX", js_cocos2dx_Node_setSkewX, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setGLProgramState", js_cocos2dx_Node_setGLProgramState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setGLProgramState", js_cocos2dx_Node_setGLProgramState, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setOnEnterCallback", js_cocos2dx_Node_setOnEnterCallback, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setOnEnterCallback", js_cocos2dx_Node_setOnEnterCallback, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("stopActionsByFlags", js_cocos2dx_Node_stopActionsByFlags, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setNormalizedPosition", js_cocos2dx_Node_setNormalizedPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setNormalizedPosition", js_cocos2dx_Node_setNormalizedPosition, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setonExitTransitionDidStartCallback", js_cocos2dx_Node_setonExitTransitionDidStartCallback, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setonExitTransitionDidStartCallback", js_cocos2dx_Node_setonExitTransitionDidStartCallback, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("convertTouchToNodeSpace", js_cocos2dx_Node_convertTouchToNodeSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("convertTouchToNodeSpace", js_cocos2dx_Node_convertTouchToNodeSpace, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
@ -8088,6 +8109,24 @@ bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
JS_ReportError(cx, "js_cocos2dx_Action_getTarget : wrong number of arguments: %d, was expecting %d", argc, 0);
|
JS_ReportError(cx, "js_cocos2dx_Action_getTarget : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_Action_getFlags(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_getFlags : Invalid Native Object");
|
||||||
|
if (argc == 0) {
|
||||||
|
unsigned int ret = cobj->getFlags();
|
||||||
|
jsval jsret = JSVAL_NULL;
|
||||||
|
jsret = uint32_to_jsval(cx, ret);
|
||||||
|
args.rval().set(jsret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_Action_getFlags : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -8128,6 +8167,26 @@ bool js_cocos2dx_Action_setTag(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
JS_ReportError(cx, "js_cocos2dx_Action_setTag : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_Action_setTag : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_Action_setFlags(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::Action* cobj = (cocos2d::Action *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Action_setFlags : Invalid Native Object");
|
||||||
|
if (argc == 1) {
|
||||||
|
unsigned int arg0;
|
||||||
|
ok &= jsval_to_uint32(cx, args.get(0), &arg0);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Action_setFlags : Error processing arguments");
|
||||||
|
cobj->setFlags(arg0);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_Action_setFlags : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -8249,8 +8308,10 @@ void js_register_cocos2dx_Action(JSContext *cx, JS::HandleObject global) {
|
||||||
JS_FN("stop", js_cocos2dx_Action_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("stop", js_cocos2dx_Action_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("update", js_cocos2dx_Action_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("update", js_cocos2dx_Action_update, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getTarget", js_cocos2dx_Action_getTarget, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getTarget", js_cocos2dx_Action_getTarget, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("getFlags", js_cocos2dx_Action_getFlags, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("step", js_cocos2dx_Action_step, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("step", js_cocos2dx_Action_step, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setTag", js_cocos2dx_Action_setTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setTag", js_cocos2dx_Action_setTag, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("setFlags", js_cocos2dx_Action_setFlags, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getTag", js_cocos2dx_Action_getTag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getTag", js_cocos2dx_Action_getTag, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setTarget", js_cocos2dx_Action_setTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setTarget", js_cocos2dx_Action_setTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("isDone", js_cocos2dx_Action_isDone, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("isDone", js_cocos2dx_Action_isDone, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
@ -14715,6 +14776,36 @@ void js_register_cocos2dx_ReverseTime(JSContext *cx, JS::HandleObject global) {
|
||||||
JSClass *jsb_cocos2d_Animate_class;
|
JSClass *jsb_cocos2d_Animate_class;
|
||||||
JSObject *jsb_cocos2d_Animate_prototype;
|
JSObject *jsb_cocos2d_Animate_prototype;
|
||||||
|
|
||||||
|
bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::Animate* cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_initWithAnimation : Invalid Native Object");
|
||||||
|
if (argc == 1) {
|
||||||
|
cocos2d::Animation* arg0;
|
||||||
|
do {
|
||||||
|
if (args.get(0).isNull()) { arg0 = nullptr; break; }
|
||||||
|
if (!args.get(0).isObject()) { ok = false; break; }
|
||||||
|
js_proxy_t *jsProxy;
|
||||||
|
JSObject *tmpObj = args.get(0).toObjectOrNull();
|
||||||
|
jsProxy = jsb_get_js_proxy(tmpObj);
|
||||||
|
arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object");
|
||||||
|
} while (0);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animate_initWithAnimation : Error processing arguments");
|
||||||
|
bool ret = cobj->initWithAnimation(arg0);
|
||||||
|
jsval jsret = JSVAL_NULL;
|
||||||
|
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||||
|
args.rval().set(jsret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_Animate_initWithAnimation : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -14763,34 +14854,22 @@ bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
JS_ReportError(cx, "js_cocos2dx_Animate_getAnimation : wrong number of arguments");
|
JS_ReportError(cx, "js_cocos2dx_Animate_getAnimation : wrong number of arguments");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Animate_getCurrentFrameIndex(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
bool ok = true;
|
|
||||||
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
cocos2d::Animate* cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL);
|
cocos2d::Animate* cobj = (cocos2d::Animate *)(proxy ? proxy->ptr : NULL);
|
||||||
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_initWithAnimation : Invalid Native Object");
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Animate_getCurrentFrameIndex : Invalid Native Object");
|
||||||
if (argc == 1) {
|
if (argc == 0) {
|
||||||
cocos2d::Animation* arg0;
|
int ret = cobj->getCurrentFrameIndex();
|
||||||
do {
|
|
||||||
if (args.get(0).isNull()) { arg0 = nullptr; break; }
|
|
||||||
if (!args.get(0).isObject()) { ok = false; break; }
|
|
||||||
js_proxy_t *jsProxy;
|
|
||||||
JSObject *tmpObj = args.get(0).toObjectOrNull();
|
|
||||||
jsProxy = jsb_get_js_proxy(tmpObj);
|
|
||||||
arg0 = (cocos2d::Animation*)(jsProxy ? jsProxy->ptr : NULL);
|
|
||||||
JSB_PRECONDITION2( arg0, cx, false, "Invalid Native Object");
|
|
||||||
} while (0);
|
|
||||||
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_Animate_initWithAnimation : Error processing arguments");
|
|
||||||
bool ret = cobj->initWithAnimation(arg0);
|
|
||||||
jsval jsret = JSVAL_NULL;
|
jsval jsret = JSVAL_NULL;
|
||||||
jsret = BOOLEAN_TO_JSVAL(ret);
|
jsret = int32_to_jsval(cx, ret);
|
||||||
args.rval().set(jsret);
|
args.rval().set(jsret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ReportError(cx, "js_cocos2dx_Animate_initWithAnimation : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_Animate_getCurrentFrameIndex : wrong number of arguments: %d, was expecting %d", argc, 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
@ -14909,8 +14988,9 @@ void js_register_cocos2dx_Animate(JSContext *cx, JS::HandleObject global) {
|
||||||
};
|
};
|
||||||
|
|
||||||
static JSFunctionSpec funcs[] = {
|
static JSFunctionSpec funcs[] = {
|
||||||
JS_FN("getAnimation", js_cocos2dx_Animate_getAnimation, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
|
||||||
JS_FN("initWithAnimation", js_cocos2dx_Animate_initWithAnimation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("initWithAnimation", js_cocos2dx_Animate_initWithAnimation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("getAnimation", js_cocos2dx_Animate_getAnimation, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("getCurrentFrameIndex", js_cocos2dx_Animate_getCurrentFrameIndex, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setAnimation", js_cocos2dx_Animate_setAnimation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setAnimation", js_cocos2dx_Animate_setAnimation, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FS_END
|
JS_FS_END
|
||||||
};
|
};
|
||||||
|
@ -17212,6 +17292,28 @@ bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsv
|
||||||
JS_ReportError(cx, "js_cocos2dx_FileUtils_getValueMapFromFile : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_getValueMapFromFile : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getFileSize : Invalid Native Object");
|
||||||
|
if (argc == 1) {
|
||||||
|
std::string arg0;
|
||||||
|
ok &= jsval_to_std_string(cx, args.get(0), &arg0);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getFileSize : Error processing arguments");
|
||||||
|
long ret = cobj->getFileSize(arg0);
|
||||||
|
jsval jsret = JSVAL_NULL;
|
||||||
|
jsret = long_to_jsval(cx, ret);
|
||||||
|
args.rval().set(jsret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_getFileSize : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -17278,26 +17380,28 @@ bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *v
|
||||||
JS_ReportError(cx, "js_cocos2dx_FileUtils_setSearchPaths : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_setSearchPaths : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_FileUtils_writeStringToFile(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL);
|
cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL);
|
||||||
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_getFileSize : Invalid Native Object");
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeStringToFile : Invalid Native Object");
|
||||||
if (argc == 1) {
|
if (argc == 2) {
|
||||||
std::string arg0;
|
std::string arg0;
|
||||||
|
std::string arg1;
|
||||||
ok &= jsval_to_std_string(cx, args.get(0), &arg0);
|
ok &= jsval_to_std_string(cx, args.get(0), &arg0);
|
||||||
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_getFileSize : Error processing arguments");
|
ok &= jsval_to_std_string(cx, args.get(1), &arg1);
|
||||||
long ret = cobj->getFileSize(arg0);
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeStringToFile : Error processing arguments");
|
||||||
|
bool ret = cobj->writeStringToFile(arg0, arg1);
|
||||||
jsval jsret = JSVAL_NULL;
|
jsval jsret = JSVAL_NULL;
|
||||||
jsret = long_to_jsval(cx, ret);
|
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||||
args.rval().set(jsret);
|
args.rval().set(jsret);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_ReportError(cx, "js_cocos2dx_FileUtils_getFileSize : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_writeStringToFile : wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
@ -17380,6 +17484,30 @@ bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp
|
||||||
JS_ReportError(cx, "js_cocos2dx_FileUtils_addSearchPath : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_addSearchPath : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_FileUtils_writeValueVectorToFile(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeValueVectorToFile : Invalid Native Object");
|
||||||
|
if (argc == 2) {
|
||||||
|
cocos2d::ValueVector arg0;
|
||||||
|
std::string arg1;
|
||||||
|
ok &= jsval_to_ccvaluevector(cx, args.get(0), &arg0);
|
||||||
|
ok &= jsval_to_std_string(cx, args.get(1), &arg1);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeValueVectorToFile : Error processing arguments");
|
||||||
|
bool ret = cobj->writeValueVectorToFile(arg0, arg1);
|
||||||
|
jsval jsret = JSVAL_NULL;
|
||||||
|
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||||
|
args.rval().set(jsret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_writeValueVectorToFile : wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -17464,6 +17592,30 @@ bool js_cocos2dx_FileUtils_getSuitableFOpen(JSContext *cx, uint32_t argc, jsval
|
||||||
JS_ReportError(cx, "js_cocos2dx_FileUtils_getSuitableFOpen : wrong number of arguments: %d, was expecting %d", argc, 1);
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_getSuitableFOpen : wrong number of arguments: %d, was expecting %d", argc, 1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_FileUtils_writeValueMapToFile(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::FileUtils* cobj = (cocos2d::FileUtils *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_FileUtils_writeValueMapToFile : Invalid Native Object");
|
||||||
|
if (argc == 2) {
|
||||||
|
cocos2d::ValueMap arg0;
|
||||||
|
std::string arg1;
|
||||||
|
ok &= jsval_to_ccvaluemap(cx, args.get(0), &arg0);
|
||||||
|
ok &= jsval_to_std_string(cx, args.get(1), &arg1);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_FileUtils_writeValueMapToFile : Error processing arguments");
|
||||||
|
bool ret = cobj->writeValueMapToFile(arg0, arg1);
|
||||||
|
jsval jsret = JSVAL_NULL;
|
||||||
|
jsret = BOOLEAN_TO_JSVAL(ret);
|
||||||
|
args.rval().set(jsret);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_FileUtils_writeValueMapToFile : wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -17685,17 +17837,20 @@ void js_register_cocos2dx_FileUtils(JSContext *cx, JS::HandleObject global) {
|
||||||
JS_FN("getSearchPaths", js_cocos2dx_FileUtils_getSearchPaths, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getSearchPaths", js_cocos2dx_FileUtils_getSearchPaths, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("writeToFile", js_cocos2dx_FileUtils_writeToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("writeToFile", js_cocos2dx_FileUtils_writeToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getValueMapFromFile", js_cocos2dx_FileUtils_getValueMapFromFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getValueMapFromFile", js_cocos2dx_FileUtils_getValueMapFromFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("getFileSize", js_cocos2dx_FileUtils_getFileSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getValueMapFromData", js_cocos2dx_FileUtils_getValueMapFromData, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getValueMapFromData", js_cocos2dx_FileUtils_getValueMapFromData, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("removeDirectory", js_cocos2dx_FileUtils_removeDirectory, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("removeDirectory", js_cocos2dx_FileUtils_removeDirectory, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setSearchPaths", js_cocos2dx_FileUtils_setSearchPaths, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setSearchPaths", js_cocos2dx_FileUtils_setSearchPaths, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getFileSize", js_cocos2dx_FileUtils_getFileSize, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("writeStringToFile", js_cocos2dx_FileUtils_writeStringToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setSearchResolutionsOrder", js_cocos2dx_FileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setSearchResolutionsOrder", js_cocos2dx_FileUtils_setSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("addSearchResolutionsOrder", js_cocos2dx_FileUtils_addSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("addSearchResolutionsOrder", js_cocos2dx_FileUtils_addSearchResolutionsOrder, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("addSearchPath", js_cocos2dx_FileUtils_addSearchPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("addSearchPath", js_cocos2dx_FileUtils_addSearchPath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("writeValueVectorToFile", js_cocos2dx_FileUtils_writeValueVectorToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("isFileExist", js_cocos2dx_FileUtils_isFileExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("isFileExist", js_cocos2dx_FileUtils_isFileExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("purgeCachedEntries", js_cocos2dx_FileUtils_purgeCachedEntries, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("purgeCachedEntries", js_cocos2dx_FileUtils_purgeCachedEntries, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("fullPathFromRelativeFile", js_cocos2dx_FileUtils_fullPathFromRelativeFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("fullPathFromRelativeFile", js_cocos2dx_FileUtils_fullPathFromRelativeFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("getSuitableFOpen", js_cocos2dx_FileUtils_getSuitableFOpen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getSuitableFOpen", js_cocos2dx_FileUtils_getSuitableFOpen, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("writeValueMapToFile", js_cocos2dx_FileUtils_writeValueMapToFile, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setWritablePath", js_cocos2dx_FileUtils_setWritablePath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setWritablePath", js_cocos2dx_FileUtils_setWritablePath, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("setPopupNotify", js_cocos2dx_FileUtils_setPopupNotify, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("setPopupNotify", js_cocos2dx_FileUtils_setPopupNotify, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("isDirectoryExist", js_cocos2dx_FileUtils_isDirectoryExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("isDirectoryExist", js_cocos2dx_FileUtils_isDirectoryExist, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
@ -29825,6 +29980,36 @@ bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, j
|
||||||
JS_ReportError(cx, "js_cocos2dx_ActionManager_removeActionByTag : wrong number of arguments: %d, was expecting %d", argc, 2);
|
JS_ReportError(cx, "js_cocos2dx_ActionManager_removeActionByTag : wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
bool js_cocos2dx_ActionManager_removeActionsByFlags(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
|
{
|
||||||
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
bool ok = true;
|
||||||
|
JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
|
||||||
|
js_proxy_t *proxy = jsb_get_js_proxy(obj);
|
||||||
|
cocos2d::ActionManager* cobj = (cocos2d::ActionManager *)(proxy ? proxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_ActionManager_removeActionsByFlags : Invalid Native Object");
|
||||||
|
if (argc == 2) {
|
||||||
|
unsigned int arg0;
|
||||||
|
cocos2d::Node* arg1;
|
||||||
|
ok &= jsval_to_uint32(cx, args.get(0), &arg0);
|
||||||
|
do {
|
||||||
|
if (args.get(1).isNull()) { arg1 = nullptr; break; }
|
||||||
|
if (!args.get(1).isObject()) { ok = false; break; }
|
||||||
|
js_proxy_t *jsProxy;
|
||||||
|
JSObject *tmpObj = args.get(1).toObjectOrNull();
|
||||||
|
jsProxy = jsb_get_js_proxy(tmpObj);
|
||||||
|
arg1 = (cocos2d::Node*)(jsProxy ? jsProxy->ptr : NULL);
|
||||||
|
JSB_PRECONDITION2( arg1, cx, false, "Invalid Native Object");
|
||||||
|
} while (0);
|
||||||
|
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_ActionManager_removeActionsByFlags : Error processing arguments");
|
||||||
|
cobj->removeActionsByFlags(arg0, arg1);
|
||||||
|
args.rval().setUndefined();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
JS_ReportError(cx, "js_cocos2dx_ActionManager_removeActionsByFlags : wrong number of arguments: %d, was expecting %d", argc, 2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp)
|
bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp)
|
||||||
{
|
{
|
||||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
|
||||||
|
@ -30183,6 +30368,7 @@ void js_register_cocos2dx_ActionManager(JSContext *cx, JS::HandleObject global)
|
||||||
static JSFunctionSpec funcs[] = {
|
static JSFunctionSpec funcs[] = {
|
||||||
JS_FN("getActionByTag", js_cocos2dx_ActionManager_getActionByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("getActionByTag", js_cocos2dx_ActionManager_getActionByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("removeActionByTag", js_cocos2dx_ActionManager_removeActionByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("removeActionByTag", js_cocos2dx_ActionManager_removeActionByTag, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
JS_FN("removeActionsByFlags", js_cocos2dx_ActionManager_removeActionsByFlags, 2, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("removeAllActions", js_cocos2dx_ActionManager_removeAllActions, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("removeAllActions", js_cocos2dx_ActionManager_removeAllActions, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("addAction", js_cocos2dx_ActionManager_addAction, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("addAction", js_cocos2dx_ActionManager_addAction, 3, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
JS_FN("resumeTarget", js_cocos2dx_ActionManager_resumeTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
JS_FN("resumeTarget", js_cocos2dx_ActionManager_resumeTarget, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
|
||||||
|
|
|
@ -127,6 +127,7 @@ bool js_cocos2dx_Node_getEventDispatcher(JSContext *cx, uint32_t argc, jsval *vp
|
||||||
bool js_cocos2dx_Node_setSkewX(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_setSkewX(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Node_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_setGLProgramState(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_setOnEnterCallback(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_Node_stopActionsByFlags(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_setNormalizedPosition(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Node_setonExitTransitionDidStartCallback(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_setonExitTransitionDidStartCallback(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Node_convertTouchToNodeSpace(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
@ -410,8 +411,10 @@ bool js_cocos2dx_Action_getOriginalTarget(JSContext *cx, uint32_t argc, jsval *v
|
||||||
bool js_cocos2dx_Action_stop(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_stop(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_update(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_update(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_getTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_Action_getFlags(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_step(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_setTag(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_setTag(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_Action_setFlags(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_getTag(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_setTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_setTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Action_isDone(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Action_isDone(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
@ -810,8 +813,9 @@ bool js_cocos2dx_Animate_constructor(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
void js_cocos2dx_Animate_finalize(JSContext *cx, JSObject *obj);
|
void js_cocos2dx_Animate_finalize(JSContext *cx, JSObject *obj);
|
||||||
void js_register_cocos2dx_Animate(JSContext *cx, JS::HandleObject global);
|
void js_register_cocos2dx_Animate(JSContext *cx, JS::HandleObject global);
|
||||||
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
|
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
|
||||||
bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
|
||||||
bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Animate_initWithAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_Animate_getAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_Animate_getCurrentFrameIndex(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Animate_setAnimation(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Animate_create(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Animate_create(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_Animate_Animate(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_Animate_Animate(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
@ -926,17 +930,20 @@ bool js_cocos2dx_FileUtils_getValueVectorFromFile(JSContext *cx, uint32_t argc,
|
||||||
bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_getSearchPaths(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_writeToFile(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_writeToFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_getValueMapFromFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_getValueMapFromData(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_removeDirectory(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_removeDirectory(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_setSearchPaths(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_getFileSize(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_writeStringToFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_setSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_addSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_addSearchResolutionsOrder(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_addSearchPath(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_FileUtils_writeValueVectorToFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_isFileExist(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_purgeCachedEntries(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_fullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_getSuitableFOpen(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_getSuitableFOpen(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_FileUtils_writeValueMapToFile(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_setWritablePath(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_setPopupNotify(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_FileUtils_isDirectoryExist(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
@ -1836,6 +1843,7 @@ void js_register_cocos2dx_ActionManager(JSContext *cx, JS::HandleObject global);
|
||||||
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
|
void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj);
|
||||||
bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_ActionManager_getActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_ActionManager_removeActionByTag(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
bool js_cocos2dx_ActionManager_removeActionsByFlags(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_ActionManager_removeAllActions(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_ActionManager_addAction(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_ActionManager_addAction(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
bool js_cocos2dx_ActionManager_resumeTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
bool js_cocos2dx_ActionManager_resumeTarget(JSContext *cx, uint32_t argc, jsval *vp);
|
||||||
|
|
|
@ -140,8 +140,8 @@ ccs._parser = cc.Class.extend({
|
||||||
return json["widgetTree"];
|
return json["widgetTree"];
|
||||||
},
|
},
|
||||||
|
|
||||||
parse: function(file, json){
|
parse: function(file, json, resourcePath){
|
||||||
var resourcePath = this._dirname(file);
|
resourcePath = resourcePath || this._dirname(file);
|
||||||
this.pretreatment(json, resourcePath);
|
this.pretreatment(json, resourcePath);
|
||||||
var node = this.parseNode(this.getNodeJson(json), resourcePath, file);
|
var node = this.parseNode(this.getNodeJson(json), resourcePath, file);
|
||||||
node && this.deferred(json, resourcePath, node, file);
|
node && this.deferred(json, resourcePath, node, file);
|
||||||
|
|
|
@ -161,6 +161,9 @@
|
||||||
var node = new cc.Node();
|
var node = new cc.Node();
|
||||||
|
|
||||||
this.generalAttributes(node, json);
|
this.generalAttributes(node, json);
|
||||||
|
var color = json["CColor"];
|
||||||
|
if(color != null)
|
||||||
|
node.setColor(getColor(color));
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,6 +63,13 @@
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @return Node#Node ret (return value: cc.Node)
|
-- @return Node#Node ret (return value: cc.Node)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Returns a flag field that is used to group the actions easily.<br>
|
||||||
|
-- return A tag.
|
||||||
|
-- @function [parent=#Action] getFlags
|
||||||
|
-- @param self
|
||||||
|
-- @return unsigned int#unsigned int ret (return value: unsigned int)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Called every frame with it's delta time, dt in seconds. DON'T override unless you know what you are doing. <br>
|
-- Called every frame with it's delta time, dt in seconds. DON'T override unless you know what you are doing. <br>
|
||||||
-- param dt In seconds.
|
-- param dt In seconds.
|
||||||
|
@ -79,6 +86,14 @@
|
||||||
-- @param #int tag
|
-- @param #int tag
|
||||||
-- @return Action#Action self (return value: cc.Action)
|
-- @return Action#Action self (return value: cc.Action)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Changes the flag field that is used to group the actions easily.<br>
|
||||||
|
-- param tag Used to identify the action easily.
|
||||||
|
-- @function [parent=#Action] setFlags
|
||||||
|
-- @param self
|
||||||
|
-- @param #unsigned int flags
|
||||||
|
-- @return Action#Action self (return value: cc.Action)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Returns a tag that is used to identify the action easily. <br>
|
-- Returns a tag that is used to identify the action easily. <br>
|
||||||
-- return A tag.
|
-- return A tag.
|
||||||
|
|
|
@ -25,6 +25,17 @@
|
||||||
-- @param #cc.Node target
|
-- @param #cc.Node target
|
||||||
-- @return ActionManager#ActionManager self (return value: cc.ActionManager)
|
-- @return ActionManager#ActionManager self (return value: cc.ActionManager)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Removes all actions matching at least one bit in flags and the target.<br>
|
||||||
|
-- param flags The flag field to match the actions' flags based on bitwise AND.<br>
|
||||||
|
-- param target A certain target.<br>
|
||||||
|
-- js NA
|
||||||
|
-- @function [parent=#ActionManager] removeActionsByFlags
|
||||||
|
-- @param self
|
||||||
|
-- @param #unsigned int flags
|
||||||
|
-- @param #cc.Node target
|
||||||
|
-- @return ActionManager#ActionManager self (return value: cc.ActionManager)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Removes all actions from all the targets.
|
-- Removes all actions from all the targets.
|
||||||
-- @function [parent=#ActionManager] removeAllActions
|
-- @function [parent=#ActionManager] removeAllActions
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
-- @extend ActionInterval
|
-- @extend ActionInterval
|
||||||
-- @parent_module cc
|
-- @parent_module cc
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- initializes the action with an Animation and will restore the original frame when the animation is over
|
||||||
|
-- @function [parent=#Animate] initWithAnimation
|
||||||
|
-- @param self
|
||||||
|
-- @param #cc.Animation animation
|
||||||
|
-- @return bool#bool ret (return value: bool)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- @overload self
|
-- @overload self
|
||||||
-- @overload self
|
-- @overload self
|
||||||
|
@ -12,11 +19,11 @@
|
||||||
-- @return Animation#Animation ret (return value: cc.Animation)
|
-- @return Animation#Animation ret (return value: cc.Animation)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- initializes the action with an Animation and will restore the original frame when the animation is over
|
-- Gets the index of sprite frame currently displayed.<br>
|
||||||
-- @function [parent=#Animate] initWithAnimation
|
-- return int the index of sprite frame currently displayed.
|
||||||
|
-- @function [parent=#Animate] getCurrentFrameIndex
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @param #cc.Animation animation
|
-- @return int#int ret (return value: int)
|
||||||
-- @return bool#bool ret (return value: bool)
|
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Sets the Animation object to be animated <br>
|
-- Sets the Animation object to be animated <br>
|
||||||
|
|
|
@ -121,6 +121,14 @@
|
||||||
-- @param #float volume
|
-- @param #float volume
|
||||||
-- @return experimental::AudioEngine#experimental::AudioEngine self (return value: cc.experimental::AudioEngine)
|
-- @return experimental::AudioEngine#experimental::AudioEngine self (return value: cc.experimental::AudioEngine)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Preload audio file.<br>
|
||||||
|
-- param filePath The file path of an audio.
|
||||||
|
-- @function [parent=#AudioEngine] preload
|
||||||
|
-- @param self
|
||||||
|
-- @param #string filePath
|
||||||
|
-- @return experimental::AudioEngine#experimental::AudioEngine self (return value: cc.experimental::AudioEngine)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Play 2d sound.<br>
|
-- Play 2d sound.<br>
|
||||||
-- param filePath The path of an audio file.<br>
|
-- param filePath The path of an audio file.<br>
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Checks whether to pop up a message box when failed to load an image. <br>
|
-- Checks whether to pop up a message box when failed to load an image.<br>
|
||||||
-- return True if pop up a message box when failed to load an image, false if not.
|
-- return True if pop up a message box when failed to load an image, false if not.
|
||||||
-- @function [parent=#FileUtils] isPopupNotify
|
-- @function [parent=#FileUtils] isPopupNotify
|
||||||
-- @param self
|
-- @param self
|
||||||
|
@ -150,7 +150,10 @@
|
||||||
-- @return array_table#array_table ret (return value: array_table)
|
-- @return array_table#array_table ret (return value: array_table)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--
|
-- write a ValueMap into a plist file<br>
|
||||||
|
-- param dict the ValueMap want to save<br>
|
||||||
|
-- param fullPath The full path to the file you want to save a string<br>
|
||||||
|
-- return bool
|
||||||
-- @function [parent=#FileUtils] writeToFile
|
-- @function [parent=#FileUtils] writeToFile
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @param #map_table dict
|
-- @param #map_table dict
|
||||||
|
@ -168,7 +171,18 @@
|
||||||
-- @return map_table#map_table ret (return value: map_table)
|
-- @return map_table#map_table ret (return value: map_table)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--
|
-- Retrieve the file size.<br>
|
||||||
|
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
||||||
|
-- param filepath The path of the file, it could be a relative or absolute path.<br>
|
||||||
|
-- return The file size.
|
||||||
|
-- @function [parent=#FileUtils] getFileSize
|
||||||
|
-- @param self
|
||||||
|
-- @param #string filepath
|
||||||
|
-- @return long#long ret (return value: long)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Converts the contents of a file to a ValueMap.<br>
|
||||||
|
-- This method is used internally.
|
||||||
-- @function [parent=#FileUtils] getValueMapFromData
|
-- @function [parent=#FileUtils] getValueMapFromData
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @param #char filedata
|
-- @param #char filedata
|
||||||
|
@ -205,14 +219,15 @@
|
||||||
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Retrieve the file size.<br>
|
-- write a string into a file<br>
|
||||||
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
-- param dataStr the string want to save<br>
|
||||||
-- param filepath The path of the file, it could be a relative or absolute path.<br>
|
-- param fullPath The full path to the file you want to save a string<br>
|
||||||
-- return The file size.
|
-- return bool True if write success
|
||||||
-- @function [parent=#FileUtils] getFileSize
|
-- @function [parent=#FileUtils] writeStringToFile
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @param #string filepath
|
-- @param #string dataStr
|
||||||
-- @return long#long ret (return value: long)
|
-- @param #string fullPath
|
||||||
|
-- @return bool#bool ret (return value: bool)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Sets the array that contains the search order of the resources.<br>
|
-- Sets the array that contains the search order of the resources.<br>
|
||||||
|
@ -245,6 +260,17 @@
|
||||||
-- @param #bool front
|
-- @param #bool front
|
||||||
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
-- @return FileUtils#FileUtils self (return value: cc.FileUtils)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- write ValueVector into a plist file<br>
|
||||||
|
-- param vecData the ValueVector want to save<br>
|
||||||
|
-- param fullPath The full path to the file you want to save a string<br>
|
||||||
|
-- return bool
|
||||||
|
-- @function [parent=#FileUtils] writeValueVectorToFile
|
||||||
|
-- @param self
|
||||||
|
-- @param #array_table vecData
|
||||||
|
-- @param #string fullPath
|
||||||
|
-- @return bool#bool ret (return value: bool)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Checks whether a file exists.<br>
|
-- Checks whether a file exists.<br>
|
||||||
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
-- note If a relative path was passed in, it will be inserted a default root path at the beginning.<br>
|
||||||
|
@ -284,6 +310,17 @@
|
||||||
-- @param #string filenameUtf8
|
-- @param #string filenameUtf8
|
||||||
-- @return string#string ret (return value: string)
|
-- @return string#string ret (return value: string)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- write ValueMap into a plist file<br>
|
||||||
|
-- param dict the ValueMap want to save<br>
|
||||||
|
-- param fullPath The full path to the file you want to save a string<br>
|
||||||
|
-- return bool
|
||||||
|
-- @function [parent=#FileUtils] writeValueMapToFile
|
||||||
|
-- @param self
|
||||||
|
-- @param #map_table dict
|
||||||
|
-- @param #string fullPath
|
||||||
|
-- @return bool#bool ret (return value: bool)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Sets writable path.
|
-- Sets writable path.
|
||||||
-- @function [parent=#FileUtils] setWritablePath
|
-- @function [parent=#FileUtils] setWritablePath
|
||||||
|
|
|
@ -10,6 +10,13 @@
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @return Frame#Frame ret (return value: ccs.Frame)
|
-- @return Frame#Frame ret (return value: ccs.Frame)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
--
|
||||||
|
-- @function [parent=#Frame] setTweenType
|
||||||
|
-- @param self
|
||||||
|
-- @param #int tweenType
|
||||||
|
-- @return Frame#Frame self (return value: ccs.Frame)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--
|
--
|
||||||
-- @function [parent=#Frame] setNode
|
-- @function [parent=#Frame] setNode
|
||||||
|
@ -30,6 +37,12 @@
|
||||||
-- @param self
|
-- @param self
|
||||||
-- @return bool#bool ret (return value: bool)
|
-- @return bool#bool ret (return value: bool)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
--
|
||||||
|
-- @function [parent=#Frame] getTweenType
|
||||||
|
-- @param self
|
||||||
|
-- @return int#int ret (return value: int)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--
|
--
|
||||||
-- @function [parent=#Frame] getEasingParams
|
-- @function [parent=#Frame] getEasingParams
|
||||||
|
|
|
@ -305,6 +305,14 @@
|
||||||
-- @param #function callback
|
-- @param #function callback
|
||||||
-- @return Node#Node self (return value: cc.Node)
|
-- @return Node#Node self (return value: cc.Node)
|
||||||
|
|
||||||
|
--------------------------------
|
||||||
|
-- Removes all actions from the running action list by its flags.<br>
|
||||||
|
-- param flags A flag field that removes actions based on bitwise AND.
|
||||||
|
-- @function [parent=#Node] stopActionsByFlags
|
||||||
|
-- @param self
|
||||||
|
-- @param #unsigned int flags
|
||||||
|
-- @return Node#Node self (return value: cc.Node)
|
||||||
|
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- Sets the position (x,y) using values between 0 and 1.<br>
|
-- Sets the position (x,y) using values between 0 and 1.<br>
|
||||||
-- The positions in pixels is calculated like the following:<br>
|
-- The positions in pixels is calculated like the following:<br>
|
||||||
|
|
|
@ -590,6 +590,42 @@ int lua_cocos2dx_audioengine_AudioEngine_setVolume(lua_State* tolua_S)
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_audioengine_AudioEngine_preload(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertable(tolua_S,1,"ccexp.AudioEngine",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S) - 1;
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
std::string arg0;
|
||||||
|
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "ccexp.AudioEngine:preload");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_audioengine_AudioEngine_preload'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cocos2d::experimental::AudioEngine::preload(arg0);
|
||||||
|
lua_settop(tolua_S, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n ", "ccexp.AudioEngine:preload",argc, 1);
|
||||||
|
return 0;
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_audioengine_AudioEngine_preload'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_audioengine_AudioEngine_play2d(lua_State* tolua_S)
|
int lua_cocos2dx_audioengine_AudioEngine_play2d(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -968,6 +1004,7 @@ int lua_register_cocos2dx_audioengine_AudioEngine(lua_State* tolua_S)
|
||||||
tolua_function(tolua_S,"pauseAll", lua_cocos2dx_audioengine_AudioEngine_pauseAll);
|
tolua_function(tolua_S,"pauseAll", lua_cocos2dx_audioengine_AudioEngine_pauseAll);
|
||||||
tolua_function(tolua_S,"uncacheAll", lua_cocos2dx_audioengine_AudioEngine_uncacheAll);
|
tolua_function(tolua_S,"uncacheAll", lua_cocos2dx_audioengine_AudioEngine_uncacheAll);
|
||||||
tolua_function(tolua_S,"setVolume", lua_cocos2dx_audioengine_AudioEngine_setVolume);
|
tolua_function(tolua_S,"setVolume", lua_cocos2dx_audioengine_AudioEngine_setVolume);
|
||||||
|
tolua_function(tolua_S,"preload", lua_cocos2dx_audioengine_AudioEngine_preload);
|
||||||
tolua_function(tolua_S,"play2d", lua_cocos2dx_audioengine_AudioEngine_play2d);
|
tolua_function(tolua_S,"play2d", lua_cocos2dx_audioengine_AudioEngine_play2d);
|
||||||
tolua_function(tolua_S,"getState", lua_cocos2dx_audioengine_AudioEngine_getState);
|
tolua_function(tolua_S,"getState", lua_cocos2dx_audioengine_AudioEngine_getState);
|
||||||
tolua_function(tolua_S,"resume", lua_cocos2dx_audioengine_AudioEngine_resume);
|
tolua_function(tolua_S,"resume", lua_cocos2dx_audioengine_AudioEngine_resume);
|
||||||
|
|
|
@ -37,6 +37,7 @@ int register_all_cocos2dx_audioengine(lua_State* tolua_S);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __cocos2dx_audioengine_h__
|
#endif // __cocos2dx_audioengine_h__
|
||||||
|
|
|
@ -4681,6 +4681,56 @@ int lua_cocos2dx_Node_setOnEnterCallback(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_Node_stopActionsByFlags(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::Node* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.Node",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::Node*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Node_stopActionsByFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
unsigned int arg0;
|
||||||
|
|
||||||
|
ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.Node:stopActionsByFlags");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Node_stopActionsByFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cobj->stopActionsByFlags(arg0);
|
||||||
|
lua_settop(tolua_S, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Node:stopActionsByFlags",argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Node_stopActionsByFlags'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_Node_setNormalizedPosition(lua_State* tolua_S)
|
int lua_cocos2dx_Node_setNormalizedPosition(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -9585,6 +9635,7 @@ int lua_register_cocos2dx_Node(lua_State* tolua_S)
|
||||||
tolua_function(tolua_S,"setSkewX",lua_cocos2dx_Node_setSkewX);
|
tolua_function(tolua_S,"setSkewX",lua_cocos2dx_Node_setSkewX);
|
||||||
tolua_function(tolua_S,"setGLProgramState",lua_cocos2dx_Node_setGLProgramState);
|
tolua_function(tolua_S,"setGLProgramState",lua_cocos2dx_Node_setGLProgramState);
|
||||||
tolua_function(tolua_S,"setOnEnterCallback",lua_cocos2dx_Node_setOnEnterCallback);
|
tolua_function(tolua_S,"setOnEnterCallback",lua_cocos2dx_Node_setOnEnterCallback);
|
||||||
|
tolua_function(tolua_S,"stopActionsByFlags",lua_cocos2dx_Node_stopActionsByFlags);
|
||||||
tolua_function(tolua_S,"setNormalizedPosition",lua_cocos2dx_Node_setNormalizedPosition);
|
tolua_function(tolua_S,"setNormalizedPosition",lua_cocos2dx_Node_setNormalizedPosition);
|
||||||
tolua_function(tolua_S,"setonExitTransitionDidStartCallback",lua_cocos2dx_Node_setonExitTransitionDidStartCallback);
|
tolua_function(tolua_S,"setonExitTransitionDidStartCallback",lua_cocos2dx_Node_setonExitTransitionDidStartCallback);
|
||||||
tolua_function(tolua_S,"convertTouchToNodeSpace",lua_cocos2dx_Node_convertTouchToNodeSpace);
|
tolua_function(tolua_S,"convertTouchToNodeSpace",lua_cocos2dx_Node_convertTouchToNodeSpace);
|
||||||
|
@ -15853,6 +15904,53 @@ int lua_cocos2dx_Action_getTarget(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_Action_getFlags(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::Action* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.Action",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::Action*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Action_getFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 0)
|
||||||
|
{
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Action_getFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
unsigned int ret = cobj->getFlags();
|
||||||
|
tolua_pushnumber(tolua_S,(lua_Number)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Action:getFlags",argc, 0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Action_getFlags'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_Action_step(lua_State* tolua_S)
|
int lua_cocos2dx_Action_step(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -15953,6 +16051,56 @@ int lua_cocos2dx_Action_setTag(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_Action_setFlags(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::Action* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.Action",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::Action*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Action_setFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
unsigned int arg0;
|
||||||
|
|
||||||
|
ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.Action:setFlags");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Action_setFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cobj->setFlags(arg0);
|
||||||
|
lua_settop(tolua_S, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Action:setFlags",argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Action_setFlags'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_Action_getTag(lua_State* tolua_S)
|
int lua_cocos2dx_Action_getTag(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -16163,8 +16311,10 @@ int lua_register_cocos2dx_Action(lua_State* tolua_S)
|
||||||
tolua_function(tolua_S,"stop",lua_cocos2dx_Action_stop);
|
tolua_function(tolua_S,"stop",lua_cocos2dx_Action_stop);
|
||||||
tolua_function(tolua_S,"update",lua_cocos2dx_Action_update);
|
tolua_function(tolua_S,"update",lua_cocos2dx_Action_update);
|
||||||
tolua_function(tolua_S,"getTarget",lua_cocos2dx_Action_getTarget);
|
tolua_function(tolua_S,"getTarget",lua_cocos2dx_Action_getTarget);
|
||||||
|
tolua_function(tolua_S,"getFlags",lua_cocos2dx_Action_getFlags);
|
||||||
tolua_function(tolua_S,"step",lua_cocos2dx_Action_step);
|
tolua_function(tolua_S,"step",lua_cocos2dx_Action_step);
|
||||||
tolua_function(tolua_S,"setTag",lua_cocos2dx_Action_setTag);
|
tolua_function(tolua_S,"setTag",lua_cocos2dx_Action_setTag);
|
||||||
|
tolua_function(tolua_S,"setFlags",lua_cocos2dx_Action_setFlags);
|
||||||
tolua_function(tolua_S,"getTag",lua_cocos2dx_Action_getTag);
|
tolua_function(tolua_S,"getTag",lua_cocos2dx_Action_getTag);
|
||||||
tolua_function(tolua_S,"setTarget",lua_cocos2dx_Action_setTarget);
|
tolua_function(tolua_S,"setTarget",lua_cocos2dx_Action_setTarget);
|
||||||
tolua_function(tolua_S,"isDone",lua_cocos2dx_Action_isDone);
|
tolua_function(tolua_S,"isDone",lua_cocos2dx_Action_isDone);
|
||||||
|
@ -23618,6 +23768,56 @@ int lua_register_cocos2dx_DelayTime(lua_State* tolua_S)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lua_cocos2dx_Animate_initWithAnimation(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::Animate* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.Animate",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::Animate*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate_initWithAnimation'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
cocos2d::Animation* arg0;
|
||||||
|
|
||||||
|
ok &= luaval_to_object<cocos2d::Animation>(tolua_S, 2, "cc.Animation",&arg0, "cc.Animate:initWithAnimation");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Animate_initWithAnimation'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bool ret = cobj->initWithAnimation(arg0);
|
||||||
|
tolua_pushboolean(tolua_S,(bool)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Animate:initWithAnimation",argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate_initWithAnimation'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_Animate_getAnimation(lua_State* tolua_S)
|
int lua_cocos2dx_Animate_getAnimation(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -23665,7 +23865,7 @@ int lua_cocos2dx_Animate_getAnimation(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int lua_cocos2dx_Animate_initWithAnimation(lua_State* tolua_S)
|
int lua_cocos2dx_Animate_getCurrentFrameIndex(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
cocos2d::Animate* cobj = nullptr;
|
cocos2d::Animate* cobj = nullptr;
|
||||||
|
@ -23685,32 +23885,29 @@ int lua_cocos2dx_Animate_initWithAnimation(lua_State* tolua_S)
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (!cobj)
|
if (!cobj)
|
||||||
{
|
{
|
||||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate_initWithAnimation'", nullptr);
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Animate_getCurrentFrameIndex'", nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
argc = lua_gettop(tolua_S)-1;
|
argc = lua_gettop(tolua_S)-1;
|
||||||
if (argc == 1)
|
if (argc == 0)
|
||||||
{
|
{
|
||||||
cocos2d::Animation* arg0;
|
|
||||||
|
|
||||||
ok &= luaval_to_object<cocos2d::Animation>(tolua_S, 2, "cc.Animation",&arg0, "cc.Animate:initWithAnimation");
|
|
||||||
if(!ok)
|
if(!ok)
|
||||||
{
|
{
|
||||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Animate_initWithAnimation'", nullptr);
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Animate_getCurrentFrameIndex'", nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
bool ret = cobj->initWithAnimation(arg0);
|
int ret = cobj->getCurrentFrameIndex();
|
||||||
tolua_pushboolean(tolua_S,(bool)ret);
|
tolua_pushnumber(tolua_S,(lua_Number)ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Animate:initWithAnimation",argc, 1);
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Animate:getCurrentFrameIndex",argc, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_lerror:
|
tolua_lerror:
|
||||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate_initWithAnimation'.",&tolua_err);
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Animate_getCurrentFrameIndex'.",&tolua_err);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -23851,8 +24048,9 @@ int lua_register_cocos2dx_Animate(lua_State* tolua_S)
|
||||||
|
|
||||||
tolua_beginmodule(tolua_S,"Animate");
|
tolua_beginmodule(tolua_S,"Animate");
|
||||||
tolua_function(tolua_S,"new",lua_cocos2dx_Animate_constructor);
|
tolua_function(tolua_S,"new",lua_cocos2dx_Animate_constructor);
|
||||||
tolua_function(tolua_S,"getAnimation",lua_cocos2dx_Animate_getAnimation);
|
|
||||||
tolua_function(tolua_S,"initWithAnimation",lua_cocos2dx_Animate_initWithAnimation);
|
tolua_function(tolua_S,"initWithAnimation",lua_cocos2dx_Animate_initWithAnimation);
|
||||||
|
tolua_function(tolua_S,"getAnimation",lua_cocos2dx_Animate_getAnimation);
|
||||||
|
tolua_function(tolua_S,"getCurrentFrameIndex",lua_cocos2dx_Animate_getCurrentFrameIndex);
|
||||||
tolua_function(tolua_S,"setAnimation",lua_cocos2dx_Animate_setAnimation);
|
tolua_function(tolua_S,"setAnimation",lua_cocos2dx_Animate_setAnimation);
|
||||||
tolua_function(tolua_S,"create", lua_cocos2dx_Animate_create);
|
tolua_function(tolua_S,"create", lua_cocos2dx_Animate_create);
|
||||||
tolua_endmodule(tolua_S);
|
tolua_endmodule(tolua_S);
|
||||||
|
@ -27207,6 +27405,56 @@ int lua_cocos2dx_FileUtils_getValueMapFromFile(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::FileUtils* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
std::string arg0;
|
||||||
|
|
||||||
|
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:getFileSize");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
long ret = cobj->getFileSize(arg0);
|
||||||
|
tolua_pushnumber(tolua_S,(lua_Number)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getFileSize",argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getFileSize'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_FileUtils_getValueMapFromData(lua_State* tolua_S)
|
int lua_cocos2dx_FileUtils_getValueMapFromData(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -27360,7 +27608,7 @@ int lua_cocos2dx_FileUtils_setSearchPaths(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S)
|
int lua_cocos2dx_FileUtils_writeStringToFile(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
cocos2d::FileUtils* cobj = nullptr;
|
cocos2d::FileUtils* cobj = nullptr;
|
||||||
|
@ -27380,32 +27628,35 @@ int lua_cocos2dx_FileUtils_getFileSize(lua_State* tolua_S)
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
if (!cobj)
|
if (!cobj)
|
||||||
{
|
{
|
||||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr);
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeStringToFile'", nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
argc = lua_gettop(tolua_S)-1;
|
argc = lua_gettop(tolua_S)-1;
|
||||||
if (argc == 1)
|
if (argc == 2)
|
||||||
{
|
{
|
||||||
std::string arg0;
|
std::string arg0;
|
||||||
|
std::string arg1;
|
||||||
|
|
||||||
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:getFileSize");
|
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.FileUtils:writeStringToFile");
|
||||||
|
|
||||||
|
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeStringToFile");
|
||||||
if(!ok)
|
if(!ok)
|
||||||
{
|
{
|
||||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_getFileSize'", nullptr);
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeStringToFile'", nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
long ret = cobj->getFileSize(arg0);
|
bool ret = cobj->writeStringToFile(arg0, arg1);
|
||||||
tolua_pushnumber(tolua_S,(lua_Number)ret);
|
tolua_pushboolean(tolua_S,(bool)ret);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:getFileSize",argc, 1);
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeStringToFile",argc, 2);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#if COCOS2D_DEBUG >= 1
|
#if COCOS2D_DEBUG >= 1
|
||||||
tolua_lerror:
|
tolua_lerror:
|
||||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_getFileSize'.",&tolua_err);
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeStringToFile'.",&tolua_err);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -27594,6 +27845,59 @@ int lua_cocos2dx_FileUtils_addSearchPath(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_FileUtils_writeValueVectorToFile(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::FileUtils* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
cocos2d::ValueVector arg0;
|
||||||
|
std::string arg1;
|
||||||
|
|
||||||
|
ok &= luaval_to_ccvaluevector(tolua_S, 2, &arg0, "cc.FileUtils:writeValueVectorToFile");
|
||||||
|
|
||||||
|
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeValueVectorToFile");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bool ret = cobj->writeValueVectorToFile(arg0, arg1);
|
||||||
|
tolua_pushboolean(tolua_S,(bool)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeValueVectorToFile",argc, 2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeValueVectorToFile'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_FileUtils_isFileExist(lua_State* tolua_S)
|
int lua_cocos2dx_FileUtils_isFileExist(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -27794,6 +28098,59 @@ int lua_cocos2dx_FileUtils_getSuitableFOpen(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_FileUtils_writeValueMapToFile(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::FileUtils* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.FileUtils",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::FileUtils*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
cocos2d::ValueMap arg0;
|
||||||
|
std::string arg1;
|
||||||
|
|
||||||
|
ok &= luaval_to_ccvaluemap(tolua_S, 2, &arg0, "cc.FileUtils:writeValueMapToFile");
|
||||||
|
|
||||||
|
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.FileUtils:writeValueMapToFile");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
bool ret = cobj->writeValueMapToFile(arg0, arg1);
|
||||||
|
tolua_pushboolean(tolua_S,(bool)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.FileUtils:writeValueMapToFile",argc, 2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_FileUtils_writeValueMapToFile'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_FileUtils_setWritablePath(lua_State* tolua_S)
|
int lua_cocos2dx_FileUtils_setWritablePath(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -28230,17 +28587,20 @@ int lua_register_cocos2dx_FileUtils(lua_State* tolua_S)
|
||||||
tolua_function(tolua_S,"getSearchPaths",lua_cocos2dx_FileUtils_getSearchPaths);
|
tolua_function(tolua_S,"getSearchPaths",lua_cocos2dx_FileUtils_getSearchPaths);
|
||||||
tolua_function(tolua_S,"writeToFile",lua_cocos2dx_FileUtils_writeToFile);
|
tolua_function(tolua_S,"writeToFile",lua_cocos2dx_FileUtils_writeToFile);
|
||||||
tolua_function(tolua_S,"getValueMapFromFile",lua_cocos2dx_FileUtils_getValueMapFromFile);
|
tolua_function(tolua_S,"getValueMapFromFile",lua_cocos2dx_FileUtils_getValueMapFromFile);
|
||||||
|
tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize);
|
||||||
tolua_function(tolua_S,"getValueMapFromData",lua_cocos2dx_FileUtils_getValueMapFromData);
|
tolua_function(tolua_S,"getValueMapFromData",lua_cocos2dx_FileUtils_getValueMapFromData);
|
||||||
tolua_function(tolua_S,"removeDirectory",lua_cocos2dx_FileUtils_removeDirectory);
|
tolua_function(tolua_S,"removeDirectory",lua_cocos2dx_FileUtils_removeDirectory);
|
||||||
tolua_function(tolua_S,"setSearchPaths",lua_cocos2dx_FileUtils_setSearchPaths);
|
tolua_function(tolua_S,"setSearchPaths",lua_cocos2dx_FileUtils_setSearchPaths);
|
||||||
tolua_function(tolua_S,"getFileSize",lua_cocos2dx_FileUtils_getFileSize);
|
tolua_function(tolua_S,"writeStringToFile",lua_cocos2dx_FileUtils_writeStringToFile);
|
||||||
tolua_function(tolua_S,"setSearchResolutionsOrder",lua_cocos2dx_FileUtils_setSearchResolutionsOrder);
|
tolua_function(tolua_S,"setSearchResolutionsOrder",lua_cocos2dx_FileUtils_setSearchResolutionsOrder);
|
||||||
tolua_function(tolua_S,"addSearchResolutionsOrder",lua_cocos2dx_FileUtils_addSearchResolutionsOrder);
|
tolua_function(tolua_S,"addSearchResolutionsOrder",lua_cocos2dx_FileUtils_addSearchResolutionsOrder);
|
||||||
tolua_function(tolua_S,"addSearchPath",lua_cocos2dx_FileUtils_addSearchPath);
|
tolua_function(tolua_S,"addSearchPath",lua_cocos2dx_FileUtils_addSearchPath);
|
||||||
|
tolua_function(tolua_S,"writeValueVectorToFile",lua_cocos2dx_FileUtils_writeValueVectorToFile);
|
||||||
tolua_function(tolua_S,"isFileExist",lua_cocos2dx_FileUtils_isFileExist);
|
tolua_function(tolua_S,"isFileExist",lua_cocos2dx_FileUtils_isFileExist);
|
||||||
tolua_function(tolua_S,"purgeCachedEntries",lua_cocos2dx_FileUtils_purgeCachedEntries);
|
tolua_function(tolua_S,"purgeCachedEntries",lua_cocos2dx_FileUtils_purgeCachedEntries);
|
||||||
tolua_function(tolua_S,"fullPathFromRelativeFile",lua_cocos2dx_FileUtils_fullPathFromRelativeFile);
|
tolua_function(tolua_S,"fullPathFromRelativeFile",lua_cocos2dx_FileUtils_fullPathFromRelativeFile);
|
||||||
tolua_function(tolua_S,"getSuitableFOpen",lua_cocos2dx_FileUtils_getSuitableFOpen);
|
tolua_function(tolua_S,"getSuitableFOpen",lua_cocos2dx_FileUtils_getSuitableFOpen);
|
||||||
|
tolua_function(tolua_S,"writeValueMapToFile",lua_cocos2dx_FileUtils_writeValueMapToFile);
|
||||||
tolua_function(tolua_S,"setWritablePath",lua_cocos2dx_FileUtils_setWritablePath);
|
tolua_function(tolua_S,"setWritablePath",lua_cocos2dx_FileUtils_setWritablePath);
|
||||||
tolua_function(tolua_S,"setPopupNotify",lua_cocos2dx_FileUtils_setPopupNotify);
|
tolua_function(tolua_S,"setPopupNotify",lua_cocos2dx_FileUtils_setPopupNotify);
|
||||||
tolua_function(tolua_S,"isDirectoryExist",lua_cocos2dx_FileUtils_isDirectoryExist);
|
tolua_function(tolua_S,"isDirectoryExist",lua_cocos2dx_FileUtils_isDirectoryExist);
|
||||||
|
@ -40347,6 +40707,59 @@ int lua_cocos2dx_ActionManager_removeActionByTag(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_ActionManager_removeActionsByFlags(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocos2d::ActionManager* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"cc.ActionManager",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocos2d::ActionManager*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ActionManager_removeActionsByFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
unsigned int arg0;
|
||||||
|
cocos2d::Node* arg1;
|
||||||
|
|
||||||
|
ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.ActionManager:removeActionsByFlags");
|
||||||
|
|
||||||
|
ok &= luaval_to_object<cocos2d::Node>(tolua_S, 3, "cc.Node",&arg1, "cc.ActionManager:removeActionsByFlags");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ActionManager_removeActionsByFlags'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cobj->removeActionsByFlags(arg0, arg1);
|
||||||
|
lua_settop(tolua_S, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.ActionManager:removeActionsByFlags",argc, 2);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ActionManager_removeActionsByFlags'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_ActionManager_removeAllActions(lua_State* tolua_S)
|
int lua_cocos2dx_ActionManager_removeAllActions(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -40952,6 +41365,7 @@ int lua_register_cocos2dx_ActionManager(lua_State* tolua_S)
|
||||||
tolua_function(tolua_S,"new",lua_cocos2dx_ActionManager_constructor);
|
tolua_function(tolua_S,"new",lua_cocos2dx_ActionManager_constructor);
|
||||||
tolua_function(tolua_S,"getActionByTag",lua_cocos2dx_ActionManager_getActionByTag);
|
tolua_function(tolua_S,"getActionByTag",lua_cocos2dx_ActionManager_getActionByTag);
|
||||||
tolua_function(tolua_S,"removeActionByTag",lua_cocos2dx_ActionManager_removeActionByTag);
|
tolua_function(tolua_S,"removeActionByTag",lua_cocos2dx_ActionManager_removeActionByTag);
|
||||||
|
tolua_function(tolua_S,"removeActionsByFlags",lua_cocos2dx_ActionManager_removeActionsByFlags);
|
||||||
tolua_function(tolua_S,"removeAllActions",lua_cocos2dx_ActionManager_removeAllActions);
|
tolua_function(tolua_S,"removeAllActions",lua_cocos2dx_ActionManager_removeAllActions);
|
||||||
tolua_function(tolua_S,"addAction",lua_cocos2dx_ActionManager_addAction);
|
tolua_function(tolua_S,"addAction",lua_cocos2dx_ActionManager_addAction);
|
||||||
tolua_function(tolua_S,"resumeTarget",lua_cocos2dx_ActionManager_resumeTarget);
|
tolua_function(tolua_S,"resumeTarget",lua_cocos2dx_ActionManager_resumeTarget);
|
||||||
|
|
|
@ -2059,6 +2059,14 @@ int register_all_cocos2dx(lua_State* tolua_S);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15792,6 +15792,56 @@ int lua_cocos2dx_studio_Frame_clone(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_studio_Frame_setTweenType(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocostudio::timeline::Frame* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"ccs.Frame",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocostudio::timeline::Frame*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_Frame_setTweenType'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
cocos2d::tweenfunc::TweenType arg0;
|
||||||
|
|
||||||
|
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "ccs.Frame:setTweenType");
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_Frame_setTweenType'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
cobj->setTweenType(arg0);
|
||||||
|
lua_settop(tolua_S, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.Frame:setTweenType",argc, 1);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_Frame_setTweenType'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_studio_Frame_setNode(lua_State* tolua_S)
|
int lua_cocos2dx_studio_Frame_setNode(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -15939,6 +15989,53 @@ int lua_cocos2dx_studio_Frame_isEnterWhenPassed(lua_State* tolua_S)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int lua_cocos2dx_studio_Frame_getTweenType(lua_State* tolua_S)
|
||||||
|
{
|
||||||
|
int argc = 0;
|
||||||
|
cocostudio::timeline::Frame* cobj = nullptr;
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_Error tolua_err;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!tolua_isusertype(tolua_S,1,"ccs.Frame",0,&tolua_err)) goto tolua_lerror;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
cobj = (cocostudio::timeline::Frame*)tolua_tousertype(tolua_S,1,0);
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
if (!cobj)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_studio_Frame_getTweenType'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
argc = lua_gettop(tolua_S)-1;
|
||||||
|
if (argc == 0)
|
||||||
|
{
|
||||||
|
if(!ok)
|
||||||
|
{
|
||||||
|
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_studio_Frame_getTweenType'", nullptr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int ret = (int)cobj->getTweenType();
|
||||||
|
tolua_pushnumber(tolua_S,(lua_Number)ret);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccs.Frame:getTweenType",argc, 0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
#if COCOS2D_DEBUG >= 1
|
||||||
|
tolua_lerror:
|
||||||
|
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_studio_Frame_getTweenType'.",&tolua_err);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int lua_cocos2dx_studio_Frame_getEasingParams(lua_State* tolua_S)
|
int lua_cocos2dx_studio_Frame_getEasingParams(lua_State* tolua_S)
|
||||||
{
|
{
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
|
@ -16387,9 +16484,11 @@ int lua_register_cocos2dx_studio_Frame(lua_State* tolua_S)
|
||||||
|
|
||||||
tolua_beginmodule(tolua_S,"Frame");
|
tolua_beginmodule(tolua_S,"Frame");
|
||||||
tolua_function(tolua_S,"clone",lua_cocos2dx_studio_Frame_clone);
|
tolua_function(tolua_S,"clone",lua_cocos2dx_studio_Frame_clone);
|
||||||
|
tolua_function(tolua_S,"setTweenType",lua_cocos2dx_studio_Frame_setTweenType);
|
||||||
tolua_function(tolua_S,"setNode",lua_cocos2dx_studio_Frame_setNode);
|
tolua_function(tolua_S,"setNode",lua_cocos2dx_studio_Frame_setNode);
|
||||||
tolua_function(tolua_S,"setTimeline",lua_cocos2dx_studio_Frame_setTimeline);
|
tolua_function(tolua_S,"setTimeline",lua_cocos2dx_studio_Frame_setTimeline);
|
||||||
tolua_function(tolua_S,"isEnterWhenPassed",lua_cocos2dx_studio_Frame_isEnterWhenPassed);
|
tolua_function(tolua_S,"isEnterWhenPassed",lua_cocos2dx_studio_Frame_isEnterWhenPassed);
|
||||||
|
tolua_function(tolua_S,"getTweenType",lua_cocos2dx_studio_Frame_getTweenType);
|
||||||
tolua_function(tolua_S,"getEasingParams",lua_cocos2dx_studio_Frame_getEasingParams);
|
tolua_function(tolua_S,"getEasingParams",lua_cocos2dx_studio_Frame_getEasingParams);
|
||||||
tolua_function(tolua_S,"setEasingParams",lua_cocos2dx_studio_Frame_setEasingParams);
|
tolua_function(tolua_S,"setEasingParams",lua_cocos2dx_studio_Frame_setEasingParams);
|
||||||
tolua_function(tolua_S,"getFrameIndex",lua_cocos2dx_studio_Frame_getFrameIndex);
|
tolua_function(tolua_S,"getFrameIndex",lua_cocos2dx_studio_Frame_getFrameIndex);
|
||||||
|
|
|
@ -512,6 +512,8 @@ int register_all_cocos2dx_studio(lua_State* tolua_S);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,7 @@ LuaMinXmlHttpRequest::~LuaMinXmlHttpRequest()
|
||||||
{
|
{
|
||||||
_httpHeader.clear();
|
_httpHeader.clear();
|
||||||
_requestHeader.clear();
|
_requestHeader.clear();
|
||||||
|
CC_SAFE_RELEASE_NULL(_httpRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -268,7 +269,7 @@ void LuaMinXmlHttpRequest::_sendRequest()
|
||||||
release();
|
release();
|
||||||
});
|
});
|
||||||
network::HttpClient::getInstance()->sendImmediate(_httpRequest);
|
network::HttpClient::getInstance()->sendImmediate(_httpRequest);
|
||||||
_httpRequest->release();
|
CC_SAFE_RELEASE_NULL(_httpRequest);
|
||||||
retain();
|
retain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
#include "UIPageView.h"
|
||||||
#include "UILayoutComponent.h"
|
#include "UILayoutComponent.h"
|
||||||
#include "2d/CCNode.h"
|
#include "2d/CCNode.h"
|
||||||
#include "GUIDefine.h"
|
#include "GUIDefine.h"
|
||||||
|
@ -667,7 +667,21 @@ namespace ui {
|
||||||
_owner->setPosition(ownerPosition);
|
_owner->setPosition(ownerPosition);
|
||||||
_owner->setContentSize(ownerSize);
|
_owner->setContentSize(ownerSize);
|
||||||
|
|
||||||
ui::Helper::doLayout(_owner);
|
if (typeid(*_owner) == typeid(PageView))
|
||||||
|
{
|
||||||
|
PageView* page = static_cast<PageView*>(_owner);
|
||||||
|
page->forceDoLayout();
|
||||||
|
|
||||||
|
Vector<Layout*> _layoutVector = page->getPages();
|
||||||
|
for(auto& item : _layoutVector)
|
||||||
|
{
|
||||||
|
ui::Helper::doLayout(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui::Helper::doLayout(_owner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LayoutComponent::setActiveEnabled(bool enable)
|
void LayoutComponent::setActiveEnabled(bool enable)
|
||||||
|
|
|
@ -149,7 +149,7 @@ void ScrollView::onSizeChanged()
|
||||||
float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width);
|
float innerSizeWidth = MAX(orginInnerSizeWidth, _contentSize.width);
|
||||||
float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height);
|
float innerSizeHeight = MAX(orginInnerSizeHeight, _contentSize.height);
|
||||||
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
|
_innerContainer->setContentSize(Size(innerSizeWidth, innerSizeHeight));
|
||||||
_innerContainer->setPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height));
|
setInnerContainerPosition(Vec2(0, _contentSize.height - _innerContainer->getContentSize().height));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollView::setInnerContainerSize(const Size &size)
|
void ScrollView::setInnerContainerSize(const Size &size)
|
||||||
|
@ -193,7 +193,7 @@ void ScrollView::setInnerContainerSize(const Size &size)
|
||||||
{
|
{
|
||||||
pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height;
|
pos.y = _contentSize.height - (1.0f - _innerContainer->getAnchorPoint().y) * _innerContainer->getContentSize().height;
|
||||||
}
|
}
|
||||||
_innerContainer->setPosition(pos);
|
setInnerContainerPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Size& ScrollView::getInnerContainerSize() const
|
const Size& ScrollView::getInnerContainerSize() const
|
||||||
|
@ -201,6 +201,27 @@ const Size& ScrollView::getInnerContainerSize() const
|
||||||
return _innerContainer->getContentSize();
|
return _innerContainer->getContentSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScrollView::setInnerContainerPosition(const Vec2 &position)
|
||||||
|
{
|
||||||
|
_innerContainer->setPosition(position);
|
||||||
|
|
||||||
|
this->retain();
|
||||||
|
if (_eventCallback)
|
||||||
|
{
|
||||||
|
_eventCallback(this, EventType::CONTAINER_MOVED);
|
||||||
|
}
|
||||||
|
if (_ccEventCallback)
|
||||||
|
{
|
||||||
|
_ccEventCallback(this, static_cast<int>(EventType::CONTAINER_MOVED));
|
||||||
|
}
|
||||||
|
this->release();
|
||||||
|
}
|
||||||
|
|
||||||
|
const Vec2 ScrollView::getInnerContainerPosition() const
|
||||||
|
{
|
||||||
|
return _innerContainer->getPosition();
|
||||||
|
}
|
||||||
|
|
||||||
void ScrollView::addChild(Node* child)
|
void ScrollView::addChild(Node* child)
|
||||||
{
|
{
|
||||||
ScrollView::addChild(child, child->getLocalZOrder(), child->getTag());
|
ScrollView::addChild(child, child->getLocalZOrder(), child->getTag());
|
||||||
|
@ -269,7 +290,7 @@ void ScrollView::moveChildren(float offsetX, float offsetY)
|
||||||
|
|
||||||
void ScrollView::moveChildrenToPosition(const Vec2& position)
|
void ScrollView::moveChildrenToPosition(const Vec2& position)
|
||||||
{
|
{
|
||||||
_innerContainer->setPosition(position);
|
setInnerContainerPosition(position);
|
||||||
|
|
||||||
Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO);
|
Vec2 outOfBoundary = getHowMuchOutOfBoundary(Vec2::ZERO);
|
||||||
updateScrollBar(outOfBoundary);
|
updateScrollBar(outOfBoundary);
|
||||||
|
@ -345,6 +366,7 @@ void ScrollView::processAutoScrolling(float deltaTime)
|
||||||
percentage = tweenfunc::quintEaseOut(percentage);
|
percentage = tweenfunc::quintEaseOut(percentage);
|
||||||
}
|
}
|
||||||
Vec2 moveDelta = _autoScrollTargetDelta * percentage;
|
Vec2 moveDelta = _autoScrollTargetDelta * percentage;
|
||||||
|
moveChildrenToPosition(_autoScrollStartPosition + moveDelta);
|
||||||
|
|
||||||
// Dispatch related events if bouncing
|
// Dispatch related events if bouncing
|
||||||
if(_bouncingBack)
|
if(_bouncingBack)
|
||||||
|
@ -366,7 +388,6 @@ void ScrollView::processAutoScrolling(float deltaTime)
|
||||||
processScrollEvent(MoveDirection::BOTTOM, true);
|
processScrollEvent(MoveDirection::BOTTOM, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moveChildrenToPosition(_autoScrollStartPosition + moveDelta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,8 +515,6 @@ void ScrollView::processInertiaScrolling(float dt)
|
||||||
|
|
||||||
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
{
|
{
|
||||||
processScrollingEvent();
|
|
||||||
|
|
||||||
touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX);
|
touchOffsetX = (_direction == Direction::VERTICAL ? 0 : touchOffsetX);
|
||||||
touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY);
|
touchOffsetY = (_direction == Direction::HORIZONTAL ? 0 : touchOffsetY);
|
||||||
if(_bounceEnabled)
|
if(_bounceEnabled)
|
||||||
|
@ -508,7 +527,10 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
float realOffsetX = touchOffsetX;
|
float realOffsetX = touchOffsetX;
|
||||||
float realOffsetY = touchOffsetY;
|
float realOffsetY = touchOffsetY;
|
||||||
|
|
||||||
bool scrollEnabledUpDown = true;
|
bool scrolledToLeft = false;
|
||||||
|
bool scrolledToRight = false;
|
||||||
|
bool scrolledToTop = false;
|
||||||
|
bool scrolledToBottom = false;
|
||||||
if (touchOffsetY > 0.0f) // up
|
if (touchOffsetY > 0.0f) // up
|
||||||
{
|
{
|
||||||
float icBottomPos = _innerContainer->getBottomBoundary();
|
float icBottomPos = _innerContainer->getBottomBoundary();
|
||||||
|
@ -518,8 +540,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
{
|
{
|
||||||
realOffsetY = _bottomBoundary - icBottomPos;
|
realOffsetY = _bottomBoundary - icBottomPos;
|
||||||
}
|
}
|
||||||
processScrollEvent(MoveDirection::BOTTOM, false);
|
scrolledToBottom = true;
|
||||||
scrollEnabledUpDown = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (touchOffsetY < 0.0f) // down
|
else if (touchOffsetY < 0.0f) // down
|
||||||
|
@ -531,12 +552,10 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
{
|
{
|
||||||
realOffsetY = _topBoundary - icTopPos;
|
realOffsetY = _topBoundary - icTopPos;
|
||||||
}
|
}
|
||||||
processScrollEvent(MoveDirection::TOP, false);
|
scrolledToTop = true;
|
||||||
scrollEnabledUpDown = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scrollEnabledLeftRight = true;
|
|
||||||
if (touchOffsetX < 0.0f) // left
|
if (touchOffsetX < 0.0f) // left
|
||||||
{
|
{
|
||||||
float icRightPos = _innerContainer->getRightBoundary();
|
float icRightPos = _innerContainer->getRightBoundary();
|
||||||
|
@ -546,8 +565,7 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
{
|
{
|
||||||
realOffsetX = _rightBoundary - icRightPos;
|
realOffsetX = _rightBoundary - icRightPos;
|
||||||
}
|
}
|
||||||
processScrollEvent(MoveDirection::RIGHT, false);
|
scrolledToRight = true;
|
||||||
scrollEnabledLeftRight = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (touchOffsetX > 0.0f) // right
|
else if (touchOffsetX > 0.0f) // right
|
||||||
|
@ -559,11 +577,34 @@ bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
|
||||||
{
|
{
|
||||||
realOffsetX = _leftBoundary - icLeftPos;
|
realOffsetX = _leftBoundary - icLeftPos;
|
||||||
}
|
}
|
||||||
processScrollEvent(MoveDirection::LEFT, false);
|
scrolledToLeft = true;
|
||||||
scrollEnabledLeftRight = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moveChildren(realOffsetX, realOffsetY);
|
moveChildren(realOffsetX, realOffsetY);
|
||||||
|
|
||||||
|
if(realOffsetX != 0 || realOffsetY != 0)
|
||||||
|
{
|
||||||
|
processScrollingEvent();
|
||||||
|
}
|
||||||
|
if(scrolledToBottom)
|
||||||
|
{
|
||||||
|
processScrollEvent(MoveDirection::BOTTOM, false);
|
||||||
|
}
|
||||||
|
if(scrolledToTop)
|
||||||
|
{
|
||||||
|
processScrollEvent(MoveDirection::TOP, false);
|
||||||
|
}
|
||||||
|
if(scrolledToLeft)
|
||||||
|
{
|
||||||
|
processScrollEvent(MoveDirection::LEFT, false);
|
||||||
|
}
|
||||||
|
if(scrolledToRight)
|
||||||
|
{
|
||||||
|
processScrollEvent(MoveDirection::RIGHT, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool scrollEnabledUpDown = (!scrolledToBottom && !scrolledToTop);
|
||||||
|
bool scrollEnabledLeftRight = (!scrolledToLeft && !scrolledToRight);
|
||||||
return scrollEnabledUpDown || scrollEnabledLeftRight;
|
return scrollEnabledUpDown || scrollEnabledLeftRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1149,6 +1190,33 @@ const Color3B& ScrollView::getScrollBarColor() const
|
||||||
return Color3B::WHITE;
|
return Color3B::WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScrollView::setScrollBarOpacity(GLubyte opacity)
|
||||||
|
{
|
||||||
|
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
|
||||||
|
if(_verticalScrollBar != nullptr)
|
||||||
|
{
|
||||||
|
_verticalScrollBar->setOpacity(opacity);
|
||||||
|
}
|
||||||
|
if(_horizontalScrollBar != nullptr)
|
||||||
|
{
|
||||||
|
_horizontalScrollBar->setOpacity(opacity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GLubyte ScrollView::getScrollBarOpacity() const
|
||||||
|
{
|
||||||
|
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
|
||||||
|
if(_verticalScrollBar != nullptr)
|
||||||
|
{
|
||||||
|
return _verticalScrollBar->getOpacity();
|
||||||
|
}
|
||||||
|
else if(_horizontalScrollBar != nullptr)
|
||||||
|
{
|
||||||
|
return _horizontalScrollBar->getOpacity();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void ScrollView::setScrollBarAutoHideEnabled(bool autoHideEnabled)
|
void ScrollView::setScrollBarAutoHideEnabled(bool autoHideEnabled)
|
||||||
{
|
{
|
||||||
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
|
CCASSERT(_scrollBarEnabled, "Scroll bar should be enabled!");
|
||||||
|
|
|
@ -99,7 +99,8 @@ public:
|
||||||
BOUNCE_TOP,
|
BOUNCE_TOP,
|
||||||
BOUNCE_BOTTOM,
|
BOUNCE_BOTTOM,
|
||||||
BOUNCE_LEFT,
|
BOUNCE_LEFT,
|
||||||
BOUNCE_RIGHT
|
BOUNCE_RIGHT,
|
||||||
|
CONTAINER_MOVED
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,6 +309,20 @@ public:
|
||||||
* @return The inner container size.
|
* @return The inner container size.
|
||||||
*/
|
*/
|
||||||
const Size& getInnerContainerSize() const;
|
const Size& getInnerContainerSize() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set inner container position
|
||||||
|
*
|
||||||
|
* @param pos Inner container position.
|
||||||
|
*/
|
||||||
|
void setInnerContainerPosition(const Vec2 &pos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get inner container position
|
||||||
|
*
|
||||||
|
* @return The inner container position.
|
||||||
|
*/
|
||||||
|
const Vec2 getInnerContainerPosition() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add callback function which will be called when scrollview event triggered.
|
* Add callback function which will be called when scrollview event triggered.
|
||||||
|
@ -449,6 +464,20 @@ public:
|
||||||
*/
|
*/
|
||||||
const Color3B& getScrollBarColor() const;
|
const Color3B& getScrollBarColor() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the scroll bar's opacity
|
||||||
|
*
|
||||||
|
* @param the scroll bar's opacity
|
||||||
|
*/
|
||||||
|
void setScrollBarOpacity(GLubyte opacity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the scroll bar's opacity
|
||||||
|
*
|
||||||
|
* @return the scroll bar's opacity
|
||||||
|
*/
|
||||||
|
GLubyte getScrollBarOpacity() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set scroll bar auto hide state
|
* @brief Set scroll bar auto hide state
|
||||||
*
|
*
|
||||||
|
|
|
@ -31,8 +31,8 @@ NS_CC_BEGIN
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAIVBMVEX///////////////////////////////////////////9/gMdvAAAAC3RSTlMAAgMLLFBTYWNkZuZhN4QAAAAvSURBVAjXRchBDgAgCAPBIi0q/3+wxBiZU7cAjJpTNBSPvMLrf7tqgPkR6hB2xzpFkgIfM9q/8QAAAABJRU5ErkJggg==";
|
static const char* HALF_CIRCLE_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAAGCAMAAADAMI+zAAAAJ1BMVEX///////////////////////////////////////////////////9Ruv0SAAAADHRSTlMABgcbbW7Hz9Dz+PmlcJP5AAAAMElEQVR4AUXHwQ2AQAhFwYcLH1H6r1djzDK3ASxUpTBeK/uTCyz7dx54b44m4p5cD1MwAooEJyk3AAAAAElFTkSuQmCC";
|
||||||
static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAAAXRSTlNm5DccCwAAAApJREFUeAFjQAYAAA0AAWHNnKQAAAAASUVORK5CYII=";
|
static const char* BODY_IMAGE_1_PIXEL_HEIGHT = "iVBORw0KGgoAAAANSUhEUgAAAAwAAAABCAMAAADdNb8LAAAAA1BMVEX///+nxBvIAAAACklEQVR4AWNABgAADQABYc2cpAAAAABJRU5ErkJggg==";
|
||||||
|
|
||||||
static const Color3B DEFAULT_COLOR(52, 65, 87);
|
static const Color3B DEFAULT_COLOR(52, 65, 87);
|
||||||
static const float DEFAULT_MARGIN = 20;
|
static const float DEFAULT_MARGIN = 20;
|
||||||
|
@ -65,6 +65,7 @@ _direction(direction),
|
||||||
_upperHalfCircle(nullptr),
|
_upperHalfCircle(nullptr),
|
||||||
_lowerHalfCircle(nullptr),
|
_lowerHalfCircle(nullptr),
|
||||||
_body(nullptr),
|
_body(nullptr),
|
||||||
|
_opacity(100),
|
||||||
_marginFromBoundary(DEFAULT_MARGIN),
|
_marginFromBoundary(DEFAULT_MARGIN),
|
||||||
_marginForLength(DEFAULT_MARGIN),
|
_marginForLength(DEFAULT_MARGIN),
|
||||||
_touching(false),
|
_touching(false),
|
||||||
|
@ -103,16 +104,16 @@ bool ScrollViewBar::init()
|
||||||
|
|
||||||
_upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE);
|
_upperHalfCircle = createSpriteFromBase64(HALF_CIRCLE_IMAGE);
|
||||||
_upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
_upperHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
||||||
addChild(_upperHalfCircle);
|
addProtectedChild(_upperHalfCircle);
|
||||||
|
|
||||||
_lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated());
|
_lowerHalfCircle = Sprite::createWithTexture(_upperHalfCircle->getTexture(), _upperHalfCircle->getTextureRect(), _upperHalfCircle->isTextureRectRotated());
|
||||||
_lowerHalfCircle->setScaleY(-1);
|
_lowerHalfCircle->setScaleY(-1);
|
||||||
_lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
_lowerHalfCircle->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
||||||
addChild(_lowerHalfCircle);
|
addProtectedChild(_lowerHalfCircle);
|
||||||
|
|
||||||
_body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT);
|
_body = createSpriteFromBase64(BODY_IMAGE_1_PIXEL_HEIGHT);
|
||||||
_body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
_body->setAnchorPoint(Vec2::ANCHOR_MIDDLE_BOTTOM);
|
||||||
addChild(_body);
|
addProtectedChild(_body);
|
||||||
|
|
||||||
setColor(DEFAULT_COLOR);
|
setColor(DEFAULT_COLOR);
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ bool ScrollViewBar::init()
|
||||||
|
|
||||||
if(_autoHideEnabled)
|
if(_autoHideEnabled)
|
||||||
{
|
{
|
||||||
setOpacity(0);
|
ProtectedNode::setOpacity(0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +166,7 @@ void ScrollViewBar::setWidth(float width)
|
||||||
void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled)
|
void ScrollViewBar::setAutoHideEnabled(bool autoHideEnabled)
|
||||||
{
|
{
|
||||||
_autoHideEnabled = autoHideEnabled;
|
_autoHideEnabled = autoHideEnabled;
|
||||||
setOpacity(255);
|
ProtectedNode::setOpacity(_opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
float ScrollViewBar::getWidth() const
|
float ScrollViewBar::getWidth() const
|
||||||
|
@ -202,7 +203,7 @@ void ScrollViewBar::update(float deltaTime)
|
||||||
if(_autoHideRemainingTime <= _autoHideTime)
|
if(_autoHideRemainingTime <= _autoHideTime)
|
||||||
{
|
{
|
||||||
_autoHideRemainingTime = MAX(0, _autoHideRemainingTime);
|
_autoHideRemainingTime = MAX(0, _autoHideRemainingTime);
|
||||||
this->setOpacity(255 * (_autoHideRemainingTime / _autoHideTime));
|
ProtectedNode::setOpacity(_opacity * (_autoHideRemainingTime / _autoHideTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +237,7 @@ void ScrollViewBar::onScrolled(const Vec2& outOfBoundary)
|
||||||
if(_autoHideEnabled)
|
if(_autoHideEnabled)
|
||||||
{
|
{
|
||||||
_autoHideRemainingTime = _autoHideTime;
|
_autoHideRemainingTime = _autoHideTime;
|
||||||
setOpacity(255);
|
ProtectedNode::setOpacity(_opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
Layout* innerContainer = _parent->getInnerContainer();
|
Layout* innerContainer = _parent->getInnerContainer();
|
||||||
|
|
|
@ -130,6 +130,8 @@ public:
|
||||||
/**
|
/**
|
||||||
* @lua NA
|
* @lua NA
|
||||||
*/
|
*/
|
||||||
|
virtual void setOpacity(GLubyte opacity) override { _opacity = opacity; }
|
||||||
|
virtual GLubyte getOpacity() const override { return _opacity; }
|
||||||
virtual void onEnter() override;
|
virtual void onEnter() override;
|
||||||
virtual void update(float deltaTime) override;
|
virtual void update(float deltaTime) override;
|
||||||
|
|
||||||
|
@ -158,6 +160,8 @@ private:
|
||||||
Sprite* _upperHalfCircle;
|
Sprite* _upperHalfCircle;
|
||||||
Sprite* _lowerHalfCircle;
|
Sprite* _lowerHalfCircle;
|
||||||
Sprite* _body;
|
Sprite* _body;
|
||||||
|
|
||||||
|
GLubyte _opacity;
|
||||||
|
|
||||||
float _marginFromBoundary;
|
float _marginFromBoundary;
|
||||||
float _marginForLength;
|
float _marginForLength;
|
||||||
|
|
|
@ -563,12 +563,14 @@ void Slider::barRendererScaleChangedWithSize()
|
||||||
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
|
if (btextureSize.width <= 0.0f || btextureSize.height <= 0.0f)
|
||||||
{
|
{
|
||||||
_barRenderer->setScale(1.0f);
|
_barRenderer->setScale(1.0f);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
float bscaleX = _contentSize.width / btextureSize.width;
|
else
|
||||||
float bscaleY = _contentSize.height / btextureSize.height;
|
{
|
||||||
_barRenderer->setScaleX(bscaleX);
|
float bscaleX = _contentSize.width / btextureSize.width;
|
||||||
_barRenderer->setScaleY(bscaleY);
|
float bscaleY = _contentSize.height / btextureSize.height;
|
||||||
|
_barRenderer->setScaleX(bscaleX);
|
||||||
|
_barRenderer->setScaleY(bscaleY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
|
_barRenderer->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
- [Nine Patch format support](#nine-patch-format-support)
|
- [Nine Patch format support](#nine-patch-format-support)
|
||||||
- [Android Studio support](#android-studio-support)
|
- [Android Studio support](#android-studio-support)
|
||||||
- [Samsung Enhanced API support](#samsung-enhanced-api-support)
|
- [Samsung Enhanced API support](#samsung-enhanced-api-support)
|
||||||
|
- [SDKBOX](#sdkbox)
|
||||||
- [The Next Step](#the-next-step)
|
- [The Next Step](#the-next-step)
|
||||||
|
|
||||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
@ -65,9 +66,9 @@ You can use [Cocos Console](www.cocos2d-x.org/wiki/Cocos2d-console) command line
|
||||||
In console application:
|
In console application:
|
||||||
```
|
```
|
||||||
// Enter cpp test folder
|
// Enter cpp test folder
|
||||||
cd tests/cpp-tests
|
cd tests/cpp-tests
|
||||||
// Or enter js test folder
|
// Or enter js test folder
|
||||||
cd tests/js-tests
|
cd tests/js-tests
|
||||||
// Or enter lua test folder
|
// Or enter lua test folder
|
||||||
cd tests/lua-tests
|
cd tests/lua-tests
|
||||||
|
|
||||||
|
@ -168,6 +169,7 @@ cocos new -l cpp|js|lua MyGame
|
||||||
* JS: Merged JSB and web engine into Cocos2d-x for a All-in-one engine
|
* JS: Merged JSB and web engine into Cocos2d-x for a All-in-one engine
|
||||||
* JS: Added `ccui.VideoPlayer` and `ccui.WebView` for iOS/Android/Web
|
* JS: Added `ccui.VideoPlayer` and `ccui.WebView` for iOS/Android/Web
|
||||||
* console: Supported build & run Android Studio project with cocos console
|
* console: Supported build & run Android Studio project with cocos console
|
||||||
|
* sdkbox: super EASY way to integrate 3rd party SDKs into cocos2d-x
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
|
@ -234,10 +236,30 @@ Samsung have provided a series of Enhanced API to optimize Cocos2d-x games for S
|
||||||
|
|
||||||
In the previous versions, the resources file name's case is ignored on win32 platform, but not ignored in other platforms. This will lead to some unexpected issues, especially when user develop with win32 platform and pulish to other platforms like Android. In win32, the file name may be found without matching the case, but on other platforms it won't be found. So we decided to make win32 platform's resources case sensitive. Please make sure you are using the correct file name for your resources.
|
In the previous versions, the resources file name's case is ignored on win32 platform, but not ignored in other platforms. This will lead to some unexpected issues, especially when user develop with win32 platform and pulish to other platforms like Android. In win32, the file name may be found without matching the case, but on other platforms it won't be found. So we decided to make win32 platform's resources case sensitive. Please make sure you are using the correct file name for your resources.
|
||||||
|
|
||||||
|
### SDKBOX
|
||||||
|
SDKBOX is a project that's built by part of the cocos2d-x team, in order to makes integrating 3rd party SDKs super EASY.
|
||||||
|
With SDKBOX you can integrate services like In App Purchase with one command
|
||||||
|
```
|
||||||
|
sdkbox import -b iap
|
||||||
|
```
|
||||||
|
Currently supported service including
|
||||||
|
|
||||||
|
* [Tune](http://cocos2d-x.org/sdkbox/tune)
|
||||||
|
* [In App Purchase](http://cocos2d-x.org/sdkbox/iap)
|
||||||
|
* [AdColony](http://cocos2d-x.org/sdkbox/adcolony)
|
||||||
|
* [Vungle](http://cocos2d-x.org/sdkbox/vungle)
|
||||||
|
* [Chartboost](http://cocos2d-x.org/sdkbox/chartboost)
|
||||||
|
* [Kochava](http://cocos2d-x.org/sdkbox/kochava)
|
||||||
|
* [Google Analytics](http://cocos2d-x.org/sdkbox/googleanalytics)
|
||||||
|
* [Flurry Analytics](http://cocos2d-x.org/sdkbox/flurryanalytics)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## The Next Step
|
## The Next Step
|
||||||
|
|
||||||
As you can see, in v3.7, we have enhanced our 2d rendering with material system and integrated polygon sprite. More importantly, our 3d features become more and more complete, 3d Physics and Navigation Mesh with the previous Camera, 3d Sprite, 3d Particle System, 3d Light, 3d Terrain, Skybox, now you can really start to use Cocos to make a 3d game.
|
As you can see, in v3.7, we have enhanced our 2d rendering with material system and integrated polygon sprite. More importantly, our 3d features become more and more complete, 3d Physics and Navigation Mesh with the previous Camera, 3d Sprite, 3d Particle System, 3d Light, 3d Terrain, Skybox, now you can really start to use Cocos to make a 3d game.
|
||||||
|
|
||||||
In v3.8, we won't do much more features, but we'd like to slow down and refine our current 3D and 2D modules.
|
In v3.8, we won't do much more features, but we'd like to slow down and refine our current 3D and 2D modules.
|
||||||
|
|
||||||
[The v3.8 milestone tasks](https://github.com/cocos2d/cocos2d-x/milestones/v3.8)
|
[The v3.8 milestone tasks](https://github.com/cocos2d/cocos2d-x/milestones/v3.8)
|
||||||
|
|
|
@ -436,8 +436,8 @@ void ScrollView::deaccelerateScrolling(float dt)
|
||||||
|
|
||||||
if ((fabsf(_scrollDistance.x) <= SCROLL_DEACCEL_DIST &&
|
if ((fabsf(_scrollDistance.x) <= SCROLL_DEACCEL_DIST &&
|
||||||
fabsf(_scrollDistance.y) <= SCROLL_DEACCEL_DIST) ||
|
fabsf(_scrollDistance.y) <= SCROLL_DEACCEL_DIST) ||
|
||||||
newY >= maxInset.y || newY <= minInset.y ||
|
((_direction == Direction::BOTH || _direction == Direction::VERTICAL) && (newY >= maxInset.y || newY <= minInset.y)) ||
|
||||||
newX >= maxInset.x || newX <= minInset.x)
|
((_direction == Direction::BOTH || _direction == Direction::HORIZONTAL) && (newX >= maxInset.x || newX <= minInset.x)))
|
||||||
{
|
{
|
||||||
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
|
this->unschedule(CC_SCHEDULE_SELECTOR(ScrollView::deaccelerateScrolling));
|
||||||
this->relocateContainer(true);
|
this->relocateContainer(true);
|
||||||
|
|
|
@ -257,6 +257,9 @@ message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
|
||||||
add_subdirectory(frameworks/cocos2d-x/external/xxhash)
|
add_subdirectory(frameworks/cocos2d-x/external/xxhash)
|
||||||
include_directories(frameworks/cocos2d-x/external/xxhash)
|
include_directories(frameworks/cocos2d-x/external/xxhash)
|
||||||
|
|
||||||
|
#buid recast
|
||||||
|
add_subdirectory(frameworks/cocos2d-x/external/recast)
|
||||||
|
|
||||||
set(GAME_SRC
|
set(GAME_SRC
|
||||||
frameworks/runtime-src/proj.linux/main.cpp
|
frameworks/runtime-src/proj.linux/main.cpp
|
||||||
frameworks/runtime-src/Classes/AppDelegate.cpp
|
frameworks/runtime-src/Classes/AppDelegate.cpp
|
||||||
|
@ -277,6 +280,7 @@ add_executable(${APP_NAME}
|
||||||
target_link_libraries(${APP_NAME}
|
target_link_libraries(${APP_NAME}
|
||||||
jscocos2d
|
jscocos2d
|
||||||
cocos2d
|
cocos2d
|
||||||
|
recast
|
||||||
)
|
)
|
||||||
|
|
||||||
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
|
set(APP_BIN_DIR "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
|
@ -29,6 +29,8 @@ set(TESTS_SRC
|
||||||
Classes/AppDelegate.cpp
|
Classes/AppDelegate.cpp
|
||||||
Classes/BaseTest.cpp
|
Classes/BaseTest.cpp
|
||||||
Classes/BillBoardTest/BillBoardTest.cpp
|
Classes/BillBoardTest/BillBoardTest.cpp
|
||||||
|
Classes/BugsTest/Bug-CCDrawNode.cpp
|
||||||
|
Classes/BugsTest/Bug-PageViewLayout.cpp
|
||||||
Classes/BugsTest/Bug-1159.cpp
|
Classes/BugsTest/Bug-1159.cpp
|
||||||
Classes/BugsTest/Bug-1174.cpp
|
Classes/BugsTest/Bug-1174.cpp
|
||||||
Classes/BugsTest/Bug-350.cpp
|
Classes/BugsTest/Bug-350.cpp
|
||||||
|
|
|
@ -18,6 +18,7 @@ ActionManagerTests::ActionManagerTests()
|
||||||
ADD_TEST_CASE(PauseTest);
|
ADD_TEST_CASE(PauseTest);
|
||||||
ADD_TEST_CASE(StopActionTest);
|
ADD_TEST_CASE(StopActionTest);
|
||||||
ADD_TEST_CASE(StopAllActionsTest);
|
ADD_TEST_CASE(StopAllActionsTest);
|
||||||
|
ADD_TEST_CASE(StopActionsByFlagsTest);
|
||||||
ADD_TEST_CASE(ResumeTest);
|
ADD_TEST_CASE(ResumeTest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,3 +292,53 @@ void ResumeTest::resumeGrossini(float time)
|
||||||
auto director = Director::getInstance();
|
auto director = Director::getInstance();
|
||||||
director->getActionManager()->resumeTarget(pGrossini);
|
director->getActionManager()->resumeTarget(pGrossini);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// StopActionsByFlagsTest
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
void StopActionsByFlagsTest::onEnter()
|
||||||
|
{
|
||||||
|
ActionManagerTest::onEnter();
|
||||||
|
|
||||||
|
auto l = Label::createWithTTF("Should stop scale & move after 4 seconds but keep rotate", "fonts/Thonburi.ttf", 16.0f);
|
||||||
|
addChild(l);
|
||||||
|
l->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 75) );
|
||||||
|
|
||||||
|
auto pMove1 = MoveBy::create(2, Vec2(200, 0));
|
||||||
|
auto pMove2 = MoveBy::create(2, Vec2(-200, 0));
|
||||||
|
auto pSequenceMove = Sequence::createWithTwoActions(pMove1, pMove2);
|
||||||
|
auto pRepeatMove = RepeatForever::create(pSequenceMove);
|
||||||
|
pRepeatMove->setFlags(kMoveFlag | kRepeatForeverFlag);
|
||||||
|
|
||||||
|
auto pScale1 = ScaleBy::create(2, 1.5f);
|
||||||
|
auto pScale2 = ScaleBy::create(2, 1.0f/1.5f);
|
||||||
|
auto pSequenceScale = Sequence::createWithTwoActions(pScale1, pScale2);
|
||||||
|
auto pRepeatScale = RepeatForever::create(pSequenceScale);
|
||||||
|
pRepeatScale->setFlags(kScaleFlag | kRepeatForeverFlag);
|
||||||
|
|
||||||
|
auto pRotate = RotateBy::create(2, 360);
|
||||||
|
auto pRepeatRotate = RepeatForever::create(pRotate);
|
||||||
|
pRepeatRotate->setFlags(kRotateFlag | kRepeatForeverFlag);
|
||||||
|
|
||||||
|
auto pChild = Sprite::create(s_pathGrossini);
|
||||||
|
pChild->setPosition( VisibleRect::center() );
|
||||||
|
|
||||||
|
addChild(pChild, 1, kTagGrossini);
|
||||||
|
pChild->runAction(pRepeatMove);
|
||||||
|
pChild->runAction(pRepeatScale);
|
||||||
|
pChild->runAction(pRepeatRotate);
|
||||||
|
this->scheduleOnce((SEL_SCHEDULE)&StopActionsByFlagsTest::stopAction, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopActionsByFlagsTest::stopAction(float time)
|
||||||
|
{
|
||||||
|
auto sprite = getChildByTag(kTagGrossini);
|
||||||
|
sprite->stopActionsByFlags(kMoveFlag | kScaleFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string StopActionsByFlagsTest::subtitle() const
|
||||||
|
{
|
||||||
|
return "Stop All Actions By Flags Test";
|
||||||
|
}
|
||||||
|
|
|
@ -80,4 +80,19 @@ public:
|
||||||
void resumeGrossini(float time);
|
void resumeGrossini(float time);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class StopActionsByFlagsTest : public ActionManagerTest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(StopActionsByFlagsTest);
|
||||||
|
|
||||||
|
virtual std::string subtitle() const override;
|
||||||
|
virtual void onEnter() override;
|
||||||
|
void stopAction(float time);
|
||||||
|
protected:
|
||||||
|
const unsigned int kMoveFlag = 0x01;
|
||||||
|
const unsigned int kScaleFlag = 0x02;
|
||||||
|
const unsigned int kRotateFlag = 0x04;
|
||||||
|
const unsigned int kRepeatForeverFlag = 0x08; // You don't need this for the test, but it's for demonstration how to activate several flags on an action.
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// CCDrawNode::onDrawGLPoint & CCDrawNode::onDrawGLLine miss
|
||||||
|
// calling GL::blendFunc, so when a sprite set blendFunc, these
|
||||||
|
// function will get a wrong result.
|
||||||
|
// In this test, see a red line when bug resolved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Bug-CCDrawNode.h"
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
|
||||||
|
bool BugDrawNodeLayer::init()
|
||||||
|
{
|
||||||
|
if (BugsTestBase::init())
|
||||||
|
{
|
||||||
|
auto size = Director::getInstance()->getWinSize();
|
||||||
|
auto testSprite = Sprite::create("cocosui/CloseNormal.png");
|
||||||
|
BlendFunc blend;
|
||||||
|
blend.src = GL_ZERO;
|
||||||
|
blend.dst = GL_ONE_MINUS_SRC_ALPHA;
|
||||||
|
testSprite->setBlendFunc(blend);
|
||||||
|
testSprite->setPosition(Vec2(size.width / 2, size.height / 2));
|
||||||
|
testSprite->setScale(10);
|
||||||
|
addChild(testSprite);
|
||||||
|
|
||||||
|
auto drawNode = DrawNode::create();
|
||||||
|
drawNode->drawLine(Vec2(0, 0), Vec2(size.width, size.height), Color4F(1, 0, 0, 0.5f));
|
||||||
|
Vec2 point = Vec2(size.width / 2, size.height / 2);
|
||||||
|
drawNode->drawPoint(point, 8, Color4F(1, 0, 0, 0.5f));
|
||||||
|
addChild(drawNode);
|
||||||
|
|
||||||
|
auto label = Label::create();
|
||||||
|
label->setString(std::string("If you see a red line with a block at center, the bug is fixed!"));
|
||||||
|
label->setPosition(size.width / 2, size.height / 4);
|
||||||
|
label->setTextColor(Color4B::ORANGE);
|
||||||
|
addChild(label);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef __BUG_CCDRAWNODE_H__
|
||||||
|
#define __BUG_CCDRAWNODE_H__
|
||||||
|
|
||||||
|
#include "BugsTest.h"
|
||||||
|
|
||||||
|
class BugDrawNodeLayer : public BugsTestBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(BugDrawNodeLayer);
|
||||||
|
|
||||||
|
virtual bool init() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,40 @@
|
||||||
|
//
|
||||||
|
// When a pageview set to relative position & size, if it
|
||||||
|
// has child widget set to relative position & size either,
|
||||||
|
// when change layer size, relayout won't correctly effect
|
||||||
|
// to the child.
|
||||||
|
// In this test, if button at the center of panel, bug is fixed!
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "Bug-PageViewLayout.h"
|
||||||
|
#include "cocostudio/CocoStudio.h"
|
||||||
|
#include "ui/CocosGUI.h"
|
||||||
|
#include "platform/CCFileUtils.h"
|
||||||
|
|
||||||
|
USING_NS_CC;
|
||||||
|
using namespace ui;
|
||||||
|
|
||||||
|
bool BugPageViewLayer::init()
|
||||||
|
{
|
||||||
|
if (BugsTestBase::init())
|
||||||
|
{
|
||||||
|
auto size = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
FileUtils::getInstance()->addSearchPath("ccs-res/cocosui/CustomTest/CustomWidgetCallbackBindTest");
|
||||||
|
auto rootNode = CSLoader::createNode("cocosui/CustomTest/CustomWidgetCallbackBindTest/PageViewBugScene.csb");
|
||||||
|
auto child = rootNode->getChildByName("ProjectNode_1");
|
||||||
|
child->setContentSize(Size(480, 320));
|
||||||
|
Helper::doLayout(child);
|
||||||
|
addChild(rootNode);
|
||||||
|
|
||||||
|
auto label = Label::create();
|
||||||
|
label->setString(std::string("If button is at the center of panel, the bug is fixed!"));
|
||||||
|
label->setPosition(size.width / 2, size.height / 4);
|
||||||
|
label->setTextColor(Color4B::ORANGE);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef __BUG_PAGEVIEWLAYOUT_H__
|
||||||
|
#define __BUG_PAGEVIEWLAYOUT_H__
|
||||||
|
|
||||||
|
#include "BugsTest.h"
|
||||||
|
|
||||||
|
class BugPageViewLayer : public BugsTestBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CREATE_FUNC(BugPageViewLayer);
|
||||||
|
|
||||||
|
virtual bool init() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // !__BUG_PAGEVIEWLAYOUT_H__
|
|
@ -9,6 +9,8 @@
|
||||||
#include "Bug-1159.h"
|
#include "Bug-1159.h"
|
||||||
#include "Bug-1174.h"
|
#include "Bug-1174.h"
|
||||||
#include "Bug-Child.h"
|
#include "Bug-Child.h"
|
||||||
|
#include "Bug-CCDrawNode.h"
|
||||||
|
#include "Bug-PageViewLayout.h"
|
||||||
|
|
||||||
BugsTests::BugsTests()
|
BugsTests::BugsTests()
|
||||||
{
|
{
|
||||||
|
@ -23,4 +25,6 @@ BugsTests::BugsTests()
|
||||||
ADD_TEST_CASE(Bug1174Layer);
|
ADD_TEST_CASE(Bug1174Layer);
|
||||||
ADD_TEST_CASE(BugChild);
|
ADD_TEST_CASE(BugChild);
|
||||||
ADD_TEST_CASE(BugCameraMask);
|
ADD_TEST_CASE(BugCameraMask);
|
||||||
|
ADD_TEST_CASE(BugDrawNodeLayer);
|
||||||
|
ADD_TEST_CASE(BugPageViewLayer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,15 @@ FileUtilsTests::FileUtilsTests()
|
||||||
ADD_TEST_CASE(TestSearchPath);
|
ADD_TEST_CASE(TestSearchPath);
|
||||||
ADD_TEST_CASE(TestFilenameLookup);
|
ADD_TEST_CASE(TestFilenameLookup);
|
||||||
ADD_TEST_CASE(TestIsFileExist);
|
ADD_TEST_CASE(TestIsFileExist);
|
||||||
|
ADD_TEST_CASE(TestIsDirectoryExist);
|
||||||
ADD_TEST_CASE(TestFileFuncs);
|
ADD_TEST_CASE(TestFileFuncs);
|
||||||
ADD_TEST_CASE(TestDirectoryFuncs);
|
ADD_TEST_CASE(TestDirectoryFuncs);
|
||||||
ADD_TEST_CASE(TextWritePlist);
|
ADD_TEST_CASE(TextWritePlist);
|
||||||
|
ADD_TEST_CASE(TestWriteString);
|
||||||
|
ADD_TEST_CASE(TestWriteData);
|
||||||
|
ADD_TEST_CASE(TestWriteValueMap);
|
||||||
|
ADD_TEST_CASE(TestWriteValueVector);
|
||||||
|
ADD_TEST_CASE(TestUnicodePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestResolutionDirectories
|
// TestResolutionDirectories
|
||||||
|
@ -21,13 +27,13 @@ void TestResolutionDirectories::onEnter()
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
|
||||||
sharedFileUtils->purgeCachedEntries();
|
sharedFileUtils->purgeCachedEntries();
|
||||||
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
|
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
|
||||||
std::vector<std::string> searchPaths = _defaultSearchPathArray;
|
std::vector<std::string> searchPaths = _defaultSearchPathArray;
|
||||||
searchPaths.insert(searchPaths.begin(), "Misc");
|
searchPaths.insert(searchPaths.begin(), "Misc");
|
||||||
sharedFileUtils->setSearchPaths(searchPaths);
|
sharedFileUtils->setSearchPaths(searchPaths);
|
||||||
|
|
||||||
_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
|
_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
|
||||||
std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray;
|
std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray;
|
||||||
|
|
||||||
|
@ -37,9 +43,9 @@ void TestResolutionDirectories::onEnter()
|
||||||
resolutionsOrder.insert(resolutionsOrder.begin()+3, "resources-wide");
|
resolutionsOrder.insert(resolutionsOrder.begin()+3, "resources-wide");
|
||||||
resolutionsOrder.insert(resolutionsOrder.begin()+4, "resources-hd");
|
resolutionsOrder.insert(resolutionsOrder.begin()+4, "resources-hd");
|
||||||
resolutionsOrder.insert(resolutionsOrder.begin()+5, "resources-iphone");
|
resolutionsOrder.insert(resolutionsOrder.begin()+5, "resources-iphone");
|
||||||
|
|
||||||
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
|
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
|
||||||
|
|
||||||
for( int i=1; i<7; i++) {
|
for( int i=1; i<7; i++) {
|
||||||
auto filename = String::createWithFormat("test%d.txt", i);
|
auto filename = String::createWithFormat("test%d.txt", i);
|
||||||
ret = sharedFileUtils->fullPathForFilename(filename->getCString());
|
ret = sharedFileUtils->fullPathForFilename(filename->getCString());
|
||||||
|
@ -50,9 +56,9 @@ void TestResolutionDirectories::onEnter()
|
||||||
void TestResolutionDirectories::onExit()
|
void TestResolutionDirectories::onExit()
|
||||||
{
|
{
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
// reset search path
|
// reset search path
|
||||||
sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
|
sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
|
||||||
sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
|
sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
|
||||||
FileUtilsDemo::onExit();
|
FileUtilsDemo::onExit();
|
||||||
}
|
}
|
||||||
|
@ -73,9 +79,9 @@ void TestSearchPath::onEnter()
|
||||||
{
|
{
|
||||||
FileUtilsDemo::onEnter();
|
FileUtilsDemo::onEnter();
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
std::string ret;
|
std::string ret;
|
||||||
|
|
||||||
sharedFileUtils->purgeCachedEntries();
|
sharedFileUtils->purgeCachedEntries();
|
||||||
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
|
_defaultSearchPathArray = sharedFileUtils->getSearchPaths();
|
||||||
std::vector<std::string> searchPaths = _defaultSearchPathArray;
|
std::vector<std::string> searchPaths = _defaultSearchPathArray;
|
||||||
|
@ -91,24 +97,24 @@ void TestSearchPath::onEnter()
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
log("Writing file to writable path succeed.");
|
log("Writing file to writable path succeed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
searchPaths.insert(searchPaths.begin(), writablePath);
|
searchPaths.insert(searchPaths.begin(), writablePath);
|
||||||
searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1");
|
searchPaths.insert(searchPaths.begin()+1, "Misc/searchpath1");
|
||||||
searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2");
|
searchPaths.insert(searchPaths.begin()+2, "Misc/searchpath2");
|
||||||
sharedFileUtils->setSearchPaths(searchPaths);
|
sharedFileUtils->setSearchPaths(searchPaths);
|
||||||
|
|
||||||
_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
|
_defaultResolutionsOrderArray = sharedFileUtils->getSearchResolutionsOrder();
|
||||||
std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray;
|
std::vector<std::string> resolutionsOrder = _defaultResolutionsOrderArray;
|
||||||
|
|
||||||
resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
|
resolutionsOrder.insert(resolutionsOrder.begin(), "resources-ipad");
|
||||||
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
|
sharedFileUtils->setSearchResolutionsOrder(resolutionsOrder);
|
||||||
|
|
||||||
for( int i=1; i<3; i++) {
|
for( int i=1; i<3; i++) {
|
||||||
auto filename = String::createWithFormat("file%d.txt", i);
|
auto filename = String::createWithFormat("file%d.txt", i);
|
||||||
ret = sharedFileUtils->fullPathForFilename(filename->getCString());
|
ret = sharedFileUtils->fullPathForFilename(filename->getCString());
|
||||||
log("%s -> %s", filename->getCString(), ret.c_str());
|
log("%s -> %s", filename->getCString(), ret.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets external.txt from writable path
|
// Gets external.txt from writable path
|
||||||
std::string fullPath = sharedFileUtils->fullPathForFilename("external.txt");
|
std::string fullPath = sharedFileUtils->fullPathForFilename("external.txt");
|
||||||
log("external file path = %s", fullPath.c_str());
|
log("external file path = %s", fullPath.c_str());
|
||||||
|
@ -118,7 +124,7 @@ void TestSearchPath::onEnter()
|
||||||
if (fp)
|
if (fp)
|
||||||
{
|
{
|
||||||
char szReadBuf[100] = {0};
|
char szReadBuf[100] = {0};
|
||||||
size_t read = fread(szReadBuf, 1, strlen(szBuf), fp);
|
size_t read = fread(szReadBuf, 1, strlen(szReadBuf), fp);
|
||||||
if (read > 0)
|
if (read > 0)
|
||||||
log("The content of file from writable path: %s", szReadBuf);
|
log("The content of file from writable path: %s", szReadBuf);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -128,10 +134,10 @@ void TestSearchPath::onEnter()
|
||||||
|
|
||||||
void TestSearchPath::onExit()
|
void TestSearchPath::onExit()
|
||||||
{
|
{
|
||||||
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
// reset search path
|
// reset search path
|
||||||
sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
|
sharedFileUtils->setSearchPaths(_defaultSearchPathArray);
|
||||||
sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
|
sharedFileUtils->setSearchResolutionsOrder(_defaultResolutionsOrderArray);
|
||||||
FileUtilsDemo::onExit();
|
FileUtilsDemo::onExit();
|
||||||
}
|
}
|
||||||
|
@ -151,31 +157,31 @@ std::string TestSearchPath::subtitle() const
|
||||||
void TestFilenameLookup::onEnter()
|
void TestFilenameLookup::onEnter()
|
||||||
{
|
{
|
||||||
FileUtilsDemo::onEnter();
|
FileUtilsDemo::onEnter();
|
||||||
|
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
ValueMap dict;
|
ValueMap dict;
|
||||||
dict["grossini.bmp"] = Value("Images/grossini.png");
|
dict["grossini.bmp"] = Value("Images/grossini.png");
|
||||||
dict["grossini.xcf"] = Value("Images/grossini.png");
|
dict["grossini.xcf"] = Value("Images/grossini.png");
|
||||||
|
|
||||||
sharedFileUtils->setFilenameLookupDictionary(dict);
|
sharedFileUtils->setFilenameLookupDictionary(dict);
|
||||||
|
|
||||||
// Instead of loading carlitos.xcf, it will load grossini.png
|
// Instead of loading carlitos.xcf, it will load grossini.png
|
||||||
auto sprite = Sprite::create("grossini.xcf");
|
auto sprite = Sprite::create("grossini.xcf");
|
||||||
this->addChild(sprite);
|
this->addChild(sprite);
|
||||||
|
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
sprite->setPosition(s.width/2, s.height/2);
|
sprite->setPosition(s.width/2, s.height/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestFilenameLookup::onExit()
|
void TestFilenameLookup::onExit()
|
||||||
{
|
{
|
||||||
|
|
||||||
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
// reset filename lookup
|
// reset filename lookup
|
||||||
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
||||||
|
|
||||||
FileUtilsDemo::onExit();
|
FileUtilsDemo::onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,16 +197,16 @@ void TestIsFileExist::onEnter()
|
||||||
FileUtilsDemo::onEnter();
|
FileUtilsDemo::onEnter();
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
Label* label = nullptr;
|
Label* label = nullptr;
|
||||||
bool isExist = false;
|
bool isExist = false;
|
||||||
|
|
||||||
isExist = sharedFileUtils->isFileExist("Images/grossini.png");
|
isExist = sharedFileUtils->isFileExist("Images/grossini.png");
|
||||||
|
|
||||||
label = Label::createWithSystemFont(isExist ? "Images/grossini.png exists" : "Images/grossini.png doesn't exist", "", 20);
|
label = Label::createWithSystemFont(isExist ? "Images/grossini.png exists" : "Images/grossini.png doesn't exist", "", 20);
|
||||||
label->setPosition(s.width/2, s.height/3);
|
label->setPosition(s.width/2, s.height/3);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
|
|
||||||
isExist = sharedFileUtils->isFileExist("Images/grossini.xcf");
|
isExist = sharedFileUtils->isFileExist("Images/grossini.xcf");
|
||||||
label = Label::createWithSystemFont(isExist ? "Images/grossini.xcf exists" : "Images/grossini.xcf doesn't exist", "", 20);
|
label = Label::createWithSystemFont(isExist ? "Images/grossini.xcf exists" : "Images/grossini.xcf doesn't exist", "", 20);
|
||||||
label->setPosition(s.width/2, s.height/3*2);
|
label->setPosition(s.width/2, s.height/3*2);
|
||||||
|
@ -209,12 +215,12 @@ void TestIsFileExist::onEnter()
|
||||||
|
|
||||||
void TestIsFileExist::onExit()
|
void TestIsFileExist::onExit()
|
||||||
{
|
{
|
||||||
|
|
||||||
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
// reset filename lookup
|
// reset filename lookup
|
||||||
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
||||||
|
|
||||||
FileUtilsDemo::onExit();
|
FileUtilsDemo::onExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,6 +234,61 @@ std::string TestIsFileExist::subtitle() const
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestIsDirectoryExist
|
||||||
|
|
||||||
|
void TestIsDirectoryExist::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
auto util = FileUtils::getInstance();
|
||||||
|
int x = s.width/2, y = s.height/3;
|
||||||
|
|
||||||
|
Label* label = nullptr;
|
||||||
|
std::string dir;
|
||||||
|
char msg[512];
|
||||||
|
auto getMsg = [&dir, &msg](bool b)->const char *
|
||||||
|
{
|
||||||
|
snprintf((char *)msg, 512, "%s for dir: \"%s\"", b ? "success" : "failed", dir.c_str());
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
dir = "Images";
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 2);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
dir = util->getWritablePath();
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
dir = util->getWritablePath();
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->isDirectoryExist(dir)), "", 20);
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestIsDirectoryExist::onExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
|
// reset filename lookup
|
||||||
|
sharedFileUtils->purgeCachedEntries();
|
||||||
|
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestIsDirectoryExist::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: check whether the directory exists";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestIsDirectoryExist::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// TestFileFuncs
|
// TestFileFuncs
|
||||||
|
|
||||||
void TestFileFuncs::onEnter()
|
void TestFileFuncs::onEnter()
|
||||||
|
@ -235,42 +296,42 @@ void TestFileFuncs::onEnter()
|
||||||
FileUtilsDemo::onEnter();
|
FileUtilsDemo::onEnter();
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
int x = s.width/2,
|
int x = s.width/2,
|
||||||
y = s.height/5;
|
y = s.height/5;
|
||||||
Label* label = nullptr;
|
Label* label = nullptr;
|
||||||
|
|
||||||
std::string filename = "__test.test";
|
std::string filename = "__test.test";
|
||||||
std::string filename2 = "__newtest.test";
|
std::string filename2 = "__newtest.test";
|
||||||
std::string filepath = sharedFileUtils->getWritablePath() + filename;
|
std::string filepath = sharedFileUtils->getWritablePath() + filename;
|
||||||
std::string content = "Test string content to put into created file";
|
std::string content = "Test string content to put into created file";
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
FILE *out = fopen(filepath.c_str(), "w");
|
FILE *out = fopen(filepath.c_str(), "w");
|
||||||
fputs(content.c_str(), out);
|
fputs(content.c_str(), out);
|
||||||
fclose(out);
|
fclose(out);
|
||||||
|
|
||||||
// Check whether file can be created
|
// Check whether file can be created
|
||||||
if (sharedFileUtils->isFileExist(filepath))
|
if (sharedFileUtils->isFileExist(filepath))
|
||||||
{
|
{
|
||||||
label = Label::createWithSystemFont("Test file '__test.test' created", "", 20);
|
label = Label::createWithSystemFont("Test file '__test.test' created", "", 20);
|
||||||
label->setPosition(x, y * 4);
|
label->setPosition(x, y * 4);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
|
|
||||||
// getFileSize Test
|
// getFileSize Test
|
||||||
long size = sharedFileUtils->getFileSize(filepath);
|
long size = sharedFileUtils->getFileSize(filepath);
|
||||||
msg = StringUtils::format("getFileSize: Test file size equals %ld", size);
|
msg = StringUtils::format("getFileSize: Test file size equals %ld", size);
|
||||||
label = Label::createWithSystemFont(msg, "", 20);
|
label = Label::createWithSystemFont(msg, "", 20);
|
||||||
label->setPosition(x, y * 3);
|
label->setPosition(x, y * 3);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
|
|
||||||
// renameFile Test
|
// renameFile Test
|
||||||
if (sharedFileUtils->renameFile(sharedFileUtils->getWritablePath(), filename, filename2))
|
if (sharedFileUtils->renameFile(sharedFileUtils->getWritablePath(), filename, filename2))
|
||||||
{
|
{
|
||||||
label = Label::createWithSystemFont("renameFile: Test file renamed to '__newtest.test'", "", 20);
|
label = Label::createWithSystemFont("renameFile: Test file renamed to '__newtest.test'", "", 20);
|
||||||
label->setPosition(x, y * 2);
|
label->setPosition(x, y * 2);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
|
|
||||||
// removeFile Test
|
// removeFile Test
|
||||||
filepath = sharedFileUtils->getWritablePath() + filename2;
|
filepath = sharedFileUtils->getWritablePath() + filename2;
|
||||||
if (sharedFileUtils->removeFile(filepath))
|
if (sharedFileUtils->removeFile(filepath))
|
||||||
|
@ -318,16 +379,16 @@ void TestDirectoryFuncs::onEnter()
|
||||||
FileUtilsDemo::onEnter();
|
FileUtilsDemo::onEnter();
|
||||||
auto s = Director::getInstance()->getWinSize();
|
auto s = Director::getInstance()->getWinSize();
|
||||||
auto sharedFileUtils = FileUtils::getInstance();
|
auto sharedFileUtils = FileUtils::getInstance();
|
||||||
|
|
||||||
int x = s.width/2,
|
int x = s.width/2,
|
||||||
y = s.height/4;
|
y = s.height/4;
|
||||||
Label* label = nullptr;
|
Label* label = nullptr;
|
||||||
|
|
||||||
std::string dir = sharedFileUtils->getWritablePath() + "__test/";
|
std::string dir = sharedFileUtils->getWritablePath() + "__test/";
|
||||||
std::string subDir = "dir1/dir2";
|
std::string subDir = "dir1/dir2";
|
||||||
std::string msg;
|
std::string msg;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
// Check whether dir can be created
|
// Check whether dir can be created
|
||||||
ok = sharedFileUtils->createDirectory(dir);
|
ok = sharedFileUtils->createDirectory(dir);
|
||||||
if (ok && sharedFileUtils->isDirectoryExist(dir))
|
if (ok && sharedFileUtils->isDirectoryExist(dir))
|
||||||
|
@ -336,7 +397,7 @@ void TestDirectoryFuncs::onEnter()
|
||||||
label = Label::createWithSystemFont(msg, "", 20);
|
label = Label::createWithSystemFont(msg, "", 20);
|
||||||
label->setPosition(x, y * 3);
|
label->setPosition(x, y * 3);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
|
|
||||||
// Create sub directories recursively
|
// Create sub directories recursively
|
||||||
ok = sharedFileUtils->createDirectory(dir + subDir);
|
ok = sharedFileUtils->createDirectory(dir + subDir);
|
||||||
if (ok && sharedFileUtils->isDirectoryExist(dir + subDir))
|
if (ok && sharedFileUtils->isDirectoryExist(dir + subDir))
|
||||||
|
@ -353,7 +414,7 @@ void TestDirectoryFuncs::onEnter()
|
||||||
label->setPosition(x, y * 2);
|
label->setPosition(x, y * 2);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove directory
|
// Remove directory
|
||||||
ok = sharedFileUtils->removeDirectory(dir);
|
ok = sharedFileUtils->removeDirectory(dir);
|
||||||
if (ok && !sharedFileUtils->isDirectoryExist(dir))
|
if (ok && !sharedFileUtils->isDirectoryExist(dir))
|
||||||
|
@ -390,7 +451,7 @@ std::string TestDirectoryFuncs::subtitle() const
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestWritePlist
|
// TextWritePlist
|
||||||
|
|
||||||
void TextWritePlist::onEnter()
|
void TextWritePlist::onEnter()
|
||||||
{
|
{
|
||||||
|
@ -398,46 +459,46 @@ void TextWritePlist::onEnter()
|
||||||
auto root = Dictionary::create();
|
auto root = Dictionary::create();
|
||||||
auto string = String::create("string element value");
|
auto string = String::create("string element value");
|
||||||
root->setObject(string, "string element key");
|
root->setObject(string, "string element key");
|
||||||
|
|
||||||
auto array = Array::create();
|
auto array = Array::create();
|
||||||
|
|
||||||
auto dictInArray = Dictionary::create();
|
auto dictInArray = Dictionary::create();
|
||||||
dictInArray->setObject(String::create("string in dictInArray value 0"), "string in dictInArray key 0");
|
dictInArray->setObject(String::create("string in dictInArray value 0"), "string in dictInArray key 0");
|
||||||
dictInArray->setObject(String::create("string in dictInArray value 1"), "string in dictInArray key 1");
|
dictInArray->setObject(String::create("string in dictInArray value 1"), "string in dictInArray key 1");
|
||||||
array->addObject(dictInArray);
|
array->addObject(dictInArray);
|
||||||
|
|
||||||
array->addObject(String::create("string in array"));
|
array->addObject(String::create("string in array"));
|
||||||
|
|
||||||
auto arrayInArray = Array::create();
|
auto arrayInArray = Array::create();
|
||||||
arrayInArray->addObject(String::create("string 0 in arrayInArray"));
|
arrayInArray->addObject(String::create("string 0 in arrayInArray"));
|
||||||
arrayInArray->addObject(String::create("string 1 in arrayInArray"));
|
arrayInArray->addObject(String::create("string 1 in arrayInArray"));
|
||||||
array->addObject(arrayInArray);
|
array->addObject(arrayInArray);
|
||||||
|
|
||||||
root->setObject(array, "array");
|
root->setObject(array, "array");
|
||||||
|
|
||||||
auto dictInDict = Dictionary::create();
|
auto dictInDict = Dictionary::create();
|
||||||
dictInDict->setObject(String::create("string in dictInDict value"), "string in dictInDict key");
|
dictInDict->setObject(String::create("string in dictInDict value"), "string in dictInDict key");
|
||||||
|
|
||||||
//add boolean to the plist
|
//add boolean to the plist
|
||||||
auto booleanObject = Bool::create(true);
|
auto booleanObject = Bool::create(true);
|
||||||
dictInDict->setObject(booleanObject, "bool");
|
dictInDict->setObject(booleanObject, "bool");
|
||||||
|
|
||||||
//add interger to the plist
|
//add interger to the plist
|
||||||
auto intObject = Integer::create(1024);
|
auto intObject = Integer::create(1024);
|
||||||
dictInDict->setObject(intObject, "integer");
|
dictInDict->setObject(intObject, "integer");
|
||||||
|
|
||||||
//add float to the plist
|
//add float to the plist
|
||||||
auto floatObject = Float::create(1024.1024f);
|
auto floatObject = Float::create(1024.1024f);
|
||||||
dictInDict->setObject(floatObject, "float");
|
dictInDict->setObject(floatObject, "float");
|
||||||
|
|
||||||
//add double to the plist
|
//add double to the plist
|
||||||
auto doubleObject = Double::create(1024.123);
|
auto doubleObject = Double::create(1024.123);
|
||||||
dictInDict->setObject(doubleObject, "double");
|
dictInDict->setObject(doubleObject, "double");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
root->setObject(dictInDict, "dictInDict, Hello World");
|
root->setObject(dictInDict, "dictInDict, Hello World");
|
||||||
|
|
||||||
// end with /
|
// end with /
|
||||||
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
||||||
std::string fullPath = writablePath + "text.plist";
|
std::string fullPath = writablePath + "text.plist";
|
||||||
|
@ -445,12 +506,12 @@ void TextWritePlist::onEnter()
|
||||||
log("see the plist file at %s", fullPath.c_str());
|
log("see the plist file at %s", fullPath.c_str());
|
||||||
else
|
else
|
||||||
log("write plist file failed");
|
log("write plist file failed");
|
||||||
|
|
||||||
auto label = Label::createWithTTF(fullPath.c_str(), "fonts/Thonburi.ttf", 6);
|
auto label = Label::createWithTTF(fullPath.c_str(), "fonts/Thonburi.ttf", 6);
|
||||||
this->addChild(label);
|
this->addChild(label);
|
||||||
auto winSize = Director::getInstance()->getWinSize();
|
auto winSize = Director::getInstance()->getWinSize();
|
||||||
label->setPosition(winSize.width/2, winSize.height/3);
|
label->setPosition(winSize.width/2, winSize.height/3);
|
||||||
|
|
||||||
auto loadDict = __Dictionary::createWithContentsOfFile(fullPath.c_str());
|
auto loadDict = __Dictionary::createWithContentsOfFile(fullPath.c_str());
|
||||||
auto loadDictInDict = (__Dictionary*)loadDict->objectForKey("dictInDict, Hello World");
|
auto loadDictInDict = (__Dictionary*)loadDict->objectForKey("dictInDict, Hello World");
|
||||||
auto boolValue = (__String*)loadDictInDict->objectForKey("bool");
|
auto boolValue = (__String*)loadDictInDict->objectForKey("bool");
|
||||||
|
@ -479,3 +540,419 @@ std::string TextWritePlist::subtitle() const
|
||||||
std::string writablePath = FileUtils::getInstance()->getWritablePath().c_str();
|
std::string writablePath = FileUtils::getInstance()->getWritablePath().c_str();
|
||||||
return ("See plist file at your writablePath");
|
return ("See plist file at your writablePath");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestWriteString::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
|
||||||
|
auto winSize = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
auto writeResult = Label::createWithTTF("show writeResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(writeResult);
|
||||||
|
writeResult->setPosition(winSize.width / 2, winSize.height * 3 / 4);
|
||||||
|
|
||||||
|
auto readResult = Label::createWithTTF("show readResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(readResult);
|
||||||
|
readResult->setPosition(winSize.width / 2, winSize.height / 3);
|
||||||
|
|
||||||
|
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
||||||
|
std::string fileName = "writeStringTest.txt";
|
||||||
|
|
||||||
|
// writeTest
|
||||||
|
std::string writeDataStr = "the string data will be write into a file";
|
||||||
|
std::string fullPath = writablePath + fileName;
|
||||||
|
if (FileUtils::getInstance()->writeStringToFile(writeDataStr, fullPath.c_str()))
|
||||||
|
{
|
||||||
|
log("see the plist file at %s", fullPath.c_str());
|
||||||
|
writeResult->setString("write success:" + writeDataStr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("write plist file failed");
|
||||||
|
writeResult->setString("write fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
// readTest
|
||||||
|
std::string readDataStr = FileUtils::getInstance()->getStringFromFile(fullPath);
|
||||||
|
readResult->setString("read success:" + readDataStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteString::onExit()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteString::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: TestWriteString to files";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteString::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteData::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
|
||||||
|
auto winSize = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
auto writeResult = Label::createWithTTF("show writeResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(writeResult);
|
||||||
|
writeResult->setPosition(winSize.width / 2, winSize.height * 3 / 4);
|
||||||
|
|
||||||
|
auto readResult = Label::createWithTTF("show readResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(readResult);
|
||||||
|
readResult->setPosition(winSize.width / 2, winSize.height / 3);
|
||||||
|
|
||||||
|
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
||||||
|
std::string fileName = "writeDataTest.txt";
|
||||||
|
|
||||||
|
// writeTest
|
||||||
|
std::string writeDataStr = "the binary data will be write into a file";
|
||||||
|
Data writeData;
|
||||||
|
writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
|
||||||
|
std::string fullPath = writablePath + fileName;
|
||||||
|
if (FileUtils::getInstance()->writeDataToFile(writeData, fullPath.c_str()))
|
||||||
|
{
|
||||||
|
log("see the plist file at %s", fullPath.c_str());
|
||||||
|
writeResult->setString("write success:" + writeDataStr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("write plist file failed");
|
||||||
|
writeResult->setString("write fail");
|
||||||
|
}
|
||||||
|
|
||||||
|
// readTest
|
||||||
|
unsigned char* buffer = nullptr;
|
||||||
|
Data readData = FileUtils::getInstance()->getDataFromFile(fullPath);
|
||||||
|
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (readData.getSize() + 1));
|
||||||
|
memcpy(buffer, readData.getBytes(), readData.getSize());
|
||||||
|
buffer[readData.getSize()] = '\0';
|
||||||
|
std::string readDataStr((const char*)buffer);
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
readResult->setString("read success:" + readDataStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteData::onExit()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteData::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: TestWriteData to files";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteData::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteValueMap::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
|
||||||
|
auto winSize = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
auto writeResult = Label::createWithTTF("show writeResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(writeResult);
|
||||||
|
writeResult->setPosition(winSize.width / 2, winSize.height * 3 / 4);
|
||||||
|
|
||||||
|
auto readResult = Label::createWithTTF("show readResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(readResult);
|
||||||
|
readResult->setPosition(winSize.width / 2, winSize.height / 3);
|
||||||
|
|
||||||
|
ValueMap valueMap;
|
||||||
|
|
||||||
|
ValueMap mapInValueMap;
|
||||||
|
mapInValueMap["string1"] = "string in dictInMap key 0";
|
||||||
|
mapInValueMap["string2"] = "string in dictInMap key 1";
|
||||||
|
valueMap["data0"] = Value(mapInValueMap);
|
||||||
|
|
||||||
|
valueMap["data1"] = Value("string in array");
|
||||||
|
|
||||||
|
ValueVector arrayInMap;
|
||||||
|
arrayInMap.push_back(Value("string 0 in arrayInMap"));
|
||||||
|
arrayInMap.push_back(Value("string 1 in arrayInMap"));
|
||||||
|
valueMap["data2"] = arrayInMap;
|
||||||
|
|
||||||
|
//add boolean to the plist
|
||||||
|
auto booleanObject = Value(true);
|
||||||
|
valueMap["data3"] = booleanObject;
|
||||||
|
|
||||||
|
//add interger to the plist
|
||||||
|
auto intObject = Value(1024);
|
||||||
|
valueMap["data4"] = intObject;
|
||||||
|
|
||||||
|
//add float to the plist
|
||||||
|
auto floatObject = Value(1024.1024f);
|
||||||
|
valueMap["data5"] = floatObject;
|
||||||
|
|
||||||
|
//add double to the plist
|
||||||
|
auto doubleObject = Value(1024.123);
|
||||||
|
valueMap["data6"] = doubleObject;
|
||||||
|
|
||||||
|
|
||||||
|
// end with /
|
||||||
|
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
||||||
|
std::string fullPath = writablePath + "testWriteValueMap.plist";
|
||||||
|
if (FileUtils::getInstance()->writeValueMapToFile(valueMap, fullPath.c_str()))
|
||||||
|
{
|
||||||
|
log("see the plist file at %s", fullPath.c_str());
|
||||||
|
writeResult->setString("write success");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("write plist file failed");
|
||||||
|
writeResult->setString("write failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueMap readValueMap = FileUtils::getInstance()->getValueMapFromFile(fullPath.c_str());
|
||||||
|
std::string readDataStr = "read data:\n";
|
||||||
|
// read value map data
|
||||||
|
ValueMap readMapInMap = readValueMap["data0"].asValueMap();
|
||||||
|
readDataStr += " mapValue:[\"string1\"][" + readMapInMap["string1"].asString() + "]\n";
|
||||||
|
readDataStr += " mapValue:[\"string2\"][" + readMapInMap["string2"].asString() + "]\n";
|
||||||
|
|
||||||
|
// read string data
|
||||||
|
readDataStr += " stringValue:" + readValueMap["data1"].asString() + "\n";
|
||||||
|
|
||||||
|
// read value vector data
|
||||||
|
ValueVector readVectorInMap = readValueMap["data2"].asValueVector();
|
||||||
|
readDataStr += " vectorValue:[1]" + readVectorInMap.at(0).asString() + "\n";
|
||||||
|
readDataStr += " vectorValue:[2]" + readVectorInMap.at(1).asString() + "\n";
|
||||||
|
|
||||||
|
// read bool data
|
||||||
|
readDataStr += " boolValue:" + StringUtils::format("%d", readValueMap["data3"].asBool()) + "\n";
|
||||||
|
|
||||||
|
// read int data
|
||||||
|
readDataStr += " intValue:" + StringUtils::format("%d", readValueMap["data4"].asInt()) + "\n";
|
||||||
|
|
||||||
|
// read float data
|
||||||
|
readDataStr += " floatValue:" + StringUtils::format("%f", readValueMap["data5"].asFloat()) + "\n";
|
||||||
|
|
||||||
|
// read double data
|
||||||
|
readDataStr += " doubleValue:" + StringUtils::format("%f", readValueMap["data6"].asDouble()) + "\n";
|
||||||
|
|
||||||
|
readResult->setString(readDataStr);
|
||||||
|
}
|
||||||
|
void TestWriteValueMap::onExit()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteValueMap::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: TestWriteValueMap to files";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteValueMap::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteValueVector::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
|
||||||
|
auto winSize = Director::getInstance()->getWinSize();
|
||||||
|
|
||||||
|
auto writeResult = Label::createWithTTF("show writeResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(writeResult);
|
||||||
|
writeResult->setPosition(winSize.width / 2, winSize.height * 3 / 4);
|
||||||
|
|
||||||
|
auto readResult = Label::createWithTTF("show readResult", "fonts/Thonburi.ttf", 18);
|
||||||
|
this->addChild(readResult);
|
||||||
|
readResult->setPosition(winSize.width / 2, winSize.height / 3);
|
||||||
|
|
||||||
|
ValueVector array;
|
||||||
|
|
||||||
|
ValueMap mapInArray;
|
||||||
|
mapInArray["string1"] = "string in dictInArray key 0";
|
||||||
|
mapInArray["string2"] = "string in dictInArray key 1";
|
||||||
|
array.push_back(Value(mapInArray));
|
||||||
|
|
||||||
|
array.push_back(Value("string in array"));
|
||||||
|
|
||||||
|
ValueVector arrayInArray;
|
||||||
|
arrayInArray.push_back(Value("string 0 in arrayInArray"));
|
||||||
|
arrayInArray.push_back(Value("string 1 in arrayInArray"));
|
||||||
|
array.push_back(Value(arrayInArray));
|
||||||
|
|
||||||
|
//add boolean to the plist
|
||||||
|
auto booleanObject = Value(true);
|
||||||
|
array.push_back(booleanObject);
|
||||||
|
|
||||||
|
//add interger to the plist
|
||||||
|
auto intObject = Value(1024);
|
||||||
|
array.push_back(intObject);
|
||||||
|
|
||||||
|
//add float to the plist
|
||||||
|
auto floatObject = Value(1024.1024f);
|
||||||
|
array.push_back(floatObject);
|
||||||
|
|
||||||
|
//add double to the plist
|
||||||
|
auto doubleObject = Value(1024.123);
|
||||||
|
array.push_back(doubleObject);
|
||||||
|
|
||||||
|
|
||||||
|
// end with /
|
||||||
|
std::string writablePath = FileUtils::getInstance()->getWritablePath();
|
||||||
|
std::string fullPath = writablePath + "testWriteValueVector.plist";
|
||||||
|
if (FileUtils::getInstance()->writeValueVectorToFile(array, fullPath.c_str()))
|
||||||
|
{
|
||||||
|
log("see the plist file at %s", fullPath.c_str());
|
||||||
|
writeResult->setString("write success");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("write plist file failed");
|
||||||
|
writeResult->setString("write failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueVector readArray = FileUtils::getInstance()->getValueVectorFromFile(fullPath.c_str());
|
||||||
|
std::string readDataStr = "read data:\n";
|
||||||
|
// read value map data
|
||||||
|
ValueMap readMapInArray = readArray.at(0).asValueMap();
|
||||||
|
readDataStr += " mapValue:[\"string1\"][" + readMapInArray["string1"].asString() + "]\n";
|
||||||
|
readDataStr += " mapValue:[\"string2\"][" + readMapInArray["string2"].asString() + "]\n";
|
||||||
|
|
||||||
|
// read string data
|
||||||
|
readDataStr += " stringValue:" + readArray.at(1).asString() + "\n";
|
||||||
|
|
||||||
|
// read value vector data
|
||||||
|
ValueVector readVectorInArray = readArray.at(2).asValueVector();
|
||||||
|
readDataStr += " vectorValue:[1]" + readVectorInArray.at(0).asString() + "\n";
|
||||||
|
readDataStr += " vectorValue:[2]" + readVectorInArray.at(1).asString() + "\n";
|
||||||
|
|
||||||
|
// read bool data
|
||||||
|
readDataStr += " boolValue:" + StringUtils::format("%d", readArray.at(3).asBool()) + "\n";
|
||||||
|
|
||||||
|
// read int data
|
||||||
|
readDataStr += " intValue:" + StringUtils::format("%d", readArray.at(4).asInt()) + "\n";
|
||||||
|
|
||||||
|
// read float data
|
||||||
|
readDataStr += " floatValue:" + StringUtils::format("%f", readArray.at(5).asFloat()) + "\n";
|
||||||
|
|
||||||
|
// read double data
|
||||||
|
readDataStr += " doubleValue:" + StringUtils::format("%f", readArray.at(6).asDouble()) + "\n";
|
||||||
|
|
||||||
|
readResult->setString(readDataStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestWriteValueVector::onExit()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteValueVector::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: TestWriteValueVector to files";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestWriteValueVector::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestUnicodePath
|
||||||
|
|
||||||
|
void TestUnicodePath::onEnter()
|
||||||
|
{
|
||||||
|
FileUtilsDemo::onEnter();
|
||||||
|
auto s = Director::getInstance()->getWinSize();
|
||||||
|
auto util = FileUtils::getInstance();
|
||||||
|
|
||||||
|
int x = s.width/2,
|
||||||
|
y = s.height/5;
|
||||||
|
Label* label = nullptr;
|
||||||
|
|
||||||
|
std::string dir = "中文路径/";
|
||||||
|
std::string filename = "测试文件.test";
|
||||||
|
|
||||||
|
std::string act;
|
||||||
|
char msg[512];
|
||||||
|
auto getMsg = [&act, &msg](bool b, const std::string& path)->const char *
|
||||||
|
{
|
||||||
|
snprintf((char *)msg, 512, "%s for %s path: \"%s\"", b ? "success" : "failed", act.c_str(), path.c_str());
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check whether unicode dir should be create or not
|
||||||
|
std::string dirPath = util->getWritablePath() + dir;
|
||||||
|
if (!util->isDirectoryExist(dirPath))
|
||||||
|
{
|
||||||
|
util->createDirectory(dirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
act = "create";
|
||||||
|
bool isExist = util->isDirectoryExist(dirPath);
|
||||||
|
label = Label::createWithSystemFont(getMsg(isExist, dirPath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 4);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
if (isExist)
|
||||||
|
{
|
||||||
|
// Check whether unicode file should be create or not
|
||||||
|
std::string filePath = dirPath + filename;
|
||||||
|
if (! util->isFileExist(filePath))
|
||||||
|
{
|
||||||
|
std::string writeDataStr = " 测试字符串.";
|
||||||
|
Data writeData;
|
||||||
|
writeData.copy((unsigned char *)writeDataStr.c_str(), writeDataStr.size());
|
||||||
|
util->writeDataToFile(writeData, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
isExist = util->isFileExist(filePath);
|
||||||
|
label = Label::createWithSystemFont(getMsg(isExist, filePath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 3);
|
||||||
|
this->addChild(label);
|
||||||
|
|
||||||
|
act = "remove";
|
||||||
|
if (isExist)
|
||||||
|
{
|
||||||
|
// read file content and log it
|
||||||
|
unsigned char* buffer = nullptr;
|
||||||
|
Data readData = util->getDataFromFile(filePath);
|
||||||
|
buffer = (unsigned char*)malloc(sizeof(unsigned char) * (readData.getSize() + 1));
|
||||||
|
memcpy(buffer, readData.getBytes(), readData.getSize());
|
||||||
|
buffer[readData.getSize()] = '\0';
|
||||||
|
// vc can't treat unicode string correctly, don't use unicode string in code
|
||||||
|
log("The content of file from writable path: %s", buffer);
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
// remove test file
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->removeFile(filePath), filePath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 2);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove test dir
|
||||||
|
label = Label::createWithSystemFont(getMsg(util->removeDirectory(dirPath), dirPath), "", 12, Size(s.width, 0));
|
||||||
|
label->setPosition(x, y * 1);
|
||||||
|
this->addChild(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestUnicodePath::onExit()
|
||||||
|
{
|
||||||
|
|
||||||
|
FileUtils *sharedFileUtils = FileUtils::getInstance();
|
||||||
|
sharedFileUtils->purgeCachedEntries();
|
||||||
|
sharedFileUtils->setFilenameLookupDictionary(ValueMap());
|
||||||
|
FileUtilsDemo::onExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestUnicodePath::title() const
|
||||||
|
{
|
||||||
|
return "FileUtils: check unicode path";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TestUnicodePath::subtitle() const
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue