diff --git a/data/images/environment/foliagecolor.png b/data/images/misc/foliagecolor.png similarity index 100% rename from data/images/environment/foliagecolor.png rename to data/images/misc/foliagecolor.png diff --git a/data/images/environment/grasscolor.png b/data/images/misc/grasscolor.png similarity index 100% rename from data/images/environment/grasscolor.png rename to data/images/misc/grasscolor.png diff --git a/data/images/misc/shadow.png b/data/images/misc/shadow.png new file mode 100644 index 0000000..06d999b Binary files /dev/null and b/data/images/misc/shadow.png differ diff --git a/data/images/misc/vignette.png b/data/images/misc/vignette.png new file mode 100644 index 0000000..f236acb Binary files /dev/null and b/data/images/misc/vignette.png differ diff --git a/src/client/Minecraft.cpp b/src/client/Minecraft.cpp index 1127246..1bd68de 100755 --- a/src/client/Minecraft.cpp +++ b/src/client/Minecraft.cpp @@ -1138,13 +1138,13 @@ void Minecraft::init() // my code - TextureId foliageId = (textures->loadTexture("environment/foliagecolor.png")); // loading the uh png for foliage color - int* foliagePixels = textures->loadTexturePixels(foliageId, "environment/foliagecolor.png"); + TextureId foliageId = (textures->loadTexture("misc/foliagecolor.png")); // loading the uh png for foliage color + int* foliagePixels = textures->loadTexturePixels(foliageId, "misc/foliagecolor.png"); // now i can finally initialize foliage color, probably not the best way to handle this but i cant be arsed rn FoliageColor::init(foliagePixels); - TextureId grassId = (textures->loadTexture("environment/grasscolor.png")); // loading the uh png for foliage color - int* grassPixels = textures->loadTexturePixels(grassId, "environment/grasscolor.png"); + TextureId grassId = (textures->loadTexture("misc/foliagecolor.png")); // loading the uh png for foliage color + int* grassPixels = textures->loadTexturePixels(grassId, "misc/foliagecolor.png"); GrassColor::init(grassPixels); bool tint = options.getBooleanValue(OPTIONS_FOLIAGE_TINT); // finally, toggleable foliage color @@ -1401,6 +1401,12 @@ void Minecraft::_levelGenerated() player->resetPos(false); } + if (level && level->dimension) { + // For example, if you want FogType or any other option + level->dimension->FogType = options.getBooleanValue(OPTIONS_FOG_TYPE); + } + + this->cameraTargetPlayer = player; std::string serverName = options.getStringValue(OPTIONS_USERNAME) + " - " + level->getLevelData()->levelName; diff --git a/src/client/Options.cpp b/src/client/Options.cpp index 68d6bae..cf719b0 100755 --- a/src/client/Options.cpp +++ b/src/client/Options.cpp @@ -62,6 +62,10 @@ OptionBool serverVisible("servervisible", true); OptionBool foliageTint("foliagetint", false); +OptionInt fogType("fogType", 0, 0, 2); + +OptionBool javaHud("javaHud", false); + OptionInt keyForward("key.forward", Keyboard::KEY_W); OptionInt keyLeft("key.left", Keyboard::KEY_A); OptionInt keyBack("key.back", Keyboard::KEY_S); @@ -166,6 +170,11 @@ void Options::initTable() { m_options[OPTIONS_RPI_CURSOR] = &rpiCursor; m_options[OPTIONS_FOLIAGE_TINT] = &foliageTint; + // more options yay + m_options[OPTIONS_FOG_TYPE] = &fogType; + + m_options[OPTIONS_JAVA_HUD] = &javaHud; + m_options[OPTIONS_AUTOJUMP] = &autoJump; m_options[OPTIONS_LAST_IP] = &lastIp; } diff --git a/src/client/Options.h b/src/client/Options.h index 96d6f3b..9852d48 100755 --- a/src/client/Options.h +++ b/src/client/Options.h @@ -85,6 +85,8 @@ enum OptionId { OPTIONS_RPI_CURSOR, OPTIONS_FOLIAGE_TINT, + OPTIONS_FOG_TYPE, + OPTIONS_JAVA_HUD, // Should be last! OPTIONS_COUNT }; diff --git a/src/client/gui/Gui.cpp b/src/client/gui/Gui.cpp index ccc9c26..8df59f0 100755 --- a/src/client/gui/Gui.cpp +++ b/src/client/gui/Gui.cpp @@ -36,7 +36,7 @@ const float Gui::DropTicks = 40.0f; //#include Gui::Gui(Minecraft* minecraft) -: minecraft(minecraft), + : minecraft(minecraft), tickCount(0), progress(0), overlayMessageTime(0), @@ -77,7 +77,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { Font* font = minecraft->font; const bool isTouchInterface = minecraft->useTouchscreen(); - + const int screenWidth = (int)(minecraft->width * InvGuiScale); const int screenHeight = (int)(minecraft->height * InvGuiScale); blitOffset = -90; @@ -86,9 +86,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { glColor4f2(1, 1, 1, 1); // H: 4 - // T: 7 - // L: 6 - // F: 3 + // T: 7 + // L: 6 + // F: 3 int ySlot = screenHeight - 16 - 3; if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { @@ -103,6 +103,12 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } } + // @todo - Shredder: I added this here but currently viginette is broken so i cant do much about it. + // if (minecraft->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)){ + // this->renderVignette(this->minecraft->player->getBrightness(a), screenWidth, screenHeight); + // } + // shredder end + if(minecraft->player->getSleepTimer() > 0) { glDisable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); @@ -113,38 +119,38 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { glEnable(GL_DEPTH_TEST); } if (!minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { - renderToolBar(a, ySlot, screenWidth); + renderToolBar(a, ySlot, screenWidth); - glEnable(GL_BLEND); - bool isChatting = (minecraft->screen && (dynamic_cast(minecraft->screen) || dynamic_cast(minecraft->screen))); - unsigned int max = 10; - if (isChatting) { - int lineHeight = 9; - max = (screenHeight - 48) / lineHeight; - if (max < 1) max = 1; - int maxScroll = (int)guiMessages.size() - (int)max; - if (maxScroll < 0) maxScroll = 0; - if (chatScrollOffset > maxScroll) chatScrollOffset = maxScroll; - } else { - chatScrollOffset = 0; - } - renderChatMessages(screenHeight, max, isChatting, font); + glEnable(GL_BLEND); + bool isChatting = (minecraft->screen && (dynamic_cast(minecraft->screen) || dynamic_cast(minecraft->screen))); + unsigned int max = 10; + if (isChatting) { + int lineHeight = 9; + max = (screenHeight - 48) / lineHeight; + if (max < 1) max = 1; + int maxScroll = (int)guiMessages.size() - (int)max; + if (maxScroll < 0) maxScroll = 0; + if (chatScrollOffset > maxScroll) chatScrollOffset = maxScroll; + } else { + chatScrollOffset = 0; + } + renderChatMessages(screenHeight, max, isChatting, font); #if !defined(RPI) - renderOnSelectItemNameText(screenWidth, font, ySlot); + renderOnSelectItemNameText(screenWidth, font, ySlot); #endif #if defined(RPI) - renderDebugInfo(); + renderDebugInfo(); #endif - if (Keyboard::isKeyDown(Keyboard::KEY_TAB)) { - renderPlayerList(font, screenWidth, screenHeight); + if (Keyboard::isKeyDown(Keyboard::KEY_TAB)) { + renderPlayerList(font, screenWidth, screenHeight); + } + + if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG)) + renderDebugInfo(); } - if (minecraft->options.getBooleanValue(OPTIONS_RENDER_DEBUG)) - renderDebugInfo(); - } - - glDisable(GL_BLEND); + glDisable(GL_BLEND); glEnable2(GL_ALPHA_TEST); } @@ -183,7 +189,7 @@ void Gui::getSlotPos(int slot, int& posX, int& posY) { int screenWidth = (int)(minecraft->width * InvGuiScale); int screenHeight = (int)(minecraft->height * InvGuiScale); posX = screenWidth / 2 - getNumSlots() * 10 + slot * 20, - posY = screenHeight - 22; + posY = screenHeight - 22; } RectangleArea Gui::getRectangleArea(int extendSide) { @@ -196,7 +202,7 @@ RectangleArea Gui::getRectangleArea(int extendSide) { return RectangleArea(0, (float)minecraft->height-pHeight, pCenterX+pHalfWidth+2, (float)minecraft->height); if (extendSide > 0) return RectangleArea(pCenterX-pHalfWidth, (float)minecraft->height-pHeight, (float)minecraft->width, (float)minecraft->height); - + return RectangleArea(pCenterX-pHalfWidth, (float)minecraft->height-pHeight, pCenterX+pHalfWidth+2, (float)minecraft->height); } @@ -242,7 +248,7 @@ void Gui::handleKeyPressed(int key) if (key == Keyboard::KEY_F1) { minecraft->options.toggle(OPTIONS_HIDEGUI); } - + if (key == 99) { if (minecraft->player->inventory->selected > 0) @@ -290,11 +296,11 @@ void Gui::tick() { if(itemNameOverlayTime < 2) itemNameOverlayTime += 1.0f / SharedConstants::TicksPerSecond; for (unsigned int i = 0; i < guiMessages.size(); i++) { - guiMessages.at(i).ticks++; + guiMessages.at(i).ticks++; } - if (!minecraft->isCreativeMode()) - tickItemDrop(); + if (!minecraft->isCreativeMode()) + tickItemDrop(); } void Gui::addMessage(const std::string& _string) { @@ -344,6 +350,8 @@ void Gui::displayClientMessage(const std::string& messageId) { addMessage(messageId); } + +// @todo - shredder: Function seems to be completely fine and ported over from java beta, but renders opaque??? need to investigate void Gui::renderVignette(float br, int w, int h) { br = 1 - br; if (br < 0) br = 0; @@ -354,7 +362,10 @@ void Gui::renderVignette(float br, int w, int h) { glDepthMask(false); glBlendFunc2(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); glColor4f2(tbr, tbr, tbr, 1); + minecraft->textures->loadAndBindTexture("misc/vignette.png"); + glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri2(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); Tesselator& t = Tesselator::instance; t.begin(); @@ -407,7 +418,7 @@ void Gui::inventoryUpdated() { } void Gui::onGraphicsReset() { - inventoryUpdated(); + inventoryUpdated(); } void Gui::texturesLoaded( Textures* textures ) { @@ -585,12 +596,12 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen bool bowEquipped = currentItem != NULL ? currentItem->getItem() == Item::bow : false; bool itemInUse = currentItem != NULL ? currentItem->getItem() == minecraft->player->getUseItem()->getItem() : false; if ((!isTouchInterface || minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) - || (bowEquipped && itemInUse)) && !minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { - minecraft->textures->loadAndBindTexture("gui/icons.png"); - glEnable(GL_BLEND); - glBlendFunc2(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); - blit(screenWidth/2 - 8, screenHeight/2 - 8, 0, 0, 16, 16); - glDisable(GL_BLEND); + || (bowEquipped && itemInUse)) && !minecraft->options.getBooleanValue(OPTIONS_HIDEGUI)) { + minecraft->textures->loadAndBindTexture("gui/icons.png"); + glEnable(GL_BLEND); + glBlendFunc2(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR); + blit(screenWidth/2 - 8, screenHeight/2 - 8, 0, 0, 16, 16); + glDisable(GL_BLEND); } else if(!bowEquipped) { const float tprogress = minecraft->gameMode->destroyProgress; const float alpha = Mth::clamp(minecraft->inputHolder->alpha, 0.0f, 1.0f); @@ -665,10 +676,10 @@ void Gui::renderHearts() { int ip2 = i + i + 1; if (armor > 0) { - int xo = xx + 80 + i * 8 + 4; - if (ip2 < armor) blit(xo, yo, 16 + 2 * 9, 9 * 1, 9, 9); - else if (ip2 == armor) blit(xo, yo, 16 + 4 * 9, 9 * 1, 9, 9); - else if (ip2 > armor) blit(xo, yo, 16 + 0 * 9, 9 * 1, 9, 9); + int xo = xx + 80 + i * 8 + 4; + if (ip2 < armor) blit(xo, yo, 16 + 2 * 9, 9 * 1, 9, 9); + else if (ip2 == armor) blit(xo, yo, 16 + 4 * 9, 9 * 1, 9, 9); + else if (ip2 > armor) blit(xo, yo, 16 + 0 * 9, 9 * 1, 9, 9); } int bg = 0; @@ -691,7 +702,7 @@ void Gui::renderBubbles() { if (minecraft->player->isUnderLiquid(Material::water)) { int screenWidth = (int)(minecraft->width * InvGuiScale); int screenHeight = (int)(minecraft->height * InvGuiScale); - + int xx = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenWidth / 2 - getNumSlots() * 10 - 1 : 2; int yo = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenHeight - 42 : 12; int count = (int) std::ceil((minecraft->player->airSupply - 2) * 10.0f / Player::TOTAL_AIR_SUPPLY); @@ -910,64 +921,64 @@ void Gui::renderOnSelectItemNameText( const int screenWidth, Font* font, int ySl // helper structure used by drawColoredString struct ColorSegment { - std::string text; - uint32_t color; + std::string text; + uint32_t color; }; // parse [tag] and [/tag] markers; tags may contain a color name (gold, green, etc.) static void parseColorTags(const std::string& in, std::vector& out) { - uint32_t curColor = 0xffffff; - size_t pos = 0; - while (pos < in.size()) { - size_t open = in.find('[', pos); - if (open == std::string::npos) { - out.push_back({in.substr(pos), curColor}); - break; - } - if (open > pos) { - out.push_back({in.substr(pos, open - pos), curColor}); - } - size_t close = in.find(']', open); - if (close == std::string::npos) { - out.push_back({in.substr(open), curColor}); - break; - } - std::string tag = in.substr(open + 1, close - open - 1); - if (!tag.empty() && tag[0] == '/') { - curColor = 0xffffff; - } else { - std::string lower; - lower.resize(tag.size()); - std::transform(tag.begin(), tag.end(), lower.begin(), ::tolower); - if (lower.find("gold") != std::string::npos) curColor = 0xffd700; - else if (lower.find("green") != std::string::npos) curColor = 0x00ff00; - else if (lower.find("yellow") != std::string::npos) curColor = 0xffff00; - else if (lower.find("red") != std::string::npos) curColor = 0xff0000; - else if (lower.find("blue") != std::string::npos) curColor = 0x0000ff; - } - pos = close + 1; - } + uint32_t curColor = 0xffffff; + size_t pos = 0; + while (pos < in.size()) { + size_t open = in.find('[', pos); + if (open == std::string::npos) { + out.push_back({in.substr(pos), curColor}); + break; + } + if (open > pos) { + out.push_back({in.substr(pos, open - pos), curColor}); + } + size_t close = in.find(']', open); + if (close == std::string::npos) { + out.push_back({in.substr(open), curColor}); + break; + } + std::string tag = in.substr(open + 1, close - open - 1); + if (!tag.empty() && tag[0] == '/') { + curColor = 0xffffff; + } else { + std::string lower; + lower.resize(tag.size()); + std::transform(tag.begin(), tag.end(), lower.begin(), ::tolower); + if (lower.find("gold") != std::string::npos) curColor = 0xffd700; + else if (lower.find("green") != std::string::npos) curColor = 0x00ff00; + else if (lower.find("yellow") != std::string::npos) curColor = 0xffff00; + else if (lower.find("red") != std::string::npos) curColor = 0xff0000; + else if (lower.find("blue") != std::string::npos) curColor = 0x0000ff; + } + pos = close + 1; + } } void Gui::drawColoredString(Font* font, const std::string& text, float x, float y, int alpha) { - std::vector segs; - parseColorTags(text, segs); - float cx = x; - for (auto &s : segs) { - int color = s.color + (alpha << 24); - font->drawShadow(s.text, cx, y, color); - cx += font->width(s.text); - } + std::vector segs; + parseColorTags(text, segs); + float cx = x; + for (auto &s : segs) { + int color = s.color + (alpha << 24); + font->drawShadow(s.text, cx, y, color); + cx += font->width(s.text); + } } float Gui::getColoredWidth(Font* font, const std::string& text) { - std::vector segs; - parseColorTags(text, segs); - float w = 0; - for (auto &s : segs) { - w += font->width(s.text); - } - return w; + std::vector segs; + parseColorTags(text, segs); + float w = 0; + for (auto &s : segs) { + w += font->width(s.text); + } + return w; } void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font* font ) { @@ -1011,13 +1022,13 @@ void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isC glEnable(GL_BLEND); // special-case join/leave announcements - int baseColor = 0xffffff; - if (msg.find(" joined the game") != std::string::npos || - msg.find(" left the game") != std::string::npos) { - baseColor = 0xffff00; // yellow - } - // replace previous logic; allow full colour tags now - Gui::drawColoredString(font, msg, x, y, alpha); + int baseColor = 0xffffff; + if (msg.find(" joined the game") != std::string::npos || + msg.find(" left the game") != std::string::npos) { + baseColor = 0xffff00; // yellow + } + // replace previous logic; allow full colour tags now + Gui::drawColoredString(font, msg, x, y, alpha); } } } @@ -1105,22 +1116,41 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) { // Draw count //Tesselator& t = Tesselator::instance; - glPushMatrix2(); - glScalef2(InvGuiScale + InvGuiScale, InvGuiScale + InvGuiScale, 1); + const float k = 0.5f * GuiScale; - - t.beginOverride(); - if (minecraft->gameMode->isSurvivalType()) { - x = baseItemX; - for (int i = 0; i < slots; i++) { - ItemInstance* item = minecraft->player->inventory->getItem(i); - if (item && item->count >= 0) - renderSlotText(item, k*x, k*ySlot + 1, true, true); - x += 20; + if (minecraft->options.getBooleanValue(OPTIONS_JAVA_HUD)) // if true enables the java beta item count size and color and calls the java items decorations + { + t.beginOverride(); + if (minecraft->gameMode->isSurvivalType()) { + x = baseItemX; + for (int i = 0; i < slots; i++) { + ItemInstance* item = minecraft->player->inventory->getItem(i); + if (item && item->count >= 0) + ItemRenderer::renderGuiItemDecorations(minecraft->font, minecraft->textures, minecraft->player->inventory->getItem(i), x, (float)ySlot); + x += 20; + } } + minecraft->textures->loadAndBindTexture("font/default8.png"); + t.endOverrideAndDraw(); + } + else { // otherwise uses the normal pocket edition one + glPushMatrix2(); + glScalef2(InvGuiScale + InvGuiScale, InvGuiScale + InvGuiScale, 1); + t.beginOverride(); + if (minecraft->gameMode->isSurvivalType()) { + x = baseItemX; + for (int i = 0; i < slots; i++) { + ItemInstance* item = minecraft->player->inventory->getItem(i); + if (item && item->count >= 0) + renderSlotText(item, k*x, k*ySlot, true, true); + x += 20; + } + } + + minecraft->textures->loadAndBindTexture("font/default8.png"); + t.endOverrideAndDraw(); + + glPopMatrix2(); } - minecraft->textures->loadAndBindTexture("font/default8.png"); - t.endOverrideAndDraw(); - glPopMatrix2(); } diff --git a/src/client/gui/screens/OptionsScreen.cpp b/src/client/gui/screens/OptionsScreen.cpp index 02a7a62..328a207 100755 --- a/src/client/gui/screens/OptionsScreen.cpp +++ b/src/client/gui/screens/OptionsScreen.cpp @@ -138,7 +138,7 @@ void OptionsScreen::render(int xm, int ym, float a) { if (currentOptionsGroup != NULL) currentOptionsGroup->render(minecraft, xmm, ymm); - + super::render(xm, ym, a); } @@ -222,11 +222,14 @@ void OptionsScreen::generateOptionScreens() { .addOptionItem(OPTIONS_ANAGLYPH_3D, minecraft) .addOptionItem(OPTIONS_VIEW_BOBBING, minecraft) .addOptionItem(OPTIONS_AMBIENT_OCCLUSION, minecraft); - + optionPanes[4]->addOptionItem(OPTIONS_ALLOW_SPRINT, minecraft) .addOptionItem(OPTIONS_BAR_ON_TOP, minecraft) .addOptionItem(OPTIONS_RPI_CURSOR, minecraft) - .addOptionItem(OPTIONS_FOLIAGE_TINT, minecraft); + .addOptionItem(OPTIONS_FOLIAGE_TINT, minecraft) + .addOptionItem(OPTIONS_JAVA_HUD, minecraft) + .addOptionItem(OPTIONS_FOG_TYPE, minecraft); + } void OptionsScreen::mouseClicked(int x, int y, int buttonNum) { @@ -248,7 +251,7 @@ void OptionsScreen::keyPressed(int eventKey) { currentOptionsGroup->keyPressed(minecraft, eventKey); if (eventKey == Keyboard::KEY_ESCAPE) minecraft->options.save(); - + super::keyPressed(eventKey); } diff --git a/src/client/renderer/LevelRenderer.cpp b/src/client/renderer/LevelRenderer.cpp index 73670cd..439a443 100755 --- a/src/client/renderer/LevelRenderer.cpp +++ b/src/client/renderer/LevelRenderer.cpp @@ -34,7 +34,7 @@ #endif LevelRenderer::LevelRenderer( Minecraft* mc) -: mc(mc), + : mc(mc), textures(mc->textures), level(NULL), cullStep(0), @@ -49,6 +49,7 @@ LevelRenderer::LevelRenderer( Minecraft* mc) xMaxChunk(0), yMaxChunk(0), zMaxChunk(0), lastViewDistance(-1), + lastFogType(-1), noEntityRenderFrames(2), totalEntities(0), @@ -145,10 +146,10 @@ void LevelRenderer::setLevel( Level* level ) level->addListener(this); allChanged(); } - if (mc->options.getBooleanValue(OPTIONS_AMBIENT_OCCLUSION)) { - mc->useAmbientOcclusion = !mc->useAmbientOcclusion; - allChanged(); - } + if (mc->options.getBooleanValue(OPTIONS_AMBIENT_OCCLUSION)) { + mc->useAmbientOcclusion = !mc->useAmbientOcclusion; + allChanged(); + } } void LevelRenderer::allChanged() @@ -161,6 +162,8 @@ void LevelRenderer::allChanged() Tile::leaves_carried->setFancy(fancy); lastViewDistance = mc->options.getIntValue(OPTIONS_VIEW_DISTANCE); + lastFogType = mc->options.getIntValue(OPTIONS_FOG_TYPE); + bool tint = mc->options.getBooleanValue(OPTIONS_FOLIAGE_TINT); FoliageColor::setUseTint(tint); GrassColor::setUseTint(tint); @@ -171,9 +174,9 @@ void LevelRenderer::allChanged() dist = (int)((float)dist * 0.8f); LOGI("last: %d, power: %d\n", lastViewDistance, mc->isPowerVR()); - #if defined(RPI) - dist *= 0.6f; - #endif +#if defined(RPI) + dist *= 0.6f; +#endif if (dist > 400) dist = 400; /* @@ -238,17 +241,17 @@ void LevelRenderer::allChanged() void LevelRenderer::deleteChunks() { for (int z = 0; z < zChunks; ++z) - for (int y = 0; y < yChunks; ++y) - for (int x = 0; x < xChunks; ++x) { - int c = getLinearCoord(x, y, z); - delete chunks[c]; - } + for (int y = 0; y < yChunks; ++y) + for (int x = 0; x < xChunks; ++x) { + int c = getLinearCoord(x, y, z); + delete chunks[c]; + } - delete[] chunks; - chunks = NULL; + delete[] chunks; + chunks = NULL; - delete[] sortedChunks; - sortedChunks = NULL; + delete[] sortedChunks; + sortedChunks = NULL; } void LevelRenderer::resortChunks( int xc, int yc, int zc ) @@ -312,6 +315,17 @@ int LevelRenderer::render( Mob* player, int layer, float alpha ) allChanged(); } + int currentFogType = mc->options.getIntValue(OPTIONS_FOG_TYPE); + if (currentFogType != lastFogType) { + lastFogType = currentFogType; + + if (level && level->dimension) { + level->dimension->FogType = currentFogType; // use new fog stuff + } + + allChanged(); + } + TIMER_PUSH("sortchunks"); for (int i = 0; i < 10; i++) { chunkFixOffs = (chunkFixOffs + 1) % chunksLength; @@ -580,11 +594,11 @@ int LevelRenderer::renderChunks( int from, int to, int layer, float alpha ) for (unsigned int i = 0; i < _renderChunks.size(); ++i) { Chunk* chunk = _renderChunks[i]; - #ifdef USE_VBO - renderList.addR(chunk->getRenderChunk(layer)); - #else - renderList.add(chunk->getList(layer)); - #endif +#ifdef USE_VBO + renderList.addR(chunk->getRenderChunk(layer)); +#else + renderList.add(chunk->getList(layer)); +#endif renderList.next(); } @@ -735,20 +749,20 @@ bool LevelRenderer::updateDirtyChunks( Mob* player, bool force ) Chunk* chunk = dirtyChunks[cursor]; if (chunk != NULL) { bool remove = false; - for (int i = 0; i < count && !remove; i++) - if (chunk == toAdd[i]) { - remove = true; - } - - if (!remove) { - //if (chunk == toAdd[0] || chunk == toAdd[1] || chunk == toAdd[2]) { - // ; // this chunk was rendered and should be removed - //} else { - if (target != cursor) { - dirtyChunks[target] = chunk; + for (int i = 0; i < count && !remove; i++) + if (chunk == toAdd[i]) { + remove = true; + } + + if (!remove) { + //if (chunk == toAdd[0] || chunk == toAdd[1] || chunk == toAdd[2]) { + // ; // this chunk was rendered and should be removed + //} else { + if (target != cursor) { + dirtyChunks[target] = chunk; + } + target++; } - target++; - } } cursor++; } @@ -922,23 +936,23 @@ bool entityRenderPredicate(const Entity* a, const Entity* b) { } void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { - if (noEntityRenderFrames > 0) { - noEntityRenderFrames--; - return; - } + if (noEntityRenderFrames > 0) { + noEntityRenderFrames--; + return; + } TIMER_PUSH("prepare"); - TileEntityRenderDispatcher::getInstance()->prepare(level, textures, mc->font, mc->cameraTargetPlayer, a); - EntityRenderDispatcher::getInstance()->prepare(level, mc->font, mc->cameraTargetPlayer, &mc->options, a); + TileEntityRenderDispatcher::getInstance()->prepare(level, textures, mc->font, mc->cameraTargetPlayer, a); + EntityRenderDispatcher::getInstance()->prepare(level, mc->font, mc->cameraTargetPlayer, &mc->options, a); - totalEntities = 0; - renderedEntities = 0; - culledEntities = 0; + totalEntities = 0; + renderedEntities = 0; + culledEntities = 0; Entity* player = mc->cameraTargetPlayer; - EntityRenderDispatcher::xOff = TileEntityRenderDispatcher::xOff = (player->xOld + (player->x - player->xOld) * a); - EntityRenderDispatcher::yOff = TileEntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a); - EntityRenderDispatcher::zOff = TileEntityRenderDispatcher::zOff = (player->zOld + (player->z - player->zOld) * a); + EntityRenderDispatcher::xOff = TileEntityRenderDispatcher::xOff = (player->xOld + (player->x - player->xOld) * a); + EntityRenderDispatcher::yOff = TileEntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a); + EntityRenderDispatcher::zOff = TileEntityRenderDispatcher::zOff = (player->zOld + (player->z - player->zOld) * a); glEnableClientState2(GL_VERTEX_ARRAY); glEnableClientState2(GL_TEXTURE_COORD_ARRAY); @@ -977,10 +991,10 @@ void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { delete[] toRender; } - TIMER_POP_PUSH("tileentities"); - for (unsigned int i = 0; i < level->tileEntities.size(); i++) { - TileEntityRenderDispatcher::getInstance()->render(level->tileEntities[i], a); - } + TIMER_POP_PUSH("tileentities"); + for (unsigned int i = 0; i < level->tileEntities.size(); i++) { + TileEntityRenderDispatcher::getInstance()->render(level->tileEntities[i], a); + } glDisableClientState2(GL_VERTEX_ARRAY); glDisableClientState2(GL_TEXTURE_COORD_ARRAY); @@ -991,7 +1005,7 @@ void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { std::string LevelRenderer::gatherStats1() { std::stringstream ss; ss << "C: " << renderedChunks << "/" << totalChunks << ". F: " << offscreenChunks << ", O: " << occludedChunks << ", E: " << emptyChunks << "\n"; - return ss.str(); + return ss.str(); } // @@ -1003,34 +1017,34 @@ std::string LevelRenderer::gatherStats1() { // IntBuffer resultBuffer = MemoryTracker.createIntBuffer(64); void LevelRenderer::renderSky(float alpha) { - if (mc->level->dimension->foggy) return; + if (mc->level->dimension->foggy) return; - glDisable2(GL_TEXTURE_2D); - Vec3 sc = level->getSkyColor(mc->cameraTargetPlayer, alpha); - float sr = (float) sc.x; - float sg = (float) sc.y; - float sb = (float) sc.z;// + 0.5f; + glDisable2(GL_TEXTURE_2D); + Vec3 sc = level->getSkyColor(mc->cameraTargetPlayer, alpha); + float sr = (float) sc.x; + float sg = (float) sc.y; + float sb = (float) sc.z;// + 0.5f; - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { - float srr = (sr * 30.0f + sg * 59.0f + sb * 11.0f) / 100.0f; - float sgg = (sr * 30.0f + sg * 70.0f) / (100.0f); - float sbb = (sr * 30.0f + sb * 70.0f) / (100.0f); + if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { + float srr = (sr * 30.0f + sg * 59.0f + sb * 11.0f) / 100.0f; + float sgg = (sr * 30.0f + sg * 70.0f) / (100.0f); + float sbb = (sr * 30.0f + sb * 70.0f) / (100.0f); - sr = srr; - sg = sgg; - sb = sbb; - } - glColor4f2(sr, sg, Mth::Min(1.0f, sb), 1); + sr = srr; + sg = sgg; + sb = sbb; + } + glColor4f2(sr, sg, Mth::Min(1.0f, sb), 1); - //Tesselator& t = Tesselator::instance; + //Tesselator& t = Tesselator::instance; - glEnable2(GL_FOG); - glColor4f2(sr, sg, sb, 1.0f); + glEnable2(GL_FOG); + glColor4f2(sr, sg, sb, 1.0f); #ifdef OPENGL_ES drawArrayVT(skyBuffer, skyVertexCount); #endif - glEnable2(GL_TEXTURE_2D); + glEnable2(GL_TEXTURE_2D); } void LevelRenderer::renderClouds( float alpha ) { @@ -1044,7 +1058,7 @@ void LevelRenderer::renderClouds( float alpha ) { //glBindTexture(GL_TEXTURE_2D, texturesloadTexture("/environment/clouds.png")); textures->loadAndBindTexture("environment/clouds.png"); - + glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1087,17 +1101,17 @@ void LevelRenderer::playSound(const std::string& name, float x, float y, float z // @todo: deny sounds here if sound is off (rather than waiting 'til SoundEngine) float dd = 16; - if (volume > 1) dd *= volume; - if (mc->cameraTargetPlayer->distanceToSqr(x, y, z) < dd * dd) { - mc->soundEngine->play(name, x, y, z, volume, pitch); - } + if (volume > 1) dd *= volume; + if (mc->cameraTargetPlayer->distanceToSqr(x, y, z) < dd * dd) { + mc->soundEngine->play(name, x, y, z, volume, pitch); + } } void LevelRenderer::addParticle(const std::string& name, float x, float y, float z, float xa, float ya, float za, int data) { float xd = mc->cameraTargetPlayer->x - x; - float yd = mc->cameraTargetPlayer->y - y; - float zd = mc->cameraTargetPlayer->z - z; + float yd = mc->cameraTargetPlayer->y - y; + float zd = mc->cameraTargetPlayer->z - z; float distanceSquared = xd * xd + yd * yd + zd * zd; //Particle* p = NULL; @@ -1111,27 +1125,27 @@ void LevelRenderer::addParticle(const std::string& name, float x, float y, float // return; //} - const float particleDistance = 16; - if (distanceSquared > particleDistance * particleDistance) return; + const float particleDistance = 16; + if (distanceSquared > particleDistance * particleDistance) return; //static Stopwatch sw; //sw.start(); - if (name == "bubble") mc->particleEngine->add(new BubbleParticle(level, x, y, z, xa, ya, za)); + if (name == "bubble") mc->particleEngine->add(new BubbleParticle(level, x, y, z, xa, ya, za)); else if (name == "crit") mc->particleEngine->add(new CritParticle2(level, x, y, z, xa, ya, za)); else if (name == "smoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za)); - //else if (name == "note") mc->particleEngine->add(new NoteParticle(level, x, y, z, xa, ya, za)); - else if (name == "explode") mc->particleEngine->add(new ExplodeParticle(level, x, y, z, xa, ya, za)); - else if (name == "flame") mc->particleEngine->add(new FlameParticle(level, x, y, z, xa, ya, za)); - else if (name == "lava") mc->particleEngine->add(new LavaParticle(level, x, y, z)); - //else if (name == "splash") mc->particleEngine->add(new SplashParticle(level, x, y, z, xa, ya, za)); + //else if (name == "note") mc->particleEngine->add(new NoteParticle(level, x, y, z, xa, ya, za)); + else if (name == "explode") mc->particleEngine->add(new ExplodeParticle(level, x, y, z, xa, ya, za)); + else if (name == "flame") mc->particleEngine->add(new FlameParticle(level, x, y, z, xa, ya, za)); + else if (name == "lava") mc->particleEngine->add(new LavaParticle(level, x, y, z)); + //else if (name == "splash") mc->particleEngine->add(new SplashParticle(level, x, y, z, xa, ya, za)); else if (name == "largesmoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f)); - else if (name == "reddust") mc->particleEngine->add(new RedDustParticle(level, x, y, z, xa, ya, za)); + else if (name == "reddust") mc->particleEngine->add(new RedDustParticle(level, x, y, z, xa, ya, za)); else if (name == "iconcrack") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data])); else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall)); - //else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall)); - //else if (name == "slime") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::slimeBall)); - //else if (name == "heart") mc->particleEngine->add(new HeartParticle(level, x, y, z, xa, ya, za)); + //else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall)); + //else if (name == "slime") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::slimeBall)); + //else if (name == "heart") mc->particleEngine->add(new HeartParticle(level, x, y, z, xa, ya, za)); //sw.stop(); //sw.printEvery(50, "add-particle-string"); @@ -1139,53 +1153,53 @@ void LevelRenderer::addParticle(const std::string& name, float x, float y, float /* void LevelRenderer::addParticle(ParticleType::Id name, float x, float y, float z, float xa, float ya, float za, int data) { - float xd = mc->cameraTargetPlayer->x - x; - float yd = mc->cameraTargetPlayer->y - y; - float zd = mc->cameraTargetPlayer->z - z; +float xd = mc->cameraTargetPlayer->x - x; +float yd = mc->cameraTargetPlayer->y - y; +float zd = mc->cameraTargetPlayer->z - z; - const float particleDistance = 16; - if (xd * xd + yd * yd + zd * zd > particleDistance * particleDistance) return; +const float particleDistance = 16; +if (xd * xd + yd * yd + zd * zd > particleDistance * particleDistance) return; - //static Stopwatch sw; - //sw.start(); +//static Stopwatch sw; +//sw.start(); - //Particle* p = NULL; +//Particle* p = NULL; - if (name == ParticleType::bubble) mc->particleEngine->add( new BubbleParticle(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::crit) mc->particleEngine->add(new CritParticle2(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::smoke) mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::explode) mc->particleEngine->add( new ExplodeParticle(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::flame) mc->particleEngine->add( new FlameParticle(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::lava) mc->particleEngine->add( new LavaParticle(level, x, y, z) ); - else if (name == ParticleType::largesmoke) mc->particleEngine->add( new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f) ); - else if (name == ParticleType::reddust) mc->particleEngine->add( new RedDustParticle(level, x, y, z, xa, ya, za) ); - else if (name == ParticleType::iconcrack) mc->particleEngine->add( new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]) ); +if (name == ParticleType::bubble) mc->particleEngine->add( new BubbleParticle(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::crit) mc->particleEngine->add(new CritParticle2(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::smoke) mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::explode) mc->particleEngine->add( new ExplodeParticle(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::flame) mc->particleEngine->add( new FlameParticle(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::lava) mc->particleEngine->add( new LavaParticle(level, x, y, z) ); +else if (name == ParticleType::largesmoke) mc->particleEngine->add( new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f) ); +else if (name == ParticleType::reddust) mc->particleEngine->add( new RedDustParticle(level, x, y, z, xa, ya, za) ); +else if (name == ParticleType::iconcrack) mc->particleEngine->add( new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]) ); - //switch (name) { - // case ParticleType::bubble: p = new BubbleParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::crit: p = new CritParticle2(level, x, y, z, xa, ya, za); break; - // case ParticleType::smoke: p = new SmokeParticle(level, x, y, z, xa, ya, za); break; - // //case ParticleType::note: p = new NoteParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::explode: p = new ExplodeParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::flame: p = new FlameParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::lava: p = new LavaParticle(level, x, y, z); break; - // //case ParticleType::splash: p = new SplashParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::largesmoke: p = new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f); break; - // case ParticleType::reddust: p = new RedDustParticle(level, x, y, z, xa, ya, za); break; - // case ParticleType::iconcrack: p = new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]); break; - // //case ParticleType::snowballpoof: p = new BreakingItemParticle(level, x, y, z, Item::snowBall); break; - // //case ParticleType::slime: p = new BreakingItemParticle(level, x, y, z, Item::slimeBall); break; - // //case ParticleType::heart: p = new HeartParticle(level, x, y, z, xa, ya, za); break; - // default: - // LOGW("Couldn't find particle of type: %d\n", name); - // break; - //} - //if (p) { - // mc->particleEngine->add(p); - //} +//switch (name) { +// case ParticleType::bubble: p = new BubbleParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::crit: p = new CritParticle2(level, x, y, z, xa, ya, za); break; +// case ParticleType::smoke: p = new SmokeParticle(level, x, y, z, xa, ya, za); break; +// //case ParticleType::note: p = new NoteParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::explode: p = new ExplodeParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::flame: p = new FlameParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::lava: p = new LavaParticle(level, x, y, z); break; +// //case ParticleType::splash: p = new SplashParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::largesmoke: p = new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f); break; +// case ParticleType::reddust: p = new RedDustParticle(level, x, y, z, xa, ya, za); break; +// case ParticleType::iconcrack: p = new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]); break; +// //case ParticleType::snowballpoof: p = new BreakingItemParticle(level, x, y, z, Item::snowBall); break; +// //case ParticleType::slime: p = new BreakingItemParticle(level, x, y, z, Item::slimeBall); break; +// //case ParticleType::heart: p = new HeartParticle(level, x, y, z, xa, ya, za); break; +// default: +// LOGW("Couldn't find particle of type: %d\n", name); +// break; +//} +//if (p) { +// mc->particleEngine->add(p); +//} - //sw.stop(); - //sw.printEvery(50, "add-particle-enum"); +//sw.stop(); +//sw.printEvery(50, "add-particle-enum"); } */ @@ -1203,7 +1217,7 @@ void LevelRenderer::renderHitSelect( Player* player, const HitResult& h, int mod glEnable2(GL_DEPTH_TEST); textures->loadAndBindTexture("terrain.png"); - + int tileId = level->getTile(h.x, h.y, h.z); Tile* tile = tileId > 0 ? Tile::tiles[tileId] : NULL; glDisable2(GL_ALPHA_TEST); @@ -1300,11 +1314,11 @@ void LevelRenderer::takePicture( TripodCamera* cam, Entity* entity ) void LevelRenderer::levelEvent(Player* player, int type, int x, int y, int z, int data) { switch (type) { case LevelEvent::SOUND_OPEN_DOOR: - if (Mth::random() < 0.5f) { - level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.door_open", 1, level->random.nextFloat() * 0.1f + 0.9f); - } else { - level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.door_close", 1, level->random.nextFloat() * 0.1f + 0.9f); - } - break; + if (Mth::random() < 0.5f) { + level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.door_open", 1, level->random.nextFloat() * 0.1f + 0.9f); + } else { + level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.door_close", 1, level->random.nextFloat() * 0.1f + 0.9f); + } + break; } } diff --git a/src/client/renderer/LevelRenderer.h b/src/client/renderer/LevelRenderer.h index df43de1..2a9c7e2 100755 --- a/src/client/renderer/LevelRenderer.h +++ b/src/client/renderer/LevelRenderer.h @@ -113,6 +113,9 @@ private: bool occlusionCheck; int lastViewDistance; + // shredder added again... + int lastFogType; + int ticks; int starList, skyList, darkList; diff --git a/src/client/renderer/entity/EntityRenderDispatcher.cpp b/src/client/renderer/entity/EntityRenderDispatcher.cpp index a3148fc..b0edea7 100755 --- a/src/client/renderer/entity/EntityRenderDispatcher.cpp +++ b/src/client/renderer/entity/EntityRenderDispatcher.cpp @@ -40,18 +40,18 @@ EntityRenderDispatcher::EntityRenderDispatcher() { //@note: The Models (model/armor) will be deleted by resp. MobRenderer assign( ER_ITEM_RENDERER, new ItemRenderer()); - assign( ER_HUMANOID_RENDERER, new HumanoidMobRenderer(new HumanoidModel(), 0)); - assign( ER_PIG_RENDERER, new PigRenderer(new PigModel(), NULL/*new PigModel(0.5f)*/, 0)); - assign( ER_COW_RENDERER, new MobRenderer(new CowModel(), 0)); - assign( ER_CHICKEN_RENDERER, new ChickenRenderer( new ChickenModel(), 0)); - assign( ER_SHEEP_RENDERER, new SheepRenderer(new SheepModel(), new SheepFurModel(), 0)); + assign( ER_HUMANOID_RENDERER, new HumanoidMobRenderer(new HumanoidModel(), 0.5)); + assign( ER_PIG_RENDERER, new PigRenderer(new PigModel(0.5), NULL/*new PigModel(0.5f)*/, 0.7)); + assign( ER_COW_RENDERER, new MobRenderer(new CowModel(), 0.7)); + assign( ER_CHICKEN_RENDERER, new ChickenRenderer( new ChickenModel(), 0.3)); + assign( ER_SHEEP_RENDERER, new SheepRenderer(new SheepModel(), new SheepFurModel(), 0.7)); assign( ER_SKELETON_RENDERER, new HumanoidMobRenderer(new SkeletonModel(), 0.5f)); assign( ER_ZOMBIE_RENDERER, new HumanoidMobRenderer(new ZombieModel(), 0.5f)); assign( ER_CREEPER_RENDERER, new CreeperRenderer()); assign( ER_SPIDER_RENDERER, new SpiderRenderer()); assign( ER_TNT_RENDERER, new TntRenderer()); assign( ER_ARROW_RENDERER, new ArrowRenderer()); - assign( ER_PLAYER_RENDERER, new PlayerRenderer(new HumanoidModel(0, 0, 64, 64), 0)); + assign( ER_PLAYER_RENDERER, new PlayerRenderer(new HumanoidModel(0, 0, 64, 64), 0.5)); assign( ER_THROWNEGG_RENDERER, new ItemSpriteRenderer(Item::egg->getIcon(0))); assign( ER_SNOWBALL_RENDERER, new ItemSpriteRenderer(Item::snowBall->getIcon(0))); assign( ER_PAINTING_RENDERER, new PaintingRenderer()); @@ -133,7 +133,7 @@ void EntityRenderDispatcher::render( Entity* entity, float x, float y, float z, EntityRenderer* renderer = getRenderer(entity); if (renderer != NULL) { renderer->render(entity, x, y, z, rot, a); - //renderer->postRender(entity, x, y, z, rot, a); + renderer->postRender(entity, x, y, z, rot, a); } } diff --git a/src/client/renderer/entity/EntityRenderer.cpp b/src/client/renderer/entity/EntityRenderer.cpp index 641581b..ad500b2 100755 --- a/src/client/renderer/entity/EntityRenderer.cpp +++ b/src/client/renderer/entity/EntityRenderer.cpp @@ -5,11 +5,17 @@ #include "../gles.h" #include "../../../world/phys/AABB.h" #include "EntityRenderDispatcher.h" +#include "../../../util/Mth.h" +#include "../../../world/level/Level.h" +#include "../../../world/level/tile/Tile.h" + +#include "../../Minecraft.h" +#include "../../Option.h" EntityRenderDispatcher* EntityRenderer::entityRenderDispatcher = NULL; EntityRenderer::EntityRenderer() -: shadowRadius(0), + : shadowRadius(0), shadowStrength(1.0f) {} @@ -36,37 +42,37 @@ void EntityRenderer::render(const AABB& bb, float xo, float yo, float zo) { glColor4f2(1, 1, 1, 1); t.begin(); t.offset(xo, yo, zo); - //t.normal(0, 0, -1); + t.normal(0, 0, -1); t.vertex(bb.x0, bb.y1, bb.z0); t.vertex(bb.x1, bb.y1, bb.z0); t.vertex(bb.x1, bb.y0, bb.z0); t.vertex(bb.x0, bb.y0, bb.z0); - //t.normal(0, 0, 1); + t.normal(0, 0, 1); t.vertex(bb.x0, bb.y0, bb.z1); t.vertex(bb.x1, bb.y0, bb.z1); t.vertex(bb.x1, bb.y1, bb.z1); t.vertex(bb.x0, bb.y1, bb.z1); - //t.normal(0, -1, 0); + t.normal(0, -1, 0); t.vertex(bb.x0, bb.y0, bb.z0); t.vertex(bb.x1, bb.y0, bb.z0); t.vertex(bb.x1, bb.y0, bb.z1); t.vertex(bb.x0, bb.y0, bb.z1); - //t.normal(0, 1, 0); + t.normal(0, 1, 0); t.vertex(bb.x0, bb.y1, bb.z1); t.vertex(bb.x1, bb.y1, bb.z1); t.vertex(bb.x1, bb.y1, bb.z0); t.vertex(bb.x0, bb.y1, bb.z0); - //t.normal(-1, 0, 0); + t.normal(-1, 0, 0); t.vertex(bb.x0, bb.y0, bb.z1); t.vertex(bb.x0, bb.y1, bb.z1); t.vertex(bb.x0, bb.y1, bb.z0); t.vertex(bb.x0, bb.y0, bb.z0); - //t.normal(1, 0, 0); + t.normal(1, 0, 0); t.vertex(bb.x1, bb.y0, bb.z0); t.vertex(bb.x1, bb.y1, bb.z0); t.vertex(bb.x1, bb.y1, bb.z1); @@ -116,134 +122,139 @@ Font* EntityRenderer::getFont() { return entityRenderDispatcher->getFont(); } -//void postRender(Entity entity, float x, float y, float z, float rot, float a) { -// if (entityRenderDispatcher.options.fancyGraphics && shadowRadius > 0) { -// float dist = entityRenderDispatcher.distanceToSqr(entity.x, entity.y, entity.z); -// float pow = (float) ((1 - dist / (16.0f * 16.0f)) * shadowStrength); -// if (pow > 0) { -// renderShadow(entity, x, y, z, pow, a); -// } -// } -// if (entity.isOnFire()) renderFlame(entity, x, y, z, a); -//} +void EntityRenderer::postRender(Entity* entity, float x, float y, float z, float rot, float a) { + if (/*entityRenderDispatcher.options.fancyGraphics &&*/entityRenderDispatcher->minecraft->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS) && shadowRadius > 0) { + float dist = entityRenderDispatcher->distanceToSqr(entity->x, entity->y, entity->z); + float pow = (float) ((1 - dist / (16.0f * 16.0f)) * shadowStrength); + if (pow > 0) { + renderShadow(entity, x, y, z, pow, a); + } + //} + if (entity->isOnFire()) renderFlame(entity, x, y, z, a); + } +} +void EntityRenderer::renderFlame(Entity* e, float x, float y, float z, float a) { -//void renderFlame(Entity e, float x, float y, float z, float a) { -// glDisable2(GL_LIGHTING); -// int tex = Tile.fire.tex; + int tex = ((Tile*)Tile::fire)->tex; -// int xt = (tex & 0xf) << 4; -// int yt = tex & 0xf0; + int xt = (tex & 0xf) << 4; + int yt = tex & 0xf0; -// float u0 = (xt) / 256.0f; -// float u1 = (xt + 15.99f) / 256.0f; -// float v0 = (yt) / 256.0f; -// float v1 = (yt + 15.99f) / 256.0f; + float u0 = (xt) / 256.0f; + float u1 = (xt + 15.99f) / 256.0f; + float v0 = (yt) / 256.0f; + float v1 = (yt + 15.99f) / 256.0f; -// glPushMatrix2(); -// glTranslatef2((float) x, (float) y, (float) z); + glPushMatrix2(); + glTranslatef2((float) x, (float) y, (float) z); -// float s = e.bbWidth * 1.4f; -// glScalef2(s, s, s); -// bindTexture("terrain.png"); -// Tesselator t = Tesselator.instance; + float s = e->bbWidth * 1.4f; + glScalef2(s, s, s); + bindTexture("terrain.png"); + Tesselator& t = Tesselator::instance; -// float r = 1.0f; -// float xo = 0.5f; -// float yo = 0.0f; + float r = 1.0f; + float xo = 0.5f; + float yo = 0.0f; -// float h = e.bbHeight / e.bbWidth; + float h = e->bbHeight / e->bbWidth; -// glRotatef2(-entityRenderDispatcher.playerRotY, 0, 1, 0); -// glTranslatef2(0, 0, -0.4f + ((int) h) * 0.02f); -// glColor4f2(1, 1, 1, 1); -// // glRotatef2(-playerRotX, 1, 0, 0); -// t.begin(); -// while (h > 0) { -// t.vertexUV(r - xo, 0 - yo, 0, u1, v1); -// t.vertexUV(0 - xo, 0 - yo, 0, u0, v1); -// t.vertexUV(0 - xo, 1.4f - yo, 0, u0, v0); -// t.vertexUV(r - xo, 1.4f - yo, 0, u1, v0); -// h -= 1; -// yo -= 1; -// r *= 0.9f; -// glTranslatef2(0, 0, -0.04f); -// } -// t.end(); -// glPopMatrix2(); -// glEnable2(GL_LIGHTING); -//} + glRotatef2(-entityRenderDispatcher->playerRotY, 0, 1, 0); + glTranslatef2(0, 0, -0.4f + ((int) h) * 0.02f); + glColor4f2(1, 1, 1, 1); + // glRotatef2(-playerRotX, 1, 0, 0); + t.begin(); + while (h > 0) { + t.vertexUV(r - xo, 0 - yo, 0, u1, v1); + t.vertexUV(0 - xo, 0 - yo, 0, u0, v1); + t.vertexUV(0 - xo, 1.4f - yo, 0, u0, v0); + t.vertexUV(r - xo, 1.4f - yo, 0, u1, v0); + h -= 1; + yo -= 1; + r *= 0.9f; + glTranslatef2(0, 0, -0.04f); + } + t.draw(); + glPopMatrix2(); + // glEnable2(GL_LIGHTING); +} -//void renderShadow(Entity e, float x, float y, float z, float pow, float a) { -// glEnable2(GL_BLEND); -// glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +void EntityRenderer::renderShadow(Entity* e, float x, float y, float z, float pow, float a) { // + glEnable2(GL_BLEND); + glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); -// Textures textures = entityRenderDispatcher.textures; -// textures.bind(textures.loadTexture("%clamp%/misc/shadow.png")); + //Textures* textures = entityRenderDispatcher->textures; + //textures->bind(textures->loadTexture("%clamp%/environment/shadow.png")); + Textures* textures = entityRenderDispatcher->textures; + textures->bind(textures->loadTexture("/misc/shadow.png")); -// Level level = getLevel(); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); -// glDepthMask(false); -// float r = shadowRadius; + Level* level = getLevel(); -// float ex = e.xOld + (e.x - e.xOld) * a; -// float ey = e.yOld + (e.y - e.yOld) * a + e.getShadowHeightOffs(); -// float ez = e.zOld + (e.z - e.zOld) * a; + glDepthMask(false); + float r = shadowRadius; -// int x0 = Mth.floor(ex - r); -// int x1 = Mth.floor(ex + r); -// int y0 = Mth.floor(ey - r); -// int y1 = Mth.floor(ey); -// int z0 = Mth.floor(ez - r); -// int z1 = Mth.floor(ez + r); + float ex = e->xOld + (e->x - e->xOld) * a; + float ey = e->yOld + (e->y - e->yOld) * a + e->getShadowHeightOffs(); + float ez = e->zOld + (e->z - e->zOld) * a; -// float xo = x - ex; -// float yo = y - ey; -// float zo = z - ez; + int x0 = Mth::floor(ex - r); + int x1 = Mth::floor(ex + r); + int y0 = Mth::floor(ey - r); + int y1 = Mth::floor(ey); + int z0 = Mth::floor(ez - r); + int z1 = Mth::floor(ez + r); -// Tesselator tt = Tesselator.instance; -// tt.begin(); -// for (int xt = x0; xt <= x1; xt++) -// for (int yt = y0; yt <= y1; yt++) -// for (int zt = z0; zt <= z1; zt++) { -// int t = level.getTile(xt, yt - 1, zt); -// if (t > 0 && level.getRawBrightness(xt, yt, zt) > 3) { -// renderTileShadow(Tile.tiles[t], x, y + e.getShadowHeightOffs(), z, xt, yt, zt, pow, r, xo, yo + e.getShadowHeightOffs(), zo); -// } -// } -// tt.end(); + float xo = x - ex; + float yo = y - ey; + float zo = z - ez; -// glColor4f2(1, 1, 1, 1); -// glDisable2(GL_BLEND); -// glDepthMask(true); -//} + Tesselator& tt = Tesselator::instance; + tt.begin(); + for (int xt = x0; xt <= x1; xt++) + for (int yt = y0; yt <= y1; yt++) + for (int zt = z0; zt <= z1; zt++) { + int t = level->getTile(xt, yt - 1, zt); + if (t > 0 && level->getRawBrightness(xt, yt, zt) > 3) { + renderTileShadow(Tile::tiles[t], x, y + e->getShadowHeightOffs(), z, xt, yt, zt, pow, r, xo, yo + e->getShadowHeightOffs(), zo); + } + } + tt.draw(); -//Level* getLevel() { -// return entityRenderDispatcher.level; -//} + glColor4f2(1, 1, 1, 1); + glDisable2(GL_BLEND); + glDepthMask(true); +} -//void renderTileShadow(Tile tt, float x, float y, float z, int xt, int yt, int zt, float pow, float r, float xo, float yo, float zo) { -// Tesselator t = Tesselator.instance; -// if (!tt.isCubeShaped()) return; +Level* EntityRenderer::getLevel() { + return entityRenderDispatcher->level; +} -// float a = ((pow - (y - (yt + yo)) / 2) * 0.5f) * getLevel().getBrightness(xt, yt, zt); -// if (a < 0) return; -// if (a > 1) a = 1; -// t.color(1, 1, 1, (float) a); -// // glColor4f2(1, 1, 1, (float) a); +void EntityRenderer::renderTileShadow(Tile* tt, float x, float y, float z, int xt, int yt, int zt, float pow, float r, float xo, float yo, float zo) { + Tesselator& t = Tesselator::instance; + if (!tt->isCubeShaped()) return; -// float x0 = xt + tt.xx0 + xo; -// float x1 = xt + tt.xx1 + xo; -// float y0 = yt + tt.yy0 + yo + 1.0 / 64.0f; -// float z0 = zt + tt.zz0 + zo; -// float z1 = zt + tt.zz1 + zo; + float a = ((pow - (y - (yt + yo)) / 2) * 0.5f) * getLevel()->getBrightness(xt, yt, zt); + if (a < 0) return; + if (a > 1) a = 1; + // t.color(1, 1, 1, (float) a); + glColor4f2(1, 1, 1, (float) a); -// float u0 = (float) ((x - (x0)) / 2 / r + 0.5f); -// float u1 = (float) ((x - (x1)) / 2 / r + 0.5f); -// float v0 = (float) ((z - (z0)) / 2 / r + 0.5f); -// float v1 = (float) ((z - (z1)) / 2 / r + 0.5f); + float x0 = xt + tt->xx0 + xo; + float x1 = xt + tt->xx1 + xo; + float y0 = yt + tt->yy0 + yo + 1.0 / 64.0f; + float z0 = zt + tt->zz0 + zo; + float z1 = zt + tt->zz1 + zo; -// t.vertexUV(x0, y0, z0, u0, v0); -// t.vertexUV(x0, y0, z1, u0, v1); -// t.vertexUV(x1, y0, z1, u1, v1); -// t.vertexUV(x1, y0, z0, u1, v0); -//} + float u0 = (float) ((x - (x0)) / 2 / r + 0.5f); + float u1 = (float) ((x - (x1)) / 2 / r + 0.5f); + float v0 = (float) ((z - (z0)) / 2 / r + 0.5f); + float v1 = (float) ((z - (z1)) / 2 / r + 0.5f); + + t.vertexUV(x0, y0, z0, u0, v0); + t.vertexUV(x0, y0, z1, u0, v1); + t.vertexUV(x1, y0, z1, u1, v1); + t.vertexUV(x1, y0, z0, u1, v0); +} diff --git a/src/client/renderer/entity/EntityRenderer.h b/src/client/renderer/entity/EntityRenderer.h index 318f7f2..699c82d 100755 --- a/src/client/renderer/entity/EntityRenderer.h +++ b/src/client/renderer/entity/EntityRenderer.h @@ -12,6 +12,8 @@ class EntityRenderDispatcher; class Entity; class AABB; class Font; +class Tile; +class Level; class EntityRenderer { @@ -24,6 +26,11 @@ public: virtual void render(Entity* entity, float x, float y, float z, float rot, float a) = 0; static void render(const AABB& bb, float xo, float yo, float zo); static void renderFlat(const AABB& bb); + void renderShadow(Entity* e, float x, float y, float z, float pow, float a); + void renderTileShadow(Tile* tt, float x, float y, float z, int xt, int yt, int zt, float pow, float r, float xo, float yo, float zo); + void renderFlame(Entity* e, float x, float y, float z, float a); + void postRender(Entity* entity, float x, float y, float z, float rot, float a); + Level* getLevel(); Font* getFont(); diff --git a/src/client/renderer/entity/ItemRenderer.cpp b/src/client/renderer/entity/ItemRenderer.cpp index 15e63d1..eaf29b4 100755 --- a/src/client/renderer/entity/ItemRenderer.cpp +++ b/src/client/renderer/entity/ItemRenderer.cpp @@ -226,7 +226,40 @@ void ItemRenderer::renderGuiItem(Font* font, Textures* textures, const ItemInsta t.draw(); } -void ItemRenderer::renderGuiItemDecorations(const ItemInstance* item, float x, float y) { + +void ItemRenderer::renderGuiItemDecorations(Font* font, Textures* textures, ItemInstance* item, int x, int y){ // this is normally unused in the header but i ported it from java beta - shredder + if (item != NULL) { + if (item->count > 1) { + std::string countStr = std::to_string(item->count); + // glDisable(GL_LIGHTING); + // glDisable(GL_DEPTH_TEST); + font->drawShadow(countStr, x + 19 - 2 - font->width(countStr), + y + 6 + 3, 0xFFFFFF); + // glEnable(GL_LIGHTING); + // glEnable(GL_DEPTH_TEST); + } + if (item->isDamaged()) { + float p = std::floor(13.5f - (float) item->getDamageValue() * 13.0f / (float) item->getMaxDamage() + 0.5); + int cc = (int) std::floor(255.5f - (float) item->getDamageValue() * 255.0f / (float) item->getMaxDamage() + 0.5); + // glDisable(GL_LIGHTING); + // glDisable(GL_DEPTH_TEST); + // glDisable(GL_TEXTURE_2D); + // auto var8 = ::net::minecraft::client::renderer::Tesselator::instance(); + Tesselator& t = Tesselator::instance; + int ca = 255 - cc << 16 | cc << 8; + int cb = (255 - cc) / 4 << 16 | 16128; + fillRect(t, x + 2, y + 13, 13, 2, 0); + fillRect(t, x + 2, y + 13, 12, 1, cb); + fillRect(t, x + 2, y + 13, p, 1, ca); + // glEnable(GL_TEXTURE_2D); + // glEnable(GL_LIGHTING); + // glEnable(GL_DEPTH_TEST); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + } +} + +void ItemRenderer::renderGuiItemDecorations(const ItemInstance* item, float x, float y) { // nothing changed here this is the normal pocket edition one. if (!item) return; if (item->count > 0 && item->isDamaged()) { float p = std::floor(13.5f - (float) item->getDamageValue() * 13.0f / (float) item->getMaxDamage()); diff --git a/src/client/renderer/entity/ItemRenderer.h b/src/client/renderer/entity/ItemRenderer.h index 9fb88f6..a104dc7 100755 --- a/src/client/renderer/entity/ItemRenderer.h +++ b/src/client/renderer/entity/ItemRenderer.h @@ -22,7 +22,7 @@ public: static void renderGuiItem(Font* font, Textures* textures, const ItemInstance* item, float x, float y, bool fancy); static void renderGuiItem(Font* font, Textures* textures, const ItemInstance* item, float x, float y, float w, float h, bool fancy); static void renderGuiItemCorrect(Font* font, Textures* textures, const ItemInstance* item, int x, int y); - //void renderGuiItemDecorations(Font* font, Textures* textures, ItemInstance* item, int x, int y); + static void renderGuiItemDecorations(Font* font, Textures* textures, ItemInstance* item, int x, int y); static void renderGuiItemDecorations(const ItemInstance* item, float x, float y); static void blit(float x, float y, float sx, float sy, float w, float h); diff --git a/src/client/renderer/entity/MobRenderer.cpp b/src/client/renderer/entity/MobRenderer.cpp index 51ccee9..3d6b3d9 100755 --- a/src/client/renderer/entity/MobRenderer.cpp +++ b/src/client/renderer/entity/MobRenderer.cpp @@ -135,7 +135,7 @@ void MobRenderer::render(Entity* e, float x, float y, float z, float rot, float //glEnable2(GL_DEPTH_TEST); glPopMatrix2(); - + postRender(mob, x, y, z, rot, a); renderName(mob, x, y, z); } diff --git a/src/util/Color.cpp b/src/util/Color.cpp new file mode 100644 index 0000000..9afaa5c --- /dev/null +++ b/src/util/Color.cpp @@ -0,0 +1,98 @@ +#include "Mth.h" + +#include "Color.h" +#include + +//Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). +//Alpha is defaulted to 1.0. The actual color used in rendering depends on finding the best match given the color space +//available for a particular output device. +//Parameters: +//r - the red component +//g - the green component +//b - the blue component +//Throws: +//IllegalArgumentException - if r, g or b are outside of the range 0.0 to 1.0, inclusive +Color::Color( float r, float g, float b) +{ + assert( r >= 0.0f && r <= 1.0f ); + assert( g >= 0.0f && g <= 1.0f ); + assert( b >= 0.0f && b <= 1.0f ); + + //argb + colour = ( (0xFF<<24) | ( (int)(r*255)<<16 ) | ( (int)(g*255)<<8 ) | ( (int)(b*255) ) ); +} + +Color::Color( int r, int g, int b) +{ + colour = ( (0xFF<<24) | ( (r&0xff)<<16 ) | ( (g&0xff)<<8 ) | ( (b&0xff) ) ); +} + + +//Creates a Color object based on the specified values for the HSB color model. +//The s and b components should be floating-point values between zero and one (numbers in the range 0.0-1.0). +//The h component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. +//This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model. +// +//Parameters: +//h - the hue component +//s - the saturation of the color +//b - the brightness of the color +//Returns: +//a Color object with the specified hue, saturation, and brightness. +Color Color::getHSBColor(float hue, float saturation, float brightness) +{ + int r = 0, g = 0, b = 0; + if (saturation == 0) + { + r = g = b = (int) (brightness * 255.0f + 0.5f); + } + else + { + float h = (hue - (float)floor(hue)) * 6.0f; + float f = h - (float)floor(h); + float p = brightness * (1.0f - saturation); + float q = brightness * (1.0f - saturation * f); + float t = brightness * (1.0f - (saturation * (1.0f - f))); + switch ((int) h) + { + case 0: + r = (int) (brightness * 255.0f + 0.5f); + g = (int) (t * 255.0f + 0.5f); + b = (int) (p * 255.0f + 0.5f); + break; + case 1: + r = (int) (q * 255.0f + 0.5f); + g = (int) (brightness * 255.0f + 0.5f); + b = (int) (p * 255.0f + 0.5f); + break; + case 2: + r = (int) (p * 255.0f + 0.5f); + g = (int) (brightness * 255.0f + 0.5f); + b = (int) (t * 255.0f + 0.5f); + break; + case 3: + r = (int) (p * 255.0f + 0.5f); + g = (int) (q * 255.0f + 0.5f); + b = (int) (brightness * 255.0f + 0.5f); + break; + case 4: + r = (int) (t * 255.0f + 0.5f); + g = (int) (p * 255.0f + 0.5f); + b = (int) (brightness * 255.0f + 0.5f); + break; + case 5: + r = (int) (brightness * 255.0f + 0.5f); + g = (int) (p * 255.0f + 0.5f); + b = (int) (q * 255.0f + 0.5f); + break; + } + } + + + return Color( r, g, b ); +} + +int Color::getRGB() +{ + return colour; +} \ No newline at end of file diff --git a/src/util/Color.h b/src/util/Color.h new file mode 100644 index 0000000..a9d31ec --- /dev/null +++ b/src/util/Color.h @@ -0,0 +1,15 @@ +#pragma once + +class Color +{ +private: + int colour; + +public: + //Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). + Color( float r, float g, float b); + Color( int r, int g, int b); + + static Color getHSBColor(float h, float s, float b); + int getRGB(); +}; \ No newline at end of file diff --git a/src/world/entity/player/Inventory.cpp b/src/world/entity/player/Inventory.cpp index 5a46535..480627b 100755 --- a/src/world/entity/player/Inventory.cpp +++ b/src/world/entity/player/Inventory.cpp @@ -245,6 +245,7 @@ void Inventory::setupDefault() { addItem(new ItemInstance(Item::seeds_melon)); addItem(new ItemInstance(Item::dye_powder, 1, DyePowderItem::WHITE)); addItem(new ItemInstance(Item::hoe_iron)); + addItem(new ItemInstance(Item::flintAndSteel)); #ifdef RPI Sel[0] = addItem(new ItemInstance(Item::sword_iron)); #else diff --git a/src/world/level/Level.cpp b/src/world/level/Level.cpp index c9132f5..bb5ac0e 100755 --- a/src/world/level/Level.cpp +++ b/src/world/level/Level.cpp @@ -30,7 +30,7 @@ #include "../../network/packet/ExplodePacket.h" Level::Level(LevelStorage* levelStorage, const std::string& levelName, const LevelSettings& settings, int generatorVersion, Dimension* fixedDimension /* = NULL */) -: levelStorage(levelStorage), + : levelStorage(levelStorage), isClientSide(false), isFindingSpawn(false), noNeighborUpdate(false), @@ -52,7 +52,7 @@ Level::Level(LevelStorage* levelStorage, const std::string& levelName, const Lev allPlayersAreSleeping(false), _nightMode(false) { - _init(levelName, settings, generatorVersion, fixedDimension); + _init(levelName, settings, generatorVersion, fixedDimension); } Level::~Level() { @@ -85,14 +85,14 @@ void Level::_init(const std::string& levelName, const LevelSettings& settings, i isGeneratingTerrain = false; LevelData* preparedData = levelStorage->prepareLevel(this); - _isNew = (preparedData == NULL); + _isNew = (preparedData == NULL); - if (preparedData == NULL) { - levelData = LevelData(settings, levelName, generatorVersion); - } else { + if (preparedData == NULL) { + levelData = LevelData(settings, levelName, generatorVersion); + } else { levelData = *preparedData; - levelData.setLevelName(levelName); - } + levelData.setLevelName(levelName); + } if (fixedDimension != NULL) { dimension = fixedDimension; @@ -100,12 +100,12 @@ void Level::_init(const std::string& levelName, const LevelSettings& settings, i dimension = DimensionFactory::createDefaultDimension( &levelData ); } - dimension->init(this); - _chunkSource = createChunkSource(); + dimension->init(this); + _chunkSource = createChunkSource(); _pathFinder = new PathFinder(); _nightMode = false; - updateSkyBrightness(); + updateSkyBrightness(); } /*protected*/ @@ -121,63 +121,63 @@ ChunkSource* Level::createChunkSource() { /*public*/ bool Level::checkAndHandleWater(const AABB& box, const Material* material, Entity* e) { - int x0 = Mth::floor(box.x0); - int x1 = Mth::floor(box.x1 + 1); + int x0 = Mth::floor(box.x0); + int x1 = Mth::floor(box.x1 + 1); - int y0 = Mth::floor(box.y0); - int y1 = Mth::floor(box.y1 + 1); + int y0 = Mth::floor(box.y0); + int y1 = Mth::floor(box.y1 + 1); - int z0 = Mth::floor(box.z0); - int z1 = Mth::floor(box.z1 + 1); + int z0 = Mth::floor(box.z0); + int z1 = Mth::floor(box.z1 + 1); - if (!hasChunksAt(x0, y0, z0, x1, y1, z1)) { - return false; - } + if (!hasChunksAt(x0, y0, z0, x1, y1, z1)) { + return false; + } - bool ok = false; - Vec3 current(0,0,0); - for (int x = x0; x < x1; x++) - for (int y = y0; y < y1; y++) - for (int z = z0; z < z1; z++) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL && tile->material == material) { - float yt0 = y + 1 - LiquidTile::getHeight(getData(x, y, z)); - if (y1 >= yt0) { - ok = true; - tile->handleEntityInside(this, x, y, z, e, current); - } - } - } - float len = current.length(); - if (len > 0) { - const float pow = 0.004f / len; - e->xd += current.x * pow; - e->yd += current.y * pow; - e->zd += current.z * pow; - } - return ok; + bool ok = false; + Vec3 current(0,0,0); + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + for (int z = z0; z < z1; z++) { + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL && tile->material == material) { + float yt0 = y + 1 - LiquidTile::getHeight(getData(x, y, z)); + if (y1 >= yt0) { + ok = true; + tile->handleEntityInside(this, x, y, z, e, current); + } + } + } + float len = current.length(); + if (len > 0) { + const float pow = 0.004f / len; + e->xd += current.x * pow; + e->yd += current.y * pow; + e->zd += current.z * pow; + } + return ok; } /*public*/ Player* Level::getNearestPlayer(Entity* source, float maxDist) { - return getNearestPlayer(source->x, source->y, source->z, maxDist); + return getNearestPlayer(source->x, source->y, source->z, maxDist); } /*public*/ Player* Level::getNearestPlayer(float x, float y, float z, float maxDist) { - float maxDistSqr = maxDist * maxDist; + float maxDistSqr = maxDist * maxDist; float best = -1; - Player* result = NULL; - for (unsigned int i = 0; i < players.size(); i++) { - Player* p = players[i]; + Player* result = NULL; + for (unsigned int i = 0; i < players.size(); i++) { + Player* p = players[i]; if (p->removed) continue; float dist = p->distanceToSqr(x, y, z); - if ((maxDist < 0 || dist < maxDistSqr) && (best == -1 || dist < best)) { - best = dist; - result = p; - } - } - return result; + if ((maxDist < 0 || dist < maxDistSqr) && (best == -1 || dist < best)) { + best = dist; + result = p; + } + } + return result; } /*public*/ @@ -189,7 +189,7 @@ void Level::tick() { _mobSpawnTick = 0; TIMER_PUSH("mobSpawner"); MobSpawner::tick(this, _spawnEnemies && difficulty > Difficulty::PEACEFUL, - _spawnFriendlies && (levelData.getTime() % 400) < MobSpawnInterval); + _spawnFriendlies && (levelData.getTime() % 400) < MobSpawnInterval); TIMER_POP(); } } @@ -231,7 +231,7 @@ void Level::tick() { tickPendingTicks(false); TIMER_POP_PUSH("tickTiles"); - tickTiles(); + tickTiles(); TIMER_POP_PUSH("sendEntityData"); for (unsigned int i = 0; i < entities.size(); ++i) { @@ -255,7 +255,7 @@ void Level::tick() { /*protected*/ void Level::tickTiles() { - _chunksToPoll.clear(); + _chunksToPoll.clear(); static const int pollChunkOffsets[] = { -1,-4, 0,-4, 1,-4, -2,-3, -1,-3, 0,-3, 1,-3, 2,-3, -3,-2, @@ -270,10 +270,10 @@ void Level::tickTiles() { TIMER_PUSH("buildList"); //static Stopwatch w; //w.start(); - for (size_t i = 0; i < players.size(); i++) { - Player* player = players[i]; - int xx = Mth::floor(player->x / 16); - int zz = Mth::floor(player->z / 16); + for (size_t i = 0; i < players.size(); i++) { + Player* player = players[i]; + int xx = Mth::floor(player->x / 16); + int zz = Mth::floor(player->z / 16); for (int i = 0; i < pollChunkOffsetsSize; i += 2) { const int xp = xx + pollChunkOffsets[i]; @@ -282,114 +282,114 @@ void Level::tickTiles() { zp >= 0 && zp < CHUNK_CACHE_WIDTH) _chunksToPoll.insert(ChunkPos(xp, zp)); } - } + } TIMER_POP(); - //if (delayUntilNextMoodSound > 0) delayUntilNextMoodSound--; + //if (delayUntilNextMoodSound > 0) delayUntilNextMoodSound--; TIMER_PUSH("loop"); - for (ChunkPosSet::iterator it = _chunksToPoll.begin(); it != _chunksToPoll.end(); ++it) { + for (ChunkPosSet::iterator it = _chunksToPoll.begin(); it != _chunksToPoll.end(); ++it) { const ChunkPos& cp = *it; - int xo = cp.x * 16; - int zo = cp.z * 16; - // LevelSource region = new Region(this, xo, 0, zo, xo + 16, 128, zo + 16); + int xo = cp.x * 16; + int zo = cp.z * 16; + // LevelSource region = new Region(this, xo, 0, zo, xo + 16, 128, zo + 16); TIMER_PUSH("getChunk"); - LevelChunk* lc = this->getChunk(cp.x, cp.z); + LevelChunk* lc = this->getChunk(cp.x, cp.z); TIMER_POP_PUSH("tickChunk"); //lc->tick(); - //if (delayUntilNextMoodSound == 0) { - // randValue = randValue * 3 + addend; - // int val = (randValue >> 2); - // int x = (val & 15); - // int z = ((val >> 8) & 15); - // int y = ((val >> 16) & 127); + //if (delayUntilNextMoodSound == 0) { + // randValue = randValue * 3 + addend; + // int val = (randValue >> 2); + // int x = (val & 15); + // int z = ((val >> 8) & 15); + // int y = ((val >> 16) & 127); - // int id = lc->getTile(x, y, z); - // x += xo; - // z += zo; - // if (id == 0 && getRawBrightness(x, y, z) <= random.nextInt(8) && getBrightness(LightLayer::Sky, x, y, z) <= 0) { - // Player* player = getNearestPlayer(x + 0.5, y + 0.5, z + 0.5, 8); - // if (player != NULL && player.distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 2 * 2) { - // //this.playSound(x + 0.5, y + 0.5, z + 0.5, "ambient.cave.cave", 0.7f, 0.8f + random.nextFloat() * 0.2f); - // delayUntilNextMoodSound = random.nextInt(20 * 60 * 10) + 20 * 60 * 5; - // } - // } - //} + // int id = lc->getTile(x, y, z); + // x += xo; + // z += zo; + // if (id == 0 && getRawBrightness(x, y, z) <= random.nextInt(8) && getBrightness(LightLayer::Sky, x, y, z) <= 0) { + // Player* player = getNearestPlayer(x + 0.5, y + 0.5, z + 0.5, 8); + // if (player != NULL && player.distanceToSqr(x + 0.5, y + 0.5, z + 0.5) > 2 * 2) { + // //this.playSound(x + 0.5, y + 0.5, z + 0.5, "ambient.cave.cave", 0.7f, 0.8f + random.nextFloat() * 0.2f); + // delayUntilNextMoodSound = random.nextInt(20 * 60 * 10) + 20 * 60 * 5; + // } + // } + //} TIMER_POP_PUSH("tickTiles"); - for (int i = 0; i < 20; i++) { //@todo: CHUNK_TILE_TICK_COUNT - _randValue = _randValue * 3 + _addend; - int val = (_randValue >> 2); - int x = (val & 15); - int z = ((val >> 8) & 15); - int y = ((val >> 16) & 127); + for (int i = 0; i < 20; i++) { //@todo: CHUNK_TILE_TICK_COUNT + _randValue = _randValue * 3 + _addend; + int val = (_randValue >> 2); + int x = (val & 15); + int z = ((val >> 8) & 15); + int y = ((val >> 16) & 127); - int id = lc->getTile(x, y, z); - if (Tile::shouldTick[id]) { - Tile::tiles[id]->tick(this, x + xo, y, z + zo, &random); - } - } + int id = lc->getTile(x, y, z); + if (Tile::shouldTick[id]) { + Tile::tiles[id]->tick(this, x + xo, y, z + zo, &random); + } + } TIMER_POP(); - } + } TIMER_POP(); //w.stop(); //w.printEvery(30, "ticktiles"); } bool Level::tickPendingTicks(bool force) { - int count = _tickNextTickSet.size(); - if (count > MAX_TICK_TILES_PER_TICK) count = MAX_TICK_TILES_PER_TICK; - for (int i = 0; i < count; i++) { + int count = _tickNextTickSet.size(); + if (count > MAX_TICK_TILES_PER_TICK) count = MAX_TICK_TILES_PER_TICK; + for (int i = 0; i < count; i++) { TickDataSet::iterator td = _tickNextTickSet.begin(); - if (!force && td->delay > levelData.getTime()) { - break; - } + if (!force && td->delay > levelData.getTime()) { + break; + } int r = 8; - if (hasChunksAt(td->x - r, td->y - r, td->z - r, td->x + r, td->y + r, td->z + r)) { - int id = getTile(td->x, td->y, td->z); - if (id == td->tileId && id > 0) { - Tile::tiles[id]->tick(this, td->x, td->y, td->z, &random); - } - } - _tickNextTickSet.erase(td); - } - return _tickNextTickSet.size() != 0; + if (hasChunksAt(td->x - r, td->y - r, td->z - r, td->x + r, td->y + r, td->z + r)) { + int id = getTile(td->x, td->y, td->z); + if (id == td->tileId && id > 0) { + Tile::tiles[id]->tick(this, td->x, td->y, td->z, &random); + } + } + _tickNextTickSet.erase(td); + } + return _tickNextTickSet.size() != 0; } /*public*/ void Level::loadPlayer(Player* player, bool doAddPlayer /*= true*/) { if (player) { CompoundTag* loadedPlayerTag = levelData.getLoadedPlayerTag(); - if (loadedPlayerTag != NULL) { - player->load(loadedPlayerTag); - levelData.setLoadedPlayerTag(NULL); - } else { + if (loadedPlayerTag != NULL) { + player->load(loadedPlayerTag); + levelData.setLoadedPlayerTag(NULL); + } else { levelData.setLoadedPlayerTo(player); } if (doAddPlayer) addEntity(player); } - //} catch (Exception e) { - // e.printStackTrace(); - //} + //} catch (Exception e) { + // e.printStackTrace(); + //} } bool Level::findPath(Path* path, Entity* from, Entity* to, float maxDist, bool canOpenDoors, bool avoidWater) { - TIMER_PUSH("pathfind"); + TIMER_PUSH("pathfind"); int x = Mth::floor(from->x); - int y = Mth::floor(from->y); - int z = Mth::floor(from->z); + int y = Mth::floor(from->y); + int z = Mth::floor(from->z); - int r = (int) (maxDist + 16); - int x1 = x - r; - int y1 = y - r; - int z1 = z - r; - int x2 = x + r; - int y2 = y + r; - int z2 = z + r; + int r = (int) (maxDist + 16); + int x1 = x - r; + int y1 = y - r; + int z1 = z - r; + int x2 = x + r; + int y2 = y + r; + int z2 = z + r; //LOGI("trying to move! 1: %ld\n", levelData.getTime()); - Region region(this, x1, y1, z1, x2, y2, z2); + Region region(this, x1, y1, z1, x2, y2, z2); _pathFinder->setLevelSource(®ion); _pathFinder->canOpenDoors = canOpenDoors; _pathFinder->avoidWater = avoidWater; @@ -399,24 +399,24 @@ bool Level::findPath(Path* path, Entity* from, Entity* to, float maxDist, bool c } bool Level::findPath(Path* path, Entity* from, int xBest, int yBest, int zBest, float maxDist, bool canOpenDoors, bool avoidWater) { - TIMER_PUSH("pathfind"); + TIMER_PUSH("pathfind"); int x = Mth::floor(from->x); - int y = Mth::floor(from->y); - int z = Mth::floor(from->z); + int y = Mth::floor(from->y); + int z = Mth::floor(from->z); - int r = (int) (maxDist + 8); - int x1 = x - r; - int y1 = y - r; - int z1 = z - r; - int x2 = x + r; - int y2 = y + r; - int z2 = z + r; - Region region(this, x1, y1, z1, x2, y2, z2); + int r = (int) (maxDist + 8); + int x1 = x - r; + int y1 = y - r; + int z1 = z - r; + int x2 = x + r; + int y2 = y + r; + int z2 = z + r; + Region region(this, x1, y1, z1, x2, y2, z2); //LOGI("trying to move! 2: %ld\n", levelData.getTime()); _pathFinder->setLevelSource(®ion); _pathFinder->canOpenDoors = canOpenDoors; _pathFinder->avoidWater = avoidWater; - _pathFinder->findPath(path, from, xBest, yBest, zBest, maxDist); + _pathFinder->findPath(path, from, xBest, yBest, zBest, maxDist); TIMER_POP(); return true; } @@ -427,57 +427,57 @@ bool Level::findPath(Path* path, Entity* from, int xBest, int yBest, int zBest, */ /*protected*/ void Level::setInitialSpawn() { - isFindingSpawn = true; - int xSpawn = CHUNK_CACHE_WIDTH * CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; - int ySpawn = 64; - int zSpawn = CHUNK_CACHE_WIDTH * CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; - while (!dimension->isValidSpawn(xSpawn, zSpawn)) { - xSpawn += random.nextInt(32) - random.nextInt(32); - zSpawn += random.nextInt(32) - random.nextInt(32); + isFindingSpawn = true; + int xSpawn = CHUNK_CACHE_WIDTH * CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; + int ySpawn = 64; + int zSpawn = CHUNK_CACHE_WIDTH * CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0; + while (!dimension->isValidSpawn(xSpawn, zSpawn)) { + xSpawn += random.nextInt(32) - random.nextInt(32); + zSpawn += random.nextInt(32) - random.nextInt(32); if (xSpawn < 4) xSpawn += 32; if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 32; if (zSpawn < 4) zSpawn += 32; if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 32; - } - levelData.setSpawn(xSpawn, ySpawn, zSpawn); - isFindingSpawn = false; + } + levelData.setSpawn(xSpawn, ySpawn, zSpawn); + isFindingSpawn = false; } /*public*/ void Level::validateSpawn() { - if (levelData.getYSpawn() <= 0) { - levelData.setYSpawn(64); - } - int xSpawn = levelData.getXSpawn(); - int zSpawn = levelData.getZSpawn(); - while (getTopTile(xSpawn, zSpawn) == 0 || getTopTile(xSpawn, zSpawn) == Tile::invisible_bedrock->id) { - xSpawn += random.nextInt(8) - random.nextInt(8); - zSpawn += random.nextInt(8) - random.nextInt(8); + if (levelData.getYSpawn() <= 0) { + levelData.setYSpawn(64); + } + int xSpawn = levelData.getXSpawn(); + int zSpawn = levelData.getZSpawn(); + while (getTopTile(xSpawn, zSpawn) == 0 || getTopTile(xSpawn, zSpawn) == Tile::invisible_bedrock->id) { + xSpawn += random.nextInt(8) - random.nextInt(8); + zSpawn += random.nextInt(8) - random.nextInt(8); if (xSpawn < 4) xSpawn += 8; if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 8; if (zSpawn < 4) zSpawn += 8; if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 8; - } - levelData.setXSpawn(xSpawn); - levelData.setZSpawn(zSpawn); + } + levelData.setXSpawn(xSpawn); + levelData.setZSpawn(zSpawn); } int Level::getTopTile(int x, int z) { - int y = 63; - while (!isEmptyTile(x, y + 1, z)) { - y++; - } - return getTile(x, y, z); + int y = 63; + while (!isEmptyTile(x, y + 1, z)) { + y++; + } + return getTile(x, y, z); } int Level::getTopTileY(int x, int z) { - int y = 63; - while (!isEmptyTile(x, y + 1, z)) { - y++; - } - return y; + int y = 63; + while (!isEmptyTile(x, y + 1, z)) { + y++; + } + return y; } // // void clearLoadedPlayerData() { @@ -513,101 +513,101 @@ void Level::saveLevelData() { //} int Level::getTile(int x, int y, int z) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return 0; - //} - if (y < 0) return 0; - if (y >= DEPTH) return 0; + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return 0; + //} + if (y < 0) return 0; + if (y >= DEPTH) return 0; //if (z == 128) { // int a = 0; //} //LOGI("%d ", z); - return getChunk(x >> 4, z >> 4)->getTile(x & 15, y, z & 15); + return getChunk(x >> 4, z >> 4)->getTile(x & 15, y, z & 15); } bool Level::isEmptyTile(int x, int y, int z) { - return getTile(x, y, z) == 0; + return getTile(x, y, z) == 0; } bool Level::hasChunkAt(int x, int y, int z) { - if (y < 0 || y >= Level::DEPTH) return false; - return hasChunk(x >> 4, z >> 4); + if (y < 0 || y >= Level::DEPTH) return false; + return hasChunk(x >> 4, z >> 4); } bool Level::hasChunksAt(int x, int y, int z, int r) { - return hasChunksAt(x - r, y - r, z - r, x + r, y + r, z + r); + return hasChunksAt(x - r, y - r, z - r, x + r, y + r, z + r); } bool Level::hasChunksAt(int x0, int y0, int z0, int x1, int y1, int z1) { - if (y1 < 0 || y0 >= Level::DEPTH) return false; + if (y1 < 0 || y0 >= Level::DEPTH) return false; - x0 >>= 4; - z0 >>= 4; - x1 >>= 4; - z1 >>= 4; + x0 >>= 4; + z0 >>= 4; + x1 >>= 4; + z1 >>= 4; - for (int x = x0; x <= x1; x++) - for (int z = z0; z <= z1; z++) - if (!hasChunk(x, z)) return false; + for (int x = x0; x <= x1; x++) + for (int z = z0; z <= z1; z++) + if (!hasChunk(x, z)) return false; - return true; + return true; } bool Level::hasChunk(int x, int z) { - return _chunkSource->hasChunk(x, z); + return _chunkSource->hasChunk(x, z); } LevelChunk* Level::getChunkAt(int x, int z) { - return getChunk(x >> 4, z >> 4); + return getChunk(x >> 4, z >> 4); } LevelChunk* Level::getChunk(int x, int z) { - return _chunkSource->getChunk(x, z); + return _chunkSource->getChunk(x, z); } bool Level::setTileAndDataNoUpdate(int x, int y, int z, int tile, int data) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return false; - //} - if (y < 0) return false; - if (y >= DEPTH) return false; - LevelChunk* c = getChunk(x >> 4, z >> 4); - return c->setTileAndData(x & 15, y, z & 15, tile, data); + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return false; + //} + if (y < 0) return false; + if (y >= DEPTH) return false; + LevelChunk* c = getChunk(x >> 4, z >> 4); + return c->setTileAndData(x & 15, y, z & 15, tile, data); } bool Level::setTileNoUpdate(int x, int y, int z, int tile) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return false; - //} - if (y < 0) return false; - if (y >= DEPTH) return false; - LevelChunk* c = getChunk(x >> 4, z >> 4); - return c->setTile(x & 15, y, z & 15, tile); + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return false; + //} + if (y < 0) return false; + if (y >= DEPTH) return false; + LevelChunk* c = getChunk(x >> 4, z >> 4); + return c->setTile(x & 15, y, z & 15, tile); } const Material* Level::getMaterial(int x, int y, int z) { - int t = getTile(x, y, z); - if (t == 0) return Material::air; - return Tile::tiles[t]->material; + int t = getTile(x, y, z); + if (t == 0) return Material::air; + return Tile::tiles[t]->material; } int Level::getData(int x, int y, int z) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return 0; - //} - if (y < 0) return 0; - if (y >= DEPTH) return 0; - LevelChunk* c = getChunk(x >> 4, z >> 4); - x &= 15; - z &= 15; - return c->getData(x, y, z); + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return 0; + //} + if (y < 0) return 0; + if (y >= DEPTH) return 0; + LevelChunk* c = getChunk(x >> 4, z >> 4); + x &= 15; + z &= 15; + return c->getData(x, y, z); } void Level::setData(int x, int y, int z, int data) { //// @newway //if (setDataNoUpdate(x, y, z, data)) { - // int t = getTile(x, y, z); + // int t = getTile(x, y, z); // if (Tile::sendTileData[t]) { // tileUpdated(x, y, z, t); // } else { @@ -616,20 +616,20 @@ void Level::setData(int x, int y, int z, int data) { //} // @oldway - if (setDataNoUpdate(x, y, z, data)) { - tileUpdated(x, y, z, getTile(x, y, z)); - } + if (setDataNoUpdate(x, y, z, data)) { + tileUpdated(x, y, z, getTile(x, y, z)); + } } bool Level::setDataNoUpdate(int x, int y, int z, int data) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return false; - //} - if (y < 0) return false; - if (y >= DEPTH) return false; - LevelChunk* c = getChunk(x >> 4, z >> 4); - x &= 15; - z &= 15; + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return false; + //} + if (y < 0) return false; + if (y >= DEPTH) return false; + LevelChunk* c = getChunk(x >> 4, z >> 4); + x &= 15; + z &= 15; //return c->setData(x, y, z, data); @@ -641,148 +641,148 @@ bool Level::setDataNoUpdate(int x, int y, int z, int data) { } bool Level::setTile(int x, int y, int z, int tile) { - if (setTileNoUpdate(x, y, z, tile)) { + if (setTileNoUpdate(x, y, z, tile)) { //printf("TILE UPDATED %d, %d, %d\n", x, y, z); - tileUpdated(x, y, z, tile); - return true; - } - return false; + tileUpdated(x, y, z, tile); + return true; + } + return false; } bool Level::setTileAndData(int x, int y, int z, int tile, int data) { - if (setTileAndDataNoUpdate(x, y, z, tile, data)) { - tileUpdated(x, y, z, tile); - return true; - } - return false; + if (setTileAndDataNoUpdate(x, y, z, tile, data)) { + tileUpdated(x, y, z, tile); + return true; + } + return false; } void Level::sendTileUpdated(int x, int y, int z) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->tileChanged(x, y, z); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->tileChanged(x, y, z); + } } /*protected*/ void Level::tileUpdated(int x, int y, int z, int tile) { - sendTileUpdated(x, y, z); - this->updateNeighborsAt(x, y, z, tile); + sendTileUpdated(x, y, z); + this->updateNeighborsAt(x, y, z, tile); } void Level::lightColumnChanged(int x, int z, int y0, int y1) { - if (y0 > y1) { - int tmp = y1; - y1 = y0; - y0 = tmp; - } - setTilesDirty(x, y0, z, x, y1, z); + if (y0 > y1) { + int tmp = y1; + y1 = y0; + y0 = tmp; + } + setTilesDirty(x, y0, z, x, y1, z); } void Level::setTileDirty(int x, int y, int z) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->setTilesDirty(x, y, z, x, y, z); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->setTilesDirty(x, y, z, x, y, z); + } } void Level::setTilesDirty(int x0, int y0, int z0, int x1, int y1, int z1) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->setTilesDirty(x0, y0, z0, x1, y1, z1); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->setTilesDirty(x0, y0, z0, x1, y1, z1); + } } void Level::swap(int x1, int y1, int z1, int x2, int y2, int z2) { - int t1 = getTile(x1, y1, z1); - int d1 = getData(x1, y1, z1); - int t2 = getTile(x2, y2, z2); - int d2 = getData(x2, y2, z2); + int t1 = getTile(x1, y1, z1); + int d1 = getData(x1, y1, z1); + int t2 = getTile(x2, y2, z2); + int d2 = getData(x2, y2, z2); - setTileAndDataNoUpdate(x1, y1, z1, t2, d2); - setTileAndDataNoUpdate(x2, y2, z2, t1, d1); + setTileAndDataNoUpdate(x1, y1, z1, t2, d2); + setTileAndDataNoUpdate(x2, y2, z2, t1, d1); - updateNeighborsAt(x1, y1, z1, t2); - updateNeighborsAt(x2, y2, z2, t1); + updateNeighborsAt(x1, y1, z1, t2); + updateNeighborsAt(x2, y2, z2, t1); } void Level::updateNeighborsAt(int x, int y, int z, int tile) { - neighborChanged(x - 1, y, z, tile); - neighborChanged(x + 1, y, z, tile); - neighborChanged(x, y - 1, z, tile); - neighborChanged(x, y + 1, z, tile); - neighborChanged(x, y, z - 1, tile); - neighborChanged(x, y, z + 1, tile); + neighborChanged(x - 1, y, z, tile); + neighborChanged(x + 1, y, z, tile); + neighborChanged(x, y - 1, z, tile); + neighborChanged(x, y + 1, z, tile); + neighborChanged(x, y, z - 1, tile); + neighborChanged(x, y, z + 1, tile); } /*private*/ void Level::neighborChanged(int x, int y, int z, int type) { - if (noNeighborUpdate || isClientSide) return; - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL) tile->neighborChanged(this, x, y, z, type); + if (noNeighborUpdate || isClientSide) return; + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL) tile->neighborChanged(this, x, y, z, type); } bool Level::canSeeSky(int x, int y, int z) { - return getChunk(x >> 4, z >> 4)->isSkyLit(x & 15, y, z & 15); + return getChunk(x >> 4, z >> 4)->isSkyLit(x & 15, y, z & 15); } int Level::getRawBrightness(int x, int y, int z) { - return getRawBrightness(x, y, z, true); + return getRawBrightness(x, y, z, true); } int Level::getRawBrightness(int x, int y, int z, bool propagate) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return MAX_BRIGHTNESS; - //} + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return MAX_BRIGHTNESS; + //} - if (propagate) { - int id = getTile(x, y, z); - if (id == Tile::stoneSlabHalf->id || id == Tile::farmland->id) { - int br = getRawBrightness(x, y + 1, z, false); - int br1 = getRawBrightness(x + 1, y, z, false); - int br2 = getRawBrightness(x - 1, y, z, false); - int br3 = getRawBrightness(x, y, z + 1, false); - int br4 = getRawBrightness(x, y, z - 1, false); - if (br1 > br) br = br1; - if (br2 > br) br = br2; - if (br3 > br) br = br3; - if (br4 > br) br = br4; - return br; - } - } + if (propagate) { + int id = getTile(x, y, z); + if (id == Tile::stoneSlabHalf->id || id == Tile::farmland->id) { + int br = getRawBrightness(x, y + 1, z, false); + int br1 = getRawBrightness(x + 1, y, z, false); + int br2 = getRawBrightness(x - 1, y, z, false); + int br3 = getRawBrightness(x, y, z + 1, false); + int br4 = getRawBrightness(x, y, z - 1, false); + if (br1 > br) br = br1; + if (br2 > br) br = br2; + if (br3 > br) br = br3; + if (br4 > br) br = br4; + return br; + } + } - if (y < 0) return 0; - if (y >= DEPTH) { - int br = MAX_BRIGHTNESS - skyDarken; - if (br < 0) br = 0; - return br; - } + if (y < 0) return 0; + if (y >= DEPTH) { + int br = MAX_BRIGHTNESS - skyDarken; + if (br < 0) br = 0; + return br; + } - LevelChunk* c = getChunk(x >> 4, z >> 4); - x &= 15; - z &= 15; - return c->getRawBrightness(x, y, z, skyDarken); + LevelChunk* c = getChunk(x >> 4, z >> 4); + x &= 15; + z &= 15; + return c->getRawBrightness(x, y, z, skyDarken); } bool Level::isSkyLit(int x, int y, int z) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return false; - //} - if (y < 0) return false; - if (y >= DEPTH) return true; - if (!hasChunk(x >> 4, z >> 4)) return false; + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return false; + //} + if (y < 0) return false; + if (y >= DEPTH) return true; + if (!hasChunk(x >> 4, z >> 4)) return false; - LevelChunk* c = getChunk(x >> 4, z >> 4); - x &= 15; - z &= 15; + LevelChunk* c = getChunk(x >> 4, z >> 4); + x &= 15; + z &= 15; return c->isSkyLit(x, y, z); } int Level::getHeightmap(int x, int z) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return 0; - //} - if (!hasChunk(x >> 4, z >> 4)) return 0; + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return 0; + //} + if (!hasChunk(x >> 4, z >> 4)) return 0; - LevelChunk* c = getChunk(x >> 4, z >> 4); - return c->getHeightmap(x & 15, z & 15); + LevelChunk* c = getChunk(x >> 4, z >> 4); + return c->getHeightmap(x & 15, z & 15); } BiomeSource* Level::getBiomeSource() { @@ -793,45 +793,45 @@ Biome* Level::getBiome( int x, int z ) { } void Level::updateLightIfOtherThan(const LightLayer& layer, int x, int y, int z, int expected) { - if (dimension->hasCeiling && (&layer) == &LightLayer::Sky) return; + if (dimension->hasCeiling && (&layer) == &LightLayer::Sky) return; - if (!hasChunkAt(x, y, z)) return; + if (!hasChunkAt(x, y, z)) return; - if (&layer == &LightLayer::Sky) { - if (isSkyLit(x, y, z)) expected = 15; - } else if (&layer == &LightLayer::Block) { - int t = getTile(x, y, z); - if (Tile::lightEmission[t] > expected) expected = Tile::lightEmission[t]; - } + if (&layer == &LightLayer::Sky) { + if (isSkyLit(x, y, z)) expected = 15; + } else if (&layer == &LightLayer::Block) { + int t = getTile(x, y, z); + if (Tile::lightEmission[t] > expected) expected = Tile::lightEmission[t]; + } - if (getBrightness(layer, x, y, z) != expected) { - updateLight(layer, x, y, z, x, y, z); - } + if (getBrightness(layer, x, y, z) != expected) { + updateLight(layer, x, y, z, x, y, z); + } } int Level::getBrightness(const LightLayer& layer, int x, int y, int z) { - if (y < 0 || y >= DEPTH/* || x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE*/) { - return layer.surrounding; - } - int xc = x >> 4; - int zc = z >> 4; - if (!hasChunk(xc, zc)) return 0; - LevelChunk* c = getChunk(xc, zc); - return c->getBrightness(layer, x & 15, y, z & 15); + if (y < 0 || y >= DEPTH/* || x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE*/) { + return layer.surrounding; + } + int xc = x >> 4; + int zc = z >> 4; + if (!hasChunk(xc, zc)) return 0; + LevelChunk* c = getChunk(xc, zc); + return c->getBrightness(layer, x & 15, y, z & 15); } void Level::setBrightness(const LightLayer& layer, int x, int y, int z, int brightness) { - //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { - // return; - //} - if (y < 0) return; - if (y >= DEPTH) return; - if (!hasChunk(x >> 4, z >> 4)) return; - LevelChunk* c = getChunk(x >> 4, z >> 4); - c->setBrightness(layer, x & 15, y, z & 15, brightness); - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->tileBrightnessChanged(x, y, z); - } + //if (x < -MAX_LEVEL_SIZE || z < -MAX_LEVEL_SIZE || x >= MAX_LEVEL_SIZE || z > MAX_LEVEL_SIZE) { + // return; + //} + if (y < 0) return; + if (y >= DEPTH) return; + if (!hasChunk(x >> 4, z >> 4)) return; + LevelChunk* c = getChunk(x >> 4, z >> 4); + c->setBrightness(layer, x & 15, y, z & 15, brightness); + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->tileBrightnessChanged(x, y, z); + } } float Level::getBrightness(int x, int y, int z) { @@ -839,7 +839,7 @@ float Level::getBrightness(int x, int y, int z) { } bool Level::isDay() { - return this->skyDarken < 4; + return this->skyDarken < 4; } //HitResult Level::clip(const Vec3& a, const Vec3& b) { @@ -847,99 +847,99 @@ bool Level::isDay() { //} HitResult Level::clip(const Vec3& A, const Vec3& b, bool liquid /*= false*/, bool solidOnly /*= false*/) { - static Stopwatch sw; - //sw.printEvery(1000, "clip"); - SwStartStopper w(sw); + static Stopwatch sw; + //sw.printEvery(1000, "clip"); + SwStartStopper w(sw); - if (A.x != A.x || A.y != A.y || A.z != A.z) return HitResult(); //@kludge This is actually a way to do it + if (A.x != A.x || A.y != A.y || A.z != A.z) return HitResult(); //@kludge This is actually a way to do it if (b.x != b.x || b.y != b.y || b.z != b.z) return HitResult(); Vec3 a(A); - int xTile1 = Mth::floor(b.x); - int yTile1 = Mth::floor(b.y); - int zTile1 = Mth::floor(b.z); + int xTile1 = Mth::floor(b.x); + int yTile1 = Mth::floor(b.y); + int zTile1 = Mth::floor(b.z); - int xTile0 = Mth::floor(a.x); - int yTile0 = Mth::floor(a.y); - int zTile0 = Mth::floor(a.z); + int xTile0 = Mth::floor(a.x); + int yTile0 = Mth::floor(a.y); + int zTile0 = Mth::floor(a.z); - int maxIterations = 200; - while (maxIterations-- >= 0) { + int maxIterations = 200; + while (maxIterations-- >= 0) { if (a.x != a.x || a.y != a.y || a.z != a.z) return HitResult(); - if (xTile0 == xTile1 && yTile0 == yTile1 && zTile0 == zTile1) + if (xTile0 == xTile1 && yTile0 == yTile1 && zTile0 == zTile1) return HitResult(); - float xClip = 999; - float yClip = 999; - float zClip = 999; + float xClip = 999; + float yClip = 999; + float zClip = 999; - if (xTile1 > xTile0) xClip = xTile0 + 1.000f; - if (xTile1 < xTile0) xClip = xTile0 + 0.000f; + if (xTile1 > xTile0) xClip = xTile0 + 1.000f; + if (xTile1 < xTile0) xClip = xTile0 + 0.000f; - if (yTile1 > yTile0) yClip = yTile0 + 1.000f; - if (yTile1 < yTile0) yClip = yTile0 + 0.000f; + if (yTile1 > yTile0) yClip = yTile0 + 1.000f; + if (yTile1 < yTile0) yClip = yTile0 + 0.000f; - if (zTile1 > zTile0) zClip = zTile0 + 1.000f; - if (zTile1 < zTile0) zClip = zTile0 + 0.000f; + if (zTile1 > zTile0) zClip = zTile0 + 1.000f; + if (zTile1 < zTile0) zClip = zTile0 + 0.000f; - float xDist = 999; - float yDist = 999; - float zDist = 999; + float xDist = 999; + float yDist = 999; + float zDist = 999; - float xd = b.x - a.x; - float yd = b.y - a.y; - float zd = b.z - a.z; + float xd = b.x - a.x; + float yd = b.y - a.y; + float zd = b.z - a.z; - if (xClip != 999) xDist = (xClip - a.x) / xd; - if (yClip != 999) yDist = (yClip - a.y) / yd; - if (zClip != 999) zDist = (zClip - a.z) / zd; + if (xClip != 999) xDist = (xClip - a.x) / xd; + if (yClip != 999) yDist = (yClip - a.y) / yd; + if (zClip != 999) zDist = (zClip - a.z) / zd; - int face = 0; - if (xDist < yDist && xDist < zDist) { - if (xTile1 > xTile0) face = 4; - else face = 5; + int face = 0; + if (xDist < yDist && xDist < zDist) { + if (xTile1 > xTile0) face = 4; + else face = 5; - a.x = xClip; - a.y += yd * xDist; - a.z += zd * xDist; - } else if (yDist < zDist) { - if (yTile1 > yTile0) face = 0; - else face = 1; + a.x = xClip; + a.y += yd * xDist; + a.z += zd * xDist; + } else if (yDist < zDist) { + if (yTile1 > yTile0) face = 0; + else face = 1; - a.x += xd * yDist; - a.y = yClip; - a.z += zd * yDist; - } else { - if (zTile1 > zTile0) face = 2; - else face = 3; + a.x += xd * yDist; + a.y = yClip; + a.z += zd * yDist; + } else { + if (zTile1 > zTile0) face = 2; + else face = 3; - a.x += xd * zDist; - a.y += yd * zDist; - a.z = zClip; - } + a.x += xd * zDist; + a.y += yd * zDist; + a.z = zClip; + } - Vec3 tPos(a.x, a.y, a.z); - xTile0 = (int) (tPos.x = (float)Mth::floor(a.x)); - if (face == 5) { - xTile0--; - tPos.x++; - } - yTile0 = (int) (tPos.y = (float)Mth::floor(a.y)); - if (face == 1) { - yTile0--; - tPos.y++; - } - zTile0 = (int) (tPos.z = (float)Mth::floor(a.z)); - if (face == 3) { - zTile0--; - tPos.z++; - } + Vec3 tPos(a.x, a.y, a.z); + xTile0 = (int) (tPos.x = (float)Mth::floor(a.x)); + if (face == 5) { + xTile0--; + tPos.x++; + } + yTile0 = (int) (tPos.y = (float)Mth::floor(a.y)); + if (face == 1) { + yTile0--; + tPos.y++; + } + zTile0 = (int) (tPos.z = (float)Mth::floor(a.z)); + if (face == 3) { + zTile0--; + tPos.z++; + } - int t = getTile(xTile0, yTile0, zTile0); - int data = getData(xTile0, yTile0, zTile0); - Tile* tile = Tile::tiles[t]; + int t = getTile(xTile0, yTile0, zTile0); + int data = getData(xTile0, yTile0, zTile0); + Tile* tile = Tile::tiles[t]; if (solidOnly && tile != NULL && tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) { // No collision @@ -948,27 +948,27 @@ HitResult Level::clip(const Vec3& A, const Vec3& b, bool liquid /*= false*/, boo HitResult r = tile->clip(this, xTile0, yTile0, zTile0, a, b); if (r.isHit()) return r; } - } - } - return HitResult(); + } + } + return HitResult(); } void Level::playSound(Entity* entity, const std::string& name, float volume, float pitch) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->playSound(name, entity->x, entity->y - entity->heightOffset, entity->z, volume, pitch); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->playSound(name, entity->x, entity->y - entity->heightOffset, entity->z, volume, pitch); + } } void Level::playSound(float x, float y, float z, const std::string& name, float volume, float pitch) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->playSound(name, x, y, z, volume, pitch); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->playSound(name, x, y, z, volume, pitch); + } } void Level::levelEvent(Player* source, int type, int x, int y, int z, int data) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->levelEvent(source, type, x, y, z, data); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->levelEvent(source, type, x, y, z, data); + } } void Level::tileEvent(int x, int y, int z, int b0, int b1) { @@ -993,7 +993,7 @@ void Level::tileEvent(int x, int y, int z, int b0, int b1) { void Level::addParticle(const std::string& id, float x, float y, float z, float xd, float yd, float zd, int data /* = 0 */) { for (unsigned int i = 0; i < _listeners.size(); i++) - _listeners[i]->addParticle(id, x, y, z, xd, yd, zd, data); + _listeners[i]->addParticle(id, x, y, z, xd, yd, zd, data); } void Level::addParticle(ParticleType::Id id, float x, float y, float z, float xd, float yd, float zd, int data /* = 0 */) { @@ -1006,13 +1006,13 @@ bool Level::addEntity(Entity* e) { if (prev) removeEntity(prev); - int xc = Mth::floor(e->x / 16.f); - int zc = Mth::floor(e->z / 16.f); + int xc = Mth::floor(e->x / 16.f); + int zc = Mth::floor(e->z / 16.f); - //bool forced = false; - //if (e->isPlayer()) { - // forced = true; - //} + //bool forced = false; + //if (e->isPlayer()) { + // forced = true; + //} bool forced = true; if (forced/* || hasChunk(xc, zc)*/) { @@ -1034,10 +1034,10 @@ Entity* Level::getEntity(int entityId) // TODO: Lookup map /*for (unsigned int i = 0; i < entities.size(); i++) { - if (entities[i]->entityId == entityId) - { - return entities[i]; - } + if (entities[i]->entityId == entityId) + { + return entities[i]; + } } return NULL;*/ EntityMap::const_iterator cit = entityIdLookup.find(entityId); @@ -1046,16 +1046,16 @@ Entity* Level::getEntity(int entityId) /*protected*/ void Level::entityAdded(Entity* e) { - for (unsigned int i = 0; i < _listeners.size(); i++) { - _listeners[i]->entityAdded(e); - } + for (unsigned int i = 0; i < _listeners.size(); i++) { + _listeners[i]->entityAdded(e); + } } /*protected*/ void Level::entityRemoved(Entity* e) { - for (unsigned int j = 0; j < _listeners.size(); j++) { - _listeners[j]->entityRemoved(e); - } + for (unsigned int j = 0; j < _listeners.size(); j++) { + _listeners[j]->entityRemoved(e); + } } Mob* Level::getMob(int entityId) @@ -1065,10 +1065,10 @@ Mob* Level::getMob(int entityId) } void Level::removeEntity(Entity* e) { - e->remove(); + e->remove(); if (e->isPlayer() && e->reallyRemoveIfPlayer) { Util::remove(players, (Player*) e); - } + } } void Level::tileEntityChanged(int x, int y, int z, TileEntity* te) { @@ -1099,16 +1099,16 @@ void Level::tileEntityChanged(int x, int y, int z, TileEntity* te) { Biome::MobSpawnerData Level::getRandomMobSpawnAt(const MobCategory& mobCategory, int x, int y, int z) { Biome::MobList mobList = _chunkSource->getMobsAt(mobCategory, x, y, z); - if (mobList.empty()) return Biome::MobSpawnerData(); + if (mobList.empty()) return Biome::MobSpawnerData(); Biome::MobSpawnerData* data = (Biome::MobSpawnerData*) WeighedRandom::getRandomItem(&random, mobList); if (!data) return Biome::MobSpawnerData(); - return *data; + return *data; } void Level::addListener(LevelListener* listener) { - _listeners.push_back(listener); + _listeners.push_back(listener); } void Level::removeListener(LevelListener* listener) { @@ -1119,76 +1119,86 @@ void Level::removeListener(LevelListener* listener) { std::vector& Level::getCubes(const Entity* source, const AABB& box_) { //@attn: check the AABB* new/delete stuff boxes.clear(); const AABB* box = &box_; - int x0 = Mth::floor(box->x0); - int x1 = Mth::floor(box->x1 + 1); - int y0 = Mth::floor(box->y0); - int y1 = Mth::floor(box->y1 + 1); - int z0 = Mth::floor(box->z0); - int z1 = Mth::floor(box->z1 + 1); + int x0 = Mth::floor(box->x0); + int x1 = Mth::floor(box->x1 + 1); + int y0 = Mth::floor(box->y0); + int y1 = Mth::floor(box->y1 + 1); + int z0 = Mth::floor(box->z0); + int z1 = Mth::floor(box->z1 + 1); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) { - if (hasChunkAt(x, Level::DEPTH / 2, z)) { - for (int y = y0 - 1; y < y1; y++) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL) { - tile->addAABBs(this, x, y, z, box, boxes); - } - } - } + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (hasChunkAt(x, Level::DEPTH / 2, z)) { + for (int y = y0 - 1; y < y1; y++) { + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL) { + tile->addAABBs(this, x, y, z, box, boxes); + } + } + } else { //int breakPoint = 0; } - } - /* - float r = 0.25; - List ee = getEntities(source, box.grow(r, r, r)); - for (int i = 0; i < ee.size(); i++) { - AABB collideBox = ee.get(i).getCollideBox(); - if (collideBox != NULL && collideBox.intersects(box)) { - boxes.add(collideBox); - } + } + /* + float r = 0.25; + List ee = getEntities(source, box.grow(r, r, r)); + for (int i = 0; i < ee.size(); i++) { + AABB collideBox = ee.get(i).getCollideBox(); + if (collideBox != NULL && collideBox.intersects(box)) { + boxes.add(collideBox); + } - collideBox = source.getCollideAgainstBox(ee.get(i)); - if (collideBox != NULL && collideBox.intersects(box)) { - boxes.add(collideBox); - } - } - */ + collideBox = source.getCollideAgainstBox(ee.get(i)); + if (collideBox != NULL && collideBox.intersects(box)) { + boxes.add(collideBox); + } + } + */ - return boxes; + return boxes; } int Level::getSkyDarken(float a) { - float td = getTimeOfDay(a); + float td = getTimeOfDay(a); - float br = 1 - (Mth::cos(td * Mth::PI * 2) * 2 + 0.5f); - if (br < 0.0f) br = 0.0f; - if (br > 0.80f) br = 0.80f; //@note; was 1.0f - return ((int) (br * 11)); + float br = 1 - (Mth::cos(td * Mth::PI * 2) * 2 + 0.5f); + if (br < 0.0f) br = 0.0f; + if (br > 0.80f) br = 0.80f; //@note; was 1.0f + return ((int) (br * 11)); } Vec3 Level::getSkyColor(Entity* source, float a) { - float td = getTimeOfDay(a); + float td = getTimeOfDay(a); float br = Mth::cos(td * Mth::PI * 2) * 2 + 0.5f; - if (br < 0.0f) br = 0.0f; - if (br > 0.75f) br = 0.75f; //@note; was 1.0f + if (br < 0.0f) br = 0.0f; + if (br > 0.75f) br = 0.75f; //@note; was 1.0f -// int xx = Mth::floor(source->x); -// int zz = Mth::floor(source->z); -// float temp = 0.5;//(float) getBiomeSource().getTemperature(xx, zz); - int skyColor = 0x3070ff;//getBiomeSource().getBiome(xx, zz).getSkyColor(temp); + int xx = Mth::floor(source->x); + int zz = Mth::floor(source->z); + // float temp = 0.5;//(float) getBiomeSource().getTemperature(xx, zz); // unused in normal pe too, just hardcoded temp values for some reason. + float temp = (float) getBiomeSource()->getTemperature(xx, zz); + int skyColor; + if (dimension->FogType == 1){ // 1 is java styled fog which should use temperatures! + skyColor = getBiomeSource()->getBiome(xx, zz)->getSkyColor(temp); + } + else { // otherwise default to the normal pocket edition skycolor - float r = ((skyColor >> 16) & 0xff) / 255.0f; - float g = ((skyColor >> 8) & 0xff) / 255.0f; - float b = ((skyColor) & 0xff) / 255.0f; - r *= br; - g *= br; - b *= br; + skyColor = 0x3070ff; + } - return Vec3(r, g, b); + // int skyColor = 0x3070ff;//getBiomeSource().getBiome(xx, zz).getSkyColor(temp); // This is the vanilla way, add it as OPTION_SKY - shredder + + float r = ((skyColor >> 16) & 0xff) / 255.0f; + float g = ((skyColor >> 8) & 0xff) / 255.0f; + float b = ((skyColor) & 0xff) / 255.0f; + r *= br; + g *= br; + b *= br; + + return Vec3(r, g, b); } Vec3 Level::getCloudColor( float a ) { @@ -1238,8 +1248,8 @@ float Level::getTimeOfDay(float a) { } float Level::getSunAngle(float a) { - float td = getTimeOfDay(a); - return td * Mth::PI * 2; + float td = getTimeOfDay(a); + return td * Mth::PI * 2; } //Vec3 Level::getCloudColor(float a) { @@ -1261,70 +1271,70 @@ float Level::getSunAngle(float a) { //} Vec3 Level::getFogColor(float a) { - float td = getTimeOfDay(a); - return dimension->getFogColor(td, a); + float td = getTimeOfDay(a); + return dimension->getFogColor(td, a); } int Level::getTopSolidBlock(int x, int z) { - LevelChunk* levelChunk = getChunkAt(x, z); + LevelChunk* levelChunk = getChunkAt(x, z); - int y = Level::DEPTH - 1; + int y = Level::DEPTH - 1; - while (getMaterial(x, y, z)->blocksMotion() && y > 0) { - y--; - } + while (getMaterial(x, y, z)->blocksMotion() && y > 0) { + y--; + } - x &= 15; - z &= 15; + x &= 15; + z &= 15; - while (y > 0) { - int t = levelChunk->getTile(x, y, z); - if (t == 0 /*|| !(Tile::tiles[t]->material->blocksMotion() || Tile::tiles[t]->material->isLiquid())*/ + while (y > 0) { + int t = levelChunk->getTile(x, y, z); + if (t == 0 /*|| !(Tile::tiles[t]->material->blocksMotion() || Tile::tiles[t]->material->isLiquid())*/ || !(Tile::tiles[t]->material->blocksMotion()) || Tile::tiles[t]->material == Material::leaves) { - y--; - } else { - return y + 1; - } - } - return -1; + y--; + } else { + return y + 1; + } + } + return -1; } int Level::getLightDepth(int x, int z) { - return getChunkAt(x, z)->getHeightmap(x & 15, z & 15); + return getChunkAt(x, z)->getHeightmap(x & 15, z & 15); } float Level::getStarBrightness(float a) { - float td = getTimeOfDay(a); + float td = getTimeOfDay(a); - float br = 1 - (Mth::cos(td * Mth::PI * 2) * 2 + 0.75f); - if (br < 0.f) br = 0; - if (br > 1.f) br = 1; + float br = 1 - (Mth::cos(td * Mth::PI * 2) * 2 + 0.75f); + if (br < 0.f) br = 0; + if (br > 1.f) br = 1; - return br * br * 0.5f; + return br * br * 0.5f; } void Level::addToTickNextTick(int x, int y, int z, int tileId, int tickDelay) { TickNextTickData td(x, y, z, tileId); - int r = 8; - if (instaTick) { - if (hasChunksAt(td.x - r, td.y - r, td.z - r, td.x + r, td.y + r, td.z + r)) { - int id = getTile(td.x, td.y, td.z); - if (id == td.tileId && id > 0) { - Tile::tiles[id]->tick(this, td.x, td.y, td.z, &random); - } - } - return; - } + int r = 8; + if (instaTick) { + if (hasChunksAt(td.x - r, td.y - r, td.z - r, td.x + r, td.y + r, td.z + r)) { + int id = getTile(td.x, td.y, td.z); + if (id == td.tileId && id > 0) { + Tile::tiles[id]->tick(this, td.x, td.y, td.z, &random); + } + } + return; + } - if (hasChunksAt(x - r, y - r, z - r, x + r, y + r, z + r)) { - if (tileId > 0) { - td.setDelay(tickDelay + levelData.getTime()); - } + if (hasChunksAt(x - r, y - r, z - r, x + r, y + r, z + r)) { + if (tileId > 0) { + td.setDelay(tickDelay + levelData.getTime()); + } if (_tickNextTickSet.find(td) == _tickNextTickSet.end()) { _tickNextTickSet.insert(td); - } - } + } + } } void Level::tickEntities() { @@ -1332,52 +1342,52 @@ void Level::tickEntities() { TIMER_PUSH("remove"); //Util::removeAll(entities, _entitiesToRemove); - // for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { - // Entity* e = _entitiesToRemove[j]; - // int xc = e->xChunk; - // int zc = e->zChunk; - // if (e->inChunk && hasChunk(xc, zc)) { - // getChunk(xc, zc)->removeEntity(e); - // } - // } - // for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { - // entityRemoved(_entitiesToRemove[j]); + // for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { + // Entity* e = _entitiesToRemove[j]; + // int xc = e->xChunk; + // int zc = e->zChunk; + // if (e->inChunk && hasChunk(xc, zc)) { + // getChunk(xc, zc)->removeEntity(e); + // } + // } + // for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { + // entityRemoved(_entitiesToRemove[j]); // //LOGI("a1 &e@delt: %p", _entitiesToRemove[j]); // delete _entitiesToRemove[j]; // //LOGI("a2"); - // } - // _entitiesToRemove.clear(); + // } + // _entitiesToRemove.clear(); EntityList pendingRemovedEntities; std::vector zombies; TIMER_POP_PUSH("regular"); - for (unsigned int i = 0; i < entities.size(); i++) { - Entity* e = entities[i]; + for (unsigned int i = 0; i < entities.size(); i++) { + Entity* e = entities[i]; - if (!e->removed) { - tick(e); + if (!e->removed) { + tick(e); if (e->getEntityTypeId() == MobTypes::Zombie) { zombies.push_back((Zombie*)e); ((Zombie*)e)->setUseNewAi(false); // @note: this is set under } - } + } TIMER_PUSH("remove"); - if (e->removed && (!e->isPlayer() || e->reallyRemoveIfPlayer)) { - int xc = e->xChunk; - int zc = e->zChunk; - if (e->inChunk && hasChunk(xc, zc)) { - getChunk(xc, zc)->removeEntity(e); - } + if (e->removed && (!e->isPlayer() || e->reallyRemoveIfPlayer)) { + int xc = e->xChunk; + int zc = e->zChunk; + if (e->inChunk && hasChunk(xc, zc)) { + getChunk(xc, zc)->removeEntity(e); + } entityIdLookup.erase(e->entityId); entities.erase(entities.begin() + (i--)); - entityRemoved(e); + entityRemoved(e); pendingRemovedEntities.push_back(e); - } + } TIMER_POP(); - } - + } + TIMER_POP_PUSH("remove"); for (unsigned int i = 0; i < pendingRemovedEntities.size(); ++i) { Entity* e = pendingRemovedEntities[i]; @@ -1498,51 +1508,51 @@ void Level::setZombieAi(std::vector& zombies) { } void Level::tick(Entity* e) { - tick(e, true); + tick(e, true); } void Level::tick(Entity* e, bool actual) { - int xc = Mth::floor(e->x); - int zc = Mth::floor(e->z); - int r = 32; - if (actual && !hasChunksAt(xc - r, 0, zc - r, xc + r, 128, zc + r)) { - return; - } + int xc = Mth::floor(e->x); + int zc = Mth::floor(e->z); + int r = 32; + if (actual && !hasChunksAt(xc - r, 0, zc - r, xc + r, 128, zc + r)) { + return; + } - e->xOld = e->x; - e->yOld = e->y; - e->zOld = e->z; - e->yRotO = e->yRot; - e->xRotO = e->xRot; + e->xOld = e->x; + e->yOld = e->y; + e->zOld = e->z; + e->yRotO = e->yRot; + e->xRotO = e->xRot; - if (actual && e->inChunk) { - e->tick(); - } + if (actual && e->inChunk) { + e->tick(); + } TIMER_PUSH("chunkCheck"); - // SANITY!! + // SANITY!! if (e->x != e->x) e->x = e->xOld; // @note: checking for NaN, not sure about Infinite if (e->y != e->y) e->y = e->yOld; if (e->z != e->z) e->z = e->zOld; if (e->xRot != e->xRot) e->xRot = e->xRotO; if (e->yRot != e->yRot) e->yRot = e->yRotO; - int xcn = Mth::floor(e->x / 16.0f); - int ycn = Mth::floor(e->y / 16.0f); - int zcn = Mth::floor(e->z / 16.0f); + int xcn = Mth::floor(e->x / 16.0f); + int ycn = Mth::floor(e->y / 16.0f); + int zcn = Mth::floor(e->z / 16.0f); - if (!e->inChunk || (e->xChunk != xcn || e->yChunk != ycn || e->zChunk != zcn)) { - if (e->inChunk && hasChunk(e->xChunk, e->zChunk)) { - getChunk(e->xChunk, e->zChunk)->removeEntity(e, e->yChunk); - } + if (!e->inChunk || (e->xChunk != xcn || e->yChunk != ycn || e->zChunk != zcn)) { + if (e->inChunk && hasChunk(e->xChunk, e->zChunk)) { + getChunk(e->xChunk, e->zChunk)->removeEntity(e, e->yChunk); + } - if (hasChunk(xcn, zcn)) { - e->inChunk = true; - getChunk(xcn, zcn)->addEntity(e); - } else { - e->inChunk = false; - } - } + if (hasChunk(xcn, zcn)) { + e->inChunk = true; + getChunk(xcn, zcn)->addEntity(e); + } else { + e->inChunk = false; + } + } TIMER_POP(); // Save player info every n:th second @@ -1554,109 +1564,109 @@ void Level::tick(Entity* e, bool actual) { } bool Level::isUnobstructed(const AABB& aabb) { - EntityList& entities = getEntities(NULL, aabb); - for (unsigned int i = 0; i < entities.size(); i++) { - Entity* e = entities[i]; - if (!e->removed && e->blocksBuilding) return false; - } - return true; + EntityList& entities = getEntities(NULL, aabb); + for (unsigned int i = 0; i < entities.size(); i++) { + Entity* e = entities[i]; + if (!e->removed && e->blocksBuilding) return false; + } + return true; } bool Level::containsAnyLiquid(const AABB& box) { - int x0 = Mth::floor(box.x0); - int x1 = Mth::floor(box.x1 + 1); - int y0 = Mth::floor(box.y0); - int y1 = Mth::floor(box.y1 + 1); - int z0 = Mth::floor(box.z0); - int z1 = Mth::floor(box.z1 + 1); + int x0 = Mth::floor(box.x0); + int x1 = Mth::floor(box.x1 + 1); + int y0 = Mth::floor(box.y0); + int y1 = Mth::floor(box.y1 + 1); + int z0 = Mth::floor(box.z0); + int z1 = Mth::floor(box.z1 + 1); - if (box.x0 < 0) x0--; - if (box.y0 < 0) y0--; - if (box.z0 < 0) z0--; + if (box.x0 < 0) x0--; + if (box.y0 < 0) y0--; + if (box.z0 < 0) z0--; - for (int x = x0; x < x1; x++) - for (int y = y0; y < y1; y++) - for (int z = z0; z < z1; z++) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL && tile->material->isLiquid()) { - return true; - } - } - return false; + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + for (int z = z0; z < z1; z++) { + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL && tile->material->isLiquid()) { + return true; + } + } + return false; } bool Level::containsFireTile(const AABB& box) { - int x0 = Mth::floor(box.x0); - int x1 = Mth::floor(box.x1 + 1); - int y0 = Mth::floor(box.y0); - int y1 = Mth::floor(box.y1 + 1); - int z0 = Mth::floor(box.z0); - int z1 = Mth::floor(box.z1 + 1); + int x0 = Mth::floor(box.x0); + int x1 = Mth::floor(box.x1 + 1); + int y0 = Mth::floor(box.y0); + int y1 = Mth::floor(box.y1 + 1); + int z0 = Mth::floor(box.z0); + int z1 = Mth::floor(box.z1 + 1); - if (hasChunksAt(x0, y0, z0, x1, y1, z1)) { - for (int x = x0; x < x1; x++) - for (int y = y0; y < y1; y++) - for (int z = z0; z < z1; z++) { - int t = getTile(x, y, z); + if (hasChunksAt(x0, y0, z0, x1, y1, z1)) { + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + for (int z = z0; z < z1; z++) { + int t = getTile(x, y, z); - if (t == ((Tile*)(Tile::fire))->id - || t == Tile::lava->id - || t == Tile::calmLava->id) { - return true; + if (t == ((Tile*)(Tile::fire))->id + || t == Tile::lava->id + || t == Tile::calmLava->id) { + return true; } - } - } - return false; + } + } + return false; } bool Level::containsMaterial(const AABB& box, const Material* material) { - int x0 = Mth::floor(box.x0); - int x1 = Mth::floor(box.x1 + 1); - int y0 = Mth::floor(box.y0); - int y1 = Mth::floor(box.y1 + 1); - int z0 = Mth::floor(box.z0); - int z1 = Mth::floor(box.z1 + 1); + int x0 = Mth::floor(box.x0); + int x1 = Mth::floor(box.x1 + 1); + int y0 = Mth::floor(box.y0); + int y1 = Mth::floor(box.y1 + 1); + int z0 = Mth::floor(box.z0); + int z1 = Mth::floor(box.z1 + 1); - for (int x = x0; x < x1; x++) - for (int y = y0; y < y1; y++) - for (int z = z0; z < z1; z++) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL && tile->material == material) { - return true; - } - } - return false; + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + for (int z = z0; z < z1; z++) { + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL && tile->material == material) { + return true; + } + } + return false; } bool Level::containsLiquid(const AABB& box, const Material* material) { - int x0 = Mth::floor(box.x0); - int x1 = Mth::floor(box.x1 + 1); - int y0 = Mth::floor(box.y0); - int y1 = Mth::floor(box.y1 + 1); - int z0 = Mth::floor(box.z0); - int z1 = Mth::floor(box.z1 + 1); + int x0 = Mth::floor(box.x0); + int x1 = Mth::floor(box.x1 + 1); + int y0 = Mth::floor(box.y0); + int y1 = Mth::floor(box.y1 + 1); + int z0 = Mth::floor(box.z0); + int z1 = Mth::floor(box.z1 + 1); - for (int x = x0; x < x1; x++) - for (int y = y0; y < y1; y++) - for (int z = z0; z < z1; z++) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile != NULL && tile->material == material) { - int data = getData(x, y, z); - float yh1 = (float)(y + 1); - if (data < 8) { - yh1 = (float)y + 1.0f - (float)data / 8.0f; - } - if (yh1 >= box.y0) { - return true; - } - } - } - return false; + for (int x = x0; x < x1; x++) + for (int y = y0; y < y1; y++) + for (int z = z0; z < z1; z++) { + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile != NULL && tile->material == material) { + int data = getData(x, y, z); + float yh1 = (float)(y + 1); + if (data < 8) { + yh1 = (float)y + 1.0f - (float)data / 8.0f; + } + if (yh1 >= box.y0) { + return true; + } + } + } + return false; } /* in java, this returns an Explosion */ void Level::explode(Entity* source, float x, float y, float z, float r) { - explode(source, x, y, z, r, false); + explode(source, x, y, z, r, false); } /* in java, this returns an Explosion */ @@ -1672,29 +1682,29 @@ void Level::explode(Entity* source, float x, float y, float z, float r, bool fir } float Level::getSeenPercent(const Vec3& center, const AABB& bb) { - float xs = 1.0f / ((bb.x1 - bb.x0) * 2 + 1); - float ys = 1.0f / ((bb.y1 - bb.y0) * 2 + 1); - float zs = 1.0f / ((bb.z1 - bb.z0) * 2 + 1); - int hits = 0; - int count = 0; - for (float xx = 0; xx <= 1; xx += xs) - for (float yy = 0; yy <= 1; yy += ys) - for (float zz = 0; zz <= 1; zz += zs) { - float x = bb.x0 + (bb.x1 - bb.x0) * xx; - float y = bb.y0 + (bb.y1 - bb.y0) * yy; - float z = bb.z0 + (bb.z1 - bb.z0) * zz; + float xs = 1.0f / ((bb.x1 - bb.x0) * 2 + 1); + float ys = 1.0f / ((bb.y1 - bb.y0) * 2 + 1); + float zs = 1.0f / ((bb.z1 - bb.z0) * 2 + 1); + int hits = 0; + int count = 0; + for (float xx = 0; xx <= 1; xx += xs) + for (float yy = 0; yy <= 1; yy += ys) + for (float zz = 0; zz <= 1; zz += zs) { + float x = bb.x0 + (bb.x1 - bb.x0) * xx; + float y = bb.y0 + (bb.y1 - bb.y0) * yy; + float z = bb.z0 + (bb.z1 - bb.z0) * zz; if (!clip(Vec3(x, y, z), center).isHit()) hits++; - count++; - } + count++; + } - return hits / (float) count; + return hits / (float) count; } bool Level::isSolidBlockingTile(int x, int y, int z) { - Tile* tile = Tile::tiles[getTile(x, y, z)]; - if (tile == NULL) return false; - return tile->material->isSolidBlocking() && tile->isCubeShaped(); + Tile* tile = Tile::tiles[getTile(x, y, z)]; + if (tile == NULL) return false; + return tile->material->isSolidBlocking() && tile->isCubeShaped(); } bool Level::isSolidRenderTile(int x, int y, int z) { @@ -1705,18 +1715,18 @@ bool Level::isSolidRenderTile(int x, int y, int z) { void Level::extinguishFire(int x, int y, int z, int face) { switch (face) { - case Facing::DOWN : y--; break; - case Facing::UP : y++; break; - case Facing::NORTH: z--; break; - case Facing::SOUTH: z++; break; - case Facing::WEST : x--; break; - case Facing::EAST : x++; break; + case Facing::DOWN : y--; break; + case Facing::UP : y++; break; + case Facing::NORTH: z--; break; + case Facing::SOUTH: z++; break; + case Facing::WEST : x--; break; + case Facing::EAST : x++; break; } - if (getTile(x, y, z) == ((Tile*)Tile::fire)->id) { - //playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.fizz", 0.5f, 2.6f + (random.nextFloat() - random.nextFloat()) * 0.8f); - setTile(x, y, z, 0); - } + if (getTile(x, y, z) == ((Tile*)Tile::fire)->id) { + //playSound(x + 0.5f, y + 0.5f, z + 0.5f, "random.fizz", 0.5f, 2.6f + (random.nextFloat() - random.nextFloat()) * 0.8f); + setTile(x, y, z, 0); + } } // String gatherStats() { // return "All: " + this.entities.size(); @@ -1783,37 +1793,37 @@ void Level::removeTileEntity(int x, int y, int z) { // int Level::getLightsToUpdate() { - return _lightUpdates.size(); + return _lightUpdates.size(); } bool Level::updateLights() { - if (_maxRecurse >= 50) { - return false; - } + if (_maxRecurse >= 50) { + return false; + } //static int _MaxSize = 0; - _maxRecurse++; - //try { - int max = 500; - while ((int)_lightUpdates.size() > 0) { - if (--max <= 0) - { - _maxRecurse--; - return true; - } - LightUpdate l = _lightUpdates.back(); - _lightUpdates.pop_back(); - l.update(this); - //if ((int)_lightUpdates.size() > _MaxSize) - //{ - // LOGI("MAX_updsize_light: %d (%d)\n", _lightUpdates.size(), _MaxSize); - // _MaxSize = _lightUpdates.size(); - //} - } - _maxRecurse--; - return false; - //} finally { - //maxRecurse--; - //} + _maxRecurse++; + //try { + int max = 500; + while ((int)_lightUpdates.size() > 0) { + if (--max <= 0) + { + _maxRecurse--; + return true; + } + LightUpdate l = _lightUpdates.back(); + _lightUpdates.pop_back(); + l.update(this); + //if ((int)_lightUpdates.size() > _MaxSize) + //{ + // LOGI("MAX_updsize_light: %d (%d)\n", _lightUpdates.size(), _MaxSize); + // _MaxSize = _lightUpdates.size(); + //} + } + _maxRecurse--; + return false; + //} finally { + //maxRecurse--; + //} } void Level::setUpdateLights(bool doUpdate) { @@ -1821,96 +1831,96 @@ void Level::setUpdateLights(bool doUpdate) { } void Level::updateLight(const LightLayer& layer, int x0, int y0, int z0, int x1, int y1, int z1) { - updateLight(layer, x0, y0, z0, x1, y1, z1, true); + updateLight(layer, x0, y0, z0, x1, y1, z1, true); } static int maxLoop = 0; void Level::updateLight(const LightLayer& layer, int x0, int y0, int z0, int x1, int y1, int z1, bool join) { - if ((dimension->hasCeiling && &layer == &LightLayer::Sky) || !_updateLights) return; + if ((dimension->hasCeiling && &layer == &LightLayer::Sky) || !_updateLights) return; - maxLoop++; + maxLoop++; //if (x0 < -5 || z0 < -5) LOGI("x, z: %d, %d\n", x0, z0); - if (maxLoop == 50) { - maxLoop--; - return; - } - int xm = (x1 + x0) / 2; - int zm = (z1 + z0) / 2; - if (!hasChunkAt(xm, Level::DEPTH / 2, zm)) { - maxLoop--; - return; - } - if (getChunkAt(xm, zm)->isEmpty()) + if (maxLoop == 50) { + maxLoop--; + return; + } + int xm = (x1 + x0) / 2; + int zm = (z1 + z0) / 2; + if (!hasChunkAt(xm, Level::DEPTH / 2, zm)) { + maxLoop--; + return; + } + if (getChunkAt(xm, zm)->isEmpty()) { maxLoop--; return; } - int count = _lightUpdates.size(); - if (join) { - int toCheck = 5; - if (toCheck > count) toCheck = count; - for (int i = 0; i < toCheck; i++) { - LightUpdate& last = _lightUpdates[_lightUpdates.size() - i - 1]; - if (last.layer == &layer && last.expandToContain(x0, y0, z0, x1, y1, z1)) { - maxLoop--; - return; - } - } - } - _lightUpdates.push_back(LightUpdate(layer, x0, y0, z0, x1, y1, z1)); - int max = 1000000; - if ((int)_lightUpdates.size() > max) { - LOGI("More than %d updates, aborting lighting updates\n", max); - _lightUpdates.clear(); - } - maxLoop--; + int count = _lightUpdates.size(); + if (join) { + int toCheck = 5; + if (toCheck > count) toCheck = count; + for (int i = 0; i < toCheck; i++) { + LightUpdate& last = _lightUpdates[_lightUpdates.size() - i - 1]; + if (last.layer == &layer && last.expandToContain(x0, y0, z0, x1, y1, z1)) { + maxLoop--; + return; + } + } + } + _lightUpdates.push_back(LightUpdate(layer, x0, y0, z0, x1, y1, z1)); + int max = 1000000; + if ((int)_lightUpdates.size() > max) { + LOGI("More than %d updates, aborting lighting updates\n", max); + _lightUpdates.clear(); + } + maxLoop--; } // // // int xxo, yyo, zzo; // bool Level::updateSkyBrightness() { - int newDark = this->getSkyDarken(1); - if (newDark != skyDarken) { - skyDarken = newDark; + int newDark = this->getSkyDarken(1); + if (newDark != skyDarken) { + skyDarken = newDark; return true; - } + } return false; } void Level::setSpawnSettings(bool spawnEnemies, bool spawnFriendlies) { - //this->spawnEnemies = spawnEnemies; - //this->spawnFriendlies = spawnFriendlies; + //this->spawnEnemies = spawnEnemies; + //this->spawnFriendlies = spawnFriendlies; } void Level::animateTick(int xt, int yt, int zt) { - int r = 16; - Random animateRandom; + int r = 16; + Random animateRandom; - for (int i = 0; i < 100; i++) { - int x = xt + random.nextInt(r) - random.nextInt(r); - int y = yt + random.nextInt(r) - random.nextInt(r); - int z = zt + random.nextInt(r) - random.nextInt(r); - int t = getTile(x, y, z); - if (t > 0) { - Tile::tiles[t]->animateTick(this, x, y, z, &animateRandom); - } - } + for (int i = 0; i < 100; i++) { + int x = xt + random.nextInt(r) - random.nextInt(r); + int y = yt + random.nextInt(r) - random.nextInt(r); + int z = zt + random.nextInt(r) - random.nextInt(r); + int t = getTile(x, y, z); + if (t > 0) { + Tile::tiles[t]->animateTick(this, x, y, z, &animateRandom); + } + } } EntityList& Level::getEntities(Entity* except, const AABB& bb) { - _es.clear(); - int xc0 = Mth::floor((bb.x0 - 2) / 16); - int xc1 = Mth::floor((bb.x1 + 2) / 16); - int zc0 = Mth::floor((bb.z0 - 2) / 16); - int zc1 = Mth::floor((bb.z1 + 2) / 16); - for (int xc = xc0; xc <= xc1; xc++) - for (int zc = zc0; zc <= zc1; zc++) { - if (hasChunk(xc, zc)) { - getChunk(xc, zc)->getEntities(except, bb, _es); - } - } - return _es; + _es.clear(); + int xc0 = Mth::floor((bb.x0 - 2) / 16); + int xc1 = Mth::floor((bb.x1 + 2) / 16); + int zc0 = Mth::floor((bb.z0 - 2) / 16); + int zc1 = Mth::floor((bb.z1 + 2) / 16); + for (int xc = xc0; xc <= xc1; xc++) + for (int zc = zc0; zc <= zc1; zc++) { + if (hasChunk(xc, zc)) { + getChunk(xc, zc)->getEntities(except, bb, _es); + } + } + return _es; } // List getEntitiesOfClass(Class baseClass, AABB bb) { @@ -1929,7 +1939,7 @@ EntityList& Level::getEntities(Entity* except, const AABB& bb) { // } const EntityList& Level::getAllEntities() { - return entities; + return entities; } // int countInstanceOf(Class clas) { @@ -1943,10 +1953,10 @@ const EntityList& Level::getAllEntities() { // /* void Level::addEntities(const EntityList& list) { - entities.insert(entities.end(), list.begin(), list.end()); - for (int j = 0; j < (int)list.size(); j++) { - entityAdded(list[j]); - } +entities.insert(entities.end(), list.begin(), list.end()); +for (int j = 0; j < (int)list.size(); j++) { +entityAdded(list[j]); +} } */ @@ -1955,65 +1965,65 @@ void Level::addEntities(const EntityList& list) { //} void Level::prepare() { - while (_chunkSource->tick()) - ; + while (_chunkSource->tick()) + ; } bool Level::mayPlace(int tileId, int x, int y, int z, bool ignoreEntities,unsigned char face) { - int targetType = getTile(x, y, z); - const Tile* targetTile = Tile::tiles[targetType]; - Tile* tile = Tile::tiles[tileId]; + int targetType = getTile(x, y, z); + const Tile* targetTile = Tile::tiles[targetType]; + Tile* tile = Tile::tiles[tileId]; - AABB* aabb = tile->getAABB(this, x, y, z); - if (ignoreEntities) aabb = NULL; - if (aabb != NULL && !isUnobstructed(*aabb)) return false; - if (targetTile == Tile::water || targetTile == Tile::calmWater || targetTile == Tile::lava || targetTile == Tile::calmLava || targetTile == (Tile*)(Tile::fire) || targetTile == Tile::topSnow) targetTile = NULL; - if (tileId > 0 && targetTile == NULL) { - if (tile->mayPlace(this, x, y, z, face)) { - return true; - } - } + AABB* aabb = tile->getAABB(this, x, y, z); + if (ignoreEntities) aabb = NULL; + if (aabb != NULL && !isUnobstructed(*aabb)) return false; + if (targetTile == Tile::water || targetTile == Tile::calmWater || targetTile == Tile::lava || targetTile == Tile::calmLava || targetTile == (Tile*)(Tile::fire) || targetTile == Tile::topSnow) targetTile = NULL; + if (tileId > 0 && targetTile == NULL) { + if (tile->mayPlace(this, x, y, z, face)) { + return true; + } + } - return false; + return false; } int Level::getSeaLevel() { - return SEA_LEVEL; + return SEA_LEVEL; } bool Level::getDirectSignal(int x, int y, int z, int dir) { - int t = getTile(x, y, z); - if (t == 0) return false; - return Tile::tiles[t]->getDirectSignal(this, x, y, z, dir); + int t = getTile(x, y, z); + if (t == 0) return false; + return Tile::tiles[t]->getDirectSignal(this, x, y, z, dir); } bool Level::hasDirectSignal(int x, int y, int z) { - if (getDirectSignal(x, y - 1, z, 0)) return true; - if (getDirectSignal(x, y + 1, z, 1)) return true; - if (getDirectSignal(x, y, z - 1, 2)) return true; - if (getDirectSignal(x, y, z + 1, 3)) return true; - if (getDirectSignal(x - 1, y, z, 4)) return true; - if (getDirectSignal(x + 1, y, z, 5)) return true; - return false; + if (getDirectSignal(x, y - 1, z, 0)) return true; + if (getDirectSignal(x, y + 1, z, 1)) return true; + if (getDirectSignal(x, y, z - 1, 2)) return true; + if (getDirectSignal(x, y, z + 1, 3)) return true; + if (getDirectSignal(x - 1, y, z, 4)) return true; + if (getDirectSignal(x + 1, y, z, 5)) return true; + return false; } bool Level::getSignal(int x, int y, int z, int dir) { - if (isSolidBlockingTile(x, y, z)) { - return hasDirectSignal(x, y, z); - } - int t = getTile(x, y, z); - if (t == 0) return false; - return Tile::tiles[t]->getSignal(this, x, y, z, dir); + if (isSolidBlockingTile(x, y, z)) { + return hasDirectSignal(x, y, z); + } + int t = getTile(x, y, z); + if (t == 0) return false; + return Tile::tiles[t]->getSignal(this, x, y, z, dir); } bool Level::hasNeighborSignal(int x, int y, int z) { - if (getSignal(x, y - 1, z, 0)) return true; - if (getSignal(x, y + 1, z, 1)) return true; - if (getSignal(x, y, z - 1, 2)) return true; - if (getSignal(x, y, z + 1, 3)) return true; - if (getSignal(x - 1, y, z, 4)) return true; - if (getSignal(x + 1, y, z, 5)) return true; - return false; + if (getSignal(x, y - 1, z, 0)) return true; + if (getSignal(x, y + 1, z, 1)) return true; + if (getSignal(x, y, z - 1, 2)) return true; + if (getSignal(x, y, z + 1, 3)) return true; + if (getSignal(x - 1, y, z, 4)) return true; + if (getSignal(x + 1, y, z, 5)) return true; + return false; } // void checkSession() { @@ -2021,44 +2031,44 @@ bool Level::hasNeighborSignal(int x, int y, int z) { // } // void Level::setTime(long time) { - this->levelData.setTime(time); + this->levelData.setTime(time); } long Level::getSeed() { - return levelData.getSeed(); + return levelData.getSeed(); } long Level::getTime() { - return levelData.getTime(); + return levelData.getTime(); } Pos Level::getSharedSpawnPos() { - return Pos(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn()); + return Pos(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn()); } void Level::setSpawnPos(Pos spawnPos) { - levelData.setSpawn(spawnPos.x, spawnPos.y, spawnPos.z); + levelData.setSpawn(spawnPos.x, spawnPos.y, spawnPos.z); } /* void Level::ensureAdded(Entity* entity) { - int xc = Mth::floor(entity->x / 16); - int zc = Mth::floor(entity->z / 16); - int r = 2; - for (int x = xc - r; x <= xc + r; x++) { - for (int z = zc - r; z <= zc + r; z++) { - this->getChunk(x, z); - } - } +int xc = Mth::floor(entity->x / 16); +int zc = Mth::floor(entity->z / 16); +int r = 2; +for (int x = xc - r; x <= xc + r; x++) { +for (int z = zc - r; z <= zc + r; z++) { +this->getChunk(x, z); +} +} - if (std::find(entities.begin(), entities.end(), entity) == entities.end()) { - entities.push_back(entity); - } +if (std::find(entities.begin(), entities.end(), entity) == entities.end()) { +entities.push_back(entity); +} } */ bool Level::mayInteract(Player* player, int xt, int yt, int zt) { - return true; + return true; } void Level::broadcastEntityEvent(Entity* e, char eventId) { @@ -2070,40 +2080,40 @@ void Level::broadcastEntityEvent(Entity* e, char eventId) { /* void Level::removeAllPendingEntityRemovals() { - //Util::removeAll(entities, _entitiesToRemove); - // //entities.removeAll(entitiesToRemove); - // for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { - // Entity* e = _entitiesToRemove[j]; - // int xc = e->xChunk; - // int zc = e->zChunk; - // if (e->inChunk && hasChunk(xc, zc)) { - // getChunk(xc, zc)->removeEntity(e); - // } - // } +//Util::removeAll(entities, _entitiesToRemove); +// //entities.removeAll(entitiesToRemove); +// for (int j = 0; j < (int)_entitiesToRemove.size(); j++) { +// Entity* e = _entitiesToRemove[j]; +// int xc = e->xChunk; +// int zc = e->zChunk; +// if (e->inChunk && hasChunk(xc, zc)) { +// getChunk(xc, zc)->removeEntity(e); +// } +// } - // for (unsigned int j = 0; j < _entitiesToRemove.size(); j++) { - // entityRemoved(_entitiesToRemove[j]); - // } - // _entitiesToRemove.clear(); +// for (unsigned int j = 0; j < _entitiesToRemove.size(); j++) { +// entityRemoved(_entitiesToRemove[j]); +// } +// _entitiesToRemove.clear(); - for (unsigned int i = 0; i < entities.size(); i++) { - Entity* e = entities[i]; +for (unsigned int i = 0; i < entities.size(); i++) { +Entity* e = entities[i]; - if (e->removed) { - int xc = e->xChunk; - int zc = e->zChunk; - if (e->inChunk && hasChunk(xc, zc)) { - getChunk(xc, zc)->removeEntity(e); - } - entities.erase( entities.begin() + (i--) ); - entityRemoved(e); - } - } +if (e->removed) { +int xc = e->xChunk; +int zc = e->zChunk; +if (e->inChunk && hasChunk(xc, zc)) { +getChunk(xc, zc)->removeEntity(e); +} +entities.erase( entities.begin() + (i--) ); +entityRemoved(e); +} +} } */ ChunkSource* Level::getChunkSource() { - return _chunkSource; + return _chunkSource; } // void tileEvent(int x, int y, int z, int b0, int b1) { @@ -2112,11 +2122,11 @@ ChunkSource* Level::getChunkSource() { // } LevelStorage* Level::getLevelStorage() { - return levelStorage; + return levelStorage; } LevelData* Level::getLevelData() { - return &levelData; + return &levelData; } void Level::takePicture( TripodCamera* cam, Entity* e ) @@ -2138,7 +2148,7 @@ int Level::getEntitiesOfType( int entityType, const AABB& bb, EntityList& list ) getChunk(xc, zc)->getEntitiesOfType(entityType, bb, list); } } - return list.size() - count; + return list.size() - count; } int Level::getEntitiesOfClass( int type, const AABB& bb, EntityList& list ) { @@ -2208,9 +2218,9 @@ void Level::updateSkyDarken() void Level::removePlayer( Player* player ) { for (unsigned int i = 0; i < players.size(); ++i) - if (players[i] == player) { - players.erase( players.begin() + i ); - } + if (players[i] == player) { + players.erase( players.begin() + i ); + } } int Level::isNightMode() { @@ -2231,7 +2241,7 @@ bool Level::inRange( int x, int y, int z ) { // AdventureSettings // AdventureSettings::AdventureSettings() -: doTickTime(true), + : doTickTime(true), noPvP(false), noPvM(false), noMvP(false), diff --git a/src/world/level/biome/Biome.cpp b/src/world/level/biome/Biome.cpp index 609ed52..f97cab8 100755 --- a/src/world/level/biome/Biome.cpp +++ b/src/world/level/biome/Biome.cpp @@ -8,6 +8,8 @@ #include "../../entity/MobCategory.h" #include "../../level/tile/TallGrass.h" +#include "../../../util/Color.h" + Biome* Biome::rainForest = NULL; Biome* Biome::swampland = NULL; Biome* Biome::seasonalForest = NULL; @@ -208,11 +210,11 @@ float Biome::adjustDepth( float depth ) int Biome::getSkyColor( float temp ) { -// temp /= 3.f; -// if (temp < -1) temp = -1; -// if (temp > 1) temp = 1; - return 0x80808080; - //return Color.getHSBColor(224 / 360.0f - temp * 0.05f, 0.50f + temp * 0.1f, 1.0f).getRGB(); + temp /= 3.f; + if (temp < -1) temp = -1; + if (temp > 1) temp = 1; +// return 0x80808080;This is the vanilla way, add it as OPTION_SKY or leave it like this bcus this function literally never gets used anyways if level has vanilla sky color - shredder + return Color::getHSBColor(224 / 360.0f - temp * 0.05f, 0.50f + temp * 0.1f, 1.0f).getRGB(); } Biome::MobList& Biome::getMobs(const MobCategory& category) diff --git a/src/world/level/chunk/LevelChunk.cpp b/src/world/level/chunk/LevelChunk.cpp index bb373fb..ef13d1b 100755 --- a/src/world/level/chunk/LevelChunk.cpp +++ b/src/world/level/chunk/LevelChunk.cpp @@ -262,14 +262,14 @@ void LevelChunk::recalcHeight(int x, int yStart, int z) { /*public*/ void LevelChunk::skyBrightnessChanged() { -// int x0 = xt; -// int y0 = this->minHeight - 16; -// int z0 = zt; -// int x1 = xt + 16; -// int y1 = Level::DEPTH - 1; -// int z1 = zt + 16; + int x0 = xt; + int y0 = this->minHeight - 16; + int z0 = zt; + int x1 = xt + 16; + int y1 = Level::DEPTH - 1; + int z1 = zt + 16; - //level->setTilesDirty(x0, y0, z0, x1, y1, z1); + level->setTilesDirty(x0, y0, z0, x1, y1, z1); } /*public*/ diff --git a/src/world/level/dimension/Dimension.cpp b/src/world/level/dimension/Dimension.cpp index 1345c07..c565409 100755 --- a/src/world/level/dimension/Dimension.cpp +++ b/src/world/level/dimension/Dimension.cpp @@ -15,7 +15,8 @@ Dimension::Dimension() ultraWarm(false), hasCeiling(false), biomeSource(NULL), - id(0) + id(0), + fogColor(0x80daff) { } @@ -93,6 +94,18 @@ float* Dimension::getSunriseColor( float td, float a ) Vec3 Dimension::getFogColor( float td, float a ) { + if (FogType == 1) + { + fogColor = 0xc0d8ff; // 1 returns java beta styled fog color. + } + else if (FogType == 2) + { + fogColor = 0x406fe5; // 2 returns some type of unused fog color IDK what this one was used for possibly early pe?? + } + else // otherwise as default we return the mcpe fog color + { + fogColor = 0x80daff; + } float br = Mth::cos(td * Mth::PI * 2) * 2 + 0.5f; if (br < 0.0f) br = 0.0f; if (br > 1.0f) br = 1.0f; @@ -104,7 +117,8 @@ Vec3 Dimension::getFogColor( float td, float a ) g *= br * 0.94f + 0.06f; b *= br * 0.91f + 0.09f; return Vec3(r, g, b); - //return Vec3(0.752941f, 0.847059f, 1); + + // } bool Dimension::mayRespawn() diff --git a/src/world/level/dimension/Dimension.h b/src/world/level/dimension/Dimension.h index e77dbe3..b33861c 100755 --- a/src/world/level/dimension/Dimension.h +++ b/src/world/level/dimension/Dimension.h @@ -49,8 +49,11 @@ public: bool hasCeiling; float brightnessRamp[16];//Level::MAX_BRIGHTNESS + 1]; int id; + + // shredder added + int FogType; // lets us choose between what fog we want ig protected: - static const long fogColor = 0x80daff;//0x406fe5;//0xc0d8ff; + long fogColor; //= 0x80daff;//0x406fe5;//0xc0d8ff; float sunriseCol[4]; }; diff --git a/src/world/level/dimension/NormalDayCycleDimension.h b/src/world/level/dimension/NormalDayCycleDimension.h index 8e44a1a..321b10a 100755 --- a/src/world/level/dimension/NormalDayCycleDimension.h +++ b/src/world/level/dimension/NormalDayCycleDimension.h @@ -9,6 +9,7 @@ class NormalDayCycleDimension: public Dimension { public: + float getTimeOfDay(long time, float a) { int dayStep = (int) (time % Level::TICKS_PER_DAY); float td = (dayStep + a) / Level::TICKS_PER_DAY - 0.25f; @@ -20,6 +21,18 @@ public: } Vec3 getFogColor( float td, float a ) { + if (FogType == 1) + { + fogColor = 0xc0d8ff; // 1 returns java beta styled fog color. + } + else if (FogType == 2) + { + fogColor = 0x406fe5; // 2 returns some type of unused fog color IDK what this one was used for possibly early pe?? + } + else // otherwise as default we return the mcpe fog color + { + fogColor = 0x80daff; + } float br = cos(td * Mth::PI * 2) * 2 + 0.5f; if (br < 0) br = 0; if (br > 1.f) br = 1.f; @@ -35,7 +48,7 @@ public: return Vec3(r, g, b); } - + }; #endif /*NET_MINECRAFT_WORLD_LEVEL_DIMENSION__NormalDayCycleDimension_H__*/