diff --git a/build/android/app/src/main/AndroidManifest.xml b/build/android/app/src/main/AndroidManifest.xml index d28a8c95..d718dbbe 100644 --- a/build/android/app/src/main/AndroidManifest.xml +++ b/build/android/app/src/main/AndroidManifest.xml @@ -3,6 +3,9 @@ xmlns:tools="http://schemas.android.com/tools" package="com.lveyou.dltest"> + + + - -/* -void android_main(android_app *state) -{ -} - -static void engineHandleCmd(android_app *pApp, int32_t cmd) -{ - switch (cmd) - { - case APP_CMD_INIT_WINDOW: - ANativeWindow *pWindow = state->pApp->window; - // Pass pWindow on to the application somehow. - break; - } -} - */ \ No newline at end of file diff --git a/build/android/app/src/main/java/com/lveyou/dltest/MainActivity.java b/build/android/app/src/main/java/com/lveyou/dltest/MainActivity.java index be941166..5279c537 100644 --- a/build/android/app/src/main/java/com/lveyou/dltest/MainActivity.java +++ b/build/android/app/src/main/java/com/lveyou/dltest/MainActivity.java @@ -3,34 +3,22 @@ package com.lveyou.dltest; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; -import android.widget.TextView; - -import com.lveyou.dltest.databinding.ActivityMainBinding; +import android.util.Log; public class MainActivity extends AppCompatActivity { // Used to load the 'dltest' library on application startup. static { System.loadLibrary("dltest"); + Log.i("dl", "加载dl库完成!"); } - private ActivityMainBinding binding; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - binding = ActivityMainBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - - // Example of a call to a native method - TextView tv = binding.sampleText; - tv.setText(stringFromJNI()); + setContentView(R.layout.activity_main); + dl_android_main(); } - /** - * A native method that is implemented by the 'dltest' native library, - * which is packaged with this application. - */ - public native String stringFromJNI(); + public native void dl_android_main(); } \ No newline at end of file diff --git a/dl/CMakeLists.txt b/dl/CMakeLists.txt index e987184f..25b66bab 100644 --- a/dl/CMakeLists.txt +++ b/dl/CMakeLists.txt @@ -17,6 +17,7 @@ aux_source_directory(${CMAKE_SOURCE_DIR}/dl/vk SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/dl/ui SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/dl/misc SRC_LIST) aux_source_directory(${CMAKE_SOURCE_DIR}/dl/script SRC_LIST) +aux_source_directory(${CMAKE_SOURCE_DIR}/dl/tool SRC_LIST) add_library (${PROJECT_NAME} ${SRC_LIST}) # 自包含头文件 @@ -102,6 +103,7 @@ FILE(GLOB INCLUDE_LIST_MEMORY "memory/*.h") FILE(GLOB INCLUDE_LIST_RENDER "render/*.h") FILE(GLOB INCLUDE_LIST_UI "ui/*.h") FILE(GLOB INCLUDE_LIST_MISC "misc/*.h") +FILE(GLOB INCLUDE_LIST_TOOL "tool/*.h") install(FILES ${INCLUDE_LIST} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl) install(FILES ${INCLUDE_LIST_BASE} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl/base) @@ -111,6 +113,7 @@ install(FILES ${INCLUDE_LIST_MEMORY} DESTINATION ${CMAKE_INSTALL_PREFIX}/include install(FILES ${INCLUDE_LIST_RENDER} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl/render) install(FILES ${INCLUDE_LIST_UI} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl/ui) install(FILES ${INCLUDE_LIST_MISC} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl/misc) +install(FILES ${INCLUDE_LIST_TOOL} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dl/tool) install(FILES ${CMAKE_SOURCE_DIR}/third/json/json.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/) diff --git a/dl/dl_platform.cpp b/dl/dl_platform.cpp new file mode 100644 index 00000000..59bb0614 --- /dev/null +++ b/dl/dl_platform.cpp @@ -0,0 +1,2 @@ +#include "dl_platform.h" + diff --git a/dl/dl_platform.h b/dl/dl_platform.h index 46b8a49b..887ed0e0 100644 --- a/dl/dl_platform.h +++ b/dl/dl_platform.h @@ -33,7 +33,6 @@ #define DL_PLATFORM DL_PLATFORM_ANDROID #endif - //! 是否64位 consteval bool is_x64() { diff --git a/dl/math/dl_math.cpp b/dl/math/dl_math.cpp index 45379d76..f3e695e8 100644 --- a/dl/math/dl_math.cpp +++ b/dl/math/dl_math.cpp @@ -246,5 +246,4 @@ void MergePath(std::list& list_pos) } } -} - +} \ No newline at end of file diff --git a/dl/tool/dl_tool_debug_info.h b/dl/tool/dl_tool_debug_info.h new file mode 100644 index 00000000..927761a6 --- /dev/null +++ b/dl/tool/dl_tool_debug_info.h @@ -0,0 +1,90 @@ +/** +* @file DND.ToolShowFps.ixx +* @brief 显示FPS等信息 +* +* +* @version 1.0 +* @author lveyou +* @date 21-12-24 +* +*/ + +export module DND.Tool.ShowFps; + +import DND.Std; +import DND.Type; +import DND.Text; +import DND.Time; +import DND.System; +import DND.Color; +import DND.Factory; +import DND.Input; +import DND.UI; +import DND.String; +import DND.Camera; + +export namespace dnd::Tool +{ +class ShowFps +{ +public: + /** + * @brief 构造 + * @note 使用0号字体 + */ + static ShowFps* Create() + { + ShowFps* ret = new ShowFps; + ret->_txt = g_factory->CreateText(0, 16, ColorDef::GREEN); + ret->_txt->SetBackground(true); + ret->_txt->SetFormat(true); + + return ret; + } + + gcText GetText() + { + return _txt; + } + + void Render(string_view str = "") + { + const RenderInfo2D ri_2d = g_system->GetRenderInfo2D(); + const RenderInfo3D ri_3d = g_system->GetRenderInfo3D(); + + string str_all = format( + "fps:[t_4][c_yellow]{}[c]\n" + "dc2d:[t_4][c_yellow]{}+{}[c]\n" + "spr:[t_4][c_yellow]{}+{}[c]\n" + "order:[t_4][c_yellow]{}[c]\n" + "dc3d:[t_4][c_yellow]{}[c]\n" + "actor:[t_4][c_yellow]{}[c]\n" + "light:[t_4][c_yellow]{}, {}, {}[c]\n" + "size:[t_4][c_yellow]{}[c]\n" + "mouse:[t_4][c_yellow]{}[c]\n" + "camera:[t_4][c_yellow]{}[c]", + g_time->GetFPS(), + ri_2d._numDrawCall, ri_2d._numDrawCallTranslucent, + ri_2d._numSprite, ri_2d._numSpriteTranslucent, + g_ui->GetOrderPickup(), + ri_3d._numDrawCall, + ri_3d._numActor, + ri_3d._numLightDir, ri_3d._numLightDot, ri_3d._numLightSpot, + toString(g_system->GetWindowSize()), + toString(g_input->GetCursorPosition()), + toString(g_factory->GetCamera()->GetPosition())); + + if (!str.empty()) + { + str_all += "\n"; + str_all += str; + } + + _txt->SetString(str_all); + _txt->Render(); + } +private: + gcText _txt; +}; + +} diff --git a/dl/tool/dl_tool_ruler.h b/dl/tool/dl_tool_ruler.h new file mode 100644 index 00000000..7e50e7ad --- /dev/null +++ b/dl/tool/dl_tool_ruler.h @@ -0,0 +1,108 @@ +/** +* @file dl_tool_ruler.h +* @brief 尺子,单位像素 +* +* +* @version 1.0 +* @author lveyou +* @date 22-03-04 +* +* @note 按下ctrl开始 +*/ +#pragma once + +namespace dl::Tool +{ +//! 尺子工具,用于测量像素长度 +class Ruler +{ +public: + /** + * @brief 构造 + * @note 使用0号字体 + */ + static Ruler* Create() + { + Ruler* ret = new Ruler; + return ret; + } + + void Update(const LogicType& lt) + { + if (lt.IsUpdate()) + { + _bRender = false; + if (g_input->KeyState(KeyCode::LEFT_CONTROL)) + { + Point xy_mouse = g_input->GetCursorPosition(); + if (_xy0[0] < 0) + { + _xy0 = xy_mouse; + } + else + { + _bRender = true; + + _txt[0]->SetString(format("({})", toString(_xy0))); + _txt[1]->SetString(format("({})", toString(xy_mouse))); + + Point xy_dt = xy_mouse - _xy0; + _txt[2]->SetString(format("dx: {} dy: {}", xy_dt[0], xy_dt[1])); + _txt[3]->SetString(format("dis: {}", (unsigned)sqrt(Math::DisPow2(xy_dt)))); + + Vector2 size0 = toVector2(_txt[0]->GetSize()); + Vector2 size1 = toVector2(_txt[1]->GetSize()); + Vector2 size3 = toVector2(_txt[3]->GetSize()); + + Point xy_center = (_xy0 + xy_mouse) / 2; + _txt[0]->SetPositionAlign(toVector2(_xy0), Align::Horizontal::RIGHT, Align::Vertical::BUTTOM); + _txt[1]->SetPositionAlign(toVector2(xy_mouse)); + _txt[2]->SetPositionAlign(toVector2(xy_center), Align::Vertical::BUTTOM); + _txt[3]->SetPositionAlign(toVector2(xy_center), Align::Horizontal::RIGHT); + + _spr->SetQuad(createQuad(toVector2(_xy0), toVector2(xy_mouse), 2)); + + } + } + else + { + _xy0 = { -1, -1 }; + } + } + + if (_bRender && lt.IsRender()) + { + _spr->Render(); + for (auto& iter : _txt) + { + iter->Render(); + } + } + + } + + ~Ruler() + { + } +private: + Ruler() : + _xy0{ -1, -1 }, + _bRender{ false } + { + _spr = g_factory->CreateSpriteDefault(ColorDef::RED); + + for (auto& iter : _txt) + { + iter = g_factory->CreateText(0, 16, ColorDef::GREEN); + iter->SetBackground(true); + } + } + + + gcSprite _spr; + array _txt;//2为dx,dy 3为dis + Point _xy0; + bool _bRender; +}; + +} diff --git a/dltest/CMakeLists.txt b/dltest/CMakeLists.txt index 40fb9550..a5434b4d 100644 --- a/dltest/CMakeLists.txt +++ b/dltest/CMakeLists.txt @@ -12,11 +12,13 @@ message(${PROJECT_SOURCE_DIR}) # 添加源、设置可执行文件 aux_source_directory(${PROJECT_SOURCE_DIR} SRC_LIST_TEST) -add_executable (${PROJECT_NAME} ${SRC_LIST_TEST}) -# 自头文件 -#include_directories(${PROJECT_SOURCE_DIR}/dl) -#link_directories(${PROJECT_BINARY_DIR}/dl) +# 安卓为动态链接库 +if (NOT CMAKE_SYSTEM_NAME MATCHES "Android") +add_executable (${PROJECT_NAME} ${SRC_LIST_TEST}) +else() +add_library (${PROJECT_NAME} SHARED ${SRC_LIST_TEST}) +endif() if (NOT CMAKE_SYSTEM_NAME MATCHES "Android") set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 23) diff --git a/dltest/main.cpp b/dltest/main.cpp index b7dc7b52..3accbe09 100644 --- a/dltest/main.cpp +++ b/dltest/main.cpp @@ -148,3 +148,12 @@ int main() Engine::Release(); return 0; } + +#if DL_PLATFORM == DL_PLATFORM_ANDROID +#include +extern "C" +JNIEXPORT void JNICALL +Java_com_lveyou_dltest_MainActivity_dl_1android_1main(JNIEnv *env, jobject thiz) +{ main(); } +#endif +