diff --git a/project/lib_projects/raknet/jni/RaknetSources/Rand.cpp b/project/lib_projects/raknet/jni/RaknetSources/Rand.cpp index c3d8413..b01d1c6 100755 --- a/project/lib_projects/raknet/jni/RaknetSources/Rand.cpp +++ b/project/lib_projects/raknet/jni/RaknetSources/Rand.cpp @@ -142,8 +142,8 @@ void seedMT( unsigned int seed, unsigned int *state, unsigned int *&next, int &l // so-- that's why the only change I made is to restrict to odd seeds. // - register unsigned int x = ( seed | 1U ) & 0xFFFFFFFFU, *s = state; - register int j; + unsigned int x = ( seed | 1U ) & 0xFFFFFFFFU, *s = state; + int j; for ( left = 0, *s++ = x, j = N; --j; *s++ = ( x *= 69069U ) & 0xFFFFFFFFU ) @@ -154,8 +154,8 @@ void seedMT( unsigned int seed, unsigned int *state, unsigned int *&next, int &l unsigned int reloadMT( unsigned int *state, unsigned int *&next, int &left ) { - register unsigned int * p0 = state, *p2 = state + 2, *pM = state + M, s0, s1; - register int j; + unsigned int * p0 = state, *p2 = state + 2, *pM = state + M, s0, s1; + int j; if ( left < -1 ) seedMT( 4357U ); diff --git a/src/Minecraft.cpp b/src/Minecraft.cpp index ed3511e..19f030c 100755 --- a/src/Minecraft.cpp +++ b/src/Minecraft.cpp @@ -385,7 +385,7 @@ void Minecraft::hostMultiplayer(int port) { void* Minecraft::prepareLevel_tspawn(void *p_param) { Minecraft* mc = (Minecraft*) p_param; - mc->generateLevel("Currently not used", mc->level); + mc.generateLevel("Currently not used", mc.level); return 0; } diff --git a/src/MinecraftClient.cpp b/src/MinecraftClient.cpp index 7c5dc71..db87ab8 100644 --- a/src/MinecraftClient.cpp +++ b/src/MinecraftClient.cpp @@ -1,6 +1,6 @@ #include "Minecraft.hpp" #include "client/Options.hpp" -#include "client/gamemode/GameMode.hpp" +#include "gamemode/GameMode.hpp" #include "client/gui/screens/ChatScreen.hpp" #include "client/gui/screens/ConsoleScreen.hpp" #include "client/gui/screens/DeathScreen.hpp" @@ -104,7 +104,7 @@ void MinecraftClient::init() { checkGlError("Init complete"); - screenChooser.setScreen(SCREEN_STARTMENU); + m_screenChooser.setScreen(SCREEN_STARTMENU); if (options.getBooleanValue(OPTIONS_FIRST_LAUNCH)) { options.toggle(OPTIONS_FIRST_LAUNCH); @@ -321,7 +321,7 @@ void MinecraftClient::onGraphicsReset() { m_textures.clear(); - font->onGraphicsReset(); + font.onGraphicsReset(); gui.onGraphicsReset(); if (levelRenderer) levelRenderer->onGraphicsReset(); @@ -532,7 +532,7 @@ void MinecraftClient::tickInput() { } if (key == Keyboard::KEY_E) { - screenChooser.setScreen(SCREEN_BLOCKSELECTION); + m_screenChooser.setScreen(SCREEN_BLOCKSELECTION); } if (!getScreen && key == Keyboard::KEY_T && level) { @@ -832,7 +832,7 @@ void MinecraftClient::pauseGame(bool isBackPaused) { pause = canFreeze; if (getScreen != NULL) return; - screenChooser.setScreen(isBackPaused? SCREEN_PAUSEPREV : SCREEN_PAUSE); + m_screenChooser.setScreen(isBackPaused? SCREEN_PAUSEPREV : SCREEN_PAUSE); } void MinecraftClient::gameLostFocus() { @@ -855,7 +855,7 @@ void MinecraftClient::setScreen( Screen* screen ) { if (screen != NULL && screen->isErrorScreen()) return; if (screen == NULL && level == NULL) - screen = screenChooser.createScreen(SCREEN_STARTMENU); + screen = m_screenChooser.createScreen(SCREEN_STARTMENU); if (this->getScreen != NULL) { this->getScreen->removed(); @@ -1052,7 +1052,7 @@ void MinecraftClient::_levelGenerated() { this->cameraTargetPlayer = player; if (player == NULL) { - player = new LocalPlayer(minecraft, level, minecraft.options.getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType()); + player = new LocalPlayer(minecraft, level, minecraft.options().getStringValue(OPTIONS_USERNAME), level->dimension->id, isCreativeType()); gameMode->initPlayer(player); } diff --git a/src/MinecraftClient.hpp b/src/MinecraftClient.hpp index 27639d6..51f2488 100644 --- a/src/MinecraftClient.hpp +++ b/src/MinecraftClient.hpp @@ -66,16 +66,16 @@ public: void optionUpdated(OptionId option, float value) override; void optionUpdated(OptionId option, int value) override; - LocalPlayer* getPlayer() { return player; } - Font* getFont() { return font; } + LocalPlayer* player() { return m_player; } + Font* font() { return m_font; } Textures& textures() { return m_textures; } Options& options() { return m_options;} Screen* getScreen() { return m_screen; } Gui& gui() { return m_gui; } ParticleEngine* getParticleEngine() {return particleEngine; } - int getScreenWidth() { return width; } - int getScreenHeigth() { return height; } + int getScreenWidth() { return m_width; } + int getScreenHeight() { return m_height; } virtual void hostMultiplayer(int port) override; @@ -92,26 +92,34 @@ public: void onBlockDestroyed(Player* player, int x, int y, int z, int face) override; + ScreenChooser& screenChooser() { return m_screenChooser; } + + PixelCalc& pixelCalc() { return m_pixelCalc; } + PixelCalc& pixelCalcUi() { return m_pixelCalcUi; } + + IInputHolder* inputHolder() { return m_inputHolder; } + SoundEngine* soundEngine() { return m_soundEngine; } + protected: void _reloadInput(); void _levelGenerated() override; - int width = 1, height = 1; + int m_width = 1, m_height = 1; - Font* font = nullptr; + Font* m_font = nullptr; // @warn This is unsafe cuz Gui may call some MinecraftClient method while MinecraftClient is not ready MouseHandler mouseHandler; LevelRenderer* levelRenderer = nullptr; GameRenderer* gameRenderer = nullptr; ParticleEngine* particleEngine = nullptr; - SoundEngine* soundEngine = nullptr; + SoundEngine* m_soundEngine = nullptr; PerfRenderer* _perfRenderer = nullptr; bool mouseGrabbed = false; - PixelCalc pixelCalc; - PixelCalc pixelCalcUi; + PixelCalc m_pixelCalc; + PixelCalc m_pixelCalcUi; Screen* m_screen = nullptr; @@ -123,9 +131,8 @@ protected: volatile bool pause = false; - // @todo make static - LocalPlayer* player = nullptr; - IInputHolder* inputHolder = nullptr; + LocalPlayer* m_player = nullptr; + IInputHolder* m_inputHolder = nullptr; Mob* cameraTargetPlayer = nullptr; bool _supportsNonTouchscreen = false; @@ -136,7 +143,7 @@ protected: Textures m_textures{m_options, *m_platform}; - ScreenChooser screenChooser{*this}; + ScreenChooser m_screenChooser{*this}; Gui m_gui{*this}; }; \ No newline at end of file diff --git a/src/client/IConfigListener.cpp b/src/client/IConfigListener.cpp index 7b6792f..6075c4a 100755 --- a/src/client/IConfigListener.cpp +++ b/src/client/IConfigListener.cpp @@ -1,16 +1,12 @@ #include "IConfigListener.hpp" -#include "Minecraft.hpp" -#ifndef STANDALONE_SERVER +#include + #include "gui/Gui.hpp" -#endif /* STANDALONE_SERVER */ -Config createConfig(Minecraft* mc) { - Config c; - #ifndef STANDALONE_SERVER - c.setScreenSize(mc->width, mc->height, Gui::GuiScale); - #endif - c.pixelCalc = mc->pixelCalc; - c.pixelCalcUi = mc->pixelCalcUi; - c.minecraft = mc; - c.options = &mc->options; + +Config::Config(MinecraftClient& mc) : minecraft(mc), options(mc.options()), pixelCalc(mc.pixelCalc()), pixelCalcUi(mc.pixelCalcUi()) {} + +Config createConfig(MinecraftClient& mc) { + Config c(mc); + c.setScreenSize(mc.getScreenWidth(), mc.getScreenHeight(), Gui::GuiScale); return c; } diff --git a/src/client/IConfigListener.hpp b/src/client/IConfigListener.hpp index 3c29a20..6662128 100755 --- a/src/client/IConfigListener.hpp +++ b/src/client/IConfigListener.hpp @@ -1,11 +1,14 @@ #pragma once #include "PixelCalc.hpp" -class Minecraft; + +class MinecraftClient; class Options; class Config { public: + Config(MinecraftClient& mc); + // Screen dimensions and world-to-screen conversion void setScreenSize(int width, int height, float scale) { this->width = width; @@ -24,14 +27,14 @@ public: int guiWidth; int guiHeight; - PixelCalc pixelCalc; - PixelCalc pixelCalcUi; + PixelCalc& pixelCalc; + PixelCalc& pixelCalcUi; - Minecraft* minecraft; - Options* options; + MinecraftClient& minecraft; + Options& options; }; -Config createConfig(Minecraft* mc); +Config createConfig(MinecraftClient& mc); // Interface for Configuration-Changed listener // This can mean (for instance); diff --git a/src/client/Options.cpp b/src/client/Options.cpp index fa5d621..54ebf95 100755 --- a/src/client/Options.cpp +++ b/src/client/Options.cpp @@ -238,7 +238,7 @@ void Options::load() { // } // if (key == OptionStrings::Controls_UseTouchJoypad) { - // m_options[OPTIONS_IS_JOY_TOUCH_AREA] = readBool(value) && minecraft->useTouchscreen(); + // m_options[OPTIONS_IS_JOY_TOUCH_AREA] = readBool(value) && minecraft.useTouchscreen(); // } // // Feedback diff --git a/src/client/gui/Font.cpp b/src/client/gui/Font.cpp index 8911370..392e4a8 100755 --- a/src/client/gui/Font.cpp +++ b/src/client/gui/Font.cpp @@ -7,7 +7,7 @@ #include "util/Mth.hpp" #include -Font::Font( Options* options, const std::string& name, Textures* textures ) +Font::Font( Options* options, const std::string& name, Textures& textures ) : options(options), fontTexture(0), fontName(name), @@ -23,7 +23,7 @@ Font::Font( Options* options, const std::string& name, Textures* textures ) } -//Font::Font( Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset ) +//Font::Font( Options* options, const std::string& name, Textures& textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset ) //: options(options), // fontTexture(0), // fontName(name), diff --git a/src/client/gui/Font.hpp b/src/client/gui/Font.hpp index 05827f0..016c40a 100755 --- a/src/client/gui/Font.hpp +++ b/src/client/gui/Font.hpp @@ -13,8 +13,8 @@ class Options; class Font { public: - Font(Options* options, const std::string& name, Textures* textures); - //Font(Options* options, const std::string& name, Textures* textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset); + Font(Options* options, const std::string& name, Textures& textures); + //Font(Options* options, const std::string& name, Textures& textures, int imgW, int imgH, int x, int y, int cols, int rows, unsigned char charOffset); void init(Options* options); void onGraphicsReset(); diff --git a/src/client/gui/Gui.cpp b/src/client/gui/Gui.cpp index 7a9a4ed..33280f8 100755 --- a/src/client/gui/Gui.cpp +++ b/src/client/gui/Gui.cpp @@ -1,11 +1,10 @@ #include "Gui.hpp" #include "Font.hpp" -#include "MinecraftClient.hpp" +#include #include "client/Options.hpp" #include "platform/input/Keyboard.hpp" #include "screens/IngameBlockSelectionScreen.hpp" #include "screens/ChatScreen.hpp" -#include "screens/ConsoleScreen.hpp" #include #include "client/player/LocalPlayer.hpp" #include "client/renderer/Tesselator.hpp" @@ -14,10 +13,10 @@ #include "client/renderer/GameRenderer.hpp" #include "client/renderer/entity/ItemRenderer.hpp" #include "client/player/input/IInputHolder.hpp" -#include "client/gamemode/GameMode.hpp" -#include "client/gamemode/CreativeMode.hpp" +#include +#include "gamemode/CreativeMode.hpp" #include "client/renderer/Textures.hpp" -#include "AppConstants.hpp" +// #include "AppConstants.hpp" #include "world/entity/player/Inventory.hpp" #include "world/level/material/Material.hpp" #include "world/item/Item.hpp" @@ -30,8 +29,6 @@ #include #include -#define MAX_MESSAGE_WIDTH 240 - float Gui::InvGuiScale = 1.0f / 3.0f; float Gui::GuiScale = 1.0f / Gui::InvGuiScale; const float Gui::DropTicks = 40.0f; @@ -54,16 +51,16 @@ Gui::~Gui() { } void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { - if (!minecraft.level || !minecraft.getPlayer()) + if (!minecraft.level || !minecraft.player()) return; - //minecraft->gameRenderer->setupGuiScreen(); - Font* font = minecraft.getFont(); + //minecraft.gameRenderer->setupGuiScreen(); + Font* font = minecraft.font(); const bool isTouchInterface = minecraft.useTouchscreen(); const int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale); - const int screenHeight = (int)(minecraft.getScreenHeigth() * InvGuiScale); + const int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); blitOffset = -90; renderProgressIndicator(isTouchInterface, screenWidth, screenHeight, a); @@ -75,9 +72,9 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { // F: 3 int ySlot = screenHeight - 16 - 3; - if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) { + if (!minecraft.options().getBooleanValue(OPTIONS_HIDEGUI)) { if (minecraft.gameMode->canHurtPlayer()) { - minecraft.getTextures()->loadAndBindTexture("gui/icons.png"); + minecraft.textures().loadAndBindTexture("gui/icons.png"); Tesselator& t = Tesselator::instance; t.beginOverride(); t.colorABGR(0xffffffff); @@ -87,7 +84,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } } - if(minecraft.getPlayer()->getSleepTimer() > 0) { + if(minecraft.player()->getSleepTimer() > 0) { glDisable(GL_DEPTH_TEST); glDisable(GL_ALPHA_TEST); @@ -96,11 +93,11 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { glEnable(GL_ALPHA_TEST); glEnable(GL_DEPTH_TEST); } - if (!minecraft.options.getBooleanValue(OPTIONS_HIDEGUI)) { + if (!minecraft.options().getBooleanValue(OPTIONS_HIDEGUI)) { renderToolBar(a, ySlot, screenWidth); glEnable(GL_BLEND); - bool isChatting = (minecraft->screen && (dynamic_cast(minecraft->screen) || dynamic_cast(minecraft->screen))); + bool isChatting = minecraft.getScreen() && dynamic_cast(minecraft.getScreen()); unsigned int max = 10; if (isChatting) { int lineHeight = 9; @@ -112,20 +109,17 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } else { chatScrollOffset = 0; } - renderChatMessages(screenHeight, max, isChatting, font); -#if !defined(RPI) - renderOnSelectItemNameText(screenWidth, font, ySlot); -#endif -#if defined(RPI) - renderDebugInfo(); -#endif + if (font != nullptr) { + renderChatMessages(screenHeight, max, isChatting, *font); + renderOnSelectItemNameText(screenWidth, *font, ySlot); - 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); @@ -133,8 +127,8 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { } int Gui::getSlotIdAt(int x, int y) { - int screenWidth = (int)(minecraft->width * InvGuiScale); - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); x = (int)(x * InvGuiScale); y = (int)(y * InvGuiScale); @@ -164,24 +158,24 @@ void Gui::flashSlot(int slotId) { } void Gui::getSlotPos(int slot, int& posX, int& posY) { - int screenWidth = (int)(minecraft->width * InvGuiScale); - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); posX = screenWidth / 2 - getNumSlots() * 10 + slot * 20, posY = screenHeight - 22; } RectangleArea Gui::getRectangleArea(int extendSide) { const int Spacing = 3; - const float pCenterX = 2.0f + (float)(minecraft->width / 2); + const float pCenterX = 2.0f + (float)(minecraft.getScreenWidth() / 2); const float pHalfWidth = (1.0f + (getNumSlots() * 10 + Spacing)) * Gui::GuiScale; const float pHeight = (22 + Spacing) * Gui::GuiScale; if (extendSide < 0) - return RectangleArea(0, (float)minecraft->height-pHeight, pCenterX+pHalfWidth+2, (float)minecraft->height); + return RectangleArea(0, (float)minecraft.getScreenHeight()-pHeight, pCenterX+pHalfWidth+2, (float)minecraft.getScreenHeight()); if (extendSide > 0) - return RectangleArea(pCenterX-pHalfWidth, (float)minecraft->height-pHeight, (float)minecraft->width, (float)minecraft->height); + return RectangleArea(pCenterX-pHalfWidth, (float)minecraft.getScreenHeight()-pHeight, (float)minecraft.getScreenWidth(), (float)minecraft.getScreenHeight()); - return RectangleArea(pCenterX-pHalfWidth, (float)minecraft->height-pHeight, pCenterX+pHalfWidth+2, (float)minecraft->height); + return RectangleArea(pCenterX-pHalfWidth, (float)minecraft.getScreenHeight()-pHeight, pCenterX+pHalfWidth+2, (float)minecraft.getScreenHeight()); } void Gui::handleClick(int button, int x, int y) { @@ -190,9 +184,9 @@ void Gui::handleClick(int button, int x, int y) { int slot = getSlotIdAt(x, y); if (slot != -1) { if (_openInventorySlot && slot == (getNumSlots()-1)) { - minecraft->screenChooser.setScreen(SCREEN_BLOCKSELECTION); + minecraft.screenChooser().setScreen(SCREEN_BLOCKSELECTION); } else { - minecraft->player->inventory->selectSlot(slot); + minecraft.player()->inventory->selectSlot(slot); itemNameOverlayTime = 0; } } @@ -200,7 +194,7 @@ void Gui::handleClick(int button, int x, int y) { void Gui::handleKeyPressed(int key) { - bool isChatting = (minecraft->screen && (dynamic_cast(minecraft->screen) || dynamic_cast(minecraft->screen))); + bool isChatting = (minecraft.getScreen() && dynamic_cast(minecraft.getScreen())); if (isChatting) { // Allow scrolling the chat history with the mouse/keyboard when chat is open if (key == 38) { // VK_UP @@ -211,12 +205,12 @@ void Gui::handleKeyPressed(int key) return; } else if (key == 33) { // VK_PRIOR (Page Up) // Scroll by a page - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); int maxVisible = (screenHeight - 48) / 9; scrollChat(maxVisible); return; } else if (key == 34) { // VK_NEXT (Page Down) - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); int maxVisible = (screenHeight - 48) / 9; scrollChat(-maxVisible); return; @@ -224,30 +218,30 @@ void Gui::handleKeyPressed(int key) } if (key == Keyboard::KEY_F1) { - minecraft->options.toggle(OPTIONS_HIDEGUI); + minecraft.options().toggle(OPTIONS_HIDEGUI); } if (key == 99) { - if (minecraft->player->inventory->selected > 0) + if (minecraft.player()->inventory->selected > 0) { - minecraft->player->inventory->selected--; + minecraft.player()->inventory->selected--; } } else if (key == 4) { - if (minecraft->player->inventory->selected < (getNumSlots() - 2)) + if (minecraft.player()->inventory->selected < (getNumSlots() - 2)) { - minecraft->player->inventory->selected++; + minecraft.player()->inventory->selected++; } } else if (key == 100) { - minecraft->screenChooser.setScreen(SCREEN_BLOCKSELECTION); + minecraft.screenChooser().setScreen(SCREEN_BLOCKSELECTION); } - else if (key == minecraft->options.getIntValue(OPTIONS_KEY_DROP)) + else if (key == minecraft.options().getIntValue(OPTIONS_KEY_DROP)) { - minecraft->player->inventory->dropSlot(minecraft->player->inventory->selected, false); + minecraft.player()->inventory->dropSlot(minecraft.player()->inventory->selected, false); } } @@ -255,7 +249,7 @@ void Gui::scrollChat(int delta) { if (delta == 0) return; - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); int maxVisible = (screenHeight - 48) / 9; if (maxVisible <= 0) return; @@ -277,18 +271,18 @@ void Gui::tick() { guiMessages.at(i).ticks++; } - if (!minecraft->isCreativeMode()) + if (!minecraft.isCreativeMode()) tickItemDrop(); } void Gui::addMessage(const std::string& _string) { - if (!minecraft->font) + if (!minecraft.font()) return; std::string string = _string; - while (minecraft->font->width(string) > MAX_MESSAGE_WIDTH) { + while (minecraft.font()->width(string) > maxMessageWidth) { unsigned int i = 1; - while (i < string.length() && minecraft->font->width(string.substr(0, i + 1)) <= MAX_MESSAGE_WIDTH) { + while (i < string.length() && minecraft.font()->width(string.substr(0, i + 1)) <= maxMessageWidth) { i++; } addMessage(string.substr(0, i)); @@ -338,7 +332,7 @@ 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"); + minecraft.textures().loadAndBindTexture("misc/vignette.png"); Tesselator& t = Tesselator::instance; t.begin(); @@ -354,14 +348,14 @@ void Gui::renderVignette(float br, int w, int h) { } void Gui::renderSlot(int slot, int x, int y, float a) { - ItemInstance* item = minecraft->player->inventory->getItem(slot); + ItemInstance* item = minecraft.player()->inventory->getItem(slot); if (!item) { //LOGW("Warning: item @ Gui::renderSlot is NULL\n"); return; } const bool fancy = true; - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, (float)x, (float)y, fancy); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures(), item, (float)x, (float)y, fancy); } void Gui::renderSlotText( const ItemInstance* item, float x, float y, bool hasFinite, bool shadow ) @@ -381,9 +375,9 @@ void Gui::renderSlotText( const ItemInstance* item, float x, float y, bool hasFi //LOGI("slot: %d - %s\n", slot, buffer); if (shadow) - minecraft->font->drawShadow(buffer, x, y, item->count>0?0xffcccccc:0x60cccccc); + minecraft.font()->drawShadow(buffer, x, y, item->count>0?0xffcccccc:0x60cccccc); else - minecraft->font->draw(buffer, x, y, item->count>0?0xffcccccc:0x60cccccc); + minecraft.font()->draw(buffer, x, y, item->count>0?0xffcccccc:0x60cccccc); } void Gui::inventoryUpdated() { @@ -395,7 +389,7 @@ void Gui::onGraphicsReset() { } void Gui::texturesLoaded( Textures* textures ) { - //_slotFont = new Font(&minecraft->options, "gui/gui_blocks.png", textures, 0, 504, 10, 1, '0'); + //_slotFont = new Font(&minecraft.options, "gui/gui_blocks.png", textures, 0, 504, 10, 1, '0'); } void Gui::onConfigChanged( const Config& c ) { @@ -410,7 +404,7 @@ void Gui::onConfigChanged( const Config& c ) { #else const float mm = 50; //20 #endif - const float maxRadius = minecraft->pixelCalcUi.millimetersToPixels(mm); + const float maxRadius = minecraft.pixelCalcUi().millimetersToPixels(mm); const float radius = Mth::Min(80.0f/2, maxRadius); //LOGI("radius, maxradius: %f, %f\n", radius, maxRadius); const float radiusInner = radius * 0.95f; @@ -455,10 +449,12 @@ void Gui::onConfigChanged( const Config& c ) { } rcFeedbackInner = t.end(true, rcFeedbackInner.vboId); - if (c.minecraft->useTouchscreen()) { + + + if (c.minecraft.useTouchscreen()) { // I'll bump this up to 6. int num = 6; // without "..." dots - if (!c.minecraft->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) && c.width > 480) { + if (!c.minecraft.options().getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA) && c.width > 480) { while (num < Inventory::MAX_SELECTION_SIZE - 1) { int x0, x1, y; getSlotPos(0, x0, y); @@ -477,7 +473,8 @@ void Gui::onConfigChanged( const Config& c ) { } else { _numSlots = Inventory::MAX_SELECTION_SIZE; // Xperia Play } - MAX_MESSAGE_WIDTH = c.guiWidth; + + maxMessageWidth = c.guiWidth; } float Gui::floorAlignToScreenPixel(float v) { @@ -524,8 +521,8 @@ void Gui::tickItemDrop() } isCurrentlyActive = true; if ((_currentDropTicks += 1.0f) >= DropTicks) { - minecraft->player->inventory->dropSlot(slot, false); - minecraft->level->playSound(minecraft->player, "random.pop", 0.3f, 1); + minecraft.player()->inventory->dropSlot(slot, false); + minecraft.level->playSound(minecraft.player(), "random.pop", 0.3f, 1); isCurrentlyActive = false; } } @@ -552,7 +549,7 @@ void Gui::postError( int errCode ) void Gui::setScissorRect( const IntRectangle& bbox ) { GLuint x = (GLuint)(GuiScale * bbox.x); - GLuint y = minecraft->height - (GLuint)(GuiScale * (bbox.y + bbox.h)); + GLuint y = minecraft.getScreenHeight() - (GLuint)(GuiScale * (bbox.y + bbox.h)); GLuint w = (GLuint)(GuiScale * bbox.w); GLuint h = (GLuint)(GuiScale * bbox.h); glScissor(x, y, w, h); @@ -565,33 +562,33 @@ float Gui::cubeSmoothStep(float percentage, float min, float max) { } void Gui::renderProgressIndicator( const bool isTouchInterface, const int screenWidth, const int screenHeight, float a ) { - ItemInstance* currentItem = minecraft->player->inventory->getSelected(); + ItemInstance* currentItem = minecraft.player()->inventory->getSelected(); 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"); + 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); } else if(!bowEquipped) { - const float tprogress = minecraft->gameMode->destroyProgress; - const float alpha = Mth::clamp(minecraft->inputHolder->alpha, 0.0f, 1.0f); + const float tprogress = minecraft.gameMode->destroyProgress; + const float alpha = Mth::clamp(minecraft.inputHolder()->alpha, 0.0f, 1.0f); //LOGI("alpha: %f\n", alpha); - if (tprogress <= 0 && minecraft->inputHolder->alpha >= 0) { + if (tprogress <= 0 && minecraft.inputHolder()->alpha >= 0) { glDisable2(GL_TEXTURE_2D); glEnable2(GL_BLEND); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (minecraft->hitResult.isHit()) + if (minecraft.hitResult.isHit()) glColor4f2(1, 1, 1, 0.8f * alpha); else glColor4f2(1, 1, 1, Mth::Min(0.4f, alpha*0.4f)); //LOGI("alpha2: %f\n", alpha); - const float x = InvGuiScale * minecraft->inputHolder->mousex; - const float y = InvGuiScale * minecraft->inputHolder->mousey; + const float x = InvGuiScale * minecraft.inputHolder()->mousex; + const float y = InvGuiScale * minecraft.inputHolder()->mousey; glTranslatef2(x, y, 0); drawArrayVT(rcFeedbackOuter.vboId, rcFeedbackOuter.vertexCount, 24); glTranslatef2(-x, -y, 0); @@ -599,7 +596,7 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen glEnable2(GL_TEXTURE_2D); glDisable(GL_BLEND); } else if (tprogress > 0) { - const float oProgress = minecraft->gameMode->oDestroyProgress; + const float oProgress = minecraft.gameMode->oDestroyProgress; const float progress = 0.5f * (oProgress + (tprogress - oProgress) * a); //static Stopwatch w; @@ -610,8 +607,8 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen glEnable(GL_BLEND); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - const float x = InvGuiScale * minecraft->inputHolder->mousex; - const float y = InvGuiScale * minecraft->inputHolder->mousey; + const float x = InvGuiScale * minecraft.inputHolder()->mousex; + const float y = InvGuiScale * minecraft.inputHolder()->mousey; glPushMatrix2(); glTranslatef2(x, y, 0); drawArrayVT(rcFeedbackOuter.vboId, rcFeedbackOuter.vertexCount, 24); @@ -632,20 +629,20 @@ void Gui::renderProgressIndicator( const bool isTouchInterface, const int screen } void Gui::renderHearts() { - bool blink = (minecraft->player->invulnerableTime / 3) % 2 == 1; - if (minecraft->player->invulnerableTime < 10) blink = false; - int h = minecraft->player->health; - int oh = minecraft->player->lastHealth; + bool blink = (minecraft.player()->invulnerableTime / 3) % 2 == 1; + if (minecraft.player()->invulnerableTime < 10) blink = false; + int h = minecraft.player()->health; + int oh = minecraft.player()->lastHealth; random.setSeed(tickCount * 312871); - int screenWidth = (int)(minecraft->width * InvGuiScale); - int screenHeight = (int)(minecraft->height * InvGuiScale); + int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * InvGuiScale); - int xx = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenWidth / 2 - getNumSlots() * 10 - 1 : 2; + int xx = (minecraft.options().getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenWidth / 2 - getNumSlots() * 10 - 1 : 2; - int armor = minecraft->player->getArmorValue(); + int armor = minecraft.player()->getArmorValue(); for (int i = 0; i < Player::MAX_HEALTH / 2; i++) { - int yo = (minecraft->options.getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenHeight - 32 : 2; + int yo = (minecraft.options().getBooleanValue(OPTIONS_BAR_ON_TOP)) ? screenHeight - 32 : 2; int ip2 = i + i + 1; if (armor > 0) { @@ -672,14 +669,14 @@ void Gui::renderHearts() { } void Gui::renderBubbles() { - if (minecraft->player->isUnderLiquid(Material::water)) { - int screenWidth = (int)(minecraft->width * InvGuiScale); - int screenHeight = (int)(minecraft->height * InvGuiScale); + if (minecraft.player()->isUnderLiquid(Material::water)) { + int screenWidth = (int)(minecraft.getScreenWidth() * InvGuiScale); + int screenHeight = (int)(minecraft.getScreenHeight() * 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); - int extra = (int) std::ceil((minecraft->player->airSupply) * 10.0f / Player::TOTAL_AIR_SUPPLY) - count; + 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); + int extra = (int) std::ceil((minecraft.player()->airSupply) * 10.0f / Player::TOTAL_AIR_SUPPLY) - count; for (int i = 0; i < count + extra; i++) { int xo = i * 8 + xx; if (i < count) blit(xo, yo, 16, 9 * 2, 9, 9); @@ -690,7 +687,7 @@ void Gui::renderBubbles() { static OffsetPosTranslator posTranslator; void Gui::onLevelGenerated() { - if (Level* level = minecraft->level) { + if (Level* level = minecraft.level) { Pos p = level->getSharedSpawnPos(); posTranslator = OffsetPosTranslator((float)-p.x, (float)-p.y, (float)-p.z); } @@ -709,8 +706,8 @@ void Gui::renderDebugInfo() { fpsLastTime = now; } - LocalPlayer* p = minecraft->player; - Level* lvl = minecraft->level; + LocalPlayer* p = minecraft.player(); + Level* lvl = minecraft.level; // Position float px = p->x, py = p->y - p->heightOffset, pz = p->z; @@ -756,7 +753,7 @@ void Gui::renderDebugInfo() { const float LH = (float)Font::DefaultLineHeight; // 10 font-pixels const float MGN = 2.0f; // left/top margin in font-pixels const float PAD = 2.0f; // horizontal padding for background - Font* font = minecraft->font; + Font* font = minecraft.font(); // 1) Draw semi-transparent background boxes behind each line for (int i = 0; i < N; i++) { @@ -781,12 +778,12 @@ void Gui::renderDebugInfo() { t.endOverrideAndDraw(); } -void Gui::renderPlayerList(Font* font, int screenWidth, int screenHeight) { +void Gui::renderPlayerList(Font& font, int screenWidth, int screenHeight) { // only show when in game, no other screen - // if (!minecraft->level) return; + // if (!minecraft.level) return; // only show the overlay while connected to a multiplayer server - Level* level = minecraft->level; + Level* level = minecraft.level; if (!level) return; if (!level->isClientSide) return; @@ -808,7 +805,7 @@ void Gui::renderPlayerList(Font* font, int screenWidth, int screenHeight) { float maxNameWidth = 0.0f; // find the longest name so we can size the box accordingly for (const std::string& name : playerNames) { - float nameWidth = font->width(name); + float nameWidth = font.width(name); if (nameWidth > maxNameWidth) maxNameWidth = nameWidth; } @@ -817,7 +814,7 @@ void Gui::renderPlayerList(Font* font, int screenWidth, int screenHeight) { std::ostringstream titleStream; titleStream << "Players (" << playerNames.size() << ")"; std::string titleText = titleStream.str(); - float titleWidth = font->width(titleText); + float titleWidth = font.width(titleText); if (titleWidth > maxNameWidth) maxNameWidth = titleWidth; @@ -847,21 +844,21 @@ void Gui::renderPlayerList(Font* font, int screenWidth, int screenHeight) { //glScalef2(textScale, textScale, 1); // draw title - //font->draw(titleText, titleX * invTextScale, titleY * invTextScale, 0xFFFFFFFF); - font->draw(titleText, titleX, titleY, 0xFFFFFFFF); + //font.draw(titleText, titleX * invTextScale, titleY * invTextScale, 0xFFFFFFFF); + font.draw(titleText, titleX, titleY, 0xFFFFFFFF); // draw player names // we should add ping icons here eventually, but for now just show names float currentY = boxTop + padding + lineHeight; for (const std::string& name : playerNames) { - font->draw(name, (boxLeft + padding), currentY, 0xFFDDDDDD); + font.draw(name, (boxLeft + padding), currentY, 0xFFDDDDDD); currentY += lineHeight; } //glPopMatrix2(); } void Gui::renderSleepAnimation( const int screenWidth, const int screenHeight ) { - int timer = minecraft->player->getSleepTimer(); + int timer = minecraft.player()->getSleepTimer(); float amount = (float) timer / (float) Player::SLEEP_DURATION; if (amount > 1) { // waking up @@ -872,11 +869,11 @@ void Gui::renderSleepAnimation( const int screenWidth, const int screenHeight ) fill(0, 0, screenWidth, screenHeight, color); } -void Gui::renderOnSelectItemNameText( const int screenWidth, Font* font, int ySlot ) { +void Gui::renderOnSelectItemNameText( const int screenWidth, Font& font, int ySlot ) { if(itemNameOverlayTime < 1.0f) { - ItemInstance* item = minecraft->player->inventory->getSelected(); + ItemInstance* item = minecraft.player()->inventory->getSelected(); if(item != NULL) { - float x = float(screenWidth / 2 - font->width(item->getName()) / 2); + float x = float(screenWidth / 2 - font.width(item->getName()) / 2); float y = float(ySlot - 22); int alpha = 255; if(itemNameOverlayTime > 0.75) { @@ -885,7 +882,7 @@ void Gui::renderOnSelectItemNameText( const int screenWidth, Font* font, int ySl alpha = int(percentage * 255); } if(alpha != 0) - font->drawShadow(item->getName(), x, y, 0x00ffffff + (alpha << 24)); + font.drawShadow(item->getName(), x, y, 0x00ffffff + (alpha << 24)); } } } @@ -933,28 +930,28 @@ static void parseColorTags(const std::string& in, std::vector& out } } -void Gui::drawColoredString(Font* font, const std::string& text, float x, float y, int alpha) { +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); + font.drawShadow(s.text, cx, y, color); + cx += font.width(s.text); } } -float Gui::getColoredWidth(Font* font, const std::string& 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); + w += font.width(s.text); } return w; } -void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font* font ) { +void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font& font ) { // if (minecraft.screen instanceof ChatScreen) { // max = 20; // isChatting = true; @@ -991,7 +988,7 @@ void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isC const float x = 2; const float y = (float)(baseY - i * 9); std::string msg = message.message; - this->fill(x, y - 1, x + MAX_MESSAGE_WIDTH, y + 8, (alpha / 2) << 24); + this->fill(x, y - 1, x + maxMessageWidth, y + 8, (alpha / 2) << 24); glEnable(GL_BLEND); // special-case join/leave announcements @@ -1009,9 +1006,9 @@ void Gui::renderChatMessages( const int screenHeight, unsigned int max, bool isC void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) { glColor4f2(1, 1, 1, .5); - minecraft->textures->loadAndBindTexture("gui/gui.png"); + minecraft.textures().loadAndBindTexture("gui/gui.png"); - Inventory* inventory = minecraft->player->inventory; + Inventory* inventory = minecraft.player()->inventory; int xBase, yBase; getSlotPos(0, xBase, yBase); @@ -1068,7 +1065,7 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) { blit(screenWidth / 2 + 10 * getNumSlots() - 20 + 4, ySlot + 6, 242, 252, 14, 4, 14, 4); } - minecraft->textures->loadAndBindTexture("gui/gui_blocks.png"); + minecraft.textures().loadAndBindTexture("gui/gui_blocks.png"); t.endOverrideAndDraw(); // Render damaged items (@todo: investigate if it's faster by drawing in same batch) @@ -1077,7 +1074,7 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) { t.beginOverride(); x = baseItemX; for (int i = 0; i < slots; i++) { - ItemRenderer::renderGuiItemDecorations(minecraft->player->inventory->getItem(i), x, (float)ySlot); + ItemRenderer::renderGuiItemDecorations(minecraft.player()->inventory->getItem(i), x, (float)ySlot); x += 20; } t.endOverrideAndDraw(); @@ -1094,16 +1091,16 @@ void Gui::renderToolBar( float a, int ySlot, const int screenWidth ) { const float k = 0.5f * GuiScale; t.beginOverride(); - if (minecraft->gameMode->isSurvivalType()) { + if (minecraft.gameMode->isSurvivalType()) { x = baseItemX; for (int i = 0; i < slots; i++) { - ItemInstance* item = minecraft->player->inventory->getItem(i); + ItemInstance* item = minecraft.player()->inventory->getItem(i); if (item && item->count >= 0) renderSlotText(item, k*x, k*ySlot + 1, true, true); x += 20; } } - minecraft->textures->loadAndBindTexture("font/default8.png"); + minecraft.textures().loadAndBindTexture("font/default8.png"); t.endOverrideAndDraw(); glPopMatrix2(); diff --git a/src/client/gui/Gui.hpp b/src/client/gui/Gui.hpp index ca7e19b..56ddf61 100755 --- a/src/client/gui/Gui.hpp +++ b/src/client/gui/Gui.hpp @@ -45,22 +45,22 @@ public: void renderToolBar( float a, int ySlot, const int screenWidth ); - void renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font* font ); + void renderChatMessages( const int screenHeight, unsigned int max, bool isChatting, Font& font ); // draw a string containing simple [color]...[/color] tags; color names are matched // case-insensitively and default to white. alpha is applied to each segment. // draw tagged string (ignores simple [color]…[/color] tags) - static void drawColoredString(Font* font, const std::string& text, float x, float y, int alpha); - static float getColoredWidth(Font* font, const std::string& text); + static void drawColoredString(Font& font, const std::string& text, float x, float y, int alpha); + static float getColoredWidth(Font& font, const std::string& text); - void renderOnSelectItemNameText( const int screenWidth, Font* font, int ySlot ); + void renderOnSelectItemNameText( const int screenWidth, Font& font, int ySlot ); void renderSleepAnimation( const int screenWidth, const int screenHeight ); void renderBubbles(); void renderHearts(); void renderDebugInfo(); - void renderPlayerList(Font* font, int screenWidth, int screenHeight); + void renderPlayerList(Font& font, int screenWidth, int screenHeight); void renderProgressIndicator( const bool isTouchInterface, const int screenWidth, const int screenHeight, float a ); @@ -127,5 +127,7 @@ private: int _currentDropSlot = -1; bool _openInventorySlot; + + int maxMessageWidth = 240; }; diff --git a/src/client/gui/GuiComponent.cpp b/src/client/gui/GuiComponent.cpp index 1d5735d..64c01f9 100755 --- a/src/client/gui/GuiComponent.cpp +++ b/src/client/gui/GuiComponent.cpp @@ -14,14 +14,14 @@ GuiComponent::~GuiComponent() { } -void GuiComponent::drawCenteredString( Font* font, const std::string& str, int x, int y, int color ) +void GuiComponent::drawCenteredString( Font& font, const std::string& str, int x, int y, int color ) { - font->drawShadow(str, (float)(x - font->width(str) / 2), (float)(y - font->height(str) / 2), color); + font.drawShadow(str, (float)(x - font.width(str) / 2), (float)(y - font.height(str) / 2), color); } -void GuiComponent::drawString( Font* font, const std::string& str, int x, int y, int color ) +void GuiComponent::drawString( Font& font, const std::string& str, int x, int y, int color ) { - font->drawShadow(str, (float)x, (float)y /*- font->height(str)/2*/, color); + font.drawShadow(str, (float)x, (float)y /*- font.height(str)/2*/, color); } void GuiComponent::blit( int x, int y, int sx, int sy, int w, int h, int sw/*=0*/, int sh/*=0*/ ) diff --git a/src/client/gui/GuiComponent.hpp b/src/client/gui/GuiComponent.hpp index d64a572..4e83b39 100755 --- a/src/client/gui/GuiComponent.hpp +++ b/src/client/gui/GuiComponent.hpp @@ -4,7 +4,6 @@ #include class Font; -class Minecraft; class GuiComponent { @@ -12,8 +11,8 @@ public: GuiComponent(); virtual ~GuiComponent(); - void drawString(Font* font, const std::string& str, int x, int y, int color); - void drawCenteredString(Font* font, const std::string& str, int x, int y, int color); + void drawString(Font& font, const std::string& str, int x, int y, int color); + void drawCenteredString(Font& font, const std::string& str, int x, int y, int color); void blit(int x, int y, int sx, int sy, int w, int h, int sw=0, int sh=0); void blit(float x, float y, int sx, int sy, float w, float h, int sw=0, int sh=0); @@ -27,6 +26,5 @@ protected: void fillHorizontalGradient(float x0, float y0, float x1, float y1, int col1, int col2); float blitOffset; - }; diff --git a/src/client/gui/Screen.cpp b/src/client/gui/Screen.cpp index 1c5d249..91f988b 100755 --- a/src/client/gui/Screen.cpp +++ b/src/client/gui/Screen.cpp @@ -7,14 +7,15 @@ #include "platform/input/Keyboard.hpp" #include "platform/input/Mouse.hpp" #include "client/renderer/Textures.hpp" +#include -Screen::Screen() +Screen::Screen(MinecraftClient& minecraft) : passEvents(false), clickedButton(NULL), tabButtonIndex(0), width(1), height(1), - minecraft(NULL), + minecraft(minecraft), font(NULL) { } @@ -33,11 +34,10 @@ void Screen::render( int xm, int ym, float a ) } } -void Screen::init( Minecraft* minecraft, int width, int height ) +void Screen::init(int width, int height) { //particles = /*new*/ GuiParticles(minecraft); - this->minecraft = minecraft; - this->font = minecraft->font; + this->font = minecraft.font(); this->width = width; this->height = height; init(); @@ -80,8 +80,8 @@ void Screen::mouseEvent() const MouseAction& e = Mouse::getEvent(); // forward wheel events to subclasses if (e.action == MouseAction::ACTION_WHEEL) { - int xm = e.x * width / minecraft->width; - int ym = e.y * height / minecraft->height - 1; + int xm = e.x * width / minecraft.getScreenWidth(); + int ym = e.y * height / minecraft.getScreenHeight() - 1; mouseWheel(e.dx, e.dy, xm, ym); return; } @@ -90,12 +90,12 @@ void Screen::mouseEvent() return; if (Mouse::getEventButtonState()) { - int xm = e.x * width / minecraft->width; - int ym = e.y * height / minecraft->height - 1; + int xm = e.x * width / minecraft.getScreenWidth(); + int ym = e.y * height / minecraft.getScreenHeight() - 1; mouseClicked(xm, ym, Mouse::getEventButton()); } else { - int xm = e.x * width / minecraft->width; - int ym = e.y * height / minecraft->height - 1; + int xm = e.x * width / minecraft.getScreenWidth(); + int ym = e.y * height / minecraft.getScreenHeight() - 1; mouseReleased(xm, ym, Mouse::getEventButton()); } } @@ -104,7 +104,7 @@ void Screen::keyboardEvent() { if (Keyboard::getEventKeyState()) { //if (Keyboard.getEventKey() == Keyboard.KEY_F11) { - // minecraft->toggleFullScreen(); + // minecraft.toggleFullScreen(); // return; //} keyPressed(Keyboard::getEventKey()); @@ -121,7 +121,7 @@ void Screen::renderBackground() void Screen::renderBackground( int vo ) { - if (minecraft->isLevelGenerated()) { + if (minecraft.isLevelGenerated()) { fillGradient(0, 0, width, height, 0xc0101010, 0xd0101010); } else { renderDirtBackground(vo); @@ -133,7 +133,7 @@ void Screen::renderDirtBackground( int vo ) //glDisable2(GL_LIGHTING); glDisable2(GL_FOG); Tesselator& t = Tesselator::instance; - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); glColor4f2(1, 1, 1, 1); float s = 32; float fvo = (float) vo; @@ -168,8 +168,8 @@ bool Screen::closeOnPlayerHurt() { void Screen::keyPressed( int eventKey ) { if (eventKey == Keyboard::KEY_ESCAPE) { - minecraft->setScreen(NULL); - //minecraft->grabMouse(); + minecraft.setScreen(NULL); + //minecraft.grabMouse(); } // pass key events to any text boxes first @@ -178,7 +178,7 @@ void Screen::keyPressed( int eventKey ) } #ifdef TABBING - if (minecraft->useTouchscreen()) + if (minecraft.useTouchscreen()) return; @@ -187,7 +187,7 @@ void Screen::keyPressed( int eventKey ) if (!tabButtonCount) return; - Options& o = minecraft->options; + Options& o = minecraft.options; if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_NEXT)) if (++tabButtonIndex == tabButtonCount) tabButtonIndex = 0; if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_PREV)) @@ -195,7 +195,7 @@ void Screen::keyPressed( int eventKey ) if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_OK)) { Button* button = tabButtons[tabButtonIndex]; if (button->active) { - minecraft->soundEngine->playUI("random.click", 1, 1); + minecraft.soundEngine()->playUI("random.click", 1, 1); buttonClicked(button); } } @@ -213,7 +213,7 @@ void Screen::charPressed(char inputChar) { void Screen::updateTabButtonSelection() { #ifdef TABBING - if (minecraft->useTouchscreen()) + if (minecraft.useTouchscreen()) return; for (unsigned int i = 0; i < tabButtons.size(); ++i) @@ -233,8 +233,8 @@ void Screen::mouseClicked( int x, int y, int buttonNum ) //LOGI("Hit-test successful: %p\n", button); clickedButton = button; /* -#if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft->isTouchscreen()) { - minecraft->soundEngine->playUI("random.click", 1, 1); +#if !defined(ANDROID) && !defined(__APPLE__) //if (!minecraft.isTouchscreen()) { + minecraft.soundEngine()->playUI("random.click", 1, 1); buttonClicked(button); #endif } */ @@ -254,12 +254,12 @@ void Screen::mouseReleased( int x, int y, int buttonNum ) if (!clickedButton || buttonNum != MouseAction::ACTION_LEFT) return; #if 1 -//#if defined(ANDROID) || defined(__APPLE__) //if (minecraft->isTouchscreen()) { +//#if defined(ANDROID) || defined(__APPLE__) //if (minecraft.isTouchscreen()) { for (unsigned int i = 0; i < buttons.size(); ++i) { Button* button = buttons[i]; if (clickedButton == button && button->clicked(minecraft, x, y)) { buttonClicked(button); - minecraft->soundEngine->playUI("random.click", 1, 1); + minecraft.soundEngine()->playUI("random.click", 1, 1); clickedButton->released(x, y); } } @@ -279,13 +279,13 @@ bool Screen::hasClippingArea( IntRectangle& out ) } void Screen::lostFocus() { - for(std::vector::iterator it = textBoxes.begin(); it != textBoxes.end(); ++it) { + for(auto it = textBoxes.begin(); it != textBoxes.end(); ++it) { TextBox* tb = *it; tb->loseFocus(minecraft); } } void Screen::toGUICoordinate( int& x, int& y ) { - x = x * width / minecraft->width; - y = y * height / minecraft->height - 1; + x = x * width / minecraft.getScreenWidth(); + y = y * height / minecraft.getScreenHeight() - 1; } diff --git a/src/client/gui/Screen.hpp b/src/client/gui/Screen.hpp index bd6053b..f925942 100755 --- a/src/client/gui/Screen.hpp +++ b/src/client/gui/Screen.hpp @@ -6,7 +6,7 @@ #include "GuiComponent.hpp" class Font; -class Minecraft; +class MinecraftClient; class Button; class TextBox; struct IntRectangle; @@ -14,11 +14,11 @@ struct IntRectangle; class Screen: public GuiComponent { public: - Screen(); + Screen(MinecraftClient& minecraft); virtual void render(int xm, int ym, float a); - void init(Minecraft* minecraft, int width, int height); + void init(int width, int height); virtual void init(); void setSize(int width, int height); @@ -67,7 +67,7 @@ public: bool passEvents; //GuiParticles* particles; protected: - Minecraft* minecraft; + MinecraftClient& minecraft; std::vector buttons; std::vector textBoxes; diff --git a/src/client/gui/components/Button.cpp b/src/client/gui/components/Button.cpp index a93962c..daab5ba 100755 --- a/src/client/gui/components/Button.cpp +++ b/src/client/gui/components/Button.cpp @@ -1,5 +1,6 @@ #include "Button.hpp" -#include "client/Minecraft.hpp" +#include +#include #include "client/renderer/Textures.hpp" Button::Button(int id, const std::string& msg) @@ -29,12 +30,12 @@ Button::Button( int id, int x, int y, int w, int h, const std::string& msg ) { } -void Button::render( Minecraft* minecraft, int xm, int ym ) +void Button::render( MinecraftClient& minecraft, int xm, int ym ) { if (!visible) return; /* - minecraft->textures->loadAndBindTexture("gui/gui.png"); + minecraft.textures().loadAndBindTexture("gui/gui.png"); glColor4f2(1, 1, 1, 1); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); @@ -52,7 +53,7 @@ void Button::released( int mx, int my ) { _currentlyDown = false; } -bool Button::clicked( Minecraft* minecraft, int mx, int my ) +bool Button::clicked( MinecraftClient& minecraft, int mx, int my ) { return active && mx >= x && my >= y && mx < x + width && my < y + height; } @@ -69,22 +70,27 @@ int Button::getYImage( bool hovered ) return res; } -void Button::renderFace(Minecraft* mc, int xm, int ym) { - Font* font = mc->font; +void Button::renderFace(MinecraftClient& mc, int xm, int ym) { + Font* font = mc.font(); + + if (font == nullptr) { + return; + } + if (!active) { - drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0); + drawCenteredString(*font, msg, x + width / 2, y + (height - 8) / 2, 0xffa0a0a0); } else { if (hovered(mc, xm, ym) || selected) { - drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0); + drawCenteredString(*font, msg, x + width / 2, y + (height - 8) / 2, 0xffffa0); } else { - drawCenteredString(font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0); + drawCenteredString(*font, msg, x + width / 2, y + (height - 8) / 2, 0xe0e0e0); } } } -void Button::renderBg( Minecraft* minecraft, int xm, int ym ) +void Button::renderBg( MinecraftClient& minecraft, int xm, int ym ) { - minecraft->textures->loadAndBindTexture("gui/gui.png"); + minecraft.textures().loadAndBindTexture("gui/gui.png"); glColor4f2(1, 1, 1, 1); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); @@ -94,8 +100,8 @@ void Button::renderBg( Minecraft* minecraft, int xm, int ym ) blit(x + width / 2, y, 200 - width / 2, 46 + yImage * 20, width / 2, height, 0, 20); } -bool Button::hovered(Minecraft* minecraft, int xm , int ym) { - return minecraft->useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym); +bool Button::hovered(MinecraftClient& minecraft, int xm , int ym) { + return minecraft.useTouchscreen()? (_currentlyDown && isInside(xm, ym)) : isInside(xm, ym); } bool Button::isInside( int xm, int ym ) { @@ -141,12 +147,12 @@ TButton::TButton( int id, int x, int y, int w, int h, const std::string& msg ) { } -void TButton::renderBg( Minecraft* minecraft, int xm, int ym ) +void TButton::renderBg( MinecraftClient& minecraft, int xm, int ym ) { - bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); + bool hovered = active && (minecraft.useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); // bool hovered = active && (_currentlyDown && isInside(xm, ym)); - minecraft->textures->loadAndBindTexture("gui/touchgui.png"); + minecraft.textures().loadAndBindTexture("gui/touchgui.png"); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); if (active) @@ -187,19 +193,22 @@ THeader::THeader( int id, int x, int y, int w, int h, const std::string& msg ) active = false; } -void THeader::render( Minecraft* minecraft, int xm, int ym ) { - Font* font = minecraft->font; +void THeader::render( MinecraftClient& minecraft, int xm, int ym ) { + Font* font = minecraft.font(); renderBg(minecraft, xm, ym); int xx = x + width/2; if (xText != -99999) xx = xText; - drawCenteredString(font, msg, xx, y + (height - 8) / 2, 0xe0e0e0); + + if (font != nullptr) { + drawCenteredString(*font, msg, xx, y + (height - 8) / 2, 0xe0e0e0); + } } -void THeader::renderBg( Minecraft* minecraft, int xm, int ym ) +void THeader::renderBg( MinecraftClient& minecraft, int xm, int ym ) { - minecraft->textures->loadAndBindTexture("gui/touchgui.png"); + minecraft.textures().loadAndBindTexture("gui/touchgui.png"); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); glColor4f2(1, 1, 1, 1); diff --git a/src/client/gui/components/Button.hpp b/src/client/gui/components/Button.hpp index 3354969..100bff7 100755 --- a/src/client/gui/components/Button.hpp +++ b/src/client/gui/components/Button.hpp @@ -7,7 +7,7 @@ #include "client/Options.hpp" class Font; -class Minecraft; +class MinecraftClient; class Button: public GuiElement { @@ -16,19 +16,19 @@ public: Button(int id, int x, int y, const std::string& msg); Button(int id, int x, int y, int w, int h, const std::string& msg); virtual ~Button() {} - virtual void render(Minecraft* minecraft, int xm, int ym); + virtual void render(MinecraftClient& minecraft, int xm, int ym); - virtual bool clicked(Minecraft* minecraft, int mx, int my); + virtual bool clicked(MinecraftClient& minecraft, int mx, int my); virtual void released(int mx, int my); virtual void setPressed(); bool isInside(int xm, int ym); protected: virtual int getYImage(bool hovered); - virtual void renderBg(Minecraft* minecraft, int xm, int ym); + virtual void renderBg(MinecraftClient& minecraft, int xm, int ym); - virtual void renderFace(Minecraft* minecraft, int xm, int ym); - bool hovered(Minecraft* minecraft, int xm, int ym); + virtual void renderFace(MinecraftClient& minecraft, int xm, int ym); + bool hovered(MinecraftClient& minecraft, int xm, int ym); public: std::string msg; int id; @@ -58,7 +58,7 @@ public: TButton(int id, int x, int y, const std::string& msg); TButton(int id, int x, int y, int w, int h, const std::string& msg); protected: - virtual void renderBg(Minecraft* minecraft, int xm, int ym); + virtual void renderBg(MinecraftClient& minecraft, int xm, int ym); }; // "Header" in Touchscreen mode @@ -69,8 +69,8 @@ public: THeader(int id, int x, int y, const std::string& msg); THeader(int id, int x, int y, int w, int h, const std::string& msg); protected: - virtual void renderBg(Minecraft* minecraft, int xm, int ym); - void render( Minecraft* minecraft, int xm, int ym ); + virtual void renderBg(MinecraftClient& minecraft, int xm, int ym); + void render( MinecraftClient& minecraft, int xm, int ym ); public: int xText; }; diff --git a/src/client/gui/components/GButton.hpp b/src/client/gui/components/GButton.hpp index f625e92..2f9a6b9 100755 --- a/src/client/gui/components/GButton.hpp +++ b/src/client/gui/components/GButton.hpp @@ -25,11 +25,11 @@ public: layers.push_back(std::make_pair(e, layerId)); } - void render( Minecraft* minecraft, int xm, int ym ) + void render( MinecraftClient& minecraft, int xm, int ym ) { if (!visible) return; - bool isHovered = minecraft->isTouchscreen()? + bool isHovered = minecraft.isTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height): false; int layer = isHovered? LayerSelected : LayerDefault; diff --git a/src/client/gui/components/GuiElement.hpp b/src/client/gui/components/GuiElement.hpp index 221aeba..7e20285 100755 --- a/src/client/gui/components/GuiElement.hpp +++ b/src/client/gui/components/GuiElement.hpp @@ -2,21 +2,21 @@ #include "client/gui/GuiComponent.hpp" class Tesselator; -class Minecraft; +class MinecraftClient; class GuiElement : public GuiComponent { public: GuiElement(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24); virtual ~GuiElement() {} - virtual void tick(Minecraft* minecraft) {} - virtual void render(Minecraft* minecraft, int xm, int ym) { } + virtual void tick(MinecraftClient& minecraft) {} + virtual void render(MinecraftClient& minecraft, int xm, int ym) { } virtual void setupPositions() {} - virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) {} - virtual void mouseReleased(Minecraft* minecraft, int x, int y, int buttonNum) {} - virtual void keyPressed(Minecraft* minecraft, int key) {} - virtual void charPressed(Minecraft* minecraft, char key) {} + virtual void mouseClicked(MinecraftClient& minecraft, int x, int y, int buttonNum) {} + virtual void mouseReleased(MinecraftClient& minecraft, int x, int y, int buttonNum) {} + virtual void keyPressed(MinecraftClient& minecraft, int key) {} + virtual void charPressed(MinecraftClient& minecraft, char key) {} virtual bool pointInside(int x, int y); diff --git a/src/client/gui/components/GuiElementContainer.cpp b/src/client/gui/components/GuiElementContainer.cpp index 795680e..9caaef8 100755 --- a/src/client/gui/components/GuiElementContainer.cpp +++ b/src/client/gui/components/GuiElementContainer.cpp @@ -13,14 +13,14 @@ GuiElementContainer::~GuiElementContainer() { } } -void GuiElementContainer::render( Minecraft* minecraft, int xm, int ym ) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::render( MinecraftClient& minecraft, int xm, int ym ) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->render(minecraft, xm, ym); } } void GuiElementContainer::setupPositions() { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->setupPositions(); } } @@ -30,37 +30,37 @@ void GuiElementContainer::addChild( GuiElement* element ) { } void GuiElementContainer::removeChild( GuiElement* element ) { - std::vector::iterator it = std::find(children.begin(), children.end(), element); + auto it = std::find(children.begin(), children.end(), element); if(it != children.end()) children.erase(it); } -void GuiElementContainer::tick( Minecraft* minecraft ) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::tick( MinecraftClient& minecraft ) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->tick(minecraft); } } -void GuiElementContainer::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->mouseClicked(minecraft, x, y, buttonNum); } } -void GuiElementContainer::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->mouseReleased(minecraft, x, y, buttonNum); } } -void GuiElementContainer::keyPressed(Minecraft* minecraft, int key) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::keyPressed(MinecraftClient& minecraft, int key) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->keyPressed(minecraft, key); } } -void GuiElementContainer::charPressed(Minecraft* minecraft, char key) { - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { +void GuiElementContainer::charPressed(MinecraftClient& minecraft, char key) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->charPressed(minecraft, key); } } \ No newline at end of file diff --git a/src/client/gui/components/GuiElementContainer.hpp b/src/client/gui/components/GuiElementContainer.hpp index bbe9c7f..2dcb91f 100755 --- a/src/client/gui/components/GuiElementContainer.hpp +++ b/src/client/gui/components/GuiElementContainer.hpp @@ -2,23 +2,23 @@ #include "GuiElement.hpp" #include class Tesselator; -class Minecraft; +class MinecraftClient; class GuiElementContainer : public GuiElement { public: GuiElementContainer(bool active=false, bool visible=true, int x = 0, int y = 0, int width=24, int height=24); virtual ~GuiElementContainer(); - virtual void render(Minecraft* minecraft, int xm, int ym); + virtual void render(MinecraftClient& minecraft, int xm, int ym); virtual void setupPositions(); virtual void addChild(GuiElement* element); virtual void removeChild(GuiElement* element); - virtual void tick( Minecraft* minecraft ); + virtual void tick( MinecraftClient& minecraft ); - virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void keyPressed(Minecraft* minecraft, int key); - virtual void charPressed(Minecraft* minecraft, char key); + virtual void mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ); + virtual void mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ); + virtual void keyPressed(MinecraftClient& minecraft, int key); + virtual void charPressed(MinecraftClient& minecraft, char key); protected: std::vector children; diff --git a/src/client/gui/components/ImageButton.cpp b/src/client/gui/components/ImageButton.cpp index 586ea72..6d270a1 100755 --- a/src/client/gui/components/ImageButton.cpp +++ b/src/client/gui/components/ImageButton.cpp @@ -1,6 +1,6 @@ #include "ImageButton.hpp" #include "client/renderer/Tesselator.hpp" -#include "client/Minecraft.hpp" +#include #include "platform/log.hpp" #include "util/Mth.hpp" #include "client/renderer/Textures.hpp" @@ -34,15 +34,15 @@ void ImageButton::setImageDef(const ImageDef& imageDef, bool setButtonSize) { } } -void ImageButton::render(Minecraft* minecraft, int xm, int ym) { +void ImageButton::render(MinecraftClient& minecraft, int xm, int ym) { if (!visible) return; - Font* font = minecraft->font; + Font* font = minecraft.font(); - //minecraft->textures->loadAndBindTexture("gui/gui.png"); + //minecraft.textures().loadAndBindTexture("gui/gui.png"); glColor4f2(1, 1, 1, 1); - bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); + bool hovered = active && (minecraft.useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); bool IsSecondImage = isSecondImage(hovered); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); @@ -53,7 +53,7 @@ void ImageButton::render(Minecraft* minecraft, int xm, int ym) { renderBg(minecraft, xm, ym); - TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId; + TextureId texId = (_imageDef.name.length() > 0)? minecraft.textures().loadAndBindTexture(_imageDef.name) : Textures::InvalidId; if ( Textures::isTextureIdValid(texId) ) { const ImageDef& d = _imageDef; Tesselator& t = Tesselator::instance; @@ -75,7 +75,7 @@ void ImageButton::render(Minecraft* minecraft, int xm, int ym) { const IntRectangle* src = _imageDef.getSrc(); if (src) { - const TextureData* d = minecraft->textures->getTemporaryTextureData(texId); + const TextureData* d = minecraft.textures().getTemporaryTextureData(texId); if (d != NULL) { float u0 = (src->x+(IsSecondImage?src->w:0)) / (float)d->w; float u1 = (src->x+(IsSecondImage?2*src->w:src->w)) / (float)d->w; @@ -126,10 +126,10 @@ void OptionButton::updateImage(Options* options) { _secondImage = options->getBooleanValue(m_optId); } -void OptionButton::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { +void OptionButton::mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ) { if(buttonNum == MouseAction::ACTION_LEFT) { if(clicked(minecraft, x, y)) { - toggle(&minecraft->options); + toggle(&minecraft.options); } } } diff --git a/src/client/gui/components/ImageButton.hpp b/src/client/gui/components/ImageButton.hpp index 5782ba6..655fc5f 100755 --- a/src/client/gui/components/ImageButton.hpp +++ b/src/client/gui/components/ImageButton.hpp @@ -57,8 +57,8 @@ public: ImageButton(int id, const std::string& msg, const ImageDef& imageDef); void setImageDef(const ImageDef& imageDef, bool setButtonSize); - void render(Minecraft* minecraft, int xm, int ym); - void renderBg(Minecraft* minecraft, int xm, int ym) {} + void render(MinecraftClient& minecraft, int xm, int ym); + void renderBg(MinecraftClient& minecraft, int xm, int ym) {} protected: virtual void setupDefault(); @@ -85,7 +85,7 @@ public: protected: bool isSecondImage(bool hovered) { return _secondImage; } - virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); + virtual void mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ); private: OptionId m_optId; diff --git a/src/client/gui/components/InventoryPane.cpp b/src/client/gui/components/InventoryPane.cpp index a120173..6c5c2f8 100755 --- a/src/client/gui/components/InventoryPane.cpp +++ b/src/client/gui/components/InventoryPane.cpp @@ -1,6 +1,6 @@ #include "InventoryPane.hpp" #include "client/gui/Gui.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/input/touchscreen/TouchAreaModel.hpp" #include "client/renderer/entity/ItemRenderer.hpp" #include "client/renderer/Tesselator.hpp" @@ -12,7 +12,7 @@ namespace Touch { static const int By = 6; // Border Frame height -InventoryPane::InventoryPane( IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize) +InventoryPane::InventoryPane( IInventoryPaneCallback* screen, MinecraftClient& mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize) : screen(screen), mc(mc), paneWidth(paneWidth), @@ -62,7 +62,7 @@ void InventoryPane::renderBatch( std::vector& items, float alpha ) glEnable2(GL_SCISSOR_TEST); GLuint x = (GLuint)(screenScale * bbox.x); - GLuint y = mc->height - (GLuint)(screenScale * (bbox.y + bbox.h)); + GLuint y = mc.getScreenHeight() - (GLuint)(screenScale * (bbox.y + bbox.h)); GLuint w = (GLuint)(screenScale * bbox.w); GLuint h = (GLuint)(screenScale * bbox.h); glScissor(x, y, w, h); @@ -75,7 +75,7 @@ void InventoryPane::renderBatch( std::vector& items, float alpha ) GridItem& item = items[i]; blit(item.xf, item.yf, 200, 46, (float)itemBbox.w, (float)itemBbox.h, 16, 16); } - mc->textures->loadAndBindTexture("gui/gui.png"); + mc.textures().loadAndBindTexture("gui/gui.png"); t.endOverrideAndDraw(); GridItem* marked = NULL; @@ -104,7 +104,7 @@ void InventoryPane::renderBatch( std::vector& items, float alpha ) t.noColor(); float xx = Gui::floorAlignToScreenPixel(item.xf + BorderPixels + 4); float yy = Gui::floorAlignToScreenPixel(item.yf + BorderPixels + 4); - ItemRenderer::renderGuiItem(NULL, mc->textures, citem, xx, yy, 16, 16, false); + ItemRenderer::renderGuiItem(NULL, mc.textures(), citem, xx, yy, 16, 16, false); if (j == markerIndex && markerShare >= 0) marked = &item, mxx = xx, myy = yy; @@ -123,7 +123,7 @@ void InventoryPane::renderBatch( std::vector& items, float alpha ) } - if (!mc->isCreativeMode()) { + if (!mc.isCreativeMode()) { const float ikText = Gui::InvGuiScale + Gui::InvGuiScale; const float kText = 0.5f * Gui::GuiScale; t.beginOverride(); @@ -138,7 +138,7 @@ void InventoryPane::renderBatch( std::vector& items, float alpha ) float tx = Gui::floorAlignToScreenPixel(kText * (item.xf + BorderPixels + 3)); float ty = Gui::floorAlignToScreenPixel(kText * (item.yf + BorderPixels + 3)); - mc->gui.renderSlotText(citem, tx, ty, true, true); + mc.gui().renderSlotText(citem, tx, ty, true, true); } t.resetScale(); glEnable2(GL_BLEND); diff --git a/src/client/gui/components/InventoryPane.hpp b/src/client/gui/components/InventoryPane.hpp index e6955f5..a4ef3d5 100755 --- a/src/client/gui/components/InventoryPane.hpp +++ b/src/client/gui/components/InventoryPane.hpp @@ -3,7 +3,7 @@ #include "ScrollingPane.hpp" #include "ImageButton.hpp" -class Minecraft; +class MinecraftClient; class ItemInstance; class Font; class IArea; @@ -16,7 +16,7 @@ class InventoryPane: public ScrollingPane { typedef ScrollingPane super; public: - InventoryPane(IInventoryPaneCallback* screen, Minecraft* mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize); + InventoryPane(IInventoryPaneCallback* screen, MinecraftClient& mc, const IntRectangle& rect, int paneWidth, float clickMarginH, int numItems, int itemSize, int itemBorderSize); ~InventoryPane(); void tick(); @@ -30,7 +30,7 @@ public: int paneWidth; IArea* _clickArea; IInventoryPaneCallback* screen; - Minecraft* mc; + MinecraftClient& mc; int fillMarginX; int fillMarginY; diff --git a/src/client/gui/components/KeyOption.cpp b/src/client/gui/components/KeyOption.cpp index 70dc61a..d860822 100644 --- a/src/client/gui/components/KeyOption.cpp +++ b/src/client/gui/components/KeyOption.cpp @@ -1,22 +1,22 @@ #include "KeyOption.hpp" -#include +#include -KeyOption::KeyOption(Minecraft* minecraft, OptionId optId) - : Touch::TButton((int)optId, Keyboard::getKeyName(minecraft->options.getIntValue(optId))) {} +KeyOption::KeyOption(MinecraftClient& minecraft, OptionId optId) + : Touch::TButton((int)optId, Keyboard::getKeyName(minecraft.options().getIntValue(optId))) {} -void KeyOption::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { +void KeyOption::mouseClicked(MinecraftClient& minecraft, int x, int y, int buttonNum) { selected = isInside(x, y); - msg = (selected)? "..." : Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id)); + msg = (selected)? "..." : Keyboard::getKeyName(minecraft.options().getIntValue((OptionId)id)); } -void KeyOption::keyPressed(Minecraft* minecraft, int key) { +void KeyOption::keyPressed(MinecraftClient& minecraft, int key) { if (!selected) return; if (key != Keyboard::KEY_ESCAPE) { - minecraft->options.set((OptionId)id, key); + minecraft.options().set((OptionId)id, key); } selected = false; - msg = Keyboard::getKeyName(minecraft->options.getIntValue((OptionId)id)); + msg = Keyboard::getKeyName(minecraft.options().getIntValue((OptionId)id)); } \ No newline at end of file diff --git a/src/client/gui/components/KeyOption.hpp b/src/client/gui/components/KeyOption.hpp index 71a64cd..b8661be 100644 --- a/src/client/gui/components/KeyOption.hpp +++ b/src/client/gui/components/KeyOption.hpp @@ -4,11 +4,11 @@ class KeyOption : public Touch::TButton { public: - KeyOption(Minecraft* minecraft, OptionId optId); + KeyOption(MinecraftClient& minecraft, OptionId optId); - virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum); + virtual void mouseClicked(MinecraftClient& minecraft, int x, int y, int buttonNum); virtual void released(int mx, int my) {} - virtual void keyPressed(Minecraft* minecraft, int key); + virtual void keyPressed(MinecraftClient& minecraft, int key); protected: bool m_captureMode; }; \ No newline at end of file diff --git a/src/client/gui/components/LargeImageButton.cpp b/src/client/gui/components/LargeImageButton.cpp index 070781e..98223e3 100755 --- a/src/client/gui/components/LargeImageButton.cpp +++ b/src/client/gui/components/LargeImageButton.cpp @@ -1,6 +1,6 @@ #include "LargeImageButton.hpp" #include "client/renderer/Tesselator.hpp" -#include "client/Minecraft.hpp" +#include #include "util/Mth.hpp" #include "platform/log.hpp" #include "util/Mth.hpp" @@ -26,14 +26,14 @@ void LargeImageButton::setupDefault() { height = 72; } -void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) { +void LargeImageButton::render(MinecraftClient& minecraft, int xm, int ym) { if (!visible) return; - Font* font = minecraft->font; + Font* font = minecraft.font(); - //minecraft->textures->loadAndBindTexture("gui/gui.png"); + //minecraft.textures().loadAndBindTexture("gui/gui.png"); glColor4f2(1, 1, 1, 1); - bool hovered = active && (minecraft->useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); + bool hovered = active && (minecraft.useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); //printf("ButtonId: %d - Hovered? %d (cause: %d, %d, %d, %d, <> %d, %d)\n", id, hovered, x, y, x+w, y+h, xm, ym); //int yImage = getYImage(hovered || selected); @@ -43,7 +43,7 @@ void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) { renderBg(minecraft, xm, ym); - TextureId texId = (_imageDef.name.length() > 0)? minecraft->textures->loadAndBindTexture(_imageDef.name) : Textures::InvalidId; + TextureId texId = (_imageDef.name.length() > 0)? minecraft.textures().loadAndBindTexture(_imageDef.name) : Textures::InvalidId; if ( Textures::isTextureIdValid(texId) ) { const ImageDef& d = _imageDef; Tesselator& t = Tesselator::instance; @@ -69,7 +69,7 @@ void LargeImageButton::render(Minecraft* minecraft, int xm, int ym) { const IntRectangle* src = _imageDef.getSrc(); if (src) { - const TextureData* d = minecraft->textures->getTemporaryTextureData(texId); + const TextureData* d = minecraft.textures().getTemporaryTextureData(texId); if (d != NULL) { float u0 = (src->x+(hovered?src->w:0)) / (float)d->w; float u1 = (src->x+(hovered?2*src->w:src->w)) / (float)d->w; diff --git a/src/client/gui/components/LargeImageButton.hpp b/src/client/gui/components/LargeImageButton.hpp index 0c2f42d..fa9220b 100755 --- a/src/client/gui/components/LargeImageButton.hpp +++ b/src/client/gui/components/LargeImageButton.hpp @@ -9,7 +9,7 @@ public: LargeImageButton(int id, const std::string& msg); LargeImageButton(int id, const std::string& msg, ImageDef& imageDef); - void render(Minecraft* minecraft, int xm, int ym); + void render(MinecraftClient& minecraft, int xm, int ym); private: void setupDefault(); diff --git a/src/client/gui/components/NinePatch.cpp b/src/client/gui/components/NinePatch.cpp index 2cd757a..1c5df00 100755 --- a/src/client/gui/components/NinePatch.cpp +++ b/src/client/gui/components/NinePatch.cpp @@ -36,7 +36,7 @@ NinePatchDescription NinePatchDescription::createSymmetrical( int texWidth, int return patch; } -NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w, float h) +NinePatchLayer::NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures& textures, float w, float h) : desc(desc), imageName(imageName), textures(textures), diff --git a/src/client/gui/components/NinePatch.hpp b/src/client/gui/components/NinePatch.hpp index 98663b9..728671e 100755 --- a/src/client/gui/components/NinePatch.hpp +++ b/src/client/gui/components/NinePatch.hpp @@ -4,7 +4,6 @@ #include "client/renderer/TextureData.hpp" #include "client/renderer/Textures.hpp" #include "client/renderer/Tesselator.hpp" -#include "client/Minecraft.hpp" class Tesselator; @@ -30,7 +29,7 @@ class NinePatchLayer: public GuiElement { struct CachedQuad; public: - NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures* textures, float w = 32, float h = 32); + NinePatchLayer(const NinePatchDescription& desc, const std::string& imageName, Textures& textures, float w = 32, float h = 32); virtual ~NinePatchLayer() {}; void setSize(float w, float h); @@ -63,12 +62,12 @@ private: class NinePatchFactory { public: - NinePatchFactory(Textures* textures, const std::string& imageName ); + NinePatchFactory(Textures& textures, const std::string& imageName ); NinePatchLayer* createSymmetrical(const IntRectangle& src, int xCutAt, int yCutAt, float w = 32.0f, float h = 32.0f); private: - Textures* textures; + Textures& textures; std::string imageName; int width; int height; diff --git a/src/client/gui/components/OptionsGroup.cpp b/src/client/gui/components/OptionsGroup.cpp index f762fe4..946d99f 100755 --- a/src/client/gui/components/OptionsGroup.cpp +++ b/src/client/gui/components/OptionsGroup.cpp @@ -1,5 +1,5 @@ #include "OptionsGroup.hpp" -#include "client/Minecraft.hpp" +#include #include "ImageButton.hpp" #include "OptionsItem.hpp" #include "Slider.hpp" @@ -14,7 +14,7 @@ OptionsGroup::OptionsGroup( std::string labelID ) { void OptionsGroup::setupPositions() { // First we write the header and then we add the items int curY = y + 18; - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->width = width - 5; (*it)->y = curY; @@ -25,17 +25,17 @@ void OptionsGroup::setupPositions() { height = curY; } -void OptionsGroup::render( Minecraft* minecraft, int xm, int ym ) { +void OptionsGroup::render( MinecraftClient& minecraft, int xm, int ym ) { float padX = 10.0f; float padY = 5.0f; - minecraft->font->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false); + minecraft.font()->draw(label, (float)x + padX, (float)y + padY, 0xffffffff, false); super::render(minecraft, xm, ym); } -OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) { - auto option = minecraft->options.getOpt(optId); +OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, MinecraftClient& minecraft ) { + auto option = minecraft.options().getOpt(optId); if (option == nullptr) return *this; @@ -51,7 +51,7 @@ OptionsGroup& OptionsGroup::addOptionItem(OptionId optId, Minecraft* minecraft ) // TODO: wrap this copypaste shit into templates -void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) { +void OptionsGroup::createToggle(OptionId optId, MinecraftClient& minecraft ) { ImageDef def; def.setSrc(IntRectangle(160, 206, 39, 20)); @@ -61,9 +61,9 @@ void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) { OptionButton* element = new OptionButton(optId); element->setImageDef(def, true); - element->updateImage(&minecraft->options); + element->updateImage(&minecraft.options); - std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + std::string itemLabel = I18n::get(minecraft.options().getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(optId, itemLabel, element); @@ -71,44 +71,44 @@ void OptionsGroup::createToggle(OptionId optId, Minecraft* minecraft ) { setupPositions(); } -void OptionsGroup::createProgressSlider(OptionId optId, Minecraft* minecraft ) { +void OptionsGroup::createProgressSlider(OptionId optId, MinecraftClient& minecraft ) { Slider* element = new SliderFloat(minecraft, optId); element->width = 100; element->height = 20; - std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + std::string itemLabel = I18n::get(minecraft.options().getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(optId, itemLabel, element); addChild(item); setupPositions(); } -void OptionsGroup::createStepSlider(OptionId optId, Minecraft* minecraft ) { +void OptionsGroup::createStepSlider(OptionId optId, MinecraftClient& minecraft ) { Slider* element = new SliderInt(minecraft, optId); element->width = 100; element->height = 20; - std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + std::string itemLabel = I18n::get(minecraft.options().getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(optId, itemLabel, element); addChild(item); setupPositions(); } -void OptionsGroup::createTextbox(OptionId optId, Minecraft* minecraft) { +void OptionsGroup::createTextbox(OptionId optId, MinecraftClient& minecraft) { TextBox* element = new TextOption(minecraft, optId); element->width = 100; element->height = 20; - std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + std::string itemLabel = I18n::get(minecraft.options().getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(optId, itemLabel, element); addChild(item); setupPositions(); } -void OptionsGroup::createKey(OptionId optId, Minecraft* minecraft) { +void OptionsGroup::createKey(OptionId optId, MinecraftClient& minecraft) { KeyOption* element = new KeyOption(minecraft, optId); element->width = 50; element->height = 20; - std::string itemLabel = I18n::get(minecraft->options.getOpt(optId)->getStringId()); + std::string itemLabel = I18n::get(minecraft.options().getOpt(optId)->getStringId()); OptionsItem* item = new OptionsItem(optId, itemLabel, element); addChild(item); setupPositions(); diff --git a/src/client/gui/components/OptionsGroup.hpp b/src/client/gui/components/OptionsGroup.hpp index 8f05ba0..11eddad 100755 --- a/src/client/gui/components/OptionsGroup.hpp +++ b/src/client/gui/components/OptionsGroup.hpp @@ -8,22 +8,22 @@ #include "client/Options.hpp" class Font; -class Minecraft; +class MinecraftClient; class OptionsGroup: public GuiElementContainer { typedef GuiElementContainer super; public: OptionsGroup(std::string labelID); virtual void setupPositions(); - virtual void render(Minecraft* minecraft, int xm, int ym); - OptionsGroup& addOptionItem(OptionId optId, Minecraft* minecraft); + virtual void render(MinecraftClient& minecraft, int xm, int ym); + OptionsGroup& addOptionItem(OptionId optId, MinecraftClient& minecraft); protected: - void createToggle(OptionId optId, Minecraft* minecraft); - void createProgressSlider(OptionId optId, Minecraft* minecraft); - void createStepSlider(OptionId optId, Minecraft* minecraft); - void createTextbox(OptionId optId, Minecraft* minecraft); - void createKey(OptionId optId, Minecraft* minecraft); + void createToggle(OptionId optId, MinecraftClient& minecraft); + void createProgressSlider(OptionId optId, MinecraftClient& minecraft); + void createStepSlider(OptionId optId, MinecraftClient& minecraft); + void createTextbox(OptionId optId, MinecraftClient& minecraft); + void createKey(OptionId optId, MinecraftClient& minecraft); std::string label; }; diff --git a/src/client/gui/components/OptionsItem.cpp b/src/client/gui/components/OptionsItem.cpp index 6c17822..dec8fce 100755 --- a/src/client/gui/components/OptionsItem.cpp +++ b/src/client/gui/components/OptionsItem.cpp @@ -1,5 +1,5 @@ #include "OptionsItem.hpp" -#include "client/Minecraft.hpp" +#include #include "locale/I18n.hpp" #include "util/Mth.hpp" OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* element ) @@ -11,7 +11,7 @@ OptionsItem::OptionsItem( OptionId optionId, std::string label, GuiElement* elem void OptionsItem::setupPositions() { int currentHeight = 0; - for(std::vector::iterator it = children.begin(); it != children.end(); ++it) { + for(auto it = children.begin(); it != children.end(); ++it) { (*it)->x = x + width - (*it)->width - 15; (*it)->y = y + currentHeight; currentHeight += (*it)->height; @@ -19,11 +19,11 @@ void OptionsItem::setupPositions() { height = currentHeight; } -void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) { +void OptionsItem::render( MinecraftClient& minecraft, int xm, int ym ) { int yOffset = (height - 8) / 2; std::string text = m_label; if (m_optionId == OPTIONS_GUI_SCALE) { - int value = minecraft->options.getIntValue(OPTIONS_GUI_SCALE); + int value = minecraft.options().getIntValue(OPTIONS_GUI_SCALE); std::string scaleText; switch (value) { case 0: scaleText = I18n::get("options.guiScale.auto"); break; @@ -37,6 +37,6 @@ void OptionsItem::render( Minecraft* minecraft, int xm, int ym ) { text += ": " + scaleText; } - minecraft->font->draw(text, (float)x, (float)y + yOffset, 0x909090, false); + minecraft.font()->draw(text, (float)x, (float)y + yOffset, 0x909090, false); super::render(minecraft, xm, ym); } \ No newline at end of file diff --git a/src/client/gui/components/OptionsItem.hpp b/src/client/gui/components/OptionsItem.hpp index e2374c0..76c1123 100755 --- a/src/client/gui/components/OptionsItem.hpp +++ b/src/client/gui/components/OptionsItem.hpp @@ -15,7 +15,7 @@ class OptionsItem: public GuiElementContainer typedef GuiElementContainer super; public: OptionsItem(OptionId optionId, std::string label, GuiElement* element); - virtual void render(Minecraft* minecraft, int xm, int ym); + virtual void render(MinecraftClient& minecraft, int xm, int ym); void setupPositions(); private: diff --git a/src/client/gui/components/RolledSelectionListV.cpp b/src/client/gui/components/RolledSelectionListV.cpp index 6d5b815..919f2cd 100755 --- a/src/client/gui/components/RolledSelectionListV.cpp +++ b/src/client/gui/components/RolledSelectionListV.cpp @@ -1,5 +1,5 @@ #include "RolledSelectionListV.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Tesselator.hpp" #include "client/renderer/gles.hpp" #include "platform/input/Mouse.hpp" @@ -7,7 +7,7 @@ #include "client/renderer/Textures.hpp" -RolledSelectionListV::RolledSelectionListV( Minecraft* minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ ) +RolledSelectionListV::RolledSelectionListV( MinecraftClient& minecraft_, int width_, int height_, int x0_, int x1_, int y0_, int y1_, int itemHeight_ ) : minecraft(minecraft_), width(width_), height(height_), @@ -297,7 +297,7 @@ void RolledSelectionListV::render( int xm, int ym, float a ) void RolledSelectionListV::renderHoleBackground( /*float x0, float x1,*/ float y0, float y1, int a0, int a1 ) { Tesselator& t = Tesselator::instance; - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); glColor4f2(1.0f, 1, 1, 1); float s = 32; t.begin(); @@ -336,7 +336,7 @@ void RolledSelectionListV::renderDirtBackground() float by0 = _renderTopBorder? y0 : 0; float by1 = _renderBottomBorder? y1 : height; - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); glColor4f2(1.0f, 1, 1, 1); float s = 32; const float uvy = (float)((int) yo); diff --git a/src/client/gui/components/RolledSelectionListV.hpp b/src/client/gui/components/RolledSelectionListV.hpp index f535fed..c96b213 100755 --- a/src/client/gui/components/RolledSelectionListV.hpp +++ b/src/client/gui/components/RolledSelectionListV.hpp @@ -1,7 +1,7 @@ #pragma once #include "client/gui/GuiComponent.hpp" -class Minecraft; +class MinecraftClient; class Tesselator; @@ -11,7 +11,7 @@ class RolledSelectionListV : public GuiComponent static const int DRAG_OUTSIDE = -2; static const int DRAG_NORMAL = 0; public: - RolledSelectionListV(Minecraft* minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemHeight); + RolledSelectionListV(MinecraftClient& minecraft, int width, int height, int x0, int x1, int y0, int y1, int itemHeight); virtual int getItemAtPosition(int x, int y); @@ -51,7 +51,7 @@ protected: virtual void onPostRender(); void renderDirtBackground(); protected: - Minecraft* minecraft; + MinecraftClient& minecraft; float x0; float x1; diff --git a/src/client/gui/components/ScrolledSelectionList.cpp b/src/client/gui/components/ScrolledSelectionList.cpp index 95aff90..4c74826 100755 --- a/src/client/gui/components/ScrolledSelectionList.cpp +++ b/src/client/gui/components/ScrolledSelectionList.cpp @@ -1,5 +1,5 @@ #include "ScrolledSelectionList.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Tesselator.hpp" #include "client/renderer/gles.hpp" #include "platform/input/Mouse.hpp" @@ -9,7 +9,7 @@ static int Abs(int d) { return d >= 0? d : -d; } -ScrolledSelectionList::ScrolledSelectionList( Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight ) +ScrolledSelectionList::ScrolledSelectionList( MinecraftClient& _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight ) : minecraft(_minecraft), width(_width), height(_height), @@ -267,7 +267,7 @@ void ScrolledSelectionList::render( int xm, int ym, float a ) void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, int a1 ) { Tesselator& t = Tesselator::instance; - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); glColor4f2(1.0f, 1, 1, 1); float s = 32; t.begin(); @@ -283,7 +283,7 @@ void ScrolledSelectionList::renderHoleBackground( float y0, float y1, int a0, in void ScrolledSelectionList::renderDirtBackground() { Tesselator& t = Tesselator::instance; - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); glColor4f2(1.0f, 1, 1, 1); float s = 32; t.begin(); diff --git a/src/client/gui/components/ScrolledSelectionList.hpp b/src/client/gui/components/ScrolledSelectionList.hpp index f85c0a7..4b35878 100755 --- a/src/client/gui/components/ScrolledSelectionList.hpp +++ b/src/client/gui/components/ScrolledSelectionList.hpp @@ -1,7 +1,7 @@ #pragma once #include "client/gui/GuiComponent.hpp" -class Minecraft; +class MinecraftClient; class Tesselator; @@ -12,7 +12,7 @@ class ScrolledSelectionList : public GuiComponent static const int DRAG_NORMAL = 0; static const int DRAG_SKIP = 1; // special case to fix android jump bug public: - ScrolledSelectionList(Minecraft* _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight); + ScrolledSelectionList(MinecraftClient& _minecraft, int _width, int _height, int _y0, int _y1, int _itemHeight); virtual void setRenderSelection(bool _renderSelection); protected: @@ -40,7 +40,7 @@ public: virtual void renderHoleBackground(float y0, float y1, int a0, int a1); void renderDirtBackground(); protected: - Minecraft* minecraft; + MinecraftClient& minecraft; float y0; float y1; diff --git a/src/client/gui/components/ScrollingPane.cpp b/src/client/gui/components/ScrollingPane.cpp index c087401..482ca1f 100755 --- a/src/client/gui/components/ScrollingPane.cpp +++ b/src/client/gui/components/ScrollingPane.cpp @@ -111,7 +111,7 @@ ScrollingPane::~ScrollingPane() { delete[] selected; } -//void ScrollingPane::init(Minecraft* mc, int width, int height) { +//void ScrollingPane::init(MinecraftClient& mc, int width, int height) { // this->mc = mc; // this->width = width; // this->height = height; diff --git a/src/client/gui/components/ScrollingPane.hpp b/src/client/gui/components/ScrollingPane.hpp index 9eada38..3171336 100755 --- a/src/client/gui/components/ScrollingPane.hpp +++ b/src/client/gui/components/ScrollingPane.hpp @@ -46,7 +46,7 @@ public: ScrollingPane(int flags, const IntRectangle& boundingBox, const IntRectangle& itemRect, int columns, int numItems, float screenScale = 1.0f, const IntRectangle& itemBoundingRect = IntRectangle(0,0,0,0)); ~ScrollingPane(); - //void init(Minecraft*, int width, int height); + //void init(MinecraftClient&, int width, int height); void tick(); void render(int xm, int ym, float alpha); diff --git a/src/client/gui/components/Slider.cpp b/src/client/gui/components/Slider.cpp index 01fa0cc..ee6501c 100755 --- a/src/client/gui/components/Slider.cpp +++ b/src/client/gui/components/Slider.cpp @@ -1,5 +1,5 @@ #include "Slider.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Textures.hpp" #include "client/gui/Screen.hpp" #include "locale/I18n.hpp" @@ -9,7 +9,7 @@ Slider::Slider(OptionId optId) : m_mouseDownOnElement(false), m_optId(optId), m_numSteps(0) {} -void Slider::render( Minecraft* minecraft, int xm, int ym ) { +void Slider::render( MinecraftClient& minecraft, int xm, int ym ) { int xSliderStart = x + 5; int xSliderEnd = x + width - 5; int ySliderStart = y + 6; @@ -28,26 +28,26 @@ void Slider::render( Minecraft* minecraft, int xm, int ym ) { } } - minecraft->textures->loadAndBindTexture("gui/touchgui.png"); + minecraft.textures().loadAndBindTexture("gui/touchgui.png"); blit(xSliderStart + (int)(m_percentage * barWidth) - handleSizeX / 2, y, 226, 126, handleSizeX, handleSizeY, handleSizeX, handleSizeY); } -void Slider::mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ) { +void Slider::mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ) { if(pointInside(x, y)) { m_mouseDownOnElement = true; } } -void Slider::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { +void Slider::mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) { m_mouseDownOnElement = false; } -void Slider::tick(Minecraft* minecraft) { - if(minecraft->screen != NULL) { +void Slider::tick(MinecraftClient& minecraft) { + if(minecraft.getScreen()!= NULL) { int xm = Mouse::getX(); int ym = Mouse::getY(); - minecraft->screen->toGUICoordinate(xm, ym); + minecraft.getScreen()->toGUICoordinate(xm, ym); if(m_mouseDownOnElement) { m_percentage = float(xm - x) / float(width); @@ -56,24 +56,24 @@ void Slider::tick(Minecraft* minecraft) { } } -SliderFloat::SliderFloat(Minecraft* minecraft, OptionId option) -: Slider(option), m_option(dynamic_cast(minecraft->options.getOpt(option))) +SliderFloat::SliderFloat(MinecraftClient& minecraft, OptionId option) +: Slider(option), m_option(dynamic_cast(minecraft.options().getOpt(option))) { m_percentage = Mth::clamp((m_option->get() - m_option->getMin()) / (m_option->getMax() - m_option->getMin()), 0.f, 1.f); } -SliderInt::SliderInt(Minecraft* minecraft, OptionId option) -: Slider(option), m_option(dynamic_cast(minecraft->options.getOpt(option))) +SliderInt::SliderInt(MinecraftClient& minecraft, OptionId option) +: Slider(option), m_option(dynamic_cast(minecraft.options().getOpt(option))) { m_numSteps = m_option->getMax() - m_option->getMin() + 1; m_percentage = float(m_option->get() - m_option->getMin()) / (m_numSteps-1); } -void SliderInt::render( Minecraft* minecraft, int xm, int ym ) { +void SliderInt::render( MinecraftClient& minecraft, int xm, int ym ) { Slider::render(minecraft, xm, ym); } -void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { +void SliderInt::mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) { Slider::mouseReleased(minecraft, x, y, buttonNum); if (pointInside(x, y)) { @@ -81,14 +81,14 @@ void SliderInt::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum curStep = Mth::clamp(curStep + m_option->getMin(), m_option->getMin(), m_option->getMax()); m_percentage = float(curStep - m_option->getMin()) / (m_numSteps-1); - minecraft->options.set(m_optId, curStep); + minecraft.options().set(m_optId, curStep); } } -void SliderFloat::mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) { +void SliderFloat::mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) { Slider::mouseReleased(minecraft, x, y, buttonNum); if (pointInside(x, y)) { - minecraft->options.set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin()); + minecraft.options().set(m_optId, m_percentage * (m_option->getMax() - m_option->getMin()) + m_option->getMin()); } } \ No newline at end of file diff --git a/src/client/gui/components/Slider.hpp b/src/client/gui/components/Slider.hpp index def696a..c9c7f12 100755 --- a/src/client/gui/components/Slider.hpp +++ b/src/client/gui/components/Slider.hpp @@ -7,10 +7,10 @@ class Slider : public GuiElement { typedef GuiElement super; public: - virtual void render( Minecraft* minecraft, int xm, int ym ); - virtual void mouseClicked( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ); - virtual void tick(Minecraft* minecraft); + virtual void render( MinecraftClient& minecraft, int xm, int ym ); + virtual void mouseClicked( MinecraftClient& minecraft, int x, int y, int buttonNum ); + virtual void mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ); + virtual void tick(MinecraftClient& minecraft); protected: Slider(OptionId optId); @@ -24,9 +24,9 @@ protected: class SliderFloat : public Slider { public: - SliderFloat(Minecraft* minecraft, OptionId option); + SliderFloat(MinecraftClient& minecraft, OptionId option); - virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override; + virtual void mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) override; protected: OptionFloat* m_option; @@ -35,10 +35,10 @@ protected: class SliderInt : public Slider { public: - SliderInt(Minecraft* minecraft, OptionId option); + SliderInt(MinecraftClient& minecraft, OptionId option); - virtual void render( Minecraft* minecraft, int xm, int ym ) override; - virtual void mouseReleased( Minecraft* minecraft, int x, int y, int buttonNum ) override; + virtual void render( MinecraftClient& minecraft, int xm, int ym ) override; + virtual void mouseReleased( MinecraftClient& minecraft, int x, int y, int buttonNum ) override; protected: OptionInt* m_option; diff --git a/src/client/gui/components/TextBox.cpp b/src/client/gui/components/TextBox.cpp index 6a506ca..df2d664 100755 --- a/src/client/gui/components/TextBox.cpp +++ b/src/client/gui/components/TextBox.cpp @@ -1,6 +1,6 @@ #include "TextBox.hpp" #include "client/gui/Gui.hpp" -#include "client/Minecraft.hpp" +#include #include "AppPlatform.hpp" #include "platform/input/Mouse.hpp" @@ -21,25 +21,25 @@ TextBox::TextBox(int id, int x, int y, int w, int h, const std::string& msg) { } -void TextBox::setFocus(Minecraft* minecraft) { +void TextBox::setFocus(MinecraftClient& minecraft) { if (!focused) { - minecraft->platform()->showKeyboard(); + minecraft.platform()->showKeyboard(); focused = true; blinkTicks = 0; blink = false; } } -bool TextBox::loseFocus(Minecraft* minecraft) { +bool TextBox::loseFocus(MinecraftClient& minecraft) { if (focused) { - minecraft->platform()->hideKeyboard(); + minecraft.platform()->hideKeyboard(); focused = false; return true; } return false; } -void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { +void TextBox::mouseClicked(MinecraftClient& minecraft, int x, int y, int buttonNum) { if (buttonNum == MouseAction::ACTION_LEFT) { if (pointInside(x, y)) { setFocus(minecraft); @@ -49,19 +49,19 @@ void TextBox::mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum) { } } -void TextBox::charPressed(Minecraft* minecraft, char c) { +void TextBox::charPressed(MinecraftClient& minecraft, char c) { if (focused && c >= 32 && c < 127 && (int)text.size() < 256) { text.push_back(c); } } -void TextBox::keyPressed(Minecraft* minecraft, int key) { +void TextBox::keyPressed(MinecraftClient& minecraft, int key) { if (focused && key == Keyboard::KEY_BACKSPACE && !text.empty()) { text.pop_back(); } } -void TextBox::tick(Minecraft* minecraft) { +void TextBox::tick(MinecraftClient& minecraft) { blinkTicks++; if (blinkTicks >= 5) { blink = !blink; @@ -69,7 +69,7 @@ void TextBox::tick(Minecraft* minecraft) { } } -void TextBox::render(Minecraft* minecraft, int xm, int ym) { +void TextBox::render(MinecraftClient& minecraft, int xm, int ym) { // textbox like in beta 1.7.3 // change appearance when focused so the user can tell it's active // active background darker gray with a subtle border @@ -81,7 +81,7 @@ void TextBox::render(Minecraft* minecraft, int xm, int ym) { glEnable2(GL_SCISSOR_TEST); glScissor( Gui::GuiScale * (x + 2), - minecraft->height - Gui::GuiScale * (y + height - 2), + minecraft.getScreenHeight() - Gui::GuiScale * (y + height - 2), Gui::GuiScale * (width - 2), Gui::GuiScale * (height - 2) ); @@ -89,12 +89,12 @@ void TextBox::render(Minecraft* minecraft, int xm, int ym) { int _y = y + (height - Font::DefaultLineHeight) / 2; if (text.empty() && !focused) { - drawString(minecraft->font, hint, x + 2, _y, 0xff5e5e5e); + drawString(minecraft.font(), hint, x + 2, _y, 0xff5e5e5e); } if (focused && blink) text.push_back('_'); - drawString(minecraft->font, text, x + 2, _y, 0xffffffff); + drawString(minecraft.font(), text, x + 2, _y, 0xffffffff); if (focused && blink) text.pop_back(); diff --git a/src/client/gui/components/TextBox.hpp b/src/client/gui/components/TextBox.hpp index 18f9324..4d9f848 100755 --- a/src/client/gui/components/TextBox.hpp +++ b/src/client/gui/components/TextBox.hpp @@ -9,7 +9,7 @@ #include "platform/input/Keyboard.hpp" class Font; -class Minecraft; +class MinecraftClient; class TextBox: public GuiElement { @@ -18,16 +18,16 @@ public: TextBox(int id, int x, int y, const std::string& msg); TextBox(int id, int x, int y, int w, int h, const std::string& msg); - virtual void mouseClicked(Minecraft* minecraft, int x, int y, int buttonNum); + virtual void mouseClicked(MinecraftClient& minecraft, int x, int y, int buttonNum); - virtual void setFocus(Minecraft* minecraft); - virtual bool loseFocus(Minecraft* minecraft); + virtual void setFocus(MinecraftClient& minecraft); + virtual bool loseFocus(MinecraftClient& minecraft); - virtual void render(Minecraft* minecraft, int xm, int ym); + virtual void render(MinecraftClient& minecraft, int xm, int ym); - virtual void keyPressed(Minecraft* minecraft, int key); - virtual void charPressed(Minecraft* minecraft, char c); - virtual void tick(Minecraft* minecraft); + virtual void keyPressed(MinecraftClient& minecraft, int key); + virtual void charPressed(MinecraftClient& minecraft, char c); + virtual void tick(MinecraftClient& minecraft); public: std::string hint; diff --git a/src/client/gui/components/TextOption.cpp b/src/client/gui/components/TextOption.cpp index d635abb..0b8a539 100644 --- a/src/client/gui/components/TextOption.cpp +++ b/src/client/gui/components/TextOption.cpp @@ -1,15 +1,15 @@ #include "TextOption.hpp" #include -TextOption::TextOption(Minecraft* minecraft, OptionId optId) - : TextBox((int)optId, minecraft->options.getOpt(optId)->getStringId()) +TextOption::TextOption(MinecraftClient& minecraft, OptionId optId) + : TextBox((int)optId, minecraft.options().getOpt(optId)->getStringId()) { - text = minecraft->options.getStringValue(optId); + text = minecraft.options().getStringValue(optId); } -bool TextOption::loseFocus(Minecraft* minecraft) { +bool TextOption::loseFocus(MinecraftClient& minecraft) { if (TextBox::loseFocus(minecraft)) { - minecraft->options.set((OptionId)id, text); + minecraft.options().set((OptionId)id, text); return true; } diff --git a/src/client/gui/components/TextOption.hpp b/src/client/gui/components/TextOption.hpp index 30c0a04..f166a48 100644 --- a/src/client/gui/components/TextOption.hpp +++ b/src/client/gui/components/TextOption.hpp @@ -4,7 +4,7 @@ class TextOption : public TextBox { public: - TextOption(Minecraft* minecraft, OptionId optId); + TextOption(MinecraftClient& minecraft, OptionId optId); - virtual bool loseFocus(Minecraft* minecraft); + virtual bool loseFocus(MinecraftClient& minecraft); }; \ No newline at end of file diff --git a/src/client/gui/screens/ArmorScreen.cpp b/src/client/gui/screens/ArmorScreen.cpp index 1aed23a..ecd2400 100755 --- a/src/client/gui/screens/ArmorScreen.cpp +++ b/src/client/gui/screens/ArmorScreen.cpp @@ -1,7 +1,7 @@ #include "ArmorScreen.hpp" #include "client/gui/Screen.hpp" #include "client/gui/components/NinePatch.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/entity/ItemRenderer.hpp" @@ -73,7 +73,7 @@ ArmorScreen::~ArmorScreen() { void ArmorScreen::init() { super::init(); - player = minecraft->player; + player = minecraft.player(); ImageDef def; def.name = "gui/spritesheet.png"; @@ -95,7 +95,7 @@ void ArmorScreen::init() { buttons.push_back(armorButtons[i]); // GUI - nine patches - NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png"); + NinePatchFactory builder(minecraft.textures() "gui/spritesheet.png"); guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4); guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3, 20, 20); @@ -200,7 +200,7 @@ void ArmorScreen::render(int xm, int ym, float a) { void ArmorScreen::buttonClicked(Button* button) { if (button == &btnClose) { - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); } if (button->id >= 0 && button->id <= 3) { @@ -252,8 +252,8 @@ std::vector ArmorScreen::getItems( const Touch::InventoryPa void ArmorScreen::updateItems() { armorItems.clear(); - for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) { - ItemInstance* item = minecraft->player->inventory->getItem(i); + for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft.player()->inventory->getContainerSize(); ++i) { + ItemInstance* item = minecraft.player()->inventory->getItem(i); if (ItemInstance::isArmorItem(item)) armorItems.push_back(item); } @@ -281,13 +281,13 @@ void ArmorScreen::drawSlotItemAt( Tesselator& t, int slot, const ItemInstance* i guiSlot->draw(t, xx, yy); if (item && !item->isNull()) { - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 2, yy, true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures() item, xx + 2, yy, true); glDisable2(GL_TEXTURE_2D); ItemRenderer::renderGuiItemDecorations(item, xx + 2, yy + 3); glEnable2(GL_TEXTURE_2D); - //minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true); + //minecraft.gui().renderSlotText(item, xx + 3, yy + 3, true, true); } else { - minecraft->textures->loadAndBindTexture("gui/items.png"); + minecraft.textures().loadAndBindTexture("gui/items.png"); blit(x + 2, y, 15 * 16, slot * 16, 16, 16, 16, 16); } } @@ -297,14 +297,14 @@ void ArmorScreen::takeAndClearSlot( int slot ) { if (!item) return; - int oldSize = minecraft->player->inventory->getNumEmptySlots(); + int oldSize = minecraft.player()->inventory->getNumEmptySlots(); - if (!minecraft->player->inventory->add(item)) - minecraft->player->drop(new ItemInstance(*item), false); + if (!minecraft.player()->inventory->add(item)) + minecraft.player()->drop(new ItemInstance(*item), false); player->setArmor(slot, NULL); - int newSize = minecraft->player->inventory->getNumEmptySlots(); + int newSize = minecraft.player()->inventory->getNumEmptySlots(); setIfNotSet(doRecreatePane, newSize != oldSize); } @@ -319,7 +319,7 @@ void ArmorScreen::renderPlayer(float xo, float yo) { glRotatef(180, 0, 0, 1); //glDisable(GL_DEPTH_TEST); - Player* player = (Player*) minecraft->player; + Player* player = (Player*) minecraft.player(); float oybr = player->yBodyRot; float oyr = player->yRot; float oxr = player->xRot; diff --git a/src/client/gui/screens/BaseContainerScreen.hpp b/src/client/gui/screens/BaseContainerScreen.hpp index c80e37e..3e97716 100755 --- a/src/client/gui/screens/BaseContainerScreen.hpp +++ b/src/client/gui/screens/BaseContainerScreen.hpp @@ -4,7 +4,7 @@ #include #include "client/gui/Screen.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" class BaseContainerMenu; @@ -13,26 +13,23 @@ class BaseContainerScreen: public Screen { typedef Screen super; public: - BaseContainerScreen(BaseContainerMenu* menu) - : menu(menu) - { - } + BaseContainerScreen(MinecraftClient& mc, BaseContainerMenu* menu) : Screen(mc), menu(menu) {} virtual void init() { super::init(); - minecraft->player->containerMenu = menu; + minecraft.player()->containerMenu = menu; } virtual void tick() { super::tick(); - if (!minecraft->player->isAlive() || minecraft->player->removed) - minecraft->player->closeContainer(); + if (!minecraft.player()->isAlive() || minecraft.player()->removed) + minecraft.player()->closeContainer(); } virtual void keyPressed( int eventKey ) { if (eventKey == Keyboard::KEY_ESCAPE) { - minecraft->player->closeContainer(); + minecraft.player()->closeContainer(); } else { super::keyPressed(eventKey); } diff --git a/src/client/gui/screens/ChatScreen.cpp b/src/client/gui/screens/ChatScreen.cpp index 31d4c87..a0c61e0 100755 --- a/src/client/gui/screens/ChatScreen.cpp +++ b/src/client/gui/screens/ChatScreen.cpp @@ -1,24 +1,40 @@ #include "ChatScreen.hpp" -#include "DialogDefinitions.hpp" -#include "client/gui/Gui.hpp" -#include "client/Minecraft.hpp" -#include "AppPlatform.hpp" -#include "platform/log.hpp" +#include "client/gui/Screen.hpp" +#include + void ChatScreen::init() { - minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_NEW_CHAT_MESSAGE); + m_input.x = 2; + m_input.width = width - 4; + m_input.height = 12; + m_input.y = height - m_input.height - 2; + + textBoxes.push_back(&m_input); } -void ChatScreen::render(int xm, int ym, float a) -{ - int status = minecraft->platform()->getUserInputStatus(); - if (status > -1) { - if (status == 1) { - std::vector v = minecraft->platform()->getUserInput(); - if (v.size() && v[0].length() > 0) - minecraft->gui.addMessage(v[0]); - } +void ChatScreen::render(int xm, int ym, float a) { + fillGradient(0, 0, width, height, 0x00000000, 0x40000000); + m_input.focused = true; - minecraft->setScreen(NULL); - } + Screen::render(xm, ym, a); } + +bool ChatScreen::handleBackEvent(bool isDown) { + minecraft.setScreen(NULL); + return true; +} + +void ChatScreen::keyPressed(int eventKey) { + // Was ai code before (we're sorry about it), but now reviewed + // and everything is ok + + if (eventKey == Keyboard::KEY_ESCAPE) { + return minecraft.setScreen(NULL); + } + + if (eventKey == Keyboard::KEY_RETURN) { + // execute... + } + + return ChatScreen::keyPressed(eventKey); +} \ No newline at end of file diff --git a/src/client/gui/screens/ChatScreen.hpp b/src/client/gui/screens/ChatScreen.hpp index 5978d49..db7c18a 100755 --- a/src/client/gui/screens/ChatScreen.hpp +++ b/src/client/gui/screens/ChatScreen.hpp @@ -1,19 +1,22 @@ #pragma once #include "client/gui/Screen.hpp" +#include "client/gui/components/TextBox.hpp" class ChatScreen: public Screen { public: - ChatScreen() {} - virtual ~ChatScreen() {} + ChatScreen(); void init(); - + void render(int xm, int ym, float a); void buttonClicked(Button* button) {}; + bool handleBackEvent(bool isDown); + void keyPressed(int eventKey); private: + TextBox m_input; }; diff --git a/src/client/gui/screens/ChestScreen.cpp b/src/client/gui/screens/ChestScreen.cpp index 590dedb..04a36b9 100755 --- a/src/client/gui/screens/ChestScreen.cpp +++ b/src/client/gui/screens/ChestScreen.cpp @@ -2,7 +2,7 @@ #include "touch/TouchStartMenuScreen.hpp" #include "client/gui/Screen.hpp" #include "client/gui/components/NinePatch.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/entity/ItemRenderer.hpp" @@ -110,7 +110,7 @@ typedef struct FlyingItem { static std::vector flyingItems; ChestScreen::ChestScreen(Player* player, ChestTileEntity* chest) -: super(new ContainerMenu(chest, chest->runningId)), //@huge @attn +: super(new ContainerMenu(minecraft, chest, chest->runningId)), //@huge @attn inventoryPane(NULL), chestPane(NULL), btnClose(4, ""), @@ -163,7 +163,7 @@ void ChestScreen::init() { buttons.push_back(&btnClose); // GUI - nine patches - NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png"); + NinePatchFactory builder(minecraft.textures() "gui/spritesheet.png"); guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4); guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3); @@ -213,7 +213,7 @@ void ChestScreen::handleRenderPane(Touch::InventoryPane* pane, Tesselator& t, in heldMs = ms; FillingContainer* c = (pane == inventoryPane)? - upcast(minecraft->player->inventory) + upcast(minecraft.player()->inventory) : upcast(chest); const int slotIndex = id + c->getNumLinkedSlots(); @@ -270,7 +270,7 @@ void ChestScreen::render(int xm, int ym, float a) { glEnable2(GL_SCISSOR_TEST); //LOGI("panesBox: %d, %d - %d, %d\n", panesBbox.x, panesBbox.y, panesBbox.w, panesBbox.h); - minecraft->gui.setScissorRect(panesBbox); + minecraft.gui().setScissorRect(panesBbox); for (unsigned int i = 0; i < flyingItems.size(); ++i) { FlyingItem& fi = flyingItems[i]; float since = (now - fi.startTime); @@ -281,8 +281,8 @@ void ChestScreen::render(int xm, int ym, float a) { float xx = Mth::lerp(fi.sx, fi.dx, t); float yy = Mth::lerp(fi.sy, fi.dy, t); - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, &fi.item, xx + 7, yy + 8, true); - //minecraft->gui.renderSlotText(&fi.item, xx + 3, yy + 3, true, true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures(), &fi.item, xx + 7, yy + 8, true); + //minecraft.gui().renderSlotText(&fi.item, xx + 3, yy + 3, true, true); flyingToSave.push_back(fi); } @@ -295,12 +295,12 @@ void ChestScreen::render(int xm, int ym, float a) { t.colorABGR(0xffffffff); glDisable2(GL_BLEND); - minecraft->textures->loadAndBindTexture("gui/spritesheet.png"); + minecraft.textures().loadAndBindTexture("gui/spritesheet.png"); } void ChestScreen::buttonClicked(Button* button) { if (button == &btnClose) { - minecraft->player->closeContainer(); + minecraft.player()->closeContainer(); } } @@ -353,11 +353,11 @@ bool ChestScreen::handleAddItem(FillingContainer* from, FillingContainer* to, in fi.dy = gTo.yf; flyingItems.push_back(fi); - if (!fromChest && minecraft->level->isClientSide) { + if (!fromChest && minecraft.level->isClientSide) { int j = toIndex; ItemInstance item = items[j]? *items[j] : ItemInstance(); ContainerSetSlotPacket p(menu->containerId, j, item); - minecraft->raknetInstance->send(p); + minecraft.raknetInstance->send(p); } } } @@ -366,7 +366,7 @@ bool ChestScreen::handleAddItem(FillingContainer* from, FillingContainer* to, in if (fromChest) { ItemInstance ins(item->count <= 0? ItemInstance() : *item); ContainerSetSlotPacket p(menu->containerId, slotIndex, ins); - minecraft->raknetInstance->send(p); + minecraft.raknetInstance->send(p); } if (item->count <= 0) from->clearSlot(slotIndex); @@ -380,8 +380,8 @@ bool ChestScreen::handleAddItem(FillingContainer* from, FillingContainer* to, in bool ChestScreen::addItem(const Touch::InventoryPane* forPane, int itemIndex) { //LOGI("items.size, index: %d, %d\n", inventoryItems.size(), itemIndex); bool l2r = (forPane == inventoryPane); - return handleAddItem( l2r? upcast(minecraft->player->inventory) : upcast(chest), - l2r? upcast(chest) : upcast(minecraft->player->inventory), + return handleAddItem( l2r? upcast(minecraft.player()->inventory) : upcast(chest), + l2r? upcast(chest) : upcast(minecraft.player()->inventory), itemIndex); } @@ -398,8 +398,8 @@ bool ChestScreen::renderGameBehind() std::vector ChestScreen::getItems( const Touch::InventoryPane* forPane ) { if (forPane == inventoryPane) { - for (int i = Inventory::MAX_SELECTION_SIZE, j = 0; i < minecraft->player->inventory->getContainerSize(); ++i, ++j) - inventoryItems[j] = minecraft->player->inventory->getItem(i); + for (int i = Inventory::MAX_SELECTION_SIZE, j = 0; i < minecraft.player()->inventory->getContainerSize(); ++i, ++j) + inventoryItems[j] = minecraft.player()->inventory->getItem(i); return inventoryItems; } else { @@ -413,8 +413,8 @@ std::vector ChestScreen::getItems( const Touch::InventoryPa void ChestScreen::setupPane() { inventoryItems.clear(); - for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) { - ItemInstance* item = minecraft->player->inventory->getItem(i); + for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft.player()->inventory->getContainerSize(); ++i) { + ItemInstance* item = minecraft.player()->inventory->getItem(i); /*if (!item || item->isNull()) continue;*/ inventoryItems.push_back(item); } @@ -439,7 +439,7 @@ void ChestScreen::setupPane() #endif // IntRectangle(0, 0, 100, 100) if (inventoryPane) delete inventoryPane; - inventoryPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, minecraft->player->inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE, ItemSize, (int)BorderPixels); + inventoryPane = new Touch::InventoryPane(this, minecraft, rect, paneWidth, BorderPixels, minecraft.player()->inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE, ItemSize, (int)BorderPixels); inventoryPane->fillMarginX = 0; inventoryPane->fillMarginY = 0; guiPaneFrame->setSize((float)rect.w + 2, (float)rect.h + 2); @@ -468,7 +468,7 @@ void ChestScreen::drawSlotItemAt( Tesselator& t, const ItemInstance* item, int x guiSlotMarker->draw(t, xx - 2, yy - 2); if (item && !item->isNull()) { - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 7, yy + 8, true); - minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures(), item, xx + 7, yy + 8, true); + minecraft.gui().renderSlotText(item, xx + 3, yy + 3, true, true); } } diff --git a/src/client/gui/screens/ChooseLevelScreen.cpp b/src/client/gui/screens/ChooseLevelScreen.cpp index a622936..721d6dd 100755 --- a/src/client/gui/screens/ChooseLevelScreen.cpp +++ b/src/client/gui/screens/ChooseLevelScreen.cpp @@ -1,7 +1,7 @@ #include "ChooseLevelScreen.hpp" #include #include -#include "client/Minecraft.hpp" +#include void ChooseLevelScreen::init() { loadLevelSource(); @@ -9,7 +9,7 @@ void ChooseLevelScreen::init() { void ChooseLevelScreen::loadLevelSource() { - LevelStorageSource* levelSource = minecraft->getLevelSource(); + LevelStorageSource* levelSource = minecraft.getLevelSource(); levelSource->getLevelList(levels); std::sort(levels.begin(), levels.end()); } diff --git a/src/client/gui/screens/ConfirmScreen.cpp b/src/client/gui/screens/ConfirmScreen.cpp index 8513cb7..89a41f8 100755 --- a/src/client/gui/screens/ConfirmScreen.cpp +++ b/src/client/gui/screens/ConfirmScreen.cpp @@ -1,6 +1,6 @@ #include "ConfirmScreen.hpp" #include "client/gui/components/Button.hpp" -#include "client/Minecraft.hpp" +#include ConfirmScreen::ConfirmScreen(Screen* parent_, const std::string& title1_, const std::string& title2_, int id_) : parent(parent_), @@ -31,7 +31,7 @@ ConfirmScreen::~ConfirmScreen() { void ConfirmScreen::init() { - if (/* minecraft->useTouchscreen() */ true) { + if (/* minecraft.useTouchscreen() */ true) { yesButton = new Touch::TButton(0, 0, 0, yesButtonText), noButton = new Touch::TButton(1, 0, 0, noButtonText); } else { diff --git a/src/client/gui/screens/ConsoleScreen.cpp b/src/client/gui/screens/ConsoleScreen.cpp deleted file mode 100644 index fec76b0..0000000 --- a/src/client/gui/screens/ConsoleScreen.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "ConsoleScreen.hpp" -#include "client/gui/Gui.hpp" -#include "client/Minecraft.hpp" -#include "client/player/LocalPlayer.hpp" -#include "platform/input/Keyboard.hpp" -#include "world/level/Level.hpp" -#include "network/RakNetInstance.hpp" -#include "network/ServerSideNetworkHandler.hpp" -#include "network/packet/ChatPacket.hpp" -#include "platform/log.hpp" - -#include -#include -#include - -ConsoleScreen::ConsoleScreen() -: _input(""), - _cursorBlink(0) -{ -} - -void ConsoleScreen::init() -{ -} - -void ConsoleScreen::tick() -{ - _cursorBlink++; -} - -bool ConsoleScreen::handleBackEvent(bool /*isDown*/) -{ - minecraft->setScreen(NULL); - return true; -} - -void ConsoleScreen::keyPressed(int eventKey) -{ - if (eventKey == Keyboard::KEY_ESCAPE) { - minecraft->setScreen(NULL); - } else if (eventKey == Keyboard::KEY_RETURN) { - execute(); - } else if (eventKey == Keyboard::KEY_BACKSPACE) { - if (!_input.empty()) - _input.erase(_input.size() - 1, 1); - } else { - super::keyPressed(eventKey); - } -} - -void ConsoleScreen::charPressed(char inputChar) -{ - if (inputChar >= 32 && inputChar < 127) - _input += inputChar; -} - -// --------------------------------------------------------------------------- -// execute: run _input as a command, print result, close screen -// --------------------------------------------------------------------------- -void ConsoleScreen::execute() -{ - if (_input.empty()) { - minecraft->setScreen(NULL); - return; - } - - if (_input[0] == '/') { - // Command - std::string result = processCommand(_input); - if (!result.empty()) - minecraft->gui.addMessage(result); - } else { - // Chat message: message - std::string msg = std::string("<") + minecraft->player->name + "> " + _input; - if (minecraft->netCallback && minecraft->raknetInstance->isServer()) { - // Hosting a LAN game: displayGameMessage shows locally + broadcasts MessagePacket to clients - static_cast(minecraft->netCallback)->displayGameMessage(msg); - } else if (minecraft->netCallback) { - // Connected client: send ChatPacket to server; server echoes it back as MessagePacket - ChatPacket chatPkt(msg); - minecraft->raknetInstance->send(chatPkt); - } else { - // Singleplayer: show locally only - minecraft->gui.addMessage(msg); - } - } - - minecraft->setScreen(NULL); -} - -// --------------------------------------------------------------------------- -// processCommand -// --------------------------------------------------------------------------- -static std::string trim(const std::string& s) { - size_t a = s.find_first_not_of(" \t"); - if (a == std::string::npos) return ""; - size_t b = s.find_last_not_of(" \t"); - return s.substr(a, b - a + 1); -} - -std::string ConsoleScreen::processCommand(const std::string& raw) -{ - // strip leading '/' - std::string line = raw; - if (!line.empty() && line[0] == '/') line = line.substr(1); - line = trim(line); - - // tokenise - std::vector args; - { - std::istringstream ss(line); - std::string tok; - while (ss >> tok) args.push_back(tok); - } - - if (args.empty()) return ""; - - Level* level = minecraft->level; - if (!level) return "No level loaded."; - - // ----------------------------------------------------------------------- - // /time ... - // ----------------------------------------------------------------------- - if (args[0] == "time") { - if (args.size() < 2) - return "Usage: /time ..."; - - const std::string& sub = args[1]; - - // -- time add ----------------------------------------------- - if (sub == "add") { - if (args.size() < 3) return "Usage: /time add "; - long delta = std::atol(args[2].c_str()); - long newTime = level->getTime() + delta; - level->setTime(newTime); - std::ostringstream out; - out << "Set the time to " << (newTime % Level::TICKS_PER_DAY); - return out.str(); - } - - // -- time set ----------------------- - if (sub == "set") { - if (args.size() < 3) return "Usage: /time set "; - const std::string& val = args[2]; - - long t = -1; - if (val == "day") t = 1000; - else if (val == "noon") t = 6000; - else if (val == "night") t = 13000; - else if (val == "midnight") t = 18000; - else { - // numeric — accept positive integers only - bool numeric = true; - for (char c : val) - if (!std::isdigit((unsigned char)c)) { numeric = false; break; } - if (!numeric) return std::string("Unknown value: ") + val; - t = std::atol(val.c_str()); - } - - // Preserve the total day count so only the time-of-day changes - long dayCount = level->getTime() / Level::TICKS_PER_DAY; - long newTime = dayCount * Level::TICKS_PER_DAY + (t % Level::TICKS_PER_DAY); - level->setTime(newTime); - std::ostringstream out; - out << "Set the time to " << t; - return out.str(); - } - - // -- time query ------------------------------ - if (sub == "query") { - if (args.size() < 3) return "Usage: /time query "; - const std::string& what = args[2]; - - long total = level->getTime(); - long daytime = total % Level::TICKS_PER_DAY; - long day = total / Level::TICKS_PER_DAY; - - std::ostringstream out; - if (what == "daytime") { out << "The time of day is " << daytime; } - else if (what == "gametime") { out << "The game time is " << total; } - else if (what == "day") { out << "The day is " << day; } - else return std::string("Unknown query: ") + what; - return out.str(); - } - - return "Unknown sub-command. Usage: /time ..."; - } - - return std::string("Unknown command: /") + args[0]; -} - -// --------------------------------------------------------------------------- -// render -// --------------------------------------------------------------------------- -void ConsoleScreen::render(int /*xm*/, int /*ym*/, float /*a*/) -{ - // Dim the game world slightly - fillGradient(0, 0, width, height, 0x00000000, 0x40000000); - - const int boxH = 12; - const int boxY = height - boxH - 2; - const int boxX0 = 2; - const int boxX1 = width - 2; - - // Input box background - fill(boxX0, boxY, boxX1, boxY + boxH, 0xc0000000); - // Border - fill(boxX0, boxY, boxX1, boxY + 1, 0xff808080); - fill(boxX0, boxY + boxH - 1, boxX1, boxY + boxH, 0xff808080); - fill(boxX0, boxY, boxX0 + 1, boxY + boxH, 0xff808080); - fill(boxX1 - 1, boxY, boxX1, boxY + boxH, 0xff808080); - - // Input text + blinking cursor - std::string displayed = _input; - if ((_cursorBlink / 10) % 2 == 0) - displayed += '_'; - - // Placeholder hint when empty - font->drawShadow(displayed, (float)(boxX0 + 2), (float)(boxY + 2), 0xffffffff); -} diff --git a/src/client/gui/screens/ConsoleScreen.hpp b/src/client/gui/screens/ConsoleScreen.hpp deleted file mode 100644 index 4defcfc..0000000 --- a/src/client/gui/screens/ConsoleScreen.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "client/gui/Screen.hpp" -#include - -class ConsoleScreen: public Screen -{ - typedef Screen super; -public: - ConsoleScreen(); - virtual ~ConsoleScreen() {} - - void init(); - void render(int xm, int ym, float a); - void tick(); - - virtual bool renderGameBehind() { return true; } - virtual bool isInGameScreen() { return true; } - virtual bool isPauseScreen() { return false; } - - virtual void keyPressed(int eventKey); - virtual void charPressed(char inputChar); - virtual bool handleBackEvent(bool isDown); - -private: - void execute(); - std::string processCommand(const std::string& cmd); - - std::string _input; - int _cursorBlink; // tick counter for cursor blink -}; - diff --git a/src/client/gui/screens/CreditsScreen.cpp b/src/client/gui/screens/CreditsScreen.cpp index a87e053..2e13d87 100644 --- a/src/client/gui/screens/CreditsScreen.cpp +++ b/src/client/gui/screens/CreditsScreen.cpp @@ -1,7 +1,7 @@ #include "CreditsScreen.hpp" #include "StartMenuScreen.hpp" #include "OptionsScreen.hpp" -#include "client/Minecraft.hpp" +#include #include "client/gui/components/Button.hpp" #include "client/gui/components/ImageButton.hpp" #include "platform/input/Mouse.hpp" @@ -67,7 +67,7 @@ void CreditsScreen::tick() { // move text upward _scrollY -= _scrollSpeed; // if text has scrolled off the top, restart - float totalHeight = _lines.size() * (minecraft->font->lineHeight + 8); + float totalHeight = _lines.size() * (minecraft.font()->lineHeight + 8); if (_scrollY + totalHeight < 0) { _scrollY = height; } @@ -82,9 +82,9 @@ void CreditsScreen::tick() { void CreditsScreen::render(int xm, int ym, float a) { renderBackground(); int w = width; - Font* font = minecraft->font; + Font* font = minecraft.font(); float y = _scrollY; - const float lineHeight = font->lineHeight + 8; + const float lineHeight = font.lineHeight + 8; for (size_t i = 0; i < _lines.size(); ++i) { const std::string& line = _lines[i]; // use color-tag-aware drawing, centre by total width @@ -93,7 +93,7 @@ void CreditsScreen::render(int xm, int ym, float a) { // underline hyperlink lines manually if (line.find("http") != std::string::npos || line.find("discord.gg") != std::string::npos) { float x0 = w/2 - lineWidth/2; - float y0 = y + font->lineHeight - 1; + float y0 = y + font.lineHeight - 1; this->fill(x0, y0, x0 + lineWidth, y0 + 1, 0xffffffff); } y += lineHeight; @@ -104,13 +104,13 @@ void CreditsScreen::render(int xm, int ym, float a) { void CreditsScreen::buttonClicked(Button* button) { if (button->id == 1) { - minecraft->setScreen(new OptionsScreen()); + minecraft.setScreen(new OptionsScreen()); } } void CreditsScreen::mouseClicked(int x, int y, int buttonNum) { // map click to a line in the scrolling text - const float lineHeight = minecraft->font->lineHeight + 8; + const float lineHeight = minecraft.font()->lineHeight + 8; for (size_t i = 0; i < _lines.size(); ++i) { float lineY = _scrollY + i * lineHeight; if (y >= lineY && y < lineY + lineHeight) { @@ -122,7 +122,7 @@ void CreditsScreen::mouseClicked(int x, int y, int buttonNum) { // extract until space size_t end = line.find(' ', start); std::string url = line.substr(start, (end == std::string::npos) ? std::string::npos : end - start); - minecraft->platform()->openURL(url); + minecraft.platform()->openURL(url); return; } } diff --git a/src/client/gui/screens/DeathScreen.cpp b/src/client/gui/screens/DeathScreen.cpp index cbdcd2a..d9c39a8 100755 --- a/src/client/gui/screens/DeathScreen.cpp +++ b/src/client/gui/screens/DeathScreen.cpp @@ -1,7 +1,7 @@ #include "DeathScreen.hpp" #include "ScreenChooser.hpp" #include "client/gui/components/Button.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "platform/time.hpp" @@ -23,7 +23,7 @@ DeathScreen::~DeathScreen() void DeathScreen::init() { - if (/* minecraft->useTouchscreen() */ true) { + if (/* minecraft.useTouchscreen() */ true) { bRespawn = new Touch::TButton(1, "Respawn!"); bTitle = new Touch::TButton(2, "Main menu"); } else { @@ -71,13 +71,13 @@ void DeathScreen::buttonClicked( Button* button ) if (button == bRespawn) { //RespawnPacket packet(); - //minecraft->raknetInstance->send(packet); + //minecraft.raknetInstance->send(packet); - minecraft->player->respawn(); - //minecraft->raknetInstance->send(); - minecraft->setScreen(NULL); + minecraft.player()->respawn(); + //minecraft.raknetInstance->send(); + minecraft.setScreen(NULL); } if (button == bTitle) - minecraft->leaveGame(); + minecraft.leaveGame(); } diff --git a/src/client/gui/screens/DialogDefinitions.hpp b/src/client/gui/screens/DialogDefinitions.hpp deleted file mode 100755 index a48a070..0000000 --- a/src/client/gui/screens/DialogDefinitions.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -class DialogDefinitions { -public: - static const int DIALOG_CREATE_NEW_WORLD = 1; - static const int DIALOG_NEW_CHAT_MESSAGE = 2; - static const int DIALOG_MAINMENU_OPTIONS = 3; - static const int DIALOG_RENAME_MP_WORLD = 4; - static const int DIALOG_DEMO_FEATURE_DISABLED = 98; -}; - diff --git a/src/client/gui/screens/DisconnectionScreen.hpp b/src/client/gui/screens/DisconnectionScreen.hpp index f78351f..aa1d165 100755 --- a/src/client/gui/screens/DisconnectionScreen.hpp +++ b/src/client/gui/screens/DisconnectionScreen.hpp @@ -3,7 +3,7 @@ #include "client/gui/Screen.hpp" #include "client/gui/Font.hpp" #include "client/gui/components/Button.hpp" -#include "client/Minecraft.hpp" +#include #include class DisconnectionScreen: public Screen @@ -20,7 +20,7 @@ public: } void init() { - if (/* minecraft->useTouchscreen() */ true) + if (/* minecraft.useTouchscreen() */ true) _back = new Touch::TButton(1, "Ok"); else _back = new Button(1, "Ok"); @@ -37,13 +37,13 @@ public: renderBackground(); super::render(xm, ym, a); - int center = (width - minecraft->font->width(_msg)) / 2; - minecraft->font->drawShadow(_msg, (float)center, (float)(height / 2 - 32), 0xffffffff); + int center = (width - minecraft.font()->width(_msg)) / 2; + minecraft.font()->drawShadow(_msg, (float)center, (float)(height / 2 - 32), 0xffffffff); } void buttonClicked(Button* button) { if (button->id == _back->id) { - minecraft->leaveGame(); + minecraft.leaveGame(); } } bool isInGameScreen() { return false; } diff --git a/src/client/gui/screens/FurnaceScreen.cpp b/src/client/gui/screens/FurnaceScreen.cpp index 6d3e5ec..831fe02 100755 --- a/src/client/gui/screens/FurnaceScreen.cpp +++ b/src/client/gui/screens/FurnaceScreen.cpp @@ -2,7 +2,7 @@ #include "crafting/PaneCraftingScreen.hpp" #include "client/gui/Screen.hpp" #include "client/gui/components/NinePatch.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/entity/ItemRenderer.hpp" @@ -115,7 +115,7 @@ void FurnaceScreen::init() { buttons.push_back(&btnClose); // GUI - nine patches - NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png"); + NinePatchFactory builder(minecraft.textures() "gui/spritesheet.png"); guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4); guiSlot = builder.createSymmetrical(IntRectangle(0, 32, 8, 8), 3, 3); @@ -250,14 +250,14 @@ void FurnaceScreen::render(int xm, int ym, float a) { t.beginOverride(); t.colorABGR(0x33ffffff); t.noColor(); - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, &burnResult, (float)(btnResult.x + 7), (float)(btnResult.y + 8), true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures(), &burnResult, (float)(btnResult.x + 7), (float)(btnResult.y + 8), true); t.endOverrideAndDraw(); glDisable2(GL_BLEND); } - minecraft->font->drawWordWrap(currentItemDesc, (float)btnResult.x - 24, (float)(btnResult.y + btnResult.height + 6), descWidth, rgbActive); + minecraft.font()->drawWordWrap(currentItemDesc, (float)btnResult.x - 24, (float)(btnResult.y + btnResult.height + 6), descWidth, rgbActive); } - minecraft->textures->loadAndBindTexture("gui/spritesheet.png"); + minecraft.textures().loadAndBindTexture("gui/spritesheet.png"); int yy = btnResult.y + 8; int fpx = furnace->getLitProgress(14) + 2; int xx0 = btnIngredient.x + 8; @@ -274,7 +274,7 @@ void FurnaceScreen::buttonClicked(Button* button) { int slot = button->id; if (button == &btnClose) { - minecraft->player->closeContainer(); + minecraft.player()->closeContainer(); } if (slot >= FurnaceTileEntity::SLOT_INGREDIENT @@ -305,8 +305,8 @@ void FurnaceScreen::recheckRecipes() const FurnaceRecipes* recipes = FurnaceRecipes::getInstance(); ItemPack ip; // Check for fuel, and items to burn - if (minecraft->player && minecraft->player->inventory) { - Inventory* inv = (minecraft->player)->inventory; + if (minecraft.player() && minecraft.player()->inventory) { + Inventory* inv = (minecraft.player())->inventory; for (int i = Inventory::MAX_SELECTION_SIZE; i < inv->getContainerSize(); ++i) { if (ItemInstance* item = inv->getItem(i)) { @@ -401,8 +401,8 @@ void FurnaceScreen::updateItems() { ItemList all(listFuel.begin(), listFuel.end()); all.insert(all.end(), listIngredient.begin(), listIngredient.end()); - for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) { - ItemInstance* item = minecraft->player->inventory->getItem(i); + for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft.player()->inventory->getContainerSize(); ++i) { + ItemInstance* item = minecraft.player()->inventory->getItem(i); if (!item) continue; //LOGI("ItemInstance (%p) Id/aux/count: %d, %d, %d\n", item, item->id, item->getAuxValue(), item->count); bool added = false; @@ -481,8 +481,8 @@ void FurnaceScreen::drawSlotItemAt( Tesselator& t, const ItemInstance* item, int guiSlotMarker->draw(t, xx - 2, yy - 2); if (item && !item->isNull()) { - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, xx + 7, yy + 8, true); - minecraft->gui.renderSlotText(item, xx + 3, yy + 3, true, true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures(), item, xx + 7, yy + 8, true); + minecraft.gui().renderSlotText(item, xx + 3, yy + 3, true, true); } } @@ -494,9 +494,9 @@ ItemInstance FurnaceScreen::moveOver(const ItemInstance* item, int maxCount) { wantedCount = Mth::Min(wantedCount, maxCount); ItemInstance removed(item->id, wantedCount, item->getAuxValue()); - int oldSize = minecraft->player->inventory->getNumEmptySlots(); - if (minecraft->player->inventory->removeResource(removed)) { - int newSize = minecraft->player->inventory->getNumEmptySlots(); + int oldSize = minecraft.player()->inventory->getNumEmptySlots(); + if (minecraft.player()->inventory->removeResource(removed)) { + int newSize = minecraft.player()->inventory->getNumEmptySlots(); setIfNotSet(doRecreatePane, newSize != oldSize); return removed; } @@ -510,24 +510,24 @@ void FurnaceScreen::takeAndClearSlot( int slot ) ItemInstance blank; furnace->setItem(slot, &blank); - if (minecraft->level->isClientSide) { + if (minecraft.level->isClientSide) { ContainerSetSlotPacket p(menu->containerId, slot, blank); - minecraft->raknetInstance->send(p); + minecraft.raknetInstance->send(p); } - int oldSize = minecraft->player->inventory->getNumEmptySlots(); + int oldSize = minecraft.player()->inventory->getNumEmptySlots(); - if (!minecraft->player->inventory->add(&oldItem)) - minecraft->player->drop(new ItemInstance(oldItem), false); + if (!minecraft.player()->inventory->add(&oldItem)) + minecraft.player()->drop(new ItemInstance(oldItem), false); - int newSize = minecraft->player->inventory->getNumEmptySlots(); + int newSize = minecraft.player()->inventory->getNumEmptySlots(); setIfNotSet(doRecreatePane, newSize != oldSize); } bool FurnaceScreen::handleAddItem( int slot, const ItemInstance* item ) { ItemInstance* furnaceItem = furnace->getItem(slot); - int oldSize = minecraft->player->inventory->getNumEmptySlots(); + int oldSize = minecraft.player()->inventory->getNumEmptySlots(); if (item->id == furnaceItem->id) { // If stackable, stack them! Else deny the addition @@ -545,11 +545,11 @@ bool FurnaceScreen::handleAddItem( int slot, const ItemInstance* item ) player->containerMenu->setSlot(slot, &moved); } - if (minecraft->level->isClientSide) { + if (minecraft.level->isClientSide) { ContainerSetSlotPacket p(menu->containerId, slot, *furnaceItem); - minecraft->raknetInstance->send(p); + minecraft.raknetInstance->send(p); } - int newSize = minecraft->player->inventory->getNumEmptySlots(); + int newSize = minecraft.player()->inventory->getNumEmptySlots(); return (newSize != oldSize); } diff --git a/src/client/gui/screens/InBedScreen.cpp b/src/client/gui/screens/InBedScreen.cpp index 571fbcf..bcc74a7 100755 --- a/src/client/gui/screens/InBedScreen.cpp +++ b/src/client/gui/screens/InBedScreen.cpp @@ -1,7 +1,7 @@ #include "InBedScreen.hpp" #include "ScreenChooser.hpp" #include "client/gui/components/Button.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "platform/time.hpp" @@ -17,7 +17,7 @@ InBedScreen::~InBedScreen() { } void InBedScreen::init() { - if (/* minecraft->useTouchscreen() */ true) { + if (/* minecraft.useTouchscreen() */ true) { bWakeUp = new Touch::TButton(1, "Leave Bed"); } else { bWakeUp = new Button(1, "Leave Bed"); @@ -43,7 +43,7 @@ void InBedScreen::render( int xm, int ym, float a ) { void InBedScreen::buttonClicked( Button* button ) { if (button == bWakeUp) { - minecraft->player->stopSleepInBed(true, true, true); - minecraft->setScreen(NULL); + minecraft.player()->stopSleepInBed(true, true, true); + minecraft.setScreen(NULL); } } diff --git a/src/client/gui/screens/IngameBlockSelectionScreen.cpp b/src/client/gui/screens/IngameBlockSelectionScreen.cpp index a797159..271303d 100755 --- a/src/client/gui/screens/IngameBlockSelectionScreen.cpp +++ b/src/client/gui/screens/IngameBlockSelectionScreen.cpp @@ -2,7 +2,7 @@ #include "client/renderer/TileRenderer.hpp" #include "client/player/LocalPlayer.hpp" #include "client/renderer/gles.hpp" -#include "client/Minecraft.hpp" +#include #include "client/sound/SoundEngine.hpp" #include "world/entity/player/Inventory.hpp" #include "platform/input/Mouse.hpp" @@ -32,8 +32,8 @@ IngameBlockSelectionScreen::IngameBlockSelectionScreen() void IngameBlockSelectionScreen::init() { - Inventory* inventory = minecraft->player->inventory; - InventoryCols = minecraft->isCreativeMode()? 13 : 9; + Inventory* inventory = minecraft.player()->inventory; + InventoryCols = minecraft.isCreativeMode()? 13 : 9; InventorySize = inventory->getContainerSize() - Inventory::MAX_SELECTION_SIZE; InventoryRows = 1 + (InventorySize - 1) / InventoryCols; @@ -49,7 +49,7 @@ void IngameBlockSelectionScreen::init() } for (int i = Inventory::MAX_SELECTION_SIZE; i < InventorySize; i++) { - if (selected == minecraft->player->inventory->getItem(i)) + if (selected == minecraft.player()->inventory->getItem(i)) { selectedItem = i - Inventory::MAX_SELECTION_SIZE; break; @@ -58,7 +58,7 @@ void IngameBlockSelectionScreen::init() if (!isAllowed(selectedItem)) selectedItem = 0; - if (!minecraft->isCreativeMode()) { + if (!minecraft.isCreativeMode()) { bArmor.width = 42; bArmor.x = 0; bArmor.y = height - bArmor.height; @@ -68,7 +68,7 @@ void IngameBlockSelectionScreen::init() void IngameBlockSelectionScreen::removed() { - minecraft->gui.inventoryUpdated(); + minecraft.gui().inventoryUpdated(); } void IngameBlockSelectionScreen::renderSlots() @@ -86,7 +86,7 @@ void IngameBlockSelectionScreen::renderSlots() //Lighting::turnOn(); //glPopMatrix2(); - minecraft->textures->loadAndBindTexture("gui/gui.png"); + minecraft.textures().loadAndBindTexture("gui/gui.png"); for (int r = 0; r < InventoryRows; r++) { int x = getSlotPosX(0) - 3; @@ -146,18 +146,18 @@ int IngameBlockSelectionScreen::getSlotPosY(int slotY) { void IngameBlockSelectionScreen::renderSlot(int slot, int x, int y, float a) { - ItemInstance* item = minecraft->player->inventory->getItem(slot); + ItemInstance* item = minecraft.player()->inventory->getItem(slot); if (!item) return; - ItemRenderer::renderGuiItem(minecraft->font, minecraft->textures, item, (float)x, (float)y, true); + ItemRenderer::renderGuiItem(minecraft.font(), minecraft.textures() item, (float)x, (float)y, true); - if (minecraft->gameMode->isCreativeType()) return; + if (minecraft.gameMode->isCreativeType()) return; if (!isAllowed(slot - Inventory::MAX_SELECTION_SIZE)) return; glPushMatrix2(); glScalef2(Gui::InvGuiScale + Gui::InvGuiScale, Gui::InvGuiScale + Gui::InvGuiScale, 1); const float k = 0.5f * Gui::GuiScale; - minecraft->gui.renderSlotText(item, k*x, k*y, true, true); + minecraft.gui().renderSlotText(item, k*x, k*y, true, true); glPopMatrix2(); } @@ -168,7 +168,7 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey) int tmpSelectedSlot = selectedItem; - Options& o = minecraft->options; + Options& o = minecraft.options(); if (eventKey == o.getIntValue(OPTIONS_KEY_LEFT) && selX > 0) { tmpSelectedSlot -= 1; @@ -195,10 +195,10 @@ void IngameBlockSelectionScreen::keyPressed(int eventKey) #ifdef RPI if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL) || eventKey == Keyboard::KEY_ESCAPE) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); #else if (eventKey == o.getIntValue(OPTIONS_KEY_MENU_CANCEL)) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); #endif } @@ -245,7 +245,7 @@ void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) if (isAllowed(slot)) { selectedItem = slot; - //minecraft->soundEngine->playUI("random.click", 1, 1); + //minecraft.soundEngine()->playUI("random.click", 1, 1); } else { _pendingQuit = !_area.isInside((float)x, (float)y) && !bArmor.isInside(x, y); @@ -265,7 +265,7 @@ void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) selectSlotAndClose(); } else { if (_pendingQuit && !_area.isInside((float)x, (float)y)) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); } } if (!_pendingQuit) @@ -274,15 +274,15 @@ void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) void IngameBlockSelectionScreen::selectSlotAndClose() { - Inventory* inventory = minecraft->player->inventory; + Inventory* inventory = minecraft.player()->inventory; // Flash the selected gui item //inventory->moveToSelectedSlot(selectedItem + Inventory::MAX_SELECTION_SIZE, true); inventory->moveToSelectionSlot(0, selectedItem + Inventory::MAX_SELECTION_SIZE, true); inventory->selectSlot(0); - minecraft->gui.flashSlot(inventory->selected); + minecraft.gui().flashSlot(inventory->selected); - minecraft->soundEngine->playUI("random.click", 1, 1); - minecraft->setScreen(NULL); + minecraft.soundEngine()->playUI("random.click", 1, 1); + minecraft.setScreen(NULL); } void IngameBlockSelectionScreen::render( int xm, int ym, float a ) @@ -313,7 +313,7 @@ void IngameBlockSelectionScreen::renderDemoOverlay() { const int centerX = (getSlotPosX(4) + getSlotPosX(5)) / 2; const int centerY = (getSlotPosY(3) + getSlotPosY(InventoryRows-1)) / 2 + 5; - drawCenteredString(minecraft->font, demoVersionString, centerX, centerY, 0xffffffff); + drawCenteredString(minecraft.font(), demoVersionString, centerX, centerY, 0xffffffff); #endif /*DEMO_MODE*/ } @@ -322,7 +322,7 @@ bool IngameBlockSelectionScreen::isAllowed(int slot) { return false; #ifdef DEMO_MODE - return slot < (minecraft->isCreativeMode()? 28 : 27); + return slot < (minecraft.isCreativeMode()? 28 : 27); #endif /*DEMO_MODE*/ return true; @@ -335,7 +335,7 @@ int IngameBlockSelectionScreen::getSlotHeight() { void IngameBlockSelectionScreen::buttonClicked( Button* button ) { if (button == &bArmor) { - minecraft->setScreen(new ArmorScreen()); + minecraft.setScreen(new ArmorScreen()); } super::buttonClicked(button); } diff --git a/src/client/gui/screens/JoinByIPScreen.cpp b/src/client/gui/screens/JoinByIPScreen.cpp index 3c9bb27..af32464 100644 --- a/src/client/gui/screens/JoinByIPScreen.cpp +++ b/src/client/gui/screens/JoinByIPScreen.cpp @@ -28,21 +28,21 @@ void JoinByIPScreen::buttonClicked(Button* button) { if (button->id == bJoin.id) { - minecraft->isLookingForMultiplayer = true; - minecraft->netCallback = new ClientSideNetworkHandler(minecraft, minecraft->raknetInstance); + minecraft.isLookingForMultiplayer = true; + minecraft.netCallback = new ClientSideNetworkHandler(minecraft, minecraft.raknetInstance); - minecraft->joinMultiplayerFromString(tIP.text); + minecraft.joinMultiplayerFromString(tIP.text); { - minecraft->options.set(OPTIONS_LAST_IP, tIP.text); + minecraft.options().set(OPTIONS_LAST_IP, tIP.text); bJoin.active = false; bBack.active = false; - minecraft->setScreen(new ProgressScreen()); + minecraft.setScreen(new ProgressScreen()); } } if (button->id == bBack.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } } @@ -50,7 +50,7 @@ bool JoinByIPScreen::handleBackEvent(bool isDown) { if (!isDown) { - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } return true; } @@ -82,7 +82,7 @@ void JoinByIPScreen::init() tabButtons.push_back(&bHeader); #endif - tIP.text = minecraft->options.getStringValue(OPTIONS_LAST_IP); + tIP.text = minecraft.options().getStringValue(OPTIONS_LAST_IP); } void JoinByIPScreen::setupPositions() { @@ -116,7 +116,7 @@ void JoinByIPScreen::render( int xm, int ym, float a ) void JoinByIPScreen::keyPressed(int eventKey) { if (eventKey == Keyboard::KEY_ESCAPE) { - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); return; } // let base class handle navigation and text box keys diff --git a/src/client/gui/screens/JoinByIPScreen.hpp b/src/client/gui/screens/JoinByIPScreen.hpp index 42ef2a1..4fb7386 100644 --- a/src/client/gui/screens/JoinByIPScreen.hpp +++ b/src/client/gui/screens/JoinByIPScreen.hpp @@ -1,7 +1,7 @@ #include "client/gui/Screen.hpp" #include "client/gui/components/Button.hpp" -#include "client/Minecraft.hpp" +#include #include "client/gui/components/ImageButton.hpp" #include "client/gui/components/TextBox.hpp" diff --git a/src/client/gui/screens/JoinGameScreen.cpp b/src/client/gui/screens/JoinGameScreen.cpp index f45bb01..8658eec 100755 --- a/src/client/gui/screens/JoinGameScreen.cpp +++ b/src/client/gui/screens/JoinGameScreen.cpp @@ -25,20 +25,20 @@ void JoinGameScreen::buttonClicked(Button* button) if (isIndexValid(gamesList->selectedItem)) { PingedCompatibleServer selectedServer = gamesList->copiedServerList[gamesList->selectedItem]; - minecraft->joinMultiplayer(selectedServer); + minecraft.joinMultiplayer(selectedServer); { bJoin.active = false; bBack.active = false; - minecraft->setScreen(new ProgressScreen()); + minecraft.setScreen(new ProgressScreen()); } } - //minecraft->locateMultiplayer(); - //minecraft->setScreen(new JoinGameScreen()); + //minecraft.locateMultiplayer(); + //minecraft.setScreen(new JoinGameScreen()); } if (button->id == bBack.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } } @@ -46,8 +46,8 @@ bool JoinGameScreen::handleBackEvent(bool isDown) { if (!isDown) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } return true; } @@ -60,7 +60,7 @@ bool JoinGameScreen::isIndexValid( int index ) void JoinGameScreen::tick() { - const ServerList& orgServerList = minecraft->raknetInstance->getServerList(); + const ServerList& orgServerList = minecraft.raknetInstance->getServerList(); ServerList serverList; for (unsigned int i = 0; i < orgServerList.size(); ++i) if (orgServerList[i].name.GetLength() > 0) @@ -108,7 +108,7 @@ void JoinGameScreen::init() buttons.push_back(&bJoin); buttons.push_back(&bBack); - minecraft->raknetInstance->clearServerList(); + minecraft.raknetInstance->clearServerList(); gamesList = new AvailableGamesList(minecraft, width, height); #ifdef ANDROID @@ -134,7 +134,7 @@ void JoinGameScreen::setupPositions() { void JoinGameScreen::render( int xm, int ym, float a ) { - bool hasNetwork = minecraft->platform()->isNetworkEnabled(true); + bool hasNetwork = minecraft.platform()->isNetworkEnabled(true); #ifdef WIN32 hasNetwork = hasNetwork && !GetAsyncKeyState(VK_TAB); #endif @@ -149,18 +149,18 @@ void JoinGameScreen::render( int xm, int ym, float a ) #else std::string s = "Scanning for WiFi Games..."; #endif - drawCenteredString(minecraft->font, s, width / 2, 8, 0xffffffff); + drawCenteredString(minecraft.font(), s, width / 2, 8, 0xffffffff); - const int textWidth = minecraft->font->width(s); + const int textWidth = minecraft.font()->width(s); const int spinnerX = width/2 + textWidth / 2 + 6; static const char* spinnerTexts[] = {"-", "\\", "|", "/"}; int n = ((int)(5.5f * getTimeS()) % 4); - drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, 8, 0xffffffff); + drawCenteredString(minecraft.font(), spinnerTexts[n], spinnerX, 8, 0xffffffff); } else { std::string s = "WiFi is disabled"; const int yy = height / 2 - 8; - drawCenteredString(minecraft->font, s, width / 2, yy, 0xffffffff); + drawCenteredString(minecraft.font(), s, width / 2, yy, 0xffffffff); } } diff --git a/src/client/gui/screens/JoinGameScreen.hpp b/src/client/gui/screens/JoinGameScreen.hpp index 119877f..ac980fc 100755 --- a/src/client/gui/screens/JoinGameScreen.hpp +++ b/src/client/gui/screens/JoinGameScreen.hpp @@ -3,7 +3,7 @@ #include "client/gui/Screen.hpp" #include "client/gui/components/Button.hpp" #include "client/gui/components/ScrolledSelectionList.hpp" -#include "client/Minecraft.hpp" +#include #include "network/RakNetInstance.hpp" @@ -18,7 +18,7 @@ class AvailableGamesList : public ScrolledSelectionList public: - AvailableGamesList(Minecraft* _minecraft, int _width, int _height) + AvailableGamesList(MinecraftClient& _minecraft, int _width, int _height) : ScrolledSelectionList(_minecraft, _width, _height, 24, _height - 30, 28) { } @@ -35,8 +35,8 @@ protected: { const PingedCompatibleServer& s = copiedServerList[i]; unsigned int color = s.isSpecial? 0xff00b0 : 0xffffa0; - drawString(minecraft->font, s.name.C_String(), x, y + 2, color); - drawString(minecraft->font, s.address.ToString(false), x, y + 16, 0xffffa0); + drawString(minecraft.font(), s.name.C_String(), x, y + 2, color); + drawString(minecraft.font(), s.address.ToString(false), x, y + 16, 0xffffa0); } }; diff --git a/src/client/gui/screens/OptionsScreen.cpp b/src/client/gui/screens/OptionsScreen.cpp index da01fa0..ce149ac 100755 --- a/src/client/gui/screens/OptionsScreen.cpp +++ b/src/client/gui/screens/OptionsScreen.cpp @@ -3,7 +3,7 @@ #include "StartMenuScreen.hpp" #include "UsernameScreen.hpp" #include "DialogDefinitions.hpp" -#include "client/Minecraft.hpp" +#include #include "AppPlatform.hpp" #include "CreditsScreen.hpp" @@ -34,14 +34,14 @@ OptionsScreen::~OptionsScreen() { btnCredits = NULL; } - for (std::vector::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { + for (auto it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { if (*it != NULL) { delete* it; *it = NULL; } } - for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { + for (auto it = optionPanes.begin(); it != optionPanes.end(); ++it) { if (*it != NULL) { delete* it; *it = NULL; @@ -76,7 +76,7 @@ void OptionsScreen::init() { buttons.push_back(btnClose); buttons.push_back(btnCredits); - for (std::vector::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { + for (auto it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { buttons.push_back(*it); tabButtons.push_back(*it); } @@ -94,7 +94,7 @@ void OptionsScreen::setupPositions() { int offsetNum = 1; - for (std::vector::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { + for (auto it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { (*it)->x = 0; (*it)->y = offsetNum * buttonHeight; @@ -114,7 +114,7 @@ void OptionsScreen::setupPositions() { btnCredits->y = height - btnCredits->height; } - for (std::vector::iterator it = optionPanes.begin(); it != optionPanes.end(); ++it) { + for (auto it = optionPanes.begin(); it != optionPanes.end(); ++it) { if (categoryButtons.size() > 0 && categoryButtons[0] != NULL) { @@ -133,8 +133,8 @@ void OptionsScreen::setupPositions() { void OptionsScreen::render(int xm, int ym, float a) { renderBackground(); - int xmm = xm * width / minecraft->width; - int ymm = ym * height / minecraft->height - 1; + int xmm = xm * width / minecraft.getScreenWidth(); + int ymm = ym * height / minecraft.getScreenHeight() - 1; if (currentOptionsGroup != NULL) currentOptionsGroup->render(minecraft, xmm, ymm); @@ -147,11 +147,11 @@ void OptionsScreen::removed() { void OptionsScreen::buttonClicked(Button* button) { if (button == btnClose) { - minecraft->options.save(); - if (minecraft->screen != NULL) { - minecraft->setScreen(NULL); + minecraft.options().save(); + if (minecraft.getScreen()!= NULL) { + minecraft.setScreen(NULL); } else { - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } } else if (button->id > 1 && button->id < 7) { @@ -159,14 +159,14 @@ void OptionsScreen::buttonClicked(Button* button) { selectCategory(categoryButton); } else if (button == btnCredits) { - minecraft->setScreen(new CreditsScreen()); + minecraft.setScreen(new CreditsScreen()); } } void OptionsScreen::selectCategory(int index) { int currentIndex = 0; - for (std::vector::iterator it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { + for (auto it = categoryButtons.begin(); it != categoryButtons.end(); ++it) { if (index == currentIndex) (*it)->selected = true; @@ -246,7 +246,7 @@ void OptionsScreen::keyPressed(int eventKey) { if (currentOptionsGroup != NULL) currentOptionsGroup->keyPressed(minecraft, eventKey); if (eventKey == Keyboard::KEY_ESCAPE) - minecraft->options.save(); + minecraft.options().save(); super::keyPressed(eventKey); } diff --git a/src/client/gui/screens/PauseScreen.cpp b/src/client/gui/screens/PauseScreen.cpp index 83b0e9d..4cc1140 100755 --- a/src/client/gui/screens/PauseScreen.cpp +++ b/src/client/gui/screens/PauseScreen.cpp @@ -1,7 +1,7 @@ #include "PauseScreen.hpp" #include "StartMenuScreen.hpp" #include "client/gui/components/ImageButton.hpp" -#include "client/Minecraft.hpp" +#include #include "util/Mth.hpp" #include "network/RakNetInstance.hpp" #include "network/ServerSideNetworkHandler.hpp" @@ -48,7 +48,7 @@ PauseScreen::~PauseScreen() { } void PauseScreen::init() { - if (/* minecraft->useTouchscreen() */ true) { + if (/* minecraft.useTouchscreen() */ true) { bContinue = new Touch::TButton(1, "Back to game"); bOptions = new Touch::TButton(5, "Options"); bQuit = new Touch::TButton(2, "Quit to title"); @@ -67,9 +67,9 @@ void PauseScreen::init() { buttons.push_back(bContinue); buttons.push_back(bQuit); buttons.push_back(bOptions); - // bSound.updateImage(&minecraft->options); - bThirdPerson.updateImage(&minecraft->options); - bHideGui.updateImage(&minecraft->options); + // bSound.updateImage(&minecraft.options); + bThirdPerson.updateImage(&minecraft.options); + bHideGui.updateImage(&minecraft.options); // buttons.push_back(&bSound); buttons.push_back(&bThirdPerson); //buttons.push_back(&bHideGui); @@ -79,8 +79,8 @@ void PauseScreen::init() { #if !defined(APPLE_DEMO_PROMOTION) && !defined(RPI) if (true || !wasBackPaused) { - if (minecraft->raknetInstance) { - if (minecraft->raknetInstance->isServer()) { + if (minecraft.raknetInstance) { + if (minecraft.raknetInstance->isServer()) { updateServerVisibilityText(); buttons.push_back(bServerVisibility); } @@ -142,7 +142,7 @@ void PauseScreen::tick() { void PauseScreen::render(int xm, int ym, float a) { renderBackground(); - //bool isSaving = !minecraft->level.pauseSave(saveStep++); + //bool isSaving = !minecraft.level.pauseSave(saveStep++); //if (isSaving || visibleTime < 20) { // float col = ((visibleTime % 10) + a) / 10.0f; // col = Mth::sin(col * Mth::PI * 2) * 0.2f + 0.8f; @@ -158,21 +158,21 @@ void PauseScreen::render(int xm, int ym, float a) { void PauseScreen::buttonClicked(Button* button) { if (button->id == bContinue->id) { - minecraft->setScreen(NULL); - //minecraft->grabMouse(); + minecraft.setScreen(NULL); + //minecraft.grabMouse(); } if (button->id == bQuit->id) { - minecraft->leaveGame(); + minecraft.leaveGame(); } if (button->id == bQuitAndSaveLocally->id) { - minecraft->leaveGame(true); + minecraft.leaveGame(true); } if (button->id == bOptions->id) { - minecraft->setScreen(new OptionsScreen()); + minecraft.setScreen(new OptionsScreen()); } if (button->id == bServerVisibility->id) { - if (minecraft->raknetInstance && minecraft->netCallback && minecraft->raknetInstance->isServer()) { - ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback; + if (minecraft.raknetInstance && minecraft.netCallback && minecraft.raknetInstance->isServer()) { + ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft.netCallback; bool allows = !ss->allowsIncomingConnections(); ss->allowIncomingConnections(allows); @@ -181,20 +181,20 @@ void PauseScreen::buttonClicked(Button* button) { } if (button->id == OptionButton::ButtonId) { - ((OptionButton*)button)->toggle(&minecraft->options); + ((OptionButton*)button)->toggle(&minecraft.options); } //if (button->id == bThirdPerson->id) { - // minecraft->options.thirdPersonView = !minecraft->options.thirdPersonView; + // minecraft.options().thirdPersonView = !minecraft.options().thirdPersonView; //} } void PauseScreen::updateServerVisibilityText() { - if (!minecraft->raknetInstance || !minecraft->raknetInstance->isServer()) + if (!minecraft.raknetInstance || !minecraft.raknetInstance->isServer()) return; - ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft->netCallback; + ServerSideNetworkHandler* ss = (ServerSideNetworkHandler*) minecraft.netCallback; bServerVisibility->msg = ss->allowsIncomingConnections()? "Server is visible" : "Server is invisible"; diff --git a/src/client/gui/screens/PrerenderTilesScreen.hpp b/src/client/gui/screens/PrerenderTilesScreen.hpp index 595025d..22ad37d 100755 --- a/src/client/gui/screens/PrerenderTilesScreen.hpp +++ b/src/client/gui/screens/PrerenderTilesScreen.hpp @@ -18,7 +18,7 @@ class PrerenderTilesScreen: public Screen { public: void init() { - Player p(minecraft->level, true); + Player p(minecraft.level, true); Inventory _inventory(&p, true); Inventory* inventory = &_inventory; @@ -93,21 +93,21 @@ public: int y = j/16 * 16; //Tesselator::instance.color(0xffffffff); - //minecraft->textures->loadAndBindTexture("gui/gui2.png"); + //minecraft.textures().loadAndBindTexture("gui/gui2.png"); //glColor4f2(0.2f, 0.5f, 0.2f, 1); //blit(x, y, 4 + 20 * (i%9), 4, 16, 16, 15, 15); //glColor4f2(1, 1, 1, 1); if (item->id < 256 && TileRenderer::canRender(Tile::tiles[item->id]->getRenderShape())) { LOGI("0, %d, %d, %d, 0\n", j, item->id, item->getAuxValue()); - ItemRenderer::renderGuiItemCorrect(minecraft->font, minecraft->textures, item, x, y); + ItemRenderer::renderGuiItemCorrect(minecraft.font(), minecraft.textures() item, x, y); } else if (item->getIcon() >= 0) { LOGI("1, %d, %d, %d, %d\n", j, item->id, item->getAuxValue(), item->getIcon()); } ++j; }*/ int j = 0; - for(std::vector::iterator i = mItems.begin(); i != mItems.end(); ++i) { + for(auto i = mItems.begin(); i != mItems.end(); ++i) { ItemInstance* item = &(*i); //LOGI("desc: %d - %s. %d\n", i, item->toString().c_str()); @@ -116,7 +116,7 @@ public: int y = j/16 * 16; if (item->id < 256 && TileRenderer::canRender(Tile::tiles[item->id]->getRenderShape())) { LOGI("0, %d, %d, %d, 0\n", j, item->id, item->getAuxValue()); - ItemRenderer::renderGuiItemCorrect(minecraft->font, minecraft->textures, item, x, y); + ItemRenderer::renderGuiItemCorrect(minecraft.font(), minecraft.textures() item, x, y); } else if (item->getIcon() >= 0) { LOGI("1, %d, %d, %d, %d\n", j, item->id, item->getAuxValue(), item->getIcon()); } @@ -139,7 +139,7 @@ public: if (item->getAuxValue() < 0) return; bool found = false; - for(std::vector::iterator i = mItems.begin(); i != mItems.end(); ++i) { + for(auto i = mItems.begin(); i != mItems.end(); ++i) { ItemInstance *jitem = &*i; if(jitem->id != item->id) continue; if(jitem->isStackedByData() && jitem->getAuxValue() != item->getAuxValue()) continue; diff --git a/src/client/gui/screens/ProgressScreen.cpp b/src/client/gui/screens/ProgressScreen.cpp index 984161c..5f355da 100755 --- a/src/client/gui/screens/ProgressScreen.cpp +++ b/src/client/gui/screens/ProgressScreen.cpp @@ -2,7 +2,7 @@ #include "DisconnectionScreen.hpp" #include "client/gui/Gui.hpp" #include "client/gui/Font.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Tesselator.hpp" #include "SharedConstants.hpp" #include "client/renderer/Textures.hpp" @@ -14,15 +14,15 @@ ProgressScreen::ProgressScreen() void ProgressScreen::render( int xm, int ym, float a ) { - if (minecraft->isLevelGenerated()) { - minecraft->setScreen(NULL); + if (minecraft.isLevelGenerated()) { + minecraft.setScreen(NULL); return; } Tesselator& t = Tesselator::instance; renderBackground(); - minecraft->textures->loadAndBindTexture("gui/background.png"); + minecraft.textures().loadAndBindTexture("gui/background.png"); const float s = 32; t.begin(); @@ -33,7 +33,7 @@ void ProgressScreen::render( int xm, int ym, float a ) t.vertexUV(0, 0, 0, 0, 0); t.draw(); - int i = minecraft->progressStagePercentage; + int i = minecraft.progressStagePercentage; if (i >= 0) { int w = 100; @@ -63,26 +63,26 @@ void ProgressScreen::render( int xm, int ym, float a ) glEnable2(GL_BLEND); const char* title = "Generating world"; - minecraft->font->drawShadow(title, (float)((width - minecraft->font->width(title)) / 2), (float)(height / 2 - 4 - 16), 0xffffff); + minecraft.font()->drawShadow(title, (float)((width - minecraft.font()->width(title)) / 2), (float)(height / 2 - 4 - 16), 0xffffff); - const char* status = minecraft->getProgressMessage(); - const int progressWidth = minecraft->font->width(status); + const char* status = minecraft.getProgressMessage(); + const int progressWidth = minecraft.font()->width(status); const int progressLeft = (width - progressWidth) / 2; const int progressY = height / 2 - 4 + 8; - minecraft->font->drawShadow(status, (float)progressLeft, (float)progressY, 0xffffff); + minecraft.font()->drawShadow(status, (float)progressLeft, (float)progressY, 0xffffff); #if APPLE_DEMO_PROMOTION - drawCenteredString(minecraft->font, "This demonstration version", width/2, progressY + 36, 0xffffff); - drawCenteredString(minecraft->font, "does not allow saving games", width/2, progressY + 46, 0xffffff); + drawCenteredString(minecraft.font(), "This demonstration version", width/2, progressY + 36, 0xffffff); + drawCenteredString(minecraft.font(), "does not allow saving games", width/2, progressY + 46, 0xffffff); #endif // If we're locating the server, show our famous spinner! - bool isLocating = (minecraft->getProgressStatusId() == 0); + bool isLocating = (minecraft.getProgressStatusId() == 0); if (isLocating) { const int spinnerX = progressLeft + progressWidth + 6; static const char* spinnerTexts[] = {"-", "\\", "|", "/"}; int n = ((int)(5.5f * getTimeS()) % 4); - drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, progressY, 0xffffffff); + drawCenteredString(minecraft.font(), spinnerTexts[n], spinnerX, progressY, 0xffffffff); } glDisable2(GL_BLEND); @@ -93,7 +93,7 @@ bool ProgressScreen::isInGameScreen() { return false; } void ProgressScreen::tick() { // After 10 seconds of not connecting -> write an error message and go back - if (++ticks == 10 * SharedConstants::TicksPerSecond && minecraft->getProgressStatusId() == 0) { - minecraft->setScreen( new DisconnectionScreen("Could not connect to server. Try again.") ); + if (++ticks == 10 * SharedConstants::TicksPerSecond && minecraft.getProgressStatusId() == 0) { + minecraft.setScreen( new DisconnectionScreen("Could not connect to server. Try again.") ); } } diff --git a/src/client/gui/screens/ScreenChooser.cpp b/src/client/gui/screens/ScreenChooser.cpp index afaf8e9..7776ccf 100755 --- a/src/client/gui/screens/ScreenChooser.cpp +++ b/src/client/gui/screens/ScreenChooser.cpp @@ -13,7 +13,7 @@ #include "touch/TouchJoinGameScreen.hpp" #include "touch/TouchIngameBlockSelectionScreen.hpp" -#include "client/Minecraft.hpp" +#include #include @@ -22,7 +22,7 @@ Screen* ScreenChooser::createScreen( ScreenId id ) Screen* screen = NULL; // :sob: - if (/* _mc->useTouchscreen() */ true) { + if (/* _mc.useTouchscreen() */ true) { switch (id) { case SCREEN_STARTMENU: screen = new Touch::StartMenuScreen(); break; case SCREEN_SELECTWORLD: screen = new Touch::SelectWorldScreen();break; diff --git a/src/client/gui/screens/SelectWorldScreen.cpp b/src/client/gui/screens/SelectWorldScreen.cpp index f6df45a..1f3cb50 100755 --- a/src/client/gui/screens/SelectWorldScreen.cpp +++ b/src/client/gui/screens/SelectWorldScreen.cpp @@ -65,12 +65,12 @@ void WorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator& t ) const int TX = centerx - itemWidth / 2 + 5; StringVector v = _descriptions[i]; - drawString(minecraft->font, v[0].c_str(), TX, TY + 0, textColor); - drawString(minecraft->font, v[1].c_str(), TX, TY + 10, textColor2); - drawString(minecraft->font, v[2].c_str(), TX, TY + 20, textColor2); - drawString(minecraft->font, v[3].c_str(), TX, TY + 30, textColor2); + drawString(minecraft.font(), v[0].c_str(), TX, TY + 0, textColor); + drawString(minecraft.font(), v[1].c_str(), TX, TY + 10, textColor2); + drawString(minecraft.font(), v[2].c_str(), TX, TY + 20, textColor2); + drawString(minecraft.font(), v[3].c_str(), TX, TY + 30, textColor2); - minecraft->textures->loadAndBindTexture(_imageNames[i]); + minecraft.textures().loadAndBindTexture(_imageNames[i]); t.color(0.3f, 1.0f, 0.2f); //float x0 = (float)x; @@ -114,7 +114,7 @@ void WorldSelectionList::commit() { std::stringstream ss; ss << level.name << "/preview.png"; - TextureId id = Textures::InvalidId;//minecraft->textures->loadTexture(ss.str(), false); + TextureId id = Textures::InvalidId;//minecraft.textures().loadTexture(ss.str(), false); if (id != Textures::InvalidId) { _imageNames.push_back( ss.str() ); @@ -124,7 +124,7 @@ void WorldSelectionList::commit() { StringVector lines; lines.push_back(level.name); - lines.push_back(minecraft->platform()->getDateString(level.lastPlayed)); + lines.push_back(minecraft.platform()->getDateString(level.lastPlayed)); lines.push_back(level.id); lines.push_back(LevelSettings::gameTypeToString(level.gameType)); _descriptions.push_back(lines); @@ -247,19 +247,19 @@ void SelectWorldScreen::buttonClicked(Button* button) // open in-game world-creation screen instead of using platform dialog if (!_hasStartedLevel) { std::string name = getUniqueLevelName("world"); - minecraft->setScreen(new SimpleChooseLevelScreen(name)); + minecraft.setScreen(new SimpleChooseLevelScreen(name)); } } if (button->id == bDelete.id) { if (isIndexValid(worldsList->selectedItem)) { LevelSummary level = worldsList->levels[worldsList->selectedItem]; LOGI("level: %s, %s\n", level.id.c_str(), level.name.c_str()); - minecraft->setScreen( new DeleteWorldScreen(level) ); + minecraft.setScreen( new DeleteWorldScreen(level) ); } } if (button->id == bBack.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser().setScreen(SCREEN_STARTMENU); } if (button->id == bWorldView.id) { // Try to "click" the item in the middle @@ -271,8 +271,8 @@ bool SelectWorldScreen::handleBackEvent(bool isDown) { if (!isDown) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser().setScreen(SCREEN_STARTMENU); } return true; } @@ -291,9 +291,9 @@ void SelectWorldScreen::tick() worldsList->tick(); if (worldsList->hasPickedLevel) { - minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None()); - minecraft->hostMultiplayer(); - minecraft->setScreen(new ProgressScreen()); + minecraft.selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None()); + minecraft.hostMultiplayer(); + minecraft.setScreen(new ProgressScreen()); _hasStartedLevel = true; return; } @@ -379,7 +379,7 @@ void SelectWorldScreen::render( int xm, int ym, float a ) //Performance::watches.get("sws-screen").stop(); //Performance::watches.get("sws-string").start(); - drawCenteredString(minecraft->font, "Select world", width / 2, 8, 0xffffffff); + drawCenteredString(minecraft.font(), "Select world", width / 2, 8, 0xffffffff); //Performance::watches.get("sws-string").stop(); //Performance::watches.get("sws-full").stop(); @@ -388,7 +388,7 @@ void SelectWorldScreen::render( int xm, int ym, float a ) void SelectWorldScreen::loadLevelSource() { - LevelStorageSource* levelSource = minecraft->getLevelSource(); + LevelStorageSource* levelSource = minecraft.getLevelSource(); levelSource->getLevelList(levels); std::sort(levels.begin(), levels.end()); @@ -438,9 +438,9 @@ void SelectWorldScreen::mouseWheel(int dx, int dy, int xm, int ym) void SelectWorldScreen::keyPressed( int eventKey ) { if (bWorldView.selected) { - if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT)) + if (eventKey == minecraft.options().getIntValue(OPTIONS_KEY_RIGHT)) worldsList->stepLeft(); - if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT)) + if (eventKey == minecraft.options().getIntValue(OPTIONS_KEY_LEFT)) worldsList->stepRight(); } @@ -462,8 +462,8 @@ DeleteWorldScreen::DeleteWorldScreen(const LevelSummary& level) void DeleteWorldScreen::postResult( bool isOk ) { if (isOk) { - LevelStorageSource* storageSource = minecraft->getLevelSource(); + LevelStorageSource* storageSource = minecraft.getLevelSource(); storageSource->deleteLevel(_level.id); } - minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD); + minecraft.screenChooser().setScreen(SCREEN_SELECTWORLD); } diff --git a/src/client/gui/screens/SimpleChooseLevelScreen.cpp b/src/client/gui/screens/SimpleChooseLevelScreen.cpp index 64c3abe..248e003 100755 --- a/src/client/gui/screens/SimpleChooseLevelScreen.cpp +++ b/src/client/gui/screens/SimpleChooseLevelScreen.cpp @@ -3,7 +3,7 @@ #include "ScreenChooser.hpp" #include "client/gui/components/Button.hpp" #include "client/gui/components/ImageButton.hpp" -#include "client/Minecraft.hpp" +#include #include "world/level/LevelSettings.hpp" #include "platform/time.hpp" #include "platform/input/Keyboard.hpp" @@ -56,7 +56,7 @@ void SimpleChooseLevelScreen::init() def.setSrc(IntRectangle(150, 0, (int)def.width, (int)def.height)); bBack->setImageDef(def, true); } - if (/* minecraft->useTouchscreen() */ true) { + if (/* minecraft.useTouchscreen() */ true) { bGamemode = new Touch::TButton(1, "Survival mode"); bCheats = new Touch::TButton(4, "Cheats: Off"); bCreate = new Touch::TButton(3, "Create"); @@ -155,11 +155,11 @@ void SimpleChooseLevelScreen::render( int xm, int ym, float a ) modeDesc = "Unlimited resources and flying"; } if (modeDesc) { - drawCenteredString(minecraft->font, modeDesc, width / 2, bGamemode->y + bGamemode->height + 4, 0xffcccccc); + drawCenteredString(minecraft.font(), modeDesc, width / 2, bGamemode->y + bGamemode->height + 4, 0xffcccccc); } - drawString(minecraft->font, "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc); - drawString(minecraft->font, "World seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc); + drawString(minecraft.font(), "World name:", tLevelName.x, tLevelName.y - Font::DefaultLineHeight - 2, 0xffcccccc); + drawString(minecraft.font(), "World seed:", tSeed.x, tSeed.y - Font::DefaultLineHeight - 2, 0xffcccccc); Screen::render(xm, ym, a); glDisable2(GL_BLEND); @@ -231,22 +231,22 @@ void SimpleChooseLevelScreen::buttonClicked( Button* button ) } std::string levelId = getUniqueLevelName(tLevelName.text); LevelSettings settings(seed, gamemode, cheatsEnabled); - minecraft->selectLevel(levelId, levelId, settings); - minecraft->hostMultiplayer(); - minecraft->setScreen(new ProgressScreen()); + minecraft.selectLevel(levelId, levelId, settings); + minecraft.hostMultiplayer(); + minecraft.setScreen(new ProgressScreen()); hasChosen = true; return; } if (button == bBack) { - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } } void SimpleChooseLevelScreen::keyPressed(int eventKey) { if (eventKey == Keyboard::KEY_ESCAPE) { - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); return; } // let base class handle navigation and text box keys @@ -255,6 +255,6 @@ void SimpleChooseLevelScreen::keyPressed(int eventKey) bool SimpleChooseLevelScreen::handleBackEvent(bool isDown) { if (!isDown) - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); return true; } diff --git a/src/client/gui/screens/StartMenuScreen.cpp b/src/client/gui/screens/StartMenuScreen.cpp index ab2d6e2..27ec62e 100755 --- a/src/client/gui/screens/StartMenuScreen.cpp +++ b/src/client/gui/screens/StartMenuScreen.cpp @@ -13,7 +13,7 @@ #include "client/gui/Font.hpp" #include "client/gui/components/ScrolledSelectionList.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Tesselator.hpp" #include "AppPlatform.hpp" #include "LicenseCodes.hpp" @@ -38,7 +38,7 @@ void StartMenuScreen::init() { bJoin.active = bHost.active = bOptions.active = true; - if (minecraft->options.getStringValue(OPTIONS_USERNAME).empty()) { + if (minecraft.options().getStringValue(OPTIONS_USERNAME).empty()) { return; // tick() will redirect to UsernameScreen } @@ -72,7 +72,7 @@ void StartMenuScreen::init() // always show base version string, suffix was previously added for Android builds std::string versionString = Common::getGameVersionString(); - std::string _username = minecraft->options.getStringValue(OPTIONS_USERNAME); + std::string _username = minecraft.options().getStringValue(OPTIONS_USERNAME); if (_username.empty()) _username = "unknown"; username = "Username: " + _username; @@ -117,23 +117,23 @@ void StartMenuScreen::buttonClicked(Button* button) { if (button->id == bHost.id) { #if defined(DEMO_MODE) || defined(APPLE_DEMO_PROMOTION) - minecraft->setScreen( new SimpleChooseLevelScreen("_DemoLevel") ); + minecraft.setScreen( new SimpleChooseLevelScreen("_DemoLevel") ); #else - minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD); + minecraft.screenChooser.setScreen(SCREEN_SELECTWORLD); #endif } if (button->id == bJoin.id) { - minecraft->locateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_JOINGAME); + minecraft.locateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_JOINGAME); } if (button->id == bOptions.id) { - minecraft->setScreen(new OptionsScreen()); + minecraft.setScreen(new OptionsScreen()); } if (button == &bQuit) { - minecraft->quit(); + minecraft.quit(); } } @@ -147,14 +147,14 @@ void StartMenuScreen::render( int xm, int ym, float a ) drawString(font, username, 2, 2, 0xffffffff); #if defined(RPI) - TextureId id = minecraft->textures->loadTexture("gui/pi_title.png"); + TextureId id = minecraft.textures().loadTexture("gui/pi_title.png"); #else - TextureId id = minecraft->textures->loadTexture("gui/title.png"); + TextureId id = minecraft.textures().loadTexture("gui/title.png"); #endif - const TextureData* data = minecraft->textures->getTemporaryTextureData(id); + const TextureData* data = minecraft.textures().getTemporaryTextureData(id); if (data) { - minecraft->textures->bind(id); + minecraft.textures().bind(id); const float x = (float)width / 2; const float y = height/16; @@ -175,23 +175,23 @@ void StartMenuScreen::render( int xm, int ym, float a ) } #if defined(RPI) - if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/raknet_high_72.png"))) + if (Textures::isTextureIdValid(minecraft.textures().loadAndBindTexture("gui/logo/raknet_high_72.png"))) blit(0, height - 12, 0, 0, 43, 12, 256, 72+72); #endif - drawString(font, version, width - font->width(version) - 2, height - 10, 0xffcccccc);//0x666666); + drawString(font, version, width - font.width(version) - 2, height - 10, 0xffcccccc);//0x666666); drawString(font, copyright, 2, height - 20, 0xffffff); glEnable2(GL_BLEND); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f2(1, 1, 1, 1); - if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png"))) + if (Textures::isTextureIdValid(minecraft.textures().loadAndBindTexture("gui/logo/github.png"))) blit(2, height - 10, 0, 0, 8, 8, 256, 256); { std::string txt = "Kolyah35/minecraft-pe-0.6.1"; - float wtxt = font->width(txt); + float wtxt = font.width(txt); Gui::drawColoredString(font, txt, 12, height - 10, 255); // underline link - float y0 = height - 10 + font->lineHeight - 1; + float y0 = height - 10 + font.lineHeight - 1; this->fill(12, (int)y0, 12 + (int)wtxt, (int)(y0 + 1), 0xffffffff); } @@ -201,16 +201,16 @@ void StartMenuScreen::render( int xm, int ym, float a ) void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) { const int logoX = 2; - const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1"); + const int logoW = 8 + 2 + font.width("Kolyah35/minecraft-pe-0.6.1"); const int logoY = height - 10; const int logoH = 10; if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH) - minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1"); + minecraft.platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1"); else Screen::mouseClicked(x, y, buttonNum); } bool StartMenuScreen::handleBackEvent( bool isDown ) { - minecraft->quit(); + minecraft.quit(); return true; } diff --git a/src/client/gui/screens/TextEditScreen.cpp b/src/client/gui/screens/TextEditScreen.cpp index eeda3d6..d016783 100755 --- a/src/client/gui/screens/TextEditScreen.cpp +++ b/src/client/gui/screens/TextEditScreen.cpp @@ -1,7 +1,7 @@ #include "TextEditScreen.hpp" #include "world/level/tile/entity/SignTileEntity.hpp" #include "AppPlatform.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/tileentity/TileEntityRenderDispatcher.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/Textures.hpp" @@ -18,7 +18,7 @@ TextEditScreen::~TextEditScreen() { } void TextEditScreen::init() { super::init(); - minecraft->platform()->showKeyboard(); + minecraft.platform()->showKeyboard(); isShowingKeyboard = true; ImageDef def; def.name = "gui/spritesheet.png"; @@ -41,9 +41,9 @@ void TextEditScreen::setupPositions() { bool TextEditScreen::handleBackEvent( bool isDown ) { sign->setChanged(); Packet* signUpdatePacket = sign->getUpdatePacket(); - minecraft->raknetInstance->send(signUpdatePacket); - minecraft->platform()->hideKeyboard(); - minecraft->setScreen(NULL); + minecraft.raknetInstance->send(signUpdatePacket); + minecraft.platform()->hideKeyboard(); + minecraft.setScreen(NULL); return true; } @@ -59,17 +59,17 @@ void TextEditScreen::render( int xm, int ym, float a ) { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - glOrthof(0.0f, (float)minecraft->width, (float)minecraft->height, 0, -1, 1); + glOrthof(0.0f, (float)minecraft.getScreenWidth(), (float)minecraft.getScreenHeight(), 0, -1, 1); glMatrixMode(GL_MODELVIEW); - minecraft->textures->loadAndBindTexture("item/sign.png"); + minecraft.textures().loadAndBindTexture("item/sign.png"); glColor4f2(1, 1, 1, 1); static float minUV[] = {0.03126f, 0.06249f}; static float maxUV[] = {0.39063f, 0.4374f}; - float scale = ((minecraft->height / 2) / 32) * 0.9f; + float scale = ((minecraft.getScreenHeight() / 2) / 32) * 0.9f; - glTranslatef(minecraft->width / 2.0f, 5.0f, 0.0f); + glTranslatef(minecraft.getScreenWidth() / 2.0f, 5.0f, 0.0f); glScalef2(scale,scale,1); t.begin(GL_QUADS); t.vertexUV(-32, 0, 0.0f,minUV[0],minUV[1]); @@ -88,13 +88,13 @@ void TextEditScreen::render( int xm, int ym, float a ) { std::string msg = sign->messages[i]; if (i == sign->selectedLine && msg.length() < 14) { std::string s = "> " + msg + " <"; - font->draw(s, -(float)font->width(s) / 2.0f, 10.0f * i, 0xFF000000, false); + font.draw(s, -(float)font.width(s) / 2.0f, 10.0f * i, 0xFF000000, false); } else { - font->draw(msg, -(float)font->width(msg) / 2.0f, 10.0f * i, 0xFF000000, false); + font.draw(msg, -(float)font.width(msg) / 2.0f, 10.0f * i, 0xFF000000, false); } } sign->selectedLine = -1; - //font->draw("Hej", minecraft->width / 2, 100, 0xFFFFFFFF, false); + //font.draw("Hej", minecraft.getScreenWidth() / 2, 100, 0xFFFFFFFF, false); glPopMatrix(); glEnable(GL_CULL_FACE); diff --git a/src/client/gui/screens/UploadPhotoScreen.cpp b/src/client/gui/screens/UploadPhotoScreen.cpp index 299b317..971b33a 100755 --- a/src/client/gui/screens/UploadPhotoScreen.cpp +++ b/src/client/gui/screens/UploadPhotoScreen.cpp @@ -13,10 +13,10 @@ selectedItem(0) void UploadPhotoScreen::init() { - int currentSelection = minecraft->player->inventory->getSelectedItemId(); + int currentSelection = minecraft.player()->inventory->getSelectedItemId(); for (int i = 0; i < Inventory::INVENTORY_SIZE; i++) { - if (currentSelection == minecraft->player->inventory->getSelectionSlotItemId(i + Inventory::SELECTION_SIZE)) + if (currentSelection == minecraft.player()->inventory->getSelectionSlotItemId(i + Inventory::SELECTION_SIZE)) { selectedItem = i; break; @@ -31,7 +31,7 @@ void UploadPhotoScreen::renderSlots() blitOffset = -90; - minecraft->textures->loadAndBindTexture("gui/gui.png"); + minecraft.textures().loadAndBindTexture("gui/gui.png"); for (int r = 0; r < Inventory::INVENTORY_ROWS; r++) { blit(width / 2 - 182 / 2, height - 22 * 3 - 22 * r, 0, 0, 182, 22); @@ -56,7 +56,7 @@ void UploadPhotoScreen::renderSlots() void UploadPhotoScreen::renderSlot(int slot, int x, int y, float a) { - int itemId = minecraft->player->inventory->getSelectionSlotItemId(slot); + int itemId = minecraft.player()->inventory->getSelectionSlotItemId(slot); if (itemId < 0) return; const bool fancy = false; @@ -68,7 +68,7 @@ void UploadPhotoScreen::renderSlot(int slot, int x, int y, float a) Tile* tile = Tile::tiles[itemId]; if (tile == NULL) return; - minecraft->textures->loadAndBindTexture("terrain.png"); + minecraft.textures().loadAndBindTexture("terrain.png"); int textureId = tile->getTexture(2, 0); blit(x, y, textureId % 16 * 16, textureId / 16 * 16, 16, 16); @@ -82,7 +82,7 @@ void UploadPhotoScreen::keyPressed(int eventKey) int selX = selectedItem % Inventory::SELECTION_SIZE; int selY = selectedItem / Inventory::SELECTION_SIZE; - Options& o = minecraft->options; + Options& o = minecraft.options; if (eventKey == o.keyLeft.key && selX > 0) { selectedItem -= 1; @@ -130,7 +130,7 @@ void UploadPhotoScreen::mouseClicked(int x, int y, int buttonNum) { if (slot >= 0 && slot < Inventory::INVENTORY_SIZE) { selectedItem = slot; - //minecraft->soundEngine->playUI("random.click", 1, 1); + //minecraft.soundEngine()->playUI("random.click", 1, 1); } } } @@ -149,7 +149,7 @@ void UploadPhotoScreen::mouseReleased(int x, int y, int buttonNum) void UploadPhotoScreen::selectSlotAndClose() { - Inventory* inventory = minecraft->player->inventory; + Inventory* inventory = minecraft.player()->inventory; int itemId = inventory->getSelectionSlotItemId(selectedItem + Inventory::SELECTION_SIZE); int i = 0; @@ -170,8 +170,8 @@ void UploadPhotoScreen::selectSlotAndClose() inventory->setSelectionSlotItemId(0, itemId); inventory->selectSlot(0); - minecraft->soundEngine->playUI("random.click", 1, 1); - minecraft->setScreen(NULL); + minecraft.soundEngine()->playUI("random.click", 1, 1); + minecraft.setScreen(NULL); } #endif diff --git a/src/client/gui/screens/UsernameScreen.cpp b/src/client/gui/screens/UsernameScreen.cpp index 78f96d3..57ba048 100644 --- a/src/client/gui/screens/UsernameScreen.cpp +++ b/src/client/gui/screens/UsernameScreen.cpp @@ -1,6 +1,6 @@ #include "UsernameScreen.hpp" #include "StartMenuScreen.hpp" -#include "client/Minecraft.hpp" +#include #include "client/gui/Font.hpp" #include "client/gui/components/Button.hpp" #include "platform/input/Keyboard.hpp" @@ -66,15 +66,15 @@ void UsernameScreen::keyPressed(int eventKey) void UsernameScreen::removed() { - minecraft->platform()->hideKeyboard(); + minecraft.platform()->hideKeyboard(); } void UsernameScreen::buttonClicked(Button* button) { if (button == &_btnDone && !tUsername.text.empty()) { - minecraft->options.set(OPTIONS_USERNAME, tUsername.text); - minecraft->options.save(); - minecraft->setScreen(NULL); // goes to StartMenuScreen + minecraft.options().set(OPTIONS_USERNAME, tUsername.text); + minecraft.options().save(); + minecraft.setScreen(NULL); // goes to StartMenuScreen } } diff --git a/src/client/gui/screens/crafting/PaneCraftingScreen.cpp b/src/client/gui/screens/crafting/PaneCraftingScreen.cpp index 9cd5672..5295d3a 100755 --- a/src/client/gui/screens/crafting/PaneCraftingScreen.cpp +++ b/src/client/gui/screens/crafting/PaneCraftingScreen.cpp @@ -2,7 +2,7 @@ #include "client/gui/screens/touch/TouchStartMenuScreen.hpp" #include "client/gui/Screen.hpp" #include "client/gui/components/NinePatch.hpp" -#include "client/Minecraft.hpp" +#include #include "client/player/LocalPlayer.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/entity/ItemRenderer.hpp" @@ -37,10 +37,10 @@ public: statePressed(statePressed) {} - void renderBg(Minecraft* minecraft, int xm, int ym) { + void renderBg(MinecraftClient& minecraft, int xm, int ym) { //fill(x+1, y+1, x+w-1, y+h-1, 0xff999999); - bool hovered = active && (minecraft->useTouchscreen()? + bool hovered = active && (minecraft.useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); if (hovered || *selectedPtr == this) @@ -103,13 +103,13 @@ void PaneCraftingScreen::init() { btnClose.setImageDef(def, true); btnClose.scaleWhenPressed = false; - btnCraft.init(minecraft->textures); + btnCraft.init(minecraft.textures); buttons.push_back(&btnCraft); buttons.push_back(&btnClose); // GUI patches - NinePatchFactory builder(minecraft->textures, "gui/spritesheet.png"); + NinePatchFactory builder(minecraft.textures() "gui/spritesheet.png"); guiBackground = builder.createSymmetrical(IntRectangle(0, 0, 16, 16), 4, 4); guiPaneFrame = builder.createSymmetrical(IntRectangle(0, 20, 8, 8), 1, 2)->setExcluded(1 << 4); @@ -230,7 +230,7 @@ void PaneCraftingScreen::render(int xm, int ym, float a) { CItem::ReqItem& req = currentItem->neededItems[i]; reqItem = req.item; if (reqItem.getAuxValue() == -1) reqItem.setAuxValue(0); - ItemRenderer::renderGuiItem(NULL, minecraft->textures, &reqItem, xx, yy, 16, 16, true); + ItemRenderer::renderGuiItem(NULL, minecraft.textures() &reqItem, xx, yy, 16, 16, true); } t.endOverrideAndDraw(); @@ -251,17 +251,17 @@ void PaneCraftingScreen::render(int xm, int ym, float a) { buf[bufIndex] = 0; if (req.enough()) - minecraft->font->drawShadow(buf, xx, yy, rgbActive); + minecraft.font()->drawShadow(buf, xx, yy, rgbActive); else { - minecraft->font->draw(buf, xx+1, yy+1, rgbInactiveShadow); - minecraft->font->draw(buf, xx, yy, rgbInactive); + minecraft.font()->draw(buf, xx+1, yy+1, rgbInactiveShadow); + minecraft.font()->draw(buf, xx, yy, rgbInactive); } } t.resetScale(); t.endOverrideAndDraw(); - //minecraft->font->drawWordWrap(currentItemDesc, rightBx + 2, (float)btnCraft.y + btnCraft.h + 6, descFrameWidth-4, rgbActive); - minecraft->font->drawWordWrap(currentItemDesc, (float)btnCraft.x, (float)(btnCraft.y + btnCraft.height + 6), (float)btnCraft.width, rgbActive); + //minecraft.font()->drawWordWrap(currentItemDesc, rightBx + 2, (float)btnCraft.y + btnCraft.h + 6, descFrameWidth-4, rgbActive); + minecraft.font()->drawWordWrap(currentItemDesc, (float)btnCraft.x, (float)(btnCraft.y + btnCraft.height + 6), (float)btnCraft.width, rgbActive); } //glDisable2(GL_ALPHA_TEST); } @@ -271,7 +271,7 @@ void PaneCraftingScreen::buttonClicked(Button* button) { craftSelectedItem(); if (button == &btnClose) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); // Did we click a category? if (button->id >= 100 && button->id < 200) { @@ -311,8 +311,8 @@ static bool sortCanCraftPredicate(const CItem* a, const CItem* b) { void PaneCraftingScreen::recheckRecipes() { ItemPack ip; - if (minecraft->player && minecraft->player->inventory) { - Inventory* inv = (minecraft->player)->inventory; + if (minecraft.player() && minecraft.player()->inventory) { + Inventory* inv = (minecraft.player())->inventory; for (int i = Inventory::MAX_SELECTION_SIZE; i < inv->getContainerSize(); ++i) { if (ItemInstance* item = inv->getItem(i)) @@ -404,8 +404,8 @@ void PaneCraftingScreen::onItemSelected(int buttonIndex, CItem* item) { const int NumCategoryItems = _categories[buttonIndex].size(); if (pane) delete pane; - pane = new ItemPane(this, minecraft->textures, paneRect, NumCategoryItems, height, minecraft->height); - pane->f = minecraft->font; + pane = new ItemPane(this, minecraft.textures() paneRect, NumCategoryItems, height, minecraft.getScreenHeight()); + pane->f = minecraft.font(); currentCategory = buttonIndex; } @@ -422,8 +422,8 @@ void PaneCraftingScreen::clearCategoryItems() void PaneCraftingScreen::keyPressed( int eventKey ) { if (eventKey == Keyboard::KEY_ESCAPE || eventKey == Keyboard::KEY_E) { - minecraft->setScreen(NULL); - //minecraft->grabMouse(); + minecraft.setScreen(NULL); + //minecraft.grabMouse(); } else { super::keyPressed(eventKey); } @@ -438,7 +438,7 @@ void PaneCraftingScreen::craftSelectedItem() ItemInstance resultItem = currentItem->item; - if (minecraft->player) { + if (minecraft.player()) { // Remove all items required for the recipe and ... for (unsigned int i = 0; i < currentItem->neededItems.size(); ++i) { CItem::ReqItem& req = currentItem->neededItems[i]; @@ -451,18 +451,18 @@ void PaneCraftingScreen::craftSelectedItem() if (Tile::sandStone->id == req.item.id && Recipe::ANY_AUX_VALUE == req.item.getAuxValue()) { toRemove.setAuxValue(0); - toRemove.count = minecraft->player->inventory->removeResource(toRemove, true); + toRemove.count = minecraft.player()->inventory->removeResource(toRemove, true); toRemove.setAuxValue(Recipe::ANY_AUX_VALUE); } if (toRemove.count > 0) { - minecraft->player->inventory->removeResource(toRemove); + minecraft.player()->inventory->removeResource(toRemove); } } // ... add the new one! (in this order, to fill empty slots better) // if it doesn't fit, throw it on the ground! - if (!minecraft->player->inventory->add(&resultItem)) { - minecraft->player->drop(new ItemInstance(resultItem), false); + if (!minecraft.player()->inventory->add(&resultItem)) { + minecraft.player()->drop(new ItemInstance(resultItem), false); } recheckRecipes(); @@ -541,12 +541,12 @@ IntRectangle CraftButton::getItemPos( int i ) return IntRectangle(); } -void CraftButton::renderBg(Minecraft* minecraft, int xm, int ym) { +void CraftButton::renderBg(MinecraftClient& minecraft, int xm, int ym) { if (!bg || !bgSelected) return; //fill(x+1, y+1, x+w-1, y+h-1, 0xff999999); - bool hovered = active && (minecraft->useTouchscreen()? + bool hovered = active && (minecraft.useTouchscreen()? (_currentlyDown && xm >= x && ym >= y && xm < x + width && ym < y + height) : isInside(xm, ym)); if (hovered || selected) diff --git a/src/client/gui/screens/crafting/PaneCraftingScreen.hpp b/src/client/gui/screens/crafting/PaneCraftingScreen.hpp index 5bcb7aa..3a786eb 100755 --- a/src/client/gui/screens/crafting/PaneCraftingScreen.hpp +++ b/src/client/gui/screens/crafting/PaneCraftingScreen.hpp @@ -25,7 +25,7 @@ public: void setNumItems(int i) { numItems = i; } IntRectangle getItemPos(int i); - void renderBg(Minecraft* minecraft, int xm, int ym); + void renderBg(MinecraftClient& minecraft, int xm, int ym); private: NinePatchLayer* bg; NinePatchLayer* bgSelected; diff --git a/src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp b/src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp index d3e05a3..ba53d1a 100755 --- a/src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp +++ b/src/client/gui/screens/touch/TouchIngameBlockSelectionScreen.cpp @@ -10,7 +10,7 @@ #include "client/renderer/entity/ItemRenderer.hpp" #include "client/renderer/Tesselator.hpp" #include "client/renderer/Textures.hpp" -#include "client/Minecraft.hpp" +#include #include "client/sound/SoundEngine.hpp" #include "world/entity/player/Inventory.hpp" #include "platform/input/Mouse.hpp" @@ -69,7 +69,7 @@ IngameBlockSelectionScreen::~IngameBlockSelectionScreen() void IngameBlockSelectionScreen::init() { - Inventory* inventory = minecraft->player->inventory; + Inventory* inventory = minecraft.player()->inventory; //const int itemWidth = 2 * BorderPixels + @@ -110,7 +110,7 @@ void IngameBlockSelectionScreen::init() buttons.push_back(&bHeader); buttons.push_back(&bDone); - if (!minecraft->isCreativeMode()) { + if (!minecraft.isCreativeMode()) { buttons.push_back(&bCraft); buttons.push_back(&bArmor); } @@ -123,7 +123,7 @@ void IngameBlockSelectionScreen::setupPositions() { bCraft.width = bArmor.width = 48; bArmor.x = bCraft.width; - if (minecraft->isCreativeMode()) { + if (minecraft.isCreativeMode()) { bHeader.x = 0; bHeader.width = width;// - bDone.w; bHeader.xText = width/2; // Center of the screen @@ -134,14 +134,14 @@ void IngameBlockSelectionScreen::setupPositions() { } clippingArea.x = 0; - clippingArea.w = minecraft->width; + clippingArea.w = minecraft.getScreenWidth(); clippingArea.y = 0; clippingArea.h = (int)(Gui::GuiScale * 24); } void IngameBlockSelectionScreen::removed() { - minecraft->gui.inventoryUpdated(); + minecraft.gui().inventoryUpdated(); } int IngameBlockSelectionScreen::getSlotPosX(int slotX) { @@ -166,7 +166,7 @@ void IngameBlockSelectionScreen::mouseClicked(int x, int y, int buttonNum) { void IngameBlockSelectionScreen::mouseReleased(int x, int y, int buttonNum) { if (_pendingClose && _blockList->_clickArea->isInside((float)x, (float)y)) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); else super::mouseReleased(x, y, buttonNum); } @@ -191,7 +191,7 @@ void IngameBlockSelectionScreen::mouseWheel(int dx, int dy, int xm, int ym) bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId) { - Inventory* inventory = minecraft->player->inventory; + Inventory* inventory = minecraft.player()->inventory; itemId += Inventory::MAX_SELECTION_SIZE; if (!inventory->getItem(itemId)) @@ -201,13 +201,13 @@ bool IngameBlockSelectionScreen::addItem(const InventoryPane* pane, int itemId) inventory->selectSlot(0); #ifdef __APPLE__ - minecraft->soundEngine->playUI("random.pop", 0.3f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random())); + minecraft.soundEngine()->playUI("random.pop", 0.3f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random())); #else - minecraft->soundEngine->playUI("random.pop2", 1.0f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random())); + minecraft.soundEngine()->playUI("random.pop2", 1.0f, 0.3f);//1.0f + 0.2f*(Mth::random()-Mth::random())); #endif // Flash the selected gui item - minecraft->gui.flashSlot(inventory->selected); + minecraft.gui().flashSlot(inventory->selected); return true; } @@ -228,7 +228,7 @@ void IngameBlockSelectionScreen::render( int xm, int ym, float a ) // render frame IntRectangle& bbox = _blockList->rect; Tesselator::instance.colorABGR(0xffffffff); - minecraft->textures->loadAndBindTexture("gui/itemframe.png"); + minecraft.textures().loadAndBindTexture("gui/itemframe.png"); glEnable2(GL_BLEND); glColor4f2(1, 1, 1, 1); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -245,31 +245,31 @@ void IngameBlockSelectionScreen::renderDemoOverlay() { const int centerX = (getSlotPosX(4) + getSlotPosX(5)) / 2; const int centerY = (getSlotPosY(0) + getSlotPosY(1)) / 2 + 5; - drawCenteredString(minecraft->font, demoVersionString, centerX, centerY, 0xffffffff); + drawCenteredString(minecraft.font(), demoVersionString, centerX, centerY, 0xffffffff); #endif /*DEMO_MODE*/ } void IngameBlockSelectionScreen::buttonClicked(Button* button) { if (button->id == bDone.id) - minecraft->setScreen(NULL); + minecraft.setScreen(NULL); if (button->id == bMenu.id) - minecraft->screenChooser.setScreen(SCREEN_PAUSE); + minecraft.screenChooser.setScreen(SCREEN_PAUSE); if (button->id == bCraft.id) - minecraft->setScreen(new WorkbenchScreen(Recipe::SIZE_2X2)); + minecraft.setScreen(new WorkbenchScreen(Recipe::SIZE_2X2)); if (button == &bArmor) - minecraft->setScreen(new ArmorScreen()); + minecraft.setScreen(new ArmorScreen()); } bool IngameBlockSelectionScreen::isAllowed( int slot ) { - if (slot < 0 || slot >= minecraft->player->inventory->getContainerSize()) + if (slot < 0 || slot >= minecraft.player()->inventory->getContainerSize()) return false; #ifdef DEMO_MODE - if (slot >= (minecraft->isCreativeMode()? 28 : 27)) return false; + if (slot >= (minecraft.isCreativeMode()? 28 : 27)) return false; #endif return true; } @@ -283,8 +283,8 @@ bool IngameBlockSelectionScreen::hasClippingArea( IntRectangle& out ) std::vector IngameBlockSelectionScreen::getItems( const InventoryPane* forPane ) { std::vector out; - for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft->player->inventory->getContainerSize(); ++i) - out.push_back(minecraft->player->inventory->getItem(i)); + for (int i = Inventory::MAX_SELECTION_SIZE; i < minecraft.player()->inventory->getContainerSize(); ++i) + out.push_back(minecraft.player()->inventory->getItem(i)); return out; } diff --git a/src/client/gui/screens/touch/TouchJoinGameScreen.cpp b/src/client/gui/screens/touch/TouchJoinGameScreen.cpp index 608a8bf..656a1ec 100755 --- a/src/client/gui/screens/touch/TouchJoinGameScreen.cpp +++ b/src/client/gui/screens/touch/TouchJoinGameScreen.cpp @@ -2,7 +2,7 @@ #include "client/gui/screens/StartMenuScreen.hpp" #include "client/gui/screens/ProgressScreen.hpp" #include "client/gui/Font.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Textures.hpp" namespace Touch { @@ -44,16 +44,16 @@ void AvailableGamesList::renderItem( int i, int x, int y, int h, Tesselator& t ) glEnable2(GL_TEXTURE_2D); glColor4f2(1,1,1,1); glEnable2(GL_BLEND); - minecraft->textures->loadAndBindTexture("gui/badge/minecon140.png"); + minecraft.textures().loadAndBindTexture("gui/badge/minecon140.png"); blit(xx2, y + 6, 0, 0, 37, 8, 140, 240); } - drawString(minecraft->font, s.name.C_String(), xx1, y + 4 + 2, color); - drawString(minecraft->font, s.address.ToString(false), xx2, y + 18, color2); + drawString(minecraft.font(), s.name.C_String(), xx1, y + 4 + 2, color); + drawString(minecraft.font(), s.address.ToString(false), xx2, y + 18, color2); /* - drawString(minecraft->font, copiedServerList[i].name.C_String(), (int)x0 + 24, y + 4, color); - drawString(minecraft->font, copiedServerList[i].address.ToString(false), (int)x0 + 24, y + 18, color); + drawString(minecraft.font(), copiedServerList[i].name.C_String(), (int)x0 + 24, y + 4, color); + drawString(minecraft.font(), copiedServerList[i].address.ToString(false), (int)x0 + 24, y + 18, color); */ } @@ -84,7 +84,7 @@ void JoinGameScreen::init() buttons.push_back(&bJoinByIp); buttons.push_back(&bHeader); - minecraft->raknetInstance->clearServerList(); + minecraft.raknetInstance->clearServerList(); gamesList = new AvailableGamesList(minecraft, width, height); #ifdef ANDROID @@ -119,25 +119,25 @@ void JoinGameScreen::buttonClicked(Button* button) if (isIndexValid(gamesList->selectedItem)) { PingedCompatibleServer selectedServer = gamesList->copiedServerList[gamesList->selectedItem]; - minecraft->joinMultiplayer(selectedServer); + minecraft.joinMultiplayer(selectedServer); { bJoin.active = false; bBack.active = false; - minecraft->setScreen(new ProgressScreen()); + minecraft.setScreen(new ProgressScreen()); } } - //minecraft->locateMultiplayer(); - //minecraft->setScreen(new JoinGameScreen()); + //minecraft.locateMultiplayer(); + //minecraft.setScreen(new JoinGameScreen()); } if(button->id == bJoinByIp.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_JOINBYIP); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_JOINBYIP); } if (button->id == bBack.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } } @@ -145,8 +145,8 @@ bool JoinGameScreen::handleBackEvent(bool isDown) { if (!isDown) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } return true; } @@ -166,7 +166,7 @@ void JoinGameScreen::tick() //gamesList->tick(); - const ServerList& orgServerList = minecraft->raknetInstance->getServerList(); + const ServerList& orgServerList = minecraft.raknetInstance->getServerList(); ServerList serverList; for (unsigned int i = 0; i < orgServerList.size(); ++i) if (orgServerList[i].name.GetLength() > 0) @@ -211,7 +211,7 @@ void JoinGameScreen::tick() void JoinGameScreen::render( int xm, int ym, float a ) { - bool hasNetwork = minecraft->platform()->isNetworkEnabled(true); + bool hasNetwork = minecraft.platform()->isNetworkEnabled(true); #ifdef WIN32 hasNetwork = hasNetwork && !GetAsyncKeyState(VK_TAB); #endif @@ -225,16 +225,16 @@ void JoinGameScreen::render( int xm, int ym, float a ) if (hasNetwork) { std::string s = "Scanning for WiFi Games..."; - drawCenteredString(minecraft->font, s, baseX, 8, 0xffffffff); + drawCenteredString(minecraft.font(), s, baseX, 8, 0xffffffff); - const int textWidth = minecraft->font->width(s); + const int textWidth = minecraft.font()->width(s); const int spinnerX = baseX + textWidth / 2 + 6; static const char* spinnerTexts[] = {"-", "\\", "|", "/"}; int n = ((int)(5.5f * getTimeS()) % 4); - drawCenteredString(minecraft->font, spinnerTexts[n], spinnerX, 8, 0xffffffff); + drawCenteredString(minecraft.font(), spinnerTexts[n], spinnerX, 8, 0xffffffff); } else { - drawCenteredString(minecraft->font, "WiFi is disabled", baseX, 8, 0xffffffff); + drawCenteredString(minecraft.font(), "WiFi is disabled", baseX, 8, 0xffffffff); } } diff --git a/src/client/gui/screens/touch/TouchJoinGameScreen.hpp b/src/client/gui/screens/touch/TouchJoinGameScreen.hpp index 3496fc3..8019ee7 100755 --- a/src/client/gui/screens/touch/TouchJoinGameScreen.hpp +++ b/src/client/gui/screens/touch/TouchJoinGameScreen.hpp @@ -3,7 +3,7 @@ #include "client/gui/Screen.hpp" #include "client/gui/components/Button.hpp" #include "client/gui/components/RolledSelectionListV.hpp" -#include "client/Minecraft.hpp" +#include #include "platform/input/Multitouch.hpp" #include "network/RakNetInstance.hpp" @@ -20,7 +20,7 @@ class AvailableGamesList : public RolledSelectionListV friend class JoinGameScreen; public: - AvailableGamesList(Minecraft* _minecraft, int _width, int _height) + AvailableGamesList(MinecraftClient& _minecraft, int _width, int _height) : RolledSelectionListV(_minecraft, _width, _height, 0, _width, 24, _height, 34), selectedItem(-1), startSelected(-1) diff --git a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp index 1518974..2aa7b50 100755 --- a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp +++ b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp @@ -21,7 +21,7 @@ namespace Touch { // // World Selection List // -TouchWorldSelectionList::TouchWorldSelectionList( Minecraft* minecraft, int width, int height ) +TouchWorldSelectionList::TouchWorldSelectionList( MinecraftClient& minecraft, int width, int height ) : _height(height), hasPickedLevel(false), pickedIndex(-1), @@ -85,12 +85,12 @@ void TouchWorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator if (i < (int)levels.size()) { // Draw the worlds StringVector v = _descriptions[i]; - drawString(minecraft->font, v[0].c_str(), TX, TY + 0, textColor); - drawString(minecraft->font, v[1].c_str(), TX, TY + 10, textColor2); - drawString(minecraft->font, v[2].c_str(), TX, TY + 20, textColor2); - drawString(minecraft->font, v[3].c_str(), TX, TY + 30, textColor2); + drawString(minecraft.font(), v[0].c_str(), TX, TY + 0, textColor); + drawString(minecraft.font(), v[1].c_str(), TX, TY + 10, textColor2); + drawString(minecraft.font(), v[2].c_str(), TX, TY + 20, textColor2); + drawString(minecraft.font(), v[3].c_str(), TX, TY + 30, textColor2); - minecraft->textures->loadAndBindTexture(_imageNames[i]); + minecraft.textures().loadAndBindTexture(_imageNames[i]); t.color(0.3f, 1.0f, 0.2f); //float x0 = (float)x; @@ -106,9 +106,9 @@ void TouchWorldSelectionList::renderItem( int i, int x, int y, int h, Tesselator t.draw(); } else { // Draw the "Create new world" icon - drawCenteredString(minecraft->font, "Create new", centerx, TY + 12, textColor); + drawCenteredString(minecraft.font(), "Create new", centerx, TY + 12, textColor); - minecraft->textures->loadAndBindTexture("gui/touchgui.png"); + minecraft.textures().loadAndBindTexture("gui/touchgui.png"); const bool selected = _newWorldSelected; @@ -164,7 +164,7 @@ void TouchWorldSelectionList::commit() { std::stringstream ss; ss << level.name << "/preview.png"; - TextureId id = Textures::InvalidId;//minecraft->textures->loadTexture(ss.str(), false); + TextureId id = Textures::InvalidId;//minecraft.textures().loadTexture(ss.str(), false); if (id != Textures::InvalidId) { _imageNames.push_back( ss.str() ); @@ -174,7 +174,7 @@ void TouchWorldSelectionList::commit() { StringVector lines; lines.push_back(levels[i].name); - lines.push_back(minecraft->platform()->getDateString(levels[i].lastPlayed)); + lines.push_back(minecraft.platform()->getDateString(levels[i].lastPlayed)); lines.push_back(levels[i].id); lines.push_back(LevelSettings::gameTypeToString(level.gameType)); _descriptions.push_back(lines); @@ -350,19 +350,19 @@ void SelectWorldScreen::buttonClicked(Button* button) if (button->id == bCreate.id) { if (!_hasStartedLevel) { std::string name = getUniqueLevelName("World"); - minecraft->setScreen(new SimpleChooseLevelScreen(name)); + minecraft.setScreen(new SimpleChooseLevelScreen(name)); } } if (button->id == bDelete.id) { if (isIndexValid(worldsList->selectedItem)) { LevelSummary level = worldsList->levels[worldsList->selectedItem]; LOGI("level: %s, %s\n", level.id.c_str(), level.name.c_str()); - minecraft->setScreen( new TouchDeleteWorldScreen(level) ); + minecraft.setScreen( new TouchDeleteWorldScreen(level) ); } } if (button->id == bBack.id) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } if (button->id == bWorldView.id) { // Try to "click" the item in the middle @@ -374,8 +374,8 @@ bool SelectWorldScreen::handleBackEvent(bool isDown) { if (!isDown) { - minecraft->cancelLocateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_STARTMENU); + minecraft.cancelLocateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_STARTMENU); } return true; } @@ -417,19 +417,19 @@ void SelectWorldScreen::tick() std::string levelId = getUniqueLevelName("World"); //int seed = Util::hashCode("/r/Minecraft"); LevelSettings settings(getEpochTimeS(), GameType::Creative); - minecraft->selectLevel(levelId, levelId, settings); - minecraft->hostMultiplayer(); - minecraft->setScreen(new ProgressScreen()); + minecraft.selectLevel(levelId, levelId, settings); + minecraft.hostMultiplayer(); + minecraft.setScreen(new ProgressScreen()); _hasStartedLevel = true; #elif defined(PLATFORM_DESKTOP) std::string name = getUniqueLevelName("World"); - minecraft->setScreen(new SimpleChooseLevelScreen(name)); + minecraft.setScreen(new SimpleChooseLevelScreen(name)); #else - int status = minecraft->platform()->getUserInputStatus(); + int status = minecraft.platform()->getUserInputStatus(); //LOGI("Status is: %d\n", status); if (status > -1) { if (status == 1) { - StringVector sv = minecraft->platform()->getUserInput(); + StringVector sv = minecraft.platform()->getUserInput(); // Read the level name. // 1) Trim name 2) Remove all bad chars 3) Append '-' chars 'til the name is unique @@ -466,9 +466,9 @@ void SelectWorldScreen::tick() // Start a new level with the given name and seed LOGI("Creating a level with id '%s', name '%s' and seed '%d'\n", levelId.c_str(), levelName.c_str(), seed); LevelSettings settings(seed, isCreative? GameType::Creative : GameType::Survival); - minecraft->selectLevel(levelId, levelName, settings); - minecraft->hostMultiplayer(); - minecraft->setScreen(new ProgressScreen()); + minecraft.selectLevel(levelId, levelName, settings); + minecraft.hostMultiplayer(); + minecraft.setScreen(new ProgressScreen()); _hasStartedLevel = true; } _state = _STATE_DEFAULT; @@ -489,11 +489,11 @@ void SelectWorldScreen::tick() if (worldsList->pickedIndex == worldsList->levels.size()) { worldsList->hasPickedLevel = false; std::string name = getUniqueLevelName("World"); - minecraft->setScreen(new SimpleChooseLevelScreen(name)); + minecraft.setScreen(new SimpleChooseLevelScreen(name)); } else { - minecraft->selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None()); - minecraft->hostMultiplayer(); - minecraft->setScreen(new ProgressScreen()); + minecraft.selectLevel(worldsList->pickedLevel.id, worldsList->pickedLevel.name, LevelSettings::None()); + minecraft.hostMultiplayer(); + minecraft.setScreen(new ProgressScreen()); _hasStartedLevel = true; return; } @@ -533,7 +533,7 @@ void SelectWorldScreen::render( int xm, int ym, float a ) Screen::render(xm, ym, a); //Performance::watches.get("sws-screen").stop(); - //minecraft->textures->loadAndBindTexture("gui/selectworld/trash.png"); + //minecraft.textures().loadAndBindTexture("gui/selectworld/trash.png"); //Performance::watches.get("sws-string").start(); //Performance::watches.get("sws-string").stop(); @@ -544,7 +544,7 @@ void SelectWorldScreen::render( int xm, int ym, float a ) void SelectWorldScreen::loadLevelSource() { - LevelStorageSource* levelSource = minecraft->getLevelSource(); + LevelStorageSource* levelSource = minecraft.getLevelSource(); levelSource->getLevelList(levels); std::sort(levels.begin(), levels.end()); @@ -572,9 +572,9 @@ bool SelectWorldScreen::isInGameScreen() { return true; } void SelectWorldScreen::keyPressed( int eventKey ) { if (bWorldView.selected) { - if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_LEFT)) + if (eventKey == minecraft.options().getIntValue(OPTIONS_KEY_LEFT)) worldsList->stepLeft(); - if (eventKey == minecraft->options.getIntValue(OPTIONS_KEY_RIGHT)) + if (eventKey == minecraft.options().getIntValue(OPTIONS_KEY_RIGHT)) worldsList->stepRight(); } @@ -596,10 +596,10 @@ TouchDeleteWorldScreen::TouchDeleteWorldScreen(const LevelSummary& level) void TouchDeleteWorldScreen::postResult( bool isOk ) { if (isOk) { - LevelStorageSource* storageSource = minecraft->getLevelSource(); + LevelStorageSource* storageSource = minecraft.getLevelSource(); storageSource->deleteLevel(_level.id); } - minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD); + minecraft.screenChooser.setScreen(SCREEN_SELECTWORLD); } }; diff --git a/src/client/gui/screens/touch/TouchSelectWorldScreen.hpp b/src/client/gui/screens/touch/TouchSelectWorldScreen.hpp index 1d4d16d..d5c93f3 100755 --- a/src/client/gui/screens/touch/TouchSelectWorldScreen.hpp +++ b/src/client/gui/screens/touch/TouchSelectWorldScreen.hpp @@ -6,7 +6,7 @@ #include "client/gui/components/ImageButton.hpp" #include "client/gui/components/Button.hpp" #include "client/gui/components/RolledSelectionListH.hpp" -#include "client/Minecraft.hpp" +#include #include "world/level/storage/LevelStorageSource.hpp" @@ -20,7 +20,7 @@ class SelectWorldScreen; class TouchWorldSelectionList : public RolledSelectionListH { public: - TouchWorldSelectionList(Minecraft* _minecraft, int _width, int _height); + TouchWorldSelectionList(MinecraftClient& _minecraft, int _width, int _height); virtual void tick(); void stepLeft(); void stepRight(); diff --git a/src/client/gui/screens/touch/TouchStartMenuScreen.cpp b/src/client/gui/screens/touch/TouchStartMenuScreen.cpp index 3dcc832..79b4716 100755 --- a/src/client/gui/screens/touch/TouchStartMenuScreen.cpp +++ b/src/client/gui/screens/touch/TouchStartMenuScreen.cpp @@ -7,7 +7,7 @@ #include "client/gui/components/ScrolledSelectionList.hpp" #include "client/gui/components/GuiElement.hpp" -#include "client/Minecraft.hpp" +#include #include "client/renderer/Tesselator.hpp" #include "client/renderer/Textures.hpp" #include "client/renderer/TextureData.hpp" @@ -85,7 +85,7 @@ void StartMenuScreen::init() // always show base version string std::string versionString = Common::getGameVersionString(); - std::string _username = minecraft->options.getStringValue(OPTIONS_USERNAME); + std::string _username = minecraft.options().getStringValue(OPTIONS_USERNAME); if (_username.empty()) _username = "unknown"; username = "Username: " + _username; @@ -127,8 +127,8 @@ void StartMenuScreen::setupPositions() { bQuit.x = width - bQuit.width; bQuit.y = 0; - copyrightPosX = width - minecraft->font->width(copyright) - 1; - versionPosX = (width - minecraft->font->width(version)) / 2;// - minecraft->font->width(version) - 2; + copyrightPosX = width - minecraft.font()->width(copyright) - 1; + versionPosX = (width - minecraft.font()->width(version)) / 2;// - minecraft.font()->width(version) - 2; } void StartMenuScreen::buttonClicked(::Button* button) { @@ -136,27 +136,27 @@ void StartMenuScreen::buttonClicked(::Button* button) { if (button->id == bHost.id) { #if defined(DEMO_MODE) || defined(APPLE_DEMO_PROMOTION) - minecraft->setScreen( new SimpleChooseLevelScreen("_DemoLevel") ); + minecraft.setScreen( new SimpleChooseLevelScreen("_DemoLevel") ); #else - minecraft->screenChooser.setScreen(SCREEN_SELECTWORLD); + minecraft.screenChooser.setScreen(SCREEN_SELECTWORLD); #endif } if (button->id == bJoin.id) { #ifdef APPLE_DEMO_PROMOTION - minecraft->platform()->createUserInput(DialogDefinitions::DIALOG_DEMO_FEATURE_DISABLED); + minecraft.platform()->createUserInput(DialogDefinitions::DIALOG_DEMO_FEATURE_DISABLED); #else - minecraft->locateMultiplayer(); - minecraft->screenChooser.setScreen(SCREEN_JOINGAME); + minecraft.locateMultiplayer(); + minecraft.screenChooser.setScreen(SCREEN_JOINGAME); #endif } if (button->id == bOptions.id) { - minecraft->setScreen(new OptionsScreen()); + minecraft.setScreen(new OptionsScreen()); } if (button == &bQuit) { - minecraft->quit(); + minecraft.quit(); } } @@ -172,14 +172,14 @@ void StartMenuScreen::render( int xm, int ym, float a ) glEnable2(GL_BLEND); #if defined(RPI) - TextureId id = minecraft->textures->loadTexture("gui/pi_title.png"); + TextureId id = minecraft.textures().loadTexture("gui/pi_title.png"); #else - TextureId id = minecraft->textures->loadTexture("gui/title.png"); + TextureId id = minecraft.textures().loadTexture("gui/title.png"); #endif - const TextureData* data = minecraft->textures->getTemporaryTextureData(id); + const TextureData* data = minecraft.textures().getTemporaryTextureData(id); if (data) { - minecraft->textures->bind(id); + minecraft.textures().bind(id); const float x = (float)width / 2; const float y = 4; @@ -200,7 +200,7 @@ void StartMenuScreen::render( int xm, int ym, float a ) drawString(font, version, versionPosX, (int)(y+h)+2, /*50,*/ 0xffcccccc);//0x666666); drawString(font, copyright, copyrightPosX, height - 10, 0xffffff); glColor4f2(1, 1, 1, 1); - if (Textures::isTextureIdValid(minecraft->textures->loadAndBindTexture("gui/logo/github.png"))) + if (Textures::isTextureIdValid(minecraft.textures().loadAndBindTexture("gui/logo/github.png"))) blit(2, height - 10, 0, 0, 8, 8, 256, 256); drawString(font, "Kolyah35/minecraft-pe-0.6.1", 12, height - 10, 0xffcccccc); //patch->draw(t, 0, 20); @@ -212,17 +212,17 @@ void StartMenuScreen::render( int xm, int ym, float a ) void StartMenuScreen::mouseClicked(int x, int y, int buttonNum) { const int logoX = 2; - const int logoW = 8 + 2 + font->width("Kolyah35/minecraft-pe-0.6.1"); + const int logoW = 8 + 2 + font.width("Kolyah35/minecraft-pe-0.6.1"); const int logoY = height - 10; const int logoH = 10; if (x >= logoX && x <= logoX + logoW && y >= logoY && y <= logoY + logoH) - minecraft->platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1"); + minecraft.platform()->openURL("https://gitea.sffempire.ru/Kolyah35/minecraft-pe-0.6.1"); else Screen::mouseClicked(x, y, buttonNum); } bool StartMenuScreen::handleBackEvent( bool isDown ) { - minecraft->quit(); + minecraft.quit(); return true; } diff --git a/src/client/multiplayer/MultiPlayerLevel.hpp b/src/client/multiplayer/MultiPlayerLevel.hpp index df2a64f..6d89f0c 100755 --- a/src/client/multiplayer/MultiPlayerLevel.hpp +++ b/src/client/multiplayer/MultiPlayerLevel.hpp @@ -54,17 +54,17 @@ public: updateSkyDarken(); for (int i = 0; i < 10 && !reEntries.empty(); i++) { - EntitySet::iterator it = reEntries.begin(); + auto it = reEntries.begin(); Entity* e = *it;//reEntries.iterator().next(); reEntries.erase(it); //if (!entities.contains(e)) addEntity(e); - EntityList::iterator jt = std::find(entities.begin(), entities.end(), e); + auto jt = std::find(entities.begin(), entities.end(), e); if (jt == entities.end()) addEntity(e); } - for (ResetInfoList::iterator it = updatesToReset.begin(); it != updatesToReset.end();) { + for (auto it = updatesToReset.begin(); it != updatesToReset.end();) { ResetInfo& r = *it; if (--r.ticks == 0) { super::setTileAndDataNoUpdate(r.x, r.y, r.z, r.tile, r.data); @@ -76,7 +76,7 @@ public: } void clearResetRegion(int x0, int y0, int z0, int x1, int y1, int z1) { - for (ResetInfoList::iterator it = updatesToReset.begin(); it != updatesToReset.end();) { + for (auto it = updatesToReset.begin(); it != updatesToReset.end();) { ResetInfo& r = *it; if (r.x >= x0 && r.y >= y0 && r.z >= z0 && r.x <= x1 && r.y <= y1 && r.z <= z1) { it = updatesToReset.erase(it); @@ -141,7 +141,7 @@ public: } Entity* removeEntity(int id) { - EntityIdMap::iterator it = entitiesById.find(id); + auto it = entitiesById.find(id); if (it != entitiesById.end()) { Entity* e = it->second; entitiesById.erase(it); @@ -208,7 +208,7 @@ protected: void entityAdded(Entity* e) { super::entityAdded(e); - EntitySet::iterator it = reEntries.find(e); + auto it = reEntries.find(e); if (it != reEntries.end()) { reEntries.erase(it); } @@ -216,7 +216,7 @@ protected: void entityRemoved(Entity* e) { super::entityRemoved(e); - EntitySet::iterator it = forced.find(e); + auto it = forced.find(e); if (it != forced.end()) { if (e->isAlive()) { reEntries.insert(e); diff --git a/src/client/particle/ParticleEngine.cpp b/src/client/particle/ParticleEngine.cpp index 5912008..6410921 100755 --- a/src/client/particle/ParticleEngine.cpp +++ b/src/client/particle/ParticleEngine.cpp @@ -5,7 +5,7 @@ #include "world/level/Level.hpp" #include "NinecraftApp.hpp" -ParticleEngine::ParticleEngine(Level* level, Textures* textures) +ParticleEngine::ParticleEngine(Level* level, Textures& textures) : level(level), textures(textures) { diff --git a/src/client/particle/ParticleEngine.hpp b/src/client/particle/ParticleEngine.hpp index 3c96c0d..6bd3293 100755 --- a/src/client/particle/ParticleEngine.hpp +++ b/src/client/particle/ParticleEngine.hpp @@ -22,7 +22,7 @@ public: static const int TEXTURE_COUNT = 4; - ParticleEngine(Level* level, Textures* textures); + ParticleEngine(Level* level, Textures& textures); ~ParticleEngine(); void add(Particle* p); diff --git a/src/client/player/LocalPlayer.cpp b/src/client/player/LocalPlayer.cpp index 8b92280..14e7b5e 100755 --- a/src/client/player/LocalPlayer.cpp +++ b/src/client/player/LocalPlayer.cpp @@ -552,8 +552,8 @@ void LocalPlayer::closeContainer() { //@Override void LocalPlayer::move(float xa, float ya, float za) { - //@note: why is this == minecraft.player needed? - if (this == minecraft.getPlayer() && minecraft.options().getBooleanValue(OPTIONS_IS_FLYING)) { + //@note: why is this == minecraft.player() needed? + if (this == minecraft.player() && minecraft.options().getBooleanValue(OPTIONS_IS_FLYING)) { noPhysics = true; float tmp = walkDist; // update calculateFlight((float) xa, (float) ya, (float) za); @@ -666,9 +666,9 @@ void LocalPlayer::hurtTo( int newHealth ) lastHealth = health; invulnerableTime = invulnerableDuration; - minecraft.getPlayer()->bypassArmor = true; + minecraft.player()->bypassArmor = true; actuallyHurt(dmg); - minecraft.getPlayer()->bypassArmor = false; + minecraft.player()->bypassArmor = false; hurtTime = hurtDuration = 10; } diff --git a/src/client/player/LocalPlayer.hpp b/src/client/player/LocalPlayer.hpp index 131e003..0d4f6d0 100755 --- a/src/client/player/LocalPlayer.hpp +++ b/src/client/player/LocalPlayer.hpp @@ -57,8 +57,8 @@ public: void displayClientMessage(const std::string& messageId); void awardStat(Stat* stat, int count) { - //minecraft->stats.award(stat, count); - //minecraft->achievementPopup.popup("Achievement get!", stat.name); + //minecraft.stats.award(stat, count); + //minecraft.achievementPopup.popup("Achievement get!", stat.name); } void causeFallDamage( float distance ); diff --git a/src/client/player/input/IMoveInput.hpp b/src/client/player/input/IMoveInput.hpp index 66b840e..6177a4d 100755 --- a/src/client/player/input/IMoveInput.hpp +++ b/src/client/player/input/IMoveInput.hpp @@ -4,7 +4,7 @@ #include "client/IConfigListener.hpp" class Player; -class Minecraft; +class MinecraftClient; class IMoveInput { diff --git a/src/client/player/input/touchscreen/TouchInputHolder.hpp b/src/client/player/input/touchscreen/TouchInputHolder.hpp index 8c0c36a..cd722fb 100755 --- a/src/client/player/input/touchscreen/TouchInputHolder.hpp +++ b/src/client/player/input/touchscreen/TouchInputHolder.hpp @@ -54,10 +54,10 @@ public: static const int MODE_OFFSET = 1; static const int MODE_DELTA = 2; - UnifiedTurnBuild(int turnMode, int width, int height, float maxMovementDelta, float sensitivity, IInputHolder* holder, Minecraft* minecraft) + UnifiedTurnBuild(int turnMode, int width, int height, float maxMovementDelta, float sensitivity, IInputHolder* holder, MinecraftClient& minecraft) : mode(turnMode), _holder(holder), - _options(&minecraft->options), + _options(&minecraft.options), cxO(0), cyO(0), wasActive(false), _totalMoveDelta(0), @@ -90,12 +90,12 @@ public: virtual void onConfigChanged(const Config& c) { if (false && _options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)) { int touchWidth = c.width - (int)inventoryArea._x1; - if (touchWidth > (int)c.minecraft->pixelCalc.millimetersToPixels(60)) - touchWidth = (int)c.minecraft->pixelCalc.millimetersToPixels(60); + if (touchWidth > (int)c.minecraft.pixelCalc.millimetersToPixels(60)) + touchWidth = (int)c.minecraft.pixelCalc.millimetersToPixels(60); int touchHeight = (int)(c.height * 0.4f); - if (touchHeight > (int)c.minecraft->pixelCalc.millimetersToPixels(40)) - touchHeight = (int)c.minecraft->pixelCalc.millimetersToPixels(40); + if (touchHeight > (int)c.minecraft.pixelCalc.millimetersToPixels(40)) + touchHeight = (int)c.minecraft.pixelCalc.millimetersToPixels(40); joyTouchArea._x0 = (float)(c.width - touchWidth); joyTouchArea._y0 = (float)(c.height - touchHeight); @@ -403,7 +403,7 @@ private: Options* _options; }; -class Minecraft; +class MinecraftClient; #if defined(_MSC_VER) #pragma warning( disable : 4355 ) // 'this' pointer in initialization list which is perfectly legal @@ -412,10 +412,10 @@ class Minecraft; class TouchInputHolder: public IInputHolder { public: - TouchInputHolder(Minecraft* mc, Options* options) + TouchInputHolder(MinecraftClient& mc, Options* options) : _mc(mc), _move(mc, options), - _turnBuild(UnifiedTurnBuild::MODE_DELTA, mc->width, mc->height, (float)MovementLimit, 1, this, mc) + _turnBuild(UnifiedTurnBuild::MODE_DELTA, mc.getScreenWidth(), mc.getScreenHeight(), (float)MovementLimit, 1, this, mc) { onConfigChanged(createConfig(mc)); } @@ -426,7 +426,7 @@ public: _move.onConfigChanged(c); _turnBuild.moveArea = _move.getRectangleArea(); _turnBuild.pauseArea = _move.getPauseRectangleArea(); - _turnBuild.inventoryArea = _mc->gui.getRectangleArea( _mc->options.getBooleanValue(OPTIONS_IS_LEFT_HANDED)? 1 : -1 ); + _turnBuild.inventoryArea = _mc.gui().getRectangleArea( _mc.options.getBooleanValue(OPTIONS_IS_LEFT_HANDED)? 1 : -1 ); _turnBuild.setSensitivity(c.options->getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA)? 1.8f : 1.0f); ((ITurnInput*)&_turnBuild)->onConfigChanged(c); } @@ -462,7 +462,7 @@ private: TouchscreenInput_TestFps _move; UnifiedTurnBuild _turnBuild; - Minecraft* _mc; + MinecraftClient& _mc; static const int MovementLimit = 200; // per update }; diff --git a/src/client/player/input/touchscreen/TouchscreenInput.cpp b/src/client/player/input/touchscreen/TouchscreenInput.cpp index ad3b080..b9bf556 100755 --- a/src/client/player/input/touchscreen/TouchscreenInput.cpp +++ b/src/client/player/input/touchscreen/TouchscreenInput.cpp @@ -5,7 +5,7 @@ #include "client/renderer/Tesselator.hpp" #include "world/entity/player/Player.hpp" -#include "client/Minecraft.hpp" +#include #include "platform/log.hpp" #include "client/renderer/Textures.hpp" #include "client/sound/SoundEngine.hpp" @@ -64,7 +64,7 @@ static void Transformed(int n, float* x, float* y, float* dx, float* dy, float x //} } -TouchscreenInput_TestFps::TouchscreenInput_TestFps( Minecraft* mc, Options* options ) +TouchscreenInput_TestFps::TouchscreenInput_TestFps( MinecraftClient& mc, Options* options ) : _minecraft(mc), _options(options), _northJump(false), @@ -129,7 +129,7 @@ void TouchscreenInput_TestFps::onConfigChanged(const Config& c) { float Bh = Bw;//0.15f; // If too large (like playing on Tablet) - PixelCalc& pc = _minecraft->pixelCalc; + PixelCalc& pc = _minecraft.pixelCalc; if (pc.pixelsToMillimeters(Bw) > 200) { //14 Bw = Bh = pc.millimetersToPixels(200); //14 } @@ -162,7 +162,7 @@ void TouchscreenInput_TestFps::onConfigChanged(const Config& c) { xx = BaseX + 2 * Bw; yy = BaseY + Bh; _model.addArea(AREA_DPAD_E, aRight = new RectangleArea(xx, yy, xx+Bw, yy+Bh)); - float maxPixels = _minecraft->pixelCalc.millimetersToPixels(10); + float maxPixels = _minecraft.pixelCalc.millimetersToPixels(10); // float btnSize = Mth::Min(18 * Gui::GuiScale, maxPixels); float btnSize = pc.millimetersToPixels(18 * Gui::GuiScale); _model.addArea(AREA_PAUSE, aPause = new RectangleArea(w - 4 - btnSize, 4, w - 4, 4 + btnSize)); @@ -312,15 +312,15 @@ void TouchscreenInput_TestFps::tick( Player* player ) } else if (areaId == AREA_PAUSE) { if (Multitouch::isReleased(p)) { - _minecraft->soundEngine->playUI("random.click", 1, 1); - _minecraft->screenChooser.setScreen(SCREEN_PAUSE); + _minecraft.soundEngine()->playUI("random.click", 1, 1); + _minecraft.screenChooser.setScreen(SCREEN_PAUSE); } } else if (areaId == AREA_CHAT) { if (Multitouch::isReleased(p)) { - _minecraft->soundEngine->playUI("random.click", 1, 1); - _minecraft->screenChooser.setScreen(SCREEN_CONSOLE); - _minecraft->platform()->showKeyboard(); + _minecraft.soundEngine()->playUI("random.click", 1, 1); + _minecraft.screenChooser.setScreen(SCREEN_CONSOLE); + _minecraft.platform()->showKeyboard(); } } @@ -409,7 +409,7 @@ void TouchscreenInput_TestFps::render( float a ) { glEnable2(GL_BLEND); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - _minecraft->textures->loadAndBindTexture("gui/gui.png"); + _minecraft.textures().loadAndBindTexture("gui/gui.png"); //glDisable2(GL_TEXTURE_2D); @@ -506,7 +506,7 @@ void TouchscreenInput_TestFps::rebuild() { drawRectangleArea(t, aJump, imageU + imageSize * 4, imageV, (float)imageSize); } - if (!_minecraft->screen) { + if (!_minecraft.screen) { t.colorABGR(0xFFFFFFFF); // if (isButtonDown(AREA_PAUSE)) t.colorABGR(cPressedPause); // else t.colorABGR(cReleasedPause); diff --git a/src/client/player/input/touchscreen/TouchscreenInput.hpp b/src/client/player/input/touchscreen/TouchscreenInput.hpp index 9d50c4d..8d81b19 100755 --- a/src/client/player/input/touchscreen/TouchscreenInput.hpp +++ b/src/client/player/input/touchscreen/TouchscreenInput.hpp @@ -9,7 +9,7 @@ class Options; class Player; -class Minecraft; +class MinecraftClient; class PolygonArea; // @todo: extract a separate MoveInput (-> merge XperiaPlayInput) @@ -26,7 +26,7 @@ public: static const int KEY_CRAFT = 6; static const int NumKeys = 7; - TouchscreenInput_TestFps(Minecraft* mc, Options* options); + TouchscreenInput_TestFps(MinecraftClient& mc, Options* options); ~TouchscreenInput_TestFps(); void onConfigChanged(const Config& c); @@ -53,7 +53,7 @@ private: bool _northJump; bool _renderFlightImage; TouchAreaModel _model; - Minecraft* _minecraft; + MinecraftClient& _minecraft; RectangleArea* aLeft; RectangleArea* aRight; diff --git a/src/client/renderer/GameRenderer.cpp b/src/client/renderer/GameRenderer.cpp index ee71628..e23eb66 100755 --- a/src/client/renderer/GameRenderer.cpp +++ b/src/client/renderer/GameRenderer.cpp @@ -10,7 +10,7 @@ #include "culling/FrustumCuller.hpp" #include "entity/EntityRenderDispatcher.hpp" #include -#include "client/gamemode/GameMode.hpp" +#include "gamemode/GameMode.hpp" #include "client/particle/ParticleEngine.hpp" #include "client/player/LocalPlayer.hpp" #include "client/gui/Screen.hpp" @@ -31,7 +31,7 @@ static int _shTicks = -1; -GameRenderer::GameRenderer( Minecraft* mc ) +GameRenderer::GameRenderer( MinecraftClient& mc ) : mc(mc), renderDistance(0), _tick(0), @@ -61,17 +61,17 @@ GameRenderer::GameRenderer( Minecraft* mc ) EntityRenderDispatcher* e = EntityRenderDispatcher::getInstance(); e->itemInHandRenderer = itemInHandRenderer; - e->textures = mc->textures; + e->textures = mc.textures; } GameRenderer::~GameRenderer() { delete itemInHandRenderer; } -void renderCursor(float x, float y, Minecraft* minecraft) { +void renderCursor(float x, float y, MinecraftClient& minecraft) { Tesselator& t = Tesselator::instance; - minecraft->textures->loadAndBindTexture("gui/cursor.png"); + minecraft.textures().loadAndBindTexture("gui/cursor.png"); glEnable(GL_BLEND); const float s = 32; @@ -90,9 +90,9 @@ void renderCursor(float x, float y, Minecraft* minecraft) { /*private*/ void GameRenderer::setupCamera(float a, int eye) { - renderDistance = (float) (16 * 16 >> (mc->options.getIntValue(OPTIONS_VIEW_DISTANCE))); + renderDistance = (float) (16 * 16 >> (mc.options.getIntValue(OPTIONS_VIEW_DISTANCE))); #if defined(ANDROID) - if (mc->isPowerVR() && mc->options.getIntValue(OPTIONS_VIEW_DISTANCE) <= 2) + if (mc.isPowerVR() && mc.options.getIntValue(OPTIONS_VIEW_DISTANCE) <= 2) renderDistance *= 0.8f; #endif @@ -100,21 +100,21 @@ void GameRenderer::setupCamera(float a, int eye) { glLoadIdentity2(); float stereoScale = 0.07f; - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2(-(eye * 2 - 1) * stereoScale, 0, 0); + if (mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2(-(eye * 2 - 1) * stereoScale, 0, 0); if (zoom != 1) { glTranslatef2((float) zoom_x, (float) -zoom_y, 0); glScalef2(zoom, zoom, 1); - gluPerspective(_setupCameraFov = getFov(a, true), mc->width / (float) mc->height, 0.05f, renderDistance); + gluPerspective(_setupCameraFov = getFov(a, true), mc.getScreenWidth() / (float) mc.getScreenHeight(), 0.05f, renderDistance); } else { - gluPerspective(_setupCameraFov = getFov(a, true), mc->width / (float) mc->height, 0.05f, renderDistance); + gluPerspective(_setupCameraFov = getFov(a, true), mc.getScreenWidth() / (float) mc.getScreenHeight(), 0.05f, renderDistance); } glMatrixMode(GL_MODELVIEW); glLoadIdentity2(); - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); + if (mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); bobHurt(a); - if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); + if (mc.options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); moveCameraToPlayer(a); } @@ -124,14 +124,14 @@ extern int _t_keepPic; /*public*/ void GameRenderer::render(float a) { TIMER_PUSH("mouse"); - if (mc->player && mc->mouseGrabbed) { - mc->mouseHandler.poll(); + if (mc.player && mc.mouseGrabbed) { + mc.mouseHandler.poll(); //printf("Controller.x,y : %f,%f\n", Controller::getX(0), Controller::getY(0)); - float ss = mc->options.getProgressValue(OPTIONS_SENSITIVITY) * 0.6f + 0.2f; + float ss = mc.options.getProgressValue(OPTIONS_SENSITIVITY) * 0.6f + 0.2f; float sens = (ss * ss * ss) * 8; - float xo = mc->mouseHandler.xd * sens * 4.f; - float yo = mc->mouseHandler.yd * sens * 4.f; + float xo = mc.mouseHandler.xd * sens * 4.f; + float yo = mc.mouseHandler.yd * sens * 4.f; const float now = _tick + a; float deltaT = now - _lastTickT; @@ -142,19 +142,19 @@ void GameRenderer::render(float a) { _rotY += yo; int yAxis = -1; - if (mc->options.getBooleanValue(OPTIONS_INVERT_Y_MOUSE)) yAxis = 1; + if (mc.options.getBooleanValue(OPTIONS_INVERT_Y_MOUSE)) yAxis = 1; - bool screenCovering = mc->screen && !mc->screen->passEvents; + bool screenCovering = mc.screen && !mc.screen->passEvents; if (!screenCovering) { - mc->player->turn(deltaT * _rotXlast, deltaT * _rotYlast * yAxis); + mc.player->turn(deltaT * _rotXlast, deltaT * _rotYlast * yAxis); } } int xMouse = (int)(Mouse::getX() * Gui::InvGuiScale); int yMouse = (int)(Mouse::getY() * Gui::InvGuiScale); - if (mc->useTouchscreen()) { + if (mc.useTouchscreen()) { const int pid = Multitouch::getFirstActivePointerIdExThisUpdate(); if (pid >= 0) { xMouse = (int)(Multitouch::getX(pid) * Gui::InvGuiScale); @@ -169,29 +169,29 @@ void GameRenderer::render(float a) { bool hasClearedColorBuffer = false; bool hasSetupGuiScreen = false; useScreenScissor = false; - if (mc->isLevelGenerated()) { + if (mc.isLevelGenerated()) { TIMER_PUSH("level"); if (_t_keepPic < 0) { - if (!(mc->screen && !mc->screen->renderGameBehind())) { + if (!(mc.screen && !mc.screen->renderGameBehind())) { - if (mc->screen && mc->screen->hasClippingArea(screenScissorArea)) + if (mc.screen && mc.screen->hasClippingArea(screenScissorArea)) useScreenScissor = true; renderLevel(a); hasClearedColorBuffer = true; - if (!mc->options.getBooleanValue(OPTIONS_HIDEGUI)) { + if (!mc.options.getBooleanValue(OPTIONS_HIDEGUI)) { TIMER_POP_PUSH("gui"); setupGuiScreen(false); hasSetupGuiScreen = true; - mc->gui.render(a, mc->screen != NULL, xMouse, yMouse); + mc.gui().render(a, mc.screen != NULL, xMouse, yMouse); } }} TIMER_POP(); } else { - glViewport(0, 0, mc->width, mc->height); + glViewport(0, 0, mc.getScreenWidth(), mc.getScreenHeight()); glMatrixMode(GL_PROJECTION); glLoadIdentity2(); glMatrixMode(GL_MODELVIEW); @@ -204,23 +204,23 @@ void GameRenderer::render(float a) { if (!hasSetupGuiScreen) setupGuiScreen(!hasClearedColorBuffer); - if (mc->player && mc->screen == NULL) { - if (mc->inputHolder) mc->inputHolder->render(a); - if (mc->player->input) mc->player->input->render(a); + if (mc.player && mc.screen == NULL) { + if (mc.inputHolder) mc.inputHolder->render(a); + if (mc.player->input) mc.player->input->render(a); } - if (mc->screen != NULL) { + if (mc.screen != NULL) { if (useScreenScissor) glDisable2(GL_SCISSOR_TEST); - mc->screen->render(xMouse, yMouse, a); + mc.screen->render(xMouse, yMouse, a); - mc->platform()->hideCursor(!mc->options.getBooleanValue(OPTIONS_RPI_CURSOR)); - if (mc->options.getBooleanValue(OPTIONS_RPI_CURSOR)) + mc.platform()->hideCursor(!mc.options.getBooleanValue(OPTIONS_RPI_CURSOR)); + if (mc.options.getBooleanValue(OPTIONS_RPI_CURSOR)) renderCursor(xMouse, yMouse, mc); // Screen might have been removed, so check it again - if (mc->screen && !mc->screen->isInGameScreen()) + if (mc.screen && !mc.screen->isInGameScreen()) sleepMs(15); } } @@ -228,10 +228,10 @@ void GameRenderer::render(float a) { /*public*/ void GameRenderer::renderLevel(float a) { - if (mc->cameraTargetPlayer == NULL) { - if (mc->player) + if (mc.cameraTargetPlayer == NULL) { + if (mc.player) { - mc->cameraTargetPlayer = mc->player; + mc.cameraTargetPlayer = mc.player; } else { @@ -242,21 +242,21 @@ void GameRenderer::renderLevel(float a) { TIMER_PUSH("pick"); pick(a); - Mob* cameraEntity = mc->cameraTargetPlayer; - LevelRenderer* levelRenderer = mc->levelRenderer; - ParticleEngine* particleEngine = mc->particleEngine; + Mob* cameraEntity = mc.cameraTargetPlayer; + LevelRenderer* levelRenderer = mc.levelRenderer; + ParticleEngine* particleEngine = mc.particleEngine; float xOff = cameraEntity->xOld + (cameraEntity->x - cameraEntity->xOld) * a; float yOff = cameraEntity->yOld + (cameraEntity->y - cameraEntity->yOld) * a; float zOff = cameraEntity->zOld + (cameraEntity->z - cameraEntity->zOld) * a; for (int i = 0; i < 2; i++) { - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { + if (mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { if (i == 0) glColorMask(false, true, true, false); else glColorMask(true, false, false, false); } TIMER_POP_PUSH("clear"); - glViewport(0, 0, mc->width, mc->height); + glViewport(0, 0, mc.getScreenWidth(), mc.getScreenHeight()); setupClearColor(a); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -272,7 +272,7 @@ void GameRenderer::renderLevel(float a) { screenScissorArea.w, screenScissorArea.h); } - if(mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { + if(mc.options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { setupFog(-1); TIMER_POP_PUSH("sky"); glFogf(GL_FOG_START, renderDistance * 0.2f); @@ -284,7 +284,7 @@ void GameRenderer::renderLevel(float a) { glEnable2(GL_FOG); setupFog(1); - if (mc->options.getBooleanValue(OPTIONS_AMBIENT_OCCLUSION)) { + if (mc.options.getBooleanValue(OPTIONS_AMBIENT_OCCLUSION)) { glShadeModel2(GL_SMOOTH); } @@ -293,17 +293,17 @@ void GameRenderer::renderLevel(float a) { frustum.prepare(xOff, yOff, zOff); TIMER_POP_PUSH("culling"); - mc->levelRenderer->cull(&frustum, a); - mc->levelRenderer->updateDirtyChunks(cameraEntity, false); + mc.levelRenderer->cull(&frustum, a); + mc.levelRenderer->updateDirtyChunks(cameraEntity, false); - if(mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { + if(mc.options.getBooleanValue(OPTIONS_FANCY_GRAPHICS)) { prepareAndRenderClouds(levelRenderer, a); } setupFog(0); glEnable2(GL_FOG); - mc->textures->loadAndBindTexture("terrain.png"); + mc.textures().loadAndBindTexture("terrain.png"); glDisable2(GL_ALPHA_TEST); glDisable2(GL_BLEND); glEnable2(GL_CULL_FACE); @@ -316,7 +316,7 @@ void GameRenderer::renderLevel(float a) { glShadeModel2(GL_FLAT); TIMER_POP_PUSH("entities"); - mc->levelRenderer->renderEntities(cameraEntity->getPos(a), &frustum, a); + mc.levelRenderer->renderEntities(cameraEntity->getPos(a), &frustum, a); // setupFog(0); TIMER_POP_PUSH("particles"); particleEngine->render(cameraEntity, a); @@ -328,12 +328,12 @@ void GameRenderer::renderLevel(float a) { glDisable2(GL_CULL_FACE); glDepthMask(GL_FALSE); glDisable2(GL_ALPHA_TEST); - mc->textures->loadAndBindTexture("terrain.png"); - //if (mc->options.fancyGraphics) { + mc.textures().loadAndBindTexture("terrain.png"); + //if (mc.options.fancyGraphics) { // glColorMask(false, false, false, false); // int visibleWaterChunks = levelRenderer->render(cameraEntity, 1, a); // glColorMask(true, true, true, true); - // if (mc->options.anaglyph3d) { + // if (mc.options.anaglyph3d) { // if (i == 0) glColorMask(false, true, true, false); // else glColorMask(true, false, false, false); // } @@ -357,13 +357,13 @@ void GameRenderer::renderLevel(float a) { glEnable2(GL_ALPHA_TEST); if (/*!Minecraft::FLYBY_MODE &&*/ zoom == 1 && cameraEntity->isPlayer()) { - if (mc->hitResult.isHit() && !cameraEntity->isUnderLiquid(Material::water)) { + if (mc.hitResult.isHit() && !cameraEntity->isUnderLiquid(Material::water)) { TIMER_POP_PUSH("select"); Player* player = (Player*) cameraEntity; - // if (mc->useTouchscreen()) { - levelRenderer->renderHitSelect(player, mc->hitResult, 0, NULL, a); //player.inventory->getSelected(), a); + // if (mc.useTouchscreen()) { + levelRenderer->renderHitSelect(player, mc.hitResult, 0, NULL, a); //player.inventory->getSelected(), a); // } - levelRenderer->renderHit(player, mc->hitResult, 0, NULL, a);//player->inventory.getSelected(), a); + levelRenderer->renderHit(player, mc.hitResult, 0, NULL, a);//player->inventory.getSelected(), a); } } @@ -375,13 +375,13 @@ void GameRenderer::renderLevel(float a) { // glDisable2(GL_FOG); setupFog(1); - if (zoom == 1 && !mc->options.getBooleanValue(OPTIONS_HIDEGUI)) { + if (zoom == 1 && !mc.options.getBooleanValue(OPTIONS_HIDEGUI)) { TIMER_POP_PUSH("hand"); glClear(GL_DEPTH_BUFFER_BIT); renderItemInHand(a, i); } - if (!mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { + if (!mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { TIMER_POP(); return; } @@ -391,16 +391,16 @@ void GameRenderer::renderLevel(float a) { } void GameRenderer::tickFov() { - if (mc->cameraTargetPlayer != mc->player) + if (mc.cameraTargetPlayer != mc.player) return; oFov = fov; - fov += (mc->player->getFieldOfViewModifier() - fov) * 0.5f; + fov += (mc.player->getFieldOfViewModifier() - fov) * 0.5f; } /*private*/ float GameRenderer::getFov(float a, bool applyEffects) { - Mob* player = mc->cameraTargetPlayer; + Mob* player = mc.cameraTargetPlayer; float fov = 70; if (applyEffects) @@ -417,7 +417,7 @@ float GameRenderer::getFov(float a, bool applyEffects) { /*private*/ void GameRenderer::moveCameraToPlayer(float a) { - Entity* player = mc->cameraTargetPlayer; + Entity* player = mc.cameraTargetPlayer; float heightOffset = player->heightOffset - 1.62f; @@ -433,10 +433,10 @@ void GameRenderer::moveCameraToPlayer(float a) { if(player->isPlayer() && ((Player*)player)->isSleeping()) { heightOffset += 1.0; glTranslatef(0.0f, 0.3f, 0); - if (!mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { - int t = mc->level->getTile(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); + if (!mc.options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { + int t = mc.level->getTile(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); if (t == Tile::bed->id) { - int data = mc->level->getData(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); + int data = mc.level->getData(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); int direction = data & 3; glRotatef(float(direction * 90), 0, 1, 0); @@ -444,10 +444,10 @@ void GameRenderer::moveCameraToPlayer(float a) { glRotatef(player->yRotO + (player->yRot - player->yRotO) * a + 180, 0, -1, 0); glRotatef(player->xRotO + (player->xRot - player->xRotO) * a, -1, 0, 0); } - } else if (mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW)/* || (player->isPlayer() && !player->isAlive())*/) { + } else if (mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW)/* || (player->isPlayer() && !player->isAlive())*/) { float cameraDist = thirdDistanceO + (thirdDistance - thirdDistanceO) * a; - if (mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { + if (mc.options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { float rotationY = thirdRotationO + (thirdRotation - thirdRotationO) * a; float xRot = thirdTiltO + (thirdTilt - thirdTiltO) * a; @@ -471,7 +471,7 @@ void GameRenderer::moveCameraToPlayer(float a) { yo *= 0.1f; zo *= 0.1f; - HitResult hr = mc->level->clip(Vec3(x + xo, y + yo, z + zo), Vec3(x - xd + xo + zo, y - yd + yo, z - zd + zo)); // newTemp + HitResult hr = mc.level->clip(Vec3(x + xo, y + yo, z + zo), Vec3(x - xd + xo + zo, y - yd + yo, z - zd + zo)); // newTemp if (hr.type != NO_HIT) { float dist = hr.pos.distanceTo(Vec3(x, y, z)); // newTemp if (dist < cameraDist) cameraDist = dist; @@ -490,7 +490,7 @@ void GameRenderer::moveCameraToPlayer(float a) { glTranslatef2(0, 0, -0.1f); } - if (!mc->options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { + if (!mc.options.getBooleanValue(OPTIONS_FIXED_CAMERA)) { glRotatef2(player->xRotO + (player->xRot - player->xRotO) * a, 1.0f, 0.0f, 0.0f); glRotatef2(player->yRotO + (player->yRot - player->yRotO) * a + 180, 0, 1, 0); //if (_t_keepPic > 0) @@ -500,7 +500,7 @@ void GameRenderer::moveCameraToPlayer(float a) { /*private*/ void GameRenderer::bobHurt(float a) { - Mob* player = mc->cameraTargetPlayer; + Mob* player = mc.cameraTargetPlayer; float hurt = player->hurtTime - a; @@ -523,11 +523,11 @@ void GameRenderer::bobHurt(float a) { /*private*/ void GameRenderer::bobView(float a) { - //if (mc->options.thirdPersonView) return; - if (!(mc->cameraTargetPlayer->isPlayer())) { + //if (mc.options.thirdPersonView) return; + if (!(mc.cameraTargetPlayer->isPlayer())) { return; } - Player* player = (Player*) mc->cameraTargetPlayer; + Player* player = (Player*) mc.cameraTargetPlayer; float wda = player->walkDist - player->walkDistO; float b = -(player->walkDist + wda * a); @@ -541,7 +541,7 @@ void GameRenderer::bobView(float a) { /*private*/ void GameRenderer::setupFog(int i) { - Mob* player = mc->cameraTargetPlayer; + Mob* player = mc.cameraTargetPlayer; float fogBuffer[4] = {fr, fg, fb, 1}; glFogfv(GL_FOG_COLOR, (GLfloat*)fogBuffer); @@ -555,7 +555,7 @@ void GameRenderer::setupFog(int i) { // float gg = 0.4f; // float bb = 0.9f; // -// if (mc->options.anaglyph3d) { +// if (mc.options.anaglyph3d) { // float rrr = (rr * 30 + gg * 59 + bb * 11) / 100; // float ggg = (rr * 30 + gg * 70) / (100); // float bbb = (rr * 30 + bb * 70) / (100); @@ -571,7 +571,7 @@ void GameRenderer::setupFog(int i) { // float gg = 0.3f; // float bb = 0.3f; // -// if (mc->options.anaglyph3d) { +// if (mc.options.anaglyph3d) { // float rrr = (rr * 30 + gg * 59 + bb * 11) / 100; // float ggg = (rr * 30 + gg * 70) / (100); // float bbb = (rr * 30 + bb * 70) / (100); @@ -589,7 +589,7 @@ void GameRenderer::setupFog(int i) { glFogf(GL_FOG_END, renderDistance * 1.0f); } - if (mc->level->dimension->foggy) { + if (mc.level->dimension->foggy) { glFogf(GL_FOG_START, 0); } } @@ -599,27 +599,27 @@ void GameRenderer::setupFog(int i) { } void GameRenderer::updateAllChunks() { - mc->levelRenderer->updateDirtyChunks(mc->cameraTargetPlayer, true); + mc.levelRenderer->updateDirtyChunks(mc.cameraTargetPlayer, true); } bool GameRenderer::updateFreeformPickDirection(float a, Vec3& outDir) { - if (!mc->inputHolder->allowPicking()) { + if (!mc.inputHolder->allowPicking()) { _shTicks = 1; return false; } - Vec3 c = mc->cameraTargetPlayer->getPos(a); + Vec3 c = mc.cameraTargetPlayer->getPos(a); - bool firstPerson = !mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); + bool firstPerson = !mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); const float PickingDistance = firstPerson? 6.0f : 12.0f; _shTicks = -1; - int vp[4] = {0, 0, mc->width, mc->height}; + int vp[4] = {0, 0, mc.getScreenWidth(), mc.getScreenHeight()}; float pt[3]; - float x = mc->inputHolder->mousex; - float y = mc->height - mc->inputHolder->mousey; + float x = mc.inputHolder->mousex; + float y = mc.getScreenHeight() - mc.inputHolder->mousey; //sw.start(); @@ -637,42 +637,42 @@ bool GameRenderer::updateFreeformPickDirection(float a, Vec3& outDir) { //sw.stop(); //sw.printEvery(30, "unproject "); - const HitResult& hit = mc->hitResult = mc->level->clip(p0, p1, false); + const HitResult& hit = mc.hitResult = mc.level->clip(p0, p1, false); // If in 3rd person view - verify that the hit target is within range if (!firstPerson && hit.isHit()) { const float MaxSqrDist = PickingDistance*PickingDistance; - if (mc->cameraTargetPlayer->distanceToSqr((float)hit.x, (float)hit.y, (float)hit.z) > MaxSqrDist) - mc->hitResult.type = NO_HIT; + if (mc.cameraTargetPlayer->distanceToSqr((float)hit.x, (float)hit.y, (float)hit.z) > MaxSqrDist) + mc.hitResult.type = NO_HIT; } return true; } /*public*/ void GameRenderer::pick(float a) { - if (mc->level == NULL) return; - if (mc->cameraTargetPlayer == NULL) return; - if (!mc->cameraTargetPlayer->isAlive()) return; + if (mc.level == NULL) return; + if (mc.cameraTargetPlayer == NULL) return; + if (!mc.cameraTargetPlayer->isAlive()) return; - float range = mc->gameMode->getPickRange(); + float range = mc.gameMode->getPickRange(); bool isPicking = true; - bool freeform = mc->useTouchscreen(); //&& !mc->options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA); + bool freeform = mc.useTouchscreen(); //&& !mc.options.getBooleanValue(OPTIONS_IS_JOY_TOUCH_AREA); if (freeform) { isPicking = updateFreeformPickDirection(a, pickDirection); } else { - mc->hitResult = mc->cameraTargetPlayer->pick(range, a); - pickDirection = mc->cameraTargetPlayer->getViewVector(a); + mc.hitResult = mc.cameraTargetPlayer->pick(range, a); + pickDirection = mc.cameraTargetPlayer->getViewVector(a); } - Vec3 from = mc->cameraTargetPlayer->getPos(a); + Vec3 from = mc.cameraTargetPlayer->getPos(a); float dist = range; - if (mc->hitResult.isHit()) { - dist = mc->hitResult.pos.distanceTo(from); + if (mc.hitResult.isHit()) { + dist = mc.hitResult.pos.distanceTo(from); } - if (mc->gameMode->isCreativeType()) { + if (mc.gameMode->isCreativeType()) { /*dist =*/ range = 12; } else { if (dist > 3) dist = 3; @@ -681,12 +681,12 @@ void GameRenderer::pick(float a) { Vec3 pv = (pickDirection * range); Vec3 to = from + pv; - mc->cameraTargetPlayer->aimDirection = pickDirection; + mc.cameraTargetPlayer->aimDirection = pickDirection; Entity* hovered = NULL; const float g = 1; - AABB aabb = mc->cameraTargetPlayer->bb.expand(pv.x, pv.y, pv.z).grow(g, g, g); - EntityList& objects = mc->level->getEntities(mc->cameraTargetPlayer, aabb); + AABB aabb = mc.cameraTargetPlayer->bb.expand(pv.x, pv.y, pv.z).grow(g, g, g); + EntityList& objects = mc.level->getEntities(mc.cameraTargetPlayer, aabb); float nearest = 0; for (unsigned int i = 0; i < objects.size(); i++) { Entity* e = objects[i]; @@ -714,26 +714,26 @@ void GameRenderer::pick(float a) { if (hovered != NULL) { if(nearest < dist) { - mc->hitResult = HitResult(hovered); + mc.hitResult = HitResult(hovered); } } - else if (isPicking && !mc->hitResult.isHit()) { + else if (isPicking && !mc.hitResult.isHit()) { // if we don't have a hit result, attempt to hit the edge of the block we are standing on // (this is an pocket edition simplification to help building floors) - //LOGI("hovered : %d (%f)\n", mc->hitResult.type, viewVec.y); + //LOGI("hovered : %d (%f)\n", mc.hitResult.type, viewVec.y); if (pickDirection.y < -.7f) { // looking down by more than roughly 45 degrees, fetch a hit to the block standing on Vec3 to = from.add(0, -2.0f, 0); - HitResult downHitResult = mc->level->clip(from, to); + HitResult downHitResult = mc.level->clip(from, to); if (downHitResult.isHit()) { - mc->hitResult = downHitResult; - mc->hitResult.indirectHit = true; + mc.hitResult = downHitResult; + mc.hitResult.indirectHit = true; // change face (not up) if (std::abs(pickDirection.x) > std::abs(pickDirection.z)) { - mc->hitResult.f = (pickDirection.x < 0)? 4 : 5; + mc.hitResult.f = (pickDirection.x < 0)? 4 : 5; } else { - mc->hitResult.f = (pickDirection.z < 0)? 2 : 3; + mc.hitResult.f = (pickDirection.z < 0)? 2 : 3; } } } @@ -743,13 +743,13 @@ void GameRenderer::pick(float a) { void GameRenderer::tick(int nTick, int maxTick) { --_t_keepPic; - if (!mc->player) + if (!mc.player) { return; } if (--_shTicks == 0) - mc->hitResult.type = NO_HIT; + mc.hitResult.type = NO_HIT; //_rotXlast = _rotX; //_rotYlast = _rotY; @@ -775,35 +775,35 @@ void GameRenderer::tick(int nTick, int maxTick) { fovOffsetO = fovOffset; cameraRollO = cameraRoll; - if (mc->cameraTargetPlayer == NULL) { - mc->cameraTargetPlayer = mc->player; + if (mc.cameraTargetPlayer == NULL) { + mc.cameraTargetPlayer = mc.player; } tickFov(); - float brr = mc->level->getBrightness( Mth::floor(mc->cameraTargetPlayer->x), - Mth::floor(mc->cameraTargetPlayer->y), - Mth::floor(mc->cameraTargetPlayer->z)); + float brr = mc.level->getBrightness( Mth::floor(mc.cameraTargetPlayer->x), + Mth::floor(mc.cameraTargetPlayer->y), + Mth::floor(mc.cameraTargetPlayer->z)); - float whiteness = (3 - mc->options.getIntValue(OPTIONS_VIEW_DISTANCE)) / 3.0f; + float whiteness = (3 - mc.options.getIntValue(OPTIONS_VIEW_DISTANCE)) / 3.0f; float fogBrT = brr * (1 - whiteness) + whiteness; fogBr += (fogBrT - fogBr) * 0.1f; _tick++; itemInHandRenderer->tick(); -// if (mc->isRaining) tickRain(); +// if (mc.isRaining) tickRain(); } /*private*/ void GameRenderer::setupClearColor(float a) { - Level* level = mc->level; - Mob* player = mc->cameraTargetPlayer; + Level* level = mc.level; + Mob* player = mc.cameraTargetPlayer; - float whiteness = 1.0f / (4 - mc->options.getIntValue(OPTIONS_VIEW_DISTANCE)); + float whiteness = 1.0f / (4 - mc.options.getIntValue(OPTIONS_VIEW_DISTANCE)); whiteness = 1 - (float) pow(whiteness, 0.25f); - Vec3 skyColor = level->getSkyColor(mc->cameraTargetPlayer, a); + Vec3 skyColor = level->getSkyColor(mc.cameraTargetPlayer, a); float sr = (float) skyColor.x; float sg = (float) skyColor.y; float sb = (float) skyColor.z; @@ -832,7 +832,7 @@ void GameRenderer::setupClearColor(float a) { fg *= brr; fb *= brr; - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { + if (mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) { float frr = (fr * 30 + fg * 59 + fb * 11) / 100; float fgg = (fr * 30 + fg * 70) / (100); float fbb = (fr * 30 + fb * 70) / (100); @@ -859,8 +859,8 @@ void GameRenderer::unZoomRegion() void GameRenderer::setupGuiScreen( bool clearColorBuffer ) { - int screenWidth = (int)(mc->width * Gui::InvGuiScale); - int screenHeight = (int)(mc->height * Gui::InvGuiScale); + int screenWidth = (int)(mc.getScreenWidth() * Gui::InvGuiScale); + int screenHeight = (int)(mc.getScreenHeight() * Gui::InvGuiScale); // Setup GUI render mode GLbitfield clearBits = clearColorBuffer? @@ -878,19 +878,19 @@ void GameRenderer::setupGuiScreen( bool clearColorBuffer ) /*private*/ void GameRenderer::renderItemInHand(float a, int eye) { glLoadIdentity2(); - if (mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); + if (mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D)) glTranslatef2((eye * 2 - 1) * 0.10f, 0, 0); glPushMatrix2(); bobHurt(a); - if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); + if (mc.options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); - if (!mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { - if (!mc->options.getBooleanValue(OPTIONS_HIDEGUI)) { + if (!mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc.cameraTargetPlayer->isPlayer() && !((Player*)mc.cameraTargetPlayer)->isSleeping())) { + if (!mc.options.getBooleanValue(OPTIONS_HIDEGUI)) { float fov = getFov(a, false); if (fov != _setupCameraFov) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(fov, mc->width / (float) mc->height, 0.05f, renderDistance); + gluPerspective(fov, mc.getScreenWidth() / (float) mc.getScreenHeight(), 0.05f, renderDistance); glMatrixMode(GL_MODELVIEW); } itemInHandRenderer->render(a); @@ -898,11 +898,11 @@ void GameRenderer::renderItemInHand(float a, int eye) { } glPopMatrix2(); - if (!mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping())) { + if (!mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) && (mc.cameraTargetPlayer->isPlayer() && !((Player*)mc.cameraTargetPlayer)->isSleeping())) { itemInHandRenderer->renderScreenEffect(a); bobHurt(a); } - if (mc->options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); + if (mc.options.getBooleanValue(OPTIONS_VIEW_BOBBING)) bobView(a); } void GameRenderer::onGraphicsReset() @@ -926,12 +926,12 @@ void GameRenderer::saveMatrices() } void GameRenderer::prepareAndRenderClouds( LevelRenderer* levelRenderer, float a ) { - //if(mc->options.isCloudsOn()) { + //if(mc.options.isCloudsOn()) { TIMER_PUSH("clouds"); glMatrixMode(GL_PROJECTION); glPushMatrix2(); glLoadIdentity2(); - gluPerspective(_setupCameraFov = getFov(a, true), mc->width / (float) mc->height, 2, renderDistance * 512); + gluPerspective(_setupCameraFov = getFov(a, true), mc.getScreenWidth() / (float) mc.getScreenHeight(), 2, renderDistance * 512); glMatrixMode(GL_MODELVIEW); glPushMatrix2(); setupFog(0); diff --git a/src/client/renderer/GameRenderer.hpp b/src/client/renderer/GameRenderer.hpp index 1757352..bc67cc2 100755 --- a/src/client/renderer/GameRenderer.hpp +++ b/src/client/renderer/GameRenderer.hpp @@ -8,14 +8,14 @@ #include "world/phys/Vec3.hpp" #include "client/gui/components/ImageButton.hpp" -class Minecraft; +class MinecraftClient; class Entity; class ItemInHandRenderer; class LevelRenderer; class GameRenderer { public: - GameRenderer(Minecraft* mc_); + GameRenderer(MinecraftClient& mc_); ~GameRenderer(); void pick(float a); @@ -54,7 +54,7 @@ public: ItemInHandRenderer* itemInHandRenderer; private: - Minecraft* mc; + MinecraftClient& mc; float renderDistance; int _tick; diff --git a/src/client/renderer/ItemInHandRenderer.cpp b/src/client/renderer/ItemInHandRenderer.cpp index cb6754e..76d308f 100755 --- a/src/client/renderer/ItemInHandRenderer.cpp +++ b/src/client/renderer/ItemInHandRenderer.cpp @@ -24,7 +24,7 @@ //static StopwatchHandler handler; -ItemInHandRenderer::ItemInHandRenderer( Minecraft* mc ) +ItemInHandRenderer::ItemInHandRenderer( MinecraftClient& mc ) : mc(mc), lastSlot(-1), height(0), @@ -51,7 +51,7 @@ void ItemInHandRenderer::tick() oHeight = height; item.id = 0; - ItemInstance* itemInHand = mc->player->inventory->getSelected(); + ItemInstance* itemInHand = mc.player->inventory->getSelected(); if (itemInHand && itemInHand->count > 0) { item.id = itemInHand->id; item.setAuxValue(itemInHand->getAuxValue()); @@ -122,10 +122,10 @@ void ItemInHandRenderer::renderItem(Mob* mob, ItemInstance* item ) if (item->id < 256) { renderObject.texture = "terrain.png"; - //mc->textures->loadAndBindTexture("terrain.png"); + //mc.textures().loadAndBindTexture("terrain.png"); } else { renderObject.texture = "gui/items.png"; - //mc->textures->loadAndBindTexture("gui/items.png"); + //mc.textures().loadAndBindTexture("gui/items.png"); } // glDisable2(GL_LIGHTING); Tesselator& t = Tesselator::instance; @@ -217,7 +217,7 @@ void ItemInHandRenderer::renderItem(Mob* mob, ItemInstance* item ) glRotatef2(45 + 290, 0, 0, 1); glTranslatef2(-15 / 16.0f, -1 / 16.0f, 0); } - mc->textures->loadAndBindTexture(renderObject.texture); + mc.textures().loadAndBindTexture(renderObject.texture); drawArrayVT_NoState(renderObject.chunk.vboId, renderObject.chunk.vertexCount); if (renderObject.isFlat) @@ -235,7 +235,7 @@ void ItemInHandRenderer::render( float a ) //w.start(); float h = oHeight + (height - oHeight) * a; - Player* player = mc->player; + Player* player = mc.player; // if (selectedTile==NULL) return; glPushMatrix2(); @@ -243,7 +243,7 @@ void ItemInHandRenderer::render( float a ) glRotatef2(player->yRotO + (player->yRot - player->yRotO) * a, 0, 1, 0); glPopMatrix2(); - float br = mc->level->getBrightness(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); + float br = mc.level->getBrightness(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); ItemInstance* item;// = selectedItem; //if (player.fishing != NULL) { @@ -354,7 +354,7 @@ void ItemInHandRenderer::render( float a ) glRotatef2(-swing3 * 20, 0, 0, 1); // glRotatef2(-swing2 * 80, 1, 0, 0); - mc->textures->loadAndBindTexture(player->getTexture()); + mc.textures().loadAndBindTexture(player->getTexture()); glTranslatef2(-1.0f, +3.6f, +3.5f); glRotatef2(120, 0, 0, 1); glRotatef2(180 + 20, 1, 0, 0); @@ -362,7 +362,7 @@ void ItemInHandRenderer::render( float a ) glScalef2(1.5f / 24.0f * 16, 1.5f / 24.0f * 16, 1.5f / 24.0f * 16); glTranslatef2(5.6f, 0, 0); - EntityRenderer* er = EntityRenderDispatcher::getInstance()->getRenderer(mc->player); + EntityRenderer* er = EntityRenderDispatcher::getInstance()->getRenderer(mc.player); HumanoidMobRenderer* playerRenderer = (HumanoidMobRenderer*) er; float ss = 1; glScalef2(ss, ss, ss); @@ -377,26 +377,26 @@ void ItemInHandRenderer::render( float a ) void ItemInHandRenderer::renderScreenEffect( float a ) { glDisable2(GL_ALPHA_TEST); - if (mc->player->isOnFire()) { - mc->textures->loadAndBindTexture("terrain.png"); + if (mc.player->isOnFire()) { + mc.textures().loadAndBindTexture("terrain.png"); renderFire(a); } - if (mc->player->isInWall()) // Inside a tile + if (mc.player->isInWall()) // Inside a tile { - int x = Mth::floor(mc->player->x); - int y = Mth::floor(mc->player->y); - int z = Mth::floor(mc->player->z); + int x = Mth::floor(mc.player->x); + int y = Mth::floor(mc.player->y); + int z = Mth::floor(mc.player->z); - mc->textures->loadAndBindTexture("terrain.png"); - int tile = mc->level->getTile(x, y, z); + mc.textures().loadAndBindTexture("terrain.png"); + int tile = mc.level->getTile(x, y, z); if (Tile::tiles[tile] != NULL) { renderTex(a, Tile::tiles[tile]->getTexture(2)); } } - // if (mc->player->isUnderLiquid(Material::water)) { - //mc->textures->loadAndBindTexture("misc/water.png"); + // if (mc.player->isUnderLiquid(Material::water)) { + //mc.textures().loadAndBindTexture("misc/water.png"); // renderWater(a); // } glEnable2(GL_ALPHA_TEST); @@ -416,7 +416,7 @@ void ItemInHandRenderer::renderTex( float a, int tex ) { Tesselator& t = Tesselator::instance; - float br;// = mc->player->getBrightness(a); + float br;// = mc.player->getBrightness(a); br = 0.1f; glColor4f2(br, br, br, 0.5f); @@ -450,7 +450,7 @@ void ItemInHandRenderer::renderWater( float a ) { Tesselator& t = Tesselator::instance; - float br = mc->player->getBrightness(a); + float br = mc.player->getBrightness(a); glColor4f2(br, br, br, 0.5f); glEnable2(GL_BLEND); glBlendFunc2(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -465,8 +465,8 @@ void ItemInHandRenderer::renderWater( float a ) float y1 = +1; float z0 = -0.5f; - float uo = -mc->player->yRot / 64.0f; - float vo = +mc->player->xRot / 64.0f; + float uo = -mc.player->yRot / 64.0f; + float vo = +mc.player->xRot / 64.0f; t.begin(); t.vertexUV(x0, y0, z0, size + uo, size + vo); diff --git a/src/client/renderer/ItemInHandRenderer.hpp b/src/client/renderer/ItemInHandRenderer.hpp index eefab5c..3341238 100755 --- a/src/client/renderer/ItemInHandRenderer.hpp +++ b/src/client/renderer/ItemInHandRenderer.hpp @@ -6,7 +6,7 @@ #include "client/renderer/RenderChunk.hpp" #include "world/item/ItemInstance.hpp" -class Minecraft; +class MinecraftClient; typedef struct RenderCall { int itemId; @@ -19,7 +19,7 @@ typedef struct RenderCall { class ItemInHandRenderer { public: - ItemInHandRenderer(Minecraft* mc); + ItemInHandRenderer(MinecraftClient& mc); void tick(); @@ -43,7 +43,7 @@ private: int lastSlot; ItemInstance item; - Minecraft* mc; + MinecraftClient& mc; //ItemInstance* selectedItem; float height; float oHeight; diff --git a/src/client/renderer/LevelRenderer.cpp b/src/client/renderer/LevelRenderer.cpp index ad6dc4a..b6e40ab 100755 --- a/src/client/renderer/LevelRenderer.cpp +++ b/src/client/renderer/LevelRenderer.cpp @@ -31,9 +31,9 @@ /* static */ const int LevelRenderer::CHUNK_SIZE = 16; #endif -LevelRenderer::LevelRenderer( Minecraft* mc) +LevelRenderer::LevelRenderer( MinecraftClient& mc) : mc(mc), - textures(mc->textures), + textures(mc.textures()), level(NULL), cullStep(0), @@ -149,16 +149,16 @@ void LevelRenderer::allChanged() { deleteChunks(); - bool fancy = mc->options.getBooleanValue(OPTIONS_FANCY_GRAPHICS); + bool fancy = mc.options.getBooleanValue(OPTIONS_FANCY_GRAPHICS); Tile::leaves->setFancy(fancy); Tile::leaves_carried->setFancy(fancy); - lastViewDistance = mc->options.getIntValue(OPTIONS_VIEW_DISTANCE); + lastViewDistance = mc.options.getIntValue(OPTIONS_VIEW_DISTANCE); int dist = (512 >> 3) << (3 - lastViewDistance); - if (lastViewDistance <= 2 && mc->isPowerVR()) + if (lastViewDistance <= 2 && mc.isPowerVR()) dist = (int)((float)dist * 0.8f); - LOGI("last: %d, power: %d\n", lastViewDistance, mc->isPowerVR()); + LOGI("last: %d, power: %d\n", lastViewDistance, mc.isPowerVR()); #if defined(RPI) dist *= 0.6f; @@ -214,7 +214,7 @@ void LevelRenderer::allChanged() } if (level != NULL) { - Entity* player = mc->cameraTargetPlayer; + Entity* player = mc.cameraTargetPlayer; if (player != NULL) { this->resortChunks(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); DistanceChunkSorter distanceSorter(player); @@ -297,7 +297,7 @@ void LevelRenderer::resortChunks( int xc, int yc, int zc ) int LevelRenderer::render( Mob* player, int layer, float alpha ) { - if (mc->options.getIntValue(OPTIONS_VIEW_DISTANCE) != lastViewDistance) { + if (mc.options.getIntValue(OPTIONS_VIEW_DISTANCE) != lastViewDistance) { allChanged(); } @@ -336,7 +336,7 @@ int LevelRenderer::render( Mob* player, int layer, float alpha ) } int count = 0; - if (occlusionCheck && !mc->options.getBooleanValue(OPTIONS_ANAGLYPH_3D) && layer == 0) { + if (occlusionCheck && !mc.options.getBooleanValue(OPTIONS_ANAGLYPH_3D) && layer == 0) { int from = 0; int to = 16; //checkQueryResults(from, to); @@ -439,7 +439,7 @@ void LevelRenderer::renderDebug(const AABB& b, float a) const { t.begin(); t.color(255, 255, 255, 255); - t.offset(((Mob*)mc->player)->getPos(a).negated()); + t.offset(((Mob*)mc.player)->getPos(a).negated()); // up t.vertexUV(x0, y0, z1, u0, v1); @@ -495,7 +495,7 @@ void LevelRenderer::render(const AABB& b) const //t.begin(); t.color(255, 255, 255, 255); - t.offset(((Mob*)mc->player)->getPos(0).negated()); + t.offset(((Mob*)mc.player)->getPos(0).negated()); t.begin(GL_LINE_STRIP); t.vertex(b.x0, b.y0, b.z0); @@ -558,7 +558,7 @@ int LevelRenderer::renderChunks( int from, int to, int layer, float alpha ) } } - Mob* player = mc->cameraTargetPlayer; + Mob* player = mc.cameraTargetPlayer; float xOff = player->xOld + (player->x - player->xOld) * alpha; float yOff = player->yOld + (player->y - player->yOld) * alpha; float zOff = player->zOld + (player->z - player->zOld) * alpha; @@ -917,14 +917,14 @@ void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { } 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.getFont(), mc.cameraTargetPlayer, a); + EntityRenderDispatcher::getInstance()->prepare(level, mc.getFont(), mc.cameraTargetPlayer, &mc.options, a); totalEntities = 0; renderedEntities = 0; culledEntities = 0; - Entity* player = mc->cameraTargetPlayer; + 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); @@ -940,12 +940,12 @@ void LevelRenderer::renderEntities(Vec3 cam, Culler* culler, float a) { for (int i = 0; i < totalEntities; i++) { Entity* entity = entities[i]; - bool thirdPerson = mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); + bool thirdPerson = mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); if (entity->shouldRender(cam) && culler->isVisible(entity->bb)) { - if (entity == mc->cameraTargetPlayer && thirdPerson == 0 && mc->cameraTargetPlayer->isPlayer() && !((Player*)mc->cameraTargetPlayer)->isSleeping()) continue; - if (entity == mc->cameraTargetPlayer && !thirdPerson) + if (entity == mc.cameraTargetPlayer && thirdPerson == 0 && mc.cameraTargetPlayer->isPlayer() && !((Player*)mc.cameraTargetPlayer)->isSleeping()) continue; + if (entity == mc.cameraTargetPlayer && !thirdPerson) continue; if (!level->hasChunkAt(Mth::floor(entity->x), Mth::floor(entity->y), Mth::floor(entity->z))) continue; @@ -992,15 +992,15 @@ 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); + 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)) { + 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); @@ -1023,10 +1023,10 @@ void LevelRenderer::renderSky(float alpha) { } void LevelRenderer::renderClouds( float alpha ) { - //if (!mc->level->dimension->isNaturalDimension()) return; + //if (!mc.level->dimension->isNaturalDimension()) return; glEnable2(GL_TEXTURE_2D); glDisable(GL_CULL_FACE); - float yOffs = (float) (mc->player->yOld + (mc->player->y - mc->player->yOld) * alpha); + float yOffs = (float) (mc.player->yOld + (mc.player->y - mc.player->yOld) * alpha); int s = 32; int d = 256 / s; Tesselator& t = Tesselator::instance; @@ -1045,14 +1045,14 @@ void LevelRenderer::renderClouds( float alpha ) { float scale = 1 / 2048.0f; float time = (ticks + alpha); - float xo = mc->player->xo + (mc->player->x - mc->player->xo) * alpha + time * 0.03f; - float zo = mc->player->zo + (mc->player->z - mc->player->zo) * alpha; + float xo = mc.player->xo + (mc.player->x - mc.player->xo) * alpha + time * 0.03f; + float zo = mc.player->zo + (mc.player->z - mc.player->zo) * alpha; int xOffs = Mth::floor(xo / 2048); int zOffs = Mth::floor(zo / 2048); xo -= xOffs * 2048; zo -= zOffs * 2048; - float yy = /*level.dimension.getCloudHeight()*/ 128 - yOffs + 0.33f;//mc->player->y + 1; + float yy = /*level.dimension.getCloudHeight()*/ 128 - yOffs + 0.33f;//mc.player->y + 1; float uo = (float) (xo * scale); float vo = (float) (zo * scale); t.begin(); @@ -1077,16 +1077,16 @@ void LevelRenderer::playSound(const std::string& name, float x, float y, float z 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 (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 xd = mc.cameraTargetPlayer->x - x; + float yd = mc.cameraTargetPlayer->y - y; + float zd = mc.cameraTargetPlayer->z - z; float distanceSquared = xd * xd + yd * yd + zd * zd; //Particle* p = NULL; @@ -1095,7 +1095,7 @@ void LevelRenderer::addParticle(const std::string& name, float x, float y, float //if (p) { // if (distanceSquared < 32 * 32) { - // mc->particleEngine->add(p); + // mc.particleEngine->add(p); // } else { delete p; } // return; //} @@ -1106,21 +1106,21 @@ void LevelRenderer::addParticle(const std::string& name, float x, float y, float //static Stopwatch sw; //sw.start(); - 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 == "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 == "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)); + 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 == "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 == "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)); //sw.stop(); //sw.printEvery(50, "add-particle-string"); @@ -1128,9 +1128,9 @@ 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; @@ -1140,15 +1140,15 @@ void LevelRenderer::addParticle(ParticleType::Id name, float x, float y, float z //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; @@ -1170,7 +1170,7 @@ void LevelRenderer::addParticle(ParticleType::Id name, float x, float y, float z // break; //} //if (p) { - // mc->particleEngine->add(p); + // mc.particleEngine->add(p); //} //sw.stop(); @@ -1261,29 +1261,29 @@ int _t_keepPic = -1; void LevelRenderer::takePicture( TripodCamera* cam, Entity* entity ) { // Push old values - Mob* oldCameraEntity = mc->cameraTargetPlayer; - bool hideGui = mc->options.getBooleanValue(OPTIONS_HIDEGUI); - bool thirdPerson = mc->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); + Mob* oldCameraEntity = mc.cameraTargetPlayer; + bool hideGui = mc.options.getBooleanValue(OPTIONS_HIDEGUI); + bool thirdPerson = mc.options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW); // @huge @attn: This is highly illegal, super temp! - mc->cameraTargetPlayer = (Mob*)cam; - mc->options.set(OPTIONS_HIDEGUI, true); - mc->options.set(OPTIONS_THIRD_PERSON_VIEW, false); + mc.cameraTargetPlayer = (Mob*)cam; + mc.options.set(OPTIONS_HIDEGUI, true); + mc.options.set(OPTIONS_THIRD_PERSON_VIEW, false); - mc->gameRenderer->renderLevel(0); + mc.gameRenderer->renderLevel(0); // Pop values back - mc->cameraTargetPlayer = oldCameraEntity; - mc->options.set(OPTIONS_HIDEGUI, hideGui); - mc->options.set(OPTIONS_THIRD_PERSON_VIEW, thirdPerson); + mc.cameraTargetPlayer = oldCameraEntity; + mc.options.set(OPTIONS_HIDEGUI, hideGui); + mc.options.set(OPTIONS_THIRD_PERSON_VIEW, thirdPerson); _t_keepPic = -1; // Save image static char filename[256]; - sprintf(filename, "%s/games/com.mojang/img_%.4d.jpg", mc->externalStoragePath.c_str(), getTimeMs()); + sprintf(filename, "%s/games/com.mojang/img_%.4d.jpg", mc.externalStoragePath.c_str(), getTimeMs()); - mc->platform()->saveScreenshot(filename, mc->width, mc->height); + mc.platform()->saveScreenshot(filename, mc.getScreenWidth(), mc.getScreenHeight()); } void LevelRenderer::levelEvent(Player* player, int type, int x, int y, int z, int data) { diff --git a/src/client/renderer/LevelRenderer.hpp b/src/client/renderer/LevelRenderer.hpp index 7bd5374..5de3d15 100755 --- a/src/client/renderer/LevelRenderer.hpp +++ b/src/client/renderer/LevelRenderer.hpp @@ -107,7 +107,7 @@ public: private: int xChunks, yChunks, zChunks; int chunkLists; - Minecraft* mc; + MinecraftClient& mc; bool occlusionCheck; int lastViewDistance; diff --git a/src/client/renderer/entity/EntityRenderDispatcher.cpp b/src/client/renderer/entity/EntityRenderDispatcher.cpp index fa62a30..1f0a8f8 100755 --- a/src/client/renderer/entity/EntityRenderDispatcher.cpp +++ b/src/client/renderer/entity/EntityRenderDispatcher.cpp @@ -163,7 +163,7 @@ void EntityRenderDispatcher::setLevel( Level* level ) this->level = level; } -void EntityRenderDispatcher::setMinecraft( Minecraft* minecraft ) +void EntityRenderDispatcher::setMinecraft( MinecraftClient& minecraft ) { this->minecraft = minecraft; } diff --git a/src/client/renderer/entity/EntityRenderDispatcher.hpp b/src/client/renderer/entity/EntityRenderDispatcher.hpp index 90e7412..3afa267 100755 --- a/src/client/renderer/entity/EntityRenderDispatcher.hpp +++ b/src/client/renderer/entity/EntityRenderDispatcher.hpp @@ -10,7 +10,7 @@ class Level; class Font; class Textures; class ItemInHandRenderer; -class Minecraft; +class MinecraftClient; class Textures; class Options; class Entity; @@ -37,7 +37,7 @@ public: EntityRenderer* getRenderer( EntityRendererId rendererId ); void setLevel(Level* level); - void setMinecraft(Minecraft* minecraft); + void setMinecraft(MinecraftClient& minecraft); float distanceToSqr(float x, float y, float z); @@ -55,7 +55,7 @@ public: Textures* textures; Level* level; - Minecraft* minecraft; + MinecraftClient& minecraft; Mob* cameraEntity; float playerRotY; diff --git a/src/client/renderer/entity/ItemRenderer.cpp b/src/client/renderer/entity/ItemRenderer.cpp index e74fed5..80fc542 100755 --- a/src/client/renderer/entity/ItemRenderer.cpp +++ b/src/client/renderer/entity/ItemRenderer.cpp @@ -166,10 +166,10 @@ int ItemRenderer::getAtlasPos(const ItemInstance* item) { } /*static*/ -void ItemRenderer::renderGuiItem(Font* font, Textures* textures, const ItemInstance* item, float x, float y, bool fancy) { +void ItemRenderer::renderGuiItem(Font* font, Textures& textures, const ItemInstance* item, float x, float y, bool fancy) { renderGuiItem(font, textures, item, x, y, 16, 16, fancy); } -void ItemRenderer::renderGuiItem(Font* font, Textures* textures, const ItemInstance* item, float x, float y, float w, float h, bool fancy) { +void ItemRenderer::renderGuiItem(Font* font, Textures& textures, const ItemInstance* item, float x, float y, float w, float h, bool fancy) { if (item == NULL) { //LOGW("item is NULL @ ItemRenderer::renderGuiItem\n"); return; @@ -261,7 +261,7 @@ void ItemRenderer::fillRect(Tesselator& t, float x, float y, float w, float h, i } -void ItemRenderer::renderGuiItemCorrect(Font* font, Textures* textures, const ItemInstance* item, int x, int y) { +void ItemRenderer::renderGuiItemCorrect(Font* font, Textures& textures, const ItemInstance* item, int x, int y) { if (item == NULL) return; diff --git a/src/client/renderer/entity/ItemRenderer.hpp b/src/client/renderer/entity/ItemRenderer.hpp index c5c03f5..41d2170 100755 --- a/src/client/renderer/entity/ItemRenderer.hpp +++ b/src/client/renderer/entity/ItemRenderer.hpp @@ -18,10 +18,10 @@ public: ItemRenderer(); void render(Entity* itemEntity_, float x, float y, float z, float rot, float a); - 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 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(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 010c4c7..8f35aea 100755 --- a/src/client/renderer/entity/MobRenderer.cpp +++ b/src/client/renderer/entity/MobRenderer.cpp @@ -2,7 +2,7 @@ #include "EntityRenderDispatcher.hpp" #include "client/gui/Font.hpp" #include "client/renderer/Tesselator.hpp" -#include "client/Minecraft.hpp" +#include #include "client/model/Model.hpp" #include "world/entity/Mob.hpp" #include "util/Mth.hpp" @@ -220,7 +220,7 @@ void MobRenderer::renderNameTag(Mob* mob, const std::string& name, float x, floa glDisable2(GL_TEXTURE_2D); t.begin(); - int w = font->width(name) / 2; + int w = font.width(name) / 2; t.color(0.0f, 0.0f, 0.0f, 0.25f); t.vertex(-(float)w - 1, -1, 0); t.vertex(-(float)w - 1, +8, 0); @@ -229,12 +229,12 @@ void MobRenderer::renderNameTag(Mob* mob, const std::string& name, float x, floa //t.end(); t.draw(); glEnable2(GL_TEXTURE_2D); - const float fnameWidth = (float)font->width(name) / -2; - font->draw(name, fnameWidth, 0, 0x20ffffff); + const float fnameWidth = (float)font.width(name) / -2; + font.draw(name, fnameWidth, 0, 0x20ffffff); glEnable2(GL_DEPTH_TEST); glDepthMask(true); - font->draw(name, (float) fnameWidth, 0, 0xffffffff); + font.draw(name, (float) fnameWidth, 0, 0xffffffff); glDisable2(GL_BLEND); glColor4f2(1, 1, 1, 1); glPopMatrix2(); diff --git a/src/client/renderer/entity/TripodCameraRenderer.cpp b/src/client/renderer/entity/TripodCameraRenderer.cpp index b9db99c..2e81b4a 100755 --- a/src/client/renderer/entity/TripodCameraRenderer.cpp +++ b/src/client/renderer/entity/TripodCameraRenderer.cpp @@ -1,7 +1,7 @@ #include "TripodCameraRenderer.hpp" #include "EntityRenderDispatcher.hpp" #include "client/renderer/Tesselator.hpp" -#include "client/Minecraft.hpp" +#include #include "world/entity/item/TripodCamera.hpp" #include "world/level/material/Material.hpp" @@ -46,7 +46,7 @@ void TripodCameraRenderer::render(Entity* cam_, float x, float y, float z, float bindTexture("item/camera.png"); cameraCube.render(1.0f / 16.0f); - bool isCurrentlyPicked = entityRenderDispatcher->minecraft->hitResult.entity == cam; + bool isCurrentlyPicked = entityRenderDispatcher->minecraft.hitResult.entity == cam; const float flashLife = getFlashTime(cam, a); diff --git a/src/client/renderer/tileentity/SignRenderer.cpp b/src/client/renderer/tileentity/SignRenderer.cpp index 9194448..7e5d983 100755 --- a/src/client/renderer/tileentity/SignRenderer.cpp +++ b/src/client/renderer/tileentity/SignRenderer.cpp @@ -49,9 +49,9 @@ void SignRenderer::render( TileEntity* te, float x, float y, float z, float a ) std::string& msg = sign->messages[i]; if (i == sign->selectedLine) { std::string s = "> " + msg + " <"; - font->draw(s, (float)-font->width(s) / 2, yy, col); + font.draw(s, (float)-font.width(s) / 2, yy, col); } else { - font->draw(msg, (float)-font->width(msg) / 2, yy, col); + font.draw(msg, (float)-font.width(msg) / 2, yy, col); } yy += 10; } diff --git a/src/client/renderer/tileentity/TileEntityRenderDispatcher.cpp b/src/client/renderer/tileentity/TileEntityRenderDispatcher.cpp index 3d07794..7f7e7c0 100755 --- a/src/client/renderer/tileentity/TileEntityRenderDispatcher.cpp +++ b/src/client/renderer/tileentity/TileEntityRenderDispatcher.cpp @@ -40,7 +40,7 @@ void TileEntityRenderDispatcher::destroy() } } -void TileEntityRenderDispatcher::prepare( Level* level, Textures* textures, Font* font, Mob* player, float a ) +void TileEntityRenderDispatcher::prepare( Level* level, Textures& textures, Font* font, Mob* player, float a ) { if (this->level != level) setLevel(level); diff --git a/src/client/renderer/tileentity/TileEntityRenderDispatcher.hpp b/src/client/renderer/tileentity/TileEntityRenderDispatcher.hpp index a10b2ee..3b4a642 100755 --- a/src/client/renderer/tileentity/TileEntityRenderDispatcher.hpp +++ b/src/client/renderer/tileentity/TileEntityRenderDispatcher.hpp @@ -25,7 +25,7 @@ public: static void destroy(); void setLevel(Level* level); - void prepare(Level* level, Textures* textures, Font* font, Mob* player, float a); + void prepare(Level* level, Textures& textures, Font* font, Mob* player, float a); void render(TileEntity* e, float a); void render(TileEntity* entity, float x, float y, float z, float a); diff --git a/src/client/sound/SoundEngine.cpp b/src/client/sound/SoundEngine.cpp index 327012e..9b5a658 100755 --- a/src/client/sound/SoundEngine.cpp +++ b/src/client/sound/SoundEngine.cpp @@ -21,7 +21,7 @@ SoundEngine::~SoundEngine() } -void SoundEngine::init( Minecraft* mc, Options* options ) +void SoundEngine::init( MinecraftClient& mc, Options* options ) { this->mc = mc; this->options = options; @@ -196,13 +196,13 @@ void SoundEngine::play(const std::string& name, float x, float y, float z, float if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; volume *= _getVolumeMult(x, y, z); - mc->platform()->playSound(name, volume, pitch); + mc.platform()->playSound(name, volume, pitch); } void SoundEngine::playUI(const std::string& name, float volume, float pitch) { if ((volume *= options->getProgressValue(OPTIONS_SOUND_VOLUME)) <= 0) return; //volume *= 2.0f; - mc->platform()->playSound(name, volume, pitch); + mc.platform()->playSound(name, volume, pitch); } #elif defined(__APPLE__) void SoundEngine::play(const std::string& name, float x, float y, float z, float volume, float pitch) { diff --git a/src/client/sound/SoundEngine.hpp b/src/client/sound/SoundEngine.hpp index 5cd7d97..a93bdbb 100755 --- a/src/client/sound/SoundEngine.hpp +++ b/src/client/sound/SoundEngine.hpp @@ -12,7 +12,7 @@ #include "SoundRepository.hpp" #include "util/Random.hpp" -class Minecraft; +class MinecraftClient; class Mob; class Options; @@ -44,7 +44,7 @@ public: ~SoundEngine(); - void init(Minecraft* mc, Options* options); + void init(MinecraftClient& mc, Options* options); void destroy(); void enable(bool status); @@ -61,6 +61,6 @@ private: SoundDesc _pp(const std::string& fn); SoundRepository sounds; - Minecraft* mc; + MinecraftClient& mc; }; diff --git a/src/client/sound/SoundEngine.mm b/src/client/sound/SoundEngine.mm index 047376e..6f40a5f 100755 --- a/src/client/sound/SoundEngine.mm +++ b/src/client/sound/SoundEngine.mm @@ -193,7 +193,7 @@ SoundDesc SoundEngine::_pp(const std::string& fn) { return SoundDesc(); } -void SoundEngine::init( Minecraft* mc, Options* options ) +void SoundEngine::init( MinecraftClient& mc, Options* options ) { this->mc = mc; this->options = options; diff --git a/src/gamemode/SurvivalMode.cpp b/src/gamemode/SurvivalMode.cpp index 745d863..da082d4 100755 --- a/src/gamemode/SurvivalMode.cpp +++ b/src/gamemode/SurvivalMode.cpp @@ -27,7 +27,7 @@ void SurvivalMode::continueDestroyBlock(Player* player, int x, int y, int z, int if ((++destroyTicks & 3) == 1) { #ifndef STANDALONE_SERVER if (tile != NULL) { - minecraft->soundEngine->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f); + minecraft.soundEngine()->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f); } #endif } @@ -59,7 +59,7 @@ bool SurvivalMode::destroyBlock(Player* player, int x, int y, int z, int face ) if (item != NULL) { item->mineBlock(t, x, y, z); if (item->count == 0) { - //item->snap(minecraft->player); + //item->snap(minecraft.player()); player->inventory->clearSlot(player->inventory->selected); } } diff --git a/src/network/ClientSideNetworkHandler.cpp b/src/network/ClientSideNetworkHandler.cpp index d932e12..149e286 100755 --- a/src/network/ClientSideNetworkHandler.cpp +++ b/src/network/ClientSideNetworkHandler.cpp @@ -94,14 +94,14 @@ void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid) level->isClientSide = false; for (int i = (int)level->players.size()-1; i >= 0; --i ) { Player* p = level->players[i]; - if (p != minecraft.getPlayer()) { + if (p != minecraft.player()) { p->reallyRemoveIfPlayer = true; level->removeEntity(p); } } } #ifndef STANDALONE_SERVER - minecraft.gui.addMessage("Disconnected from server"); + minecraft.gui().addMessage("Disconnected from server"); #endif } @@ -164,7 +164,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MessageP { LOGI("MessagePacket\n"); #ifndef STANDALONE_SERVER - minecraft.gui.addMessage(packet->message.C_String()); + minecraft.gui().addMessage(packet->message.C_String()); #endif } @@ -283,12 +283,12 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, AddPlaye std::string message = packet->name.C_String(); message += " joined the game"; #ifndef STANDALONE_SERVER - minecraft.gui.addMessage(message); + minecraft.gui().addMessage(message); #endif } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemovePlayerPacket* packet) { - if (!level || source == minecraft.getPlayer()->owner) return; + if (!level || source == minecraft.player()->owner) return; if (Player* player = findPlayer(level, packet->entityId, &packet->owner)) { player->reallyRemoveIfPlayer = true; @@ -307,7 +307,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemovePl //std::string message = packet->name.C_String(); //message += " joined the game"; - //minecraft.gui.addMessage(message); + //minecraft.gui().addMessage(message); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveEntityPacket* packet) @@ -315,7 +315,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveEn if (!level) return; Entity* entity = level->getEntity(packet->entityId); - LOGI("RemoveEntityPacket %p %p, %d\n", entity, minecraft.getPlayer(), entity?(int)(entity->isPlayer()): -1); + LOGI("RemoveEntityPacket %p %p, %d\n", entity, minecraft.player(), entity?(int)(entity->isPlayer()): -1); if (!entity) return; level->removeEntity(entity); @@ -356,8 +356,8 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, TakeItem return; // try take it and if we don't have space; re-throw it - if (minecraft.getPlayer()->entityId == packet->playerId - && !minecraft.getPlayer()->inventory->add(&item)) { + if (minecraft.player()->entityId == packet->playerId + && !minecraft.player()->inventory->add(&item)) { DropItemPacket dropPacket(packet->playerId, item); minecraft.raknetInstance->send(dropPacket); } @@ -429,7 +429,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ExplodeP void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LevelEventPacket* packet) { if (!level) return; if(packet->eventId == LevelEvent::ALL_PLAYERS_SLEEPING) { - minecraft.getPlayer()->setAllPlayersSleeping(); + minecraft.player()->setAllPlayersSleeping(); } else { minecraft.level->levelEvent(NULL, packet->eventId, packet->x, packet->y, packet->z, packet->data); @@ -622,7 +622,7 @@ void ClientSideNetworkHandler::arrangeRequestChunkOrder() { int cz = CHUNK_CACHE_WIDTH / 2; // If player exists, let's sort around him - Player* p = minecraft.getPlayer(); + Player* p = minecraft.player(); if (p) { cx = Mth::floor(p->x / (float)CHUNK_WIDTH); cz = Mth::floor(p->z / (float)CHUNK_DEPTH); @@ -750,7 +750,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, AnimateP return; // Own player - Then don't play... : - if (minecraft.getPlayer()->entityId == packet->entityId) { + if (minecraft.player()->entityId == packet->entityId) { if (packet->action == AnimatePacket::Swing) return; } @@ -779,26 +779,26 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, UseItemP void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, SetHealthPacket* packet) { - if (!level || !minecraft.getPlayer()) + if (!level || !minecraft.player()) return; - minecraft.getPlayer()->hurtTo(packet->health); + minecraft.player()->hurtTo(packet->health); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, SetSpawnPositionPacket* packet) { - if (!level || !minecraft.getPlayer()) return; + if (!level || !minecraft.player()) return; if (!level->inRange(packet->x, packet->y, packet->z)) return; - minecraft.getPlayer()->setRespawnPosition(Pos(packet->x, packet->y, packet->z)); + minecraft.player()->setRespawnPosition(Pos(packet->x, packet->y, packet->z)); level->getLevelData()->setSpawn(packet->x, packet->y, packet->z); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, HurtArmorPacket* packet) { - if (!level || !minecraft.getPlayer()) { + if (!level || !minecraft.player()) { return; } - minecraft.getPlayer()->hurtArmor(packet->dmg); + minecraft.player()->hurtArmor(packet->dmg); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RespawnPacket* packet) @@ -817,37 +817,37 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, Containe if (packet->type == ContainerType::FURNACE) { FurnaceTileEntity* te = new FurnaceTileEntity(); te->clientSideOnly = true; - minecraft.getPlayer()->openFurnace(te); - if (minecraft.getPlayer()->containerMenu) - minecraft.getPlayer()->containerMenu->containerId = packet->containerId; + minecraft.player()->openFurnace(te); + if (minecraft.player()->containerMenu) + minecraft.player()->containerMenu->containerId = packet->containerId; } if (packet->type == ContainerType::CONTAINER) { ChestTileEntity* te = new ChestTileEntity(); te->clientSideOnly = true; - minecraft.getPlayer()->openContainer(te); - if (minecraft.getPlayer()->containerMenu) - minecraft.getPlayer()->containerMenu->containerId = packet->containerId; + minecraft.player()->openContainer(te); + if (minecraft.player()->containerMenu) + minecraft.player()->containerMenu->containerId = packet->containerId; } } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ContainerClosePacket* packet) { - if (minecraft.getPlayer() && minecraft.getPlayer()->containerMenu) - minecraft.getPlayer()->closeContainer(); + if (minecraft.player() && minecraft.player()->containerMenu) + minecraft.player()->closeContainer(); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ContainerSetContentPacket* packet) { - if (!minecraft.getPlayer()) + if (!minecraft.player()) return; if (packet->containerId == 0) { for (unsigned int i = 0; i < packet->items.size(); ++i) { - minecraft.getPlayer()->inventory->setItem(Inventory::MAX_SELECTION_SIZE + i, &packet->items[i]); + minecraft.player()->inventory->setItem(Inventory::MAX_SELECTION_SIZE + i, &packet->items[i]); } - } else if (minecraft.getPlayer()->containerMenu && minecraft.getPlayer()->containerMenu->containerId == packet->containerId) { + } else if (minecraft.player()->containerMenu && minecraft.player()->containerMenu->containerId == packet->containerId) { for (unsigned int i = 0; i < packet->items.size(); ++i) { - minecraft.getPlayer()->containerMenu->setSlot(i, &packet->items[i]); + minecraft.player()->containerMenu->setSlot(i, &packet->items[i]); } } } @@ -856,28 +856,28 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, Containe { //LOGI("ContainerSetSlot\n"); - if (!minecraft.getPlayer() - || !minecraft.getPlayer()->containerMenu - || minecraft.getPlayer()->containerMenu->containerId != packet->containerId) + if (!minecraft.player() + || !minecraft.player()->containerMenu + || minecraft.player()->containerMenu->containerId != packet->containerId) return; - //minecraft.getPlayer()->containerMenu->setSlot(packet->slot, packet->item.isNull()? NULL : &packet->item); - minecraft.getPlayer()->containerMenu->setSlot(packet->slot, &packet->item); + //minecraft.player()->containerMenu->setSlot(packet->slot, packet->item.isNull()? NULL : &packet->item); + minecraft.player()->containerMenu->setSlot(packet->slot, &packet->item); } void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ContainerSetDataPacket* packet) { //LOGI("ContainerSetData\n"); - if (minecraft.getPlayer() && minecraft.getPlayer()->containerMenu && minecraft.getPlayer()->containerMenu->containerId == packet->containerId) { + if (minecraft.player() && minecraft.player()->containerMenu && minecraft.player()->containerMenu->containerId == packet->containerId) { //LOGI("client: SetData2 %d, %d\n", packet->id, packet->value); - minecraft.getPlayer()->containerMenu->setData(packet->id, packet->value); + minecraft.player()->containerMenu->setData(packet->id, packet->value); } } void ClientSideNetworkHandler::handle( const RakNet::RakNetGUID& source, ChatPacket* packet ) { #ifndef STANDALONE_SERVER - minecraft.gui.displayClientMessage(packet->message); + minecraft.gui().displayClientMessage(packet->message); #endif } diff --git a/src/network/NATPunchHandler.cpp b/src/network/NATPunchHandler.cpp deleted file mode 100755 index 33b4942..0000000 --- a/src/network/NATPunchHandler.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "NATPunchHandler.h" -#include "raknet/TCPInterface.h" -#include "raknet/HTTPConnection.h" -#include "PHPDirectoryServer2.hpp" - -using namespace RakNet; -NATPuchHandler::NATPuchHandler() { - tcpInterface = new TCPInterface; -} -NATPuchHandler::~NATPuchHandler() { - delete tcpInterface; -} - -void NATPuchHandler::initialize() { - tcpInterface->Start(0, 64); -} - -void NATPuchHandler::registerToGameList(const RakNet::RakString& serverName, int port) { - HTTPConnection httpConnection; - httpConnection.Init(tcpInterface, "johanbernhardsson.se"); - PHPDirectoryServer2 directoryServer; - directoryServer.Init(&httpConnection, "/DirectoryServer.php"); - directoryServer.UploadTable("", serverName, port, true); -} - -void NATPuchHandler::removeFromGameList() { - -} - -void NATPuchHandler::close() { - -} - diff --git a/src/network/NATPunchHandler.hpp b/src/network/NATPunchHandler.hpp deleted file mode 100755 index 70cfad3..0000000 --- a/src/network/NATPunchHandler.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "raknet/TCPInterface.h" -#include "raknet/RakString.h" -class NATPuchHandler { -public: - enum NATPuchHandlerStatus { - NATPuchInitilized = 0, - NATPuchFetchingServerList = 1, - NATPuchConnecting = 2, - NATPuchConnected = 3, - NATPuchDissconnected = 4 - }; - NATPuchHandler(); - ~NATPuchHandler(); - void initialize(); - void registerToGameList(const RakNet::RakString& serverName, int port); - void removeFromGameList(); - void close(); -private: - RakNet::TCPInterface *tcpInterface; -}; - diff --git a/src/network/PHPDirectoryServer2.cpp b/src/network/PHPDirectoryServer2.cpp deleted file mode 100755 index f10bef4..0000000 --- a/src/network/PHPDirectoryServer2.cpp +++ /dev/null @@ -1,293 +0,0 @@ -/// \file -/// \brief Contains WebGameList, a client for communicating with a HTTP list of game servers -/// -/// This file is part of RakNet Copyright 2008 Kevin Jenkins. -/// -/// Usage of RakNet is subject to the appropriate license agreement. -/// Creative Commons Licensees are subject to the -/// license found at -/// http://creativecommons.org/licenses/by-nc/2.5/ -/// Single application licensees are subject to the license found at -/// http://www.jenkinssoftware.com/SingleApplicationLicense.html -/// Custom license users are subject to the terms therein. -/// GPL license users are subject to the GNU General Public -/// License as published by the Free -/// Software Foundation - -#include "PHPDirectoryServer2.hpp" -#include "raknet/HTTPConnection.h" -#include "raknet/RakSleep.h" -#include "raknet/RakString.h" -#include "raknet/RakNetTypes.h" -#include "raknet/GetTime.h" -#include "raknet/RakAssert.h" -#include -#include -#include -#include "raknet/Itoa.h" - -// Column with this header contains the name of the game, passed to UploadTable() -static const char *GAME_NAME_COMMAND="__GAME_NAME"; -// Column with this header contains the port of the game, passed to UploadTable() -static const char *GAME_PORT_COMMAND="__GAME_PORT"; -// Column with this header contains the IP address of the game, passed to UploadTable() -static const char *SYSTEM_ADDRESS_COMMAND="_System_Address"; -// Returned from the PHP server indicating when this row was last updated. -static const char *LAST_UPDATE_COMMAND="__SEC_AFTER_EPOCH_SINCE_LAST_UPDATE"; - -using namespace RakNet; -using namespace DataStructures; - -PHPDirectoryServer2::PHPDirectoryServer2() - : nextRepost(0) -{ - Map::IMPLEMENT_DEFAULT_COMPARISON(); -} -PHPDirectoryServer2::~PHPDirectoryServer2() -{ -} -void PHPDirectoryServer2::Init(HTTPConnection *_http, const char *_path) -{ - http=_http; - pathToPHP=_path; -} - -void PHPDirectoryServer2::SetField( RakNet::RakString columnName, RakNet::RakString value ) -{ - if (columnName.IsEmpty()) - return; - - if (columnName==GAME_NAME_COMMAND || - columnName==GAME_PORT_COMMAND || - columnName==LAST_UPDATE_COMMAND) - { - RakAssert("PHPDirectoryServer2::SetField attempted to set reserved column name" && 0); - return; - } - - fields.Set(columnName, value); -} -unsigned int PHPDirectoryServer2::GetFieldCount(void) const -{ - return fields.Size(); -} -void PHPDirectoryServer2::GetField(unsigned int index, RakNet::RakString &columnName, RakNet::RakString &value) -{ - RakAssert(index < fields.Size()); - columnName=fields.GetKeyAtIndex(index); - value=fields[index]; -} -void PHPDirectoryServer2::SetFields(DataStructures::Table *table) -{ - ClearFields(); - - unsigned columnIndex, rowIndex; - DataStructures::Table::Row *row; - - for (rowIndex=0; rowIndex < table->GetRowCount(); rowIndex++) - { - row = table->GetRowByIndex(rowIndex, 0); - for (columnIndex=0; columnIndex < table->GetColumnCount(); columnIndex++) - { - SetField( table->ColumnName(columnIndex), row->cells[columnIndex]->ToString(table->GetColumnType(columnIndex)) ); - } - } -} - -void PHPDirectoryServer2::ClearFields(void) -{ - fields.Clear(); - nextRepost=0; -} - -void PHPDirectoryServer2::UploadTable(RakNet::RakString uploadPassword, RakNet::RakString gameName, unsigned short gamePort, bool autoRepost) -{ - gameNameParam=gameName; - gamePortParam=gamePort; - currentOperation=""; - currentOperation="?query=upload&uploadPassword="; - currentOperation+=uploadPassword; - SendOperation(); - - if (autoRepost) - nextRepost=RakNet::GetTimeMS()+50000; - else - nextRepost=0; -} -void PHPDirectoryServer2::DownloadTable(RakNet::RakString downloadPassword) -{ - currentOperation="?query=download&downloadPassword="; - currentOperation+=downloadPassword; - SendOperation(); -} -void PHPDirectoryServer2::UploadAndDownloadTable(RakNet::RakString uploadPassword, RakNet::RakString downloadPassword, RakNet::RakString gameName, unsigned short gamePort, bool autoRepost) -{ - gameNameParam=gameName; - gamePortParam=gamePort; - currentOperation="?query=upDown&downloadPassword="; - currentOperation+=downloadPassword; - currentOperation+="&uploadPassword="; - currentOperation+=uploadPassword; - - SendOperation(); - - if (autoRepost) - nextRepost=RakNet::GetTimeMS()+50000; - else - nextRepost=0; -} - -HTTPReadResult PHPDirectoryServer2::ProcessHTTPRead(RakNet::RakString httpRead) -{ - const char *c = (const char*) httpRead.C_String(); // current position - HTTPReadResult resultCode=HTTP_RESULT_EMPTY; - - lastDownloadedTable.Clear(); - - - if (*c=='\n') - c++; - char buff[256]; - int buffIndex; - bool isCommand=true; - DataStructures::List columns; - DataStructures::List values; - RakNet::RakString curString; - bool isComment=false; - buffIndex=0; - while(c && *c) - { - // 3 is comment - if (*c=='\003') - { - isComment=!isComment; - c++; - continue; - } - if (isComment) - { - c++; - continue; - } - - // 1 or 2 separates fields - // 4 separates rows - if (*c=='\001') - { - if (isCommand) - { - buff[buffIndex]=0; - columns.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_); - isCommand=false; - if (buff[0]!=0) - resultCode=HTTP_RESULT_GOT_TABLE; - } - else - { - buff[buffIndex]=0; - values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_); - isCommand=true; - } - buffIndex=0; - } - else if (*c=='\002') - { - buff[buffIndex]=0; - buffIndex=0; - values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_); - isCommand=true; - PushColumnsAndValues(columns, values); - columns.Clear(true, _FILE_AND_LINE_); - values.Clear(true, _FILE_AND_LINE_); - - } - else - { - if (buffIndex<256-1) - buff[buffIndex++]=*c; - } - c++; - } - if (buff[0] && columns.Size()==values.Size()+1) - { - buff[buffIndex]=0; - values.Push(RakString::NonVariadic(buff), _FILE_AND_LINE_); - } - - PushColumnsAndValues(columns, values); - - return resultCode; -} -void PHPDirectoryServer2::PushColumnsAndValues(DataStructures::List &columns, DataStructures::List &values) -{ - DataStructures::Table::Row *row=0; - - unsigned int i; - for (i=0; i < columns.Size() && i < values.Size(); i++) - { - if (columns[i].IsEmpty()==false) - { - unsigned col = lastDownloadedTable.ColumnIndex(columns[i]); - if(col == (unsigned)-1) - { - col = lastDownloadedTable.AddColumn(columns[i], DataStructures::Table::STRING); - } - - if (row==0) - { - row = lastDownloadedTable.AddRow(lastDownloadedTable.GetAvailableRowId()); - } - row->UpdateCell(col,values[i].C_String()); - } - } -} -const DataStructures::Table *PHPDirectoryServer2::GetLastDownloadedTable(void) const -{ - return &lastDownloadedTable; -} -void PHPDirectoryServer2::SendOperation(void) -{ - RakString outgoingMessageBody; - char buff[64]; - - outgoingMessageBody += GAME_PORT_COMMAND; - outgoingMessageBody += '\001'; - outgoingMessageBody += Itoa(gamePortParam,buff,10); - outgoingMessageBody += '\001'; - outgoingMessageBody += GAME_NAME_COMMAND; - outgoingMessageBody += '\001'; - outgoingMessageBody += gameNameParam; - - for (unsigned i = 0; i < fields.Size(); i++) - { - RakString value = fields[i]; - value.URLEncode(); - outgoingMessageBody += RakString("\001%s\001%s", - fields.GetKeyAtIndex(i).C_String(), - value.C_String()); - } - - RakString postURL; - postURL+=pathToPHP; - postURL+=currentOperation; - http->Post(postURL.C_String(), outgoingMessageBody, "application/x-www-form-urlencoded"); - -} -void PHPDirectoryServer2::Update(void) -{ - if (http->IsBusy()) - return; - - - if (nextRepost==0 || fields.Size()==0) - return; - - RakNet::TimeMS time = GetTimeMS(); - - // Entry deletes itself after 60 seconds, so keep reposting if set to do so - if (time > nextRepost) - { - nextRepost=RakNet::GetTimeMS()+50000; - SendOperation(); - } -} diff --git a/src/network/PHPDirectoryServer2.hpp b/src/network/PHPDirectoryServer2.hpp deleted file mode 100755 index c89858f..0000000 --- a/src/network/PHPDirectoryServer2.hpp +++ /dev/null @@ -1,137 +0,0 @@ -/// \file -/// \brief Contains PHPDirectoryServer2, a client for communicating with a HTTP list of game servers -/// -/// This file is part of RakNet Copyright 2008 Kevin Jenkins. -/// -/// Usage of RakNet is subject to the appropriate license agreement. -/// Creative Commons Licensees are subject to the -/// license found at -/// http://creativecommons.org/licenses/by-nc/2.5/ -/// Single application licensees are subject to the license found at -/// http://www.jenkinssoftware.com/SingleApplicationLicense.html -/// Custom license users are subject to the terms therein. -/// GPL license users are subject to the GNU General Public -/// License as published by the Free -/// Software Foundation; either version 2 of the License, or (at your -/// option) any later version. - -#ifndef __PHP_DIRECTORY_SERVER_2 -#define __PHP_DIRECTORY_SERVER_2 - -#include "raknet/RakString.h" -#include "raknet/HTTPConnection.h" -#include "raknet/RakNetTypes.h" -#include "raknet/DS_Queue.h" -#include "raknet/DS_Table.h" -#include "raknet/DS_Map.h" - -namespace RakNet { - -struct SystemAddress; - -enum HTTPReadResult -{ - HTTP_RESULT_GOT_TABLE, - HTTP_RESULT_EMPTY -}; - -/// \brief Use PHPDirectoryServer2 as a C++ client to DirectoryServer.php -/// -/// PHPDirectoryServer2 works with the HTTPConnection class (which works with the TCPInterface class) in order to communiate with DirectoryServer.php found under Samples/PHPDirectoryServer2 -class PHPDirectoryServer2 -{ -public: - PHPDirectoryServer2(); - virtual ~PHPDirectoryServer2(); - - /// Associate PHPDirectoryServer2 with the HTTPConnection class it will communicate through - /// \param[in] _http The instance of HTTP connection we will communicate through - /// \param[in] _path The path to the PHP file on the remote server. For example, if the path is mysite.com/raknet/DirectoryServer.php then you would enter raknet/DirectoryServer.php - void Init(HTTPConnection *_http, const char *_path); - - /// Set a parameter (these are passed to the server) - /// To delete a column, just pass an empty string for value - /// Store the game name and port with UploadTable, rather than SetField, as these columns are required and use reserved column names - /// \param[in] columnName The name of the column to store - /// \param[in] value What value to hold for the uploaded row (only one row can be uploaded at a time) - void SetField(RakNet::RakString columnName, RakNet::RakString value); - - /// Returns the number of fields set with SetField() - unsigned int GetFieldCount(void) const; - - /// Returns a field set with SetField() - /// \param[in] index The 0 based index into the field list - /// \param[out] columnName The \a columnName parameter passed to SetField() - /// \param[out] value The \a value parameter passed to SetField() - void GetField(unsigned int index, RakNet::RakString &columnName, RakNet::RakString &value); - - /// Set all parameters at once from a table - /// \param[in] table A table containing the values you want to send. Note that all values are stored as strings in PHP - void SetFields(DataStructures::Table *table); - - /// Clear all fields - void ClearFields(void); - - /// Upload the values set with SetFields() or SetField() - /// On success: - /// 1. HTTPConnection::HasRead() will return true. - /// 2. Pass the value returned by HTTPConnection::Read() to PHPDirectoryServer2::ProcessHTTPRead(). - /// 3. The return value of PHPDirectoryServer2::ProcessHTTPRead() will be HTTP_RESULT_EMPTY - /// \param[in] uploadPassword The upload password set in the PHP page itself when you first uploaded and viewed it in the webpage. - /// \param[in] gameName Every entry must have a game name. Pass it here. - /// \param[in] gamePort Every entry must have a game port. Pass it here. The IP address will be stored automatically, or you can manually set it by passing a field named _System_Address - /// \param[in] autoRepost Tables must be uploaded every 60 seconds or they get dropped. Set autoRepost to true to automatically reupload the most recent table. - void UploadTable(RakNet::RakString uploadPassword, RakNet::RakString gameName, unsigned short gamePort, bool autoRepost); - - /// Send a download request to the PHP server. - /// On success: - /// 1. HTTPConnection::HasRead() will return true. - /// 2. Pass the value returned by HTTPConnection::Read() to PHPDirectoryServer2::ProcessHTTPRead(). - /// 3. The return value of PHPDirectoryServer2::ProcessHTTPRead() will be HTTP_RESULT_GOT_TABLE or HTTP_RESULT_EMPTY - /// 4. On HTTP_RESULT_GOT_TABLE, use GetLastDownloadedTable() to read the results. - /// \param[in] downloadPassword The download password set in the PHP page itself when you first uploaded and viewed it in the webpage. - void DownloadTable(RakNet::RakString downloadPassword); - - /// Same as calling DownloadTable immediately followed by UploadTable, except only the download result is returned - /// \param[in] uploadPassword The upload password set in the PHP page itself when you first uploaded and viewed it in the webpage. - /// \param[in] downloadPassword The download password set in the PHP page itself when you first uploaded and viewed it in the webpage. - /// \param[in] gameName Every entry must have a game name. Pass it here. - /// \param[in] gamePort Every entry must have a game port. Pass it here. The IP address will be stored automatically, or you can manually set it by passing a field named _System_Address - /// \param[in] autoRepost Tables must be uploaded every 60 seconds or they get dropped. Set autoRepost to true to automatically reupload the most recent table. - void UploadAndDownloadTable(RakNet::RakString uploadPassword, RakNet::RakString downloadPassword, RakNet::RakString gameName, unsigned short gamePort, bool autoRepost); - - /// When HTTPConnection::ProcessDataPacket() returns true, and not an error, pass HTTPConnection::Read() to this function - /// The message will be parsed into DataStructures::Table, and a copy stored internally which can be retrieved by GetLastDownloadedTable(); - /// \param[in] packetData Returned from HTTPInterface::Read() - /// \return One of the values for HTTPReadResult - HTTPReadResult ProcessHTTPRead(RakNet::RakString httpRead); - - /// Returns the last value returned from ProcessHTTPString - /// Default columns are "__GAME_NAME", "__GAME_PORT", "_System_Address" - /// \return The table created by parsing httpString - const DataStructures::Table *GetLastDownloadedTable(void) const; - - /// Call this periodically - it will handle connection states and refreshing updates to the server - void Update(void); - -private: - HTTPConnection *http; - RakNet::RakString pathToPHP; - - RakNet::RakString gameNameParam; - unsigned short gamePortParam; - - void SendOperation(void); - void PushColumnsAndValues(DataStructures::List &columns, DataStructures::List &values); - - DataStructures::Table lastDownloadedTable; - DataStructures::Map fields; - RakNet::RakString currentOperation; - RakNet::TimeMS nextRepost; - -}; - -} // namespace RakNet - -#endif - diff --git a/src/network/ServerSideNetworkHandler.cpp b/src/network/ServerSideNetworkHandler.cpp index 4a189cb..7b64717 100755 --- a/src/network/ServerSideNetworkHandler.cpp +++ b/src/network/ServerSideNetworkHandler.cpp @@ -163,7 +163,7 @@ void ServerSideNetworkHandler::redistributePacket(Packet* packet, const RakNet:: void ServerSideNetworkHandler::displayGameMessage(const std::string& message) { #ifndef STANDALONE_SERVER - minecraft->gui.addMessage(message); + minecraft.gui().addMessage(message); #else LOGI("%s\n", message.c_str()); #endif @@ -238,7 +238,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac // Player* newPlayer = new ServerPlayer(minecraft, level); - minecraft->gameMode->initAbilities(newPlayer->abilities); + minecraft.gameMode->initAbilities(newPlayer->abilities); newPlayer->owner = source; newPlayer->name = packet->clientName.C_String(); _pendingPlayers.push_back(newPlayer); @@ -256,7 +256,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac RakNet::BitStream bitStream; // @todo: Read from LevelData? - int gameType = minecraft->isCreativeMode() + int gameType = minecraft.isCreativeMode() ? GameType::Creative : GameType::Survival; @@ -321,7 +321,7 @@ void ServerSideNetworkHandler::onReady_ClientGeneration(const RakNet::RakNetGUID level->addEntity(newPlayer); #ifndef STANDALONE_SERVER - minecraft->gui.addMessage(newPlayer->name + " joined the game"); + minecraft.gui().addMessage(newPlayer->name + " joined the game"); #else LOGW("%s joined the game\n", newPlayer->name.c_str()); #endif @@ -405,7 +405,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveBl if (oldTile != NULL && changed) { level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, oldTile->soundType->getBreakSound(), (oldTile->soundType->getVolume() + 1) / 2, oldTile->soundType->getPitch() * 0.8f); - if (minecraft->gameMode->isSurvivalType() && player->canDestroy(oldTile)) + if (minecraft.gameMode->isSurvivalType() && player->canDestroy(oldTile)) //oldTile->spawnResources(level, x, y, z, data, 1); //@todo oldTile->playerDestroy(level, player, x, y, z, data); @@ -454,7 +454,7 @@ void ServerSideNetworkHandler::levelGenerated( Level* level ) level->addListener(this); #ifndef STANDALONE_SERVER - allowIncomingConnections(minecraft->options.getBooleanValue(OPTIONS_SERVER_VISIBLE)); + allowIncomingConnections(minecraft.options.getBooleanValue(OPTIONS_SERVER_VISIBLE)); #else allowIncomingConnections(true); #endif @@ -508,11 +508,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, Interact Player* player = (Player*) src; if (InteractPacket::Attack == packet->action) { player->swing(); - minecraft->gameMode->attack(player, entity); + minecraft.gameMode->attack(player, entity); } if (InteractPacket::Interact == packet->action) { player->swing(); - minecraft->gameMode->interact(player, entity); + minecraft.gameMode->interact(player, entity); } redistributePacket(packet, source); @@ -568,10 +568,10 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, UseItemP if(packet->face == 255) { // Special case: x,y,z means direction-of-action player->aimDirection.set(packet->x / 32768.0f, packet->y / 32768.0f, packet->z / 32768.0f); - minecraft->gameMode->useItem(player, level, item); + minecraft.gameMode->useItem(player, level, item); } else { - minecraft->gameMode->useItemOn(player, level, item, packet->x, packet->y, packet->z, packet->face, + minecraft.gameMode->useItemOn(player, level, item, packet->x, packet->y, packet->z, packet->face, Vec3(packet->clickX + packet->x, packet->clickY + packet->y, packet->clickZ + packet->z)); } @@ -597,7 +597,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, PlayerAc if (entity && entity->isPlayer()) { Player* player = (Player*) entity; if(packet->action == PlayerActionPacket::RELEASE_USE_ITEM) { - minecraft->gameMode->releaseUsingItem(player); + minecraft.gameMode->releaseUsingItem(player); return; } else if(packet->action == PlayerActionPacket::STOP_SLEEPING) { @@ -646,7 +646,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, Containe Player* p = findPlayer(level, &source); if (!p) return; - // // if (p != minecraft->player) + // // if (p != minecraft.player()) // static_cast(p)->doCloseContainer(); if (auto sp = dynamic_cast(p)) @@ -716,7 +716,7 @@ void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SignUpd void ServerSideNetworkHandler::allowIncomingConnections( bool doAllow ) { if (doAllow) { - raknetInstance->announceServer(minecraft->getServerName()); + raknetInstance->announceServer(minecraft.getServerName()); } else { raknetInstance->announceServer(""); } diff --git a/src/network/command/CommandServer.cpp b/src/network/command/CommandServer.cpp index b741e69..ecd0c37 100755 --- a/src/network/command/CommandServer.cpp +++ b/src/network/command/CommandServer.cpp @@ -103,9 +103,9 @@ CommandServer::CommandServer( Minecraft* mc ) restoreBuffer(0), inited(false) { - camera = new CameraEntity(mc->level); + camera = new CameraEntity(mc.level); - Pos p = mc->level->getSharedSpawnPos(); + Pos p = mc.level->getSharedSpawnPos(); apiPosTranslate = OffsetPosTranslator((float)-p.x, (float)-p.y, (float)-p.z); } @@ -196,9 +196,9 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) apiPosTranslate.from(x, y, z); if (hasData) - mc->level->setTileAndData(x, y, z, id, data & 15); + mc.level->setTileAndData(x, y, z, id, data & 15); else - mc->level->setTile(x, y, z, id); + mc.level->setTile(x, y, z, id); return NullString; } @@ -209,7 +209,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) return Fail; } apiPosTranslate.from(x, y, z); - return ToStringOk(mc->level->getTile(x, y, z)); + return ToStringOk(mc.level->getTile(x, y, z)); } if (cmd == "world.setBlocks") { @@ -243,9 +243,9 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) for (int z = z0; z <= z1; ++z) for (int x = x0; x <= x1; ++x) { if (hasData) - mc->level->setTileAndData(x, y, z, id, data & 15); + mc.level->setTileAndData(x, y, z, id, data & 15); else - mc->level->setTile(x, y, z, id); + mc.level->setTile(x, y, z, id); } return NullString; } @@ -257,7 +257,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) } x -= (int)apiPosTranslate.xo; z -= (int)apiPosTranslate.zo; - const int y = mc->level->getHeightmap(x, z) + (int)apiPosTranslate.yo; + const int y = mc.level->getHeightmap(x, z) + (int)apiPosTranslate.yo; return ToStringOk(y); } @@ -266,7 +266,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) // Player related get, set and query // if (cmd == "player.setTile") { - if (!mc->player) + if (!mc.player) return Fail; int x, y, z; @@ -275,16 +275,16 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) } apiPosTranslate.from(x, y, z); - Entity* e = (Entity*) mc->player; + Entity* e = (Entity*) mc.player; e->moveTo((float)x + 0.5f, (float)y, (float)z + 0.5f, e->yRot, e->xRot); return NullString; } if (cmd == "player.getTile") { - if (!mc->player) + if (!mc.player) return Fail; - Entity* e = (Entity*) mc->player; + Entity* e = (Entity*) mc.player; int x = (int)e->x, y = (int)(e->y - e->heightOffset), z = (int)e->z; apiPosTranslate.to(x, y, z); @@ -292,7 +292,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) } if (cmd == "player.setPos") { - if (!mc->player) + if (!mc.player) return Fail; float x, y, z; @@ -301,16 +301,16 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) } apiPosTranslate.from(x, y, z); - Entity* e = (Entity*) mc->player; + Entity* e = (Entity*) mc.player; e->moveTo(x, y, z, e->yRot, e->xRot); return NullString; } if (cmd == "player.getPos") { - if (!mc->player) + if (!mc.player) return Fail; - Entity* e = (Entity*) mc->player; + Entity* e = (Entity*) mc.player; float x = e->x, y = e->y - e->heightOffset, z = e->z; apiPosTranslate.to(x, y, z); @@ -326,7 +326,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (4 != sscanf(rest.c_str(), "%d,%d,%d,%d", &id, &x, &y, &z)) { return Fail; } - Entity* e = mc->level->getEntity(id); + Entity* e = mc.level->getEntity(id); if (!e) return Fail; apiPosTranslate.from(x, y, z); @@ -339,7 +339,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (1 != sscanf(rest.c_str(), "%d", &id)) return Fail; - Entity* e = mc->level->getEntity(id); + Entity* e = mc.level->getEntity(id); if (!e) return Fail; int x = (int)e->x, y = (int)(e->y - e->heightOffset), z = (int)e->z; @@ -353,7 +353,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (4 != sscanf(rest.c_str(), "%d,%f,%f,%f", &id, &x, &y, &z)) { return Fail; } - Entity* e = mc->level->getEntity(id); + Entity* e = mc.level->getEntity(id); if (!e) return Fail; apiPosTranslate.from(x, y, z); @@ -366,7 +366,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (1 != sscanf(rest.c_str(), "%d", &id)) return Fail; - Entity* e = mc->level->getEntity(id); + Entity* e = mc.level->getEntity(id); if (!e) return Fail; float x = e->x, y = e->y - e->heightOffset, z = e->z; @@ -379,7 +379,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) // if (cmd == "chat.post") { #ifndef STANDALONE_SERVER - mc->gui.addMessage(rest); + mc.gui().addMessage(rest); #endif ChatPacket p(rest, false); dispatchPacket(p); @@ -392,7 +392,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) // if (cmd == "camera.mode.setFixed") { camera->follow(-1); - mc->cameraTargetPlayer = camera; + mc.cameraTargetPlayer = camera; return NullString; } if (cmd == "camera.mode.setNormal") { @@ -401,10 +401,10 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (1 != sscanf(rest.c_str(), "%d", &entityId)) return Fail; } if (entityId > 0) { - Entity* e = mc->level->getEntity(entityId); - if (e && e->isMob()) mc->cameraTargetPlayer = (Mob*)e; + Entity* e = mc.level->getEntity(entityId); + if (e && e->isMob()) mc.cameraTargetPlayer = (Mob*)e; } else { - mc->cameraTargetPlayer = (Mob*)mc->player; + mc.cameraTargetPlayer = (Mob*)mc.player; } return NullString; } @@ -414,10 +414,10 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (!rest.empty()) { if (1 != sscanf(rest.c_str(), "%d", &entityId)) return Fail; } - if (entityId < 0) entityId = mc->player->entityId; + if (entityId < 0) entityId = mc.player->entityId; camera->follow(entityId); - mc->cameraTargetPlayer = camera; + mc.cameraTargetPlayer = camera; return NullString; } @@ -428,7 +428,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) } apiPosTranslate.from(x, y, z); - Entity* e = (Entity*) mc->cameraTargetPlayer; + Entity* e = (Entity*) mc.cameraTargetPlayer; e->moveTo((float)x + 0.5f, (float)y, (float)z + 0.5f, e->yRot, e->xRot); return NullString; } @@ -439,10 +439,10 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) // if (cmd == "world.getPlayerIds") { std::stringstream s; - int size = mc->level->players.size(); + int size = mc.level->players.size(); for (int i = 0; i < size; ++i) { if (i != 0) s << "|"; - s << mc->level->players[i]->entityId; + s << mc.level->players[i]->entityId; } s << "\n"; return s.str(); @@ -454,8 +454,8 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) // Set and restore Checkpoint // if (cmd == "world.checkpoint.save") { - if (mc->player) { - Entity* e = (Entity*) mc->player; + if (mc.player) { + Entity* e = (Entity*) mc.player; static Stopwatch sw; sw.start(); @@ -478,7 +478,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s) if (success) { int xx = 16 * (restorePos.x - 2); int zz = 16 * (restorePos.z - 2); - mc->level->setTilesDirty(xx, restorePos.y, zz, + mc.level->setTilesDirty(xx, restorePos.y, zz, xx + 5 * 16, restorePos.y + RestoreHeight, zz + 5 * 16); } return success? NullString : Fail; @@ -523,7 +523,7 @@ bool CommandServer::handleCheckpoint(bool doRestore ) { int offset = 0; for (int z = cz - 2; z <= cz + 2; ++z) for (int x = cx - 2; x <= cx + 2; ++x) { - LevelChunk* c = mc->level->getChunk(x, z); + LevelChunk* c = mc.level->getChunk(x, z); if (!c) continue; if (doRestore) { @@ -546,7 +546,7 @@ void CommandServer::tick() { _updateClients(); ++t; - // if (mc->cameraTargetPlayer == camera) { + // if (mc.cameraTargetPlayer == camera) { // camera->tick(); // } } @@ -564,7 +564,7 @@ void CommandServer::_updateAccept() { clients.push_back(ConnectedClient(fd)); ConnectedClient& c = clients[clients.size()-1]; - c.lastPoll_blockHit = mc->level->getTime(); + c.lastPoll_blockHit = mc.level->getTime(); } void CommandServer::_updateClients() { @@ -593,20 +593,20 @@ bool CommandServer::_updateClient(ConnectedClient& client) { } void CommandServer::dispatchPacket( Packet& p ) { - // if (!mc->netCallback || !mc->player) return; - // const RakNet::RakNetGUID& guid = ((Player*)mc->player)->owner; - // mc->raknetInstance->send(p); - //p.handle(guid, mc->netCallback); + // if (!mc.netCallback || !mc.player) return; + // const RakNet::RakNetGUID& guid = ((Player*)mc.player)->owner; + // mc.raknetInstance->send(p); + //p.handle(guid, mc.netCallback); } std::string CommandServer::handleEventPollMessage( ConnectedClient& client, const std::string& cmd ) { - ICreator* c = mc->getCreator(); + ICreator* c = mc.getCreator(); if (!c) { return Fail; } if (cmd == "events.clear") { - long t = mc->level->getTime(); + long t = mc.level->getTime(); client.lastPoll_blockHit = t; return NullString; } @@ -617,7 +617,7 @@ std::string CommandServer::handleEventPollMessage( ConnectedClient& client, cons events.write(ss, apiPosTranslate, client.lastPoll_blockHit); - client.lastPoll_blockHit = mc->level->getTime(); + client.lastPoll_blockHit = mc.level->getTime(); ss << "\n"; return ss.str(); @@ -627,17 +627,17 @@ std::string CommandServer::handleEventPollMessage( ConnectedClient& client, cons } void updateAdventureSettingFlag(Minecraft* mc, AdventureSettingsPacket::Flags flag, bool status) { - AdventureSettingsPacket p(mc->level->adventureSettings); + AdventureSettingsPacket p(mc.level->adventureSettings); p.set(flag, status); - p.fillIn(mc->level->adventureSettings); - mc->raknetInstance->send(p); + p.fillIn(mc.level->adventureSettings); + mc.raknetInstance->send(p); } std::string CommandServer::handleSetSetting( const std::string& setting, int value ) { bool status = value != 0; - // if (setting == "autojump") mc->player->autoJumpEnabled = status; + // if (setting == "autojump") mc.player->autoJumpEnabled = status; AdventureSettingsPacket::Flags flag = (AdventureSettingsPacket::Flags)0; if (setting == "nametags_visible") flag = AdventureSettingsPacket::ShowNameTags; diff --git a/src/raknet/Rand.cpp b/src/raknet/Rand.cpp index c3d8413..b01d1c6 100755 --- a/src/raknet/Rand.cpp +++ b/src/raknet/Rand.cpp @@ -142,8 +142,8 @@ void seedMT( unsigned int seed, unsigned int *state, unsigned int *&next, int &l // so-- that's why the only change I made is to restrict to odd seeds. // - register unsigned int x = ( seed | 1U ) & 0xFFFFFFFFU, *s = state; - register int j; + unsigned int x = ( seed | 1U ) & 0xFFFFFFFFU, *s = state; + int j; for ( left = 0, *s++ = x, j = N; --j; *s++ = ( x *= 69069U ) & 0xFFFFFFFFU ) @@ -154,8 +154,8 @@ void seedMT( unsigned int seed, unsigned int *state, unsigned int *&next, int &l unsigned int reloadMT( unsigned int *state, unsigned int *&next, int &left ) { - register unsigned int * p0 = state, *p2 = state + 2, *pM = state + M, s0, s1; - register int j; + unsigned int * p0 = state, *p2 = state + 2, *pM = state + M, s0, s1; + int j; if ( left < -1 ) seedMT( 4357U ); diff --git a/src/server/ServerPlayer.cpp b/src/server/ServerPlayer.cpp index de00cc4..ae7d433 100755 --- a/src/server/ServerPlayer.cpp +++ b/src/server/ServerPlayer.cpp @@ -21,7 +21,7 @@ #include "network/packet/HurtArmorPacket.hpp" ServerPlayer::ServerPlayer( Minecraft* minecraft, Level* level ) -: super(level, minecraft->isCreativeMode()), +: super(level, minecraft.isCreativeMode()), _mc(minecraft), _prevHealth(-999), _containerCounter(0) @@ -37,7 +37,7 @@ ServerPlayer::~ServerPlayer() { void ServerPlayer::stopSleepInBed(bool forcefulWakeUp, bool updateLevelList, bool saveRespawnPoint) { if(isSleeping()) { AnimatePacket packet(AnimatePacket::WAKE_UP, this); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); } super::stopSleepInBed(forcefulWakeUp, updateLevelList, saveRespawnPoint); } @@ -61,13 +61,13 @@ void ServerPlayer::tick() { if (health != _prevHealth) { _prevHealth = health; SetHealthPacket packet(health); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); } } void ServerPlayer::take( Entity* e, int orgCount ) { TakeItemEntityPacket packet(e->entityId, entityId); - _mc->raknetInstance->send(packet); + _mc.raknetInstance->send(packet); super::take(e, orgCount); } @@ -75,14 +75,14 @@ void ServerPlayer::take( Entity* e, int orgCount ) { void ServerPlayer::hurtArmor(int dmg) { super::hurtArmor(dmg); HurtArmorPacket packet(dmg); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); } void ServerPlayer::openContainer( ChestTileEntity* container) { LOGI("Client is opening a container\n"); nextContainerCounter(); ContainerOpenPacket packet(_containerCounter, ContainerType::CONTAINER, container->getName(), container->getContainerSize()); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); setContainerMenu(new ContainerMenu(container, container->runningId)); } @@ -90,14 +90,14 @@ void ServerPlayer::openFurnace( FurnaceTileEntity* furnace ) { LOGI("Client is opening a furnace\n"); nextContainerCounter(); ContainerOpenPacket packet(_containerCounter, ContainerType::FURNACE, furnace->getName(), furnace->getContainerSize()); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); setContainerMenu(new FurnaceMenu(furnace)); } void ServerPlayer::closeContainer() { LOGI("Client is closing a container\n"); ContainerClosePacket packet(containerMenu->containerId); - _mc->raknetInstance->send(owner, packet); + _mc.raknetInstance->send(owner, packet); doCloseContainer(); } @@ -117,20 +117,20 @@ bool ServerPlayer::hasResource( int id ) { // void ServerPlayer::setContainerData( BaseContainerMenu* menu, int id, int value ) { ContainerSetDataPacket p(menu->containerId, id, value); - _mc->raknetInstance->send(owner, p); + _mc.raknetInstance->send(owner, p); //LOGI("Setting container data for id %d: %d\n", id, value); } void ServerPlayer::slotChanged( BaseContainerMenu* menu, int slot, const ItemInstance& item, bool isResultSlot ) { if (isResultSlot) return; ContainerSetSlotPacket p(menu->containerId, slot, item); - _mc->raknetInstance->send(owner, p); + _mc.raknetInstance->send(owner, p); //LOGI("Slot %d changed\n", slot); } void ServerPlayer::refreshContainer( BaseContainerMenu* menu, const std::vector& items ) { ContainerSetContentPacket p(menu->containerId, menu->getItems()); - _mc->raknetInstance->send(owner, p); + _mc.raknetInstance->send(owner, p); //LOGI("Refreshing container with %d items\n", items.size()); } @@ -155,11 +155,11 @@ void ServerPlayer::setContainerMenu( BaseContainerMenu* menu ) { void ServerPlayer::completeUsingItem() { EntityEventPacket p(entityId, EntityEvent::USE_ITEM_COMPLETE); - _mc->raknetInstance->send(owner, p); + _mc.raknetInstance->send(owner, p); super::completeUsingItem(); } void ServerPlayer::displayClientMessage( const std::string& messageId ) { ChatPacket package(messageId); - _mc->raknetInstance->send(owner, package); + _mc.raknetInstance->send(owner, package); } diff --git a/src/util/PerfRenderer.cpp b/src/util/PerfRenderer.cpp index d37a6bf..9c761ee 100755 --- a/src/util/PerfRenderer.cpp +++ b/src/util/PerfRenderer.cpp @@ -66,7 +66,7 @@ void PerfRenderer::renderFpsMeter( float tickTime ) glMatrixMode(GL_PROJECTION); glEnable2(GL_COLOR_MATERIAL); glLoadIdentity2(); - glOrthof(0, (GLfloat)_mc->width, (GLfloat)_mc->height, 0, 1000, 3000); + glOrthof(0, (GLfloat)_mc.getScreenWidth(), (GLfloat)_mc.getScreenHeight(), 0, 1000, 3000); glMatrixMode(GL_MODELVIEW); glLoadIdentity2(); glTranslatef2(0, 0, -2000); @@ -79,16 +79,16 @@ void PerfRenderer::renderFpsMeter( float tickTime ) int hh1 = (int) (usPer60Fps / 200); float count = (float)frameTimes.size(); t.color(0x20000000); - t.vertex(0, (float)(_mc->height - hh1), 0); - t.vertex(0, (float)_mc->height, 0); - t.vertex(count, (float)_mc->height, 0); - t.vertex(count, (float)(_mc->height - hh1), 0); + t.vertex(0, (float)(_mc.getScreenHeight() - hh1), 0); + t.vertex(0, (float)_mc.getScreenHeight(), 0); + t.vertex(count, (float)_mc.getScreenHeight(), 0); + t.vertex(count, (float)(_mc.getScreenHeight() - hh1), 0); t.color(0x20200000); - t.vertex(0, (float)(_mc->height - hh1 * 2), 0); - t.vertex(0, (float)(_mc->height - hh1), 0); - t.vertex(count, (float)(_mc->height - hh1), 0); - t.vertex(count, (float)(_mc->height - hh1 * 2), 0); + t.vertex(0, (float)(_mc.getScreenHeight() - hh1 * 2), 0); + t.vertex(0, (float)(_mc.getScreenHeight() - hh1), 0); + t.vertex(count, (float)(_mc.getScreenHeight() - hh1), 0); + t.vertex(count, (float)(_mc.getScreenHeight() - hh1 * 2), 0); t.draw(); float totalTime = 0; @@ -98,10 +98,10 @@ void PerfRenderer::renderFpsMeter( float tickTime ) int hh = (int) (totalTime / 200 / frameTimes.size()); t.begin(); t.color(0x20400000); - t.vertex(0, (float)(_mc->height - hh), 0); - t.vertex(0, (float)_mc->height, 0); - t.vertex(count, (float)_mc->height, 0); - t.vertex(count, (float)(_mc->height - hh), 0); + t.vertex(0, (float)(_mc.getScreenHeight() - hh), 0); + t.vertex(0, (float)_mc.getScreenHeight(), 0); + t.vertex(count, (float)_mc.getScreenHeight(), 0); + t.vertex(count, (float)(_mc.getScreenHeight() - hh), 0); t.draw(); t.begin(GL_LINES); @@ -120,23 +120,23 @@ void PerfRenderer::renderFpsMeter( float tickTime ) float time = 10 * 1000 * frameTimes[i] / 200; float time2 = 10 * 1000 * tickTimes[i] / 200; - t.vertex(i + 0.5f, _mc->height - time + 0.5f, 0); - t.vertex(i + 0.5f, _mc->height + 0.5f, 0); + t.vertex(i + 0.5f, _mc.getScreenHeight() - time + 0.5f, 0); + t.vertex(i + 0.5f, _mc.getScreenHeight() + 0.5f, 0); - // if (_mc->frameTimes[i]>nsPer60Fps) { + // if (_mc.frameTimes[i]>nsPer60Fps) { t.color(0xff000000 + cc * 65536 + cc * 256 + cc * 1); // } else { // t.color(0xff808080 + cc/2 * 256); // } - t.vertex(i + 0.5f, _mc->height - time + 0.5f, 0); - t.vertex(i + 0.5f, _mc->height - (time - time2) + 0.5f, 0); + t.vertex(i + 0.5f, _mc.getScreenHeight() - time + 0.5f, 0); + t.vertex(i + 0.5f, _mc.getScreenHeight() - (time - time2) + 0.5f, 0); } t.draw(); //t.end(); int r = 160; - int x = _mc->width - r - 10; - int y = _mc->height - r * 2; + int x = _mc.getScreenWidth() - r - 10; + int y = _mc.getScreenHeight() - r * 2; glEnable(GL_BLEND); t.begin(); t.color(0x000000, 200); @@ -193,9 +193,9 @@ void PerfRenderer::renderFpsMeter( float tickTime ) msg << node.name << " "; } int col = 0xffffff; - _font->drawShadow(msg.str(), (float)(x - r), (float)(y - r / 2 - 16), col); + _font.drawShadow(msg.str(), (float)(x - r), (float)(y - r / 2 - 16), col); std::string msg2 = toPercentString(node.globalPercentage); - _font->drawShadow(msg2, (float)(x + r - _font->width(msg2)), (float)(y - r / 2 - 16), col); + _font.drawShadow(msg2, (float)(x + r - _font.width(msg2)), (float)(y - r / 2 - 16), col); } for (unsigned int i = 0; i < list.size(); i++) { @@ -210,12 +210,12 @@ void PerfRenderer::renderFpsMeter( float tickTime ) msg << result.name; float xx = (float)(x - r); float yy = (float)(y + r/2 + i * 8 + 20); - _font->drawShadow(msg.str(), xx, yy, result.getColor()); + _font.drawShadow(msg.str(), xx, yy, result.getColor()); std::string msg2 = toPercentString(result.percentage); //LOGI("name: %s: perc: %f == %s @ %d, %d\n", msg.str().c_str(), result.percentage, msg2.c_str(), xx, yy); - _font->drawShadow(msg2, xx - 50 - _font->width(msg2), yy, result.getColor()); + _font.drawShadow(msg2, xx - 50 - _font.width(msg2), yy, result.getColor()); msg2 = toPercentString(result.globalPercentage); - _font->drawShadow(msg2, xx - _font->width(msg2), yy, result.getColor()); + _font.drawShadow(msg2, xx - _font.width(msg2), yy, result.getColor()); } } diff --git a/src/world/entity/ai/goal/GoalSelector.hpp b/src/world/entity/ai/goal/GoalSelector.hpp index b81c778..da98433 100755 --- a/src/world/entity/ai/goal/GoalSelector.hpp +++ b/src/world/entity/ai/goal/GoalSelector.hpp @@ -34,7 +34,7 @@ public: void tick() { std::vector toStart; - for (std::vector::iterator it = goals.begin(); it != goals.end(); ++it) { + for (auto it = goals.begin(); it != goals.end(); ++it) { InternalGoal& ig = *it; bool isUsing = ig.isUsing; //usingGoals.contains(ig); @@ -57,14 +57,14 @@ public: //bool debug = false; //if (debug && toStart.size() > 0) printf("Starting: "); - for (std::vector::iterator it = toStart.begin(); it != toStart.end(); ++it) { + for (auto it = toStart.begin(); it != toStart.end(); ++it) { InternalGoal& ig = *it; //if (debug) printf(" %s, ", ig.goal.toString() + ", "); ig.goal->start(); } //if (debug && usingGoals.size() > 0) printf("Running: "); - for (std::vector::iterator it = goals.begin(); it != goals.end(); ++it) { + for (auto it = goals.begin(); it != goals.end(); ++it) { InternalGoal& ig = *it; if (ig.isUsing) { //if (debug) printf(" %s\n", ig.goal.toString()); @@ -78,7 +78,7 @@ public: //} private: bool canUseInSystem(InternalGoal& goal) { - for (std::vector::iterator it = goals.begin(); it != goals.end(); ++it) { + for (auto it = goals.begin(); it != goals.end(); ++it) { InternalGoal& ig = *it; if (ig.goal == goal.goal && ig.prio == goal.prio) continue; diff --git a/src/world/level/Level.cpp b/src/world/level/Level.cpp index 4a95644..9a6c0cc 100755 --- a/src/world/level/Level.cpp +++ b/src/world/level/Level.cpp @@ -1136,10 +1136,6 @@ std::vector& Level::getCubes(const Entity* source, const AABB& box_) { //@ } } } - else - { - //int breakPoint = 0; - } } /* float r = 0.25;