Browse Source

implemented open with in engine

meemknight 2 years ago
parent
commit
98f2c605ae
31 changed files with 1084 additions and 568 deletions
  1. 14 11
      Pika/CMakeLists.txt
  2. 0 1
      Pika/core/coreConfig/pikaConfig.h
  3. 31 5
      Pika/core/pikaEditor/assetManagerWindow/assetManagerWindow.cpp
  4. 14 3
      Pika/core/pikaRuntime/containerManager/containerManager.cpp
  5. 6 1
      Pika/core/pikaRuntime/dllLoader/dllLoader.cpp
  6. 1 1
      Pika/core/pikaRuntime/dllLoader/dllLoader.h
  7. 23 7
      Pika/core/pikaRuntime/pikaMain.cpp
  8. 2 2
      Pika/core/pikaSTD/engineLibraresSupport/engineGL2DSupport.cpp
  9. 7 1
      Pika/core/pikaSTD/stringManipulation/stringManipulation.h
  10. 22 9
      Pika/core/sharedRuntime/baseContainer.h
  11. BIN
      Pika/engineResources/engineSaves/options1.bin
  12. BIN
      Pika/engineResources/engineSaves/options2.bin
  13. BIN
      Pika/engineResources/engineSaves/window1.bin
  14. BIN
      Pika/engineResources/engineSaves/window2.bin
  15. BIN
      Pika/engineResources/input.recording
  16. 10 0
      Pika/gameplay/containers.h
  17. 9 1
      Pika/gameplay/containers/mario/mario.cpp
  18. 20 189
      Pika/gameplay/containers/mario/mario.h
  19. 39 0
      Pika/gameplay/containers/mario/marioCommon.cpp
  20. 228 1
      Pika/gameplay/containers/mario/marioCommon.h
  21. 17 31
      Pika/gameplay/containers/mario/marioEditor.h
  22. 2 2
      Pika/gameplay/containers/minecraftDungeons/mcDungeonsEditor.h
  23. 16 19
      Pika/gameplay/containers/minecraftDungeons/mcDungeonsMenu.h
  24. 167 23
      Pika/gameplay/containers/minecraftDungeons/mcDungeonsgameplay.h
  25. 2 4
      Pika/resources/logs.txt
  26. BIN
      Pika/resources/mario/map1.mario
  27. BIN
      Pika/resources/mcDungeons/hearth.png
  28. 52 59
      Pika/thirdparty/gl2d/include/gl2d/gl2d.h
  29. 209 198
      Pika/thirdparty/gl2d/src/gl2d.cpp
  30. 6 0
      Pika/thirdparty/profilerLib/CMakeLists.txt
  31. 187 0
      Pika/thirdparty/profilerLib/include/profilerLib.h

+ 14 - 11
Pika/CMakeLists.txt

@@ -7,19 +7,22 @@ cmake_minimum_required(VERSION 3.16)
 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDebug$<$<CONFIG:Debug>:Debug>")
 set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
 
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) #link time optimization
 
-#declare projects
-project(pikaCore)
-project(pikaGameplay)
-project(pikaProduction)
 
-
-#set glfw to NOT use dynamic runtime and not build unnecessary stuff
+#set glfw to NOT use dynamic runtime and not build unnecessary stuff, we have to do this before we declare projects
 set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
 set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
 set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
 set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
-set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
+set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) #under no circumstance we want this to happen so please cmake DON'T compile my project using shared libs
+
+
+#declare projects
+project(pikaCore)
+project(pikaGameplay)
+project(pikaProduction)
+
 
 #add third party libraries
 add_subdirectory(thirdparty/glfw-3.3.2)
@@ -32,7 +35,7 @@ add_subdirectory(thirdparty/stb_image)
 add_subdirectory(thirdparty/stb_truetype)
 add_subdirectory(thirdparty/imgui-docking)
 add_subdirectory(thirdparty/safeSafe)
