Improve your VS2010 performance under VMWare 7

Posted by HippieHunter Sat, 19 Dec 2009 02:02:00 GMT
Finally in VMWare 7 you can enable 3d acceleration and not just have VS2010 Beta 2 crash outright. you would hope this would improve performance when doing things like scrolling in the code editor. well it does, just not as much as it should. The WPF guys are doing some nifty eye candy scaling based on your hardware level. So if we want the full performance boost we need to disable the graphical goodies. Ive not seen a way to do this from inside VS but you can do it from regedit HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\General Has AutoAdjustExperiance and VisualEffectsAllowed. If you set them both to 0, Visual studio 2010 will perform much better.

Compiler safety and typing

Posted by HippieHunter Thu, 11 Jun 2009 18:03:00 GMT

As far as the internet is concerned C++ is a staticly typed language (also some people who think its strongly typed), academically we know this is untrue but this isn’t about what’s actually correct it’s about the perception of safety or lack of, from the C++ compiler. Certainly C++ lets you break all the rules and use void* for all types throwing caution to the wind but that’s not really all that common in non ancient C code. 
 
This particular rant is brought to you by a stack overflow response to a blatant flame war question "C++ slow, python fast? (in terms of development time)" one part of the large response caught my attention "That being said, static typing might be helpful if you're just making the move to larger programs. The compiler will catch some things that will only show up at run time with Python." While this is certainly true to an extent it’s really ignoring a very important reality. Inexperienced C++ programmers (the op clearly is) are wholly incapable of writing safe (read: compiler checked) C++. Remember that bit about all types as void*, rope, hanging and shooting one’s self? Well there are many shades of void* and most of them are used more frequently. at one of the more nitpicky ends is const correctness, it really is a pretty massive pain in the ass to maintain 100% const correctness but it’s got the odd habit of producing categorically better code. So why am I brining up const incorrectness and void* programming? Because that’s how people who are new (or old) to the language go about solving problems, with unsafe hacks to fill in their language feature knowledge gaps. 
 
My point in all of this is that people who believe they are effectively relaying the strengths and weaknesses of languages almost never say anything useful at all. Argument generalization is not the friend of general purpose programming languages. So here comes the mother of all generalizations, in all things if you are bad there is no tool that will make you good, only tools that will make you less bad. There are however tools that can make you worse, so if you're a badie at programming no amount of thinking C++ is faster or more type safe will ever make your code faster or more type safe.

boost.Assignment and other romps through syntax

Posted by HippieHunter Tue, 27 Jan 2009 12:03:00 GMT

 

 here is a bit of code from AV, don't think of this as c++, really it should be thought of as an AV built ins scripting DSL that happens to get compiled by the c++ compiler.

void somemethod()
{
        class PhilosophersStone
  {
  public:
    PhilosophersStone(vector<uint32_t> buildings, Project&; proj)  
    {
      buildings.push_back(proj.Id());
      proj.OnUpdateTurn = OnUpdateTurn;
    }
    static void OnUpdateTurn(Council& council, Player& player, Territory& territory, ControlModel& controlModel)

    {
      controlModel._commandAndControl += 5;
    }
  } philosophersStone(philosophy._buildings, PROJECT_TABLE.CreateProject(5000, 
    10000, 
    "Philosophers Stone",
    "its super cool and stuff",
    list_of( PREREQUISITE_TABLE.TechRequisite(philosophy))));
}

as you look at this you may notice that ive managed to get way to much code into a class declaration, yes infact the last ';' you see there is the ';' you normally see on class rawr {}; <---- that one. You might be saying to your self "holy shit wtf is he doing", well one of the features inherited from C is that you can create an instance of a struct/class directly after the definition of the type. well since this is c++, i can add a constructor and put that sucker on the end. Next up I create a project with mostly simple parameters but wait!!!! wtf is this list_of thing? list_of comes from boost.Assignment and it allows me to define a collection inline. the somewhat odd syntax for multiple elements would be list_of(5)(4)(3)(2)(1), just a bit of an eye-full there with all the overloaded operator() action. Still this once again demonstrates to me how vastly superior C++ is to every other language on the planet(that includes spoken languages).

 

 

 

 

 


baking with function pointers

Posted by HippieHunter Fri, 23 Jan 2009 00:41:00 GMT

One of the more interesting features in C++ template(IMHO) is being able to bake a compile time constant value directly into a template instance. One nice thing about function pointers is that they have a constant for an address. I'm not 100% sure what I can really use this for but it certainly looks cool! Of certain interest is template deduction on a function pointer, I was very surprised(pleasantly) to find this code compile.

