浏览代码

added allocator for container and push notification

vlod 3 年之前
父节点
当前提交
20ef957a78
共有 26 个文件被更改,包括 587 次插入121 次删除
  1. 6 1
      Pika/core/pikaEditor/editor/editor.cpp
  2. 2 0
      Pika/core/pikaEditor/editor/editor.h
  3. 5 0
      Pika/core/pikaRuntime/containerManager/README.md
  4. 93 0
      Pika/core/pikaRuntime/containerManager/containerManager.cpp
  5. 42 0
      Pika/core/pikaRuntime/containerManager/containerManager.h
  6. 19 2
      Pika/core/pikaRuntime/dllLoader/dllLoader.cpp
  7. 16 5
      Pika/core/pikaRuntime/dllLoader/dllLoader.h
  8. 33 11
      Pika/core/pikaRuntime/pikaMain.cpp
  9. 16 2
      Pika/core/pikaRuntime/runtimeContainer/runtimeContainer.h
  10. 22 21
      Pika/core/pikaSTD/pikaAllocator/freeListAllocator.cpp
  11. 9 5
      Pika/core/pikaSTD/pikaAllocator/freeListAllocator.h
  12. 6 2
      Pika/core/sharedRuntime/baseContainer.h
  13. 10 3
      Pika/core/sharedRuntime/containerInformation.h
  14. 68 0
      Pika/core/sharedRuntime/globalAllocator/globalAllocator.cpp
  15. 13 0
      Pika/core/sharedRuntime/globalAllocator/globalAllocator.h
  16. 1 1
      Pika/core/sharedRuntime/memoryArena/memoryArena.cpp
  17. 0 0
      Pika/core/sharedRuntime/memoryArena/memoryArena.h
  18. 91 0
      Pika/core/sharedRuntime/pushNotification/pushNotification.cpp
  19. 36 0
      Pika/core/sharedRuntime/pushNotification/pushNotification.h
  20. 52 45
      Pika/core/sharedRuntime/shortcutApi/shortcutApi.cpp
  21. 3 2
      Pika/core/sharedRuntime/shortcutApi/shortcutApi.h
  22. 1 1
      Pika/gameplay/containers.cpp
  23. 1 1
      Pika/gameplay/containers.h
  24. 14 5
      Pika/gameplay/containers/pikaGameplay.h
  25. 21 10
      Pika/gameplay/dll/dllMain.cpp
  26. 7 4
      Pika/gameplay/dll/dllMain.h

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

@@ -16,9 +16,9 @@ void pika::Editor::init(pika::ShortcutManager &shortcutManager)
 	shortcutManager.registerShortcut(EDIT_SHORTCUTS, "", &windowFlags.editShortcutsWindow);
 
 
-
 	logWindow.init();
 	editShortcutsWindow.init();
+	pushNotificationManager.init();
 }
 
 
@@ -136,5 +136,10 @@ void pika::Editor::update(const pika::Input &input,
 
 #pragma endregion
 
+#pragma region push notification
+	static bool open = true;
+	pushNotificationManager.update(open);
+#pragma endregion
+
 
 }

+ 2 - 0
Pika/core/pikaEditor/editor/editor.h

@@ -5,6 +5,7 @@
 #include <windowSystemm/input.h>
 #include <shortcutApi/shortcutApi.h>
 #include <editShortcuts/editShortcuts.h>
+#include <pushNotification/pushNotification.h>
 
 namespace pika
 {
@@ -30,6 +31,7 @@ namespace pika
 
 		pika::LogWindow logWindow;
 		pika::EditShortcutsWindow editShortcutsWindow;
+		pika::PushNotificationManager pushNotificationManager;
 	};
 
 

+ 5 - 0
Pika/core/pikaRuntime/containerManager/README.md

@@ -0,0 +1,5 @@
+# containerManager
+
+
+This will manage the containers. It will hold their memory and stuff.
+Some systems have special requirements like allocators should stay fixed in memory.

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

