Page 1 of 2

simple 24 hour game clock

Posted: Wed Jun 10, 2009 12:45 pm
by bit-pusher
(deleted; here was a broken clock demo)

Posted: Wed Jun 10, 2009 2:20 pm
by Lonesome Ducky
This is pretty cool! This would actually be pretty useful for the game I'm working on, thanks for the code! Here's a suggestion though, maybe you could make DAYLENGTH user definable, that way I could have a quicker time cycle for my game.

Posted: Wed Jun 10, 2009 2:38 pm
by bit-pusher
Change DAY_LENGTH_MS to the number of real-world ms you want a game day to last.

Is that what you meant? :)

Posted: Wed Jun 10, 2009 3:47 pm
by Lonesome Ducky
Well the problem is that it's a define, and if I want to continually change it, I can't. So why not make it a regular u32 so it can be changed whenever needed? That's what I'm talking about :)

Posted: Wed Jun 10, 2009 8:12 pm
by bit-pusher
Sure, go for it :D

I was just demonstrating the calculation really, you can make it a u32 no worries.

Posted: Thu Jun 11, 2009 10:31 am
by bit-pusher
Midnight wrote:
JuppS wrote:great, second site of this thread and still no Midnight-code! :roll:
I'm realy looking forward to see the great code snippet that needs so long to be finished! :twisted:
Yeah it's comming. I'm adding some new features now and I got side tracked by bit-pushers code.

I found a bug in it btw. GetGameTime() doesn't even return hours what it returns is a minute count divided by 24. It's totally wrong.

I'm not going to fix his code but later I'll replace it.
-- Oops it's maybe not that clear how to use... my bad. GetGameTime() returns a float in range 0.0f - 24.0f; GetGameMinutes() and GetGameHours() return integers. I'll post a more complete demo.

Posted: Thu Jun 11, 2009 11:20 am
by bit-pusher
(deleted)

Posted: Thu Jun 11, 2009 4:33 pm
by hybrid
I took the freedom and split the other thread from yours, so you can keep your thread cleaned.

Posted: Thu Jun 11, 2009 7:16 pm
by bit-pusher
Cool; updated the original post to add the demo link and for context.

Posted: Thu Jun 11, 2009 8:38 pm
by Midnight
right good you didn't ruin his post. awsome.

anyways I'll say again THIS IS NOT A 24 HOUR CLOCK.

it's a 24 minute clock :wink:

actually I think it may even be a 24 min clock based on 100 second minutes.

read your code trust me it's not right I have tested it and the hours pass like seconds.

Posted: Thu Jun 11, 2009 10:34 pm
by bit-pusher
Hmm wierd.. seems to work OK for me. Any probs with the demo, or is it just the code on this page? :S

Posted: Thu Jun 11, 2009 11:06 pm
by Nox
Midnight did not read the following:
bit-pusher wrote:Change DAY_LENGTH_MS to the number of real-world ms you want a game day to last.

Posted: Fri Jun 12, 2009 5:45 am
by Midnight
Nox wrote:Midnight did not read the following:
bit-pusher wrote:Change DAY_LENGTH_MS to the number of real-world ms you want a game day to last.
Yes I've read it. One would think that was in response to a question about changing the time factor. should it not be defaulted to real world milliseconds?

anyways I decided I would test this.. oh and guess what 86400000 milliseconds aka 24 hours is far too large of a number to be handled by any common variable type limits.

so I guess at this point one might say fail?

For all of you that need a 12 OR 24 hour clock try mine which "inspired" bit-pusher to steal my thunder. well now I'm stealing it back! 8)

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=33947

let me guess bit-pusher. either you had this junk laying around and decided that it was clock posting time because I made you think of it. OR you thought hey a clock I can do that faster then midnight maybe I should throw some poop together really fast and try to out do him. it'll be easy it's just a clock. sound about right bit-pusher? it's ok don't answer I don't want to hear your lies.

... after browsing his website I already know which one it was.

Posted: Fri Jun 12, 2009 6:54 am
by Dorth
18446744073709551615 u64 or time_t in most case
4294967295 u32 or time_t in some rare case
86400000
And let's not talk about floats or time_t as floats or double. And since I'm pretty certain it is only used for division, it will not push through the roof any value.

Also, just learn to use friggin gmtime or localtime if you want real day time (and it's tm struct). It has been coded to handle the pre-1970 case, the leap years, the daytime, etc. It is far more solid and reliable than either your clock (when used for the purpose of tracking real time, ofc) and will not fail misteriously when ported to another system.

Posted: Fri Jun 12, 2009 7:12 am
by Midnight
Dorth wrote:18446744073709551615 u64 or time_t in most case
4294967295 u32 or time_t in some rare case
.......
First of all my code is only coded for windows. I'll be sure to specify that just for you.

Secondly I have tested bit-pushers code using 86400000 and guess what the result was?

Since when is u32 4294967295?? is it not 65535 give or take?

I know for a fact that u32 is limited to 65535 because I've actually tested it in my own code. unlike bit-pusher that will perhaps never even use his own code.

And as for gmtime my code was never designed for accurate real world time keeping. It was designed as a GAME Clock hence the name and the time warping functions.

It seems to me you'd be better off actually testing it yourself before trying to discredit me. As if I don't get enough abuse from this community as it is.

oh and it's spelled mysteriously. I'll let you slide though because it appears to be a typo. :P

fail dorth. fail.