Skip to content

Commit

Permalink
Android and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Sep 28, 2022
1 parent 2cca829 commit 8864d2f
Show file tree
Hide file tree
Showing 50 changed files with 2,708 additions and 2,285 deletions.
5 changes: 4 additions & 1 deletion BuildAndroid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
BuildType=Release
#BuildType=Debug

cmake -B ../Jazz2-Android-${BuildType} -D CMAKE_BUILD_TYPE=${BuildType} -D CMAKE_PREFIX_PATH=$(pwd)/../nCine-android-external -D NCINE_BUILD_ANDROID=ON
export ANDROID_HOME="$(pwd)/../android-sdk"
export GRADLE_HOME="$(pwd)/../gradle"

cmake -B ../Jazz2-Android-${BuildType} -D CMAKE_BUILD_TYPE=${BuildType} -D CMAKE_PREFIX_PATH=$(pwd)/../nCine-external -D EXTERNAL_ANDROID_DIR=$(pwd)/../nCine-android-external -D NCINE_BUILD_ANDROID=ON -D NCINE_ASSEMBLE_APK=ON -D NDK_DIR=$(pwd)/../android-ndk
make -j2 -C ../Jazz2-Android-${BuildType}
65 changes: 30 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,43 @@ include(ncine_imported_targets)
#include(ncine_nuklear)
include(ncine_tracy)

# Falling back to either GLFW or SDL2 if the other one is not available
if(NOT GLFW_FOUND AND NOT SDL2_FOUND AND NOT Qt5_FOUND)
message(FATAL_ERROR "No backend between SDL2, GLFW, and QT5 has been found")
elseif(GLFW_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "GLFW")
message(STATUS "Using GLFW as the preferred backend")
elseif(SDL2_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "SDL2")
message(STATUS "Using SDL2 as the preferred backend")
elseif(Qt5_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "QT5")
message(STATUS "Using QT5 as the preferred backend")
elseif(SDL2_FOUND AND NOT GLFW_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "GLFW")
set(NCINE_PREFERRED_BACKEND "SDL2")
message(WARNING "Using SDL2 as backend because GLFW cannot be found")
elseif(GLFW_FOUND AND NOT SDL2_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "SDL2")
set(NCINE_PREFERRED_BACKEND "GLFW")
message(WARNING "Using GLFW as backend because SDL2 cannot be found")
if(NCINE_BUILD_ANDROID)
if(NCINE_DYNAMIC_LIBRARY)
add_library(ncine SHARED)
else()
add_library(ncine STATIC)
target_compile_definitions(ncine PUBLIC "NCINE_STATIC")
endif()
else()
# Falling back to either GLFW or SDL2 if the other one is not available
if(NOT GLFW_FOUND AND NOT SDL2_FOUND AND NOT Qt5_FOUND)
message(FATAL_ERROR "No backend between SDL2, GLFW, and QT5 has been found")
elseif(GLFW_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "GLFW")
message(STATUS "Using GLFW as the preferred backend")
elseif(SDL2_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "SDL2")
message(STATUS "Using SDL2 as the preferred backend")
elseif(Qt5_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "QT5")
message(STATUS "Using QT5 as the preferred backend")
elseif(SDL2_FOUND AND NOT GLFW_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "GLFW")
set(NCINE_PREFERRED_BACKEND "SDL2")
message(WARNING "Using SDL2 as backend because GLFW cannot be found")
elseif(GLFW_FOUND AND NOT SDL2_FOUND AND NCINE_PREFERRED_BACKEND STREQUAL "SDL2")
set(NCINE_PREFERRED_BACKEND "GLFW")
message(WARNING "Using GLFW as backend because SDL2 cannot be found")
endif()

add_executable(ncine)
endif()

#if(NCINE_DYNAMIC_LIBRARY)
# add_library(ncine SHARED)
#else()
# add_library(ncine STATIC)
# target_compile_definitions(ncine PUBLIC "NCINE_STATIC")
#endif()

#add_library(ncine_main STATIC ${CMAKE_SOURCE_DIR}/tests/main.cpp)
#target_link_libraries(ncine_main PRIVATE ncine)
#set_target_properties(ncine PROPERTIES DEBUG_POSTFIX "_d")
#set_target_properties(ncine_main PROPERTIES DEBUG_POSTFIX "_d")

add_executable(ncine)

include(ncine_compiler_options)

