Home » Community » Forums » » Enginuity, Part III
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic

Page:   1 2 3 4 5 6 7 8 9 »»

 Last Thread Next Thread 
 Enginuity, Part III
Post Reply 
Hmmmmm, some interesting new concepts for me to explore. Cheers, superpig


pan narrans | My Website | Study + Hard Work + Loud Profanity = Good Code

 User Rating: 1788   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

num num num :9

 User Rating: 1027   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

pan narrans, is it just me or do you have the first reply in all the Enginuity discussion topics?

 User Rating: 2118   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

A few problems with that code though... first, it relies on SDL_GetTickCount, which.. well, just isn't accurate enough for such small time stamps, hence you could see a bottleneck in one run, and the next run it dissappears (because it wasn't really a bottleneck, the timer just isn't accurate enough to measure such small time slices). I would say you are better off using the rdtsc (Read time stamp counter). It measures the number of CPU cycles taken to process a certain section, and is thus, MUCH more accurate. (Of course, you have to store this in a 64-bit number as it grows very large, very quickly).

Simple example on how to use this (msvc style):
inline unsigned __int64 readTimeStampCounter()
{
  #pragma warning( disable: 4035 )  // Disable warning message "no return value"

  __asm rdtsc
}


This will return the clock cycle of the CPU . So, you can take the end-start to get total cycles passed. Similar to how you're using the other timer, but a whole lot more accurate!

 User Rating: 1053   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

If you want to use RDTSC I suggest you take a look at this.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Ready4Dis
A few problems with that code though... first, it relies on SDL_GetTickCount, which.. well, just isn't accurate enough for such small time stamps, hence you could see a bottleneck in one run, and the next run it dissappears (because it wasn't really a bottleneck, the timer just isn't accurate enough to measure such small time slices). I would say you are better off using the rdtsc (Read time stamp counter). It measures the number of CPU cycles taken to process a certain section, and is thus, MUCH more accurate. (Of course, you have to store this in a 64-bit number as it grows very large, very quickly).


Sounds good... but:

1) Are you sure _rdtsc is cross-platform? Remember, this is all meant to run on linux/macOS...
2) SDL_GetTickCount uses (on Win32 at least) QueryPerformanceCounter, or so I'm told. For a quick-and-dirty runtime profiler, that's accurate enough for me...

If you're not bothered by those, then by all means use a cycle counter - I could forsee problems when trying to calculate the framerate from that, though.



Superpig
- saving pigs from untimely fates, and when he's not doing that, runs The Binary Refinery.

 User Rating: 2118   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

Could you please push out the next article? =) I know you have a few more written. This community, as well as I, would def be most appreciative if you could push another one out soon. lol aka. tomorrow? Aside from that, your series is absolutly fabulous. Keep up the great work. -- andy

 User Rating: 1040   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

love the series so far, waiting for more...
just one thing... its www.fmod.org
not www.fmod.com

 User Rating: 1057   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Great article! Really!

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by lucinpub
love the series so far, waiting for more...
just one thing... its www.fmod.org
not www.fmod.com


Aww, crap. I thought it was the other way around... had the same problem with the original draft in the Game Programming forum.

skillfreak: Uh, I'd better give my typing fingers time to cool down first

Superpig
- saving pigs from untimely fates, and when he's not doing that, runs The Binary Refinery.

 User Rating: 2118   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

Astonishing article as the others two! Congratulations

I'm waiting for the next one!

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

No need to say the said, tell the told, speak the spoken. How many articles more do you still have for us?

.lick


 User Rating: 1469   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Enginuity (lol)

I'm glad somebody's willing to tackle how to make a game engine properly (using OOP w/ C++ at least). Chris Hargrove did a good job in cotc, sad to see it's 'fate' though. Be interesting to see what kinda games come from gamedevers using the engine from yer series. Looking forward to part 4, gl superpig (I hope you didn't get yer name from savin those pigs in Earthworm Jim ).

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

<nit-pick>
In the kernel loop, isn't ++it faster than it++?
</nit-pick>

 User Rating: 1016   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