#include<iostream>
#include<string>

using namespace std;

template<typename T, T (*F)(T)>
class rawrg
{
public:
  rawrg(T val)
  {
    F(val);
  }
};

template<typename T>
T method(T t)
{
  cout<< t << endl;
  return t;
}

int main()
{
  rawrg<const string&, &method> rawr("trivial");
  rawrg<float, &method> rawrg(5.5);
}

Ridiculus coolness

Posted by HippieHunter Mon, 22 Dec 2008 05:19:00 GMT

 This is a snip of code from AV and I am about to tell you once again, the single coolest thing in C++ is member pointers(function and data). oh and local class declarations are also THE shit. I suppose this isnt neccisarily the most readable code in the world but.... the most awsome things rarely are. Now if only synergy supported this :d

void MessageBox::SendMessage(ArchverseCore::Game::DiplomaticMessage &message)
{
  Player sendingPlayer, recivingPlayer;
  if(PLAYER_TABLE.Exists(message._senderId) &&
    PLAYER_TABLE.Exists(message._targetId))
  {
    class PushMessage
    {
    private:
      uint32_t _messageId;
      vector<uint32_t>& (MessageBox::*_target)();
    public:
      PushMessage(uint32_t messageId, vector<uint32_t>& (MessageBox::*target)()) : _messageId(messageId), _target(target) {}
      bool operator()(Player& player)
      {
        (player.Messages().*_target)().push_back(_messageId);
        return true;
      }
    };
    MESSAGE_TABLE.SaveMessage(message);
    PLAYER_TABLE.LockedTransaction(message._senderId, PushMessage(message._id, &MessageBox::Sent));
    PLAYER_TABLE.LockedTransaction(message._targetId, PushMessage(message._id, &MessageBox::Inbox));
  }

}

functional programming in Synergy/DE

Posted by HippieHunter Thu, 18 Dec 2008 17:46:00 GMT

 Yes it is possible to do the basics of functional programming in Synergy. It is missing some of the conveniences of C++ or ML but still it works. sometime in the future I will explain how this is useful to the average user.

import System.Collections
namespace functor
  
  ;;; <summary>
      ;;; The main entry point for the application.
      ;;; </summary>        
  main
  record
    al, @ArrayList
    ii, int
  proc
    al = new ArrayList()
    for ii from 0 thru 100
    begin
    data iii, @int
      iii = (@int)ii
      al.add(iii)
    end
    open(1, o, "tt:")
    for_each.Call(al, new MyFunctor())
  endmain
  
  class for_each
    public static method Call, void
    al, @ArrayList
    func, @SimpleIntFunctor
    endparams
    record
      ii, int
    proc
      for ii from 0 thru al.Count - 1
      begin
        func.Call((int)al[ii])
      end
    endmethod
      endclass
  
  abstract class SimpleIntFunctor
    public abstract method Call, void
    i, int
    proc
    endmethod
    
  endclass
    
  class MyFunctor extends SimpleIntFunctor
    
    public override method Call, void
    i, int
    proc
        writes(1, %string(i))  
    endmethod        
  endclass      
endnamespace

C++ is the greatist and most terribleist!

Posted by HippieHunter Sat, 26 Apr 2008 07:56:00 GMT
template<typename T>
class MemberPointerContainer
{
  typedef int T::* MEMPTR;
public:
  MemberPointerContainer(MEMPTR element)
  {
    _element = element;
  }
   
  template<typename R>
  static MemberPointerContainer CreateMemberPointer(R T::* element)
  {
    return MemberPointerContainer(reinterpret_cast<MEMPTR>(element));
  }
 
  template<typename R>
  void Set(T& t, R value)
  {
    typedef R T::* MEMPTR_SPECIALIZED;
    t.*(reinterpret_cast<MEMPTR_SPECIALIZED>(_element)) = value;
  }
  MEMPTR _element;
};

class NetworkEntity
{
public:
  int field1;
  int field2;
  double field3;
};
#include<vector>
void main()
{
  std::vector< MemberPointerContainer<NetworkEntity> > vect;  
  vect.push_back(MemberPointerContainer<NetworkEntity>::CreateMemberPointer(&NetworkEntity::field1));
  vect.push_back(MemberPointerContainer<NetworkEntity>::CreateMemberPointer(&NetworkEntity::field2));  
  vect.push_back(MemberPointerContainer<NetworkEntity>::CreateMemberPointer(&NetworkEntity::field3));
  NetworkEntity net;
  vect[0].Set(net, 5);
}
the nice thing is that even with all this indirection going on getting and setting is just like calling a member via 'this' as far as the actual x86 instructions are concerned. Why might this bee cool and terrible? Well the basic readability of it defines the terribleness, that combined with the general idea that you can do literally anything with C++ is a reasonably straight forward yet often obscure manor. As for the greatness, well this bit-o-code is going to help me write persistence layers that dont suck to code for. Something along the lines of boost::serialize only light weightier and more specialized to dealing with my style of data structures.