set(NCINE_ROOT ${CMAKE_SOURCE_DIR})
set(NCINE_SOURCE_DIR "${NCINE_ROOT}/Jazz2/")
set(NCINE_REVERSE_DNS "jazz2.resurrection")
set(NCINE_APP_NAME "Jazz² Resurrection")
set(NCINE_APP_DESCRIPTION "Open-source reimplementation of Jazz Jackrabbit 2")

include(ncine_headers)
#include(ncine_private_headers)
include(ncine_sources)
include(ncine_extra_sources)
include(ncine_generated_sources)
Expand Down Expand Up @@ -110,11 +109,7 @@ if(NCINE_WITH_TRACY)
PUBLIC $<BUILD_INTERFACE:${TRACY_INCLUDE_ONLY_DIR}/tracy>
PUBLIC $<INSTALL_INTERFACE:include/tracy>)
endif()
target_include_directories(ncine
INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
INTERFACE $<INSTALL_INTERFACE:include>
PRIVATE Shared
)
target_include_directories(ncine PRIVATE ${NCINE_ROOT}/Shared)
if(NOT NCINE_DYNAMIC_LIBRARY)
target_include_directories(ncine
INTERFACE $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/ncine>)
Expand Down
4 changes: 4 additions & 0 deletions Jazz2/Jazz2/Actors/ActorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "Weapons/FreezerShot.h"
#include "Weapons/ToasterShot.h"

#if !defined(WITH_COROUTINES)
# pragma message("<coroutine> support was not found, building without asynchronous loading support")
#endif

#include "../../nCine/Primitives/Matrix4x4.h"
#include "../../nCine/Base/Random.h"
#include "../../nCine/Base/FrameTimer.h"
Expand Down
14 changes: 14 additions & 0 deletions Jazz2/Jazz2/Actors/ActorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include "../../nCine/Primitives/AABB.h"
#include "../../nCine/Audio/AudioBufferPlayer.h"

// If coroutines are not supported, load resources synchronously
#if !defined(WITH_COROUTINES)
# define co_return return
# define co_await
#endif

namespace Jazz2
{
class ILevelHandler;
Expand Down Expand Up @@ -280,6 +286,7 @@ namespace Jazz2::Actors
_metadata = ContentResolver::Current().RequestMetadata(path);
}

#if defined(WITH_COROUTINES)
auto RequestMetadataAsync(const StringView& path)
{
struct awaitable {
Expand All @@ -299,6 +306,13 @@ namespace Jazz2::Actors
};
return awaitable { this, path };
}
#else
void RequestMetadataAsync(const StringView& path)
{
auto metadata = ContentResolver::Current().RequestMetadata(path);
_metadata = metadata;
}
#endif

constexpr void SetState(ActorState flags) noexcept
{
Expand Down
2 changes: 1 addition & 1 deletion Jazz2/Jazz2/Actors/Enemies/EnemyBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace Jazz2::Actors::Enemies
{ EventType::Gem, 6 }
};

constexpr int combinedChance = std::accumulate(DropChanges, DropChanges + _countof(DropChanges), 0, [](const int& sum, const auto& item) {
int combinedChance = std::accumulate(DropChanges, DropChanges + _countof(DropChanges), 0, [](const int& sum, const auto& item) {
return sum + item.Chance;
});

Expand Down
5 changes: 3 additions & 2 deletions Jazz2/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace Jazz2
_blurPass3(this),
_blurPass4(this),
#endif
_pressedKeys((uint32_t)KeySym::COUNT_BASE),
_pressedKeys((uint32_t)KeySym::COUNT),
_pressedActions(0),
_overrideActions(0),
_playerFrozenEnabled(false)
Expand Down Expand Up @@ -1386,7 +1386,8 @@ namespace Jazz2
if (_pressedKeys[(uint32_t)UI::ControlScheme::Key1(0, PlayerActions::ChangeWeapon)] || _pressedKeys[(uint32_t)UI::ControlScheme::Key2(0, PlayerActions::ChangeWeapon)]) {
_pressedActions |= (1 << (int)PlayerActions::ChangeWeapon);
}
if (_pressedKeys[(uint32_t)UI::ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)UI::ControlScheme::Key2(0, PlayerActions::Menu)]) {
// Allow Android Back button as menu key
if (_pressedKeys[(uint32_t)UI::ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)UI::ControlScheme::Key2(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)KeySym::BACK]) {
_pressedActions |= (1 << (int)PlayerActions::Menu);
}

Expand Down
4 changes: 2 additions & 2 deletions Jazz2/Jazz2/UI/Cinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Jazz2::UI
_frameProgress(0.0f),
_framesLeft(0),
_currentOffsets { },
_pressedKeys((uint32_t)KeySym::COUNT_BASE),
_pressedKeys((uint32_t)KeySym::COUNT),
_pressedActions(0)
{
theApplication().gfxDevice().setWindowTitle("Jazz² Resurrection"_s);
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace Jazz2::UI

if (_pressedKeys[(uint32_t)KeySym::RETURN] || _pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Fire)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Fire)] ||
_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Jump)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Jump)] ||
_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)]) {
_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)KeySym::BACK]) {
_pressedActions |= (1 << (int)PlayerActions::Fire);
}

