aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/ZoneIo.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/ZoneIo.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.World/ZoneIo.cpp')
-rw-r--r--Minecraft.World/ZoneIo.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/Minecraft.World/ZoneIo.cpp b/Minecraft.World/ZoneIo.cpp
new file mode 100644
index 00000000..f1838c86
--- /dev/null
+++ b/Minecraft.World/ZoneIo.cpp
@@ -0,0 +1,48 @@
+#include "stdafx.h"
+#include "ByteBuffer.h"
+#include "ZoneIo.h"
+
+ZoneIo::ZoneIo(HANDLE channel, __int64 pos)
+{
+ this->channel = channel;
+ this->pos = pos;
+}
+
+void ZoneIo::write(byteArray bb, int size)
+{
+ ByteBuffer *buff = ByteBuffer::wrap(bb);
+// if (bb.length != size) throw new IllegalArgumentException("Expected " + size + " bytes, got " + bb.length); // 4J - TODO
+ buff->order(ZonedChunkStorage::BYTEORDER);
+ buff->position(bb.length);
+ buff->flip();
+ write(buff, size);
+ delete buff;
+}
+
+void ZoneIo::write(ByteBuffer *bb, int size)
+{
+ DWORD numberOfBytesWritten;
+ SetFilePointer(channel,(int)pos,NULL,NULL);
+ WriteFile(channel,bb->getBuffer(), bb->getSize(),&numberOfBytesWritten,NULL);
+ pos += size;
+}
+
+ByteBuffer *ZoneIo::read(int size)
+{
+ DWORD numberOfBytesRead;
+ byteArray bb = byteArray(size);
+ SetFilePointer(channel,(int)pos,NULL,NULL);
+ ByteBuffer *buff = ByteBuffer::wrap(bb);
+ // 4J - to investigate - why is this buffer flipped before anything goes in it?
+ buff->order(ZonedChunkStorage::BYTEORDER);
+ buff->position(size);
+ buff->flip();
+ ReadFile(channel, buff->getBuffer(), buff->getSize(), &numberOfBytesRead, NULL);
+ pos += size;
+ return buff;
+}
+
+void ZoneIo::flush()
+{
+ // 4J - was channel.force(false);
+} \ No newline at end of file