Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Return time as an interger?

Author
Message
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 00:17
Hello everyone,
What is the best way to return time as an integer? For example, if I want a specific event to happen at 8:00 P.M. what would need to be done?
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2007 03:05
maybe convert real times into a number system 0000-2359
that will fit inside integer, even inside short
just parse the date time to time, hours and minutes in 24 hour format.

My DBP plugins page is now hosted [href]here[/href]
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 05:08
I'm sorry, I'm not 100% sure what you mean...
Does the format dbTimer() uses return in some kind of system time format?
If it's not too much to ask... could someone draw up a quick example?
I would be very grateful.
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 12th Dec 2007 13:20 Edited at: 12th Dec 2007 13:22
Quote: "
dbGetTime$

This command will return the current clock time as a formatted string. The string contains the time in the format HH:MM:SS. HH indicating the current hour number 00-23, MM indicating the current minute number 00-59 and SS indicating the current second number 00-59.

Syntax

char* dbGetTime$ ( void )"


The above is from the help files.

So all you would need to do is either check the first part of the string to see if it is "20" or convert the first part into an integer, like so:



And then check if it is 20.

Edit: Obvously this would need to be done every minute at least, and to check the other values i.e minute and seconds just use the dbMid() function for the minutes and dbRight() function for the seconds.

The Sun is trying to kill me!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2007 15:55
Sorry, I assumed that you would be using C++ native functionality to do nearly everything in you game code, with the exception of DX manipulation. That's the model I follow in VB.NET. I do everything in pure .net (avoiding all DB_ based functions) with the exception of the functions needed to deal with game elements of Direct X (3d, 2d, audio, etc).

Who would have imagined a backgammon game in the DB_ engine using Generics Dictionary Entry collections, of Strongly Typed objects from my classes of Chip, Post, and PostNode... but anyway I digress. Sorry I assumed that you used a similar coding model.

What I meant specifically regarding the time being cast into an integer, in vb.net, you could do something like:

Dim iTime as integer
iTime = CInt(Now.Hour.ToString & Now.Minute.ToString)

so if the time of day is 9:54 AM the integer cast from the string "954" would be 954 As Integer

just a thought

My DBP plugins page is now hosted [href]here[/href]
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 12th Dec 2007 18:07
@CattleRustler

Ok you mean use a 32bit integer and use each byte to hold the 0-9 number of the time 0:9:5:4, or 954 as a whole integer.

Yeah I try to code similar to the way you do, using all the native language functions etc where possible. But .NET is different to C++ in that there is a lot more done for you, C++ you have to go search and bang head against wall for a while. .NET is so much nicer on that front, you want to know how to do something?

Type: System. and then navigate to the namespace that concerns you, and find the class you need (pretty much anyway )

The Sun is trying to kill me!
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2007 18:42 Edited at: 12th Dec 2007 18:49
my example above is not breaking it into bytes, so I am using the whole integer to store a number that never will exceed 2359. If were actually doing this i'd use a different variable type like Short or something else, that wasnt as big as integer.

Quote: "But .NET is different to C++ in that there is a lot more done for you, C++ you have to go search and bang head against wall for a while"

Done for you if you want it to be, but when you dont you can go as low level as C++. Hence why when I was first learning vb years ago (vb6) and started tinkering with c++, by that time .net was on the horizon so I waited. Result: I never really learned enough c++ to be proficient in it, but I didnt have to bang my head or jump through hoops with it either.

My DBP plugins page is now hosted [href]here[/href]
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2007 18:52
Side Note - Cattle Rustler - Did you know - that by using aligned "endian sized" integers - (say even when a short would do) is faster that using the smaller data type? The reason is that intel (and others - even not x86 famliy) usually have "Native" opcode/internal instructions that deal with "Aligned Data" in less clock cycles than instructions dealing with "half" or "byte" sized data. Even non-aligned data for that matter where "Half" a 32bit vlue - is in the lower 16 bits of one address while the other "half" is in the upper 16bits of another.

In the case I mention LAST above - the CPU literally (internally) needs to recreate a register with the 32bit value - do what it was going to - and perhaps "break it back apart" to store it. Even if the opcodes don't look like that is what is happening - its what IS happening "NATIVELY" in the CPU architecture.

