Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3luaruntime

This commit is contained in:
chuanweizhang2013 2014-07-03 11:13:59 +08:00
commit b88b5e4c3d
116 changed files with 2804 additions and 2117 deletions

View File

@ -1,4 +1,4 @@
cocos2d-x-3.2 ???
cocos2d-x-3.2beta0 Jul.2 2014
[NEW] FastTMXTiledMap: added fast tmx, which is much more faster for static tiled map
[NEW] GLProgramState: can use uniform location to get/set uniform values
[NEW] HttpClient: added sendImmediate()
@ -32,6 +32,7 @@ cocos2d-x-3.2 ???
[FIX] UIListView: element position is changed a little when you click and up a list view without move
[FIX] UIListView: element will respond to item_end event when end of scrolling a list view
[FIX] UIVideo: crash when try to remove videoView(STATE_PLAYBACK_COMPLETED) on android
[FIX] WP8: crash of utils::captureScreen()
cocos2d-x-3.2-alpha0 Jun.17 2014
[NEW] Console: add a command to show engine version

View File

@ -1042,12 +1042,6 @@
3E6176781960F89B00DE83F5 /* CCGameController.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176651960F89B00DE83F5 /* CCGameController.h */; };
3E6176791960F89B00DE83F5 /* CCGamepad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176661960F89B00DE83F5 /* CCGamepad.cpp */; };
3E61767A1960F89B00DE83F5 /* CCGamepad.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176671960F89B00DE83F5 /* CCGamepad.h */; };
3E6176831960F9C400DE83F5 /* CCNSLog.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61767C1960F9C400DE83F5 /* CCNSLog.h */; };
3E6176841960F9C400DE83F5 /* CCNSLog.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E61767E1960F9C400DE83F5 /* CCNSLog.mm */; };
3E6176851960F9C400DE83F5 /* LoggerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E61767F1960F9C400DE83F5 /* LoggerClient.h */; };
3E6176861960F9C400DE83F5 /* LoggerClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E6176801960F9C400DE83F5 /* LoggerClient.m */; };
3E6176871960F9C400DE83F5 /* LoggerCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176811960F9C400DE83F5 /* LoggerCommon.h */; };
3E6176881960F9C400DE83F5 /* NSLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = 3E6176821960F9C400DE83F5 /* NSLogger.h */; };
3EA0FB6B191C841D00B170C8 /* UIVideoPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */; };
3EA0FB6C191C841D00B170C8 /* UIVideoPlayerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */; };
3EA47870195478E00068D9D1 /* CCBundleReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */; };
@ -2393,12 +2387,6 @@
3E6176651960F89B00DE83F5 /* CCGameController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGameController.h; path = ../base/CCGameController.h; sourceTree = "<group>"; };
3E6176661960F89B00DE83F5 /* CCGamepad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCGamepad.cpp; path = ../base/CCGamepad.cpp; sourceTree = "<group>"; };
3E6176671960F89B00DE83F5 /* CCGamepad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGamepad.h; path = ../base/CCGamepad.h; sourceTree = "<group>"; };
3E61767C1960F9C400DE83F5 /* CCNSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNSLog.h; sourceTree = "<group>"; };
3E61767E1960F9C400DE83F5 /* CCNSLog.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CCNSLog.mm; sourceTree = "<group>"; };
3E61767F1960F9C400DE83F5 /* LoggerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggerClient.h; sourceTree = "<group>"; };
3E6176801960F9C400DE83F5 /* LoggerClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoggerClient.m; sourceTree = "<group>"; };
3E6176811960F9C400DE83F5 /* LoggerCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoggerCommon.h; sourceTree = "<group>"; };
3E6176821960F9C400DE83F5 /* NSLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSLogger.h; sourceTree = "<group>"; };
3EA0FB69191C841D00B170C8 /* UIVideoPlayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIVideoPlayer.h; sourceTree = "<group>"; };
3EA0FB6A191C841D00B170C8 /* UIVideoPlayerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UIVideoPlayerIOS.mm; sourceTree = "<group>"; };
3EA4786E195478E00068D9D1 /* CCBundleReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBundleReader.cpp; sourceTree = "<group>"; };
@ -3505,7 +3493,6 @@
1A57033E180BD0490088DEC7 /* external */ = {
isa = PBXGroup;
children = (
3E61767B1960F9C400DE83F5 /* nslog */,
1AC026971914068200FA920D /* ConvertUTF */,
46C02E0418E91123004B7456 /* xxhash */,
46A168B21807AF9C005B8026 /* Box2D */,
@ -4189,28 +4176,6 @@
path = internal;
sourceTree = "<group>";
};
3E61767B1960F9C400DE83F5 /* nslog */ = {
isa = PBXGroup;
children = (
3E61767C1960F9C400DE83F5 /* CCNSLog.h */,
3E61767D1960F9C400DE83F5 /* ios */,
);
name = nslog;
path = ../external/nslog;
sourceTree = "<group>";
};
3E61767D1960F9C400DE83F5 /* ios */ = {
isa = PBXGroup;
children = (
3E61767E1960F9C400DE83F5 /* CCNSLog.mm */,
3E61767F1960F9C400DE83F5 /* LoggerClient.h */,
3E6176801960F9C400DE83F5 /* LoggerClient.m */,
3E6176811960F9C400DE83F5 /* LoggerCommon.h */,
3E6176821960F9C400DE83F5 /* NSLogger.h */,
);
path = ios;
sourceTree = "<group>";
};
46A15FD01807A56F005B8026 /* audio */ = {
isa = PBXGroup;
children = (
@ -5663,7 +5628,6 @@
50ABBD411925AB0000A911A9 /* CCMath.h in Headers */,
1A5701A0180BCB590088DEC7 /* CCFont.h in Headers */,
50ABBD9A1925AB4100A911A9 /* CCGLProgramStateCache.h in Headers */,
3E6176881960F9C400DE83F5 /* NSLogger.h in Headers */,
50ABBD3F1925AB0000A911A9 /* CCGeometry.h in Headers */,
50ABBFFE1926664800A911A9 /* CCFileUtilsApple.h in Headers */,
1A5701A4180BCB590088DEC7 /* CCFontAtlas.h in Headers */,
@ -5744,7 +5708,6 @@
1A570303180BCE890088DEC7 /* CCParallaxNode.h in Headers */,
50ABBE2A1925AB6F00A911A9 /* CCAutoreleasePool.h in Headers */,
1A57030F180BCF190088DEC7 /* CCComponent.h in Headers */,
3E6176851960F9C400DE83F5 /* LoggerClient.h in Headers */,
3E61766F1960F89B00DE83F5 /* CCControllerDirectionPad.h in Headers */,
1A570313180BCF190088DEC7 /* CCComponentContainer.h in Headers */,
0634A4DF194B19E400E608AF /* CCNodeReader.h in Headers */,
@ -5759,7 +5722,6 @@
50ABBD4B1925AB0000A911A9 /* Mat4.h in Headers */,
1A01C69B18F57BE800EFE3A6 /* CCSet.h in Headers */,
50ABBED61925AB6F00A911A9 /* utlist.h in Headers */,
3E6176871960F9C400DE83F5 /* LoggerCommon.h in Headers */,
1A57035B180BD0B00088DEC7 /* unzip.h in Headers */,
5034CA48191D591100CE6051 /* ccShader_Label_normal.frag in Headers */,
50ABBD531925AB0000A911A9 /* Quaternion.h in Headers */,
@ -5789,7 +5751,6 @@
50E6D33B18E174130051CA34 /* UIRelativeBox.h in Headers */,
503DD8EB1926736A00CD74DD /* CCGL.h in Headers */,
50ABBE3C1925AB6F00A911A9 /* CCData.h in Headers */,
3E6176831960F9C400DE83F5 /* CCNSLog.h in Headers */,
1AD71DD8180E26E600808F54 /* CCLabelTTFLoader.h in Headers */,
503DD8FA1926B0DB00CD74DD /* CCIMEDispatcher.h in Headers */,
1AD71DDC180E26E600808F54 /* CCLayerColorLoader.h in Headers */,
@ -6757,7 +6718,6 @@
2AC795E318628746005EC8E1 /* SkeletonBounds.cpp in Sources */,
2AC795E418628746005EC8E1 /* Event.cpp in Sources */,
2AC795E518628746005EC8E1 /* EventData.cpp in Sources */,
3E6176861960F9C400DE83F5 /* LoggerClient.m in Sources */,
2AC795E618628746005EC8E1 /* BoundingBoxAttachment.cpp in Sources */,
46A171001807CECB005B8026 /* CCPhysicsJoint.cpp in Sources */,
46A171051807CECB005B8026 /* CCPhysicsWorld.cpp in Sources */,
@ -6842,7 +6802,6 @@
2905FA4B18CF08D100240AA3 /* UICheckBox.cpp in Sources */,
1A5701BE180BCB5A0088DEC7 /* CCLabelAtlas.cpp in Sources */,
1A5701C2180BCB5A0088DEC7 /* CCLabelBMFont.cpp in Sources */,
3E6176841960F9C400DE83F5 /* CCNSLog.mm in Sources */,
1A087AE91860400400196EF5 /* edtaa3func.cpp in Sources */,
B375107E1823ACA100B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */,
1A5701C8180BCB5A0088DEC7 /* CCLabelTextFormatter.cpp in Sources */,

View File

@ -180,7 +180,7 @@ void FastTMXLayer::onDraw(int offset, int count)
GL::bindTexture2D(_texture->getName());
getGLProgramState()->apply(_modelViewTransform);
glBindVertexArray(0);
GL::bindVAO(0);
glBindBuffer(GL_ARRAY_BUFFER, _buffersVBO[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _buffersVBO[1]);

View File

@ -861,24 +861,25 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
}
}
// TODO: support ends with '/..'
// End with '/..'?
bool searchFromParent = false;
if (length > 3 &&
name[length-3] == '/' &&
name[length-2] == '.' &&
name[length-1] == '.')
{
searchFromParent = true;
subStrlength -= 3;
}
// bool searchFromParent = false;
// if (length > 3 &&
// name[length-3] == '/' &&
// name[length-2] == '.' &&
// name[length-1] == '.')
// {
// searchFromParent = true;
// subStrlength -= 3;
// }
// Remove '/', '//' and '/..' if exist
// Remove '/', '//' if exist
std::string newName = name.substr(subStrStartPos, subStrlength);
// If search from parent, then add * at first to make it match its children, which will do make
if (searchFromParent)
{
newName.insert(0, "[[:alnum:]]+/");
}
// if (searchFromParent)
// {
// newName.insert(0, "[[:alnum:]]+/");
// }
if (searchFromRoot)
{
@ -943,10 +944,14 @@ bool Node::doEnumerate(std::string name, std::function<bool (Node *)> callback)
needRecursive = true;
}
std::hash<std::string> h;
size_t hashOfName = h(searchName);
bool ret = false;
for (const auto& child : _children)
{
if(std::regex_match(child->_name, std::regex(searchName)))
// TODO: regular expression support
// Android doesn't support c++ 11 regular expression well, may use external lib
if (hashOfName == child->_hashOfName && searchName.compare(child->_name) == 0)
{
if (!needRecursive)
{

View File

@ -714,20 +714,17 @@ public:
virtual Node* getChildByName(const std::string& name) const;
/** Search the children of the receiving node to perform processing for nodes which share a name.
*
* @param name The name to search for, support c++11 regular expression
* @param name The name to search for
* Search syntax options:
* `/` : When placed at the start of the search string, this indicates that the search should be performed on the tree's node.
* `//`: Can only be placed at the begin of the search string. This indicates that the search should be performed on the tree's node
* and be performed recursively across the entire node tree.
* `..`: The search should move up to the node's parent. Can only be placed at the end of string
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children
*
* @code
* enumerateChildren("/MyName", ...): This searches the root's children and matches any node with the name `MyName`.
* enumerateChildren("//MyName", ...): This searches the root's children recursively and matches any node with the name `MyName`.
* enumerateChildren("[[:alnum:]]+", ...): This search string matches every node of its children.
* enumerateChildren("/MyName", ...): This searches the node tree and matches the parent node of every node named `MyName`.
* enumerateChildren("A[[:digit:]]", ...): This searches the node's children and returns any child named `A0`, `A1`, ..., `A9`
* enumerateChildren("Abby/Normal", ...): This searches the node's grandchildren and returns any node whose name is `Normal`
* and whose parent is named `Abby`.
* enumerateChildren("//Abby/Normal", ...): This searches the node tree and returns any node whose name is `Normal` and whose

View File

@ -121,8 +121,7 @@ public:
void sendEventButton(ControllerButtonInput* button, bool isPressed, float value, bool isAnalog)
{
button->setPressed(isPressed);
if (!isAnalog)
button->setValue(value);
button->setValue(value);
button->setAnalog(isAnalog);
EventController evt(EventController::ControllerEventType::BUTTON_STATUS_CHANGED, _controller, button);
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);

View File

@ -41,8 +41,6 @@
#import <GameController/GameController.h>
#include "CCNSLog.h"
@interface GCControllerConnectionEventHandler : NSObject
typedef void (^GCControllerConnectionBlock)(GCController* controller);
@ -153,8 +151,6 @@ const std::vector<Controller*>& Controller::getControllers()
void Controller::startDiscoveryController()
{
CCNSLOG("startDiscoveryController...: %s", "hello");
[GCController startWirelessControllerDiscoveryWithCompletionHandler: nil];
[[GCControllerConnectionEventHandler getInstance] observerConnection: ^(GCController* gcController) {
@ -163,7 +159,6 @@ void Controller::startDiscoveryController()
gcController.controllerPausedHandler = ^(GCController* gcCon){
CCNSLOG("Controller(%p)'s paused handler was invoked.", gcCon);
auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcCon](Controller* c){ return c->_impl->_gcController == gcCon; });
CCASSERT(iter != _controllers.end(), "Could not find the controller");
@ -177,7 +172,6 @@ void Controller::startDiscoveryController()
button->setPressed(false);
};
CCNSLOG("controller %p was connnected!", gcController);
_controllers.push_back(controller);
@ -185,7 +179,6 @@ void Controller::startDiscoveryController()
Director::getInstance()->getEventDispatcher()->dispatchEvent(&evt);
} disconnection: ^(GCController* gcController) {
CCNSLOG("controller %p was disconnected!", gcController);
auto iter = std::find_if(_controllers.begin(), _controllers.end(), [gcController](Controller* c){ return c->_impl->_gcController == gcController; });
@ -256,22 +249,18 @@ Gamepad* Controller::getGamepad() const
if (_impl->_gcController.extendedGamepad != nil)
{
_impl->_gcController.extendedGamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad up %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.extendedGamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad down %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.extendedGamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad left %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.extendedGamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad right %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getRight(), button);
};
@ -329,22 +318,18 @@ Gamepad* Controller::getGamepad() const
else
{
_impl->_gcController.gamepad.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad up %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getUp(), button);
};
_impl->_gcController.gamepad.dpad.down.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad down %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getDown(), button);
};
_impl->_gcController.gamepad.dpad.left.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad left %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getLeft(), button);
};
_impl->_gcController.gamepad.dpad.right.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed){
CCNSLOG("dpad right %d, %f", button.pressed, button.value);
sendEventButton(_gamepad->getDirectionPad()->getRight(), button);
};

View File

@ -23,7 +23,7 @@
THE SOFTWARE.
****************************************************************************/
#include "CCControllerThumbStick.h"
#include "CCControllerThumbstick.h"
#include "CCControllerAxisInput.h"
#include "CCControllerButtonInput.h"

View File

@ -28,7 +28,6 @@
#include "CCControllerButtonInput.h"
#include "CCControllerAxisInput.h"
#include "ccMacros.h"
#include "CCNSLog.h"
NS_CC_BEGIN
@ -72,7 +71,6 @@ bool EventListenerController::init()
{
auto button = static_cast<ControllerButtonInput*>(evtController->getControllerElement());
CCNSLOG("button event: %d, %d, %f", button->isPressed(), button->isPrevStatusPressed(), button->getValue());
if (this->onButtonPressed && button->isPressed() && !button->isPrevStatusPressed())
{
this->onButtonPressed(evtController->getController(), button, event);

View File

@ -72,19 +72,50 @@ void onCaptureScreen(const std::function<void(bool, const std::string&)>& afterC
}
glPixelStorei(GL_PACK_ALIGNMENT, 1);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
// The frame buffer is always created with portrait orientation on WP8.
// So if the current device orientation is landscape, we need to rotate the frame buffer.
auto renderTargetSize = glView->getRenerTargetSize();
CCASSERT(width * height == static_cast<int>(renderTargetSize.width * renderTargetSize.height), "The frame size is not matched");
glReadPixels(0, 0, (int)renderTargetSize.width, (int)renderTargetSize.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#else
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
#endif
std::shared_ptr<GLubyte> flippedBuffer(new GLubyte[width * height * 4], [](GLubyte* p) { CC_SAFE_DELETE_ARRAY(p); });
if (!flippedBuffer)
{
break;
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
if (width == static_cast<int>(renderTargetSize.width))
{
// The current device orientation is portrait.
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
}
else
{
// The current device orientation is landscape.
for (int row = 0; row < width; ++row)
{
for (int col = 0; col < height; ++col)
{
*(int*)(flippedBuffer.get() + (height - col - 1) * width * 4 + row * 4) = *(int*)(buffer.get() + row * height * 4 + col * 4);
}
}
}
#else
for (int row = 0; row < height; ++row)
{
memcpy(flippedBuffer.get() + (height - row - 1) * width * 4, buffer.get() + row * width * 4, width * 4);
}
#endif
std::shared_ptr<Image> image(new Image);
if (image)
{

View File

@ -144,14 +144,42 @@ ComAttribute* ComAttribute::create(void)
bool ComAttribute::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *fileData = cocoNode[3].GetChildArray();
CC_BREAK_IF(!fileData);
file = fileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(fileData[2].GetValue());
CC_BREAK_IF(resType != 0);
}
if (comName != nullptr)
{
setName(comName);
@ -160,22 +188,17 @@ bool ComAttribute::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
parse(filePath.c_str());
bRet = true;
} while (0);
return bRet;
if (parse(filePath.c_str()))
{
ret = true;
}
}while (0);
return ret;
}
bool ComAttribute::parse(const std::string &jsonFile)

View File

@ -69,14 +69,46 @@ void ComAudio::setEnabled(bool b)
bool ComAudio::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
bool loop = false;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(pfileData[2].GetValue());
CC_BREAK_IF(resType != 0);
loop = atoi(cocoNode[5].GetValue()) != 0? true:false;
ret = true;
}
if (comName != nullptr)
{
setName(comName);
@ -85,17 +117,14 @@ bool ComAudio::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
if (strcmp(file, "") == 0)
{
continue;
}
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
if (strcmp(className, "CCBackgroundAudio") == 0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
@ -108,9 +137,8 @@ bool ComAudio::serialize(void* r)
filePath.replace(pos, filePath.length(), ".wav");
#endif
preloadBackgroundMusic(filePath.c_str());
bool loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
setLoop(loop);
playBackgroundMusic(filePath.c_str(), loop);
playBackgroundMusic(filePath.c_str(), loop);
}
else if(strcmp(className, "CCComAudio") == 0)
{
@ -120,10 +148,9 @@ bool ComAudio::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
ret = true;
}while (0);
return ret;
}
ComAudio* ComAudio::create(void)

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string>
#include "DictionaryHelper.h"
#include "base/ObjectFactory.h"
#include "CocoLoader.h"
#define DECLARE_CLASS_COMPONENT_INFO \
@ -45,5 +46,16 @@ THE SOFTWARE.
#define CREATE_CLASS_COMPONENT_INFO(className) \
cocos2d::ObjectFactory::TInfo(#className, &className::createInstance)
struct SerData
{
const rapidjson::Value *_rData;
cocostudio::stExpCocoNode *_cocoNode;
SerData()
{
_rData = NULL;
_cocoNode = NULL;
}
};
#endif

View File

@ -90,14 +90,44 @@ void ComRender::setNode(cocos2d::Node *node)
bool ComRender::serialize(void* r)
{
bool bRet = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
const char *plist = nullptr;
std::string filePath;
std::string plistPath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
}
else if(cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
plist = pfileData[1].GetValue();
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = atoi(pfileData[2].GetValue());
}
if (comName != nullptr)
{
setName(comName);
@ -106,72 +136,175 @@ bool ComRender::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
const char *plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
std::string filePath;
std::string plistPath;
if (file != nullptr)
{
filePath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(file));
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
if (plist != nullptr)
{
plistPath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(plist));
plistPath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(plist));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
if (resType == 0)
{
if (strcmp(className, "CCSprite") == 0 && filePath.find(".png") != std::string::npos)
if (strcmp(className, "CCSprite") == 0 && (filePath.find(".png") != filePath.npos || filePath.find(".pvr.ccz") != filePath.npos))
{
_render = Sprite::create(filePath.c_str());
_render->retain();
_render = CCSprite::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != std::string::npos)
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != filePath.npos)
{
_render = TMXTiledMap::create(filePath.c_str());
_render->retain();
_render = CCTMXTiledMap::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != std::string::npos)
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != filePath.npos)
{
_render = ParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Vec2(0.0f, 0.0f));
_render->retain();
_render = CCParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Point(0.0f, 0.0f));
_render->retain();
ret = true;
}
else if(strcmp(className, "CCArmature") == 0)
{
std::string reDir = filePath;
std::string file_path = "";
size_t pos = reDir.find_last_of('/');
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_path = reDir.substr(0, pos+1);
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname");
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
if (actionName != nullptr && pAr->getAnimation() != nullptr)
else if (file_extension == ".CSB")
{
pAr->getAnimation()->play(actionName);
ssize_t size = 0;
unsigned char *pBytes = nullptr;
std::string binaryFilePath = FileUtils::getInstance()->fullPathForFilename(filePath.c_str());
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
int count = tpRootCocoNode->GetChildNum();
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
for (int i = 0; i < count; ++i)
{
std::string key = tpChildArray[i].GetName(&tCocoLoader);
if (key.compare("armature_data") == 0)
{
int length = tpChildArray[i].GetChildNum();
stExpCocoNode *armature_dataArray = tpChildArray[i].GetChildArray();
if (length < 1)
{
continue;
}
length = armature_dataArray[0].GetChildNum();
stExpCocoNode *armature_data = armature_dataArray[0].GetChildArray();
for (int j = 0; j < length; ++j)
{
std::string key1 = armature_data[j].GetName(&tCocoLoader);
const char *str1 = armature_data[j].GetValue();
if (key.compare("name") == 0)
{
if (str1 != nullptr)
{
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = CCArmature::create(str1);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
}
}
}
}
}
}
else
{
continue;
}
}
else
{
continue;
}
}
else if(strcmp(className, "GUIComponent") == 0)
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
else if (file_extension == ".CSB")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromBinaryFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
}
else
{
@ -190,8 +323,10 @@ bool ComRender::serialize(void* r)
}
strPngFile.replace(pos, strPngFile.length(), ".png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str());
_render = Sprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
_render = CCSprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
ret = true;
}
else
{
@ -202,10 +337,9 @@ bool ComRender::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
} while (0);
return ret;
}
ComRender* ComRender::create(void)

View File

@ -56,28 +56,133 @@ const char* SceneReader::sceneReaderVersion()
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/)
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
std::string reDir = fileName;
std::string file_extension = "";
size_t pos = reDir.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = reDir.substr(pos, reDir.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON")
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
}
else if(file_extension == ".CSB")
{
ssize_t size = 0;
unsigned char *pBytes = nullptr;
do {
std::string binaryFilePath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
CC_BREAK_IF(tpRootCocoNode->GetChildNum() == 0);
_node = Node::create();
int nCount = 0;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
std::string key = tpChildArray[15].GetName(&tCocoLoader);
if (key == "components")
{
nCount = tpChildArray[15].GetChildNum();
}
stExpCocoNode *pComponents = tpChildArray[15].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < nCount; i++)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key1 = subDict[1].GetName(&tCocoLoader);
const char *comName = subDict[1].GetValue();
Component *pCom = nullptr;
if (key1 == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
setPropertyFromJsonDict(&tCocoLoader, tpRootCocoNode, _node);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
_node->addComponent(*iter);
}
stExpCocoNode *pGameObjects = tpChildArray[11].GetChildArray();
int length = tpChildArray[11].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(&tCocoLoader, &pGameObjects[i], _node, attachComponent);
}
TriggerMng::getInstance()->parse(&tCocoLoader, tpChildArray);
}
}
}while (0);
return _node;
}
else
{
log("read file [%s] error!\n", fileName.c_str());
}
return nullptr;
}
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool bRet = false;
bool ret = false;
do {
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
bRet = true;
ret = true;
} while (0);
return bRet;
return ret;
}
Node* SceneReader::nodeByTag(Node *parent, int tag)
@ -172,9 +277,13 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = this->createComponent(comName);
CCLOG("classname = %s", comName);
SerData *data = new SerData();
if (com != nullptr)
{
if (com->serialize((void*)(&subDict)))
data->_rData = &subDict;
data->_cocoNode = nullptr;
if (com->serialize(data))
{
ComRender *tRender = dynamic_cast<ComRender*>(com);
if (tRender == nullptr)
@ -187,9 +296,10 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
}
}
CC_SAFE_DELETE(data);
if(_fnSelector != nullptr)
{
_fnSelector(com, (void*)(&subDict));
_fnSelector(com, data);
}
}
@ -234,6 +344,111 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
return nullptr;
}
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = nullptr;
stExpCocoNode *pNodeArray = cocoNode->GetChildArray();
std::string Key = pNodeArray[1].GetName(cocoLoader);
if (Key == "classname")
{
className = pNodeArray[1].GetValue();
}
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
int count = 0;
std::string key = pNodeArray[13].GetName(cocoLoader);
if (key == "components")
{
count = pNodeArray[13].GetChildNum();
}
stExpCocoNode *pComponents = pNodeArray[13].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < count; ++i)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key1 = subDict[1].GetName(cocoLoader);
const char *comName = subDict[1].GetValue();
Component *pCom = nullptr;
if (key1 == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
CC_SAFE_DELETE(data);
if (parent != nullptr)
{
if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = CCNode::create();
if (pRender != nullptr)
{
_vecComs.push_back(pRender);
}
}
else
{
gb = pRender->getNode();
gb->retain();
pRender->setNode(nullptr);
CC_SAFE_RELEASE_NULL(pRender);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(cocoLoader, cocoNode, gb);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray();
if (pGameObjects != nullptr)
{
int length = pNodeArray[12].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(cocoLoader, &pGameObjects[i], gb, attachComponent);
}
}
return gb;
}
return nullptr;
}
void SceneReader::setTarget(const std::function<void(cocos2d::Ref* obj, void* doc)>& selector)
{
@ -276,6 +491,62 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d:
float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation");
node->setRotation(fRotationZ);
}
void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node)
{
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
float x = 0.0f, y = 0.0f, fScaleX = 1.0f, fScaleY = 1.0f, fRotationZ = 1.0f;
bool bVisible = false;
int nTag = 0, nZorder = -1;
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
{
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "x")
{
x = atof(value.c_str());
node->setPositionX(x);
}
else if (key == "y")
{
y = atof(value.c_str());
node->setPositionY(y);
}
else if (key == "visible")
{
bVisible = (bool)atoi(value.c_str());
node->setVisible(bVisible);
}
else if (key == "objecttag")
{
nTag = atoi(value.c_str());
node->setTag(nTag);
}
else if (key == "zorder")
{
nZorder = atoi(value.c_str());
node->setZOrder(nZorder);
}
else if(key == "scalex")
{
fScaleX = atof(value.c_str());
node->setScaleX(fScaleX);
}
else if(key == "scaley")
{
fScaleY = atof(value.c_str());
node->setScaleY(fScaleY);
}
else if(key == "rotation")
{
fRotationZ = atof(value.c_str());
node->setRotation(fRotationZ);
}
}
}
SceneReader* SceneReader::getInstance()
{

View File

@ -76,6 +76,10 @@ private:
cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node);
bool readJson(const std::string &fileName, rapidjson::Document& doc);
cocos2d::Node* createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node);
cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag);
private:
static SceneReader* s_sharedReader;

