Saturday, 29 January 2011

Happy - Belated - New Year

Sorry, Sorry Sorry, I'm sorry to the masses of phantom no-ones not reading my blog, this is a very belated welcome to the new year.  I have not been blogging, I've not been writing, I've not been on the Internet.  I have however had a jolly good Christmas and been very busy at work.

I'm sorry to say that work took the majority of time, I'll not go into details, but lets just say that a person at work, whom had a couple of months to provide part of a system didn't deliver, and I was roped in with a week to go to get it done (which I did by the way - but I don't think anyone realises that my two day lash job code was over a third of this major project... Aaaaaanyway, enough said about that.

What have I been up to?  Well, on the 26th of this Month, I became an Uncle for the first time.  My little brother's wife gave birth to a beautiful baby girl (Awwwwww).  So, tomorrow I'm going over to meet her.

My dog has also been ill, he had to have an operation to remove a lump from his belly.  All it well however, he's bounced back and the lab work says it was just a fatty lump.  So all good.

I myself have been ill also, I've indeed been to the doctor today and been put on a few strange and strong pills.  I took one and then floated around Morrisons doing the weekly shop, I have no idea what I've bought.

In personal gaming time I've not actually had that much time, I did however receive a 60 day time card for World of Warcraft for Christmas... I didn't get Cataclysm! Just time.  So I have been really really really enjoying myself maxing out all my achievements on my various characters.  I've also created a new alt, whom I'm playing utterly solo (no help from my other characters money pots or skills)... and it's a bit of a new one for me, it's a Dwarf... My first Dwarf... and a Shaman... I've never played Shaman.  And I'm really enjoying that.



I'm happy to see that my predictions of the level to item level gap were correct, as people march about with 110K health, I'm also bemused to see people in "LFG" channels demanding a certain level of item... "Not got six months of raiding done on this three month old expansion?  Well fuck off noob"... It is not a pretty sight.

When the WoW time expires I have a line up of things to do, if you'll remember I bought a new gaming rig (Core i7 - 12Gb of RAM etc etc), well one of my RAID array hard drives gave up the ghost two weeks ago, so I've had the joy of a complete reinstall of my OS.  This means that apart from WoW I have no games on the machine.

So, Civ5 and Dragon Age are going to be my two games for February and March.



I have also spent an inordinate amount of money and purchased Microsoft Visual Studio 2010 Professional.  I'm not going to tell you how much it cost me, because just writing it down will make me feel sick.  But I have sort of fallen in love with it as a development environment.

Its not perfect, there are problems with building (sometimes) and its doing its intellisense with SQL Server... and even with 12GB of RAM and 8 CPU cores it is slow at updating the hints as it goes.  But for visualising your code, organising your development and debugging (watches especially) it is brilliant.

It is the first application I've been using which I know is using the new Direct2D and DirectWrite interfaces (themselves build on top if Direct3D 10.1 and DXGI.  And that elegance and low impact on the system (for what its doing there's very little impact on my system) has inspired me to go back to native programming.

So, I've taken my C# hat and decided to leave it in the office each night, and I come home and put on my C++ hat.  I've been thoroughly enjoying Scott Meyers book "Effective C++".



It is an excellent way to wrap your head back into proper progamming technique after a break into C# or Java.  Indeed the items contained within will often make reference to how "other languages" do things and how to attain the same thing in C++.

The net upshot of this return to my love of hard core programming has been a small C++ (Win32 - not CLR) wrapper system around Direct2D, which can take a handle from a C# form and draw the Direct2D graphics defined by the C# calls within.  Its so nifty I've been given a new project at work to make it a commercial grade project... which is nice.

Indeed right now, while writing this blog I'm researching something which I've never really used in C++, the function pointers.  As Meyers points out, its is a travesty that the C++ Compiler doesn't support proper delegate functions, it is in fact easier to implement proper delegates rather than function pointers... but still delegates are not part of the C++ standards.  Though I am going to be looking at what TR1 and Boost might be offering.

Anyway, for anyone puzzling all the information out there, here's how to call a "void function" which you've pointed at from another function.  The function "A::DoSomethingWithA" takes a void pointer to a function as a parameter and calls that function.   The function is "DoIt" and I just declare a class A and pass "DoIt" as the parameter, so here you go:


class A
{
public:

A ()
{
}

~A ()
{
}

// Call a void function pointer... so we run the exteral code given
void DoSomethingWithA ( void(*ExternalFunctionPointer)(void) )
{
ExternalFunctionPointer();
}
};


// The function we are going to be passing to be called from inside A
void __cdecl DoIt (void)
{
printf_s("Hello World");
}

// The main function, which declares a class A and Does something with a function passed as a pointer
int main(int argc, char* argv[])
{
A* a = new A();
a->DoSomethingWithA(&DoIt);
delete a;

getch();

return 0;
}

Wednesday, 15 December 2010

Whhhy....

I've just been looking at a website for a few parts for my Computer, well a hard drive as I have one dying...

And I happen to spot this product... I can't think why I was drawn to look at it, despite not needing one...


Civ and Code

So, what have I been up to?  Well, since the yule tide is rolling over us I've been incredibly busy at work.

