-
Notifications
You must be signed in to change notification settings - Fork 0
/
Template
134 lines (69 loc) · 2.04 KB
/
Template
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package Display;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.util.Random;
public class Display extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public Thread thread;
public static JFrame frame = new JFrame();
public static String title ="[Inster Name]";
public static final int WIDHT = 1000;
public static final int HEIGHT = 1000;
public static boolean running = false;
public static int frames = 0;
public static int FPS = 0;
public Graphics graph;
public Display(){
}
public synchronized void start() {
running = true;
this.thread = new Thread(this,"Display");
this.thread.start();
}
public synchronized void stop() {
running = false;
try {
this.thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void run() {
long lastTime = System.nanoTime();
long timer = System.currentTimeMillis();
final double ns = 1000000000.0 / FPS;
double delta = 0;
while(running) {
long now = System.nanoTime();
delta += (now - lastTime)/ns;
lastTime = now;
while (delta >= 1) {
update();
delta --;
render();
frames++;
}
if (System.currentTimeMillis() - timer >1000 ) {
timer += 1000;
frame.setTitle(title+" || Frames : :" + frames);
frames = 0;
}
}
stop();
}
public void update() {
}
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
graph = bs.getDrawGraphics();
graph.dispose();
bs.show();
frame.show();
}
}