Home » Community » Forums » » Handy PC/Mac OS X Snippets for Indie Development
  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


 Last Thread Next Thread 
 Handy PC/Mac OS X Snippets for Indie Development
Post Reply 
Just want to point out that using WMI's VideoController information is probably a much more reliable way of looking up video RAM than using DX5.

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

Thanks a ton for these snippets... They are very helpful!

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

I believe that round() function will only work for positive numbers.

simple fix:
int Round( float x ) 
{
  float direction = 0.5f;
  if( x < 0.0f )
      direction = -0.5f;
  return static_cast<int>( x + direction );
} 



and a while I'm at it, more C++ oriented replacement for itoa()

#include <string> 

template< typename T >
std::string std_itoa( T const& val ) 
{
	std::stringstream ss;
	std::string ret;
	ss << val;
	ss >> ret;
	return ret;
}

// need to specialize for constant strings, stringstreams dont like spaces.
std::string std_itoa(const char* val) {
	return std::string(val);
}




"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!"
-- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website


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

Usefull snippets, but I get the idea the article was written a while ago.
I that you will find that Apple will deprecate AGL fairly soon in favor of CGL, since AGL is mainly there for Mac OS 9 compatibility, and OS 9 support is going with the Intel switch.

Edit: I see that the deprecation is already happening, albeit maybe not intentionally. Apple has deprecated several non-AGL functions neccessary to create a fullscreen render context in AGL, so although AGL is still in use, it may not be very useable for long. I haven't yet been able to coerse the CoreGraphics functions to be replacements for the deprecated functions, although there should be someway to do this.

[Edited by - swiftcoder on January 11, 2006 12:22:24 PM]

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

Useful tips, but I must criticse the way they're implemented. Specifically, the use of #ifdef throughout the code. If you're working on a large project with potentially many platforms this sort of coding can quickly lead to trouble. Instead I'd prefer to separate out the implementations for these platform/API specific functions into separate files, for example the file win_management.cpp which contains MessageBox and window setup code - it would have counterparts win_management_WIN.cpp, win_management_LIN.cpp and win_management_OSX.cpp. One tip I got off rick_appleton is that in the main .cpp file you could simple do your #ifdef check and include the relevant win_management_*.cpp file that way. Doing this maintains the portability you've suggested as well as made it more manageable overall.

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

Thanks for the comments. I guess most of them are right. About the WMI videoController thing, it looks like it is not available for Windows 98. That could be a problem if you plan to sell low-requirement shareware games.

This morning I received an e-mail asking for a QueryPerformanceTimer replacement in Mac OS X. I recommended the Carbon function "Microseconds". Is there anything better?


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

Quote:
Original post by Zaelsius
This morning I received an e-mail asking for a QueryPerformanceTimer replacement in Mac OS X. I recommended the Carbon function "Microseconds". Is there anything better?


Well, using QueryPerformanceTimer()-like functions are actually pretty dangerous, because their frequencies never are assured - they can change at any point during program execution. For instance that is the case with modern SpeedStep-like processor features where the clock frequency changes all the time.

I'm not saying QueryPerformanceTimer() is useless, but you'll need a layer on top of it which makes it more reliable.

GetTickCount() is safer, but you'll need to live with its much lower precission.

Of course, if you only want a method to check how long a small portion of code takes to execute, you don't need to care about all this.

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

Quote:
Original post by Zaelsius
This morning I received an e-mail asking for a QueryPerformanceTimer replacement in Mac OS X. I recommended the Carbon function "Microseconds". Is there anything better?


The best function seems to be the Unix gettimeofday() (since OS X is a unix box...)

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

errr... just use libSDL ... it handles it all ;-)

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

Quote:
Original post by Anonymous Poster
errr... just use libSDL ... it handles it all ;-)


Actually, it covers a great deal of stuff no one ever seems to use, such as CD Audio playing, and it doesn't have a few very useful features, such as fullscreen-windowed context switching (without rebuilding the context), which are available from the OS.

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

any idea about a function like Win32 ShellExecute that works under Mac OS X? to be more specific I want a function that opens the default browser(ShellExecute opens the default browser if it is given a URL as the program).

thanks

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

Quote:
Original post by Xeee
any idea about a function like Win32 ShellExecute that works under Mac OS X? to be more specific I want a function that opens the default browser(ShellExecute opens the default browser if it is given a URL as the program).
thanks


Not perhaps the safest method, but it works:
int result = system("open http://www.gamedev.net");
if (result == -1)
; // failure

system() is the standard C function, and open is an Apple (or at least NEXT) specific program that opens the specified file or URL with the correct program, as determined by the OS, so for a URL it will open the default browser.
There should be a way to do this directly with a Carbon function, but I don't work in Carbon much and I don't know of one off hand.

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

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: