Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  Gage Timer  (Read 4540 times)
0 Members and 1 Guest are viewing this topic.
Offline ranabp

Senior Newbie




Blit Me :)


« Posted 2003-08-08 03:09:05 »

Hellow,
I am using Gage Timer for my game loop, here is what i mean :
1  
2  
3  
4  
5  
6  
gameManager.update();
render();
sleep = gt.getTicksPerSecond()/60; //60fps
ticks = gt.getClockTicks();
gt.sleepUntil(sleep+ticks);
ticks = ticks+sleep;


The code shows i have a class "gameManager". Now if i wanted to create a new Timer (gmt) which is created "gameManager" for its indepedent events, will that timer be affected by the "gt" shown above ??

Basically, will the new timer run in a new Thread independent of gt or not ?
Thx

Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-08-08 04:06:21 »

As far as I understand, the time doesn't actually use any threads itself. If you create one instance, and call sleepUntil() using two seperate threads they'll both wait independantly of each other..

I keep wondering whether GAGETimer would be more convinient as a singlton or a bunch of static methods.

Kev

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #2 - Posted 2003-08-10 00:15:11 »

Quote
I keep wondering whether GAGETimer would be more convinient as a singlton or a bunch of static methods.


Nope. You might want to use multiple timers. For example, a new AdvancedTimer could be intialized and used for a "countdown" timer independent of the frame rate timer. (e.g. Mario dies when the timer hit 100 seconds)

Java Game Console Project
Last Journal Entry: 12/17/04
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2003-08-10 05:31:53 »

Ah, good point Smiley

Offline Max Pesce

Junior Devvie




Nil tam arduum quod non ingenio vincas


« Reply #4 - Posted 2003-08-10 08:51:55 »


If the problem is having more timers running...

No need to create other timers for misc events...

I'm using a simple algorithm:

1. Calculate delta millisec elapsed since the last logical frame.
2. Subtract this time slice to all "task" pending.
3. When a task expire you generate an event.
4. If the task is ciclical you may want to reset the delay for that task

Pack this concept in a Class able to handle more task at the same time and you've got a perfect timer for all your game's event

Hope it helps.

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2003-08-11 13:42:32 »

Well yes, you could do that. In fact that's basically what GAGETimer does internally. It's just as easy (any probably a bit cleaner) to just use another instance of the timer. All instances are working off the same timing source, but the individual instances are dealing with the naggling details for you. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Max Pesce

Junior Devvie




Nil tam arduum quod non ingenio vincas


« Reply #6 - Posted 2003-08-11 16:32:15 »

Quote
Well yes, you could do that. In fact that's basically what GAGETimer does internally. It's just as easy (any probably a bit cleaner) to just use another instance of the timer. All instances are working off the same timing source, but the individual instances are dealing with the naggling details for you. Smiley


Yes it's a good solution...

But you can generate Events and make entity classes receive them simply implementing a EventListener interface...
In my case tasks have a name string so it's simple to create em and receive their messages.

For example in CastleTrouble I have used many of this simultaneous tasks:

- "Hurry up!" (only in beta) after 60 secs it alters the enemies' speed.
- Intro delays and events...
- One cyclic to make a hourGlass run (only in beta)
- Delay before opening doors
and many others...

Another great pro of this method is that other "sources" can generate events, my library can generate events:

- When a sprite change a frame during an animation
- At the end of an animation (this is really useful to concatenate animations or to use animations as precalculated delays)
- At the end of a MOD or a MIDI
and so on...

So having a Task based timer is a great thing expecially if you have (or want) also an Event driven system.




Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (20 views)
2018-05-13 18:23:11

nelsongames (68 views)
2018-04-24 18:15:36

nelsongames (65 views)
2018-04-24 18:14:32

ivj94 (748 views)
2018-03-24 14:47:39

ivj94 (79 views)
2018-03-24 14:46:31

ivj94 (555 views)
2018-03-24 14:43:53

Solater (94 views)
2018-03-17 05:04:08

nelsongames (168 views)
2018-03-05 17:56:34

Gornova (338 views)
2018-03-02 22:15:33

buddyBro (998 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!