@@ -0,0 +1,93 @@
+#include "containerManager.h"
+#include "containerManager.h"
+#include "containerManager.h"
+#include <globalAllocator/globalAllocator.h>
+
+bool pika::ContainerManager::createContainer
+(std::string name, pika::ContainerInformation containerInformation, pika::DllLoader &dllLoader)
+{
+
+	if (runningContainers.find(name) != runningContainers.end())
+	{
+		//todo log error
+		return false;
+	}
+
+
+	pika::RuntimeContainer container;
+	container.arena.allocateStaticMemory(containerInformation); //this just allocates the memory
+
+	container.allocator.init(malloc(100000), 100000); //todo 
+
+	dllLoader.bindAllocatorDllRealm(&container.allocator);
+	 //this calls the constructors (from the dll realm)
+	if (!dllLoader.constructRuntimeContainer(container, containerInformation.containerName.c_str()))
+	{
+		dllLoader.resetAllocatorDllRealm();
+
+
+		//todo log error
+
+		container.arena.dealocateStaticMemory();
+
+		free(container.allocator.originalBaseMemory);
+
+		return false;
+	}
+	dllLoader.resetAllocatorDllRealm();
+
+	
+	dllLoader.bindAllocatorDllRealm(&container.allocator);
+	container.pointer->create(); //this calls create() (from the dll realm)
+	dllLoader.resetAllocatorDllRealm();//sets the global allocator back to standard (used for runtime realm)
+
+
+	runningContainers[name] = container;
+
+	return true;
+}
+
+void pika::ContainerManager::init()
+{
+}
+
+void pika::ContainerManager::update(pika::DllLoader &dllLoader, pika::Input input, float deltaTime, pika::WindowState windowState)
+{
+	for (auto &c : runningContainers)
+	{
+		dllLoader.bindAllocatorDllRealm(&c.second.allocator);
+		c.second.pointer->update(input, deltaTime, windowState);
+		dllLoader.resetAllocatorDllRealm();
+
+	}
+
+}
+
+bool pika::ContainerManager::destroyContainer(std::string name, pika::DllLoader &dllLoader)
+{
+	auto c = runningContainers.find(name);
+	if (c == runningContainers.end())
+	{
+		//todo log error
+		return false;
+	}
+
+	dllLoader.bindAllocatorDllRealm(&c->second.allocator);
+	dllLoader.destructContainer_(&(c->second.pointer), &c->second.arena);
+	dllLoader.resetAllocatorDllRealm();
+
+	c->second.arena.dealocateStaticMemory();
+
+	free(c->second.allocator.originalBaseMemory);
+
+	return true;
+}
+
+void pika::ContainerManager::destroyAllContainers(pika::DllLoader &dllLoader)
+{
+	for (auto &c : runningContainers)
+	{
+		destroyContainer(c.first, dllLoader);
+
+	}
+}

+ 42 - 0
Pika/core/pikaRuntime/containerManager/containerManager.h

@@ -0,0 +1,42 @@
+#pragma once
+#include <logs/log.h>
+#include <runtimeContainer/runtimeContainer.h>
+
+#include <unordered_map>
+#include <string>
+
+#include <dllLoader/dllLoader.h>
+
+#include <windowSystemm/input.h>
+#include <windowSystemm/window.h>
+
+namespace pika
+{
+
+	
+	struct ContainerManager
+	{
+
+		std::unordered_map<std::string, pika::RuntimeContainer> runningContainers;
+
+		bool createContainer(
+			std::string name, pika::ContainerInformation containerInformation,
+			pika::DllLoader &dllLoader);
+
+		void init();
+
+		void update(
+			pika::DllLoader &dllLoader,
+			pika::Input input,
+			float deltaTime,
+			pika::WindowState windowState);
+
+		bool destroyContainer(std::string name, pika::DllLoader &dllLoader);
+
+		void destroyAllContainers(pika::DllLoader &dllLoader);
+	};
+
+
+
+
+}

+ 19 - 2
Pika/core/pikaRuntime/dllLoader/dllLoader.cpp

@@ -51,12 +51,17 @@
 		getContainersInfo_ = (getContainersInfo_t *)GetProcAddress(dllHand, "getContainersInfo");
 		constructContainer_ = (constructContainer_t *)GetProcAddress(dllHand, "constructContainer");
 		destructContainer_ = (destructContainer_t *)GetProcAddress(dllHand, "destructContainer");
+		bindAllocator_ = (bindAllocator_t *)GetProcAddress(dllHand, "bindAllocator");;
+		resetAllocator_ = (resetAllocator_t *)GetProcAddress(dllHand, "resetAllocator");;
+		
 
 		if (!gameplayStart_) { return false; }
 		if (!gameplayReload_) { return false; }
 		if (!getContainersInfo_) { return false; }
 		if (!constructContainer_) { return false; }
 		if (!destructContainer_) { return false; }
+		if (!bindAllocator_) { return false; }
+		if (!resetAllocator_) { return false; }
 
 		return	true;
 	}
@@ -113,6 +118,8 @@
 		getContainersInfo_ = getContainersInfo;
 		constructContainer_ = constructContainer;
 		destructContainer_ = destructContainer;
+		bindAllocator_ = bindAllocator;
+		resetAllocator_ = resetAllocator;
 
 		return	true;
 	}
@@ -129,9 +136,19 @@
 
 #endif
 
-void pika::DllLoader::constructRuntimeContainer(RuntimeContainer &c, const char *name)
+bool pika::DllLoader::constructRuntimeContainer(RuntimeContainer &c, const char *name)
+{
+	return constructContainer_(&c.pointer, &c.arena, name);
+}
+
+void pika::DllLoader::bindAllocatorDllRealm(pika::memory::FreeListAllocator *allocator)
+{
+	bindAllocator_(allocator);
+}
+
+void pika::DllLoader::resetAllocatorDllRealm()
 {
-	constructContainer_(&c.pointer, &c.arena, name);
+	resetAllocator_();
 }
 
 	

+ 16 - 5
Pika/core/pikaRuntime/dllLoader/dllLoader.h

@@ -6,7 +6,7 @@
 #include <containerInformation.h>
 #include <vector>
 #include <baseContainer.h>
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
 #include <runtimeContainer/runtimeContainer.h>
 
 #define GAMEPLAYSTART(x) void x(pika::PikaContext pikaContext)
