[SOLVED] Problem with simpleUpdate

If you are talking about the AppState. There is an explanation of how it works.

Each AppState has its own update loop, which hooks into the main simpleUpdate() loop (callback).

I do not think that I should try to step on these rakes to check.

Do you have a suggestion as to how I can update the data in the game, the CPU time, and not at the request of the GPU?

Pay attention to this only on jME3. Or name the game where you saw it. CS can?

  1. How many tutorials have you been through ?
  2. Your questions are difficult to understand (perhaps its a language barrier on my part) - but try to outline what you want to do in pseducode

I’ll simplify: to increase the variable +1 in the program loop.

i.e. you want a separate from AppState (render thread) loop at custom update rate. If so, this was addressed already:

What I’d stress here is “as you’d have defined an architecture that decouples the game objects from the visualization”. This comes first.

(I had this step done, and even having a working example in front of me, it took me a couple of days to split it into completely separate projects - and, yeah, to finally have absolutely distilled from any visual stuff server-side “program loop”. But that’s just me, probably everyone can do faster).

Very informative and with code examples … thanks.

In other 3D engines, give a link for example: Tasks

Here the lyrics will be told …

Tutorials

at least do those tutorials first https://jmonkeyengine.github.io/wiki/jme3.html#tutorials-for-beginners, lot of code examples. It is well spend time, really. And please stop answering/requesting in one liners, that is a waste of times for both sides.

Do I look like an idiot?

You tell me yet to read this: https://jmonkeyengine.github.io/wiki/jme3/beginner/hello_main_event_loop.html

I will explain that this example allows you to update 60 times per second. When synchronization is enabled.

Not sure if you want an answer on this. But I just try to give you some pointers, I mean you free man and can do what ever you like to do, maybe JME is just not the right engine for you. I would say just move on there are so many other engines which are so much better, right? And I’m sure the other engines doesn’t have those issues you are complaining about.

I dont know what you look like :smile:

I figured you just wanted to update a variable in the update loop (because that’s what you wrote).

But if you want to update more than 60 times per second with vsync enabled, then, as Paul already answered:

So you want a solution that involves multi threading?

I do not need your advice on what to do.

I do not know what I want anymore … Most likely, multithreading or a nuclear reactor…

Change data in a sub thread, and merge them into main thread after job is done.

http://jmonkeyengine.github.io/wiki/jme3/advanced/multithreading.html

1 Like

The Callable thing in that article is a little too complex. I made an example using only a Thread.

In main thread

/**
 * Load model in main thread
 */
private void loadModel() {
    // load asset
    final Spatial model = assetManager.loadModel("Models/Ashe/b_ashe_b.obj");
    model.scale(0.03f);
    model.center();

    // attach the model into SceneGraph
    rootNode.attachChild(model);
}

In a subthread.

/**
 * Load model in a subthread
 */
private void loadModel() {
    // create a thread
    new Thread () {
        public void run() {
            // load asset
            final Spatial model = assetManager.loadModel("Models/Ashe/b_ashe_b.obj");
            model.scale(0.03f);
            model.center();

            // notify the main thread, attach the model into SceneGraph
            enqueue(new Runnable() {
                public void run() {
                    rootNode.attachChild(model);
                }
            });
        }
    }.start();
}
1 Like

if you want to update something 60 times a second, then it’s trivial to do so. This is why people are telling you that it’s basic java and that your argument is moot.

float delay = 1f / 60f;
float currentDelay = 0f;

@Override
public void update(float tpf) {

    currentDelay += tpf;

    if (currentDelay < delay) {
        return;
    }

    currentDelay = 0f;
    
   // anything past here is run once every 60th of a second, or at 60fps if you want to call it that.
  doSomethingAt60fps();
}

Regarding the Panda Task that you specified - it pretty much describes an AppState with a choosable update period. The “Task Manager” that you speak of is the AppStateManager.

So let’s digress, for the sake of sanity itself. There are two objects below. An UpdateSpeed Enum and an UpdateMonitor class.

public enum  UpdateSpeed {

    FPS_120(1f / 120f),
    FPS_60(1f / 60f),
    FPS_30(1f / 30f),
    FPS_20(1f / 20f),
    FPS_10(1f / 10f),
    FPS_5(1f / 5f),
    FPS_2(1f / 2f);

    private final float delay;

    UpdateSpeed(float delay) {
        this.delay = delay;
    }

    public float getDelay() {
        return this.delay;
    }
}
public class UpdateMonitor {

    private UpdateSpeed speed;
    private float currentDelay;

    public UpdateMonitor(UpdateSpeed speed) {
        this.speed = speed;
    }

    public boolean update(float time) {
        this.currentDelay += time;

        if (this.currentDelay >= speed.getDelay()) {
            this.currentDelay = 0f;
            return true;
        }

        return false;
    }

    public UpdateSpeed getSpeed() {
        return this.speed;
    }

    public void setSpeed(UpdateSpeed speed) {
        this.speed = speed;
    }

}

Useage:


private UpdateMonitor updateMonitor = new UpdateMonitor(UpdateSpeed.FPS_60);

@Override
public void update(float tpf) {
    
    if (!updateMonitor.update(tpf)) {
        return;
    }

    doSomething();   

}

This does exactly as you want. It updates at whatever speed you choose in the UpdateMonitor constructor. I use this myself to limit GUI updates. Sometimes the GUI only needs to be updated 5 times a second, and not at the current frame rate.

But to get back on point - this is not the Panda engine. Different engines work in different ways - but they are essentially the same in design, it’s just done differently. People are sugguesting you read the tutorials - not because you are an idiot - but so that you understand how this engine works.

1 Like
float delay = 1f / 60f;
float currentDelay = 0f;

@Override
public void update(float tpf) {

    currentDelay += tpf;

    if (currentDelay < delay) {
        return;
    }

    currentDelay = 0f;
    
   // anything past here is run once every 60th of a second, or at 60fps if you want to call it that.
  doSomethingAt60fps();
}

And where does this method start?

Its your method, call it where ever you want :slight_smile:

But if you’re talking about the update method in an AppState, its called during the simpleUpdate of the application, read all about it here: http://jmonkeyengine.github.io/wiki/jme3/advanced/application_states.html

As already said, have your class extend BaseAppState and override the update method as shown, then add your class to the appstatemanager.