Main_loop question

Hi!..

I have used Unity and Unreal for some times, such engines have a function that updates every frame (Update() and Tick()), in the case of Panda3D there is framework.main_loop();

So, i was wondering how can I update things in P3D… any idea?

for instance in Unreal:
void AMyPlayer::Tick (){
//move something to left * deltaTime
}

I don’t see a way to do this in Panda (of course there must be one)
Thanks.

Pay attention to this code.

// This is our task - a global or static function that has to return DoneStatus.
// The task object is passed as argument, plus a void* pointer, containing custom data.
// For more advanced usage, we can subclass AsyncTask and override the do_task method.
AsyncTask::DoneStatus spinCameraTask(GenericAsyncTask *task, void *data) {
  // Calculate the new position and orientation (inefficient - change me!)
  double time = globalClock->get_real_time();
  double angledegrees = time * 6.0;
  double angleradians = angledegrees * (3.14 / 180.0);
  camera.set_pos(20*sin(angleradians),-20.0*cos(angleradians),3);
  camera.set_hpr(angledegrees, 0, 0);

  // Tell the task manager to continue this task the next frame.
  return AsyncTask::DS_cont;
}

In this example.

https://docs.panda3d.org/1.10/cpp/introduction/tutorial/controlling-the-camera

Read this further.

https://docs.panda3d.org/1.10/cpp/programming/tasks-and-events/tasks?highlight=tasks

1 Like

So, there is no update function… all are task based isn’t ?
I will give a read… thanks

You can answer it yourself if you find the difference between the task and the step function. However, I assume you want to render the frame?

basically, or do any per-frame task…for instance detect a button key or set a clock, print a message repeatedly on the screen if a condition comes true… etc. At least on Unreal and Unity I did these things inside an Update() or Tick() functions…

So in your opinion, the tasks are not suitable for this? I want to understand the difference between a step function and a task in your opinion.

In my opinion tasks do the job, in a different way, but do the job… I only need to get used to…
thanks!