@@ -17,19 +17,26 @@ typedef GAMEPLAYSTART(gameplayStart_t);
 typedef GAMEPLAYRELOAD(gameplayReload_t);
 #undef GAMEPLAYRELOAD
 
-#define GETCONTAINERSINFO(x) void x(std::vector<ContainerInformation> &info)
+#define GETCONTAINERSINFO(x) void x(std::vector<pika::ContainerInformation> &info)
 typedef GETCONTAINERSINFO(getContainersInfo_t);
 #undef GETCONTAINERSINFO
 
-#define CONSTRUCTCONTAINER(x) void x(Container **c, pika::memory::MemoryArena *arena, const char *name);
+#define CONSTRUCTCONTAINER(x) bool x(Container **c, pika::memory::MemoryArena *arena, const char *name);
 typedef CONSTRUCTCONTAINER(constructContainer_t);
 #undef CONSTRUCTCONTAINER
 
-
 #define DESTRUCTCONTAINER(x) void x(Container **c, pika::memory::MemoryArena *arena);
 typedef DESTRUCTCONTAINER(destructContainer_t);
 #undef DESTRUCTCONTAINER
 
+#define BINDALLOCATOR(x) void x(pika::memory::FreeListAllocator *arena);
+typedef BINDALLOCATOR(bindAllocator_t);
+#undef BINDALLOCATOR
+
+#define RESETALLOCATOR(x) void x();
+typedef RESETALLOCATOR(resetAllocator_t)
+#undef RESETALLOCATOR
+
 //todo remove windows include 
 #define NOMINMAX
 #define WIN32_LEAN_AND_MEAN
@@ -46,13 +53,17 @@ struct DllLoader
 	getContainersInfo_t *getContainersInfo_ = {};
 	constructContainer_t *constructContainer_ = {};
 	destructContainer_t *destructContainer_ = {};
+	bindAllocator_t *bindAllocator_ = {};
+	resetAllocator_t *resetAllocator_ = {};
 
 	std::filesystem::path p = {};
 	FILETIME filetime = {};
 	HMODULE dllHand = {};
 
 	bool loadDll(std::filesystem::path path);
-	void constructRuntimeContainer(RuntimeContainer &c, const char *name);
+	bool constructRuntimeContainer(pika::RuntimeContainer &c, const char *name);
+	void bindAllocatorDllRealm(pika::memory::FreeListAllocator *allocator);
+	void resetAllocatorDllRealm();
 
 	void unloadDll();
 

+ 33 - 11
Pika/core/pikaRuntime/pikaMain.cpp

@@ -10,7 +10,7 @@
 #include "dllLoader/dllLoader.h"
 #include "pikaImgui/pikaImgui.h"
 
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
 #include <runtimeContainer/runtimeContainer.h>
 
 #include <logs/log.h>
@@ -18,11 +18,20 @@
 
 #include <editor/editor.h>
 #include <shortcutApi/shortcutApi.h>
+#include <globalAllocator/globalAllocator.h>
 
+#include <containerManager/containerManager.h>
+
+extern int n;
 
 int main()
 {
 
+#pragma region init global variables stuff
+	pika::initShortcutApi();
+#pragma endregion
+
+
 #pragma region log
 	pika::LogManager logs;
 	logs.init("logs.txt");
@@ -51,11 +60,21 @@ int main()
 #pragma region init dll reaml
 	dllLoader.gameplayStart_(window.context);
 
-	std::vector<ContainerInformation> loadedContainers;
+	std::vector<pika::ContainerInformation> loadedContainers;
+	loadedContainers.reserve(100);
 	//todo validate stuff
 	dllLoader.getContainersInfo_(loadedContainers);
 #pragma endregion
 
+#pragma region container manager
+
+	pika::ContainerManager containerManager;
+
+	containerManager.init();
+
+#pragma endregion
+
+
 #pragma region shortcuts
 	pika::ShortcutManager shortcutManager;
 #pragma endregion
@@ -65,15 +84,13 @@ int main()
 	editor.init(shortcutManager);
 #pragma endregion
 
-
-
+	
 	logs.log("test");
 
-	RuntimeContainer container;
-	container.arena.allocateStaticMemory(loadedContainers[0]); //this just allocates the memory
 
-	dllLoader.constructRuntimeContainer(container, "Gameplay"); //this calls the constructors
-	container.pointer->create();	//this calls create()
+	containerManager.createContainer("Main level",
+		loadedContainers[0], dllLoader);
+
 
 	while (!window.shouldClose())
 	{
@@ -100,9 +117,8 @@ int main()
 
 	#pragma endregion
 
-	
+		containerManager.update(dllLoader, window.input, window.deltaTime, window.windowState);
 
-		container.pointer->update(window.input, window.deltaTime, window.windowState);
 
 	#pragma region end imgui frame
 		pika::imguiEndFrame(window.context);
@@ -111,9 +127,15 @@ int main()
 
 		window.update();
 		shortcutManager.update(window.input);
-	}
 
+		if (window.input.buttons[pika::Button::Q].released())
+		{
+			editor.pushNotificationManager.pushNotification("hello");
+		}
+
+	}
 
