فهرست منبع

Merge branch 'dev' into remove-_class

dmuratshin 9 سال پیش
والد
کامیت
bd6765ef7c

+ 1 - 0
.gitignore

@@ -64,3 +64,4 @@ build
 .DS_Store
 *.VC.db
 *.VC.VC.opendb
+oxygine/SDL/win32/oxygine.vcxproj.user

BIN
doc/doc.zip


BIN
doc/wiki.zip


BIN
libs/SDL2.dll


BIN
libs/SDL2.lib


BIN
libs/SDL2main.lib


+ 39 - 25
oxygine/SDL/android/lib/src/org/libsdl/app/SDLActivity.java

@@ -369,7 +369,10 @@ public class SDLActivity extends Activity {
                 break;
             case COMMAND_TEXTEDIT_HIDE:
                 if (mTextEdit != null) {
-                    mTextEdit.setVisibility(View.GONE);
+                    // Note: On some devices setting view to GONE creates a flicker in landscape.
+                    // Setting the View's sizes to 0 is similar to GONE but without the flicker.
+                    // The sizes will be set to useful values when the keyboard is shown again.
+                    mTextEdit.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
 
                     InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                     imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
@@ -724,6 +727,21 @@ public class SDLActivity extends Activity {
         }
     }
 
+    // Check if a given device is considered a possible SDL joystick
+    public static boolean isDeviceSDLJoystick(int deviceId) {
+        InputDevice device = InputDevice.getDevice(deviceId);
+        // We cannot use InputDevice.isVirtual before API 16, so let's accept
+        // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
+        if ((device == null) || (deviceId < 0)) {
+            return false;
+        }
+        int sources = device.getSources();
+        return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) ||
+                ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
+                ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
+        );
+    }
+
     // APK expansion files support
 
     /** com.android.vending.expansion.zipfile.ZipResourceFile object or null. */
@@ -1220,23 +1238,25 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
     @Override
     public boolean onKey(View  v, int keyCode, KeyEvent event) {
         // Dispatch the different events depending on where they come from
-        // Some SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
-        // So, we try to process them as DPAD or GAMEPAD events first, if that fails we try them as KEYBOARD
-
-        if ( (event.getSource() & InputDevice.SOURCE_GAMEPAD) != 0 ||
-                   (event.getSource() & InputDevice.SOURCE_DPAD) != 0 ) {
+        // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD
+        // So, we try to process them as JOYSTICK/DPAD/GAMEPAD events first, if that fails we try them as KEYBOARD
+        //
+        // Furthermore, it's possible a game controller has SOURCE_KEYBOARD and
+        // SOURCE_JOYSTICK, while its key events arrive from the keyboard source
+        // So, retrieve the device itself and check all of its sources
+        if (SDLActivity.isDeviceSDLJoystick(event.getDeviceId())) {
+            // Note that we always process a pressed/released button here, as an unopened
+            // SDL_Joystick's button press should not be processed as a keyboard's key press
             if (event.getAction() == KeyEvent.ACTION_DOWN) {
-                if (SDLActivity.onNativePadDown(event.getDeviceId(), keyCode) == 0) {
-                    return true;
-                }
+                SDLActivity.onNativePadDown(event.getDeviceId(), keyCode);
+                return true;
             } else if (event.getAction() == KeyEvent.ACTION_UP) {
-                if (SDLActivity.onNativePadUp(event.getDeviceId(), keyCode) == 0) {
-                    return true;
-                }
+                SDLActivity.onNativePadUp(event.getDeviceId(), keyCode);
+                return true;
             }
         }
 
-        if( (event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
+        if ((event.getSource() & InputDevice.SOURCE_KEYBOARD) != 0) {
             if (event.getAction() == KeyEvent.ACTION_DOWN) {
                 //Log.v("SDL", "key down: " + keyCode);
                 SDLActivity.onNativeKeyDown(keyCode);
@@ -1395,7 +1415,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
             }
             SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
                                       y / SensorManager.GRAVITY_EARTH,
-                                      event.values[2] / SensorManager.GRAVITY_EARTH - 1);
+                                      event.values[2] / SensorManager.GRAVITY_EARTH);
         }
     }
 }
