<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>underscore discovery</title>
	<atom:link href="http://blog.owned.co.za/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.owned.co.za</link>
	<description>Game Development</description>
	<lastBuildDate>Tue, 25 May 2010 11:43:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ctrlr &#8211; Weekend games 01</title>
		<link>http://blog.owned.co.za/?p=246</link>
		<comments>http://blog.owned.co.za/?p=246#comments</comments>
		<pubDate>Fri, 21 May 2010 22:44:33 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=246</guid>
		<description><![CDATA[I have lost touch of the quick fun games that everyone loves to play/make. I decided to get out of this little mindset by challenging myself to what i am calling a weekend game. The rules i made for myself are simple : Start day : some day on a weekend End day : the [...]]]></description>
			<content:encoded><![CDATA[<p>I have lost touch of the quick fun games that everyone loves to play/make. I decided to get out of this little mindset by challenging myself to what i am calling a weekend game. The rules i made for myself are simple :</p>
<p>  Start day : some day on a weekend<br />
  End day : the next weekend<br />
  Restrictions : No more than 3 days touching code, Design to succeed</p>
<p>The results so far, ctrlr. It is going well so far, 1 day or so of code, LOADS to polish. There is meant to be fog of war, so its not that simple even though this map might seem simple. Theres also a hidden backdoor, which lets you get the wifi quicker.</p>
<p><strong>What is it : </strong></p>
<p>  A mix of 3 mini games, shared mechanics, simple objective based gameplay.<br />
  (so far one mini game is almost entirely playable, just posting for feedback and ideas)</p>
<p><strong>Why is it : </strong></p>
<p>  I spent a good few hours playing commandos last weekend, and i love how difficult it is, and i love how the challenges can take long because you have to figure it out. I also love normal stealth/sneaking/security games so i figured i would want to make my own one.</p>
<p>The concept is the four phases, get info on the building etc, get into the internal network via hacking in, set up a nice path to infiltrate, infiltrate and complete objectives.</p>
<p><strong>How is it : </strong></p>
<p>  Note, i am designing the game with an iPhone interface for many reasons,<br />
  so keep it mind that it will be on a touch device.  This means the &#8220;weird&#8221; zooming feature in the recon phase is designed similar to the photo viewer on the device (where i prototyped interface controls). Also the world scale + finger size makes it difficult to control a tiny player, zooming in also focuses the gameplay, making it a little more intense etc.</p>
<p>  Controls :<br />
        Double click to zoom in or out<br />
        Once zoomed in (and only when zoomed in) you click to move.<br />
        Escape goes back from any game mode or menu</p>
<p>  Known Issues : </p>
<p>        The controls are feeling a bit annoying in recon mode, the collision snags occasionally (my fault)&#8230;<br />
        Its possible to get &#8220;stuck&#8221; i think, not sure.<br />
        Its possible to double click and have no zoom, and move zoomed out, double click a few times to correct the view.</p>
<p><strong>How does it look : </strong></p>
<p><img src="http://img225.imageshack.us/img225/8179/hackzor1copy.jpg"></p>
<p><img src="http://img301.imageshack.us/img301/9335/hackzortargetchoose2.png"></p>
<p><img src="http://owned.co.za/screenshot.220.jpg"></p>
<p><img src="http://owned.co.za/screenshot.222.jpg"></p>
<p><strong>Where is it :</strong></p>
<p>yes yes, there is a playable version. </p>
<p><strong> Updated 25 May (adding mac build. nothing else new yet) </strong></p>
<p><a href="http://owned.co.za/CTRLR01.exe"> Windows Build &#8211; Self Extractor (1.5MB) </a><br />
<a href="http://owned.co.za/CTRLR01.zip"> Popular-demand-zip (1.7MB) </a><br />
<a href="http://owned.co.za/ctrlr.app.zip"> Mac version ( > Intel only) (2.1MB) </a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=246</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PhoenixCore 0.2 &#8211; &#8216;Nightingale&#8217; released</title>
		<link>http://blog.owned.co.za/?p=242</link>
		<comments>http://blog.owned.co.za/?p=242#comments</comments>
		<pubDate>Mon, 26 Apr 2010 13:46:16 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[2d engine]]></category>
		<category><![CDATA[2d game engine]]></category>
		<category><![CDATA[fast 2d engine]]></category>
		<category><![CDATA[free 2d engine]]></category>
		<category><![CDATA[game development tools]]></category>
		<category><![CDATA[game engine]]></category>
		<category><![CDATA[optimised 2d engine]]></category>
		<category><![CDATA[phoenix engine]]></category>
		<category><![CDATA[phoenixcore]]></category>
		<category><![CDATA[phoenixgl]]></category>
		<category><![CDATA[rendering engine]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=242</guid>
		<description><![CDATA[Why i care I am currently using PhoenixCore for my Uplink Clone, and have watched it progress out of PhoenixGL. Jon Parrott made an incredibly cool approach to using a 2d engine with really great performance. More of his awesome work is found on the right or over here Link PhoenixCore is EASY, its straightfoward [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Why i care</strong></p>
<p>I am currently using PhoenixCore for my Uplink Clone, and have watched it progress out of PhoenixGL. Jon Parrott made an incredibly cool approach to using a 2d engine with really great performance. More of his awesome work is found on the right or over here <a href="http://parrottdev.blogspot.com/"> Link </a><br />
PhoenixCore is EASY, its straightfoward and its high level enough to be powerful. And its easy.</p>
<p><strong>What is it</strong></p>
<p>Straight from the site,<br />
PhoenixCore is an experimental 2D rendering framework based on OpenGL and written in C++.<br />
It is a fairly abstract library for rendering 2D geometry.<br />
PhoenixCore&#8217;s features include:<br />
Setting up an OpenGL Context.<br />
Processing user Input (Keyboard, Mouse).<br />
Managing OpenGL Context (swapping buffers, etc).<br />
Provides abstract math classes for Vectors and Matrices.<br />
Provides interface to loading and manipulating Textures.<br />
Provides methods to modify the View Port and Transformation Matrix.<br />
Provides classes for representing geometric primitives.<br />
Provides methods for drawing geometric primitives.<br />
Provides abstract class for Color representation and manipulation.<br />
Provides access to high-precision timers.<br />
Provides high-level threaded resource management.<br />
Implements and experimental automatic optimizing batch renderer.</p>
<p><strong>Downloads and Docs</strong></p>
<p>Docs are over here <a href="http://phoenixgl.googlecode.com/svn/tags/0.2/Docs/html/index.html"> Docs </a></p>
<p>Get it over here <a href="http://phoenixgl.googlecode.com/files/PhoenixCore-0.2-Release.zip"> Download </a></p>
<p><strong> Changes in 0.2 </strong></p>
<p>Nightingale has several differences from 0.1. It contains major API changes and upgrading should be taken with caution. </p>
<p>Changed Droppable, Resource, and ResourceManager significantly. They no longer use the create() method or private constructors. They now use intrusive_ptrs instead of shared_ptrs which simplifies our interface. </p>
<p>Abstracted the WindowManager interface and implement GLFW as a WindowManager. This allows us to support other window managers in the future. </p>
<p>A new window event interface that uses boost::signals2. </p>
<p>Removed the core&#8217;s dependence on the EventReceiver and made it a singleton. It now has functions for getting what the user has typed ( getKeyboardString ). It also now uses the new WindowEvent system and is used exclusively in client code. </p>
<p>BatchGeometry&#8217;s group functions are now taken care of by GroupState objects that are attached to the BatchRenderer for each group id.<br />
More, more.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=242</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FLCore Client Integration.</title>
		<link>http://blog.owned.co.za/?p=228</link>
		<comments>http://blog.owned.co.za/?p=228#comments</comments>
		<pubDate>Thu, 22 Apr 2010 01:49:24 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[art]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[hacking game]]></category>
		<category><![CDATA[hacking sim]]></category>
		<category><![CDATA[uplink]]></category>
		<category><![CDATA[uplink clone]]></category>
		<category><![CDATA[uplink game]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=228</guid>
		<description><![CDATA[Not a lot of time at the moment but i finally fixed the key input issues i was having with my rendering. While i finish the other minor details, i can post something else. I really love uplink. In honour of its awesomeness, you may notice some resemblance to it in certain places. Its intended [...]]]></description>
			<content:encoded><![CDATA[<p>Not a lot of time at the moment but i finally fixed the key input issues i was having with my rendering. While i finish the other minor details, i can post something else.</p>
<p>I really love uplink. In honour of its awesomeness, you may notice some resemblance to it in certain places. </p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img406.imageshack.us/img406/3470/screenshot212.jpg" rel="wp-prettyPhoto[g228]"><img src="http://img406.imageshack.us/img406/3470/screenshot212.jpg" alt="" title="mockups" width="640" class="size-full wp-image-110" /></a><p class="wp-caption-text">Original</p></div>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img97.imageshack.us/img97/9779/screenshot213m.jpg" rel="wp-prettyPhoto[g228]"><img src="http://img97.imageshack.us/img97/9779/screenshot213m.jpg" alt="" title="mockups" width="640" class="size-full wp-image-110" /></a><p class="wp-caption-text">My remake</p></div>
<p>Its intended as a tribute, <3 uplink.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=228</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>v8 c++ Crash Course</title>
		<link>http://blog.owned.co.za/?p=205</link>
		<comments>http://blog.owned.co.za/?p=205#comments</comments>
		<pubDate>Tue, 20 Apr 2010 17:52:05 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[c++ v8]]></category>
		<category><![CDATA[cplusplus]]></category>
		<category><![CDATA[embedding javascript in game]]></category>
		<category><![CDATA[game scripts]]></category>
		<category><![CDATA[google v8 javascript engine]]></category>
		<category><![CDATA[in game javascript]]></category>
		<category><![CDATA[javascript engine]]></category>
		<category><![CDATA[scripting in game]]></category>
		<category><![CDATA[using c++ and v8]]></category>
		<category><![CDATA[using v8 in games]]></category>
		<category><![CDATA[v8]]></category>
		<category><![CDATA[v8 javascript]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=205</guid>
		<description><![CDATA[A formatting note &#8211; I have tried to clean the code a little to work with this width of page. The original code with less dumbassery is linked in the header file here for reference. Get the example code from here : LINK I know i needed one. When i had chosen v8 as my [...]]]></description>
			<content:encoded><![CDATA[<p>A formatting note &#8211; I have tried to clean the code a little to work with this width of page. The original code with less dumbassery is linked in the header file here for reference.</p>
<p><strong> Get the example code </strong></p>
<p>from here : <a href="http://owned.co.za/downloads/codesample_v8_helpers.h"> LINK </a></p>
<p><strong>I know i needed one.</strong><br />
When i had chosen v8 as my weapon of choice i found it to be incredibly easy to grasp.<br />
What i didnt expect is for the simplicity to grab me around the ankles and dangle<br />
me off the edge of confusion cliff. </p>
<p>Before i realised i was scratching my head with a few good c++ books open wondering what<br />
on earth i had done wrong that was giving v8 exceptions from a single line of code.<br />
What i would advise, is try to avoid shortcuts. I was using CProxyV8, i had seen v8Juice and<br />
both of them are really neat, but every single error i ran into was related to me not understanding<br />
what it is v8 was actually asking for and most times it was because of the use of the wrappers.</p>
<p><strong>Finding my own way</strong><br />
I learnt a few things along the way &#8211; using v8 from the ground up is actually easier to understand.<br />
The first thing that helps is to look at the v8 namespace comments as they usually<br />
reveal something important, if its related to the JS side, or if its related to the c++ side.Once i saw<br />
that i was attempting to use a JS object as a c++ class, yea things started to make more sense.</p>
<p><strong>What i needed from v8. </strong><br />
Now while the point and line class example is so heavily leaned on, it still didnt really help me to figure out the route i needed to take to expose certain classes to the script environment. The included sample http process and the other samples also , did things in a very straightforward and limited way. Below i will present an empty class from my codebase, with the code i used to expose and gracefully use the script side easily.</p>
<p><strong>I needed to wrap and unwrap a class.</strong><br />
In order to expose a class to JS, i wanted to use an EXISTING C++ class, and just pass a pointer/handle to the scripts. That way i can also control what part of my game/scripts they can actually overwrite and change, and what instances of class they can manipulate. For example, i dont want multiple instances of the core, or any subsystem of the core. I just want a script side global(used loosely here) that the script writer can access (and which also protects him from accidentally overwriting one of my objects). </p>
<p><strong>A template based helper function </strong><br />
I wrote 2 functions that are free to use , and will wrap and unwrap a class accordingly. The usage of the code provided here is shown lower down, so it might not make sense here. Wrapping involves creating a JS object from a c++ class, and maintaining a handle to manipulate it, and unwrapping involves unwrapping an object to a c++ pointer again, normally from the v8arguments handle that a function passes in on being called.</p>
<p>	example use :<br />
	ExposeClass< somenamespace::someClass >( somev8Context, someClassInstance, v8::String::New(&#8220;someclass&#8221;), v8::ReadOnly);</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//http://blog.owned.co.za v8 Javascript Helper Function ,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Give this function the c++ object (an instance) to wrap, </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//and it returns a JS object to expose things under.</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//Note theres 2 functions here , </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//the top one is used by the ExposeClass function</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">template&lt;class T&gt; </div>
</li>
<li class="li1">
<div class="de1">v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; WrapClass<span class="br0">&#40;</span>T* y<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Handle scope for temporary handles, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">HandleScope</span> handle_scope;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Persistent</span>&lt;v8::<span class="me2">ObjectTemplate</span>&gt; &nbsp;class_template_;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">ObjectTemplate</span>&gt; rt = v8::<span class="me2">ObjectTemplate</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The raw template is the ObjectTemplate</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// (that can be exposed to script too)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//but is maintained internally.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; rt-&gt;SetInternalFieldCount<span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create the actual template object, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; class_template_ = v8::<span class="me2">Persistent</span>&lt;v8::<span class="me2">ObjectTemplate</span>&gt;::<span class="kw3">New</span><span class="br0">&#40;</span>rt<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create the new handle to return, and set its template type </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; result = class_template_-&gt;NewInstance<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">External</span>&gt; class_ptr</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; class_ptr = v8::<span class="me2">External</span>::<span class="kw3">New</span><span class="br0">&#40;</span>static_cast&lt;T*&gt;<span class="br0">&#40;</span>y<span class="br0">&#41;</span><span class="br0">&#41;</span>; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Point the 0 index Field to the c++ pointer for unwrapping later</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; result-&gt;SetInternalField<span class="br0">&#40;</span><span class="nu0">0</span>, class_ptr<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Return the value, releasing the other handles on its way.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> handle_scope.<span class="me1">Close</span><span class="br0">&#40;</span>result<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">template&lt;class T&gt;</div>
</li>
<li class="li1">
<div class="de1">v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; ExposeClass<span class="br0">&#40;</span>v8::<span class="me2">Persistent</span>&lt;v8::<span class="me2">Context</span>&gt; context, </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T* y, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; exposedName, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">PropertyAttribute</span> props<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">HandleScope</span> handle_scope;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; obj = Core::<span class="me2">Script</span>::<span class="me2">WrapClass</span>&lt;T&gt;<span class="br0">&#40;</span>y<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; context-&gt;Global<span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;Set<span class="br0">&#40;</span>exposedName, obj, props<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> handle_scope.<span class="me1">Close</span><span class="br0">&#40;</span>obj<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
</ol>
</div>
<p>	And for unwrapping &#8211; (usually inside CALLED functions from script.<br />
	use : someNamespace::someClass* sc =<br />
		UnwrapClass< someNamespace::someClass >( myJSObjToUnwrap );</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//http://blog.owned.co.za v8 Javascript Helper Function ,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Give this function the v8 JS object to unwrap, and the class to unwrap to.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">template&lt;class T&gt; </div>
</li>
<li class="li1">
<div class="de1">T* UnwrapClass<span class="br0">&#40;</span>v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; obj<span class="br0">&#41;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">External</span>&gt; field;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; field = v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">External</span>&gt;::<span class="me2">Cast</span><span class="br0">&#40;</span>obj-&gt;GetInternalField<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">void</span>* ptr = field-&gt;Value<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> static_cast&lt;T*&gt;<span class="br0">&#40;</span>ptr<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><strong>How i use the above templates </strong><br />
Nobody is claiming magic in the code above, it might even be wrong and or, doing something badly. I just found it to work &#8211; any comments and fixes will be noted and adjusted if you comment. Now, the usage, at least MY usage of the above code was to expose c++ classes with existing c++ functions to the script context.</p>
<p><strong>Step 1 &#8211; A Class to expose, with some members id like in scripts. </strong></p>
<p> First, i have a c++ class declared, with some static functions that i would like to expose.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> cCore</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">public</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This is a simple example, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//do not copy this as a real class.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; cCore<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; ~cCore<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We need a persistant handle to the core in scripts, a non persistant</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//v8::Handle&lt;v8::Object&gt; will get lost in the handle scopes, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//and throw some weird exceptions to hunt down. </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Wrap class and unwrap class return </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//NON persistant handles, so store your own </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//persistant ones if you want to </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//use it outside of the first handle scope.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//core script object, &nbsp;&quot;core&quot; in scripts.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Persistent</span>&lt;v8::<span class="me2">Object</span>&gt; cso_core; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//We expose some functions in our class to the scripts from c++, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//By wrapping an object (cso_core above) and the attaching functions</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//to that object. Those functions, when called from javascript &#8211; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//end up here.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The functions are self explanatory.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Print some text to the console/ui console</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">static</span> v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; xecho<span class="br0">&#40;</span><span class="kw4">const</span> v8::<span class="me2">Arguments</span>&amp; args<span class="br0">&#41;</span>;&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//execute a javascript file &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">static</span> v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; xexec<span class="br0">&#40;</span><span class="kw4">const</span> v8::<span class="me2">Arguments</span>&amp; args<span class="br0">&#41;</span>;&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//exit all systems and shutdown &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">static</span> v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; xexit<span class="br0">&#40;</span><span class="kw4">const</span> v8::<span class="me2">Arguments</span>&amp; args<span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>; <span class="co1">//end class declaration</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>	<strong>Step 2 &#8211; Creating the Javascript Object , of my class.</strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Just for clarity sake, so you can see my workflow.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> cScriptSystem::<span class="me2">startup</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create a script engine for the core</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">HandleScope</span> handle_scope;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create a context for the system to use </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//(i have just one at this point)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; coreContext = v8::<span class="me2">Context</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="kw2">NULL</span>, global<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Enter the main context, making it active.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Context</span>::<span class="me2">Scope</span> context_scope<span class="br0">&#40;</span>coreContext<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; exposeCore<span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//see below</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//And the code to expose the class, </span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">void</span> cScriptSystem::<span class="me2">exposeCore</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">HandleScope</span> handlescope;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This will be reused to expose multiple </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//classes, short name for easy code.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; cc;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//get the JS version of the C++ object, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//note that core is simply Core::cCore* core; </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; cc = ExposeClass&lt; Core::<span class="me2">cCore</span> &gt;<span class="br0">&#40;</span>coreContext, core, &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">String</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="st0">&quot;core&quot;</span><span class="br0">&#41;</span>, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">ReadOnly</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//set the persistant handle for use outside of this handlescospe</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; core-&gt;cso_core = v8::<span class="me2">Persistent</span>&lt;v8::<span class="me2">Object</span>&gt;::<span class="kw3">New</span><span class="br0">&#40;</span>cc<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Give the functions to the object. </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This makes the functions come out as </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//core.echo(), core.exec(), core.exit() in scripts.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; Expose<span class="br0">&#40;</span>core-&gt;cso_core, v8::<span class="me2">String</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="st0">&quot;echo&quot;</span><span class="br0">&#41;</span> , </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">InvocationCallback</span><span class="br0">&#40;</span>Core::<span class="me2">cCore</span>::<span class="me2">xecho</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Expose<span class="br0">&#40;</span>core-&gt;cso_core, v8::<span class="me2">String</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="st0">&quot;exec&quot;</span><span class="br0">&#41;</span> , </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">InvocationCallback</span><span class="br0">&#40;</span>Core::<span class="me2">cCore</span>::<span class="me2">xexec</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Expose<span class="br0">&#40;</span>core-&gt;cso_core, v8::<span class="me2">String</span>::<span class="kw3">New</span><span class="br0">&#40;</span><span class="st0">&quot;exit&quot;</span><span class="br0">&#41;</span> , </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v8::<span class="me2">InvocationCallback</span><span class="br0">&#40;</span>Core::<span class="me2">cCore</span>::<span class="me2">xexit</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p> <strong>Step 3 &#8211; Actually handling the function calls on the c++ side.</strong></p>
<p> This is where the unwrapClass comes in&#8230; If you noticed the v8::Arguments&#038; args on the functions,<br />
 it hands in the class that the function is being called upon. So if i called core.exit() , the object<br />
 that it will pass me is the core object (our C++ object, in JS form). See the code for clarity, </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; cCore::<span class="me2">xexit</span><span class="br0">&#40;</span><span class="kw4">const</span> v8::<span class="me2">Arguments</span>&amp; args<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//args.Holder() is the object that the function was invoked upon. </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This means it could be exposed to 2 classes, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//under different types so be sure</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//that you dont just randomly unwrap into the wrong container type.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Core::<span class="me2">cCore*</span> core = UnwrapClass&lt;Core::<span class="me2">cCore</span>&gt;<span class="br0">&#40;</span> args.<span class="me1">Holder</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The code inside the normal exit function is identical, </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//so i can just call the normal c++ code directly.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; core-&gt;startShutdown<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This is to return void, basically.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> v8::<span class="me2">Undefined</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>	<strong>Step 4 &#8211; The missing function.</strong><br />
	I left out a function along the way, you may have noticed. The function is called Expose, </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> Expose<span class="br0">&#40;</span>v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Object</span>&gt; intoObject, v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">Value</span>&gt; namev8String, v8::<span class="me2">InvocationCallback</span> funcID<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; v8::<span class="me2">HandleScope</span> handle_scope;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; v8::<span class="me2">Handle</span>&lt;v8::<span class="me2">FunctionTemplate</span>&gt; thisFunc;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; thisFunc = v8::<span class="me2">FunctionTemplate</span>::<span class="kw3">New</span><span class="br0">&#40;</span>funcID<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; intoObject-&gt;Set<span class="br0">&#40;</span>namev8String, thisFunc-&gt;GetFunction<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>	<strong>Conclusion</strong></p>
<p>	I hope this helps clarify the v8 logic, and helps users figure out how easy it actually is to automate things with templates and macros. Theres still many ways to simplify the code above but for simplicity &#8211; take it as it is. </p>
<p>	In closing, v8 offers some super easy to use casting functions. Ill give some examples as i found these to be really nice but be wary, do exception handling, type checking and proper management of values handed to c++ from v8. It will save you some time looking through v8 exception callstacks if you manually handle possible exceptions.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//you can now use it std::string(*somestdstring)</span></div>
</li>
<li class="li1">
<div class="de1">v8::<span class="me2">String</span>::<span class="me2">Utf8Value</span>&nbsp; &nbsp;somestdstring <span class="br0">&#40;</span> args<span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="br0">&#41;</span>; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//you can now use it *somecstring (same as const char* somecstring;)</span></div>
</li>
<li class="li1">
<div class="de1">v8::<span class="me2">String</span>::<span class="me2">Utf8Value</span>&nbsp; &nbsp;somecstring <span class="br0">&#40;</span> args<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> <span class="br0">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//normal double, </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">double</span> somedouble = args<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>-&gt;ToNumber<span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;Value<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//booleans</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">bool</span> somebool = args<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span>-&gt;ToBoolean<span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;BooleanValue<span class="br0">&#40;</span><span class="br0">&#41;</span>; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//and integers.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> someint = args<span class="br0">&#91;</span><span class="nu0">4</span><span class="br0">&#93;</span>-&gt;ToInt32<span class="br0">&#40;</span><span class="br0">&#41;</span>-&gt;Int32Value<span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//And one last thing, giving javascript meaningful return values. </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//This should be more than enough to let you figure out how simple</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//v8 makes things for you on the c++ side.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> handle_scope.<span class="me1">Close</span><span class="br0">&#40;</span>v8::<span class="me2">Number</span>::<span class="kw3">New</span><span class="br0">&#40;</span>somedouble<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> handle_scope.<span class="me1">Close</span><span class="br0">&#40;</span>v8::<span class="me2">Int32</span>::<span class="kw3">New</span><span class="br0">&#40;</span>someint<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> handle_scope.<span class="me1">Close</span><span class="br0">&#40;</span>v8::<span class="me2">Boolean</span>::<span class="kw3">New</span><span class="br0">&#40;</span>somebool<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=205</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The future, Now.</title>
		<link>http://blog.owned.co.za/?p=202</link>
		<comments>http://blog.owned.co.za/?p=202#comments</comments>
		<pubDate>Wed, 14 Apr 2010 09:06:36 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=202</guid>
		<description><![CDATA[Main menu is implemented, new Awesomium experimental build is in and working, new phoenixCore is being merged. Client is on the way out, be ready. If you want to play when its ready, let me know in the comments.]]></description>
			<content:encoded><![CDATA[<p>Main menu is implemented,<br />
new Awesomium experimental build is in and working,<br />
new phoenixCore is being merged.<br />
Client is on the way out, be ready.<br />
If you want to play when its ready, let me know in the comments.</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img69.imageshack.us/img69/1756/tea1c.jpg" rel="wp-prettyPhoto[g202]"><img src="http://img69.imageshack.us/img69/1756/tea1c.jpg" alt="" title="the future, now" width="450" class="size-full wp-image-110" /></a><p class="wp-caption-text">The future for everyone, right now</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=202</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Weekend Painting</title>
		<link>http://blog.owned.co.za/?p=198</link>
		<comments>http://blog.owned.co.za/?p=198#comments</comments>
		<pubDate>Tue, 06 Apr 2010 06:05:18 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=198</guid>
		<description><![CDATA[So with the long weekend around, i decided to do some painting in between my programming to keep me sane. Top down 2d game, high school setting. Dont really wanna give much away but, heres some images &#8211; all hand painted using little bits of photos and a pen tablet. The papers, the carpet and [...]]]></description>
			<content:encoded><![CDATA[<p>So with the long weekend around, i decided to do some painting in between my programming to keep me sane. Top down 2d game, high school setting. Dont really wanna give much away but, heres some images &#8211;<br />
all hand painted using little bits of photos and a pen tablet. The papers, the carpet and the wood texture is pictures, the rest is just painted in manually to fit the lighting</p>
<p>Click to see the real size</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img263.imageshack.us/img263/5984/screenshot150w.jpg" rel="wp-prettyPhoto[g198]"><img src="http://img263.imageshack.us/img263/5984/screenshot150w.jpg" alt="" title="mockups" width="450" class="size-full wp-image-110" /></a><p class="wp-caption-text">Cafeteria</p></div>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img64.imageshack.us/img64/599/screenshot151i.jpg" rel="wp-prettyPhoto[g198]"><img src="http://img64.imageshack.us/img64/599/screenshot151i.jpg" alt="" title="mockups" width="450" class="size-full wp-image-110" /></a><p class="wp-caption-text">Principals office</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=198</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>FLCore : Mission Editor Preview</title>
		<link>http://blog.owned.co.za/?p=194</link>
		<comments>http://blog.owned.co.za/?p=194#comments</comments>
		<pubDate>Wed, 24 Mar 2010 17:03:42 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[FLCore]]></category>
		<category><![CDATA[free game]]></category>
		<category><![CDATA[fuzzy spoon]]></category>
		<category><![CDATA[FuzzYspo0N]]></category>
		<category><![CDATA[fuzzyspoon]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[indie]]></category>
		<category><![CDATA[indie game dev]]></category>
		<category><![CDATA[online games]]></category>
		<category><![CDATA[owned]]></category>
		<category><![CDATA[phoenixcore]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime games]]></category>
		<category><![CDATA[sagamedev]]></category>
		<category><![CDATA[south african game development]]></category>
		<category><![CDATA[south african games]]></category>
		<category><![CDATA[toolchain]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[underscore discovery]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=194</guid>
		<description><![CDATA[While i really love writing stories, i know that there are people who can do a better job than i could hope to. I thought about it a while ago and figured if i can give a story writer a tool that truly exposes the features they need to create an epic tale, it will [...]]]></description>
			<content:encoded><![CDATA[<p>While i really love writing stories, i know that there are people who can do a better job than i could hope to. I thought about it a while ago and figured if i can give a story writer a tool that truly exposes the features they need to create an epic tale, it will make the world of difference right? </p>
<p>Well, to make things easier on everyone (and offer something interesting to look at) i have made a quick sketch of what i can see a mission editor might look like. Yes, its in game too.</p>
<p>NOTE : CLICK ON THE IMAGE TO SEE THE ACTUAL PREVIEW</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 650px"><a href="http://img715.imageshack.us/img715/7891/memock.jpg" rel="wp-prettyPhoto[g194]"><img src="http://img210.imageshack.us/img210/963/mockuppre.jpg" alt="" title="mockups" width="640" height="400" class="size-full wp-image-110" /></a><p class="wp-caption-text">Mission Editor Mockup</p></div>
<p><strong> Keep in mind </strong><br />
This is an extremely rough mockup. Dont get too excited about bad layout and missing information and blah. Its just an idea to get the creative minds thinking. Comments and feedback are more than welcome, </p>
<p>How can the mission editor be something really awesome? DISCUSS :></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=194</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>FLCore Weekend Updates</title>
		<link>http://blog.owned.co.za/?p=190</link>
		<comments>http://blog.owned.co.za/?p=190#comments</comments>
		<pubDate>Tue, 23 Mar 2010 18:46:31 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fuzzy spoon]]></category>
		<category><![CDATA[FuzzYspo0N]]></category>
		<category><![CDATA[fuzzyspoon]]></category>
		<category><![CDATA[game development]]></category>
		<category><![CDATA[gamedev]]></category>
		<category><![CDATA[indie]]></category>
		<category><![CDATA[indie game dev]]></category>
		<category><![CDATA[indie games]]></category>
		<category><![CDATA[online games]]></category>
		<category><![CDATA[owned]]></category>
		<category><![CDATA[phoenixcore]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[south african game development]]></category>
		<category><![CDATA[south african games]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=190</guid>
		<description><![CDATA[What&#8217;s new code side After spending a bit of time rethinking things for this multi UI experience i was testing and implementing a whole bunch of core code. I rewrote a good number of things that i wasn&#8217;t happy with and i was implementing things in a more detached manner. Once i had that all [...]]]></description>
			<content:encoded><![CDATA[<p><strong> What&#8217;s new code side </strong><br />
After spending a bit of time rethinking things for this multi UI experience i was testing and implementing a whole bunch of core code. I rewrote a good number of things that i wasn&#8217;t happy with and i was implementing things in a more detached manner.</p>
<p>Once i had that all done i dug into splitting out my hacked up test code into a proper abstracted interface, i got to testing my first interface with my current interface. The test was here, could i have the console (debug window) based javascript shell running at the exact same time as the visual shell, AND, have them using the same core module? Can i tell the core i need a login, and the visual interface responds as well? All things considered i managed to achieve this and more over a few hours thanks to boost, and Jon Parrot (the anti-brain-mess filter i run sometimes).</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 460px"><a href="http://img641.imageshack.us/img641/5565/screenshot135t.jpg" rel="wp-prettyPhoto[g190]"><img src="http://img641.imageshack.us/img641/5565/screenshot135t.jpg" alt="" title="multiui" width="450" height="290" class="size-full wp-image-110" /></a><p class="wp-caption-text">Typing in console while the main UI runs asynchronous</p></div>
<p><strong>Blog theme</strong></p>
<p>While you may have noticed by now, i have updated the theme of my blog to something legible. Thanks for all the feedback and views on the last one, and as i continue to make this one better comments are always welcome.<br />
Again, the awesome image in the background is from an awesome friend, Paul &#8211; <a href="http://paul.owned.co.za">Link</a><br />
.Fin</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=190</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Design Challenge 3 : RE : Networking</title>
		<link>http://blog.owned.co.za/?p=183</link>
		<comments>http://blog.owned.co.za/?p=183#comments</comments>
		<pubDate>Fri, 19 Mar 2010 09:14:29 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[game development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[game programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[v8]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=183</guid>
		<description><![CDATA[Ok, so apparently the last post was a bit of a mess, i will try again. What im looking for from the response of the reader. Simple. Would you, perhaps a programmer or not, be inclined to extend your client with your own tools if it were like the description below. Its not complete, its [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so apparently the last post was a bit of a mess, i will try again.</p>
<p><strong>What im looking for from the response of the reader.</strong></p>
<p>Simple. </p>
<p>Would you, perhaps a programmer or not, be inclined to extend your client with your own tools if it were like the description below. </p>
<p>Its not complete, its not 100% in depth, its idea based speculation based on some prototyping i did. </p>
<p><strong>The concept of the game</strong></p>
<p>The game is a hacking simulator, a pretend world where there are other players, and NPC&#8217;s that are hackable. If you ever played uplink <a href="http://www.introversion.co.uk/uplink">from introversion</a> then you will immediately know the premise.</p>
<p>In the game, a player has a/some computers at his disposable. Each of these computers in the world, can be logged into (unless protected).<br />
The User Interface of the game is a futuristic desktop environment that is customisable via code, in game.<br />
The gameplay consists of missions, storylines, and the usual stuff &#8211; mini games pretending to be hacking mechanics etc.</p>
<p><strong>The concept of the &#8220;engine&#8221;</strong></p>
<p>The idea behind the &#8220;engine&#8221; in game is to allow the player to extend the operating system. Do your best, to make yourself a better in game hacker. How do i take over the computer at server xyz? I need a tool that can list its users. Write one, steal one, copy one, buy one.</p>
<p>Alot of thought behind the engine i wont bother cramming in one post.</p>
<p><strong> The in-game OS, your deskstop in game</strong></p>
<p>This is where it all happens. You have a web browser, a few network tools (like ping below) and you have a developer priveledged account. What now? </p>
<p>a) <strong>Do something new.</strong> Make a new clock widget, make a cool flash based tracer. You choose.<br />
b) <strong>Make something better.</strong> Add a user interface to the command line ping tool. Add a UI to the tracer, make it count in ms instead of seconds.<br />
c) <strong>Give something back.</strong> Submit a new tool/modified tool for inclusion in the core OS.</p>
<p><strong> The code sample </strong></p>
<p>What the code below is demonstrating is an INGAME ping tool. This has nothing to do with server/game state. It is merely a tool that i would like in game. For example, if a users PC online is running on a slow connection, it will take much longer to get in, do stuff and get out.<br />
This is important because you dont want to get caught, so i can now (based on the simple script below) tell if a user is taking a long time to respond to the server.</p>
<p><strong> Keep in mind </strong></p>
<p>Its a prototype code sample. It semi works and some things i just put in for brevity. I need to know if the direction im taking on exposing the core is worth taking.<br />
<strong> WOULD YOU EVEN BOTHER </strong> to do something new in game. If its as easy as it is below, would you? </p>
<p><strong>The Client side tool, </strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Client side tool for pinging another player in the game</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Author : FuzzYspo0N</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Etc</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//First, in order to create a tool on the client and server side,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//we simply assign a variable as a tool type. This might fail if </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//there is already a tool with this name &#8211; this returns undefined.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> corePingTool = <span class="kw2">new</span> core.<span class="me1">tool</span><span class="br0">&#40;</span><span class="st0">&quot;corePingTool&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Maybe something simple to register a tool with a defined </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//callback for users. This global tool shows up at the shell,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// as a &quot;command line&quot; tool,and if a tool invokes</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//a ui then it is not run via command shell but explicitly</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; core.<span class="me1">tool</span>.<span class="me1">registerGlobalTool</span><span class="br0">&#40;</span><span class="st0">&quot;ping&quot;</span>, <span class="st0">&quot;client name, ping count &quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//onExecute gets called whenever someone tries to ping </span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//(either called via ui or via the above command line)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Variable arguments handed in </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> corePingTool.<span class="me1">onExecute</span> = <span class="kw2">function</span><span class="br0">&#40;</span>param<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// 0 is reserved, so 1 is client name. 2 is ping count.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> clientName = param<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> pingCount = param<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>pingCount == core.<span class="me1">invalid</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; pingCount = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//if we have a user like this, we can use em</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> userId = core.<span class="me1">users</span>.<span class="me1">isAUser</span><span class="br0">&#40;</span>clientName<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>userId != core.<span class="me1">users</span>.<span class="me1">invalidUser</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create a new network javascript object. </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This object handles network packing/streams internally.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The to dev, this is simple &#8211; a javascript object. </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Push data into the stream, and be done.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The toolId is to header the packet type, for the server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//to know what to do with it.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> pck = <span class="kw2">new</span> core.<span class="me1">net</span>.<span class="me1">packet</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">toolId</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Add our data into the packet for the server to care</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">push</span><span class="br0">&#40;</span>userId<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">push</span><span class="br0">&#40;</span>pingCount<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Give it a callback when its feeling talkative</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">response</span> = <span class="kw1">this</span>.<span class="me1">onResponse</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Send it to the server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">send</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//The servers response to a ping command</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> corePingTool.<span class="me1">onResponse</span> = <span class="kw2">function</span><span class="br0">&#40;</span>param<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//0 reserved, 1 is always the response code, 2 is the result</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//(known, from server side), 3 is the client requested</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>param<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> == core.<span class="me1">net</span>.<span class="me1">success</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//should output something like </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &nbsp; &nbsp;ping response 128ms from &quot; DumbassTeh&quot; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> end = <span class="st0">&#8216; from &quot; &#8216;</span> + param<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> + <span class="st0">&#8216; &quot; &#8216;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo<span class="br0">&#40;</span><span class="st0">&#8216;Ping response &#8216;</span> + param<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> + <span class="st0">&#8216;ms&#8217;</span> + end<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//message box failure</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><strong>The server side response</strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Server side tool for pinging another player in the game</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Author : FuzzYspo0N</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Etc</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//expects &#8211; a packet with </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 1 &#8211; sourceUserId </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 2 &#8211; destUserId</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 3 &#8211; ping count</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">//context globals</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//var toolId is handed in from the system</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> corePingTool_Main = <span class="kw2">function</span><span class="br0">&#40;</span> pck<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Pck is basically a javascript array, and pop will</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//simply keep a &quot;stackIndex&quot; internally. So in essence</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//what you can see here is </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// stackIndex += 1;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// return pck[stackIndex - 1];</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> sourceId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> destId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> pingCount = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>i = <span class="nu0">0</span>; i &lt; pingCount; ++i<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//query : clientId, requesterId, daemonId, handler</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">query</span><span class="br0">&#40;</span>destId, sourceId, toolId, onPingBack<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> onPingBack = <span class="kw2">function</span><span class="br0">&#40;</span>pck<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 1 &#8211; sourceUserId </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 2 &#8211; destUserId</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 3 &#8211; response &#8211; if successful, it will have the ms it took</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> sourceId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> destId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> response = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>response != core.<span class="me1">net</span>.<span class="me1">response</span>.<span class="me1">timedout</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//the respond will hit the client callback that </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//pck.onresponse registered.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">respond</span><span class="br0">&#40;</span>sourceId, toolId, response<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respond : destId, toolId, responseCode</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> resp = core.<span class="me1">net</span>.<span class="me1">response</span>.<span class="me1">timedout</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">respond</span><span class="br0">&#40;</span>sourceId, toolId, resp<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Comments, views, ideas, etc &#8211; Welcome. Please, i like ideas.</p>
<p><strong>Update!! </strong></p>
<p>I am attaching a mockup of how the tools *could* work , for development of the OS features. This is why i need feedback, is it plausible to expect some non developers to enjoy modifiying their desktop more than just a background image? etc.<br />
Click on the image to see the full one.</p>
<div id="attachment_110" class="wp-caption aligncenter" style="width: 460px"><a href="http://img709.imageshack.us/img709/7383/devtools01.jpg" rel="wp-prettyPhoto[g183]"><img src="http://img151.imageshack.us/img151/194/devpre.jpg" alt="" title="Devtools" width="450" height="299" class="size-full wp-image-110" /></a><p class="wp-caption-text">Developer tool interface? Why not.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=183</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Design Challenge 2 : Networking</title>
		<link>http://blog.owned.co.za/?p=166</link>
		<comments>http://blog.owned.co.za/?p=166#comments</comments>
		<pubDate>Fri, 19 Mar 2010 00:44:10 +0000</pubDate>
		<dc:creator>FuzzYspo0N</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.owned.co.za/?p=166</guid>
		<description><![CDATA[EDIT Seeing as i had TL;DR this post. theres a new one over here /EDIT So i have been implementing some networking for my &#8220;design challenge&#8221; and i challenged myself to do something generic enough to allow extension without rebuilding (easy via scripting) and to challenge myself to be able to split the tasks across [...]]]></description>
			<content:encoded><![CDATA[<p><strong> EDIT </strong></p>
<p>Seeing as i had TL;DR this post. theres a new one over <a href="http://blog.owned.co.za/?p=183">here </a></p>
<p><strong> /EDIT </strong></p>
<p>So i have been implementing some networking for my &#8220;design challenge&#8221; and i challenged myself to do something generic enough to allow extension without rebuilding (easy via scripting) and to challenge myself to be able to split the tasks across server/client and keep it all really simple. No network fiddling no byte packing, it will all be handled internally.</p>
<p><strong>What im looking for from the response of the reader.</strong></p>
<p>Simple. </p>
<p>Would you, perhaps a programmer or not, be inclined to extend your client with your own tools if it were like the description below. </p>
<p>Its not complete, its not 100% in depth, its idea based speculation based on some prototyping i did. </p>
<p><strong>Disclaimer</strong><br />
Before i get shot at for the code below, its experimental. There is inconsistency for a reason. Theres param[] and theres pop() theres weird conventions, and looking closer you may see the third part of this &#8220;tool&#8221; is a daemon. Seems like a lot of effort? I dont know if it is and thats kind of why im posting. Keep in mind this is a &#8220;simple&#8221; networked system. Theres users, and theres scripting, and theres ideas. </p>
<p><strong> The in-game OS </strong><br />
One note is that the &#8220;OS&#8221; in this game is designed around 3 larger parts. Tools, Daemons and the core interface. A tool is a simple utility, a daemon &#8220;listens and responds&#8221;, and the core exposes the internals.<br />
There are programs, and apps, and widgets and blah. THe point is to not over design, but to design in a way that the code will create itself. If 4 of my friends play, and 3 of them write a simple tool &#8211;  the game has gotten better for everyone. If i write a cool looking clock widget, it can be distributed as part of the core desktop. If someone writes a simple twitter viewer, etc etc etc etc. The networking interface supports much more than shown in the simple high level functions below so i guess anything is plausible.</p>
<p>I would like opinions or views, a discussion on my idea below. Is there a way for something as simple as ping to be even simpler for the, non core developer to ADD to the game, post release?</p>
<p><strong> Observations </strong><br />
YES, there might be ridiculous ideas here, and I know there may also be a lot of unknowns too, in the ideas below. </p>
<p><strong> The prototype code </strong></p>
<p>Now theres nothing magical going on in my server, its a simple eNet server thats got a thin wrapper for data streams and managing of packets, and a simple (might have &#8220;overhead&#8221;) way to embed &#8220;variants&#8221; in a stream without worrying about it.<br />
Implementing a simple hash table for certain network contexts that exists between client and server &#8211; instead of sending strings. If i add a string to the stream, its packed into a hash table on the server side and never sent again, only the index of that string.<br />
The code i have below is a simple javascript code in the ideal context for the game, on the lowest level. The core has access to the networking, and to the users , and the core itself.</p>
<p><strong>The Client side tool, </strong></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Client side tool for pinging another player in the game</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Author : FuzzYspo0N</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Etc</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//First, in order to create a tool on the client and server side,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//we simply assign a variable as a tool type. This might fail if </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//there is already a tool with this name &#8211; this returns undefined.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> corePingTool = <span class="kw2">new</span> core.<span class="me1">tool</span><span class="br0">&#40;</span><span class="st0">&quot;corePingTool&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Maybe something simple to register a tool with a defined </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//callback for users. This global tool shows up at the shell,</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// as a &quot;command line&quot; tool,and if a tool invokes</span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//a ui then it is not run via command shell but explicitly</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; core.<span class="me1">tool</span>.<span class="me1">registerGlobalTool</span><span class="br0">&#40;</span><span class="st0">&quot;ping&quot;</span>, <span class="st0">&quot;client name, ping count &quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//onExecute gets called whenever someone tries to ping </span></div>
</li>
<li class="li2">
<div class="de2"><span class="co1">//(either called via ui or via the above command line)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//Variable arguments handed in </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> corePingTool.<span class="me1">onExecute</span> = <span class="kw2">function</span><span class="br0">&#40;</span>param<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// 0 is reserved, so 1 is client name. 2 is ping count.</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> clientName = param<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> pingCount = param<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>pingCount == core.<span class="me1">invalid</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; pingCount = <span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//if we have a user like this, we can use em</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> userId = core.<span class="me1">users</span>.<span class="me1">isAUser</span><span class="br0">&#40;</span>clientName<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>userId != core.<span class="me1">users</span>.<span class="me1">invalidUser</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Create a new network javascript object. </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//This object handles network packing/streams internally.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The to dev, this is simple &#8211; a javascript object. </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Push data into the stream, and be done.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//The toolId is to header the packet type, for the server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//to know what to do with it.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> pck = <span class="kw2">new</span> core.<span class="me1">net</span>.<span class="me1">packet</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">toolId</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Add our data into the packet for the server to care</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">push</span><span class="br0">&#40;</span>userId<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">push</span><span class="br0">&#40;</span>pingCount<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Give it a callback when its feeling talkative</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">response</span> = <span class="kw1">this</span>.<span class="me1">onResponse</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//Send it to the server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; pck.<span class="me1">send</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//The servers response to a ping command</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> corePingTool.<span class="me1">onResponse</span> = <span class="kw2">function</span><span class="br0">&#40;</span>param<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//0 reserved, 1 is always the response code, 2 is the result</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//(known, from server side), 3 is the client requested</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>param<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> == core.<span class="me1">net</span>.<span class="me1">success</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//should output something like </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// &nbsp; &nbsp;ping response 128ms from &quot; DumbassTeh&quot; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> end = <span class="st0">&#8216; from &quot; &#8216;</span> + param<span class="br0">&#91;</span><span class="nu0">3</span><span class="br0">&#93;</span> + <span class="st0">&#8216; &quot; &#8216;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo<span class="br0">&#40;</span><span class="st0">&#8216;Ping response &#8216;</span> + param<span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> + <span class="st0">&#8216;ms&#8217;</span> + end<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//message box failure</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><strong>The server side response</strong></p>
<p>On the server side, once i, an in game developer have registered my new tool (via the developer tools/console), i can begin to expand the server script locally (theres a sandbox of sorts that allows this). </p>
<p>The way it will work is based on the toolId that is handed in the packet to the server. What the server does, to keep things generic, is look for a script on the server based on tool ids. For example, it might look like core/tools/34ea3.js when the server is done with it. It then looks for the tool name (handed in the constructor of the tool) to use as a function : </p>
<p>execute(toolName + &#8220;_Main&#8221;, packet);</p>
<p>The simplicity allows as many tools as needed be registered automatically without explicity adding them, the developer of the tool simply registers his tool via the constructor and console.<br />
The code sample below can demonstrate the idea behind the above client code, on the server side.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Server side tool for pinging another player in the game</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Author : FuzzYspo0N</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// Etc</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//expects &#8211; a packet with </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 1 &#8211; sourceUserId </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 2 &#8211; destUserId</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 3 &#8211; ping count</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">//context globals</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//var toolId is handed in from the system</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> corePingTool_Main = <span class="kw2">function</span><span class="br0">&#40;</span> pck<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//Pck is basically a javascript array, and pop will</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//simply keep a &quot;stackIndex&quot; internally. So in essence</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//what you can see here is </span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">// stackIndex += 1;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// return pck[stackIndex - 1];</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> sourceId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> destId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">var</span> pingCount = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span>i = <span class="nu0">0</span>; i &lt; pingCount; ++i<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//query : clientId, requesterId, daemonId, handler</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">query</span><span class="br0">&#40;</span>destId, sourceId, toolId, onPingBack<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2"><span class="kw2">var</span> onPingBack = <span class="kw2">function</span><span class="br0">&#40;</span>pck<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 1 &#8211; sourceUserId </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 2 &#8211; destUserId</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//pop 3 &#8211; response &#8211; if successful, it will have the ms it took</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> sourceId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> destId = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> response = pck.<span class="me1">pop</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>response != core.<span class="me1">net</span>.<span class="me1">response</span>.<span class="me1">timedout</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//the respond will hit the client callback that </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//pck.onresponse registered.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">respond</span><span class="br0">&#40;</span>sourceId, toolId, response<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//respond : destId, toolId, responseCode</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; core.<span class="me1">net</span>.<span class="me1">respond</span><span class="br0">&#40;</span>sourceId, toolId, core.<span class="me1">net</span>.<span class="me1">response</span>.<span class="me1">timedout</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Comments, views, ideas, etc &#8211; Welcome. Please, i like ideas.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.owned.co.za/?feed=rss2&amp;p=166</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