Expand Down
6 changes: 3 additions & 3 deletions Jazz2/Jazz2/UI/Menu/BeginSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Jazz2::UI::Menu
#endif
_items[(int)Item::Options].Name = "Options"_s;
_items[(int)Item::About].Name = "About"_s;
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_EMSCRIPTEN)
#if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)
_items[(int)Item::Quit].Name = "Quit"_s;
#endif
}
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace Jazz2::UI::Menu
if (_root->ActionHit(PlayerActions::Fire)) {
ExecuteSelected();
} else if (_root->ActionHit(PlayerActions::Menu)) {
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_EMSCRIPTEN)
#if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)
if (_selectedIndex != (int)Item::Quit) {
_root->PlaySfx("MenuSelect"_s, 0.6f);
_animation = 0.0f;
Expand Down Expand Up @@ -174,7 +174,7 @@ namespace Jazz2::UI::Menu
#endif
case (int)Item::Options: _root->SwitchToSection<OptionsSection>(); break;
case (int)Item::About: _root->SwitchToSection<AboutSection>(); break;
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_EMSCRIPTEN)
#if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)
case (int)Item::Quit: theApplication().quit(); break;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion Jazz2/Jazz2/UI/Menu/BeginSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Jazz2::UI::Menu
#endif
Options,
About,
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_EMSCRIPTEN)
#if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)
Quit,
#endif
Count
Expand Down
10 changes: 9 additions & 1 deletion Jazz2/Jazz2/UI/Menu/GameplayOptionsSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ namespace Jazz2::UI::Menu
_isDirty(false)
{
_items[(int)Item::Enhancements].Name = "Enhancements"_s;
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_IOS)
_items[(int)Item::EnableRgbLights].Name = "Razer Chroma™"_s;
#endif
#if defined(WITH_ANGELSCRIPT)
_items[(int)Item::AllowUnsignedScripts].Name = "Scripting"_s;
#endif
Expand Down Expand Up @@ -107,11 +109,13 @@ namespace Jazz2::UI::Menu
if (i >= 1) {
bool enabled;
switch (i) {
default:
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_IOS)
case (int)Item::EnableRgbLights: enabled = PreferencesCache::EnableRgbLights; break;
#endif
#if defined(WITH_ANGELSCRIPT)
case (int)Item::AllowUnsignedScripts: enabled = PreferencesCache::AllowUnsignedScripts; break;
#endif
default: enabled = false;
}

#if defined(WITH_ANGELSCRIPT)
Expand Down Expand Up @@ -168,6 +172,7 @@ namespace Jazz2::UI::Menu

