Browse Source

finished tema

vlod 1 year ago
parent
commit
aec493af4a

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

@@ -280,7 +280,8 @@ struct RequestedContainerInfo
 
 		return success;
 	}
-
+	
+	//todo version that returns a char vector
 	bool getFileSizeBinary(std::string_view name, size_t &size)
 	{
 		//PIKA_DEVELOPMENT_ONLY_ASSERT(getFileSizePointer, "get file size pointer not assigned");

+ 113 - 4
Pika/gameplay/containers/isometricGame/isometricGame.cpp

@@ -6,6 +6,7 @@
 #include <glui/glui.h>
 #include <deque>
 #include <unordered_map>
+#include <safeSave/safeSave.h>
 
 bool IsometricGame::create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 {
@@ -64,6 +65,69 @@ bool IsometricGame::create(RequestedContainerInfo &requestedInfo, pika::StaticSt
 			
 	}
 
+	size_t s = 0;
+	if (requestedInfo.getFileSizeBinary(PIKA_RESOURCES_PATH "iso/save.bin", s))
+	{
+		char *buffer = new char[s];
+		
+		if (requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "iso/save.bin", buffer, s))
+		{
+			sfs::SafeSafeKeyValueData data;
+
+			data.loadFromFileData(buffer, s);
+
+
+			bool good = true;
+
+			good = data.getFloat("life", life) == sfs::noError;
+
+			if (good)
+			{
+
+
+				good = data.getInt("redstoneCount", redstoneCount) == sfs::noError;
+				good = data.getInt("redstoneTorchesCount", redstoneTorchesCount) == sfs::noError;
+				good = data.getInt("foodCount", foodCount) == sfs::noError;
+				good = data.getInt("itemSelected", itemSelected) == sfs::noError;
+				good = data.getInt("currentLevel", currentLevel) == sfs::noError;
+				void *ptr = 0;
+				size_t s = 0;
+				good = data.getRawDataPointer("playerPosition", ptr, s) == sfs::noError;
+				good = s == sizeof(playerPosition);
+
+				if (good)
+				{
+					memcpy(&playerPosition, ptr, s);					
+				}
+				else { return 0; }
+
+				for (int i = 0; i < MAPS_COUNT; i++)
+				{
+					void *ptr = 0;
+					size_t s = 0;
+
+					data.getRawDataPointer("map" + std::to_string(i),
+						ptr, s);
+
+					good = s == sizeof(levels[i].mapData[0]) * levels[i].size.x
+						* levels[i].size.y * levels[i].size.z;
+
+					good = s == levels[i].mapData.size() * sizeof(levels[i].mapData[0]);
+
+					if (good)
+					{
+						memcpy(levels[i].mapData.data(), ptr, s);
+					}
+				}
+
+				if (!good) { return 0; }
+			}
+		}
+		
+		delete[] buffer;
+	}
+	
+
 	return true;
 }
 
@@ -171,7 +235,7 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 	}
 #pragma endregion
 
-	
+	life -= input.deltaTime * 0.004;
 	
 	IsometricGameEditor::Map &map = levels[currentLevel];
 
@@ -183,6 +247,7 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 	};
 
 	{
+
 		redstone.clear();
 		redstone.resize(map.size.x * map.size.y * map.size.z);
 
@@ -742,6 +807,8 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 					b->set(IsometricGameEditor::Blocks::redstoneTorch, 0);
 				}
 			}
+
+			saveData(requestedInfo);
 		}
 
 	}
@@ -769,6 +836,14 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 			glui::Frame f(uiBox);
 			renderer.renderRectangle(uiBox, {0.1,0.1,0.1,0.5});
 
+			{
+				auto healthBox = uiBox;
+				healthBox.y += healthBox.w;
+				healthBox.w *= 0.3;
+				healthBox.z *= life;
+				renderer.renderRectangle(healthBox, {0.9,0.1,0.1,0.5});
+			}
+
 			float boxSize = uiBox.z / 3.f;
 
 			if (redstoneCount)
@@ -787,7 +862,7 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 			{
 				renderer.renderRectangle({uiBox.x + boxSize * itemSelected, uiBox.y, boxSize, boxSize}, itemFrameSprite);
 			}
-
+			redstone;
 			if (redstoneCount)
 				renderer.renderText({uiBox.x + boxSize * 0.75, uiBox.y + boxSize * 0.75},
 				std::to_string(redstoneCount).c_str(), font, Colors_White);
@@ -828,11 +903,15 @@ bool IsometricGame::update(pika::Input input, pika::WindowState windowState, Req
 
 				if (IsometricGameEditor::pointInBox(glm::vec2(input.mouseX, input.mouseY), {uiBox.x + boxSize * 2, uiBox.y, boxSize, boxSize}))
 				{
-					itemSelected = 2; //toto eat
+					if (foodCount > 0)
+					{
+						foodCount--;
+						life = 1.f;
+					}
 				}
 			}
 
