aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvoid_17 <heroerror3@gmail.com>2026-03-02 14:51:05 +0700
committervoid_17 <heroerror3@gmail.com>2026-03-02 14:51:05 +0700
commitdef238ff08dd90a06e0916876601f9a03f22c510 (patch)
tree54c2755099646b8bcc6480a3f4774fe0550b47c5
parentdea1d620744b6d6eb8441f91e905facbee277156 (diff)
Fix C-style struct functor definitions
-rw-r--r--Minecraft.World/File.cpp40
-rw-r--r--Minecraft.World/File.h28
-rw-r--r--Minecraft.World/JavaIntHash.h66
-rw-r--r--Minecraft.World/Player.h16
-rw-r--r--Minecraft.World/TickNextTickData.cpp4
-rw-r--r--Minecraft.World/TickNextTickData.h32
6 files changed, 102 insertions, 84 deletions
diff --git a/Minecraft.World/File.cpp b/Minecraft.World/File.cpp
index ae0cf96c..1d66bfeb 100644
--- a/Minecraft.World/File.cpp
+++ b/Minecraft.World/File.cpp
@@ -12,13 +12,13 @@
const wchar_t File::pathSeparator = L'\\';
#ifdef _XBOX
-const wstring File::pathRoot = L"GAME:"; // Path root after pathSeparator has been removed
+const std::wstring File::pathRoot = L"GAME:"; // Path root after pathSeparator has been removed
#else
-const wstring File::pathRoot = L""; // Path root after pathSeparator has been removed
+const std::wstring File::pathRoot = L""; // Path root after pathSeparator has been removed
#endif
//Creates a new File instance from a parent abstract pathname and a child pathname string.
-File::File( const File &parent, const wstring& child )
+File::File( const File &parent, const std::wstring& child )
{
m_abstractPathName = parent.getPath() + pathSeparator + child;
}
@@ -67,7 +67,7 @@ File::File( const wstring& pathname ) //: parent( NULL )
*/
}
-File::File( const wstring& parent, const wstring& child ) //: m_abstractPathName( child )
+File::File( const std::wstring& parent, const std::wstring& child ) //: m_abstractPathName( child )
{
m_abstractPathName = pathRoot + pathSeparator + parent + pathSeparator + child;
//this->parent = new File( parent );
@@ -149,9 +149,9 @@ bool File::mkdir() const
//
bool File::mkdirs() const
{
- vector<wstring> path = stringSplit( m_abstractPathName, pathSeparator );
+ std::vector<std::wstring> path = stringSplit( m_abstractPathName, pathSeparator );
- wstring pathToHere = L"";
+ std::wstring pathToHere = L"";
AUTO_VAR(itEnd, path.end());
for( AUTO_VAR(it, path.begin()); it != itEnd; it++ )
{
@@ -237,7 +237,7 @@ bool File::renameTo(File dest)
// 4J Stu - The wstringtofilename function returns a pointer to the same location in memory every time it is
// called, therefore we were getting sourcePath and destPath having the same value. The solution here is to
// make a copy of the sourcePath by storing it in a std::string
- string sourcePath = wstringtofilename(getPath());
+ std::string sourcePath = wstringtofilename(getPath());
const char *destPath = wstringtofilename(dest.getPath());
#ifdef _DURANGO
__debugbreak(); // TODO
@@ -272,9 +272,9 @@ bool File::renameTo(File dest)
//An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname.
//The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory,
//or if an I/O error occurs.
-vector<File *> *File::listFiles() const
+std::vector<File *> *File::listFiles() const
{
- vector<File *> *vOutput = new vector<File *>();
+ std::vector<File *> *vOutput = new vector<File *>();
// TODO 4J Stu - Also need to check for I/O errors?
if( !isDirectory() )
@@ -386,8 +386,8 @@ vector<File *> *File::listFiles() const
FindClose( hFind);
}
#else
- char path[MAX_PATH];
- sprintf( path, "%s\\*", wstringtofilename( getPath() ) );
+ char path[MAX_PATH] {};
+ snprintf( path, MAX_PATH, "%s\\*", wstringtofilename( getPath() ) );
HANDLE hFind = FindFirstFile( path, &wfd);
if(hFind != INVALID_HANDLE_VALUE)
{
@@ -415,13 +415,13 @@ vector<File *> *File::listFiles() const
//Returns:
//An array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname.
//The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
-vector<File *> *File::listFiles(FileFilter *filter) const
+std::vector<File *> *File::listFiles(FileFilter *filter) const
{
// TODO 4J Stu - Also need to check for I/O errors?
if( !isDirectory() )
return NULL;
- vector<File *> *vOutput = new vector<File *>();
+ std::vector<File *> *vOutput = new std::vector<File *>();
#ifdef __PS3__
const char *lpFileName=wstringtofilename(getPath());
@@ -521,7 +521,7 @@ bool File::isDirectory() const
//Returns the length of the file denoted by this abstract pathname. The return value is unspecified if this pathname denotes a directory.
//Returns:
//The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist
-__int64 File::length()
+int64_t File::length()
{
#ifdef __PS3__
//extern const char* getPS3HomePath();
@@ -624,7 +624,7 @@ __int64 File::length()
//Returns:
//A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970),
//or 0L if the file does not exist or if an I/O error occurs
-__int64 File::lastModified()
+int64_t File::lastModified()
{
WIN32_FILE_ATTRIBUTE_DATA fileInfoBuffer;
#ifdef _UNICODE
@@ -657,7 +657,7 @@ __int64 File::lastModified()
}
}
-const wstring File::getPath() const
+const std::wstring File::getPath() const
{
/*
wstring path;
@@ -672,7 +672,7 @@ const wstring File::getPath() const
return m_abstractPathName;
}
-wstring File::getName() const
+std::wstring File::getName() const
{
unsigned int sep = (unsigned int )(m_abstractPathName.find_last_of( this->pathSeparator ));
return m_abstractPathName.substr( sep + 1, m_abstractPathName.length() );
@@ -700,3 +700,9 @@ int File::hash_fnct(const File &k)
return (int) hashCode;
}
+
+int FileKeyHash::operator() (const File &k) const
+{ return File::hash_fnct(k); }
+
+bool FileKeyEq::operator() (const File &x, const File &y) const
+{ return File::eq_test(x,y); } \ No newline at end of file
diff --git a/Minecraft.World/File.h b/Minecraft.World/File.h
index 0b710cd4..ae07a4b7 100644
--- a/Minecraft.World/File.h
+++ b/Minecraft.World/File.h
@@ -1,5 +1,9 @@
#pragma once
-using namespace std;
+
+#include <cstdint>
+#include <vector>
+#include <string>
+
// 4J Stu - Represents java standard library class
class FileFilter;
@@ -24,11 +28,11 @@ public:
bool exists() const;
bool isFile() const;
bool renameTo(File dest);
- vector<File *> *listFiles() const; // Array
- vector<File *> *listFiles(FileFilter *filter) const;
+ std::vector<File *> *listFiles() const; // Array
+ std::vector<File *> *listFiles(FileFilter *filter) const;
bool isDirectory() const;
- __int64 length();
- __int64 lastModified();
+ int64_t length();
+ int64_t lastModified();
const wstring getPath() const; // 4J Jev: TODO
wstring getName() const;
@@ -43,14 +47,12 @@ private:
//File(vector<wstring> *path);
};
-typedef struct
+struct FileKeyHash
{
- int operator() (const File &k) const { return File::hash_fnct(k); }
-
-} FileKeyHash;
+ int operator() (const File &k) const;
+};
-typedef struct
+struct FileKeyEq
{
- bool operator() (const File &x, const File &y) const {return File::eq_test(x,y); }
-
-} FileKeyEq; \ No newline at end of file
+ bool operator() (const File &x, const File &y) const;
+}; \ No newline at end of file
diff --git a/Minecraft.World/JavaIntHash.h b/Minecraft.World/JavaIntHash.h
index 447b8052..fe608469 100644
--- a/Minecraft.World/JavaIntHash.h
+++ b/Minecraft.World/JavaIntHash.h
@@ -1,13 +1,15 @@
#pragma once
+#include <cstdint>
+
// Java doesn't have a default hash value for ints, however, the hashmap itself does some "supplemental" hashing, so
// our ints actually get hashed by code as implemented below. std templates *do* have a standard hash for ints, but it
// would appear to be a bit expensive so matching the java one for now anyway. This code implements the supplemental
// hashing that happens in java so we can match what their maps are doing with ints.
-typedef struct
+struct IntKeyHash
{
- int operator() (const int &k) const
+ inline int operator()(const int &k) const
{
int h = k;
h += ~(h << 9);
@@ -16,62 +18,64 @@ typedef struct
h ^= (((unsigned int)h) >> 10);
return h;
}
+};
-} IntKeyHash;
-
-typedef struct
+struct IntKeyEq
{
- bool operator() (const int &x, const int &y) const { return x==y; }
-} IntKeyEq;
-
+ inline bool operator()(const int &x, const int &y) const
+ { return x==y; }
+};
// This hash functor is taken from the IntHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather
// than implement the class itself
-typedef struct
+struct IntKeyHash2
{
- int operator() (const int &k) const
+ inline int operator()(const int &k) const
{
- unsigned int h = (unsigned int)k;
+ unsigned int h = static_cast<unsigned int>(k);
h ^= (h >> 20) ^ (h >> 12);
- return (int)(h ^ (h >> 7) ^ (h >> 4));
+ return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
}
-} IntKeyHash2;
+};
// This hash functor is taken from the LongHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather
// than implement the class itself
-typedef struct
+struct LongKeyHash
{
- int hash(const int &k) const
+ inline int hash(const int &k) const
{
- unsigned int h = (unsigned int)k;
+ unsigned int h = static_cast<unsigned int>(k);
h ^= (h >> 20) ^ (h >> 12);
- return (int)(h ^ (h >> 7) ^ (h >> 4));
+ return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
}
- int operator() (const __int64 &k) const
+ inline int operator()(const int64_t &k) const
{
- return hash((int) ( k ^ (((__uint64)k) >> 32 )));
+ return hash(static_cast<int>(k ^ ((static_cast<uint64_t>(k)) >> 32)));
}
-} LongKeyHash;
+};
-typedef struct
+struct LongKeyEq
{
- bool operator() (const __int64 &x, const __int64 &y) const { return x==y; }
-} LongKeyEq;
+ inline bool operator() (const int64_t &x, const int64_t &y) const
+ { return x == y; }
+};
-typedef struct
+enum eINSTANCEOF;
+struct eINSTANCEOFKeyHash
{
- int operator() (const eINSTANCEOF &k) const
+ int operator()(const eINSTANCEOF &k) const
{
- unsigned int h = (unsigned int)k;
+ unsigned int h = static_cast<unsigned int>(k);
h ^= (h >> 20) ^ (h >> 12);
- return (int)(h ^ (h >> 7) ^ (h >> 4));
+ return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
}
-} eINSTANCEOFKeyHash;
+};
-typedef struct
+struct eINSTANCEOFKeyEq
{
- bool operator() (const eINSTANCEOF &x, const eINSTANCEOF &y) const { return x==y; }
-} eINSTANCEOFKeyEq;
+ inline bool operator()(const eINSTANCEOF &x, const eINSTANCEOF &y) const
+ { return x == y; }
+};
diff --git a/Minecraft.World/Player.h b/Minecraft.World/Player.h
index c323bf05..185a70a7 100644
--- a/Minecraft.World/Player.h
+++ b/Minecraft.World/Player.h
@@ -539,13 +539,15 @@ private:
#endif
};
-typedef struct
+struct PlayerKeyHash
{
- int operator() (const shared_ptr<Player> k) const { return Player::hash_fnct (k); }
-
-} PlayerKeyHash;
+ inline int operator() (const shared_ptr<Player> k) const
+ { return Player::hash_fnct (k); }
+};
-typedef struct
+struct PlayerKeyEq
{
- bool operator() (const shared_ptr<Player> x, const shared_ptr<Player> y) const { return Player::eq_test (x, y); }
-} PlayerKeyEq;
+ inline bool operator() (const shared_ptr<Player> x, const shared_ptr<Player> y) const
+ { return Player::eq_test (x, y); }
+};
+
diff --git a/Minecraft.World/TickNextTickData.cpp b/Minecraft.World/TickNextTickData.cpp
index 95cab285..96771be1 100644
--- a/Minecraft.World/TickNextTickData.cpp
+++ b/Minecraft.World/TickNextTickData.cpp
@@ -2,7 +2,7 @@
#include "TickNextTickData.h"
-__int64 TickNextTickData::C = 0;
+int64_t TickNextTickData::C = 0;
TickNextTickData::TickNextTickData(int x, int y, int z, int tileId)
{
@@ -33,7 +33,7 @@ int TickNextTickData::hashCode() const
return (((x * 1024 * 1024) + (z * 1024) + y) * 256) + tileId;
}
-TickNextTickData *TickNextTickData::delay(__int64 l)
+TickNextTickData *TickNextTickData::delay(int64_t l)
{
this->m_delay = l;
return this;
diff --git a/Minecraft.World/TickNextTickData.h b/Minecraft.World/TickNextTickData.h
index 41ee99da..c83f6993 100644
--- a/Minecraft.World/TickNextTickData.h
+++ b/Minecraft.World/TickNextTickData.h
@@ -1,26 +1,28 @@
#pragma once
+#include <cstdint>
+
// 4J Stu - In Java TickNextTickData implements Comparable<TickNextTickData>
// We don't need to do that as it is only as helper for the java sdk sorting operations
class TickNextTickData
{
private:
- static __int64 C;
+ static int64_t C;
public:
int x, y, z, tileId;
- __int64 m_delay;
+ int64_t m_delay;
private:
- __int64 c;
+ int64_t c;
public:
TickNextTickData(int x, int y, int z, int tileId);
bool equals(const void *o) const;
int hashCode() const;
- TickNextTickData *delay(__int64 l);
+ TickNextTickData *delay(int64_t l);
int compareTo(const TickNextTickData *tnd) const;
static bool compare_fnct(const TickNextTickData &x, const TickNextTickData &y);
@@ -28,19 +30,21 @@ public:
static bool eq_test(const TickNextTickData &x, const TickNextTickData &y);
};
-typedef struct
+struct TickNextTickDataKeyHash
{
- int operator() (const TickNextTickData &k) const { return TickNextTickData::hash_fnct (k); }
-
-} TickNextTickDataKeyHash;
+ int operator() (const TickNextTickData &k) const
+ { return TickNextTickData::hash_fnct (k); }
+};
-typedef struct
+struct TickNextTickDataKeyEq
{
- bool operator() (const TickNextTickData &x, const TickNextTickData &y) const { return TickNextTickData::eq_test (x, y); }
-} TickNextTickDataKeyEq;
+ bool operator() (const TickNextTickData &x, const TickNextTickData &y) const
+ { return TickNextTickData::eq_test (x, y); }
+};
-typedef struct
+struct TickNextTickDataKeyCompare
{
- bool operator() (const TickNextTickData &x, const TickNextTickData &y) const { return TickNextTickData::compare_fnct (x, y); }
+ bool operator() (const TickNextTickData &x, const TickNextTickData &y) const
+ { return TickNextTickData::compare_fnct (x, y); }
-} TickNextTickDataKeyCompare; \ No newline at end of file
+}; \ No newline at end of file