-
+add_subdirectory(thirdparty/profilerLib)
 
 #Define some macros for the project sources
 file(GLOB_RECURSE PIKA_SOURCES_CORE_CONFIG			CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/core/coreConfig/*.cpp")
@@ -74,7 +77,7 @@ target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pik
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaRuntime/")
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/pikaSTD/")
 target_include_directories(pikaCore PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
-target_link_libraries(pikaCore PRIVATE glad glfw gl2d gl3d glui glm stb_image stb_truetype imgui safeSave)
+target_link_libraries(pikaCore PRIVATE glad glfw gl2d  gl3d glui glm stb_image stb_truetype imgui safeSave profilerLib)
 #################^^^^^^^^#############################
 
 
@@ -90,7 +93,7 @@ target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core
 target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gameplay/")
 target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
 target_include_directories(pikaGameplay PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pluggins/")
-target_link_libraries(pikaGameplay PRIVATE glad glfw gl2d gl3d glui glm stb_image stb_truetype imgui safeSave)
+target_link_libraries(pikaGameplay PRIVATE glad glfw gl2d gl3d glui glm stb_image stb_truetype imgui safeSave profilerLib)
 #################^^^^^^^^^^^^^^############################
 
 
@@ -112,7 +115,7 @@ target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/ga
 target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/core/sharedRuntime/")
 target_include_directories(pikaProduction PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/pluggins/")
 
-target_link_libraries(pikaProduction PRIVATE glad glfw gl2d gl3d glui glm stb_image stb_truetype imgui safeSave)
+target_link_libraries(pikaProduction PRIVATE glad glfw gl2d gl3d glui glm stb_image stb_truetype imgui safeSave profilerLib)
 
 
 

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

@@ -42,7 +42,6 @@
 
 #define PIKA_REMOVE_OPTIONAL_NOVALUE_CHECKS_IN_PRODUCTION 1
 
-//#define PIKA_REMOVE_EDITOR_IN_PRODUCATION 1 //todo remove this, just keep the console or sthing
 
 #define PIKA_REMOVE_PUSH_NOTIFICATION_IN_PRODUCTION 0
 

+ 31 - 5
Pika/core/pikaEditor/assetManagerWindow/assetManagerWindow.cpp

@@ -92,6 +92,8 @@ namespace pika
 		//returns 1 if should break
 		auto displayItem = [&](const std::filesystem::directory_entry &p) -> bool
 		{
+
+
 			if (ImGui::BeginChild(p.path().filename().string().c_str(), {size, size + 40}, false,
 				ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse))
 			{
@@ -121,8 +123,9 @@ namespace pika
 						auto it = currentDll.containerExtensionsSupport.find(p.path().filename().extension().string());
 						if (it != currentDll.containerExtensionsSupport.end())
 						{
+
 							//todo name						
-							containerManager.createContainer(it->second, currentDll, logManager, imguiIDsManager, consoleWindow, p.path().string());
+							containerManager.createContainer(it->second[0], currentDll, logManager, imguiIDsManager, consoleWindow, p.path().string());
 						}
 					}
 				}
@@ -178,17 +181,40 @@ namespace pika
 							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"))
+							if (it->second.size() == 1)
 							{
-								containerManager.createContainer(it->second, currentDll, logManager, imguiIDsManager, consoleWindow, p.path().string());
+								//todo name						
+								if (ImGui::Button("Open In engine"))
+								{
+									containerManager.createContainer(it->second[0], currentDll, logManager, imguiIDsManager, consoleWindow, p.path().string());
+									ImGui::CloseCurrentPopup();
+								}
 							}
+							else
+							{
+								if (ImGui::BeginMenu("Open with:"))
+								{
+
+									for (auto &i : it->second)
+									{
+										if(ImGui::MenuItem(i.c_str()))
+										{
+											containerManager.createContainer(i, currentDll, logManager, imguiIDsManager, consoleWindow, p.path().string());
+											ImGui::CloseCurrentPopup();
+										}
+									}
+
+									ImGui::EndMenu();
+								}
+
+							}
+
+							
 						}
 					}
 					

+ 14 - 3
Pika/core/pikaRuntime/containerManager/containerManager.cpp

@@ -192,11 +192,14 @@ pika::containerId_t pika::ContainerManager::createContainer
 		return 0;
 	}
 
+	//create imgui fbo just for developement mode
+#ifndef PIKA_PRODUCTION
 	if (containerInformation.containerStaticInfo.requestImguiFbo)
 	{
-		container.requestedContainerInfo.requestedFBO.createFramebuffer(400, 400); //todo resize small or sthing
+		container.requestedContainerInfo.requestedFBO.createFramebuffer(40, 40);
 		container.imguiWindowId = imguiIDsManager.getImguiIds();
 	}
+#endif
 
 	loadedDll.bindAllocatorDllRealm(&container.allocator);
 	
@@ -290,6 +293,8 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 
 	std::vector<CreateContainerInfo> containersToCreate;
 
+	std::vector<containerId_t> containersToDelete;//delete because they returned 0
+
 #pragma region running containers
 	for (auto &c : runningContainers)
 	{
@@ -540,7 +545,7 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 				if (!isOpen)
 				{
 					rez = 1;
-					destroyContainer(c.first, loadedDll, logs);
+					containersToDelete.push_back(c.first);
 				}
 
 			}
@@ -563,7 +568,7 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 			{
 				logs.log(("Terminated container because it returned 0: " + std::string(c.second.baseContainerName)
 					+ " #" + std::to_string(c.first)).c_str());
-				destroyContainer(c.first, loadedDll, logs);
+				containersToDelete.push_back(c.first);
 			}
 
 		}
@@ -573,6 +578,12 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 		}
 
 	}
+
+	for (auto i : containersToDelete)
+	{
+		destroyContainer(i, loadedDll, logs);
+	}
+
 #pragma endregion
 
 

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

@@ -47,7 +47,12 @@ void pika::LoadedDll::reloadContainerExtensionsSupport()
 		{
 			for (auto &e : c.containerStaticInfo.extensionsSuported)
 			{
-				containerExtensionsSupport[e.to_string()] = c.containerName;
+				if (containerExtensionsSupport.find(e.to_string()) == containerExtensionsSupport.end())
+				{
+					containerExtensionsSupport[e.to_string()] = {};
+				}
+
+				containerExtensionsSupport[e.to_string()].push_back(c.containerName);
 			}
 		}
 	}

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

@@ -91,7 +91,7 @@ struct LoadedDll
 
 	std::vector<pika::ContainerInformation> containerInfo;
 
-	std::unordered_map<std::string, std::string> containerExtensionsSupport;
+	std::unordered_map<std::string, std::vector<std::string>> containerExtensionsSupport;
 
 	bool constructRuntimeContainer(pika::RuntimeContainer &c, const char *name);
 

+ 23 - 7
Pika/core/pikaRuntime/pikaMain.cpp

@@ -107,7 +107,6 @@ int main()
 #pragma endregion
 
 
-
 #pragma region init global variables stuff
 	pika::initShortcutApi();
 #pragma endregion
@@ -184,14 +183,23 @@ int main()
 #endif
 #pragma endregion
 
-#if !PIKA_SHOULD_REMOVE_EDITOR
-	auto container = containerManager.createContainer
-	(loadedDll.containerInfo[0], loadedDll, logs, imguiIdsManager, &editor.consoleWindow, std::string());
-#else
-	auto container = containerManager.createContainer
-	(loadedDll.containerInfo[0], loadedDll, logs, imguiIdsManager, nullptr, std::string());
+#if PIKA_PRODUCTION == 1
+	for (auto &c : loadedDll.containerInfo)
+	{
+		if (c.containerStaticInfo.openOnApplicationStartup)
+		{
+		#if !PIKA_SHOULD_REMOVE_EDITOR
+			auto container = containerManager.createContainer
+			(c, loadedDll, logs, imguiIdsManager, &editor.consoleWindow, std::string());
+		#else
+			auto container = containerManager.createContainer
+			(c, loadedDll, logs, imguiIdsManager, nullptr, std::string());
+		#endif
+		}
+	}
 #endif
 
+
 	while (!shouldClose)
 	{
 		if (window.shouldClose())
@@ -250,6 +258,14 @@ int main()
 		containerManager.update(loadedDll, window, logs, imguiIdsManager, nullptr);
 	#endif
 
+		//close engine if no more containers are open
+	#if PIKA_PRODUCTION == 1
+		if (containerManager.runningContainers.empty())
+		{
+			shouldClose = true;
+		}
+	#endif
+
 
 	#pragma endregion
 

+ 2 - 2
Pika/core/pikaSTD/engineLibraresSupport/engineGL2DSupport.cpp

@@ -17,7 +17,7 @@
 
 		delete[] data;
 	}
-	else { return 0; }
+	else { return {}; }
 
 	return t;
 }
@@ -36,7 +36,7 @@
 
 		delete[] data;
 	}
-	else { return 0; }
+	else { return {}; }
 
 	return t;
 }

+ 7 - 1
Pika/core/pikaSTD/stringManipulation/stringManipulation.h

@@ -25,8 +25,14 @@ namespace pika
 
 	size_t strlcpy(char *dst, const std::string &src, size_t size);
 
+	//template<size_t N>
+	//inline size_t strlcpy(char *dst, pika::StaticString<N> &s)
+	//{
+	//	return strlcpy(dst, s.data(), s.size());
+	//}
+
 
 	std::vector<std::string> split(const char *source, char c);
-	
 
+	
 }

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

@@ -148,7 +148,19 @@ struct RequestedContainerInfo
 		return 1;
 	}
 
-	bool readEntireFileBinary(const char *name, std::vector<char> &data)
+	bool appendFileBinary(std::string_view name, void *data, size_t s)
+	{
+		std::ofstream f(name, std::ios::binary | std::ios::out | std::ios::app);
+
+		if (!f.is_open()) { return 0; }
+
+		f.write((char *)data, s);
+
+		f.close();
+		return 1;
+	}
+
+	bool readEntireFileBinary(std::string_view name, std::vector<char> &data)
 	{
 		size_t s = 0;
 		data.clear();
@@ -160,7 +172,7 @@ struct RequestedContainerInfo
 		return readEntireFileBinary(name, data.data(), s);
 	}
 
-	bool readEntireFile(const char *name, std::string &data)
+	bool readEntireFile(std::string_view name, std::string &data)
 	{
 		size_t s = 0;
 		data.clear();
@@ -172,7 +184,7 @@ struct RequestedContainerInfo
 		return readEntireFile(name, data.data(), s);
 	}
 
-	bool readEntireFileBinary(const char *name, void *buffer, size_t size)
+	bool readEntireFileBinary(std::string_view name, void *buffer, size_t size, size_t from = 0)
 	{
 		//PIKA_DEVELOPMENT_ONLY_ASSERT(readEntireFilePointer, "read entire file pointer not assigned");
 		bool success = true;
@@ -187,6 +199,7 @@ struct RequestedContainerInfo
 			}
 			else
 			{
+				f.seekg(from);
 				f.read((char*)buffer, size);
 				f.close();
 			}
@@ -196,7 +209,7 @@ struct RequestedContainerInfo
 		return success;
 	}
 
-	bool readEntireFile(const char *name, void *buffer, size_t size)
+	bool readEntireFile(std::string_view name, void *buffer, size_t size)
 	{
 		//PIKA_DEVELOPMENT_ONLY_ASSERT(readEntireFilePointer, "read entire file pointer not assigned");
 		bool success = true;
@@ -220,7 +233,7 @@ struct RequestedContainerInfo
 		return success;
 	}
 
-	bool getFileSizeBinary(const char *name, size_t &size)
+	bool getFileSizeBinary(std::string_view name, size_t &size)
 	{
 		//PIKA_DEVELOPMENT_ONLY_ASSERT(getFileSizePointer, "get file size pointer not assigned");
 
@@ -246,7 +259,7 @@ struct RequestedContainerInfo
 		return size;
 	}
 
-	bool getFileSize(const char *name, size_t &size)
+	bool getFileSize(std::string_view name, size_t &size)
 	{
 		bool success = true;
 		size = 0;
@@ -295,7 +308,7 @@ struct ContainerStaticInfo
 
 	bool andInputWithWindowHasFocus = 1;
 	bool andInputWithWindowHasFocusLastFrame = 1;
-
+	bool openOnApplicationStartup = 0;
 
 	bool _internalNotImplemented = 0;
 
@@ -311,8 +324,8 @@ struct ContainerStaticInfo
 			this->requestImguiIds == other.requestImguiIds &&
 			this->useDefaultAllocator == other.useDefaultAllocator &&
 			this->andInputWithWindowHasFocus == other.andInputWithWindowHasFocus &&
-			this->andInputWithWindowHasFocusLastFrame == other.andInputWithWindowHasFocusLastFrame;
-		;
+			this->andInputWithWindowHasFocusLastFrame == other.andInputWithWindowHasFocusLastFrame &&
+			this->openOnApplicationStartup == other.openOnApplicationStartup;
 	}
 
 	bool operator!=(const ContainerStaticInfo &other)

BIN
Pika/engineResources/engineSaves/options1.bin


BIN
Pika/engineResources/engineSaves/options2.bin


BIN
Pika/engineResources/engineSaves/window1.bin


BIN
Pika/engineResources/engineSaves/window2.bin


BIN
Pika/engineResources/input.recording


+ 10 - 0
Pika/gameplay/containers.h

@@ -24,6 +24,14 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "containers/minecraftDungeons/mcDungeonsgameplay.h"
 #include "containers/minecraftDungeons/mcDungeonsMenu.h"
 
+#if PIKA_PRODUCTION == 1
+
+#define PIKA_ALL_CONTAINERS() \
+	PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
+	PIKA_DECLARE_CONTAINER(McDungeonsMenu) 
+
+#else
+
 #define PIKA_ALL_CONTAINERS() \
 	PIKA_DECLARE_CONTAINER(Gameplay) \
 	PIKA_DECLARE_CONTAINER(ImmageViewer) \
@@ -35,3 +43,5 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(McDungeonsEditor) \
 	PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
 	PIKA_DECLARE_CONTAINER(McDungeonsMenu) 
+
+#endif

+ 9 - 1
Pika/gameplay/containers/mario/mario.cpp

@@ -1,6 +1,8 @@
 #include "mario.h"
 
 
+namespace mario
+{
 
 
 glm::vec2 Transform::getTopLeftCorner()
@@ -93,7 +95,10 @@ void Player::moveVelocityX(float dir)
 
 void Player::jump(float power)
 {
-	velocity.y = -power;
+	if (grounded)
+	{
+		velocity.y = -power;
+	}
 }
 
 const float terminalVelocity = 60;
@@ -360,3 +365,6 @@ end:
 	if (downTouch) { grounded = true; }
 
 }
+
+
+};

+ 20 - 189
Pika/gameplay/containers/mario/mario.h

@@ -8,69 +8,14 @@
 #include "marioCommon.h"
 #include <fileChanged.h>
 
-struct Transform
-{
-	glm::vec2 position = {};
-	glm::vec2 size = {};
-
-	glm::vec2 getTopLeftCorner();
-	glm::vec2 getCenter();
-	glm::vec2 getBottomLeftCorner();
-	glm::vec2 getBottomCenter();
-
-};
-
-#define PLAYER_SIZE glm::vec2(6.f / 8.f, 1.f)
-
-struct Player
-{
-	Transform position = {glm::vec2(0,0), PLAYER_SIZE};
-
-	glm::vec2 lastPos{};
-
-	glm::vec2 velocity = {};
-
-	bool movingRight = 0;
-	bool grounded = 0;
-
-	void move(glm::vec2 dir);
-
-	void moveVelocityX(float dir);
-
-	void jump(float power);
-
-	void applyGravity(float gravity);
-
-	bool movingThisFrame = false;
-
-
-	//should be called only once per frame last
-	void updateMove();
-
-	//this should be called before collisions 
-	void updatePhisics(float deltaTime);
-
-
-	void resolveConstrains(Block *map);
 
-	void checkCollisionBrute(glm::vec2 &pos, glm::vec2 lastPos,
-		Block *map, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
-
-	glm::vec2 Player::performCollision(Block *map, glm::vec2 pos, glm::vec2 size,
-		glm::vec2 delta, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
-
-	int input = 0;
-};
 
 struct Mario: public Container
 {
 
-	gl2d::Renderer2D renderer;
-	gl2d::Texture tiles;
-	gl2d::Texture marioTexture;
-	gl2d::TextureAtlasPadding atlas;
+	mario::GameplaySimulation simulator;
+	mario::GameplayRenderer renderer;
 	
-	Player player;
 	pika::FileChanged fileChanged;
 
 	//todo user can request imgui ids; shortcut manager context; allocators
@@ -79,77 +24,27 @@ struct Mario: public Container
 		ContainerStaticInfo info = {};
 		info.defaultHeapMemorySize = pika::MB(10);
 
-		info.requestImguiFbo = true; //todo this should not affect the compatibility of input recording
+		info.extensionsSuported = {".mario"};
 
+		info.requestImguiFbo = true; //todo this should not affect the compatibility of input recording
 
 		return info;
 	}
 
-	Block *map;
-	glm::ivec2 mapSize = {100, 100};
-
-	Block &getMapBlockUnsafe(int x, int y)
-	{
-		return map[x + y * mapSize.x];
-	}
-
-	bool loadMap(RequestedContainerInfo &requestedInfo)
-	{
-		size_t s = 0;
-		if (requestedInfo.getFileSizeBinary(PIKA_RESOURCES_PATH "/mario/map1.mario", s))
-		{
-			if (s == mapSize.x * mapSize.y)
-			{
-				requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "/mario/map1.mario", map, mapSize.x * mapSize.y);
-			}
-			else { return 0; }
-		}
-		else { return 0; }
-
-		return 1;
-	}
+	std::string mapFile = PIKA_RESOURCES_PATH "/mario/map1.mario";
 
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	{
-		player.position.position = {1,1};
-
-		renderer.create();
-		//gl2d::setErrorFuncCallback() //tood
-		//pika::initShortcutApi();
-
-		size_t s = 0;
-		if (requestedInfo.getFileSizeBinary(PIKA_RESOURCES_PATH "/mario/1985_tiles.png", s))
+		if (commandLineArgument.size() != 0)
 		{
-			void *data = new unsigned char[s];
-			if (requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "/mario/1985_tiles.png", data, s))
-			{
-				tiles.createFromFileDataWithPixelPadding((unsigned char*)data, s, 8, true, false);
-
-			}
-			else { return 0; }
-
-			delete[] data;
+			mapFile = commandLineArgument.to_string();
 		}
-		else { return 0; }
-
-		//todo push pop or sthing
-		pika::memory::setGlobalAllocatorToStandard();
-		marioTexture.loadFromFile(PIKA_RESOURCES_PATH "/mario/mario.png", true, false);
-		marioTexture.loadFromFile(PIKA_RESOURCES_PATH "/mario/mario.png", true, false);
-		pika::memory::setGlobalAllocator(requestedInfo.mainAllocator);
-
-
-		atlas = gl2d::TextureAtlasPadding(8, 10, 8*8, 8*10);
 
-		map = new Block[mapSize.x * mapSize.y];
-		Block d{27,0};
-		memset(map, *(int *)(&d), mapSize.x * mapSize.y);
+		bool rez = simulator.create(requestedInfo, mapFile);
 
-		renderer.currentCamera.zoom = 60.f;
-		
-		bool rez = loadMap(requestedInfo);
+		rez &= renderer.init(requestedInfo);
 
-		fileChanged.setFile(PIKA_RESOURCES_PATH "/mario/map1.mario");
+		fileChanged.setFile(mapFile.c_str());
 
 		return rez;
 	}
@@ -158,30 +53,12 @@ struct Mario: public Container
 		RequestedContainerInfo &requestedInfo)
 	{
 
-		{
-			glClear(GL_COLOR_BUFFER_BIT);
-			gl2d::enableNecessaryGLFeatures();
-			renderer.updateWindowMetrics(windowState.w, windowState.h);
-		}
-
 		if (fileChanged.changed())
 		{
-			loadMap(requestedInfo);
+			mario::loadMap(requestedInfo, mapFile, &simulator.map, simulator.mapSize);
 		}
 
 		{
-			float wheel = ImGui::GetIO().MouseWheel;
-
-			//todo standard out
-
-			if ((ImGui::GetIO().KeysData[ImGuiKey_LeftCtrl].Down || ImGui::GetIO().KeysData[ImGuiKey_RightCtrl].Down) && input.hasFocus)
-			{
-				renderer.currentCamera.zoom += wheel * 3;
-			}
-
-			renderer.currentCamera.zoom = std::min(renderer.currentCamera.zoom, 70.f);
-			renderer.currentCamera.zoom = std::max(renderer.currentCamera.zoom, 50.f);
-
 			int delta = 0;
 
 			if (input.hasFocus)
@@ -197,69 +74,23 @@ struct Mario: public Container
 				
 			}
 
-			player.input = delta;
+			simulator.moveDelta = delta;
 
-			if (input.buttons[pika::Button::Space].pressed() && player.grounded)
+			if (input.buttons[pika::Button::Space].pressed())
 			{
-				player.jump(60);
+				simulator.jump = true;
 			}
-
-			//phisics
+			else
 			{
-				player.moveVelocityX(5 * input.deltaTime * player.input);
-				
-				player.applyGravity(300.f * input.deltaTime);
-
-				player.updatePhisics(input.deltaTime);
-
-				player.grounded = false;
-				player.resolveConstrains(map);
-
-				//player.playerAnimation.grounded = i.second.grounded;
-
-				player.updateMove();
-
-				//player.playerAnimation.update(input.deltaTime);
+				simulator.jump = false;
 			}
 
-			//todo update gl2d this function
-			renderer.currentCamera.follow(player.position.getCenter(), input.deltaTime * 3, 0.0001, 0.2, windowState.w, windowState.h);
-
-		}
-		auto viewRect = renderer.getViewRect();
-
-		glm::ivec2 minV;
-		glm::ivec2 maxV;
-		//render
-		{
-
-			minV = {viewRect.x - 2, viewRect.y - 2};
-			maxV = minV + glm::ivec2{viewRect.z + 4, viewRect.w + 4};
-			minV = glm::max(minV, {0,0});
-			maxV = glm::min(maxV, mapSize);
-
-
-			for (int j = minV.y; j < maxV.y; j++)
-				for (int i = minV.x; i < maxV.x; i++)
-				{
-					auto b = getMapBlockUnsafe(i, j);
-					auto uv = getTileUV(atlas, b.type, b.flipped);
+			simulator.updateFrame(input.deltaTime);
 
-					renderer.renderRectangle({i, j, 1, 1}, {}, {}, tiles, uv);
-
-				}
+		
 		}
-
-		glm::vec4 pos(player.position.position, 1, 1);
-		//pos.y -= 1 / 8.f;
-		pos.x -= 1 / 8.f;
-
-		renderer.renderRectangle(pos, {}, {}, marioTexture, 
-			player.movingRight ? glm::vec4(0,1,1,0) : glm::vec4(1, 1, 0, 0));
-
-
-		renderer.flush();
-
+		
+		renderer.update(input, windowState, simulator);
 
 		return true;
 	}

+ 39 - 0
Pika/gameplay/containers/mario/marioCommon.cpp

@@ -1,5 +1,7 @@
 #include "marioCommon.h"
 
+namespace mario
+{
 
 
 bool isSolid(int id)
@@ -33,3 +35,40 @@ bool aabb(glm::vec4 b1, glm::vec4 b2, float delta)
 	}
 	return 0;
 }
+
+bool loadMap(RequestedContainerInfo &requestedInfo, std::string file, Block **map, glm::ivec2 &mapSize)
+{
+	
+	delete[] * map;
+
+	if (!requestedInfo.readEntireFileBinary(file, &mapSize, sizeof(mapSize)))
+	{
+		return 0;
+	}
+
+	*map = new Block[mapSize.x * mapSize.y];
+	Block d{27,0};
+	memset(*map, *(int *)(&d), mapSize.x * mapSize.y);
+
+	size_t s = 0;
+	if (requestedInfo.getFileSizeBinary(file.c_str(), s))
+	{
+		if (s == mapSize.x * mapSize.y + sizeof(mapSize))
+		{
+			requestedInfo.readEntireFileBinary(file.c_str(), *map, mapSize.x * mapSize.y, sizeof(mapSize));
+		}
+		else 
+		{
+			requestedInfo.consoleWindow->write("Error: mario file is corrupt\n");
+			return 0; 
+		}
+	}
+	else { return 0; }
+
+	return 1;
+}
+
+
+
+};
+

+ 228 - 1
Pika/gameplay/containers/mario/marioCommon.h

@@ -1,6 +1,9 @@
 #pragma once
 #include <gl2d/gl2d.h>
+#include <baseContainer.h>
 
+namespace mario
+{
 
 
 constexpr const char *collisionMap =
@@ -33,4 +36,228 @@ struct Block
 
 
 
-bool aabb(glm::vec4 b1, glm::vec4 b2, float delta);
+bool aabb(glm::vec4 b1, glm::vec4 b2, float delta);
+
+struct Transform
+{
+	glm::vec2 position = {};
+	glm::vec2 size = {};
+
+	glm::vec2 getTopLeftCorner();
+	glm::vec2 getCenter();
+	glm::vec2 getBottomLeftCorner();
+	glm::vec2 getBottomCenter();
+
+};
+
+#define PLAYER_SIZE glm::vec2(6.f / 8.f, 1.f)
+
+struct Player
+{
+	Transform position = {glm::vec2(0,0), PLAYER_SIZE};
+
+	glm::vec2 lastPos{};
+
+	glm::vec2 velocity = {};
+
+	bool movingRight = 0;
+	bool grounded = 0;
+
+	void move(glm::vec2 dir);
+
+	void moveVelocityX(float dir);
+
+	void jump(float power);
+
+	void applyGravity(float gravity);
+
+	bool movingThisFrame = false;
+
+
+	//should be called only once per frame last
+	void updateMove();
+
+	//this should be called before collisions 
+	void updatePhisics(float deltaTime);
+
+
+	void resolveConstrains(Block *map);
+
+	void checkCollisionBrute(glm::vec2 &pos, glm::vec2 lastPos,
+		Block *map, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
+
+	glm::vec2 Player::performCollision(Block *map, glm::vec2 pos, glm::vec2 size,
+		glm::vec2 delta, bool &upTouch, bool &downTouch, bool &leftTouch, bool &rightTouch);
+
+	int input = 0;
+};
+
+bool loadMap(RequestedContainerInfo &requestedInfo, std::string file, Block **map, glm::ivec2 &mapSize);
+
+struct GameplaySimulation
+{
+
+	GameplaySimulation() {}
+
+	bool create(RequestedContainerInfo &requestedInfo, std::string file)
+	{
+		player.position.position = {1,1};
+
+		bool rez = loadMap(requestedInfo, file, &map, mapSize);
+
+		return rez;
+	}
+
+	Player player;
+
+	Block *map;
+	glm::ivec2 mapSize = {100, 100};
+
+	Block &getMapBlockUnsafe(int x, int y)
+	{
+		return map[x + y * mapSize.x];
+	}
+
+
+	int moveDelta = 0;
+	bool jump = 0;
+
+	
+	void updateFrame(float deltaTime)
+	{
+		player.input = moveDelta;
+		if(jump)player.jump(50);
+
+		//phisics
+		{
+			player.moveVelocityX(5 * deltaTime * player.input);
+
+			player.applyGravity(200.f * deltaTime);
+
+			player.updatePhisics(deltaTime);
+
+			player.grounded = false;
+			player.resolveConstrains(map);
+
+			//player.playerAnimation.grounded = i.second.grounded;
+
+			player.updateMove();
+
+			//player.playerAnimation.update(input.deltaTime);
+		}
+
+
+	}
+
+
+};
+
+struct GameplayRenderer
+{
+	gl2d::Renderer2D renderer;
+	gl2d::Texture tiles;
+	gl2d::Texture marioTexture;
+	gl2d::TextureAtlasPadding atlas;
+
+	bool init(RequestedContainerInfo &requestedInfo)
+	{
+		renderer.create();
+		//gl2d::setErrorFuncCallback() //tood
+		//pika::initShortcutApi();
+
+		size_t s = 0;
+		if (requestedInfo.getFileSizeBinary(PIKA_RESOURCES_PATH "/mario/1985_tiles.png", s))
+		{
+			void *data = new unsigned char[s];
+			if (requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "/mario/1985_tiles.png", data, s))
+			{
+				tiles.createFromFileDataWithPixelPadding((unsigned char *)data, s, 8, true, false);
+
+			}
+			else { return 0; }
+
+			delete[] data;
+		}
+		else { return 0; }
+
+		//todo push pop or sthing
+		pika::memory::setGlobalAllocatorToStandard();
+		marioTexture.loadFromFile(PIKA_RESOURCES_PATH "/mario/mario.png", true, false);
+		marioTexture.loadFromFile(PIKA_RESOURCES_PATH "/mario/mario.png", true, false);
+		pika::memory::setGlobalAllocator(requestedInfo.mainAllocator);
+
+
+		atlas = gl2d::TextureAtlasPadding(8, 10, 8 * 8, 8 * 10);
+
+		renderer.currentCamera.zoom = 60.f;
+	
+		return 1;
+	}
+
+
+	void update(pika::Input input, pika::WindowState windowState,
+		GameplaySimulation &simulator)
+	{
+		{
+			glClear(GL_COLOR_BUFFER_BIT);
+			gl2d::enableNecessaryGLFeatures();
+			renderer.updateWindowMetrics(windowState.w, windowState.h);
+		}
+
+		float wheel = ImGui::GetIO().MouseWheel;
+		//todo standard out
+
+		if ((ImGui::GetIO().KeysData[ImGuiKey_LeftCtrl].Down || ImGui::GetIO().KeysData[ImGuiKey_RightCtrl].Down) && input.hasFocus)
+		{
+			renderer.currentCamera.zoom += wheel * 3;
+		}
+
+		renderer.currentCamera.zoom = std::min(renderer.currentCamera.zoom, 70.f);
+		renderer.currentCamera.zoom = std::max(renderer.currentCamera.zoom, 50.f);
+
+		//todo update gl2d this function
+		renderer.currentCamera.follow(simulator.player.position.getCenter(), input.deltaTime * 3, 0.0001, 0.2, windowState.w, windowState.h);
+		
+
+		auto viewRect = renderer.getViewRect();
+
+		glm::ivec2 minV;
+		glm::ivec2 maxV;
+		//render
+		{
+
+			minV = {viewRect.x - 2, viewRect.y - 2};
+			maxV = minV + glm::ivec2{viewRect.z + 4, viewRect.w + 4};
+			minV = glm::max(minV, {0,0});
+			maxV = glm::min(maxV, simulator.mapSize);
+
+
+			for (int j = minV.y; j < maxV.y; j++)
+				for (int i = minV.x; i < maxV.x; i++)
+				{
+					auto b = simulator.getMapBlockUnsafe(i, j);
+					auto uv = getTileUV(atlas, b.type, b.flipped);
+
+					renderer.renderRectangle({i, j, 1, 1}, {}, {}, tiles, uv);
+
+				}
+		}
+
+		glm::vec4 pos(simulator.player.position.position, 1, 1);
+		//pos.y -= 1 / 8.f;
+		pos.x -= 1 / 8.f;
+
+		renderer.renderRectangle(pos, {}, {}, marioTexture,
+			simulator.player.movingRight ? glm::vec4(0, 1, 1, 0) : glm::vec4(1, 1, 0, 0));
+
+
+		renderer.flush();
+
+
+	}
+
+
+
+};
+
+};

+ 17 - 31
Pika/gameplay/containers/mario/marioEditor.h

@@ -24,9 +24,9 @@ struct MarioEditor: public Container
 	int currentBlock = 0;
 	bool flip = 0;
 	
-	Block *map;
+	mario::Block *map;
 
-	Block &getMapBlockUnsafe(int x, int y)
+	mario::Block &getMapBlockUnsafe(int x, int y)
 	{
 		return map[x + y * mapSize.x];
 	}
@@ -59,28 +59,16 @@ struct MarioEditor: public Container
 
 
 		atlas = gl2d::TextureAtlasPadding(8, 10, 8*8, 8*10);
+		
+		bool rez = mario::loadMap(requestedInfo, commandLineArgument.to_string(), &map, mapSize);
 
-
-		map = new Block[mapSize.x * mapSize.y];
-		Block d{27,0};
-		memset(map, *(int *)(&d), mapSize.x * mapSize.y);
-
-		if (commandLineArgument.size() != 0)
+		if (rez)
 		{
-			memcpy(path, commandLineArgument.data(), commandLineArgument.size());
-
-			size_t s = 0;
-			if (requestedInfo.getFileSizeBinary(commandLineArgument.to_string().c_str(), s))
-			{
-				if (s == mapSize.x * mapSize.y)
-				{
-					requestedInfo.readEntireFileBinary(commandLineArgument.to_string().c_str(), map, mapSize.x * mapSize.y);
-				}
-			}
-
+			pika::strlcpy(path, commandLineArgument.data(), commandLineArgument.size()+1);
+			//path = commandLineArgument;
 		}
 
-		return true;
+		return rez;
 	}
 
 	bool update(pika::Input input, pika::WindowState windowState,
@@ -155,7 +143,7 @@ struct MarioEditor: public Container
 				for (int i = minV.x; i < maxV.x; i++)
 				{
 					auto b = getMapBlockUnsafe(i, j);
-					auto uv = getTileUV(atlas, b.type, b.flipped);
+					auto uv = mario::getTileUV(atlas, b.type, b.flipped);
 
 					renderer.renderRectangle({i, j, 1, 1}, {}, {}, tiles, uv);
 
@@ -182,7 +170,7 @@ struct MarioEditor: public Container
 			else
 			{
 			renderer.renderRectangle({blockPosition, 1, 1}, {0.9,0.9,0.9,0.9}, {}, {}, tiles, 
-				getTileUV(atlas, currentBlock, flip));
+				mario::getTileUV(atlas, currentBlock, flip));
 			}
 
 		}
@@ -202,9 +190,8 @@ struct MarioEditor: public Container
 			
 			if (ImGui::Button("save"))
 			{
-				pika::memory::setGlobalAllocatorToStandard();
-				sfs::writeEntireFile((void*)map, mapSize.x * mapSize.y, path);
-				pika::memory::setGlobalAllocator(requestedInfo.mainAllocator);
+				requestedInfo.writeEntireFileBinary(path, &mapSize, sizeof(mapSize));
+				requestedInfo.appendFileBinary(path, (void *)map, mapSize.x *mapSize.y);
 			}
 
 			ImGui::Separator();
@@ -218,7 +205,7 @@ struct MarioEditor: public Container
 				unsigned short localCount = 0;
 				while (mCount < 8*10)
 				{
-					auto uv = getTileUV(atlas, mCount);
+					auto uv = mario::getTileUV(atlas, mCount);
 
 					ImGui::PushID(mCount);
 					if (ImGui::ImageButton((void *)(intptr_t)tiles.id,
@@ -245,9 +232,9 @@ struct MarioEditor: public Container
 					unsigned short localCount = 0;
 					while (mCount < 8 * 10)
 					{
-						if (isSolid(mCount))
+						if (mario::isSolid(mCount))
 						{
-							auto uv = getTileUV(atlas, mCount);
+							auto uv = mario::getTileUV(atlas, mCount);
 
 							ImGui::PushID(mCount);
 							if (ImGui::ImageButton((void *)(intptr_t)tiles.id,
@@ -272,9 +259,9 @@ struct MarioEditor: public Container
 					unsigned short localCount = 0;
 					while (mCount < 8*10)
 					{
-						if (!isSolid(mCount))
+						if (!mario::isSolid(mCount))
 						{
-							auto uv = getTileUV(atlas, mCount);
+							auto uv = mario::getTileUV(atlas, mCount);
 
 							ImGui::PushID(mCount);
 							if (ImGui::ImageButton((void *)(intptr_t)tiles.id,
@@ -324,7 +311,6 @@ struct MarioEditor: public Container
 
 
 		renderer.flush();
-
 	
 		return true;
 	}

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

@@ -676,10 +676,10 @@ struct McDungeonsEditor: public Container
 	void destruct()
 	{
 
-		this->renderer.clearAllRendererResources();
 		this->renderer.skyBox.clearTextures();
 		this->renderer.colorCorrectionTexture().clear();
-		//this->renderer2d.clear();
+		this->renderer.clearAllRendererResources();
+		this->renderer2d.clear();
 
 	}
 

+ 16 - 19
Pika/gameplay/containers/minecraftDungeons/mcDungeonsMenu.h

@@ -25,7 +25,7 @@ struct McDungeonsMenu : public Container
 		info.defaultHeapMemorySize = pika::MB(100);
 
 		info.requestImguiFbo = true; 
-
+		info.openOnApplicationStartup = true;
 		
 		
 
@@ -49,7 +49,6 @@ struct McDungeonsMenu : public Container
 	bool update(pika::Input input, pika::WindowState windowState,
 		RequestedContainerInfo &requestedInfo)
 	{
-		//todo keep window on top stuff
 
 		glClear(GL_COLOR_BUFFER_BIT);
 
@@ -65,17 +64,18 @@ struct McDungeonsMenu : public Container
 
 			if (ui.Button("Start game", Colors_White, button))
 			{
-
+				requestedInfo.createContainer("McDungeonsGameplay");
+				return 0;
 			}
 
-			ui.BeginMenu("Settings", Colors_White, button);
-			{
-				if (ui.Button("Adaptive rezolution", Colors_White, button))
-				{
-
-				}
-			}
-			ui.EndMenu();
+			//ui.BeginMenu("Settings", Colors_White, button);
+			//{
+			//	if (ui.Button("Adaptive rezolution", Colors_White, button))
+			//	{
+			//
+			//	}
+			//}
+			//ui.EndMenu();
 
 		}
 		ui.End();
@@ -92,17 +92,14 @@ struct McDungeonsMenu : public Container
 		return true;
 	}
 
-	//optional
 	void destruct()
 	{
 
-		//todo
-		//renderer.clear();
-		
+		renderer.clear();
+		font.texture.cleanup();
+		logo.cleanup();
+		button.cleanup();
+
 	}
 
 };
-
-//todo flag to clear screen from engine
-//todo error popup
-//todo error popup disable in release

+ 167 - 23
Pika/gameplay/containers/minecraftDungeons/mcDungeonsgameplay.h

@@ -13,10 +13,12 @@
 #include <stringManipulation/stringManipulation.h>
 #include <engineLibraresSupport/engineGL2DSupport.h>
 #include <glui/glui.h>
+#include <profilerLib.h>
 
 struct McDungeonsGameplay: public Container
 {
 
+	PL::AverageProfiler profiler;
 
 	//todo user can request imgui ids; shortcut manager context; allocators
 	static ContainerStaticInfo containerInfo()
@@ -61,6 +63,8 @@ struct McDungeonsGameplay: public Container
 	{
 		PhysicsComponent physics;
 		gl3d::Entity entity;
+		float life = 1;
+		float attackCulldown = 0.f;
 
 		Zombie() {};
 		Zombie(int x, int z) { physics.position = {x,z}; physics.lastPos = {x,z}; };
@@ -87,6 +91,9 @@ struct McDungeonsGameplay: public Container
 
 	float winTimer = 4;
 	float cameraYoffset = 0;
+	float attackCulldown = 0;
+	float animationCulldown = 0;
+	float health = 1;
 
 	gl2d::Renderer2D renderer2d;
 	gl3d::Renderer3D renderer;
@@ -96,6 +103,7 @@ struct McDungeonsGameplay: public Container
 	gl3d::Model diamondModel;
 
 	gl2d::Texture diamondTexture;
+	gl2d::Texture hearthTexture;
 	gl2d::Font font;
 
 	gl3d::Entity sword;
@@ -411,14 +419,18 @@ struct McDungeonsGameplay: public Container
 
 	std::string currentFile = {};
 
+	int profilerCounter = 0;
+	PL::ProfileRezults rez = {};
+
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	{
-		playerPhysics.position = {21,32};
-		playerPhysics.lastPos = {21,32};
+		playerPhysics.position = {14,26};
+		playerPhysics.lastPos = {14,26};
 
 		renderer2d.create();
-
+		
 		diamondTexture = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "mcDungeons/diamond.png", requestedInfo, true, false);
+		hearthTexture = pika::gl2d::loadTexture(PIKA_RESOURCES_PATH "mcDungeons/hearth.png", requestedInfo, true, false);
 		font = pika::gl2d::loadFont(PIKA_RESOURCES_PATH "mcDungeons/CommodorePixeled.ttf", requestedInfo);
 
 
@@ -433,6 +445,7 @@ struct McDungeonsGameplay: public Container
 		
 		renderer.init(1, 1, PIKA_RESOURCES_PATH "BRDFintegrationMap.png", requestedInfo.requestedFBO.fbo);
 		renderer.colorCorrectionTexture() = renderer.loadColorLookupTextureFromFile(PIKA_RESOURCES_PATH "/mcDungeons/lut.png");
+		renderer.colorCorrection() = false;
 
 		//renderer.skyBox = renderer.loadSkyBox(names);
 		//renderer.skyBox.color = {0.2,0.3,0.8};
@@ -503,6 +516,7 @@ struct McDungeonsGameplay: public Container
 		sword = renderer.createEntity(swordModel, {}, false);
 
 		//enemies
+		if(1)
 		{
 			enemies.push_back(Zombie(18, 46));
 			enemies.push_back(Zombie(16, 46));
@@ -514,6 +528,23 @@ struct McDungeonsGameplay: public Container
 			enemies.push_back(Zombie(71, 63));
 			enemies.push_back(Zombie(56, 72));
 			
+			enemies.push_back(Zombie(38, 68));
+			enemies.push_back(Zombie(30, 63));
+			enemies.push_back(Zombie(27, 55));
+			enemies.push_back(Zombie(82, 65));
+			enemies.push_back(Zombie(83, 56));
+			enemies.push_back(Zombie(94, 49));
+			enemies.push_back(Zombie(102, 49));
+			enemies.push_back(Zombie(112, 61));
+
+			enemies.push_back(Zombie(105, 83));
+			enemies.push_back(Zombie(100, 86));
+			enemies.push_back(Zombie(101, 95));
+			enemies.push_back(Zombie(91, 90));
+			enemies.push_back(Zombie(61, 85));
+			enemies.push_back(Zombie(64, 90));
+			enemies.push_back(Zombie(73, 96));
+
 
 			for (auto &i : enemies)
 			{
@@ -530,7 +561,6 @@ struct McDungeonsGameplay: public Container
 				renderer.setEntityAnimationIndex(i.entity, Animations::zombieIdle);
 			}
 
-
 		}
 
 		//diamonds
@@ -555,12 +585,23 @@ struct McDungeonsGameplay: public Container
 		renderer.setExposure(1.5f);
 		renderer.frustumCulling = false;
 		
+
 		return true;
 	}
 
 	bool update(pika::Input input, pika::WindowState windowState,
 		RequestedContainerInfo &requestedInfo)
 	{
+	
+		profiler.end();
+		profiler.start();
+
+		profilerCounter++;
+		if (profilerCounter > 150)
+		{
+			rez = profiler.getAverageAndResetData();
+			profilerCounter = 0;
+		}
 
 		renderer2d.updateWindowMetrics(windowState.w, windowState.h);
 
@@ -570,6 +611,8 @@ struct McDungeonsGameplay: public Container
 		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
 		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
 
+		
+
 
 		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		glEnable(GL_DEPTH_TEST);
@@ -584,10 +627,9 @@ struct McDungeonsGameplay: public Container
 	
 		bool shouldRecreate = 0;
 
-
+		/*
 		ImGui::PushID(requestedInfo.requestedImguiIds);
 
-
 		if (ImGui::Begin("General3DEditor"))
 		{
 			if (ImGui::Button("recreate world"))
@@ -604,6 +646,7 @@ struct McDungeonsGameplay: public Container
 		ImGui::End();
 
 		ImGui::PopID();
+		*/
 
 		if (shouldRecreate)
 		{
@@ -624,21 +667,24 @@ struct McDungeonsGameplay: public Container
 			{
 				glm::vec2 dir = {};
 
-				if (input.buttons[pika::Button::A].held() || input.buttons[pika::Button::Left].held())
+				if (animationCulldown <= 0)
 				{
-					dir -= glm::vec2(1,1);
-				}
-				if (input.buttons[pika::Button::D].held() || input.buttons[pika::Button::Right].held())
-				{
-					dir += glm::vec2(1,1);
-				}
-				if (input.buttons[pika::Button::W].held() || input.buttons[pika::Button::Up].held())
-				{
-					dir += glm::vec2(1,-1);
-				}
-				if (input.buttons[pika::Button::S].held() || input.buttons[pika::Button::Down].held())
-				{
-					dir -= glm::vec2(1, -1);
+					if (input.buttons[pika::Button::A].held() || input.buttons[pika::Button::Left].held())
+					{
+						dir -= glm::vec2(1, 1);
+					}
+					if (input.buttons[pika::Button::D].held() || input.buttons[pika::Button::Right].held())
+					{
+						dir += glm::vec2(1, 1);
+					}
+					if (input.buttons[pika::Button::W].held() || input.buttons[pika::Button::Up].held())
+					{
+						dir += glm::vec2(1, -1);
+					}
+					if (input.buttons[pika::Button::S].held() || input.buttons[pika::Button::Down].held())
+					{
+						dir -= glm::vec2(1, -1);
+					}
 				}
 
 				if (dir.x != 0 || dir.y != 0)
@@ -653,16 +699,65 @@ struct McDungeonsGameplay: public Container
 					};
 					
 					playerPhysics.desiredRotation = std::atan2(dir.x, dir.y);
+
+					if (animationCulldown <= 0)
 					renderer.setEntityAnimationIndex(player, Animations::run);
 				}
 				else
 				{
+					if (animationCulldown <= 0)
 					renderer.setEntityAnimationIndex(player, Animations::idle);
-				}
+				}  
 
 				float speed = 3;
 				playerPhysics.position += dir * input.deltaTime * speed;
 
