Skip to content

Commit

Permalink
Updated engine and build system to 2.1.0, quick build by axmol build
Browse files Browse the repository at this point in the history
  • Loading branch information
EugenyN committed Jan 21, 2024
1 parent 442f795 commit 3e102fe
Show file tree
Hide file tree
Showing 51 changed files with 521 additions and 159 deletions.
6 changes: 3 additions & 3 deletions .axproj.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"engine_version": "axmol-1.0.0",
"project_type": "cpp"
}
"engine_version": "2.1.0",
"project_type": "cpp"
}
123 changes: 70 additions & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#/****************************************************************************
# Copyright (c) 2013-2014 cocos2d-x.org
# Copyright (c) 2021-2022 Bytedance Inc.
# Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
#
# https://axmolengine.github.io/
#
Expand Down Expand Up @@ -43,14 +43,13 @@ if(NOT DEFINED BUILD_ENGINE_DONE) # to test Tanks4 into root project
set(_AX_ROOT "$ENV{AX_ROOT}")

if(NOT (_AX_ROOT STREQUAL ""))
set(_AX_ROOT_PATH "${_AX_ROOT}")
file(TO_CMAKE_PATH ${_AX_ROOT_PATH} _AX_ROOT_PATH) # string(REPLACE "\\" "/" _AX_ROOT_PATH ${_AX_ROOT_PATH})
file(TO_CMAKE_PATH ${_AX_ROOT} _AX_ROOT)
message(STATUS "Using system env var _AX_ROOT=${_AX_ROOT}")
else()
message(FATAL_ERROR "Please run setup.py add system env var 'AX_ROOT' to specific the engine root")
message(FATAL_ERROR "Please run setup.ps1 add system env var 'AX_ROOT' to specific the engine root")
endif()

set(CMAKE_MODULE_PATH ${_AX_ROOT_PATH}/cmake/Modules/)
set(CMAKE_MODULE_PATH ${_AX_ROOT}/cmake/Modules/)

include(AXBuildSet)

Expand Down Expand Up @@ -78,12 +77,12 @@ if(NOT DEFINED BUILD_ENGINE_DONE) # to test Tanks4 into root project
endif()

set(_AX_USE_PREBUILT FALSE)
if ((WIN32 OR LINUX) AND DEFINED AX_PREBUILT_DIR AND IS_DIRECTORY ${_AX_ROOT_PATH}/${AX_PREBUILT_DIR})
if ((WIN32 OR LINUX) AND DEFINED AX_PREBUILT_DIR AND IS_DIRECTORY ${_AX_ROOT}/${AX_PREBUILT_DIR})
set(_AX_USE_PREBUILT TRUE)
endif()

if (NOT _AX_USE_PREBUILT)
add_subdirectory(${_AX_ROOT_PATH}/core ${ENGINE_BINARY_PATH}/axmol/core)
add_subdirectory(${_AX_ROOT}/core ${ENGINE_BINARY_PATH}/axmol/core)
endif()
endif()

Expand All @@ -100,28 +99,28 @@ if (NOT DEFINED AX_PREBUILT_DIR)
AX_USE_WEBP=0)
endif()