View File

@ -96,8 +96,8 @@ public:
stExpCocoNode* GetChildArray();
public:
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
};

View File

@ -104,6 +104,44 @@ void TriggerMng::parse(const rapidjson::Value &root)
}
}
}
void TriggerMng::parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
CCLOG("%s", triggerMngVersion());
int count = pCocoNode[13].GetChildNum();
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
bool useBindings = engine != NULL;
if (useBindings)
{
if (count > 0 )
{
rapidjson::Document document;
buildJson(document, pCocoLoader, pCocoNode);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
engine->parseConfig(ScriptEngineProtocol::ConfigType::COCOSTUDIO, buffer.GetString());
}
}
else
#endif // #if CC_ENABLE_SCRIPT_BINDING
{
for (int i = 0; i < count; ++i)
{
TriggerObj *obj = TriggerObj::create();
obj->serialize(pCocoLoader, &pTriggersArray[i]);
_triggerObjs.insert(std::pair<unsigned int, TriggerObj*>(obj->getId(), obj));
obj->retain();
}
}
}
TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
{
@ -152,6 +190,216 @@ bool TriggerMng::isEmpty(void) const
return _triggerObjs.empty();
}
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int count = pCocoNode[13].GetChildNum();
int length = 0;
int num = 0;
int size = 0;
int extent = 0;
int border = 0;
std::string key0;
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
document.SetArray();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
for (int i0 = 0; i0 < count; ++i0)
{
rapidjson::Value vElemItem(rapidjson::kObjectType);
border = pTriggersArray[i0].GetChildNum();
stExpCocoNode *pTriggerArray = pTriggersArray[i0].GetChildArray();
for (int i1 = 0; i1 < border; ++i1)
{
std::string key1 = pTriggerArray[i1].GetName(pCocoLoader);
const char *str1 = pTriggerArray[i1].GetValue();
if (key1.compare("actions") == 0)
{
rapidjson::Value actionsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerArray[i1].GetChildArray();
for (int i2 = 0; i2 < length; ++i2)
{
rapidjson::Value action(rapidjson::kObjectType);
num = pActionsArray[i2].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray();
for (int i3 = 0; i3 < num; ++i3)
{
std::string key2 = pActionArray[i3].GetName(pCocoLoader);
const char *str2 = pActionArray[i3].GetValue();
if (key2.compare("classname") == 0)
{
if (str2 != NULL)
{
action.AddMember("classname", str2, allocator);
}
}
else if (key2.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pActionArray[i3].GetChildNum();
stExpCocoNode *pDataItemsArray = pActionArray[i3].GetChildArray();
for (int i4 = 0; i4 < size; ++i4)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i4].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i4].GetChildArray();
for (int i5 = 0; i5 < extent; ++i5)
{
std::string key3 = pDataItemArray[i5].GetName(pCocoLoader);
const char *str3 = pDataItemArray[i5].GetValue();
if (key3.compare("key") == 0)
{
if (str3 != NULL)
{
dataitem.AddMember("key", str3, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i4].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str3, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str3);
float fV = atof(str3);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
action.AddMember("dataitems", dataitems, allocator);
}
}
actionsItem.PushBack(action, allocator);
}
vElemItem.AddMember("actions", actionsItem, allocator);
}
else if (key1.compare("conditions") == 0)
{
rapidjson::Value condsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerArray[i1].GetChildArray();
for (int i6 = 0; i6 < length; ++i6)
{
rapidjson::Value cond(rapidjson::kObjectType);
num = pConditionsArray[i6].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i6].GetChildArray();
for (int i7 = 0; i7 < num; ++i7)
{
std::string key4 = pConditionArray[i7].GetName(pCocoLoader);
const char *str4 = pConditionArray[i7].GetValue();
if (key4.compare("classname") == 0)
{
if (str4 != NULL)
{
cond.AddMember("classname", str4, allocator);
}
}
else if (key4.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pConditionArray[i7].GetChildNum();
stExpCocoNode *pDataItemsArray = pConditionArray[i7].GetChildArray();
for (int i8 = 0; i8 < size; ++i8)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i8].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i8].GetChildArray();
for (int i9 = 0; i9 < extent; ++i9)
{
std::string key5 = pDataItemArray[i9].GetName(pCocoLoader);
const char *str5 = pDataItemArray[i9].GetValue();
if (key5.compare("key") == 0)
{
if (str5 != NULL)
{
dataitem.AddMember("key", str5, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i9].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str5, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str5);
float fV = atof(str5);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
cond.AddMember("dataitems", dataitems, allocator);
}
}
condsItem.PushBack(cond, allocator);
}
vElemItem.AddMember("conditions", condsItem, allocator);
}
else if (key1.compare("events") == 0)
{
rapidjson::Value eventsItem(rapidjson::kArrayType);
length = pTriggerArray[i1].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerArray[i1].GetChildArray();
for (int i10 = 0; i10 < length; ++i10)
{
rapidjson::Value event(rapidjson::kObjectType);
stExpCocoNode *pEventArray = pEventsArray->GetChildArray();
std::string key6 = pEventArray[0].GetName(pCocoLoader);
const char *str6 = pEventArray[0].GetValue();
if (key6.compare("id") == 0 && str6 != NULL)
{
event.AddMember("id", atoi(str6), allocator);
eventsItem.PushBack(event, allocator);
}
}
vElemItem.AddMember("events", eventsItem, allocator);
}
else if (key1.compare("id") == 0)
{
if (str1 != NULL)
{
vElemItem.AddMember("id", atoi(str1), allocator);
}
}
}
document.PushBack(vElemItem, allocator);
}
}
void TriggerMng::addArmatureMovementCallBack(Armature *pAr, Ref *pTarget, SEL_MovementEventCallFunc mecf)
{
if (pAr == nullptr || _movementDispatches == nullptr || pTarget == nullptr || mecf == nullptr)

View File

@ -64,6 +64,7 @@ public:
public:
void parse(const rapidjson::Value &root);
void parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
void removeAll(void);
cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
TriggerObj* getTriggerObj(unsigned int id) const;
@ -78,6 +79,8 @@ public:
void dispatchEvent(cocos2d::EventCustom* tEvent);
void removeEventListener(cocos2d::EventListener* listener);
void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority);
private:
void buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
private:
static TriggerMng *_sharedTriggerMng;