switch (_selectedIndex) {
case (int)Item::Enhancements: _root->SwitchToSection<GameplayEnhancementsSection>(); break;
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_IOS)
case (int)Item::EnableRgbLights:
PreferencesCache::EnableRgbLights = !PreferencesCache::EnableRgbLights;
if (!PreferencesCache::EnableRgbLights) {
Expand All @@ -176,11 +181,14 @@ namespace Jazz2::UI::Menu
_isDirty = true;
_animation = 0.0f;
break;
#endif
#if defined(WITH_ANGELSCRIPT)
case (int)Item::AllowUnsignedScripts:
PreferencesCache::AllowUnsignedScripts = !PreferencesCache::AllowUnsignedScripts;
_isDirty = true;
_animation = 0.0f;
break;
#endif
}
}
}
2 changes: 2 additions & 0 deletions Jazz2/Jazz2/UI/Menu/GameplayOptionsSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ namespace Jazz2::UI::Menu
private:
enum class Item {
Enhancements,
#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_IOS)
EnableRgbLights,
#endif
#if defined(WITH_ANGELSCRIPT)
AllowUnsignedScripts,
#endif
Expand Down
3 changes: 2 additions & 1 deletion Jazz2/Jazz2/UI/Menu/InGameMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ namespace Jazz2::UI::Menu
pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Jump)] || pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Jump)]) {
_pressedActions |= (1 << (int)PlayerActions::Fire);
}
if (pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)]) {
// Allow Android Back button as menu key
if (pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)] || pressedKeys[(uint32_t)KeySym::BACK]) {
_pressedActions |= (1 << (int)PlayerActions::Menu);
}
// Use SwitchWeapon action as Delete key
Expand Down
5 changes: 3 additions & 2 deletions Jazz2/Jazz2/UI/Menu/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Jazz2::UI::Menu
_logoTransition(0.0f),
_texturedBackgroundPass(this),
_texturedBackgroundPhase(0.0f),
_pressedKeys((uint32_t)KeySym::COUNT_BASE),
_pressedKeys((uint32_t)KeySym::COUNT),
_pressedActions(0),
_touchButtonsTimer(0.0f)
{
Expand Down Expand Up @@ -377,7 +377,8 @@ namespace Jazz2::UI::Menu
_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Jump)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Jump)]) {
_pressedActions |= (1 << (int)PlayerActions::Fire);
}
if (_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)]) {
// Allow Android Back button as menu key
if (_pressedKeys[(uint32_t)ControlScheme::Key1(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)ControlScheme::Key2(0, PlayerActions::Menu)] || _pressedKeys[(uint32_t)KeySym::BACK]) {
_pressedActions |= (1 << (int)PlayerActions::Menu);
}
// Use SwitchWeapon action as Delete key
Expand Down
35 changes: 31 additions & 4 deletions Jazz2/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "nCine/Threading/Thread.h"
#include "nCine/tracy.h"

#if defined(DEATH_TARGET_ANDROID)
# include "nCine/Android/AndroidApplication.h"
#endif

#include "Jazz2/IRootController.h"
#include "Jazz2/ContentResolver.h"
#include "Jazz2/LevelHandler.h"
Expand Down Expand Up @@ -96,7 +100,12 @@ void __WriteLog(LogLevel level, const char* fmt, ...)
}
// clang-format on

__android_log_write(priority, "Jazz2", logEntry);
va_list args;
va_start(args, fmt);
unsigned int length = vsnprintf(logEntry, MaxEntryLength, fmt, args);
va_end(args);

__android_log_write(priority, "jazz2", logEntry);
#else
constexpr char Reset[] = "\033[0m";
constexpr char Bold[] = "\033[1m";
Expand Down Expand Up @@ -247,8 +256,21 @@ void GameEventHandler::onInit()
{
_flags = Flags::None;
_pendingState = PendingState::None;

#if !defined(DEATH_TARGET_ANDROID) && !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)


#if defined(DEATH_TARGET_ANDROID)
// Set working directory to external storage on Android
StringView externalPath = static_cast<AndroidApplication&>(theApplication()).externalDataPath();
if (!externalPath.empty()) {
if (fs::SetWorkingDirectory(externalPath)) {
LOGI_X("External storage path: %s", externalPath.data());
} else {
LOGE_X("Cannot set external storage path \"%s\"", externalPath.data());
}
} else {
LOGE("Cannot get external storage path");
}
#elif !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_IOS)
theApplication().setAutoSuspension(false);

if (PreferencesCache::EnableFullscreen) {
Expand Down Expand Up @@ -783,7 +805,12 @@ void GameEventHandler::SaveEpisodeContinue(const std::unique_ptr<LevelInitializa
}
}

#if defined(DEATH_TARGET_WINDOWS) && !defined(WITH_QT5)
#if defined(DEATH_TARGET_ANDROID)
std::unique_ptr<IAppEventHandler> createAppEventHandler()
{
return std::make_unique<GameEventHandler>();
}
#elif defined(DEATH_TARGET_WINDOWS) && !defined(WITH_QT5)
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
return PCApplication::start([]() -> std::unique_ptr<IAppEventHandler> {
Expand Down
Loading

0 comments on commit 8864d2f

Please sign in to comment.