I have however been enjoying Civ5, I'm reasonably happy to play the game, though in DirectX 10 mode is does crash out sometimes.  Hopefully the up coming patch for it will sort somethings out.

In the world of code, especially at work though, I have been very busy.  I have a project to put together, but as an aside I've been looking at the boost C++ libraries, one little ditty I recently had to sort out was a hostname resolver for IPv4, here is that C++ for anyone interested in boost:

// Investigation into Boost - 14/12/2010
// (c)2010 - Jon Bond

///
/// Function to resolve a URL as an IP Address
///
std::string ResolveURLAsIPv4 (const std::string& URL, const int Port)
{
#ifdef _DEBUG
char* msg = Debugging::AssignMessage(128);
sprintf_s (msg, 128, "ResolveURLAsIP (%s : %i)", URL.c_str(), Port);
OutputDebugStringA (msg);
DWORD StartTick = GetTickCount();
#endif


std::string result = "127.0.0.1";

try 
{
// Construct the resolver service we're going to run
boost::asio::io_service IOService;
boost::asio::ip::tcp::resolver resolver(IOService);

// Set up the IP query we're going to run on the resolver service
boost::asio::ip::tcp::resolver::query query(
boost::asio::ip::tcp::v4(),
URL,
boost::lexical_cast(Port) );

// Set up the query we're going to iterate through
boost::asio::ip::tcp::resolver::iterator i = resolver.resolve(query);

// Iterate through all the end points returned by the DNS query
boost::asio::ip::tcp::resolver::iterator endIterator;
for ( ;
i != endIterator;
++i)
{
// Get the current end point indicated
boost::asio::ip::tcp::endpoint currentEndPoint = *i;

// Process the result
if ( currentEndPoint.address().is_v4() )
{
result = currentEndPoint.address().to_string();
// break out of the loop
break;
}
}
}
catch (std::exception e)
{
#ifdef _DEBUG
sprintf_s (msg, 128, "Error in ResolveURLAsIP.");
OutputDebugStringA (msg);
delete msg;
#endif

throw e;
}

#ifdef _DEBUG
DWORD Diff = GetTickCount() - StartTick;
sprintf_s (msg, 128, "ResolveURLAsIP Complete [%d] %s => %s", Diff, URL.c_str(), result.c_str() );
OutputDebugStringA (msg);
delete msg;
#endif

return result;
}
Please note, I know I could cut down the number of boost::asio:: whatever indirections by using 'using' statements, but this is fully written out so I could understand what was going on.

The other ditty I've been playing with is Direct2D as part of DirectX 10 on Vista & Windows 7... here's my class to initialise the Direct2D interface:

// Investigation into Direct2D - 3/12/2010
// (c)2010 - Jon Bond

#pragma once

// The program main
#include "..\Program\Program.h"

// Include the header
#include "D2D1.h"

// Include the library
#pragma comment (lib, "d2d1.lib")

namespace GuiMain
{

// The gui
class Gui
{
private:
// Shows whether there has been an error
bool m_Error;

// The window handle
HWND m_WindowHandle;

// The factory
ID2D1Factory *m_Factory;

// The render target
ID2D1HwndRenderTarget *m_Target;

// Factory handlers
void SetupFactory();
void CloseFactory();

// Create the resources
void CreateDeviceResources();
void ReleaseDeviceResources();

// Get the window size
D2D1_SIZE_U GetWindowSize ();

// A white solid brush
ID2D1SolidColorBrush* m_WhiteBrush;

public:

// The gui constructor
Gui (HWND WindowHandle);

// The gui destructor
~Gui ();

// Draw something
void Render ();

};


}

Code:

// Investigation into Direct2D - 3/12/2010
// (c)2010 - Jon Bond
#include "GuiMain.h"

namespace GuiMain
{

// Constructor
Gui::Gui(HWND WindowHandle)
{
m_Error = false;

// The window handle
m_WindowHandle = WindowHandle;

// Set up the factory
SetupFactory();
}

// Destructor
Gui::~Gui()
{
// Release the device drawing resources
ReleaseDeviceResources ();

// Close the factory
CloseFactory ();

m_WindowHandle = NULL;
}

// Set up the COM class factory for this interface
void Gui::SetupFactory()
{
HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_Factory);
if ( hr == S_OK )
{
CreateDeviceResources ();
}
}

// Close the factory
void Gui::CloseFactory()
{
// Release the factor, if it exists
if ( m_Factory != NULL )
{
m_Factory->Release();
m_Factory = NULL;
}
}

// The device resources
void Gui::CreateDeviceResources()
{
HRESULT hr ;

hr = m_Factory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(),
D2D1::HwndRenderTargetProperties(m_WindowHandle, GetWindowSize()),
&m_Target);
if ( hr != S_OK )
{
m_Error = true;
}
else
{
// Create the white brush
hr = this->m_Target->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF::White),
&m_WhiteBrush);

if ( hr != S_OK )
{
m_Error = true;
}
}
}