+	containerManager.destroyAllContainers(dllLoader);
 
 	return 0;
 }

+ 16 - 2
Pika/core/pikaRuntime/runtimeContainer/runtimeContainer.h

@@ -2,13 +2,27 @@
 #include <pikaConfig.h>
 #include <string>
 #include <baseContainer.h>
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
+#include <pikaAllocator/freeListAllocator.h>
+
+namespace pika
+{
+
 
 struct RuntimeContainer
 {
 	std::string baseContainerName = {};
 	//std::string name = {};
+
+	//this is the pointer to the container virtual class
 	Container *pointer = {};
 
+	//this is the container memory arena. here we have all the static data of the container
 	pika::memory::MemoryArena arena = {};
-};
+
+	//this is the allocator of the arena.
+	pika::memory::FreeListAllocator allocator = {};
+};
+
+
+}

+ 22 - 21
Pika/core/pikaSTD/pikaAllocator/freeListAllocator.cpp

@@ -41,6 +41,7 @@ namespace memory
 
 	void FreeListAllocator::init(void *baseMemory, size_t memorySize)
 		{
+			originalBaseMemory = baseMemory;
 			end = (void *)((size_t)baseMemory + memorySize);
 
 			static_assert(sizeof(FreeBlock) == sizeof(AllocatedBlock), "");
@@ -414,27 +415,27 @@ namespace memory
 
 		}
 
-	void *FreeListAllocator::threadSafeAllocate(size_t size)
-		{
-			mu.lock();
-
-			auto a = this->allocate(size);
-
-			mu.unlock();
-
-			return a;
-		}
-
-	void FreeListAllocator::threadSafeFree(void *mem)
-		{
-			if (mem == nullptr) { return; }
-
-			mu.lock();
-
-			this->free(mem);
-
-			mu.unlock();
-		}
+	//void *FreeListAllocator::threadSafeAllocate(size_t size)
+	//	{
+	//		mu.lock();
+	//
+	//		auto a = this->allocate(size);
+	//
+	//		mu.unlock();
+	//
+	//		return a;
+	//	}
+	//
+	//void FreeListAllocator::threadSafeFree(void *mem)
+	//	{
+	//		if (mem == nullptr) { return; }
+	//
+	//		mu.lock();
+	//
+	//		this->free(mem);
+	//
+	//		mu.unlock();
+	//	}
 
 	void FreeListAllocator::calculateMemoryMetrics(size_t &availableMemory, size_t &biggestBlock, int &freeBlocks)
 		{

+ 9 - 5
Pika/core/pikaSTD/pikaAllocator/freeListAllocator.h

@@ -30,7 +30,11 @@ namespace memory
 			void* semaphore;
 		
 			~FreeListAllocatorMutex();
-		
+			
+			FreeListAllocatorMutex(FreeListAllocatorMutex &other) = delete;
+			FreeListAllocatorMutex(FreeListAllocatorMutex &&other) = delete;
+			FreeListAllocatorMutex &operator=(const FreeListAllocatorMutex &other) = delete;
+
 		};
 	
 	#elif defined(PIKA_LINUX)
@@ -44,6 +48,7 @@ namespace memory
 	struct FreeListAllocator
 	{
 		char* baseMemory = 0;
+		void* originalBaseMemory = 0;
 	
 		FreeListAllocator() = default;
 		FreeListAllocator(void* baseMemory, size_t memorySize)
@@ -57,9 +62,8 @@ namespace memory
 	
 		void free(void* mem);
 	
-		void* threadSafeAllocate(size_t size);
-	
-		void threadSafeFree(void* mem);
+		//void* threadSafeAllocate(size_t size);
+		//void threadSafeFree(void* mem);
 	
 		//available memory is the free memory
 		//biggest block is how large is the biggest free memory block
@@ -76,7 +80,7 @@ namespace memory
 	
 		void* end = 0;
 	
-		FreeListAllocatorMutex mu;
+		//FreeListAllocatorMutex mu;
 	
 		size_t getEnd()
 		{

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

@@ -1,12 +1,16 @@
 #pragma once
 #include <windowSystemm/window.h>
 
-
 struct Container
 {
 
 	virtual void create() = 0;
 
-	virtual void update(pika::Input input, float deltaTime, pika::WindowState windowState) = 0;
+	virtual void update(
+		pika::Input input, 
+		float deltaTime, 
+		pika::WindowState windowState) = 0;
+
+	virtual ~Container() {};
 
 };

+ 10 - 3
Pika/core/sharedRuntime/containerInformation.h

@@ -1,14 +1,21 @@
 #pragma once
 #include <string>
 
+namespace pika
+{
+
 struct ContainerInformation
 {
 	ContainerInformation() {};
 	ContainerInformation(
-	size_t containerStructBaseSize,
-	const char *containerName):containerStructBaseSize(containerStructBaseSize), containerName(containerName) {};
+		size_t containerStructBaseSize,
+		const char *containerName):containerStructBaseSize(containerStructBaseSize), containerName(containerName)
+	{
+	};
 
 	size_t containerStructBaseSize = 0;
 	std::string containerName = "";
 
-};
+};
+
+}

