Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Alternative to Timeouts (https://forums.graalonline.com/forums/showthread.php?t=134261351)

Codein 12-19-2010 10:55 PM

Alternative to Timeouts
 
Are there any functions which I can use the core game loop over using multiple timeouts?

If not, what is the most efficient alternative to timeouts? For example, I want to create a baddy and minimise the number of timeouts I want to use.

Just a question out of curiosity really.

fowlplay4 12-19-2010 11:02 PM

Use Scheduled Events, and Waitfor.

It's the triggers and the code that calls them that will be slow part in your code anyway.

Oh yeah if you have respawns longer than 10 minutes be sure to have a DB maintain the time they should respawn on because levels and npcs like to reset after being inactive (no players inside) for 10 or so minutes.

cbk1994 12-19-2010 11:02 PM

Use scheduleEvent.

PHP Code:

function onCreated() {
  
this.scheduleEvent(60"onDie"); // you need a third (possibly blank) parameter on clientside with v5
}

function 
onDie() {
  echo(
"dead.");



Codein 12-19-2010 11:06 PM

This applies to mobile devices?

fowlplay4 12-19-2010 11:11 PM

Yeah it'll work on mobile clients. Keep in mind schedule event is pretty much the same thing as using a timeout loop and using multiple schedule events over one timeout will be less-efficient.

DustyPorViva 12-19-2010 11:11 PM

Quote:

Originally Posted by Codein (Post 1616908)
This applies to mobile devices?

This for an iPhone server? A loop is still a loop. An infinite loop is still going to be intensive on the processor whether it's a timeout or waitfor.

Codein 12-19-2010 11:17 PM

Quote:

Originally Posted by DustyPorViva (Post 1616912)
This for an iPhone server? A loop is still a loop. An infinite loop is still going to be intensive on the processor whether it's a timeout or waitfor.

I mean this in the least rudest way possible but that's obvious and I know this. What I REALLY want is to most efficient way to use the game loop. There are certain things that do not need to be on the server yet do need to be constantly moving.

DustyPorViva 12-19-2010 11:21 PM

Quote:

Originally Posted by Codein (Post 1616913)
I mean this in the least rudest way possible but that's obvious and I know this. What I REALLY want is to most efficient way to use the game loop. There are certain things that do not need to be on the server yet do need to be constantly moving.

Aye, and what I'm saying is if you want something constantly moving on the clientside you're probably not going to get it, even with the most efficient method... a loop is still a loop. Even with relying almost all on default, Classic iPhone still runs pretty bad with so many players. Adding anything more is just going to murder the processor.

12171217 12-19-2010 11:37 PM

Classic iPhone runs poorly because there's so many textures on different images, requiring them to upload so many images every frame. If Stefan were to merge heads onto 1024x1024 sheets and display pieces of it from UV coordinates, it would probably run better.

Unless Stefan already does this. I'm not sure if he does or not, but it's one of the only reasons why I can think that iPhone Graal runs so poorly.

Codein 12-19-2010 11:39 PM

Quote:

Originally Posted by DustyPorViva (Post 1616916)
Aye, and what I'm saying is if you want something constantly moving on the clientside you're probably not going to get it, even with the most efficient method... a loop is still a loop. Even with relying almost all on default, Classic iPhone still runs pretty bad with so many players. Adding anything more is just going to murder the processor.

The entire game is running inside a loop. What I'm looking for is a way to use that loop. An event would be handy, such as 'onGameLoop' or something. That way there would be no need to use timeouts at all, or any seperate loop. It'd just be part of the core loop.

Maybe this should now be a Future Improvement request? I'm still looking for someone to shoot me down with "You're completely wrong, timeouts are essentially this 'register a hook with the game loop'".

cbk1994 12-20-2010 12:29 AM

Someone (Tig?) told me scheduleEvent was "optimized" for iPhone and is more efficient than using a timeout in the same manner (for an infinite loop) but I have no idea if that's true or not.

You could always do your own tests, but I imagine the difference is miniscule.

Codein 12-20-2010 12:32 AM

Quote:

Originally Posted by cbk1994 (Post 1616936)
Someone (Tig?) told me scheduleEvent was "optimized" for iPhone and is more efficient than using a timeout in the same manner (for an infinite loop) but I have no idea if that's true or not.

You could always do your own tests, but I imagine the difference is miniscule.

This is all just thought for the future. I don't have access to any iPhone enabled servers nor do I have an iPhone (I'm using an Android based device).

Anyways, thanks for all your input guys. It has been useful.

cbk1994 12-20-2010 12:50 AM

I did a bit of testing on an iPhone 4.

I commented out, in turn, either the trigger for timeOut or the trigger for scheduleEventTest.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.loopCount 0;
  
  
this.trigger("scheduleEventTest");
  
// this.trigger("timeOut");
}

function 
onScheduleEventTest() {
  
this.loopCount ++;
  
player.chat this.loopCount;
  
  
this.scheduleEvent(0.05"scheduleEventTest");
}

function 
onTimeOut() {
  
this.loopCount ++;
  
player.chat this.loopCount;
  
  
this.setTimer(0.05);


Results from clientstats after running for about 4 minutes (until the loop counter hit 5k):
scheduleEvent:
Quote:

1. 1.35521233 % Weapon Shared/iPhoneLoopTest
onCreated: 0.000052182 %
onScheduleEventTest: 1.074318247 %
setTimer:
Quote:

1. 1.271795034 % Weapon Shared/iPhoneLoopTest
onCreated: 0.000053123 %
onTimeOut: 1.037823939 %
I closed and re-opened Graal before each test on the iPhone.

Codein 12-20-2010 12:57 AM

Quote:

Originally Posted by cbk1994 (Post 1616956)
I did a bit of testing on an iPhone 4.

I commented out, in turn, either the trigger for timeOut or the trigger for scheduleEventTest.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.loopCount 0;
  
  
this.trigger("scheduleEventTest");
  
// this.trigger("timeOut");
}

function 
onScheduleEventTest() {
  
this.loopCount ++;
  
player.chat this.loopCount;
  
  
this.scheduleEvent(0.05"scheduleEventTest");
}

function 
onTimeOut() {
  
this.loopCount ++;
  
player.chat this.loopCount;
  
  
this.setTimer(0.05);


Results from clientstats after running for about 4 minutes (until the loop counter hit 5k):
scheduleEvent:


setTimer:


I closed and re-opened Graal before each test on the iPhone.

That is quite interesting. Thanks for the statistics, I would (+ rep 1) if possible.

So basically there is no nice way of doing it. Well, at least I'm fully aware of the constraints on that part.

xAndrewx 12-20-2010 09:55 AM

on Era iPhone I've designed a system which triggers alot of actions- (function onHealthChanged, onItemChange etc); to optimize effects, use particles.


All times are GMT +2. The time now is 09:06 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.