Просмотр исходного кода

Merge branch 'dev' into new-render

# Conflicts:
#	oxygine/src/oxygine/core/oxygine.cpp
#	tools/others/update_examples_entry.py
[email protected] 8 лет назад
Родитель
Сommit
990a9593de

+ 2 - 2
examples/Demo/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/DemoBox2D/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Game/part1/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Game/part2/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Game/part3/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Game/part4/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Game/part5/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/HelloWorld/src/main.cpp

@@ -86,7 +86,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -152,7 +152,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 2 - 2
examples/Match3/src/main.cpp

@@ -85,7 +85,7 @@ void run()
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
     // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
-    return;
+    //return;
 #endif
 
     // This is the main game loop.
@@ -151,7 +151,7 @@ extern "C"
 
 #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
         // If parameter 2 is set to 1, refresh rate will be 60 fps, 2 - 30 fps, 3 - 15 fps.
-        SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
+        //SDL_iPhoneSetAnimationCallback(core::getWindow(), 1, one, nullptr);
 #endif
 
 #if EMSCRIPTEN

+ 5 - 0
oxygine/src/oxygine/HttpRequestTask.cpp

@@ -116,6 +116,11 @@ namespace oxygine
         return _fname;
     }
 
+    const std::string& HttpRequestTask::getUrl() const
+    {
+        return _url;
+    }
+
     bool HttpRequestTask::_prerun()
     {
         _progressDeltaDelayed = 0;

+ 1 - 0
oxygine/src/oxygine/HttpRequestTask.h

@@ -44,6 +44,7 @@ namespace oxygine
         const std::vector<unsigned char>&   getResponse() const;
         const std::vector<unsigned char>&   getPostData() const;
         const std::string&                  getFileName() const;
+        const std::string&                  getUrl() const;
 
 
         /**swap version of getResponse if you want to modify result buffer inplace*/

+ 21 - 25
oxygine/src/oxygine/InputText.cpp

@@ -32,18 +32,10 @@ namespace oxygine
 
     void InputText::start(spTextField ta)
     {
-#ifdef __S3E__
-        log::error("InputText isn't implemented for MARMALADE");
-#endif
-
         addRef();
 
-        //if (_active == this)
-        //  return;
         if (_active)
-        {
             _active->stop();
-        }
 
         _active = this;
 
@@ -51,14 +43,28 @@ namespace oxygine
 
         core::getDispatcher()->addEventListener(core::EVENT_SYSTEM, CLOSURE(this, &InputText::_onSysEvent));
 
-#ifndef __S3E__
         SDL_StartTextInput();
-#endif
-        //log::messageln("InputText::start  %x", this);
+
         _txt = "";
         updateText();
     }
 
+
+
+    void InputText::stop()
+    {
+        if (!_textActor)
+            return;
+
+        SDL_StopTextInput();
+        core::getDispatcher()->removeEventListeners(this);
+
+        _active = 0;
+        _textActor = 0;
+        //log::messageln("InputText::stop  %x", this);
+        releaseRef();
+    }
+
     void InputText::setAllowedSymbols(const std::string& utf8str)
     {
         _allowed = utf8str;
@@ -84,19 +90,6 @@ namespace oxygine
         _maxLength = v;
     }
 
-    void InputText::stop()
-    {
-#ifndef __S3E__
-        SDL_StopTextInput();
-#endif
-        core::getDispatcher()->removeEventListeners(this);
-
-        _active = 0;
-        _textActor = 0;
-        //log::messageln("InputText::stop  %x", this);
-        releaseRef();
-    }
-
     void InputText::_onSysEvent(Event* event)
     {
 #ifndef __S3E__
@@ -107,6 +100,9 @@ namespace oxygine
     void InputText::updateText()
     {
         _textActor->setText(_txt);
+
+        Event evnt(EVENT_TEXT_CHANGED);
+        dispatchEvent(&evnt);
     }
 
     bool findCode(const char* str, int c)
@@ -210,7 +206,7 @@ namespace oxygine
                     break;
                     case SDLK_RETURN:
                     {
-                        Event evnt(Event::COMPLETE);
+                        Event evnt(EVENT_COMPLETE);
                         dispatchEvent(&evnt);
                     }
                     break;

+ 4 - 0
oxygine/src/oxygine/InputText.h

@@ -1,6 +1,7 @@
 #pragma once
 #include "oxygine-include.h"
 #include "EventDispatcher.h"
+#include "Event.h"
 #include <string>
 
 #ifndef __S3E__
@@ -14,6 +15,9 @@ namespace oxygine
     class InputText: public EventDispatcher
     {
     public:
+        enum {EVENT_TEXT_CHANGED = sysEventID('I', 'T', 'C') };
+        enum {EVENT_COMPLETE = Event::COMPLETE};
+
         InputText();
         ~InputText();
 

+ 2 - 0
oxygine/src/oxygine/actor/TextField.cpp

@@ -374,6 +374,8 @@ namespace oxygine
             stream << " " << (s.breakLongWords ? "breakLongWords=1" : "breakLongWords=0");
         if (!onlydiff || def.kerning != s.kerning)
             stream << " kerning=" << s.kerning;
+        if (!onlydiff || def.baselineScale != s.baselineScale)
+            stream << " baselineScale=" << s.baselineScale;
         if (!onlydiff || def.linesOffset != s.linesOffset)
             stream << " linesOffset=" << s.linesOffset;
         if (!onlydiff || def.fontSize != s.fontSize)

+ 56 - 16
oxygine/src/oxygine/actor/WebImage.cpp

@@ -15,7 +15,7 @@ namespace oxygine
     }
 
 
-    WebImage::WebImage() : _http(0)
+    WebImage::WebImage() : _http(0), _allowSwap(false)
     {
         setSize(64, 64);
         _image = new Sprite;
@@ -30,39 +30,65 @@ namespace oxygine
 
     void WebImage::load(const std::string& url)
     {
+        _allowSwap = true;
         _image->setResAnim(0);
 
-        _http = HttpRequestTask::create();
-        if (!_http)
+        spHttpRequestTask task = HttpRequestTask::create();
+        if (!task)
             return;
-        _http->setUrl(url);
-        _http->run();
+        task->setUrl(url);
+        task->run();
 
-        addRef();//protect actor for delete
-        _http->addEventListener(AsyncTask::COMPLETE, CLOSURE(this, &WebImage::loaded));
-        _http->addEventListener(AsyncTask::ERROR, CLOSURE(this, &WebImage::error));
+        _load(task);
     }
 
-    void WebImage::error(Event* e)
+    void WebImage::load(spHttpRequestTask task)
     {
-        dispatchEvent(e);
-        releaseRef();
-        _http = 0;
+        _allowSwap = false;
+        _image->setResAnim(0);
+        _load(task);
     }
 
-    void WebImage::loaded(Event* e)
+    void WebImage::_load(spHttpRequestTask task)
     {
-        if (_ref_counter <= 1)//if it is already dead
+        _http = task;
+
+        if (task->getStatus() == HttpRequestTask::status_completed)
         {
-            releaseRef();
+            init();
             return;
         }
 
+        if (task->getStatus() == HttpRequestTask::status_failed)
+        {
+            return;
+        }
+
+
+        addRef();//protect actor from delete
+        _http->addEventListener(AsyncTask::COMPLETE, CLOSURE(this, &WebImage::loaded));
+        _http->addEventListener(AsyncTask::ERROR, CLOSURE(this, &WebImage::error));
+    }
 
+    void WebImage::error(Event* e)
+    {
         dispatchEvent(e);
+        releaseRef();
+        _http = 0;
+    }
 
+    void WebImage::init()
+    {
         file::buffer bf;
-        _http->getResponseSwap(bf.data);
+        if (_allowSwap)
+        {
+            _http->getResponseSwap(bf.data);
+            _allowSwap = false;
+        }
+        else
+        {
+            bf.data = _http->getResponse();
+        }
 
         Image mt;
         if (mt.init(bf, true))
@@ -72,7 +98,21 @@ namespace oxygine
 
             fit();
         }
+        _http = 0;
+    }
+
+    void WebImage::loaded(Event* e)
+    {
+        if (_ref_counter <= 1)//if it is already dead
+        {
+            releaseRef();
+            return;
+        }
+
+
+        dispatchEvent(e);
 
+        init();
         _http = 0;
         releaseRef();
     }

+ 6 - 0
oxygine/src/oxygine/actor/WebImage.h

@@ -17,19 +17,25 @@ namespace oxygine
         ~WebImage();
 
         void load(const std::string& url);
+        void load(spHttpRequestTask task);
         void unload();
 
     private:
+        void _load(spHttpRequestTask task);
+
         void loaded(Event*);
         void error(Event*);
         void sizeChanged(const Vector2& size) override;
         void fit();
 
+        void init();
+
         ResAnim _rs;
 
         spSprite _image;
 
         spHttpRequestTask _http;
+        bool _allowSwap;
     };
 }
 