# record sources, headers, Content...
set(GAME_SOURCE)
set(GAME_HEADER)
# The common cross-platforms source files and header files
file(GLOB_RECURSE GAME_HEADER
Source/*.h Source/*.hpp
)
file(GLOB_RECURSE GAME_SOURCE
Source/*.cpp Source/*.c
)

set(GAME_INC_DIRS
"${CMAKE_CURRENT_SOURCE_DIR}/Source"
)

set(content_folder
"${CMAKE_CURRENT_SOURCE_DIR}/Content"
)

if(APPLE)
ax_mark_multi_resources(common_content_files RES_TO "Resources" FOLDERS ${GAME_RES_FOLDER})
ax_mark_multi_resources(common_content_files RES_TO "Resources" FOLDERS ${content_folder})
elseif(WINDOWS)
ax_mark_multi_resources(common_content_files RES_TO "Content" FOLDERS ${GAME_RES_FOLDER})
ax_mark_multi_resources(common_content_files RES_TO "Content" FOLDERS ${content_folder})
endif()

# add cross-platforms source files and header files
file(GLOB_RECURSE GAME_SOURCE
Source/*.cpp
)

file(GLOB_RECURSE GAME_HEADER
Source/*.h
)

if(ANDROID)
# the APP_NAME should match on AndroidManifest.xml
list(APPEND GAME_SOURCE
Expand All @@ -131,16 +130,26 @@ elseif(LINUX)
list(APPEND GAME_SOURCE
proj.linux/main.cpp
)
elseif(WINDOWS)
list(APPEND GAME_HEADER
proj.win32/main.h
proj.win32/resource.h
)
list(APPEND GAME_SOURCE ${common_content_files})
elseif(WASM)
list(APPEND GAME_SOURCE
proj.win32/main.cpp
proj.win32/game.rc
${common_content_files}
proj.wasm/main.cpp
)
list(APPEND GAME_SOURCE ${common_content_files})
elseif(WINDOWS)
if(NOT WINRT)
list(APPEND GAME_HEADER
proj.win32/main.h
proj.win32/resource.h
)
list(APPEND GAME_SOURCE
proj.win32/main.cpp
proj.win32/game.rc
)
else()
ax_setup_winrt_sources()
endif()
list(APPEND GAME_SOURCE ${common_content_files})
elseif(APPLE)
if(IOS)
list(APPEND GAME_HEADER
Expand All @@ -150,13 +159,13 @@ elseif(APPLE)

if (TVOS)
set(APP_UI_RES
proj.ios_mac/ios/LaunchScreenBackground.png
proj.ios_mac/ios/targets/tvos/LaunchScreenBackground.png
proj.ios_mac/ios/targets/tvos/LaunchScreen.storyboard
proj.ios_mac/ios/targets/tvos/Images.xcassets
)
else()
set(APP_UI_RES
proj.ios_mac/ios/LaunchScreenBackground.png
proj.ios_mac/ios/targets/ios/LaunchScreenBackground.png
proj.ios_mac/ios/targets/ios/LaunchScreen.storyboard
proj.ios_mac/ios/targets/ios/Images.xcassets
)
Expand Down Expand Up @@ -184,14 +193,14 @@ elseif(APPLE)
endif()

# mark app complie info and libs info
set(all_code_files
set(APP_SOURCES
${GAME_HEADER}
${GAME_SOURCE}
)
if(NOT ANDROID)
add_executable(${APP_NAME} ${all_code_files})
add_executable(${APP_NAME} ${APP_SOURCES})
else()
add_library(${APP_NAME} SHARED ${all_code_files})
add_library(${APP_NAME} SHARED ${APP_SOURCES})
# whole archive for jni
target_link_libraries(${APP_NAME} -Wl,--whole-archive cpp_android_spec -Wl,--no-whole-archive)
config_android_shared_libs("org.axmol.lib" "${CMAKE_CURRENT_SOURCE_DIR}/proj.android/app/src")
Expand All @@ -201,17 +210,20 @@ if (NOT _AX_USE_PREBUILT)
target_link_libraries(${APP_NAME} ${_AX_CORE_LIB})
endif()

target_include_directories(${APP_NAME}
PRIVATE Source
PRIVATE ${_AX_ROOT_PATH}/core/audio
)
# The optional thirdparties(not dependent by engine)
if (AX_WITH_YAML_CPP)
list(APPEND GAME_INC_DIRS "${_AX_ROOT}/thirdparty/yaml-cpp/include")
endif()

target_include_directories(${APP_NAME} PRIVATE ${GAME_INC_DIRS})


# mark app resources
setup_ax_app_config(${APP_NAME})
# mark app resources, resource will be copy auto after mark
ax_setup_app_config(${APP_NAME})
if(APPLE)
set_target_properties(${APP_NAME} PROPERTIES RESOURCE "${APP_UI_RES}")
set_xcode_property(${APP_NAME} INSTALL_PATH "\$(LOCAL_APPS_DIR)")
set_xcode_property(${APP_NAME} PRODUCT_BUNDLE_IDENTIFIER "org.axmol.hellocpp")
set_xcode_property(${APP_NAME} PRODUCT_BUNDLE_IDENTIFIER "org.eugenyn.tanks4")

if(MACOSX)
set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist")
Expand All @@ -221,37 +233,42 @@ if(APPLE)
elseif(IOS)
set_target_properties(${APP_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/ios/targets/ios/Info.plist")
set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
set_xcode_property(${APP_NAME} TARGETED_DEVICE_FAMILY "1,2")
endif()

# For code-signing, set the DEVELOPMENT_TEAM:
#set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "GRLXXXX2K9")
elseif(WINDOWS)
if(NOT _AX_USE_PREBUILT)
ax_copy_target_dll(${APP_NAME})
ax_sync_target_dlls(${APP_NAME})
endif()
endif()

if (NOT APPLE)
if ((NOT APPLE) AND (NOT WINRT))
ax_get_resource_path(APP_RES_DIR ${APP_NAME})
ax_sync_target_res(${APP_NAME} LINK_TO ${APP_RES_DIR} FOLDERS ${content_folder} SYM_LINK 1)

if((WINDOWS AND (NOT (CMAKE_GENERATOR STREQUAL "Ninja"))))
if((WINDOWS AND (NOT (CMAKE_GENERATOR MATCHES "Ninja"))))
set_property(TARGET ${APP_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${content_folder}")
if(NOT DEFINED BUILD_ENGINE_DONE)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${APP_NAME})
endif()
endif()
endif()

# The optional thirdparties(not dependent by engine)
if (AX_WITH_YAML_CPP)
target_include_directories(${APP_NAME} PRIVATE ${_AX_ROOT_PATH}/thirdparty/yaml-cpp/include)
target_link_libraries(${APP_NAME} yaml-cpp)
elseif(WINRT)
if(NOT DEFINED BUILD_ENGINE_DONE)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${APP_NAME})
endif()
endif()

if (_AX_USE_PREBUILT) # support windows and linux
use_ax_compile_define(${APP_NAME})

include(${_AX_ROOT_PATH}/cmake/Modules/AXLinkHelpers.cmake)
ax_link_cxx_prebuilt(${APP_NAME} ${_AX_ROOT_PATH} ${AX_PREBUILT_DIR})
endif()
include(AXLinkHelpers)
ax_link_cxx_prebuilt(${APP_NAME} ${_AX_ROOT} ${AX_PREBUILT_DIR})
endif()

if (NOT DEFINED BUILD_ENGINE_DONE)
ax_uwp_set_all_targets_deploy_min_version()
endif()

ax_setup_app_props(${APP_NAME})
Empty file added Content/res/.gitkeep
Empty file.
35 changes: 23 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,37 @@ Also the game is available on Itch.io: https://eugenyn.itch.io/tanks-kombat

## Build from source

#### Prerequisites
### Prerequisites

1. Download [Axmol](https://github.com/axmolengine/axmol) game engine.
2. Config ```axmol```, run ```python setup.py``` from axmol root directory.
2. Install [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell), powershell-7 is recommended, it's support Windows, macOS, Linux
3. Config ```axmol```, run ```pwsh setup.ps1``` from axmol root directory.
4. Ensure C/C++ compiler toolset installed on your machine.

#### Windows
### Quick build by `axmol build` for all target platforms [`Recommended`]

1. Install Visual Studio 2019/2022 (for toolchain)
2. Install [CMake](https://cmake.org/) 3.14+
Using a powershell console window, the `axmol build` command will auto setup general depended toolsets, so you can simply build project for all platform targets, i.e.

- win32: `axmol build -p win32`
- android: `axmol build -p android -a arm64` can runs on Windows, Linux, macOS and script will auto setup android sdk

See [DevSetup](https://github.com/axmolengine/axmol/blob/dev/docs/DevSetup.md) for additional options.

### Manually build with cmake

#### Windows (Visual Studio)

1. Install Visual Studio 2022 (for toolchain)
2. Install [CMake](https://cmake.org/) 3.28.1+
3. Use CMake to build project files:
* for 32 bit Visual Studio 2022: ```cmake -S . -B build -G "Visual Studio 17 2022" -A Win32```
* for 64 bit Visual Studio 2022: ```cmake -S . -B build -G "Visual Studio 17 2022" -A x64```
4. Build and run project.

Also you can use built-in CMake projects support in your IDE (use Visual Studio as toolchain)
4. Use Visual Studio to open the newly created solution file. Build and run project.

#### Android
#### Android (Android Studio)

1. Install Android Studio
2. Install SDK Build-Tools, NDK r23c+, CMake 3.10+ from Android Studio ```SDK Manager```
1. Install Android Studio 2023.1.1+
2. Install SDK Build-Tools 34.0.0, NDK r23c+, CMake, from Android Studio ```SDK Manager```, use Gradle Plugin (AGP) 8.2.1
3. Open ```proj.android``` in Android Studio, wait for ```Gradle sync``` finish.
4. Build and run project.

Expand All @@ -68,7 +79,7 @@ Also you can use built-in CMake projects support in your IDE (use Visual Studio

## Third-party code and libraries

* [Axmol Game Engine](https://github.com/axmolengine/axmol) fork of [Cocos2d-x-4.0](https://github.com/cocos2d/cocos2d-x)
* [Axmol Game Engine](https://github.com/axmolengine/axmol)
* [SneakyInput-Cocos2dx-2.0.x](https://github.com/cpinan/SneakyInput-Cocos2dx-2.0.x)
* [Random Cave Using Cellular Automata](http://gamedevelopment.tutsplus.com/tutorials/generate-random-cave-levels-using-cellular-automata--gamedev-9664)
* [A* Pathfinding with Cocos2D](http://www.raywenderlich.com/4970/how-to-implement-a-pathfinding-with-cocos2d-tutorial) (Objective-C)
Expand Down
4 changes: 2 additions & 2 deletions Source/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_

#include "cocos2d.h"
#include "axmol.h"

class AppDelegate : private cocos2d::Application
class AppDelegate : private ax::Application
{
public:
AppDelegate();
Expand Down
2 changes: 1 addition & 1 deletion Source/Components/AI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Objects\Bonus.h"
#include "Objects\GameObject.h"
#include "Scenes\GameplayScene.h"
#include "base/CCEventListenerCustom.h"
#include "base/EventListenerCustom.h"

USING_NS_CC;

Expand Down
10 changes: 5 additions & 5 deletions Source/Engine.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Engine.h"
#include "Scenes\BaseScene.h"
#include "Scenes\MainMenuScene.h"
#include "2d/CCFontAtlasCache.h"
#include "2d/FontAtlasCache.h"
#include "audio/AudioEngine.h"

USING_NS_CC;
USING_NS_AX;

GameMode GameMode::createFromDict(const ValueMap& dict)
{
Expand Down Expand Up @@ -62,18 +62,18 @@ void Engine::launchGame()
loadSettings();

auto director = Director::getInstance();
auto glview = director->getOpenGLView();
auto glview = director->getGLView();

if (!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
#if (AX_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (AX_TARGET_PLATFORM == CC_PLATFORM_MAC) || (AX_TARGET_PLATFORM == CC_PLATFORM_LINUX)
if (Settings.fullscreen)
glview = GLViewImpl::createWithFullScreen(GAME_TITLE);
else
glview = GLViewImpl::createWithRect(GAME_TITLE, Rect(0, 0, Settings.windowsSize.width, Settings.windowsSize.height));
#else
glview = GLViewImpl::create(GAME_TITLE);
#endif
director->setOpenGLView(glview);
director->setGLView(glview);
}

director->setDisplayStats(DISPLAY_STATS);
Expand Down
4 changes: 2 additions & 2 deletions Source/Scenes/AboutScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool AboutScene::init()
"zironid_n, M-Tee\n"
"Kenney Vleugels\n\n"
"3d party code:\n\n"
"Cocos2d-x 3.9, SneakyInput";
"Axmol 2.1, SneakyInput";

const char* aboutYellow =
"Programming and game design:\n\n"
Expand Down Expand Up @@ -87,7 +87,7 @@ void AboutScene::showDebugInfo()

Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
auto glview = Director::getInstance()->getOpenGLView();
auto glview = Director::getInstance()->getGLView();

float dpiScale = (float)Device::getDPI() / 86.0f;
float resolutionScale = 1.0f / glview->getScaleX();
Expand Down
2 changes: 1 addition & 1 deletion Source/Scenes/BaseScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void BaseScene::addJoystick()
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Point origin = Director::getInstance()->getVisibleOrigin();
auto glview = Director::getInstance()->getOpenGLView();
auto glview = Director::getInstance()->getGLView();

float dpiScale = (float)Device::getDPI() / 86.0f;
float resolutionScale = 1.0f / glview->getScaleX();
Expand Down
2 changes: 2 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
axmol build -p win32
2 changes: 1 addition & 1 deletion proj.android/app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:taskAffinity="" >
android:taskAffinity=""
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Loading

0 comments on commit 3e102fe

Please sign in to comment.