Elixar Posted March 25, 2019 Share Posted March 25, 2019 (edited) The aim is Efficiency, I am wondering what would put more stress on the program. Option 1 is using only 1 thread onPaint() but if that thread is constantly looping then it's actually a lot of code that can all be removed if you just used a BufferedImage However... Using option 2 would also be re-placing the image over and over again, And i'm not exactly sure if that's being downloaded each looping cycle or it's being Cached naturally to the user. ( I'm not talking about syncing my resource file with the sdn, Im talking about when the script is on the SDN will the osbot client cache the image onto the Bot-Users personal Computer? Is that something I'll have to implement myself?What is more memory/cpu intense? Reloading an image each cycleor changing font types, re-drawing rectangles and colors 10-20 times per loop Option 1 @Override public void onPaint(Graphics2D g) { g.setColor(new Color(34, 30, 73, 255)); g.fillRect(0, 132, 84, 24); // g.drawRect(x, y, width, height); g.fillRect(0, 182, 84, 24); // g.drawRect(x, y, width, height); g.fillRect(0, 232, 60, 24); // g.drawRect(x, y, width, height); g.setFont(new Font("Trebuchet MS", Font.BOLD, 14)); g.setColor(new Color(255, 209, 102)); g.drawString("XP Gained", 3, 129); g.drawString("XP P/hour", 3, 179); g.drawString("Lvls Gained", 3, 229); } Option 2 BufferedImage background; @Override public void onStart(){ try{ background = ImageIO.read(Main.class.getResourceAsStream("/resources/background.png")); } catch(IOException e){ log(e); } } @Override public void onPaint(Graphics2D g){ if(background != null){ g.drawImage(background, null, x, y); } } } Thanks for all your answers wtf these Icons are to big lmao? Edited March 25, 2019 by Elixar Quote Link to comment Share on other sites More sharing options...
asdttt Posted March 29, 2019 Share Posted March 29, 2019 The first function uses higgghly optimized draw functions to create the rectangle, and uses less memory as your image would require to be stored in OldGen and never be collected by the garbage collector. It's by far more efficient then drawing an image. Both are still very efficient however and wont make a noticeable performance impact on your script. As for your second question regarding option 2. "Main.class.getResourceAsStream("/resources/background.png")" is grabbing your "background.png" directly from the loaded jar. It is not downloading anything that wasn't already streamed to the client. So in terms of "cacheing" it, it already exists in memory and therefor I guess you could say it's cached. Tl;Dr: Use BufferedImage if you'd like to create a more advanced/pretty background using an image. Use Option 1 if you just want something very fast, with little to no memory overhead. Either way, both are very efficient. Quote Link to comment Share on other sites More sharing options...