Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  central, time-driven loop ?  (Read 1886 times)
0 Members and 1 Guest are viewing this topic.
Offline bahuman

Junior Member





« Posted 2006-06-26 13:38:35 »

Hi!
I've taken a quick look at the darkstar swordWorld tutorial, and I  have one major question.
Suppose I want certain things to happen "independently" of the users (like monsters running around, natural events, flow of time, ...), how would I do that?

In a single player game, I would have a central loop that the game would execute everytime it is drawing a frame. Creating a task that runs forever is out of the question, because of the locking and starvation issues. Would it be acceptible to create a task that instantiates a copy of itself?
Offline Ragosch

Junior Member




Java games rock!


« Reply #1 - Posted 2006-06-26 13:59:43 »

I guess that is what package com.sun.gi.gloutils.pdtimer is for. A new event can be registered via SimTask.registerTimerEvent(...). I have not tried it out yet, but it should basically work like the heartbeat in a mud-like game.

Ragosch
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #2 - Posted 2006-06-26 18:15:39 »

Thats my take on it too

In EA2 the timer resolution should be changed, at the moment you pass in the time in ms, but the timer will only fire off 1s a second max.

Endolf

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-06-27 00:21:37 »

Right.

There is a low level system heartbeat directly accessible off the SimTask BUT things driven off that are slice dependant and each slcie has its own independant timer.

The PDTImer utility builds ontop of this to keep one system-wide list of timer events and allow parralel processing of the evenst by whatever slice has free processing time available.  It also makes the list of timer events persistant across restrats of any or all of the slices.

Edit:  Do keep in moind however that timer driven code on the server side is a necessary evil with the accent on evil.  Overuse of this facility is the fastest way to end up bogging down your servers.  If at all reasonable, it is better to have your server acting as an event driven processor of client events then generatring its own off a heartbeat.  Clients *should* have central "game loops".  Servers should not.

Keep in mind that, in many cases,  the server is a whole lot like a sub-atomic physics system.  Its state is irellevent until you need to measure something for the client and thus can be left uncalculated til then.  As a brain-dead example, if a guard is pacing back and forth ina predictable manner, and ther are no players to see him, his pacing is irellevent.  *When* the player gets close enough to see him is time enough to calculate position.  Simialrly, if your client is doing thinsg like collision detection then your server can afford to wait and check for cheating in "significant" position chnages rather then on every move of the character, like the client has to.

These are all the things you should think about if you plan on scaling to any reasonably large numbers...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bahuman

Junior Member





« Reply #4 - Posted 2006-06-27 20:16:13 »

Thanks for the input!

I'll go back to planning my killer game that will make me instantly famous (and rich, of course)
 Wink
Offline beowulf03809

Junior Member




We live for the code, we die for the code


« Reply #5 - Posted 2006-06-28 13:35:16 »


Edit:  Do keep in moind however that timer driven code on the server side is a necessary evil with the accent on evil.  Overuse of this facility is the fastest way to end up bogging down your servers.  If at all reasonable, it is better to have your server acting as an event driven processor of client events then generatring its own off a heartbeat.  Clients *should* have central "game loops".  Servers should not.


Jeff, for a persistent world game there may be events you want to have happening in the background which keep the world dynamic but are not a direct part of a player's actions.  The basic game model I've referenced in other recent threads is a pirate-based game with you travelling the Carribien.  A weather system is a key example of something that is global to the game world, should be completely server driven, and has direct impact on all clients ( and many other game events ).  If a tropical storm builds up and moves west thru the region it will damage port cities, disrupt trade, and threaten the PCs.  After the storm as passed and impact dertermined, some ports may be very bad places to trade while they rebuild, or they may have an increase in thier need for certain trade goods during that time.  And how one port is impacted by the storm would have an economic impact on other near by ports that they trade with, even if those ports are not directly damaged ( the price of rum goes up if the major supplier for that area is devestated ).

