Script arithmatic woes w/ getRealTime()
by Orion Elenzil · in Torque Game Engine · 11/26/2007 (4:08 pm) · 5 replies
Stock tge 1.4 demo, check it:
any advice ?
i'm trying to write a profiler for script,
and getRealTime() returns values like 885404203.
==>$a = 885404203; ==>echo(885404203 - $a); -21 ==>echo($a); 885404203
any advice ?
i'm trying to write a profiler for script,
and getRealTime() returns values like 885404203.
About the author
#2
www.garagegames.com/mg/forums/result.thread.php?qt=31425
11/26/2007 (4:42 pm)
Torquescript doesn't handle large numbers very well. To get around this I added some console functions. Check the end of this post:www.garagegames.com/mg/forums/result.thread.php?qt=31425
#3
11/26/2007 (4:44 pm)
It seems to be treating the numbers as floating point. This is exactly why Torque Script should be a mildly typed languages.
#4
11/26/2007 (4:50 pm)
Ah cool; thanks guys.
#5
(i renamed your guys from "MathSub" to "mSubS32" etc)
fwiw it's worth, i made an attempt at allowing script to use the C++ profiler,
but gave up. here's the core of my code if anyone wants to pick it up.
requires STL, which i didn't integrate into our codebase, so i can't really advise on how to get that going,
but STL isn't the core of what's going on, so it shouldn't be a blocker.
it compiles and runs and Sort Of works, but basically doesn't quite work.
the idea was i was trying to emulate what the PROFILE_START() and PROFILE_END() macros do.
profiler.h
profiler.cc
11/26/2007 (6:07 pm)
Thanks again Peter, that fixed it.==>$a = getRealTime(); echo(mSubS32(getRealTime(), $a)); 0
(i renamed your guys from "MathSub" to "mSubS32" etc)
fwiw it's worth, i made an attempt at allowing script to use the C++ profiler,
but gave up. here's the core of my code if anyone wants to pick it up.
requires STL, which i didn't integrate into our codebase, so i can't really advise on how to get that going,
but STL isn't the core of what's going on, so it shouldn't be a blocker.
it compiles and runs and Sort Of works, but basically doesn't quite work.
the idea was i was trying to emulate what the PROFILE_START() and PROFILE_END() macros do.
profiler.h
#include <string> #include <map> ... using namespace std; ... typedef map<string, ProfilerRootData*> ProfilerDataMapT;
profiler.cc
ConsoleFunction(profilerScriptStart, void, 2, 2, "(string section name) Begin a profiling section.")
{
argc; argv;
if(!gProfiler)
return;
U32 keyLen = dStrlen(argv[1]) + 32;
char* key = new char[keyLen];
dSprintf(key, keyLen, "Script_%s", argv[1]);
static Profiler::ProfilerDataMapT profilerDatas;
ProfilerRootData* pdata = NULL;
const string k(key);
Profiler::ProfilerDataMapT::iterator i;
i = profilerDatas.find(k);
if (i != profilerDatas.end())
{
pdata = i->second;
delete [] key; // we accumulate these guys
}
if (pdata == NULL)
{
pdata = new ProfilerRootData(key);
profilerDatas.insert(make_pair(k, pdata));
}
gProfiler->hashPush(pdata);
}
ConsoleFunction(profilerScriptEnd, void, 2, 2, "(string section name) Finish a profiling section.")
{
argc; argv;
if(!gProfiler)
return;
gProfiler->hashPop();
}
Associate Orion Elenzil
Real Life Plus
perhaps i should try to hook this stuff in to the C++ profiler