rewrote & formatted meson, also added gles to renderer, no need to touch, it works, and it'll help for future support. basically a neat lil touch

This commit is contained in:
JuiceyDev 2026-03-28 15:21:52 +01:00 committed by Tropical
parent e2a6c3f92c
commit 4aa8106e52
4 changed files with 146 additions and 97 deletions

View file

@ -5,6 +5,7 @@
#include <GL/glu.h>
#include <GL/glext.h>
#include <dlfcn.h>
#include <vector>
#include "../../Minecraft.World/IO/Streams/IntBuffer.h"
#include "../../Minecraft.World/IO/Streams/FloatBuffer.h"
@ -27,7 +28,15 @@
#undef glReadPixels
#undef glActiveTexture
// _4j suffix shit (todo: make ts better)
// Helper functions & stuff
inline GLuint* getIntPtr(IntBuffer* buf) {
return buf ? (GLuint*)((int*)buf->getBuffer() + buf->position()) : nullptr;
}
inline GLvoid* getBytePtr(ByteBuffer* buf) {
return buf ? (GLvoid*)((char*)buf->getBuffer() + buf->position()) : nullptr;
}
// _4j suffix shit
int glGenTextures() {
GLuint id = 0;
::glGenTextures(1, &id);
@ -35,10 +44,11 @@ int glGenTextures() {
}
void glGenTextures_4J(IntBuffer* buf) {
GLuint id = 0;
::glGenTextures(1, &id);
buf->put((int)id);
buf->flip();
if (!buf) return;
int n = buf->limit() - buf->position();
if (n > 0) {
::glGenTextures(n, getIntPtr(buf));
}
}
void glDeleteTextures(int id) {
@ -47,10 +57,10 @@ void glDeleteTextures(int id) {
}
void glDeleteTextures_4J(IntBuffer* buf) {
if (buf && buf->limit() > 0) {
int id = buf->get(0);
GLuint uid = (GLuint)id;
::glDeleteTextures(1, &uid);
if (!buf) return;
int n = buf->limit() - buf->position();
if (n > 0) {
::glDeleteTextures(n, getIntPtr(buf));
}
}
@ -79,13 +89,13 @@ void glTexCoordPointer_4J(int size, int type, FloatBuffer* pointer) {
}
void glNormalPointer_4J(int type, ByteBuffer* pointer) {
::glNormalPointer((GLenum)type, 0, pointer->getBuffer());
::glNormalPointer((GLenum)type, 0, getBytePtr(pointer));
}
void glColorPointer_4J(int size, bool normalized, int stride,
ByteBuffer* pointer) {
(void)normalized;
::glColorPointer(size, GL_UNSIGNED_BYTE, stride, pointer->getBuffer());
::glColorPointer(size, GL_UNSIGNED_BYTE, stride, getBytePtr(pointer));
}
void glVertexPointer_4J(int size, int type, FloatBuffer* pointer) {
@ -100,20 +110,22 @@ void glEndList_4J(int dummy) {
void glTexImage2D_4J(int target, int level, int internalformat, int width,
int height, int border, int format, int type,
ByteBuffer* pixels) {
void* data = pixels ? pixels->getBuffer() : nullptr;
::glTexImage2D((GLenum)target, level, internalformat, width, height, border,
(GLenum)format, (GLenum)type, data);
(GLenum)format, (GLenum)type, getBytePtr(pixels));
}
void glCallLists_4J(IntBuffer* lists) {
if (!lists) return;
int count = lists->limit() - lists->position();
::glCallLists(count, GL_INT, lists->getBuffer());
if (count > 0) {
::glCallLists(count, GL_INT, getIntPtr(lists));
}
}
void glReadPixels_4J(int x, int y, int width, int height, int format, int type,
ByteBuffer* pixels) {
::glReadPixels(x, y, width, height, (GLenum)format, (GLenum)type,
pixels->getBuffer());
getBytePtr(pixels));
}
void glGetFloat(int pname, FloatBuffer* params) {
@ -173,11 +185,11 @@ static void initQueryFuncs() {
void glGenQueriesARB_4J(IntBuffer* buf) {
initQueryFuncs();
if (_glGenQueriesARB) {
GLuint id = 0;
_glGenQueriesARB(1, &id);
buf->put((int)id);
buf->flip();
if (_glGenQueriesARB && buf) {
int n = buf->limit() - buf->position();
if (n > 0) {
_glGenQueriesARB(n, getIntPtr(buf));
}
}
}
void glGenQueriesARB(IntBuffer* buf) { glGenQueriesARB_4J(buf); }
@ -196,11 +208,10 @@ void glEndQueryARB(int target) { glEndQueryARB_4J(target); }
void glGetQueryObjectuARB_4J(int id, int pname, IntBuffer* params) {
initQueryFuncs();
if (_glGetQueryObjectuivARB) {
GLuint val = 0;
_glGetQueryObjectuivARB((GLuint)id, (GLenum)pname, &val);
params->put((int)val);
params->flip();
if (_glGetQueryObjectuivARB && params) {
// LWJGL does not change limits/positions during these calls, it
// reads/writes exactly at pointer!!
_glGetQueryObjectuivARB((GLuint)id, (GLenum)pname, getIntPtr(params));
}
}
void glGetQueryObjectuARB(int id, int pname, IntBuffer* params) {
@ -222,8 +233,8 @@ void LinuxGLLogLightmapState(const char* stage, int textureId,
::glActiveTexture(restoreTexture);
app.DebugPrintf(
"[linux-lightmap] %s tex=%d scale=%d active=%#x unit1Bound=%d\n",
stage, textureId, scaleLight ? 1 : 0, activeTexture, unit1Binding);
"[linux-lightmap] %s tex=%d scale=%d active=%#x unit1Bound=%d\n", stage,
textureId, scaleLight ? 1 : 0, activeTexture, unit1Binding);
}
#endif
#endif

View file

@ -8,21 +8,21 @@ exclude_sources = [
# all sources except ./Platform/*
client_sources = run_command(
'sh', '-c',
'find "'
+ meson.current_source_dir()
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
+ ' '.join(exclude_sources),
check : true,
'sh',
'-c', 'find "'
+ meson.current_source_dir()
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
+ ' '.join(exclude_sources),
check: true,
).stdout().strip().split('\n')
# all sources in ./Platform (top-level files only)
platform_sources = run_command(
'sh', '-c',
'find "'
+ meson.current_source_dir() / 'Platform'
+ '" -maxdepth 1 \\( -name "*.cpp" -o -name "*.c" \\)',
check : true,
'sh',
'-c', 'find "'
+ meson.current_source_dir() / 'Platform'
+ '" -maxdepth 1 \\( -name "*.cpp" -o -name "*.c" \\)',
check: true,
).stdout().strip().split('\n')
# some platform-specific sources that are for some stupid reason in Common
@ -32,47 +32,47 @@ exclude_platform_common_sources = [
# we use system zlib instead, since this one is old as hell and isn't configured for linux correctly
' ! -path "*/zlib/*"',
' ! -name "SonyLeaderboardManager.cpp"',
' ! -name "UIScene_InGameSaveManagementMenu.cpp"'
' ! -name "UIScene_InGameSaveManagementMenu.cpp"',
]
# all sources in in ./Platform/Common
platform_sources += run_command(
'sh', '-c',
'find "'
+ meson.current_source_dir() / 'Platform/Common'
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
+ ' '.join(exclude_platform_common_sources),
check : true,
'sh',
'-c', 'find "'
+ meson.current_source_dir() / 'Platform/Common'
+ '" \\( -name "*.cpp" -o -name "*.c" \\)'
+ ' '.join(exclude_platform_common_sources),
check: true,
).stdout().strip().split('\n')
# linux-specific files (everything in Platform/Linux)
if host_machine.system() == 'linux'
platform_sources += run_command(
'sh', '-c',
'find "'
+ meson.current_source_dir() / 'Platform/Linux'
+ '" \\( -name "*.cpp" -o -name "*.c" \\) ',
check : true,
'sh',
'-c', 'find "'
+ meson.current_source_dir() / 'Platform/Linux'
+ '" \\( -name "*.cpp" -o -name "*.c" \\) ',
check: true,
).stdout().strip().split('\n')
endif
client_dependencies = [
render_dep,
input_dep,
profile_dep,
storage_dep,
assets_localisation_dep,
world_dep,
gl_dep,
glu_dep,
thread_dep,
thread_dep,
dependency('zlib'),
miniaudio_dep
render_dep,
input_dep,
profile_dep,
storage_dep,
assets_localisation_dep,
world_dep,
gl_dep,
glu_dep,
thread_dep,
dl_dep,
dependency('zlib'),
miniaudio_dep,
]
if get_option('enable_vsync')
global_cpp_defs += '-DENABLE_VSYNC'
global_cpp_defs += ['-DENABLE_VSYNC']
endif
if get_option('classic_panorama')
@ -85,8 +85,8 @@ if get_option('ui_backend') == 'shiggy'
fallback : ['shiggy', 'shiggy_dep'],
)
global_cpp_defs += '-D_ENABLEIGGY'
client_dependencies += shiggy_dep
global_cpp_defs += ['-D_ENABLEIGGY']
client_dependencies += shiggy_dep
endif
if get_option('ui_backend') == 'java'
@ -95,25 +95,30 @@ endif
client = executable('Minecraft.Client',
client_sources + platform_sources + localisation[1],
include_directories : [include_directories('Platform', 'Platform/Linux/Iggy/include'),stb],
dependencies : client_dependencies,
cpp_args : global_cpp_args + global_cpp_defs + [
'-DUNICODE', '-D_UNICODE',
include_directories: [include_directories('Platform', 'Platform/Linux/Iggy/include'), stb],
dependencies: client_dependencies,
cpp_args: global_cpp_args
+ global_cpp_defs
+ [
'-DUNICODE',
'-D_UNICODE',
'-include', meson.current_source_dir() / 'Platform/stdafx.h',
],
c_args : global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
install : true,
install_dir : ''
c_args: global_cpp_defs + ['-DUNICODE', '-D_UNICODE'],
install: true,
install_dir: '',
)
# To support actually running the client from the build folder, we need to
# copy the generated assets from Minecraft.Assets into the working directory
# of the client.
custom_target('copy_assets_to_client',
custom_target(
'copy_assets_to_client',
input: [client, media_archive],
output: 'assets.stamp', # using a stamp file to avoid copying assets every time
command : [
python, meson.project_source_root() / 'scripts/copy_assets_to_client.py',
command: [
python,
meson.project_source_root() / 'scripts/copy_assets_to_client.py',
meson.project_source_root(),
meson.project_build_root(),
meson.current_build_dir(),
@ -121,4 +126,4 @@ custom_target('copy_assets_to_client',
'@OUTPUT@',
],
build_by_default: true,
)
)

View file

@ -1,7 +1,9 @@
project('4jcraft-chucklegrounds', ['cpp', 'c'],
version : '0.1.0',
project(
'4jcraft',
['cpp', 'c'],
version: '0.1.0',
meson_version: '>= 1.7',
default_options : [
default_options: [
'cpp_std=c++23',
'warning_level=0',
'buildtype=debug', # for now
@ -16,22 +18,6 @@ python = pymod.find_installation('python3', required: true)
cc = meson.get_compiler('cpp')
# system deps
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.
thread_dep = dependency('threads')
miniaudio_dep = dependency('miniaudio')
stb = subproject('stb').get_variable('stb_inc')
# compile flags (chagne ts juicey)
global_cpp_args = [
'-fpermissive',
'-Wshift-count-overflow',
'-pipe', # use pipes instead of temp files between compiler stages
]
# global ccp defs type shi
global_cpp_defs = [
'-DSPLIT_SAVES',
'-D_LARGE_WORLDS',
@ -49,11 +35,51 @@ if host_machine.system() == 'linux'
]
endif
add_project_arguments(global_cpp_defs, language: ['cpp', 'c'])
global_cpp_args = [
'-fpermissive',
'-Wshift-count-overflow',
'-pipe',
]
add_project_arguments(global_cpp_args, language: 'cpp')
sdl2_dep = dependency('sdl2')
thread_dep = dependency('threads')
dl_dep = cc.find_library('dl', required: true)
if '-DGLES' in global_cpp_defs
gl_dep = dependency('glesv2')
glu_dep = dependency('', required: false)
else
gl_dep = dependency('gl')
glu_dep = dependency('glu')
endif
stb = subproject('stb').get_variable('stb_inc')
stb_dep = declare_dependency(include_directories: stb)
miniaudio_dep = dependency('miniaudio')
render_dep = dependency('4j-render', fallback: ['4jlibs', 'render_dep'])
input_dep = dependency('4j-input', fallback: ['4jlibs', 'input_dep'])
profile_dep = dependency('4j-profile', fallback: ['4jlibs', 'profile_dep'])
storage_dep = dependency('4j-storage', fallback: ['4jlibs', 'storage_dep'])
all_deps = [
gl_dep,
glu_dep,
sdl2_dep,
thread_dep,
dl_dep,
stb_dep,
miniaudio_dep,
render_dep,
input_dep,
profile_dep,
storage_dep,
]
subdir('Minecraft.Assets')
subdir('Minecraft.World')
subdir('Minecraft.Client')
subdir('Minecraft.Client')

View file

@ -13,3 +13,10 @@ option('enable_vsync',
type : 'boolean',
value : true,
description : 'Toggles V-Sync and adds options to unlock maximum in-game framerate.')
option(
'gles',
type: 'boolean',
value: true,
description: 'Use OpenGL ES instead of Desktop GL',
)