模型下載網(wǎng)站開發(fā)流程廣州網(wǎng)頁制作
配置:
日志庫文件github:
GitHub - gabime/spdlog: Fast C++ logging library.
新建vendor文件夾
將下載好的spdlog放入
配置YOTOEngine的附加包含目錄:
配置Sandbox的附加包含目錄:
包裝spdlog:
在YOTO文件夾下創(chuàng)建Log.cpp和log.h
log.h:
#pragma once
#include"Core.h"
#include<spdlog/spdlog.h>
#include "spdlog/sinks/stdout_color_sinks.h"
namespace YOTO {class YOTO_API Log{public:static void Init();//inline是為了提高性能,相當(dāng)于直接把函數(shù)里的代碼段放在那里//返回的是Logger,分為服務(wù)器logger和核心loggerinline static std::shared_ptr<spdlog::logger> GetCoreLogger() { return s_CoreLogger; }inline static std::shared_ptr<spdlog::logger> GetClientLogger() { return s_ClientLogger; }private:static std::shared_ptr<spdlog::logger> s_CoreLogger;static std::shared_ptr<spdlog::logger> s_ClientLogger;};
}
//Core 的log 的簡化
#define YT_CORE_ERROR(...) ::YOTO::Log::GetCoreLogger()->error(__VA_ARGS__)
#define YT_CORE_WARN(...) ::YOTO::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define YT_CORE_INFO(...) ::YOTO::Log::GetCoreLogger()->info(__VA_ARGS__)
#define YT_CORE_TRACE(...) ::YOTO::Log::GetCoreLogger()->trace(__VA_ARGS__)
#define YT_CORE_FATAL(...) ::YOTO::Log::GetCoreLogger()->fatal(__VA_ARGS__)
//client 的log的簡化
#define YT_CLIENT_ERROR(...) ::YOTO::Log::GetClientLogger()->error(__VA_ARGS__)
#define YT_CLIENT_WARN(...) ::YOTO::Log::GetClientLogger()->warn(__VA_ARGS__)
#define YT_CLIENT_INFO(...) ::YOTO::Log::GetClientLogger()->info(__VA_ARGS__)
#define YT_CLIENT_TRACE(...) ::YOTO::Log::GetClientLogger()->trace(__VA_ARGS__)
#define YT_CLIENT_FATAL(...) ::YOTO::Log::GetClientLogger()->fatal(__VA_ARGS__)
?log.cpp:
#include "Log.h"namespace YOTO {std::shared_ptr<spdlog::logger> Log::s_CoreLogger;std::shared_ptr<spdlog::logger> Log::s_ClientLogger;void Log::Init() {//設(shè)置日志格式spdlog::set_pattern("%^[%T] %n: %v%$");//創(chuàng)建多線程logger,核心logger為YOTOs_CoreLogger = spdlog::stdout_color_mt("YOTO");//設(shè)置打印消息的級(jí)別,trace是打印所有東西(篩選器)s_CoreLogger->set_level(spdlog::level::level_enum::trace);//客戶端的為APPs_ClientLogger= spdlog::stdout_color_mt("APP");s_ClientLogger->set_level(spdlog::level::level_enum::trace);}
}
?測試:
在YOTO.h中加入#include "YOTO/Log.h",記得重新生成,把dll加入到Sandbox(后續(xù)會(huì)使用premake簡化該流程,這里暫時(shí)手動(dòng)生成)
我們?cè)谌肟邳c(diǎn)修改代碼測試:
#pragma once#ifdef YT_PLATFORM_WINDOWS
#include "../YOTO.h"extern YOTO::Application* YOTO::CreateApplication();
void main(int argc,char** argv) {YOTO::Log::Init();YT_CORE_ERROR("測試警告信息");int test = 1;YT_CLIENT_INFO("測試info:test={0}",test);auto app = YOTO::CreateApplication();app->Run();delete app;
}
#endif
輸出:
Premake配置安裝:
點(diǎn)擊下載:https://github.com/premake/premake-core/releases/download/v5.0.0-beta2/premake-5.0.0-beta2-windows.zip
創(chuàng)建vendor文件夾:文件結(jié)構(gòu)如下
放入聲明文件LICENSE.txt:
Copyright (c) 2003-2016 Jason Perkins and individual contributors.
All rights reserved.Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:1. Redistributions of source code must retain the above copyright notice,this list of conditions and the following disclaimer.2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentationand/or other materials provided with the distribution.3. Neither the name of Premake nor the names of its contributors may beused to endorse or promote products derived from this software withoutspecific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
編寫premake5.lua文件:
workspace "YOTOEngine" -- sln文件名architecture "x64" configurations{"Debug","Release","Dist"}-- 組成輸出目錄:Debug-windows-x86_64
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"project "YOTOEngine" location "YOTOEngine"--在sln所屬文件夾下的Hazel文件夾kind "SharedLib"--dll動(dòng)態(tài)庫language "C++"targetdir ("bin/" .. outputdir .. "/%{prj.name}") -- 輸出目錄objdir ("bin-int/" .. outputdir .. "/%{prj.name}")-- 中間目錄-- 包含的所有h和cpp文件files{"%{prj.name}/src/**.h","%{prj.name}/src/**.cpp"}-- 包含目錄includedirs{"%{prj.name}/vendor/spdlog-1.x/include"}-- 如果是window系統(tǒng)filter "system:windows"cppdialect "C++17"-- On:代碼生成的運(yùn)行庫選項(xiàng)是MTD,靜態(tài)鏈接MSVCRT.lib庫;-- Off:代碼生成的運(yùn)行庫選項(xiàng)是MDD,動(dòng)態(tài)鏈接MSVCRT.dll庫;打包后的exe放到另一臺(tái)電腦上若無這個(gè)dll會(huì)報(bào)錯(cuò)staticruntime "On" systemversion "latest" -- windowSDK版本-- 預(yù)處理器定義defines{"YT_PLATFORM_WINDOWS","YT_BUILD_DLL"}-- 編譯好后移動(dòng)Hazel.dll文件到Sandbox文件夾下postbuildcommands{("{COPY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/Sandbox")}-- 不同配置下的預(yù)定義不同filter "configurations:Debug"defines "YT_DEBUG"symbols "On"filter "configurations:Release"defines "YT_RELEASE"optimize "On"filter "configurations:Dist"defines "YT_DIST"optimize "On"project "Sandbox"location "Sandbox"kind "ConsoleApp"language "C++"targetdir ("bin/" .. outputdir .. "/%{prj.name}")objdir ("bin-int/" .. outputdir .. "/%{prj.name}")files{"%{prj.name}/src/**.h","%{prj.name}/src/**.cpp"}-- 同樣包含spdlog頭文件includedirs{"YOTOEngine/vendor/spdlog-1.x/include","YOTOEngine/src"}-- 引用YOTOEnginelinks{"YOTOEngine"}filter "system:windows"cppdialect "C++17"staticruntime "On"systemversion "latest"defines{"YT_PLATFORM_WINDOWS"}filter "configurations:Debug"defines "YT_DEBUG"symbols "On"filter "configurations:Release"defines "YT_RELEASE"optimize "On"filter "configurations:Dist"defines "YT_DIST"optimize "On"
創(chuàng)建Generate.bat文件,每次將bin和bin-int刪除然后點(diǎn)這個(gè)文件就可以自動(dòng)生成。
call vendor\bin\premake\premake5.exe vs2019
PAUSE
?遇到問題不要慌:
這個(gè)問題是還沒創(chuàng)建完就啟動(dòng)了,只需要等一會(huì)兒就好了。
等待10秒鐘之后:啟動(dòng)!
今天就看到這里,下一集:事件系統(tǒng)【持續(xù)更新中】