HazelEngine 学习记录-Entry Point

02.Entry Point

  • 将程序启动的入口放置在 Hazel 中:

    • 在 Hazel/src 中新建 Hazel 文件夹 ,新建Core.h
    //Core.h
    #pragma once
    #ifdef HZ_PLATFORM_WINDOWS
    	#if HZ_BUILD_DLL
    		#define HAZEL_API __declspec(dllexport)
    	#else
    		#define HAZEL_API __declspec(dllimport)
    	#endif
    #else 
    	#error Hazel only support windows !
    #endif
    
    • Hazel 属性页中添加预处理器定义 HZ_PLATFORM_WINDOWS;HZ_BUILD_DLL; SandBox 中同时添加HZ_PLATFORM_WINDOWS;
    • 创建 Application 类
    //Application.h
    #pragma once
    #include "Core.h"
    namespace Hazel{
    	class HAZEL_API Application
    	{
    
    	public:
    		Application();
    		virtual ~Application();
    
    
    		void Run();
    	};
    
    }
    //Application.cpp
    #include "Application.h"
    namespace Hazel {
    
    	Application::Application()
    	{
    	}
    
    	Application::~Application()
    	{
    	}
    
    	void Application::Run()
    	{
    		while (true);
    	}
    
    
    }
    
    
    • 在 Hazel 文件夹中新建 Hazel.h,将 Application 进行包含
    #pragma once
    //For use by hazel applications
    
    #include "Hazel/Application.h"
    
    • 想在 SandBox 中包含Hazel.h 先进行目录包含,在 SandBox 属性页中添加附加包含目录 $(SolutionDir)Hazel\src;
    • 创建SandBoxApp.cpp 添加一下内容:
    #include <Hazel.h>
    
    class SandBox : public Hazel::Application
    {
    public:
    	SandBox() {}
    	~SandBox() {}
    
    };
    
    
    int main() {
    	SandBox* sandbox = new SandBox();
    	sandbox->Run();
    	delete sandbox;
    }
    
    • 运行之后发现报错,原因是没有讲新产生的 .dll 文件放到可运行文件所在文件夹当中,复制 Hazel debug 产生的 dll 文件到 exe 文件夹目录当中。
    • 在 Hazel/src/Hazel 中创建 EntryPoint.h 将 main 函数移入,在 Application.h 中对 CreateApplicaition 声明
    //EntryPoint.h
    #pragma once
    
    #ifdef HZ_PLATFORM_WINDOWS
    
    extern Hazel::Application* Hazel::CreateApplication();
    
    int main(int argc, char** argv) 
    {
    	
    	auto app = Hazel::CreateApplication();
    	app->Run();
    	delete app;
    }
    
    #endif
    
    //Application.h
    //To be defined in Client
    	Application* CreateApplication();
    
    • 在原本的 main 函数位置添加
    Hazel::Application* Hazel::CreateApplication() 
    {
    	return new SandBox();
    }
    

    ​ 并在 Hazel.h 中添加 #include “EntryPoint.h”

  • 将工程上传至 github

    • cmd 中键入 git status ,显示文件信息如下:

cmd

  • 创建 .gitignore 文件 添加
#Directories
.vs/
bin/ 
bin-int/

在这里插入图片描述

  • git add *

在这里插入图片描述

  • 隐藏 .user 文件, 在 gitignore 添加 *.user
  • git reset git status git add * git status

在这里插入图片描述

  • commit -m “Setup basic Application and Entry Point.”

  • git push origin master 将工程上传至github(没有成功)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值