@@ -1422,7 +1442,7 @@ class DummyEdit extends View implements View.OnKeyListener {
     public boolean onKey(View v, int keyCode, KeyEvent event) {
 
         // This handles the hardware keyboard input
-        if (event.isPrintingKey()) {
+        if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
             if (event.getAction() == KeyEvent.ACTION_DOWN) {
                 ic.commitText(String.valueOf((char) event.getUnicodeChar()), 1);
             }
@@ -1485,7 +1505,7 @@ class SDLInputConnection extends BaseInputConnection {
          */
         int keyCode = event.getKeyCode();
         if (event.getAction() == KeyEvent.ACTION_DOWN) {
-            if (event.isPrintingKey()) {
+            if (event.isPrintingKey() || keyCode == KeyEvent.KEYCODE_SPACE) {
                 commitText(String.valueOf((char) event.getUnicodeChar()), 1);
             }
             SDLActivity.onNativeKeyDown(keyCode);
@@ -1586,13 +1606,7 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
             if (joystick == null) {
                 joystick = new SDLJoystick();
                 InputDevice joystickDevice = InputDevice.getDevice(deviceIds[i]);
-
-                if ( 
-                      (joystickDevice.getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 
-                   ||
-                      (joystickDevice.getSources() & InputDevice.SOURCE_CLASS_BUTTON) != 0 
-                  )
-                {
+                if (SDLActivity.isDeviceSDLJoystick(deviceIds[i])) {
                     joystick.device_id = deviceIds[i];
                     joystick.name = joystickDevice.getName();
                     joystick.axes = new ArrayList<InputDevice.MotionRange>();
@@ -1601,7 +1615,7 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
                     List<InputDevice.MotionRange> ranges = joystickDevice.getMotionRanges();
                     Collections.sort(ranges, new RangeComparator());
                     for (InputDevice.MotionRange range : ranges ) {
-                        if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 ) {
+                        if ((range.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
                             if (range.getAxis() == MotionEvent.AXIS_HAT_X ||
                                 range.getAxis() == MotionEvent.AXIS_HAT_Y) {
                                 joystick.hats.add(range);
@@ -1655,7 +1669,7 @@ class SDLJoystickHandler_API12 extends SDLJoystickHandler {
 
     @Override
     public boolean handleMotionEvent(MotionEvent event) {
-        if ( (event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
+        if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
             int actionPointerIndex = event.getActionIndex();
             int action = event.getActionMasked();
             switch(action) {

+ 16 - 7
oxygine/src/res/Resources.cpp

@@ -127,6 +127,11 @@ namespace oxygine
         __freeName();
     }
 
+    bool Resources::isEmpty() const
+    {
+        return _docs.empty();
+    }
+
     void Resources::updateName(const std::string& filename)
     {
         char head[256];
@@ -167,7 +172,7 @@ namespace oxygine
     };
 
 
-    void Resources::loadXML(const std::string& xmlFile, const ResourcesLoadOptions& opt)
+    bool Resources::loadXML(const std::string& xmlFile, const ResourcesLoadOptions& opt)
     {
         _name = xmlFile;
         _loadCounter = opt._loadCompletely ? 1 : 0;
@@ -175,7 +180,15 @@ namespace oxygine
 
         FS_LOG("step0");
         file::buffer fb;
-        file::read(xmlFile, fb);
+        int sz = file::read(xmlFile, fb);
+
+
+        if (!sz)
+        {
+            log::error("can't load xml file: '%s'", xmlFile.c_str());
+            OX_ASSERT(!"can't find xml file");
+            return false;
+        }
 
         FS_LOG("step1");
 
@@ -207,11 +220,6 @@ namespace oxygine
                 doc_meta.load_buffer_inplace(&fb_meta.data[0], fb_meta.data.size());
         }
 
-        if (!fb.data.size())
-        {
-            OX_ASSERT(fb.data.size() && "can't find xml file");
-            return;
-        }
 
         pugi::xml_document* doc = new pugi::xml_document();
         _docs.push_back(doc);
@@ -279,6 +287,7 @@ namespace oxygine
         }
 
         FS_LOG("xml loaded");
+        return true;
     }
 
     void Resources::collect(resources& r)

+ 4 - 1
oxygine/src/res/Resources.h

@@ -79,7 +79,7 @@ namespace oxygine
         @param xml file paths
         @param options
         */
-        void loadXML(const std::string& xmlFile, const ResourcesLoadOptions& opt = ResourcesLoadOptions());
+        bool loadXML(const std::string& xmlFile, const ResourcesLoadOptions& opt = ResourcesLoadOptions());
 
         /**Adds Resource*/
         void add(Resource* r, bool accessByShortenID = false);
@@ -93,6 +93,9 @@ namespace oxygine
         /**Completely deletes all loaded resources*/
         void free();
 
+        /**Does it have any loaded xmls*/
+        bool isEmpty() const;
+
         /** get resource by id, no case sensitive
         @param resource id
         */

+ 4 - 0
tools/others/build_oxygine_with_sdl.py

@@ -58,12 +58,14 @@ SDL_dest = temp + "/SDL"
 OXYGINE_dest = temp + "/oxygine-framework/"
 SOUND_dest = temp + "/oxygine-sound/"
 FLOW_dest = temp + "/oxygine-flow/"
+FT_dest = temp + "/oxygine-freetype/"
 
 print("cleaning temp...")
 shutil.rmtree(temp, True)
 
 
 def export(repo, dest):
+    print("exporting " + repo)
     cmd = "git -C %s checkout-index -a -f --prefix=%s/" % (
         "d:/" + repo, "d:/oxygine-framework/temp/" + dest)
     os.system(cmd)
@@ -77,6 +79,7 @@ buildzip("oxygine-framework.zip")
 export("SDL", "SDL")
 export("oxygine-sound", "oxygine-sound")
 export("oxygine-flow", "oxygine-flow")
+export("oxygine-freetype", "oxygine-freetype")
 
 
 shutil.rmtree(SDL_dest + "/test")
@@ -125,6 +128,7 @@ def copy(path):
 enum(OXYGINE_dest + "/examples/", copy)
 enum(SOUND_dest + "/examples/", copy)
 enum(FLOW_dest + "/examples/", copy)
+enum(FT_dest + "/examples/", copy)
 
 shutil.copy(SDL_dest + "/android-project/src/org/libsdl/app/SDLActivity.java",
             OXYGINE_dest + "/oxygine/SDL/android/lib/src/org/libsdl/app/SDLActivity.java")

+ 5 - 2
tools/resbuild/xml_processor.py

@@ -138,8 +138,11 @@ class XmlProcessor(object):
         self._npot = args.npot
         #self._meta_element = None
 
-        self.helper = oxygine_helper.helper(
-            os.path.split(__file__)[0] + "/../../")
+        rp = os.path.abspath(__file__) 
+        rp = os.path.dirname(rp)
+        rp = os.path.join(rp, "../../")
+        rp = os.path.normpath(rp) + "/"
+        self.helper = oxygine_helper.helper(rp)
 
         self.register_processor(process_font.bmfc_font_Processor())
         self.register_processor(process_font.font_Processor())