Eclipse IDE를 사용하여 Java로 프로그래밍 할 때 디버그 기능을 사용하는 경우가 있습니다. 프로그램을 실행하는 동안 실시간으로 변수를 변경하고 싶습니다. 그러나, 꽤 자주 나는 변수를 변경하는 것이 현재 실행중인 프로그램에 영향을 미치지 않는다는 것을 알게되었습니다.Eclipse 디버그 모드 변경 변수
제 질문은 : 디버깅을위한 특정 규칙이 있습니까? 어떤 변수가 디버거 또는 범위에 있습니까?
어리석은 질문 인 경우 유감스럽게 생각합니다. 필자는 이클립스에서 디버깅을하고, 일반적으로 프로그래밍하는 것에 대해 상당히 새로운 것이다.
아래 코드는 샘플입니다. 읽기가 어렵거나 뭐든간에 유감 스럽지만 문제는 여기에 있습니다. Ball 클래스에서는 PARTICLES_PER_CLICK
또는 SPEED
과 같은 최종 변수를 변경할 때마다 실시간으로 업데이트되며 프로그램 창에서 차이점을 확인할 수 있습니다. 그러나 RADIUS
변수를 변경하면 다른 두 변수와 같은 클래스에 있어도 아무런 변화가 없습니다.
public class Main {
public static final int WIDTH = 1280;
public static final int HEIGHT = 720;
public static Ball[] ball = new Ball[100000];
public Main() {
try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create();
Display.setTitle("Game Engine");
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
boolean[] doOnce = new boolean[10];
boolean gravity = false;
while (!Display.isCloseRequested()) {
if (Mouse.isButtonDown(1) || Mouse.isButtonDown(1)) {
if (!doOnce[0]) {
Ball.createParticles();
doOnce[0]=true;
}
} else {
doOnce[0] = false;
}
glClear(GL_COLOR_BUFFER_BIT);
for (int i = 1; i <= Ball.ballAmount; i++) {
ball[i].updatePosition(gravity);
if (Mouse.isButtonDown(0)) {
gravity = true;
} else {
gravity = false;
}
if (ball[i].position.x > 0 && ball[i].position.y > 0 && ball[i].position.x < WIDTH && ball[i].position.y < HEIGHT) {
glBegin(GL_TRIANGLE_FAN);
glVertex2d(ball[i].position.x, ball[i].position.y);
for(int u=0;u<=360;u+=5){
glVertex2d(ball[i].position.x+Math.cos(u)*Ball.RADIUS, ball[i].position.y+Math.sin(u)*Ball.RADIUS);
}
glEnd();
}
}
System.out.println("Particle Amount: " + Ball.ballAmount);
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
public static void main(String[] args) {
new Main();
}
}
class Ball {
public Vector2f position, velocity;
public static final int RADIUS = 10;
public static final int INITIAL_SPEED = 5;
public static final int SPEED = 2;
public static final int PARTICLES_PER_CLICK = 50;
public static int ballAmount = 0;
public double r, g, b;
public static Random rnd = new Random();
public Ball(double x, double y) {
int angle = rnd.nextInt(360);
position = new Vector2f((float) x, (float) y);
velocity = new Vector2f((float) Math.cos(angle) * rnd.nextFloat() * INITIAL_SPEED, (float) Math.sin(angle) * rnd.nextFloat() * INITIAL_SPEED);
this.r = rnd.nextDouble();
this.g = rnd.nextDouble();
this.b = rnd.nextDouble();
}
public void updatePosition(boolean gravity) {
this.position.x += this.velocity.x * SPEED;
this.position.y += this.velocity.y * SPEED;
if (gravity) {
double dx = this.position.x - Mouse.getX();
double dy = this.position.y - (Main.HEIGHT - Mouse.getY());
double distance = Math.sqrt(dx * dx + dy * dy);
this.velocity.x -= (this.position.x - Mouse.getX())/distance;
this.velocity.y -= (this.position.y - (Main.HEIGHT - Mouse.getY()))/distance;
} else {
this.velocity.x *= 0.99;
this.velocity.y *= 0.99;
}
}
public static void createParticles() {
for (int i = 1; i <= PARTICLES_PER_CLICK; i++) {
ballAmount += 1;
Main.ball[ballAmount] = new Ball(Mouse.getX(),Main.HEIGHT- Mouse.getY());
}
}
}
시간이 많이 들지 않을 때 좀 더 자세하게 설명하고 싶지만 일반적으로 디버깅하는 동안 변수를 수정하는 것을 피하고 유기적으로 값을 지정해야합니다. ** 특별 ** 상황에서만 디버거를 통해 값을 삽입하는 것이 좋습니다. – Makoto