<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title>NoshBar's Dumping Ground</title>
		<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php</link>
		<description><![CDATA[© copyright 2010-2012 Dirk de la Hunt. All rights reserved. <a rel="me" href="https:///mastodon.gamedev.place/@dirkderkdurk">Mastodon</a>]]></description>
		<copyright>Copyright 2026, NoshBar</copyright>
		<managingEditor>NoshBar</managingEditor>
		<language>en-US</language>
		<generator>SPHPBLOG 0.7.0</generator>
		<item>
			<title>From the depths of GMail...</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry160430-165312</link>
			<description><![CDATA[I was trying to find the picture of teenage me playing guitar naked like Blink 182 when...<br /><br /><center><a href="images/bananasplit_big.png"><img src="/images/bananasplit.png" alt=""  /></a></center><br /><center><em>(click the image for a larger version)</em></center>]]></description>
			<category>The Rest</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry160430-165312</guid>
			<author>NoshBar</author>
			<pubDate>Sat, 30 Apr 2016 15:53:12 GMT</pubDate>
		</item>
		<item>
			<title>Local multi-player through split-screen in Unreal Engine 4 BluePrints</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140711-115729</link>
			<description><![CDATA[<center><iframe width="560" height="315" src="//www.youtube.com/embed/VUAzn5unhkU" frameborder="0" allowfullscreen></iframe></center><br /><br /><em><em>Note:</em> uses <a href="https://www.unrealengine.com/" >UE4.2</a>, there were some issues with split-screen in earlier versions.<br /></em><br /><br /><h3>Step-by-step instructions for enabling split-screen</h3><br />1.<br /><a href="images/split_screen_settings_big.jpg"><img src="/images/split_screen_settings.jpg" alt=""  /></a><br /><br />And that&#039;s it.<br /><br />Mostly. As long as your player object has a camera, this will all just magically work once you add another player either by placing another player in the UI or through adding one in <a href="https://www.unrealengine.com/blog/blueprint-basics" >BluePrints</a> using <em>CreatePlayer()</em>.<br /><br /><h3>Problem modifying the second player</h3><br />I hit a snag trying to act on the second player through BluePrints.<br />I had created a <em><strong>Character</strong></em>-derived player class called <em>Player_BP</em> and set up the BluePrint graph for it so that when the &quot;change colour&quot; key-event fires, the material of the player mesh changes.<br />I did this by clicking on the mesh from the components tab on the left of the graph view and dragging it into the BluePrint graph as a <strong>GET</strong> operation node, then used the <em>Change Material</em> node to change the material, simple enough.<br /><br />This works great for the first player, but if you create a new character instance in the game of type <em>Player_BP</em> and have it react to the 2nd-player change-colour input, it still changes the colour of the first instance.<br /><br />I thought I was creating a class with member variables, and that making a new instance would run that script on the new instance.<br />This led me to investigate when variables are considered static, the document states that a variable is static <strong>unless</strong>:<ul><li>Exposed as editable</li><li>Set to something using the <strong>SET</strong> node</li></ul><br />This doesn&#039;t work as I expected, but I understand the reasoning. However, I didn&#039;t feel like exposing it as editable (making a new variable to do so?) or setting it manually using <strong>SET</strong>, so I manually got the second player character and modified the material like that.<br /><br /><a href="images/change_player_2_big.jpg"><img src="/images/change_player_2.jpg" alt=""  /></a><br /><em>(the first block shows how I first assumed it would work for all instances, the second block shows how I handled it afterwards to address each instance manually, using a for loop in my game, checking if the player is equal to NONE before trying to use it)</em><br /><br /><h3>Level layout for two</h3><br />Having finally got the colours of my players changing correctly I realised that I had one tiny flaw: I&#039;m a moron and hadn&#039;t thought that they&#039;d be sharing the same level, so when one player changed the colour of the platforms, it would change it for the second player too.<br />While that could be chaotic fun, I don&#039;t think it would actually work.<br /><br />Dismayed and on the point of giving up, I thought that I could simply make a clone of the platforms somewhere off screen from player 1, and make it a simple race to the top, but I really wanted the players to be able to see their competition on the same set of platforms as they were on.<br /><br />Then I realised: I truly am an idiot. Mirror it!  Simply flip the camera around 180 degrees when creating the second player, create double-layered platforms and BAM!<br /><br /><a href="images/sideview_big.jpg"><img src="/images/sideview.jpg" alt=""  /></a><br /><br />The picture above shows how I really do have double platforms and players on different Z-planes, as well as enlarged collision-boxes around the players so that they can collide with each other despite not being on the same Z-plane.<br />I have several plans for reworking this so that it looks less like two separate levels stuck together.<br /><br /><h3>Dealing with collisions</h3><br /><em>Disclaimer:</em> I still don&#039;t really know what I&#039;m doing with this. While I understand Box2D and Chipmunk collision groups and masks, this makes little sense to me.<br /><br />So, I wanted to have the two players collide when they&#039;re the same colour, and pass through each other when opposing colours.<br /><br />I guessed that I needed to change the group or mask or something of one of them when the user changed colours, but I couldn&#039;t find anything like a mask or group.<br />There are <em>Channels</em> however. After struggling for a while to to understand creating and using custom channels, I simply went with the following hack.<br /><br />Setting up the collision presets in the details tab of my player class so that pawns collide with pawns, makes sense, right?:<br /><a href="/images/collision_defaults.jpg"><img src="/images/collision_defaults.jpg" alt=""  /></a><br /><br />Adjusting the collision channels on the second player in BluePrints to set the collision response to <em>Ignore</em> if the players are different colours:<br /><a href="images/collision_blue_big.jpg"><img src="/images/collision_blue.jpg" alt=""  /></a>]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140711-115729</guid>
			<author>NoshBar</author>
			<pubDate>Fri, 11 Jul 2014 10:57:29 GMT</pubDate>
		</item>
		<item>
			<title>Some hints for fumbling around Unreal Engine 4</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140624-191233</link>
			<description><![CDATA[<center><iframe width="500" height="315" src="//www.youtube.com/embed/oY7ycWOCuYc" frameborder="0" allowfullscreen></iframe></center><br /><br /><h3>What this is</h3><br />This is a quick walk-through of the chaotic process I went through in recreating my <a href="http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry130501-122423" >8-hour jumping game</a> in <a href="https://www.unrealengine.com/" >Unreal Engine 4</a> using <a href="https://www.unrealengine.com/blog/blueprint-basics" >BluePrints</a> only.<br />I gave myself 8 hours again, seeing as I had the logic down and &quot;simply&quot; needed to learn a new environment (this was my first time using Unreal Engine).<br /><br /><strong>NOTE:</strong> I am an idiot, and as such sometimes enjoy jumping into things without reading any documentation simply because I love trying to figure things out on my own. I did through forums and AnswerHub and through Google, but I didn&#039;t sit down and read all the documentation.<br />So I&#039;m sure/guessing that the things I tripped on are in the documentation. I know I&#039;m a bad person.<br /><br /><h3>Things they (probably) don&#039;t tell you about input</h3><br />When Unreal first announced the release of 4.0 I watched a few of <a href="https://www.youtube.com/playlist?list=PLZlv_N0_O1gaG5BW72It4chjhypxIO9ZB" >their tutorial videos</a> to get a feel of how easy things were to convince myself that I needed to purchase it.<br />This meant I had seen some footage of assigning keypresses and joystick axis/buttons to events which you can easily act upon in BluePrints.<br /><br />Armed with this randomly-chosen video tutorial knowledge that had aged in my brain for 2 months, I was ready to go!<br />My first goal was to get a BluePrint event firing when I pressed the &quot;left&quot; key, so I created a new <em>blank</em> project <em>without starter content</em> and set off on a misadventure!<br /><a href="images/blankproject_big.jpg"><img src="/images/blankproject.jpg" alt=""  /></a><br /><br />I flittered joyfully to the Edit-&gt;Project Settings-&gt;Input section...<br /><a href="images/inputmapping_big.jpg"><img src="/images/inputmapping.jpg" alt=""  /></a><br /><br />...mapped the keys and hooked up the event in BluePrint...<br /><a href="/images/moveright.jpg"><img src="/images/moveright.jpg" alt=""  /></a><br /><br />...annnnd: nothing.<br />I pushed the left arrow key and the camera moved left... fine, I guess I have to override that somewhere... let me just change the key to &quot;N&quot;, that can&#039;t be mapped internally.<br /><br />Nothing.<br />Okaaay, a quick search on the net revealed the answer! You have to enable input for the object:<br /><a href="/images/enableinput.jpg"><img src="/images/enableinput.jpg" alt=""  /></a><br /><br />Nothing. Hmm.<br />More searching... &quot;Be sure that the input isn&#039;t being blocked&quot;, awesome!<br /><a href="/images/blockinput.jpg"><img src="/images/blockinput.jpg" alt=""  /></a><br /><br />De nada. Ah, vale.<br />Más la búsqueda... &quot;Be sure that the input isn&#039;t being consumed&quot;, de acuerdo!<br /><a href="/images/consumeinput.jpg"><img src="/images/consumeinput.jpg" alt=""  /></a><br />(open graph, select OnKeyEvent node, the details pane on the left)<br /><br />Still nothing. Okay. Getting annoyed now.<br />The forums didn&#039;t seem to have an answer, searching quickly through the documentation didn&#039;t reveal anything either, and what&#039;s worse, video tutorials were showing me how insanely easy it was!<br />&quot;Let&#039;s open the sample project and re-map the keys&quot;, followed by the same stuff I was doing.<br />&quot;Create a new sample project, BluePrint ThirdPerson&quot;, followed by the same stuff I was doing.<br /><br />After randomly stabbing darkness with a blunt mouse cursor I finally discovered that you need to create a new BluePrint object derived from GameMode and set your project to use it.<br /><a href="/images/gamemode.jpg"><img src="/images/gamemode.jpg" alt=""  /></a><br />(Edit-&gt;Project Settings-&gt;Game-&gt;Maps and modes)<br /><br /><strong>TL;DR;</strong><br />If you&#039;re starting a blank project without starter content, you need a &quot;Game Mode&quot; BluePrint object to get input.<br /><br /><br /><h3>Generating a very basic and ugly random level</h3><br />Having spent more time on looking how to resolve input than I have dedicated to exercise this year I was finally on to getting something on the screen.<br />I needed to generate platforms of random width that are randomly placed in an upwards direction. This part was easy!<br /><br /><a href="images/makeplatforms_big.jpg"><img src="/images/makeplatforms.jpg" alt=""  /></a><br />Simply create a mesh that is 1x1 in size, create a BluePrint actor/pawn that uses it, then spawn new instances of it using a for-loop in BluePrint.<br /><br /><br /><h3>Adding the player</h3><br />I added a new BluePrint and based it on the... <em>Actor</em>... <em>Pawn</em>, no... <em>Character</em> class... not sure.<br />My jumping block is hardly a character, but I want it to react to player input which the tooltip hints is a PlayerController...<br />I&#039;ll start with actor and work my way up...<br /><br />First things first (oddly enough), I want a little cube that platforms throw into the air and that moves to the appropriate side when I hit an arrow key.<br />It must also stop moving sideways instantly once I release the key.<br />To do so, I&#039;m going to need to set the velocity or add a force to the player, right.<br /><br />Actor and Pawn both appear to have a function you can call to <em>GetVelocity()</em>, but there isn&#039;t a <em>SetVelocity()</em>.<br />Strange, but I generate several random conspiracies as to why that could be.<br /><br />In the past when I&#039;ve worked with physics engines, I&#039;ve done something like &quot;add force&quot; or &quot;add impulse&quot;.<br />Searching for these did reveal that there is an &quot;Add Impulse&quot; you can apply to an actor, but BluePrints wasn&#039;t having any of it (<em>later I would discover that you can cast the actor to a Primitive Component and do this</em>).<br /><br />I also didn&#039;t want to have to take their old position, work out where the should be with the new velocity, and then call <em>SetActorLocation()</em>, because then I may as well not even use the physics engine.<br /><br />Through some lucky distraction in looking through answers online, I saw that there is a function called <em>LaunchCharacter()</em> to throw a character into the air, awesome!<br />I made a new player BluePrint based on Character and made the platforms <em>LaunchCharacter()</em> when an OnOverlap physics collision occurred.<br /><br /><a href="images/simplejump_big.jpg"><img src="/images/simplejump.jpg" alt=""  /></a><br /><br />Finally, my stupid cube could see its house from there. Time to make it move sideways.<br />Fortunately <em>LaunchCharacter()</em> takes a vector when launching something, so in order to not change the vertical velocity, I could simply <em>GetVelocity()</em> for it, change the sideways value and pump that into <em>LaunchCharacter()</em>!<br />Except not.<br />Then I realised that <em>LaunchCharacter()</em> has an option to only affect the axis I was bothered about, so I added another LaunchCharacter to make it move sideways only, hurray!<br /><br />Sadly, my character kept moving sideways even when I let go of the key.<br />Fortunately I&#039;m not stupid, I could simply <em>GetVelocity()</em> for it, negate the sideways value and pump that into <em>LaunchCharacter()</em>!<br />Predictably, this didn&#039;t work either, *sigh*.<br /><br />Finally my brain clicked and upon releasing a movement key the BluePrint simply calls <em>LaunchCharacter()</em> with zero values and the override option enabled for the sideways value.<br /><a href="images/movementblueprint_big.jpg"><img src="/images/movementblueprint.jpg" alt=""  /></a><br /><br /><br /><h3>Changing colours</h3><br />This was easy enough, I had thought about changing the materials dynamically, so that when the &quot;change colour&quot; key was pressed I would simply invert the brightness of the two coloured materials, but in the end I decided to just create 4 materials and swap between them:<ul><li>Bright orange</li><li>Dim orange</li><li>Bright blue</li><li> Dim blue</li></ul><br />But this meant keeping track of all the platforms throughout the lifetime of the level so that I could change the material assigned to them.<br />In my level BluePrint I added two array variables, one each for the orange and blue platforms.<br />OnChangeColourEvent I iterate through both arrays and assign either the dim or bright materials to them depending on the colour of the player.<br /><br /><a href="images/colour_swap_big.jpg"><img src="/images/colour_swap.jpg" alt=""  /></a><br /><br />To prevent the player from being able to rebound off platforms that are not their current colour, in the OnCollisionOverlap() event I check to see if the player and platform materials match, if not I don&#039;t do anything.<br /><br /><a href="images/colour_hitsame_big.jpg"><img src="/images/colour_hitsame.jpg" alt=""  /></a><br /><br /><h3>Setting resolution of the game</h3><br />Searching for a way to set the runtime resolution of my game lead me to the documentation page describing the &quot;Quick Settings-&gt;Scalability&quot; menu on the main editor toolbar, but this made no sense in that I couldn&#039;t see a single thing on how to set the resolution specifically.<br /><br />As it turns out  the only way I could find how to do it was to add a node at the start of my level graph to issue a Console command of e.g., <em>r.SetRes 1280x720</em><br /><br /><h3>Adding the juice</h3><br />Seeing as the basic stuff had been done and I was running out of time to complete new things (like proper level creation), I decided to justify my choice in doing this in UE4 by <a href="https://www.youtube.com/watch?v=Fy0aCDmgnxg" >juicing things up</a>.<br />And this is where UE4 started to shine, adding particle-systems on platform collisions was trivial, adding funky overdone lighting effects was too...<br />Honestly, to be able to just spawn a particle system at a collision point and have those particles bounce off platforms while lighting their surrounding areas up is mind-blowing for my mode 13 brain.<br /><br /><a href="images/particles_big.jpg"><img src="/images/particles.jpg" alt=""  /></a><br /><br /><h3>Summary</h3><br />I thought that using something like Unreal Engine would take the fun out of creating a game, leaving me with putting the <em>&quot;ass&quot;</em> in <em>&quot;art assets&quot;</em>.<br />But the fun of learning how to use the engine and joy of debugging BluePrint code visually, combined with being able to add insane lighting and particle effects in a whimsical folly of sugar-fueled insanity is... well, it still feels like making a game and like I achieved something, which is all I can ask for at the end of a day.]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140624-191233</guid>
			<author>NoshBar</author>
			<pubDate>Tue, 24 Jun 2014 18:12:33 GMT</pubDate>
		</item>
		<item>
			<title>jmp:err in Unreal Engine 4, prototype 1</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140622-155339</link>
			<description><![CDATA[<center><iframe width="420" height="315" src="//www.youtube.com/embed/9Ww4xGAqBEc" frameborder="0" allowfullscreen></iframe></center><br /><br /><h2>What it is</h2><br />This is (the prototype of) an Unreal Engine 4 remake of <a href="http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry130501-122423" >my tiny 8-hour jumping game</a>, featuring random level generation and so much lighting that it makes blind people wince.<br /><br />I set aside 8 hours to finally get started on Unreal Engine and while there&#039;s no proper objective beyond getting to the top right now, the basic gameplay mechanics of only being able to jump on the platform matching your current colour is working.<br />It&#039;s naturally also a delight to be able to visually edit a particle system... and replacing the sparks with an explosive particle system to enable <strong>Michael Bay</strong> mode is <em>AWESOME!</em><br /><br />Sane and pretty level generation comes next, as well as a few billion other &quot;tiny&quot; things (prettier materials, scoring, etc.)...<br /><br /><h2>Capturing footage</h2><br />I&#039;m (definitely) probably just being stupid, but I thought that <a href="http://www.geforce.com/geforce-experience/shadowplay" >ShadowPlay</a> from Nvidia was the solution to all my game-footage capturing problems.<br /><br />Well, first I had to update my video driver, fair enough.<br />Then it simply wouldn&#039;t &quot;switch on&quot;.<br />Fine.<br />You have to re-install the GeForce Experience application.<br />Fine.<br />Then I couldn&#039;t seem to capture footage of a windowed-game, only full screen...<br />FINE.<br />Oh look, it&#039;s randomly scaling things to fit something somewhere.<br /><br /><strong>TL;DR</strong>: use <a href="https://obsproject.com/" >Open Broadcaster Software</a>, close the Unreal Editor, start your game, set OBS to &quot;Game Mode&quot; and you&#039;re set.]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140622-155339</guid>
			<author>NoshBar</author>
			<pubDate>Sun, 22 Jun 2014 14:53:39 GMT</pubDate>
		</item>
		<item>
			<title>Ghosts of futures past.</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140515-152006</link>
			<description><![CDATA[<center><a href="/images/depression1.jpg"><img src="/images/depression1.jpg" alt=""  /></a></center>]]></description>
			<category>Illustrations, The Rest</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140515-152006</guid>
			<author>NoshBar</author>
			<pubDate>Thu, 15 May 2014 14:20:06 GMT</pubDate>
		</item>
		<item>
			<title>Howto quickly change permissions and delete a folder.</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140511-170330</link>
			<description><![CDATA[Ever had one of those folders that doesn&#039;t technically belong to you and -even though you&#039;ve got Administrator rights- you can&#039;t delete it?<br /><br />The usual way is to right-click the folder, select security, click advanced, change the owner of it and all subitems to you, then accept, then right-click and open it again so that you can grant full rights on the folder to you...<br /><br />Well, say now you want to do this for a bunch of folders, say an existing Windows installation on a drive you&#039;re using from within a newer Windows installation... it&#039;s a huge pain in the gluteus maximus.<br /><br />Why not <strike>Zoidberg</strike> a DOS batch file?<br /><pre>takeown /F %1\* /R /A<br />icacls %1\*.* /T /grant administrators:F<br />rmdir /S /Q %1</pre><br />Example usage: <code>deleteit.bat e:\windows</code><br /><br /><strong>Note:</strong> if <code>icacls</code> is not available, try just <code>cacls</code> which also works, but first prompts you if you&#039;re sure.]]></description>
			<category>Hacks, Other</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140511-170330</guid>
			<author>NoshBar</author>
			<pubDate>Sun, 11 May 2014 16:03:30 GMT</pubDate>
		</item>
		<item>
			<title>Short-Sighted Snake prototype</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140430-150650</link>
			<description><![CDATA[<center><iframe width="420" height="315" src="//www.youtube.com/embed/JjBsCizKH1Y?rel=0" frameborder="0" allowfullscreen></iframe></center><br /><br />Get it <a href="/files/sssnake.zip" >here</a>.<br /><br /><h3>What you&#039;re getting</h3><br />A Snake-type game where you are a short-sighted snake trying to find food in an unknown maze.<br /><br />This prototype is unproudly delivered to you in the form of a thousand different hacks tied together with tape made from hack extract with a sprinkling of the worst &quot;levels&quot; ever &quot;designed&quot;.<br /><br /><h3>What I wanted to do</h3><br />Well, for starters, &quot;Short-sighted Snake&quot; abbreviates beautifully to &quot;SSS&quot;.<br />This is both often the <a href="http://en.wikipedia.org/wiki/Onomatopoeia" >onomatopoeia</a> used for snakes AND an abbreviation for <a href="http://en.wikipedia.org/wiki/Subsurface_scattering" >SubSurface Scattering</a>... meaning I would have had the opportunity to go crazy with making 3 beautifully SSS rendered snakes next to each other to display the logo &quot;SSS&quot;.<br /><br />Title-screens aside, of course I wanted there to be a nice user interface for selecting levels, viewing scores, etc., but alas, I&#039;ve just run out of the opportunity to be able to work on this any longer.<br /><br /><h3>How to play</h3><br />Upon loading the &quot;game&quot;, use <strong>SPACE</strong> to start the game, then the arrow keys for changing direction of the snake.<br /><br />As an added bonus hindering feature, you can also press &quot;<strong>3</strong>&quot; to view the level in pseudo-3D where the food sometimes becomes obscured by walls.<br /><br /><h3>How to make levels</h3><br />Should you one day lose your senses and decide you&#039;d like to play this &quot;game&quot;, you can make your own levels to replace the ones kindly provided in this distribution by Satan himself.<br /><ul><li>Levels are 32-bit PNG image files</li><li>Walls are defined by painting with a colour whose Alpha value is an even number</li><li>Upon startup, the game looks for consecutive files named &quot;level1.png&quot;, &quot;level2.png&quot; and so on, until &quot;level&lt;N&gt;.png&quot; is not found.</li></ul><br />]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140430-150650</guid>
			<author>NoshBar</author>
			<pubDate>Wed, 30 Apr 2014 14:06:50 GMT</pubDate>
		</item>
		<item>
			<title>DWScript in a DLL</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140419-154008</link>
			<description><![CDATA[Or to be quite silly:<br />Delphi Web Scripting in a Dynamic Link Library for running Object Pascal scripts in C [and other languages]<br /><br /><h3>What it is.</h3><br /><a href="https://github.com/noshbar/c_dwscript" >This</a> is a simple Windows DLL <em>(<a href="https://github.com/noshbar/c_dwscript" >32-bit DLL provided</a>)</em> that enables you to compile and run Object Pascal scripts from within your favourite language (provided it supports loading DLL&#039;s with the stdcall calling convention) using the <a href="http://www.delphitools.info/dwscript/" >DWScript engine</a> by Eric Grange.<br /><br />Support for calling functions in the Pascal script is supported, as well as registering functions from e.g., C that the script can call. (A sample C wrapper and example are included in the <strong>&quot;c_interface&quot;</strong> folder).<br /><br />Available under the <a href="http://www.mozilla.org/MPL/1.1/" >Mozilla Public License 1.1</a><br /><br />Why? Who can honestly say they&#039;ve never wanted to run hand-optimised assembler inlined into Pascal Script from within Visual Basic 6? <a href="https://www.youtube.com/watch?v=T4TlVRsm8v0" >I know I have.</a><br /><br /><h3>Features.</h3><br /><ul><li>Run full Object Pascal scripts from within your application</li><li>Jitter can be enabled for JIT compilation, speeding up code &quot;quite a lot&quot;.<br />I obtained nearly double the execution performance in some cases e.g, running my smallPT renderer conversion without JIT enabled took 39 seconds, whereas the JIT enabled one only took 25 seconds.<br /><strong>[*only when compiled with Delphi for now]</strong></li><li>OLE support can be enabled<br /><strong>[*only when compiled with Delphi for now]</strong></li><li>ASM support can be enabled<br /><strong>[*requires NASM executable in the same path as the DLL]</strong></li><li>The provided DLL was built using Delphi XE 5 from an SVN checkout of the DWScript sources on the 18th of April 2014.</li></ul><br /><br /><h3>Using.</h3><br />A simple C example would be something like this:<br /><pre>HMODULE handle = DWScript_initialise(&quot;dwscript.dll&quot;);  <br />//you can make as many contexts as you like, but cannot mix and match contexts as you wish<br />DWScriptContext context = DWScript_createContext(DWScript_Flags_Ole | DWScript_Flags_Asm);<br />//add any local C functions into the context with DWScript_addFunction()<br />//and DWScript_addParameter() before compiling<br />DWScript_compile(context, &quot;begin end.&quot;, DWScript_Flags_Jitter); //only necessary once per context<br />DWScript_execute(context, DWScript_Flags_None); //call as many times as you like<br />DWScript_destroyContext(context);<br />DWScript_finalise(handle);<br /></pre><br /><br /><h3>Ideas / TODO</h3><br /><ul><li>Instead of the horrendous fixed-array of unions parameter nonsense going on, you could optionally make the functions take varargs and make calling them a much-more straight-forward affair.  <br />My only worry then is that you&#039;d have to change from stdcall to cdecl, thereby losing the ability to use this DLL from within certain languages.</li><li>Fix Unicode/AnsiString conversions  /  Implement Unicode support</li><li>Add the ability to run a script in a non-blocking manner.</li><li>Add debugger support so that you can set breakpoints in the code, etc.</li><li>Make error handling and reporting not suck.</li></ul><br /><br /><h3>Free Pascal Notes.</h3><br /><strong>TL;DR;</strong> Only <a href="https://dl.dropboxusercontent.com/u/4716604/fpc2.7.1.7z" >this</a> binary collection of FPC 2.7.1 works for me.<br /><br />I initially started this project using <a href="http://www.freepascal.org/" >Free Pascal</a>.<br /><br />As DWScript uses Generics, I needed a newer version of the Free Pascal compiler than what they provide on their home page (2.6).<br /><br />Fortunately I had <a href="http://sourceforge.net/projects/laz4android/" >Laz4Android</a> installed, which came with a build of FPC 2.7.1  <br />This also provided me with the Masks unit that some DWScript units needed.  <br /><em>(I found mine in laz4android/components/lazutils)</em><br /><br />I initially made some horrible hacks to the DWScript code to just get it compiling <em>(deleting entire classes, casting wide to ansi strings, etc.)</em>, a simple proof-of-concept to see if it was worthwhile continuing.<br /><br />Once I had a working DLL, I decided to update my version of Laz4Android to see if it fared any better at the Generics stuff...<br /><pre>Error: Undefined symbol: VMT_$DWSUTILS_$$_$GENDEF386</pre><br />Hmm, Google had nothing on it, nothing on GENDEF386, couldn&#039;t find mention of this in the sources.  <br />Oh well, no worry, I&#039;ll just try:<br /><ul><li>compiling FPC from SVN</li><li><a href="http://www.crossfpc.com/" >CrossFPC</a></li><li><a href="http://www.pilotlogic.com/sitejoom/index.php/codetyphon" >CodeTyphon</a></li><li>A random version of Laz4Android I found</li><li>Building it all on the command line using FPC, then linking it all manually with verbosity set to &quot;I can show you the world&quot;</li></ul>...<br /><pre>Error: Undefined symbol: VMT_$DWSUTILS_$$_$GENDEF386</pre>Well screw you too.<br /><br />I&#039;ve done some investigation into it, I built a little Python Pascal Parser to detect differentiating Interface/Implementation function descriptions and found some things... but nothing the compiler seems upset about.  <br />So instead, if you want to use Free Pascal to compile this, you can try using the binary dump of FPC2.7.1 I took from my working version of Laz4Android from <a href="https://dl.dropboxusercontent.com/u/4716604/fpc2.7.1.7z" >here</a>.]]></description>
			<category>Ramblings, Coding Related, Hacks, Other</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry140419-154008</guid>
			<author>NoshBar</author>
			<pubDate>Sat, 19 Apr 2014 14:40:08 GMT</pubDate>
		</item>
		<item>
			<title>Avoiding blurry image drawing with the HTML5 Canvas</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry131121-131751</link>
			<description><![CDATA[I recently discovered the HTML5 Canvas, it&#039;s lovely, like the good old days of using $A000:0000!<br /><br />However, when drawing an image to the canvas it kept coming out all blurry. As it turns out, there are actually quite a few possible reasons for this to happen... here&#039;s a short checklist of what I discovered on my quest to fix it.<br /><br /><h3>Setting Canvas dimensions</h3><br /><br />Most articles I came across mentioned that you should always explicitly specify the dimensions of a canvas, either when creating the element in bland HTML e.g., <br /><pre>&lt;canvas id=&quot;drawable&quot; width=&quot;100px&quot; height=&quot;100px&quot;&gt;&lt;/canvas&gt;</pre><br />or via JavaScript e.g,<br /><pre>canvas        = document.getElementById(&quot;drawable&quot;);<br />canvas.width  = window.innerWidth;<br />canvas.height = window.innerHeight;<br /></pre><br /><br /><h3>Setting Canvas style dimensions</h3><br /><br />The above is actually not enough though, you also need to set the CSS dimensions, changing the above JavaScript to SOMETHING like:<br /><pre>canvas              = document.getElementById(&quot;drawable&quot;);<br />canvas.width        = window.innerWidth;<br />canvas.height       = window.innerHeight;<br />canvas.style.width  = canvas.width.toString() + &quot;px&quot;;<br />canvas.style.height = canvas.height.toString() + &quot;px&quot;;<br /></pre><br /><br /><h3>Catering for different pixel ratios</h3><br /><br />Testing my code out on my retina iPad, I discovered that <code>window.innerWidth</code> and <code>window.innerHeight</code> were returning half of what they should have.<br /><br />Turns out there&#039;s a variable called <code>window.devicePixelRatio</code> that is present on retina devices, and contains the scale you should use when dealing with dimensions...<br /><br />...sort of. See the &quot;Drawing Pixels is hard&quot; link below for a much clearer explanation.<br /><br /><h3>CSS image rendering settings</h3><br /><br />Turns out there&#039;s ALSO a CSS variable you can change to affect how things are handled internally, it&#039;s called <code>image-rendering</code><br /><br />You can use it something like this:<br /><pre>/* applies to GIF and PNG images; avoids blurry edges */<br /><br />img[src$=&quot;.gif&quot;], img[src$=&quot;.png&quot;] {<br />                   image-rendering: -moz-crisp-edges;         /* Firefox */<br />                   image-rendering:   -o-crisp-edges;         /* Opera */<br />                   image-rendering: -webkit-optimize-contrast;/* Webkit (non-standard naming) */<br />                   image-rendering: crisp-edges;<br />                   -ms-interpolation-mode: nearest-neighbor;  /* IE (non-standard property) */<br />                 }<br /></pre><br /><br /><h3>Pixel offsets</h3><br /><br />Finally getting to what actually fixed it for me, a silly mistake to make.<br /><br />I wanted to draw my image centered on the canvas, so ended up doing something like: x = canvas.width / 2 - image.naturalWidth / 2, doing the same thing for y.<br /><br />This leads to floating point co-ordinates, perhaps starting in the middle of a pixel. Being a JavaScript dunce I simply used <code>parseInt(x)</code> to draw the image, and that seemed to cure it for me.<br /><br />Oddly enough though, I&#039;ve seen many mentions of always drawing to x+0.5,y+0.5, but I have no idea why you&#039;d do that... unless you always happened to start at 0.5 in the first place.<br /><br /><h3>References</h3><br /><br /><a href="http://phoboslab.org/log/2012/09/drawing-pixels-is-hard" >Drawing pixels is hard</a><br /><br />About the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering?redirectlocale=en-US&amp;redirectslug=CSS%2Fimage-rendering" >image-rendering</a> setting<br />]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry131121-131751</guid>
			<author>NoshBar</author>
			<pubDate>Thu, 21 Nov 2013 13:17:51 GMT</pubDate>
		</item>
		<item>
			<title>Remote eBook viewer</title>
			<link>http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry131119-122608</link>
			<description><![CDATA[<h3>Introduction</h3><br /><a href="http://calibre-ebook.com/" >Calibre</a> is handy for organising eBooks.<br /><a href="http://en.wikipedia.org/wiki/Lexcycle_Stanza" >Stanza</a> is really handy for reading eBooks on the iPad.<br />Calibre can act as an <a href="http://anoved.net/2012/01/calibre-content-server/" >eBook server</a>.<br />Stanza is capable of using this functionality to transfer books from your PC to your iPad.<br />Hooray, all my book-reading requirements are fulfilled!<br /><br />*sigh*, of course not.<br /><br />Stanza had a lot going for it: it was free; it could decode numerous eBook formats; it could download books from Calibre.<br />Sadly, it now has some issue: it is no longer available; with newer versions of iOS it has a bug where you can&#039;t navigate away from resized pages (well, you <em>can</em>, but it&#039;s a pain in the <a href="http://en.wikipedia.org/wiki/Justin_Bieber" >gluteus maximus</a>).<br /><br />As I personally only read books at home (not on holiday) I also found it a waste to have the eBook stored on my device, not only because of the space usage, but the Calibre-connection was really intermittent and unreliable and I&#039;d rather count dust-bunnies on the floor than use iTunes to sync data.<br /><br /><h3>The Stupid Idea</h3><br />It is thus that I came up with another almost-patented stupid idea:<br />Make a remote Calibre eBook viewer, almost like a Calibre-<a href="http://www.tightvnc.com/" >VNC</a>.<br />Make a tiny web-server that reads the Calibre database and feeds book information using <a href="http://en.wikipedia.org/wiki/JSON" >JSON</a>, and use a tiny WebApp that requests pages as images.<br />All processing happens on the server, so PDF pages are rendered to an image of the desired size and fed up as high-quality JPEG/PNG images to the WebApp.<br /><br />This means that I no longer need to download books to my device, nor do I need to rely on the viewing application to cater for the format I want, as I can simply implement it on the server.<br />In theory, it means you could also read all your books from anywhere in the world via the internet, even if you forgot to sync it with your device.<br /><br /><h3>The Prototype</h3><br />As always, when I want to prototype something quickly, I turned to <a href="http://www.freepascal.org/" >FreePascal</a>/<a href="http://www.lazarus.freepascal.org/" >Lazarus</a>.<br />Lazarus had everything I needed to test the idea:<ul><li>a web-server class to server the JSON and images</li><li>a zlib class to open a test CBZ comic book</li><li>image classes to quickly load and resize JPEG images</li></ul><br />Next I made a very hacky <a href="http://jquery.com/" >jQuery</a> powered WebApp page thing to list books and navigate through a chosen book.<br />The web request &quot;API&quot; was very simple, you could ask how many pages a book had (<code>/info/?id=10</code>) or ask for a page from a book (<code>/view/?id=10&amp;page=13</code>).<br />Next I made sure that the /view/ &quot;command&quot; supplied the dimensions of the current viewport so that became the native 1:1 &quot;scale&quot; for pages from the book.<br />The idea was that you could then zoom the 1:1 image locally in JavaScript, perhaps pan it around a bit, and then make another request to the server with a zoom factor, to clear the image up a bit.<br /><br />I was set, it was all working pretty sweetly, so I went ahead and used <a href="http://kernelex.sourceforge.net/wiki/Sumatra_PDF" >libmupdf</a> to test processing of PDF files, and... awesome.<br />It still has a minor issue where drawing the image to an HTML5 canvas results in it being blurry (despite setting the CSS dimensions to match, despite setting some custom moz and webkit filters), but -hey-, good enough for now.<br /><br /><h3>The Proper Version</h3><br />So, now it comes to making the &quot;proper&quot; version for people of the world to use, and I&#039;m stuck.<br />I could make it in <a href="http://www.python.org/" >Python</a>, but then people would have to install Python to get it to work... perhaps a non-issue?<br />I could make it in <a href="http://www.mono-project.com/" >Mono</a> just for my own fun, but again, it&#039;s another framework people need to install.<br />I could simply clean up the Lazarus version I guess, but there are a few niggly weird bits that I&#039;d have to work around, and the resulting executable would be quite large.<br />I could make a plugin for Calibre, maybe?<br />I could make a plugin for Sumatra, maybe?<br />I&#039;m tempted to do a very tiny version in C/C++ using the <a href="http://code.google.com/p/mongoose/" >Mongoose web server</a> library (<a href="http://www.lua.org/" >Lua</a> webpages? Woohoo!), <a href="https://code.google.com/p/jpeg-compressor/" >JPEG compressor library</a> and libmupdf... buuut that kind of thing always takes quite long to do properly.<br /><br />This is all assuming that people would want to use this kind of thing and that I need to take it beyond the prototype...<br />But coding is fuuuun... can&#039;t... stop... self...<br />]]></description>
			<category>Ramblings, Coding Related</category>
			<guid isPermaLink="true">http://iwasdeportedandalligotwasthislousydomain.co.uk/index.php?entry=entry131119-122608</guid>
			<author>NoshBar</author>
			<pubDate>Tue, 19 Nov 2013 12:26:08 GMT</pubDate>
		</item>
	</channel>
</rss>
