Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-19-2010, 10:55 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
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.
Reply With Quote
  #2  
Old 12-19-2010, 11:02 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #3  
Old 12-19-2010, 11:02 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.");

__________________
Reply With Quote
  #4  
Old 12-19-2010, 11:06 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
This applies to mobile devices?
Reply With Quote
  #5  
Old 12-19-2010, 11:11 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #6  
Old 12-19-2010, 11:11 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Codein View Post
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.
Reply With Quote
  #7  
Old 12-19-2010, 11:17 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by DustyPorViva View Post
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.
Reply With Quote
  #8  
Old 12-19-2010, 11:21 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Codein View Post
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.
Reply With Quote
  #9  
Old 12-19-2010, 11:37 PM
12171217 12171217 is offline
Banned
Join Date: Jan 2009
Posts: 453
12171217 has a spectacular aura about
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.
Reply With Quote
  #10  
Old 12-19-2010, 11:39 PM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by DustyPorViva View Post
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'".
Reply With Quote
  #11  
Old 12-20-2010, 12:29 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #12  
Old 12-20-2010, 12:32 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #13  
Old 12-20-2010, 12:50 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #14  
Old 12-20-2010, 12:57 AM
Codein Codein is offline
jwd
Codein's Avatar
Join Date: Oct 2005
Location: Greater Manchester
Posts: 2,423
Codein has a spectacular aura aboutCodein has a spectacular aura about
Send a message via AIM to Codein Send a message via MSN to Codein
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #15  
Old 12-20-2010, 09:55 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
on Era iPhone I've designed a system which triggers alot of actions- (function onHealthChanged, onItemChange etc); to optimize effects, use particles.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:39 PM.


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