Browse Source

added extension specifier support

meemknight 2 years ago
parent
commit
d0e8b06a53

+ 1 - 0
Pika/core/coreConfig/pikaConfigInternal.h

@@ -54,4 +54,5 @@
 #define PIKA_SHOULD_REMOVE_EDITOR 0
 #endif
 
+//#define PIKA_SHOULD_REMOVE_IMGUI 0
 //#define PIKA_SHOULD_REMOVE_EDITOR 0

+ 18 - 8
Pika/core/pikaEditor/assetManagerWindow/assetManagerWindow.cpp

@@ -6,18 +6,18 @@
 #include <Windows.h>
 #endif
 
-#if !PIKA_SHOULD_REMOVE_IMGUI
+#if !PIKA_SHOULD_REMOVE_EDITOR
 
 namespace pika
 {
 
-
 	void AssetManagerWindow::init(pika::pikaImgui::ImGuiIdsManager &idManager)
 	{
 		imguiId = idManager.getImguiIds();
 	}
 	
-	void AssetManagerWindow::update(bool &open)
+	void AssetManagerWindow::update(bool &open, ContainerManager &containerManager, LoadedDll &currentDll,
+		pika::LogManager &logManager, pika::pikaImgui::ImGuiIdsManager &imguiIDsManager, ConsoleWindow *consoleWindow)
 	{
 		ImGui::PushID(imguiId);
 
@@ -57,7 +57,7 @@ namespace pika
 		if (ImGui::Button("Open resources folder"))
 		{
 		#if PIKA_WINDOWS
-			ShellExecute(NULL, "open", PIKA_RESOURCES_PATH, NULL, NULL, SW_RESTORE);
+			ShellExecuteA(NULL, "open", PIKA_RESOURCES_PATH, NULL, NULL, SW_RESTORE);
 		#endif
 		}
 
@@ -132,12 +132,12 @@ namespace pika
 					#if PIKA_WINDOWS
 						if (p.is_directory())
 						{
-							ShellExecute(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
+							ShellExecuteA(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
 						}
 						else
 						{
 							auto path = p.path().parent_path().string();
-							ShellExecute(NULL, "open", path.c_str(), NULL, NULL, SW_RESTORE);
+							ShellExecuteA(NULL, "open", path.c_str(), NULL, NULL, SW_RESTORE);
 						}
 					#endif
 						ImGui::CloseCurrentPopup();
@@ -162,13 +162,23 @@ namespace pika
 						if (ImGui::Button("open file"))
 						{
 						#if PIKA_WINDOWS
-							ShellExecute(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
+							ShellExecuteA(NULL, "open", p.path().string().c_str(), NULL, NULL, SW_RESTORE);
 						#endif
 							ImGui::CloseCurrentPopup();
 						}
 					}
-
 					
+					{
+						auto it = currentDll.containerExtensionsSupport.find(p.path().filename().extension().string());
+						if (it!= currentDll.containerExtensionsSupport.end())
+						{
+							//todo name						
+							if (ImGui::Button("Open In engine"))
+							{
+								containerManager.createContainer(it->second, currentDll, logManager, imguiIDsManager, consoleWindow);
+							}
+						}
+					}
 
 					ImGui::EndPopup();
 				}

+ 4 - 2
Pika/core/pikaEditor/assetManagerWindow/assetManagerWindow.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include "pikaConfig.h"
-#if !PIKA_SHOULD_REMOVE_IMGUI
+#if !PIKA_SHOULD_REMOVE_EDITOR
 
 #include <logs/log.h>
 #include <IconsForkAwesome.h>
@@ -9,6 +9,7 @@
 #include <pikaImgui/pikaImgui.h>
 #include <filesystem>
 #include <string>
+#include <containerManager/containerManager.h>
 
 namespace pika
 {
@@ -19,7 +20,8 @@ namespace pika
 
 		void init(pika::pikaImgui::ImGuiIdsManager &idManager);
 
-		void update(bool &open);
+		void update(bool &open, ContainerManager &containerManager, LoadedDll &currentDll,
+			pika::LogManager &logManager, pika::pikaImgui::ImGuiIdsManager &imguiIDsManager, ConsoleWindow *consoleWindow);
 
 		static constexpr char *ICON = ICON_FK_FILES_O;
 		static constexpr char *NAME = "Asset manager";

+ 2 - 1
Pika/core/pikaEditor/editor/editor.cpp

@@ -252,7 +252,8 @@ void pika::Editor::update(const pika::Input &input,
 
 	if (windowFlags.assetManagerWindow)
 	{
-		assetManagerWindow.update(windowFlags.assetManagerWindow);
+		assetManagerWindow.update(windowFlags.assetManagerWindow, containerManager, loadedDll, 
+			logs, imguiIDsManager, &consoleWindow);
 	}
 
 #pragma endregion

+ 2 - 1
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -580,8 +580,9 @@ void pika::ContainerManager::reloadDll(pika::LoadedDll &loadedDll, pika::PikaWin
 
 	}
 
-
 	loadedDll.gameplayReload_(window.context);
+	
+
 
 	logs.log("Reloaded dll");
 

+ 1 - 2
Pika/core/pikaRuntime/containerManager/containerManager.h

@@ -20,9 +20,8 @@ namespace pika
 	struct ContainerManager
 	{
 
-
 		std::unordered_map<containerId_t, pika::RuntimeContainer> runningContainers;
-
+		
 		containerId_t createContainer(
 			pika::ContainerInformation containerInformation,
 			pika::LoadedDll &loadedDll, pika::LogManager &logManager, 

+ 20 - 1
Pika/core/pikaRuntime/dllLoader/dllLoader.cpp

@@ -10,7 +10,6 @@ static std::filesystem::path dllPath = std::filesystem::current_path();
 	#ifdef PIKA_WINDOWS
 	
 	#define NOMINMAX
-	#define WIN32_LEAN_AND_MEAN
 	#include <Windows.h>
 
 	static FILETIME getLastWriteFile(const char *name)
@@ -39,6 +38,22 @@ static std::filesystem::path dllPath = std::filesystem::current_path();
 #endif
 
 
+void pika::LoadedDll::reloadContainerExtensionsSupport()
+{
+#pragma region reload extension support
+	{
+		containerExtensionsSupport.clear();
+		for (auto &c : containerInfo)
+		{
+			for (auto &e : c.containerStaticInfo.extensionsSuported)
+			{
+				containerExtensionsSupport[e.to_string()] = c.containerName;
+			}
+		}
+	}
+#pragma endregion
+}
+
 bool pika::LoadedDll::constructRuntimeContainer(RuntimeContainer &c, const char *name)
 {
 	PIKA_DEVELOPMENT_ONLY_ASSERT(constructContainer_ != nullptr, "dll not loaded");
@@ -155,6 +170,8 @@ bool pika::LoadedDll::loadDll(int id, pika::LogManager &logs)
 	getContainerInfoAndCheck(logs);
 	this->id = id;
 
+	reloadContainerExtensionsSupport();
+
 	return	true;
 }
 
@@ -263,6 +280,8 @@ bool pika::LoadedDll::loadDll(int id, pika::LogManager &logs)
 	getContainerInfoAndCheck(logs);
 	this->id = id;
 
+	reloadContainerExtensionsSupport();
+
 	return	true;
 }
 

+ 6 - 1
Pika/core/pikaRuntime/dllLoader/dllLoader.h

@@ -10,6 +10,8 @@
 #include <runtimeContainer/runtimeContainer.h>
 #include <logs/log.h>
 #include <sstream>
+#include <unordered_map>
+#include <string>
 
 #define GAMEPLAYSTART(x) void x(pika::PikaContext &pikaContext)
 typedef GAMEPLAYSTART(gameplayStart_t);
@@ -48,7 +50,6 @@ typedef DISSABLEALLOCATORS(dissableAllocators_t)
 
 #ifdef PIKA_WINDOWS
 #define NOMINMAX
-#define WIN32_LEAN_AND_MEAN
 #include <Windows.h>
 #endif
 
@@ -86,8 +87,12 @@ struct LoadedDll
 
 	bool shouldReloadDll();
 
+	void reloadContainerExtensionsSupport();
+
 	std::vector<pika::ContainerInformation> containerInfo;
 
+	std::unordered_map<std::string, std::string> containerExtensionsSupport;
+
 	bool constructRuntimeContainer(pika::RuntimeContainer &c, const char *name);
 
 	void bindAllocatorDllRealm(pika::memory::FreeListAllocator *allocator);

+ 0 - 1
Pika/core/pikaRuntime/pikaMain.cpp

@@ -50,7 +50,6 @@ BOOL WINAPI customConsoleHandlerRoutine(
 
 #endif
 
-
 int main()
 {
 

+ 33 - 0
Pika/core/pikaSTD/staticString.h

@@ -0,0 +1,33 @@
+//////////////////////////////////////////
+//staticString.h
+//Luta Vlad(c) 2022
+//https://github.com/meemknight/PikaEngine
+//////////////////////////////////////////
+
+#include <staticVector.h>
+#include <string>
+
+namespace pika
+{
+
+	template<size_t N>
+	struct StaticString: public StaticVector<char, N>
+	{
+		StaticString() {};
+
+		StaticString(const char *c)
+		{
+			for (; *c != 0; c++)
+			{
+				push_back(*c);
+			}
+		}
+
+		std::string to_string()
+		{
+			return std::string(beg_, beg_ + size_);
+		}
+	};
+
+
+}

+ 8 - 2
Pika/core/pikaSTD/staticVector.h

@@ -25,9 +25,16 @@ namespace pika
 
 		static constexpr unsigned int MAX_SIZE = N;
 
-
 		StaticVector() {};
 
+		StaticVector(std::initializer_list<T> &&l)
+		{
+			for (auto &i : l)
+			{
+				push_back(i);
+			}
+		};
+
 		StaticVector(StaticVector &&other)
 		{
 			for (size_t i = 0; i < other.size_; i++)
@@ -156,7 +163,6 @@ namespace pika
 			size_--;
 		}
 
-	private:
 
 		size_t size_ = 0;
 		T beg_[N];

+ 6 - 0
Pika/core/sharedRuntime/baseContainer.h

@@ -9,6 +9,8 @@
 #include <pikaConsoleManager/pikaConsoleWindow.h>
 #include <globalAllocator/globalAllocator.h>
 #include <fstream>
+#include <staticString.h>
+
 
 #define READENTIREFILE(x) bool x(const char* name, void* buffer, size_t size)
 typedef READENTIREFILE(readEntireFile_t);
@@ -38,6 +40,7 @@ struct RequestedContainerInfo
 
 	pika::ConsoleWindow *consoleWindow = nullptr;
 
+
 	//todo add logs here
 
 	//returns true if succeded (can return false if console is disabeled)
@@ -163,6 +166,9 @@ struct ContainerStaticInfo
 
 	pika::StaticVector<size_t, MaxAllocatorsCount> bonusAllocators = {};
 
+	//add file extensions here so that the engine knows that your container can open them.
+	pika::StaticVector<pika::StaticString<16>, 16> extensionsSuported = {};
+
 	//the engine will create a new window for your container and give you the fbo to bind to
 	//in release that fbo will just be the default framebuffer
 	bool requestImguiFbo = 0;

BIN
Pika/engineResources/engineSaves/windowPos1.bin


BIN
Pika/engineResources/engineSaves/windowPos2.bin


+ 4 - 0
Pika/pluggins/pluggins/immageViewer.h

@@ -21,6 +21,10 @@ struct ImmageViewer: public Container
 		ContainerStaticInfo info = {};
 		info.defaultHeapMemorySize = pika::MB(20);
 
+		//todo to lower
+		info.extensionsSuported = {".png", ".bmp", ".psd", ".tga", ".gif", ".hdr", ".pic", ".ppm", ".pgm", ".jpg", ".jpeg"};
+
+
 		//todo imgui ids
 
 		return info;

+ 2 - 5
Pika/resources/logs.txt

@@ -1,5 +1,2 @@
-#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
+#2023-01-25 17:45:26: Created container: Gameplay
+#2023-01-25 17:45:37: Destroyed continer: Gameplay #1