View File

@ -48,6 +48,11 @@ bool BaseTriggerCondition::detect()
void BaseTriggerCondition::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerCondition::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerCondition::removeAll()
{
@ -75,6 +80,10 @@ void BaseTriggerAction::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerAction::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerAction::removeAll()
{
}
@ -231,6 +240,102 @@ void TriggerObj::serialize(const rapidjson::Value &val)
}
}
void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
int num = 0;
stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray();
for (int i0 = 0; i0 < length; ++i0)
{
std::string key = pTriggerObjArray[i0].GetName(pCocoLoader);
const char* str0 = pTriggerObjArray[i0].GetValue();
if (key.compare("id") == 0)
{
if (str0 != NULL)
{
_id = atoi(str0); //(unsigned int)(DICTOOL->getIntValue_json(val, "id"));
}
}
else if (key.compare("conditions") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerObjArray[i0].GetChildArray();
for (int i1 = 0; i1 < count; ++i1)
{
num = pConditionsArray[i1].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i1].GetChildArray();
const char *classname = pConditionArray[0].GetValue();
if (classname == nullptr)
{
continue;
}
BaseTriggerCondition *con = dynamic_cast<BaseTriggerCondition*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(con != nullptr, "class named classname can not implement!");
con->serialize(pCocoLoader, &pConditionArray[1]);
con->init();
_cons.pushBack(con);
}
}
else if (key.compare("actions") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerObjArray[i0].GetChildArray();
for (int i2 = 0; i2 < count; ++i2)
{
num = pActionsArray[i2].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray();
const char *classname = pActionArray[0].GetValue();
if (classname == nullptr)
{
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(act != NULL, "class named classname can not implement!");
act->serialize(pCocoLoader, &pActionArray[1]);
act->init();
_acts.pushBack(act);
}
}
else if (key.compare("events") == 0)
{
count = pTriggerObjArray[i0].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerObjArray[i0].GetChildArray();
for (int i3 = 0; i3 < count; ++i3)
{
num = pEventsArray[i3].GetChildNum();
stExpCocoNode *pEventArray = pEventsArray[i3].GetChildArray();
const char *str1 = pEventArray[0].GetValue();
if (str1 == nullptr)
{
continue;
}
int event = atoi(str1);
if (event < 0)
{
continue;
}
char* buf = new char[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
CC_SAFE_DELETE_ARRAY(buf);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
}
}
unsigned int TriggerObj::getId()
{
return _id;

View File

@ -44,6 +44,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll();
};
@ -56,6 +57,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll();
};
@ -72,6 +74,7 @@ public:
virtual void done();
virtual void removeAll();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
unsigned int getId();
void setEnabled(bool enabled);

View File

@ -48,7 +48,9 @@ namespace cocostudio
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
Text* label = static_cast<Text*>(widget);
std::string jsonPath = GUIReader::getInstance()->getFilePath();
for (int i = 0; i < cocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
@ -67,7 +69,8 @@ namespace cocostudio
}else if(key == P_FontSize){
label->setFontSize(valueToInt(value));
}else if(key == P_FontName){
label->setFontName(value);
std::string fontFilePath = jsonPath.append(value);
label->setFontName(fontFilePath);
}else if(key == P_AreaWidth){
label->setTextAreaSize(Size(valueToFloat(value), label->getTextAreaSize().height));
}else if(key == P_AreaHeight){

View File

@ -264,7 +264,9 @@ namespace cocostudio
widget->setColor(_color);
widget->setOpacity(_opacity);
//the setSize method will be conflict with scale9Width & scale9Height
widget->setSize(Size(_width, _height));
if (!widget->isIgnoreContentAdaptWithSize()) {
widget->setSize(Size(_width, _height));
}
widget->setPosition(_position);
widget->setAnchorPoint(_originalAnchorPoint);
}

View File

@ -42,10 +42,10 @@ void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) {
textureAtlas->retain();
self->rendererObject = textureAtlas;
// Using getContentSize to make it supports the strategy of loading resources in cocos2d-x.
// self->width = texture->getPixelsWide();
// self->height = texture->getPixelsHigh();
self->width = texture->getContentSize().width;
self->height = texture->getContentSize().height;
self->width = texture->getPixelsWide();
self->height = texture->getPixelsHigh();
// self->width = texture->getContentSize().width;
// self->height = texture->getContentSize().height;
}
void _spAtlasPage_disposeTexture (spAtlasPage* self) {

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.lib"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
</manifest>

View File

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="androidcontrollerdelegate" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libcontrollerdelegate</name>
<name>libControllerManualAdapter</name>
<comment></comment>
<projects>
</projects>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="androidcontrollermoga" default="help">
<project name="androidControllerManualAdapter" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="NewApi">
<ignore path="src/org/cocos2dx/lib/GameControllerHelper.java" />
</issue>
</lint>

View File

@ -0,0 +1,16 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
android.library.reference.1=../java
android.library=true

View File

@ -0,0 +1,316 @@
/****************************************************************************
Copyright (c) 2010-2013 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.lib;
import java.lang.reflect.Method;
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
import org.cocos2dx.lib.Cocos2dxActivity;
import android.os.Bundle;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.util.Log;
public abstract class GameControllerActivity extends Cocos2dxActivity implements InputDeviceListener {
// ===========================================================
// Constants
// ===========================================================
private final static String TAG = GameControllerActivity.class.getSimpleName();
public static final int DRIVERTYPE_NIBIRU = 0;
public static final int DRIVERTYPE_MOGA = 1;
public static final int DRIVERTYPE_OUYA = 2;
public static final int DRIVERTYPE_STANDARD = 3;
public static final int DRIVERTYPE_UNKNOWN = 4;
// ===========================================================
// Fields
// ===========================================================
private static GameControllerActivity sGameControllerActivity;
private InputManagerCompat mInputManager = null;
protected GameControllerHelper mControllerHelper = null;
protected GameControllerDelegate mControllerNibiru = null;
protected GameControllerDelegate mControllerMoga = null;
protected GameControllerDelegate mControllerOuya = null;
public void connectController(int driveType){
try {
ClassLoader loader = sGameControllerActivity.getClassLoader();
Class<?> controllerDelegate = null;
if (driveType == DRIVERTYPE_MOGA) {
if (mControllerMoga != null) {
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerMoga");
} else if (driveType == DRIVERTYPE_NIBIRU) {
if (mControllerNibiru != null) {
mControllerNibiru.onCreate(sGameControllerActivity);
mControllerNibiru.onResume();
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
} else if (driveType == DRIVERTYPE_OUYA) {
if (mControllerOuya != null) {
return;
}
controllerDelegate = loader.loadClass("org.cocos2dx.lib.GameControllerOuya");
}
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
sGameControllerActivity.setGameControllerInstance(instance, driveType);
if (driveType == DRIVERTYPE_NIBIRU) {
Method method = controllerDelegate.getDeclaredMethod("onResume");
method.invoke(instance);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public void setGameControllerInstance(GameControllerDelegate controllerDelegate, int driveType) {
if (driveType == DRIVERTYPE_NIBIRU) {
mControllerNibiru = controllerDelegate;
}else if (driveType == DRIVERTYPE_MOGA) {
mControllerMoga = controllerDelegate;
}
else if (driveType == DRIVERTYPE_OUYA) {
mControllerOuya = controllerDelegate;
}
controllerDelegate.setControllerEventListener(mControllerEventListener);
controllerDelegate.onCreate(sGameControllerActivity);
}
public GameControllerDelegate getGameControllerDelegate(int driveType){
if (driveType == DRIVERTYPE_NIBIRU) {
return mControllerNibiru;
}else if (driveType == DRIVERTYPE_MOGA) {
return mControllerMoga;
}
else if (driveType == DRIVERTYPE_OUYA) {
return mControllerOuya;
}
return null;
}
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
@Override
public void onButtonEvent(String vendorName, int controller, int button,
boolean isPressed, float value, boolean isAnalog) {
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
}
@Override
public void onAxisEvent(String vendorName, int controller, int axisID,
float value, boolean isAnalog) {
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
}
@Override
public void onConnected(String vendorName, int controller) {
GameControllerAdapter.onConnected(vendorName, controller);
}
@Override
public void onDisconnected(String vendorName, int controller) {
GameControllerAdapter.onDisconnected(vendorName, controller);
}
};
// ===========================================================
// Constructors
// ===========================================================
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sGameControllerActivity = this;
mInputManager = InputManagerCompat.Factory.getInputManager(this);
mInputManager.registerInputDeviceListener(this, null);
if (mControllerNibiru != null) {
mControllerNibiru.onCreate(this);
}
if (mControllerMoga != null) {
mControllerMoga.onCreate(this);
}
if (mControllerOuya != null) {
mControllerOuya.onCreate(this);
}
if (mControllerHelper == null) {
mControllerHelper = new GameControllerHelper(this);
}
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
if (mControllerNibiru != null) {
handled |= mControllerNibiru.dispatchKeyEvent(event);
}
if (mControllerMoga != null) {
handled |= mControllerMoga.dispatchKeyEvent(event);
}
if (mControllerOuya != null) {
handled |= mControllerOuya.dispatchKeyEvent(event);
}
handled |= mControllerHelper.dispatchKeyEvent(event);
return handled || super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
if (mControllerNibiru != null) {
handled |= mControllerNibiru.dispatchGenericMotionEvent(event);
}
if (mControllerMoga != null) {
handled |= mControllerMoga.dispatchGenericMotionEvent(event);
}
if (mControllerOuya != null) {
handled |= mControllerOuya.dispatchGenericMotionEvent(event);
}
handled |= mControllerHelper.dispatchGenericMotionEvent(event);
return handled || super.dispatchGenericMotionEvent(event);
}
@Override
public void onInputDeviceAdded(int deviceId) {
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
InputDevice device = InputDevice.getDevice(deviceId);
int deviceSource = device.getSources();
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
GameControllerAdapter.onConnected("Standard", deviceId);
}
}
/*
* 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
* this to make sure that the ship has an up-to-date InputDevice.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceChanged(int)
*/
@Override
public void onInputDeviceChanged(int deviceId) {
Log.d(TAG,"onInputDeviceChanged:" + deviceId);
}
/*
* Remove any ship associated with the ID.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceRemoved(int)
*/
@Override
public void onInputDeviceRemoved(int deviceId) {
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
InputDevice device = InputDevice.getDevice(deviceId);
int deviceSource = device.getSources();
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
GameControllerAdapter.onDisconnected("Standard", deviceId);
}
}
@Override
protected void onResume() {
super.onResume();
if (mControllerNibiru != null) {
mControllerNibiru.onResume();
}
if (mControllerMoga != null) {
mControllerMoga.onResume();
}
if (mControllerOuya != null) {
mControllerOuya.onResume();
}
}
@Override
protected void onPause() {
if (mControllerNibiru != null) {
mControllerNibiru.onPause();
}
if (mControllerMoga != null) {
mControllerMoga.onPause();
}
if (mControllerOuya != null) {
mControllerOuya.onPause();
}
super.onPause();
}
@Override
protected void onDestroy() {
if (mControllerNibiru != null) {
mControllerNibiru.onDestroy();
}
if (mControllerMoga != null) {
mControllerMoga.onDestroy();
}
if (mControllerOuya != null) {
mControllerOuya.onDestroy();
}
super.onDestroy();
}
}