+ 68 - 0
Pika/core/sharedRuntime/globalAllocator/globalAllocator.cpp

@@ -0,0 +1,68 @@
+#include "globalAllocator.h"
+#include <malloc.h>
+#include <pikaAllocator/freeListAllocator.h>
+
+
+void *DefaultAllocator(size_t size)
+{
+	return malloc(size);
+}
+void DefaultFree(void *ptr)
+{
+	free(ptr);
+}
+
+pika::memory::FreeListAllocator *currentCustomAllocator = {};
+void *CustomAllocator(size_t size)
+{
+	return currentCustomAllocator->allocate(size);
+}
+void CustomFree(void *ptr)
+{
+	currentCustomAllocator->free(ptr);
+}
+
+void* (*GlobalAllocateFunction)(size_t) = DefaultAllocator;
+void  (*GlobalFree)(void *) = DefaultFree;
+
+namespace pika
+{
+namespace memory
+{
+	void setGlobalAllocatorToStandard()
+	{
+		GlobalAllocateFunction = DefaultAllocator;
+		GlobalFree = DefaultFree;
+	}
+
+	void setGlobalAllocator(pika::memory::FreeListAllocator *allocator)
+	{
+		currentCustomAllocator = allocator;
+		GlobalAllocateFunction = CustomAllocator;
+		GlobalFree = CustomFree;
+	}
+}
+}
+
+
+
+void *operator new  (size_t count)
+{
+	return GlobalAllocateFunction(count);
+}
+
+void *operator new[](size_t count)
+{
+	return GlobalAllocateFunction(count);
+}
+
+void operator delete  (void *ptr)
+{
+
+	GlobalFree(ptr);
+}
+
+void operator delete[](void *ptr)
+{
+	GlobalFree(ptr);
+}

+ 13 - 0
Pika/core/sharedRuntime/globalAllocator/globalAllocator.h

@@ -0,0 +1,13 @@
+#pragma once
+
+#include <pikaAllocator/freeListAllocator.h>
+
+namespace pika
+{
+namespace memory
+{
+	void setGlobalAllocatorToStandard();
+	
+	void setGlobalAllocator(pika::memory::FreeListAllocator *allocator);
+}
+}

+ 1 - 1
Pika/core/pikaSTD/pikaAllocator/memoryArena.cpp → Pika/core/sharedRuntime/memoryArena/memoryArena.cpp

@@ -1,4 +1,4 @@
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
 #include <malloc.h>
 
 

+ 0 - 0
Pika/core/pikaSTD/pikaAllocator/memoryArena.h → Pika/core/sharedRuntime/memoryArena/memoryArena.h


+ 91 - 0
Pika/core/sharedRuntime/pushNotification/pushNotification.cpp

@@ -0,0 +1,91 @@
+#include "pushNotification.h"
+#include <imgui.h>
+#include <iostream>
+
+
+void pika::PushNotificationManager::init()
+{
+}
+
+void pika::PushNotificationManager::update(bool &open)
+{
+
+	if (notificationQue.empty())
+	{
+		return;
+	}
+
+	static int corner = 0;
+	ImGuiIO &io = ImGui::GetIO();
+	ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking
+		| ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav
+		| ImGuiWindowFlags_AlwaysAutoResize;
+	
+	//set popup pos
+	{
+		const float PADX = 10.0f;
+		const float PADY = 20.0f;
+		const ImGuiViewport *viewport = ImGui::GetMainViewport();
+		ImVec2 work_pos = viewport->WorkPos;
+		ImVec2 work_size = viewport->WorkSize;
+		ImVec2 window_pos, window_pos_pivot;
+		window_pos.x = (corner & 1) ? (work_pos.x + work_size.x - PADX) : (work_pos.x + PADX);
+		window_pos.y = (corner & 2) ? (work_pos.y + work_size.y - PADY) : (work_pos.y + PADY);
+		window_pos_pivot.x = (corner & 1) ? 1.0f : 0.0f;
+		window_pos_pivot.y = (corner & 2) ? 1.0f : 0.0f;
+		ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot);
+		ImGui::SetNextWindowViewport(viewport->ID);
+		window_flags |= ImGuiWindowFlags_NoMove;
+	}
+	
+	ImGui::SetNextWindowBgAlpha(0.30f); // Transparent background
+	if (ImGui::Begin("Example: Simple overlay", &open, window_flags))
+	{
+
+		for (auto i = 0; i < notificationQue.size(); i++)
+		{
+			if (i!=0)
+			{
+				ImGui::Separator();
+			}
+			
+			//ImGui::PushID(i);
+			ImGui::Text(notificationQue[i].content.c_str(), i);
+			//ImGui::PopID();
+		}
+
+		//ImGui::Text("adfgh");
+		//ImGui::Separator();
+		//ImGui::Text("adfgh");
+		//ImGui::Separator();
+		//ImGui::Text("adfgh");
+
+
+
+		if (ImGui::BeginPopupContextWindow())
+		{
+			if (ImGui::MenuItem("Top-left", NULL, corner == 0)) corner = 0;
+			if (ImGui::MenuItem("Top-right", NULL, corner == 1)) corner = 1;
+			if (ImGui::MenuItem("Bottom-left", NULL, corner == 2)) corner = 2;
+			if (ImGui::MenuItem("Bottom-right", NULL, corner == 3)) corner = 3;
+			if (ImGui::MenuItem("Close")) open = false;
+			ImGui::EndPopup();
+		}
+	}
+	ImGui::End();
+
+	
+	while (!notificationQue.empty() && notificationQue.front().startTime +
+		std::chrono::seconds(5) < std::chrono::steady_clock::now())
+	{
+		notificationQue.pop_front();
+	}
+
+
+}
+
+void pika::PushNotificationManager::pushNotification(const char *content)
+{
+	notificationQue.push_back
+		(Notification(std::string(content), std::chrono::steady_clock::now()));
+}

