Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Game starts lagging when increasing xoffset and yoffset  (Read 651 times)
0 Members and 1 Guest are viewing this topic.
Offline lcass
« Posted 2013-08-27 19:06:19 »

Hi I have a java game and when  I increase the xoffset and yoffset the fps goes down hugely , in the top left corner(xoffset = 0; y offset = 0;) 450 fps , in the bottom right corner I get 19 fps.
Here is the code for my rendering and my world tick();
1  
2  
3  
4  
5  
6  
7  
8  
public void render() {
      for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
            core.pixmap[x + (y * width)] = image[x + core.xoffset][y
                  + core.yoffset];
         }
      }
   }
This is what draws it to the pixmap;

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   public void render() {
      BufferStrategy bs = getBufferStrategy();
      if (bs == null) {
         createBufferStrategy(2);
         return;
      }
     
      screen.clear();
      screen.render();
      Graphics g = bs.getDrawGraphics();
      g.drawImage(pixmapimg, 0, 0, width, height, null);
     
      g.dispose();
      bs.show();

   }

handles the image drawing(in a seperate class)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
for (int x = -32 + core.xoffset / 32; x < (core.width + core.xoffset + 100) / 32; x++) {
         
         
         for (int y = -32 + core.yoffset / 32; y < (core.height
               + core.yoffset + 100) / 32; y++) {
            if (x >= 0 && x < (core.width * 3) / 32 && y >= 0
                  && y < (core.height * 3) / 32) {
               core.screen.draw(x * 32, y * 32, map[x][y].getgraphics());
               map[x][y].tick();
            }
         }
      }

and the world.tick();
Offline Herjan
« Reply #1 - Posted 2013-08-27 19:13:26 »

And the world.tick??? Smiley

Why offset in an array? Sorry, I don't know what you're doing, maybe post your project on github or so?

Offline lcass
« Reply #2 - Posted 2013-08-27 19:21:20 »

Ahh i see, Offset in the array is because I use 1 array for the map and 2 arrays for rendering(one of which is the DataBufferInt). So for getting the tile I use the offsets. The tilemap is the ENTIRE map where as the pixmap is all that is visible.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #3 - Posted 2013-08-28 16:18:33 »

anyone?
Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« Reply #4 - Posted 2013-08-28 16:50:07 »

For starters
why is your bufferstrategy inside your render loop? its getting destroyed/recreated each one?
Same with graphics?

why not initialize() somewhere else for bufferstrategy and then graphics g.

Then just call screen clear, rende,r dispose, show inside the render loop?




Also you seem to be lacking some code in your snippets. Also for example you say in the top left corner(xoffset = 0; y offset = 0;) 450 fps , in the bottom right corner I get 19 fps.

What is the xoffset == ? when its getting 19?


"Experience is what you get when you did not get what you wanted"
Offline lcass
« Reply #5 - Posted 2013-08-28 17:56:42 »

For starters
why is your bufferstrategy inside your render loop? its getting destroyed/recreated each one?
Same with graphics?

why not initialize() somewhere else for bufferstrategy and then graphics g.

Then just call screen clear, rende,r dispose, show inside the render loop?




Also you seem to be lacking some code in your snippets. Also for example you say in the top left corner(xoffset = 0; y offset = 0;) 450 fps , in the bottom right corner I get 19 fps.

What is the xoffset == ? when its getting 19?


Ooh didnt notice that hold on , ill get those offsets. Also it only checks it but I will change it around.
Offline lcass
« Reply #6 - Posted 2013-08-28 17:58:46 »

The offsets are : x = 1152 : y = 1152   i'd like to note that it doesnt just suddenly go to 19 as the x and y offset increases the fps drops.
Offline lcass
« Reply #7 - Posted 2013-08-28 18:29:33 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
private boolean graphicsinitialized = false;
   private Graphics g;
   private BufferStrategy bs;

   public void initrender() {
      bs = getBufferStrategy();
      if (bs == null) {
         createBufferStrategy(2);
         initrender();
         System.out.println("test");
         return;
      }
     
   }

   public void render() {

      if (!graphicsinitialized) {
         initrender();
         graphicsinitialized = true;
      }
      g = bs.getDrawGraphics();
      if (g != null) {
         screen.clear();
         screen.render();
         g.drawImage(pixmapimg, 0, 0, width, height, null);

         g.dispose();
         bs.show();
      }

   }

my updated render code
Offline lcass
« Reply #8 - Posted 2013-08-29 12:15:44 »

anything?
Offline tdegroot96

Junior Member


Projects: 1



« Reply #9 - Posted 2013-08-29 22:47:45 »

are you rendering with the width and height of your map?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #10 - Posted 2013-08-30 00:41:08 »

I render the area of the screen you currently look at.so as the xoffset increases the position it draws in goes further to the right.
Its the width and height of the frame not the map.
Offline lcass
« Reply #11 - Posted 2013-08-30 00:56:47 »

Gah ive located the lag to the world.tick(); in the left corner it simulates 400 tiles in the bottom right it simulates over 2000
Offline tdegroot96

Junior Member


Projects: 1



« Reply #12 - Posted 2013-08-30 10:12:27 »

Ouch, know where it occured?
Offline lcass
« Reply #13 - Posted 2013-08-30 14:41:48 »

im just going to rewrite it I have a much better more efficient method that only adds twice.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (15 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!