View File

@ -0,0 +1,191 @@
package org.cocos2dx.lib;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
public class GameControllerHelper {
public static final String StandardControllerName = "Standard";
SparseIntArray ControllerKeyMap;
private static final int AXIS_X = 0;
private static final int AXIS_Y = 1;
private static final int AXIS_Z = 11;
private static final int AXIS_RZ = 14;
private static final int AXIS_LTRIGGER = 17;
private static final int AXIS_RTRIGGER = 18;
public static final int AXIS_GAS = 22;
private static final int AXIS_BRAKE = 23;
private static final int AXIS_THROTTLE = 19;
public GameControllerHelper(GameControllerActivity activity){
ControllerKeyMap = new SparseIntArray(25);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
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_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
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_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
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_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
ControllerKeyMap.put(AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
ControllerKeyMap.put(AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
ControllerKeyMap.put(AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
ControllerKeyMap.put(AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
//KEYCODE_BUTTON_MODE
}
private float mOldLeftThumbstickX = 0.0f;
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private float mOldThrottle = 0.0f;
private float mOldBrake = 0.0f;
private float mOldGas = 0.0f;
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
int eventSource = event.getSource();
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
if (event.getAction() == MotionEvent.ACTION_MOVE) {
int devicedId = event.getDeviceId();
float newAXIS_LX = event.getAxisValue(AXIS_X);
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
mOldLeftThumbstickX = newAXIS_LX;
handled = true;
}
float newAXIS_LY = event.getAxisValue(AXIS_Y);
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
mOldLeftThumbstickY = newAXIS_LY;
handled = true;
}
float newAXIS_RX = event.getAxisValue(AXIS_Z);
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
mOldRightThumbstickX = newAXIS_RX;
handled = true;
}
float newAXIS_RY = event.getAxisValue(AXIS_RZ);
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
mOldRightThumbstickY = newAXIS_RY;
handled = true;
}
float newAXIS_LTRIGGER = event.getAxisValue(AXIS_LTRIGGER);
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
if (Float.compare(newAXIS_LTRIGGER, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_LTRIGGER, true);
}
mOldLeftTrigger = newAXIS_LTRIGGER;
handled = true;
}
float newAXIS_RTRIGGER = event.getAxisValue(AXIS_RTRIGGER);
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
if (Float.compare(newAXIS_RTRIGGER, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_RTRIGGER, true);
}
mOldRightTrigger = newAXIS_RTRIGGER;
handled = true;
}
float newAXIS_BRAKE = event.getAxisValue(AXIS_BRAKE);
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
if (Float.compare(newAXIS_BRAKE, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_BRAKE, true);
}
mOldBrake = newAXIS_BRAKE;
handled = true;
}
float newAXIS_THROTTLE = event.getAxisValue(AXIS_THROTTLE);
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
if (Float.compare(newAXIS_THROTTLE, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_THROTTLE, true);
}
mOldThrottle = newAXIS_THROTTLE;
handled = true;
}
float newAXIS_GAS = event.getAxisValue(AXIS_GAS);
if (Float.compare(newAXIS_GAS , mOldGas) != 0) {
if (Float.compare(newAXIS_GAS, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_GAS, true);
}
mOldGas = newAXIS_GAS;
handled = true;
}
}
}
return handled;
}
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
int eventSource = event.getSource();
int controllerKey = ControllerKeyMap.get(event.getKeyCode());
if (controllerKey != 0 && (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)
|| ((eventSource & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD)))
{
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
handled = true;
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,true, 1.0f, false);
}else if (action == KeyEvent.ACTION_UP) {
handled = true;
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,false, 0.0f, false);
}
}
return handled;
}
}

