mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-01 23:25:09 +02:00
precalculate networked block palette buffer
This commit is contained in:
@@ -194,6 +194,14 @@ function serializeTags (tags) {
|
|||||||
return Buffer.concat([lengthBuf, fullData]);
|
return Buffer.concat([lengthBuf, fullData]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toVarIntBuffer (array) {
|
||||||
|
const parts = [];
|
||||||
|
for (const num of array) {
|
||||||
|
parts.push(writeVarInt(num));
|
||||||
|
}
|
||||||
|
return Buffer.concat(parts);
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to C-style hex byte array string
|
// Convert to C-style hex byte array string
|
||||||
function toCArray (buffer) {
|
function toCArray (buffer) {
|
||||||
const hexBytes = [...buffer].map(b => `0x${b.toString(16).padStart(2, "0")}`);
|
const hexBytes = [...buffer].map(b => `0x${b.toString(16).padStart(2, "0")}`);
|
||||||
@@ -267,6 +275,8 @@ async function convert () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const networkBlockPalette = toVarIntBuffer(Object.values(itemsAndBlocks.palette));
|
||||||
|
|
||||||
const sourceCode = `\
|
const sourceCode = `\
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "registries.h"
|
#include "registries.h"
|
||||||
@@ -282,6 +292,11 @@ ${toCArray(tagBuffer)}
|
|||||||
|
|
||||||
// Block palette
|
// Block palette
|
||||||
uint16_t block_palette[] = { ${Object.values(itemsAndBlocks.palette).join(", ")} };
|
uint16_t block_palette[] = { ${Object.values(itemsAndBlocks.palette).join(", ")} };
|
||||||
|
// Block palette as VarInt buffer
|
||||||
|
uint8_t network_block_palette[] = {
|
||||||
|
${toCArray(networkBlockPalette)}
|
||||||
|
};
|
||||||
|
|
||||||
// Block-to-item mapping
|
// Block-to-item mapping
|
||||||
uint16_t B_to_I[] = { ${itemsAndBlocks.mappingWithOverrides.join(", ")} };
|
uint16_t B_to_I[] = { ${itemsAndBlocks.mappingWithOverrides.join(", ")} };
|
||||||
// Item-to-block mapping
|
// Item-to-block mapping
|
||||||
@@ -305,6 +320,7 @@ extern uint8_t registries_bin[${fullRegistryBuffer.length}];
|
|||||||
extern uint8_t tags_bin[${tagBuffer.length}];
|
extern uint8_t tags_bin[${tagBuffer.length}];
|
||||||
|
|
||||||
extern uint16_t block_palette[256]; // Block palette
|
extern uint16_t block_palette[256]; // Block palette
|
||||||
|
extern uint8_t network_block_palette[${networkBlockPalette.length}]; // Block palette as VarInt buffer
|
||||||
extern uint16_t B_to_I[256]; // Block-to-item mapping
|
extern uint16_t B_to_I[256]; // Block-to-item mapping
|
||||||
uint8_t I_to_B (uint16_t item); // Item-to-block mapping
|
uint8_t I_to_B (uint16_t item); // Item-to-block mapping
|
||||||
|
|
||||||
|
@@ -284,10 +284,7 @@ int sc_setCenterChunk (int client_fd, int x, int y) {
|
|||||||
// S->C Chunk Data and Update Light
|
// S->C Chunk Data and Update Light
|
||||||
int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z) {
|
int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z) {
|
||||||
|
|
||||||
int palette_size = 0;
|
const int chunk_data_size = (4101 + sizeVarInt(256) + sizeof(network_block_palette)) * 24;
|
||||||
for (int i = 0; i < 256; i ++) palette_size += sizeVarInt(block_palette[i]);
|
|
||||||
|
|
||||||
const int chunk_data_size = (4101 + sizeVarInt(256) + palette_size) * 24;
|
|
||||||
|
|
||||||
writeVarInt(client_fd, 17 + sizeVarInt(chunk_data_size) + chunk_data_size);
|
writeVarInt(client_fd, 17 + sizeVarInt(chunk_data_size) + chunk_data_size);
|
||||||
writeByte(client_fd, 0x27);
|
writeByte(client_fd, 0x27);
|
||||||
@@ -306,13 +303,15 @@ int sc_chunkDataAndUpdateLight (int client_fd, int _x, int _z) {
|
|||||||
y = i * 16 - 64;
|
y = i * 16 - 64;
|
||||||
writeUint16(client_fd, 4096); // block count
|
writeUint16(client_fd, 4096); // block count
|
||||||
writeByte(client_fd, 8); // bits per entry
|
writeByte(client_fd, 8); // bits per entry
|
||||||
writeVarInt(client_fd, 256);
|
writeVarInt(client_fd, 256); // block palette length
|
||||||
for (int j = 0; j < 256; j ++) writeVarInt(client_fd, block_palette[j]);
|
// block palette as varint buffer
|
||||||
|
send(client_fd, network_block_palette, sizeof(network_block_palette), 0);
|
||||||
|
// chunk section buffer
|
||||||
buildChunkSection(x, y, z);
|
buildChunkSection(x, y, z);
|
||||||
send(client_fd, chunk_section, 4096, 0);
|
send(client_fd, chunk_section, 4096, 0);
|
||||||
// biome data
|
// biome data
|
||||||
writeByte(client_fd, 0); // bits per entry
|
writeByte(client_fd, 0); // bits per entry
|
||||||
writeByte(client_fd, W_plains); // palette
|
writeByte(client_fd, W_plains); // biome palette
|
||||||
// reset watchdog and yield
|
// reset watchdog and yield
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user