Răsfoiți Sursa

finished more or less console (good enough)

meemknight 3 ani în urmă
părinte
comite
b96515ee2c

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

@@ -46,7 +46,7 @@
 
 #define PIKA_REMOVE_PUSH_NOTIFICATION_IN_PRODUCTION 0
 
-#define PIKA_ENABLE_CONSOLE_IN_PRODUCTION 1
+//#define PIKA_ENABLE_CONSOLE_IN_PRODUCTION 1 //removed for now
 
 
 #define PIKA_CLEAR_SCREEN_BY_ENGINE_IN_PRODUCTION 0

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

@@ -242,7 +242,7 @@ void pika::ContainerManager::init()
 }
 
 void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow &window,
-	pika::LogManager &logs, pika::pikaImgui::ImGuiIdsManager &imguiIdManager)
+	pika::LogManager &logs, pika::pikaImgui::ImGuiIdsManager &imguiIdManager, pika::ConsoleWindow *consoleWindow)
 {
 	PIKA_DEVELOPMENT_ONLY_ASSERT(loadedDll.dllHand != 0, "dll not loaded when trying to update containers");
 
@@ -260,7 +260,6 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 	}
 
 	
-	
 #pragma endregion
 
 
@@ -268,6 +267,9 @@ void pika::ContainerManager::update(pika::LoadedDll &loadedDll, pika::PikaWindow
 	for (auto &c : runningContainers)
 	{
 
+		c.second.requestedContainerInfo.consoleWindow = consoleWindow;
+
+
 		if (c.second.flags.status == pika::RuntimeContainer::FLAGS::STATUS_RUNNING
 			||
 			c.second.flags.status == pika::RuntimeContainer::FLAGS::STATUS_BEING_RECORDED

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

@@ -55,7 +55,8 @@ namespace pika
 			pika::LoadedDll &loadedDll,
 			pika::PikaWindow &window,
 			pika::LogManager &logs,
-			pika::pikaImgui::ImGuiIdsManager &imguiIdManager);
+			pika::pikaImgui::ImGuiIdsManager &imguiIdManager,
+			pika::ConsoleWindow *consoleWindow);
 
 		void reloadDll(pika::LoadedDll &loadedDll,
 			pika::PikaWindow &window,

+ 43 - 39
Pika/core/pikaRuntime/pikaMain.cpp

@@ -52,44 +52,44 @@ int main()
 #pragma region Console
 
 	
-#if !(PIKA_SHOULD_REMOVE_EDITOR)
-	//internal console
-
-	{
-
-
-		//std::streambuf *old = std::cout.rdbuf(consoleBuffer.rdbuf());
-
-		//std::cout << "Bla" << std::endl;
-		//printf("test\n");
-		//std::cout.sync_with_stdio();
-
-		//std::string text = buffer.str();
-	}
-
-#else
-	//normal console if enabeled
-#if defined(PIKA_WINDOWS)
-#ifdef PIKA_PRODUCTION
-#if PIKA_ENABLE_CONSOLE_IN_PRODUCTION
-	{
-		AllocConsole();
-		(void)freopen("conin$", "r", stdin);
-		(void)freopen("conout$", "w", stdout);
-		(void)freopen("conout$", "w", stderr);
-		std::cout.sync_with_stdio();
-
-		//HWND hwnd = GetConsoleWindow(); //dissable console x button
-		//HMENU hmenu = GetSystemMenu(hwnd, FALSE);
-		//EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED);
-
-		SetConsoleCtrlHandler(0, true); //dissable ctrl+c shortcut in console
-		SetConsoleCtrlHandler(customConsoleHandlerRoutine, true); //custom exti function on clicking x button on console
-	}
-#endif
-#endif
-#endif
-#endif
+//#if !(PIKA_SHOULD_REMOVE_EDITOR)
+//	//internal console
+//
+//	{
+//
+//
+//		//std::streambuf *old = std::cout.rdbuf(consoleBuffer.rdbuf());
+//
+//		//std::cout << "Bla" << std::endl;
+//		//printf("test\n");
+//		//std::cout.sync_with_stdio();
+//
+//		//std::string text = buffer.str();
+//	}
+//
+//#else
+//	//normal console if enabeled
+//#if defined(PIKA_WINDOWS)
+//#ifdef PIKA_PRODUCTION
+//#if PIKA_ENABLE_CONSOLE_IN_PRODUCTION
+//	{
+//		AllocConsole();
+//		(void)freopen("conin$", "r", stdin);
+//		(void)freopen("conout$", "w", stdout);
+//		(void)freopen("conout$", "w", stderr);
+//		std::cout.sync_with_stdio();
+//
+//		//HWND hwnd = GetConsoleWindow(); //dissable console x button
+//		//HMENU hmenu = GetSystemMenu(hwnd, FALSE);
+//		//EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED);
+//
+//		SetConsoleCtrlHandler(0, true); //dissable ctrl+c shortcut in console
+//		SetConsoleCtrlHandler(customConsoleHandlerRoutine, true); //custom exti function on clicking x button on console
+//	}
+//#endif
+//#endif
+//#endif
+//#endif
 
 
 #pragma endregion
@@ -225,9 +225,13 @@ int main()
 			editor.shouldReloadDll = false;
 			containerManager.reloadDll(loadedDll, window, logs);
 		}
+
+		containerManager.update(loadedDll, window, logs, imguiIdsManager, &editor.consoleWindow);
+
+	#else
+		containerManager.update(loadedDll, window, logs, imguiIdsManager, nullptr);
 	#endif
 
-	containerManager.update(loadedDll, window, logs, imguiIdsManager);
 
 	#pragma endregion
 

+ 7 - 7
Pika/core/pikaSTD/pikaSizes.h

@@ -7,14 +7,14 @@
 
 namespace pika
 {
-	inline size_t KB(size_t x) { return x * 1024ull; }
-	inline size_t MB(size_t x) { return KB(x) * 1024ull; }
-	inline size_t GB(size_t x) { return MB(x) * 1024ull; }
-	inline size_t TB(size_t x) { return GB(x) * 1024ull; }
+	inline size_t constexpr KB(size_t x) { return x * 1024ull; }
+	inline size_t constexpr MB(size_t x) { return KB(x) * 1024ull; }
+	inline size_t constexpr GB(size_t x) { return MB(x) * 1024ull; }
+	inline size_t constexpr TB(size_t x) { return GB(x) * 1024ull; }
 
-	inline float BYTES_TO_KB(size_t x) { return x / 1024.f; }
-	inline float BYTES_TO_MB(size_t x) { return BYTES_TO_KB(x) / 1024.f; }
-	inline float BYTES_TO_GB(size_t x) { return BYTES_TO_MB(x) / 1024.f; }
+	inline float constexpr BYTES_TO_KB(size_t x) { return x / 1024.f; }
+	inline float constexpr BYTES_TO_MB(size_t x) { return BYTES_TO_KB(x) / 1024.f; }
+	inline float constexpr BYTES_TO_GB(size_t x) { return BYTES_TO_MB(x) / 1024.f; }
 
 	inline void align64(size_t &val)
 	{

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

@@ -6,6 +6,7 @@
 #include <pikaAllocator/freeListAllocator.h>
 #include <staticVector.h>
 #include <pikaGL/frameBuffer.h>
+#include <pikaConsoleManager/pikaConsoleWindow.h>
 
 #define READENTIREFILE(x) bool x(const char* name, void* buffer, size_t size)
 typedef READENTIREFILE(readEntireFile_t);
@@ -33,6 +34,19 @@ struct RequestedContainerInfo
 	int requestedImguiIds = 0;
 	int imguiTotalRequestedIds = 0;
 
+	pika::ConsoleWindow *consoleWindow = nullptr;
+
+	//returns true if succeded (can return false if console is disabeled)
+	bool consoleWrite(const char* c)
+	{
+		//do not allocate memory here!
+		//console window is from core realm
+
+		if (!consoleWindow) { return false; }
+		consoleWindow->write(c);
+		return true;
+	}
+
 	//todo implement
 	bool readEntireFile(const char *name, void *buffer, size_t size)
 	{

+ 35 - 9
Pika/core/pikaEditor/pikaConsoleManager/pikaConsoleWindow.cpp → Pika/core/sharedRuntime/pikaConsoleManager/pikaConsoleWindow.cpp

@@ -9,7 +9,6 @@ namespace pika
 	void ConsoleWindow::init(pika::pikaImgui::ImGuiIdsManager &idManager)
 	{
 		imguiId = idManager.getImguiIds();
-		s.reserve(4000);
 	}
 
 	void ConsoleWindow::update(pika::LogManager &logManager, bool &open)
@@ -21,13 +20,6 @@ namespace pika
 		//s += std::string{(std::istreambuf_iterator<char>(buffer)),
 		//	std::istreambuf_iterator<char>()};
 
-		constexpr int SIZE = 3000; //todo
-		
-		if (s.size() > SIZE)
-		{
-			s.erase(0, s.size() - SIZE);
-		}
-
 		ImGui::PushID(imguiId);
 
 		if (!ImGui::Begin(ICON_NAME, &open))
@@ -43,7 +35,18 @@ namespace pika
 
 		ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
 		
-		ImGui::TextWrapped(s.c_str());
+		if (wrapped)
+		{
+			if(bufferBeginPos <= BUFFER_SIZE - 1)
+			ImGui::TextWrapped(&buffer[bufferBeginPos + 1]);
+			//ImGui::SameLine();
+			ImGui::TextWrapped(buffer);
+		}
+		else
+		{
+			ImGui::TextWrapped(buffer);
+		}
+
 		//ImGui::TextUnformatted(s.c_str());
 
 		ImGui::PopStyleVar();
@@ -59,5 +62,28 @@ namespace pika
 
 	}
 
+	void ConsoleWindow::write(const char *c)
+	{
+		size_t i = 0;
+		while (c[i] != 0)
+		{
+			buffer[bufferBeginPos] = c[i];
+			i++;
+			bufferBeginPos++;
+
+			if (bufferBeginPos >= BUFFER_SIZE)
+			{
+				bufferBeginPos = 0;
+				wrapped = true;
+			}
+
+			if (wrapped)
+			{
+				buffer[bufferBeginPos] = 0;
+			}
+		}
+
+	}
+
 };
 

+ 9 - 1
Pika/core/pikaEditor/pikaConsoleManager/pikaConsoleWindow.h → Pika/core/sharedRuntime/pikaConsoleManager/pikaConsoleWindow.h

@@ -1,6 +1,7 @@
 #pragma once
 #include <pikaImgui/pikaImgui.h>
 #include <logs/log.h>
+#include <pikaSizes.h>
 
 namespace pika
 {
@@ -18,7 +19,14 @@ namespace pika
 
 		int imguiId = 0;
 
-		std::string s;
+		constexpr static const size_t BUFFER_SIZE = 3000;
+
+		char buffer[BUFFER_SIZE+1] = {};
+		size_t bufferBeginPos = 0;
+
+		bool wrapped = 0;
+
+		void write(const char *c);
 	};
 
 

BIN
Pika/engineResources/engineSaves/window1.bin


BIN
Pika/engineResources/engineSaves/window2.bin


BIN
Pika/engineResources/engineSaves/windowPos1.bin


BIN
Pika/engineResources/engineSaves/windowPos2.bin


BIN
Pika/engineResources/poza.snapshot


BIN
Pika/engineResources/test.recording


BIN
Pika/engineResources/test.snapshot


+ 7 - 8
Pika/gameplay/containers/pikaGameplay.h

@@ -1,6 +1,5 @@
 #pragma once
 
-#include <iostream>
 #include <gl2d/gl2d.h>
 #include <imgui.h>
 #include <baseContainer.h>
@@ -19,7 +18,7 @@ struct Gameplay : public Container
 
 	gl2d::Renderer2D renderer;
 
-	float *r =0;
+	float *r = 0;
 
 	//todo user can request imgui ids; shortcut manager context; allocators
 	static ContainerStaticInfo containerInfo()
@@ -52,7 +51,7 @@ struct Gameplay : public Container
 	{
 		renderer.create();
 		//pika::initShortcutApi();
-		r = new float(0);
+		r = new float;
 
 		//void *test = new char[pika::MB(10)]; //todo let the allocator tell the engine somehow that it is out of memory
 	}
@@ -64,17 +63,17 @@ struct Gameplay : public Container
 
 		glClear(GL_COLOR_BUFFER_BIT);
 
-		if (pika::shortcut(input, "Ctrl + S"))
+		//if (pika::shortcut(input, "Ctrl + S"))
+		if (input.buttons[pika::Button::S].released())
 		{
-			std::cout << "save \n";
+			requestedInfo.consoleWrite("save\n");
 		}
 
-		//std::cout << "save\n";
 
 
 		if (input.buttons[pika::Button::P].held())
 		{
-			std::cout << input.deltaTime;
+			requestedInfo.consoleWrite(std::to_string(input.deltaTime).c_str());
 		}
 
 
@@ -83,7 +82,7 @@ struct Gameplay : public Container
 
 		*r += input.deltaTime * 4.f;
 
-		renderer.renderRectangle({10, 10, 100, 100}, Colors_Red, {}, *r);
+		renderer.renderRectangle({10, 10, 100, 100}, Colors_Blue, {}, *r);
 
 		//if (input.lMouse.pressed())
 		//{

+ 2 - 3
Pika/resources/logs.txt

@@ -1,3 +1,2 @@
-#2022-10-23 13:01:27: Created container: Gameplay
-#2022-10-23 13:02:01: Reloaded dll
-#2022-10-23 13:02:08: Destroyed continer: Gameplay #1
+#2022-10-31 11:04:19: Created container: Gameplay
+#2022-10-31 11:16:06: Destroyed continer: Gameplay #1