+ 36 - 0
Pika/core/sharedRuntime/pushNotification/pushNotification.h

@@ -0,0 +1,36 @@
+#pragma once
+#include <string>
+#include <chrono>
+#include <deque>
+
+namespace pika
+{
+
+	struct Notification
+	{
+		std::string content = "";
+		std::chrono::steady_clock::time_point startTime = {};
+
+		Notification(std::string content, std::chrono::steady_clock::time_point startTime):
+			content(content), startTime(startTime){};
+
+		Notification() {};
+	};
+
+
+	struct PushNotificationManager
+	{
+
+		void init();
+
+		void update(bool &open);
+
+		void pushNotification(const char *content);
+
+		std::deque<Notification> notificationQue;
+	};
+
+
+
+
+}

+ 52 - 45
Pika/core/sharedRuntime/shortcutApi/shortcutApi.cpp

@@ -12,50 +12,56 @@ struct Mapping
 	short imgui = 0;
 };
 
-std::unordered_map<std::string, Mapping> buttonMapping =
-{
-	{"a", {pika::Button::A, ImGuiKey_A}},
-	{ "b", {pika::Button::B, ImGuiKey_B} },
-	{ "c", {pika::Button::C, ImGuiKey_C} },
-	{ "d", {pika::Button::D, ImGuiKey_D} },
-	{ "e", {pika::Button::E, ImGuiKey_E} },
-	{ "f", {pika::Button::F, ImGuiKey_F} },
-	{ "g", {pika::Button::G, ImGuiKey_G} },
-	{ "h", {pika::Button::H, ImGuiKey_H} },
-	{ "i", {pika::Button::I, ImGuiKey_I} },
-	{ "j", {pika::Button::J, ImGuiKey_J} },
-	{ "k", {pika::Button::K, ImGuiKey_K} },
-	{ "l", {pika::Button::L, ImGuiKey_L} },
-	{ "m", {pika::Button::M, ImGuiKey_M} },
-	{ "n", {pika::Button::N, ImGuiKey_N} },
-	{ "o", {pika::Button::O, ImGuiKey_O} },
-	{ "p", {pika::Button::P, ImGuiKey_P} },
-	{ "q", {pika::Button::Q, ImGuiKey_Q} },
-	{ "r", {pika::Button::R, ImGuiKey_R} },
-	{ "s", {pika::Button::S, ImGuiKey_S} },
-	{ "t", {pika::Button::T, ImGuiKey_T} },
-	{ "u", {pika::Button::U, ImGuiKey_U} },
-	{ "v", {pika::Button::V, ImGuiKey_V} },
-	{ "w", {pika::Button::W, ImGuiKey_W} },
-	{ "x", {pika::Button::X, ImGuiKey_X} },
-	{ "y", {pika::Button::Y, ImGuiKey_Y} },
-	{ "z", {pika::Button::Z, ImGuiKey_Z} },
-	{ "0", {pika::Button::NR0, ImGuiKey_0}}, { "1", {pika::Button::NR1, ImGuiKey_1} }, { "2", {pika::Button::NR2, ImGuiKey_2} }, { "3", {pika::Button::NR3, ImGuiKey_3} },
-	{ "4", {pika::Button::NR4, ImGuiKey_0}}, { "5", {pika::Button::NR5, ImGuiKey_5} }, { "6", {pika::Button::NR6, ImGuiKey_6} }, { "7", {pika::Button::NR7, ImGuiKey_7} },
-	{ "8", {pika::Button::NR8, ImGuiKey_8}}, { "9", {pika::Button::NR9, ImGuiKey_9} },
-	{ "space", {pika::Button::Space , ImGuiKey_Space}},
-	{ "enter", {pika::Button::Enter, ImGuiKey_Enter} },
-	{ "escape", {pika::Button::Escape, ImGuiKey_Escape} },
-	{ "up", {pika::Button::Up, ImGuiKey_UpArrow} },
-	{ "down", {pika::Button::Down , ImGuiKey_DownArrow}},
-	{ "left", {pika::Button::Left , ImGuiKey_LeftArrow}},
-	{ "right", {pika::Button::Right , ImGuiKey_RightArrow}},
-	{ "ctrl", {pika::Button::LeftCtrl , ImGuiKey_LeftCtrl}},
-	{ "tab", {pika::Button::Tab , ImGuiKey_Tab}},
-	{ "alt", {pika::Button::LeftAlt , ImGuiKey_LeftAlt}},
+//todo remove global things that allocate memory
+std::unordered_map<std::string, Mapping> buttonMapping;
 
-};
+void pika::initShortcutApi()
+{
+	buttonMapping =
+	{
+		{"a", {pika::Button::A, ImGuiKey_A}},
+		{ "b", {pika::Button::B, ImGuiKey_B} },
+		{ "c", {pika::Button::C, ImGuiKey_C} },
+		{ "d", {pika::Button::D, ImGuiKey_D} },
+		{ "e", {pika::Button::E, ImGuiKey_E} },
+		{ "f", {pika::Button::F, ImGuiKey_F} },
+		{ "g", {pika::Button::G, ImGuiKey_G} },
+		{ "h", {pika::Button::H, ImGuiKey_H} },
+		{ "i", {pika::Button::I, ImGuiKey_I} },
+		{ "j", {pika::Button::J, ImGuiKey_J} },
+		{ "k", {pika::Button::K, ImGuiKey_K} },
+		{ "l", {pika::Button::L, ImGuiKey_L} },
+		{ "m", {pika::Button::M, ImGuiKey_M} },
+		{ "n", {pika::Button::N, ImGuiKey_N} },
+		{ "o", {pika::Button::O, ImGuiKey_O} },
+		{ "p", {pika::Button::P, ImGuiKey_P} },
+		{ "q", {pika::Button::Q, ImGuiKey_Q} },
+		{ "r", {pika::Button::R, ImGuiKey_R} },
+		{ "s", {pika::Button::S, ImGuiKey_S} },
+		{ "t", {pika::Button::T, ImGuiKey_T} },
+		{ "u", {pika::Button::U, ImGuiKey_U} },
+		{ "v", {pika::Button::V, ImGuiKey_V} },
+		{ "w", {pika::Button::W, ImGuiKey_W} },
+		{ "x", {pika::Button::X, ImGuiKey_X} },
+		{ "y", {pika::Button::Y, ImGuiKey_Y} },
+		{ "z", {pika::Button::Z, ImGuiKey_Z} },
+		{ "0", {pika::Button::NR0, ImGuiKey_0}}, { "1", {pika::Button::NR1, ImGuiKey_1} }, { "2", {pika::Button::NR2, ImGuiKey_2} }, { "3", {pika::Button::NR3, ImGuiKey_3} },
+		{ "4", {pika::Button::NR4, ImGuiKey_0}}, { "5", {pika::Button::NR5, ImGuiKey_5} }, { "6", {pika::Button::NR6, ImGuiKey_6} }, { "7", {pika::Button::NR7, ImGuiKey_7} },
+		{ "8", {pika::Button::NR8, ImGuiKey_8}}, { "9", {pika::Button::NR9, ImGuiKey_9} },
+		{ "space", {pika::Button::Space , ImGuiKey_Space}},
+		{ "enter", {pika::Button::Enter, ImGuiKey_Enter} },
+		{ "escape", {pika::Button::Escape, ImGuiKey_Escape} },
+		{ "up", {pika::Button::Up, ImGuiKey_UpArrow} },
+		{ "down", {pika::Button::Down , ImGuiKey_DownArrow}},
+		{ "left", {pika::Button::Left , ImGuiKey_LeftArrow}},
+		{ "right", {pika::Button::Right , ImGuiKey_RightArrow}},
+		{ "ctrl", {pika::Button::LeftCtrl , ImGuiKey_LeftCtrl}},
+		{ "tab", {pika::Button::Tab , ImGuiKey_Tab}},
+		{ "alt", {pika::Button::LeftAlt , ImGuiKey_LeftAlt}},
+
+	};
 
+}
 
 
 