View File

@ -20,6 +20,9 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private SparseIntArray mKeyMap = null;
@ -60,9 +63,13 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
}
public void onKeyEvent(KeyEvent event) {
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
public void onKeyEvent(KeyEvent event) {
int keycode = event.getKeyCode();
if (keycode == KeyEvent.KEYCODE_BUTTON_L2
|| keycode == KeyEvent.KEYCODE_BUTTON_R2) {
return;
}
boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN;
boolean isAnalog = false;
if (keycode == KeyEvent.KEYCODE_BUTTON_THUMBL
@ -82,10 +89,12 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
if (mControllerEventListener == null) {
return;
}
int controllerId = event.getControllerId();
float newLeftThumbstickX = event.getAxisValue(MotionEvent.AXIS_X);
if (newLeftThumbstickX != mOldLeftThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(),
controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_X,
newLeftThumbstickX, true);
mOldLeftThumbstickX = newLeftThumbstickX;
@ -94,7 +103,7 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newLeftThumbstickY = event.getAxisValue(MotionEvent.AXIS_Y);
if (newLeftThumbstickY != mOldLeftThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(),
controllerId,
GameControllerDelegate.THUMBSTICK_LEFT_Y,
newLeftThumbstickY, true);
mOldLeftThumbstickY = newLeftThumbstickY;
@ -103,7 +112,7 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newRightThumbstickX = event.getAxisValue(MotionEvent.AXIS_Z);
if (newRightThumbstickX != mOldRightThumbstickX) {
mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(),
controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_X,
newRightThumbstickX, true);
mOldRightThumbstickX = newRightThumbstickX;
@ -112,11 +121,39 @@ public class GameControllerMoga implements ControllerListener, GameControllerDel
float newRightThumbstickY = event.getAxisValue(MotionEvent.AXIS_RZ);
if (newRightThumbstickY != mOldRightThumbstickY) {
mControllerEventListener.onAxisEvent(mVendorName,
event.getControllerId(),
controllerId,
GameControllerDelegate.THUMBSTICK_RIGHT_Y,
newRightThumbstickY, true);
mOldRightThumbstickY = newRightThumbstickY;
}
float newLeftTrigger = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
if (newLeftTrigger != mOldLeftTrigger) {
boolean isPressed = true;
if (Float.compare(newLeftTrigger, 0.0f) == 0) {
isPressed = false;
}
mControllerEventListener.onButtonEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_LEFT_TRIGGER,
isPressed,
newLeftTrigger, true);
mOldLeftTrigger = newLeftTrigger;
}
float newRightTrigger = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
if (newRightTrigger != mOldRightTrigger) {
boolean isPressed = true;
if (Float.compare(newRightTrigger, 0.0f) == 0) {
isPressed = false;
}
mControllerEventListener.onButtonEvent(mVendorName,
controllerId,
GameControllerDelegate.BUTTON_RIGHT_TRIGGER,
isPressed,
newRightTrigger, true);
mOldRightTrigger = newRightTrigger;
}
}
@Override

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libcontrollermoga</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,17 +0,0 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libcontrollernibiru</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.lib"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
</manifest>

View File

@ -1,17 +0,0 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

View File

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="androidcontrollernibiru" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>libcontrollerouya</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,4 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.cocos2dx.lib"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10"/>
</manifest>

View File

@ -1,17 +0,0 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked into Version Control Systems, as it is
# integral to the build system of your project.
# This file is only used by the Ant script.
# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.
# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.

View File

@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="androidcontrollerouya" default="help">
<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />
<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />
<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />
<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
unless="sdk.dir"
/>
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />
</project>

View File

@ -1,20 +0,0 @@
# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -12,5 +12,4 @@
android.library=true
# Project target.
target=android-16
android.library.reference.1=../ControllerDelegate
target=android-10

View File

@ -24,9 +24,6 @@ THE SOFTWARE.
package org.cocos2dx.lib;
import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;
import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat;
import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener;
import android.app.Activity;
import android.content.Context;
@ -36,15 +33,12 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.util.Log;
import android.widget.FrameLayout;
import android.preference.PreferenceManager.OnActivityResultListener;
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener, InputDeviceListener {
public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
// ===========================================================
// Constants
// ===========================================================
@ -59,10 +53,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
private Cocos2dxHandler mHandler;
private static Cocos2dxActivity sContext = null;
private Cocos2dxVideoHelper mVideoHelper = null;
private InputManagerCompat mInputManager = null;
protected GameControllerHelper mControllerHelper = null;
protected GameControllerDelegate mControllerDelegate = null;
public static Context getContext() {
return sContext;
@ -79,45 +69,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
}
}
public void setGameControllerInstance(GameControllerDelegate controllerDelegate) {
if (mControllerDelegate != null) {
mControllerDelegate.onDestroy();
mControllerDelegate = null;
}
mControllerDelegate = controllerDelegate;
mControllerDelegate.setControllerEventListener(mControllerEventListener);
mControllerDelegate.onCreate(this);
}
public GameControllerDelegate getGameControllerInstance(){
return mControllerDelegate;
}
ControllerEventListener mControllerEventListener = new ControllerEventListener() {
@Override
public void onButtonEvent(String vendorName, int controller, int button,
boolean isPressed, float value, boolean isAnalog) {
GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog);
}
@Override
public void onAxisEvent(String vendorName, int controller, int axisID,
float value, boolean isAnalog) {
GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog);
}
@Override
public void onConnected(String vendorName, int controller) {
GameControllerAdapter.onConnected(vendorName, controller);
}
@Override
public void onDisconnected(String vendorName, int controller) {
GameControllerAdapter.onDisconnected(vendorName, controller);
}
};
// ===========================================================
// Constructors
// ===========================================================
@ -137,16 +88,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
if (mVideoHelper == null) {
mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
}
mInputManager = InputManagerCompat.Factory.getInputManager(this);
mInputManager.registerInputDeviceListener(this, null);
if (mControllerDelegate != null) {
mControllerDelegate.onCreate(this);
}
if (mControllerHelper == null) {
mControllerHelper = new GameControllerHelper(this);
}
}
// ===========================================================
@ -157,96 +98,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
if (mControllerDelegate != null) {
handled = mControllerDelegate.dispatchKeyEvent(event);
}
else {
handled = mControllerHelper.dispatchKeyEvent(event);
}
return handled || super.dispatchKeyEvent(event);
}
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
if (mControllerDelegate != null) {
handled = mControllerDelegate.dispatchGenericMotionEvent(event);
}else {
handled = mControllerHelper.dispatchGenericMotionEvent(event);
}
return handled || super.dispatchGenericMotionEvent(event);
}
@Override
public void onInputDeviceAdded(int deviceId) {
Log.d(TAG,"onInputDeviceAdded:" + deviceId);
InputDevice device = InputDevice.getDevice(deviceId);
int deviceSource = device.getSources();
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
GameControllerAdapter.onConnected("Standard", deviceId);
}
}
/*
* 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
* this to make sure that the ship has an up-to-date InputDevice.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceChanged(int)
*/
@Override
public void onInputDeviceChanged(int deviceId) {
Log.d(TAG,"onInputDeviceChanged:" + deviceId);
}
/*
* Remove any ship associated with the ID.
*
* @see
* com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener
* #onInputDeviceRemoved(int)
*/
@Override
public void onInputDeviceRemoved(int deviceId) {
Log.d(TAG,"onInputDeviceRemoved:" + deviceId);
InputDevice device = InputDevice.getDevice(deviceId);
int deviceSource = device.getSources();
if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
GameControllerAdapter.onDisconnected("Standard", deviceId);
}
}
@Override
protected void onResume() {
super.onResume();
Cocos2dxHelper.onResume();
this.mGLSurfaceView.onResume();
if (mControllerDelegate != null) {
mControllerDelegate.onResume();
}
}
@Override
protected void onPause() {
if (mControllerDelegate != null) {
mControllerDelegate.onPause();
}
super.onPause();
Cocos2dxHelper.onPause();
@ -255,11 +116,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe
@Override
protected void onDestroy() {
if (mControllerDelegate != null) {
mControllerDelegate.onDestroy();
}
mControllerHelper.destrory();
super.onDestroy();
}

View File

@ -1,870 +0,0 @@
package org.cocos2dx.lib;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONObject;
import org.apache.http.Header;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.FileAsyncHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import dalvik.system.DexClassLoader;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.Toast;
public class GameControllerHelper {
private final static String TAG = GameControllerHelper.class.getSimpleName();
public static final String StandardControllerName = "Standard";
public static final String[] DRIVERS_NAME = {"nibiru","moga","ouya",StandardControllerName};
public static final int DRIVERTYPE_NIBIRU = 0;
public static final int DRIVERTYPE_MOGA = 1;
public static final int DRIVERTYPE_OUYA = 2;
public static final int DRIVERTYPE_STANDARD = 3;
public static final int DRIVERTYPE_UNKNOWN = 4;
public static final String SPP_UUID = "00001101-0000-1000-8000-00805F9B34FB";
SparseIntArray ControllerKeyMap;
private static final String COCOS_CONTROLLER_URL = "http://115.28.134.83:9000/download/cocoscontroller/";
private static final String COCOS_CONTROLLER_CONFIG = "controller.json";
private static final String NIBIRU_DEP_PACKAGE = "com.nibiru";
private static final String MOGA__DEP_PACKAGE = "com.bda.pivot.mogapgp";
private static Cocos2dxActivity sCocos2dxActivity;
private static GameControllerHelper sControllerHelper;
private List<String> mNibiruSupportedDrives;
private String mNibiruDepFileName;
private String mNibiruLibFileName;
private int mNibiruLibFileSize;
private int mNibiruDepFileSize;
private List<String> mMogaSupportedDrives;
private String mMogaDepFileName;
private String mMogaLibFileName;
private int mMogaLibFileSize;
private int mMogaDepFileSize;
private List<String> mOuyaSupportedDrives;
private String mOuyaLibFileName;
private int mOuyaLibFileSize;
private AsyncHttpClient mDownDepsHttpClient = null;
private BluetoothAdapter mBluetoothAdapter = null;
private ArrayList<BluetoothDevice> mBluetoothDevices = null;
private SparseIntArray mDevicesDriver;
private int mClearDevices = 0;
private String mConfigFilePath;
private String mLocalSavePath = null;
private boolean mLazyInit = true;
private boolean mLazyConfigInit = true;
private static ControllerListener mControllerListener = null;
public static interface ControllerListener{
void onDownloadConfigStarted();
void onDownloadConfigFinished(boolean isSuccess);
void onControllerDiscoveryStarted();
//
void onControllerDiscoveryFinish(ArrayList<BluetoothDevice> devices);
void onDownloadDepsStarted();
void onDownloadDepsProgress(int bytesWritten, int totalSize);
void onDownloadDepsFinished(boolean isSuccess);
void onInstallDriver(String filePath);
void onConnectController();
}
public void setControllerListener(ControllerListener listener){
mControllerListener = listener;
}
public GameControllerHelper(Cocos2dxActivity activity){
sCocos2dxActivity = activity;
sControllerHelper = this;
ControllerKeyMap = new SparseIntArray(25);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_A, GameControllerDelegate.BUTTON_A);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_B, GameControllerDelegate.BUTTON_B);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_C, GameControllerDelegate.BUTTON_C);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_X, GameControllerDelegate.BUTTON_X);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Y, GameControllerDelegate.BUTTON_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_Z, GameControllerDelegate.BUTTON_Z);
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_LEFT, GameControllerDelegate.BUTTON_DPAD_LEFT);
ControllerKeyMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, GameControllerDelegate.BUTTON_DPAD_RIGHT);
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_THUMBR, GameControllerDelegate.BUTTON_RIGHT_THUMBSTICK);
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_L2, GameControllerDelegate.BUTTON_LEFT_TRIGGER);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_R2, GameControllerDelegate.BUTTON_RIGHT_TRIGGER);
ControllerKeyMap.put(MotionEvent.AXIS_X, GameControllerDelegate.THUMBSTICK_LEFT_X);
ControllerKeyMap.put(MotionEvent.AXIS_Y, GameControllerDelegate.THUMBSTICK_LEFT_Y);
ControllerKeyMap.put(MotionEvent.AXIS_Z, GameControllerDelegate.THUMBSTICK_RIGHT_X);
ControllerKeyMap.put(MotionEvent.AXIS_RZ, GameControllerDelegate.THUMBSTICK_RIGHT_Y);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_START, GameControllerDelegate.BUTTON_START);
ControllerKeyMap.put(KeyEvent.KEYCODE_BUTTON_SELECT, GameControllerDelegate.BUTTON_SELECT);
//KEYCODE_BUTTON_MODE
}
public void connectController(){
if (mLazyInit) {
mLazyInit = false;
mNibiruSupportedDrives = new ArrayList<String>(30);
mMogaSupportedDrives = new ArrayList<String>(5);
mOuyaSupportedDrives = new ArrayList<String>(5);
mLocalSavePath = Environment.getExternalStorageDirectory() + File.separator + "CocosGameController" + File.separator;
mConfigFilePath = sCocos2dxActivity.getFilesDir().getAbsolutePath() + File.separator + COCOS_CONTROLLER_CONFIG;
mDownDepsHttpClient = new AsyncHttpClient();
mDownDepsHttpClient.setTimeout(360 * 1000);
}
if (mControllerListener != null) {
mControllerListener.onDownloadConfigStarted();
}
if (mLazyConfigInit) {
if (mDownDepsHttpClient != null) {
mDownDepsHttpClient.cancelRequests(sCocos2dxActivity, true);
}
requestControllerConfig();
}
else {
scanBluetoothDrive();
}
}
public Set<BluetoothDevice> getBondedDevices(){
if (mBluetoothAdapter == null) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
return null;
}
}
return mBluetoothAdapter.getBondedDevices();
}
public void destrory(){
if (mDownDepsHttpClient != null) {
mDownDepsHttpClient.cancelRequests(sCocos2dxActivity, true);
}
}
private boolean scanBluetoothDrive(){
if (mControllerListener != null) {
mControllerListener.onDownloadConfigFinished(true);
}
if (mBluetoothAdapter == null) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
return false;
}
if (mBluetoothDevices == null) {
mBluetoothDevices = new ArrayList<BluetoothDevice>(5);
mDevicesDriver = new SparseIntArray();
}
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
//filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
//filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
//filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
sCocos2dxActivity.registerReceiver(mBluetoothReceiver, filter);
IntentFilter appFilter = new IntentFilter();
appFilter.addAction("android.intent.action.PACKAGE_ADDED");
appFilter.addDataScheme("package");
sCocos2dxActivity.registerReceiver(mAppReceiver, appFilter);
}
if (!mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.enable();
}
if (mBluetoothAdapter.isDiscovering()) {
mBluetoothAdapter.cancelDiscovery();
}
mBluetoothAdapter.startDiscovery();
return true;
}
public int checkDriverType(BluetoothDevice device){
String deviceName = device.getName();
if (mNibiruSupportedDrives.contains(deviceName)) {
return DRIVERTYPE_NIBIRU;
}
else if (mMogaSupportedDrives.contains(deviceName)) {
return DRIVERTYPE_MOGA;
}
else if (mOuyaSupportedDrives.contains(deviceName)) {
return DRIVERTYPE_OUYA;
}
else {
}
return DRIVERTYPE_UNKNOWN;
}
public static void installApplication(String filePath){
if (sCocos2dxActivity != null) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sCocos2dxActivity.startActivity(intent);
}
}
public static boolean checkApplication(String packName){
try {
ApplicationInfo applicationInfo = sCocos2dxActivity.getPackageManager().getApplicationInfo(packName, PackageManager.GET_UNINSTALLED_PACKAGES);
Log.d(TAG, applicationInfo.toString());
return true;
} catch (NameNotFoundException e) {
return false;
}
}
private BroadcastReceiver mBluetoothReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (mBluetoothDevices.contains(device)) {
return;
}
Log.d(TAG, "Remote device discovered :" + device.getName());
//We can't ensure non-controller can be filtered out.Some game controller marked with computer class.
/*String deviceName = device.getName();
if(device.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.COMPUTER
|| device.getBluetoothClass().getMajorDeviceClass() == BluetoothClass.Device.Major.PHONE)
{
Log.w(TAG, "Remote device discovered :" + deviceName + " is computer or phone." + device.getBluetoothClass().getMajorDeviceClass());
return;
}*/
mBluetoothDevices.add(device);
int type = checkDriverType(device);
if (type != DRIVERTYPE_UNKNOWN) {
mTargetDriverType = type;
mClearDevices += 1;
}
mDevicesDriver.append(mBluetoothDevices.size() - 1, type);
}
else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Log.d(TAG, "The local Bluetooth adapter has finished the device discovery process.");
if (mControllerListener != null) {
mControllerListener.onControllerDiscoveryFinish(mBluetoothDevices);
}
else {
if (mBluetoothDevices.size() == 0) {
if (checkApplication(NIBIRU_DEP_PACKAGE)) {
downControllerDeps(DRIVERTYPE_NIBIRU);
}
Log.w(TAG, "Not found any supported bluetooth game controller!");
}else {
if (mClearDevices == 1 ) {
downControllerDeps(mTargetDriverType);
}
else {
Log.i(TAG, "More than one device");
//todo:show sel
}
}
}
}
else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
Log.d(TAG, "The local Bluetooth adapter has started the remote device discovery process.");
if(mControllerListener != null){
mControllerListener.onControllerDiscoveryStarted();
}
mBluetoothDevices.clear();
mDevicesDriver.clear();
mClearDevices = 0;
mTargetDriverType = DRIVERTYPE_UNKNOWN;
//check moga controller
Iterator<BluetoothDevice> it = mBluetoothAdapter.getBondedDevices().iterator();
while (it.hasNext()) {
BluetoothDevice device = it.next();
//if(device.getBluetoothClass().getMajorDeviceClass() != BluetoothClass.Device.Major.COMPUTER
// && device.getBluetoothClass().getMajorDeviceClass() != BluetoothClass.Device.Major.PHONE)
{
if (!mBluetoothDevices.contains(device)) {
mBluetoothDevices.add(device);
int type = checkDriverType(device);
Log.d(TAG, "BluetoothDevice objects that are bonded (paired) to the local adapter :" + device.getName());
if (type != DRIVERTYPE_UNKNOWN) {
mClearDevices += 1;
mTargetDriverType = type;
}
mDevicesDriver.append(mBluetoothDevices.size() - 1, type);
}
}
}
}
}
};
private static int depsCount = 0;
private static int mTargetDriverType = DRIVERTYPE_UNKNOWN;
private static int mDownloadTotalSize;
private static int mDownloadLibSize;
private static int mLibDownloadCompletedSize;
private static int mDepDownloadCompletedSize;
public void downControllerDeps(int driverType){
if (driverType == DRIVERTYPE_STANDARD || driverType == DRIVERTYPE_UNKNOWN) {
return;
}
if (mControllerListener != null) {
mControllerListener.onDownloadDepsStarted();
}
mDownloadTotalSize = 0;
mLibDownloadCompletedSize = 0;
mDepDownloadCompletedSize = 0;
mTargetDriverType = driverType;
depsCount = 1;
GameControllerUtils.ensureDirectoryExist(mLocalSavePath);
String remoteDir = COCOS_CONTROLLER_URL + DRIVERS_NAME[driverType] + File.separator;
if (driverType == DRIVERTYPE_NIBIRU) {
mDownloadLibSize = mNibiruLibFileSize;
mDownloadTotalSize += mNibiruLibFileSize;
if (!checkApplication(NIBIRU_DEP_PACKAGE)) {
depsCount += 1;
mDownloadTotalSize += mNibiruDepFileSize;
mDownDepsHttpClient.get(remoteDir + mNibiruDepFileName, new MyDepsAsyncHandler(
new File(mLocalSavePath + mNibiruDepFileName), MyDepsAsyncHandler.FILETYPE_DEP_APK));
}
File libFile = new File(mLocalSavePath + mNibiruLibFileName);
if (libFile.exists() && libFile.length() == mNibiruLibFileSize) {
depsCount -= 1;
if (depsCount == 0) {
onDepsReady();
}
}
else {
mDownDepsHttpClient.get(remoteDir + mNibiruLibFileName, new MyDepsAsyncHandler(
libFile, MyDepsAsyncHandler.FILETYPE_JAR));
}
}
else if (driverType == DRIVERTYPE_MOGA) {
mDownloadLibSize = mMogaLibFileSize;
mDownloadTotalSize += mMogaLibFileSize;
if (!checkApplication(MOGA__DEP_PACKAGE)) {
mDownloadTotalSize += mMogaDepFileSize;
depsCount += 1;
mDownDepsHttpClient.get(remoteDir + mMogaDepFileName, new MyDepsAsyncHandler(
new File(mLocalSavePath + mMogaDepFileName), MyDepsAsyncHandler.FILETYPE_DEP_APK));
}
File libFile = new File(mLocalSavePath + mMogaLibFileName);
if (libFile.exists() && libFile.length() == mMogaLibFileSize) {
depsCount -= 1;
if (depsCount == 0) {
onDepsReady();
}
}else {
mDownDepsHttpClient.get(remoteDir + mMogaLibFileName, new MyDepsAsyncHandler(
libFile, MyDepsAsyncHandler.FILETYPE_JAR));
}
}
else if(driverType == DRIVERTYPE_OUYA){
mDownloadLibSize = mOuyaLibFileSize;
mDownloadTotalSize += mOuyaLibFileSize;
File libFile = new File(mLocalSavePath + mOuyaLibFileName);
if (libFile.exists() && libFile.length() == mOuyaLibFileSize) {
depsCount -= 1;
if (depsCount == 0) {
onDepsReady();
}
}else {
mDownDepsHttpClient.get(remoteDir + mOuyaLibFileName, new MyDepsAsyncHandler(
new File(mLocalSavePath + mOuyaLibFileName), MyDepsAsyncHandler.FILETYPE_JAR));
}
}
}
static class MyDepsAsyncHandler extends FileAsyncHttpResponseHandler{
public static final int FILETYPE_DEP_APK = 0;
public static final int FILETYPE_JAR = 1;
private int mFileType = FILETYPE_DEP_APK;
public MyDepsAsyncHandler(File file, int fileType) {
super(file);
mFileType = fileType;
}
@Override
public void onFailure(int statusCode, Header[] headers,
Throwable e, File file) {
if (mFileType == FILETYPE_JAR) {
if (file.exists() && file.length() == mDownloadLibSize) {
depsCount -= 1;
if (depsCount == 0) {
if (mControllerListener != null) {
mControllerListener.onDownloadDepsFinished(true);
}
sControllerHelper.onDepsReady();
}
}
}
else if (mFileType == FILETYPE_DEP_APK) {
if (mControllerListener != null) {
mControllerListener.onDownloadDepsFinished(false);
}
}
Log.e(TAG,"Failed to download:" + file.getName());
}
@Override
public void onSuccess(File file) {
Log.d(TAG, "Down file success:" + file.getName());
depsCount -= 1;
if (depsCount == 0) {
if (mControllerListener != null) {
mControllerListener.onDownloadDepsFinished(true);
}
sControllerHelper.onDepsReady();
}
}
@Override
public void onProgress(int bytesWritten, int totalSize) {
if (mFileType == FILETYPE_JAR) {
mLibDownloadCompletedSize = bytesWritten;
} else {
mDepDownloadCompletedSize = bytesWritten;
}
if (mControllerListener != null) {
mControllerListener.onDownloadDepsProgress(mLibDownloadCompletedSize + mDepDownloadCompletedSize, mDownloadTotalSize);
}
Log.d(TAG, "totalSize:" + totalSize + ", bytesWritten:" + bytesWritten);
}
}
private void onDepsReady(){
Log.d(TAG, "onDepsReady:" + mTargetDriverType);
if (mTargetDriverType == DRIVERTYPE_NIBIRU) {
if (checkApplication(NIBIRU_DEP_PACKAGE)) {
createControllerInstance(mLocalSavePath + mNibiruLibFileName, mTargetDriverType);
}
else {
if (mControllerListener != null) {
mControllerListener.onInstallDriver(mLocalSavePath + mMogaDepFileName);
}
installApplication(mLocalSavePath + mNibiruDepFileName);
}
}
else if (mTargetDriverType == DRIVERTYPE_MOGA) {
if (checkApplication(MOGA__DEP_PACKAGE)) {
createControllerInstance(mLocalSavePath + mMogaLibFileName, mTargetDriverType);
}
else {
if (mControllerListener != null) {
mControllerListener.onInstallDriver(mLocalSavePath + mMogaDepFileName);
}
installApplication(mLocalSavePath + mMogaDepFileName);
}
}
else if (mTargetDriverType == DRIVERTYPE_OUYA) {
/*if (checkApplication(OUYA_FRAMEWORK_PACKAGE)) {
if (checkApplication(OUYA_LAUNCHER_PACKAGE)) {
createControllerInstance(mLocalSavePath + mOuyaLibFileName, mTargetSDK);
}
else {
installApplication(mLocalSavePath + mOuyaLauncherFileName);
}
}
else {
installApplication(mLocalSavePath + mOuyaFrameworkFileName);
}*/
createControllerInstance(mLocalSavePath + mOuyaLibFileName, mTargetDriverType);
}
}
private static final String CONFIGKEY_DRIVES = "drives";
private static final String CONFIGKEY_LIB_FILENAME = "lib";
private static final String CONFIGKEY_LIB_FILESIZE = "lib-size";
private static final String CONFIGKEY_DEP_FILENAME = "dep-apk";
private static final String CONFIGKEY_DEP_FILESIZE = "dep-size";
private boolean parseConfig(String jsonString){
mMogaSupportedDrives.clear();
mNibiruSupportedDrives.clear();
mOuyaSupportedDrives.clear();
try {
JSONObject configObject = new JSONObject(jsonString);
JSONObject nibiruObject = configObject.getJSONObject("nibiru");
JSONArray drives = nibiruObject.getJSONArray(CONFIGKEY_DRIVES);
int count = drives.length();
for (int i = 0; i < count; i++) {
mNibiruSupportedDrives.add(drives.getString(i));
}
mNibiruDepFileName = nibiruObject.getString(CONFIGKEY_DEP_FILENAME);
mNibiruDepFileSize = nibiruObject.getInt(CONFIGKEY_DEP_FILESIZE);
mNibiruLibFileName = nibiruObject.getString(CONFIGKEY_LIB_FILENAME);
mNibiruLibFileSize = nibiruObject.getInt(CONFIGKEY_LIB_FILESIZE);
JSONObject mogaObject = configObject.getJSONObject("moga");
drives = mogaObject.getJSONArray(CONFIGKEY_DRIVES);
count = drives.length();
for (int i = 0; i < count; i++) {
mMogaSupportedDrives.add(drives.getString(i));
}
mMogaDepFileName = mogaObject.getString(CONFIGKEY_DEP_FILENAME);
mMogaDepFileSize = mogaObject.getInt(CONFIGKEY_DEP_FILESIZE);
mMogaLibFileName = mogaObject.getString(CONFIGKEY_LIB_FILENAME);
mMogaLibFileSize = mogaObject.getInt(CONFIGKEY_LIB_FILESIZE);
JSONObject ouyaObject = configObject.getJSONObject("ouya");
drives = ouyaObject.getJSONArray(CONFIGKEY_DRIVES);
count = drives.length();
for (int i = 0; i < count; i++) {
mOuyaSupportedDrives.add(drives.getString(i));
}
mOuyaLibFileName = ouyaObject.getString(CONFIGKEY_LIB_FILENAME);
mOuyaLibFileSize = ouyaObject.getInt(CONFIGKEY_LIB_FILESIZE);
//mOuyaFrameworkFileName = ouyaObject.getString("dep-framework");
//mOuyaLauncherFileName = ouyaObject.getString("dep-launcher");
mLazyConfigInit = false;
return true;
} catch (Exception e1) {
e1.printStackTrace();
return false;
}
}
private void requestControllerConfig() {
final JsonHttpResponseHandler configResponseHandler = new JsonHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers,
String responseBody, Throwable e) {
Log.e(TAG, "Failed to download game controller config!");
String configJSON = GameControllerUtils.readJsonFile(mConfigFilePath);
if (configJSON != null) {
if (parseConfig(configJSON)) {
scanBluetoothDrive();
return;
}
}
if (mControllerListener != null) {
mControllerListener.onDownloadConfigFinished(false);
}
/*new AlertDialog.Builder(sCocos2dxActivity)
.setTitle("Loading controller config failed!")
.setMessage(
"Please make sure internet connection works ok!")
.setPositiveButton("Retry",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
requestControllerConfig();
}
}).setCancelable(false).show();*/
}
@Override
public void onSuccess(int statusCode, Header[] headers,
String responseBody) {
String jsonString = responseBody.trim();
try {
if (parseConfig(jsonString)) {
scanBluetoothDrive();
showToast("Get controller config succeed!");
File configFile = new File(mConfigFilePath);
FileOutputStream outputStream = new FileOutputStream(configFile);
byte[] contentString = jsonString.getBytes();
outputStream.write(contentString, 0, contentString.length);
outputStream.flush();
outputStream.close();
return;
}
else {
String jsonStr = GameControllerUtils.readJsonFile(mConfigFilePath);
if (jsonStr != null) {
if (parseConfig(jsonStr)) {
scanBluetoothDrive();
showToast("Get controller config succeed!");
return;
}
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
if (mControllerListener != null) {
mControllerListener.onDownloadConfigFinished(false);
}
Log.e(TAG, "Failed to download controller config!");
}
};
mDownDepsHttpClient.get(COCOS_CONTROLLER_URL + COCOS_CONTROLLER_CONFIG, configResponseHandler);
}
private static void showToast(String message){
Toast.makeText(sCocos2dxActivity, message, Toast.LENGTH_SHORT).show();
}
private static void createControllerInstance(String libFilePath,int sdkType) {
File libFile = new File(libFilePath);
if (! libFile.exists()) {
Log.w(TAG, libFile.toString() + "not exist!");
return;
}
DexClassLoader classLoader = null;
try {
File dexOutputDir = sCocos2dxActivity.getDir("dex", Context.MODE_PRIVATE);
classLoader = new DexClassLoader(libFile.getCanonicalPath(), dexOutputDir.getCanonicalPath(),
null, sCocos2dxActivity.getClassLoader());
} catch (Exception e1) {
e1.printStackTrace();
}
try {
Class<?> controllerDelegate = null;
if (sdkType == DRIVERTYPE_MOGA) {
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerMoga");
} else if (sdkType == DRIVERTYPE_NIBIRU) {
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerNibiru");
} else if (sdkType == DRIVERTYPE_OUYA) {
controllerDelegate = classLoader.loadClass("org.cocos2dx.lib.GameControllerOuya");
}
GameControllerDelegate instance = (GameControllerDelegate)controllerDelegate.newInstance();
if (mControllerListener != null) {
mControllerListener.onConnectController();
}
sCocos2dxActivity.setGameControllerInstance(instance);
if (sdkType == DRIVERTYPE_NIBIRU) {
Method method = controllerDelegate.getDeclaredMethod("onResume");
method.invoke(instance);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
private BroadcastReceiver mAppReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String packageName = intent.getDataString();
Log.d(TAG, "mAppReceiver:" + intent);
if (packageName.contains(NIBIRU_DEP_PACKAGE)) {
createControllerInstance(mLocalSavePath + mNibiruLibFileName, DRIVERTYPE_NIBIRU);
}
else if (packageName.contains(MOGA__DEP_PACKAGE)) {
createControllerInstance(mLocalSavePath + mMogaLibFileName, DRIVERTYPE_MOGA);
}
}
};
private float mOldLeftThumbstickX = 0.0f;
private float mOldLeftThumbstickY = 0.0f;
private float mOldRightThumbstickX = 0.0f;
private float mOldRightThumbstickY = 0.0f;
private float mOldLeftTrigger = 0.0f;
private float mOldRightTrigger = 0.0f;
private float mOldThrottle = 0.0f;
private float mOldBrake = 0.0f;
public boolean dispatchGenericMotionEvent(MotionEvent event) {
boolean handled = false;
int eventSource = event.getSource();
if ( ((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) )
{
if (event.getAction() == MotionEvent.ACTION_MOVE) {
int devicedId = event.getDeviceId();
float newAXIS_LX = event.getAxisValue(MotionEvent.AXIS_X);
if (Float.compare(newAXIS_LX , mOldLeftThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_X, newAXIS_LX, true);
mOldLeftThumbstickX = newAXIS_LX;
handled = true;
}
float newAXIS_LY = event.getAxisValue(MotionEvent.AXIS_Y);
if (Float.compare(newAXIS_LY , mOldLeftThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_LEFT_Y, newAXIS_LY, true);
mOldLeftThumbstickY = newAXIS_LY;
handled = true;
}
float newAXIS_RX = event.getAxisValue(MotionEvent.AXIS_Z);
if (Float.compare(newAXIS_RX , mOldRightThumbstickX) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_X, newAXIS_RX, true);
mOldRightThumbstickX = newAXIS_RX;
handled = true;
}
float newAXIS_RY = event.getAxisValue(MotionEvent.AXIS_RZ);
if (Float.compare(newAXIS_RY , mOldRightThumbstickY) != 0) {
GameControllerAdapter.onAxisEvent(StandardControllerName, devicedId, GameControllerDelegate.THUMBSTICK_RIGHT_Y, newAXIS_RY, true);
mOldRightThumbstickY = newAXIS_RY;
handled = true;
}
float newAXIS_LTRIGGER = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
if (Float.compare(newAXIS_LTRIGGER , mOldLeftTrigger) != 0) {
if (Float.compare(newAXIS_LTRIGGER, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_LTRIGGER, true);
}
mOldLeftTrigger = newAXIS_LTRIGGER;
handled = true;
}
float newAXIS_RTRIGGER = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
if (Float.compare(newAXIS_RTRIGGER , mOldRightTrigger) != 0) {
if (Float.compare(newAXIS_RTRIGGER, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_RTRIGGER, true);
}
mOldRightTrigger = newAXIS_RTRIGGER;
handled = true;
}
float newAXIS_BRAKE = event.getAxisValue(MotionEvent.AXIS_BRAKE);
if (Float.compare(newAXIS_BRAKE , mOldBrake) != 0) {
if (Float.compare(newAXIS_BRAKE, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_LEFT_TRIGGER, true, newAXIS_BRAKE, true);
}
mOldBrake = newAXIS_BRAKE;
handled = true;
}
float newAXIS_THROTTLE = event.getAxisValue(MotionEvent.AXIS_THROTTLE);
if (Float.compare(newAXIS_THROTTLE , mOldThrottle) != 0) {
if (Float.compare(newAXIS_THROTTLE, 0.0f) == 0) {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, false, 0.0f, true);
}else {
GameControllerAdapter.onButtonEvent(StandardControllerName, devicedId, GameControllerDelegate.BUTTON_RIGHT_TRIGGER, true, newAXIS_THROTTLE, true);
}
mOldThrottle = newAXIS_THROTTLE;
handled = true;
}
}
}
return handled;
}
public boolean dispatchKeyEvent(KeyEvent event) {
boolean handled = false;
int eventSource = event.getSource();
int controllerKey = ControllerKeyMap.get(event.getKeyCode());
if (controllerKey != 0 && (((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)
|| ((eventSource & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD)))
{
int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
handled = true;
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,true, 1.0f, false);
}else if (action == KeyEvent.ACTION_UP) {
handled = true;
GameControllerAdapter.onButtonEvent(StandardControllerName,event.getDeviceId(), controllerKey,false, 0.0f, false);
}
}
return handled;
}
}

