Archive

Archive for June, 2010

Poor man’s A/C

June 22nd, 2010 Jerdak No comments

Lifehacker brings this interesting article about staying cool w/o the need for air conditioning (…. no thank you) but the first item on their list made me smile.

Back in college our “air conditioner” was a bucket/bag of ice sitting in front of a fan. The “peak” cooling time was when the ice had somewhat melted and the fan began blowing a tiny mist throughout the room.

Categories: Uncategorized Tags:

Sad, but in a crotch kicking way

June 17th, 2010 admin No comments

I read this on CNN today and it made me sad, very sad:

He singled out this sentence from Obama as unfortunate: “That is why just after the rig sank, I assembled a team of our nation’s best scientists and engineers to tackle this challenge — a team led by Dr. Steven Chu, a Nobel Prize-winning physicist and our nation’s secretary of energy.”

“A little less professorial, less academic and more ordinary,” Payack recommended. “That’s the type of phraseology that makes you (appear) aloof and out of touch.”

This in reference to Obama’s speech regarding the oil spill. Apparently it was written for 10th graders according to this Paul J.J. Payack, president of Global Language Monitor. I’m not up on Payack’s qualifications and I dearly hope he is just some unqualified hack. The alternative to Payack being a crank is that American’s are so fuck stupid they can’t follow the sentence above. I’d like to know what elements of the sentence might throw those w/ a lesser reading level.

Lets look some possible problems:

  1. # of words:  There are roughly 41 words.  I haven’t added up all the characters but there is a good chance that wouldn’t fit on twitter or in a text.  Obama needs to dumb it down a notch.  Use monosyllabic words only:  “Rig sank, I make team, clean bad stuff.”  Done and done bitches, post it!
  2. Nobel prize winning“:  We know from our republican “pundits” that American’s don’t like that fancy edumacation crap.  We want our leaders borderline retarded and their scientists no less so.  We want Joe Everyman, who didn’t need fancy schoolin’ to teach him the hard rules of life, who dropped out of school at the age of 6 to work in the coal mine, who barely understands how to actually count his age on his hand.  Besides, “scientist” is really just another word for elitist prick.  One step below someone who adopts a fake British accent, eh govna.
  3. physicist“:  Alright, to be fair to Payack, there is a good chance most American’s think this word describes a high school gym teacher and who wants that guy running the show?
  4. The “,”:  I see 2 comma’s in that sentence to break up the thought.  Obama, during recitation, should have simply rambled w/ nary a pause for breath.  How else are American’s supposed to get all that he says while managing to ignore their children and txt their friends about the latest Jersey Shore developments?

It’s a sad fucking state of affairs when our president needs to dumb it down from easily understandable to …. whatever the fuck comes below that.  I wonder if, in the years to come, we’ll have a president who talks to the “average American” and the other 70% of us are left in the cold trying to decipher what can only be described as “drooled ramblings.”

Categories: Uncategorized Tags:

Beauty of Unity3D

June 15th, 2010 admin No comments

Previously I touched a bit on adding 3D content to a page using the, as yet, unfinalized WebGL standard. The page I made was simple and displayed a non-shaded bspline. But what if you aren’t savvy or maybe you lack the time to wrangle the oddities of OpenGL? The best option that I’ve found so far is Unity3D, a free(for the Indie version) game engine.

One of my most popular posts covers merging Ogre3D w/ Havok physics. That project actually continued long after the page I posted was up (sadly the code couldn’t be updated as it became an official project) and I was having a blast. The problem was I never had enough time. As the only developer on the project I had to handle every piece of the engine. I could pull from many open source options but integration was never fast and easy, like a Yeti. On top of that there wasn’t any sort of scripting framework, all changes had to be written in raw C++ and recompiled. Scripting was always planned but kept taking a back seat to graphics, networking, and physics.


Why am I blathering (BLATHERING BLATHERSKITE!…. Anyone? DuckTales?) on about time and 3D engines? Unity3D pretty much does everything you need and then some w/o the hassle of coding an entire engine. The beauty of their engine isn’t necessarily the tech., it’s the editor. Simple to understand, easy to use, and extremely friendly on novice users. Indeed, everything is tied to an impressive C#/Java scripting framework that makes accessing existing core functionality a snap. Coupled w/ an active community and some decent examples Unity3D is very easy to pick up.

Scripts are compiled on the fly in to a sort of pseudo bytecode(also known as jit compiled, or just in time compiled).

