Browse Source

small fixes

vlod 8 months ago
parent
commit
3da79e7c58

+ 4 - 1
Pika/core/pikaSTD/logs/log.cpp

@@ -2,12 +2,13 @@
 #include <fstream>
 #include <chrono>
 #include <iomanip>
+#include <sstream>
 
 void pika::LogManager::init(std::string name)
 {
 
 	this->name = name;
-	bool firstLog = 0;
+	firstLog = 0;
 	
 }
 
@@ -56,6 +57,8 @@ std::stringstream formatLog(const char *l, int type)
 
 void pika::LogManager::logToFile(const char *l, int type)
 {
+	if (name == "") { name = DefaultLogFile; }
+
 	//todo unlickely atribute
 	if (!firstLog)
 	{

+ 1 - 2
Pika/core/pikaSTD/logs/log.h

@@ -17,7 +17,6 @@ namespace pika
 		void init(std::string name);
 
 		
-
 		//this will be dependent on the configuration of the project. 
 		void log(const char *l, int type = pika::logNormal);
 		
@@ -25,8 +24,8 @@ namespace pika
 		std::string name = "";
 		bool firstLog = 0;
 
-		std::deque<std::string> internalLogs;
 		static constexpr int maxInternalLogCount = 200;
+		std::deque<std::string> internalLogs; //used to print the logs in a internal console
 
 		
 		pika::PushNotificationManager *pushNotificationManager = 0;

+ 1 - 0
Pika/core/pikaSTD/stringManipulation/stringManipulation.cpp

@@ -4,6 +4,7 @@
 namespace pika
 {
 
+	//todo probably should also add a /0 at the end  + TAKE CARE OF SIZE!!!!
 	void removeCharacters(char *dest, const char *source, const char *charsToRemove, size_t destSize)
 	{
 		int write = 0;

+ 2 - 0
Pika/gameplay/containers.h

@@ -46,6 +46,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 #include "containers/physicsTest/logo.h"
 
 #include "containers/angryBirds/angryBirds.h"
+#include "containers/milk/milk.h"
 
 #if PIKA_PRODUCTION == 1
 
@@ -78,6 +79,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(MarioEditor) \
 	PIKA_DECLARE_CONTAINER(MarioNeuralTrainer) \
 	PIKA_DECLARE_CONTAINER(McDungeonsGameplay) \
+	PIKA_DECLARE_CONTAINER(Milk) \
 	PIKA_DECLARE_CONTAINER(MarioNeuralVizualizer) 
 	//PIKA_DECLARE_CONTAINER(McDungeonsEditor)
 	//PIKA_DECLARE_CONTAINER(McDungeonsMenu)

+ 156 - 0
Pika/gameplay/containers/milk/milk.h

@@ -0,0 +1,156 @@
+#pragma once
+
+#include <gl2d/gl2d.h>
+#include <gl3d.h>
+#include <imgui.h>
+#include <baseContainer.h>
+#include <shortcutApi/shortcutApi.h>
+#include <pikaSizes.h>
+#include <imgui_spinner.h>
+#include <engineLibraresSupport/engineGL3DSupport.h>
+
+
+struct Milk: public Container
+{
+
+	
+
+	//todo user can request imgui ids; shortcut manager context; allocators
+	static ContainerStaticInfo containerInfo()
+	{
+		ContainerStaticInfo info = {};
+		info.defaultHeapMemorySize = pika::MB(100);
+
+		info.requestImguiFbo = true;
+		info.requestImguiIds = 1;
+
+		return info;
+	}
+
+	gl3d::Renderer3D renderer;
+	gl3d::Model helmetModel;
+	gl3d::Entity helmetEntity;
+	pika::gl3d::General3DEditor editor;
+
+	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
+	{
+	
+		//glEnable(GL_DEBUG_OUTPUT);
+		//glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
+		//glDebugMessageCallback(gl3d::glDebugOutput, &renderer.errorReporter);
+		//glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
+
+
+		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
+		renderer.fileOpener.userData = &requestedInfo;
+		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
+		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
+		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
+
+		renderer.init(1, 1, PIKA_RESOURCES_PATH "BRDFintegrationMap.png", requestedInfo.requestedFBO.fbo);
+
+		renderer.adaptiveResolution.useAdaptiveResolution = false;
+
+		//renderer.skyBox = renderer.atmosfericScattering({0.2,1,0.3}, {0.9,0.1,0.1}, {0.4, 0.4, 0.8}, 0.8f); //todo a documentation
+		//todo api for skybox stuff
+		//renderer.skyBox.color = {0.2,0.3,0.9};
+
+		//const char *names[6] =
+		//{	PIKA_RESOURCES_PATH "/skyBoxes/ocean/right.jpg",
+		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/left.jpg",
+		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/top.jpg",
+		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/bottom.jpg",
+		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/front.jpg",
+		//	PIKA_RESOURCES_PATH "/skyBoxes/ocean/back.jpg"};
+		//
+		//renderer.skyBox = renderer.loadSkyBox(names);
+		//renderer.skyBox.color = {0.2,0.3,0.8};
+
+		renderer.skyBox = renderer.loadHDRSkyBox(PIKA_RESOURCES_PATH "/skyBoxes/canary_wharf_2k.hdr");
+		renderer.skyBox.color = {0.4,0.4,0.4};
+
+
+		helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "helmet/helmet.obj", gl3d::TextureLoadQuality::maxQuality, 1.f);
+		//helmetModel = renderer.loadModel(PIKA_RESOURCES_PATH "/knight/uploads_files_1950170_Solus_the_knight.gltf", 1.f);
+
+		
+		renderer.createDirectionalLight({-1,-0.5,-0.2});
+
+
+		gl3d::Transform t;
+		t.position = {0, 0, -3};
+		t.rotation = {1.5, 0 , 0};
+
+		helmetEntity = renderer.createEntity(helmetModel, t);
+
+		return true;
+	}
+
+	bool update(pika::Input input, pika::WindowState windowState,
+		RequestedContainerInfo &requestedInfo)
+	{
+		
+		//editor.update(requestedInfo.requestedImguiIds, renderer, input, 5, requestedInfo, {windowState.windowW,windowState.windowH});
+
+
+		renderer.setErrorCallback(&errorCallbackCustom, &requestedInfo);
+		renderer.fileOpener.userData = &requestedInfo;
+		renderer.fileOpener.readEntireFileBinaryCallback = readEntireFileBinaryCustom;
+		renderer.fileOpener.readEntireFileCallback = readEntireFileCustom;
+		renderer.fileOpener.fileExistsCallback = defaultFileExistsCustom;
+
+
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		glEnable(GL_DEPTH_TEST);
+
+		renderer.updateWindowMetrics(windowState.windowW, windowState.windowH);
+		renderer.camera.aspectRatio = (float)windowState.windowW / windowState.windowH; //todo do this in update
+		
+		{
+			static glm::dvec2 lastMousePos = {};
+			if (input.rMouse.held())
+			{
+				glm::dvec2 currentMousePos = {input.mouseX, input.mouseY};
+
+				float speed = 0.8f;
+
+				glm::vec2 delta = lastMousePos - currentMousePos;
+				delta *= speed * input.deltaTime;
+
+				renderer.camera.rotateCamera(delta);
+
+				lastMousePos = currentMousePos;
+			}
+			else
+			{
+				lastMousePos = {input.mouseX, input.mouseY};
+			}
+		}
+		
+
+		renderer.render(input.deltaTime);
+
+
+		glDisable(GL_DEPTH_TEST);
+
+
+		//if (!ImGui::Begin("Test window"))
+		//{
+		//	ImGui::End();
+		//	return;
+		//}
+		//
+		//auto t = renderer.getEntityMeshMaterialTextures(helmetEntity, 0);
+		//
+		//ImGui::Image((void*)renderer.getTextureOpenglId(t.albedoTexture), {200, 200});
+		//
+		//ImGui::End();
+
+		return true;
+	}
+
+};
+
+//todo flag to clear screen from engine
+//todo error popup
+//todo error popup disable in release

+ 26 - 16
Pika/gameplay/containers/physicsTest/physicsTest.h

@@ -70,10 +70,10 @@ struct PhysicsTest: public Container
 
 		physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 9.81) * 100.f;
 		//physicsEngine.simulationphysicsSettings.gravity = glm::vec2(0, 0);
-		physicsEngine.simulationphysicsSettings.airDragCoeficient = 0.01f;
+		//physicsEngine.simulationphysicsSettings.airDragCoeficient = 0.01f;
 		//physicsEngine.collisionChecksCount = 1;
 
-		for (int i = 0; i < 0; i++)
+		for (int i = 0; i < 2; i++)
 		{
 			//if (i == 1) { mass = 0; }
 
@@ -130,7 +130,7 @@ struct PhysicsTest: public Container
 
 
 		//rope
-		if(0)
+		if(1)
 		{
 			auto bodyA = physicsEngine.addBody({200, 800}, ph2d::createCircleCollider({20}));
 			physicsEngine.bodies[bodyA].flags.setKinematic(true);
@@ -138,7 +138,7 @@ struct PhysicsTest: public Container
 			for (int i = 0; i < 25; i++)
 			{
 				auto bodyB = physicsEngine.addBody({200 + i * 45, 800}, ph2d::createCircleCollider({20}));
-				physicsEngine.addConstrain({bodyA, bodyB, 35, 50000 * 1.2});
+				physicsEngine.addConstrain({bodyA, bodyB, 40, 5000 * 1.2});
 				bodyA = bodyB;
 				ropeIds.insert(bodyA);
 
@@ -152,7 +152,7 @@ struct PhysicsTest: public Container
 
 		//physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
 
-		if(1)
+		if(0)
 		{
 			auto b = physicsEngine.addBody({500, 200}, ph2d::createConvexPolygonCollider(shape, 5));
 			auto body = physicsEngine.addBody({500, 500}, ph2d::createCircleCollider({100}));
@@ -168,6 +168,15 @@ struct PhysicsTest: public Container
 			//physicsEngine.bodies[body].flags.setFreezeRotation();
 		}
 
+		{
+			auto body = physicsEngine.addBody({500, 500}, ph2d::createBoxCollider({200, 200}));
+			//physicsEngine.bodies[body].flags.setFreezeRotation();
+
+			body = physicsEngine.addBody({420, 200}, ph2d::createCircleCollider({50}));
+			//physicsEngine.bodies[body].flags.setFreezeRotation();
+
+		}
+
 		//physicsEngine.addBody({500, 1100}, 
 		//	ph2d::createBoxCollider({1100, 10}));
 		
@@ -346,6 +355,7 @@ struct PhysicsTest: public Container
 			if (simulate)
 			{
 				physicsEngine.collisionChecksCount = 8;
+				physicsEngine.setFixedTimeStamp = 0;
 				physicsEngine.runSimulation(input.deltaTime);
 			}
 			else
@@ -363,21 +373,21 @@ struct PhysicsTest: public Container
 				auto right = b.getAABB().max().x;
 				auto top = b.getAABB().min().y;
 
-				if (bottom > floorPos)
-				{
-					float diff = bottom - floorPos;
-					b.motionState.pos.y -= diff;
-					b.motionState.lastPos = b.motionState.pos;
-				
-					b.motionState.velocity.y *= -0.2f;
-				}
+				//if (bottom > floorPos)
+				//{
+				//	float diff = bottom - floorPos;
+				//	b.motionState.pos.y -= diff;
+				//	b.motionState.lastPos = b.motionState.pos;
+				//
+				//	b.motionState.velocity.y *= -0.2;
+				//}
 
 				if (left < 0)
 				{
 					b.motionState.pos.x -= left;
 					b.motionState.lastPos = b.motionState.pos;
 
-					b.motionState.velocity.x *= -0.9;
+					b.motionState.velocity.x *= -1;
 				}
 
 				if (right > rightPos)
@@ -385,7 +395,7 @@ struct PhysicsTest: public Container
 					b.motionState.pos.x -= right - rightPos;
 					b.motionState.lastPos = b.motionState.pos;
 
-					b.motionState.velocity.x *= -0.9;
+					b.motionState.velocity.x *= -1;
 				}
 
 				if (top < 0)
@@ -393,7 +403,7 @@ struct PhysicsTest: public Container
 					b.motionState.pos.y -= top;
 					b.motionState.lastPos = b.motionState.pos;
 
-					b.motionState.velocity.y *= -0.9;
+					b.motionState.velocity.y *= -1;
 				}
 			}
 		}

+ 2 - 2
Pika/resources/logs.txt

@@ -1,2 +1,2 @@
-#2024-12-05 15:58:02: Created container: AngryBirds
-#2024-12-05 16:01:25: Destroyed continer: AngryBirds #1
+#2025-03-27 15:00:39: Created container: Milk
+#2025-03-27 15:00:41: Destroyed continer: Milk #1

+ 1 - 1
Pika/thirdparty/ph2d/src/ph2d.cpp

@@ -1489,6 +1489,7 @@ namespace ph2d
 					glm::vec2 b = collider.convexPolygon.vertexesObjectSpace[(i + 1) % c];
 					mass += cross(a, b) / 2.f;
 				}
+				return mass;
 			}
 			break;
 
@@ -1559,7 +1560,6 @@ bool overlap(ph2d::Body &a, ph2d::Body &b)
 void ph2d::MotionState::applyImpulseObjectPosition(glm::vec2 impulse, glm::vec2 contactVector, BodyFlags flags)
 {
 
-
 	if (mass != 0 && mass != INFINITY )
 	{
 		glm::vec2 toAdd = (1.0f / mass) * impulse;