// The release the device resources
void Gui::ReleaseDeviceResources()
{
m_WhiteBrush->Release();
// Dispose of the tar
if ( m_Target != NULL )
{
m_Target->Release();
m_Target = NULL;
}
}
// Return the screen size
D2D1_SIZE_U Gui::GetWindowSize ()
{
RECT rect;
GetClientRect (m_WindowHandle, &rect);
return D2D1::SizeU(rect.right-rect.left, rect.bottom-rect.top);
}
// Render something
void Gui::Render ()
{
m_Target->SetAntialiasMode(D2D1_ANTIALIAS_MODE::D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
m_Target->BeginDraw();
m_Target->Clear(D2D1::ColorF(D2D1::ColorF::Black));
m_Target->SetTransform(D2D1::Matrix3x2F::Identity());
D2D1_SIZE_U size = GetWindowSize();
m_Target->DrawLine (
D2D1::Point2F(0.0f, 0.0f),
D2D1::Point2F(size.width, size.height),
m_WhiteBrush,
0.5f
);
m_Target->EndDraw();
}
}

Please note, all my code here is copyright 2010 - Myself, but you may use it as you see fit.  So long as you leave my copyrght notices and name on the code.

Monday, 6 December 2010

Its time for 'it'

So, it is about to happen... if you don't know what I mean by 'it' then you've been living under a rock, because the 'it' to which I refer is Cataclysm.

I'm going to be honest, I have been back, briefly into WoW; I had a month on my main account a while back, but I was hopelessly annoyed at the inflation of items over my hard earned raid gear... so I quit again.

But now, it is the day, before the big day.  And I'm feeling a few pangs of longing, even though I'm pissed off utterly with the inflation in the game, I love its look, I love the game; I'm just so tired and bored of it.

And I'm going to miss Loch Modan, I'm going to miss Stormwind, I'm going to miss all those lands we've all spent so long living in.

Okay, I'm not going to miss Outlands, nor am I going to give a shit about Northrend.  But as I consider myself a veteran player of the original game, and I spent the best part of three years just playing out those area's, I am going to miss them.

The questions are... when will I go in to take a look at everything that's going on?  And will I miss it all going on "live" because its happening on a Tuesday and I'm at work?

Monday, 22 November 2010

The Chore of No Game

So, I've recently been wrestling with a new PC build... well, not so much wrestling as oiling up and pressing myself against its sheer sexual energy.

But the failure of my old rig really cut into my regular play time, so much so, that the dreaded lady of the house seems to think that I should always have a lot of time to watch X-Factor and the like with her on a Saturday night... Oh Lord above save me!

But I have actually managed to get two games installed now, first off Eve, which I have all three accounts training on thanks to 5 free days on each from CCP... I'm not re-subbing to Eve just yet, with so much expenditure recently I can't justify it.

Likewise, I've not looked at any of the F2P MMO's (D&D, LOTRO or RoM) which I was playing previously, mainly because I will have to wait for vast amounts of data to download in order to get into them...

But I have put CIV5 back on the machine, thanks to Steam and the superior bandwidth Valve get it was a breeze.  And over the weekend I enjoyed a decent random game as the French, when I busily wiped the smug Samurai smile off of Japan's face.

Another thing I have been up to though is selling off lots of my old PC parts on the old auction sites.  I had hoped the CPU in my old Quad Core rig (its Core 2 Quad Q6600 2.6GHZ) would have survived the destruction wrought in my old rig dying, but it seems its not, dropping it into another Core2 Quad able mobo I have and it seems to be dead as a door nail... Hey ho, onwards and upwards with my eight thread true quad core and 12GB of RAM... Roar.

Friday, 12 November 2010

The Good, The Bad and the Intel...

Just a quick new post, first of all, the good... I've had a stinking cold for like a week, and it has kept me up all night, but finally after forcing myself to stay in bed and doing a lot of Vitamin-C I feel better.

The Bad... My main PC has died, it is no more... my prior post about patching out the broken piece of memory was just holding off the inevitable, and it burned out the motherboard.

This leads me to the Intel, I've just placed an order for a new Core i7 - 950 chip, a nice Asus motherboard and 12GB of DDR3 from Corsair.

The bad news is between now and then I'm using my old P4 (which is still a nice P4 HT 3 ghz).

Monday, 8 November 2010

Remember, Remember the Month of November

Well, it's been a busy busy old time for me, so appologies to anyone out there wondering why I was not sending out my moaning groaning vibe.

So here we are, it's November... A month of Rememberance here in Britain, on the 11th we Remember and mark the end of the First World War, and reflect on the losses our armed forces have suffered then and ever since.

Having one grand father a veteran of the Battle of North Cape and D-Day aboard HMS Belfast, the other a veteran of the British Expeditionary Forces who fled the beaches of Dunkirk and whom later was part of the return at Normandy; not to mention one Grandmother who tended the wounds of returning USAAF Airmen and another in the British Land Army.

I find myself taking a moment to remember them.
They went with songs to the battle, they were young.
Straight of limb, true of eyes, steady and aglow.
They were staunch to the end against odds uncounted,
They fell with their faces to the foe.
They shall grow not old, as we that are left grow old:
Age shall not weary them, nor the years condemn.
At the going down of the sun and in the morning,
We will remember them.