It is around 20 times faster than traditional javascript and around 50% slower than native C++ code.

The only real downside is the lack of control over the core at the C++ level. Adding in features is definitely possible but if you are someone that needs complete control over every aspect of his/her engine you’ll be disappointed. All this means is you have to be clever with the tools you are given in order to create a unique game. Additionally if you are looking to make something other than a generic RTS or FPS you’ll need the pro version which offers full shader support and RTT.

To see an example, click below to download the Unity plugin. After which the 3D image of a toy gun should appear. This is a VERY simple model viewer I threw together in maybe 10 minutes? It took me longer to write this post.


Left/Right Arrow Keys – Rotate around Y-Axis (Spin)
Up/Down Arrow Keys – Rotate around X-Axis (Tilt)

And this is the only script in that scene:

var rotateSpeed : float = 1.0;
var center : Vector3 = Vector3.zero;
var prefab : Transform;
 
 
private var windowRect : Rect = new Rect(0,0,150,50);
 
function Awake(){
	///calculate model center;
	var mesh : Mesh = GetComponent(MeshFilter).mesh;
	var bounds = mesh.bounds;
 
	///Be sure to apply all transformations current present in the model.
	center = mesh.bounds.center;
	center = transform.rotation * center;
	center = center * transform.localScale.x;
	center += transform.position;
 
	///Draw a dummy object to the scene, not necessary but helps to debug odd centers.
	print("Center: " + center.x + "," + center.y + "," + center.z);
	Instantiate(prefab,center, Quaternion.identity);
}
 
function OnGUI () {
	windowRect = GUI.Window (0, windowRect, SpeedGUI, "Speed Control");
}
function SpeedGUI(id : int){
	rotateSpeed = GUI.HorizontalSlider (Rect (25, 25, 100, 30), rotateSpeed, 1.0, 25.0);
}
function Update () {
 
	//Key left/right & up/down key movements
	var rotZ = Input.GetAxis("Vertical");
	var rotY = Input.GetAxis("Horizontal");
 
	//Rotate model around it's center.
	transform.RotateAround(center, Vector3.up,-rotY * rotateSpeed);
	transform.RotateAround(center, Vector3.right,rotZ * rotateSpeed);
}
Categories: Coding, Technology Tags: , , , ,

Cleaner Theme

June 14th, 2010 Jerdak No comments

As you can see the theme has been touched up a bit. I got tired of the tiny reading area and the dual widget columns. I believe this one is called iNova on top of which I’ve made just a couple of modifications.

Categories: Uncategorized Tags:

WinSCP Wrapper (Managed c++)

June 14th, 2010 Jerdak No comments

Here is a little code I wrote to help me access WinSCP via Managed C++.

The code is extremely simple.  A worker thread is spawned which reads from a message packet.  Even though this class uses a worker thread it is technically synchronous.  You can only run a new WinSCP command when the last one has been completed.  The basic logic is thus:  Assign Command to WinSCP -> WinSCP Runs Command Automatically -> WinSCP Returns to a MessageComplete delegate -> Assigned a Command to WinSCP

There isn’t a particular reason for my lack of true asynchronous support other than a lack of time for proper coding.  The time saved by running commands from a queue is negligible given how little I do with the data I request in my apps.  That’s also why you’ll see the beginnings of thread safety (locking) but why it isn’t complete.  Since everything has to run in a specific order there is no need to lock any variables.

The code for this project is being attached directly to this post rather than in my SVN account.

Usage:

ref class ScpRun {
public:
	ScpRun(){
		_commandList = gcnew System::Collections::Generic::List<WinScpCmd^>;
		_scp = gcnew WinScpWrapper();
		_this = this;
		_account = gcnew String("");
	};
	bool Done(){return _bDone;}
	void Run();
	void Stop(){_this->_scp->RequestStop();}
 
	///Get/Set WinSCP account name
	property String ^Account {
		String ^ get(){return _account;}
		void set(System::String ^ s){_account = s;}
	};
protected:
 
	///WinSCP message is complete
	static void ScpMessageComplete(System::Object ^sender, WinScpEventArgs ^args);
private:
 
	///WinSCP wrapper API
	WinScpWrapper ^_scp;
 
	///Command stack (each return message from WinSCP)
	System::Collections::Generic::List<WinScpCmd^> ^_commandList;
 
	///Self-referential pointer for worker thread
	private: static ScpRun ^_this;
 
	///Worker thread complete?
	bool _bDone;
 
        ///WinSCP account name
	System::String ^_account;
};

