Browse Source

last frame has focus

meemknight 2 years ago
parent
commit
655dc95536

+ 36 - 0
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -182,6 +182,9 @@ pika::containerId_t pika::ContainerManager::createContainer
 	pika::strlcpy(container.baseContainerName, containerInformation.containerName,
 		sizeof(container.baseContainerName));
 
+	container.andInputWithWindowHasFocus = containerInformation.containerStaticInfo.andInputWithWindowHasFocus;
+	container.andInputWithWindowHasFocusLastFrame = containerInformation.containerStaticInfo.andInputWithWindowHasFocusLastFrame;
+
 	if (!allocateContainerMemory(container, containerInformation, (void*)memoryPos))
 	{
 		logManager.log((std::string("Couldn't allocate memory for constructing container: #") 
@@ -394,6 +397,34 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 
 			auto callUpdate = [&](pika::WindowState &windowState) -> bool
 			{
+				windowInput.lastFrameHasFocus = c.second.lastFrameFocus;
+				c.second.lastFrameFocus = windowInput.hasFocus;
+
+				if (c.second.andInputWithWindowHasFocus || c.second.andInputWithWindowHasFocusLastFrame)
+				{
+					bool andValue = 1;
+					if (c.second.andInputWithWindowHasFocus && !windowInput.hasFocus)
+					{
+						andValue = 0;
+					}
+					if (c.second.andInputWithWindowHasFocusLastFrame && !windowInput.lastFrameHasFocus)
+					{
+						andValue = 0;
+					}
+
+					if (!andValue) 
+					{
+						memset(windowInput.typedInput, 0, sizeof(windowInput.typedInput));
+						windowInput.lMouse = {};
+						windowInput.rMouse = {};
+						for (int i = 0; i < Button::BUTTONS_COUNT; i++)
+						{
+							windowInput.buttons[i] = {};
+						}
+					}
+
+				}
+
 
 				c.second.requestedContainerInfo.mainAllocator = &c.second.allocator; //reset this
 				c.second.requestedContainerInfo.bonusAllocators = &c.second.bonusAllocators;
@@ -465,6 +496,10 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 						windowInput.hasFocus = ImGui::IsWindowFocused()
 							&& ImGui::GetPlatformIO().Platform_GetWindowFocus(viewPort) && !io.AppFocusLost;
 					}
+					else
+					{
+						windowInput.hasFocus = 0;
+					}
 
 					//windowInput.hasFocus = windowInput.hasFocus && !io.AppFocusLost;
 				}
@@ -522,6 +557,7 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 				rez = callUpdate(window.windowState);
 			}
 
+
 			if (!rez) 
 			{
 				logs.log(("Terminated container because it returned 0: " + std::string(c.second.baseContainerName)

+ 6 - 0
Pika/core/pikaRuntime/runtimeContainer/runtimeContainer.h

@@ -39,6 +39,12 @@ struct RuntimeContainer
 	float frameTimer = 0;
 	float currentMs = 0;
 
+	bool lastFrameFocus = 0;
+
+	//passed from container static info
+	bool andInputWithWindowHasFocus = 0;
+	bool andInputWithWindowHasFocusLastFrame = 0;
+
 	struct FLAGS
 	{
 		enum

+ 2 - 9
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.cpp

@@ -448,7 +448,7 @@ void pika::gl3d::fpsInput(::gl3d::Renderer3D &renderer, pika::Input &input, floa
 	renderer.camera.moveFPS(dir);
 
 	{
-		if (input.hasFocus)
+		if (input.hasFocus && input.lastFrameHasFocus)
 		{
 			requestedInfo.setFpsCursor();
 
@@ -460,19 +460,12 @@ void pika::gl3d::fpsInput(::gl3d::Renderer3D &renderer, pika::Input &input, floa
 			delta *= speed * input.deltaTime;
 
 			renderer.camera.rotateCamera(delta);
-
-			glm::ivec2 windowMid = windowSize / 2;
-			//requestedInfo.setMousePositionRelevantToWindow(windowMid.x, windowMid.y);
 			lastMousePos = currentMousePos;
-			//lastMousePos = {windowMid.x, windowMid.y};
-
-			//requestedInfo.consoleWrite((std::to_string(currentMousePos.y) + " " + std::to_string(windowMid.y) + '\n').c_str());
 		}
 		else
 		{
-			lastMousePos = {input.mouseX, input.mouseY};
 			requestedInfo.setNormalCursor();
-
+			lastMousePos = {input.mouseX, input.mouseY};
 		}
 
 	}

+ 7 - 1
Pika/core/sharedRuntime/baseContainer.h

@@ -267,6 +267,10 @@ struct ContainerStaticInfo
 
 	unsigned int requestImguiIds = 0;
 
+	bool andInputWithWindowHasFocus = 1;
+	bool andInputWithWindowHasFocusLastFrame = 1;
+
+
 	bool _internalNotImplemented = 0;
 
 	bool operator==(const ContainerStaticInfo &other)
@@ -279,7 +283,9 @@ struct ContainerStaticInfo
 			this->_internalNotImplemented == other._internalNotImplemented &&
 			this->requestImguiFbo == other.requestImguiFbo &&
 			this->requestImguiIds == other.requestImguiIds &&
-			this->useDefaultAllocator == other.useDefaultAllocator;
+			this->useDefaultAllocator == other.useDefaultAllocator &&
+			this->andInputWithWindowHasFocus == other.andInputWithWindowHasFocus &&
+			this->andInputWithWindowHasFocusLastFrame == other.andInputWithWindowHasFocusLastFrame;
 		;
 	}
 

+ 1 - 1
Pika/core/sharedRuntime/containerInformation.h

@@ -38,7 +38,7 @@ struct ContainerInformation
 	size_t containerStructBaseSize = 0; //static memory
 	std::string containerName = "";
 	ContainerStaticInfo containerStaticInfo = {};
-	bool useDefaultAllocator = 0;
+	bool useDefaultAllocator = 0; //move into container static info when implementing
 
 	size_t calculateMemoryRequirements()
 	{

+ 3 - 1
Pika/core/sharedRuntime/windowSystemm/input.h

@@ -68,10 +68,12 @@ namespace pika
 		
 		char typedInput[20] = {};
 
+		float deltaTime = 0;
+
 		//focus is here because it makes sense for the replay
 		bool hasFocus = 0;
+		bool lastFrameHasFocus = 0;
 
-		float deltaTime = 0;
 	};
 
 	

+ 2 - 2
Pika/gameplay/containers/minecraftDungeons/mcDungeonsEditor.h

@@ -474,7 +474,7 @@ struct McDungeonsEditor: public Container
 			glm::vec3 block = {};
 			glm::vec3 prev = {};
 
-			if (input.lMouse.released() && input.hasFocus) //todo and this by the engine
+			if (input.lMouse.pressed() && input.hasFocus && input.lastFrameHasFocus) //todo and this by the engine
 			{
 				auto cameraRayPos = renderer.camera.position;
 				cameraRayPos.y += 1.5;
@@ -486,7 +486,7 @@ struct McDungeonsEditor: public Container
 					shouldRecreate = 1;
 				}
 			}else 
-			if (input.rMouse.released() && input.hasFocus && currentBlock != 0)
+			if (input.rMouse.pressed() && input.hasFocus && input.lastFrameHasFocus && currentBlock != 0)
 			{
 				auto cameraRayPos = renderer.camera.position;
 				cameraRayPos.y += 1.5;

+ 4 - 4
Pika/resources/logs.txt

@@ -1,4 +1,4 @@
-#2023-02-25 19:21:43: Created container: Gameplay
-#2023-02-25 19:22:14: Created container: McDungeonsEditor
-#2023-02-25 19:22:19: Destroyed continer: Gameplay #1
-#2023-02-25 19:22:19: Destroyed continer: McDungeonsEditor #2
+#2023-02-26 12:37:37: Created container: Gameplay
+#2023-02-26 12:37:46: Created container: MarioEditor
+#2023-02-26 12:37:54: Destroyed continer: Gameplay #1
+#2023-02-26 12:38:34: Destroyed continer: MarioEditor #2