View File

@ -65,6 +65,7 @@ public:
const Mat4& getReverseOrientationMatrix () const {return m_reverseOrientationMatrix;};
Windows::Graphics::Display::DisplayOrientations getDeviceOrientation() {return m_orientation;};
Size getRenerTargetSize() const { return Size(m_width, m_height); }
virtual void setIMEKeyboardState(bool bOpen);
void ShowKeyboard(Windows::Foundation::Rect r);

View File

@ -61,7 +61,7 @@ namespace {
typedef Texture2D::PixelFormatInfoMap::value_type PixelFormatInfoMapValue;
static const PixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] =
{
PixelFormatInfoMapValue(Texture2D::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::BGRA8888, Texture2D::PixelFormatInfo(GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, 32, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA8888, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, 32, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGBA4444, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, 16, false, true)),
PixelFormatInfoMapValue(Texture2D::PixelFormat::RGB5A1, Texture2D::PixelFormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, 16, false, true)),
@ -1032,6 +1032,14 @@ rgba(1) -> 12345678
*/
Texture2D::PixelFormat Texture2D::convertDataToFormat(const unsigned char* data, ssize_t dataLen, PixelFormat originFormat, PixelFormat format, unsigned char** outData, ssize_t* outDataLen)
{
// don't need to convert
if (format == originFormat || format == PixelFormat::AUTO)
{
*outData = (unsigned char*)data;
*outDataLen = dataLen;
return originFormat;
}
switch (originFormat)
{
case PixelFormat::I8:

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module ActionTimelineCache
-- @parent_module ccs
--------------------------------
-- @function [parent=#ActionTimelineCache] createAction

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module Application
-- @parent_module cc
--------------------------------
-- @function [parent=#Application] getTargetPlatform

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module Console
-- @parent_module cc
--------------------------------
-- @function [parent=#Console] stop

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module Director
-- @parent_module cc
--------------------------------
-- @function [parent=#Director] pause

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module FileUtils
-- @parent_module cc
--------------------------------
-- @function [parent=#FileUtils] fullPathForFilename

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module GLViewProtocol
-- @parent_module cc
--------------------------------
-- @function [parent=#GLViewProtocol] setFrameSize

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module Helper
-- @parent_module ccui
--------------------------------
-- @function [parent=#Helper] seekWidgetByTag

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module NodeReader
-- @parent_module ccs
--------------------------------
-- @function [parent=#NodeReader] setJsonPath

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module PhysicsContactPostSolve
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsContactPostSolve] getFriction

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module PhysicsContactPreSolve
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsContactPreSolve] getFriction

View File

@ -1,5 +1,6 @@
--------------------------------
-- @module PhysicsDebugDraw
-- @parent_module cc
return nil

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module PhysicsJoint
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsJoint] getBodyA

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module PhysicsWorld
-- @parent_module cc
--------------------------------
-- @function [parent=#PhysicsWorld] getGravity

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module Ref
-- @parent_module cc
--------------------------------
-- @function [parent=#Ref] release

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module SceneReader
-- @parent_module ccs
--------------------------------
-- @function [parent=#SceneReader] setTarget

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module SimpleAudioEngine
-- @parent_module cc
--------------------------------
-- @function [parent=#SimpleAudioEngine] preloadBackgroundMusic

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module TMXMapInfo
-- @parent_module cc
--------------------------------
-- @function [parent=#TMXMapInfo] setObjectGroups

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module TransitionEaseScene
-- @parent_module cc
--------------------------------
-- @function [parent=#TransitionEaseScene] easeActionWithAction

View File

@ -1,6 +1,7 @@
--------------------------------
-- @module UserDefault
-- @parent_module cc
--------------------------------
-- @function [parent=#UserDefault] setIntegerForKey

View File

@ -945,6 +945,7 @@
);
"OTHER_LDFLAGS[arch=arm64]" = "-llua";
"OTHER_LDFLAGS[sdk=iphonesimulator7.1]" = "-llua";
"OTHER_LDFLAGS[sdk=iphonesimulator8.0]" = "-llua";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../../platform/ios";
@ -970,6 +971,7 @@
);
"OTHER_LDFLAGS[arch=arm64]" = "-llua";
"OTHER_LDFLAGS[sdk=iphonesimulator7.1]" = "-llua";
"OTHER_LDFLAGS[sdk=iphonesimulator8.0]" = "-llua";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
USER_HEADER_SEARCH_PATHS = "$(inherited) $(SRCROOT)/../../../platform/ios";

View File

@ -1104,7 +1104,7 @@ Vec2 Layout::getWorldCenterPoint(Widget* widget)const
return widget->convertToWorldSpace(Vec2(widgetSize.width/2, widgetSize.height/2));
}
float Layout::caculateNearestDistance(Widget* baseWidget)
float Layout::calculateNearestDistance(Widget* baseWidget)
{
float distance = FLT_MAX;
@ -1114,7 +1114,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
Layout *layout = dynamic_cast<Layout*>(node);
int length;
if (layout) {
length = layout->caculateNearestDistance(baseWidget);
length = layout->calculateNearestDistance(baseWidget);
}
else
{
@ -1137,7 +1137,7 @@ float Layout::caculateNearestDistance(Widget* baseWidget)
return distance;
}
float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget)
float Layout::calculateFarestDistance(cocos2d::ui::Widget *baseWidget)
{
float distance = -FLT_MAX;
@ -1147,7 +1147,7 @@ float Layout::caculateFarestDistance(cocos2d::ui::Widget *baseWidget)
Layout *layout = dynamic_cast<Layout*>(node);
int length;
if (layout) {
length = layout->caculateFarestDistance(baseWidget);
length = layout->calculateFarestDistance(baseWidget);
}
else
{
@ -1194,7 +1194,8 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
float distance = FLT_MAX;
int found = 0;
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT ||
direction == FocusDirection::DOWN || direction == FocusDirection::UP)
{
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
@ -1207,7 +1208,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateNearestDistance(baseWidget);
length = layout->calculateNearestDistance(baseWidget);
}
else
{
@ -1225,39 +1226,7 @@ int Layout::findNearestChildWidgetIndex(FocusDirection direction, Widget* baseWi
return found;
}
index = 0;
found = 0;
distance = FLT_MAX;
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
{
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
if (w && w->isFocusEnabled())
{
Vec2 wPosition = this->getWorldCenterPoint(w);
float length;
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateNearestDistance(baseWidget);
}
else
{
length = (wPosition - widgetPosition).getLength();
}
if (length < distance)
{
found = index;
distance = length;
}
}
index++;
}
return found;
}
CCASSERT(0, "invalid focus direction!!!");
return 0;
}
@ -1273,7 +1242,8 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
float distance = -FLT_MAX;
int found = 0;
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT)
if (direction == FocusDirection::LEFT || direction == FocusDirection::RIGHT
|| direction == FocusDirection::DOWN || direction == FocusDirection::UP)
{
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
@ -1286,7 +1256,7 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateFarestDistance(baseWidget);
length = layout->calculateFarestDistance(baseWidget);
}
else
{
@ -1304,39 +1274,6 @@ int Layout::findFarestChildWidgetIndex(FocusDirection direction, cocos2d::ui::Wi
return found;
}
index = 0;
found = 0;
distance = -FLT_MAX;
if (direction == FocusDirection::DOWN || direction == FocusDirection::UP) {
Vec2 widgetPosition = this->getWorldCenterPoint(baseWidget);
while (index < count)
{
Widget *w = dynamic_cast<Widget*>(this->getChildren().at(index));
if (w && w->isFocusEnabled())
{
Vec2 wPosition = this->getWorldCenterPoint(w);
float length;
Layout *layout = dynamic_cast<Layout*>(w);
if (layout)
{
length = layout->caculateFarestDistance(baseWidget);
}
else
{
length = (wPosition - widgetPosition).getLength();
}
if (length > distance)
{
found = index;
distance = length;
}
}
index++;
}
return found;
}
CCASSERT(0, "invalid focus direction!!!");
return 0;
}
@ -1368,6 +1305,9 @@ Widget *Layout::findFirstNonLayoutWidget()
Layout* layout = dynamic_cast<Layout*>(node);
if (layout) {
widget = layout->findFirstNonLayoutWidget();
if (widget != nullptr) {
return widget;
}
}
else{
Widget *w = dynamic_cast<Widget*>(node);

View File

@ -376,7 +376,7 @@ protected:
*@param the base widget which will be used to caculate the distance between the layout's children and itself
*@return return the nearest distance between the baseWidget and the layout's children
*/
float caculateNearestDistance(Widget* baseWidget);
float calculateNearestDistance(Widget* baseWidget);
/**
* caculate the farest distance between the baseWidget and the children of the layout
@ -384,7 +384,7 @@ protected:
*@return return the farest distance between the baseWidget and the layout's children
*/
float caculateFarestDistance(Widget* baseWidget);
float calculateFarestDistance(Widget* baseWidget);
/**
* when a layout pass the focus to it's child, use this method to determine which algorithm to use, nearest or farest distance algorithm or not

View File

@ -852,7 +852,7 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
bool ScrollView::scrollChildrenVertical(float touchOffsetX, float touchOffsetY)
{
float realOffset = touchOffsetY;
bool scrollEnabled = false;
bool scrollEnabled = true;
if (_bounceEnabled)
{
float icBottomPos = _innerContainer->getBottomBoundary();
@ -894,7 +894,7 @@ bool ScrollView::scrollChildrenVertical(float touchOffsetX, float touchOffsetY)
bool ScrollView::scrollChildrenHorizontal(float touchOffsetX, float touchOffestY)
{
bool scrollenabled = false;
bool scrollenabled = true;
float realOffset = touchOffsetX;
if (_bounceEnabled)
{
@ -936,7 +936,7 @@ bool ScrollView::scrollChildrenHorizontal(float touchOffsetX, float touchOffestY
bool ScrollView::scrollChildrenBoth(float touchOffsetX, float touchOffsetY)
{
bool scrollenabled = false;
bool scrollenabled = true;
float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY;
if (_bounceEnabled)

View File

@ -747,38 +747,23 @@
"cocos/platform/android/CCGLView.h",
"cocos/platform/android/CCPlatformDefine.h",
"cocos/platform/android/CCStdC.h",
"cocos/platform/android/ControllerDelegate/.classpath",
"cocos/platform/android/ControllerDelegate/.project",
"cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerDelegate/AndroidManifest.xml",
"cocos/platform/android/ControllerDelegate/ant.properties",
"cocos/platform/android/ControllerDelegate/build.xml",
"cocos/platform/android/ControllerDelegate/proguard-project.txt",
"cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java",
"cocos/platform/android/ControllerMoga/.classpath",
"cocos/platform/android/ControllerMoga/.project",
"cocos/platform/android/ControllerMoga/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerMoga/AndroidManifest.xml",
"cocos/platform/android/ControllerMoga/ant.properties",
"cocos/platform/android/ControllerMoga/build.xml",
"cocos/platform/android/ControllerMoga/proguard-project.txt",
"cocos/platform/android/ControllerMoga/src/org/cocos2dx/lib/GameControllerMoga.java",
"cocos/platform/android/ControllerNibiru/.classpath",
"cocos/platform/android/ControllerNibiru/.project",
"cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerNibiru/AndroidManifest.xml",
"cocos/platform/android/ControllerNibiru/ant.properties",
"cocos/platform/android/ControllerNibiru/build.xml",
"cocos/platform/android/ControllerNibiru/proguard-project.txt",
"cocos/platform/android/ControllerNibiru/src/org/cocos2dx/lib/GameControllerNibiru.java",
"cocos/platform/android/ControllerOuya/.classpath",
"cocos/platform/android/ControllerOuya/.project",
"cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerOuya/AndroidManifest.xml",
"cocos/platform/android/ControllerOuya/ant.properties",
"cocos/platform/android/ControllerOuya/build.xml",
"cocos/platform/android/ControllerOuya/proguard-project.txt",
"cocos/platform/android/ControllerOuya/src/org/cocos2dx/lib/GameControllerOuya.java",
"cocos/platform/android/ControllerManualAdapter/.classpath",
"cocos/platform/android/ControllerManualAdapter/.project",
"cocos/platform/android/ControllerManualAdapter/.settings/org.eclipse.jdt.core.prefs",
"cocos/platform/android/ControllerManualAdapter/AndroidManifest.xml",
"cocos/platform/android/ControllerManualAdapter/ant.properties",
"cocos/platform/android/ControllerManualAdapter/build.xml",
"cocos/platform/android/ControllerManualAdapter/lint.xml",
"cocos/platform/android/ControllerManualAdapter/proguard-project.txt",
"cocos/platform/android/ControllerManualAdapter/project.properties",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
"cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
"cocos/platform/android/java/.classpath",
"cocos/platform/android/java/.project",
"cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs",
@ -807,11 +792,8 @@
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerHelper.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java",
"cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java",
"cocos/platform/android/javaactivity.cpp",
"cocos/platform/android/jni/DPIJni.cpp",
"cocos/platform/android/jni/DPIJni.h",

View File

@ -33,7 +33,7 @@ void CurlTest::onTouchesEnded(const std::vector<Touch*>& touches, Event *event)
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "google.com");
curl_easy_setopt(curl, CURLOPT_URL, "baidu.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);

Some files were not shown because too many files have changed in this diff Show More