6 Commits

Author SHA1 Message Date
Mohamed Ashraf e1a20497e8 i'm stupid 2026-03-25 10:05:03 +04:00
Mohamed Ashraf ac1fea0720 it compile 2026-03-25 10:00:01 +04:00
Mohamed Ashraf 8855266638 Not to mention most commit messages are just things like "skjdfhaufhafalkfjdashf". 2026-03-25 09:51:43 +04:00
Mohamed Ashraf 2f53275462 ficks directx maht 2026-03-25 09:32:20 +04:00
Mohamed Ashraf 1408a56ddc wawawawawawawa
forgot to enabel some stuff
2026-03-25 09:28:39 +04:00
Mohamed Ashraf b04b2d70fc redoing everything 2026-03-25 09:14:52 +04:00
14 changed files with 96102 additions and 34 deletions
@@ -10,6 +10,11 @@
#include "../../Minecraft.World/Blocks/Tile.h" #include "../../Minecraft.World/Blocks/Tile.h"
#include "../../Minecraft.World/Level/WaterLevelChunk.h" #include "../../Minecraft.World/Level/WaterLevelChunk.h"
#if defined(__EMSCRIPTEN__)
// eh... I should've enabled wasm64
#define InterlockedCompareExchangeRelease InterlockedCompareExchangeRelease64
#endif
MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) { MultiPlayerChunkCache::MultiPlayerChunkCache(Level* level) {
XZSIZE = level->dimension->getXZSize(); // 4J Added XZSIZE = level->dimension->getXZSize(); // 4J Added
XZOFFSET = XZSIZE / 2; // 4J Added XZOFFSET = XZSIZE / 2; // 4J Added
@@ -31,7 +31,11 @@ int strcasecmp(const char* a, const char* b) {
return ca - cb; return ca - cb;
} }
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#ifndef __EMSCRIPTEN__
#include "miniaudio.h" #include "miniaudio.h"
#else
#include "../../Emscripten/miniaudio.h"
#endif // __EMSCRIPTEN__
#undef STB_VORBIS_HEADER_ONLY #undef STB_VORBIS_HEADER_ONLY
#include "stb_vorbis.c" #include "stb_vorbis.c"
#endif #endif
@@ -3,7 +3,11 @@ class Mob;
class Options; class Options;
using namespace std; using namespace std;
#include "../../Minecraft.World/Util/SoundTypes.h" #include "../../Minecraft.World/Util/SoundTypes.h"
#ifndef __EMSCRIPTEN__
#include "./miniaudio.h" #include "./miniaudio.h"
#else
#include "../../Emscripten/miniaudio.h"
#endif
constexpr float SFX_3D_MIN_DISTANCE = 1.0f; constexpr float SFX_3D_MIN_DISTANCE = 1.0f;
constexpr float SFX_3D_MAX_DISTANCE = 16.0f; constexpr float SFX_3D_MAX_DISTANCE = 16.0f;
constexpr float SFX_3D_ROLLOFF = 0.5f; constexpr float SFX_3D_ROLLOFF = 0.5f;
File diff suppressed because it is too large Load Diff
@@ -99,6 +99,8 @@
#elif defined(_M_ARM) || defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || \ #elif defined(_M_ARM) || defined(_M_ARM64) || defined(_M_HYBRID_X86_ARM64) || \
defined(_M_ARM64EC) || __arm__ || __aarch64__ defined(_M_ARM64EC) || __arm__ || __aarch64__
#define _XM_ARM_NEON_INTRINSICS_ #define _XM_ARM_NEON_INTRINSICS_
#elif defined(__EMSCRIPTEN__)
#define _XM_NO_INTRINSICS_
#elif !defined(_XM_NO_INTRINSICS_) #elif !defined(_XM_NO_INTRINSICS_)
#error DirectX Math does not support this target #error DirectX Math does not support this target
#endif #endif
@@ -23,7 +23,9 @@
#include <stdio.h> #include <stdio.h>
#include <sys/time.h> #include <sys/time.h>
#include <locale> #include <locale>
#ifndef __EMSCRIPTEN__
#include <linux/mman.h> #include <linux/mman.h>
#endif // __EMSCRIPTEN__
#include <sys/mman.h> #include <sys/mman.h>
#include <codecvt> #include <codecvt>
+12 -2
View File
@@ -46,7 +46,7 @@ platform_sources += run_command(
).stdout().strip().split('\n') ).stdout().strip().split('\n')
# linux-specific files (everything in Platform/Linux) # linux-specific files (everything in Platform/Linux)
if host_machine.system() == 'linux' if host_machine.system() == 'linux' or host_machine.system() == 'emscripten'
platform_sources += run_command( platform_sources += run_command(
'sh', '-c', 'sh', '-c',
'find "' 'find "'
@@ -56,6 +56,15 @@ if host_machine.system() == 'linux'
).stdout().strip().split('\n') ).stdout().strip().split('\n')
endif endif
is_emscripten = host_machine.system() == 'emscripten'
emcc_link_args = []
if is_emscripten
emcc_link_args += ['--preload-file', meson.global_source_root() + '/build/Minecraft.Client/Common@Common']
emcc_link_args += ['--shell-file', meson.global_source_root() + '/scripts/shell.html']
emcc_link_args += ['-o 4JCraft.html']
endif
client_dependencies = [ client_dependencies = [
render_dep, render_dep,
input_dep, input_dep,
@@ -67,7 +76,7 @@ client_dependencies = [
glu_dep, glu_dep,
thread_dep, thread_dep,
thread_dep, thread_dep,
dependency('zlib'), zlib_dep,
miniaudio_dep miniaudio_dep
] ]
@@ -101,6 +110,7 @@ client = executable('Minecraft.Client',
'-DUNICODE', '-D_UNICODE', '-DUNICODE', '-D_UNICODE',
'-include', meson.current_source_dir() / 'Platform/stdafx.h', '-include', meson.current_source_dir() / 'Platform/stdafx.h',
], ],
link_args: emcc_link_args,
c_args : global_cpp_defs + ['-DUNICODE', '-D_UNICODE'], c_args : global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
install : true, install : true,
install_dir : '' install_dir : ''
Submodule Minecraft.World/Emscripten/md5 added at d8e299482a
+10 -5
View File
@@ -1,14 +1,16 @@
#include "../Platform/stdafx.h" #include "../Platform/stdafx.h"
#if defined(_WIN32)
#include <xhash>
#else
#include <openssl/md5.h>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
#if defined(_WIN32)
#include <xhash>
#elif defined (__EMSCRIPTEN__)
// no.
#else
#include <openssl/md5.h>
#include <openssl/evp.h>
#endif // _WIN32 #endif // _WIN32
#include "Hasher.h" #include "Hasher.h"
#include <openssl/evp.h>
Hasher::Hasher(std::wstring& salt) { this->salt = salt; } Hasher::Hasher(std::wstring& salt) { this->salt = salt; }
@@ -29,6 +31,9 @@ std::wstring Hasher::getHash(std::wstring& name) {
//{ //{
// throw new RuntimeException(e); // throw new RuntimeException(e);
//} //}
#elif defined(__EMSCRIPTEN__)
std::wstring s = std::wstring(salt).append(name);
return s;
#else #else
// adapted from a SSL example // adapted from a SSL example
std::wstring combined = salt + name; std::wstring combined = salt + name;
+6 -2
View File
@@ -46,8 +46,12 @@ lib_world = static_library('Minecraft.World',
], ],
) )
zlib_dep = dependency('zlib') is_emscripten = host_machine.system() == 'emscripten'
crypto_dep = dependency('libcrypto') # for MD5 in Hasher.cpp on Linux if is_emscripten
crypto_dep = declare_dependency()
else
crypto_dep = dependency('libcrypto') # for MD5 in Hasher.cpp on Linux
endif
world_dep = declare_dependency( world_dep = declare_dependency(
link_with : lib_world, link_with : lib_world,
+43 -6
View File
@@ -17,13 +17,26 @@ python = pymod.find_installation('python3', required: true)
cc = meson.get_compiler('cpp') cc = meson.get_compiler('cpp')
# system deps # system deps
gl_dep = dependency('gl') if host_machine.system() == 'emscripten'
glu_dep = dependency('glu') # These are handled in Emscripten via -sUSE_<whatever>
sdl2_dep = dependency('sdl2') # Yes.. i know sdl3 is out, but there's not point upgrading right now except when gl_dep = declare_dependency()
glu_dep = declare_dependency()
sdl2_dep = declare_dependency()
thread_dep = declare_dependency()
zlib_dep = declare_dependency()
miniaudio_dep = declare_dependency()
else
gl_dep = dependency('gl')
glu_dep = dependency('glu')
sdl2_dep = dependency('sdl2') # Yes.. i know sdl3 is out, but there's not point upgrading right now except when
# someone is gonna ask me "Hey juicey can you make it SDL3?" and i'd be like fuck you and still do it. # someone is gonna ask me "Hey juicey can you make it SDL3?" and i'd be like fuck you and still do it.
thread_dep = dependency('threads') thread_dep = dependency('threads')
miniaudio_dep = dependency('miniaudio') zlib_dep = dependency('zlib')
miniaudio_dep = dependency('miniaudio')
endif
stb = subproject('stb').get_variable('stb_inc') stb = subproject('stb').get_variable('stb_inc')
# compile flags (chagne ts juicey) # compile flags (chagne ts juicey)
global_cpp_args = [ global_cpp_args = [
'-fpermissive', '-fpermissive',
@@ -31,6 +44,29 @@ global_cpp_args = [
'-pipe', # use pipes instead of temp files between compiler stages '-pipe', # use pipes instead of temp files between compiler stages
] ]
if host_machine.system() == 'emscripten'
add_project_arguments(
'-pthread',
'--use-port=zlib',
'-sUSE_SDL=2',
'--use-port=sdl2',
language: 'cpp'
)
add_project_link_arguments(
'-sUSE_SDL=2',
'-sUSE_WEBGL2=1',
'-sLEGACY_GL_EMULATION=1',
'-sALLOW_MEMORY_GROWTH=1',
'-sPTHREAD_POOL_SIZE=4',
'-sERROR_ON_UNDEFINED_SYMBOLS=0',
'-sASSERTIONS=0',
'--use-port=zlib',
'--use-port=sdl2',
language: 'cpp'
)
endif
# global ccp defs type shi # global ccp defs type shi
global_cpp_defs = [ global_cpp_defs = [
'-DSPLIT_SAVES', '-DSPLIT_SAVES',
@@ -41,7 +77,8 @@ global_cpp_defs = [
'-DDEBUG', '-DDEBUG',
] ]
if host_machine.system() == 'linux' # DecalOverdose: yes i know it's bad to do this but I don't know a better way to do this.
if host_machine.system() == 'linux' or host_machine.system() == 'emscripten'
global_cpp_defs += [ global_cpp_defs += [
'-Dlinux', '-Dlinux',
'-D__linux', '-D__linux',
+15
View File
@@ -0,0 +1,15 @@
[binaries]
c = 'emcc'
cpp = 'em++'
ar = 'emar'
strip = 'emstrip'
[built-in options]
c_args = []
c_link_args = []
[host_machine]
system = 'emscripten'
cpu_family = 'wasm32'
cpu = 'wasm32'
endian = 'little'
+115
View File
@@ -0,0 +1,115 @@
<!doctype html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Emscripten-Generated Code</title>
<style>{{{ SHELL_CSS }}}</style>
</head>
<body>
<a href="http://emscripten.org">{{{ SHELL_LOGO }}}</a>
<div class="spinner" id='spinner'></div>
<div class="emscripten" id="status">Downloading...</div>
<span id='controls'>
<span><input type="checkbox" id="resize">Resize canvas</span>
<span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer &nbsp;&nbsp;&nbsp;</span>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked,
document.getElementById('resize').checked)">
</span>
</span>
<div class="emscripten">
<progress value="0" max="100" id="progress" hidden=1></progress>
</div>
<div class="emscripten_border">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
<textarea id="output" rows="8"></textarea>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var spinnerElement = document.getElementById('spinner');
var canvasElement = document.getElementById('canvas');
var outputElement = document.getElementById('output');
if (outputElement) outputElement.value = ''; // clear browser cache
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvasElement.addEventListener('webglcontextlost', (e) => {
alert('WebGL context lost. You will need to reload the page.');
e.preventDefault();
}, false);
var setStatus = (text) => {
if (!setStatus.last) setStatus.last = { time: Date.now(), text: '' };
if (text === setStatus.last.text) return;
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
var now = Date.now();
// if this is a progress update, skip it if too soon
if (m && now - setStatus.last.time < 30) return;
setStatus.last.time = now;
setStatus.last.text = text;
if (m) {
text = m[1];
progressElement.value = parseInt(m[2])*100;
progressElement.max = parseInt(m[4])*100;
progressElement.hidden = false;
spinnerElement.hidden = false;
} else {
progressElement.value = null;
progressElement.max = null;
progressElement.hidden = true;
if (!text) spinnerElement.style.display = 'none';
}
statusElement.innerHTML = text;
};
#if MODULARIZE && !EXPORT_ES6
var moduleArgs = {
#else
var Module = {
#endif
print(...args) {
console.log(...args);
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&amp;");
//text = text.replace(/</g, "&lt;");
//text = text.replace(/>/g, "&gt;");
//text = text.replace('\n', '<br>', 'g');
if (outputElement) {
var text = args.join(' ');
outputElement.value += text + "\n";
outputElement.scrollTop = outputElement.scrollHeight; // focus on bottom
}
},
canvas: canvasElement,
setStatus: setStatus,
totalDependencies: 0,
monitorRunDependencies(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
setStatus(left ? 'Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')' : 'All downloads complete.');
}
};
setStatus('Downloading...');
window.onerror = (event) => {
// TODO: do not warn on ok events like simulating an infinite loop or exitStatus
setStatus('Exception thrown, see JavaScript console');
spinnerElement.style.display = 'none';
setStatus = (text) => {
if (text) console.error('[post-exception status] ' + text);
};
};
</script>
{{{ SCRIPT }}}
#if MODULARIZE && !EXPORT_ES6
<script type='text/javascript'>
{{{ EXPORT_NAME }}}(moduleArgs);
</script>
#endif
</body>
</html>