simple 24 hour game clock

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

simple 24 hour game clock

Post by bit-pusher »

(deleted; here was a broken clock demo)
Last edited by bit-pusher on Fri Jun 12, 2009 9:54 am, edited 4 times in total.
coldcity.com - code, games, stuffs
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post 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? :)
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post 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 :)
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post by bit-pusher »

Sure, go for it :D

I was just demonstrating the calculation really, you can make it a u32 no worries.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post 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.
Last edited by bit-pusher on Thu Jun 11, 2009 11:25 am, edited 1 time in total.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post by bit-pusher »

(deleted)
Last edited by bit-pusher on Fri Jun 12, 2009 9:54 am, edited 1 time in total.
coldcity.com - code, games, stuffs
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I took the freedom and split the other thread from yours, so you can keep your thread cleaned.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post by bit-pusher »

Cool; updated the original post to add the demo link and for context.
coldcity.com - code, games, stuffs
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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.
bit-pusher
Posts: 13
Joined: Tue Jun 09, 2009 11:53 am
Location: Wales, UK
Contact:

Post 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
coldcity.com - code, games, stuffs
Nox
Posts: 304
Joined: Wed Jan 14, 2009 6:23 pm

Post 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.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post 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.
Midnight
Posts: 1772
Joined: Fri Jul 02, 2004 2:37 pm
Location: Wonderland

Post 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.
Last edited by Midnight on Fri Jun 12, 2009 7:25 am, edited 2 times in total.
Locked