The warnings are starting to build up and I'm getting 3 errors due to not returning anything from the CMMPointer's = operator (although I didn't earlier)
error C4716: 'CMMPointer<ITask>::operator=' : must return a value
with the first one, inline operator =(const CMMPointer<T> &p) and
error C4716: 'CMMPointer<ITask>::operator=' : must return a value
error C4716: 'CMMPointer<BaseDator>::operator=' : must return a value
with inline operator =(T* o)

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by Anonymous Poster
The warnings are starting to build up and I'm getting 3 errors due to not returning anything from the CMMPointer's = operator (although I didn't earlier)
error C4716: 'CMMPointer::operator=' : must return a value
with the first one, inline operator =(const CMMPointer &p) and
error C4716: 'CMMPointer::operator=' : must return a value
error C4716: 'CMMPointer<baseDator>::operator=' : must return a value
with inline operator =(T* o)


You must be using GCC or MSVC7. MSVC6 lets me get away with it, but I'm aware that it officially, operator= is meant to have a return type specified.


operator =(...){...}


should be


CMMPointer<T> &operator =(...){...; return (*this); }


It's fixed in my current code (as far as I know) so the later articles will have updated source.

Pipo: Not sure, at least 3 more.

Synder: heh. Actually, it comes from a cartoon character I used to draw, though I'm told it's also the name of an obscure anime series.

Oh, and if anyone actually *does* develop something using Enginuity code, I always appreciate a heads-up. I wanna see what amazing things people do with it!

sbennett: *sigh* I seem to remember the discussion on the draft article (in the depths of the game programming forum) lost about 3 pages to that question the general consensus was that todays optimizing compilers are smart enough to pick whichever is faster, but you are of course always free to change the code.

Superpig
- saving pigs from untimely fates, and when he's not doing that, runs The Binary Refinery.

Enginuity1 | Enginuity2 | Enginuity3

[edited by - Superpig on July 5, 2003 5:42:52 PM]

 User Rating: 2118   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

quote:
Original post by superpig
quote:
Original post by Ready4Dis
A few problems with that code though... first, it relies on SDL_GetTickCount, which.. well, just isn't accurate enough for such small time stamps, hence you could see a bottleneck in one run, and the next run it dissappears (because it wasn't really a bottleneck, the timer just isn't accurate enough to measure such small time slices). I would say you are better off using the rdtsc (Read time stamp counter). It measures the number of CPU cycles taken to process a certain section, and is thus, MUCH more accurate. (Of course, you have to store this in a 64-bit number as it grows very large, very quickly).


Sounds good... but:

1) Are you sure _rdtsc is cross-platform? Remember, this is all meant to run on linux/macOS...
2) SDL_GetTickCount uses (on Win32 at least) QueryPerformanceCounter, or so I'm told. For a quick-and-dirty runtime profiler, that's accurate enough for me...

If you're not bothered by those, then by all means use a cycle counter - I could forsee problems when trying to calculate the framerate from that, though.



Superpig
- saving pigs from untimely fates, and when he's not doing that, runs The Binary Refinery.



