.com.unity Forums
  The Official e-Store of Shrapnel Games

This Month's Specials

Raging Tiger- Save $9.00
The Star and the Crescent- Save $9.00

   







Go Back   .com.unity Forums > Shrapnel Community > Space Empires: IV & V

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old July 6th, 2007, 11:31 AM
Will's Avatar

Will Will is offline
Lieutenant Colonel
 
Join Date: Mar 2001
Location: Emeryville, CA
Posts: 1,412
Thanks: 0
Thanked 0 Times in 0 Posts
Will is on a distinguished road
Default Re: Ship AIs that talk to each other

Quote:
AngleWyrm said:
Quote:
Will said:
And these days, it's up to the compiler to do profiling optimizations, not the programmer. The only optimization really left to programmers now are macro-level... i.e. choosing a O(n log n) algorithm over an O(n^2) algorithm.
Compilers can do a lot, but the coder should look at a profile as well. In one project (Hat random container), when I profiled the code, I found out that it was spending a lot of time in one particular function call (the update_weights function). With this information, I was able to get a good speed boost by moving one locally constructed variable into a class member position.
Yes, but that's still what I would call "macro-level". You're getting the speed boost because instead of calculating a value that doesn't change much n times, you store it in a higher scope and calculate it fewer (one?) times. That's an algorithmic choice, much like choosing mergesort over bubblesort is, only with less dramatic results.

Even then, compilers will do a lot of that within function or method blocks. It can't be done like you were saying up to the class-level, because then optimizations would be changing the data-structure of an object, which breaks compatibility with un-optimized code. But anything that is in a self-contained block with an immutable interface to other code the compiler will optimize better than a human programmer would. So, it's best not to worry about those and focus instead on building good algorithms and data structures.

--edit: and damn! I wish the people I work with commented their code thoroughly like you did. Just a note, you may want to split hat.h into hat.h and hat.cpp, that way if you ever make a change to the methods that don't affect the interface, you don't need to recompile everything that #includes hat.h. It's a habit best learned early, lest you need to recompile and relink thousands of source files instead of just relinking thousands and recompiling one
__________________
GEEK CODE V.3.12: GCS/E d-- s: a-- C++ US+ P+ L++ E--- W+++ N+ !o? K- w-- !O M++ V? PS+ PE Y+ PGP t- 5++ X R !tv-- b+++ DI++ D+ G+ e+++ h !r*-- y?
SE4 CODE: A-- Se+++* GdY $?/++ Fr! C++* Css Sf Ai Au- M+ MpN S Ss- RV Pw- Fq-- Nd Rp+ G- Mm++ Bb@ Tcp- L+
Reply With Quote
 

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 05:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.