refactor: entrypoint
This commit is contained in:
		
							parent
							
								
									26d180ef2f
								
							
						
					
					
						commit
						7f7eb8439c
					
				
					 6 changed files with 32 additions and 110 deletions
				
			
		|  | @ -9,19 +9,13 @@ struct FailedAssertion: std::exception | |||
| 	FailedAssertion(const char *file, int line); | ||||
| }; | ||||
| 
 | ||||
| // OpenGL
 | ||||
| struct glException: std::exception | ||||
| { | ||||
| 	glException(unsigned int source, unsigned int type, unsigned int id, const char *msg); | ||||
| }; | ||||
| 
 | ||||
| #define lt_assert(x, ...)                                       \ | ||||
| 	{                                                           \ | ||||
| 		if (!(x))                                               \ | ||||
| 		{                                                       \ | ||||
| 			log_crt(__VA_ARGS__);                               \ | ||||
| #define lt_assert(x, ...)                                    \ | ||||
| 	{                                                        \ | ||||
| 		if (!(x))                                            \ | ||||
| 		{                                                    \ | ||||
| 			log_crt(__VA_ARGS__);                            \ | ||||
| 			throw ::lt::FailedAssertion(__FILE__, __LINE__); \ | ||||
| 		}                                                       \ | ||||
| 		}                                                    \ | ||||
| 	} | ||||
| 
 | ||||
| } // namespace lt
 | ||||
|  |  | |||
|  | @ -27,6 +27,8 @@ public: | |||
| 
 | ||||
| 	virtual ~Application(); | ||||
| 
 | ||||
| 	[[nodiscard]] auto sanity_check() const -> bool; | ||||
| 
 | ||||
| 	void game_loop(); | ||||
| 
 | ||||
| 	[[nodiscard]] auto get_window() -> Window & | ||||
|  |  | |||
|  | @ -1,90 +1,27 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #ifdef LIGHT_PLATFORM_WINDOWS | ||||
| #include <engine/engine.hpp> | ||||
| 
 | ||||
| 	#include <engine/engine.hpp> | ||||
| 
 | ||||
| // to be defined in client project
 | ||||
| extern auto lt::create_application() -> lt::Scope<lt::Application>; | ||||
| 
 | ||||
| // #todo: use windows specific stuff
 | ||||
| int main(int argc, char *argv[]) | ||||
| int main(int argc, char *argv[]) // NOLINT
 | ||||