-
+			
 		}
 		renderer.popCamera();
 
@@ -860,3 +939,33 @@ void IsometricGame::destruct(RequestedContainerInfo &requestedInfo)
 	renderer.cleanup();
 
 }
+
+void IsometricGame::saveData(RequestedContainerInfo &requestedInfo)
+{
+
+	sfs::SafeSafeKeyValueData data;
+
+	data.setFloat("life", life);
+	data.setInt("redstoneCount", redstoneCount);
+	data.setInt("redstoneTorchesCount", redstoneTorchesCount);
+	data.setInt("foodCount", foodCount);
+	data.setInt("itemSelected", itemSelected);
+	data.setInt("currentLevel", currentLevel);
+
+	data.setRawData("playerPosition", &playerPosition[0], sizeof(playerPosition));
+
+
+	for (int i = 0; i < MAPS_COUNT; i++)
+	{
+		data.setRawData("map" + std::to_string(i),
+			levels[i].mapData.data(),
+			sizeof(levels[i].mapData[0]) * levels[i].size.x
+			* levels[i].size.y * levels[i].size.z
+		);
+	}
+
+	auto fileData = data.formatIntoFileData();
+
+	requestedInfo.writeEntireFileBinary(PIKA_RESOURCES_PATH "iso/save.bin", fileData.data(), fileData.size());
+
+}

+ 2 - 2
Pika/gameplay/containers/isometricGame/isometricGame.h

@@ -32,6 +32,7 @@ struct IsometricGame: public Container
 
 	gl2d::Texture itemFrameSprite;
 
+	float life = 1;
 
 	int redstoneCount = 0;
 	int redstoneTorchesCount = 0;
@@ -69,8 +70,6 @@ struct IsometricGame: public Container
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument);
 
 
-	int currentBlock = 0;
-
 	struct Block
 	{
 		unsigned char type;
@@ -100,4 +99,5 @@ struct IsometricGame: public Container
 
 	void destruct(RequestedContainerInfo &requestedInfo) override;
 
+	void saveData(RequestedContainerInfo &requestedInfo);
 };

+ 1 - 1
Pika/resources/3d/default.gl3d

@@ -1 +1 @@
-{"SSR":false,"SSRdata":{"maxRayDelta":0.6000000238418579,"maxRayStep":1.75,"maxSteps":20,"minRayStep":0.4000000059604645,"numBinarySearchSteps":7},"adaptiveResolution":false,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"colorCorrection":false,"exposure":1.7000000476837158,"frustumCulling":true,"fxaa":false,"fxaaData":{"edgeDarkTreshold":0.125,"edgeMinTreshold":0.02800000086426735,"iterations":12,"qualityMultiplyer":0.800000011920929,"subPixelQuality":0.949999988079071},"light subscatter":true,"normal mapping":true,"ssao":true,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}
+{"SSR":false,"SSRdata":{"maxRayDelta":0.6000000238418579,"maxRayStep":1.75,"maxSteps":20,"minRayStep":0.4000000059604645,"numBinarySearchSteps":7},"adaptiveResolution":false,"ambientb":1.0,"ambientg":1.0,"ambientr":1.0,"chromaticAberation":false,"chromaticAberationData":{"strength":20.0,"unfocusDistance":5.0},"colorCorrection":false,"exposure":1.7000000476837158,"frustumCulling":true,"fxaa":false,"fxaaData":{"edgeDarkTreshold":0.125,"edgeMinTreshold":0.02800000086426735,"iterations":12,"qualityMultiplyer":0.800000011920929,"subPixelQuality":0.949999988079071},"light subscatter":true,"normal mapping":true,"ssao":true,"ssaoData":{"bias":0.02500000037252903,"exponent":5.0,"radius":0.20000000298023224,"sampleCount":16}}

BIN
Pika/resources/iso/save.bin


+ 6 - 2
Pika/resources/logs.txt

@@ -1,2 +1,6 @@
-#2024-01-12 14:13:14: Created container: ThreeDGameExample
-#2024-01-12 14:13:32: Destroyed continer: ThreeDGameExample #1
+#2024-01-14 17:20:25: Created container: IsometricGame
+#2024-01-14 17:20:40: Destroyed continer: IsometricGame #1
+#2024-01-14 17:20:42: Created container: IsometricGame
+#2024-01-14 17:21:33: Destroyed continer: IsometricGame #2
+#2024-01-14 17:21:35: Created container: IsometricGame
+#2024-01-14 17:21:44: Destroyed continer: IsometricGame #3