If I'm understanding correctly, you are suggesting not using a traditional game loop on the server and keeping the game design event driven.  If that's the case, in order to handle something like what I descirbed above ( and perhaps a dynamic economic model similar to what was brought up recently in another SGS thread ) would you suggest running an external service for these complex global systems?  It could either provides events to the SGS as if it was a client or expose an interface for the SGS to querry ( like a basic J2EE web service ).  In this example it would handle modeling the weather, impacting the port location, and tracking the rebuilding progress.  If a player visits the port the SGS would send a request for current status to the service and use that information to generate the actual port objects.

It just sounds a bit counter intuitive to have to move something like this outside of the rest of the game server.  The scaling capability and likely co-locating business model of the SGS is a major draw for me since I really will be starting small, but hope to grow.  If I have to isolate a chunk of my "world" outside of the SGS and take on the questions of managing that service seperately it really impacts the ROI.

Of course, if I'm way off base, please let me know...  Roll Eyes
Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2006-06-28 19:04:20 »


Edit:  Do keep in moind however that timer driven code on the server side is a necessary evil with the accent on evil.  Overuse of this facility is the fastest way to end up bogging down your servers.  If at all reasonable, it is better to have your server acting as an event driven processor of client events then generatring its own off a heartbeat.  Clients *should* have central "game loops".  Servers should not.


Jeff, for a persistent world game there may be events you want to have happening in the background which keep the world dynamic but are not a direct part of a player's actions. 

Agreed which is why I said <b>necessary</b>.  We did include a timer ebcause we reocgnized the need.  The trick is to use it as much as really necessary, and no more.

Quote
A weather system is a key example of something that is global to the game world, should be completely server driven, and has direct impact on all clients ( and many other game events ).

Sure.  The good news however is that it evolves slowly so it shoudl be ona pretty low period tick Cool

Quote

If I'm understanding correctly, you are suggesting not using a traditional game loop on the server and keeping the game design event driven.

Yes.

Quote
  If that's the case, in order to handle something like what I descirbed above ( and perhaps a dynamic economic model similar to what was brought up recently in another SGS thread ) would you suggest running an external service for these complex global systems? 

You could, but I dont think its necessary. A tick every 10 minutes to update your weather is not going to hurt your performance much.
A tick every 60th of a second to do micro adjustments of global monster positions will.  It should be noted that this is not just my observation. We're heard it repeated by real develoerps with real shipped and successful games (which I asnt name for NDA reasons)... that the number one cause of over-load for them was tight control of AI of bots.



Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline beowulf03809

Junior Member




We live for the code, we die for the code


« Reply #7 - Posted 2006-06-28 19:13:51 »

Thanks for the clarification, Jeff. 

Basically you suggest to just take a cautious approach.  A tick every couple minutes to execute and maintain global events shouldn't be significant, but don't get carried away.  To paraphrase the lesson I was taught when learning to off-road: "Slow as possible.  Fast as necessary."
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2006-06-28 19:16:16 »

Thanks for the clarification, Jeff. 

Basically you suggest to just take a cautious approach.  A tick every couple minutes to execute and maintain global events shouldn't be significant, but don't get carried away.  To paraphrase the lesson I was taught when learning to off-road: "Slow as possible.  Fast as necessary."

Thats it Cool

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (21 views)
2014-09-12 09:08:26

Norakomi (55 views)
2014-09-10 13:57:51

TehJavaDev (66 views)
2014-09-10 06:39:09

Tekkerue (33 views)
2014-09-09 02:24:56

mitcheeb (54 views)
2014-09-08 06:06:29

BurntPizza (38 views)
2014-09-07 01:13:42

Longarmx (24 views)
2014-09-07 01:12:14

Longarmx (30 views)
2014-09-07 01:11:22

Longarmx (28 views)
2014-09-07 01:10:19

mitcheeb (37 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!