+ 12 - 0
oxygine/src/oxygine/core/android/jniHelper.cpp

@@ -37,4 +37,16 @@ namespace oxygine
             res.emplace_back(str);
         }
     }
+
+    jobjectArray jniGetObjectStringArray(const vector<std::string>& src, JNIEnv* env)
+    {
+        jobjectArray res = env->NewObjectArray(src.size(), env->FindClass("java/lang/String"), nullptr);
+
+        for (size_t i = 0; i < src.size(); ++i)
+        {
+            env->SetObjectArrayElement(res, i, env->NewStringUTF(src[i].c_str()));
+        }
+
+        return res;
+    }
 }

+ 2 - 0
oxygine/src/oxygine/core/android/jniHelper.h

@@ -48,4 +48,6 @@ namespace oxygine
 
     std::string jniGetString(JNIEnv* env, jstring jstr);
     void        jniGetStringArray(vector<std::string>& res, JNIEnv* env, jobjectArray jarray);
+    jobjectArray jniGetObjectStringArray(const vector<std::string>& src, JNIEnv* env);
+
 }

+ 3 - 77
oxygine/src/oxygine/core/oxygine.cpp

@@ -103,83 +103,6 @@ namespace oxygine
 
     static pthread_t _mainThread;
 
-#ifdef __S3E__
-
-    int32 pointerEvent(void* sysData, void* u)
-    {
-        s3ePointerEvent* ev = (s3ePointerEvent*)sysData;
-        int type = 0;
-        switch (ev->m_Button)
-        {
-            case S3E_POINTER_BUTTON_SELECT:
-                type = ev->m_Pressed ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP;
-                break;
-            case S3E_POINTER_BUTTON_MOUSEWHEELUP:
-                type = TouchEvent::WHEEL_UP;
-                break;
-            case S3E_POINTER_BUTTON_MOUSEWHEELDOWN:
-                type = TouchEvent::WHEEL_DOWN;
-                break;
-        }
-
-        MouseButton b = MouseButton_Left;
-        switch (ev->m_Button)
-        {
-            case S3E_POINTER_BUTTON_LEFTMOUSE: b = MouseButton_Left; break;
-            case S3E_POINTER_BUTTON_RIGHTMOUSE: b = MouseButton_Right; break;
-            case S3E_POINTER_BUTTON_MIDDLEMOUSE: b = MouseButton_Middle; break;
-        }
-
-        Input::instance.sendPointerButtonEvent(getStage(), b, (float)ev->m_x, (float)ev->m_y, 1.0f, type, &Input::instance._pointerMouse);
-
-        return 0;
-    }
-
-    int32 pointerMotionEvent(void* sysData, void* u)
-    {
-        s3ePointerMotionEvent* ev = (s3ePointerMotionEvent*)sysData;
-
-        Input::instance.sendPointerMotionEvent(getStage(), (float)ev->m_x, (float)ev->m_y, 1.0f, &Input::instance._pointerMouse);
-        return 0;
-    }
-
-    int32 pointerTouchEvent(void* sysData, void* u)
-    {
-        Input* This = (Input*)u;
-        s3ePointerTouchEvent* ev = (s3ePointerTouchEvent*)sysData;
-        int id = ev->m_TouchID + 1;
-
-        Input::instance.sendPointerButtonEvent(getStage(), MouseButton_Touch, (float)ev->m_x, (float)ev->m_y, 1.0f, ev->m_Pressed ? TouchEvent::TOUCH_DOWN : TouchEvent::TOUCH_UP, Input::instance.getTouchByIndex(id));
-
-        return 0;
-    }
-
-    int32 pointerTouchMotionEvent(void* sysData, void* u)
-    {
-        Input* This = (Input*)u;
-        s3ePointerTouchMotionEvent* ev = (s3ePointerTouchMotionEvent*)sysData;
-        int id = ev->m_TouchID + 1;
-
-        Input::instance.sendPointerMotionEvent(getStage(), (float)ev->m_x, (float)ev->m_y, 1.0f, Input::instance.getTouchByIndex(id));
-
-        return 0;
-    }
-
-    int32 applicationPause(void* systemData, void* userData)
-    {
-        Event ev(Stage::DEACTIVATE);
-        getStage()->dispatchEvent(&ev);
-        return 0;
-    }
-
-    int32 applicationUnPause(void* systemData, void* userData)
-    {
-        Event ev(Stage::ACTIVATE);
-        getStage()->dispatchEvent(&ev);
-        return 0;
-    }
-#endif
-
     namespace key
     {
         void update();
@@ -854,6 +777,8 @@ namespace oxygine
         {
             log::messageln("core::release");
 
+            InputText::stopAnyInput();
+
             _threadMessages.clear();
             _uiMessages.clear();
 
@@ -882,6 +807,7 @@ namespace oxygine
             Stage::instance = 0;
             file::free();
 
+
             Resources::unregisterResourceType("atlas");
             Resources::unregisterResourceType("buffer");
             Resources::unregisterResourceType("font");

+ 2 - 0
tools/others/update_examples_entry.py

@@ -15,8 +15,10 @@ items = (
     examples + "Game/Part5",
     examples + "HelloWorld",
     examples + "Match3",
+    parent + "oxygine-freetype/example/game/project/",
     parent + "oxygine-sound/examples/SoundDemo/",
     parent + "oxygine-flow/examples/HelloFlow/",
+    parent + "oxygine-game/my_awesome_game/project/src/",
 )