You can use rdtsc on any current x86 cpu (I forget when it came out, but I beleive any pentium 1+ has it, maybe even the 486's?). MacOS, you will have to find a different way to acheive this (although, i believe it has something very similar), but I wouldn't rely on GetTickCount.. it's only accurrate to 10 milliseconds, which is MUCH longer than a lot of smaller functions take. So, it will appear that a 10ms function takes the same time as a 1ms function, and if that 1ms function is called repeatedly, it will appear like it's taking up WAY more time than it really is, so you'll be trying to fix things that aren't actually bottle necks. Yes, calculating the frame rate from it would be hard (you'd have to figure out the cpu speed to be able to use this value for anything time based), but comparing it against itself for percentages will work properly for something like this without needing the clock speed. When it comes to profiling small sections of code that are run many times, the missing accuracy in the GetTickCount method will probably have a lot of people optomizing stuff that isn't a problem.

 User Rating: 1053   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by Ready4Dis
I wouldn't rely on GetTickCount.. it's only accurrate to 10 milliseconds


Could you point me to evidence of that? Not that I don't believe you, just that I've been told it uses QueryPerformanceCounter (which is accurate to 1ms).

Superpig
- saving pigs from untimely fates, and when he's not doing that, runs The Binary Refinery.

Enginuity1 | Enginuity2 | Enginuity3

[edited by - Superpig on July 5, 2003 5:33:56 PM]

 User Rating: 2118   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

I'm thoroughly enjoying this series so far, even though I'm not personally interested in writing a game at this point, it's still providing tons of useful information applicable to many other projects. Good job

 User Rating: 1015    Report this Post to a Moderator | Link

Why should settings be stored in a std::string? Why not boost::any?

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by Anonymous Poster
Why should settings be stored in a std::string? Why not boost::any?



Because BOOST isn't being used.....

 User Rating: 1027   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

superpig I believe your right about the Performance counter, however SDL most likely falls back to Window's GetTickCount if a performance counter is not available (not sure what cpu's don't have this). If so your only going to have 10-15 ms accuracy.

 User Rating: 1070   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I just checked the SDL code, and it uses querryperformancecounter if available, but does fall back to GetTickCount when it's on windows CE (under a windows platform). It should be accurate enough under most version of windows, not sure about the linux implementation. I also found out that queryperformancecounter is very slow to call, where my version is much faster in this case. I guess it'll be fine for the majority of programmers on this site, as most run a version of windows with a high performance counter built in. I wasn't sure what SDL_GetTickCount used and judging by the name, it appeared to be just a copy of GetTickCount with an SDL thrown in front of it . Like I said though, for the most part, SDL_GetTickCount will be good enough for most people.

 User Rating: 1053   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Settings.cpp
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(14) : warning C4311: 'type cast' : pointer truncation from 'CSettingsManager *' to 'int'
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(9) : while compiling class-template member function 'Singleton<T>::Singleton(void)'
with
[
T=CSettingsManager
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\Settings.h(16) : see reference to class template instantiation 'Singleton<T>' being compiled
with
[
T=CSettingsManager
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(14) : warning C4311: 'type cast' : pointer truncation from 'Singleton<T> *' to 'int'
with
[
T=CSettingsManager
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(15) : warning C4311: 'type cast' : pointer truncation from 'Singleton<T> *const ' to 'int'
with
[
T=CSettingsManager
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(15) : warning C4312: 'type cast' : conversion from 'int' to 'CSettingsManager *' of greater size
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\mmanager.h(41) : error C2440: 'return' : cannot convert from 'CMMPointer<T>' to 'int'
with
[
T=BaseDator
]
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\mmanager.h(37) : while compiling class-template member function 'int CMMPointer<T>::operator =(const CMMPointer<T> &'
with
[
T=BaseDator
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\utility(56) : see reference to class template instantiation 'CMMPointer<T>' being compiled
with
[
T=BaseDator
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(42) : see reference to class template instantiation 'std:air<_Ty1,_Ty2>' being compiled
with
[
_Ty1=const std::string,
_Ty2=CMMPointer<BaseDator>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(61) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,CMMPointer<BaseDator>,std::less<std::string>,std::allocator<std:air<const std::string,CMMPointer<BaseDator>>>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(83) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,CMMPointer<BaseDator>,std::less<std::string>,std::allocator<std:air<const std::string,CMMPointer<BaseDator>>>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xtree(101) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,CMMPointer<BaseDator>,std::less<std::string>,std::allocator<std:air<const std::string,CMMPointer<BaseDator>>>,false>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\map(77) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,CMMPointer<BaseDator>,std::less<std::string>,std::allocator<std:air<const std::string,CMMPointer<BaseDator>>>,false>
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\Settings.h(31) : see reference to class template instantiation 'std::map<_Kty,_Ty,_Pr,_Alloc>' being compiled
with
[
_Kty=std::string,
_Ty=CMMPointer<BaseDator>,
_Pr=std::less<std::string>,
_Alloc=std::allocator<std:air<const std::string,CMMPointer<BaseDator>>>
]
Kernel.cpp
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(14) : warning C4311: 'type cast' : pointer truncation from 'CKernel *' to 'int'
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(9) : while compiling class-template member function 'Singleton<T>::Singleton(void)'
with
[
T=CKernel
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\Kernel.h(20) : see reference to class template instantiation 'Singleton<T>' being compiled
with
[
T=CKernel
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(14) : warning C4311: 'type cast' : pointer truncation from 'Singleton<T> *' to 'int'
with
[
T=CKernel
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(15) : warning C4311: 'type cast' : pointer truncation from 'Singleton<T> *const ' to 'int'
with
[
T=CKernel
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\singleton.h(15) : warning C4312: 'type cast' : conversion from 'int' to 'CKernel *' of greater size
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\mmanager.h(48) : error C2440: 'return' : cannot convert from 'ITask' to 'int'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\mmanager.h(44) : while compiling class-template member function 'int CMMPointer<T>::operator =(T *)'
with
[
T=ITask
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\list(34) : see reference to class template instantiation 'CMMPointer<T>' being compiled
with
[
T=ITask
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\list(51) : see reference to class template instantiation 'std::_List_nod<_Ty,_Alloc>' being compiled
with
[
_Ty=CMMPointer<ITask>,
_Alloc=std::allocator<CMMPointer<ITask>>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\list(71) : see reference to class template instantiation 'std::_List_ptr<_Ty,_Alloc>' being compiled
with
[
_Ty=CMMPointer<ITask>,
_Alloc=std::allocator<CMMPointer<ITask>>
]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\list(88) : see reference to class template instantiation 'std::_List_val<_Ty,_Alloc>' being compiled
with
[
_Ty=CMMPointer<ITask>,
_Alloc=std::allocator<CMMPointer<ITask>>
]
c:\Documents and Settings\Matt\My Documents\Visual Studio Projects\Engine\Engine\Kernel.h(34) : see reference to class template instantiation 'std::list<_Ty,_Ax>' being compiled
with
[
_Ty=CMMPointer<ITask>,
_Ax=std::allocator<CMMPointer<ITask>>
]


Still alot of problems.

 User Rating: 1015    Report this Post to a Moderator | Link
Page:   1 2 3 4 5 6 7 8 9 »»
All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: