Browse Source

made a better api to declare containers

meemknight 2 years ago
parent
commit
77ff642500

+ 5 - 5
Pika/gameplay/containers.cpp

@@ -2,7 +2,7 @@
 #include <logs/assert.h>
 #include <logs/assert.h>
 
 
 
 
-#define PIKA_MAKE_CONTAINER_GET(x)	if (std::strcmp(name, #x ) == 0)						\
+#define PIKA_DECLARE_CONTAINER(x)	if (std::strcmp(name, #x ) == 0)						\
 {																							\
 {																							\
 if (sizeof(x) != memoryArena->containerStructMemory.size) { return nullptr; }				\
 if (sizeof(x) != memoryArena->containerStructMemory.size) { return nullptr; }				\
 	return new(memoryArena->containerStructMemory.block)  x ();								\
 	return new(memoryArena->containerStructMemory.block)  x ();								\
@@ -14,12 +14,12 @@ else
 Container *getContainer(const char *name, pika::memory::MemoryArena *memoryArena)
 Container *getContainer(const char *name, pika::memory::MemoryArena *memoryArena)
 {
 {
 
 
-	PIKA_MAKE_CONTAINER_GET(Gameplay)
-	PIKA_MAKE_CONTAINER_GET(ImmageViewer)
-	PIKA_MAKE_CONTAINER_GET(ThreeDTest)
+	PIKA_ALL_CONTAINERS()
 	{
 	{
 		//"invalid container name: "
 		//"invalid container name: "
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
-}
+}
+
+#undef PIKA_DECLARE_CONTAINER

+ 10 - 0
Pika/gameplay/containers.h

@@ -16,3 +16,13 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "containers/pikaGameplay.h"
 #include "containers/pikaGameplay.h"
 #include "containers/threedtest.h"
 #include "containers/threedtest.h"
 #include "pluggins/immageviewer.h"
 #include "pluggins/immageviewer.h"
+#include "pluggins/threeDEditor.h"
+
+
+
+#define PIKA_ALL_CONTAINERS() \
+	PIKA_DECLARE_CONTAINER(Gameplay) \
+	PIKA_DECLARE_CONTAINER(ImmageViewer) \
+	PIKA_DECLARE_CONTAINER(ThreeDTest) \
+	PIKA_DECLARE_CONTAINER(ThreeDEditor) 
+

+ 5 - 4
Pika/gameplay/dll/dllMain.cpp

@@ -15,16 +15,17 @@
 
 
 //todo use a global static array that can be accessed from other cpps and the macro will create an instance of a struct 
 //todo use a global static array that can be accessed from other cpps and the macro will create an instance of a struct 
 //that will push that container
 //that will push that container
-#define PIKA_MAKE_CONTAINER_INFO(x) pika::ContainerInformation(sizeof(x), #x, x::containerInfo())
+#define PIKA_DECLARE_CONTAINER(x) info.push_back( pika::ContainerInformation(sizeof(x), #x, x::containerInfo()) );
 
 
 PIKA_API void getContainersInfo(std::vector<pika::ContainerInformation> &info)
 PIKA_API void getContainersInfo(std::vector<pika::ContainerInformation> &info)
 {
 {
 	info.clear();
 	info.clear();
-	info.push_back(PIKA_MAKE_CONTAINER_INFO(Gameplay));
-	info.push_back(PIKA_MAKE_CONTAINER_INFO(ImmageViewer));
-	info.push_back(PIKA_MAKE_CONTAINER_INFO(ThreeDTest));
+	PIKA_ALL_CONTAINERS()
+
 }
 }
 
 
+#undef PIKA_DECLARE_CONTAINER
+
 //this should not allocate memory
 //this should not allocate memory
 PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name)
 PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name)
 {
 {

+ 197 - 0
Pika/pluggins/pluggins/threeDEditor.h

@@ -0,0 +1,197 @@
+#pragma once
+
+#include <gl2d/gl2d.h>
+#include <gl3d.h>
+#include <imgui.h>
+#include <baseContainer.h>
+#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);
+}
+*/
+
+struct ThreeDEditor: public Container
+{
+
+
+
+	//todo user can request imgui ids; shortcut manager context; allocators
+	static ContainerStaticInfo containerInfo()
+	{
+		ContainerStaticInfo info = {};
+		info.defaultHeapMemorySize = pika::MB(20);
+
+		info.requestImguiFbo = true;
+		info.requestImguiIds = 1;
+
+		return info;
+	}
+
+	gl3d::Renderer3D renderer;
+	gl3d::Model helmetModel;
+	gl3d::Entity helmetEntity;
+
+	void create(RequestedContainerInfo &requestedInfo)
+	{
+
+
+		//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};
+		//t.rotation = {1.5, 0 , 0};
+		//
+		//helmetEntity = renderer.createEntity(helmetModel, t);
+
+	}
+
+	//todo return value
+	void update(pika::Input input, pika::WindowState windowState,
+		RequestedContainerInfo &requestedInfo)
+	{
+
+
+		//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"))
+		{
+			ImGui::End();
+			return;
+		}
+		
+		
+		ImGui::Text("test");
+		ImGui::Button("close");
+
+		ImGui::End();
+
+	}
+
+};
+
+//todo flag to clear screen from engine
+//todo error popup
+//todo error popup disable in release

+ 5 - 4
Pika/resources/logs.txt

@@ -1,4 +1,5 @@
-#2023-01-23 22:23:38: Created container: Gameplay
-#2023-01-23 22:23:51: Created container: ThreeDTest
-#2023-01-23 22:24:59: Destroyed continer: Gameplay #1
-#2023-01-23 22:24:59: Destroyed continer: ThreeDTest #2
+#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