diff --git a/src/main/java/org/runejs/client/Game.java b/src/main/java/org/runejs/client/Game.java index a88a8cb53..678ba1d9e 100644 --- a/src/main/java/org/runejs/client/Game.java +++ b/src/main/java/org/runejs/client/Game.java @@ -13,6 +13,7 @@ import org.runejs.client.io.Buffer; import org.runejs.client.language.English; import org.runejs.client.language.Native; +import org.runejs.client.media.Constants3D; import org.runejs.client.media.Rasterizer; import org.runejs.client.media.Rasterizer3D; import org.runejs.client.media.VertexNormal; @@ -79,6 +80,8 @@ public class Game { public static FriendList friendList; public static final SocialList ignoreList = new SocialList(100); + + public static final LoginScreen loginScreen = new LoginScreen(); public static int anInt784 = 0; public static GameInterface chatboxInterface; @@ -517,8 +520,8 @@ else if (GameInterface.aBoolean2177) } Rasterizer3D.setBounds(absoluteX + gameInterface.originalWidth / 2, gameInterface.originalHeight / 2 + absoluteY); - int camHeight = modelZoom * Rasterizer3D.sinetable[rotationX] >> 16; - int camDistance = modelZoom * Rasterizer3D.cosinetable[rotationX] >> 16; + int camHeight = modelZoom * Constants3D.sinetable[rotationX] >> 16; + int camDistance = modelZoom * Constants3D.cosinetable[rotationX] >> 16; if (model != null) { if (gameInterface.isNewInterfaceFormat) { model.method799(); @@ -856,21 +859,21 @@ public static void method353() { MovedStatics.draw2DActorAttachments(); MovedStatics.drawPositionHintIcon(); ((Class35) Rasterizer3D.interface3).animateTextures(MovedStatics.anInt199); - MovedStatics.draw3dScreen(); + ScreenController.gameRenderer.draw3dScreenOverlays(); DebugTools.drawWalkPath(); DebugTools.drawClipping(); + ScreenController.drawFrame(); + if(ScreenController.frameMode == ScreenMode.FIXED) { Console.console.drawConsole(512, 334); Console.console.drawConsoleArea(512, 334); } else { - ScreenController.RenderResizableUI(); Console.console.drawConsole(ScreenController.drawWidth, 334); Console.console.drawConsoleArea(ScreenController.drawWidth, 334); } - if(aBoolean519 && UpdateServer.getActiveCount(false, true) == 0) { aBoolean519 = false; } @@ -977,142 +980,118 @@ public static void drawGameScreen() { GameInterface.drawTabIcons = true; } - if(ScreenController.frameMode == ScreenMode.FIXED) { - - if(MovedStatics.menuOpen && MovedStatics.menuScreenArea == 1) { - GameInterface.redrawTabArea = true; - } - method353(); + if(MovedStatics.menuOpen && MovedStatics.menuScreenArea == 1) { + GameInterface.redrawTabArea = true; + } - if(GameInterface.atInventoryInterfaceType == -3) { - GameInterface.redrawTabArea = true; - } - if(GameInterface.activeInterfaceType == 2) { - GameInterface.redrawTabArea = true; - } - MovedStatics.drawTabArea(); + if(GameInterface.atInventoryInterfaceType == -3) { + GameInterface.redrawTabArea = true; + } + if(GameInterface.activeInterfaceType == 2) { + GameInterface.redrawTabArea = true; + } - if(GameInterface.atInventoryInterfaceType == 3) { - ChatBox.redrawChatbox = true; - } - if(GameInterface.activeInterfaceType == 3) { - ChatBox.redrawChatbox = true; - } - if(Native.clickToContinueString != null) { - ChatBox.redrawChatbox = true; - } - if(MovedStatics.menuOpen && MovedStatics.menuScreenArea == 2) { - ChatBox.redrawChatbox = true; - } - if(ChatBox.redrawChatbox) { - ChatBox.redrawChatbox = false; - ChatBox.renderChatbox(); - // Console.console.drawConsoleArea(); - } + if(GameInterface.atInventoryInterfaceType == 3) { + ChatBox.redrawChatbox = true; + } + if(GameInterface.activeInterfaceType == 3) { + ChatBox.redrawChatbox = true; + } + if(Native.clickToContinueString != null) { + ChatBox.redrawChatbox = true; + } + if(MovedStatics.menuOpen && MovedStatics.menuScreenArea == 2) { + ChatBox.redrawChatbox = true; + } + if(ScreenController.frameMode == ScreenMode.FIXED) { Minimap.renderMinimap(); + } - if(GameInterface.drawTabIcons) { - if(flashingTabId != -1 && flashingTabId == currentTabId) { - flashingTabId = -1; - OutgoingPackets.sendMessage(new ClickFlashingTabIconOutboundMessage(currentTabId)); - } - GameInterface.drawTabIcons = false; - MovedStatics.showIconsRedrawnText = true; - MovedStatics.method527(currentTabId, tabWidgetIds, GameInterface.tabAreaInterfaceId == -1, MovedStatics.pulseCycle % 20 >= 10 ? flashingTabId : -1); - } - if(MovedStatics.redrawChatbox) { - MovedStatics.showIconsRedrawnText = true; - MovedStatics.redrawChatbox = false; - method943(ChatBox.tradeMode, MovedStatics.fontNormal, ChatBox.privateChatMode, ChatBox.publicChatMode); - } - - SoundSystem.updateObjectSounds(Player.localPlayer.worldX, Player.worldLevel, MovedStatics.anInt199, Player.localPlayer.worldY); - MovedStatics.anInt199 = 0; + method353(); - } else { - method353(); + if(ChatBox.redrawChatbox) { + ChatBox.redrawChatbox = false; ChatBox.renderChatbox(); + } - MovedStatics.drawTabArea(); - - // this render is handled in `ResizableFrameRenderer` - //Minimap.renderMinimap(); + MovedStatics.drawTabArea(); - if(GameInterface.drawTabIcons) { - if(flashingTabId != -1 && flashingTabId == currentTabId) { - flashingTabId = -1; - OutgoingPackets.sendMessage(new ClickFlashingTabIconOutboundMessage(currentTabId)); - } - GameInterface.drawTabIcons = false; - MovedStatics.showIconsRedrawnText = true; - MovedStatics.method527(currentTabId, tabWidgetIds, GameInterface.tabAreaInterfaceId == -1, MovedStatics.pulseCycle % 20 >= 10 ? flashingTabId : -1); - } - if(MovedStatics.redrawChatbox) { - MovedStatics.showIconsRedrawnText = true; - MovedStatics.redrawChatbox = false; - method943(ChatBox.tradeMode, MovedStatics.fontNormal, ChatBox.privateChatMode, ChatBox.publicChatMode); + if(GameInterface.drawTabIcons) { + if(flashingTabId != -1 && flashingTabId == currentTabId) { + flashingTabId = -1; + OutgoingPackets.sendMessage(new ClickFlashingTabIconOutboundMessage(currentTabId)); } + GameInterface.drawTabIcons = false; + MovedStatics.showIconsRedrawnText = true; + MovedStatics.method527(currentTabId, tabWidgetIds, GameInterface.tabAreaInterfaceId == -1, MovedStatics.pulseCycle % 20 >= 10 ? flashingTabId : -1); + } - SoundSystem.updateObjectSounds(Player.localPlayer.worldX, Player.worldLevel, MovedStatics.anInt199, Player.localPlayer.worldY); - MovedStatics.anInt199 = 0; + if(MovedStatics.redrawChatbox) { + MovedStatics.showIconsRedrawnText = true; + MovedStatics.redrawChatbox = false; + method943(ChatBox.tradeMode, MovedStatics.fontNormal, ChatBox.privateChatMode, ChatBox.publicChatMode); } + SoundSystem.updateObjectSounds(Player.localPlayer.worldX, Player.worldLevel, MovedStatics.anInt199, Player.localPlayer.worldY); + MovedStatics.anInt199 = 0; + + ScreenController.rasterizer.resetBounds(); } public static void displayMessageForResponseCode(int responseCode) { if(responseCode == -3) { - Class60.setLoginScreenMessage(English.connectionTimedOut, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.connectionTimedOut, English.pleaseTryUsingDifferentWorld, ""); } else if(responseCode == -2) { - Class60.setLoginScreenMessage("", English.errorConnectingToServer, ""); + loginScreen.setLoginScreenMessage("", English.errorConnectingToServer, ""); } else if(responseCode == -1) { - Class60.setLoginScreenMessage(English.noResponseFromServer, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.noResponseFromServer, English.pleaseTryUsingDifferentWorld, ""); } else if(responseCode == 3) { - Class60.setLoginScreenMessage("", English.invalidUsernameOrPassword, ""); + loginScreen.setLoginScreenMessage("", English.invalidUsernameOrPassword, ""); } else if(responseCode == 4) { - Class60.setLoginScreenMessage(English.yourAccountHasBeenDisabled, English.pleaseCheckYourMessageCenterForDetails, ""); + loginScreen.setLoginScreenMessage(English.yourAccountHasBeenDisabled, English.pleaseCheckYourMessageCenterForDetails, ""); } else if(responseCode == 5) { - Class60.setLoginScreenMessage(English.yourAccountIsAlreadyLoggedIn, English.tryAgainIn60Secs, ""); + loginScreen.setLoginScreenMessage(English.yourAccountIsAlreadyLoggedIn, English.tryAgainIn60Secs, ""); } else if(responseCode == 6) { - Class60.setLoginScreenMessage(English.gameHasBeenUpdated, English.pleaseReloadThisPage, ""); + loginScreen.setLoginScreenMessage(English.gameHasBeenUpdated, English.pleaseReloadThisPage, ""); } else if(responseCode == 7) { - Class60.setLoginScreenMessage(English.theWorldIsFull, English.pleaseUseADifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.theWorldIsFull, English.pleaseUseADifferentWorld, ""); } else if(responseCode == 8) { - Class60.setLoginScreenMessage(English.unableToConnect, English.loginServerOffline, ""); + loginScreen.setLoginScreenMessage(English.unableToConnect, English.loginServerOffline, ""); } else if(responseCode == 9) { - Class60.setLoginScreenMessage(English.loginLimitExceeded, English.tooManyConnectionsFromYourAddress, ""); + loginScreen.setLoginScreenMessage(English.loginLimitExceeded, English.tooManyConnectionsFromYourAddress, ""); } else if(responseCode == 10) { - Class60.setLoginScreenMessage(English.unableToConnect, English.badSessionId, ""); + loginScreen.setLoginScreenMessage(English.unableToConnect, English.badSessionId, ""); } else if(responseCode == 11) { - Class60.setLoginScreenMessage(English.weSuspectSomeoneKnowsYourPassword, English.pressChangeYourPasswordOnFrontPage, ""); + loginScreen.setLoginScreenMessage(English.weSuspectSomeoneKnowsYourPassword, English.pressChangeYourPasswordOnFrontPage, ""); } else if(responseCode == 12) { - Class60.setLoginScreenMessage(English.youNeedMembersAccountToLoginToThisWorld, English.pleaseSubscribeOrUseDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.youNeedMembersAccountToLoginToThisWorld, English.pleaseSubscribeOrUseDifferentWorld, ""); } else if(responseCode == 13) { - Class60.setLoginScreenMessage(English.couldNotCompleteLogin, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.couldNotCompleteLogin, English.pleaseTryUsingDifferentWorld, ""); } else if(responseCode == 14) { - Class60.setLoginScreenMessage(English.theServerIsBeingUpdated, English.pleaseWait1MinuteAndTryAgain, ""); + loginScreen.setLoginScreenMessage(English.theServerIsBeingUpdated, English.pleaseWait1MinuteAndTryAgain, ""); } else if(responseCode == 16) { - Class60.setLoginScreenMessage(English.tooManyIncorrectLoginsFromYourAddress, English.pleaseWait5MinutesBeforeTryingAgain, ""); + loginScreen.setLoginScreenMessage(English.tooManyIncorrectLoginsFromYourAddress, English.pleaseWait5MinutesBeforeTryingAgain, ""); } else if(responseCode == 17) { - Class60.setLoginScreenMessage(English.youAreStandingInMembersOnlyArea, English.toPlayOnThisWorldMoveToFreeArea, ""); + loginScreen.setLoginScreenMessage(English.youAreStandingInMembersOnlyArea, English.toPlayOnThisWorldMoveToFreeArea, ""); } else if(responseCode == 18) { - Class60.setLoginScreenMessage(English.accountLockedAsWeSuspectItHasBeenStolen, English.pressRecoverLockedAccountOnFrontPage, ""); + loginScreen.setLoginScreenMessage(English.accountLockedAsWeSuspectItHasBeenStolen, English.pressRecoverLockedAccountOnFrontPage, ""); } else if(responseCode == 20) { - Class60.setLoginScreenMessage(English.invalidLoginserverRequested, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.invalidLoginserverRequested, English.pleaseTryUsingDifferentWorld, ""); } else if(responseCode == 22) { - Class60.setLoginScreenMessage(English.malformedLoginPacket, English.pleaseTryAgain, ""); + loginScreen.setLoginScreenMessage(English.malformedLoginPacket, English.pleaseTryAgain, ""); } else if(responseCode == 23) { - Class60.setLoginScreenMessage(English.noReplyFromLoginserver, English.pleaseWait1MinuteAndTryAgain, ""); + loginScreen.setLoginScreenMessage(English.noReplyFromLoginserver, English.pleaseWait1MinuteAndTryAgain, ""); } else if(responseCode == 24) { - Class60.setLoginScreenMessage(English.errorLoadingYourProfile, English.pleaseContactCustomerSupport, ""); + loginScreen.setLoginScreenMessage(English.errorLoadingYourProfile, English.pleaseContactCustomerSupport, ""); } else if(responseCode == 25) { - Class60.setLoginScreenMessage(English.unexpectedLoginserverResponse, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.unexpectedLoginserverResponse, English.pleaseTryUsingDifferentWorld, ""); } else if(responseCode == 26) { - Class60.setLoginScreenMessage(English.thisComputersAddressHasBeenBlocked, English.asItWasUsedToBreakOurRules, ""); + loginScreen.setLoginScreenMessage(English.thisComputersAddressHasBeenBlocked, English.asItWasUsedToBreakOurRules, ""); } else if(responseCode == 27) { - Class60.setLoginScreenMessage("", English.serviceUnavailable, ""); + loginScreen.setLoginScreenMessage("", English.serviceUnavailable, ""); } else { - Class60.setLoginScreenMessage(English.unexpectedServerResponse, English.pleaseTryUsingDifferentWorld, ""); + loginScreen.setLoginScreenMessage(English.unexpectedServerResponse, English.pleaseTryUsingDifferentWorld, ""); } MovedStatics.processGameStatus(10); } @@ -1735,7 +1714,7 @@ public static void handleLoginScreenActions() { } if (loginStatus == 8) { anInt1756 = 0; - Class60.setLoginScreenMessage(English.youHaveJustLeftAnotherWorld, English.yourProfileWillBeTransferredIn, (anInt784 / 60) + English.suffixSeconds); + loginScreen.setLoginScreenMessage(English.youHaveJustLeftAnotherWorld, English.yourProfileWillBeTransferredIn, (anInt784 / 60) + English.suffixSeconds); if (--anInt784 <= 0) { loginStatus = 0; } @@ -2169,9 +2148,9 @@ public void processGameLoop() { MovedStatics.startup(); method992(); } else if (gameStatusCode == 10) { - Class60.updateLogin(); + loginScreen.updateLogin(); } else if (gameStatusCode == 20) { - Class60.updateLogin(); + loginScreen.updateLogin(); handleLoginScreenActions(); } else if (gameStatusCode == 25) currentScene.landscape.loadRegion(); @@ -2209,11 +2188,11 @@ public void updateStatusText() { if (gameStatusCode == 0) renderer.drawLoadingText(MovedStatics.anInt1607, null, Native.currentLoadingText); else if (gameStatusCode == 5) { - Class60.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); + loginScreen.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); } else if (gameStatusCode == 10) { - Class60.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); + loginScreen.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); } else if (gameStatusCode == 20) { - Class60.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); + loginScreen.drawLoadingScreen(TypeFace.fontBold, TypeFace.fontSmall); } else if (gameStatusCode == 25) { if (MovedStatics.anInt1634 == 1) { if (anInt874 > MovedStatics.anInt2231) @@ -2229,7 +2208,6 @@ else if (gameStatusCode == 5) { MovedStatics.method940(English.loadingPleaseWait, false, null); } else if (gameStatusCode == 30) { drawGameScreen(); - } else if (gameStatusCode == 35) { method164(); } else if (gameStatusCode == 40) diff --git a/src/main/java/org/runejs/client/Landscape.java b/src/main/java/org/runejs/client/Landscape.java index fafbdbb03..12fc0755a 100644 --- a/src/main/java/org/runejs/client/Landscape.java +++ b/src/main/java/org/runejs/client/Landscape.java @@ -513,7 +513,7 @@ private void createRegion(CollisionMap[] collisionMaps) { } int underlayMinimapColour = 0; if(hslBitsetRandomised != -1) - underlayMinimapColour = Rasterizer3D.hsl2rgb[mixLightness(hslBitsetRandomised, 96)]; + underlayMinimapColour = Rasterizer3D.palette.hsl2rgb[mixLightness(hslBitsetRandomised, 96)]; if(overlayId != 0) { int shape = 1 + tile_underlay_path[_plane][x][y]; byte rotation = tile_overlay_rotation[_plane][x][y]; @@ -540,7 +540,7 @@ else if(s > 255) } int rgb = 0; if(overlayMinimapColour != -2) - rgb = Rasterizer3D.hsl2rgb[MovedStatics.mixLightnessSigned(overlayMinimapColour, 96)]; + rgb = Rasterizer3D.palette.hsl2rgb[MovedStatics.mixLightnessSigned(overlayMinimapColour, 96)]; if(overlayDefinition.secondaryColor != -1) { int i_54_ = 0xff & randomiserHue + overlayDefinition.otherHue; int i_55_ = overlayDefinition.otherSaturation + randomiserLightness; @@ -550,7 +550,7 @@ else if(s > 255) } else i_55_ = 0; overlayMinimapColour = generateHslBitset(overlayDefinition.otherLightness, i_55_, i_54_); - rgb = Rasterizer3D.hsl2rgb[MovedStatics.mixLightnessSigned(overlayMinimapColour, 96)]; + rgb = Rasterizer3D.palette.hsl2rgb[MovedStatics.mixLightnessSigned(overlayMinimapColour, 96)]; } this.scene.addTile(_plane, x, y, shape, rotation, textureId, vertexHeightSW, vertexHeightSE, vertexHeightNE, vertexHeightNW, mixLightness(hslBitsetOriginal, lightIntensitySW), mixLightness(hslBitsetOriginal, lightIntensitySE), mixLightness(hslBitsetOriginal, lightIntensityNE), mixLightness(hslBitsetOriginal, lightIntensityNW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySW), MovedStatics.mixLightnessSigned(hslBitset, lightIntensitySE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNE), MovedStatics.mixLightnessSigned(hslBitset, lightIntensityNW), underlayMinimapColour, rgb); } else diff --git a/src/main/java/org/runejs/client/Class60.java b/src/main/java/org/runejs/client/LoginScreen.java similarity index 77% rename from src/main/java/org/runejs/client/Class60.java rename to src/main/java/org/runejs/client/LoginScreen.java index 40056feb8..abfdb9228 100644 --- a/src/main/java/org/runejs/client/Class60.java +++ b/src/main/java/org/runejs/client/LoginScreen.java @@ -10,7 +10,7 @@ import org.runejs.client.input.MouseHandler; import org.runejs.client.language.English; import org.runejs.client.language.Native; -import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.VertexNormal; import org.runejs.client.net.UpdateServer; import org.runejs.client.sound.MusicSystem; @@ -23,65 +23,65 @@ /** * The class that handles the login screen. */ -public class Class60 { - public static int loginScreenState = 0; - public static int loginScreenFocus = 0; - public static ProducingGraphicsBuffer muteButton; +public class LoginScreen { + public int loginScreenState = 0; + public int loginScreenFocus = 0; + public ProducingGraphicsBuffer muteButton; /** * Part of login screen */ - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_1631; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_1631; /** * Part of login screen */ - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_1206; - public static ProducingGraphicsBuffer flameRightBackground; - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_1285; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_1206; + public ProducingGraphicsBuffer flameRightBackground; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_1285; /** * Something to do with flames, maybe */ - public static int anInt2452 = 0; + public int anInt2452 = 0; /** * Something to do with flames, maybe */ - public static int anInt2613 = 0; + public int anInt2613 = 0; /** * Something to do with flames, maybe */ - public static int[] anIntArray1013; + public int[] anIntArray1013; /** * Something to do with flames, maybe */ - public static int[] anIntArray1198; - public static int[] anIntArray2865; - public static int[] anIntArray3248; - public static ProducingGraphicsBuffer flameLeftBackground; + public int[] anIntArray1198; + public int[] anIntArray2865; + public int[] anIntArray3248; + public ProducingGraphicsBuffer flameLeftBackground; /** * Something to do with flames, maybe */ - public static ImageRGB aClass40_Sub5_Sub14_Sub4_918; + public ImageRGB aClass40_Sub5_Sub14_Sub4_918; /** * Something to do with flames, maybe */ - public static int[] anIntArray466 = new int[256]; + public int[] anIntArray466 = new int[256]; /** * Something to do with flames, maybe */ - public static int[] anIntArray178; - public static ImageRGB aClass40_Sub5_Sub14_Sub4_2043; - public static ProducingGraphicsBuffer loginBoxGraphics; - public static IndexedImage loginScreenBox; - public static IndexedImage imgLoginScreenButton; - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_907; - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_463; - public static ProducingGraphicsBuffer aProducingGraphicsBuffer_2524; - public static int[] anIntArray3255; - public static int[] anIntArray1168; - public static int anInt1641 = 0; - public static IndexedImage[] aClass40_Sub5_Sub14_Sub2Array535; - public static int[] anIntArray1445; - - public static void updateLogin() { + public int[] anIntArray178; + public ImageRGB aClass40_Sub5_Sub14_Sub4_2043; + public ProducingGraphicsBuffer loginBoxGraphics; + public IndexedImage loginScreenBox; + public IndexedImage imgLoginScreenButton; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_907; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_463; + public ProducingGraphicsBuffer aProducingGraphicsBuffer_2524; + public int[] anIntArray3255; + public int[] anIntArray1168; + public int anInt1641 = 0; + public IndexedImage[] aClass40_Sub5_Sub14_Sub2Array535; + public int[] anIntArray1445; + + public void updateLogin() { method836(1); if(MouseHandler.clickType == 1 && MouseHandler.clickY >= ScreenController.drawHeight-42 && MouseHandler.clickX>=ScreenController.drawWidth-42 ){ @@ -197,22 +197,26 @@ public static void updateLogin() { } } - public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { - loginBoxGraphics.prepareRasterizer(); + public void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { + loginBoxGraphics.prepareRasterizer(rasterizer); + + fontBold.setRasterizer(rasterizer); + fontSmall.setRasterizer(rasterizer); + // Rasterizer.drawFilledRectangle(0,0, ScreenController.frameWidth, ScreenController.frameHeight, 0); if (Game.gameStatusCode == 0 || Game.gameStatusCode == 5) { int i = 20; fontBold.drawStringLeft(English.gameIsLoadingPleaseWait, 180, 74 + -i, 16777215); int i_89_ = -i + 82; - Rasterizer.drawUnfilledRectangle(28, i_89_, 304, 34, 9179409); - Rasterizer.drawUnfilledRectangle(29, 1 + i_89_, 302, 32, 0); - Rasterizer.drawFilledRectangle(30, 2 + i_89_, MovedStatics.anInt1607 * 3, 30, 9179409); - Rasterizer.drawFilledRectangle(3 * MovedStatics.anInt1607 + 30, i_89_ + 2, -(MovedStatics.anInt1607 * 3) + 300, 30, 0); + rasterizer.drawUnfilledRectangle(28, i_89_, 304, 34, 9179409); + rasterizer.drawUnfilledRectangle(29, 1 + i_89_, 302, 32, 0); + rasterizer.drawFilledRectangle(30, 2 + i_89_, MovedStatics.anInt1607 * 3, 30, 9179409); + rasterizer.drawFilledRectangle(3 * MovedStatics.anInt1607 + 30, i_89_ + 2, -(MovedStatics.anInt1607 * 3) + 300, 30, 0); fontBold.drawStringLeft(Native.currentLoadingText, 180, -i + 105, 16777215); } if (Game.gameStatusCode == 20) { int drawY = 40; - loginScreenBox.drawImage(0, 0); + loginScreenBox.drawImage(rasterizer, 0, 0); fontBold.drawShadowedStringCenter(Native.loginScreenMessageLineOne, 180, drawY, 16776960, true); drawY += 15; fontBold.drawShadowedStringCenter(Native.loginScreenMessageLineTwo, 180, drawY, 16776960, true); @@ -226,7 +230,7 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { drawY += 15; } if (Game.gameStatusCode == 10) { - loginScreenBox.drawImage(0, 0); + loginScreenBox.drawImage(rasterizer, 0, 0); if (loginScreenState == 0) { /*fontBold.drawShadowedStringCenter(English.welcomeTo, 180, 80, 16776960, true); int drawX = 100; @@ -247,7 +251,7 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { i_93_ += 15; } - imgLoginScreenButton.drawImage(-73 + i, i_92_ - 20); + imgLoginScreenButton.drawImage(rasterizer, -73 + i, i_92_ - 20); fontBold.drawShadowedStringCenter(English.login, i, 5 + i_92_, 16777215, true); } else if (loginScreenState == 2) { @@ -277,11 +281,11 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { width = fontBold.getStringWidth(English.password + starredPassword.substring(offset) + Native.justAnotherYellowBar); } fontBold.drawShadowedString(English.password + starredPassword.substring(offset) + (MovedStatics.pulseCycle % 40 < 20 & loginScreenFocus == 1 ? Native.justAnotherYellowBar : ""), 92, y1, true, 16777215); - imgLoginScreenButton.drawImage(-73 + drawX, y2 + -20); + imgLoginScreenButton.drawImage(rasterizer, -73 + drawX, y2 + -20); y1 += 15; fontBold.drawShadowedStringCenter(English.login, drawX, y2 + 5, 16777215, true); drawX = 260; - imgLoginScreenButton.drawImage(-73 + drawX, y2 + -20); + imgLoginScreenButton.drawImage(rasterizer, -73 + drawX, y2 + -20); fontBold.drawShadowedStringCenter(English.cancel, drawX, 5 + y2, 16777215, true); } else if (loginScreenState == 3) { fontBold.drawShadowedStringCenter(English.createAFreeAccount, 180, 40, 16776960, true); @@ -294,24 +298,24 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { i_93_ += 15; } - imgLoginScreenButton.drawImage(-73 + i, i_92_ - 20); + imgLoginScreenButton.drawImage(rasterizer, -73 + i, i_92_ - 20); fontBold.drawShadowedStringCenter(English.cancel, i, 5 + i_92_, 16777215, true); } } - muteButton.prepareRasterizer(); + muteButton.prepareRasterizer(rasterizer); ImageRGB musicIcon = TabParts.GetPart("music"); if(ScreenController.frameMode == ScreenMode.RESIZABLE) { - Rasterizer.drawFilledRectangle(0, 0, ScreenController.drawWidth, ScreenController.drawHeight, 0); + rasterizer.drawFilledRectangle(0, 0, ScreenController.drawWidth, ScreenController.drawHeight, 0); } - Rasterizer.drawFilledRectangle(0, 0, 42, 42, 0x4d4431); - Rasterizer.drawUnfilledRectangle(0, 0, 42, 42, 0x242017); - musicIcon.drawImage(4, 3); + rasterizer.drawFilledRectangle(0, 0, 42, 42, 0x4d4431); + rasterizer.drawUnfilledRectangle(0, 0, 42, 42, 0x242017); + musicIcon.drawImage(rasterizer, 4, 3); if(MusicSystem.musicVolume == 0) { - Rasterizer.drawDiagonalLine(0,0, 42,42, 0xFF0000); + rasterizer.drawDiagonalLine(0,0, 42,42, 0xFF0000); } renderFlames(); @@ -352,7 +356,7 @@ public static void drawLoadingScreen(TypeFace fontBold, TypeFace fontSmall) { } } - public static void setLoginScreenMessage(String line1, String line2, String line3) { + public void setLoginScreenMessage(String line1, String line2, String line3) { Native.loginScreenMessageLineOne = line1; Native.loginScreenMessageLineTwo = line2; Native.loginScreenMessageLineThree = line3; @@ -361,7 +365,7 @@ public static void setLoginScreenMessage(String line1, String line2, String line /** * Login screen flames? */ - private static void method836(int arg0) { + private void method836(int arg0) { int i = 256; for (int i_0_ = 10; i_0_ < 117; i_0_++) { int i_1_ = (int) (Math.random() * 100.0); @@ -411,48 +415,54 @@ private static void method836(int arg0) { } } - public static void renderLoginScreen(Component arg0, CacheArchive huffmanCacheArchive, CacheArchive gameImageCacheArchive) { + public ProducingGraphicsBuffer graphicsBuffer; + public RasterizerInstanced rasterizer; + + public void createLoginScreen(Component arg0, CacheArchive huffmanCacheArchive, CacheArchive gameImageCacheArchive) { if (!MovedStatics.aBoolean512) { - flameLeftBackground = MovedStatics.createGraphicsBuffer(128, 265, arg0); - Rasterizer.resetPixels(); - flameRightBackground = MovedStatics.createGraphicsBuffer(128, 265, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_907 = MovedStatics.createGraphicsBuffer(509, 171, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_1206 = MovedStatics.createGraphicsBuffer(360, 132, arg0); - Rasterizer.resetPixels(); - loginBoxGraphics = MovedStatics.createGraphicsBuffer(360, 200, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_463 = MovedStatics.createGraphicsBuffer(202, 238, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_1285 = MovedStatics.createGraphicsBuffer(203, 238, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_2524 = MovedStatics.createGraphicsBuffer(74, 94, arg0); - Rasterizer.resetPixels(); - aProducingGraphicsBuffer_1631 = MovedStatics.createGraphicsBuffer(75, 94, arg0); - Rasterizer.resetPixels(); - muteButton = MovedStatics.createGraphicsBuffer(42, 42, arg0); - Rasterizer.resetPixels(); + graphicsBuffer = MovedStatics.createGraphicsBuffer(arg0.getWidth(), arg0.getHeight(), arg0); + rasterizer = new RasterizerInstanced(graphicsBuffer); + + flameLeftBackground = MovedStatics.createGraphicsBuffer(128, 265, arg0, rasterizer); + rasterizer.resetPixels(); + flameRightBackground = MovedStatics.createGraphicsBuffer(128, 265, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_907 = MovedStatics.createGraphicsBuffer(509, 171, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_1206 = MovedStatics.createGraphicsBuffer(360, 132, arg0, rasterizer); + rasterizer.resetPixels(); + loginBoxGraphics = MovedStatics.createGraphicsBuffer(360, 200, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_463 = MovedStatics.createGraphicsBuffer(202, 238, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_1285 = MovedStatics.createGraphicsBuffer(203, 238, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_2524 = MovedStatics.createGraphicsBuffer(74, 94, arg0, rasterizer); + rasterizer.resetPixels(); + aProducingGraphicsBuffer_1631 = MovedStatics.createGraphicsBuffer(75, 94, arg0, rasterizer); + rasterizer.resetPixels(); + muteButton = MovedStatics.createGraphicsBuffer(42, 42, arg0, rasterizer); + rasterizer.resetPixels(); byte[] is = huffmanCacheArchive.method170("", Native.titleImage); ImageRGB titleImg = new ImageRGB(is, arg0); - flameLeftBackground.prepareRasterizer(); - titleImg.drawInverse(0, 0); - flameRightBackground.prepareRasterizer(); - titleImg.drawInverse(-637, 0); - aProducingGraphicsBuffer_907.prepareRasterizer(); - titleImg.drawInverse(-128, 0); - aProducingGraphicsBuffer_1206.prepareRasterizer(); - titleImg.drawInverse(-202, -371); - loginBoxGraphics.prepareRasterizer(); - titleImg.drawInverse(-202, -171); - aProducingGraphicsBuffer_463.prepareRasterizer(); - titleImg.drawInverse(0, -265); - aProducingGraphicsBuffer_1285.prepareRasterizer(); - titleImg.drawInverse(-562, -265); - aProducingGraphicsBuffer_2524.prepareRasterizer(); - titleImg.drawInverse(-128, -171); - aProducingGraphicsBuffer_1631.prepareRasterizer(); - titleImg.drawInverse(-562, -171); + flameLeftBackground.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 0, 0); + flameRightBackground.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -637, 0); + aProducingGraphicsBuffer_907.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -128, 0); + aProducingGraphicsBuffer_1206.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -202, -371); + loginBoxGraphics.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -202, -171); + aProducingGraphicsBuffer_463.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 0, -265); + aProducingGraphicsBuffer_1285.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -562, -265); + aProducingGraphicsBuffer_2524.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -128, -171); + aProducingGraphicsBuffer_1631.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -562, -171); int[] is_18_ = new int[titleImg.imageWidth]; for (int i = 0; i < titleImg.imageHeight; i++) { for (int i_19_ = 0; i_19_ < titleImg.imageWidth; i_19_++) @@ -460,37 +470,37 @@ public static void renderLoginScreen(Component arg0, CacheArchive huffmanCacheAr for (int i_20_ = 0; i_20_ < titleImg.imageWidth; i_20_++) titleImg.pixels[i_20_ + titleImg.imageWidth * i] = is_18_[i_20_]; } - flameLeftBackground.prepareRasterizer(); - titleImg.drawInverse(382, 0); - flameRightBackground.prepareRasterizer(); - titleImg.drawInverse(-255, 0); - aProducingGraphicsBuffer_907.prepareRasterizer(); - titleImg.drawInverse(254, 0); - aProducingGraphicsBuffer_1206.prepareRasterizer(); - titleImg.drawInverse(180, -371); - loginBoxGraphics.prepareRasterizer(); - titleImg.drawInverse(180, -171); - aProducingGraphicsBuffer_463.prepareRasterizer(); - titleImg.drawInverse(382, -265); - aProducingGraphicsBuffer_1285.prepareRasterizer(); - titleImg.drawInverse(-180, -265); - aProducingGraphicsBuffer_2524.prepareRasterizer(); - titleImg.drawInverse(254, -171); - aProducingGraphicsBuffer_1631.prepareRasterizer(); - titleImg.drawInverse(-180, -171); - muteButton.prepareRasterizer(); + flameLeftBackground.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 382, 0); + flameRightBackground.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -255, 0); + aProducingGraphicsBuffer_907.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 254, 0); + aProducingGraphicsBuffer_1206.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 180, -371); + loginBoxGraphics.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 180, -171); + aProducingGraphicsBuffer_463.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 382, -265); + aProducingGraphicsBuffer_1285.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -180, -265); + aProducingGraphicsBuffer_2524.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, 254, -171); + aProducingGraphicsBuffer_1631.prepareRasterizer(rasterizer); + titleImg.drawInverse(rasterizer, -180, -171); + muteButton.prepareRasterizer(rasterizer); ImageRGB musicIcon = TabParts.GetPart("music"); - Rasterizer.drawFilledRectangle(0, 0, 42, 42, 0x4d4431); - Rasterizer.drawUnfilledRectangle(0, 0, 42, 42, 0x242017); - musicIcon.drawImage(4, 3); + rasterizer.drawFilledRectangle(0, 0, 42, 42, 0x4d4431); + rasterizer.drawUnfilledRectangle(0, 0, 42, 42, 0x242017); + musicIcon.drawImage(rasterizer, 4, 3); titleImg = MovedStatics.method1028(gameImageCacheArchive, Native.logo, ""); - aProducingGraphicsBuffer_907.prepareRasterizer(); + aProducingGraphicsBuffer_907.prepareRasterizer(rasterizer); // UNCOMMENT LINE UNDER FOR LOGO // class40_sub5_sub14_sub4.drawImage(-128 + 382 + -(class40_sub5_sub14_sub4.imageWidth / 2), 18); // Comment line under to remove custom logo: ImageRGB logo = Images.GetPart("logo"); - logo.drawImage(-128 + 382 + -(logo.imageWidth / 2), 18); + logo.drawImage(rasterizer, -128 + 382 + -(logo.imageWidth / 2), 18); loginScreenBox = Game.method359(Native.titleBox, "", gameImageCacheArchive); imgLoginScreenButton = Game.method359(Native.titleButton, "", gameImageCacheArchive); @@ -548,7 +558,7 @@ public static void renderLoginScreen(Component arg0, CacheArchive huffmanCacheAr } } - public static void method879(IndexedImage arg1) { + public void method879(IndexedImage arg1) { int i = 0; for(/**/; i < anIntArray1168.length; i++) anIntArray1168[i] = 0; @@ -583,7 +593,7 @@ public static void method879(IndexedImage arg1) { } } - public static void renderFlames() { + public void renderFlames() { if (anInt2452 <= 0) { if (anInt2613 > 0) { for (int i = 0; i < 256; i++) { @@ -656,8 +666,39 @@ else if (anInt2613 > 256) } } - public static int method614(int arg1, int arg2, int arg3) { + public int method614(int arg1, int arg2, int arg3) { int i_7_ = 256 + -arg3; return (arg3 * (0xff00 & arg2) + i_7_ * (0xff00 & arg1) & 0xff0000) + (~0xff00ff & (0xff00ff & arg1) * i_7_ + arg3 * (0xff00ff & arg2)) >> 8; } + + + public void cleanUp() { + if (MovedStatics.aBoolean512) { + anIntArray1198 = null; + flameRightBackground = null; + aProducingGraphicsBuffer_1631 = null; + aProducingGraphicsBuffer_1206 = null; + anIntArray1168 = null; + anIntArray3255 = null; + imgLoginScreenButton = null; + anIntArray1445 = null; + loginScreenBox = null; + anIntArray2865 = null; + flameLeftBackground = null; + aProducingGraphicsBuffer_907 = null; + aProducingGraphicsBuffer_2524 = null; + aClass40_Sub5_Sub14_Sub4_918 = null; + aClass40_Sub5_Sub14_Sub2Array535 = null; + anIntArray3248 = null; + loginBoxGraphics = null; + aClass40_Sub5_Sub14_Sub4_2043 = null; + anIntArray178 = null; + aProducingGraphicsBuffer_1285 = null; + aProducingGraphicsBuffer_463 = null; + anIntArray1013 = null; + MusicSystem.method405(10); + UpdateServer.resetUpdateServerRequests(true); + MovedStatics.aBoolean512 = false; + } + } } diff --git a/src/main/java/org/runejs/client/MovedStatics.java b/src/main/java/org/runejs/client/MovedStatics.java index e7abfb187..52f347324 100644 --- a/src/main/java/org/runejs/client/MovedStatics.java +++ b/src/main/java/org/runejs/client/MovedStatics.java @@ -16,6 +16,7 @@ import org.runejs.client.input.MouseHandler; import org.runejs.client.io.Buffer; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.renderable.Item; import org.runejs.client.media.renderable.Model; import org.runejs.client.net.*; @@ -123,7 +124,6 @@ public class MovedStatics { public static volatile int eventClickY = 0; public static int anInt2628 = 0; public static volatile boolean clearScreen = true; - public static ProducingGraphicsBuffer gameScreenImageProducer; /** * Bit masks for packet buffer */ @@ -314,7 +314,7 @@ public class MovedStatics { public static boolean aBoolean512; public static int[] anIntArray3111; public static Signlink signlink; - public static ProducingGraphicsBuffer tabPieveLowerRight; + public static ProducingGraphicsBuffer tabPieceLowerRight; public static GameSocket lostConnectionSocket; public static ProducingGraphicsBuffer tabPieceLeft; public static int anInt3048 = 1; @@ -362,36 +362,6 @@ public class MovedStatics { */ public static int anInt2869 = 0; - public static void method440() { - if (aBoolean512) { - Class60.anIntArray1198 = null; - Class60.flameRightBackground = null; - Class60.aProducingGraphicsBuffer_1631 = null; - Class60.aProducingGraphicsBuffer_1206 = null; - Class60.anIntArray1168 = null; - Class60.anIntArray3255 = null; - Class60.imgLoginScreenButton = null; - Class60.anIntArray1445 = null; - Class60.loginScreenBox = null; - Class60.anIntArray2865 = null; - Class60.flameLeftBackground = null; - Class60.aProducingGraphicsBuffer_907 = null; - Class60.aProducingGraphicsBuffer_2524 = null; - Class60.aClass40_Sub5_Sub14_Sub4_918 = null; - Class60.aClass40_Sub5_Sub14_Sub2Array535 = null; - Class60.anIntArray3248 = null; - Class60.loginBoxGraphics = null; - Class60.aClass40_Sub5_Sub14_Sub4_2043 = null; - Class60.anIntArray178 = null; - Class60.aProducingGraphicsBuffer_1285 = null; - Class60.aProducingGraphicsBuffer_463 = null; - Class60.anIntArray1013 = null; - MusicSystem.method405(10); - UpdateServer.resetUpdateServerRequests(true); - aBoolean512 = false; - } - } - public static int[] menuActionTypes = new int[500]; public static boolean showSidePanelRedrawnText = false; /** @@ -443,7 +413,6 @@ public static void method996() { tabImageProducer.prepareRasterizer(); if (ScreenController.frameMode == ScreenMode.FIXED) { inventoryBackgroundImage.drawImage(0, 0); - } else { int currentX = 0; int currentY = 0; @@ -909,18 +878,20 @@ public static void processGameStatus(int statusCode) { } if (statusCode == 0 || statusCode == 35) { method344(-40); - method440(); + Game.loginScreen.cleanUp(); if (aProducingGraphicsBuffer_2213 == null) aProducingGraphicsBuffer_2213 = createGraphicsBuffer(765, 503, Game.gameCanvas); } if (statusCode == 5 || statusCode == 10 || statusCode == 20) { aProducingGraphicsBuffer_2213 = null; method344(-69); - Class60.renderLoginScreen(Game.gameCanvas, CacheArchive.huffmanCacheArchive, CacheArchive.gameImageCacheArchive); + Game.loginScreen.createLoginScreen(Game.gameCanvas, CacheArchive.huffmanCacheArchive, CacheArchive.gameImageCacheArchive); } if (statusCode == 25 || statusCode == 30 || statusCode == 40) { aProducingGraphicsBuffer_2213 = null; - method440(); + Game.loginScreen.cleanUp(); + TypeFace.fontBold.setRasterizer(null); + TypeFace.fontSmall.setRasterizer(null); method763(Game.gameCanvas, CacheArchive.gameImageCacheArchive); } Game.gameStatusCode = statusCode; @@ -943,18 +914,22 @@ public static void addActionRow(String string, int menuAction, int firstOperand, } - public static ProducingGraphicsBuffer createGraphicsBuffer(int width, int height, Component component) { + public static ProducingGraphicsBuffer createGraphicsBuffer(int width, int height, Component component, RasterizerInstanced rasterizerInstance) { try { ProducingGraphicsBuffer producingGraphicsBuffer = new ProducingGraphicsBuffer_Sub2(); - producingGraphicsBuffer.method1041(13, width, component, height); + producingGraphicsBuffer.method1041(13, width, component, height, rasterizerInstance); return producingGraphicsBuffer; } catch(Throwable throwable) { ProducingGraphicsBuffer_Sub1 class68_sub1 = new ProducingGraphicsBuffer_Sub1(); - class68_sub1.method1041(44, width, component, height); + class68_sub1.method1041(44, width, component, height, rasterizerInstance); return class68_sub1; } } + public static ProducingGraphicsBuffer createGraphicsBuffer(int width, int height, Component component) { + return createGraphicsBuffer(width, height, component, null); + } + /** * Count down any temporary scene objects and remove them if necessary. */ @@ -1447,7 +1422,6 @@ private static void method344(int arg0) { tabTopBack = null; tabImageProducer = null; tabHighlightImageTopLeftEdge = null; - gameScreenImageProducer = null; tabHighlightImageBottomRightEdge = null; ChatBox.chatBoxImageProducer = null; mapBackRight = null; @@ -1459,7 +1433,7 @@ private static void method344(int arg0) { tabHighlightImageBottomLeft = null; tabHighlightImageBottomLeftEdge = null; fullScreenTextureArray = null; - tabPieveLowerRight = null; + tabPieceLowerRight = null; framePieceTop = null; chatboxBackgroundImage = null; } @@ -1519,231 +1493,6 @@ private static void addObject(int arg0, int arg1, int arg2, int arg3, int arg4, } } - public static void renderSplitPrivateMessages() { - if(ChatBox.splitPrivateChat != 0) { - TypeFace class40_sub5_sub14_sub1 = fontNormal; - int i = 0; - if(systemUpdateTime != 0) - i = 1; - for(int i_0_ = 0; i_0_ < 100; i_0_++) { - if(ChatBox.chatMessages[i_0_] != null) { - String class1 = ChatBox.chatPlayerNames[i_0_]; - int i_1_ = 0; - int i_2_ = ChatBox.chatTypes[i_0_]; - if(class1 != null && class1.startsWith(Native.whiteCrown)) { - class1 = class1.substring(5); - i_1_ = 1; - } - if(class1 != null && class1.startsWith(Native.goldCrown)) { - class1 = class1.substring(5); - i_1_ = 2; - } - if((i_2_ == 3 || i_2_ == 7) && (i_2_ == 7 || ChatBox.privateChatMode == 0 || ChatBox.privateChatMode == 1 && Player.hasFriend(class1))) { - int i_3_ = 329 - 13 * i; - int i_4_ = 4; - i++; - class40_sub5_sub14_sub1.drawString(English.from, i_4_, i_3_, 0); - class40_sub5_sub14_sub1.drawString(English.from, i_4_, -1 + i_3_, 65535); - i_4_ += class40_sub5_sub14_sub1.getStringWidth(English.from); - i_4_ += class40_sub5_sub14_sub1.method689(32); - if(i_1_ == 1) { - moderatorIcon[0].drawImage(i_4_, i_3_ - 12); - i_4_ += 14; - } - if(i_1_ == 2) { - moderatorIcon[1].drawImage(i_4_, -12 + i_3_); - i_4_ += 14; - } - class40_sub5_sub14_sub1.drawString(class1 + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], i_4_, i_3_, 0); - class40_sub5_sub14_sub1.drawString(class1 + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], i_4_, -1 + i_3_, 65535); - if(i >= 5) - return; - } - if(i_2_ == 5 && ChatBox.privateChatMode < 2) { - int i_5_ = -(i * 13) + 329; - i++; - class40_sub5_sub14_sub1.drawString(ChatBox.chatMessages[i_0_], 4, i_5_, 0); - class40_sub5_sub14_sub1.drawString(ChatBox.chatMessages[i_0_], 4, i_5_ - 1, 65535); - if(i >= 5) - return; - } - if(i_2_ == 6 && ChatBox.privateChatMode < 2) { - int i_6_ = -(13 * i) + 329; - i++; - class40_sub5_sub14_sub1.drawString(English.to + Native.whitespace_b + class1 + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], 4, i_6_, 0); - class40_sub5_sub14_sub1.drawString(English.to + Native.whitespace_b + class1 + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], 4, i_6_ + -1, 65535); - if(i >= 5) - return; - } - } - } - } - } - - public static void draw3dScreen() { - renderSplitPrivateMessages(); - if (crossType == 1) { - cursorCross[crossIndex / 100].drawImage(GameInterface.crossX - 8 - 4, GameInterface.crossY - 8 - 4); - } - if (crossType == 2) { - cursorCross[4 + crossIndex / 100].drawImage(GameInterface.crossX - 8 - 4, GameInterface.crossY - 8 - 4); - } - if (GameInterface.gameScreenInterfaceId != -1 || GameInterface.walkableWidgetId != -1) { - int areaId = GameInterface.gameScreenInterfaceId != -1 ? 0 : 4; - int id = GameInterface.gameScreenInterfaceId != -1 ? GameInterface.gameScreenInterfaceId : GameInterface.walkableWidgetId; - GameInterface.handleSequences(id); - int yOffset = (ScreenController.drawHeight /2) - (334/2) - (184/2); - int xOffset = (ScreenController.drawWidth /2) - (512/2) - (234/3); - if(ScreenController.frameMode == ScreenMode.FIXED) { - yOffset = 0; - xOffset = 0; - } - Game.drawParentInterface(areaId, xOffset, yOffset, 512+ xOffset, 334 + yOffset, id); - } - method1018(); - Player.setTutorialIslandFlag(); - if (!menuOpen) { - processRightClick(); - drawMenuTooltip(4); - } else { - if(ScreenController.frameMode == ScreenMode.FIXED && menuScreenArea == 0){ - drawMenu(4,4); - } - } - if (multiCombatState == 1) { - multiCombatIcon.drawImage(472, 296); - } - if (showFps) { - int y = 20; - int x = 507; - if(ScreenController.frameMode != ScreenMode.FIXED) { - x = ScreenController.drawWidth - 220; - } - - int colour = 0xffff00; - if (GameShell.fps < 30 && VertexNormal.lowMemory) { - colour = 0xff0000; - } - if (GameShell.fps < 20 && !VertexNormal.lowMemory) { - colour = 0xff0000; - } - fontNormal.drawStringRight("Fps: " + GameShell.fps, x, y, colour); - colour = 0xffff00; - y += 15; - Runtime runtime = Runtime.getRuntime(); - int memoryUsed = (int) ((runtime.totalMemory() + -runtime.freeMemory()) / 1024L); - if (memoryUsed > 32768 && VertexNormal.lowMemory) { - colour = 0xff0000; - } - if (memoryUsed < 65536 && !VertexNormal.lowMemory) { - colour = 0xff0000; - } - fontNormal.drawStringRight("Mem: " + memoryUsed + "k", x, y, colour); - y += 15; - - fontNormal.drawStringRight("MouseX: " + MouseHandler.mouseX, x, y ,0xffff00); - y += 15; - - fontNormal.drawStringRight("MouseY: " + MouseHandler.mouseY, x, y ,0xffff00); - y += 15; - fontNormal.drawStringRight("ClickX: " + MouseHandler.clickX, x, y ,0xffff00); - y += 15; - - fontNormal.drawStringRight("ClickY: " + MouseHandler.clickY, x, y ,0xffff00); - y += 15; - if (showSidePanelRedrawnText) { - fontNormal.drawStringRight(English.sidePanelRedrawn, x, y, 16711680); - y += 15; - showSidePanelRedrawnText = false; - } - if (showChatPanelRedrawnText) { - fontNormal.drawStringRight(English.chatPanelRedrawn, x, y, 16711680); - y += 15; - showChatPanelRedrawnText = false; - } - if (showIconsRedrawnText) { - fontNormal.drawStringRight(English.iconsRedrawn, x, y, 16711680); - showIconsRedrawnText = false; - y += 15; - } - } - if (Configuration.DEBUG_WIDGETS) { - int y = 20; - int x = 507; - if(ScreenController.frameMode != ScreenMode.FIXED) { - x = ScreenController.drawWidth - 220; - } - int widgetParentId = hoveredWidgetId >> 16; - int widgetChildId = hoveredWidgetId & 0x7fff; - String typeAsString = ""; - - // Gather widget metadata from the cached interfaces - GameInterface[] parentInterface; - GameInterface childInterface = null; - if (widgetParentId >= 0 && widgetChildId < 469) { - parentInterface = GameInterface.cachedInterfaces[widgetParentId]; - - if (parentInterface != null) { - childInterface = parentInterface[widgetChildId]; - } - - if (childInterface != null) { - switch (childInterface.type) { - case TEXT: - typeAsString = "TEXT"; - break; - case GRAPHIC: - typeAsString = "GRAPHIC"; - break; - case MODEL: - typeAsString = "MODEL"; - break; - case RECTANGLE: - typeAsString = "RECTANGLE"; - break; - case INVENTORY: - typeAsString = "INVENTORY"; - break; - case LINE: - typeAsString = "LINE"; - break; - case TEXT_INVENTORY: - typeAsString = "TEXT_INVENTORY"; - break; - case LAYER: - typeAsString = "LAYER"; - break; - case IF1_TOOLTIP: - typeAsString = "IF1_TOOLTIP"; - break; - default: - typeAsString = "UNKNOWN"; - } - } - } - - fontNormal.drawStringRight("Widget " + widgetParentId + ":" + widgetChildId, x, y, 0xffff00); - y+= 15; - if (childInterface != null) { - fontNormal.drawStringRight("Parent ID: " + childInterface.parentId, x, y, 0xffff00); - y+= 15; - fontNormal.drawStringRight("Type: " + typeAsString, x, y, 0xffff00); - y+= 15; - } - - } - if (systemUpdateTime != 0) { - int seconds = systemUpdateTime / 50; - int minutes = seconds / 60; - seconds %= 60; - if (seconds < 10) { - fontNormal.drawString(English.systemUpdateIn + minutes + Native.prefixColonZero + seconds, 4, 329, 16776960); - } else { - fontNormal.drawString(English.systemUpdateIn + minutes + Native.colon + seconds, 4, 329, 16776960); - } - } - } - public static void processNpcMenuOptions(ActorDefinition actorDefinition, int x, int y, int index) { if (menuActionRow < 400) { if (actorDefinition.childIds != null) { @@ -1921,7 +1670,7 @@ public static void drawWelcomeScreenGraphics() { framePieceTop.drawGraphics(0, 0, graphics); mapBackRight.drawGraphics(516, 4, graphics); tabPieceUpperRight.drawGraphics(516, 205, graphics); - tabPieveLowerRight.drawGraphics(496, 357, graphics); + tabPieceLowerRight.drawGraphics(496, 357, graphics); chatboxTop.drawGraphics(0, 338, graphics); } } catch(Exception exception) { @@ -1938,13 +1687,14 @@ public static void method763(Component arg0, CacheArchive arg2) { tabBottomBack = Game.method359(Native.imgBackbase2, Native.aClass1_305, arg2); tabTopBack = Game.method359(Native.imgBackhmid1, Native.aClass1_305, arg2); ChatBox.chatBoxImageProducer = createGraphicsBuffer(479, 96, arg0); - chatboxBackgroundImage.drawImage(0, 0); + ChatBox.rasterizer = new RasterizerInstanced(ChatBox.chatBoxImageProducer); + chatboxBackgroundImage.drawImage(ChatBox.rasterizer, 0, 0); Minimap.mapbackProducingGraphicsBuffer = createGraphicsBuffer(172, 156, arg0); Rasterizer.resetPixels(); Minimap.minimapBackgroundImage.drawImage(0, 0); tabImageProducer = createGraphicsBuffer(190, 261, arg0); inventoryBackgroundImage.drawImage(0, 0); - gameScreenImageProducer = createGraphicsBuffer(ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight, arg0); + ScreenController.setDrawComponent(arg0); Rasterizer.resetPixels(); chatModes = createGraphicsBuffer(496, 50, arg0); tabBottom = createGraphicsBuffer(269, 37, arg0); @@ -1971,7 +1721,7 @@ public static void method763(Component arg0, CacheArchive arg2) { tabPieceUpperRight = createGraphicsBuffer(image.imageWidth, image.imageHeight, arg0); image.drawInverse(0, 0); image = method1028(arg2, Native.imgBackvmid3, Native.aClass1_305); - tabPieveLowerRight = createGraphicsBuffer(image.imageWidth, image.imageHeight, arg0); + tabPieceLowerRight = createGraphicsBuffer(image.imageWidth, image.imageHeight, arg0); image.drawInverse(0, 0); image = method1028(arg2, Native.imgBackhmid2, Native.aClass1_305); chatboxTop = createGraphicsBuffer(image.imageWidth, image.imageHeight, arg0); @@ -2143,17 +1893,22 @@ public static void method940(String arg1, boolean arg2, String arg3) { int i = 151; method1018(); i -= 3; + + RasterizerInstanced oldRasterizer = fontNormal.getRasterizer(); + fontNormal.setRasterizer(ScreenController.rasterizer); + fontNormal.drawStringLeft(arg1, 257, i, 0); fontNormal.drawStringLeft(arg1, 256, i + -1, 16777215); if(arg3 != null) { i += 15; if(arg2) { int i_0_ = 4 + fontNormal.getStringWidth(arg3); - Rasterizer.drawFilledRectangle(257 - i_0_ / 2, -11 + i, i_0_, 11, 0); + ScreenController.rasterizer.drawFilledRectangle(257 - i_0_ / 2, -11 + i, i_0_, 11, 0); } fontNormal.drawStringLeft(arg3, 257, i, 0); fontNormal.drawStringLeft(arg3, 256, i - 1, 16777215); } + fontNormal.setRasterizer(oldRasterizer); drawGameScreenGraphics(); } @@ -2599,8 +2354,8 @@ else if(i < Player.localPlayerCount) int i_1_ = 30 * actor.remainingHitpoints / actor.maximumHitpoints; if(i_1_ > 30) i_1_ = 30; - Rasterizer.drawFilledRectangle(-15 + screenPos.x, screenPos.y + -3, i_1_, 5, 65280); - Rasterizer.drawFilledRectangle(-15 + screenPos.x + i_1_, screenPos.y + -3, 30 + -i_1_, 5, 16711680); + ScreenController.rasterizer.drawFilledRectangle(-15 + screenPos.x, screenPos.y + -3, i_1_, 5, 65280); + ScreenController.rasterizer.drawFilledRectangle(-15 + screenPos.x + i_1_, screenPos.y + -3, 30 + -i_1_, 5, 16711680); } } for(int i_2_ = 0; i_2_ < 4; i_2_++) { @@ -2955,7 +2710,7 @@ public static int method988(CacheArchive arg0, CacheArchive arg1) { } public static void method1018() { - gameScreenImageProducer.prepareRasterizer(); + ScreenController.drawComponent.prepareRasterizer(); fullScreenTextureArray = Rasterizer3D.setLineOffsets(fullScreenTextureArray); } @@ -3064,7 +2819,7 @@ else if(arg0) public static void drawGameScreenGraphics() { try { Graphics graphics = Game.gameCanvas.getGraphics(); - gameScreenImageProducer.drawGraphics(ScreenController.frameMode == ScreenMode.FIXED ? 4 : 0, ScreenController.frameMode == ScreenMode.FIXED ? 4 : 0, graphics); + ScreenController.drawComponent.drawGraphics(ScreenController.frameMode == ScreenMode.FIXED ? 4 : 0, ScreenController.frameMode == ScreenMode.FIXED ? 4 : 0, graphics); } catch(Exception exception) { Game.gameCanvas.repaint(); } diff --git a/src/main/java/org/runejs/client/ProducingGraphicsBuffer.java b/src/main/java/org/runejs/client/ProducingGraphicsBuffer.java index 9018039e3..adbb1c872 100644 --- a/src/main/java/org/runejs/client/ProducingGraphicsBuffer.java +++ b/src/main/java/org/runejs/client/ProducingGraphicsBuffer.java @@ -1,6 +1,7 @@ package org.runejs.client; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import java.awt.*; @@ -11,11 +12,20 @@ public abstract class ProducingGraphicsBuffer { public Image image; public abstract void method1041(int i, int i_2_, Component component, int i_3_); + public abstract void method1041(int i, int i_2_, Component component, int i_3_, RasterizerInstanced rasterizerInstance); public abstract void drawGraphics(int x, int y, Graphics graphics); public abstract void paintComponent(int x, int y, Graphics graphics); + public void prepareRasterizer(RasterizerInstanced rasterizerInstance) { + if (rasterizerInstance == null) { + Rasterizer.prepare(pixels, width, height); + } else { + rasterizerInstance.prepare(pixels, width, height); + } + } + public void prepareRasterizer() { - Rasterizer.prepare(pixels, width, height); + prepareRasterizer(null); } } diff --git a/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub1.java b/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub1.java index d7cf5ec34..41650b9e3 100644 --- a/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub1.java +++ b/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub1.java @@ -1,6 +1,7 @@ package org.runejs.client; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import java.awt.*; import java.awt.image.*; @@ -50,7 +51,7 @@ public synchronized void addConsumer(ImageConsumer arg0) { arg0.setHints(14); } - public void method1041(int arg0, int arg1, Component arg2, int arg3) { + public void method1041(int arg0, int arg1, Component arg2, int arg3, RasterizerInstanced rasterizerInstanced) { pixels = new int[1 + arg1 * arg3]; width = arg1; height = arg3; @@ -64,7 +65,11 @@ public void method1041(int arg0, int arg1, Component arg2, int arg3) { arg2.prepareImage(image, this); drawPixels(); arg2.prepareImage(image, this); - this.prepareRasterizer(); + this.prepareRasterizer(rasterizerInstanced); + } + + public void method1041(int arg0, int arg1, Component arg2, int arg3) { + method1041(arg0, arg1, arg2, arg3, null); } public void startProduction(ImageConsumer arg0) { diff --git a/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub2.java b/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub2.java index 66b5d3051..bbd39114d 100644 --- a/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub2.java +++ b/src/main/java/org/runejs/client/ProducingGraphicsBuffer_Sub2.java @@ -1,5 +1,7 @@ package org.runejs.client; +import org.runejs.client.media.RasterizerInstanced; + import java.awt.*; import java.awt.image.*; import java.util.Hashtable; @@ -14,7 +16,7 @@ public void paintComponent(int arg1, int arg3, Graphics arg2) { arg2.drawImage(image, arg1, arg3, aComponent2214); } - public void method1041(int arg0, int arg1, Component arg2, int arg3) { + public void method1041(int arg0, int arg1, Component arg2, int arg3, RasterizerInstanced rasterizerInstance) { width = arg1; if(arg0 > 4) { pixels = new int[1 + arg3 * arg1]; @@ -24,7 +26,11 @@ public void method1041(int arg0, int arg1, Component arg2, int arg3) { WritableRaster writableraster = Raster.createWritableRaster(directcolormodel.createCompatibleSampleModel(width, height), databufferint, null); image = new BufferedImage(directcolormodel, writableraster, false, new Hashtable()); aComponent2214 = arg2; - prepareRasterizer(); + prepareRasterizer(rasterizerInstance); } } + + public void method1041(int arg0, int arg1, Component arg2, int arg3) { + method1041(arg0, arg1, arg2, arg3, null); + } } diff --git a/src/main/java/org/runejs/client/Texture.java b/src/main/java/org/runejs/client/Texture.java index 0a3ad65cf..faa50578a 100644 --- a/src/main/java/org/runejs/client/Texture.java +++ b/src/main/java/org/runejs/client/Texture.java @@ -2,6 +2,7 @@ import org.runejs.client.cache.CacheArchive; import org.runejs.client.cache.media.IndexedImage; +import org.runejs.client.media.ColorUtils; import org.runejs.client.node.Node; import org.runejs.client.io.Buffer; import org.runejs.client.media.Rasterizer3D; @@ -136,7 +137,7 @@ public boolean method869(double arg0, int textureSize, CacheArchive imageArchive } } for(int i_19_ = 0; i_19_ < imgPalette.length; i_19_++) - imgPalette[i_19_] = Rasterizer3D.adjustBrightness(imgPalette[i_19_], arg0); + imgPalette[i_19_] = ColorUtils.adjustBrightness(imgPalette[i_19_], arg0); int i_20_; if(i_12_ == 0) i_20_ = 0; diff --git a/src/main/java/org/runejs/client/cache/def/ItemDefinition.java b/src/main/java/org/runejs/client/cache/def/ItemDefinition.java index f8e0283fc..bfcf2d003 100644 --- a/src/main/java/org/runejs/client/cache/def/ItemDefinition.java +++ b/src/main/java/org/runejs/client/cache/def/ItemDefinition.java @@ -4,6 +4,7 @@ import org.runejs.client.cache.media.ImageRGB; import org.runejs.client.io.Buffer; import org.runejs.client.language.English; +import org.runejs.client.media.Constants3D; import org.runejs.client.media.Rasterizer; import org.runejs.client.media.Rasterizer3D; import org.runejs.client.media.renderable.Model; @@ -168,8 +169,8 @@ public static ImageRGB sprite(int stackSize, int id, int backColour) { if(backColour > 0) i_11_ *= 1.04; Rasterizer3D.notTextured = false; - int i_12_ = Rasterizer3D.sinetable[definition.xan2d] * i_11_ >> 16; - int i_13_ = i_11_ * Rasterizer3D.cosinetable[definition.xan2d] >> 16; + int i_12_ = Constants3D.sinetable[definition.xan2d] * i_11_ >> 16; + int i_13_ = i_11_ * Constants3D.cosinetable[definition.xan2d] >> 16; model.method799(); model.drawModel(0, definition.yan2d, definition.zan2d, definition.xan2d, definition.xOffset2d, definition.yOffset2d + model.modelHeight / 2 + i_12_, i_13_ + definition.yOffset2d); for(int i_14_ = 31; i_14_ >= 0; i_14_--) { diff --git a/src/main/java/org/runejs/client/cache/media/ImageRGB.java b/src/main/java/org/runejs/client/cache/media/ImageRGB.java index cc4d5db0b..cef4b3a86 100644 --- a/src/main/java/org/runejs/client/cache/media/ImageRGB.java +++ b/src/main/java/org/runejs/client/cache/media/ImageRGB.java @@ -3,12 +3,14 @@ import org.runejs.client.MovedStatics; import org.runejs.client.cache.CacheArchive; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; +import org.runejs.client.node.CachedNode; import org.runejs.client.util.BitUtils; import java.awt.*; import java.awt.image.PixelGrabber; -public class ImageRGB extends Rasterizer { +public class ImageRGB extends CachedNode { public int offsetY; public int imageHeight; public int imageWidth; @@ -355,6 +357,43 @@ public void drawImageWithTexture(int x, int y, int textureId, int arg3) { method722(maxWidth << 3, maxHeight << 3, x << 4, y << 4, textureId, arg3); } + public void drawImage(RasterizerInstanced rasterizer, int x, int y) { + x += offsetX; + y += offsetY; + int dest_offset = x + y * rasterizer.destinationWidth; + int source_offset = 0; + int line_count = imageHeight; + int line_width = imageWidth; + int line_offset_dest = rasterizer.destinationWidth - line_width; + int line_offset_source = 0; + if(y < rasterizer.viewportTop) { + int clip_height = rasterizer.viewportTop - y; + line_count -= clip_height; + y = rasterizer.viewportTop; + source_offset += clip_height * line_width; + dest_offset += clip_height * rasterizer.destinationWidth; + } + if(y + line_count > rasterizer.viewportBottom) + line_count -= y + line_count - rasterizer.viewportBottom; + if(x < rasterizer.viewportLeft) { + int clip_width = rasterizer.viewportLeft - x; + line_width -= clip_width; + x = rasterizer.viewportLeft; + source_offset += clip_width; + dest_offset += clip_width; + line_offset_source += clip_width; + line_offset_dest += clip_width; + } + if(x + line_width > rasterizer.viewportRight) { + int clip_width = x + line_width - rasterizer.viewportRight; + line_width -= clip_width; + line_offset_source += clip_width; + line_offset_dest += clip_width; + } + if(line_width > 0 && line_count > 0) + blockCopyTrans(rasterizer.destinationPixels, pixels, 0, source_offset, dest_offset, line_width, line_count, line_offset_dest, line_offset_source); + } + public void drawImage(int x, int y) { x += offsetX; y += offsetY; @@ -782,11 +821,11 @@ public void method722(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5 } } - public void prepareRasterizer() { - Rasterizer.prepare(pixels, imageWidth, imageHeight); + public void prepareRasterizer(RasterizerInstanced rasterizer) { + rasterizer.prepare(pixels, imageWidth, imageHeight); } - public void shapeImageToPixels(int x, int y, int width, int height, int arg4, int arg5, int k1, int zoom, int[] arg8, int[] arg9) { + public void shapeImageToPixels(RasterizerInstanced rasterizer, int x, int y, int width, int height, int arg4, int arg5, int k1, int zoom, int[] arg8, int[] arg9) { try { int centerX = -width / 2; int centerY = -height / 2; @@ -796,7 +835,7 @@ public void shapeImageToPixels(int x, int y, int width, int height, int arg4, in cosine = cosine * zoom >> 8; int i_125_ = (arg4 << 16) + centerY * sine + centerX * cosine; int i_126_ = (arg5 << 16) + centerY * cosine - centerX * sine; - int destinationOffset = x + y * Rasterizer.destinationWidth; + int destinationOffset = x + y * rasterizer.destinationWidth; for(y = 0; y < height; y++) { int i_128_ = arg8[y]; @@ -809,13 +848,13 @@ public void shapeImageToPixels(int x, int y, int width, int height, int arg4, in if(!(pixels.length < pixelToGet || pixelToGet < 0)){ colour = pixels[pixelToGet]; } - Rasterizer.destinationPixels[i_129_++] = colour; + rasterizer.destinationPixels[i_129_++] = colour; i_130_ += cosine; i_131_ -= sine; } i_125_ += sine; i_126_ += cosine; - destinationOffset += Rasterizer.destinationWidth; + destinationOffset += rasterizer.destinationWidth; } } catch(Exception exception) { /* empty */ @@ -823,41 +862,41 @@ public void shapeImageToPixels(int x, int y, int width, int height, int arg4, in } } - public void drawTo(IndexedImage indexedImage, int x, int y) { + public void drawTo(RasterizerInstanced rasterizer, IndexedImage indexedImage, int x, int y) { x += offsetX; y += offsetY; - int dest_ptr = x + y * Rasterizer.destinationWidth; + int dest_ptr = x + y * rasterizer.destinationWidth; int source_ptr = 0; int line_count = imageHeight; int line_width = imageWidth; - int line_offset_dest = Rasterizer.destinationWidth - line_width; + int line_offset_dest = rasterizer.destinationWidth - line_width; int line_offset_src = 0; - if(y < Rasterizer.viewportTop) { - int clip_height = Rasterizer.viewportTop - y; + if(y < rasterizer.viewportTop) { + int clip_height = rasterizer.viewportTop - y; line_count -= clip_height; - y = Rasterizer.viewportTop; + y = rasterizer.viewportTop; source_ptr += clip_height * line_width; - dest_ptr += clip_height * Rasterizer.destinationWidth; + dest_ptr += clip_height * rasterizer.destinationWidth; } - if(y + line_count > Rasterizer.viewportBottom) - line_count -= y + line_count - Rasterizer.viewportBottom; - if(x < Rasterizer.viewportLeft) { - int clip_width = Rasterizer.viewportLeft - x; + if(y + line_count > rasterizer.viewportBottom) + line_count -= y + line_count - rasterizer.viewportBottom; + if(x < rasterizer.viewportLeft) { + int clip_width = rasterizer.viewportLeft - x; line_width -= clip_width; - x = Rasterizer.viewportLeft; + x = rasterizer.viewportLeft; source_ptr += clip_width; dest_ptr += clip_width; line_offset_src += clip_width; line_offset_dest += clip_width; } - if(x + line_width > Rasterizer.viewportRight) { - int clip_width = x + line_width - Rasterizer.viewportRight; + if(x + line_width > rasterizer.viewportRight) { + int clip_width = x + line_width - rasterizer.viewportRight; line_width -= clip_width; line_offset_src += clip_width; line_offset_dest += clip_width; } if(line_width > 0 && line_count > 0) - blockCopyMask(Rasterizer.destinationPixels, pixels, 0, source_ptr, dest_ptr, line_width, line_count, line_offset_dest, line_offset_src, indexedImage.imgPixels); + blockCopyMask(rasterizer.destinationPixels, pixels, 0, source_ptr, dest_ptr, line_width, line_count, line_offset_dest, line_offset_src, indexedImage.imgPixels); } public void trim() { @@ -875,6 +914,43 @@ public void trim() { } } + public void drawInverse(RasterizerInstanced rasterizer, int x, int y) { + x += offsetX; + y += offsetY; + int rasterizerPixel = x + y * rasterizer.destinationWidth; + int pixel = 0; + int newHeight = imageHeight; + int newWidth = imageWidth; + int rasterizerPixelOffset = rasterizer.destinationWidth - newWidth; + int pixelOffset = 0; + if(y < rasterizer.viewportTop) { + int yOffset = rasterizer.viewportTop - y; + newHeight -= yOffset; + y = rasterizer.viewportTop; + pixel += yOffset * newWidth; + rasterizerPixel += yOffset * rasterizer.destinationWidth; + } + if(y + newHeight > rasterizer.viewportBottom) + newHeight -= y + newHeight - rasterizer.viewportBottom; + if(x < rasterizer.viewportLeft) { + int xOffset = rasterizer.viewportLeft - x; + newWidth -= xOffset; + x = rasterizer.viewportLeft; + pixel += xOffset; + rasterizerPixel += xOffset; + pixelOffset += xOffset; + rasterizerPixelOffset += xOffset; + } + if(x + newWidth > rasterizer.viewportRight) { + int widthOffset = x + newWidth - rasterizer.viewportRight; + newWidth -= widthOffset; + pixelOffset += widthOffset; + rasterizerPixelOffset += widthOffset; + } + if(newWidth > 0 && newHeight > 0) + copyPixels(rasterizer.destinationPixels, pixels, pixel, rasterizerPixel, newWidth, newHeight, rasterizerPixelOffset, pixelOffset); + } + public void drawInverse(int x, int y) { x += offsetX; y += offsetY; @@ -949,7 +1025,7 @@ public void drawImageWithOpacity(int x, int y, int opacity) { method730(Rasterizer.destinationPixels, pixels, 0, i_149_, i, i_151_, i_150_, i_152_, i_153_, opacity); } - public void drawRotated(int x, int y, int pivotX, int pivotY, int width, int height, int zoom, double angle) { + public void drawRotated(RasterizerInstanced rasterizer, int x, int y, int pivotX, int pivotY, int width, int height, int zoom, double angle) { try { int centerX = -width / 2; int centerY = -height / 2; @@ -959,7 +1035,7 @@ public void drawRotated(int x, int y, int pivotX, int pivotY, int width, int hei cosine = cosine * zoom >> 8; int sourceOffsetX = (pivotX << 16) + centerY * sine + centerX * cosine; int sourceoffsetY = (pivotY << 16) + centerY * cosine - centerX * sine; - int destinationOffset = x + y * Rasterizer.destinationWidth; + int destinationOffset = x + y * rasterizer.destinationWidth; for(y = 0; y < height; y++) { int i = destinationOffset; int offsetX = sourceOffsetX; @@ -967,7 +1043,7 @@ public void drawRotated(int x, int y, int pivotX, int pivotY, int width, int hei for(x = -width; x < 0; x++) { int i_166_ = pixels[(offsetX >> 16) + (offsetY >> 16) * imageWidth]; if(i_166_ != 0) - Rasterizer.destinationPixels[i++] = i_166_; + rasterizer.destinationPixels[i++] = i_166_; else i++; offsetX += cosine; @@ -975,7 +1051,7 @@ public void drawRotated(int x, int y, int pivotX, int pivotY, int width, int hei } sourceOffsetX += sine; sourceoffsetY += cosine; - destinationOffset += Rasterizer.destinationWidth; + destinationOffset += rasterizer.destinationWidth; } } catch(Exception exception) { /* empty */ diff --git a/src/main/java/org/runejs/client/cache/media/IndexedImage.java b/src/main/java/org/runejs/client/cache/media/IndexedImage.java index 60b01c8ac..3f59f8f86 100644 --- a/src/main/java/org/runejs/client/cache/media/IndexedImage.java +++ b/src/main/java/org/runejs/client/cache/media/IndexedImage.java @@ -3,6 +3,7 @@ import org.runejs.client.MovedStatics; import org.runejs.client.cache.CacheArchive; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; public class IndexedImage extends Rasterizer { public int imgWidth; @@ -71,6 +72,43 @@ public IndexedImage cloneImage() { return newImage; } + public void drawImage(RasterizerInstanced rasterizer, int x, int y) { + x += xDrawOffset; + y += yDrawOffset; + int rasterizerOffset = x + y * rasterizer.destinationWidth; + int pixelOffset = 0; + int imageHeight = imgHeight; + int imageWidth = imgWidth; + int deviation = rasterizer.destinationWidth - imageWidth; + int originalDeviation = 0; + if(y < rasterizer.viewportTop) { + int yOffset = rasterizer.viewportTop - y; + imageHeight -= yOffset; + y = rasterizer.viewportTop; + pixelOffset += yOffset * imageWidth; + rasterizerOffset += yOffset * rasterizer.destinationWidth; + } + if(y + imageHeight > rasterizer.viewportBottom) + imageHeight -= y + imageHeight - rasterizer.viewportBottom; + if(x < rasterizer.viewportLeft) { + int xOffset = rasterizer.viewportLeft - x; + imageWidth -= xOffset; + x = rasterizer.viewportLeft; + pixelOffset += xOffset; + rasterizerOffset += xOffset; + originalDeviation += xOffset; + deviation += xOffset; + } + if(x + imageWidth > rasterizer.viewportRight) { + int xOffset = x + imageWidth - rasterizer.viewportRight; + imageWidth -= xOffset; + originalDeviation += xOffset; + deviation += xOffset; + } + if(imageWidth > 0 && imageHeight > 0) + ImageRGB.shapeImageToPixels(imgPixels, rasterizer.destinationPixels, pixelOffset, rasterizerOffset, imageWidth, imageHeight, deviation, originalDeviation, palette); + } + public void drawImage(int x, int y) { x += xDrawOffset; y += yDrawOffset; diff --git a/src/main/java/org/runejs/client/cache/media/TypeFace.java b/src/main/java/org/runejs/client/cache/media/TypeFace.java index d8ee8e1a0..75aa9aa00 100644 --- a/src/main/java/org/runejs/client/cache/media/TypeFace.java +++ b/src/main/java/org/runejs/client/cache/media/TypeFace.java @@ -8,6 +8,7 @@ import org.runejs.client.cache.media.textUtils.TextTagNode; import org.runejs.client.cache.media.textUtils.TextTagQueue; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import java.awt.*; import java.util.Random; @@ -64,6 +65,8 @@ public class TypeFace extends Rasterizer { private int anInt2920; private TextColourQueue textcolour; + private RasterizerInstanced rasterizer; + public TypeFace(int[] arg0, int[] arg1, int[] arg2, int[] arg3, byte[][] arg4) { characterDefaultHeight = 0; random = new Random(); @@ -94,6 +97,12 @@ public TypeFace(int[] arg0, int[] arg1, int[] arg2, int[] arg3, byte[][] arg4) { anInt2919 = i_49_ - characterDefaultHeight; } + public void setRasterizer(RasterizerInstanced rasterizer) { + this.rasterizer = rasterizer; + } + + public RasterizerInstanced getRasterizer() { return this.rasterizer; } + public static TypeFace constructFont() { TypeFace class40_sub5_sub14_sub1 = new TypeFace(MovedStatics.anIntArray3111, MovedStatics.anIntArray456, MovedStatics.anIntArray3312, MovedStatics.anIntArray1972, MovedStatics.aByteArrayArray1370); MovedStatics.method569(); @@ -601,108 +610,117 @@ public int getColour(String code) { public void drawCharacter(int character, int x, int y, int width, int height, int colour) { - int rasterizerPixel = x + y * Rasterizer.destinationWidth; - int rasterizerPixelOffset = Rasterizer.destinationWidth - width; + int destinationWidth = getDestinationWidth(); + int[] viewportDimensions = getViewportDimensions(); + + int rasterizerPixel = x + y * destinationWidth; + int rasterizerPixelOffset = destinationWidth - width; int characterPixelOffset = 0; int characterPixel = 0; - if (y < Rasterizer.viewportTop) { - int offsetY = Rasterizer.viewportTop - y; + if (y < viewportDimensions[1]) { + int offsetY = viewportDimensions[1] - y; height -= offsetY; - y = Rasterizer.viewportTop; + y = viewportDimensions[1]; characterPixel += offsetY * width; - rasterizerPixel += offsetY * Rasterizer.destinationWidth; + rasterizerPixel += offsetY * destinationWidth; } - if (y + height > Rasterizer.viewportBottom) { - height -= y + height - Rasterizer.viewportBottom; + if (y + height > viewportDimensions[3]) { + height -= y + height - viewportDimensions[3]; } - if (x < Rasterizer.viewportLeft) { - int offsetX = Rasterizer.viewportLeft - x; + if (x < viewportDimensions[0]) { + int offsetX = viewportDimensions[0] - x; width -= offsetX; - x = Rasterizer.viewportLeft; + x = viewportDimensions[0]; characterPixel += offsetX; rasterizerPixel += offsetX; characterPixelOffset += offsetX; rasterizerPixelOffset += offsetX; } - if (x + width > Rasterizer.viewportRight) { - int endOffsetX = x + width - Rasterizer.viewportRight; + if (x + width > viewportDimensions[2]) { + int endOffsetX = x + width - viewportDimensions[2]; width -= endOffsetX; characterPixelOffset += endOffsetX; rasterizerPixelOffset += endOffsetX; } if (width > 0 && height > 0) { - drawCharacterPixels(characterPixels[character], Rasterizer.destinationPixels, characterPixel, rasterizerPixel, characterPixelOffset, rasterizerPixelOffset, width, height, colour); + drawCharacterPixels(characterPixels[character], getDestinationPixels(), characterPixel, rasterizerPixel, characterPixelOffset, rasterizerPixelOffset, width, height, colour); } } public void drawCharacterItalics(int character, int x, int y, int width, int height, int colour) { - int rasterizerPixel = x + y * Rasterizer.destinationWidth; - int rasterizerPixelOffset = Rasterizer.destinationWidth - width; + int destinationWidth = getDestinationWidth(); + int[] viewportDimensions = getViewportDimensions(); + + int rasterizerPixel = x + y * destinationWidth; + int rasterizerPixelOffset = destinationWidth - width; int characterPixelOffset = 0; int characterPixel = 0; - if (y < Rasterizer.viewportTop) { - int offsetY = Rasterizer.viewportTop - y; + if (y < viewportDimensions[1]) { + int offsetY = viewportDimensions[1] - y; height -= offsetY; - y = Rasterizer.viewportTop; + y = viewportDimensions[1]; characterPixel += offsetY * width; - rasterizerPixel += offsetY * Rasterizer.destinationWidth; + rasterizerPixel += offsetY * destinationWidth; } - if (y + height > Rasterizer.viewportBottom) { - height -= y + height - Rasterizer.viewportBottom; + if (y + height > viewportDimensions[3]) { + height -= y + height - viewportDimensions[3]; } - if (x < Rasterizer.viewportLeft) { - int offsetX = Rasterizer.viewportLeft - x; + if (x < viewportDimensions[0]) { + int offsetX = viewportDimensions[0] - x; width -= offsetX; - x = Rasterizer.viewportLeft; + x = viewportDimensions[0]; characterPixel += offsetX; rasterizerPixel += offsetX; characterPixelOffset += offsetX; rasterizerPixelOffset += offsetX; } - if (x + width > Rasterizer.viewportRight) { - int endOffsetX = x + width - Rasterizer.viewportRight; + if (x + width > viewportDimensions[2]) { + int endOffsetX = x + width - viewportDimensions[2]; width -= endOffsetX; characterPixelOffset += endOffsetX; rasterizerPixelOffset += endOffsetX; } if (width > 0 && height > 0) { - drawCharacterPixelsItalic(characterPixels[character], Rasterizer.destinationPixels, characterPixel, rasterizerPixel, characterPixelOffset, rasterizerPixelOffset, width, height, colour); + drawCharacterPixelsItalic(characterPixels[character], getDestinationPixels(), characterPixel, rasterizerPixel, characterPixelOffset, rasterizerPixelOffset, width, height, colour); } } - public void drawCharacterLegacy(byte[] pixels, int x, int y, int width, int height, int colour) { - int rasterizerPixel = x + y * Rasterizer.destinationWidth; - int remainingWidth = Rasterizer.destinationWidth - width; + private void drawCharacterLegacy(byte[] pixels, int x, int y, int width, int height, int colour) { + int destinationWidth = getDestinationWidth(); + int[] viewportDimensions = getViewportDimensions(); + + int rasterizerPixel = x + y * destinationWidth; + int remainingWidth = destinationWidth - width; int characterPixelOffset = 0; int characterPixel = 0; - if (y < Rasterizer.viewportTop) { - int offsetY = Rasterizer.viewportTop - y; + if (y < viewportDimensions[1]) { + int offsetY = viewportDimensions[1] - y; height -= offsetY; - y = Rasterizer.viewportTop; + y = viewportDimensions[1]; characterPixel += offsetY * width; - rasterizerPixel += offsetY * Rasterizer.destinationWidth; + rasterizerPixel += offsetY * destinationWidth; } - if (y + height >= Rasterizer.viewportBottom) - height -= y + height - Rasterizer.viewportBottom + 1; - if (x < Rasterizer.viewportLeft) { - int offsetX = Rasterizer.viewportLeft - x; + if (y + height > viewportDimensions[3]) + height -= y + height - viewportDimensions[3]; + if (x < viewportDimensions[0]) { + int offsetX = viewportDimensions[0] - x; width -= offsetX; - x = Rasterizer.viewportLeft; + x = viewportDimensions[0]; characterPixel += offsetX; rasterizerPixel += offsetX; characterPixelOffset += offsetX; remainingWidth += offsetX; } - if (x + width >= Rasterizer.viewportRight) { - int endOffsetX = x + width - Rasterizer.viewportRight + 1; + if (x + width > viewportDimensions[2]) { + int endOffsetX = x + width - viewportDimensions[2]; width -= endOffsetX; characterPixelOffset += endOffsetX; remainingWidth += endOffsetX; } if (width > 0 && height > 0) { - drawCharacterPixels(pixels, Rasterizer.destinationPixels, characterPixel, rasterizerPixel, characterPixelOffset, remainingWidth, width, height, colour); + drawCharacterPixels(pixels, getDestinationPixels(), characterPixel, rasterizerPixel, characterPixelOffset, remainingWidth, width, height, colour); } } @@ -967,20 +985,34 @@ public final void drawBasicStringXYMods(String string, int drawX, int drawY, int int charWidth = characterScreenWidths[character]; if (strikethroughColor != -1) { if (opacity > 255) { - Rasterizer.drawHorizontalLine(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); - } else { - Rasterizer.drawHorizontalLineAlpha(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor, opacity); + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } else { + rasterizer.drawHorizontalLine(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } + } else { + if (rasterizer == null) { + Rasterizer.drawHorizontalLineAlpha(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor, opacity); + } else { + rasterizer.drawHorizontalLineAlpha(drawX, drawY + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor, opacity); + } } } if (underlineColor != -1) { if (opacity > 255) { - Rasterizer.drawHorizontalLine(drawX, drawY + characterDefaultHeight, charWidth, underlineColor); - + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(drawX, drawY + characterDefaultHeight, charWidth, underlineColor); + } else { + rasterizer.drawHorizontalLine(drawX, drawY + characterDefaultHeight, charWidth, underlineColor); + } } else { - - Rasterizer.drawHorizontalLineAlpha(drawX, drawY + characterDefaultHeight, charWidth, underlineColor, opacity); + if (rasterizer == null) { + Rasterizer.drawHorizontalLineAlpha(drawX, drawY + characterDefaultHeight, charWidth, underlineColor, opacity); + } else { + rasterizer.drawHorizontalLineAlpha(drawX, drawY + characterDefaultHeight, charWidth, underlineColor, opacity); + } } } @@ -1178,10 +1210,18 @@ public void drawBasicString(String string, int x, int y) { int charWidth = characterScreenWidths[c]; if (strikethroughColor != -1) { - Rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } else { + rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } } if (underlineColor != -1) { - Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + } else { + rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + } } x += charWidth; var5 = c; @@ -1262,10 +1302,18 @@ public void drawBasicStringLegacy(String string, int x, int y) { int charWidth = characterScreenWidths[c]; if (strikethroughColor != -1) { - Rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } else { + rasterizer.drawHorizontalLine(x, y + (int) ((double) characterDefaultHeight * 0.7D), charWidth, strikethroughColor); + } } if (underlineColor != -1) { - Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + if (rasterizer == null) { + Rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + } else { + rasterizer.drawHorizontalLine(x, y + characterDefaultHeight + 1, charWidth, underlineColor); + } } x += charWidth; var5 = c; @@ -1284,74 +1332,107 @@ public void drawCharacterAlphaItalics(int character, int x, int y, int width, in } public void drawAlphaCharacter(byte[] characterPixels, int x, int y, int width, int height, int colour, int alpha) { - int rasterizerPixel = x + y * Rasterizer.destinationWidth; - int rasterizerPixelOffset = Rasterizer.destinationWidth - width; + int destinationWidth = getDestinationWidth(); + int[] viewportDimensions = getViewportDimensions(); + + int rasterizerPixel = x + y * destinationWidth; + int rasterizerPixelOffset = destinationWidth - width; int characterPixelOffset = 0; int characterPixel = 0; - if (y < Rasterizer.viewportTop) { - int yOffset = Rasterizer.viewportTop - y; + if (y < viewportDimensions[1]) { + int yOffset = viewportDimensions[1] - y; height -= yOffset; - y = Rasterizer.viewportTop; + y = viewportDimensions[1]; characterPixel += yOffset * width; - rasterizerPixel += yOffset * Rasterizer.destinationWidth; + rasterizerPixel += yOffset * destinationWidth; } - if (y + height >= Rasterizer.viewportBottom) - height -= y + height - Rasterizer.viewportBottom + 1; - if (x < Rasterizer.viewportLeft) { - int xOffset = Rasterizer.viewportLeft - x; + if (y + height >= viewportDimensions[3]) + height -= y + height - viewportDimensions[3] + 1; + if (x < viewportDimensions[0]) { + int xOffset = viewportDimensions[0] - x; width -= xOffset; - x = Rasterizer.viewportLeft; + x = viewportDimensions[0]; characterPixel += xOffset; rasterizerPixel += xOffset; characterPixelOffset += xOffset; rasterizerPixelOffset += xOffset; } - if (x + width >= Rasterizer.viewportRight) { - int widthoffset = x + width - Rasterizer.viewportRight + 1; + if (x + width >= viewportDimensions[2]) { + int widthoffset = x + width - viewportDimensions[2] + 1; width -= widthoffset; characterPixelOffset += widthoffset; rasterizerPixelOffset += widthoffset; } if (width > 0 && height > 0) { - drawCharacterPixelsAlpha(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, Rasterizer.destinationPixels, colour, height, width, characterPixels); + drawCharacterPixelsAlpha(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, getDestinationPixels(), colour, height, width, characterPixels); + } + } + + private int getDestinationWidth() { + if (rasterizer == null) { + return Rasterizer.destinationWidth; + } else { + return rasterizer.destinationWidth; + } + } + + private int[] getViewportDimensions() { + int[] output = new int[4]; + + if (rasterizer == null) { + Rasterizer.getViewportDimensions(output); + } else { + rasterizer.getViewportDimensions(output); + } + + return output; + } + + private int[] getDestinationPixels() { + if (rasterizer == null) { + return Rasterizer.destinationPixels; + } else { + return rasterizer.destinationPixels; } } public void drawAlphaCharacterItalics(byte[] characterPixels, int x, int y, int width, int height, int colour, int alpha) { - int rasterizerPixel = x + y * Rasterizer.destinationWidth; - int rasterizerPixelOffset = Rasterizer.destinationWidth - width; + int destinationWidth = getDestinationWidth(); + int[] viewportDimensions = getViewportDimensions(); + + int rasterizerPixel = x + y * destinationWidth; + int rasterizerPixelOffset = destinationWidth - width; int characterPixelOffset = 0; int characterPixel = 0; - if (y < Rasterizer.viewportTop) { - int yOffset = Rasterizer.viewportTop - y; + if (y < viewportDimensions[1]) { + int yOffset = viewportDimensions[1] - y; height -= yOffset; - y = Rasterizer.viewportTop; + y = viewportDimensions[1]; characterPixel += yOffset * width; - rasterizerPixel += yOffset * Rasterizer.destinationWidth; + rasterizerPixel += yOffset * destinationWidth; } - if (y + height >= Rasterizer.viewportBottom) - height -= y + height - Rasterizer.viewportBottom + 1; - if (x < Rasterizer.viewportLeft) { - int xOffset = Rasterizer.viewportLeft - x; + if (y + height >= viewportDimensions[3]) + height -= y + height - viewportDimensions[3] + 1; + if (x < viewportDimensions[0]) { + int xOffset = viewportDimensions[0] - x; width -= xOffset; - x = Rasterizer.viewportLeft; + x = viewportDimensions[0]; characterPixel += xOffset; rasterizerPixel += xOffset; characterPixelOffset += xOffset; rasterizerPixelOffset += xOffset; } - if (x + width >= Rasterizer.viewportRight) { - int widthoffset = x + width - Rasterizer.viewportRight + 1; + if (x + width >= viewportDimensions[2]) { + int widthoffset = x + width - viewportDimensions[2] + 1; width -= widthoffset; characterPixelOffset += widthoffset; rasterizerPixelOffset += widthoffset; } if (width > 0 && height > 0) { - drawCharacterPixelsAlphaItalics(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, Rasterizer.destinationPixels, colour, height, width, characterPixels); + drawCharacterPixelsAlphaItalics(characterPixel, rasterizerPixelOffset, characterPixelOffset, rasterizerPixel, alpha, getDestinationPixels(), colour, height, width, characterPixels); } } - public void drawCharacterPixelsAlpha(int characterPixel, int rasterizerPixelOffset, int characterPixelOffset, int rasterizerPixel, int alpha, int[] rasterizerPixels, int colour, int height, int width, byte[] characterPixels) { colour = ((colour & 0xff00ff) * alpha & 0xff00ff00) + ((colour & 0xff00) * alpha & 0xff0000) >> 8; alpha = 256 - alpha; diff --git a/src/main/java/org/runejs/client/cache/media/gameInterface/GameInterface.java b/src/main/java/org/runejs/client/cache/media/gameInterface/GameInterface.java index 319a01b7b..f671ac034 100644 --- a/src/main/java/org/runejs/client/cache/media/gameInterface/GameInterface.java +++ b/src/main/java/org/runejs/client/cache/media/gameInterface/GameInterface.java @@ -17,6 +17,7 @@ import org.runejs.client.language.English; import org.runejs.client.language.Native; import org.runejs.client.media.Rasterizer; +import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.renderable.Model; import org.runejs.client.media.renderable.actor.Npc; import org.runejs.client.media.renderable.actor.Pathfinding; @@ -453,6 +454,25 @@ else if(type == 620) { } } + public static void drawScrollBar(RasterizerInstanced rasterizer, int x, int y, int height, int scrollPosition, int scrollMaximum) { + int length = (-32 + height) * height / scrollMaximum; + MovedStatics.scrollbarArrowImages[0].drawImage(rasterizer, x, y); + MovedStatics.scrollbarArrowImages[1].drawImage(rasterizer, x, y - (-height + 16)); + rasterizer.drawFilledRectangle(x, y + 16, 16, height + -32, SCROLLBAR_COLOR_BACKGROUND); + if(length < 8) + length = 8; + int scrollCurrent = (-32 + height - length) * scrollPosition / (-height + scrollMaximum); + rasterizer.drawFilledRectangle(x, 16 + y + scrollCurrent, 16, length, SCROLLBAR_COLOR_CHIP_FILL); + rasterizer.drawVerticalLine(x, 16 + y + scrollCurrent, length, SCROLLBAR_COLOR_CHIP_EDGE_LIGHT); + rasterizer.drawVerticalLine(1 + x, scrollCurrent + y + 16, length, SCROLLBAR_COLOR_CHIP_EDGE_LIGHT); + rasterizer.drawHorizontalLine(x, scrollCurrent + y + 16, 16, SCROLLBAR_COLOR_CHIP_EDGE_LIGHT); + rasterizer.drawHorizontalLine(x, 17 + y + scrollCurrent, 16, SCROLLBAR_COLOR_CHIP_EDGE_LIGHT); + rasterizer.drawVerticalLine(x + 15, y + 16 + scrollCurrent, length, SCROLLBAR_COLOR_CHIP_EDGE_DARK); + rasterizer.drawVerticalLine(x + 14, scrollCurrent + 17 + y, length - 1, SCROLLBAR_COLOR_CHIP_EDGE_DARK); + rasterizer.drawHorizontalLine(x, length + scrollCurrent + 15 + y, 16, SCROLLBAR_COLOR_CHIP_EDGE_DARK); + rasterizer.drawHorizontalLine(x + 1, 14 + y + scrollCurrent + length, 15, SCROLLBAR_COLOR_CHIP_EDGE_DARK); + } + public static void drawScrollBar(int x, int y, int height, int scrollPosition, int scrollMaximum) { int length = (-32 + height) * height / scrollMaximum; MovedStatics.scrollbarArrowImages[0].drawImage(x, y); diff --git a/src/main/java/org/runejs/client/frame/ChatBox.java b/src/main/java/org/runejs/client/frame/ChatBox.java index 212021f28..fecdfbe34 100644 --- a/src/main/java/org/runejs/client/frame/ChatBox.java +++ b/src/main/java/org/runejs/client/frame/ChatBox.java @@ -7,8 +7,8 @@ import org.runejs.client.input.MouseHandler; import org.runejs.client.language.English; import org.runejs.client.language.Native; -import org.runejs.client.media.Rasterizer; import org.runejs.client.media.Rasterizer3D; +import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.renderable.actor.Player; import java.awt.*; @@ -37,53 +37,75 @@ public class ChatBox { public static String chatboxInput = ""; public static String chatMessage = ""; + public static RasterizerInstanced rasterizer; + private static char[] VALID_CHARACTERS = {' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[', ']', '_', '{', '}', '/', '|'}; + public static void renderChatbox() { MovedStatics.showChatPanelRedrawnText = true; method305(); if(messagePromptRaised) { - TypeFace.fontBold.drawStringLeft(Native.enterPlayerNameHeader, 239, 40, 0); - TypeFace.fontBold.drawStringLeft(chatMessage + "*", 239, 60, 128); + TypeFace font = TypeFace.fontBold; + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); + font.drawStringLeft(Native.enterPlayerNameHeader, 239, 40, 0); + font.drawStringLeft(chatMessage + "*", 239, 60, 128); + font.setRasterizer(oldRasterizer); } else if(inputType == 1) { - TypeFace.fontBold.drawStringLeft(English.enterAmount, 239, 40, 0); - TypeFace.fontBold.drawStringLeft(inputMessage + "*", 239, 60, 128); + TypeFace font = TypeFace.fontBold; + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); + font.drawStringLeft(English.enterAmount, 239, 40, 0); + font.drawStringLeft(inputMessage + "*", 239, 60, 128); + font.setRasterizer(oldRasterizer); } else if(inputType == 2) { - TypeFace.fontBold.drawStringLeft(English.enterName, 239, 40, 0); - TypeFace.fontBold.drawStringLeft(inputMessage + "*", 239, 60, 128); + TypeFace font = TypeFace.fontBold; + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); + font.drawStringLeft(English.enterName, 239, 40, 0); + font.drawStringLeft(inputMessage + "*", 239, 60, 128); + font.setRasterizer(oldRasterizer); } else if(inputType == 3) { if(!inputMessage.equals(lastItemSearchInput)) { itemSearch(inputMessage); lastItemSearchInput = inputMessage; } TypeFace font = MovedStatics.fontNormal; - Rasterizer.setBounds(0, 0, 463, 77); + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); for(int index = 0; index < itemSearchResultCount; index++) { int y = index * 14 + 18 - itemSearchScroll; if(y > 0 && y < 110) font.drawStringLeft(itemSearchResultNames[index], 239, y, 0); } - Rasterizer.resetBounds(); if(itemSearchResultCount > 5) - GameInterface.drawScrollBar(463, 0, 77, itemSearchScroll, 7 + 14 * itemSearchResultCount); + GameInterface.drawScrollBar(rasterizer, 463, 0, 77, itemSearchScroll, 7 + 14 * itemSearchResultCount); if(inputMessage.length() != 0) { if(itemSearchResultCount == 0) TypeFace.fontBold.drawStringLeft(English.noMatchingObjectsFound, 239, 40, 0); } else TypeFace.fontBold.drawStringLeft(English.enterObjectName, 239, 40, 255); font.drawStringLeft(inputMessage + "*", 239, 90, 0); - Rasterizer.drawHorizontalLine(0, 77, 479, 0); + rasterizer.drawHorizontalLine(0, 77, 479, 0); + font.setRasterizer(oldRasterizer); } else if(Native.clickToContinueString != null) { - TypeFace.fontBold.drawStringLeft(Native.clickToContinueString, 239, 40, 0); - TypeFace.fontBold.drawStringLeft(English.clickToContinue, 239, 60, 128); + TypeFace font = TypeFace.fontBold; + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); + font.drawStringLeft(Native.clickToContinueString, 239, 40, 0); + font.drawStringLeft(English.clickToContinue, 239, 60, 128); + font.setRasterizer(oldRasterizer); } else if(GameInterface.chatboxInterfaceId != -1) { redrawChatbox = !Game.drawParentInterface(2, 0, 0, 479, 96, GameInterface.chatboxInterfaceId); } else if(dialogueId == -1) { int line = 0; - TypeFace typeFace = MovedStatics.fontNormal; - Rasterizer.setBounds(0, 0, 463, 77); + TypeFace font = MovedStatics.fontNormal; + RasterizerInstanced oldRasterizer = font.getRasterizer(); + font.setRasterizer(rasterizer); + rasterizer.setBounds(0, 0, 77, 463); for(int i = 0; i < 100; i++) { if(chatMessages[i] != null) { int type = chatTypes[i]; @@ -101,22 +123,22 @@ public static void renderChatbox() { if(type == 0) { line++; if(y > 0 && y < 110) - typeFace.drawString(chatMessages[i], 4, y, 0); + font.drawString(chatMessages[i], 4, y, 0); } if((type == 1 || type == 2) && (type == 1 || publicChatMode == 0 || publicChatMode == 1 && Player.hasFriend(name))) { if(y > 0 && y < 110) { int x = 4; if(privelege == 1) { - MovedStatics.moderatorIcon[0].drawImage(x, y + -12); + MovedStatics.moderatorIcon[0].drawImage(rasterizer, x, y + -12); x += 14; } if(privelege == 2) { - MovedStatics.moderatorIcon[1].drawImage(x, y - 12); + MovedStatics.moderatorIcon[1].drawImage(rasterizer, x, y - 12); x += 14; } - typeFace.drawString(name+ Native.colon, x, y, 0); - x += 8 + typeFace.getStringWidth(name); - typeFace.drawString(chatMessages[i], x, y, 255); + font.drawString(name+ Native.colon, x, y, 0); + x += 8 + font.getStringWidth(name); + font.drawString(chatMessages[i], x, y, 255); } line++; } @@ -124,59 +146,60 @@ public static void renderChatbox() { line++; if(y > 0 && y < 110) { int i_13_ = 4; - typeFace.drawString(English.from, i_13_, y, 0); - i_13_ += typeFace.getStringWidth(English.from); - i_13_ += typeFace.method689(32); + font.drawString(English.from, i_13_, y, 0); + i_13_ += font.getStringWidth(English.from); + i_13_ += font.method689(32); if(privelege == 1) { - MovedStatics.moderatorIcon[0].drawImage(i_13_, y + -12); + MovedStatics.moderatorIcon[0].drawImage(rasterizer, i_13_, y + -12); i_13_ += 14; } if(privelege == 2) { - MovedStatics.moderatorIcon[1].drawImage(i_13_, y - 12); + MovedStatics.moderatorIcon[1].drawImage(rasterizer, i_13_, y - 12); i_13_ += 14; } - typeFace.drawString(name + Native.colon, i_13_, y, 0); - i_13_ += 8 + typeFace.getStringWidth(name); - typeFace.drawString(chatMessages[i], i_13_, y, 8388608); + font.drawString(name + Native.colon, i_13_, y, 0); + i_13_ += 8 + font.getStringWidth(name); + font.drawString(chatMessages[i], i_13_, y, 8388608); } } if(type == 4 && (tradeMode == 0 || tradeMode == 1 && Player.hasFriend(name))) { line++; if(y > 0 && y < 110) - typeFace.drawString(name + " " + chatMessages[i], 4, y, 8388736); + font.drawString(name + " " + chatMessages[i], 4, y, 8388736); } if(type == 5 && splitPrivateChat == 0 && privateChatMode < 2) { if(y > 0 && y < 110) - typeFace.drawString(chatMessages[i], 4, y, 8388608); + font.drawString(chatMessages[i], 4, y, 8388608); line++; } if(type == 6 && splitPrivateChat == 0 && privateChatMode < 2) { if(y > 0 && y < 110) { - typeFace.drawString(English.to + Native.whitespace_b + name + Native.colon, 4, y, 0); - typeFace.drawString(chatMessages[i], typeFace.getStringWidth(English.to + Native.whitespace_b + name) + 12, y, 8388608); + font.drawString(English.to + Native.whitespace_b + name + Native.colon, 4, y, 0); + font.drawString(chatMessages[i], font.getStringWidth(English.to + Native.whitespace_b + name) + 12, y, 8388608); } line++; } if(type == 8 && (tradeMode == 0 || tradeMode == 1 && Player.hasFriend(name))) { line++; if(y > 0 && y < 110) - typeFace.drawString(name + Native.whitespace_b + chatMessages[i], 4, y, 8270336); + font.drawString(name + Native.whitespace_b + chatMessages[i], 4, y, 8270336); } } } - Rasterizer.resetBounds(); + rasterizer.resetBounds(); chatboxScrollMax = line * 14 + 7; if(chatboxScrollMax < 78) chatboxScrollMax = 78; - GameInterface.drawScrollBar(463, 0, 77, chatboxScrollMax - chatboxScroll - 77, chatboxScrollMax); + GameInterface.drawScrollBar(rasterizer, 463, 0, 77, chatboxScrollMax - chatboxScroll - 77, chatboxScrollMax); String name; if(Player.localPlayer != null && Player.localPlayer.playerName != null) name = Player.localPlayer.playerName; else name = Native.username.toString(); - typeFace.drawString(name + Native.colon, 4, 90, 0); - typeFace.drawBasicStringLegacy("@blu@" + chatboxInput + Native.asterisk, typeFace.getStringWidth(name + Native.COLON_CHARACTER) + 6, 90); - Rasterizer.drawHorizontalLine(0, 77, 479, 0); + font.drawString(name + Native.colon, 4, 90, 0); + font.drawBasicStringLegacy("@blu@" + chatboxInput + Native.asterisk, font.getStringWidth(name + Native.COLON_CHARACTER) + 6, 90); + rasterizer.drawHorizontalLine(0, 77, 479, 0); + font.setRasterizer(oldRasterizer); } else { boolean bool = Game.drawParentInterface(3, 0, 0, 479, 96, dialogueId); if(!bool) @@ -289,9 +312,9 @@ public static void drawChatBoxGraphics() { public static void method305() { // if(ScreenController.frameMode == ScreenMode.FIXED){ - chatBoxImageProducer.prepareRasterizer(); + chatBoxImageProducer.prepareRasterizer(rasterizer); // } - MovedStatics.chatboxBackgroundImage.drawImage(0, 0); + MovedStatics.chatboxBackgroundImage.drawImage(rasterizer, 0, 0); MovedStatics.chatboxLineOffsets = Rasterizer3D.setLineOffsets(MovedStatics.chatboxLineOffsets); } } diff --git a/src/main/java/org/runejs/client/frame/ChatBoxRenderer.java b/src/main/java/org/runejs/client/frame/ChatBoxRenderer.java new file mode 100644 index 000000000..f6769e86d --- /dev/null +++ b/src/main/java/org/runejs/client/frame/ChatBoxRenderer.java @@ -0,0 +1,29 @@ +package org.runejs.client.frame; + +import org.runejs.client.MovedStatics; + +/** + * Renders the chat box. + */ +public class ChatBoxRenderer extends FramePieceRenderer { + public ChatBoxRenderer() { + super( + new FramePieceAnchor( + FramePieceAnchor.Anchor.BOTTOM | FramePieceAnchor.Anchor.LEFT, + 0, + -22 + ), + 516, + 184 + ); + } + + public void render() { + copyProducer(ChatBox.chatBoxImageProducer, 17, 16); + copyProducer(MovedStatics.chatModes, 0, 112); + copyProducerCutOff(MovedStatics.tabBottom, 496, 125, 20, MovedStatics.tabBottom.height, 0, 0); + copyProducer(MovedStatics.chatboxRight, 0, 16); + copyProducerCutOff(MovedStatics.chatboxTop, 0, 0, MovedStatics.chatboxTop.width - 37, MovedStatics.chatboxTop.height - 3, 0, 3); + copyProducerCutOff(MovedStatics.tabPieceLowerRight, 496, 16, 20, MovedStatics.tabPieceLowerRight.height, 0, 0); + } +} diff --git a/src/main/java/org/runejs/client/frame/DebugTools.java b/src/main/java/org/runejs/client/frame/DebugTools.java index c54725011..3b9135140 100644 --- a/src/main/java/org/runejs/client/frame/DebugTools.java +++ b/src/main/java/org/runejs/client/frame/DebugTools.java @@ -3,7 +3,6 @@ import org.runejs.client.Landscape; import org.runejs.client.MovedStatics; import org.runejs.client.cache.media.TypeFace; -import org.runejs.client.media.Rasterizer; import org.runejs.client.media.renderable.actor.Player; import org.runejs.client.scene.Point2d; @@ -31,7 +30,7 @@ public static void drawWalkPath() { Point2d nextPos = MovedStatics.getProjectedScreenPosition(0, tileY * 128 + 64, tileX * 128 + 64); if (lastTilePos != null && nextPos != null) { - Rasterizer.drawDiagonalLine(lastTilePos.x, lastTilePos.y, nextPos.x, nextPos.y, 0x00FFAC); + ScreenController.rasterizer.drawDiagonalLine(lastTilePos.x, lastTilePos.y, nextPos.x, nextPos.y, 0x00FFAC); } // handle final walkpath label separately to avoid clipping issues @@ -46,13 +45,13 @@ public static void drawWalkPath() { } if (pathStartPos != null) { - Rasterizer.drawCircle(pathStartPos.x, pathStartPos.y, 2, 0xE055DE); + ScreenController.rasterizer.drawCircle(pathStartPos.x, pathStartPos.y, 2, 0xE055DE); TypeFace.fontSmall.drawStringLeft(walkpathX[0] + "," + walkpathY[0], pathStartPos.x, pathStartPos.y + 1, 0); TypeFace.fontSmall.drawStringLeft(walkpathX[0] + "," + walkpathY[0], pathStartPos.x, pathStartPos.y, 0x00AAFF); } if (pathFinishPos != null) { - Rasterizer.drawCircle(pathFinishPos.x, pathFinishPos.y, 4, 0xE055DE); + ScreenController.rasterizer.drawCircle(pathFinishPos.x, pathFinishPos.y, 4, 0xE055DE); TypeFace.fontSmall.drawStringLeft(walkpathX[walkpathX.length - 1] + "," + walkpathY[walkpathY.length - 1], pathFinishPos.x, pathFinishPos.y + 1, 0); TypeFace.fontSmall.drawStringLeft(walkpathX[walkpathX.length - 1] + "," + walkpathY[walkpathY.length - 1], pathFinishPos.x, pathFinishPos.y, 0x00AAFF); } @@ -96,40 +95,40 @@ public static void drawClipping() { if ((data & 0x2) == 0x2) { // north if (posNE != null && posNW != null) { - Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor); } } if ((data & 0x8) == 0x8) { // east if (posSE != null && posNE != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor); } } if ((data & 0x20) == 0x20) { // south if (posSE != null && posSW != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor); } } if ((data & 0x80) == 0x80) { // west if (posSW != null && posNW != null) { - Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor); } } if ((data & 0x100) == 0x100) { // total block if (posNE != null && posNW != null) { - Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNW.x, posNW.y, blockWalkColor); } if (posSE != null && posNE != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posNE.x, posNE.y, blockWalkColor); } if (posSE != null && posSW != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSW.x, posSW.y, blockWalkColor); } if (posSW != null && posNW != null) { - Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor); + ScreenController.rasterizer.drawDiagonalLine(posSW.x, posSW.y, posNW.x, posNW.y, blockWalkColor); } } @@ -138,79 +137,79 @@ public static void drawClipping() { if ((data & 0x400) == 0x400) { // north (projectile) if (posNEA != null && posNWA != null) { - Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor); if (posNE != null) { - Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); } if (posNW != null) { - Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); } } } if ((data & 0x1000) == 0x1000) { // east (projectile) if (posSEA != null && posNEA != null) { - Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor); } } if ((data & 0x4000) == 0x4000) { // south (projectile) if (posSEA != null && posSWA != null) { - Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor); } } if ((data & 0x10000) == 0x10000) { // west (projectile) if (posSWA != null && posNWA != null) { - Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor); } } if ((data & 0x20000) == 0x20000) { // total block (projectile) if (posNEA != null && posNWA != null) { - Rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNEA.x, posNEA.y, posNWA.x, posNWA.y, blockProjectileColor); if (posNE != null) { - Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); } if (posNW != null) { - Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); } } if (posSEA != null && posNEA != null) { - Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posNEA.x, posNEA.y, blockProjectileColor); if (posSE != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor); } if (posNE != null) { - Rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNE.x, posNE.y, posNEA.x, posNEA.y, blockProjectileColor); } } if (posSEA != null && posSWA != null) { - Rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSEA.x, posSEA.y, posSWA.x, posSWA.y, blockProjectileColor); if (posSE != null) { - Rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSE.x, posSE.y, posSEA.x, posSEA.y, blockProjectileColor); } if (posSW != null) { - Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor); } } if (posSWA != null && posNWA != null) { - Rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSWA.x, posSWA.y, posNWA.x, posNWA.y, blockProjectileColor); if (posSW != null) { - Rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posSW.x, posSW.y, posSWA.x, posSWA.y, blockProjectileColor); } if (posNW != null) { - Rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); + ScreenController.rasterizer.drawDiagonalLine(posNW.x, posNW.y, posNWA.x, posNWA.y, blockProjectileColor); } } } diff --git a/src/main/java/org/runejs/client/frame/FixedFrameRenderer.java b/src/main/java/org/runejs/client/frame/FixedFrameRenderer.java new file mode 100644 index 000000000..0fce74b82 --- /dev/null +++ b/src/main/java/org/runejs/client/frame/FixedFrameRenderer.java @@ -0,0 +1,76 @@ +package org.runejs.client.frame; + +import org.runejs.client.frame.tab.TabProducer; +import org.runejs.client.media.RasterizerInstanced; + +public class FixedFrameRenderer implements FrameRenderer { + public final TabProducer tabProducer = new TabProducer(); + + private int drawWidth; + private int drawHeight; + + @Override + public void setDrawSize(int drawWidth, int drawHeight) { + this.drawWidth = drawWidth; + this.drawHeight = drawHeight; + } + + @Override + public boolean isCoordinatesInChatArea(int x, int y) { + return x > 17 && y > 357 && x < 496 && y < 453; + } + + @Override + public boolean isCoordinatesIn3dScreen(int x, int y) { + return x > 4 && y > 4 && x < 516 && y < 338; + } + + @Override + public boolean isCoordinatesInMinimapArea(int x, int y) { + return x > 575 && y < 156; + } + + @Override + public boolean isCoordinatesInTabArea(int x, int y) { + return x > 553 && y > 205 && x < 743 && y < 466; + } + + @Override + public boolean isCoordinatesInExtendedTabArea(int x, int y) { + int[] top = tabProducer.getTopBarCoordSize(drawWidth - 241, drawHeight - (334)); + int[] bottom = tabProducer.getBottomBarCoordSize(drawWidth - 241, drawHeight - (334)); + if(x > top[0] && x < top[0]+top[2] && y > top[1] && y < top[1]+top[3]) { + return true; + } else return x > bottom[0] && x < bottom[0] + bottom[2] && y > bottom[1] && y < bottom[1] + bottom[3]; + } + + @Override + public boolean isCoordinatesInExtendedChatArea(int x, int y) { + return x > 0 && y > drawHeight - 184 && x < 516; + } + + @Override + public TabProducer getTabProducer() { + return tabProducer; + } + + @Override + public void draw(int mouseX, int mouseY, boolean debugView) { + + } + + @Override + public void setRasterizer(RasterizerInstanced rasterizer) { + + } + + @Override + public void stop() { + + } + + @Override + public void run() { + + } +} diff --git a/src/main/java/org/runejs/client/frame/FramePieceAnchor.java b/src/main/java/org/runejs/client/frame/FramePieceAnchor.java new file mode 100644 index 000000000..5f482c434 --- /dev/null +++ b/src/main/java/org/runejs/client/frame/FramePieceAnchor.java @@ -0,0 +1,68 @@ +package org.runejs.client.frame; + +/** + * Represents an anchor for a {@link FramePieceRenderer}, + * i.e. the position of the piece relative to the overall window. + */ +public class FramePieceAnchor { + /** + * The different anchor types. + * + * These are bit flags, so they can be combined. + */ + public static class Anchor { + public static final int LEFT = 0b0001; + public static final int RIGHT = 0b0010; + public static final int TOP = 0b0100; + public static final int BOTTOM = 0b1000; + } + + /** + * The anchor type, composed of the {@link Anchor} flags. + */ + public final int anchor; + + /** + * The margin from the anchor in the X direction. + */ + public final int marginX; + + /** + * The margin from the anchor in the Y direction. + */ + public final int marginY; + + public FramePieceAnchor(int anchor, int marginX, int marginY) { + this.anchor = anchor; + this.marginX = marginX; + this.marginY = marginY; + } + + /** + * Gets the position of the piece relative to the overall window. + * + * @param drawWidth The width of the window. + * @param drawHeight The height of the window. + * @param sizeX The width of the piece. + * @param sizeY The height of the piece. + * @return The position of the piece. + */ + public int[] getPosition(int drawWidth, int drawHeight, int sizeX, int sizeY) { + int x = 0; + int y = 0; + + if ((anchor & Anchor.LEFT) == Anchor.LEFT) { + x = marginX; + } else if ((anchor & Anchor.RIGHT) == Anchor.RIGHT) { + x = drawWidth - sizeX - marginX; + } + + if ((anchor & Anchor.TOP) == Anchor.TOP) { + y = marginY; + } else if ((anchor & Anchor.BOTTOM) == Anchor.BOTTOM) { + y = drawHeight - sizeY - marginY; + } + + return new int[]{x, y}; + } +} diff --git a/src/main/java/org/runejs/client/frame/FramePieceRenderer.java b/src/main/java/org/runejs/client/frame/FramePieceRenderer.java index 57942d714..425e002e4 100644 --- a/src/main/java/org/runejs/client/frame/FramePieceRenderer.java +++ b/src/main/java/org/runejs/client/frame/FramePieceRenderer.java @@ -1,117 +1,69 @@ package org.runejs.client.frame; -import org.runejs.client.cache.media.ImageRGB; +import org.runejs.client.Game; +import org.runejs.client.MovedStatics; +import org.runejs.client.ProducingGraphicsBuffer; import org.runejs.client.media.RasterizerInstanced; -public class FramePieceRenderer { - public RasterizerInstanced rasterizerInstanced; +public abstract class FramePieceRenderer { + protected RasterizerInstanced rasterizerInstanced; - public void shapeImageToPixels(ImageRGB image, int x, int y, int width, int height, int arg4, int arg5, int k1, int zoom, int[] arg8, int[] arg9) { - try { - int centerX = -width / 2; - int centerY = -height / 2; - int sine = (int) (Math.sin((double) k1 / 326.11) * 65536.0); - int cosine = (int) (Math.cos((double) k1 / 326.11) * 65536.0); - sine = sine * zoom >> 8; - cosine = cosine * zoom >> 8; - int i_125_ = (arg4 << 16) + centerY * sine + centerX * cosine; - int i_126_ = (arg5 << 16) + centerY * cosine - centerX * sine; - int destinationOffset = x + y * rasterizerInstanced.destinationWidth; + public final FramePieceAnchor anchor; + public final int width; + public final int height; - for(y = 0; y < height; y++) { - int i_128_ = arg8[y]; - int i_129_ = destinationOffset + i_128_; - int i_130_ = i_125_ + cosine * i_128_; - int i_131_ = i_126_ - sine * i_128_; - for(x = -arg9[y]; x < 0; x++) { - int pixelToGet = (i_130_ >> 16) + (i_131_ >> 16) * image.imageWidth; - int colour = 0; - if(!(image.pixels.length < pixelToGet || pixelToGet < 0)){ - colour = image.pixels[pixelToGet]; - } - rasterizerInstanced.destinationPixels[i_129_++] = colour; - i_130_ += cosine; - i_131_ -= sine; - } - i_125_ += sine; - i_126_ += cosine; - destinationOffset += rasterizerInstanced.destinationWidth; - } - } catch(Exception exception) { - /* empty */ - exception.printStackTrace(); - } + public FramePieceRenderer(FramePieceAnchor anchor, int width, int height) { + this.anchor = anchor; + this.width = width; + this.height = height; + + // TODO inject this, sometimes needs to be GameShell.game or something + ProducingGraphicsBuffer graphics = MovedStatics.createGraphicsBuffer(width, height, Game.gameCanvas); + this.rasterizerInstanced = new RasterizerInstanced(graphics); } - public void drawImage(ImageRGB image, int x, int y) { - x += image.offsetX; - y += image.offsetY; - int dest_offset = x + y * rasterizerInstanced.destinationWidth; - int source_offset = 0; - int line_count = image.imageHeight; - int line_width = image.imageWidth; - int line_offset_dest = rasterizerInstanced.destinationWidth - line_width; - int line_offset_source = 0; - if(y < rasterizerInstanced.viewportTop) { - int clip_height = rasterizerInstanced.viewportTop - y; - line_count -= clip_height; - y = rasterizerInstanced.viewportTop; - source_offset += clip_height * line_width; - dest_offset += clip_height * rasterizerInstanced.destinationWidth; - } - if(y + line_count > rasterizerInstanced.viewportBottom) - line_count -= y + line_count - rasterizerInstanced.viewportBottom; - if(x < rasterizerInstanced.viewportLeft) { - int clip_width = rasterizerInstanced.viewportLeft - x; - line_width -= clip_width; - x = rasterizerInstanced.viewportLeft; - source_offset += clip_width; - dest_offset += clip_width; - line_offset_source += clip_width; - line_offset_dest += clip_width; - } - if(x + line_width > rasterizerInstanced.viewportRight) { - int clip_width = x + line_width - rasterizerInstanced.viewportRight; - line_width -= clip_width; - line_offset_source += clip_width; - line_offset_dest += clip_width; - } - if(line_width > 0 && line_count > 0) - ImageRGB.blockCopyTrans(rasterizerInstanced.destinationPixels, image.pixels, 0, source_offset, dest_offset, line_width, line_count, line_offset_dest, line_offset_source); + /** + * Draws the piece to the game screen. + * + * @param drawWidth The width of the window. + * @param drawHeight The height of the window. + */ + public void draw(RasterizerInstanced destination, int drawWidth, int drawHeight) { + int[] position = this.anchor.getPosition(drawWidth, drawHeight, width, height); + + int x = position[0]; + int y = position[1]; + + destination.copyPixels(rasterizerInstanced.destinationPixels, width, height, x, y); } - public void drawRotated(ImageRGB image, int x, int y, int pivotX, int pivotY, int width, int height, int zoom, double angle) { - try { - int centerX = -width / 2; - int centerY = -height / 2; - int sine = (int) (Math.sin(angle) * 65536.0); - int cosine = (int) (Math.cos(angle) * 65536.0); - sine = sine * zoom >> 8; - cosine = cosine * zoom >> 8; - int sourceOffsetX = (pivotX << 16) + centerY * sine + centerX * cosine; - int sourceoffsetY = (pivotY << 16) + centerY * cosine - centerX * sine; - int destinationOffset = x + y * rasterizerInstanced.destinationWidth; - for(y = 0; y < height; y++) { - int i = destinationOffset; - int offsetX = sourceOffsetX; - int offsetY = sourceoffsetY; - for(x = -width; x < 0; x++) { - int i_166_ = image.pixels[(offsetX >> 16) + (offsetY >> 16) * image.imageWidth]; - if(i_166_ != 0) - rasterizerInstanced.destinationPixels[i++] = i_166_; - else - i++; - offsetX += cosine; - offsetY -= sine; - } - sourceOffsetX += sine; - sourceoffsetY += cosine; - destinationOffset += rasterizerInstanced.destinationWidth; - } - } catch(Exception exception) { - /* empty */ - exception.printStackTrace(); - } + /** + * Copies the pixels from a ProducingGraphicsBuffer to the rasterizer. + * + * See {@link RasterizerInstanced#copyPixels} for more information. + * + * @param producer The ProducingGraphicsBuffer to copy from. + * @param x The X position to copy to. + * @param y The Y position to copy to. + */ + protected void copyProducer(ProducingGraphicsBuffer producer, int x, int y) { + rasterizerInstanced.copyPixels(producer.pixels, producer.width, producer.height, x, y); + } + /** + * Copies the pixels from a ProducingGraphicsBuffer to the rasterizer. + * + * See {@link RasterizerInstanced#copyPixelsCutOff} for more information. + * + * @param producer The ProducingGraphicsBuffer to copy from. + * @param x The X position to copy to. + * @param y The Y position to copy to. + * @param width The width of the area to copy. + * @param height The height of the area to copy. + * @param offsetX The X offset to copy from. + * @param offsetY The Y offset to copy from. + */ + protected void copyProducerCutOff(ProducingGraphicsBuffer producer, int x, int y, int width, int height, int offsetX, int offsetY) { + rasterizerInstanced.copyPixelsCutOff(producer.pixels, producer.width, producer.height, x, y, width, height, offsetX, offsetY); } } diff --git a/src/main/java/org/runejs/client/frame/FrameRenderer.java b/src/main/java/org/runejs/client/frame/FrameRenderer.java index 1fac680de..465d86d61 100644 --- a/src/main/java/org/runejs/client/frame/FrameRenderer.java +++ b/src/main/java/org/runejs/client/frame/FrameRenderer.java @@ -1,4 +1,22 @@ package org.runejs.client.frame; +import org.runejs.client.frame.tab.TabProducer; +import org.runejs.client.media.RasterizerInstanced; + public interface FrameRenderer extends Runnable { + void setDrawSize(int drawWidth, int drawHeight); + + boolean isCoordinatesInChatArea(int x, int y); + boolean isCoordinatesIn3dScreen(int x, int y); + boolean isCoordinatesInMinimapArea(int x, int y); + boolean isCoordinatesInTabArea(int x, int y); + boolean isCoordinatesInExtendedTabArea(int x, int y); + boolean isCoordinatesInExtendedChatArea(int x, int y); + + TabProducer getTabProducer(); + + void setRasterizer(RasterizerInstanced rasterizer); + + void draw(int mouseX, int mouseY, boolean debugView); + void stop(); } diff --git a/src/main/java/org/runejs/client/frame/Game3DRenderer.java b/src/main/java/org/runejs/client/frame/Game3DRenderer.java new file mode 100644 index 000000000..e99f0ece6 --- /dev/null +++ b/src/main/java/org/runejs/client/frame/Game3DRenderer.java @@ -0,0 +1,249 @@ +package org.runejs.client.frame; + +import org.runejs.Configuration; +import org.runejs.client.Game; +import org.runejs.client.GameShell; +import org.runejs.client.MovedStatics; +import org.runejs.client.cache.media.TypeFace; +import org.runejs.client.cache.media.gameInterface.GameInterface; +import org.runejs.client.input.MouseHandler; +import org.runejs.client.language.English; +import org.runejs.client.language.Native; +import org.runejs.client.media.RasterizerInstanced; +import org.runejs.client.media.VertexNormal; +import org.runejs.client.media.renderable.actor.Player; + +public class Game3DRenderer { + private final RasterizerInstanced rasterizer; + + public Game3DRenderer(RasterizerInstanced rasterizer) { + this.rasterizer = rasterizer; + } + + private void renderSplitPrivateMessages(TypeFace font) { + if(ChatBox.splitPrivateChat != 0) { + int i = 0; + if(MovedStatics.systemUpdateTime != 0) + i = 1; + for(int i_0_ = 0; i_0_ < 100; i_0_++) { + if(ChatBox.chatMessages[i_0_] != null) { + String name = ChatBox.chatPlayerNames[i_0_]; + int crown = 0; + int type = ChatBox.chatTypes[i_0_]; + if(name != null && name.startsWith(Native.whiteCrown)) { + name = name.substring(5); + crown = 1; + } + if(name != null && name.startsWith(Native.goldCrown)) { + name = name.substring(5); + crown = 2; + } + if((type == 3 || type == 7) && (type == 7 || ChatBox.privateChatMode == 0 || ChatBox.privateChatMode == 1 && Player.hasFriend(name))) { + int y = 329 - 13 * i; + int x = 4; + i++; + font.drawString(English.from, x, y, 0); + font.drawString(English.from, x, -1 + y, 65535); + x += font.getStringWidth(English.from); + x += font.method689(32); + if(crown == 1) { + MovedStatics.moderatorIcon[0].drawImage(rasterizer, x, y - 12); + x += 14; + } + if(crown == 2) { + MovedStatics.moderatorIcon[1].drawImage(rasterizer,x, -12 + y); + x += 14; + } + font.drawString(name + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], x, y, 0); + font.drawString(name + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], x, -1 + y, 65535); + if(i >= 5) + return; + } + if(type == 5 && ChatBox.privateChatMode < 2) { + int y = -(i * 13) + 329; + i++; + font.drawString(ChatBox.chatMessages[i_0_], 4, y, 0); + font.drawString(ChatBox.chatMessages[i_0_], 4, y - 1, 65535); + if(i >= 5) + return; + } + if(type == 6 && ChatBox.privateChatMode < 2) { + int y = -(13 * i) + 329; + i++; + font.drawString(English.to + Native.whitespace_b + name + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], 4, y, 0); + font.drawString(English.to + Native.whitespace_b + name + Native.COLON_CHARACTER + ChatBox.chatMessages[i_0_], 4, y + -1, 65535); + if(i >= 5) + return; + } + } + } + } + } + + public void draw3dScreenOverlays() { + TypeFace font = MovedStatics.fontNormal; + font.setRasterizer(this.rasterizer); + + renderSplitPrivateMessages(font); + if (MovedStatics.crossType == 1) { + MovedStatics.cursorCross[MovedStatics.crossIndex / 100].drawImage(GameInterface.crossX - 8 - 4, GameInterface.crossY - 8 - 4); + } + if (MovedStatics.crossType == 2) { + MovedStatics.cursorCross[4 + MovedStatics.crossIndex / 100].drawImage(GameInterface.crossX - 8 - 4, GameInterface.crossY - 8 - 4); + } + if (GameInterface.gameScreenInterfaceId != -1 || GameInterface.walkableWidgetId != -1) { + int areaId = GameInterface.gameScreenInterfaceId != -1 ? 0 : 4; + int id = GameInterface.gameScreenInterfaceId != -1 ? GameInterface.gameScreenInterfaceId : GameInterface.walkableWidgetId; + GameInterface.handleSequences(id); + int yOffset = (ScreenController.drawHeight /2) - (334/2) - (184/2); + int xOffset = (ScreenController.drawWidth /2) - (512/2) - (234/3); + if(ScreenController.frameMode == ScreenMode.FIXED) { + yOffset = 0; + xOffset = 0; + } + Game.drawParentInterface(areaId, xOffset, yOffset, 512+ xOffset, 334 + yOffset, id); + } + MovedStatics.method1018(); + Player.setTutorialIslandFlag(); + if (!MovedStatics.menuOpen) { + MovedStatics.processRightClick(); + MovedStatics.drawMenuTooltip(4); + } else { + if(ScreenController.frameMode == ScreenMode.FIXED && MovedStatics.menuScreenArea == 0){ + MovedStatics.drawMenu(4,4); + } + } + if (MovedStatics.multiCombatState == 1) { + MovedStatics.multiCombatIcon.drawImage(472, 296); + } + if (MovedStatics.showFps) { + int y = 20; + int x = 507; + if(ScreenController.frameMode != ScreenMode.FIXED) { + x = ScreenController.drawWidth - 220; + } + + int colour = 0xffff00; + if (GameShell.fps < 30 && VertexNormal.lowMemory) { + colour = 0xff0000; + } + if (GameShell.fps < 20 && !VertexNormal.lowMemory) { + colour = 0xff0000; + } + font.drawStringRight("Fps: " + GameShell.fps, x, y, colour); + colour = 0xffff00; + y += 15; + Runtime runtime = Runtime.getRuntime(); + int memoryUsed = (int) ((runtime.totalMemory() + -runtime.freeMemory()) / 1024L); + if (memoryUsed > 32768 && VertexNormal.lowMemory) { + colour = 0xff0000; + } + if (memoryUsed < 65536 && !VertexNormal.lowMemory) { + colour = 0xff0000; + } + font.drawStringRight("Mem: " + memoryUsed + "k", x, y, colour); + y += 15; + + font.drawStringRight("MouseX: " + MouseHandler.mouseX, x, y ,0xffff00); + y += 15; + + font.drawStringRight("MouseY: " + MouseHandler.mouseY, x, y ,0xffff00); + y += 15; + font.drawStringRight("ClickX: " + MouseHandler.clickX, x, y ,0xffff00); + y += 15; + + font.drawStringRight("ClickY: " + MouseHandler.clickY, x, y ,0xffff00); + y += 15; + if (MovedStatics.showSidePanelRedrawnText) { + font.drawStringRight(English.sidePanelRedrawn, x, y, 16711680); + y += 15; + MovedStatics.showSidePanelRedrawnText = false; + } + if (MovedStatics.showChatPanelRedrawnText) { + font.drawStringRight(English.chatPanelRedrawn, x, y, 16711680); + y += 15; + MovedStatics.showChatPanelRedrawnText = false; + } + if (MovedStatics.showIconsRedrawnText) { + font.drawStringRight(English.iconsRedrawn, x, y, 16711680); + MovedStatics.showIconsRedrawnText = false; + y += 15; + } + } + if (Configuration.DEBUG_WIDGETS) { + int y = 20; + int x = 507; + if(ScreenController.frameMode != ScreenMode.FIXED) { + x = ScreenController.drawWidth - 220; + } + int widgetParentId = MovedStatics.hoveredWidgetId >> 16; + int widgetChildId = MovedStatics.hoveredWidgetId & 0x7fff; + String typeAsString = ""; + + // Gather widget metadata from the cached interfaces + GameInterface[] parentInterface; + GameInterface childInterface = null; + if (widgetParentId >= 0 && widgetChildId < 469) { + parentInterface = GameInterface.cachedInterfaces[widgetParentId]; + + if (parentInterface != null) { + childInterface = parentInterface[widgetChildId]; + } + + if (childInterface != null) { + switch (childInterface.type) { + case TEXT: + typeAsString = "TEXT"; + break; + case GRAPHIC: + typeAsString = "GRAPHIC"; + break; + case MODEL: + typeAsString = "MODEL"; + break; + case RECTANGLE: + typeAsString = "RECTANGLE"; + break; + case INVENTORY: + typeAsString = "INVENTORY"; + break; + case LINE: + typeAsString = "LINE"; + break; + case TEXT_INVENTORY: + typeAsString = "TEXT_INVENTORY"; + break; + case LAYER: + typeAsString = "LAYER"; + break; + case IF1_TOOLTIP: + typeAsString = "IF1_TOOLTIP"; + break; + default: + typeAsString = "UNKNOWN"; + } + } + } + + font.drawStringRight("Widget " + widgetParentId + ":" + widgetChildId, x, y, 0xffff00); + y+= 15; + if (childInterface != null) { + font.drawStringRight("Parent ID: " + childInterface.parentId, x, y, 0xffff00); + y+= 15; + font.drawStringRight("Type: " + typeAsString, x, y, 0xffff00); + y+= 15; + } + + } + if (MovedStatics.systemUpdateTime != 0) { + int seconds = MovedStatics.systemUpdateTime / 50; + int minutes = seconds / 60; + seconds %= 60; + if (seconds < 10) { + font.drawString(English.systemUpdateIn + minutes + Native.prefixColonZero + seconds, 4, 329, 16776960); + } else { + font.drawString(English.systemUpdateIn + minutes + Native.colon + seconds, 4, 329, 16776960); + } + } + } +} diff --git a/src/main/java/org/runejs/client/frame/Minimap.java b/src/main/java/org/runejs/client/frame/Minimap.java index 7f4d4a972..521740fda 100644 --- a/src/main/java/org/runejs/client/frame/Minimap.java +++ b/src/main/java/org/runejs/client/frame/Minimap.java @@ -5,7 +5,6 @@ import org.runejs.client.cache.media.ImageRGB; import org.runejs.client.cache.media.IndexedImage; import org.runejs.client.media.Rasterizer; -import org.runejs.client.media.Rasterizer3D; import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.renderable.Model; import org.runejs.client.media.renderable.actor.Npc; @@ -14,7 +13,12 @@ import java.awt.*; -public class Minimap extends FramePieceRenderer { +/** + * Class to store the minimap state + * + * TODO (jkm) Work is in-progress to remove all rendering capability from this class + */ +public class Minimap { public static ImageRGB minimapCompass; public static int minimapState = 0; public static IndexedImage minimapBackgroundImage; @@ -39,27 +43,8 @@ public class Minimap extends FramePieceRenderer { */ public static int[][] anIntArrayArray129 = new int[][]{new int[16], {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1}, {1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1}, {0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1}, {1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1}}; public static int minimapLevel = -1; - private static int[] resizableMinimapOffsets1; - private static int[] resizableMinimapOffsets2; - private static ProducingGraphicsBuffer resizableMiniMapimage; - private int[] resizableCompasOffsets1; - private int[] resizableCompasOffsets2; - private ProducingGraphicsBuffer tempResizableMiniMapimage; - private static int[] resizableMinimapLineOffsets; - public Minimap() { - this.tempResizableMiniMapimage = MovedStatics.createGraphicsBuffer(210, 210, Game.gameCanvas); - resizableMinimapOffsets1 = new int[200]; - resizableMinimapOffsets2 = new int[200]; - for(int i = 0; i < resizableMinimapOffsets2.length; i++) { - resizableMinimapOffsets1[i] = 200; - resizableMinimapOffsets2[i] = 0; - } - - resizableMiniMapimage = MovedStatics.createGraphicsBuffer(210, 210, Game.gameCanvas); - rasterizerInstanced = new RasterizerInstanced(this.tempResizableMiniMapimage); - - } + public static RasterizerInstanced rasterizer = new RasterizerInstanced(); public static void drawOnMinimap(int x, int y, ImageRGB sprite) { if (sprite == null) { @@ -79,9 +64,9 @@ public static void drawOnMinimap(int x, int y, ImageRGB sprite) { int i_3_ = cosine * y + x * sine >> 16; int i_4_ = -(y * sine) + cosine * x >> 16; if (l > 2500) - sprite.drawTo(minimapBackgroundImage, 98 + i_3_ + -(sprite.maxWidth / 2), -(sprite.maxHeight / 2) + -i_4_ + 79); + sprite.drawTo(rasterizer, minimapBackgroundImage, 98 + i_3_ + -(sprite.maxWidth / 2), -(sprite.maxHeight / 2) + -i_4_ + 79); else - sprite.drawImage(4 + -(sprite.maxWidth / 2) + i_3_ + 94, -4 + -i_4_ + 83 + -(sprite.maxHeight / 2)); + sprite.drawImage(rasterizer, 4 + -(sprite.maxWidth / 2) + i_3_ + 94, -4 + -i_4_ + 83 + -(sprite.maxHeight / 2)); } public static void renderMinimap() { @@ -89,13 +74,13 @@ public static void renderMinimap() { if(minimapState == 2) { byte[] mmBackgroundPixels = minimapBackgroundImage.imgPixels; - int[] rasterPixels = Rasterizer.destinationPixels; + int[] rasterPixels = rasterizer.destinationPixels; int pixelCount = mmBackgroundPixels.length; for(int i = 0; i < pixelCount; i++) { if(mmBackgroundPixels[i] == 0) rasterPixels[i] = 0; } - minimapCompass.shapeImageToPixels(0, 0, 33, 33, 25, 25, Game.getMinimapRotation(), 256, MovedStatics.anIntArray62, MovedStatics.anIntArray66); + minimapCompass.shapeImageToPixels(rasterizer, 0, 0, 33, 33, 25, 25, Game.getMinimapRotation(), 256, MovedStatics.anIntArray62, MovedStatics.anIntArray66); drawMapBack(); return; } @@ -105,7 +90,7 @@ public static void renderMinimap() { int angle = Game.getMinimapRotation() & 0x7ff; int minimapZoom = 0; - minimapImage.shapeImageToPixels(25, 5, 146, 151, centerX, centerY, angle, minimapZoom + 256, MovedStatics.anIntArray1186, MovedStatics.anIntArray852); + minimapImage.shapeImageToPixels(rasterizer, 25, 5, 146, 151, centerX, centerY, angle, minimapZoom + 256, MovedStatics.anIntArray1186, MovedStatics.anIntArray852); for(int i = 0; minimapHintCount > i; i++) { int hintX = 2 + 4 * minimapHintX[i] + -(Player.localPlayer.worldX / 32); int hintY = 2 + 4 * minimapHintY[i] - Player.localPlayer.worldY / 32; @@ -179,11 +164,11 @@ else if(isTeammate) int flagY = 2 + 4 * Game.destinationY + -(Player.localPlayer.worldY / 32); drawOnMinimap(flagY, flagX, minimapMarkers[0]); } - Rasterizer.drawFilledRectangle(97, 78, 3, 3, 16777215); - minimapCompass.shapeImageToPixels(0, 0, 33, 33, 25, 25, Game.getMinimapRotation(), 256, MovedStatics.anIntArray62, MovedStatics.anIntArray66); - minimapBackgroundImage.drawImage(0, 0); + rasterizer.drawFilledRectangle(97, 78, 3, 3, 16777215); + minimapCompass.shapeImageToPixels(rasterizer, 0, 0, 33, 33, 25, 25, Game.getMinimapRotation(), 256, MovedStatics.anIntArray62, MovedStatics.anIntArray66); + minimapBackgroundImage.drawImage(rasterizer, 0, 0); - if(MovedStatics.menuOpen && ScreenController.frameMode == ScreenMode.FIXED && MovedStatics.menuScreenArea == 1) { + if(MovedStatics.menuOpen && MovedStatics.menuScreenArea == 1) { MovedStatics.drawMenu(550, 4); } drawMapBack(); @@ -191,7 +176,7 @@ else if(isTeammate) } public static void createMinimapRaster() { - mapbackProducingGraphicsBuffer.prepareRasterizer(); + mapbackProducingGraphicsBuffer.prepareRasterizer(rasterizer); } private static void drawMinimapIcon(ImageRGB sprite, int mapX, int mapY) { @@ -209,7 +194,7 @@ private static void drawMinimapIcon(ImageRGB sprite, int mapX, int mapY) { double angle = Math.atan2(x, y); int drawX = (int) (Math.sin(angle) * 63.0); int drawY = (int) (57.0 * Math.cos(angle)); - MovedStatics.minimapEdge.drawRotated(-10 + 94 + drawX + 4, 83 + -drawY + -20, 15, 15, 20, 20, 256, angle); + MovedStatics.minimapEdge.drawRotated(rasterizer, -10 + 94 + drawX + 4, 83 + -drawY + -20, 15, 15, 20, 20, 256, angle); } else { drawOnMinimap(mapY, mapX, sprite); } @@ -294,7 +279,7 @@ private static void drawObject(int plane, int tileX, int wallRGB, int doorRGB, i if(iconSprite != null) { int offsetX = (-iconSprite.imgWidth + gameObjectDefinition.sizeX * 4) / 2; int offsetY = (gameObjectDefinition.sizeY * 4 + -iconSprite.imgHeight) / 2; - iconSprite.drawImage(48 + 4 * tileX + offsetX, offsetY + 48 + (104 + -tileY - gameObjectDefinition.sizeY) * 4); + iconSprite.drawImage(rasterizer, 48 + 4 * tileX + offsetX, offsetY + 48 + (104 + -tileY - gameObjectDefinition.sizeY) * 4); } } } @@ -310,7 +295,7 @@ private static void drawObject(int plane, int tileX, int wallRGB, int doorRGB, i if(iconSprite != null) { int offsetY = (-iconSprite.imgHeight + gameObjectDefinition.sizeY * 4) / 2; int offsetX = (gameObjectDefinition.sizeX * 4 + -iconSprite.imgWidth) / 2; - iconSprite.drawImage(offsetX + tileX * 4 + 48, 48 - (-(4 * (-tileY + 104 + -gameObjectDefinition.sizeY)) + -offsetY)); + iconSprite.drawImage(rasterizer, offsetX + tileX * 4 + 48, 48 - (-(4 * (-tileY + 104 + -gameObjectDefinition.sizeY)) + -offsetY)); } } else if(type == 9) { int[] dest = minimapImage.pixels; @@ -340,7 +325,7 @@ private static void drawObject(int plane, int tileX, int wallRGB, int doorRGB, i if(iconSprite != null) { int i_17_ = (-iconSprite.imgWidth + gameObjectDefinition.sizeX * 4) / 2; int i_18_ = (-iconSprite.imgHeight + 4 * gameObjectDefinition.sizeY) / 2; - iconSprite.drawImage(4 * tileX + 48 + i_17_, i_18_ + (104 - (tileY + gameObjectDefinition.sizeY)) * 4 + 48); + iconSprite.drawImage(rasterizer, 4 * tileX + 48 + i_17_, i_18_ + (104 - (tileY + gameObjectDefinition.sizeY)) * 4 + 48); } } } @@ -361,7 +346,7 @@ public static void createMinimap(int plane) { offset += 4; } } - minimapImage.prepareRasterizer(); + minimapImage.prepareRasterizer(rasterizer); // generate slightly random offset door and wall colors // door: (228, 228, 228) to (248, 248, 248) @@ -421,200 +406,4 @@ public static void drawMapBack() { Game.gameCanvas.repaint(); } } - - public void drawResizableMiniMapArea(int x, int y) { - ScreenController.drawFramePiece(resizableMiniMapimage, x, y); - } - - public void RenderResizableMiniMapArea(int x, int y) { - if(this.resizableCompasOffsets1 == null) { - resizableCompasOffsets1 = new int[33]; - resizableCompasOffsets2 = new int[33]; - for(int y1 = 0; y1 < 33; y1++) { - int i_15_ = 0; - int i_16_ = 999; - for(int x1 = 0; x1 < 34; x1++) { - if(minimapBackgroundImage.imgPixels[minimapBackgroundImage.imgWidth * y1 + x1] == 0) { - if(i_16_ == 999) - i_16_ = x1; - } else if(i_16_ != 999) { - i_15_ = x1; - break; - } - } - resizableCompasOffsets2[y1] = i_16_; - resizableCompasOffsets1[y1] = -i_16_ + i_15_; - } - } - if(minimapState == 2) { - resizableMiniMapimage.prepareRasterizer(); - resizableMinimapLineOffsets = Rasterizer3D.setLineOffsets(resizableMinimapLineOffsets); - byte[] mmBackgroundPixels = minimapBackgroundImage.imgPixels; - int[] rasterPixels = Rasterizer.destinationPixels; - int pixelCount = mmBackgroundPixels.length; - for(int i = 0; i < pixelCount; i++) { - if(mmBackgroundPixels[i] == 0) - rasterPixels[i] = 0; - } - Rasterizer.drawFilledRectangle(0, 0, 210, 210, 0x242017); - Rasterizer.drawFilledRectangle(5, 5, 200, 200, 0x000000); - - // Rasterizer.drawFilledRectangle(x-43,y, 43, 43, 0x242017); - Rasterizer.drawFilledRectangle(0, 0, 20, 42, 0x242017); - Rasterizer.drawFilledRectangle(0, 0, 42, 20, 0x242017); - - Rasterizer.drawCircle(21, 21, 20, 0x242017); - minimapCompass.shapeImageToPixels(5, 5, 33, 33, 25, 25, Game.getMinimapRotation(), 256, resizableCompasOffsets2, resizableCompasOffsets1); - - - MovedStatics.method1018(); - - ScreenController.drawFramePiece(resizableMiniMapimage, x, y); - return; - } - - int i = 48 + Player.localPlayer.worldX / 32; - int i_8_ = 464 + -(Player.localPlayer.worldY / 32); - int i_9_ = Game.getMinimapRotation() & 0x7ff; - int minimapZoom = 0; - - shapeImageToPixels(minimapImage,5, 5, 200, 200, i, i_8_, i_9_, minimapZoom + 256, resizableMinimapOffsets2, resizableMinimapOffsets1); - drawResizableMinimapDots(); - rasterizerInstanced.drawFilledRectangle(105, 105, 3, 3, 16777215); - rasterizerInstanced.drawFilledRectangle(0, 0, 210, 5, 0x242017); - rasterizerInstanced.drawFilledRectangle(0, 205, 210, 5, 0x242017); - rasterizerInstanced.drawFilledRectangle(0, 0, 5, 210, 0x242017); - rasterizerInstanced.drawFilledRectangle(205, 0, 5, 210, 0x242017); - - // Rasterizer.drawFilledRectangle(x-43,y, 43, 43, 0x242017); - rasterizerInstanced.drawFilledRectangle(0, 0, 20, 42, 0x242017); - rasterizerInstanced.drawFilledRectangle(0, 0, 42, 20, 0x242017); - - rasterizerInstanced.drawCircle(21, 21, 20, 0x242017); - shapeImageToPixels(minimapCompass, 5, 5, 33, 33, 25, 25, Game.getMinimapRotation(), 256, resizableCompasOffsets2, resizableCompasOffsets1); - - System.arraycopy(tempResizableMiniMapimage.pixels, 0, resizableMiniMapimage.pixels,0, resizableMiniMapimage.pixels.length); -// Class65.method1018(); - - // ScreenController.drawFramePiece(resizableMiniMapimage, x, y); - - } - - private void drawResizableMinimapDots() { - for(int i = 0; minimapHintCount > i; i++) { - int hintX = 2 + 4 * minimapHintX[i] + -(Player.localPlayer.worldX / 32); - int hintY = 2 + 4 * minimapHintY[i] - Player.localPlayer.worldY / 32; - drawOnResizableMinimap(hintX, hintY, minimapHint[i]); - } - for(int x = 0; x < 104; x++) { - for(int y = 0; y < 104; y++) { - LinkedList linkedList = MovedStatics.groundItems[Player.worldLevel][x][y]; - if(linkedList != null) { - int itemY = -(Player.localPlayer.worldY / 32) + 2 + y * 4; - int itemX = -(Player.localPlayer.worldX / 32) + 2 + x * 4; - drawOnResizableMinimap(itemX, itemY, mapDots[0]); - } - } - } - for(int i = 0; Player.npcCount > i; i++) { - Npc npc = Player.npcs[Player.npcIds[i]]; - if(npc != null && npc.isInitialized()) { - ActorDefinition definition = npc.actorDefinition; - if(definition.childIds != null) - definition = definition.getChildDefinition(); - if(definition != null && definition.renderOnMinimap && definition.isClickable) { - int npcX = -(Player.localPlayer.worldX / 32) + npc.worldX / 32; - int npcY = npc.worldY / 32 + -(Player.localPlayer.worldY / 32); - drawOnResizableMinimap(npcX, npcY, mapDots[1]); - } - } - } - for(int i = 0; Player.localPlayerCount > i; i++) { - Player player = Player.trackedPlayers[Player.trackedPlayerIndices[i]]; - if(player != null && player.isInitialized()) { - int playerX = player.worldX / 32 + -(Player.localPlayer.worldX / 32); - int playerY = -(Player.localPlayer.worldY / 32) + player.worldY / 32; - boolean isFriend = Game.friendList.containsPlayerUsername(player.playerName); - boolean isTeammate = false; - if(Player.localPlayer.teamId != 0 && player.teamId != 0 && player.teamId == Player.localPlayer.teamId) - isTeammate = true; - if(isFriend) - drawOnResizableMinimap(playerX, playerY, mapDots[3]); - else if(isTeammate) - drawOnResizableMinimap(playerX, playerY, mapDots[4]); - else - drawOnResizableMinimap(playerX, playerY, mapDots[2]); - } - } - if(Player.headIconDrawType != 0 && MovedStatics.pulseCycle % 20 < 10) { - if(Player.headIconDrawType == 1 && MovedStatics.hintIconNpcTarget >= 0 && Player.npcs.length > MovedStatics.hintIconNpcTarget) { - Npc npc = Player.npcs[MovedStatics.hintIconNpcTarget]; - if(npc != null) { - int npcX = -(Player.localPlayer.worldX / 32) + npc.worldX / 32; - int npcY = npc.worldY / 32 - Player.localPlayer.worldY / 32; - drawMinimapMark(minimapMarkers[1], npcX, npcY); - } - } - if(Player.headIconDrawType == 2) { - int hintY = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-MovedStatics.baseY + MovedStatics.hintIconPosY); - int hintX = 4 * (MovedStatics.hintIconPosX - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32); - drawMinimapMark(minimapMarkers[1], hintX, hintY); - } - if(Player.headIconDrawType == 10 && MovedStatics.hintIconPlayerTarget >= 0 && Player.trackedPlayers.length > MovedStatics.hintIconPlayerTarget) { - Player player = Player.trackedPlayers[MovedStatics.hintIconPlayerTarget]; - if(player != null) { - int playerY = -(Player.localPlayer.worldY / 32) + player.worldY / 32; - int playerX = player.worldX / 32 - Player.localPlayer.worldX / 32; - drawMinimapMark(minimapMarkers[1], playerX, playerY); - } - } - } - if(MovedStatics.destinationX != 0) { - int flagX = 2 + MovedStatics.destinationX * 4 + -(Player.localPlayer.worldX / 32); - int flagY = 2 + 4 * Game.destinationY + -(Player.localPlayer.worldY / 32); - drawOnResizableMinimap(flagX, flagY, minimapMarkers[0]); - } - } - - public void drawOnResizableMinimap(int x, int y, ImageRGB sprite) { - if(sprite == null) { - return; - } - int angle = 0x7ff & Game.getMinimapRotation(); - int l = y * y + x * x; - if(l > 17000) { - return; - } - int sine = Model.SINE[angle]; - int cosine = Model.COSINE[angle]; - int zoom = 0; - - sine = sine * 256 / (zoom + 256); - cosine = cosine * 256 / (zoom + 256); - int i_3_ = cosine * x + y * sine >> 16; - int i_4_ = -(x * sine) + cosine * y >> 16; - drawImage(sprite, 106 + i_3_ + -(sprite.maxWidth / 2), -(sprite.maxHeight / 2) + -i_4_ + 106); - } - - public void drawMinimapMark(ImageRGB sprite, int mapX, int mapY) { - int len = mapX * mapX + mapY * mapY; - if (len > 4225 && len < 90000) { - int theta = 0x7ff & Game.getMinimapRotation(); - int sine = Model.SINE[theta]; - int cosine = Model.COSINE[theta]; - int zoom = 0; - - sine = sine * 256 / (zoom + 256); - cosine = cosine * 256 / (zoom + 256); - int y = cosine * mapY - sine * mapX >> 16; - int x = mapX * cosine + mapY * sine >> 16; - double angle = Math.atan2(x, y); - int drawX = (int) (Math.sin(angle) * 63.0); - int drawY = (int) (57.0 * Math.cos(angle)); - drawRotated(sprite, -10 + 94 + drawX + 4, 83 + -drawY + -20, 15, 15, 20, 20, 256, angle); - } else { - drawOnResizableMinimap(mapY, mapX, sprite); - } - } - } diff --git a/src/main/java/org/runejs/client/frame/MinimapRenderer.java b/src/main/java/org/runejs/client/frame/MinimapRenderer.java new file mode 100644 index 000000000..66d3e9fe5 --- /dev/null +++ b/src/main/java/org/runejs/client/frame/MinimapRenderer.java @@ -0,0 +1,293 @@ +package org.runejs.client.frame; + +import org.runejs.client.Game; +import org.runejs.client.LinkedList; +import org.runejs.client.MovedStatics; +import org.runejs.client.cache.def.ActorDefinition; +import org.runejs.client.cache.media.ImageRGB; +import org.runejs.client.media.RasterizerInstanced; +import org.runejs.client.media.renderable.Model; +import org.runejs.client.media.renderable.actor.Npc; +import org.runejs.client.media.renderable.actor.Player; + +/** + * A {@link FramePieceRenderer} that renders the minimap. + * + * TODO (jkm) this currently renders the "resizable" mode (square) minimap only + */ +public class MinimapRenderer extends FramePieceRenderer { + public static int[] resizableMinimapOffsets1; + public static int[] resizableMinimapOffsets2; + public int[] resizableCompasOffsets1; + public int[] resizableCompasOffsets2; + public static int[] resizableMinimapLineOffsets; + + /** + * To avoid flickering, we draw to a temporary rasterizer first, + * then flush this to the output rasterizer at once, in its entirety. + */ + private RasterizerInstanced rasterizerTemp; + + public MinimapRenderer() { + super( + new FramePieceAnchor( + FramePieceAnchor.Anchor.TOP | FramePieceAnchor.Anchor.RIGHT, + 0, + 0 + ), + 210, + 210 + ); + + resizableMinimapOffsets1 = new int[200]; + resizableMinimapOffsets2 = new int[200]; + for(int i = 0; i < resizableMinimapOffsets2.length; i++) { + resizableMinimapOffsets1[i] = 200; + resizableMinimapOffsets2[i] = 0; + } + + rasterizerTemp = new RasterizerInstanced( + MovedStatics.createGraphicsBuffer(this.width, this.height, Game.gameCanvas) + ); + } + + public void RenderResizableMiniMapArea(int x, int y) { + if(resizableCompasOffsets1 == null) { + resizableCompasOffsets1 = new int[33]; + resizableCompasOffsets2 = new int[33]; + for(int y1 = 0; y1 < 33; y1++) { + int i_15_ = 0; + int i_16_ = 999; + for(int x1 = 0; x1 < 34; x1++) { + if(Minimap.minimapBackgroundImage.imgPixels[Minimap.minimapBackgroundImage.imgWidth * y1 + x1] == 0) { + if(i_16_ == 999) + i_16_ = x1; + } else if(i_16_ != 999) { + i_15_ = x1; + break; + } + } + resizableCompasOffsets2[y1] = i_16_; + resizableCompasOffsets1[y1] = -i_16_ + i_15_; + } + } + + // TODO handle black minimap for Minimap.minimapState == 2 + + int i = 48 + Player.localPlayer.worldX / 32; + int i_8_ = 464 + -(Player.localPlayer.worldY / 32); + int i_9_ = Game.getMinimapRotation() & 0x7ff; + int minimapZoom = 0; + + shapeImageToPixels(Minimap.minimapImage,5, 5, 200, 200, i, i_8_, i_9_, minimapZoom + 256, resizableMinimapOffsets2, resizableMinimapOffsets1); + drawResizableMinimapDots(); + rasterizerTemp.drawFilledRectangle(105, 105, 3, 3, 16777215); + rasterizerTemp.drawFilledRectangle(0, 0, 210, 5, 0x242017); + rasterizerTemp.drawFilledRectangle(0, 205, 210, 5, 0x242017); + rasterizerTemp.drawFilledRectangle(0, 0, 5, 210, 0x242017); + rasterizerTemp.drawFilledRectangle(205, 0, 5, 210, 0x242017); + + // Rasterizer.drawFilledRectangle(x-43,y, 43, 43, 0x242017); + rasterizerTemp.drawFilledRectangle(0, 0, 20, 42, 0x242017); + rasterizerTemp.drawFilledRectangle(0, 0, 42, 20, 0x242017); + + rasterizerTemp.drawCircle(21, 21, 20, 0x242017); + shapeImageToPixels(Minimap.minimapCompass, 5, 5, 33, 33, 25, 25, Game.getMinimapRotation(), 256, resizableCompasOffsets2, resizableCompasOffsets1); + + System.arraycopy(rasterizerTemp.destinationPixels, 0, rasterizerInstanced.destinationPixels,0, rasterizerInstanced.destinationPixels.length); +// Class65.method1018(); + + // ScreenController.drawFramePiece(resizableMiniMapimage, x, y); + + } + + + + private void shapeImageToPixels(ImageRGB image, int x, int y, int width, int height, int arg4, int arg5, int k1, int zoom, int[] arg8, int[] arg9) { + try { + int centerX = -width / 2; + int centerY = -height / 2; + int sine = (int) (Math.sin((double) k1 / 326.11) * 65536.0); + int cosine = (int) (Math.cos((double) k1 / 326.11) * 65536.0); + sine = sine * zoom >> 8; + cosine = cosine * zoom >> 8; + int i_125_ = (arg4 << 16) + centerY * sine + centerX * cosine; + int i_126_ = (arg5 << 16) + centerY * cosine - centerX * sine; + int destinationOffset = x + y * rasterizerTemp.destinationWidth; + + for(y = 0; y < height; y++) { + int i_128_ = arg8[y]; + int i_129_ = destinationOffset + i_128_; + int i_130_ = i_125_ + cosine * i_128_; + int i_131_ = i_126_ - sine * i_128_; + for(x = -arg9[y]; x < 0; x++) { + int pixelToGet = (i_130_ >> 16) + (i_131_ >> 16) * image.imageWidth; + int colour = 0; + if(!(image.pixels.length < pixelToGet || pixelToGet < 0)){ + colour = image.pixels[pixelToGet]; + } + rasterizerTemp.destinationPixels[i_129_++] = colour; + i_130_ += cosine; + i_131_ -= sine; + } + i_125_ += sine; + i_126_ += cosine; + destinationOffset += rasterizerTemp.destinationWidth; + } + } catch(Exception exception) { + /* empty */ + exception.printStackTrace(); + } + } + + private void drawResizableMinimapDots() { + for(int i = 0; Minimap.minimapHintCount > i; i++) { + int hintX = 2 + 4 * Minimap.minimapHintX[i] + -(Player.localPlayer.worldX / 32); + int hintY = 2 + 4 * Minimap.minimapHintY[i] - Player.localPlayer.worldY / 32; + drawOnResizableMinimap(hintX, hintY, Minimap.minimapHint[i]); + } + for(int x = 0; x < 104; x++) { + for(int y = 0; y < 104; y++) { + LinkedList linkedList = MovedStatics.groundItems[Player.worldLevel][x][y]; + if(linkedList != null) { + int itemY = -(Player.localPlayer.worldY / 32) + 2 + y * 4; + int itemX = -(Player.localPlayer.worldX / 32) + 2 + x * 4; + drawOnResizableMinimap(itemX, itemY, Minimap.mapDots[0]); + } + } + } + for(int i = 0; Player.npcCount > i; i++) { + Npc npc = Player.npcs[Player.npcIds[i]]; + if(npc != null && npc.isInitialized()) { + ActorDefinition definition = npc.actorDefinition; + if(definition.childIds != null) + definition = definition.getChildDefinition(); + if(definition != null && definition.renderOnMinimap && definition.isClickable) { + int npcX = -(Player.localPlayer.worldX / 32) + npc.worldX / 32; + int npcY = npc.worldY / 32 + -(Player.localPlayer.worldY / 32); + drawOnResizableMinimap(npcX, npcY, Minimap.mapDots[1]); + } + } + } + for(int i = 0; Player.localPlayerCount > i; i++) { + Player player = Player.trackedPlayers[Player.trackedPlayerIndices[i]]; + if(player != null && player.isInitialized()) { + int playerX = player.worldX / 32 + -(Player.localPlayer.worldX / 32); + int playerY = -(Player.localPlayer.worldY / 32) + player.worldY / 32; + boolean isFriend = Game.friendList.containsPlayerUsername(player.playerName); + boolean isTeammate = false; + if(Player.localPlayer.teamId != 0 && player.teamId != 0 && player.teamId == Player.localPlayer.teamId) + isTeammate = true; + if(isFriend) + drawOnResizableMinimap(playerX, playerY, Minimap.mapDots[3]); + else if(isTeammate) + drawOnResizableMinimap(playerX, playerY, Minimap.mapDots[4]); + else + drawOnResizableMinimap(playerX, playerY, Minimap.mapDots[2]); + } + } + if(Player.headIconDrawType != 0 && MovedStatics.pulseCycle % 20 < 10) { + if(Player.headIconDrawType == 1 && MovedStatics.hintIconNpcTarget >= 0 && Player.npcs.length > MovedStatics.hintIconNpcTarget) { + Npc npc = Player.npcs[MovedStatics.hintIconNpcTarget]; + if(npc != null) { + int npcX = -(Player.localPlayer.worldX / 32) + npc.worldX / 32; + int npcY = npc.worldY / 32 - Player.localPlayer.worldY / 32; + drawMinimapMark(Minimap.minimapMarkers[1], npcX, npcY); + } + } + if(Player.headIconDrawType == 2) { + int hintY = -(Player.localPlayer.worldY / 32) + 2 + 4 * (-MovedStatics.baseY + MovedStatics.hintIconPosY); + int hintX = 4 * (MovedStatics.hintIconPosX - MovedStatics.baseX) - (-2 + Player.localPlayer.worldX / 32); + drawMinimapMark(Minimap.minimapMarkers[1], hintX, hintY); + } + if(Player.headIconDrawType == 10 && MovedStatics.hintIconPlayerTarget >= 0 && Player.trackedPlayers.length > MovedStatics.hintIconPlayerTarget) { + Player player = Player.trackedPlayers[MovedStatics.hintIconPlayerTarget]; + if(player != null) { + int playerY = -(Player.localPlayer.worldY / 32) + player.worldY / 32; + int playerX = player.worldX / 32 - Player.localPlayer.worldX / 32; + drawMinimapMark(Minimap.minimapMarkers[1], playerX, playerY); + } + } + } + if(MovedStatics.destinationX != 0) { + int flagX = 2 + MovedStatics.destinationX * 4 + -(Player.localPlayer.worldX / 32); + int flagY = 2 + 4 * Game.destinationY + -(Player.localPlayer.worldY / 32); + drawOnResizableMinimap(flagX, flagY, Minimap.minimapMarkers[0]); + } + } + + public void drawOnResizableMinimap(int x, int y, ImageRGB sprite) { + if(sprite == null) { + return; + } + int angle = 0x7ff & Game.getMinimapRotation(); + int l = y * y + x * x; + if(l > 17000) { + return; + } + int sine = Model.SINE[angle]; + int cosine = Model.COSINE[angle]; + int zoom = 0; + + sine = sine * 256 / (zoom + 256); + cosine = cosine * 256 / (zoom + 256); + int i_3_ = cosine * x + y * sine >> 16; + int i_4_ = -(x * sine) + cosine * y >> 16; + rasterizerTemp.drawImage(sprite, 106 + i_3_ + -(sprite.maxWidth / 2), -(sprite.maxHeight / 2) + -i_4_ + 106); + } + + public void drawMinimapMark(ImageRGB sprite, int mapX, int mapY) { + int len = mapX * mapX + mapY * mapY; + if (len > 4225 && len < 90000) { + int theta = 0x7ff & Game.getMinimapRotation(); + int sine = Model.SINE[theta]; + int cosine = Model.COSINE[theta]; + int zoom = 0; + + sine = sine * 256 / (zoom + 256); + cosine = cosine * 256 / (zoom + 256); + int y = cosine * mapY - sine * mapX >> 16; + int x = mapX * cosine + mapY * sine >> 16; + double angle = Math.atan2(x, y); + int drawX = (int) (Math.sin(angle) * 63.0); + int drawY = (int) (57.0 * Math.cos(angle)); + drawRotated(sprite, -10 + 94 + drawX + 4, 83 + -drawY + -20, 15, 15, 20, 20, 256, angle); + } else { + drawOnResizableMinimap(mapY, mapX, sprite); + } + } + + private void drawRotated(ImageRGB image, int x, int y, int pivotX, int pivotY, int width, int height, int zoom, double angle) { + try { + int centerX = -width / 2; + int centerY = -height / 2; + int sine = (int) (Math.sin(angle) * 65536.0); + int cosine = (int) (Math.cos(angle) * 65536.0); + sine = sine * zoom >> 8; + cosine = cosine * zoom >> 8; + int sourceOffsetX = (pivotX << 16) + centerY * sine + centerX * cosine; + int sourceoffsetY = (pivotY << 16) + centerY * cosine - centerX * sine; + int destinationOffset = x + y * rasterizerTemp.destinationWidth; + for(y = 0; y < height; y++) { + int i = destinationOffset; + int offsetX = sourceOffsetX; + int offsetY = sourceoffsetY; + for(x = -width; x < 0; x++) { + int i_166_ = image.pixels[(offsetX >> 16) + (offsetY >> 16) * image.imageWidth]; + if(i_166_ != 0) + rasterizerTemp.destinationPixels[i++] = i_166_; + else + i++; + offsetX += cosine; + offsetY -= sine; + } + sourceOffsetX += sine; + sourceoffsetY += cosine; + destinationOffset += rasterizerTemp.destinationWidth; + } + } catch(Exception exception) { + /* empty */ + exception.printStackTrace(); + } + } +} diff --git a/src/main/java/org/runejs/client/frame/ResizableFrameRenderer.java b/src/main/java/org/runejs/client/frame/ResizableFrameRenderer.java index 2948c8542..78148b5d8 100644 --- a/src/main/java/org/runejs/client/frame/ResizableFrameRenderer.java +++ b/src/main/java/org/runejs/client/frame/ResizableFrameRenderer.java @@ -1,32 +1,170 @@ package org.runejs.client.frame; import org.runejs.client.Game; +import org.runejs.client.MovedStatics; import org.runejs.client.frame.tab.TabProducer; +import org.runejs.client.media.RasterizerInstanced; public class ResizableFrameRenderer implements FrameRenderer { - private final Minimap minimap; - private final TabProducer tabProducer; + public final MinimapRenderer minimap = new MinimapRenderer(); + public final TabProducer tabProducer = new TabProducer(); + public final ChatBoxRenderer chatbox = new ChatBoxRenderer(); - public ResizableFrameRenderer(Minimap minimap, TabProducer tabProducer) { - this.minimap = minimap; - this.tabProducer = tabProducer; + private Thread drawingThread; + + private int drawWidth; + private int drawHeight; + + private boolean canDraw; + private boolean shouldStop = false; + private RasterizerInstanced rasterizer; + + public ResizableFrameRenderer(RasterizerInstanced rasterizer) { + drawingThread = new Thread(this); + drawingThread.start(); + + this.rasterizer = rasterizer; } @Override public void run() { - while(true){ - if(Game.gameStatusCode <= 35 && Game.gameStatusCode >= 30){ + while(!shouldStop){ + if(canDraw && Game.gameStatusCode <= 35 && Game.gameStatusCode >= 30){ minimap.RenderResizableMiniMapArea(ScreenController.drawWidth - 210, 0); - } - if(Game.gameStatusCode <= 35 && Game.gameStatusCode >= 30){ tabProducer.RenderResizableSideBarArea(); + chatbox.render(); } try { Thread.sleep(1); } catch(InterruptedException e) { e.printStackTrace(); } + } + } + + public void setDrawSize(int drawWidth, int drawHeight) { + this.drawWidth = drawWidth; + this.drawHeight = drawHeight; + } + private void drawToScreen() { + minimap.draw(this.rasterizer, drawWidth, drawHeight); + tabProducer.draw(this.rasterizer, drawWidth, drawHeight); + chatbox.draw(this.rasterizer, drawWidth, drawHeight); + } + + /** + * Draw the debug view over the top + * + * TODO (jkm) remove static Rasterizer calls here + * + * @param mX Mouse position X + * @param mY Mouse position Y + */ + private void drawDebugView(int mX, int mY) { + int[] tabInterFaceCoords= tabProducer.getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); + int[] tabInterFaceTop = tabProducer.getTopBarCoordSize(drawWidth - 241, drawHeight - (334)); + int[] tabInterFaceBottom = tabProducer.getBottomBarCoordSize(drawWidth - 241, drawHeight - (334)); + if (isCoordinatesIn3dScreen(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(0, 0, drawWidth, drawHeight, 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(0, 0, drawWidth, drawHeight, 0xFF00FF, 90); + } + if (isCoordinatesInExtendedTabArea(mX, mY) && !isCoordinatesInTabArea(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(tabInterFaceTop[0], tabInterFaceTop[1], tabInterFaceTop[2], tabInterFaceTop[3], 0x00FF00, 90); + rasterizer.drawFilledRectangleAlpha(tabInterFaceBottom[0], tabInterFaceBottom[1], tabInterFaceBottom[2], tabInterFaceBottom[3], 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(tabInterFaceTop[0], tabInterFaceTop[1], tabInterFaceTop[2], tabInterFaceTop[3], 0x0000FF, 90); + rasterizer.drawFilledRectangleAlpha(tabInterFaceBottom[0], tabInterFaceBottom[1], tabInterFaceBottom[2], tabInterFaceBottom[3], 0x0000FF, 90); } + if (isCoordinatesInTabArea(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(tabInterFaceCoords[0], tabInterFaceCoords[1], MovedStatics.tabImageProducer.width, MovedStatics.tabImageProducer.height, 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(tabInterFaceCoords[0], tabInterFaceCoords[1], MovedStatics.tabImageProducer.width, MovedStatics.tabImageProducer.height, 0x0000FF, 90); + } + if (isCoordinatesInExtendedChatArea(mX, mY) && !isCoordinatesInChatArea(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(0, drawHeight - (162), 516, drawHeight, 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(0, drawHeight - (162), 516, drawHeight, 0x0000FF, 90); + } + if (isCoordinatesInChatArea(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(17, drawHeight - (162) + 16, ChatBox.chatBoxImageProducer.width, ChatBox.chatBoxImageProducer.height, 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(17, drawHeight - (162) + 16, ChatBox.chatBoxImageProducer.width, ChatBox.chatBoxImageProducer.height, 0x0000FF, 90); + } + if (isCoordinatesInMinimapArea(mX, mY)) { + rasterizer.drawFilledRectangleAlpha(drawWidth - 210, 0, 210, 210, 0x00FF00, 90); + } else { + rasterizer.drawFilledRectangleAlpha(drawWidth - 210, 0, 210, 210, 0x0000FF, 90); + } + + rasterizer.drawFilledRectangle(mX - 4, mY - 4, 4, 4, 0xFF0000); + } + + public boolean isCoordinatesInChatArea(int x, int y) { + int minX = 17; + int minY = drawHeight - (162) + 16; + // TODO (jkm) point these elsewhere + int maxX = minX + ChatBox.chatBoxImageProducer.width; + int maxY = minY + ChatBox.chatBoxImageProducer.height; + return x > minX && y > minY && x < maxX && y < maxY; + } + + public boolean isCoordinatesIn3dScreen(int x, int y) { + return x > 0 && y > 0 && x < drawWidth && y < drawHeight && !isCoordinatesInExtendedTabArea(x, y) && !isCoordinatesInTabArea(x, y) && !isCoordinatesInMinimapArea(x, y) && !isCoordinatesInExtendedChatArea(x, y); + } + + public boolean isCoordinatesInMinimapArea(int x, int y) { + return x > drawWidth - 210 && y < 210; + } + + public boolean isCoordinatesInTabArea(int x, int y) { + int[] tabInterFaceCoords= tabProducer.getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); + + int minX = tabInterFaceCoords[0]; + int minY = tabInterFaceCoords[1]; + int maxX = minX + tabInterFaceCoords[2]; + int maxY = minY + tabInterFaceCoords[3]; + return x > minX && y > minY && x < maxX && y < maxY; + } + + public boolean isCoordinatesInExtendedTabArea(int x, int y) { + int[] top = tabProducer.getTopBarCoordSize(drawWidth - 241, drawHeight - (334)); + int[] bottom = tabProducer.getBottomBarCoordSize(drawWidth - 241, drawHeight - (334)); + if(x > top[0] && x < top[0]+top[2] && y > top[1] && y < top[1]+top[3]) { + return true; + } else return x > bottom[0] && x < bottom[0] + bottom[2] && y > bottom[1] && y < bottom[1] + bottom[3]; + } + + public boolean isCoordinatesInExtendedChatArea(int x, int y) { + return x > 0 && y > drawHeight - 184 && x < 516; + } + + public TabProducer getTabProducer() { + return tabProducer; + } + + @Override + public void setRasterizer(RasterizerInstanced rasterizer) { + this.rasterizer = rasterizer; + } + + public void draw(int mouseX, int mouseY, boolean debugView) { + canDraw = true; + + drawToScreen(); + + if (debugView) { + drawDebugView(mouseX, mouseY); + } + + if (MovedStatics.menuOpen) { + MovedStatics.drawMenu(0, 0); + } + } + + @Override + public void stop() { + shouldStop = true; } } diff --git a/src/main/java/org/runejs/client/frame/ScreenController.java b/src/main/java/org/runejs/client/frame/ScreenController.java index e66eba021..b48ff2907 100644 --- a/src/main/java/org/runejs/client/frame/ScreenController.java +++ b/src/main/java/org/runejs/client/frame/ScreenController.java @@ -2,12 +2,13 @@ import org.runejs.client.cache.media.gameInterface.GameInterface; import org.runejs.client.cache.media.gameInterface.GameInterfaceArea; -import org.runejs.client.frame.tab.TabProducer; import org.runejs.client.input.MouseHandler; import org.runejs.client.language.English; import org.runejs.client.language.Native; +import org.runejs.client.media.Constants3D; import org.runejs.client.media.Rasterizer; import org.runejs.client.media.Rasterizer3D; +import org.runejs.client.media.RasterizerInstanced; import org.runejs.client.media.renderable.actor.Pathfinding; import org.runejs.client.media.renderable.actor.Player; import org.runejs.client.message.outbound.chat.SetChatOptionsOutboundMessage; @@ -18,29 +19,48 @@ import java.text.MessageFormat; public class ScreenController { - - public static ScreenMode frameMode = null; public static int frameWidth = 765; public static int frameHeight = 540; public static int drawWidth = 765; public static int drawHeight = 540; - public static Minimap minimap = new Minimap(); - public static TabProducer tabProducer = new TabProducer(); - private static Thread drawingThread; + public static ProducingGraphicsBuffer drawComponent; + public static RasterizerInstanced rasterizer = new RasterizerInstanced( + null, + ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, + ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight + ); + public static Game3DRenderer gameRenderer = new Game3DRenderer(rasterizer); + private static FrameRenderer renderer; public static boolean DebugView = false; + public static void setDrawComponent(Component component) { + drawComponent = MovedStatics.createGraphicsBuffer( + ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, + ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight, + component + ); + + rasterizer.setGraphics(drawComponent); + } public static void frameMode(ScreenMode screenMode) { if (frameMode != screenMode) { frameMode = screenMode; + + if (renderer != null) { + renderer.stop(); + } + if (screenMode == ScreenMode.FIXED) { frameWidth = 765; frameHeight = 503; GameShell.clientFrame.setResizable(false); GameShell.clientFrame.setPreferredSize(new Dimension(ScreenController.frameWidth, ScreenController.frameHeight)); GameShell.clientFrame.setMinimumSize(new Dimension(ScreenController.frameWidth, ScreenController.frameHeight)); + + renderer = new FixedFrameRenderer(); } else if (screenMode == ScreenMode.RESIZABLE) { frameWidth = 900; frameHeight = 637; @@ -48,10 +68,12 @@ public static void frameMode(ScreenMode screenMode) { GameShell.clientFrame.setPreferredSize(new Dimension(ScreenController.frameWidth, ScreenController.frameHeight)); GameShell.clientFrame.setMinimumSize(new Dimension(ScreenController.frameWidth, ScreenController.frameHeight)); - + renderer = new ResizableFrameRenderer(rasterizer); } else if (screenMode == ScreenMode.FULLSCREEN) { frameWidth = (int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(); frameHeight = (int) Toolkit.getDefaultToolkit().getScreenSize().getHeight(); + + renderer = new ResizableFrameRenderer(rasterizer); } GameShell.clientFrame.setSize(ScreenController.frameWidth, ScreenController.frameHeight); Dimension innerSize = getInnerSize(GameShell.clientFrame); @@ -88,21 +110,24 @@ public static void setBounds() { Dimension innerSize = getInnerSize(GameShell.clientFrame); drawHeight = innerSize.height; drawWidth = innerSize.width; - Rasterizer3D.prepare(null, frameMode == ScreenMode.FIXED ? 512 : drawWidth, frameMode == ScreenMode.FIXED ? 334 : drawHeight); + + renderer.setDrawSize(drawWidth, drawHeight); + + Rasterizer.prepare(null, frameMode == ScreenMode.FIXED ? 512 : drawWidth, frameMode == ScreenMode.FIXED ? 334 : drawHeight); MovedStatics.fullScreenTextureArray = Rasterizer3D.setLineOffsets(null); - Rasterizer3D.prepare(null, frameMode == ScreenMode.FIXED ? 479 : drawWidth, frameMode == ScreenMode.FIXED ? 96 : drawHeight); + Rasterizer.prepare(null, frameMode == ScreenMode.FIXED ? 479 : drawWidth, frameMode == ScreenMode.FIXED ? 96 : drawHeight); // TODO rethink this, maybe its way easier than this // MovedStatics.chatboxLineOffsets = Rasterizer3D.setLineOffsets(null); // Rasterizer3D.prepare(null, frameMode == ScreenMode.FIXED ? 190 : drawWidth, frameMode == ScreenMode.FIXED ? 261 : drawHeight); MovedStatics.sidebarOffsets = Rasterizer3D.setLineOffsets(null); - Rasterizer3D.prepare(null, frameMode == ScreenMode.FIXED ? 765 : drawWidth, frameMode == ScreenMode.FIXED ? 503 : drawHeight); + Rasterizer.prepare(null, frameMode == ScreenMode.FIXED ? 765 : drawWidth, frameMode == ScreenMode.FIXED ? 503 : drawHeight); Player.viewportOffsets = Rasterizer3D.setLineOffsets(null); int[] is = new int[9]; for (int i = 0; i < 9; i++) { int i_0_ = 15 + 32 * i + 128; int i_1_ = 3 * i_0_ + 600; - int i_2_ = Rasterizer3D.sinetable[i_0_]; + int i_2_ = Constants3D.sinetable[i_0_]; is[i] = i_2_ * i_1_ >> 16; } @@ -111,7 +136,8 @@ public static void setBounds() { Game.gameCanvas.setSize(ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight); if (Game.gameStatusCode <= 35 && Game.gameStatusCode >= 30) { - MovedStatics.gameScreenImageProducer = MovedStatics.createGraphicsBuffer(ScreenController.frameMode == ScreenMode.FIXED ? 512 : ScreenController.drawWidth, ScreenController.frameMode == ScreenMode.FIXED ? 334 : ScreenController.drawHeight, GameShell.clientFrame); + // set to resizable mode + setDrawComponent(GameShell.clientFrame); } else { Game.gameCanvas.setSize(MovedStatics.width, MovedStatics.height); Game.gameCanvas.setVisible(true); @@ -124,69 +150,12 @@ public static void setBounds() { } } - /** - * TODO (jkm) move all this to ResizableFrameRenderer - */ - public static void RenderResizableUI() { - if (drawingThread == null) { - renderer = new ResizableFrameRenderer(minimap, tabProducer); - drawingThread = new Thread(renderer); - drawingThread.start(); - } - minimap.drawResizableMiniMapArea(drawWidth - 210, 0); - RenderTabArea(drawWidth - 234, drawHeight - (337)); - RenderChatArea(0, drawHeight - (162)); - - tabProducer.drawResizableSideBarArea(drawWidth - 241, drawHeight - (334)); - - if (DebugView) { - int mX = MouseHandler.mouseX; - int mY = MouseHandler.mouseY; - - int[] tabInterFaceCoords= tabProducer.getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); - int[] tabInterFaceTop = tabProducer.getTopBarCoordSize(drawWidth - 241, drawHeight - (334)); - int[] tabInterFaceBottom = tabProducer.getBottomBarCoordSize(drawWidth - 241, drawHeight - (334)); - if (isCoordinatesIn3dScreen(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(0, 0, drawWidth, drawHeight, 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(0, 0, drawWidth, drawHeight, 0xFF00FF, 90); - } - if (isCoordinatesInExtendedTabArea(mX, mY) && !isCoordinatesInTabArea(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(tabInterFaceTop[0], tabInterFaceTop[1], tabInterFaceTop[2], tabInterFaceTop[3], 0x00FF00, 90); - Rasterizer.drawFilledRectangleAlpha(tabInterFaceBottom[0], tabInterFaceBottom[1], tabInterFaceBottom[2], tabInterFaceBottom[3], 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(tabInterFaceTop[0], tabInterFaceTop[1], tabInterFaceTop[2], tabInterFaceTop[3], 0x0000FF, 90); - Rasterizer.drawFilledRectangleAlpha(tabInterFaceBottom[0], tabInterFaceBottom[1], tabInterFaceBottom[2], tabInterFaceBottom[3], 0x0000FF, 90); - } - if (isCoordinatesInTabArea(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(tabInterFaceCoords[0], tabInterFaceCoords[1], MovedStatics.tabImageProducer.width, MovedStatics.tabImageProducer.height, 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(tabInterFaceCoords[0], tabInterFaceCoords[1], MovedStatics.tabImageProducer.width, MovedStatics.tabImageProducer.height, 0x0000FF, 90); - } - if (isCoordinatesInExtendedChatArea(mX, mY) && !isCoordinatesInChatArea(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(0, drawHeight - (162), 516, drawHeight, 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(0, drawHeight - (162), 516, drawHeight, 0x0000FF, 90); - } - if (isCoordinatesInChatArea(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(17, drawHeight - (162) + 16, ChatBox.chatBoxImageProducer.width, ChatBox.chatBoxImageProducer.height, 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(17, drawHeight - (162) + 16, ChatBox.chatBoxImageProducer.width, ChatBox.chatBoxImageProducer.height, 0x0000FF, 90); - } - if (isCoordinatesInMinimapArea(mX, mY)) { - Rasterizer.drawFilledRectangleAlpha(drawWidth - 210, 0, 210, 210, 0x00FF00, 90); - } else { - Rasterizer.drawFilledRectangleAlpha(drawWidth - 210, 0, 210, 210, 0x0000FF, 90); - } - - - Rasterizer.drawFilledRectangle(MouseHandler.mouseX - 4, MouseHandler.mouseY - 4, 4, 4, 0xFF0000); - } - - if (MovedStatics.menuOpen) { - MovedStatics.drawMenu(0, 0); - } + public static void drawFrame() { + // create the render thread if required, and draw the output to screen + int mX = MouseHandler.mouseX; + int mY = MouseHandler.mouseY; + renderer.draw(mX, mY, DebugView); } @@ -200,100 +169,29 @@ public static Dimension getInnerSize(Frame frame) { return size; } - /** - * TODO (jkm) move all this to ResizableFrameRenderer - */ - public static void RenderTabArea(int x, int y) { - // height 337 - // width 234 - drawFramePiece(MovedStatics.tabPieceLeft, x + 212, y + 39); - drawFramePieceCutout(MovedStatics.tabPieceUpperRight, x, y + 39, MovedStatics.tabPieceUpperRight.width - 15, MovedStatics.tabPieceUpperRight.height, 15, 0); - drawFramePieceCutout(MovedStatics.tabPieveLowerRight, x, y + 191, MovedStatics.tabPieveLowerRight.width - 35, MovedStatics.tabPieveLowerRight.height, 35, 0); - drawFramePieceCutout(MovedStatics.chatboxTop, x, y + 172, MovedStatics.chatboxTop.width - 531, MovedStatics.chatboxTop.height, 531, 0); - drawFramePieceCutout(MovedStatics.tabBottom, x, y + 300, MovedStatics.tabBottom.width - 35, MovedStatics.tabBottom.height, 35, 0); - drawFramePieceCutout(MovedStatics.tabTop, x, y, MovedStatics.tabTop.width - 15, MovedStatics.tabTop.height - 6, 15, 6); - drawFramePiece(MovedStatics.tabImageProducer, x + 22, y + 39); - } - - /** - * TODO (jkm) move all this to ResizableFrameRenderer - */ - public static void RenderChatArea(int x, int y) { - //width 516 - //height 184 - drawFramePiece(ChatBox.chatBoxImageProducer, x + 17, y + 16); - drawFramePiece(MovedStatics.chatModes, x, y + 112); - drawFramePieceCutout(MovedStatics.tabBottom, x + 496, y + 125, 20, MovedStatics.tabBottom.height, 0, 0); - drawFramePiece(MovedStatics.chatboxRight, x, y + 16); - drawFramePieceCutout(MovedStatics.chatboxTop, x, y, MovedStatics.chatboxTop.width - 37, MovedStatics.chatboxTop.height - 3, 0, 3); - // System.out.println(Class40_Sub5_Sub1.chatboxRight.height + (Class17.chatboxTop.height-3) + HuffmanEncoding.aProducingGraphicsBuffer_1541.height); - - drawFramePieceCutout(MovedStatics.tabPieveLowerRight, x + 496, y + 16, 20, MovedStatics.tabPieveLowerRight.height, 0, 0); - } - - public static void drawFramePiece(ProducingGraphicsBuffer framePiece, int x, int y) { - Rasterizer.copyPixels(framePiece.pixels, framePiece.width, framePiece.height, x, y); - } - - public static void drawFramePieceCutout(ProducingGraphicsBuffer framePiece, int x, int y, int width, int height, int offsetX, int offsetY) { - Rasterizer.copyPixelsCutOff(framePiece.pixels, framePiece.width, framePiece.height, x, y, width, height, offsetX, offsetY); - } - public static boolean isCoordinatesIn3dScreen(int x, int y) { - if (frameMode == ScreenMode.FIXED) { - return x > 4 && y > 4 && x < 516 && y < 338; - } else { - return x > 0 && y > 0 && x < drawWidth && y < drawHeight && !isCoordinatesInExtendedTabArea(x, y) && !isCoordinatesInTabArea(x, y) && !isCoordinatesInMinimapArea(x, y) && !isCoordinatesInExtendedChatArea(x, y); - - } + return renderer.isCoordinatesIn3dScreen(x, y); } public static boolean isCoordinatesInTabArea(int x, int y) { - if (frameMode == ScreenMode.FIXED) { - return x > 553 && y > 205 && x < 743 && y < 466; - } else { - int[] tabInterFaceCoords= tabProducer.getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); - - int minX = tabInterFaceCoords[0]; - int minY = tabInterFaceCoords[1]; - int maxX = minX + tabInterFaceCoords[2]; - int maxY = minY + tabInterFaceCoords[3]; - return x > minX && y > minY && x < maxX && y < maxY; - } + return renderer.isCoordinatesInTabArea(x, y); } public static boolean isCoordinatesInExtendedTabArea(int x, int y) { - int[] top = tabProducer.getTopBarCoordSize(drawWidth - 241, drawHeight - (334)); - int[] bottom = tabProducer.getBottomBarCoordSize(drawWidth - 241, drawHeight - (334)); - if(x > top[0] && x < top[0]+top[2] && y > top[1] && y < top[1]+top[3]) { - return true; - } else return x > bottom[0] && x < bottom[0] + bottom[2] && y > bottom[1] && y < bottom[1] + bottom[3]; + return renderer.isCoordinatesInExtendedTabArea(x, y); } public static boolean isCoordinatesInExtendedChatArea(int x, int y) { - return x > 0 && y > drawHeight - 184 && x < 516; + return renderer.isCoordinatesInExtendedChatArea(x, y); } public static boolean isCoordinatesInChatArea(int x, int y) { - if (frameMode == ScreenMode.FIXED) { - return x > 17 && y > 357 && x < 496 && y < 453; - } else { - int minX = 17; - int minY = drawHeight - (162) + 16; - int maxX = minX + ChatBox.chatBoxImageProducer.width; - int maxY = minY + ChatBox.chatBoxImageProducer.height; - return x > minX && y > minY && x < maxX && y < maxY; - } - + return renderer.isCoordinatesInChatArea(x, y); } public static boolean isCoordinatesInMinimapArea(int x, int y) { - if (frameMode == ScreenMode.FIXED) { - return x > 575 && y < 156; - } else { - return x > drawWidth - 210 && y < 210; - } + return renderer.isCoordinatesInMinimapArea(x, y); } public static void handleTabClick(int mouseX, int mouseY) { @@ -304,7 +202,7 @@ else if (Game.tabWidgetIds[Game.currentTabId] != -1) { MovedStatics.handleInterfaceActions(GameInterfaceArea.TAB_AREA, mouseX, mouseY, 553, 205, 743, 466, Game.tabWidgetIds[Game.currentTabId]); } } else { - int[] tabInterFaceCoords= tabProducer.getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); + int[] tabInterFaceCoords= renderer.getTabProducer().getTabInterfaceCoordSize(drawWidth - 241, drawHeight - (334)); if (GameInterface.tabAreaInterfaceId != -1) MovedStatics.handleInterfaceActions(GameInterfaceArea.TAB_AREA, mouseX, mouseY, tabInterFaceCoords[0], tabInterFaceCoords[1], tabInterFaceCoords[0]+tabInterFaceCoords[2],tabInterFaceCoords[1]+tabInterFaceCoords[3], GameInterface.tabAreaInterfaceId); @@ -374,8 +272,8 @@ public static void handleMinimapMouse() { } } int angle = 0x7ff & Game.getMinimapRotation(); - int sin = Rasterizer3D.sinetable[angle]; - int cos = Rasterizer3D.cosinetable[angle]; + int sin = Constants3D.sinetable[angle]; + int cos = Constants3D.cosinetable[angle]; int zoom = 0; @@ -554,7 +452,7 @@ public static void handleTabClick() { } } else { if(isCoordinatesInExtendedTabArea(x, y)) { - tabProducer.clickTabButton(x,y, drawWidth - 241, drawHeight - (334)); + renderer.getTabProducer().clickTabButton(x,y, drawWidth - 241, drawHeight - (334)); } } diff --git a/src/main/java/org/runejs/client/frame/console/Console.java b/src/main/java/org/runejs/client/frame/console/Console.java index dbd891a87..0161bc401 100644 --- a/src/main/java/org/runejs/client/frame/console/Console.java +++ b/src/main/java/org/runejs/client/frame/console/Console.java @@ -4,7 +4,7 @@ import org.runejs.client.cache.media.TypeFace; import org.runejs.client.cache.media.gameInterface.GameInterface; import org.runejs.client.frame.ChatBox; -import org.runejs.client.media.Rasterizer; +import org.runejs.client.frame.ScreenController; import org.runejs.client.message.outbound.console.ConsoleCommandOutboundMessage; import org.runejs.client.net.OutgoingPackets; import org.runejs.client.frame.console.Commands.*; @@ -81,14 +81,14 @@ public void drawConsole(int width, int height) { if (consoleOpen) { int scrollpos = getMaxScroll() - currentScroll - 310; if (messageCount > 17) { - GameInterface.drawScrollBar(width - 18, 0, height-21, scrollpos, getMaxScroll()); + GameInterface.drawScrollBar(ScreenController.rasterizer, width - 18, 0, height-21, scrollpos, getMaxScroll()); } if (alpha) { - Rasterizer.drawFilledRectangleAlpha(0, 0, width, height, 0x513092, 97); + ScreenController.rasterizer.drawFilledRectangleAlpha(0, 0, width, height, 0x513092, 97); } else { - Rasterizer.drawFilledRectangle(0, 0, width, height, 0x513092); + ScreenController.rasterizer.drawFilledRectangle(0, 0, width, height, 0x513092); } - Rasterizer.drawHorizontalLine(1, height-19, width, 0xffffff); + ScreenController.rasterizer.drawHorizontalLine(1, height-19, width, 0xffffff); TypeFace.fontBold.setEffects(0xffffff, -1); TypeFace.fontBold.drawBasicString(">", 11, height-4); if (this.versionWidth == -1) { diff --git a/src/main/java/org/runejs/client/frame/tab/TabProducer.java b/src/main/java/org/runejs/client/frame/tab/TabProducer.java index 87f5bb7ca..04aa8d49a 100644 --- a/src/main/java/org/runejs/client/frame/tab/TabProducer.java +++ b/src/main/java/org/runejs/client/frame/tab/TabProducer.java @@ -2,18 +2,15 @@ import org.runejs.client.Game; import org.runejs.client.MovedStatics; -import org.runejs.client.ProducingGraphicsBuffer; import org.runejs.client.cache.media.ImageRGB; import org.runejs.client.cache.media.gameInterface.GameInterface; +import org.runejs.client.frame.FramePieceAnchor; import org.runejs.client.frame.FramePieceRenderer; -import org.runejs.client.frame.ScreenController; import org.runejs.client.frame.tab.parts.TabParts; import org.runejs.client.media.RasterizerInstanced; // TODO: DONT RUN NORMAL TAB RENDERER WHEN THIS IS RUNNING public class TabProducer extends FramePieceRenderer { - private static ProducingGraphicsBuffer resizableSideBarImage; - private ProducingGraphicsBuffer tempResizableSideBar; private ImageRGB edgeLeft; private ImageRGB edgeRight; private ImageRGB combat; @@ -42,12 +39,28 @@ public class TabProducer extends FramePieceRenderer { private static int workingWidth = 232; private static int workingHeight = 334; + /** + * To avoid flickering, we draw to a temporary rasterizer first, + * then flush this to the output rasterizer at once, in its entirety. + */ + private RasterizerInstanced rasterizerTemp; + public TabProducer() { - this.tempResizableSideBar = MovedStatics.createGraphicsBuffer(241, 334, Game.gameCanvas); - resizableSideBarImage = MovedStatics.createGraphicsBuffer(241, 334, Game.gameCanvas); - rasterizerInstanced = new RasterizerInstanced(this.tempResizableSideBar); - rasterizerInstanced.drawFilledRectangle(0, 0, 241, 334, Integer.MAX_VALUE); + super( + new FramePieceAnchor( + FramePieceAnchor.Anchor.BOTTOM | FramePieceAnchor.Anchor.RIGHT, + 0, + 0 + ), + 241, + 334 + ); + + rasterizerTemp = new RasterizerInstanced( + MovedStatics.createGraphicsBuffer(this.width, this.height, Game.gameCanvas) + ); + rasterizerTemp.drawFilledRectangle(0, 0, 241, 334, Integer.MAX_VALUE); } private void drawActiveTab(int currentTabId, int currentY) { @@ -99,7 +112,7 @@ private void drawActiveTab(int currentTabId, int currentY) { x = 202; break; } - drawImage(part, x,currentY); + rasterizerTemp.drawImage(part, x,currentY); } public int[] getTabButtonStartCoords(int tabButtonIndex) { @@ -153,12 +166,6 @@ public int[] getTabButtonBox(int tabButtonIndex) { return new int[] {start[0],start[1], end[0], start[1]+ topbar[3]}; } - - - public void drawResizableSideBarArea(int x, int y) { - ScreenController.drawFramePiece(resizableSideBarImage, x, y); - } - public int[] getTabInterfaceCoordSize(int baseX, int baseY) { if(MovedStatics.tabImageProducer == null) { return new int[]{0,0,0,0}; @@ -198,14 +205,14 @@ private void drawMiddlePiece(int baseX, int baseY, int width, int height) { if(MovedStatics.tabImageProducer == null) { return; } - rasterizerInstanced.copyPixels( + rasterizerTemp.copyPixels( MovedStatics.tabImageProducer.pixels, MovedStatics.tabImageProducer.width, MovedStatics.tabImageProducer.height, baseX + width / 2 - MovedStatics.tabImageProducer.width / 2, baseY + height / 2 - MovedStatics.tabImageProducer.height / 2); - drawImage(edgeLeft, baseX, baseY + height / 2 - edgeLeft.imageHeight / 2); - drawImage(edgeRight, baseX + width - edgeRight.imageWidth, baseY + height / 2 - edgeRight.imageHeight / 2); + rasterizerTemp.drawImage(edgeLeft, baseX, baseY + height / 2 - edgeLeft.imageHeight / 2); + rasterizerTemp.drawImage(edgeRight, baseX + width - edgeRight.imageWidth, baseY + height / 2 - edgeRight.imageHeight / 2); } public void RenderResizableSideBarArea() { @@ -239,24 +246,23 @@ public void RenderResizableSideBarArea() { int y = 0; - drawImage(background, x + 24, y + 20); - drawImage(background, x + 24 + background.imageWidth, y + 20); - drawImage(background, x + 24 + background.imageWidth + 20, y + 20); + rasterizerTemp.drawImage(background, x + 24, y + 20); + rasterizerTemp.drawImage(background, x + 24 + background.imageWidth, y + 20); + rasterizerTemp.drawImage(background, x + 24 + background.imageWidth + 20, y + 20); - drawImage(background, x + 24, y + workingHeight - background.imageHeight - 20); - drawImage(background, x + 24 + background.imageWidth, y + workingHeight - background.imageHeight - 20); - drawImage(background, x + 24 + background.imageWidth + 20, y + workingHeight - background.imageHeight - 20); + rasterizerTemp.drawImage(background, x + 24, y + workingHeight - background.imageHeight - 20); + rasterizerTemp.drawImage(background, x + 24 + background.imageWidth, y + workingHeight - background.imageHeight - 20); + rasterizerTemp.drawImage(background, x + 24 + background.imageWidth + 20, y + workingHeight - background.imageHeight - 20); drawMiddlePiece(x, y, workingWidth, workingHeight); drawTopRow(x, y, workingWidth, workingHeight); drawBottomRow(x, y, workingWidth, workingHeight); - System.arraycopy(tempResizableSideBar.pixels, 0, resizableSideBarImage.pixels, 0, resizableSideBarImage.pixels.length); - + System.arraycopy(rasterizerTemp.destinationPixels, 0, rasterizerInstanced.destinationPixels,0, rasterizerInstanced.destinationPixels.length); } private void drawBottomRow(int x, int y, int workingWidth, int workingHeight) { - drawImage(bottomRow, x - 4, y + workingHeight - bottomRow.imageHeight); + rasterizerTemp.drawImage(bottomRow, x - 4, y + workingHeight - bottomRow.imageHeight); int currentX = x; int currentY = y + workingHeight - bottomRow.imageHeight; if (6 < Game.currentTabId) { @@ -264,40 +270,40 @@ private void drawBottomRow(int x, int y, int workingWidth, int workingHeight) { } currentX += combat.imageWidth; - drawImage(friends, currentX, currentY); + rasterizerTemp.drawImage(friends, currentX, currentY); currentX += combat.imageWidth; - drawImage(ignores, currentX, currentY); + rasterizerTemp.drawImage(ignores, currentX, currentY); currentX += combat.imageWidth; - drawImage(logout, currentX, currentY); + rasterizerTemp.drawImage(logout, currentX, currentY); currentX += combat.imageWidth; - drawImage(options, currentX, currentY); + rasterizerTemp.drawImage(options, currentX, currentY); currentX += combat.imageWidth; - drawImage(emotes, currentX, currentY); + rasterizerTemp.drawImage(emotes, currentX, currentY); currentX += combat.imageWidth; - drawImage(music, currentX, currentY); + rasterizerTemp.drawImage(music, currentX, currentY); } private void drawTopRow(int x, int y, int workingWidth, int workingHeight) { - drawImage(topRow, x - 4, y); + rasterizerTemp.drawImage(topRow, x - 4, y); if (Game.currentTabId < 7) { this.drawActiveTab(Game.currentTabId, y); } int currentX = x; - drawImage(combat, currentX, y); + rasterizerTemp.drawImage(combat, currentX, y); currentX += stats.imageWidth; - drawImage(stats, currentX, y); + rasterizerTemp.drawImage(stats, currentX, y); currentX += stats.imageWidth; - drawImage(quests, currentX, y); + rasterizerTemp.drawImage(quests, currentX, y); currentX += stats.imageWidth; - drawImage(inventory, currentX, y); + rasterizerTemp.drawImage(inventory, currentX, y); currentX += stats.imageWidth; - drawImage(equipment, currentX, y); + rasterizerTemp.drawImage(equipment, currentX, y); currentX += stats.imageWidth; - drawImage(prayer, currentX, y); + rasterizerTemp.drawImage(prayer, currentX, y); currentX += stats.imageWidth; - drawImage(magic, currentX, y); + rasterizerTemp.drawImage(magic, currentX, y); } private static void RenderCustomTabArea(int baseX, int baseY) { diff --git a/src/main/java/org/runejs/client/media/ColorUtils.java b/src/main/java/org/runejs/client/media/ColorUtils.java new file mode 100644 index 000000000..f7734bf3a --- /dev/null +++ b/src/main/java/org/runejs/client/media/ColorUtils.java @@ -0,0 +1,19 @@ +package org.runejs.client.media; + +public class ColorUtils { + public static int adjustBrightness(int rgb, double brightness) { + double r = (double) (rgb >> 16) / 256.0; + double g = (double) (rgb >> 8 & 0xff) / 256.0; + double b = (double) (rgb & 0xff) / 256.0; + + r = Math.pow(r, brightness); + g = Math.pow(g, brightness); + b = Math.pow(b, brightness); + + int outR = (int) (r * 256.0); + int outG = (int) (g * 256.0); + int outB = (int) (b * 256.0); + + return (outR << 16) + (outG << 8) + outB; + } +} diff --git a/src/main/java/org/runejs/client/media/Constants3D.java b/src/main/java/org/runejs/client/media/Constants3D.java new file mode 100644 index 000000000..3e7a73b31 --- /dev/null +++ b/src/main/java/org/runejs/client/media/Constants3D.java @@ -0,0 +1,38 @@ +package org.runejs.client.media; + +public class Constants3D { + public static int[] cosinetable = new int[2048]; + public static int[] sinetable = new int[2048]; + /** + * Some kind of colour information, Dane calls this "reciprocal16" + */ + public static int[] anIntArray2929 = new int[2048]; + public static int[] shadowDecay = new int[512]; + + static { + for(int i = 1; i < 512; i++) { + Constants3D.shadowDecay[i] = 32768 / i; + } + for(int i = 1; i < 2048; i++) { + Constants3D.anIntArray2929[i] = 65536 / i; + } + for(int i = 0; i < 2048; i++) { + // Pre-calculate sin and cos to save memory + // + // Circumference / Cuts = Cut radians + // Cuts defines how many angles around the circle we want to store, so in this case: + // PI * 2 / 2048 = 0.0030679615 radians + // + // Furthermore, 65536 * x is something we call fixed point arithmetics. It is used to store decimals as an integer instead of a double. + // 65536 = 2^16, so 16 is the scaling factor + // The original value can be restored by dividing x by (2^scalingFactor) or just bit-shifting x right by the scaling factor + // Note that when bit-shifting, you lose all the decimals, and only get the whole number. This is the most common + // practice wherever the sin and cos tables are used in the client + // + // Also, don't forget your basic maths: sin(x) = the length of the opposite side, cos(x) = the length of the adjacent side + // sin(x) + cos(x) = r + Constants3D.sinetable[i] = (int) (65536.0 * Math.sin((double) i * 0.0030679615)); + Constants3D.cosinetable[i] = (int) (65536.0 * Math.cos((double) i * 0.0030679615)); + } + } +} diff --git a/src/main/java/org/runejs/client/media/Palette.java b/src/main/java/org/runejs/client/media/Palette.java new file mode 100644 index 000000000..62b5f5466 --- /dev/null +++ b/src/main/java/org/runejs/client/media/Palette.java @@ -0,0 +1,89 @@ +package org.runejs.client.media; + +public class Palette { + public final int[] hsl2rgb; + + public Palette(int[] hsl2rgb) { + this.hsl2rgb = hsl2rgb; + } + + public static Palette create(double brightness) { + int[] hsl2rgb = new int[65536]; + + brightness += Math.random() * 0.03 - 0.015; + int index = 0; + + for(int y = 0; y < 512; y++) { + double hue = (double) (y >> 3) / 64.0 + 0.0078125; + double lightness = (double) (y & 0x7) / 8.0 + 0.0625; + + for(int x = 0; x < 128; x++) { + double intensity = (double) x / 128.0; + double red = intensity; + double green = intensity; + double blue = intensity; + + if(lightness != 0.0) { + double a; + if(intensity < 0.5) { + a = intensity * (1.0 + lightness); + } else { + a = intensity + lightness - intensity * lightness; + } + double b = 2.0 * intensity - a; + double fRed = hue + 0.3333333333333333; + if(fRed > 1.0) { + fRed--; + } + double fGreen = hue; + double fBlue = hue - 0.3333333333333333; + if(fBlue < 0.0) { + fBlue++; + } + if(6.0 * fRed < 1.0) { + red = b + (a - b) * 6.0 * fRed; + } else if(2.0 * fRed < 1.0) { + red = a; + } else if(3.0 * fRed < 2.0) { + red = b + (a - b) * (0.6666666666666666 - fRed) * 6.0; + } else { + red = b; + } + if(6.0 * fGreen < 1.0) { + green = b + (a - b) * 6.0 * fGreen; + } else if(2.0 * fGreen < 1.0) { + green = a; + } else if(3.0 * fGreen < 2.0) { + green = b + (a - b) * (0.6666666666666666 - fGreen) * 6.0; + } else { + green = b; + } + if(6.0 * fBlue < 1.0) { + blue = b + (a - b) * 6.0 * fBlue; + } else if(2.0 * fBlue < 1.0) { + blue = a; + } else if(3.0 * fBlue < 2.0) { + blue = b + (a - b) * (0.6666666666666666 - fBlue) * 6.0; + } else { + blue = b; + } + } + + int outR = ((int) (red * 256.0) << 16); + int outG = ((int) (green * 256.0) << 8); + int outB = ((int) (blue * 256.0)); + + int rgb = outR | outG | outB; + rgb = ColorUtils.adjustBrightness(rgb, brightness); + + if(rgb == 0) { + rgb = 1; + } + + hsl2rgb[index++] = rgb; + } + } + + return new Palette(hsl2rgb); + } +} diff --git a/src/main/java/org/runejs/client/media/Rasterizer.java b/src/main/java/org/runejs/client/media/Rasterizer.java index 0eb31552d..f111b621c 100644 --- a/src/main/java/org/runejs/client/media/Rasterizer.java +++ b/src/main/java/org/runejs/client/media/Rasterizer.java @@ -20,9 +20,9 @@ public class Rasterizer extends CachedNode { private static final int[] tmpY = new int[64]; public static void prepare(int[] pixels, int width, int height) { - Rasterizer.destinationPixels = pixels; - Rasterizer.destinationWidth = width; - Rasterizer.destinationHeight = height; + destinationPixels = pixels; + destinationWidth = width; + destinationHeight = height; setBounds(0, 0, width, height); } @@ -41,10 +41,10 @@ public static void setBounds(int minX, int minY, int maxX, int maxY) { minX = 0; if(minY < 0) minY = 0; - if(maxX > Rasterizer.destinationWidth) - maxX = Rasterizer.destinationWidth; - if(maxY > Rasterizer.destinationHeight) - maxY = Rasterizer.destinationHeight; + if(maxX > destinationWidth) + maxX = destinationWidth; + if(maxY > destinationHeight) + maxY = destinationHeight; viewportLeft = minX; viewportTop = minY; viewportRight = maxX; @@ -103,8 +103,8 @@ public static void drawFilledRectangle(int x, int y, int width, int height, int width = viewportRight - x; if(y + height > viewportBottom) height = viewportBottom - y; - int pixelOffset = Rasterizer.destinationWidth - width; - int pixel = x + y * Rasterizer.destinationWidth; + int pixelOffset = destinationWidth - width; + int pixel = x + y * destinationWidth; for(int heightCounter = -height; heightCounter < 0; heightCounter++) { for(int widthCounter = -width; widthCounter < 0; widthCounter++) destinationPixels[pixel++] = colour; @@ -134,8 +134,8 @@ public static void copyPixels(int[] pixels, int width, int height, int paintX, i width = viewportRight - paintX; if(paintY + height > viewportBottom) height = viewportBottom - paintY; - int pixelOffset = Rasterizer.destinationWidth - width; - int pixel = paintX + paintY * Rasterizer.destinationWidth; + int pixelOffset = destinationWidth - width; + int pixel = paintX + paintY * destinationWidth; for(int heightCounter = -height; heightCounter < 0; heightCounter++) { for(int widthCounter = -width; widthCounter < 0; widthCounter++) { if(pixels[sourcePixel] != Integer.MAX_VALUE) { @@ -162,8 +162,8 @@ public static void copyPixelsCutOff(int[] pixels, int srcWidth, int srcHeight, i drawWidth = viewportRight - paintX; if(paintY + drawHeight > viewportBottom) drawHeight = viewportBottom - paintY; - int pixelOffset = Rasterizer.destinationWidth - (drawWidth); - int pixel = paintX + paintY * Rasterizer.destinationWidth; + int pixelOffset = destinationWidth - (drawWidth); + int pixel = paintX + paintY * destinationWidth; for(int heightCounter = -(drawHeight); heightCounter < 0; heightCounter++) { for(int widthCounter = -(drawWidth); widthCounter < 0; widthCounter++) destinationPixels[pixel++] = pixels[sourcePixel++]; @@ -269,12 +269,12 @@ public static void drawCircleAlpha(int x, int y, int radius, int color, int alph int g = (color >> 8 & 255) * alpha; int b = (color & 255) * alpha; int topY = y - radius; - if (topY < Rasterizer.viewportTop) { - topY = Rasterizer.viewportTop; + if (topY < viewportTop) { + topY = viewportTop; } int bottomY = y + radius + 1; - if (bottomY > Rasterizer.viewportBottom) { - bottomY = Rasterizer.viewportBottom; + if (bottomY > viewportBottom) { + bottomY = viewportBottom; } int var14 = topY; int var15 = radius * radius; @@ -306,7 +306,7 @@ public static void drawCircleAlpha(int x, int y, int radius, int color, int alph if (var21 > viewportRight) { var21 = viewportRight; } - var22 = var20 + var14 * Rasterizer.destinationWidth; + var22 = var20 + var14 * destinationWidth; for (var23 = var20; var23 < var21; ++var23) { var9 = (destinationPixels[var22] >> 16 & 255) * a; var10 = (destinationPixels[var22] >> 8 & 255) * a; @@ -335,7 +335,7 @@ public static void drawCircleAlpha(int x, int y, int radius, int color, int alph if (var21 > viewportRight - 1) { var21 = viewportRight - 1; } - var22 = var20 + var14 * Rasterizer.destinationWidth; + var22 = var20 + var14 * destinationWidth; for (var23 = var20; var23 <= var21; ++var23) { var9 = (destinationPixels[var22] >> 16 & 255) * a; var10 = (destinationPixels[var22] >> 8 & 255) * a; @@ -443,8 +443,8 @@ public static void drawFilledRectangleAlpha(int x, int y, int width, int height, int r = (colour >> 16 & 0xff) * alpha; int g = (colour >> 8 & 0xff) * alpha; int b = (colour & 0xff) * alpha; - int widthOffset = Rasterizer.destinationWidth - width; - int pixel = x + y * Rasterizer.destinationWidth; + int widthOffset = destinationWidth - width; + int pixel = x + y * destinationWidth; for(int heightCounter = 0; heightCounter < height; heightCounter++) { for(int widthCounter = -width; widthCounter < 0; widthCounter++) { int red = (destinationPixels[pixel] >> 16 & 0xff) * a; diff --git a/src/main/java/org/runejs/client/media/Rasterizer3D.java b/src/main/java/org/runejs/client/media/Rasterizer3D.java index 6feae569b..5351c3ad5 100644 --- a/src/main/java/org/runejs/client/media/Rasterizer3D.java +++ b/src/main/java/org/runejs/client/media/Rasterizer3D.java @@ -2,14 +2,13 @@ import org.runejs.client.Interface3; -public class Rasterizer3D extends Rasterizer { - /** - * Some kind of colour information, Dane calls this "reciprocal16" - */ - public static int[] anIntArray2929 = new int[2048]; +public class Rasterizer3D { + public static boolean lowMemory = false; + + public static Palette palette; + public static int bottomY; public static int center_y; - public static int[] hsl2rgb = new int[65536]; public static int alpha = 0; /** * x position/size info of some kind @@ -27,7 +26,6 @@ public class Rasterizer3D extends Rasterizer { public static int center_x; public static int[] lineOffsets; public static Interface3 interface3; - public static int[] shadowDecay = new int[512]; /** * y position/size info of some kind * @@ -40,44 +38,14 @@ public class Rasterizer3D extends Rasterizer { * TODO rename */ public static int anInt2942; - public static int[] sinetable = new int[2048]; /** * TODO (jkm) investigate and rename, don't think this is accurate */ public static boolean notTextured = true; public static int viewportRx; - public static int[] cosinetable = new int[2048]; public static boolean restrict_edges = false; - public static boolean lowMemory = false; private static boolean useLatestShadeLine = true; - static { - for(int i = 1; i < 512; i++) { - shadowDecay[i] = 32768 / i; - } - for(int i = 1; i < 2048; i++) { - anIntArray2929[i] = 65536 / i; - } - for(int i = 0; i < 2048; i++) { - // Pre-calculate sin and cos to save memory - // - // Circumference / Cuts = Cut radians - // Cuts defines how many angles around the circle we want to store, so in this case: - // PI * 2 / 2048 = 0.0030679615 radians - // - // Furthermore, 65536 * x is something we call fixed point arithmetics. It is used to store decimals as an integer instead of a double. - // 65536 = 2^16, so 16 is the scaling factor - // The original value can be restored by dividing x by (2^scalingFactor) or just bit-shifting x right by the scaling factor - // Note that when bit-shifting, you lose all the decimals, and only get the whole number. This is the most common - // practice wherever the sin and cos tables are used in the client - // - // Also, don't forget your basic maths: sin(x) = the length of the opposite side, cos(x) = the length of the adjacent side - // sin(x) + cos(x) = r - sinetable[i] = (int) (65536.0 * Math.sin((double) i * 0.0030679615)); - cosinetable[i] = (int) (65536.0 * Math.cos((double) i * 0.0030679615)); - } - } - public static void drawScanLine(int[] dest, int destOffset, int color, int startX, int endX) { // restrict_edges indicates if there's a need to restrict the drawing operation within certain boundaries (viewport) if(restrict_edges) { @@ -703,7 +671,7 @@ public static void drawTexturedLine(int[] dest, int[] texture, int dest_off, int } else { if(end_x - start_x > 7) { k3 = end_x - start_x >> 3; - j3 = (gradient - shadeValue) * shadowDecay[k3] >> 6; + j3 = (gradient - shadeValue) * Constants3D.shadowDecay[k3] >> 6; } else { k3 = 0; j3 = 0; @@ -1082,14 +1050,14 @@ public static void drawShadedLine562(int dest[], int dest_off, int startX, int e if(notTextured) { loops = endX - startX >> 2; if(loops > 0) { - off = (grad - colorIndex) * shadowDecay[loops] >> 15; + off = (grad - colorIndex) * Constants3D.shadowDecay[loops] >> 15; } else { off = 0; } if(alpha == 0) { if(loops > 0) { do { - color = hsl2rgb[colorIndex >> 8]; + color = palette.hsl2rgb[colorIndex >> 8]; colorIndex += off; dest[++dest_off] = color; dest[++dest_off] = color; @@ -1099,7 +1067,7 @@ public static void drawShadedLine562(int dest[], int dest_off, int startX, int e } loops = endX - startX & 0x3; if(loops > 0) { - color = hsl2rgb[colorIndex >> 8]; + color = palette.hsl2rgb[colorIndex >> 8]; do { dest[++dest_off] = color; } while(--loops > 0); @@ -1109,7 +1077,7 @@ public static void drawShadedLine562(int dest[], int dest_off, int startX, int e int dest_alpha = 256 - alpha; if(loops > 0) { do { - color = hsl2rgb[colorIndex >> 8]; + color = palette.hsl2rgb[colorIndex >> 8]; colorIndex += off; color = ((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00); int i_169_ = dest[++dest_off]; @@ -1124,7 +1092,7 @@ public static void drawShadedLine562(int dest[], int dest_off, int startX, int e } loops = endX - startX & 0x3; if(loops > 0) { - color = hsl2rgb[colorIndex >> 8]; + color = palette.hsl2rgb[colorIndex >> 8]; color = ((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00); do { int i_170_ = dest[++dest_off]; @@ -1136,14 +1104,14 @@ public static void drawShadedLine562(int dest[], int dest_off, int startX, int e loops = endX - startX; if(alpha == 0) { do { - dest[++dest_off] = hsl2rgb[colorIndex >> 8]; + dest[++dest_off] = palette.hsl2rgb[colorIndex >> 8]; colorIndex += off; } while(--loops > 0); } else { int i = alpha; int i_171_ = 256 - alpha; do { - color = hsl2rgb[colorIndex >> 8]; + color = palette.hsl2rgb[colorIndex >> 8]; colorIndex += off; color = ((color & 0xff00ff) * i_171_ >> 8 & 0xff00ff) + ((color & 0xff00) * i_171_ >> 8 & 0xff00); int i_ = dest[++dest_off]; @@ -1219,7 +1187,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end // Calculate the slope of the color gradient using the shadowDecay array if the line is long enough. // For very short lines (length less than or equal to 0), there is no gradient and the slope is zero. if(loops > 0) { - color_slope = (grad - color_index) * shadowDecay[loops] >> 15; + color_slope = (grad - color_index) * Constants3D.shadowDecay[loops] >> 15; } else { color_slope = 0; } @@ -1230,7 +1198,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end // Repeat for each 4-pixel chunk in the line. while(--loops >= 0) { // Convert the color index to an RGB color. - color = hsl2rgb[color_index >> 8]; + color = palette.hsl2rgb[color_index >> 8]; // Adjust the color index for the next iteration using the color slope. color_index += color_slope; @@ -1247,7 +1215,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end // If there are remaining pixels, paint them as well. if(loops > 0) { - color = hsl2rgb[color_index >> 8]; + color = palette.hsl2rgb[color_index >> 8]; do { dest[dest_off++] = color; } while(--loops > 0); @@ -1261,7 +1229,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end // Repeat for the number of 4-pixel chunks in the line. while(--loops >= 0) { // Convert the color index to an RGB color. - color = hsl2rgb[color_index >> 8]; + color = palette.hsl2rgb[color_index >> 8]; // Adjust the color index for the next iteration using the color slope. color_index += color_slope; @@ -1283,7 +1251,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end // If there are remaining pixels, paint them as well. if(loops > 0) { - color = hsl2rgb[color_index >> 8]; + color = palette.hsl2rgb[color_index >> 8]; // Apply alpha transparency again as we just re-retrieved the color color = ((color & 0xff00ff) * dest_alpha >> 8 & 0xff00ff) + ((color & 0xff00) * dest_alpha >> 8 & 0xff00); @@ -1326,7 +1294,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end if(alpha == 0) { do { // Paint the pixel with the color corresponding to the current color index. - dest[dest_off++] = hsl2rgb[color_index >> 8]; + dest[dest_off++] = palette.hsl2rgb[color_index >> 8]; // Adjust the color index for the next pixel. color_index += color_slope; } while(--loops > 0); // Repeat for the number of pixels in the line (no chunking) @@ -1336,7 +1304,7 @@ public static void drawShadedLine(int[] dest, int dest_off, int start_x, int end int i_44_ = 256 - alpha; do { // Calculate the color for the current pixel. - color = hsl2rgb[color_index >> 8]; + color = palette.hsl2rgb[color_index >> 8]; // Adjust the color index for the next pixel. color_index += color_slope; @@ -1783,22 +1751,6 @@ public static void drawShadedTriangle(int a_y, int b_y, int c_y, int a_x, int b_ } } - public static int adjustBrightness(int rgb, double brightness) { - double r = (double) (rgb >> 16) / 256.0; - double g = (double) (rgb >> 8 & 0xff) / 256.0; - double b = (double) (rgb & 0xff) / 256.0; - - r = Math.pow(r, brightness); - g = Math.pow(g, brightness); - b = Math.pow(b, brightness); - - int outR = (int) (r * 256.0); - int outG = (int) (g * 256.0); - int outB = (int) (b * 256.0); - - return (outR << 16) + (outG << 8) + outB; - } - public static int[] setLineOffsets(int[] arg0) { return method700(Rasterizer.viewportLeft, Rasterizer.viewportTop, Rasterizer.viewportRight, Rasterizer.viewportBottom, arg0); } @@ -1826,7 +1778,7 @@ public static void setBounds(int arg0, int arg1) { } public static void createPalette(double brightness) { - createPalette(brightness, 512); + palette = Palette.create(brightness); } public static void drawFlatTriangle(int a_x, int a_y, int b_x, int b_y, int c_x, int c_y, int colour) { @@ -2171,79 +2123,5 @@ public static int[] getLineOffsets() { return lineOffsets; } - public static void createPalette(double brightness, int const_512) { - brightness += Math.random() * 0.03 - 0.015; - int index = 0; - - for(int y = 0; y < const_512; y++) { - double hue = (double) (y >> 3) / 64.0 + 0.0078125; - double lightness = (double) (y & 0x7) / 8.0 + 0.0625; - for(int x = 0; x < 128; x++) { - double intensity = (double) x / 128.0; - double red = intensity; - double green = intensity; - double blue = intensity; - - if(lightness != 0.0) { - double a; - if(intensity < 0.5) { - a = intensity * (1.0 + lightness); - } else { - a = intensity + lightness - intensity * lightness; - } - double b = 2.0 * intensity - a; - double fRed = hue + 0.3333333333333333; - if(fRed > 1.0) { - fRed--; - } - double fGreen = hue; - double fBlue = hue - 0.3333333333333333; - if(fBlue < 0.0) { - fBlue++; - } - if(6.0 * fRed < 1.0) { - red = b + (a - b) * 6.0 * fRed; - } else if(2.0 * fRed < 1.0) { - red = a; - } else if(3.0 * fRed < 2.0) { - red = b + (a - b) * (0.6666666666666666 - fRed) * 6.0; - } else { - red = b; - } - if(6.0 * fGreen < 1.0) { - green = b + (a - b) * 6.0 * fGreen; - } else if(2.0 * fGreen < 1.0) { - green = a; - } else if(3.0 * fGreen < 2.0) { - green = b + (a - b) * (0.6666666666666666 - fGreen) * 6.0; - } else { - green = b; - } - if(6.0 * fBlue < 1.0) { - blue = b + (a - b) * 6.0 * fBlue; - } else if(2.0 * fBlue < 1.0) { - blue = a; - } else if(3.0 * fBlue < 2.0) { - blue = b + (a - b) * (0.6666666666666666 - fBlue) * 6.0; - } else { - blue = b; - } - } - - int outR = ((int) (red * 256.0) << 16); - int outG = ((int) (green * 256.0) << 8); - int outB = ((int) (blue * 256.0)); - - int rgb = outR | outG | outB; - rgb = adjustBrightness(rgb, brightness); - - if(rgb == 0) { - rgb = 1; - } - - hsl2rgb[index++] = rgb; - } - } - } } diff --git a/src/main/java/org/runejs/client/media/RasterizerInstanced.java b/src/main/java/org/runejs/client/media/RasterizerInstanced.java index 6e903f37a..9a2840fd0 100644 --- a/src/main/java/org/runejs/client/media/RasterizerInstanced.java +++ b/src/main/java/org/runejs/client/media/RasterizerInstanced.java @@ -1,6 +1,7 @@ package org.runejs.client.media; import org.runejs.client.ProducingGraphicsBuffer; +import org.runejs.client.cache.media.ImageRGB; import org.runejs.client.node.CachedNode; import org.runejs.client.media.renderable.Model; @@ -20,6 +21,13 @@ public class RasterizerInstanced extends CachedNode { private static final int[] tmpX = new int[64]; private static final int[] tmpY = new int[64]; + public RasterizerInstanced() { + this.destinationPixels = new int[0]; + this.destinationWidth = 0; + this.destinationHeight = 0; + setBounds(0, 0, 0, 0); + } + public RasterizerInstanced(int[] pixels, int width, int height) { this.destinationPixels = pixels; this.destinationWidth = width; @@ -29,12 +37,30 @@ public RasterizerInstanced(int[] pixels, int width, int height) { public RasterizerInstanced(ProducingGraphicsBuffer producingGraphicsBuffer) { + setGraphics(producingGraphicsBuffer); + } + + public void setGraphics(ProducingGraphicsBuffer producingGraphicsBuffer) { this.destinationPixels = producingGraphicsBuffer.pixels; this.destinationWidth = producingGraphicsBuffer.width; this.destinationHeight = producingGraphicsBuffer.height; setBounds(0, 0, producingGraphicsBuffer.height, producingGraphicsBuffer.width); } + public void getViewportDimensions(int[] arg0) { + arg0[0] = viewportLeft; + arg0[1] = viewportTop; + arg0[2] = viewportRight; + arg0[3] = viewportBottom; + } + + public void setViewportDimensions(int[] arg0) { + viewportLeft = arg0[0]; + viewportTop = arg0[1]; + viewportRight = arg0[2]; + viewportBottom = arg0[3]; + } + public void prepare(int[] pixels, int width, int height) { this.destinationPixels = pixels; this.destinationWidth = width; @@ -135,7 +161,18 @@ public void method657(int[] arg0) { viewportBottom = arg0[3]; } - + /** + * Copies a given set of pixels into a destination array. This method takes the entire source array + * and fits it into the viewport. If the source image is larger than the viewport, the image will be + * cropped. If the source image starts at coordinates outside the viewport, the image will be adjusted + * to start from the viewport edge. + * + * @param pixels The source pixel array from which to copy pixels. + * @param width The width of the source pixel array. + * @param height The height of the source pixel array. + * @param paintX The x-coordinate at which to start painting pixels in the destination. + * @param paintY The y-coordinate at which to start painting pixels in the destination. + */ public void copyPixels(int[] pixels, int width, int height, int paintX, int paintY) { int sourcePixel = 0; if(paintX < viewportLeft) { @@ -153,12 +190,35 @@ public void copyPixels(int[] pixels, int width, int height, int paintX, int pain int pixelOffset = this.destinationWidth - width; int pixel = paintX + paintY * this.destinationWidth; for(int heightCounter = -height; heightCounter < 0; heightCounter++) { - for(int widthCounter = -width; widthCounter < 0; widthCounter++) - destinationPixels[pixel++] = pixels[sourcePixel++]; + for(int widthCounter = -width; widthCounter < 0; widthCounter++) { + // (jkm) this check wasn't in the initial RasterizerInstanced implementation, not sure why ... + if(pixels[sourcePixel] != Integer.MAX_VALUE) { + destinationPixels[pixel] = pixels[sourcePixel]; + } + pixel++; + sourcePixel++; + } pixel += pixelOffset; } } - + + /** + * Copies a specified region of a given set of pixels into a destination array. This method allows to define + * a sub-region within the source array (offsetX, offsetY, drawWidth, drawHeight) to be copied. Similar to + * the copyPixels method, this method adjusts the image position based on viewport boundaries and also crops + * the image if the region is larger than the viewport. However, in contrast to copyPixels, it allows for more + * flexible image manipulation by being able to define a specific region from the source image to copy. + * + * @param pixels The source pixel array from which to copy pixels. + * @param srcWidth The width of the source pixel array. + * @param srcHeight The height of the source pixel array. + * @param paintX The x-coordinate at which to start painting pixels in the destination. + * @param paintY The y-coordinate at which to start painting pixels in the destination. + * @param drawWidth The width of the region of the source array to be copied. + * @param drawHeight The height of the region of the source array to be copied. + * @param offsetX The x-coordinate of the starting point of the region in the source array. + * @param offsetY The y-coordinate of the starting point of the region in the source array. + */ public void copyPixelsCutOff(int[] pixels, int srcWidth, int srcHeight, int paintX, int paintY, int drawWidth, int drawHeight, int offsetX, int offsetY) { int sourcePixel = offsetX + offsetY * srcWidth; if(paintX < viewportLeft) { @@ -551,5 +611,40 @@ public void drawVerticalLine(int x, int y, int length, int colour) { destinationPixels[pixelOffset + pixel * destinationWidth] = colour; } - + public void drawImage(ImageRGB image, int x, int y) { + x += image.offsetX; + y += image.offsetY; + int dest_offset = x + y * this.destinationWidth; + int source_offset = 0; + int line_count = image.imageHeight; + int line_width = image.imageWidth; + int line_offset_dest = this.destinationWidth - line_width; + int line_offset_source = 0; + if(y < this.viewportTop) { + int clip_height = this.viewportTop - y; + line_count -= clip_height; + y = this.viewportTop; + source_offset += clip_height * line_width; + dest_offset += clip_height * this.destinationWidth; + } + if(y + line_count > this.viewportBottom) + line_count -= y + line_count - this.viewportBottom; + if(x < this.viewportLeft) { + int clip_width = this.viewportLeft - x; + line_width -= clip_width; + x = this.viewportLeft; + source_offset += clip_width; + dest_offset += clip_width; + line_offset_source += clip_width; + line_offset_dest += clip_width; + } + if(x + line_width > this.viewportRight) { + int clip_width = x + line_width - this.viewportRight; + line_width -= clip_width; + line_offset_source += clip_width; + line_offset_dest += clip_width; + } + if(line_width > 0 && line_count > 0) + ImageRGB.blockCopyTrans(this.destinationPixels, image.pixels, 0, source_offset, dest_offset, line_width, line_count, line_offset_dest, line_offset_source); + } } diff --git a/src/main/java/org/runejs/client/media/renderable/Model.java b/src/main/java/org/runejs/client/media/renderable/Model.java index 3c803caec..c15c9c9e7 100644 --- a/src/main/java/org/runejs/client/media/renderable/Model.java +++ b/src/main/java/org/runejs/client/media/renderable/Model.java @@ -5,6 +5,7 @@ import org.runejs.client.cache.def.FramemapDefinition; import org.runejs.client.input.MouseHandler; import org.runejs.client.io.Buffer; +import org.runejs.client.media.Constants3D; import org.runejs.client.media.Rasterizer3D; import org.runejs.client.media.VertexNormal; import org.runejs.client.Class40_Sub5_Sub15; @@ -18,7 +19,6 @@ public class Model extends Renderable { public static int[] anIntArray3199; public static int[] anIntArray3200 = new int[1600]; public static boolean[] aBooleanArray3201; - public static int[] anIntArray3202; public static int[] anIntArray3203; public static int[] vertexScreenY; public static int[] anIntArray3205; @@ -60,19 +60,18 @@ public class Model extends Renderable { vertexScreenZ = new int[4096]; anIntArray3214 = new int[1]; anIntArray3216 = new int[2000]; - anIntArray3202 = Rasterizer3D.hsl2rgb; vertexScreenX = new int[4096]; anIntArray3222 = new int[10]; anIntArray3219 = new int[2000]; anIntArray3223 = new int[4096]; - SINE = Rasterizer3D.sinetable; + SINE = Constants3D.sinetable; anIntArray3225 = new int[4096]; resourceCount = 0; anIntArray3227 = new int[10]; anIntArray3221 = new int[12]; - COSINE = Rasterizer3D.cosinetable; + COSINE = Constants3D.cosinetable; aBooleanArray3224 = new boolean[4096]; - anIntArray3228 = Rasterizer3D.anIntArray2929; + anIntArray3228 = Constants3D.anIntArray2929; anIntArray3226 = new int[12]; int i = 0; int i_322_ = 248; @@ -846,7 +845,7 @@ public void renderAtPoint(int arg0, CameraRotation cameraRotation, int x, int z, } } try { - method815(bool, bool_18_, arg8); + draw(bool, bool_18_, arg8); } catch(Exception exception) { /* empty */ } @@ -901,7 +900,7 @@ public void drawOrthogonalModel(int arg0, int arg1, int arg2, int arg3, int arg4 } } try { - method815(false, false, 0); + draw(false, false, 0); } catch(Exception exception) { /* empty */ } @@ -1329,7 +1328,7 @@ public void drawModel(int rotationX, int rotationZ, int rotationY, int cameraPit } } try { - method815(false, false, 0); + draw(false, false, 0); } catch(Exception exception) { /* empty */ } @@ -1345,7 +1344,7 @@ public void method813() { } } - public void method814(int arg0) { + public void drawNearClippedFace(int arg0) { int i = Rasterizer3D.center_x; int i_148_ = Rasterizer3D.center_y; int i_149_ = 0; @@ -1440,7 +1439,7 @@ public void method814(int arg0) { if(i_177_ == 0) Rasterizer3D.drawShadedTriangle(i_174_, i_175_, i_176_, i_171_, i_172_, i_173_, anIntArray3222[0], anIntArray3222[1], anIntArray3222[2]); else if(i_177_ == 1) - Rasterizer3D.drawFlatTriangle(i_171_, i_174_, i_172_, i_175_, i_173_, i_176_, anIntArray3202[triangleHSLA[arg0]]); + Rasterizer3D.drawFlatTriangle(i_171_, i_174_, i_172_, i_175_, i_173_, i_176_, Rasterizer3D.palette.hsl2rgb[triangleHSLA[arg0]]); else if(i_177_ == 2) { int i_178_ = triangleDrawType[arg0] >> 2; int i_179_ = texturedTrianglePointsX[i_178_]; @@ -1467,7 +1466,7 @@ else if(i_177_ == 2) { Rasterizer3D.drawShadedTriangle(i_174_, i_175_, i_176_, i_171_, i_172_, i_173_, anIntArray3222[0], anIntArray3222[1], anIntArray3222[2]); Rasterizer3D.drawShadedTriangle(i_174_, i_176_, anIntArray3205[3], i_171_, i_173_, anIntArray3227[3], anIntArray3222[0], anIntArray3222[2], anIntArray3222[3]); } else if(i_186_ == 1) { - int i_187_ = anIntArray3202[triangleHSLA[arg0]]; + int i_187_ = Rasterizer3D.palette.hsl2rgb[triangleHSLA[arg0]]; Rasterizer3D.drawFlatTriangle(i_171_, i_174_, i_172_, i_175_, i_173_, i_176_, i_187_); Rasterizer3D.drawFlatTriangle(i_171_, i_174_, i_173_, i_176_, anIntArray3227[3], anIntArray3205[3], i_187_); } else if(i_186_ == 2) { @@ -1488,7 +1487,7 @@ else if(i_177_ == 2) { } } - public void method815(boolean flag, boolean arg1, int arg2) { + public void draw(boolean flag, boolean arg1, int arg2) { if(diagonal3D < 1600) { for(int i = 0; i < diagonal3D; i++) anIntArray3200[i] = 0; @@ -1544,7 +1543,7 @@ public void method815(boolean flag, boolean arg1, int arg2) { if(i_216_ > 0) { int[] is = anIntArrayArray3210[i]; for(int i_217_ = 0; i_217_ < i_216_; i_217_++) - method823(is[i_217_]); + drawFace(is[i_217_]); } } } else { @@ -1598,7 +1597,7 @@ else if(i_221_ == 10) while(i_229_ == 0) { if(i_228_ <= i) break; - method823(is[i_225_++]); + drawFace(is[i_225_++]); if(i_225_ == i_226_ && is != anIntArrayArray3208[11]) { i_225_ = 0; i_226_ = anIntArray3226[11]; @@ -1613,7 +1612,7 @@ else if(i_221_ == 10) while(i_229_ == 3) { if(i_228_ <= i_223_) break; - method823(is[i_225_++]); + drawFace(is[i_225_++]); if(i_225_ == i_226_ && is != anIntArrayArray3208[11]) { i_225_ = 0; i_226_ = anIntArray3226[11]; @@ -1626,7 +1625,7 @@ else if(i_221_ == 10) i_228_ = -1000; } while(i_229_ == 5 && i_228_ > i_224_) { - method823(is[i_225_++]); + drawFace(is[i_225_++]); if(i_225_ == i_226_ && is != anIntArrayArray3208[11]) { i_225_ = 0; i_226_ = anIntArray3226[11]; @@ -1641,10 +1640,10 @@ else if(i_221_ == 10) int i_230_ = anIntArray3226[i_229_]; int[] is_231_ = anIntArrayArray3208[i_229_]; for(int i_232_ = 0; i_232_ < i_230_; i_232_++) - method823(is_231_[i_232_]); + drawFace(is_231_[i_232_]); } while(i_228_ != -1000) { - method823(is[i_225_++]); + drawFace(is[i_225_++]); if(i_225_ == i_226_ && is != anIntArrayArray3208[11]) { i_225_ = 0; is = anIntArrayArray3208[11]; @@ -1772,39 +1771,39 @@ public void method822() { } } - public void method823(int arg0) { - if(aBooleanArray3224[arg0]) - method814(arg0); + public void drawFace(int face) { + if(aBooleanArray3224[face]) + drawNearClippedFace(face); else { - int i = trianglePointsX[arg0]; - int i_237_ = trianglePointsY[arg0]; - int i_238_ = trianglePointsZ[arg0]; - Rasterizer3D.restrict_edges = aBooleanArray3201[arg0]; + int i = trianglePointsX[face]; + int i_237_ = trianglePointsY[face]; + int i_238_ = trianglePointsZ[face]; + Rasterizer3D.restrict_edges = aBooleanArray3201[face]; if(triangleAlphaValues == null) Rasterizer3D.alpha = 0; else - Rasterizer3D.alpha = triangleAlphaValues[arg0]; + Rasterizer3D.alpha = triangleAlphaValues[face]; int i_239_; if(triangleDrawType == null) i_239_ = 0; else - i_239_ = triangleDrawType[arg0] & 0x3; + i_239_ = triangleDrawType[face] & 0x3; if(i_239_ == 0) - Rasterizer3D.drawShadedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[arg0], triangleHSLB[arg0], triangleHSLC[arg0]); + Rasterizer3D.drawShadedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[face], triangleHSLB[face], triangleHSLC[face]); else if(i_239_ == 1) - Rasterizer3D.drawFlatTriangle(vertexScreenX[i], vertexScreenY[i], vertexScreenX[i_237_], vertexScreenY[i_237_], vertexScreenX[i_238_], vertexScreenY[i_238_], anIntArray3202[triangleHSLA[arg0]]); + Rasterizer3D.drawFlatTriangle(vertexScreenX[i], vertexScreenY[i], vertexScreenX[i_237_], vertexScreenY[i_237_], vertexScreenX[i_238_], vertexScreenY[i_238_], Rasterizer3D.palette.hsl2rgb[triangleHSLA[face]]); else if(i_239_ == 2) { - int i_240_ = triangleDrawType[arg0] >> 2; + int i_240_ = triangleDrawType[face] >> 2; int i_241_ = texturedTrianglePointsX[i_240_]; int i_242_ = texturedTrianglePointsY[i_240_]; int i_243_ = texturedTrianglePointsZ[i_240_]; - Rasterizer3D.drawTexturedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[arg0], triangleHSLB[arg0], triangleHSLC[arg0], anIntArray3225[i_241_], anIntArray3225[i_242_], anIntArray3225[i_243_], anIntArray3203[i_241_], anIntArray3203[i_242_], anIntArray3203[i_243_], anIntArray3223[i_241_], anIntArray3223[i_242_], anIntArray3223[i_243_], triangleColorValues[arg0]); + Rasterizer3D.drawTexturedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[face], triangleHSLB[face], triangleHSLC[face], anIntArray3225[i_241_], anIntArray3225[i_242_], anIntArray3225[i_243_], anIntArray3203[i_241_], anIntArray3203[i_242_], anIntArray3203[i_243_], anIntArray3223[i_241_], anIntArray3223[i_242_], anIntArray3223[i_243_], triangleColorValues[face]); } else if(i_239_ == 3) { - int i_244_ = triangleDrawType[arg0] >> 2; + int i_244_ = triangleDrawType[face] >> 2; int i_245_ = texturedTrianglePointsX[i_244_]; int i_246_ = texturedTrianglePointsY[i_244_]; int i_247_ = texturedTrianglePointsZ[i_244_]; - Rasterizer3D.drawTexturedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[arg0], triangleHSLA[arg0], triangleHSLA[arg0], anIntArray3225[i_245_], anIntArray3225[i_246_], anIntArray3225[i_247_], anIntArray3203[i_245_], anIntArray3203[i_246_], anIntArray3203[i_247_], anIntArray3223[i_245_], anIntArray3223[i_246_], anIntArray3223[i_247_], triangleColorValues[arg0]); + Rasterizer3D.drawTexturedTriangle(vertexScreenY[i], vertexScreenY[i_237_], vertexScreenY[i_238_], vertexScreenX[i], vertexScreenX[i_237_], vertexScreenX[i_238_], triangleHSLA[face], triangleHSLA[face], triangleHSLA[face], anIntArray3225[i_245_], anIntArray3225[i_246_], anIntArray3225[i_247_], anIntArray3203[i_245_], anIntArray3203[i_246_], anIntArray3203[i_247_], anIntArray3223[i_245_], anIntArray3223[i_246_], anIntArray3223[i_247_], triangleColorValues[face]); } } } diff --git a/src/main/java/org/runejs/client/util/PerlinNoise.java b/src/main/java/org/runejs/client/util/PerlinNoise.java index 13cdd2214..bdbed0562 100644 --- a/src/main/java/org/runejs/client/util/PerlinNoise.java +++ b/src/main/java/org/runejs/client/util/PerlinNoise.java @@ -1,6 +1,6 @@ package org.runejs.client.util; -import org.runejs.client.media.Rasterizer3D; +import org.runejs.client.media.Constants3D; /** * Perlin noise, used in the client for procedural terrain heightmap. @@ -23,7 +23,7 @@ public static int get(int x, int y, int scale) { private static int interpolateForPerlin(int arg0, int arg1, int arg2, boolean arg3, int arg4) { if (!arg3) return -109; - int i = 65536 + -Rasterizer3D.cosinetable[1024 * arg4 / arg1] >> 1; + int i = 65536 + -Constants3D.cosinetable[1024 * arg4 / arg1] >> 1; return ((65536 + -i) * arg0 >> 16) + (arg2 * i >> 16); }