Browse Source

Added a lua script (Window_controls.lua) to control window functions
Added more usertypes to LuaScript
Added an empty GUI system/scene/task for future GUI implementation

Paul A 4 years ago
parent
commit
1f9a4a9e30

+ 9 - 2
Praxis3D/Data/Maps/componentTest.pmap

@@ -7,7 +7,7 @@
 			"LocalPosition": "0.0f, 0.0f, 0.0f",
 			"LocalRotation": "0.0f, 0.0f, 0.0f",
 			"LocalScale": "1.0f, 1.0f, 1.0f",
-			"Children":
+			"Children": 
 			[
 				{
 					"ID": "1"
@@ -15,7 +15,14 @@
 				{
 					"ID": "2"
 				}
-			]
+			],
+			"Script":
+			{
+				"Lua": 
+				{
+					"Filename": "Window_controls.lua"
+				}
+			}
 		},
 		{
 			"ID": "1",

+ 62 - 0
Praxis3D/Data/Scripts/Window_controls.lua

@@ -0,0 +1,62 @@
+
+function init ()
+	-- Create needed variables
+	create(Types.EngineVariables, 'engineVariables');
+	create(Types.InputVariables, 'inputVariables');
+	create(Types.WindowVariables, 'windowVariables');
+	
+	-- Create key commands, used to track pressed keys
+	create(Types.KeyCommand, 'closeKey')
+	create(Types.KeyCommand, 'fullscreenKey')
+	create(Types.KeyCommand, 'mouseCaptureKey')
+	create(Types.KeyCommand, 'vsyncKey')
+	
+	-- Bind keys to their corresponding buttons on the keyboard
+	closeKey:bind(inputVariables.close_window_key)
+	fullscreenKey:bind(inputVariables.fullscreen_key)
+	mouseCaptureKey:bind(inputVariables.clip_mouse_key)
+	vsyncKey:bind(inputVariables.vsync_key)
+	
+	-- Get current variables
+	fullscreenBool = windowVariables.fullscreen
+	mouseCaptureBool = windowVariables.mouse_captured
+	vsyncBool = windowVariables.vertical_sync
+	
+	print('Window_controls.lua script initialized.')
+end
+
+function update (p_deltaTime)
+	
+	if closeKey:isActivated() then
+		-- Set the engine running state to false, so it is shutdown the next frame
+		setEngineRunning(false)
+	end	
+	
+	if fullscreenKey:isActivated() then
+		-- Invert the corresponding bool
+		fullscreenBool = not fullscreenBool
+		-- Make the window fullscreen/windowed
+		setFullscreen(fullscreenBool)
+		-- Deactivate the button, so it's not triggered the next frame, unless pressed again
+		fullscreenKey:deactivate()
+	end	
+	
+	if mouseCaptureKey:isActivated() then
+		-- Invert the corresponding bool
+		mouseCaptureBool = not mouseCaptureBool
+		-- Capture/release the mouse
+		setMouseCapture(mouseCaptureBool)
+		-- Deactivate the button, so it's not triggered the next frame, unless pressed again
+		mouseCaptureKey:deactivate()
+	end	
+	
+	if vsyncKey:isActivated() then
+		-- Invert the corresponding bool
+		vsyncBool = not vsyncBool
+		-- Enable/disable vertical synchronization
+		setVerticalSync(vsyncBool)
+		-- Deactivate the button, so it's not triggered the next frame, unless pressed again
+		vsyncKey:deactivate()
+	end	
+	
+end

+ 6 - 1
Praxis3D/Praxis3D.vcxproj

@@ -118,7 +118,7 @@
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
       <ConformanceMode>true</ConformanceMode>
-      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalOptions>/bigobj /MP24 %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
       <AdditionalDependencies>opengl32.lib;assimp.lib;SDL2.lib;SDL2main.lib;glew32.lib;FreeImage.lib;tbb.lib;luajit.lib;lua51.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -141,6 +141,8 @@
     <ClCompile Include="Source\ErrorHandler.cpp" />
     <ClCompile Include="Source\ErrorHandlerLocator.cpp" />
     <ClCompile Include="Source\GeometryBuffer.cpp" />
+    <ClCompile Include="Source\GUIScene.cpp" />
+    <ClCompile Include="Source\GUITask.cpp" />
     <ClCompile Include="Source\Input.cpp" />
     <ClCompile Include="Source\KeyCommand.cpp" />
     <ClCompile Include="Source\LightComponent.cpp" />
@@ -228,6 +230,9 @@
     <ClInclude Include="Source\GeometryPass.h" />
     <ClInclude Include="Source\GraphicsDataSets.h" />
     <ClInclude Include="Source\GraphicsObject.h" />
+    <ClInclude Include="Source\GUIScene.h" />
+    <ClInclude Include="Source\GUISystem.h" />
+    <ClInclude Include="Source\GUITask.h" />
     <ClInclude Include="Source\HdrMappingPass.h" />
     <ClInclude Include="Source\InheritanceObjects.h" />
     <ClInclude Include="Source\Input.h" />

+ 33 - 0
Praxis3D/Praxis3D.vcxproj.filters

@@ -127,6 +127,24 @@
     <Filter Include="World\Objects">
       <UniqueIdentifier>{073f3e46-6b78-459f-b76e-6a8931bf6a7d}</UniqueIdentifier>
     </Filter>
+    <Filter Include="GUI">
+      <UniqueIdentifier>{5d9cc408-17a7-4f79-a669-b3449d7c1f4b}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="GUI\Header Files">
+      <UniqueIdentifier>{5b18d5ae-2a79-4bb2-86d8-b021445d22a8}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="GUI\Source Files">
+      <UniqueIdentifier>{4257612d-0208-4a78-b788-2553db8da2f7}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="GUI\Objects">
+      <UniqueIdentifier>{29af1193-a5e7-4f6c-9fc7-a7a1b4382503}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="GUI\Objects\Header Files">
+      <UniqueIdentifier>{2111e2f4-fd05-445b-9534-8e7beb5504fc}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="GUI\Objects\Source Files">
+      <UniqueIdentifier>{e75f10ec-4a83-4f51-8b00-0c9dc4522066}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="main.cpp">
@@ -294,6 +312,12 @@
     <ClCompile Include="Source\LuaScript.cpp">
       <Filter>Renderer\Objects\Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="Source\GUIScene.cpp">
+      <Filter>GUI\Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="Source\GUITask.cpp">
+      <Filter>GUI\Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="Source\ErrorCodes.h">
@@ -635,6 +659,15 @@
     <ClInclude Include="Source\LuaScript.h">
       <Filter>Scripting\Objects\Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Source\GUIScene.h">
+      <Filter>GUI\Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Source\GUITask.h">
+      <Filter>GUI\Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="Source\GUISystem.h">
+      <Filter>GUI\Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="Data\config.ini" />

+ 3 - 0
Praxis3D/Source/Config.h

@@ -27,6 +27,7 @@ namespace Systems
 	#define TYPEID(Code) \
 	Code(Null, = -1) \
 	Code(Graphics,) \
+	Code(GUI,) \
 	Code(Script,) \
 	Code(World,) \
 	Code(NumberOfSystems,) 
@@ -35,6 +36,7 @@ namespace Systems
 	const static std::string SystemNames[NumberOfSystems] =
 	{
 		GetString(Graphics),
+		GetString(GUI),
 		GetString(Script),
 		GetString(World)
 	};
@@ -519,6 +521,7 @@ class Config
 	friend class DebugUIScript;
 	friend class DeferredRenderer;
 	friend class ErrorHandler;
+	friend class LuaScript;
 	friend class RendererFrontend;
 	friend class Window;
 public:

+ 2 - 2
Praxis3D/Source/DebugUIScript.h

@@ -96,7 +96,7 @@ public:
 		if(m_mouseCaptureCommand.isActivated())
 		{
 			// Toggle the mouse capture mode
-			WindowLocator().get().setMouseCapture(!Config::windowVar().mouse_captured);
+			WindowLocator::get().setMouseCapture(!Config::windowVar().mouse_captured);
 
 			// Deactivate the key command so this piece of code is not triggered again if the key wasn't released
 			m_mouseCaptureCommand.deactivate();
@@ -105,7 +105,7 @@ public:
 		if(m_vertSyncCommand.isActivated())
 		{
 			// Toggle the vertical synchronization
-			WindowLocator().get().setVerticalSync(!Config::windowVar().vertical_sync);
+			WindowLocator::get().setVerticalSync(!Config::windowVar().vertical_sync);
 
 			// Deactivate the key command so this piece of code is not triggered again if the key wasn't released
 			m_vertSyncCommand.deactivate();

+ 25 - 0
Praxis3D/Source/GUIScene.cpp

@@ -0,0 +1,25 @@
+#include "GUIScene.h"
+
+GUIScene::GUIScene(SystemBase *p_system, SceneLoader *p_sceneLoader) : SystemScene(p_system, p_sceneLoader)
+{
+	m_GUITask = new GUITask(this);
+}
+
+ErrorCode GUIScene::setup(const PropertySet& p_properties)
+{
+	return ErrorCode();
+}
+
+void GUIScene::update(const float p_deltaTime)
+{
+}
+
+SystemObject* GUIScene::createObject(const PropertySet& p_properties)
+{
+	return nullptr;
+}
+
+ErrorCode GUIScene::destroyObject(SystemObject* p_systemObject)
+{
+	return ErrorCode();
+}

+ 38 - 0
Praxis3D/Source/GUIScene.h

@@ -0,0 +1,38 @@
+#pragma once
+
+#include "System.h"
+#include "GUITask.h"
+
+class GUISystem;
+
+class GUIScene : public SystemScene
+{
+public:
+	GUIScene(SystemBase* p_system, SceneLoader* p_sceneLoader);
+
+	ErrorCode init() { return ErrorCode::Success; }
+
+	ErrorCode setup(const PropertySet& p_properties);
+
+	void update(const float p_deltaTime);
+
+	ErrorCode preload() { return ErrorCode::Success; }
+
+	void loadInBackground() { }
+
+	// Exports all the data of the scene (including all objects within) as a PropertySet (for example, used for saving to map file)
+	PropertySet exportObject() { return PropertySet(); }
+
+	SystemObject* createObject(const PropertySet& p_properties);
+	ErrorCode destroyObject(SystemObject* p_systemObject);
+
+	void changeOccurred(ObservedSubject* p_subject, BitMask p_changeType) { }
+
+	SystemTask* getSystemTask() { return m_GUITask; };
+	Systems::TypeID getSystemType() { return Systems::TypeID::GUI; };
+	BitMask getDesiredSystemChanges() { return Systems::Changes::Generic::CreateObject || Systems::Changes::Generic::DeleteObject; }
+	BitMask getPotentialSystemChanges() { return Systems::Changes::None; }
+
+private:
+	GUITask *m_GUITask;
+};

+ 68 - 0
Praxis3D/Source/GUISystem.h

@@ -0,0 +1,68 @@
+#pragma once
+
+#include "ErrorHandlerLocator.h"
+#include "System.h"
+#include "GUIScene.h"
+
+class GUISystem : public SystemBase
+{
+public:
+	GUISystem()
+	{
+		m_GUIScene = nullptr;
+		m_systemName = GetString(Systems::GUI);
+	}
+	~GUISystem() { }
+
+	ErrorCode init()
+	{
+		ErrorCode returnCode = ErrorCode::Success;
+
+		return returnCode;
+	}
+
+	ErrorCode setup(const PropertySet& p_properties)
+	{
+		ErrorCode returnCode = ErrorCode::Success;
+
+		return returnCode;
+	}
+
+	virtual ErrorCode preload()
+	{
+		ErrorCode returnCode = ErrorCode::Success;
+
+		return returnCode;
+	}
+	void loadInBackground() { }
+
+	Systems::TypeID getSystemType() { return Systems::GUI; }
+
+	SystemScene *createScene(SceneLoader *p_sceneLoader)
+	{
+		if (m_GUIScene == nullptr)
+		{
+			// Create new scene
+			m_GUIScene = new GUIScene(this, p_sceneLoader);
+			ErrorCode sceneError = m_GUIScene->init();
+
+			// Check if it initialized correctly (cannot continue without the scene)
+			if (sceneError != ErrorCode::Success)
+			{
+				ErrHandlerLoc::get().log(sceneError);
+			}
+			else
+			{
+				// Check for errors
+				GLenum glError = glGetError();
+			}
+		}
+
+		return m_GUIScene;
+	}
+
+	SystemScene* getScene() { return m_GUIScene; }
+
+protected:
+	GUIScene* m_GUIScene;
+};

+ 16 - 0
Praxis3D/Source/GUITask.cpp

@@ -0,0 +1,16 @@
+#include "GUIScene.h"
+#include "GUITask.h"
+
+GUITask::GUITask(GUIScene* p_GUIScene) : SystemTask(p_GUIScene), m_GUIScene(p_GUIScene)
+{
+}
+
+GUITask::~GUITask()
+{
+}
+
+void GUITask::update(const float p_deltaTime)
+{
+	m_GUIScene->update(p_deltaTime);
+}
+

+ 22 - 0
Praxis3D/Source/GUITask.h

@@ -0,0 +1,22 @@
+#pragma once
+
+#include "System.h"
+
+class GUIScene;
+
+class GUITask : public SystemTask
+{
+	friend class GUIScene;
+public:
+	GUITask(GUIScene* p_GUIScene);
+	~GUITask();
+
+	Systems::TypeID getSystemType() { return Systems::GUI; }
+
+	void update(const float p_deltaTime);
+
+	bool isPrimaryThreadOnly() { return false; }
+
+private:
+	GUIScene* m_GUIScene;
+};

+ 54 - 1
Praxis3D/Source/LuaScript.h

@@ -14,8 +14,10 @@ namespace LuaDefinitions
 #define LUA_USER_TYPES(Code) \
     Code(MouseInfo,) \
     Code(KeyCommand,) \
+	Code(EngineVariables, ) \
 	Code(GameplayVariables,) \
 	Code(InputVariables,) \
+	Code(WindowVariables,) \
 	Code(SpatialDataManager,) \
 	Code(NumOfTypes, )
 	DECLARE_ENUM(UserTypes, LUA_USER_TYPES)
@@ -124,10 +126,30 @@ private:
 		m_luaState.set_function("getMouseInfo", []() -> const Window::MouseInfo { return WindowLocator::get().getMouseInfo(); });
 		m_luaState.set_function("mouseCaptured", []() -> const bool { return Config::windowVar().mouse_captured; });
 
+		m_luaState.set_function("setFullscreen", [](const bool p_v1) -> const void { WindowLocator::get().setFullscreen(p_v1); });
+		m_luaState.set_function("setMouseCapture", [](const bool p_v1) -> const void { WindowLocator::get().setMouseCapture(p_v1); });
+		m_luaState.set_function("setVerticalSync", [](const bool p_v1) -> const void { WindowLocator::get().setVerticalSync(p_v1); });
+		m_luaState.set_function("setWindowTitle", [](const std::string &p_v1) -> const void { WindowLocator::get().setWindowTitle(p_v1); });
+
+		m_luaState.set_function("setEngineRunning", [](const bool p_v1) -> const void {Config::m_engineVar.running = p_v1; });
+
 		m_luaState.set_function(Config::scriptVar().createObjectFunctionName, &LuaScript::createObjectInLua, this);
 	}
 	void setUsertypes()
 	{
+		m_luaState.new_usertype<Config::EngineVariables>("EngineVariables",
+			"change_ctrl_cml_notify_list_reserv", &Config::EngineVariables::change_ctrl_cml_notify_list_reserv,
+			"change_ctrl_grain_size", &Config::EngineVariables::change_ctrl_grain_size,
+			"change_ctrl_notify_list_reserv", &Config::EngineVariables::change_ctrl_notify_list_reserv,
+			"change_ctrl_oneoff_notify_list_reserv", &Config::EngineVariables::change_ctrl_oneoff_notify_list_reserv,
+			"change_ctrl_subject_list_reserv", &Config::EngineVariables::change_ctrl_subject_list_reserv,
+			"delta_time_divider", &Config::EngineVariables::delta_time_divider,
+			"gl_context_major_version", &Config::EngineVariables::gl_context_major_version,
+			"gl_context_minor_version", &Config::EngineVariables::gl_context_minor_version,
+			"object_directory_init_pool_size", &Config::EngineVariables::object_directory_init_pool_size,
+			"smoothing_tick_samples", &Config::EngineVariables::smoothing_tick_samples,
+			"running", &Config::EngineVariables::running);
+
 		m_luaState.new_usertype<Config::GameplayVariables>("GameplayVariables",
 			"camera_freelook_speed", &Config::GameplayVariables::camera_freelook_speed);
 
@@ -161,12 +183,29 @@ private:
 			"up_key", &Config::InputVariables::up_key,
 			"vsync_key", &Config::InputVariables::vsync_key,
 			"mouse_filter", &Config::InputVariables::mouse_filter,
-			"cromouse_warp_modess", &Config::InputVariables::mouse_warp_mode,
+			"mouse_warp_mode", &Config::InputVariables::mouse_warp_mode,
 			"mouse_jaw", &Config::InputVariables::mouse_jaw,
 			"mouse_pitch", &Config::InputVariables::mouse_pitch,
 			"mouse_pitch_clip", &Config::InputVariables::mouse_pitch_clip,
 			"mouse_sensitivity", &Config::InputVariables::mouse_sensitivity);
 
+		m_luaState.new_usertype<Config::WindowVariables>("WindowVariables",
+			"name", &Config::WindowVariables::name,
+			"default_display", &Config::WindowVariables::default_display,
+			"window_position_x", &Config::WindowVariables::window_position_x,
+			"window_position_y", &Config::WindowVariables::window_position_y,
+			"window_size_fullscreen_x", &Config::WindowVariables::window_size_fullscreen_x,
+			"window_size_fullscreen_y", &Config::WindowVariables::window_size_fullscreen_y,
+			"window_size_windowed_x", &Config::WindowVariables::window_size_windowed_x,
+			"window_size_windowed_y", &Config::WindowVariables::window_size_windowed_y,
+			"fullscreen", &Config::WindowVariables::fullscreen,
+			"fullscreen_borderless", &Config::WindowVariables::fullscreen_borderless,
+			"mouse_captured", &Config::WindowVariables::mouse_captured,
+			"mouse_release_on_lost_focus", &Config::WindowVariables::mouse_release_on_lost_focus,
+			"resizable", &Config::WindowVariables::resizable,
+			"vertical_sync", &Config::WindowVariables::vertical_sync,
+			"window_in_focus", &Config::WindowVariables::window_in_focus);
+
 		m_luaState.new_usertype<glm::vec3>("Vec3",
 			sol::constructors<glm::vec3(), glm::vec3(float), glm::vec3(float, float, float), glm::vec3(glm::vec4)>(),
 			"x", &glm::vec3::x,
@@ -317,6 +356,13 @@ private:
 				m_keyCommands.push_back(keyCommand);
 			}
 				break;
+				
+			case LuaDefinitions::EngineVariables:
+
+				// Set the given variable name in Lua to point to the EngineVariables object
+				m_luaState.set(p_variableName, Config::engineVar());
+
+				break;
 
 			case LuaDefinitions::GameplayVariables:
 
@@ -332,6 +378,13 @@ private:
 
 				break;
 
+			case LuaDefinitions::WindowVariables:
+
+				// Set the given variable name in Lua to point to the WindowVariables object
+				m_luaState.set(p_variableName, Config::windowVar());
+
+				break;
+
 			case LuaDefinitions::SpatialDataManager:
 
 				// Set the given variable name in Lua to point to the Spatial Data Manager object

+ 13 - 0
Praxis3D/Source/PlayState.cpp

@@ -1,5 +1,6 @@
 
 #include "ClockLocator.h"
+#include "GUISystem.h"
 #include "PlayState.h"
 #include "PropertySet.h"
 #include "ScriptSystem.h"
@@ -47,6 +48,18 @@ ErrorCode PlayState::init(TaskManager *p_taskManager)
 		m_systems[Systems::Graphics] = &g_nullSystemBase;
 	}
 
+	//  ___________________________________
+	// |								   |
+	// |	 GUI SYSTEM INITIALIZATION	   |
+	// |___________________________________|
+	// Create GUI system and check if it was successful (if not, assign a null system in it's place)
+	m_systems[Systems::GUI] = new GUISystem();
+	if (m_systems[Systems::GUI]->init() != ErrorCode::Success)
+	{
+		delete m_systems[Systems::GUI];
+		m_systems[Systems::GUI] = &g_nullSystemBase;
+	}
+
 	//  ___________________________________
 	// |								   |
 	// |  SCRIPTING SYSTEM INITIALIZATION  |