To summerize - Saving bits is fine - But if Speed is your thing - keep the data ALIGNED - and WHENEVER possible - use ALIGNED ENDIAN SIZED integers - and ALIGNED data period. The benefit of the speed gains outweigh the "bit savings" in my book.

monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 12th Dec 2007 18:58 Edited at: 12th Dec 2007 19:00
Quote: "my example above is not breaking it into bytes, so I am using the whole integer to store a number that never will exceed 2359. If were actually doing this i'd use a different variable type like Short or something else, that wasnt as big as integer."


Ok, so what would be the point in using the time in this manner, doing it how I said would reduce the memory used so instead of using an integer for the hour and one for the minute you use one integer for the whole time.

Edit: Just seen Jason's post above, you learn something new everyday

Quote: "but I didnt have to bang my head or jump through hoops with it either."


One of few.

The .NET low-level argument. I have been using C++ for 12 years on and off, and have been using .NET for 6. .NET is an interpreted language, that is, it uses the CLR to convert the IL into machine executable code.

Anyway, straying from the point. The above code I posted is the way to do what I think you wanted to do.

The Sun is trying to kill me!
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 19:16
Thank you monotonic, that worked beautify.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2007 19:37 Edited at: 12th Dec 2007 19:41
I THINK - Even in .Net - Native Size Data Structures - Powers of 32bits - SHOULD "be faster" - hopefully MS Aligns the data in its own optimizations.

[edit]On a 64 bit Processor - 64bit wide "integers" and structures - that aligned - would be native and therefore faster -
Running 32 bit code in a 64 bit machine doesn't give any gain - is is inherently slower than using 64bit mode natively - naturally.
Just wanted to point that out - seeing how everything is going 64bit these days
[/edit]

CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2007 20:02
Quote: ".NET is an interpreted language, that is, it uses the CLR to convert the IL into machine executable code."


Not quite sure why this was brought up but, your terminology is wrong. .NET is not "interpretted", VB6 running out of its IDE, instead of making an exe, would be an example of "interpretted". .NET is simply precompiled to IL, as you stated, and then at runtime the IL is JIT compiled to native machine code and is executed. And regarding "low level argument", which theres was none, if I can maninpulate things on the pointer level, for example, am I wrong in what I am saying by "low level"?


Quote: "Ok, so what would be the point in using the time in this manner"

maybe I misunderstood the original poster's first statement?
Quote: "Hello everyone,
What is the best way to return time as an integer? For example, if I want a specific event to happen at 8:00 P.M. what would need to be done? "

Im not claiming to fully answer his question, i did, however, put the time in an integer.

My DBP plugins page is now hosted [href]here[/href]
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 20:03
For some reason, I don't think dbMid() is working right. It only gets a single character, and it doesn't even look like its relevant to the time.



Then again, I am not sure what the 'iValue' (the one dbMid() takes as a second variable) is. I have had no trouble at all with dbLeft() and dbRight() for hour and seconds respectively. Does anyone know what I am doing wrong? Thanks.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2007 20:05
look up substr (in C++ or .net) substr is what you want for that.

Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 20:30
Nevermind I got it.
Apparently dbMid() only returns a single character, so instead I just used dbRight() and moved it over 5 spaces, like such:



Thank you all for your help!
monotonic
18
Years of Service
User Offline
Joined: 24th Mar 2006
Location: Nottinghamshire, England
Posted: 12th Dec 2007 20:43 Edited at: 12th Dec 2007 20:44
Be careful dbRight returns everything to the right of the index.

0|1|2|3|4|5|6|7|
2|0|;|1|5|;|2|6|

The above time is Hour: 20, Min: 15, Sec: 26.

So dbRight( dbGetTime( ), 5 ) will return the seconds.

if you do this:



The above gives you the minutes, it strips of the seconds with the dbLeft(), then strips out the hours with dbRight()

The Sun is trying to kill me!
Crimson X
16
Years of Service
User Offline
Joined: 28th Nov 2007
Location: New Hampshire
Posted: 12th Dec 2007 20:50
After trying to use the integer in something other than a string of text, I discovered you were right! The updated one you gave me works great, thanks a bunch.

Login to post a reply

Server time is: 2024-11-19 20:36:51
Your offset time is: 2024-11-19 20:36:51