From 0da6ad6be23e6ca4ea7edf1bf14463ee1de2b3e7 Mon Sep 17 00:00:00 2001 From: ducphamhong Date: Fri, 27 Sep 2024 15:54:10 +0700 Subject: [PATCH] Add sample character controller --- CMakeProjects.cmake | 1 + Projects/Skylicht/Client/CBaseApp.cpp | 3 + Projects/Skylicht/Client/CBaseApp.h | 8 + .../Client/CrashHandler/CCrashHandler.cpp | 7 +- .../Engine/Material/CMaterialManager.cpp | 16 +- Samples/CharacterController/CMakeLists.txt | 332 ++++++++++++++++++ .../CharacterController/Source/CViewDemo.cpp | 67 ++++ .../CharacterController/Source/CViewDemo.h | 23 ++ .../CharacterController/Source/CViewInit.cpp | 281 +++++++++++++++ .../CharacterController/Source/CViewInit.h | 49 +++ .../Source/CharacterController.cpp | 83 +++++ .../Source/CharacterController.h | 28 ++ Samples/CharacterController/Source/Version.h | 4 + Samples/TemplateEmpty/Source/CViewDemo.cpp | 67 ++++ Samples/TemplateEmpty/Source/CViewDemo.h | 23 ++ Samples/TemplateEmpty/Source/CViewInit.cpp | 265 ++++++++++++++ Samples/TemplateEmpty/Source/CViewInit.h | 49 +++ Samples/TemplateEmpty/Source/Template.cpp | 83 +++++ Samples/TemplateEmpty/Source/Template.h | 28 ++ Samples/TemplateEmpty/Source/Version.h | 4 + 20 files changed, 1418 insertions(+), 3 deletions(-) create mode 100644 Samples/CharacterController/CMakeLists.txt create mode 100644 Samples/CharacterController/Source/CViewDemo.cpp create mode 100644 Samples/CharacterController/Source/CViewDemo.h create mode 100644 Samples/CharacterController/Source/CViewInit.cpp create mode 100644 Samples/CharacterController/Source/CViewInit.h create mode 100644 Samples/CharacterController/Source/CharacterController.cpp create mode 100644 Samples/CharacterController/Source/CharacterController.h create mode 100644 Samples/CharacterController/Source/Version.h create mode 100644 Samples/TemplateEmpty/Source/CViewDemo.cpp create mode 100644 Samples/TemplateEmpty/Source/CViewDemo.h create mode 100644 Samples/TemplateEmpty/Source/CViewInit.cpp create mode 100644 Samples/TemplateEmpty/Source/CViewInit.h create mode 100644 Samples/TemplateEmpty/Source/Template.cpp create mode 100644 Samples/TemplateEmpty/Source/Template.h create mode 100644 Samples/TemplateEmpty/Source/Version.h diff --git a/CMakeProjects.cmake b/CMakeProjects.cmake index 1ae446e7a..a72f761bf 100644 --- a/CMakeProjects.cmake +++ b/CMakeProjects.cmake @@ -33,6 +33,7 @@ if (BUILD_EXAMPLES AND BUILD_SKYLICHT_LIGHMAPPER) subdirs(Samples/PBR) if (BUILD_SKYLICHT_PHYSIC) + subdirs(Samples/CharacterController) subdirs(Samples/Physics) endif() diff --git a/Projects/Skylicht/Client/CBaseApp.cpp b/Projects/Skylicht/Client/CBaseApp.cpp index 17101297d..e98f4b08d 100644 --- a/Projects/Skylicht/Client/CBaseApp.cpp +++ b/Projects/Skylicht/Client/CBaseApp.cpp @@ -56,6 +56,8 @@ namespace Skylicht #if defined(_WIN32) m_enableRunWhenPause = true; #endif + + m_appName = "Skylicht Engine"; } CBaseApp::~CBaseApp() @@ -92,6 +94,7 @@ namespace Skylicht } m_appEventReceivers.push_back(appEventType(name, pEvent)); + m_appName = name; } void CBaseApp::unRegisterAppEvent(IApplicationEventReceiver* pEvent) diff --git a/Projects/Skylicht/Client/CBaseApp.h b/Projects/Skylicht/Client/CBaseApp.h index 8d828843d..00f271593 100644 --- a/Projects/Skylicht/Client/CBaseApp.h +++ b/Projects/Skylicht/Client/CBaseApp.h @@ -66,6 +66,9 @@ namespace Skylicht bool m_enableRunWhenPause; video::SColor m_clearColor; + + std::string m_appName; + public: CBaseApp(); @@ -76,6 +79,11 @@ namespace Skylicht public: + inline const char* getAppName() + { + return m_appName.c_str(); + } + void showDebugConsole(); static void reportLeakMemory(); diff --git a/Projects/Skylicht/Client/CrashHandler/CCrashHandler.cpp b/Projects/Skylicht/Client/CrashHandler/CCrashHandler.cpp index f53a8522c..15b1c0231 100644 --- a/Projects/Skylicht/Client/CrashHandler/CCrashHandler.cpp +++ b/Projects/Skylicht/Client/CrashHandler/CCrashHandler.cpp @@ -25,6 +25,9 @@ This file is part of the "Skylicht Engine". #include "pch.h" #include "CCrashHandler.h" +#include "CApplication.h" +#include "Utils/CStringImp.h" + #ifdef USE_CRASHHANDLER #define MAX_STACK_DEPTH 64 #define MAX_UNDECORATEDNAME_LENGTH 256 @@ -76,9 +79,11 @@ namespace Skylicht SYSTEMTIME time; GetLocalTime(&time); + std::wstring appName = CStringImp::convertUTF8ToUnicode(getApplication()->getAppName()); + wchar_t szFileName[MAX_PATH]; swprintf(szFileName, MAX_PATH, L"%s-%04d-%02d%02d-%02d%02d.dmp", - L"SkylichtApp", + appName.c_str(), time.wYear, time.wMonth, time.wDay, diff --git a/Projects/Skylicht/Engine/Material/CMaterialManager.cpp b/Projects/Skylicht/Engine/Material/CMaterialManager.cpp index 4b9132ca1..4de303c14 100644 --- a/Projects/Skylicht/Engine/Material/CMaterialManager.cpp +++ b/Projects/Skylicht/Engine/Material/CMaterialManager.cpp @@ -52,7 +52,12 @@ namespace Skylicht for (int j = 0, n = (int)list.size(); j < n; j++) { CMaterial* m = list[j]; - m->drop(); + if (m->drop() == false) + { + char log[512]; + sprintf(log, "[CMaterialManager] Leak material %s - file: %s", m->getName(), m->getMaterialPath()); + os::Printer::log(log); + } } list.clear(); ++i; @@ -60,7 +65,14 @@ namespace Skylicht m_materials.clear(); for (CMaterial* m : m_listGenerateMaterials) - m->drop(); + { + if (m->drop() == false) + { + char log[512]; + sprintf(log, "[CMaterialManager] Leak material generated %s", m->getName()); + os::Printer::log(log); + } + } m_listGenerateMaterials.clear(); } diff --git a/Samples/CharacterController/CMakeLists.txt b/Samples/CharacterController/CMakeLists.txt new file mode 100644 index 000000000..93bfc216d --- /dev/null +++ b/Samples/CharacterController/CMakeLists.txt @@ -0,0 +1,332 @@ +include_directories( + ${SKYLICHT_ENGINE_SOURCE_DIR}/Samples/CharacterController/Source + ${SKYLICHT_ENGINE_SOURCE_DIR}/Samples/SampleFW + ${SKYLICHT_ENGINE_PROJECT_DIR}/Main + ${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Include + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/System + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Engine + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Components + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Collision + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Physics + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Client + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Lightmapper + ${SKYLICHT_ENGINE_PROJECT_DIR}/Skylicht/Audio + ${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdParty/freetype2/include + ${SKYLICHT_ENGINE_PROJECT_DIR}/Bullet3/src +) + +if (BUILD_IMGUI) + include_directories(${SKYLICHT_ENGINE_PROJECT_DIR}/Imgui) +endif() + +set(template_path ${SKYLICHT_ENGINE_PROJECT_DIR}/Main) + +file(GLOB_RECURSE application_source + ./Source/**.cpp + ./Source/**.c + ./Source/**.h + ../SampleFW/**.h + ../SampleFW/**.cpp) + +setup_project_group("${application_source}" ${CMAKE_CURRENT_SOURCE_DIR}) + +list (APPEND application_source ${template_path}/pch.cpp) +list (APPEND application_source ${template_path}/pch.h) + +if (BUILD_ANDROID) + file(GLOB_RECURSE platform_android_source + ${template_path}/Platforms/Android/**.cpp + ${template_path}/Platforms/Android/**.c + ${template_path}/Platforms/Android/**.h) + + list (APPEND application_source ${platform_android_source}) +endif() + +if (BUILD_WINDOWS_STORE) + file(MAKE_DIRECTORY ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController) + file(MAKE_DIRECTORY ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController/Assets) + + file(GLOB uwp_assets + ${template_path}/Platforms/UWP/Assets/**.* + ${SKYLICHT_ENGINE_BIN_DIR}/**.zip) + + foreach(asset_file ${uwp_assets}) + file(COPY "${asset_file}" DESTINATION ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController/Assets) + endforeach() + + file(COPY ${template_path}/Platforms/UWP/Package.appxmanifest + DESTINATION + ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController) + + file(COPY ${template_path}/Platforms/UWP/TemporaryKey.pfx + DESTINATION + ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController) + + file(GLOB_RECURSE platform_uwp_source + ${template_path}/Platforms/UWP/**.cpp + ${template_path}/Platforms/UWP/**.c + ${template_path}/Platforms/UWP/**.h) + + # copy resource to generate prj folder + file(GLOB_RECURSE platform_uwp_asset ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController/Assets/**.*) + add_source_group("${platform_uwp_asset}" "Assets") + + list (APPEND application_source ${platform_uwp_source}) + + set_property(SOURCE ${platform_uwp_asset} PROPERTY VS_DEPLOYMENT_CONTENT 1) +endif() + +if (MSVC OR CYGWIN OR MINGW) + include_directories(${template_path}/Platforms/Win32) + + file(GLOB_RECURSE platform_win32_source + ${template_path}/Platforms/Win32/**.cpp + ${template_path}/Platforms/Win32/**.c + ${template_path}/Platforms/Win32/**.h) + + list (APPEND application_source ${platform_win32_source}) +endif() + +if (BUILD_MACOS) + # Angle API + include_directories(${SKYLICHT_ENGINE_PROJECT_DIR}/Angle/include) + include_directories(${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Source/Angle) + include_directories(${template_path}/Platforms/MacOS) + + file(GLOB_RECURSE platform_mac_source + ${template_path}/Platforms/MacOS/**.cpp + ${template_path}/Platforms/MacOS/**.c + ${template_path}/Platforms/MacOS/**.h + ${template_path}/Platforms/MacOS/**.m + ${template_path}/Platforms/MacOS/**.mm) + + list (APPEND application_source ${platform_mac_source}) +endif() + +if (BUILD_IOS) + # Angle API + include_directories(${SKYLICHT_ENGINE_PROJECT_DIR}/Angle/include) + include_directories(${SKYLICHT_ENGINE_PROJECT_DIR}/Irrlicht/Source/Angle) + include_directories(${template_path}/Platforms/IOS) + + file(GLOB_RECURSE platform_ios_source + ${template_path}/Platforms/IOS/**.cpp + ${template_path}/Platforms/IOS/**.c + ${template_path}/Platforms/IOS/**.h + ${template_path}/Platforms/IOS/**.m + ${template_path}/Platforms/IOS/**.mm) + + file(GLOB_RECURSE platform_ios_resources ${template_path}/Platforms/IOS/**.storyboard) + + list (APPEND application_source ${platform_ios_source}) +endif() + +if (BUILD_DEBUG_VLD) + if (CMAKE_CL_64) + set(vld_dll_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/Vld/bin/Win64/*.*") + else() + set(vld_dll_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/Vld/bin/Win32/*.*") + endif() +endif() + +if (BUILD_SDL AND MSVC) + if (CMAKE_CL_64) + set(sdl_lib_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/SDL/lib/x64") + set(sdl_dll_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/SDL/lib/x64/*.dll") + else() + set(sdl_lib_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/SDL/lib/x86") + set(sdl_dll_path "${SKYLICHT_ENGINE_PROJECT_DIR}/ThirdPartySDK/SDL/lib/x86/*.dll") + endif() + link_directories(${sdl_lib_path}) +endif() + +if (MINGW OR CYGWIN) + # .rc build + set(CMAKE_RC_COMPILER_INIT windres) + enable_language(RC) + set(CMAKE_RC_COMPILE_OBJECT " -O coff -i -o ") +endif() + +if (BUILD_EMSCRIPTEN) + add_executable(SampleCharacterController + ${application_source} + ${template_path}/Platforms/Emscripten/MainWebGL.cpp + ) +elseif(BUILD_SDL) + add_executable(SampleCharacterController + ${application_source} + ${template_path}/Platforms/SDL2/MainSDL.cpp + ) +elseif(BUILD_LINUX) + add_executable(SampleCharacterController + ${application_source} + ${template_path}/Platforms/Linux/MainLinux.cpp + ) +elseif(BUILD_ANDROID) + add_library(SampleCharacterController SHARED ${application_source}) +elseif (BUILD_WINDOWS_STORE) + add_executable(SampleCharacterController + ${application_source} + ${platform_uwp_asset} + ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController/TemporaryKey.pfx + ${SKYLICHT_ENGINE_SOURCE_DIR}/PrjUWP/Samples/CharacterController/Package.appxmanifest + ) +elseif (MSVC OR CYGWIN OR MINGW) + add_executable(SampleCharacterController WIN32 + ${application_source} + ${template_path}/Platforms/Win32/Skylicht.rc + ) +elseif (BUILD_MACOS) + file(GLOB resources_files "${SKYLICHT_ENGINE_BIN_DIR}/*.zip") + + set(angle_lib_path "${SKYLICHT_ENGINE_PROJECT_DIR}/Angle/out/MacOS/Release/${CMAKE_OSX_ARCHITECTURES}") + file(GLOB dylib_files "${angle_lib_path}/*.dylib") + + add_executable(SampleCharacterController + ${application_source} + ${resources_files} + ${dylib_files} + ) + + set_target_properties(SampleCharacterController PROPERTIES MACOSX_BUNDLE TRUE) + + target_link_libraries(SampleCharacterController "-framework Cocoa") + + message(STATUS "- Setup project: SampleCharacterController") + foreach(res_file ${resources_files}) + file(RELATIVE_PATH res_path "${SKYLICHT_ENGINE_BIN_DIR}" ${res_file}) + message(STATUS " - Add resources: ${res_path}") + set_property(SOURCE ${res_file} PROPERTY MACOSX_PACKAGE_LOCATION "Resources") + source_group("Bin" FILES "${res_file}") + endforeach() + + foreach(lib_file ${dylib_files}) + set_property(SOURCE ${lib_file} PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks") + set_source_files_properties(${lib_file} PROPERTIES XCODE_FILE_ATTRIBUTES "CodeSignOnCopy") + source_group("Libs" FILES "${lib_file}") + endforeach() + + add_custom_command(TARGET SampleCharacterController + POST_BUILD COMMAND + ${CMAKE_INSTALL_NAME_TOOL} -change ./libEGL.dylib @rpath/libEGL.dylib + $) + + add_custom_command(TARGET SampleCharacterController + POST_BUILD COMMAND + ${CMAKE_INSTALL_NAME_TOOL} -change ./libGLESv2.dylib @rpath/libGLESv2.dylib + $) + + set_target_properties(SampleCharacterController PROPERTIES + MACOSX_RPATH ON + BUILD_WITH_INSTALL_RPATH 1 + INSTALL_RPATH "@executable_path/../Frameworks" + ) +elseif (BUILD_IOS) + set(MACOSX_BUNDLE_EXECUTABLE_NAME SampleCharacterController) + + set(APP_NAME "SampleCharacterController") + set(APP_BUNDLE_IDENTIFIER "com.team_name.project_name") + set(CODE_SIGN_IDENTITY "iPhone Developer") + + set(PRODUCT_NAME ${APP_NAME}) + set(EXECUTABLE_NAME ${APP_NAME}) + set(MACOSX_BUNDLE_EXECUTABLE_NAME ${APP_NAME}) + set(MACOSX_BUNDLE_BUNDLE_NAME ${APP_BUNDLE_IDENTIFIER}) + set(MACOSX_BUNDLE_GUI_IDENTIFIER ${APP_BUNDLE_IDENTIFIER}) + + file(GLOB resources_files "${SKYLICHT_ENGINE_BIN_DIR}/*.zip") + + set(angle_lib_path "${SKYLICHT_ENGINE_PROJECT_DIR}/Angle/out/IOS/Release/${IOS_PLATFORM}") + file(GLOB angle_framework_files "${angle_lib_path}/*.framework") + + set (framework_files "") + list (APPEND framework_files ${angle_framework_files}) + + add_executable(SampleCharacterController MACOSX_BUNDLE + ${application_source} + ${resources_files} + ${platform_ios_resources} + ${framework_files} + ) + + message(STATUS "- Setup project: SampleCharacterController") + foreach(res_file ${resources_files}) + file(RELATIVE_PATH res_path "${SKYLICHT_ENGINE_BIN_DIR}" ${res_file}) + source_group("Bin" FILES "${res_file}") + endforeach() + + foreach(lib_file ${framework_files}) + source_group("Frameworks" FILES "${lib_file}") + set_property(SOURCE ${lib_file} PROPERTY MACOSX_PACKAGE_LOCATION "Frameworks") + set_source_files_properties(${lib_file} PROPERTIES XCODE_FILE_ATTRIBUTES "CodeSignOnCopy") + endforeach() + + set_target_properties(SampleCharacterController PROPERTIES XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER ${APP_BUNDLE_IDENTIFIER}) + set_target_properties(SampleCharacterController PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENTITY}) + set_target_properties(SampleCharacterController PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY}) + set_target_properties(SampleCharacterController PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${template_path}/Platforms/IOS/plist.in") + + # add assets icon + target_sources(SampleCharacterController PRIVATE "${template_path}/Platforms/IOS/Assets.xcassets") + + list (APPEND platform_ios_resources "${template_path}/Platforms/IOS/Assets.xcassets") + set_target_properties(SampleCharacterController PROPERTIES RESOURCE "${resources_files} ${platform_ios_resources}") + + # link framework + target_link_libraries(SampleCharacterController "-framework Foundation") + target_link_libraries(SampleCharacterController "-framework UIKit") + target_link_libraries(SampleCharacterController "-framework CoreGraphics") + target_link_libraries(SampleCharacterController "-framework Metal") + target_link_libraries(SampleCharacterController "-framework MetalKit") + target_link_libraries(SampleCharacterController "-framework AudioToolbox") + target_link_libraries(SampleCharacterController "-framework AVFAudio") +else() + add_executable(SampleCharacterController ${application_source}) +endif() + +target_precompiled_header(SampleCharacterController ${template_path}/pch.cpp ${application_source}) + +# Linker +if (BUILD_ANDROID) + target_link_libraries(SampleCharacterController Client log) +else() + target_link_libraries(SampleCharacterController Client) +endif() + +# Imgui +if (BUILD_IMGUI) + target_link_libraries(SampleCharacterController Imgui) +endif() + +# Emscripten +if (BUILD_EMSCRIPTEN) + message(STATUS "Setting build in data: ${CMAKE_CURRENT_BINARY_DIR}") + file(COPY "${SKYLICHT_ENGINE_BIN_DIR}/BuiltIn" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + + message(STATUS "Setting compilation target to WASM") + set(CMAKE_EXECUTABLE_SUFFIX ".wasm.html") + set_target_properties(SampleCharacterController PROPERTIES LINK_FLAGS "-s USE_SDL=2 -s USE_WEBGL2=1 -s FORCE_FILESYSTEM=1 -s FETCH=1 -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=['_main','_main_resize'] -s EXPORTED_RUNTIME_METHODS=['ccall'] --preload-file ./BuiltIn --shell-file ${template_path}/Platforms/Emscripten/Shell/shell.html --disable-shared -s WASM=1 -s BINARYEN_METHOD='native-wasm'") + + set(project_name SampleCharacterController) + configure_file(${template_path}/Platforms/Emscripten/Index.html ${SKYLICHT_ENGINE_BIN_DIR}/Index.html) + configure_file(${template_path}/Platforms/Emscripten/Index.html ${SKYLICHT_ENGINE_BIN_DIR}/SampleCharacterController.html) +endif() + +#VLD +if (BUILD_DEBUG_VLD) + file(GLOB_RECURSE vld_bin_files ${vld_dll_path}) + foreach(vld_bin ${vld_bin_files}) + add_custom_command(TARGET SampleCharacterController POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${vld_bin} $) + endforeach() +endif() + +#SDL +if (BUILD_SDL AND MSVC) + file(GLOB_RECURSE sdl_bin_files ${sdl_dll_path}) + foreach(sdl_bin ${sdl_bin_files}) + add_custom_command(TARGET SampleCharacterController POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sdl_bin} $) + endforeach() +endif() + +set_target_properties(SampleCharacterController PROPERTIES VERSION ${SKYLICHT_VERSION}) +set_target_properties(SampleCharacterController PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") diff --git a/Samples/CharacterController/Source/CViewDemo.cpp b/Samples/CharacterController/Source/CViewDemo.cpp new file mode 100644 index 000000000..9595cdcaa --- /dev/null +++ b/Samples/CharacterController/Source/CViewDemo.cpp @@ -0,0 +1,67 @@ +#include "pch.h" +#include "CViewDemo.h" + +#include "Context/CContext.h" +#include "CImguiManager.h" +#include "imgui.h" + +CViewDemo::CViewDemo() +{ + +} + +CViewDemo::~CViewDemo() +{ + +} + +void CViewDemo::onInit() +{ + CContext* context = CContext::getInstance(); + CCamera* camera = context->getActiveCamera(); + + CScene* scene = context->getScene(); + scene->updateIndexSearchObject(); + + +} + +void CViewDemo::onDestroy() +{ + +} + +void CViewDemo::onUpdate() +{ + CContext* context = CContext::getInstance(); + CScene* scene = context->getScene(); + if (scene != NULL) + scene->update(); +} + +void CViewDemo::onRender() +{ + CContext* context = CContext::getInstance(); + + CCamera* camera = context->getActiveCamera(); + CCamera* guiCamera = context->getGUICamera(); + + CScene* scene = context->getScene(); + + // render scene + if (camera != NULL && scene != NULL) + { + context->getRenderPipeline()->render(NULL, camera, scene->getEntityManager(), core::recti()); + } + + // render GUI + if (guiCamera != NULL) + { + CGraphics2D::getInstance()->render(guiCamera); + } +} + +void CViewDemo::onPostRender() +{ + +} diff --git a/Samples/CharacterController/Source/CViewDemo.h b/Samples/CharacterController/Source/CViewDemo.h new file mode 100644 index 000000000..255b5c850 --- /dev/null +++ b/Samples/CharacterController/Source/CViewDemo.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ViewManager/CView.h" + +class CViewDemo : public CView +{ +protected: + +public: + CViewDemo(); + + virtual ~CViewDemo(); + + virtual void onInit(); + + virtual void onDestroy(); + + virtual void onUpdate(); + + virtual void onRender(); + + virtual void onPostRender(); +}; \ No newline at end of file diff --git a/Samples/CharacterController/Source/CViewInit.cpp b/Samples/CharacterController/Source/CViewInit.cpp new file mode 100644 index 000000000..691277c1a --- /dev/null +++ b/Samples/CharacterController/Source/CViewInit.cpp @@ -0,0 +1,281 @@ +#include "pch.h" +#include "CViewInit.h" +#include "CViewDemo.h" + +#include "ViewManager/CViewManager.h" +#include "Context/CContext.h" +#include "Transform/CWorldTransformSystem.h" + +#include "Primitive/CPlane.h" +#include "Primitive/CCube.h" +#include "Primitive/CSphere.h" +#include "SkySun/CSkySun.h" + + +CViewInit::CViewInit() : + m_initState(CViewInit::DownloadBundles), + m_getFile(NULL), + m_downloaded(0), + m_bakeSHLighting(true) +{ + +} + +CViewInit::~CViewInit() +{ + +} + +io::path CViewInit::getBuiltInPath(const char* name) +{ + return getApplication()->getBuiltInPath(name); +} + +void CViewInit::onInit() +{ + CBaseApp* app = getApplication(); + app->showDebugConsole(); + app->getFileSystem()->addFileArchive(getBuiltInPath("BuiltIn.zip"), false, false); + + CShaderManager* shaderMgr = CShaderManager::getInstance(); + shaderMgr->initBasicShader(); + shaderMgr->initSGForwarderShader(); + shaderMgr->initSGDeferredShader(); + + CGlyphFreetype* freetypeFont = CGlyphFreetype::getInstance(); + freetypeFont->initFont("Segoe UI Light", "BuiltIn/Fonts/segoeui/segoeuil.ttf"); + + // init basic gui + CZone* zone = CContext::getInstance()->initScene()->createZone(); + m_guiObject = zone->createEmptyObject(); + CCanvas* canvas = m_guiObject->addComponent(); + + // load font + m_font = new CGlyphFont(); + m_font->setFont("Segoe UI Light", 25); + + // create text + m_textInfo = canvas->createText(m_font); + m_textInfo->setTextAlign(EGUIHorizontalAlign::Center, EGUIVerticalAlign::Middle); + m_textInfo->setText(L"Init assets"); + + // create gui camera + CGameObject* guiCameraObject = zone->createEmptyObject(); + CCamera* guiCamera = guiCameraObject->addComponent(); + guiCamera->setProjectionType(CCamera::OrthoUI); + CContext::getInstance()->setGUICamera(guiCamera); +} + +void CViewInit::initScene() +{ + CBaseApp* app = getApplication(); + + // create a scene + CScene* scene = CContext::getInstance()->getScene(); + CZone* zone = scene->getZone(0); + + // camera + CGameObject* camObj = zone->createEmptyObject(); + camObj->addComponent(); + camObj->addComponent()->setMoveSpeed(2.0f); + camObj->addComponent()->setMoveSpeed(1.0f); + + CCamera* camera = camObj->getComponent(); + camera->setPosition(core::vector3df(0.0f, 5.0f, 10.0f)); + camera->lookAt(core::vector3df(0.0f, 1.0f, 0.0f), core::vector3df(0.0f, 1.0f, 0.0f)); + + // gui camera + CGameObject* guiCameraObject = zone->createEmptyObject(); + CCamera* guiCamera = guiCameraObject->addComponent(); + guiCamera->setProjectionType(CCamera::OrthoUI); + + // sky + CSkySun* skySun = zone->createEmptyObject()->addComponent(); + + // reflection probe + CGameObject* reflectionProbeObj = zone->createEmptyObject(); + CReflectionProbe* reflection = reflectionProbeObj->addComponent(); + reflection->loadStaticTexture("Common/Textures/Sky/PaperMill"); + + // lighting + CGameObject* lightObj = zone->createEmptyObject(); + CDirectionalLight* directionalLight = lightObj->addComponent(); + SColor c(255, 255, 244, 214); + directionalLight->setColor(SColorf(c)); + + CTransformEuler* lightTransform = lightObj->getTransformEuler(); + lightTransform->setPosition(core::vector3df(2.0f, 2.0f, 2.0f)); + + core::vector3df direction = core::vector3df(4.0f, -6.0f, -4.5f); + lightTransform->setOrientation(direction, Transform::Oy); + + CMeshManager* meshManager = CMeshManager::getInstance(); + + CEntityPrefab* prefab = meshManager->loadModel("SampleModels/TestScene/TestScene.dae", NULL, true); + if (prefab != NULL) + { + // load material + std::vector textureFolders; + ArrayMaterial& materials = CMaterialManager::getInstance()->loadMaterial("SampleModels/TestScene/TestScene.mat", true, textureFolders); + + // create render mesh object + CGameObject* testScene = zone->createEmptyObject(); + testScene->setStatic(true); + + // render mesh & init material + CRenderMesh* renderer = testScene->addComponent(); + renderer->initFromPrefab(prefab); + renderer->initMaterial(materials); + + CIndirectLighting* indirectLighting = testScene->addComponent(); + + testScene->getTransformEuler()->setScale(core::vector3df(0.01f, 0.01f, 0.01f)); + } + + // rendering + u32 w = app->getWidth(); + u32 h = app->getHeight(); + + CContext* context = CContext::getInstance(); + + context->initRenderPipeline(w, h); + context->setActiveZone(zone); + context->setActiveCamera(camera); + context->setGUICamera(guiCamera); + context->setDirectionalLight(directionalLight); +} + +void CViewInit::onDestroy() +{ + m_guiObject->remove(); + delete m_font; +} + +void CViewInit::onUpdate() +{ + CContext* context = CContext::getInstance(); + + switch (m_initState) + { + case CViewInit::DownloadBundles: + { + io::IFileSystem* fileSystem = getApplication()->getFileSystem(); + + std::vector listBundles; + listBundles.push_back("Common.zip"); + listBundles.push_back("SampleModels.zip"); + listBundles.push_back("SampleModelsResource.zip"); + listBundles.push_back(getApplication()->getTexturePackageName("SampleModels.zip")); + +#ifdef __EMSCRIPTEN__ + const char* filename = listBundles[m_downloaded].c_str(); + + if (m_getFile == NULL) + { + m_getFile = new CGetFileURL(filename, filename); + m_getFile->download(CGetFileURL::Get); + + char log[512]; + sprintf(log, "Download asset: %s", filename); + os::Printer::log(log); + } + else + { + char log[512]; + sprintf(log, "Download asset: %s - %d%%", filename, m_getFile->getPercent()); + m_textInfo->setText(log); + + if (m_getFile->getState() == CGetFileURL::Finish) + { + // [bundles].zip + fileSystem->addFileArchive(filename, false, false); + + if (++m_downloaded >= listBundles.size()) + m_initState = CViewInit::InitScene; + else + { + delete m_getFile; + m_getFile = NULL; + } + } + else if (m_getFile->getState() == CGetFileURL::Error) + { + // retry download + delete m_getFile; + m_getFile = NULL; + } + } +#else + + for (std::string& bundle : listBundles) + { + const char* r = bundle.c_str(); + fileSystem->addFileArchive(getBuiltInPath(r), false, false); + } + + m_initState = CViewInit::InitScene; +#endif + } + break; + case CViewInit::InitScene: + { + initScene(); + m_initState = CViewInit::Finished; + } + break; + case CViewInit::Error: + { + // todo nothing with black screen + } + break; + default: + { + CScene* scene = context->getScene(); + if (scene != NULL) + scene->update(); + + CViewManager::getInstance()->getLayer(0)->changeView(); + } + break; + } +} + +void CViewInit::onRender() +{ + if (m_initState == CViewInit::Finished) + { + CContext* context = CContext::getInstance(); + CScene* scene = CContext::getInstance()->getScene(); + CBaseRP* rp = CContext::getInstance()->getRenderPipeline(); + + if (m_bakeSHLighting == true) + { + m_bakeSHLighting = false; + + CZone* zone = scene->getZone(0); + + // light probe + CGameObject* lightProbeObj = zone->createEmptyObject(); + CLightProbe* lightProbe = lightProbeObj->addComponent(); + lightProbeObj->getTransformEuler()->setPosition(core::vector3df(0.0f, 1.0f, 0.0f)); + + CGameObject* bakeCameraObj = scene->getZone(0)->createEmptyObject(); + CCamera* bakeCamera = bakeCameraObj->addComponent(); + scene->updateAddRemoveObject(); + + // bake light probe + Lightmapper::CLightmapper* lm = Lightmapper::CLightmapper::getInstance(); + lm->initBaker(64); + + std::vector probes; + probes.push_back(lightProbe); + + lm->bakeProbes(probes, bakeCamera, rp, scene->getEntityManager()); + } + } + else + { + CCamera* guiCamera = CContext::getInstance()->getGUICamera(); + CGraphics2D::getInstance()->render(guiCamera); + } +} diff --git a/Samples/CharacterController/Source/CViewInit.h b/Samples/CharacterController/Source/CViewInit.h new file mode 100644 index 000000000..cbf0e11a0 --- /dev/null +++ b/Samples/CharacterController/Source/CViewInit.h @@ -0,0 +1,49 @@ +#pragma once + +#include "SkylichtEngine.h" +#include "ViewManager/CView.h" +#include "Emscripten/CGetFileURL.h" + +class CViewInit : public CView +{ +public: + enum EInitState + { + DownloadBundles, + InitScene, + Error, + Finished + }; + +protected: + CGetFileURL* m_getFile; + + bool m_bakeSHLighting; + + EInitState m_initState; + unsigned int m_downloaded; + + CGameObject* m_guiObject; + CGUIText* m_textInfo; + CGlyphFont* m_font; + +protected: + io::path getBuiltInPath(const char* name); + +public: + CViewInit(); + + virtual ~CViewInit(); + + virtual void onInit(); + + virtual void onDestroy(); + + virtual void onUpdate(); + + virtual void onRender(); + +protected: + + void initScene(); +}; diff --git a/Samples/CharacterController/Source/CharacterController.cpp b/Samples/CharacterController/Source/CharacterController.cpp new file mode 100644 index 000000000..5d87f718a --- /dev/null +++ b/Samples/CharacterController/Source/CharacterController.cpp @@ -0,0 +1,83 @@ +#include "pch.h" +#include "CharacterController.h" + +#include "Context/CContext.h" +#include "ViewManager/CViewManager.h" +#include "CImguiManager.h" + +#include "CViewInit.h" + +void installApplication(const std::vector& argv) +{ + CharacterController* app = new CharacterController(); + getApplication()->registerAppEvent("CharacterController", app); +} + +CharacterController::CharacterController() +{ + CContext::createGetInstance(); + CViewManager::createGetInstance()->initViewLayer(1); + CLightmapper::createGetInstance(); + CImguiManager::createGetInstance(); +} + +CharacterController::~CharacterController() +{ + CViewManager::releaseInstance(); + CContext::releaseInstance(); + CLightmapper::releaseInstance(); + CImguiManager::releaseInstance(); +} + +void CharacterController::onInitApp() +{ + CViewManager::getInstance()->getLayer(0)->pushView(); +} + +void CharacterController::onUpdate() +{ + CViewManager::getInstance()->update(); +} + +void CharacterController::onRender() +{ + CViewManager::getInstance()->render(); +} + +void CharacterController::onPostRender() +{ + // post render application + CViewManager::getInstance()->postRender(); +} + +bool CharacterController::onBack() +{ + // on back key press + // return TRUE will run default by OS (Mobile) + // return FALSE will cancel BACK FUNCTION by OS (Mobile) + return CViewManager::getInstance()->onBack(); +} + +void CharacterController::onResize(int w, int h) +{ + if (CContext::getInstance() != NULL) + CContext::getInstance()->resize(w, h); +} + +void CharacterController::onResume() +{ + // resume application + CViewManager::getInstance()->onResume(); +} + +void CharacterController::onPause() +{ + // pause application + CViewManager::getInstance()->onPause(); +} + +void CharacterController::onQuitApp() +{ + // end application + delete this; +} \ No newline at end of file diff --git a/Samples/CharacterController/Source/CharacterController.h b/Samples/CharacterController/Source/CharacterController.h new file mode 100644 index 000000000..f585c02a9 --- /dev/null +++ b/Samples/CharacterController/Source/CharacterController.h @@ -0,0 +1,28 @@ +#pragma once + +#include "IApplicationEventReceiver.h" + +class CharacterController : public IApplicationEventReceiver +{ +public: + CharacterController(); + virtual ~CharacterController(); + + virtual void onUpdate(); + + virtual void onRender(); + + virtual void onPostRender(); + + virtual void onResume(); + + virtual void onPause(); + + virtual bool onBack(); + + virtual void onResize(int w, int h); + + virtual void onInitApp(); + + virtual void onQuitApp(); +}; \ No newline at end of file diff --git a/Samples/CharacterController/Source/Version.h b/Samples/CharacterController/Source/Version.h new file mode 100644 index 000000000..0cb2aa68b --- /dev/null +++ b/Samples/CharacterController/Source/Version.h @@ -0,0 +1,4 @@ +#pragma once + +#define PROJECT_NAME "CharacterController" +#define PROJECT_VERSION "0.0.2" \ No newline at end of file diff --git a/Samples/TemplateEmpty/Source/CViewDemo.cpp b/Samples/TemplateEmpty/Source/CViewDemo.cpp new file mode 100644 index 000000000..9595cdcaa --- /dev/null +++ b/Samples/TemplateEmpty/Source/CViewDemo.cpp @@ -0,0 +1,67 @@ +#include "pch.h" +#include "CViewDemo.h" + +#include "Context/CContext.h" +#include "CImguiManager.h" +#include "imgui.h" + +CViewDemo::CViewDemo() +{ + +} + +CViewDemo::~CViewDemo() +{ + +} + +void CViewDemo::onInit() +{ + CContext* context = CContext::getInstance(); + CCamera* camera = context->getActiveCamera(); + + CScene* scene = context->getScene(); + scene->updateIndexSearchObject(); + + +} + +void CViewDemo::onDestroy() +{ + +} + +void CViewDemo::onUpdate() +{ + CContext* context = CContext::getInstance(); + CScene* scene = context->getScene(); + if (scene != NULL) + scene->update(); +} + +void CViewDemo::onRender() +{ + CContext* context = CContext::getInstance(); + + CCamera* camera = context->getActiveCamera(); + CCamera* guiCamera = context->getGUICamera(); + + CScene* scene = context->getScene(); + + // render scene + if (camera != NULL && scene != NULL) + { + context->getRenderPipeline()->render(NULL, camera, scene->getEntityManager(), core::recti()); + } + + // render GUI + if (guiCamera != NULL) + { + CGraphics2D::getInstance()->render(guiCamera); + } +} + +void CViewDemo::onPostRender() +{ + +} diff --git a/Samples/TemplateEmpty/Source/CViewDemo.h b/Samples/TemplateEmpty/Source/CViewDemo.h new file mode 100644 index 000000000..255b5c850 --- /dev/null +++ b/Samples/TemplateEmpty/Source/CViewDemo.h @@ -0,0 +1,23 @@ +#pragma once + +#include "ViewManager/CView.h" + +class CViewDemo : public CView +{ +protected: + +public: + CViewDemo(); + + virtual ~CViewDemo(); + + virtual void onInit(); + + virtual void onDestroy(); + + virtual void onUpdate(); + + virtual void onRender(); + + virtual void onPostRender(); +}; \ No newline at end of file diff --git a/Samples/TemplateEmpty/Source/CViewInit.cpp b/Samples/TemplateEmpty/Source/CViewInit.cpp new file mode 100644 index 000000000..4e8d8ea86 --- /dev/null +++ b/Samples/TemplateEmpty/Source/CViewInit.cpp @@ -0,0 +1,265 @@ +#include "pch.h" +#include "CViewInit.h" +#include "CViewDemo.h" + +#include "ViewManager/CViewManager.h" +#include "Context/CContext.h" +#include "Transform/CWorldTransformSystem.h" + +#include "Primitive/CPlane.h" +#include "Primitive/CCube.h" +#include "Primitive/CSphere.h" +#include "SkySun/CSkySun.h" + + +CViewInit::CViewInit() : + m_initState(CViewInit::DownloadBundles), + m_getFile(NULL), + m_downloaded(0), + m_bakeSHLighting(true) +{ + +} + +CViewInit::~CViewInit() +{ + +} + +io::path CViewInit::getBuiltInPath(const char* name) +{ + return getApplication()->getBuiltInPath(name); +} + +void CViewInit::onInit() +{ + CBaseApp* app = getApplication(); + app->showDebugConsole(); + app->getFileSystem()->addFileArchive(getBuiltInPath("BuiltIn.zip"), false, false); + + CShaderManager* shaderMgr = CShaderManager::getInstance(); + shaderMgr->initBasicShader(); + shaderMgr->initSGForwarderShader(); + shaderMgr->initSGDeferredShader(); + + CGlyphFreetype* freetypeFont = CGlyphFreetype::getInstance(); + freetypeFont->initFont("Segoe UI Light", "BuiltIn/Fonts/segoeui/segoeuil.ttf"); + + // init basic gui + CZone* zone = CContext::getInstance()->initScene()->createZone(); + m_guiObject = zone->createEmptyObject(); + CCanvas* canvas = m_guiObject->addComponent(); + + // load font + m_font = new CGlyphFont(); + m_font->setFont("Segoe UI Light", 25); + + // create text + m_textInfo = canvas->createText(m_font); + m_textInfo->setTextAlign(EGUIHorizontalAlign::Center, EGUIVerticalAlign::Middle); + m_textInfo->setText(L"Init assets"); + + // create gui camera + CGameObject* guiCameraObject = zone->createEmptyObject(); + CCamera* guiCamera = guiCameraObject->addComponent(); + guiCamera->setProjectionType(CCamera::OrthoUI); + CContext::getInstance()->setGUICamera(guiCamera); +} + +void CViewInit::initScene() +{ + CBaseApp* app = getApplication(); + + // create a scene + CScene* scene = CContext::getInstance()->getScene(); + CZone* zone = scene->getZone(0); + + // camera + CGameObject* camObj = zone->createEmptyObject(); + camObj->addComponent(); + camObj->addComponent()->setMoveSpeed(2.0f); + camObj->addComponent()->setMoveSpeed(1.0f); + + CCamera* camera = camObj->getComponent(); + camera->setPosition(core::vector3df(0.0f, 5.0f, 10.0f)); + camera->lookAt(core::vector3df(0.0f, 1.0f, 0.0f), core::vector3df(0.0f, 1.0f, 0.0f)); + + // gui camera + CGameObject* guiCameraObject = zone->createEmptyObject(); + CCamera* guiCamera = guiCameraObject->addComponent(); + guiCamera->setProjectionType(CCamera::OrthoUI); + + // sky + CSkySun* skySun = zone->createEmptyObject()->addComponent(); + + // reflection probe + CGameObject* reflectionProbeObj = zone->createEmptyObject(); + CReflectionProbe* reflection = reflectionProbeObj->addComponent(); + reflection->loadStaticTexture("Common/Textures/Sky/PaperMill"); + + // lighting + CGameObject* lightObj = zone->createEmptyObject(); + CDirectionalLight* directionalLight = lightObj->addComponent(); + SColor c(255, 255, 244, 214); + directionalLight->setColor(SColorf(c)); + + CTransformEuler* lightTransform = lightObj->getTransformEuler(); + lightTransform->setPosition(core::vector3df(2.0f, 2.0f, 2.0f)); + + core::vector3df direction = core::vector3df(4.0f, -6.0f, -4.5f); + lightTransform->setOrientation(direction, Transform::Oy); + + // plane + CGameObject* grid = zone->createEmptyObject(); + grid->setName("Plane"); + grid->getTransformEuler()->setScale(core::vector3df(10.0f, 1.0f, 10.0f)); + + CPlane* plane = grid->addComponent(); + plane->getMaterial()->changeShader("BuiltIn/Shader/SpecularGlossiness/Deferred/MetersGrid.xml"); + + + + // rendering + u32 w = app->getWidth(); + u32 h = app->getHeight(); + + CContext* context = CContext::getInstance(); + + context->initRenderPipeline(w, h); + context->setActiveZone(zone); + context->setActiveCamera(camera); + context->setGUICamera(guiCamera); + context->setDirectionalLight(directionalLight); +} + +void CViewInit::onDestroy() +{ + m_guiObject->remove(); + delete m_font; +} + +void CViewInit::onUpdate() +{ + CContext* context = CContext::getInstance(); + + switch (m_initState) + { + case CViewInit::DownloadBundles: + { + io::IFileSystem* fileSystem = getApplication()->getFileSystem(); + + std::vector listBundles; + listBundles.push_back("Common.zip"); + +#ifdef __EMSCRIPTEN__ + const char* filename = listBundles[m_downloaded].c_str(); + + if (m_getFile == NULL) + { + m_getFile = new CGetFileURL(filename, filename); + m_getFile->download(CGetFileURL::Get); + + char log[512]; + sprintf(log, "Download asset: %s", filename); + os::Printer::log(log); + } + else + { + char log[512]; + sprintf(log, "Download asset: %s - %d%%", filename, m_getFile->getPercent()); + m_textInfo->setText(log); + + if (m_getFile->getState() == CGetFileURL::Finish) + { + // [bundles].zip + fileSystem->addFileArchive(filename, false, false); + + if (++m_downloaded >= listBundles.size()) + m_initState = CViewInit::InitScene; + else + { + delete m_getFile; + m_getFile = NULL; + } + } + else if (m_getFile->getState() == CGetFileURL::Error) + { + // retry download + delete m_getFile; + m_getFile = NULL; + } + } +#else + + for (std::string& bundle : listBundles) + { + const char* r = bundle.c_str(); + fileSystem->addFileArchive(getBuiltInPath(r), false, false); + } + + m_initState = CViewInit::InitScene; +#endif + } + break; + case CViewInit::InitScene: + { + initScene(); + m_initState = CViewInit::Finished; + } + break; + case CViewInit::Error: + { + // todo nothing with black screen + } + break; + default: + { + CScene* scene = context->getScene(); + if (scene != NULL) + scene->update(); + + CViewManager::getInstance()->getLayer(0)->changeView(); + } + break; + } + } + +void CViewInit::onRender() +{ + if (m_initState == CViewInit::Finished) + { + CContext* context = CContext::getInstance(); + CScene* scene = CContext::getInstance()->getScene(); + CBaseRP* rp = CContext::getInstance()->getRenderPipeline(); + + if (m_bakeSHLighting == true) + { + m_bakeSHLighting = false; + + CZone* zone = scene->getZone(0); + + // light probe + CGameObject* lightProbeObj = zone->createEmptyObject(); + CLightProbe* lightProbe = lightProbeObj->addComponent(); + lightProbeObj->getTransformEuler()->setPosition(core::vector3df(0.0f, 1.0f, 0.0f)); + + CGameObject* bakeCameraObj = scene->getZone(0)->createEmptyObject(); + CCamera* bakeCamera = bakeCameraObj->addComponent(); + scene->updateAddRemoveObject(); + + // bake light probe + Lightmapper::CLightmapper* lm = Lightmapper::CLightmapper::getInstance(); + lm->initBaker(64); + + std::vector probes; + probes.push_back(lightProbe); + + lm->bakeProbes(probes, bakeCamera, rp, scene->getEntityManager()); + } + } + else + { + CCamera* guiCamera = CContext::getInstance()->getGUICamera(); + CGraphics2D::getInstance()->render(guiCamera); + } +} diff --git a/Samples/TemplateEmpty/Source/CViewInit.h b/Samples/TemplateEmpty/Source/CViewInit.h new file mode 100644 index 000000000..cbf0e11a0 --- /dev/null +++ b/Samples/TemplateEmpty/Source/CViewInit.h @@ -0,0 +1,49 @@ +#pragma once + +#include "SkylichtEngine.h" +#include "ViewManager/CView.h" +#include "Emscripten/CGetFileURL.h" + +class CViewInit : public CView +{ +public: + enum EInitState + { + DownloadBundles, + InitScene, + Error, + Finished + }; + +protected: + CGetFileURL* m_getFile; + + bool m_bakeSHLighting; + + EInitState m_initState; + unsigned int m_downloaded; + + CGameObject* m_guiObject; + CGUIText* m_textInfo; + CGlyphFont* m_font; + +protected: + io::path getBuiltInPath(const char* name); + +public: + CViewInit(); + + virtual ~CViewInit(); + + virtual void onInit(); + + virtual void onDestroy(); + + virtual void onUpdate(); + + virtual void onRender(); + +protected: + + void initScene(); +}; diff --git a/Samples/TemplateEmpty/Source/Template.cpp b/Samples/TemplateEmpty/Source/Template.cpp new file mode 100644 index 000000000..574559745 --- /dev/null +++ b/Samples/TemplateEmpty/Source/Template.cpp @@ -0,0 +1,83 @@ +#include "pch.h" +#include "Template.h" + +#include "Context/CContext.h" +#include "ViewManager/CViewManager.h" +#include "CImguiManager.h" + +#include "CViewInit.h" + +void installApplication(const std::vector& argv) +{ + Template* app = new Template(); + getApplication()->registerAppEvent("Template", app); +} + +Template::Template() +{ + CContext::createGetInstance(); + CViewManager::createGetInstance()->initViewLayer(1); + CLightmapper::createGetInstance(); + CImguiManager::createGetInstance(); +} + +Template::~Template() +{ + CViewManager::releaseInstance(); + CContext::releaseInstance(); + CLightmapper::releaseInstance(); + CImguiManager::releaseInstance(); +} + +void Template::onInitApp() +{ + CViewManager::getInstance()->getLayer(0)->pushView(); +} + +void Template::onUpdate() +{ + CViewManager::getInstance()->update(); +} + +void Template::onRender() +{ + CViewManager::getInstance()->render(); +} + +void Template::onPostRender() +{ + // post render application + CViewManager::getInstance()->postRender(); +} + +bool Template::onBack() +{ + // on back key press + // return TRUE will run default by OS (Mobile) + // return FALSE will cancel BACK FUNCTION by OS (Mobile) + return CViewManager::getInstance()->onBack(); +} + +void Template::onResize(int w, int h) +{ + if (CContext::getInstance() != NULL) + CContext::getInstance()->resize(w, h); +} + +void Template::onResume() +{ + // resume application + CViewManager::getInstance()->onResume(); +} + +void Template::onPause() +{ + // pause application + CViewManager::getInstance()->onPause(); +} + +void Template::onQuitApp() +{ + // end application + delete this; +} \ No newline at end of file diff --git a/Samples/TemplateEmpty/Source/Template.h b/Samples/TemplateEmpty/Source/Template.h new file mode 100644 index 000000000..0fa8292ea --- /dev/null +++ b/Samples/TemplateEmpty/Source/Template.h @@ -0,0 +1,28 @@ +#pragma once + +#include "IApplicationEventReceiver.h" + +class Template : public IApplicationEventReceiver +{ +public: + Template(); + virtual ~Template(); + + virtual void onUpdate(); + + virtual void onRender(); + + virtual void onPostRender(); + + virtual void onResume(); + + virtual void onPause(); + + virtual bool onBack(); + + virtual void onResize(int w, int h); + + virtual void onInitApp(); + + virtual void onQuitApp(); +}; \ No newline at end of file diff --git a/Samples/TemplateEmpty/Source/Version.h b/Samples/TemplateEmpty/Source/Version.h new file mode 100644 index 000000000..0cb2aa68b --- /dev/null +++ b/Samples/TemplateEmpty/Source/Version.h @@ -0,0 +1,4 @@ +#pragma once + +#define PROJECT_NAME "CharacterController" +#define PROJECT_VERSION "0.0.2" \ No newline at end of file