* 安卓编译成功

This commit is contained in:
2023-11-12 23:40:44 +08:00
parent bfbd8d9278
commit 09866f770c
12 changed files with 227 additions and 90 deletions
@@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.lveyou.dltest">
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
@@ -1,48 +0,0 @@
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.18.1)
# Declares and names the project.
project("dltest")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
dltest
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
dltest
# Links the target library to the log library
# included in the NDK.
${log-lib})
@@ -1,18 +0,0 @@
//#include <jni.h>
/*
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;
}
}
*/
@@ -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();
}
+3
View File
@@ -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/)
+2
View File
@@ -0,0 +1,2 @@
#include "dl_platform.h"
-1
View File
@@ -33,7 +33,6 @@
#define DL_PLATFORM DL_PLATFORM_ANDROID
#endif
//! 是否64位
consteval bool is_x64()
{
+1 -2
View File
@@ -246,5 +246,4 @@ void MergePath(std::list<Point>& list_pos)
}
}
}
}
+90
View File
@@ -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;
};
}
+108
View File
@@ -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<gcText, 4> _txt;//2为dx,dy 3为dis
Point _xy0;
bool _bRender;
};
}
+6 -4
View File
@@ -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)
+9
View File
@@ -148,3 +148,12 @@ int main()
Engine::Release();
return 0;
}
#if DL_PLATFORM == DL_PLATFORM_ANDROID
#include <jni.h>
extern "C"
JNIEXPORT void JNICALL
Java_com_lveyou_dltest_MainActivity_dl_1android_1main(JNIEnv *env, jobject thiz)
{ main(); }
#endif