Skip to content

Commit

Permalink
Optimize and fix Section.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
uis246 committed Dec 15, 2020
1 parent d7b338a commit b0f5f80
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 33 deletions.
13 changes: 0 additions & 13 deletions cwd/assets/altcraft/code/lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,6 @@ function plugin.onUnload ()
AC.LogInfo("AC Core unloaded")
end

function plugin.onTick (deltaTime)
if AC.GetGameState() and AC.GetGameState():GetPlayer() and AC.GetGameState():GetTimeStatus().worldAge > 0 then
-- local player = AC.GetGameState():GetPlayer()
-- player.pos.x = player.pos.x + deltaTime * 0.5

-- local playerPos = AC.GetGameState():GetPlayer().pos
-- local wrld = AC.GetGameState():GetWorld()
-- playerPosV = Vector.new(playerPos.x, playerPos.y - 1, playerPos.z)
-- bid = wrld:GetBlockId(playerPosV)
-- print(bid.id..":"..bid.state)
end
end

local blocks = require("altcraft/blocks")
blocks.RegisterBlocks()

Expand Down
6 changes: 6 additions & 0 deletions src/ModLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ void ModLoader::LoadModinfo(AssetTreeNode &node) noexcept {
}

LOG(INFO) << "Module " << (mod->name.empty() ? mod->modid : mod->name) << " loaded";

node.data.clear();
node.data.shrink_to_fit();
}

void ModLoader::LoadMcmeta(AssetTreeNode &node) {
Expand All @@ -138,6 +141,9 @@ void ModLoader::LoadMcmeta(AssetTreeNode &node) {
existing->description = pack["description"];
mods.push_back(existing);
}

node.data.clear();
node.data.shrink_to_fit();
}

void ModLoader::ParseAssetTexture(AssetTreeNode &node) noexcept {
Expand Down
21 changes: 9 additions & 12 deletions src/Platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@
# ifdef __GNUC__
# define AC_API __attribute__((visibility("default")))
# define AC_INTERNAL __attribute__((visibility("internal")))
# define bswap_64(x) __builtin_bswap64(x)
# else
# define AC_API
# define AC_INTERNAL
# endif
#endif

#if defined(_WIN32)&&defined(_MSC_VER)
# include <stdlib.h>
# define bswap_64(x) _byteswap_uint64(x)
#elif !defined(__GNUC__)
# define mv64(x, i) ((x&((uint64_t)0xFF<<(i*8)))>>(i*8)<<((7-i)*8))
# define bswap_64(x) ( mv64(x, 0) | mv64(x, 1) | mv64(x, 2) | mv64(x, 3) | mv64(x, 4) | mv64(x, 5) | mv64(x, 6) | mv64(x, 7))
#endif

#ifdef __linux__
# include <pthread.h>
# undef AC_THREAD_SET_NAME
Expand All @@ -58,15 +67,3 @@
#define floorASR(value, shmat, dest) (dest=std::floor(value / (float)(2 << shmat)))
#define floorASRQ(value, shmat, dest) (dest=std::floor(value / (float)(2 << shmat)))
#endif

#ifndef __GNUC__
# ifndef WIN32
# error This does not works
# define mv64(x, i) (x&(0xFF<<(i*8)))>>((7-i)*8)
# define bswap_64(x) ( mv64(x, 0) | mv64(x, 1) | mv64(x, 2) | mv64(x, 3) | mv64(x, 4) | mv64(x, 5) | mv64(x, 6) | mv64(x, 7))
# else
# define bswap_64(x) _byteswap_uint64(x)
# endif
#else
# include <byteswap.h>
#endif
9 changes: 7 additions & 2 deletions src/RendererSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static const GLfloat uv_coords[] = {

GLuint RendererSection::VboUvs = 0;

RendererSection::RendererSection(const RendererSectionData &data) {
RendererSection::RendererSection(RendererSectionData &data) {
OPTICK_EVENT();
if (!VboUvs) {
glGenBuffers(1, &VboUvs);
Expand Down Expand Up @@ -122,7 +122,7 @@ size_t RendererSection::GetHash() {
return hash;
}

void RendererSection::UpdateData(const RendererSectionData & data) {
void RendererSection::UpdateData(RendererSectionData & data) {
OPTICK_EVENT();

numOfFaces = data.verts.size()/4;
Expand Down Expand Up @@ -157,4 +157,9 @@ void RendererSection::UpdateData(const RendererSectionData & data) {

glBindBuffer(GL_ARRAY_BUFFER, 0);
glCheckError();

data.quadInfo.clear();
data.quadInfo.shrink_to_fit();
data.verts.clear();
data.verts.shrink_to_fit();
}
6 changes: 3 additions & 3 deletions src/RendererSection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class RendererSection {
size_t hash;
Vector sectionPos;

RendererSection(const RendererSection &other) = delete;
RendererSection(RendererSection &other) = delete;
public:
RendererSection(const RendererSectionData &data);
RendererSection(RendererSectionData &data);

RendererSection(RendererSection &&other);

Expand All @@ -41,5 +41,5 @@ class RendererSection {

friend void swap(RendererSection &lhs, RendererSection &rhs);

void UpdateData(const RendererSectionData &data);
void UpdateData(RendererSectionData &data);
};
7 changes: 4 additions & 3 deletions src/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,17 @@ void Section::ExpandBPB() noexcept {

size_t sz = (16*16*16/2) << (this->pow - 1);
uint16_t *expanded = reinterpret_cast<uint16_t*>(malloc(sz));
if (this->pow == 2) {//Expand to 8 bPB
if (this->pow == 2) {//Expand to 8 BpB from 4
uint8_t *old = reinterpret_cast<uint8_t*>(blocks);
uint8_t *new_blocks = reinterpret_cast<uint8_t*>(expanded);
for (size_t i = 0; i < 16*16*16; i++) {
uint8_t nibble = i&1;
new_blocks[i] = (old[i>>1] >> (nibble << 2)) & 0x0F;
}
} else if (this->pow == 3) {//Expand to 16 bPB
} else if (this->pow == 3) {//Expand to 16 BpB from 8
uint8_t *old = reinterpret_cast<uint8_t*>(blocks);
for (size_t i = 0; i < 16*16*16; i++) {
expanded[i] = palette[blocks[i]];
expanded[i] = palette[old[i]];
}
}

Expand Down

0 comments on commit b0f5f80

Please sign in to comment.