+
+				if (input.buttons[pika::Button::Space].pressed() && attackCulldown <= 0)
+				{
+					renderer.setEntityAnimationIndex(player, Animations::attack);
+					animationCulldown = 0.45;
+					attackCulldown = 0.8;
+
+					for (int i = 0; i < enemies.size(); i++)
+					{
+						float d = glm::distance(playerPhysics.position, enemies[i].physics.position);
+						if (d < 1.5f)
+						{
+							enemies[i].life -= 0.4;
+
+							if (enemies[i].life <= 0)
+							{
+								renderer.deleteEntity(enemies[i].entity);
+								enemies.erase(enemies.begin() + i);
+								i--;
+								continue;
+							}
+
+							glm::vec2 dir(1, 0);
+
+							if (d != 0)
+							{
+								dir = (enemies[i].physics.position - playerPhysics.position) / d;
+							}
+
+							enemies[i].physics.position += dir * 1.5f;
+						}
+
+					}
+
+				}
+
+			}
+
+			if (animationCulldown > 0)
+			{
+				animationCulldown -= input.deltaTime;
+			}
+
+			if (attackCulldown > 0)
+			{
+				attackCulldown -= input.deltaTime;
 			}
 
 		#pragma endregion
@@ -760,6 +855,11 @@ struct McDungeonsGameplay: public Container
 					{
 						renderer.setEntityAnimationIndex(e.entity, Animations::zombieAttack);
 
+						if (e.attackCulldown <= 0.f)
+						{
+							health -= 0.2;
+							e.attackCulldown = 1.f;
+						}
 						//attack
 					}
 				}
