Initial commit
What works? - Reading files (AssetManager::loadFile) - Rendering colored & textured rects (Renderer::addRect) - Getting input (TouchInputEvent) TODO Port this to windows
15
.gitignore
vendored
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
*.iml
|
||||||
|
.gradle
|
||||||
|
/local.properties
|
||||||
|
/.idea/caches
|
||||||
|
/.idea/libraries
|
||||||
|
/.idea/modules.xml
|
||||||
|
/.idea/workspace.xml
|
||||||
|
/.idea/navEditor.xml
|
||||||
|
/.idea/assetWizardSettings.xml
|
||||||
|
.DS_Store
|
||||||
|
/build
|
||||||
|
/captures
|
||||||
|
.externalNativeBuild
|
||||||
|
.cxx
|
||||||
|
local.properties
|
3
.idea/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
1
.idea/.name
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Krimi Dinner Engine
|
6
.idea/compiler.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<bytecodeTargetLevel target="11" />
|
||||||
|
</component>
|
||||||
|
</project>
|
19
.idea/gradle.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
|
<component name="GradleSettings">
|
||||||
|
<option name="linkedExternalProjectsSettings">
|
||||||
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="GRADLE" />
|
||||||
|
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
</project>
|
9
.idea/misc.xml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectType">
|
||||||
|
<option name="id" value="Android" />
|
||||||
|
</component>
|
||||||
|
</project>
|
1
app/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/build
|
69
app/build.gradle
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
plugins {
|
||||||
|
id 'com.android.application'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk 32
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "tech.recreational.kde"
|
||||||
|
minSdk 26
|
||||||
|
targetSdk 32
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
arguments "-DANDROID_STL=c++_static"
|
||||||
|
cppFlags ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
// Skip deprecated ABIs. Only required when using NDK 16 or earlier.
|
||||||
|
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildFeatures {
|
||||||
|
prefab true
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
arguments "-DANDROID_STL=c++_shared"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug {
|
||||||
|
externalNativeBuild {
|
||||||
|
minifyEnabled = false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
cmake {
|
||||||
|
arguments "-DANDROID_STL=c++_shared"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
path file('src/main/cpp/CMakeLists.txt')
|
||||||
|
version '3.18.1'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'androidx.games:games-activity:1.2.1'
|
||||||
|
implementation 'androidx.games:games-frame-pacing:1.10.1'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||||
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
|
||||||
|
}
|
21
app/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,26 @@
|
||||||
|
package tech.recreational.kde;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
public void useAppContext() {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||||
|
assertEquals("tech.recreational.kde", appContext.getPackageName());
|
||||||
|
}
|
||||||
|
}
|
29
app/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
package="tech.recreational.kde">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
android:fullBackupContent="@xml/backup_rules"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/Application.Fullscreen"
|
||||||
|
tools:targetApi="31">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.lib_name"
|
||||||
|
android:value="kde" />
|
||||||
|
|
||||||
|
|
||||||
|
<activity android:name=".KDEActivity" android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
BIN
app/src/main/assets/smiley_PNG42.png
Normal file
After Width: | Height: | Size: 279 KiB |
68
app/src/main/cpp/AssetManager.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#include "AssetManager.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
#include <game-activity/native_app_glue/android_native_app_glue.h>
|
||||||
|
|
||||||
|
#define STBI_NO_STDIO
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include "stb_image.h"
|
||||||
|
|
||||||
|
AssetManager* AssetManager::ptr = nullptr;
|
||||||
|
|
||||||
|
AssetManager::AssetManager() : m_asset_mgr(nullptr) {};
|
||||||
|
AssetManager::~AssetManager() {}
|
||||||
|
|
||||||
|
void AssetManager::create(AAssetManager *android_asset_manager)
|
||||||
|
{
|
||||||
|
AssetManager::ptr = new AssetManager;
|
||||||
|
AssetManager::ptr->m_asset_mgr = android_asset_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManager::loadFile(const char* path, FileBuffer* p_file_buffer)
|
||||||
|
{
|
||||||
|
AAsset* asset = AAssetManager_open(m_asset_mgr, path, AASSET_MODE_BUFFER);
|
||||||
|
if (!asset) {
|
||||||
|
ALOGE("Failed to open asset %s", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const void* buffer = AAsset_getBuffer(asset);
|
||||||
|
if (!buffer) {
|
||||||
|
ALOGE("Failed to retrieve contents of asset %s", path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto length = static_cast<size_t>(AAsset_getLength64(asset));
|
||||||
|
p_file_buffer->data = buffer,
|
||||||
|
p_file_buffer->size = length;
|
||||||
|
p_file_buffer->internal = asset;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetManager::loadTexture(const char* path, Texture* p_texture)
|
||||||
|
{
|
||||||
|
FileBuffer texture_data = {};
|
||||||
|
if (!loadFile(path, &texture_data))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int width, height, channels;
|
||||||
|
const auto* raw_data = reinterpret_cast<const stbi_uc*>(texture_data.data);
|
||||||
|
stbi_uc* data = stbi_load_from_memory(raw_data,
|
||||||
|
static_cast<int>(texture_data.size),
|
||||||
|
&width, &height, &channels,
|
||||||
|
4);
|
||||||
|
if (!data) {
|
||||||
|
ALOGE("Failed to parse texture file %s", path);
|
||||||
|
releaseFileBuffer(texture_data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*p_texture = Texture(width, height, data);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssetManager::releaseFileBuffer(FileBuffer &fb)
|
||||||
|
{
|
||||||
|
AAsset_close(reinterpret_cast<AAsset*>(fb.internal));
|
||||||
|
fb.internal = nullptr;
|
||||||
|
fb.data = nullptr;
|
||||||
|
fb.size = 0;
|
||||||
|
}
|
40
app/src/main/cpp/AssetManager.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_ASSETMANAGER_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_ASSETMANAGER_H
|
||||||
|
|
||||||
|
#include "Texture.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
|
||||||
|
struct AAssetManager;
|
||||||
|
|
||||||
|
struct FileBuffer
|
||||||
|
{
|
||||||
|
const void* data;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
void* internal;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AssetManager {
|
||||||
|
public:
|
||||||
|
static AssetManager* ptr;
|
||||||
|
|
||||||
|
static void create(AAssetManager* android_asset_manager);
|
||||||
|
|
||||||
|
bool loadFile(const char* path, FileBuffer* p_file_buffer);
|
||||||
|
|
||||||
|
bool loadTexture(const char* path, Texture* p_texture);
|
||||||
|
|
||||||
|
void releaseFileBuffer(FileBuffer& fb);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AssetManager();
|
||||||
|
~AssetManager();
|
||||||
|
|
||||||
|
AssetManager(const AssetManager&) = delete;
|
||||||
|
AssetManager& operator=(const AssetManager&) = delete;
|
||||||
|
|
||||||
|
AAssetManager* m_asset_mgr;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
27
app/src/main/cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
cmake_minimum_required(VERSION 3.18.1)
|
||||||
|
project("kde")
|
||||||
|
|
||||||
|
find_library(log-lib log )
|
||||||
|
find_package(game-activity REQUIRED CONFIG)
|
||||||
|
find_package(games-frame-pacing REQUIRED CONFIG)
|
||||||
|
|
||||||
|
add_library(kde SHARED
|
||||||
|
kde.cpp
|
||||||
|
NativeEngine.cpp
|
||||||
|
NativeEngine.h
|
||||||
|
Renderer.cpp
|
||||||
|
Renderer.h
|
||||||
|
Texture.cpp
|
||||||
|
Texture.h
|
||||||
|
AssetManager.cpp
|
||||||
|
AssetManager.h
|
||||||
|
StringRepository.h
|
||||||
|
StringRepository.cpp
|
||||||
|
Hash.h
|
||||||
|
Hash.cpp)
|
||||||
|
target_link_libraries(kde ${log-lib}
|
||||||
|
EGL
|
||||||
|
GLESv3
|
||||||
|
android
|
||||||
|
game-activity::game-activity
|
||||||
|
games-frame-pacing::swappy_static)
|
152
app/src/main/cpp/Hash.cpp
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
#include "Hash.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
Hash::Hash()
|
||||||
|
: m_bucket_count(0),
|
||||||
|
m_used_buckets(0),
|
||||||
|
m_keys(nullptr),
|
||||||
|
m_values(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Hash::Hash(uint32_t bucket_count)
|
||||||
|
: m_bucket_count(0),
|
||||||
|
m_used_buckets(0),
|
||||||
|
m_keys(nullptr),
|
||||||
|
m_values(nullptr)
|
||||||
|
{
|
||||||
|
auto* mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * 2 * bucket_count));
|
||||||
|
if (!mem)
|
||||||
|
return;
|
||||||
|
m_bucket_count = bucket_count;
|
||||||
|
m_keys = mem;
|
||||||
|
m_values = mem + bucket_count;
|
||||||
|
memset(mem, 0, sizeof(uint64_t) * 2 * bucket_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
Hash::Hash(const Hash& copy)
|
||||||
|
: m_bucket_count(copy.m_bucket_count),
|
||||||
|
m_used_buckets(copy.m_used_buckets),
|
||||||
|
m_keys(nullptr),
|
||||||
|
m_values(nullptr)
|
||||||
|
{
|
||||||
|
auto* mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * 2 * m_bucket_count));
|
||||||
|
if (!mem)
|
||||||
|
return;
|
||||||
|
m_keys = mem;
|
||||||
|
m_values = mem + m_bucket_count;
|
||||||
|
memcpy(m_keys, copy.m_keys, sizeof(uint64_t) * 2 * m_bucket_count);
|
||||||
|
}
|
||||||
|
|
||||||
|
Hash& Hash::operator=(const Hash& rhs)
|
||||||
|
{
|
||||||
|
if (m_keys)
|
||||||
|
free(m_keys);
|
||||||
|
m_bucket_count = rhs.m_bucket_count;
|
||||||
|
m_used_buckets = rhs.m_used_buckets;
|
||||||
|
auto* mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * 2 * m_bucket_count));
|
||||||
|
if (!mem) {
|
||||||
|
m_bucket_count = 0;
|
||||||
|
m_keys = nullptr;
|
||||||
|
m_values = nullptr;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
m_keys = mem;
|
||||||
|
m_values = mem + m_bucket_count;
|
||||||
|
memcpy(m_keys, rhs.m_keys, sizeof(uint64_t) * 2 * m_bucket_count);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Hash::~Hash()
|
||||||
|
{
|
||||||
|
free(m_keys);
|
||||||
|
m_used_buckets = 0;
|
||||||
|
m_bucket_count = 0;
|
||||||
|
m_keys = nullptr;
|
||||||
|
m_values = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t Hash::lookup(uint64_t key, uint64_t default_value)
|
||||||
|
{
|
||||||
|
if (m_bucket_count == 0)
|
||||||
|
return default_value;
|
||||||
|
uint64_t i = key % m_bucket_count;
|
||||||
|
do {
|
||||||
|
if (m_keys[i] == key)
|
||||||
|
return m_values[i];
|
||||||
|
else if (m_keys[i] == HASH_EMPTY_KEY)
|
||||||
|
return default_value;
|
||||||
|
i = (i + 1) % m_bucket_count;
|
||||||
|
} while (i != key % m_bucket_count);
|
||||||
|
return default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Hash::insert(uint64_t key, uint64_t value)
|
||||||
|
{
|
||||||
|
if (key == HASH_EMPTY_KEY || key == HASH_TOMBSTONE_KEY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resize if necessary
|
||||||
|
float usage = static_cast<float>(m_used_buckets) / static_cast<float>(m_bucket_count);
|
||||||
|
if (m_bucket_count == 0 || usage > .5f) {
|
||||||
|
uint32_t new_cap = (m_bucket_count > 0) ? m_bucket_count * 2 : 128;
|
||||||
|
auto* new_mem = reinterpret_cast<uint64_t*>(malloc(sizeof(uint64_t) * new_cap * 2));
|
||||||
|
if (!new_mem)
|
||||||
|
return false;
|
||||||
|
uint64_t* new_keys = new_mem;
|
||||||
|
uint64_t* new_values = new_keys + new_cap;
|
||||||
|
memset(new_keys, HASH_EMPTY_KEY, sizeof(uint64_t) * new_cap);
|
||||||
|
|
||||||
|
// Re-insert all values
|
||||||
|
for (uint32_t i = 0; i < m_bucket_count; ++i) {
|
||||||
|
if (m_keys[i] != HASH_EMPTY_KEY) {
|
||||||
|
uint64_t idx = m_keys[i] % new_cap;
|
||||||
|
while (true) {
|
||||||
|
if (new_keys[idx] == HASH_EMPTY_KEY) {
|
||||||
|
new_keys[idx] = m_keys[i];
|
||||||
|
new_values[idx] = m_values[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
idx = (idx + 1) % new_cap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(m_keys);
|
||||||
|
m_keys = new_keys;
|
||||||
|
m_values = new_values;
|
||||||
|
m_bucket_count = new_cap;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t i = key % m_bucket_count;
|
||||||
|
do {
|
||||||
|
if (m_keys[i] == HASH_EMPTY_KEY || m_keys[i] == HASH_TOMBSTONE_KEY) {
|
||||||
|
m_keys[i] = key;
|
||||||
|
m_values[i] = value;
|
||||||
|
++m_used_buckets;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (m_keys[i] == key) {
|
||||||
|
m_values[i] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
i = (i + 1) % m_bucket_count;
|
||||||
|
} while (i != (key % m_bucket_count));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Hash::remove(uint64_t key)
|
||||||
|
{
|
||||||
|
if (m_bucket_count == 0)
|
||||||
|
return;
|
||||||
|
uint64_t i = key % m_bucket_count;
|
||||||
|
do {
|
||||||
|
if (m_keys[i] == key) {
|
||||||
|
m_keys[i] = HASH_TOMBSTONE_KEY;
|
||||||
|
}
|
||||||
|
else if (m_keys[i] == HASH_EMPTY_KEY) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (i != key % m_bucket_count);
|
||||||
|
}
|
33
app/src/main/cpp/Hash.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_HASH_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_HASH_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static constexpr uint64_t HASH_EMPTY_KEY = 0;
|
||||||
|
static constexpr uint64_t HASH_TOMBSTONE_KEY = 1;
|
||||||
|
|
||||||
|
class Hash
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Hash();
|
||||||
|
Hash(uint32_t bucket_count);
|
||||||
|
Hash(const Hash& copy);
|
||||||
|
Hash& operator=(const Hash& rhs);
|
||||||
|
~Hash();
|
||||||
|
|
||||||
|
uint64_t lookup(uint64_t key, uint64_t default_value);
|
||||||
|
|
||||||
|
bool insert(uint64_t key, uint64_t value);
|
||||||
|
|
||||||
|
void remove(uint64_t key);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_bucket_count;
|
||||||
|
uint32_t m_used_buckets;
|
||||||
|
uint64_t* m_keys;
|
||||||
|
uint64_t* m_values;
|
||||||
|
};
|
||||||
|
|
||||||
|
using nt_hash = Hash;
|
||||||
|
|
||||||
|
#endif
|
17
app/src/main/cpp/Log.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_LOG_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_LOG_H
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
|
||||||
|
#define LOG_TAG "KrimiDinnerEngine"
|
||||||
|
|
||||||
|
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);
|
||||||
|
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__);
|
||||||
|
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__);
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define ALOGV(...)
|
||||||
|
#else
|
||||||
|
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //KRIMI_DINNER_ENGINE_LOG_H
|
410
app/src/main/cpp/NativeEngine.cpp
Normal file
|
@ -0,0 +1,410 @@
|
||||||
|
//
|
||||||
|
// Created by kevin on 02.10.2022.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "NativeEngine.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "AssetManager.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include "TouchInput.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <swappy/swappyGL.h>
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
|
||||||
|
static NativeEngineState g_app_state = { false };
|
||||||
|
|
||||||
|
static void _handle_cmd_proxy(struct android_app* app, int32_t cmd)
|
||||||
|
{
|
||||||
|
auto* engine = reinterpret_cast<NativeEngine*>(app->userData);
|
||||||
|
engine->handleAppCmd(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEngine::NativeEngine(struct android_app *app)
|
||||||
|
: m_app(app),
|
||||||
|
m_egl_display(EGL_NO_DISPLAY),
|
||||||
|
m_egl_surface(EGL_NO_SURFACE),
|
||||||
|
m_egl_context(EGL_NO_CONTEXT),
|
||||||
|
m_jni_env(nullptr),
|
||||||
|
m_has_focus(false),
|
||||||
|
m_has_window(false),
|
||||||
|
m_is_visible(false),
|
||||||
|
m_in_motion(false)
|
||||||
|
{
|
||||||
|
SwappyGL_init(getJniEnv(), m_app->activity->javaGameActivity);
|
||||||
|
SwappyGL_setSwapIntervalNS(SWAPPY_SWAP_20FPS);
|
||||||
|
|
||||||
|
android_app_set_key_event_filter(m_app, NULL);
|
||||||
|
android_app_set_motion_event_filter(m_app, NULL);
|
||||||
|
|
||||||
|
AssetManager::create(m_app->activity->assetManager);
|
||||||
|
|
||||||
|
m_smiley = StringRepository::global->internString("smiley_PNG42.png");
|
||||||
|
m_smiley_pos = { 100, 100 };
|
||||||
|
}
|
||||||
|
|
||||||
|
NativeEngine::~NativeEngine()
|
||||||
|
{
|
||||||
|
ALOGI("NativeEngine: destructor");
|
||||||
|
SwappyGL_destroy();
|
||||||
|
killContext();
|
||||||
|
if (m_jni_env) {
|
||||||
|
m_app->activity->vm->DetachCurrentThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::gameLoop()
|
||||||
|
{
|
||||||
|
m_app->userData = this;
|
||||||
|
m_app->onAppCmd = _handle_cmd_proxy;
|
||||||
|
m_app->textInputState = 0;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
int events;
|
||||||
|
struct android_poll_source* source;
|
||||||
|
|
||||||
|
// Poll commands
|
||||||
|
while ((ALooper_pollAll(isAnimating() ? 0 : -1, nullptr,
|
||||||
|
&events, reinterpret_cast<void**>(&source))) >= 0) {
|
||||||
|
if (source)
|
||||||
|
source->process(source->app, source);
|
||||||
|
if (m_app->destroyRequested)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr int MAX_INPUT_EVENTS = 16;
|
||||||
|
TouchInputEvent input_events[MAX_INPUT_EVENTS];
|
||||||
|
int input_event_count = 0;
|
||||||
|
|
||||||
|
// Handle input
|
||||||
|
android_input_buffer* input_buffer = android_app_swap_input_buffers(m_app);
|
||||||
|
if (input_buffer) {
|
||||||
|
if (input_buffer->keyEventsCount > 0) {
|
||||||
|
android_app_clear_key_events(input_buffer);
|
||||||
|
}
|
||||||
|
if (input_buffer->motionEventsCount > 0) {
|
||||||
|
for (unsigned int i = 0; i < input_buffer->motionEventsCount; ++i) {
|
||||||
|
GameActivityMotionEvent motion_event = input_buffer->motionEvents[i];
|
||||||
|
if (motion_event.action == AMOTION_EVENT_ACTION_DOWN) {
|
||||||
|
if (motion_event.pointerCount > 0) {
|
||||||
|
GameActivityPointerAxes pointer = motion_event.pointers[0];
|
||||||
|
float x = GameActivityPointerAxes_getX(&pointer);
|
||||||
|
float y = GameActivityPointerAxes_getY(&pointer);
|
||||||
|
|
||||||
|
// Record this motion
|
||||||
|
m_in_motion = true;
|
||||||
|
m_last_down.x = x;
|
||||||
|
m_last_down.y = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (motion_event.action == AMOTION_EVENT_ACTION_UP) {
|
||||||
|
if (!m_in_motion) {
|
||||||
|
ALOGW("Got an UP motion without a corresponding DOWN motion");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (motion_event.pointerCount > 0) {
|
||||||
|
GameActivityPointerAxes pointer = motion_event.pointers[0];
|
||||||
|
float x = GameActivityPointerAxes_getX(&pointer);
|
||||||
|
float y = GameActivityPointerAxes_getY(&pointer);
|
||||||
|
|
||||||
|
float dist = sqrtf((x - m_last_down.x) * (x - m_last_down.x) +
|
||||||
|
(y - m_last_down.y) * (y - m_last_down.y));
|
||||||
|
|
||||||
|
if (dist < 5.f) {
|
||||||
|
// TAP
|
||||||
|
ALOGI("TAP at %f %f", x, y);
|
||||||
|
input_events[input_event_count].kind = TouchInputEventKind::Tap;
|
||||||
|
input_events[input_event_count].start = { x, y };
|
||||||
|
input_events[input_event_count].end = { x, y };
|
||||||
|
++input_event_count;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Swipe
|
||||||
|
ALOGI("Swipe from %f %f to %f %f",
|
||||||
|
m_last_down.x, m_last_down.y,
|
||||||
|
x, y);
|
||||||
|
input_events[input_event_count].kind = TouchInputEventKind::Tap;
|
||||||
|
input_events[input_event_count].start = { m_last_down.x, m_last_down.y };
|
||||||
|
input_events[input_event_count].end = { x, y };
|
||||||
|
++input_event_count;
|
||||||
|
}
|
||||||
|
m_in_motion = false;
|
||||||
|
if (input_event_count == MAX_INPUT_EVENTS)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (motion_event.action == AMOTION_EVENT_ACTION_CANCEL) {
|
||||||
|
m_in_motion = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
android_app_clear_motion_events(input_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAnimating() && Renderer::ptr) {
|
||||||
|
static float x = 1.f;
|
||||||
|
static float d = -0.01f;
|
||||||
|
x += d;
|
||||||
|
if ( x <= 0.f)
|
||||||
|
d *= -1.f;
|
||||||
|
else if (x >= 1.f)
|
||||||
|
d *= -1.f;
|
||||||
|
|
||||||
|
|
||||||
|
if (input_event_count > 0) {
|
||||||
|
m_smiley_pos = input_events[input_event_count - 1].end;
|
||||||
|
m_smiley_pos.x -= 250;
|
||||||
|
m_smiley_pos.y -= 250;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer::ptr->addRect(100, 100, 500, 500, 0.3f, 0.3f, 0.3f, 1.f);
|
||||||
|
Renderer::ptr->addRect(m_smiley_pos.x, m_smiley_pos.y, 500, 500, 0.f, x*x, 1.f - x*x, 1.f, m_smiley);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isAnimating()) {
|
||||||
|
renderFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::isAnimating() const
|
||||||
|
{
|
||||||
|
return m_has_window && m_has_focus && m_is_visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void NativeEngine::handleAppCmd(int32_t cmd)
|
||||||
|
{
|
||||||
|
ALOGV("NativeEngine: Handling command %d.", cmd);
|
||||||
|
switch (cmd) {
|
||||||
|
case APP_CMD_SAVE_STATE:
|
||||||
|
break;
|
||||||
|
case APP_CMD_INIT_WINDOW:
|
||||||
|
ALOGV("NativeEngine:: APP_CMD_INIT_WINDOW");
|
||||||
|
if (m_app->window) {
|
||||||
|
m_has_window = true;
|
||||||
|
SwappyGL_setWindow(m_app->window);
|
||||||
|
if (m_app->savedStateSize == sizeof(m_state) && m_app->savedState) {
|
||||||
|
m_state = *reinterpret_cast<NativeEngineState*>(m_app->savedState);
|
||||||
|
m_has_focus = m_state.has_focus;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Workaround APP_CMD_GAINED_FOCUS issue where the focus state is not passed
|
||||||
|
// down from GameActivity when restarting Activity
|
||||||
|
m_has_focus = g_app_state.has_focus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ALOGV("HandleCommand(%d): hasWindow = %d, hasFocus = %d", cmd,
|
||||||
|
m_has_window ? 1 : 0, m_has_focus ? 1 : 0);
|
||||||
|
break;
|
||||||
|
case APP_CMD_TERM_WINDOW:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_TERM_WINDOW");
|
||||||
|
killSurface();
|
||||||
|
m_has_window = false;
|
||||||
|
break;
|
||||||
|
case APP_CMD_GAINED_FOCUS:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_GAINED_FOCUS");
|
||||||
|
m_has_focus = true;
|
||||||
|
m_state.has_focus = g_app_state.has_focus = m_has_focus;
|
||||||
|
break;
|
||||||
|
case APP_CMD_LOST_FOCUS:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_LOST_FOCUS");
|
||||||
|
m_has_focus = false;
|
||||||
|
m_state.has_focus = g_app_state.has_focus = m_has_focus;
|
||||||
|
break;
|
||||||
|
case APP_CMD_START:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_START");
|
||||||
|
m_is_visible = true;
|
||||||
|
break;
|
||||||
|
case APP_CMD_STOP:
|
||||||
|
ALOGV("NativeEngine: APP_CMD_STOP");
|
||||||
|
m_is_visible = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ALOGW("Unhandled command.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ALOGV("NativeEngine STATUS: F%d, V%d, W%d, EGL: D %p, S %p, CTX %p, CFG %p",
|
||||||
|
m_has_focus, m_is_visible, m_has_window, m_egl_display, m_egl_surface, m_egl_context,
|
||||||
|
m_egl_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEnv* NativeEngine::getJniEnv()
|
||||||
|
{
|
||||||
|
if (!m_jni_env) {
|
||||||
|
if (m_app->activity->vm->AttachCurrentThread(&m_jni_env, nullptr) != 0) {
|
||||||
|
ALOGE("*** FATAL ERROR: failed to attach thread to JNI.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
ALOGI("Attached current thread to JNI, %p", m_jni_env);
|
||||||
|
}
|
||||||
|
return m_jni_env;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::prepareToRender()
|
||||||
|
{
|
||||||
|
if (m_egl_display == EGL_NO_DISPLAY || m_egl_surface == EGL_NO_SURFACE || m_egl_context == EGL_NO_CONTEXT) {
|
||||||
|
if (!initDisplay()) {
|
||||||
|
ALOGE("NativeEngine: failed to create display");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initSurface()) {
|
||||||
|
ALOGE("NativeEngine: failed to create surface.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!initContext()) {
|
||||||
|
ALOGE("NativeEngine: failed to create context.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALOGI("NativeEngine: binding surface and context (display %p, surface %p, context %p)",
|
||||||
|
m_egl_display, m_egl_surface, m_egl_context);
|
||||||
|
|
||||||
|
if (eglMakeCurrent(m_egl_display, m_egl_surface, m_egl_surface, m_egl_context) == EGL_FALSE) {
|
||||||
|
ALOGE("NativeEngine: eglMakeCurrent failed, EGL error: %d", eglGetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
initGLObjects();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::initDisplay()
|
||||||
|
{
|
||||||
|
if (m_egl_display != EGL_NO_DISPLAY) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALOGI("NativeEngine: Initializing display");
|
||||||
|
m_egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
|
if (eglInitialize(m_egl_display, 0, 0) == EGL_FALSE) {
|
||||||
|
ALOGE("NativeEngine: Failed to init display, error %d", eglGetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::killDisplay()
|
||||||
|
{
|
||||||
|
ALOGI("NativeEngine: Killing display");
|
||||||
|
killContext();
|
||||||
|
killSurface();
|
||||||
|
|
||||||
|
if (m_egl_display != EGL_NO_DISPLAY) {
|
||||||
|
eglTerminate(m_egl_display);
|
||||||
|
m_egl_display = EGL_NO_DISPLAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::initSurface()
|
||||||
|
{
|
||||||
|
assert(m_egl_display != EGL_NO_DISPLAY);
|
||||||
|
if (m_egl_surface != EGL_NO_SURFACE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ALOGI("NativeEngine: initializing surface");
|
||||||
|
|
||||||
|
EGLint num_configs;
|
||||||
|
const EGLint attribs[] = {
|
||||||
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
|
||||||
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||||
|
EGL_BLUE_SIZE, 8,
|
||||||
|
EGL_GREEN_SIZE, 8,
|
||||||
|
EGL_RED_SIZE, 8,
|
||||||
|
EGL_DEPTH_SIZE, 16,
|
||||||
|
EGL_NONE,
|
||||||
|
};
|
||||||
|
eglChooseConfig(m_egl_display, attribs, &m_egl_config, 1, &num_configs);
|
||||||
|
|
||||||
|
m_egl_surface = eglCreateWindowSurface(m_egl_display, m_egl_config, m_app->window, nullptr);
|
||||||
|
if (m_egl_surface == EGL_NO_SURFACE) {
|
||||||
|
ALOGE("Failed to create EGL surface. EGL error: %d", eglGetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::killSurface()
|
||||||
|
{
|
||||||
|
ALOGI("NativeEngine: Killing surface.");
|
||||||
|
eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
|
if (m_egl_surface != EGL_NO_SURFACE) {
|
||||||
|
eglDestroySurface(m_egl_display, m_egl_surface);
|
||||||
|
m_egl_surface = EGL_NO_SURFACE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::initContext()
|
||||||
|
{
|
||||||
|
ALOGI("NativeEngine: initializing context");
|
||||||
|
assert(m_egl_display != EGL_NO_DISPLAY);
|
||||||
|
|
||||||
|
EGLint attrib_list[] = {
|
||||||
|
EGL_CONTEXT_CLIENT_VERSION, 3,
|
||||||
|
EGL_NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
if (m_egl_context != EGL_NO_CONTEXT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
m_egl_context = eglCreateContext(m_egl_display, m_egl_config, nullptr, attrib_list);
|
||||||
|
if (m_egl_context == EGL_NO_CONTEXT) {
|
||||||
|
ALOGE("Failed to create EGL context, egl error: %d", eglGetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::killContext()
|
||||||
|
{
|
||||||
|
ALOGI("NativeEngine: Killing context");
|
||||||
|
|
||||||
|
killGLObjects();
|
||||||
|
|
||||||
|
eglMakeCurrent(m_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
|
if (m_egl_context != EGL_NO_CONTEXT) {
|
||||||
|
eglDestroyContext(m_egl_display, m_egl_context);
|
||||||
|
m_egl_context = EGL_NO_CONTEXT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NativeEngine::initGLObjects()
|
||||||
|
{
|
||||||
|
if (Renderer::ptr) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Renderer::create();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::killGLObjects()
|
||||||
|
{
|
||||||
|
if (Renderer::ptr) {
|
||||||
|
Renderer::destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeEngine::renderFrame()
|
||||||
|
{
|
||||||
|
if (!prepareToRender()) {
|
||||||
|
ALOGE("NativeEngine: preparation to render failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
eglQuerySurface(m_egl_display, m_egl_surface, EGL_WIDTH, &width);
|
||||||
|
eglQuerySurface(m_egl_display, m_egl_surface, EGL_HEIGHT, &height);
|
||||||
|
|
||||||
|
Renderer::ptr->renderFrame(static_cast<float>(width), static_cast<float>(height));
|
||||||
|
|
||||||
|
if (!SwappyGL_swap(m_egl_display, m_egl_surface)) {
|
||||||
|
ALOGW("NativeEngine: SwappyGL_swap failed, EGL error %d", eglGetError());
|
||||||
|
}
|
||||||
|
}
|
65
app/src/main/cpp/NativeEngine.h
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_NATIVEENGINE_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_NATIVEENGINE_H
|
||||||
|
|
||||||
|
#include "Position.h"
|
||||||
|
#include "StringRepository.h"
|
||||||
|
|
||||||
|
#include <game-activity/native_app_glue/android_native_app_glue.h>
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
|
||||||
|
struct NativeEngineState
|
||||||
|
{
|
||||||
|
bool has_focus;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NativeEngine {
|
||||||
|
public:
|
||||||
|
NativeEngine(struct android_app* app);
|
||||||
|
~NativeEngine();
|
||||||
|
|
||||||
|
void gameLoop();
|
||||||
|
|
||||||
|
void handleAppCmd(int32_t event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isAnimating() const;
|
||||||
|
|
||||||
|
JNIEnv* getJniEnv();
|
||||||
|
|
||||||
|
bool prepareToRender();
|
||||||
|
void renderFrame();
|
||||||
|
|
||||||
|
bool initDisplay();
|
||||||
|
void killDisplay();
|
||||||
|
bool initSurface();
|
||||||
|
void killSurface();
|
||||||
|
bool initContext();
|
||||||
|
void killContext();
|
||||||
|
|
||||||
|
bool initGLObjects();
|
||||||
|
void killGLObjects();
|
||||||
|
|
||||||
|
struct android_app* m_app;
|
||||||
|
|
||||||
|
bool m_has_window;
|
||||||
|
bool m_has_focus;
|
||||||
|
bool m_is_visible;
|
||||||
|
|
||||||
|
NativeEngineState m_state;
|
||||||
|
|
||||||
|
EGLDisplay m_egl_display;
|
||||||
|
EGLSurface m_egl_surface;
|
||||||
|
EGLContext m_egl_context;
|
||||||
|
EGLConfig m_egl_config;
|
||||||
|
|
||||||
|
StringHandle m_smiley;
|
||||||
|
Position m_smiley_pos;
|
||||||
|
|
||||||
|
Position m_last_down;
|
||||||
|
bool m_in_motion;
|
||||||
|
|
||||||
|
JNIEnv* m_jni_env;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
10
app/src/main/cpp/Position.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_POSITION_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_POSITION_H
|
||||||
|
|
||||||
|
struct Position
|
||||||
|
{
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //KRIMI_DINNER_ENGINE_POSITION_H
|
258
app/src/main/cpp/Renderer.cpp
Normal file
|
@ -0,0 +1,258 @@
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "AssetManager.h"
|
||||||
|
|
||||||
|
Renderer* Renderer::ptr = nullptr;
|
||||||
|
|
||||||
|
static const char* g_vert_src =
|
||||||
|
"#version 300 es \n"
|
||||||
|
"precision mediump float; \n"
|
||||||
|
"uniform vec2 res; // resolution \n"
|
||||||
|
"layout (location = 0) in vec2 v_p0; // top left corner on screen \n"
|
||||||
|
"layout (location = 1) in vec2 v_p1; // top right corner on screen \n"
|
||||||
|
"layout (location = 2) in vec2 v_src_p0; \n"
|
||||||
|
"layout (location = 3) in vec2 v_src_p1; \n"
|
||||||
|
"layout (location = 4) in vec4 v_color; // color \n"
|
||||||
|
"out vec4 f_color; \n"
|
||||||
|
"out vec2 f_uv; \n"
|
||||||
|
"const vec2 vertices[6] = vec2[6]( \n"
|
||||||
|
" vec2(-1,-1), \n"
|
||||||
|
" vec2(+1, -1), \n"
|
||||||
|
" vec2(-1, +1), \n"
|
||||||
|
" vec2(+1, -1), \n"
|
||||||
|
" vec2(+1, +1), \n"
|
||||||
|
" vec2(-1, +1) \n"
|
||||||
|
"); \n"
|
||||||
|
"void main() \n"
|
||||||
|
"{ \n"
|
||||||
|
" vec2 v = vertices[gl_VertexID]; \n"
|
||||||
|
" // destination on screen \n"
|
||||||
|
" //vec2 dst_half_size = (v_p1 - v_p0) / 2.0; \n"
|
||||||
|
" //vec2 dst_center = (v_p1 + v_p0) / 2.0; \n"
|
||||||
|
" vec2 dst_pos = v * ((v_p1 - v_p0) / 2.0) + ((v_p1 + v_p0) / 2.0); \n"
|
||||||
|
" dst_pos.y = res.y - dst_pos.y; \n"
|
||||||
|
" vec2 src = v * ((v_src_p1 - v_src_p0) / 2.0) + ((v_src_p1 + v_src_p0) / 2.0); \n"
|
||||||
|
" gl_Position = vec4(2.0 * dst_pos.x / res.x - 1.0, \n"
|
||||||
|
" 2.0 * dst_pos.y / res.y - 1.0, \n"
|
||||||
|
" 0.0, \n"
|
||||||
|
" 1.0); \n"
|
||||||
|
" f_color = v_color; \n"
|
||||||
|
" f_uv = src; \n"
|
||||||
|
"} \n";
|
||||||
|
|
||||||
|
static const char* g_frag_src =
|
||||||
|
"#version 300 es \n"
|
||||||
|
"precision mediump float; \n"
|
||||||
|
"in vec2 f_uv; \n"
|
||||||
|
"in vec4 f_color; \n"
|
||||||
|
"layout (location = 0) out vec4 frag_color; \n"
|
||||||
|
"uniform sampler2D s_texture; \n"
|
||||||
|
"void main() \n"
|
||||||
|
"{ \n"
|
||||||
|
" vec4 tex_color = texture(s_texture, f_uv); \n"
|
||||||
|
" frag_color = tex_color * f_color; \n"
|
||||||
|
"} \n";
|
||||||
|
|
||||||
|
void Renderer::create()
|
||||||
|
{
|
||||||
|
Renderer::ptr = new Renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::destroy()
|
||||||
|
{
|
||||||
|
delete Renderer::ptr;
|
||||||
|
Renderer::ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer::Renderer()
|
||||||
|
{
|
||||||
|
GLuint vertex = 0, fragment = 0;
|
||||||
|
vertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
|
glShaderSource(vertex, 1, &g_vert_src, nullptr);
|
||||||
|
glCompileShader(vertex);
|
||||||
|
int status = 0;
|
||||||
|
glGetShaderiv(vertex, GL_COMPILE_STATUS, &status);
|
||||||
|
if (status != GL_TRUE) {
|
||||||
|
char info[512];
|
||||||
|
glGetShaderInfoLog(vertex, 512, nullptr, info);
|
||||||
|
ALOGE("Failed to compile ui vertex shader: %s", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fragment = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
glShaderSource(fragment, 1, &g_frag_src, nullptr);
|
||||||
|
glCompileShader(fragment);
|
||||||
|
glGetShaderiv(fragment, GL_COMPILE_STATUS, &status);
|
||||||
|
if (status != GL_TRUE) {
|
||||||
|
char info[512];
|
||||||
|
glGetShaderInfoLog(fragment, 512, nullptr, info);
|
||||||
|
ALOGE("Failed to compile ui fragment shader: %s", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_shader = glCreateProgram();
|
||||||
|
glAttachShader(m_shader, vertex);
|
||||||
|
glAttachShader(m_shader, fragment);
|
||||||
|
glLinkProgram(m_shader);
|
||||||
|
glGetProgramiv(m_shader, GL_LINK_STATUS, &status);
|
||||||
|
if (status != GL_TRUE) {
|
||||||
|
char info[512];
|
||||||
|
glGetProgramInfoLog(m_shader, 512, nullptr, info);
|
||||||
|
ALOGE("Failed to link ui shader: %s", info);
|
||||||
|
}
|
||||||
|
|
||||||
|
glDeleteShader(vertex);
|
||||||
|
glDeleteShader(fragment);
|
||||||
|
|
||||||
|
glGenBuffers(1, &m_vbo);
|
||||||
|
glGenVertexArrays(1, &m_vao);
|
||||||
|
glBindVertexArray(m_vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)0);
|
||||||
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(2 * sizeof(float)));
|
||||||
|
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(4 * sizeof(float)));
|
||||||
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(6 * sizeof(float)));
|
||||||
|
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Rect), (GLvoid*)(8 * sizeof(float)));
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glEnableVertexAttribArray(1);
|
||||||
|
glEnableVertexAttribArray(2);
|
||||||
|
glEnableVertexAttribArray(3);
|
||||||
|
glEnableVertexAttribArray(4);
|
||||||
|
glVertexAttribDivisor(0, 1);
|
||||||
|
glVertexAttribDivisor(1, 1);
|
||||||
|
glVertexAttribDivisor(2, 1);
|
||||||
|
glVertexAttribDivisor(3, 1);
|
||||||
|
glVertexAttribDivisor(4, 1);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
// Dummy texture (1x1px white)
|
||||||
|
unsigned char tex[] = { 255, 255, 255, 255 };
|
||||||
|
Texture dummy_texture(1, 1, tex);
|
||||||
|
m_textures.insert(std::make_pair(0, dummy_texture));
|
||||||
|
m_dummy_texture = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer::~Renderer() {
|
||||||
|
for (auto texture : m_textures)
|
||||||
|
texture.second.destroy();
|
||||||
|
glDeleteProgram(m_shader);
|
||||||
|
glDeleteVertexArrays(1, &m_vao);
|
||||||
|
glDeleteBuffers(1, &m_vbo);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h)
|
||||||
|
{
|
||||||
|
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, m_dummy_texture, 0.f, 0.f, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h, StringHandle texture)
|
||||||
|
{
|
||||||
|
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, texture, 0.f, 0.f, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h, float r, float g, float b, float a)
|
||||||
|
{
|
||||||
|
addRect(x, y, w, h, r, g, b, a, m_dummy_texture, 0.f, 0.f, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h, float r, float g, float b, float a, StringHandle texture)
|
||||||
|
{
|
||||||
|
addRect(x, y, w, h, r, g, b, a, texture, 0.f, 0.f, 1.f, 1.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h, StringHandle texture, float src_x, float src_y, float src_w, float src_h)
|
||||||
|
{
|
||||||
|
addRect(x, y, w, h, 1.f, 1.f, 1.f, 1.f, texture, src_x, src_y, src_w, src_h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::addRect(float x, float y, float w, float h, float r, float g, float b, float a, StringHandle texture, float src_x, float src_y, float src_w, float src_h)
|
||||||
|
{
|
||||||
|
if (m_textures.find(texture) == m_textures.end()) {
|
||||||
|
Texture tex;
|
||||||
|
if (!AssetManager::ptr->loadTexture(StringRepository::global->getString(texture),
|
||||||
|
&tex)) {
|
||||||
|
ALOGE("Failed to load texture");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_textures.insert(std::make_pair(texture, tex));
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect rect = {};
|
||||||
|
rect.dst_p0_x = x;
|
||||||
|
rect.dst_p0_y = y;
|
||||||
|
rect.dst_p1_x = x + w;
|
||||||
|
rect.dst_p1_y = y + h;
|
||||||
|
rect.src_p0_x = src_x;
|
||||||
|
rect.src_p0_y = src_y;
|
||||||
|
rect.src_p1_x = src_w;
|
||||||
|
rect.src_p1_y = src_y + src_h;
|
||||||
|
rect.r = r;
|
||||||
|
rect.g = g;
|
||||||
|
rect.b = b;
|
||||||
|
rect.a = a;
|
||||||
|
m_rects.push_back(rect);
|
||||||
|
m_draw_textures.push_back(texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Renderer::renderFrame(float width, float height)
|
||||||
|
{
|
||||||
|
assert(m_rects.size() == m_draw_textures.size());
|
||||||
|
|
||||||
|
const auto rect_count = static_cast<GLsizei>(m_rects.size());
|
||||||
|
if (rect_count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
glViewport(0, 0, static_cast<int>(width), static_cast<int>(height));
|
||||||
|
glClearColor(0.8f, 0.3f, 0.3f, 1.f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendEquation(GL_FUNC_ADD);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
|
glBindVertexArray(m_vao);
|
||||||
|
glUseProgram(m_shader);
|
||||||
|
glUniform2f(glGetUniformLocation(m_shader, "res"), width, height);
|
||||||
|
glUniform1i(glGetUniformLocation(m_shader, "s_texture"), 0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||||
|
|
||||||
|
size_t start = 0;
|
||||||
|
StringHandle current_texture = m_draw_textures[0];
|
||||||
|
while (start < rect_count) {
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
m_textures[current_texture].bind();
|
||||||
|
for (size_t i = start; i < rect_count; ++i) {
|
||||||
|
StringHandle texture = m_draw_textures[i];
|
||||||
|
if ((texture != current_texture)) {
|
||||||
|
// Draw everything in [start, i - 1]
|
||||||
|
const size_t count = i - start;
|
||||||
|
glBufferData(GL_ARRAY_BUFFER,
|
||||||
|
static_cast<GLsizeiptr>(sizeof(Rect) * count), &m_rects[start],
|
||||||
|
GL_STREAM_DRAW);
|
||||||
|
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, static_cast<GLsizei>(count));
|
||||||
|
|
||||||
|
start = i;
|
||||||
|
current_texture = texture;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == rect_count - 1) {
|
||||||
|
// just draw it
|
||||||
|
const size_t count = rect_count - start;
|
||||||
|
glBufferData(GL_ARRAY_BUFFER,
|
||||||
|
static_cast<GLsizeiptr>(sizeof(Rect) * count), &m_rects[start],
|
||||||
|
GL_STREAM_DRAW);
|
||||||
|
glDrawArraysInstanced(GL_TRIANGLES, 0, 6, static_cast<GLsizei>(count));
|
||||||
|
|
||||||
|
start = rect_count;
|
||||||
|
current_texture = texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
m_rects.clear();
|
||||||
|
m_draw_textures.clear();
|
||||||
|
}
|
62
app/src/main/cpp/Renderer.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_RENDERER_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_RENDERER_H
|
||||||
|
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "Texture.h"
|
||||||
|
#include "StringRepository.h"
|
||||||
|
|
||||||
|
class Renderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static Renderer* ptr;
|
||||||
|
|
||||||
|
static void create();
|
||||||
|
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h);
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h, StringHandle texture);
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h, float r, float g, float b, float a);
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h, float r, float g, float b, float a, StringHandle texture);
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h, StringHandle texture, float src_x, float src_y, float src_w, float src_h);
|
||||||
|
|
||||||
|
void addRect(float x, float y, float w, float h, float r, float g, float b, float a, StringHandle texture, float src_x, float src_y, float src_w, float src_h);
|
||||||
|
|
||||||
|
void renderFrame(float width, float height);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Renderer();
|
||||||
|
~Renderer();
|
||||||
|
|
||||||
|
Renderer(const Renderer&) = delete;
|
||||||
|
Renderer& operator=(const Renderer&) = delete;
|
||||||
|
|
||||||
|
struct Rect {
|
||||||
|
float dst_p0_x, dst_p0_y;
|
||||||
|
float dst_p1_x, dst_p1_y;
|
||||||
|
float src_p0_x, src_p0_y;
|
||||||
|
float src_p1_x, src_p1_y;
|
||||||
|
float r, g, b, a;
|
||||||
|
};
|
||||||
|
|
||||||
|
GLuint m_shader;
|
||||||
|
GLuint m_vao;
|
||||||
|
GLuint m_vbo;
|
||||||
|
|
||||||
|
StringHandle m_dummy_texture;
|
||||||
|
|
||||||
|
std::vector<Rect> m_rects;
|
||||||
|
std::vector<StringHandle> m_draw_textures;
|
||||||
|
|
||||||
|
std::unordered_map<StringHandle, Texture> m_textures;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
84
app/src/main/cpp/StringRepository.cpp
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
#include "StringRepository.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
static StringRepository g_global_repository;
|
||||||
|
StringRepository* StringRepository::global = &g_global_repository;
|
||||||
|
|
||||||
|
static uint64_t hashString(const char* string, unsigned int length)
|
||||||
|
{
|
||||||
|
uint64_t hash = 0xcbf29ce484222325;
|
||||||
|
for (unsigned int i = 0; i < length; ++i) {
|
||||||
|
hash = hash ^ string[i];
|
||||||
|
hash = hash * 0x00000100000001B3;
|
||||||
|
}
|
||||||
|
if (hash == HASH_EMPTY_KEY || hash == HASH_TOMBSTONE_KEY)
|
||||||
|
hash = ~hash;
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringRepository::StringRepository(const StringRepository& copy)
|
||||||
|
{
|
||||||
|
if (m_buffer)
|
||||||
|
free(m_buffer);
|
||||||
|
m_one_past_last_char = copy.m_one_past_last_char;
|
||||||
|
m_buffer_size = copy.m_buffer_size;
|
||||||
|
m_hash = copy.m_hash;
|
||||||
|
m_buffer = reinterpret_cast<char*>(malloc(m_buffer_size));
|
||||||
|
memcpy(m_buffer, copy.m_buffer, m_buffer_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringRepository::~StringRepository()
|
||||||
|
{
|
||||||
|
m_one_past_last_char = 0;
|
||||||
|
m_buffer_size = 0;
|
||||||
|
free(m_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringHandle StringRepository::internStringLength(const char* string, unsigned int length)
|
||||||
|
{
|
||||||
|
uint64_t hash = hashString(string, length);
|
||||||
|
uint32_t offset = static_cast<uint32_t>(m_hash.lookup(hash, UINT32_MAX));
|
||||||
|
if (offset == UINT32_MAX) {
|
||||||
|
offset = m_one_past_last_char;
|
||||||
|
if ((offset + length + 1) >= m_buffer_size) {
|
||||||
|
uint32_t new_size = (m_buffer_size > 0) ? 2 * m_buffer_size : 1024;
|
||||||
|
void* tmp = realloc(m_buffer, new_size);
|
||||||
|
if (!tmp)
|
||||||
|
return 0;
|
||||||
|
m_buffer = reinterpret_cast<char*>(tmp);
|
||||||
|
m_buffer_size = new_size;
|
||||||
|
}
|
||||||
|
char* dest = m_buffer + offset;
|
||||||
|
memcpy(dest, string, length);
|
||||||
|
dest[length] = '\0';
|
||||||
|
m_one_past_last_char += length + 1;
|
||||||
|
if (!m_hash.insert(hash, offset))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return static_cast<StringHandle>(offset + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
StringHandle StringRepository::internString(const char* string)
|
||||||
|
{
|
||||||
|
return internStringLength(string, strlen(string));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* StringRepository::getString(StringHandle handle)
|
||||||
|
{
|
||||||
|
if (handle == 0 || handle >= m_one_past_last_char)
|
||||||
|
return nullptr;
|
||||||
|
uint32_t offset = handle - 1;
|
||||||
|
return &m_buffer[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringRepository::releaseString(StringHandle)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
void StringRepository::freeAll()
|
||||||
|
{
|
||||||
|
m_one_past_last_char = 0;
|
||||||
|
m_hash = Hash();
|
||||||
|
}
|
39
app/src/main/cpp/StringRepository.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_STRINGREPOSITORY_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_STRINGREPOSITORY_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "Hash.h"
|
||||||
|
|
||||||
|
using StringHandle = uint32_t;
|
||||||
|
|
||||||
|
// Alias for compatibility
|
||||||
|
using nt_string_handle = StringHandle;
|
||||||
|
|
||||||
|
class StringRepository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// The default string repository
|
||||||
|
static StringRepository* global;
|
||||||
|
|
||||||
|
StringRepository() = default;
|
||||||
|
StringRepository(const StringRepository& copy);
|
||||||
|
~StringRepository();
|
||||||
|
|
||||||
|
StringHandle internStringLength(const char* string, unsigned int length);
|
||||||
|
|
||||||
|
StringHandle internString(const char* string);
|
||||||
|
|
||||||
|
const char* getString(StringHandle handle);
|
||||||
|
|
||||||
|
void releaseString(StringHandle handle);
|
||||||
|
|
||||||
|
void freeAll();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32_t m_buffer_size;
|
||||||
|
uint32_t m_one_past_last_char;
|
||||||
|
char* m_buffer;
|
||||||
|
Hash m_hash;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
34
app/src/main/cpp/Texture.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
|
Texture::Texture(unsigned int width, unsigned int height, const void *data)
|
||||||
|
: m_texture(0)
|
||||||
|
{
|
||||||
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
glGenTextures(1, &m_texture);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D,
|
||||||
|
0,
|
||||||
|
GL_RGBA,
|
||||||
|
static_cast<GLsizei>(width),
|
||||||
|
static_cast<GLsizei>(height),
|
||||||
|
0,
|
||||||
|
GL_RGBA,
|
||||||
|
GL_UNSIGNED_BYTE,
|
||||||
|
data);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::destroy()
|
||||||
|
{
|
||||||
|
glDeleteTextures(1, &m_texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Texture::bind() const
|
||||||
|
{
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_texture);
|
||||||
|
}
|
25
app/src/main/cpp/Texture.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_TEXTURE_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_TEXTURE_H
|
||||||
|
|
||||||
|
#include <GLES3/gl3.h>
|
||||||
|
|
||||||
|
class Renderer;
|
||||||
|
|
||||||
|
class Texture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Texture() : m_texture(0) {}
|
||||||
|
Texture(unsigned int width, unsigned int height, const void* data);
|
||||||
|
Texture(const Texture&) = default;
|
||||||
|
Texture(Texture&&) = default;
|
||||||
|
Texture& operator=(const Texture&) = default;
|
||||||
|
|
||||||
|
void destroy();
|
||||||
|
|
||||||
|
void bind() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
GLuint m_texture;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
19
app/src/main/cpp/TouchInput.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef KRIMI_DINNER_ENGINE_TOUCHINPUT_H
|
||||||
|
#define KRIMI_DINNER_ENGINE_TOUCHINPUT_H
|
||||||
|
|
||||||
|
#include "Position.h"
|
||||||
|
|
||||||
|
enum class TouchInputEventKind
|
||||||
|
{
|
||||||
|
Tap,
|
||||||
|
Swipe
|
||||||
|
};
|
||||||
|
|
||||||
|
struct TouchInputEvent
|
||||||
|
{
|
||||||
|
TouchInputEventKind kind;
|
||||||
|
Position start;
|
||||||
|
Position end;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
15
app/src/main/cpp/kde.cpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#include <game-activity/GameActivity.cpp>
|
||||||
|
#include <game-text-input/gametextinput.cpp>
|
||||||
|
extern "C" {
|
||||||
|
#include <game-activity/native_app_glue/android_native_app_glue.c>
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" { void android_main(struct android_app* app); }
|
||||||
|
|
||||||
|
#include "NativeEngine.h"
|
||||||
|
|
||||||
|
void android_main(struct android_app* app) {
|
||||||
|
auto* engine = new NativeEngine(app);
|
||||||
|
engine->gameLoop();
|
||||||
|
delete engine;
|
||||||
|
}
|
7897
app/src/main/cpp/stb_image.h
Normal file
26
app/src/main/java/tech/recreational/kde/KDEActivity.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package tech.recreational.kde;
|
||||||
|
import androidx.core.view.ViewCompat;
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat;
|
||||||
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
import com.google.androidgamesdk.GameActivity;
|
||||||
|
|
||||||
|
public class KDEActivity extends GameActivity {
|
||||||
|
static {
|
||||||
|
System.loadLibrary("kde");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
hideSystemBars();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hideSystemBars() {
|
||||||
|
WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(
|
||||||
|
getWindow().getDecorView());
|
||||||
|
if (windowInsetsController == null)
|
||||||
|
return;
|
||||||
|
windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
|
||||||
|
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||||
|
<aapt:attr name="android:fillColor">
|
||||||
|
<gradient
|
||||||
|
android:endX="85.84757"
|
||||||
|
android:endY="92.4963"
|
||||||
|
android:startX="42.9492"
|
||||||
|
android:startY="49.59793"
|
||||||
|
android:type="linear">
|
||||||
|
<item
|
||||||
|
android:color="#44000000"
|
||||||
|
android:offset="0.0" />
|
||||||
|
<item
|
||||||
|
android:color="#00000000"
|
||||||
|
android:offset="1.0" />
|
||||||
|
</gradient>
|
||||||
|
</aapt:attr>
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
</vector>
|
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#3DDC84"
|
||||||
|
android:pathData="M0,0h108v108h-108z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M9,0L9,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,0L19,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,0L29,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,0L39,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,0L49,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,0L59,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,0L69,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,0L79,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M89,0L89,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M99,0L99,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,9L108,9"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,19L108,19"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,29L108,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,39L108,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,49L108,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,59L108,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,69L108,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,79L108,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,89L108,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,99L108,99"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,29L89,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,39L89,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,49L89,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,59L89,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,69L89,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,79L89,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,19L29,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,19L39,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,19L49,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,19L59,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,19L69,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,19L79,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
</vector>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 982 B |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
After Width: | Height: | Size: 7.6 KiB |
16
app/src/main/res/values-night/themes.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Theme.KrimiDinnerENgine" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||||
|
<!-- Primary brand color. -->
|
||||||
|
<item name="colorPrimary">@color/purple_200</item>
|
||||||
|
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||||
|
<item name="colorOnPrimary">@color/black</item>
|
||||||
|
<!-- Secondary brand color. -->
|
||||||
|
<item name="colorSecondary">@color/teal_200</item>
|
||||||
|
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||||
|
<item name="colorOnSecondary">@color/black</item>
|
||||||
|
<!-- Status bar color. -->
|
||||||
|
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
</style>
|
||||||
|
</resources>
|
10
app/src/main/res/values/colors.xml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="purple_200">#FFBB86FC</color>
|
||||||
|
<color name="purple_500">#FF6200EE</color>
|
||||||
|
<color name="purple_700">#FF3700B3</color>
|
||||||
|
<color name="teal_200">#FF03DAC5</color>
|
||||||
|
<color name="teal_700">#FF018786</color>
|
||||||
|
<color name="black">#FF000000</color>
|
||||||
|
<color name="white">#FFFFFFFF</color>
|
||||||
|
</resources>
|
3
app/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<resources>
|
||||||
|
<string name="app_name">Krimi Dinner Engine</string>
|
||||||
|
</resources>
|
7
app/src/main/res/values/themes.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="Application.Fullscreen" parent="Theme.AppCompat.Light.NoActionBar">
|
||||||
|
<item name="android:windowFullscreen">true</item>
|
||||||
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
13
app/src/main/res/xml/backup_rules.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
Sample backup rules file; uncomment and customize as necessary.
|
||||||
|
See https://developer.android.com/guide/topics/data/autobackup
|
||||||
|
for details.
|
||||||
|
Note: This file is ignored for devices older that API 31
|
||||||
|
See https://developer.android.com/about/versions/12/backup-restore
|
||||||
|
-->
|
||||||
|
<full-backup-content>
|
||||||
|
<!--
|
||||||
|
<include domain="sharedpref" path="."/>
|
||||||
|
<exclude domain="sharedpref" path="device.xml"/>
|
||||||
|
-->
|
||||||
|
</full-backup-content>
|
19
app/src/main/res/xml/data_extraction_rules.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?><!--
|
||||||
|
Sample data extraction rules file; uncomment and customize as necessary.
|
||||||
|
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||||
|
for details.
|
||||||
|
-->
|
||||||
|
<data-extraction-rules>
|
||||||
|
<cloud-backup>
|
||||||
|
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||||
|
<include .../>
|
||||||
|
<exclude .../>
|
||||||
|
-->
|
||||||
|
</cloud-backup>
|
||||||
|
<!--
|
||||||
|
<device-transfer>
|
||||||
|
<include .../>
|
||||||
|
<exclude .../>
|
||||||
|
</device-transfer>
|
||||||
|
-->
|
||||||
|
</data-extraction-rules>
|
17
app/src/test/java/tech/recreational/kde/ExampleUnitTest.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package tech.recreational.kde;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example local unit test, which will execute on the development machine (host).
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
public class ExampleUnitTest {
|
||||||
|
@Test
|
||||||
|
public void addition_isCorrect() {
|
||||||
|
assertEquals(4, 2 + 2);
|
||||||
|
}
|
||||||
|
}
|
9
build.gradle
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
plugins {
|
||||||
|
id 'com.android.application' version '7.2.2' apply false
|
||||||
|
id 'com.android.library' version '7.2.2' apply false
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
21
gradle.properties
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Project-wide Gradle settings.
|
||||||
|
# IDE (e.g. Android Studio) users:
|
||||||
|
# Gradle settings configured through the IDE *will override*
|
||||||
|
# any settings specified in this file.
|
||||||
|
# For more details on how to configure your build environment visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
|
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
||||||
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
|
# org.gradle.parallel=true
|
||||||
|
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||||
|
# Android operating system, and which are packaged with your app"s APK
|
||||||
|
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||||
|
android.useAndroidX=true
|
||||||
|
# Enables namespacing of each library's R class so that its R class includes only the
|
||||||
|
# resources declared in the library itself and none from the library's dependencies,
|
||||||
|
# thereby reducing the size of the R class for that library
|
||||||
|
android.nonTransitiveRClass=true
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
6
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#Sun Oct 02 14:06:47 CEST 2022
|
||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
185
gradlew
vendored
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright 2015 the original author or authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
##
|
||||||
|
## Gradle start up script for UN*X
|
||||||
|
##
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
PRG="$0"
|
||||||
|
# Need this for relative symlinks.
|
||||||
|
while [ -h "$PRG" ] ; do
|
||||||
|
ls=`ls -ld "$PRG"`
|
||||||
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||||
|
if expr "$link" : '/.*' > /dev/null; then
|
||||||
|
PRG="$link"
|
||||||
|
else
|
||||||
|
PRG=`dirname "$PRG"`"/$link"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
SAVED="`pwd`"
|
||||||
|
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||||
|
APP_HOME="`pwd -P`"
|
||||||
|
cd "$SAVED" >/dev/null
|
||||||
|
|
||||||
|
APP_NAME="Gradle"
|
||||||
|
APP_BASE_NAME=`basename "$0"`
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD="maximum"
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "`uname`" in
|
||||||
|
CYGWIN* )
|
||||||
|
cygwin=true
|
||||||
|
;;
|
||||||
|
Darwin* )
|
||||||
|
darwin=true
|
||||||
|
;;
|
||||||
|
MINGW* )
|
||||||
|
msys=true
|
||||||
|
;;
|
||||||
|
NONSTOP* )
|
||||||
|
nonstop=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||||
|
else
|
||||||
|
JAVACMD="$JAVA_HOME/bin/java"
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD="java"
|
||||||
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||||
|
MAX_FD_LIMIT=`ulimit -H -n`
|
||||||
|
if [ $? -eq 0 ] ; then
|
||||||
|
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||||
|
MAX_FD="$MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
ulimit -n $MAX_FD
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Darwin, add options to specify how the application appears in the dock
|
||||||
|
if $darwin; then
|
||||||
|
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||||
|
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||||
|
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||||
|
|
||||||
|
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||||
|
|
||||||
|
# We build the pattern for arguments to be converted via cygpath
|
||||||
|
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||||
|
SEP=""
|
||||||
|
for dir in $ROOTDIRSRAW ; do
|
||||||
|
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||||
|
SEP="|"
|
||||||
|
done
|
||||||
|
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||||
|
# Add a user-defined pattern to the cygpath arguments
|
||||||
|
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||||
|
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||||
|
fi
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
i=0
|
||||||
|
for arg in "$@" ; do
|
||||||
|
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||||
|
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||||
|
|
||||||
|
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||||
|
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||||
|
else
|
||||||
|
eval `echo args$i`="\"$arg\""
|
||||||
|
fi
|
||||||
|
i=`expr $i + 1`
|
||||||
|
done
|
||||||
|
case $i in
|
||||||
|
0) set -- ;;
|
||||||
|
1) set -- "$args0" ;;
|
||||||
|
2) set -- "$args0" "$args1" ;;
|
||||||
|
3) set -- "$args0" "$args1" "$args2" ;;
|
||||||
|
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||||
|
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||||
|
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||||
|
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||||
|
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||||
|
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Escape application args
|
||||||
|
save () {
|
||||||
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
|
echo " "
|
||||||
|
}
|
||||||
|
APP_ARGS=`save "$@"`
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||||
|
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
89
gradlew.bat
vendored
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%" == "" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%" == "" set DIRNAME=.
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if "%ERRORLEVEL%" == "0" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||||
|
echo.
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
echo location of your Java installation.
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
16
settings.gradle
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
gradlePluginPortal()
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rootProject.name = "Krimi Dinner Engine"
|
||||||
|
include ':app'
|