mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-07-13 05:57:02 +00:00
Merge branch 'dev' into refactor/no-std-wildcard
This commit is contained in:
commit
41db813a6d
36
.devcontainer/Dockerfile
Normal file
36
.devcontainer/Dockerfile
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
FROM mcr.microsoft.com/devcontainers/cpp:1-ubuntu-24.04
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Dependencies
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y software-properties-common \
|
||||
&& add-apt-repository -y ppa:ubuntu-toolchain-r/test \
|
||||
&& apt-get update \
|
||||
&& apt-get install -y \
|
||||
build-essential \
|
||||
cmake \
|
||||
libglfw3-dev \
|
||||
libgl-dev \
|
||||
libglu1-mesa-dev \
|
||||
libopenal-dev \
|
||||
libvorbis-dev \
|
||||
libpng-dev \
|
||||
libpthread-stubs0-dev \
|
||||
lld \
|
||||
meson \
|
||||
ninja-build \
|
||||
gcc-15 \
|
||||
g++-15 \
|
||||
# Clean up lol
|
||||
&& apt-get autoremove -y \
|
||||
&& apt-get clean -y \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set GCC 15 as default
|
||||
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 100 \
|
||||
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-15 100 \
|
||||
&& update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 100 \
|
||||
&& update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 100
|
||||
|
||||
ENV DEBIAN_FRONTEND=dialog
|
||||
17
.devcontainer/devcontainer.json
Normal file
17
.devcontainer/devcontainer.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "4JCraft Dev Container",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {},
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cpptools-extension-pack",
|
||||
"mesonbuild.mesonbuild"
|
||||
]
|
||||
}
|
||||
},
|
||||
"remoteUser": "vscode"
|
||||
}
|
||||
|
|
@ -11,6 +11,9 @@
|
|||
#include <cmath>
|
||||
#include <pthread.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include "stb_image.h"
|
||||
|
||||
C4JRender RenderManager;
|
||||
|
||||
static GLFWwindow *s_window = nullptr;
|
||||
|
|
@ -495,106 +498,62 @@ void C4JRender::TextureDynamicUpdateEnd() {}
|
|||
|
||||
void C4JRender::Tick() {}
|
||||
void C4JRender::UpdateGamma(unsigned short) {}
|
||||
// really don't know if this is nessesary but didn't find any other functions to load images properly as a png..
|
||||
// im sorry.
|
||||
#ifdef __linux__
|
||||
#include <png.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static HRESULT LoadPNGFromRows(png_structp png, png_infop info, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut)
|
||||
// This sucks, but at least better than libpng
|
||||
static HRESULT LoadFromSTB(unsigned char* data, int width, int height, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut)
|
||||
{
|
||||
int width = png_get_image_width(png, info);
|
||||
int height = png_get_image_height(png, info);
|
||||
png_byte color_type = png_get_color_type(png, info);
|
||||
png_byte bit_depth = png_get_bit_depth(png, info);
|
||||
int pixelCount = width * height;
|
||||
int* pixels = new int[pixelCount];
|
||||
|
||||
if (bit_depth == 16) png_set_strip_16(png);
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_palette_to_rgb(png);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png);
|
||||
if (png_get_valid(png, info, PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png);
|
||||
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_filler(png, 0xFF, PNG_FILLER_AFTER);
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png);
|
||||
|
||||
png_read_update_info(png, info);
|
||||
|
||||
unsigned char *buf = new unsigned char[width * height * 4];
|
||||
png_bytep *rows = new png_bytep[height];
|
||||
for (int y = 0; y < height; y++)
|
||||
rows[y] = buf + y * width * 4;
|
||||
png_read_image(png, rows);
|
||||
delete[] rows;
|
||||
// considering i worked on previous projects with raw pngs,,,,,
|
||||
int *pixels = new int[width * height];
|
||||
for (int i = 0; i < width * height; i++)
|
||||
for (int i = 0; i < pixelCount; i++)
|
||||
{
|
||||
unsigned char r = buf[i * 4 + 0];
|
||||
unsigned char g = buf[i * 4 + 1];
|
||||
unsigned char b = buf[i * 4 + 2];
|
||||
unsigned char a = buf[i * 4 + 3];
|
||||
unsigned char r = data[i * 4 + 0];
|
||||
unsigned char g = data[i * 4 + 1];
|
||||
unsigned char b = data[i * 4 + 2];
|
||||
unsigned char a = data[i * 4 + 3];
|
||||
|
||||
//pixels[i] = (a << 24) | (b << 16) | (g << 8) | r;
|
||||
pixels[i] = (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
delete[] buf;
|
||||
|
||||
pSrcInfo->Width = width;
|
||||
pSrcInfo->Height = height;
|
||||
if (pSrcInfo)
|
||||
{
|
||||
pSrcInfo->Width = width;
|
||||
pSrcInfo->Height = height;
|
||||
}
|
||||
|
||||
*ppDataOut = pixels;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT C4JRender::LoadTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut)
|
||||
HRESULT C4JRender::LoadTextureData(const char* szFilename, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut)
|
||||
{
|
||||
FILE *fp = fopen(szFilename, "rb");
|
||||
if (!fp) return E_FAIL;
|
||||
int width, height, channels;
|
||||
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png) { fclose(fp); return E_FAIL; }
|
||||
png_infop info = png_create_info_struct(png);
|
||||
if (!info) { png_destroy_read_struct(&png, NULL, NULL); fclose(fp); return E_FAIL; }
|
||||
if (setjmp(png_jmpbuf(png))) { png_destroy_read_struct(&png, &info, NULL); fclose(fp); return E_FAIL; }
|
||||
unsigned char* data = stbi_load(szFilename, &width, &height, &channels, 4);
|
||||
if (!data)
|
||||
return E_FAIL;
|
||||
|
||||
png_init_io(png, fp);
|
||||
png_read_info(png, info);
|
||||
HRESULT hr = LoadFromSTB(data, width, height, pSrcInfo, ppDataOut);
|
||||
|
||||
HRESULT hr = LoadPNGFromRows(png, info, pSrcInfo, ppDataOut);
|
||||
png_destroy_read_struct(&png, &info, NULL);
|
||||
fclose(fp);
|
||||
stbi_image_free(data);
|
||||
return hr;
|
||||
}
|
||||
|
||||
struct PNGMemReader { const unsigned char *data; png_size_t pos; png_size_t size; };
|
||||
|
||||
static void png_mem_read(png_structp png, png_bytep out, png_size_t len)
|
||||
HRESULT C4JRender::LoadTextureData(BYTE* pbData, DWORD dwBytes, D3DXIMAGE_INFO* pSrcInfo, int** ppDataOut)
|
||||
{
|
||||
PNGMemReader *r = (PNGMemReader *)png_get_io_ptr(png);
|
||||
if (r->pos + len > r->size) len = r->size - r->pos;
|
||||
memcpy(out, r->data + r->pos, len);
|
||||
r->pos += len;
|
||||
}
|
||||
int width, height, channels;
|
||||
|
||||
HRESULT C4JRender::LoadTextureData(BYTE *pbData, DWORD dwBytes, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut)
|
||||
{
|
||||
png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!png) return E_FAIL;
|
||||
png_infop info = png_create_info_struct(png);
|
||||
if (!info) { png_destroy_read_struct(&png, NULL, NULL); return E_FAIL; }
|
||||
if (setjmp(png_jmpbuf(png))) { png_destroy_read_struct(&png, &info, NULL); return E_FAIL; }
|
||||
unsigned char* data = stbi_load_from_memory(pbData, dwBytes, &width, &height, &channels, 4);
|
||||
if (!data)
|
||||
return E_FAIL;
|
||||
|
||||
PNGMemReader reader = { pbData, 0, dwBytes };
|
||||
png_set_read_fn(png, &reader, png_mem_read);
|
||||
png_read_info(png, info);
|
||||
HRESULT hr = LoadFromSTB(data, width, height, pSrcInfo, ppDataOut);
|
||||
|
||||
HRESULT hr = LoadPNGFromRows(png, info, pSrcInfo, ppDataOut);
|
||||
png_destroy_read_struct(&png, &info, NULL);
|
||||
stbi_image_free(data);
|
||||
return hr;
|
||||
}
|
||||
|
||||
#else
|
||||
HRESULT C4JRender::LoadTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut) { return S_OK; }
|
||||
HRESULT C4JRender::LoadTextureData(BYTE *pbData, DWORD dwBytes, D3DXIMAGE_INFO *pSrcInfo, int **ppDataOut) { return S_OK; }
|
||||
#endif
|
||||
HRESULT C4JRender::SaveTextureData(const char *szFilename, D3DXIMAGE_INFO *pSrcInfo, int *ppDataOut) { return S_OK; }
|
||||
HRESULT C4JRender::SaveTextureDataToMemory(void *pOutput, int outputCapacity, int *outputLength, int width, int height, int *ppDataIn) { return S_OK; }
|
||||
void C4JRender::TextureGetStats() {}
|
||||
|
|
|
|||
7988
4J.Render/stb_image.h
Normal file
7988
4J.Render/stb_image.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -225,7 +225,7 @@ Texture *StitchedTexture::getSource()
|
|||
|
||||
Texture *StitchedTexture::getFrame(int i)
|
||||
{
|
||||
return frames->at(0);
|
||||
return frames->at(i);
|
||||
}
|
||||
|
||||
int StitchedTexture::getFrames()
|
||||
|
|
|
|||
51
README.md
51
README.md
|
|
@ -9,7 +9,7 @@
|
|||
4JCraft is a modified version of the Minecraft Console Legacy Edition aimed on porting old Minecraft to different platforms (such as Linux, Android, Emscripten, etc.)
|
||||
|
||||
Join our community:
|
||||
* Discord (Not currently available): https://discord.gg/zFCwRWkkUg
|
||||
* Discord: https://discord.gg/zFCwRWkkUg
|
||||
* Steam: https://steamcommunity.com/groups/4JCraft
|
||||
|
||||
## Planned platforms to be supported:
|
||||
|
|
@ -32,7 +32,7 @@ sudo apt install \
|
|||
build-essential cmake \
|
||||
libglfw3-dev libgl-dev libglu1-mesa-dev \
|
||||
libopenal-dev libvorbis-dev \
|
||||
libpthread-stubs0-dev
|
||||
libpng-dev libpthread-stubs0-dev
|
||||
```
|
||||
|
||||
On Arch/Manjaro:
|
||||
|
|
@ -43,32 +43,27 @@ sudo pacman -S base-devel gcc pkgconf cmake glfw-x11 mesa openal libvorbis glu
|
|||
|
||||
If you are on wayland, you may swap `glfw-x11` to `glfw-wayland` for native wayland windowing instead of xwayland.
|
||||
|
||||
On Docker:
|
||||
|
||||
If you don't want to deal with installing dependencies, you can use the included devcontainer. Open the project in VS Code with the [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension and it will set everything up for you — GCC 15, Meson, Ninja, lld, and all the libraries.
|
||||
|
||||
Alternatively, you can build and use the container manually:
|
||||
|
||||
```bash
|
||||
docker build -t 4jcraft-dev .devcontainer/
|
||||
docker run -it -v $(pwd):/workspaces/4jcraft -w /workspaces/4jcraft 4jcraft-dev bash
|
||||
```
|
||||
|
||||
### Configure & Build
|
||||
|
||||
> [!IMPORTANT]
|
||||
> GCC 15 or newer is currently *required* to build this project. Ubuntu installations in particular may have older versions preinstalled, so verify your compiler version with `gcc --version`.
|
||||
> If you are using GCC, then GCC 15 or newer is currently *required* to build this project. Ubuntu installations in particular may have older versions preinstalled, so verify your compiler version with `gcc --version`.
|
||||
|
||||
This project uses the [Meson](https://mesonbuild.com/) (with [Ninja](https://ninja-build.org/)) as a build system and [lld](https://lld.llvm.org/) as a linker.
|
||||
This project uses the [Meson](https://mesonbuild.com/) build system (with [Ninja](https://ninja-build.org/)).
|
||||
|
||||
#### Install Tooling
|
||||
|
||||
1. Follow [this Quickstart guide](https://mesonbuild.com/Quick-guide.html) for installing or building Meson and Ninja on your respective distro.
|
||||
2. Install the `lld` linker using your distro's package manager. This may be distributed as part of an [LLVM toolchain](https://llvm.org/).
|
||||
|
||||
Debian/Ubuntu:
|
||||
```bash
|
||||
sudo apt-get install lld
|
||||
```
|
||||
|
||||
RedHat/Fedora:
|
||||
```bash
|
||||
sudo dnf install lld
|
||||
```
|
||||
|
||||
Arch/Manjaro:
|
||||
```bash
|
||||
sudo pacman -S lld
|
||||
```
|
||||
Follow [this Quickstart guide](https://mesonbuild.com/Quick-guide.html) for installing or building Meson and Ninja on your respective distro.
|
||||
|
||||
#### Configure & Build
|
||||
|
||||
|
|
@ -80,6 +75,20 @@ meson setup build
|
|||
meson compile -C build
|
||||
```
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> For the fastest compilation speeds, you may want to use the compilers and linkers provided by an [LLVM toolchain](https://llvm.org/) (`clang`/`lld`) over your system compiler and linker. To do this, install `clang` and `lld`, and configure your build using the `llvm_native.txt` nativescript in `/scripts`:
|
||||
>
|
||||
> ```bash
|
||||
> meson setup --native-file ./scripts/llvm_native.txt build
|
||||
> ```
|
||||
>
|
||||
> ...or if you've already configured a build directory:
|
||||
>
|
||||
> ```bash
|
||||
> meson setup --native-file ./scripts/llvm_native.txt build --reconfigure
|
||||
> ```
|
||||
|
||||
The binary is output to:
|
||||
|
||||
```
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ project('4jcraft-chucklegrounds', ['cpp', 'c'],
|
|||
|
||||
cc = meson.get_compiler('cpp')
|
||||
|
||||
# Use LLD for dramatically faster linking (ld.lld must be installed)
|
||||
add_project_link_arguments('-fuse-ld=lld', language : ['c', 'cpp'])
|
||||
|
||||
# system deps
|
||||
gl_dep = dependency('gl')
|
||||
glu_dep = dependency('glu')
|
||||
|
|
|
|||
Loading…
Reference in a new issue