Browse Source

updated emsc

dmuratshin 9 years ago
parent
commit
b2e0ded9b0

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 examples/HelloFreeType/proj.win32/Debug_v140/
 examples/HelloFreeType/proj.win32/Debug_v140/
 examples/HelloFreeType/proj.win32/.vs/
 examples/HelloFreeType/proj.win32/.vs/
+*.VC.db

+ 10 - 8
CMakeLists.txt

@@ -2,14 +2,12 @@ cmake_minimum_required (VERSION 2.6)
 project (OXYGINE_FREETYPE)
 project (OXYGINE_FREETYPE)
 
 
 if (EMSCRIPTEN)
 if (EMSCRIPTEN)
-	set(CMAKE_CXX_FLAGS "-Wno-warn-absolute-paths")
-	message(status emscripten)
-	set(OXYGINEMAGICPARTICLES_INCLUDE_DIRS 
-		${CMAKE_CURRENT_SOURCE_DIR}/src
-		${CMAKE_CURRENT_SOURCE_DIR}/magic_particles/emscripten)
+	set(CMAKE_CXX_FLAGS "-Wno-warn-absolute-paths -s USE_FREETYPE=1")
+	set(OXYGINE_FREETYPE_INCLUDE_DIRS 
+		${CMAKE_CURRENT_SOURCE_DIR}/src)
 
 
-	set(OXYGINEMAGICPARTICLES_LIBS
-		${CMAKE_CURRENT_SOURCE_DIR}/magic_particles/emscripten/libmagic.a)
+	set(OXYGINE_FREETYPE_CXX_FLAGS "-s USE_FREETYPE=1")
+	
 elseif(MSVC)
 elseif(MSVC)
 	set(OXYGINE_FREETYPE_INCLUDE_DIRS 
 	set(OXYGINE_FREETYPE_INCLUDE_DIRS 
 		${CMAKE_CURRENT_SOURCE_DIR}/src
 		${CMAKE_CURRENT_SOURCE_DIR}/src
@@ -32,4 +30,8 @@ add_library(oxygine-freetype STATIC
 #target_link_libraries(oxyginemagicparticles)
 #target_link_libraries(oxyginemagicparticles)
 
 
 set(OXYGINE_FREETYPE_INCLUDE_DIRS ${OXYGINE_FREETYPE_INCLUDE_DIRS} PARENT_SCOPE)
 set(OXYGINE_FREETYPE_INCLUDE_DIRS ${OXYGINE_FREETYPE_INCLUDE_DIRS} PARENT_SCOPE)
-set(OXYGINE_FREETYPE_LIBS ${OXYGINE_FREETYPE_LIBS} PARENT_SCOPE)
+set(OXYGINE_FREETYPE_LIBS ${OXYGINE_FREETYPE_LIBS} PARENT_SCOPE)
+set(OXYGINE_FREETYPE_CXX_FLAGS
+	${OXYGINE_FREETYPE_CXX_FLAGS}
+	PARENT_SCOPE)
+

+ 13 - 3
examples/HelloFreeType/proj.cmake/CMakeLists.txt

@@ -10,11 +10,21 @@ add_subdirectory(../../../../oxygine-freetype/ oxygine-freetype)
 include_directories(${OXYGINE_FREETYPE_INCLUDE_DIRS})
 include_directories(${OXYGINE_FREETYPE_INCLUDE_DIRS})
 link_directories(${OXYGINE_FREETYPE_LIBRARY_DIRS})
 link_directories(${OXYGINE_FREETYPE_LIBRARY_DIRS})
 
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
-add_executable(HelloFreeType ../src/entry_point.cpp ../src/example.cpp  ../src/example.h )
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OXYGINE_CXX_FLAGS} ${OXYGINE_FREETYPE_CXX_FLAGS}")
+
+add_executable(HelloFreeType ../src/main.cpp ../src/example.cpp  ../src/example.h )
+target_link_libraries(HelloFreeType ${OXYGINE_CORE_LIBS} ${OXYGINE_FREETYPE_LIBS} oxygine-freetype)
+
+
 
 
 if (WIN32) #disable console mode for VC++
 if (WIN32) #disable console mode for VC++
 	set_target_properties(HelloFreeType PROPERTIES WIN32_EXECUTABLE TRUE)
 	set_target_properties(HelloFreeType PROPERTIES WIN32_EXECUTABLE TRUE)
 endif(WIN32)
 endif(WIN32)
 
 
-target_link_libraries(HelloFreeType ${OXYGINE_CORE_LIBS} ${OXYGINE_FREETYPE_LIBS} oxygine-freetype)
+
+
+if (EMSCRIPTEN)
+	SET(CMAKE_EXECUTABLE_SUFFIX ".html")	
+	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1 -s WARN_ON_UNDEFINED_SYMBOLS=1 --memory-init-file 0 -s TOTAL_MEMORY=50331648")
+	em_link_pre_js(HelloFreeType  ${OXYGINE_JS_LIBRARIES}  ${CMAKE_CURRENT_SOURCE_DIR}/data.js)
+endif(EMSCRIPTEN)

+ 9 - 0
examples/HelloFreeType/proj.cmake/build_emsc.bat

@@ -0,0 +1,9 @@
+call emsdk activate
+
+python ../../../../oxygine-framework/tools/others/embed_folder_js.py -s ../data
+
+mkdir build_emsc
+cd build_emsc
+cmake -DCMAKE_TOOLCHAIN_FILE="%EMSCRIPTEN%/cmake/Modules/Platform/emscripten.cmake" -G"Unix Makefiles" ..
+make
+cd ..

+ 9 - 0
examples/HelloFreeType/proj.cmake/build_emsc_release.bat

@@ -0,0 +1,9 @@
+call emsdk activate
+
+python ../../../../oxygine-framework/tools/others/embed_folder_js.py -s ../data
+
+mkdir build_emsc_release
+cd build_emsc_release
+cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="%EMSCRIPTEN%/cmake/Modules/Platform/emscripten.cmake" -G"Unix Makefiles" ..
+make
+cd ..

+ 0 - 25
examples/HelloFreeType/proj.emscripten/CMakeLists.txt

@@ -1,25 +0,0 @@
-cmake_minimum_required (VERSION 2.6)
-project (HelloFreeType)
-
-add_subdirectory(../../../../oxygine-framework/ oxygine-framework)
-add_definitions(${OXYGINE_DEFINITIONS})
-include_directories(${OXYGINE_INCLUDE_DIRS})
-link_directories(${OXYGINE_LIBRARY_DIRS})
-
-SET(CMAKE_EXECUTABLE_SUFFIX ".html")
-set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-Wno-warn-absolute-paths -std=c++11")
-
-add_executable(HelloFreeType ../src/entry_point.cpp ../src/example.cpp  ../src/example.h )
-
-if (CMAKE_BUILD_TYPE STREQUAL Debug)
-	SET(linkFlags "-g4 ")
-else() # Either MinSizeRel, RelWithDebInfo or Release, all which run with optimizations enabled.
-	SET(linkFlags "-O2 ")
-endif()
-
-set(linkFlags "${linkFlags} -s NO_EXIT_RUNTIME=1 -s FULL_ES2=1 -s WARN_ON_UNDEFINED_SYMBOLS=1 --memory-init-file 0 -Wno-warn-absolute-paths -s TOTAL_MEMORY=50331648")
-
-set_target_properties(HelloFreeType PROPERTIES LINK_FLAGS "${linkFlags}")
-
-target_link_libraries(HelloFreeType ${OXYGINE_CORE_LIBS})
-em_link_pre_js(HelloFreeType  ${OXYGINE_JS_LIBRARIES}  ${CMAKE_CURRENT_SOURCE_DIR}/data.js)

+ 0 - 7
examples/HelloFreeType/proj.emscripten/build.bat

@@ -1,7 +0,0 @@
-python ../../../../oxygine-framework//tools/others/embed_folder_js.py -s ../data
-
-mkdir build
-cd build
-cmake -DCMAKE_TOOLCHAIN_FILE="%EMSCRIPTEN%/cmake/Modules/Platform/emscripten.cmake" -G"Unix Makefiles" .. 
-make
-cd ..

+ 0 - 7
examples/HelloFreeType/proj.emscripten/build_release.bat

@@ -1,7 +0,0 @@
-python ../../../../oxygine-framework//tools/others/embed_folder_js.py -s ../data
-
-mkdir build_release
-cd build_release
-cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="%EMSCRIPTEN%/cmake/Modules/Platform/emscripten.cmake" -G"Unix Makefiles" .. 
-make
-cd ..

+ 0 - 151
examples/HelloFreeType/src/entry_point.cpp

@@ -1,151 +0,0 @@
-/**
-Attention!
-This file has Oxygine initialization stuff.
-If you just started you don't need to understand it exactly you could check it later.
-You could start from example.cpp and example.h it has main functions being called from there
-*/
-#include "core/oxygine.h"
-#include "Stage.h"
-#include "DebugActor.h"
-
-#include "example.h"
-
-
-using namespace oxygine;
-
-
-//called each frame
-int mainloop()
-{
-    example_update();
-    //update our stage
-    //update all actors. Actor::update would be called also for all children
-    getStage()->update();
-
-    if (core::beginRendering())
-    {
-        Color clearColor(32, 32, 32, 255);
-        Rect viewport(Point(0, 0), core::getDisplaySize());
-        //render all actors. Actor::render would be called also for all children
-        getStage()->render(clearColor, viewport);
-
-        core::swapDisplayBuffers();
-    }
-
-    //update internal components
-    //all input events would be passed to Stage::instance.handleEvent
-    //if done is true then User requests quit from app.
-    bool done = core::update();
-
-    return done ? 1 : 0;
-}
-
-//it is application entry point
-void run()
-{
-    ObjectBase::__startTracingLeaks();
-
-    //initialize Oxygine's internal stuff
-    core::init_desc desc;
-
-#if OXYGINE_SDL || OXYGINE_EMSCRIPTEN
-    //we could setup initial window size on SDL builds
-    desc.w = 960;
-    desc.h = 640;
-    //marmalade settings could be changed from emulator's menu
-#endif
-
-
-    example_preinit();
-    core::init(&desc);
-
-
-    //create Stage. Stage is a root node
-    Stage::instance = new Stage(true);
-    Point size = core::getDisplaySize();
-    getStage()->setSize(size);
-
-    //DebugActor is a helper actor node. It shows FPS, memory usage and other useful stuff
-    DebugActor::show();
-
-    //initialize this example stuff. see example.cpp
-    example_init();
-
-#ifdef EMSCRIPTEN
-    /*
-    if you build for Emscripten mainloop would be called automatically outside.
-    see emscripten_set_main_loop below
-    */
-    return;
-#endif
-
-
-    //here is main game loop
-    while (1)
-    {
-        int done = mainloop();
-        if (done)
-            break;
-    }
-    //user wants to leave application...
-
-    //lets dump all created objects into log
-    //all created and not freed resources would be displayed
-    ObjectBase::dumpCreatedObjects();
-
-    //lets cleanup everything right now and call ObjectBase::dumpObjects() again
-    //we need to free all allocated resources and delete all created actors
-    //all actors/sprites are smart pointer objects and actually you don't need it remove them by hands
-    //but now we want delete it by hands
-
-    //check example.cpp
-    example_destroy();
-
-
-    //renderer.cleanup();
-
-    /**releases all internal components and Stage*/
-    core::release();
-
-    //dump list should be empty now
-    //we deleted everything and could be sure that there aren't any memory leaks
-    ObjectBase::dumpCreatedObjects();
-
-    ObjectBase::__stopTracingLeaks();
-    //end
-}
-
-#ifdef __S3E__
-int main(int argc, char* argv[])
-{
-    run();
-    return 0;
-}
-#endif
-
-
-#ifdef OXYGINE_SDL
-
-#include "SDL_main.h"
-extern "C"
-{
-    int main(int argc, char* argv[])
-    {
-        run();
-        return 0;
-    }
-};
-#endif
-
-#ifdef EMSCRIPTEN
-#include <emscripten.h>
-
-void one() { mainloop(); }
-
-int main(int argc, char* argv[])
-{
-    run();
-    emscripten_set_main_loop(one, 0, 0);
-    return 0;
-}
-#endif

+ 164 - 0
examples/HelloFreeType/src/main.cpp

@@ -0,0 +1,164 @@
+/**
+    Attention!
+    This file initializes the Oxygine engine.
+    If you just started here and don't understand the code completely, feel free to come back later.
+    You can start from example.cpp and example.h, which main functions are called from here.
+*/
+#include "core/oxygine.h"
+#include "Stage.h"
+#include "DebugActor.h"
+#include "example.h"
+
+
+using namespace oxygine;
+
+
+// This function is called each frame
+int mainloop()
+{
+    // Update engine-internal components
+    // If input events are available, they are passed to Stage::instance.handleEvent
+    // If the function returns true, it means that the user requested the application to terminate
+    bool done = core::update();
+
+    // It gets passed to our example game implementation
+    example_update();
+
+    // Update our stage
+    // Update all actors. Actor::update will also be called for all its children
+    getStage()->update();
+
+    if (core::beginRendering())
+    {
+        Color clearColor(32, 32, 32, 255);
+        Rect viewport(Point(0, 0), core::getDisplaySize());
+        // Render all actors inside the stage. Actor::render will also be called for all its children
+        getStage()->render(clearColor, viewport);
+
+        core::swapDisplayBuffers();
+    }
+
+    return done ? 1 : 0;
+}
+
+// Application entry point
+void run()
+{
+    ObjectBase::__startTracingLeaks();
+
+    // Initialize Oxygine's internal stuff
+    core::init_desc desc;
+    desc.title = "Oxygine Application";
+
+#if OXYGINE_SDL || OXYGINE_EMSCRIPTEN
+    // The initial window size can be set up here on SDL builds
+    desc.w = 960;
+    desc.h = 640;
+    // Marmalade settings can be modified from the emulator's menu
+#endif
+
+
+    example_preinit();
+    core::init(&desc);
+
+
+    // Create the stage. Stage is a root node for all updateable and drawable objects
+    Stage::instance = new Stage(true);
+    Point size = core::getDisplaySize();
+    getStage()->setSize(size);
+
+    // DebugActor is a helper actor node. It shows FPS, memory usage and other useful stuff
+    DebugActor::show();
+
+    // Initializes our example game. See example.cpp
+    example_init();
+
+#ifdef EMSCRIPTEN
+    /*
+    If you build for Emscripten, mainloop is called automatically and shouldn't be called here.
+    See emscripten_set_main_loop in the EMSCRIPTEN section below
+    */
+    return;
+#endif
+
+
+
+#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
+    // On iPhone mainloop is called automatically by CADisplayLink, see int main() below
+    return;
+#endif
+
+    // This is the main game loop.
+    while (1)
+    {
+        int done = mainloop();
+        if (done)
+            break;
+    }
+    /*
+     If we get here, the user has requested the Application to terminate.
+     We dump and log all our created objects that have not been freed yet
+    */
+    ObjectBase::dumpCreatedObjects();
+
+    /*
+    Let's clean up everything right now and call ObjectBase::dumpObjects() again.
+    We need to free all allocated resources and delete all created actors.
+    All actors/sprites are smart-pointer objects and don't need to be removed by hand.
+    But now we want to delete it by hand.
+    */
+
+    // See example.cpp for the shutdown function implementation
+    example_destroy();
+
+
+    //renderer.cleanup();
+
+    // Releases all internal components and the stage
+    core::release();
+
+    // The dump list should be empty by now,
+    // we want to make sure that there aren't any memory leaks, so we call it again.
+    ObjectBase::dumpCreatedObjects();
+
+    ObjectBase::__stopTracingLeaks();
+    //end
+}
+
+#ifdef __S3E__
+int main(int argc, char* argv[])
+{
+    run();
+    return 0;
+}
+#endif
+
+
+#ifdef OXYGINE_SDL
+
+#include "SDL_main.h"
+#include "SDL.h"
+
+extern "C"
+{
+    void one(void* param) { mainloop(); }
+    void oneEmsc() { mainloop(); }
+
+    int main(int argc, char* argv[])
+    {
+
+        run();
+
+#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);
+#endif
+
+#if EMSCRIPTEN
+        emscripten_set_main_loop(oneEmsc, 0, 0);
+#endif
+
+        return 0;
+    }
+};
+#endif