| try | ||||
| { | ||||
| 	std::ignore = argc; | ||||
| 	std::ignore = argv; | ||||
| 
 | ||||
| 	auto application = lt::Scope<lt::Application> {}; | ||||
| 	int exitCode = 0; | ||||
| 
 | ||||
| 	std::vector<std::string> args; | ||||
| 	application = lt::create_application(); | ||||
| 
 | ||||
| 	if (argc > 1) | ||||
| 		args.assign(argv + 1, argv + argc); | ||||
| 	lt_assert(application, "Failed to create application"); | ||||
| 	lt_assert(application->sanity_check(), "Failed to verify the sanity of the application"); | ||||
| 
 | ||||
| 	try | ||||
| 	{ | ||||
| 		application = lt::create_application(); | ||||
| 		lt_assert(application, "lt::Application is not intialized"); | ||||
| 	application->game_loop(); | ||||
| 
 | ||||
| 		for (int i = 0; i < argc; i++) | ||||
| 			log_inf("argv[{}]: {}", i, argv[i]); | ||||
| 
 | ||||
| 		application->game_loop(); | ||||
| 	} | ||||
| 	// failed engine assertion
 | ||||
| 	catch (lt::FailedAssertion) | ||||
| 	{ | ||||
| 		log_crt("Terminating due to unhandled 'FailedEngineAssertion'"); | ||||
| 		exitCode = -1; | ||||
| 	} | ||||
| 	// gl exception
 | ||||
| 	catch (lt::glException) | ||||
| 	{ | ||||
| 		log_crt("Terminating due to unhandled 'glException'"); | ||||
| 		exitCode = -3; | ||||
| 	} | ||||
| 	// dx exception
 | ||||
| 	catch (lt::dxException) | ||||
| 	{ | ||||
| 		log_crt("Terminating due to unhandled 'dxException'"); | ||||
| 		exitCode = -4; | ||||
| 	} | ||||
| 
 | ||||
| 	delete application; | ||||
| 	return exitCode; | ||||
| 	return EXIT_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| #elif defined(LIGHT_PLATFORM_LINUX) | ||||
| 
 | ||||
| 	#include <engine/engine.hpp> | ||||
| 
 | ||||
| // to be defined in client project
 | ||||
| extern auto lt::create_application() -> lt::Scope<lt::Application>; | ||||
| 
 | ||||
| // #todo: use linux specific stuff
 | ||||
| int main(int  /*argc*/, char * /*argv*/[]) | ||||
| catch (const std::exception &exp) | ||||
| { | ||||
| 	auto application = lt::Scope<lt::Application> {}; | ||||
| 	int exitCode = 0; | ||||
| 
 | ||||
| 	try | ||||
| 	{ | ||||
| 		application = lt::create_application(); | ||||
| 		lt_assert(application, "lt::Application is not intialized"); | ||||
| 
 | ||||
| 		application->game_loop(); | ||||
| 	} | ||||
| 	// failed engine assertion
 | ||||
| 	catch (lt::FailedAssertion) | ||||
| 	{ | ||||
| 		log_crt("Exitting due to unhandled 'FailedEngineAssertion'"); | ||||
| 		exitCode = -1; | ||||
| 	} | ||||
| 	// gl exception
 | ||||
| 	catch (lt::glException) | ||||
| 	{ | ||||
| 		log_crt("main: exitting due to unhandled 'glException'"); | ||||
| 		exitCode = -3; | ||||
| 	} | ||||
| 
 | ||||
| 	return exitCode; | ||||
| 	log_crt("Terminating due to uncaught exception:"); | ||||
| 	log_crt("\texception.what(): {}", exp.what()); | ||||
| 	return EXIT_FAILURE; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <debug/assertions.hpp> | ||||
| #include <engine/core/application.hpp> | ||||
| #include <engine/core/window.hpp> | ||||
| #include <engine/debug/instrumentor.hpp> | ||||
|  | @ -7,7 +8,6 @@ | |||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/window.hpp> | ||||
| #include <debug/assertions.hpp> | ||||
| #include <ranges> | ||||
| #include <renderer/blender.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
|  | @ -186,6 +186,12 @@ void Application::on_event(const Event &event) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| [[nodiscard]] auto Application::sanity_check() const -> bool | ||||
| { | ||||
| 	// TODO(Light): verify sanity of the application state
 | ||||
| 	return true; | ||||
| } | ||||
| 
 | ||||
| void Application::log_debug_data() | ||||
| { | ||||
| 	log_inf("Platform::"); | ||||
|  |  | |||
|  | @ -12,24 +12,6 @@ FailedAssertion::FailedAssertion(const char *file, int line) | |||
| 	log_crt("Assertion failed in: {} (line {})", file, line); | ||||
| } | ||||
| 
 | ||||
| glException::glException(unsigned int source, unsigned int type, unsigned int id, const char *msg) | ||||
| { | ||||
| 	// #todo: improve
 | ||||
| 	log_crt("________________________________________"); | ||||
| 	log_crt("glException::glException::"); | ||||
| 	// log_crt("        Severity: {}",
 | ||||
| 	// Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH));
 | ||||
| 	// log_crt("        Source  : {}", Stringifier::glDebugMsgSource(source));
 | ||||
| 	// log_crt("        Type    : {}", Stringifier::glDebugMsgType(type));
 | ||||
| 	log_crt("        ID      : {}", id); | ||||
| 	// log_crt("        Vendor  : {}", glGetString(GL_VENDOR));
 | ||||
| 	// log_crt("        renderer: {}", glGetString(GL_RENDERER));
 | ||||
| 	// log_crt("        Version : {}", glGetString(GL_VERSION));
 | ||||
| 	// log_crt("        critical, SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION));
 | ||||
| 	log_crt("        {}", msg); | ||||
| 	log_crt("________________________________________"); | ||||
| } | ||||
| 
 | ||||
| #ifdef LIGHT_PLATFORM_WINDOWS | ||||
| dxException::dxException(long hr, const char *file, int line) | ||||
| { | ||||
|  |  | |||
|  | @ -74,7 +74,8 @@ void glGraphicsContext::set_debug_message_callback() | |||
| 		    switch (severity) | ||||
| 		    { | ||||
| 		    case GL_DEBUG_SEVERITY_HIGH: | ||||
| 			    // throw glException(source, type, id, message);
 | ||||
| 			    // TODO(Light): Add gl exception class
 | ||||
| 			    throw std::runtime_error { "gl exception" }; | ||||
| 			    return; | ||||
| 
 | ||||
| 		    case GL_DEBUG_SEVERITY_MEDIUM: | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue