mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 09:45:45 +01:00
Compare commits
2 Commits
5b5f1f54af
...
0baadfca75
| Author | SHA1 | Date | |
|---|---|---|---|
| 0baadfca75 | |||
| 9a45294e56 |
@@ -1,3 +1,6 @@
|
||||
# Copyright (c) 2025 Quinn
|
||||
# Licensed under the MIT Licence. See LICENSE for details
|
||||
#
|
||||
---
|
||||
# ---------------------------
|
||||
# general style settings
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "mcx.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -9,18 +11,22 @@
|
||||
#include "../util/compat/endian.h"
|
||||
#include "../util/intdef.h"
|
||||
|
||||
#define TABLE 0x2000 // table byte size
|
||||
#define SECTOR 0x1000 // sector size
|
||||
#define CHUNKS 0x400 // amount of chunks in a file
|
||||
|
||||
/* Moves chunks `src_s` to `src_e` (inclusive) from `src`, back onto `dst`. */
|
||||
static void mvchunks(u8 *restrict buf, u8 *src, u8 *dst, int src_s, int src_e) {
|
||||
assert(src > dst);
|
||||
u32 *table = (u32 *)buf;
|
||||
size_t len = src - dst; // acquire the amount of bytes that we shall move
|
||||
assert(!(len % 0x1000));
|
||||
assert(!(len % SECTOR));
|
||||
|
||||
// count how many bytes we need to move, whilst updating location data
|
||||
size_t blen = 0;
|
||||
for (src_s++; src_s <= src_e; src_s++) {
|
||||
blen += (be32toh(table[src_s]) & 0xFF) * 0x1000;
|
||||
table[src_s] -= htobe32((len / 0x1000) << 8);
|
||||
blen += (be32toh(table[src_s]) & 0xFF) * SECTOR;
|
||||
table[src_s] -= htobe32((len / SECTOR) << 8);
|
||||
}
|
||||
memmove(dst, src, blen);
|
||||
}
|
||||
@@ -33,12 +39,12 @@ static size_t delchunk(u8 *restrict buf, size_t rmb, int sidx, int eidx) {
|
||||
u32 *table = (u32 *)buf;
|
||||
size_t slen, bidx, blen;
|
||||
slen = be32toh(table[sidx]) & 0xFF; // acquire the sector length of the chunk
|
||||
bidx = (be32toh(table[sidx]) >> 8) * 0x1000; // acquire and compute the byte offset the chunk starts at
|
||||
blen = slen * 0x1000; // compute the byte length of the chunk
|
||||
bidx = (be32toh(table[sidx]) >> 8) * SECTOR; // acquire and compute the byte offset the chunk starts at
|
||||
blen = slen * SECTOR; // compute the byte length of the chunk
|
||||
|
||||
// reset the table data
|
||||
table[sidx] = 0;
|
||||
table[sidx + 0x400] = htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
|
||||
table[sidx + CHUNKS] = htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
|
||||
|
||||
// move the succeeding chunks over the deleted chunk
|
||||
u8 *dst = buf + bidx - rmb;
|
||||
@@ -51,26 +57,26 @@ static size_t delchunk(u8 *restrict buf, size_t rmb, int sidx, int eidx) {
|
||||
* This is done instead of `delchunk` being globally linked, because
|
||||
* `delchunk` requests more specific parameters, which is confusing outside this module. */
|
||||
size_t mcx_delchunk(u8 *restrict buf, int chunk) {
|
||||
return delchunk(buf, 0, chunk, 0x400);
|
||||
return delchunk(buf, 0, chunk, CHUNKS);
|
||||
}
|
||||
|
||||
size_t mcx_delchunk_range(u8 *restrict buf, int start, int end) {
|
||||
assert(start < end && end < 0x400);
|
||||
assert(start < end && end < CHUNKS);
|
||||
u32 *table = (u32 *)buf;
|
||||
u8 *dst = buf + (be32toh(table[start]) >> 8) * 0x1000;
|
||||
u8 *src = buf + (be32toh(table[end]) >> 8) * 0x1000;
|
||||
src += (be32toh(table[end]) & 0xFF) * 0x1000;
|
||||
u8 *dst = buf + (be32toh(table[start]) >> 8) * SECTOR;
|
||||
u8 *src = buf + (be32toh(table[end]) >> 8) * SECTOR;
|
||||
src += (be32toh(table[end]) & 0xFF) * SECTOR;
|
||||
|
||||
// zeroes-out the chunk data within this range. (and set the timestamp)
|
||||
u32 ts = htobe32(time(NULL));
|
||||
for (int i = start; i <= end; i++) {
|
||||
table[i] = 0;
|
||||
table[i + 0x400] = ts;
|
||||
table[i + CHUNKS] = ts;
|
||||
}
|
||||
|
||||
// move the remaining chunks down
|
||||
if (end < 0x3FF)
|
||||
mvchunks(buf, src, dst, end, 0x3FF);
|
||||
if (end < (CHUNKS - 1))
|
||||
mvchunks(buf, src, dst, end, (CHUNKS - 1));
|
||||
return src - dst;
|
||||
}
|
||||
|
||||
@@ -88,7 +94,7 @@ size_t mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunk
|
||||
u16 chunkids[chunkc + 1];
|
||||
memcpy(chunkids, chunks, chunkc);
|
||||
qsort(chunkids, chunkc, sizeof(int), cmp_chunkids);
|
||||
chunkids[chunkc] = 0x400; // set the spare chunk to the max chunks, so the rest of the chunks are moved
|
||||
chunkids[chunkc] = CHUNKS; // set the spare chunk to the max chunks, so the rest of the chunks are moved
|
||||
|
||||
size_t rmb = 0;
|
||||
for (int i = 0; i < chunkc; i++)
|
||||
@@ -97,10 +103,10 @@ size_t mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunk
|
||||
}
|
||||
|
||||
/* Sum together the 4th byte in each location integer to compute the sector size of all chunks.
|
||||
* Multiplying by `0x1000`, and adding the size of the table itself. */
|
||||
* Multiplying by `SECTOR`, and adding the size of the table itself. */
|
||||
size_t mcx_calcsize(const u8 *restrict buf) {
|
||||
size_t size = 0;
|
||||
for (uint i = 0; i < 0x400; i++)
|
||||
for (uint i = 0; i < CHUNKS; i++)
|
||||
size += *(buf + (i * 4) + 3);
|
||||
return (size * 0x1000) + 0x2000;
|
||||
return (size * CHUNKS) + TABLE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "nbt.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if __INCLUDE_LEVEL__ > 0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "input.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "render.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "mapcolour.h"
|
||||
|
||||
#include "../../util/vec.h"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include "../../util/vec.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "shader.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "window.h"
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
int window_init(void); // initializes the global window, returns non-zero upon failure
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
||||
#undef GLAD_GL_IMPLEMENTATION
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<endian.h>)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if defined __unix__
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if defined(__unix__)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "conf.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
/* variable-width integer types */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
/* Acquires the next power of two of value `x`.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include "intdef.h"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../src/util/conf.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include <glad/gl.h>
|
||||
#undef GLAD_GL_IMPLEMENTATION
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include "test.h"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright (c) 2025 Quinn
|
||||
// Licensed under the MIT Licence. See LICENSE for details
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user