@@ -125,6 +131,7 @@ std::string normalizeShortcutName(const char *shortcut)
 }
 
 
+
 //todo shortcut should rely on glfw backend when imgui is disabeled in production build
 bool shortcut(const pika::Input &input, const char *shortcut)
 {
@@ -201,21 +208,21 @@ void ShortcutManager::update(const pika::Input &input)
 
 }
 
-void ShortcutManager::registerShortcut(const char *name, const char *s, bool *toggle)
+bool ShortcutManager::registerShortcut(const char *name, const char *s, bool *toggle)
 {
 
-
 	if (registeredShortcuts.find(name) != registeredShortcuts.end())
 	{
 		//todo log error
+		return 0;
 	}
 	else
 	{
 		registeredShortcuts[name] 
 			= Shortcut{std::move(normalizeShortcutName(s)), toggle};
+		return 1;
 	}
 
-
 }
 
 const char *ShortcutManager::getShortcut(const char *name)

+ 3 - 2
Pika/core/sharedRuntime/shortcutApi/shortcutApi.h

@@ -17,16 +17,17 @@ namespace pika
 
 		std::unordered_map<std::string, Shortcut> registeredShortcuts;
 
-		void registerShortcut(const char *name, const char *s, bool *toggle);
+		bool registerShortcut(const char *name, const char *s, bool *toggle);
 
 		const char *getShortcut(const char *name);
 	};
 
