openplanet-nl / issues

Issue tracker for Openplanet.
10 stars 0 forks source link

Add second `Render()`-like method #194

Open fentras opened 2 years ago

fentras commented 2 years ago

Right now for Tweaker to work it requires keeping Hide overlay on hidden game UI option enabled because Render() callback is the only callback that can run ahead of the game speed (and therefore overwrite values before the game can revert them back). Since I don't have time to properly change Tweaker behavior (so it doesn't use Render() callback) it would be nice if something like Routine() method could be added. It will run just like Render() ahead of game speed but won't be affected by Hide overlay on hidden game UI option. CoroutineFunc() or Update() doesn't work.

Here's the quick example with render distance only working in Render() method (go to plugin Settings to change the update method).

Plugin_UpdateMethods.as ```asc #name "Update Methods" [Setting name="Update Method"] UpdateMethod Setting_UpdateMethod = UpdateMethod::None; CTrackMania@ app; CHmsViewport@ view; void Update(float dt) { if (Setting_UpdateMethod == UpdateMethod::Update) RenderDistance(); } void Routine() { while(true) { if (Setting_UpdateMethod == UpdateMethod::RoutineYield) { RenderDistance(); yield(); } else if (Setting_UpdateMethod == UpdateMethod::RoutineSleep) { RenderDistance(); sleep(1); } else { yield(); } } } void Render() { if (Setting_UpdateMethod == UpdateMethod::Render) RenderDistance(); } void RenderDistance() { if (app.GameScene !is null && (app.CurrentPlayground !is null || app.Editor !is null) && view.Cameras.Length > 0) { view.Cameras[0].FarZ = 100; print(Time::get_Now()); } } void Main() { @app = cast(GetApp()); @view = app.Viewport; startnew(Routine); } enum UpdateMethod { None, Update, RoutineYield, RoutineSleep, Render } ```

https://user-images.githubusercontent.com/26721650/195425118-4cf8d938-896e-4277-82ca-773f94b384db.mp4

codecat commented 2 years ago

I have a feature currently in development that might help with stuff like this. I'll update you when I have more done.