@@ -768,6 +868,11 @@ struct McDungeonsGameplay: public Container
 					renderer.setEntityAnimationIndex(e.entity, Animations::zombieIdle);
 				}
 
+				if (e.attackCulldown > 0)
+				{
+					e.attackCulldown -= input.deltaTime;
+				}
+
 				solveRotation(e.physics);
 
 				resolveConstrains(e.physics);
@@ -863,8 +968,23 @@ struct McDungeonsGameplay: public Container
 			winTimer -= input.deltaTime;
 			if (winTimer <= 0.f)
 			{
+				requestedInfo.createContainer("McDungeonsMenu");
+				return 0;
+			}
+		}
+		else
+		{
+			if (health <= 0.f)
+			{
+				requestedInfo.createContainer("McDungeonsMenu");
 				return 0;
 			}
+			else
+			{
+				health += input.deltaTime / 60.f;
+				if (health > 1.f) { health = 1.f; }
+			}
+
 		}
 
 		diamondPeriod += input.deltaTime * 0.2;
@@ -905,7 +1025,7 @@ struct McDungeonsGameplay: public Container
 		glDisable(GL_DEPTH_TEST);
 
 
-
+		if(1)
 		{
 			glui::Frame screen({0,0,windowState.w, windowState.h});
 
@@ -926,8 +1046,21 @@ struct McDungeonsGameplay: public Container
 
 				renderer2d.renderText({glui::Box().xLeftPerc(0.5f).yTopPerc(0.9f)()}, s.c_str(), font,
 					{1,1,1,0.5}, 1.0f, 4, 3, false);
-					
+			}
 