There isn’t much going on here. We create a generic WinSCP handler class. In my example we create a command stack (just a list), each successive command is sent to WinSCP when the previous one is complete.

ScpRun::Run

void ScpRun::Run(){
	_bDone = false;
	{	///Create command list
 
                //The very first call MUST be to open an account name.  I suggest setting up an easy name using WinSCP that you can reference here.
                _commandList->Add(gcnew WinScpCmd(WSC_OPEN,_account));
 
                //Next we'll add a command to print the current working directory	
		_commandList->Add(gcnew WinScpCmd(WSC_PWD,""));
 
                //Now lets dump the contents of our current directory
		_commandList->Add(gcnew WinScpCmd(WSC_LS,""));
 
                //Lastly be sure to kill your connection
		_commandList->Add(gcnew WinScpCmd(WSC_CLOSE,""));
	}
 
        //Pull the first command off our command stack and call WinSCP
	WinScpCmd ^tmp = _commandList[0];
	_commandList->RemoveAt(0);
 
        //Here we send our command to WinSCP, arguments are parsed by the class
	scp->wsc_call(tmp->Command,tmp->Arguments);
 
        //Be sure to assigned a MessageComplete callback function
	scp->WSCMessageComplete += gcnew WinScpWrapper::MessageComplete(&ScpRun::ScpMessageComplete);
 
        //Tell WinSCPWrapper it's time to start
        scp->RequestStart();
}

Again, all real simple code. We’ve added 4 commands to our command stack and we’ve sent the first off to be run. When that command is complete (successfully or not) it will push out an event to any MessageComplete handlers. I should note here that there isn’t any sort of timeout value. An assumption is made (wrongfully or not) that WinSCP will always return a value.

ScpRun::ScpMessageComplete

void ScpRun::ScpMessageComplete(System::Object ^sender, WinScpEventArgs ^args){
	//Arguments only have 2 states, success or failure.
        if(!args->_bSuccess){
		switch(args->_trigger){
			case WSC_PWD:
			case WSC_LS:
			case WSC_OPEN:
			case WSC_CLOSE:
				printf("Crap-sicle our command has failed.");
				break;
			default:
				break;
		}
		printf("[Command %s failed.]\n",args->_fullCommand);
	} else {
		switch(args->_trigger){
			case WSC_LS:{
				break;
			case WSC_PWD:
				break;
			default:
				printf("Command %s complete.\n",args->_fullCommand);
				printf("   - Value: %s.\n",args->_value);
				break;
		}
	}
 
	///If command list contains more commands, run them.  (Demo only)
	if(_this->_commandList->Count > 0){
		WinScpCmd ^tmp = _this->_commandList[0];
		_this->_commandList->RemoveAt(0);
		_this->scp->wsc_call(tmp->Command,tmp->Arguments);
	} else {
		_this->_bDone = true;
	}
}

Here we handle return messages from our WinSCP wrapper. It would be advisable to add some code here to handle an error from WSC_OPEN that tells the command stack to stop issue commands and set _bDone to true;

The only remaining action is to run our handler class:

	ScpRun ^scp = gcnew ScpRun ();
	scp->Account		= "dummy_account_name";
	scp->Run();
 
	//loop until done
	while(!scp->Done()){
		Threading::Thread::Sleep(15);
	}
	//Tell SCP to stop which in turn tells our WinSCP wrapper to kill its worker thread.
	scp->Stop();

I should mention the WinScpWrapper files. There are some lines that look like the following:

#include <GIniWrapper.h>
//gcnew String(config.getValue.....

You’ll have to remove references to and replace any calls to ‘config.getvalue’ w/ raw values. You’ll see in my get value though that the 3rd argument is actually a default value, just use these. It’s important that you use the same delimiter and cmd_ender that I use. WinSCP, as far as I can tell, doesn’t return any sort of codes. When your command is complete nothing is sent to say as much. You might be able to search for blank lines but I wasn’t sure if these would show up in other commands. Instead what I’ve done is after I issue a command to WinSCP I issue an additional command w/ ‘__END_CMD__’ as the message. WinSCP won’t know how to parse this command but it will still be written to the process handlers output. In this way we can search for valid commands between subsequent ‘winscp>’ command line tags. It’s a kludge but it works.

Categories: Coding Tags: , , , ,