Browse Source

working at making a 3D editor

meemknight 2 years ago
parent
commit
53b14e4bbf

+ 9 - 9
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -100,22 +100,22 @@ bool pika::ContainerManager::setRecordingToContainer(pika::containerId_t contain
 
 }
 
-//todo use regions further appart in production
+//todo mabe use regions further appart in production
 void* pika::ContainerManager::allocateContainerMemory(pika::RuntimeContainer &container,
 	pika::ContainerInformation containerInformation, void *memPos)
 {
-	size_t memoryRequired = containerInformation.calculateMemoryRequirements();
+		size_t memoryRequired = containerInformation.calculateMemoryRequirements();
 
-	void * baseMemory = allocateOSMemory(memoryRequired, memPos);
+		void *baseMemory = allocateOSMemory(memoryRequired, memPos);
 
-	if (baseMemory == nullptr) { return 0; }
+		if (baseMemory == nullptr) { return 0; }
 
-	container.totalSize = memoryRequired;
+		container.totalSize = memoryRequired;
 
-	allocateContainerMemoryAtBuffer(container,
-		containerInformation, baseMemory);
+		allocateContainerMemoryAtBuffer(container,
+			containerInformation, baseMemory);
 
-	return baseMemory;
+		return baseMemory;
 }
 
 void pika::ContainerManager::allocateContainerMemoryAtBuffer(pika::RuntimeContainer &container,
@@ -183,7 +183,7 @@ pika::containerId_t pika::ContainerManager::createContainer
 	pika::RuntimeContainer container = {};
 	pika::strlcpy(container.baseContainerName, containerInformation.containerName,
 		sizeof(container.baseContainerName));
-	
+
 	if (!allocateContainerMemory(container, containerInformation, (void*)memoryPos))
 	{
 		logManager.log((std::string("Couldn't allocate memory for constructing container: #") 

+ 66 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.cpp

@@ -0,0 +1,66 @@
+#include "engineGL3DSupport.h"
+
+
+
+void errorCallbackCustom(std::string err, void *userData)
+{
+	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
+
+	data->consoleWrite((err + "\n").c_str());
+}
+
+std::string readEntireFileCustom(const char *fileName, bool &couldNotOpen, void *userData)
+{
+	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
+	couldNotOpen = false;
+
+	size_t size = 0;
+	if (!data->getFileSize(fileName, size))
+	{
+		couldNotOpen = true;
+		return "";
+	}
+
+	std::string buffer;
+	buffer.resize(size + 1);
+
+	if (!data->readEntireFile(fileName, &buffer.at(0), size))
+	{
+		couldNotOpen = true;
+		return "";
+	}
+
+	return buffer;
+}
+
+std::vector<char> readEntireFileBinaryCustom(const char *fileName, bool &couldNotOpen, void *userData)
+{
+	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
+	couldNotOpen = false;
+
+	size_t size = 0;
+	if (!data->getFileSizeBinary(fileName, size))
+	{
+		couldNotOpen = true;
+		return {};
+	}
+
+	std::vector<char> buffer;
+	buffer.resize(size + 1, 0);
+
+	if (!data->readEntireFileBinary(fileName, &buffer.at(0), size))
+	{
+		couldNotOpen = true;
+		return {};
+	}
+
+	return buffer;
+}
+
+bool defaultFileExistsCustom(const char *fileName, void *userData)
+{
+	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
+	size_t s = 0;
+	return data->getFileSizeBinary(fileName, s);
+}
+

+ 10 - 0
Pika/core/pikaSTD/engineLibraresSupport/engineGL3DSupport.h

@@ -0,0 +1,10 @@
+#pragma once
+
+#include <gl3d.h>
+#include <baseContainer.h>
+
+
+void errorCallbackCustom(std::string err, void *userData);
+std::string readEntireFileCustom(const char *fileName, bool &couldNotOpen, void *userData);
+std::vector<char> readEntireFileBinaryCustom(const char *fileName, bool &couldNotOpen, void *userData);
+bool defaultFileExistsCustom(const char *fileName, void *userData);

+ 9 - 2
Pika/core/sharedRuntime/baseContainer.h

@@ -155,6 +155,12 @@ struct ContainerStaticInfo
 	//this is the main heap allocator memory size
 	size_t defaultHeapMemorySize = 0;
 	
+
+	//this will use the global allocator. you won't be able to use input recording or snapshots, and the 
+	//memory leak protection won't be possible.
+	bool useDefaultAllocator = 0;
+
+
 	pika::StaticVector<size_t, MaxAllocatorsCount> bonusAllocators = {};
 
 	//the engine will create a new window for your container and give you the fbo to bind to
@@ -173,8 +179,9 @@ struct ContainerStaticInfo
 			this->defaultHeapMemorySize == other.defaultHeapMemorySize &&
 			this->bonusAllocators == other.bonusAllocators &&
 			this->_internalNotImplemented == other._internalNotImplemented &&
-			this->requestImguiFbo == other.requestImguiFbo;
-			this->requestImguiIds == other.requestImguiIds;
+			this->requestImguiFbo == other.requestImguiFbo &&
+			this->requestImguiIds == other.requestImguiIds &&
+			this->useDefaultAllocator == other.useDefaultAllocator;
 		;
 	}
 

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

@@ -15,6 +15,7 @@ struct ContainerInformation
 		containerStructBaseSize(containerStructBaseSize), containerName(containerName),
 		containerStaticInfo(containerStaticInfo)
 	{
+		useDefaultAllocator = containerStaticInfo.useDefaultAllocator;
 	};
 
 	bool operator==(const ContainerInformation &other)
@@ -24,7 +25,8 @@ struct ContainerInformation
 		return
 			this->containerStructBaseSize == other.containerStructBaseSize &&
 			this->containerName == other.containerName &&
-			this->containerStaticInfo == other.containerStaticInfo;
+			this->containerStaticInfo == other.containerStaticInfo &&
+			this->useDefaultAllocator == other.useDefaultAllocator;
 
 	}
 
@@ -36,9 +38,12 @@ struct ContainerInformation
 	size_t containerStructBaseSize = 0; //static memory
 	std::string containerName = "";
 	ContainerStaticInfo containerStaticInfo = {};
+	bool useDefaultAllocator = 0;
 
 	size_t calculateMemoryRequirements()
 	{
+		if (useDefaultAllocator) { return 0; }
+
 		size_t size = 0;
 
 		size += containerStructBaseSize;

+ 0 - 1
Pika/gameplay/containers.h

@@ -19,7 +19,6 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "pluggins/threeDEditor.h"
 
 
-
 #define PIKA_ALL_CONTAINERS() \
 	PIKA_DECLARE_CONTAINER(Gameplay) \
 	PIKA_DECLARE_CONTAINER(ImmageViewer) \

+ 1 - 62
Pika/gameplay/containers/threedtest.h

@@ -7,68 +7,7 @@
 #include <shortcutApi/shortcutApi.h>
 #include <pikaSizes.h>
 #include <imgui_spinner.h>
-
-void inline errorCallbackCustom(std::string err, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo*)userData;
-
-	data->consoleWrite((err+"\n").c_str());
-}
-
-std::string inline readEntireFileCustom(const char *fileName, bool &couldNotOpen, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	couldNotOpen = false;
-
-	size_t size = 0;
-	if (!data->getFileSize(fileName, size))
-	{
-		couldNotOpen = true;
-		return "";
-	}
-
-	std::string buffer;
-	buffer.resize(size+1);
-
-	if (!data->readEntireFile(fileName, &buffer.at(0), size))
-	{
-		couldNotOpen = true;
-		return "";
-	}
-
-	return buffer;
-}
-
-std::vector<char> inline readEntireFileBinaryCustom(const char *fileName, bool &couldNotOpen, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	couldNotOpen = false;
-
-	size_t size = 0;
-	if (!data->getFileSizeBinary(fileName, size))
-	{
-		couldNotOpen = true;
-		return {};
-	}
-
-	std::vector<char> buffer;
-	buffer.resize(size + 1, 0);
-
-	if (!data->readEntireFileBinary(fileName, &buffer.at(0), size))
-	{
-		couldNotOpen = true;
-		return {};
-	}
-
-	return buffer;
-}
-
-bool inline defaultFileExistsCustom(const char *fileName, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	size_t s=0;
-	return data->getFileSizeBinary(fileName, s);
-}
+#include <engineLibraresSupport/engineGL3DSupport.h>
 
 
 struct ThreeDTest: public Container

+ 64 - 138
Pika/pluggins/pluggins/threeDEditor.h

@@ -7,70 +7,8 @@
 #include <shortcutApi/shortcutApi.h>
 #include <pikaSizes.h>
 #include <imgui_spinner.h>
+#include <engineLibraresSupport/engineGL3DSupport.h>
 
-/*
-void inline errorCallbackCustom(std::string err, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-
-	data->consoleWrite((err + "\n").c_str());
-}
-
-std::string inline readEntireFileCustom(const char *fileName, bool &couldNotOpen, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	couldNotOpen = false;
-
-	size_t size = 0;
-	if (!data->getFileSize(fileName, size))
-	{
-		couldNotOpen = true;
-		return "";
-	}
-
-	std::string buffer;
-	buffer.resize(size + 1);
-
-	if (!data->readEntireFile(fileName, &buffer.at(0), size))
-	{
-		couldNotOpen = true;
-		return "";
-	}
-
-	return buffer;
-}
-
-std::vector<char> inline readEntireFileBinaryCustom(const char *fileName, bool &couldNotOpen, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	couldNotOpen = false;
-
-	size_t size = 0;
-	if (!data->getFileSizeBinary(fileName, size))
-	{
-		couldNotOpen = true;
-		return {};
-	}
-
-	std::vector<char> buffer;
-	buffer.resize(size + 1, 0);
-
-	if (!data->readEntireFileBinary(fileName, &buffer.at(0), size))
-	{
-		couldNotOpen = true;
-		return {};
-	}
-
-	return buffer;
-}
-
-bool inline defaultFileExistsCustom(const char *fileName, void *userData)
-{
-	RequestedContainerInfo *data = (RequestedContainerInfo *)userData;
-	size_t s = 0;
-	return data->getFileSizeBinary(fileName, s);
-}
-*/
 
 struct ThreeDEditor: public Container
 {
@@ -81,7 +19,7 @@ struct ThreeDEditor: public Container
 	static ContainerStaticInfo containerInfo()
 	{
 		ContainerStaticInfo info = {};
-		info.defaultHeapMemorySize = pika::MB(20);
+		info.defaultHeapMemorySize = pika::MB(1000); //todo option to use global allocator
 
 		info.requestImguiFbo = true;
 		info.requestImguiIds = 1;
@@ -97,37 +35,37 @@ struct ThreeDEditor: public Container
 	{
 
 
-		//renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
-		//renderer.fileOpener.userData = &requestedInfo;
-		//renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
-		//renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
-		//renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
-		//
-		//renderer.init(1, 1, PIKA_RESOURCES_PATH "BRDFintegrationMap.png", requestedInfo.requestedFBO.fbo);
-		//
-		////renderer.skyBox = renderer.atmosfericScattering({0.2,1,0.3}, {0.9,0.1,0.1}, {0.4, 0.4, 0.8}, 0.8f); //todo a documentation
-		////todo api for skybox stuff
-		////renderer.skyBox.color = {0.2,0.3,0.9};
-		//
-		//const char *names[6] =
-		//{PIKA_RESOURCES_PATH "/skyBoxes/ocean/right.jpg",
-		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/left.jpg",
-		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/top.jpg",
-		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/bottom.jpg",
-		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/front.jpg",
-		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/back.jpg"};
-		//
-		//renderer.skyBox = renderer.loadSkyBox(names);
-		////renderer.skyBox.color = {0.2,0.3,0.8};
-		//
+		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
+		renderer.fileOpener.userData = &requestedInfo;
+		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
+		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
+		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
+		
+		renderer.init(1, 1, PIKA_RESOURCES_PATH "BRDFintegrationMap.png", requestedInfo.requestedFBO.fbo);
+		
+		//renderer.skyBox = renderer.atmosfericScattering({0.2,1,0.3}, {0.9,0.1,0.1}, {0.4, 0.4, 0.8}, 0.8f); //todo a documentation
+		//todo api for skybox stuff
+		//renderer.skyBox.color = {0.2,0.3,0.9};
+		
+		const char *names[6] =
+		{PIKA_RESOURCES_PATH "/skyBoxes/ocean/right.jpg",
+			PIKA_RESOURCES_PATH "/skyBoxes/ocean/left.jpg",
+			PIKA_RESOURCES_PATH "/skyBoxes/ocean/top.jpg",
+			PIKA_RESOURCES_PATH "/skyBoxes/ocean/bottom.jpg",
+			PIKA_RESOURCES_PATH "/skyBoxes/ocean/front.jpg",
+			PIKA_RESOURCES_PATH "/skyBoxes/ocean/back.jpg"};
+		
+		renderer.skyBox = renderer.loadSkyBox(names);
+		//renderer.skyBox.color = {0.2,0.3,0.8};
+		
 		//helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "helmet/helmet.obj");
-		////helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "/knight/uploads_files_1950170_Solus_the_knight.gltf", 1.f);
-		//
-		//gl3d::Transform t;
-		//t.position = {0, 0, -3};
+		helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "/knight/uploads_files_1950170_Solus_the_knight.gltf");
+		
+		gl3d::Transform t;
+		t.position = {0, 0, -4};
 		//t.rotation = {1.5, 0 , 0};
-		//
-		//helmetEntity = renderer.createEntity(helmetModel, t);
+		
+		helmetEntity = renderer.createEntity(helmetModel, t);
 
 	}
 
@@ -137,56 +75,44 @@ struct ThreeDEditor: public Container
 	{
 
 
-		//renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
-		//renderer.fileOpener.userData = &requestedInfo;
-		//renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
-		//renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
-		//renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
-		//
-		//
-		//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-		//glEnable(GL_DEPTH_TEST);
-		//
-		//renderer.updateWindowMetrics(windowState.w, windowState.h);
-		//renderer.camera.aspectRatio = (float)windowState.w / windowState.h; //todo do this in update
-		//
-		//{
-		//	static glm::dvec2 lastMousePos = {};
-		//	if (input.rMouse.held())
-		//	{
-		//		glm::dvec2 currentMousePos = {input.mouseX, input.mouseY};
-		//
-		//		float speed = 0.8f;
-		//
-		//		glm::vec2 delta = lastMousePos - currentMousePos;
-		//		delta *= speed * input.deltaTime;
-		//
-		//		renderer.camera.rotateCamera(delta);
-		//
-		//		lastMousePos = currentMousePos;
-		//	}
-		//	else
-		//	{
-		//		lastMousePos = {input.mouseX, input.mouseY};
-		//	}
-		//}
-		//
-		//
-		//renderer.render(input.deltaTime);
-		//glDisable(GL_DEPTH_TEST);
-
-
-		if (!ImGui::Begin("Test window"))
+		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
+		renderer.fileOpener.userData = &requestedInfo;
+		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
+		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
+		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
+		
+		
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		glEnable(GL_DEPTH_TEST);
+		
+		renderer.updateWindowMetrics(windowState.w, windowState.h);
+		renderer.camera.aspectRatio = (float)windowState.w / windowState.h; //todo do this in update
+		
 		{
-			ImGui::End();
-			return;
+			static glm::dvec2 lastMousePos = {};
+			if (input.rMouse.held())
+			{
+				glm::dvec2 currentMousePos = {input.mouseX, input.mouseY};
+		
+				float speed = 0.8f;
+		
+				glm::vec2 delta = lastMousePos - currentMousePos;
+				delta *= speed * input.deltaTime;
+		
+				renderer.camera.rotateCamera(delta);
+		
+				lastMousePos = currentMousePos;
+			}
+			else
+			{
+				lastMousePos = {input.mouseX, input.mouseY};
+			}
 		}
 		
 		
-		ImGui::Text("test");
-		ImGui::Button("close");
+		renderer.render(input.deltaTime);
+		glDisable(GL_DEPTH_TEST);
 
-		ImGui::End();
 
 	}
 

+ 5 - 5
Pika/resources/logs.txt

@@ -1,5 +1,5 @@
-#2023-01-24 13:16:48: Created container: Gameplay
-#2023-01-24 13:16:51: Created container: ThreeDEditor
-#2023-01-24 13:17:36: Reloaded dll
-#2023-01-24 13:18:08: Destroyed continer: ThreeDEditor #2
-#2023-01-24 13:18:10: Destroyed continer: Gameplay #1
+#2023-01-24 13:28:33: Created container: Gameplay
+#2023-01-24 13:28:51: Reloaded dll
+#2023-01-24 13:29:12: Created container: ThreeDEditor
+#2023-01-24 13:29:19: Destroyed continer: Gameplay #1
+#2023-01-24 13:29:19: Destroyed continer: ThreeDEditor #2