Use root controller with factory pattern
This commit is contained in:
		
							parent
							
								
									cea3710c76
								
							
						
					
					
						commit
						23694c755d
					
				
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,2 +1,5 @@
 | 
			
		||||
link/
 | 
			
		||||
.vscode/
 | 
			
		||||
earn/
 | 
			
		||||
*.swp
 | 
			
		||||
*.swo
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1 @@
 | 
			
		||||
apt install -y libx11-dev
 | 
			
		||||
@ -1,22 +1,10 @@
 | 
			
		||||
#include "act/root.h"
 | 
			
		||||
#include "allocate/factory.h"
 | 
			
		||||
#include "draw/window.h"
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
root_controller_t::configuration_t::configuration_t(std::vector<root_controller_t::mode_t> modes_p) {
 | 
			
		||||
	modes_m = modes_p;
 | 
			
		||||
}
 | 
			
		||||
root_controller_t::root_controller_t(root_controller_t::configuration_t configuration_p) {
 | 
			
		||||
	configuration_m = configuration_p;
 | 
			
		||||
}
 | 
			
		||||
root_controller_t* root_controller_factory_t::create(root_controller_t::configuration_t configuration_p) {
 | 
			
		||||
	void* ptr = malloc(sizeof(root_controller_t));
 | 
			
		||||
	return static_cast<root_controller_t*>(ptr);
 | 
			
		||||
}
 | 
			
		||||
factory_t::status_t root_controller_factory_t::dispose(root_controller_t* root_controller_p) {
 | 
			
		||||
	free(root_controller_p);
 | 
			
		||||
	return factory_t::status_t::ok;
 | 
			
		||||
root_controller_t::root_controller_t(root_controller_t::configuration_t* configuration_p) {
 | 
			
		||||
	mode_m = configuration_p->mode_m;
 | 
			
		||||
}
 | 
			
		||||
controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p) {
 | 
			
		||||
	if (
 | 
			
		||||
	window_service_t* window_service = new window_service_t();
 | 
			
		||||
	window_service_t::status_t window_status = window_service->create_window();
 | 
			
		||||
	controller_t::status_t controller_status;
 | 
			
		||||
@ -31,3 +19,10 @@ controller_t::status_t root_controller_t::on_event(controller_t::event_t event_p
 | 
			
		||||
	}
 | 
			
		||||
	return controller_status;
 | 
			
		||||
}
 | 
			
		||||
root_controller_t* root_controller_factory_t::create(root_controller_t::configuration_t* configuration_p) {
 | 
			
		||||
	return new root_controller_t(configuration_p);
 | 
			
		||||
}
 | 
			
		||||
factory_t<root_controller_t::configuration_t, root_controller_t>::status_t root_controller_factory_t::dispose(root_controller_t* root_controller_p) {
 | 
			
		||||
	delete root_controller_p;
 | 
			
		||||
	return factory_t<root_controller_t::configuration_t, root_controller_t>::status_t::ok;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,20 +10,15 @@ class root_controller_t : public controller_t {
 | 
			
		||||
		app,
 | 
			
		||||
		game
 | 
			
		||||
	};
 | 
			
		||||
	class configuration_t {
 | 
			
		||||
		private:
 | 
			
		||||
		std::vector<mode_t> modes_m;
 | 
			
		||||
		public:
 | 
			
		||||
		configuration_t(std::vector<mode_t> modes_p);
 | 
			
		||||
	struct configuration_t {
 | 
			
		||||
		mode_t mode_m;
 | 
			
		||||
	};
 | 
			
		||||
	root_controller_t(configuration_t* configuration_p);
 | 
			
		||||
	controller_t::status_t on_event(event_t event_p) override;
 | 
			
		||||
	private:
 | 
			
		||||
	configuration_t configuration_m;
 | 
			
		||||
	root_controller_t(configuration_t configuration_p);
 | 
			
		||||
	friend class root_controller_factory_t;
 | 
			
		||||
	mode_t mode_m;
 | 
			
		||||
};
 | 
			
		||||
class root_controller_factory_t : public factory_t<root_controller_t::configuration_t, root_controller_t> {
 | 
			
		||||
	public:
 | 
			
		||||
	root_controller_t* create(root_controller_t::configuration_t* configuration_p) override;
 | 
			
		||||
	factory_t::status_t dispose(root_controller_t* root_controller_p) override;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -2,12 +2,10 @@
 | 
			
		||||
#include "act/root.h"
 | 
			
		||||
#include <vector>
 | 
			
		||||
int main(int argc, char *argv[]) {
 | 
			
		||||
	root_controller_factory_t factory_l;
 | 
			
		||||
	std::vector<root_controller_t::mode_t> modes_l;
 | 
			
		||||
	modes_l.push_back(root_controller_t::mode_t::app);
 | 
			
		||||
	root_controller_t::configuration_t configuration_l(modes_l);
 | 
			
		||||
	root_controller_t* controller_l = factory_l.create(&configuration_l);
 | 
			
		||||
	root_controller_t::configuration_t configuration_l;
 | 
			
		||||
	configuration_l.mode_m = root_controller_t::mode_t::app;
 | 
			
		||||
	root_controller_t* controller_l = new root_controller_t(&configuration_l);
 | 
			
		||||
	controller_t::status_t status_l = controller_l->on_event(controller_t::event_t::start);
 | 
			
		||||
	factory_l.dispose(controller_l);
 | 
			
		||||
	delete controller_l;
 | 
			
		||||
	return status_l;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
main.cpp
 | 
			
		||||
act/root.cpp
 | 
			
		||||
platform/linux/draw/window.cpp
 | 
			
		||||
target/linux/draw/window.cpp
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								earn/executable
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								earn/executable
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user