-
 bool shortcut(const pika::Input &input, const char *shortcut);
 
 bool MenuItem(const pika::Input &input, const char *label, const char *shortcut, bool *p_selected, bool enabled = true);
 
 std::string normalizeShortcutName(const char *shortcut);
 
+void initShortcutApi();
+
 }

+ 1 - 1
Pika/gameplay/containers.cpp

@@ -1,7 +1,7 @@
 #include <containers.h>
 #include <logs/assert.h>
 
-
+//this should not allocate memory
 Container *getContainer(const char *name, pika::memory::MemoryArena *memoryArena)
 {
 

+ 1 - 1
Pika/gameplay/containers.h

@@ -8,7 +8,7 @@
 
 
 #include "containers/pikaGameplay.h"
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
 
 
 Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena);

+ 14 - 5
Pika/gameplay/containers/pikaGameplay.h

@@ -6,18 +6,27 @@
 #include <baseContainer.h>
 #include <shortcutApi/shortcutApi.h>
 
+struct Test
+{
+	int *ptr = 0;
+	Test() { ptr = new int(5); }
+};
+
 struct Gameplay : public Container
 {
 
 	gl2d::Renderer2D renderer;
 
+	float *r =0;
+
+
 	void create()
 	{
 		renderer.create();
-
+		//pika::initShortcutApi();
+		r = new float(0);
 	}
 
-	float r = 0;
 
 	void update(pika::Input input, float deltaTime, pika::WindowState windowState)
 	{
@@ -31,9 +40,9 @@ struct Gameplay : public Container
 		gl2d::enableNecessaryGLFeatures();
 		renderer.updateWindowMetrics(windowState.w, windowState.h);
 
-		r += deltaTime * 3.f;
+		*r += deltaTime * 4.f;
 
-		renderer.renderRectangle({10, 10, 100, 100}, Colors_Magenta, {}, r);
+		renderer.renderRectangle({10, 10, 100, 100}, Colors_Blue, {}, *r);
 
 		//if (input.lMouse.pressed())
 		//{
@@ -58,7 +67,7 @@ struct Gameplay : public Container
 		//ImGui::Begin("window from gameplay");
 		//ImGui::End();
 		
-		//ImGui::ShowDemoWindow();
+		ImGui::ShowDemoWindow();
 	}
 
 };

+ 21 - 10
Pika/gameplay/dll/dllMain.cpp

@@ -10,29 +10,40 @@
 #include "containers/pikaGameplay.h"
 #include <containers.h>
 
-#include <pikaAllocator/memoryArena.h>
+#include <memoryArena/memoryArena.h>
+#include <globalAllocator/globalAllocator.h>
 
+#define PIKA_MAKE_CONTAINER_INFO(x) pika::ContainerInformation(sizeof(x), #x)
 
-#define PIKA_MAKE_CONTAINER_INFO(x) ContainerInformation(sizeof(x), #x)
-
-PIKA_API void getContainersInfo(std::vector<ContainerInformation> &info)
+PIKA_API void getContainersInfo(std::vector<pika::ContainerInformation> &info)
 {
-	info.clear();
+	info.clear();//todo reserve before or use static buffer????
 	info.push_back(PIKA_MAKE_CONTAINER_INFO(Gameplay));
 }
 
-PIKA_API void constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name)
+//this should not allocate memory
+PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name)
 {
 	*c = getContainer(name, arena);
-	PIKA_PERMA_ASSERT(*c, "coultn't create container(probably invalid name)");
-	return;
-
+	return *c != 0;
 
 }
 
 PIKA_API void destructContainer(Container **c, pika::memory::MemoryArena *arena)
 {
-	//placement delete here
+	//no need to call delete.
+	(*c)->~Container();
+
+}
+
+PIKA_API void bindAllocator(pika::memory::FreeListAllocator *arena)
+{
+	pika::memory::setGlobalAllocator(arena);
+}
+
+PIKA_API void resetAllocator()
+{
+	pika::memory::setGlobalAllocatorToStandard();
 }
 
 

+ 7 - 4
Pika/gameplay/dll/dllMain.h

@@ -5,10 +5,13 @@
 #include <containers.h>
 #include <containerInformation.h>
 #include <vector>
-#include <pikaAllocator/memoryArena.h>	
+#include <memoryArena/memoryArena.h>
+#include <pikaAllocator/freeListAllocator.h>
 
 PIKA_API void gameplayStart(pika::PikaContext pikaContext);
 PIKA_API void gameplayReload(pika::PikaContext pikaContext);
-PIKA_API void getContainersInfo(std::vector<ContainerInformation> &info);
-PIKA_API void constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name);
-PIKA_API void destructContainer(Container **c, pika::memory::MemoryArena *arena);
+PIKA_API void getContainersInfo(std::vector<pika::ContainerInformation> &info);
+PIKA_API bool constructContainer(Container **c, pika::memory::MemoryArena *arena, const char *name);
+PIKA_API void destructContainer(Container **c, pika::memory::MemoryArena *arena);
+PIKA_API void bindAllocator(pika::memory::FreeListAllocator *arena);
+PIKA_API void resetAllocator();