Programming languages

Posted by HippieHunter Fri, 16 Feb 2007 05:11:00 GMT

 As it turns out I really like the idea of languages other than C++, such as LISP or ML its just that when I see the syntax I want to rip my eyes out and throw them in an incinerator. Im sure they are great languages and LISP apparently even preforms as well as C++ but I just cant live with out C++. I guess I'm stuck with it, at the ripe old age of 20 and I'm to old to learn a new language. Well not totally true, I program in C# at work and I guess I do technically know DBL but I don't do anything in DBL and C# is practically just C--, so I'm right at home with it.

 
This brings me to the reason I've been looking at other languages, Archspace scripting for AI. Its a really fantastic idea in theory but the problems of choosing the best tool for the job get a little hairy. So I will just throw out the line up, First up there is LISP. LISP is historically useful in this area, I have no idea why but it has been tied to AI research since the idea of such things came into being. Second up we have AngelScript, Its like C++ only with no pointers. The pros; Easy binding to C++, decent performance, C++ syntax. The cons; I don't actually know anyone with direct experience in the language. Then we have Lua, its small, has decent performance and is easily embedded into something made in C++. But Lua is so god damn horrible to look at, not a ; or {} in sight, As a c++ programmer I rely on those to tell me important information. I will also mention Squirrel, its another C like Scripting language but its typeless like Lua so if it were me, and I was into the whole typeless thing I would be in there like swim ware. But I have really mixed feelings about typeless languages like that, JavaScript has left me with a bad taste in my mouth. 
 
As a side note, no one ever reads my F'ing blog so ive shamelessly plugged myself on the Archspace Forums. I have no idea if it will do me any good.

Archspace 2

Posted by HippieHunter Thu, 15 Feb 2007 04:01:00 GMT

 Ive yet again picked up working on Archspace 2, this must be the 100th time. Each time I come back to it though I look at the design and tweak it a little, eventually I might actually get the one I want. Hopefully when I do its crazy awesome good. Just a little overview for those of you who care, Ive taken a loosely coupled approach to design. Pretty much everything is an entity and entity's can contain other entity's, of course. That was design round one, in round two I realized that I would have to do a little more then just basic updates of entity's in their own self contained worlds but it would be horribly hard to do so looking through the entity's children for all the info. So I decided to keep the children and add some members that were really just pointers to the children but with type info associated. At this point I have the architecture to update anything in the game using implementations of a visitor and in that update I can actualy do something with the info contained. 

 
Now in one of my more recent re-workings I've decided to make the generation of XML more explicit. Before now I was just sending in a stream, filling it with data and sending it on its marry way to the client. Now the system explicitly uses the XML DOM provided by Poco and then as the last step it pushes it out to a stream. If there was one thing I learned about doing HTML output in C++ it was that C++ and escaped chars everywhere are not the most fun thing in the world. Through this I'm really hoping that there will be very few constant strings actually in the code, with everything in the XSLT or contained in some sort of text lookup for purposes of multi language support.
 
For my next feat of awesome I intend to come up with a heavily programmable battle system, where the users can actually program the AI that controls their ships but still have some decent premade options available. I'm guessing I will have to support multiple scripting languages to make things fair, since I would choose something like AngelScript or Pike long before I used Lua, Python or Ruby. But those languages are much more popular so life would be better if I allow a bunch of them. I don't think i would want to integrate perl though since it would probably not be very safe. 

Boost is fun

Posted by HippieHunter Tue, 23 Jan 2007 04:43:00 GMT

 Lately I've been working on the next version of Archspace. While I knew about a lot of the great things in boost I had never really used them in practice. Well I've found my new digital best friend, Boost Lambda Library. Its just so damn cool though I should say that it wouldn't be nearly as cool without Boost Bind along with it.

 
The design of Archverse demands that it very heavily use containers, iterators and patterns. Without Boost Lambda doing these things are really kinda tedious and grow unwieldy with time. Lambda lets me write functors right where they need to be used instead of adding a new header file and making another cpp file for just one tiny little class with one tiny little function. Functors are one of the nicest parts about C++ now I can use them all over the place without wasting time writting full blown function objects.