+			{
+				renderer2d.renderRectangle(glui::Box().xRight(-10).yTop(10).xDimensionPixels(100).yAspectRatio(1.f),
+					{1,1,1,health},
+					{}, 0,
+					hearthTexture);
+			}
+
+			{
+				std::string fps = std::to_string(std::max(0, int(1.f / rez.timeSeconds))) + " fps";
+
+
+				renderer2d.renderText(glui::Box().xLeft(10).yBottom(-10)(), fps.c_str(), font,
+					{0.8,0.8,0.8,0.2}, 0.5, 4, 3, false);
 			}
 
 		}
@@ -942,6 +1075,17 @@ struct McDungeonsGameplay: public Container
 		return true;
 	}
 
+	void destruct()
+	{
+
+		this->renderer.skyBox.clearTextures();
+		this->renderer.colorCorrectionTexture().clear();
+		this->renderer.clearAllRendererResources();
+		this->renderer2d.clear();
+
+	}
+
+
 };
 
 //todo flag to clear screen from engine

+ 2 - 4
Pika/resources/logs.txt

@@ -1,4 +1,2 @@
-#2023-03-15 14:01:10: Created container: Gameplay
-#2023-03-15 14:01:15: Created container: McDungeonsGameplay
-#2023-03-15 14:01:54: Destroyed continer: Gameplay #1
-#2023-03-15 14:03:02: Destroyed continer: McDungeonsGameplay #2
+#2023-04-25 10:00:19: Created container: Mario
+#2023-04-25 10:00:22: Destroyed continer: Mario #1

