Haxel Engine learning 5 -- precompiled header file

添加precompiled header 

#pragma once

#include<iostream>
#include<memory>
#include<utility>
#include<algorithm>
#include<functional>

#include<string>
#include<vector>
#include<sstream>
#include<unordered_map>
#include<unordered_set>

#ifdef HZ_PLATFORM_WINDOWS
	#include<Windows.h>
#endif // HZ_PLATFORM_WINDOWS

修改premake5.lua

 

project "Hazel"
	location "Hazel"
	kind "SharedLib" --dll
	language "C++"

	targetdir("bin/" .. outputDir .. "/%{prj.name}")
	objdir("bin-int/" .. outputDir .. "/%{prj.name}")

	pchheader "hzpch.h"
	pchsource "Hazel/src/hzpch.cpp"


	files
	{
		"%{prj.name}/src/**.h",
		"%{prj.name}/src/**.cpp",
	}
	includedirs
	{
		"%{prj.name}/vendor/spdlog/include",
		"%{prj.name}/src",
	}
	filter "system:windows"
		cppdialect "C++17"
		staticruntime "On" --linking the runtime library
		systemversion "latest"

		defines
		{
			"HZ_BUILD_DLL",
			"HZ_PLATFORM_WINDOWS",
		}

		--create a postbuild step to put the .dll where we want to be
		postbuildcommands{
			("{COPY} %{cfg.buildtarget.relpath} ../bin/" ..outputDir.. "/Sandbox")
		}

		filter "configurations:Debug" --only apply to Debug configurations
			defines "HZ_DEGUG"
			symbols "On"

		filter "configurations:Release" --only apply to Debug configurations
			defines "HZ_RELEASE"
			optimize "On"
		
		filter "configurations:Dist" --only apply to Debug configurations
			defines "HZ_DIST"
			optimize "On"
	

    pchheader "hzpch.h"
    pchsource "Hazel/src/hzpch.cpp"

重新运行GenerateProject.bat

可以看到项目中的precompiled header已经修改了

把所有的.cpp文件都 include "hzpch.h" 

 Application.cpp

#include "hzpch.h"
#include "Application.h"
#include "Hazel/Event/ApplicationEvent.h"
#include "Hazel/Log.h"
namespace Hazel {

	Application::Application()
	{
	}
	
	
	Application::~Application()
	{
	}

	
	
	
	void Application:: Run() {
		WindowResizeEvent e(1280, 720);
		HZ_TRACE(e);
		while (true);
	}
}
	

Log.cpp

#include "hzpch.h"
#include "Log.h"


namespace Hazel {

	std::shared_ptr<spdlog::logger> Log::s_CoreLogger; //static 对象需要在类外初始化
	std::shared_ptr<spdlog::logger> Log::s_ClientLogger;

	void Log::Init() {

		spdlog::set_pattern("%^[%T] %n: %v%$");
		s_CoreLogger = spdlog::stdout_color_mt("HAZEL");
		s_CoreLogger->set_level(spdlog::level::trace);
		s_ClientLogger = spdlog::stderr_color_mt("APP");
		s_ClientLogger->set_level(spdlog::level::trace);


	}
	

}

查看编译时间:

使用预编译头(precompiled header)时间 

不使用预编译头时间:

可以看到添加了precompiled header会更加快

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值