BIN
Pika/resources/mario/map1.mario


BIN
Pika/resources/mcDungeons/hearth.png


+ 52 - 59
Pika/thirdparty/gl2d/include/gl2d/gl2d.h

@@ -66,11 +66,11 @@ namespace gl2d
 
 	void init();
 
-	void defaultErrorFunc(const char *msg);
+	void defaultErrorFunc(const char* msg);
 
 	using errorFuncType = decltype(defaultErrorFunc);
 
-	errorFuncType *setErrorFuncCallback(errorFuncType *newFunc);
+	errorFuncType* setErrorFuncCallback(errorFuncType* newFunc);
 
 	struct Font;
 
@@ -128,29 +128,27 @@ namespace gl2d
 		GLuint id = 0;
 
 		Texture() {};
-		Texture(const char *file, bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED,
+		explicit Texture(const char* file, bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED,
 			bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS)
-		{
-			loadFromFile(file, pixelated, useMipMaps);
-		}
+			{ loadFromFile(file, pixelated, useMipMaps); }
 
 		glm::ivec2 GetSize();
 
 		//Note: This function expects a buffer of bytes in GL_RGBA format
-		void createFromBuffer(const char *image_data, const int width,
+		void createFromBuffer(const char* image_data, const int width,
 			const int height, bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED, bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS);
-		void create1PxSquare(const char *b = 0);
-		void createFromFileData(const unsigned char *image_file_data, const size_t image_file_size,
+		void create1PxSquare(const char* b = 0);
+		void createFromFileData(const unsigned char* image_file_data, const size_t image_file_size, 
 			bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED, bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS);
-		void createFromFileDataWithPixelPadding(const unsigned char *image_file_data,
+		void createFromFileDataWithPixelPadding(const unsigned char* image_file_data,
 			const size_t image_file_size, int blockSize,
 			bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED, bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS);
 
-		void loadFromFile(const char *fileName,
+		void loadFromFile(const char* fileName,
 			bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED, bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS);
 
 		//used for texture atlases, adds a pixel between each item to remove visual artefacts
-		void loadFromFileWithPixelPadding(const char *fileName, int blockSize,
+		void loadFromFileWithPixelPadding(const char* fileName, int blockSize,
 			bool pixelated = GL2D_DEFAULT_TEXTURE_LOAD_MODE_PIXELATED, bool useMipMaps = GL2D_DEFAULT_TEXTURE_LOAD_MODE_USE_MIPMAPS);
 
 		void bind(const unsigned int sample = 0);
@@ -159,7 +157,7 @@ namespace gl2d
 		void cleanup();
 	};
 
-	struct TextureRegion
+	struct TextureRegion //todo add uses for this
 	{
 		Texture texture;
 		glm::vec4 textureCoords;
@@ -178,7 +176,7 @@ namespace gl2d
 	struct TextureAtlas
 	{
 		TextureAtlas() {};
-		TextureAtlas(int x, int y):xCount(x), yCount(y) {};
+		TextureAtlas(int x, int y) :xCount(x), yCount(y) {};
 
 		int xCount = 0;
 		int yCount = 0;
@@ -194,7 +192,7 @@ namespace gl2d
 		TextureAtlasPadding() {};
 
 		//count count size of the full texture(in pixels)
-		TextureAtlasPadding(int x, int y, int xSize, int ySize):xCount(x), yCount(y)
+		TextureAtlasPadding(int x, int y, int xSize, int ySize) :xCount(x), yCount(y)
 			, xSize(xSize), ySize(ySize)
 		{
 		};
@@ -215,13 +213,7 @@ namespace gl2d
 
 	///////////////////// Font /////////////////////
 #pragma region Font
-#define Default_Font_Characters_Range_Begin cast(char, ' ')
-#define Default_Font_Characters_Range_End cast(char, '~')
-#define Default_Font_Characters_Range_Size cast(isize, Default_Font_Characters_Range_End - Default_Font_Characters_Range_Begin)
-
-	typedef float Font_Size;
 
-	typedef struct Font Font;
 	struct Font
 	{
 		Texture           texture = {};
@@ -235,8 +227,10 @@ namespace gl2d
 
 		void createFromTTF(const unsigned char *ttf_data, const size_t ttf_data_size);
 		void createFromFile(const char *file);
+
 	};
 
+
 #pragma endregion
 
 	///////////////////// Camera /////////////////////
@@ -256,7 +250,7 @@ namespace gl2d
 
 		void follow(glm::vec2 pos, float speed, float min, float max, float w, float h);
 
-		glm::vec2 convertPoint(const glm::vec2 &p, float windowW, float windowH); //todo move to internal
+		glm::vec2 convertPoint(const glm::vec2& p, float windowW, float windowH); //todo move to internal
 	};
 
 
@@ -300,12 +294,12 @@ namespace gl2d
 		Renderer2D() {};
 
 		//feel free to delete this lines but you probably don't want to copy the renderer from a place to another
-		Renderer2D(Renderer2D &other) = delete;
+		Renderer2D(Renderer2D &other) = delete; 
 		Renderer2D operator=(Renderer2D &other) = delete;
 
 		void create();
 
-		//todo
+		//does not clear resources allocated by user like textures, fonts and fbos
 		void clear();
 
 		GLuint buffers[Renderer2DBufferType::bufferSize] = {};
@@ -322,7 +316,6 @@ namespace gl2d
 		int texturePositionsCount = 0;
 		int spriteTexturesCount = 0;
 
-		Texture white1pxSquareTexture = {};
 
 		internal::ShaderProgram currentShader = {};
 		std::vector<internal::ShaderProgram> shaderPushPop;
@@ -343,7 +336,7 @@ namespace gl2d
 		void updateWindowMetrics(int w, int h) { windowW = w; windowH = h; }
 
 		//converts pixels to screen (top left) (bottom right)
-		glm::vec4 toScreen(const glm::vec4 &transform);
+		glm::vec4 toScreen(const glm::vec4& transform);
 
 		inline void clearDrawData()
 		{
@@ -366,31 +359,31 @@ namespace gl2d
 		void renderRectangle(const Rect transforms, const Color4f colors[4], const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords);
 		inline void renderRectangle(const Rect transforms, const Color4f colors, const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords)
 		{
-			Color4f c[4] = {colors,colors,colors,colors};
+			Color4f c[4] = { colors,colors,colors,colors };
 			renderRectangle(transforms, c, origin, rotation, texture, textureCoords);
 		}
 
 		void renderRectangleAbsRotation(const Rect transforms, const Color4f colors[4], const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords);
 		inline void renderRectangleAbsRotation(const Rect transforms, const Color4f colors, const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords)
 		{
-			Color4f c[4] = {colors,colors,colors,colors};
+			Color4f c[4] = { colors,colors,colors,colors };
 			renderRectangleAbsRotation(transforms, c, origin, rotation, texture, textureCoords);
 		}
 
 		void renderRectangle(const Rect transforms, const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords);
 		void renderRectangleAbsRotation(const Rect transforms, const glm::vec2 origin, const float rotation, const Texture texture, const glm::vec4 textureCoords = GL2D_DefaultTextureCoords);
 
-		void renderRectangle(const Rect transforms, const Color4f colors[4], const glm::vec2 origin = {0,0}, const float rotation = 0);
-		inline void renderRectangle(const Rect transforms, const Color4f colors, const glm::vec2 origin = {0,0}, const float rotation = 0)
+		void renderRectangle(const Rect transforms, const Color4f colors[4], const glm::vec2 origin = { 0,0 }, const float rotation = 0);
+		inline void renderRectangle(const Rect transforms, const Color4f colors, const glm::vec2 origin = { 0,0 }, const float rotation = 0)
 		{
-			Color4f c[4] = {colors,colors,colors,colors};
+			Color4f c[4] = { colors,colors,colors,colors };
 			renderRectangle(transforms, c, origin, rotation);
 		}
 
-		void renderRectangleAbsRotation(const Rect transforms, const Color4f colors[4], const glm::vec2 origin = {0,0}, const float rotation = 0);
-		inline void renderRectangleAbsRotation(const Rect transforms, const Color4f colors, const glm::vec2 origin = {0,0}, const float rotation = 0)
+		void renderRectangleAbsRotation(const Rect transforms, const Color4f colors[4], const glm::vec2 origin = { 0,0 }, const float rotation = 0);
+		inline void renderRectangleAbsRotation(const Rect transforms, const Color4f colors, const glm::vec2 origin = { 0,0 }, const float rotation = 0)
 		{
-			Color4f c[4] = {colors,colors,colors,colors};
+			Color4f c[4] = { colors,colors,colors,colors };
 			renderRectangleAbsRotation(transforms, c, origin, rotation);
 		}
 
@@ -439,8 +432,8 @@ namespace gl2d
 
 	struct ParticleSettings
 	{
-		ParticleSettings *deathRattle = nullptr;
-		ParticleSettings *subemitParticle = nullptr;
+		ParticleSettings* deathRattle = nullptr;
+		ParticleSettings* subemitParticle = nullptr;
 
 		int onCreateCount = 0;
 
@@ -462,7 +455,7 @@ namespace gl2d
 		ParticleApearence createApearence = {};
 		ParticleApearence createEndApearence = {};
 
-		gl2d::Texture *texturePtr = 0;
+		gl2d::Texture* texturePtr = 0;
 
 		int tranzitionType = TRANZITION_TYPES::linear;
 	};
@@ -473,12 +466,12 @@ namespace gl2d
 		void initParticleSystem(int size);
 		void cleanup();
 
-		void emitParticleWave(ParticleSettings *ps, glm::vec2 pos);
+		void emitParticleWave(ParticleSettings* ps, glm::vec2 pos);
 
 
 		void applyMovement(float deltaTime);
 
-		void draw(Renderer2D &r);
+		void draw(Renderer2D& r);
 
 		bool postProcessing = true;
 		float pixelateFactor = 2;
@@ -487,37 +480,37 @@ namespace gl2d
 
 		int size = 0;
 
-		float *posX = 0;
-		float *posY = 0;
+		float* posX = 0;
+		float* posY = 0;
 
-		float *directionX = 0;
-		float *directionY = 0;
+		float* directionX = 0;
+		float* directionY = 0;
 
-		float *rotation = 0;
+		float* rotation = 0;
 
-		float *sizeXY = 0;
+		float* sizeXY = 0;
 
-		float *dragX = 0;
-		float *dragY = 0;
+		float* dragX = 0;
+		float* dragY = 0;
 
-		float *duration = 0;
-		float *durationTotal = 0;
+		float* duration = 0;
+		float* durationTotal = 0;
 
-		glm::vec4 *color = 0;
+		glm::vec4* color = 0;
 
-		float *rotationSpeed = 0;
-		float *rotationDrag = 0;
+		float* rotationSpeed = 0;
+		float* rotationDrag = 0;
 
-		float *emitTime = 0;
+		float* emitTime = 0;
 
-		char *tranzitionType = 0;
-		ParticleSettings **deathRattle = 0;
-		ParticleSettings **thisParticleSettings = 0;
-		ParticleSettings **emitParticle = 0;
+		char* tranzitionType = 0;
+		ParticleSettings** deathRattle = 0;
+		ParticleSettings** thisParticleSettings = 0;
+		ParticleSettings** emitParticle = 0;
 
-		gl2d::Texture **textures = 0;
+		gl2d::Texture** textures = 0;
 
-		std::mt19937 random{std::random_device{}()};
+		std::mt19937 random{ std::random_device{}() };
 
 		gl2d::FrameBuffer fb = {};
 

File diff suppressed because it is too large
+ 209 - 198
Pika/thirdparty/gl2d/src/gl2d.cpp


+ 6 - 0
Pika/thirdparty/profilerLib/CMakeLists.txt

@@ -0,0 +1,6 @@
+cmake_minimum_required(VERSION 3.13)
+project(profilerLib)
+
+
+add_library(profilerLib INTERFACE)
+target_include_directories(profilerLib INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/")

+ 187 - 0
Pika/thirdparty/profilerLib/include/profilerLib.h

@@ -0,0 +1,187 @@
+#pragma once
+#include <intrin.h>
+#include <Windows.h>
+
+///////////////////////////////////////////
+//https://github.com/meemknight/profilerLib
+//do not remove this notice
+//(c) Luta Vlad
+///////////////////////////////////////////
+
+
+//set this to true to remove the implementation
+//usefull to quickly remove debug and profile cod and to port to
+//other platforms
+#define PROFILER_LIB_REMOVE_IMPLEMENTATION 0
+
+
+namespace PL 
+{
+
+	struct ProfileRezults
+	{
+		float timeSeconds;
+		unsigned int cpuClocks;
+	};
+
+#if !PROFILER_LIB_REMOVE_IMPLEMENTATION
+
+	struct PerfFreqvency
+	{
+		PerfFreqvency()
+		{
+			QueryPerformanceFrequency(&perfFreq);
+		}
+
+		LARGE_INTEGER perfFreq;
+	};
+	const static PerfFreqvency freq;
+
+
+	struct Profiler
+	{
+
+		LARGE_INTEGER startTime = {};
+		__int64 cycleCount = {};
+
+		void start()
+		{
+			QueryPerformanceCounter(&startTime);
+			cycleCount = __rdtsc();
+		}
+
+		ProfileRezults end()
+		{
+			__int64 endCycleCount = __rdtsc();
+			LARGE_INTEGER endTime;
+			QueryPerformanceCounter(&endTime);
+
+			cycleCount = endCycleCount - cycleCount;
+			startTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
+
+
+			ProfileRezults r = {};
+
+			r.timeSeconds = (float)startTime.QuadPart / (float)freq.perfFreq.QuadPart;
+			r.cpuClocks = cycleCount;
+
+			return r;
+		}
+
+	};
+
+	const int AverageProfilerMaxTests = 200;
+
+	struct AverageProfiler
+	{
+		ProfileRezults rezults[AverageProfilerMaxTests];
+		int index = 0;
+
+		Profiler profiler;
+
+		void start()
+		{
+			profiler.start();
+		}
+
+		ProfileRezults end()
+		{
+			auto r = profiler.end();
+			
+			if(index < AverageProfilerMaxTests)
+			{
+				rezults[index] = r;
+				index++;
+			}
+
+			return r;
+		}
+
+		ProfileRezults getAverageNoResetData()
+		{
+			if (index == 0)
+			{
+				return { 0,0 };
+			}
+
+			long double time = 0;
+			unsigned long cpuTime = 0;
+
+			for(int i=0;i<index;i++)
+			{
+				time += rezults[i].timeSeconds;
+				cpuTime += rezults[i].cpuClocks;
+			}
+
+
+			return { (float)(time / index), cpuTime /index };
+		}
+		
+		void resetData()
+		{
+			index = 0;
+		}
+
+		ProfileRezults getAverageAndResetData()
+		{
+			auto r = getAverageNoResetData();
+			resetData();
+			return r;
+		}
+
+
+	};
+
+#else
+
+	struct Profiler
+	{
+	
+		
+		void start()
+		{
+			
+		}
+	
+		ProfileRezults end()
+		{	
+			return {};
+		}
+	
+	};
+	
+	
+	struct AverageProfiler
+	{
+		
+		void start()
+		{
+		}
+	
+		ProfileRezults end()
+		{
+			return {};
+		}
+	
+		ProfileRezults getAverageNoResetData()
+		{
+			
+			return {};
+		}
+	
+		void resetData()
+		{
+		}
+	
+		ProfileRezults getAverageAndResetData()
+		{
+			return {};
+		}
+	
+	};
+
+
+
+#endif
+
+};

Some files were not shown because too many files changed in this diff