Friday, 23 August 2013

New web site is up

I have completely failed to keep you all up to date with the latest development news from me.
A few days ago, my new games development web site went live. Even if I do say so myself, I think it's pretty cool. The entire site is coded by hand (apart from the Lightbox scripts). I prefer to create my own sites this way, so that I have total control over the content, without relying on, or being limited by, a third party content management system.
Anyway, if you want to have a look (and I know you do), then hop on over to: http://www.krazypengwin.com.
Second bit of news, probably not as impressive, but I think it is equally important, I have made some changes to the Colour Code Generator I mentioned before. It is now possible to drag and drop colours from the custom colours to the main colour button, and vice versa. It is also possible to use drag and drop to reorder the colours in the custom section. A little more important, I have added the possibility to drag and drop a colour from the application directly to the source code, and it will insert the colour, in the format selected, into your code. Not a massive change, but it could be useful and save a few seconds, rather than having to click Copy and then Paste. Some more formats have also been added, so the colours can now be formatted for the following languages: Monkey, BlitzMax, Xojo, Cocoa for OS X, Cocoa for iOS, Lazarus (and Delphi), Python, HTML, CSS and as either a list of decimal or hexadecimal values.
This little tool, along with some of the others I have written, will be available from my web site once I have written the help documentation.

Saturday, 17 August 2013

Yet another in house tool created

Not been long since my last post, but I thought you all might like to know about my newest in house tool that will save me a lot of time in the future.
First of all, the reasoning behind it: both Monkey and BlitzMax have the facility to import animation strips for using with your sprites. These are images which hold all the frames of a particular animation, so that you can load them at once, rather than having to load multiple images, which is a lot slower.
The concept behind it is dead easy, each frame of the animation has the same height and width, and therefore, the image is easy to break up into the individual frames as the animation progresses. The downside of this is the time it can take to manually create an animation strip, particularly if you have a lot of frames, it is not uncommon to use 15 separate frames just for walking in a single direction. Below is an example of the animation strip I used when I created Mr Wong's Loopy Laundry:
As you can see, there are 59 frames to animate Mr Wong. I created this by hand and it took quite a time.


So, to help ease this process, I have written a small program I call Image Stitcher. I guess you could call it the sister program of Image Slicer. What it allows me to do, is import each of the frames, select the output height and width of the frames (in case I decide to enlarge or shrink them), the drawing style (scaled - maintaining aspect ration, stretched or cropped) and the number of columns in the animation strip. This is then exported as a single image, like the one above.

As you can already see, this is a massive time saver, that will hopefully save me hours of work.
As with my other tools, it was written with Xojo.

Saturday, 10 August 2013

New tools

OK, time for another update (already!?).
I have been in the process of developing some in house tools that will help me write the games. I generally create tools as and when I need, or want, them. I could probably go to the App Store and find other peoples versions myself, but I figure, why pay for them, when I can write them. After all, if you are a plumber, you don't call someone in to fix the sink.

So I thought I would show them to you, just so you don't think I've been idly sitting on my arse.



These are obviously jus the icons that our amazing art department (erm... me) created. I shall go through each of these in order.


First up, the Colour Code Generator:

I don't know about you, but I hate having to work out colours and insert them into the source code, or web page. So this little tool allows me to select a colour, using the standard OS X colour selector and it will then display the colour codes in decimal and hex, as well as a source format of my choosing (at present, it will display code for Monkey/BlitzMax, HTML/CSS and Xojo/RealStudio). I can then click copy which will copy the source to the clipboard for pasting into my source code. If I already know the decimal or hex codes, I can enter them manually and it will adjust the colour accordingly. It's a small app, but quite a time saver.

Next, Database Analyser:

This is quite an old tool I wrote some time ago and it is a major headache remover when developing database applications in Xojo.
The analyser will load an SQLLite database file that has been created in the Xojo IDE and kick out the source code required for Xojo to create a new database file on the fly with the same structure. If you have designed quite a large database, this can save you, literally, hours of coding time, converting it to source code.

Font Builder:

Although the Monkey language is ideal for writing cross platform games, one of the areas where it is lacking is font and text support. In fact, it virtually has no font support. So to remedy this, Font Builder allows me to create a PNG image file of the required font and it also exports a definition file that is then loaded into Monkey (using my own custom class) and the font can then be used within the game. But, it is not limited to the standard TrueType fonts that come with a Mac, nor just to those that are downloadable. Because the Builder uses PNG images, it is also possible to create your own fonts, in colour, for your games. This can allow a much more vibrant screen display, without having to create a bunch of extra image files.

Image Slicer:

Working on my current game, I came upon a few limitations in Android that prevented me from using large images effectively. I also noticed that some of the images I was  using were pretty inefficient, memory wise, as there were large areas of transparencies in them. Image Slicer allows me to slice images in a grid pattern of my choosing. I am also able to select which slices are to be exported and which are to be ignored. This way, I can more effectively manage the memory usage of my games and also obtain a few speed enhancements.

Finally, Max Debugger:

I have shown this one before. As I do most of my coding in BBEdit, rather than the Monkey or BlitzMax IDE's, I needed a way to debug my BlitzMax games without having to fire up the IDE. Max Debugger is just that, simply a debugger for BlitzMax games.
I do plan to enhance this further at some point in the future to also act as a debugger for Monkey and to allow remote debugging for multiple platforms.

All these tools were written with RealStudio (I haven't actually upgraded to Xojo yet) and compiled as Cocoa apps.
Wow! Seems like months since I last posted anything here.

Oh, wait. I HAS been months!

So, what have I been up to in the world of programming?

Well, I have begun work on some new games under the Krazy Pengwin Games label. I'll post some more news about them soon.
I have switched game development language to Monkey. This is also by Blitz Research, in fact, it can be seen as the little brother to BlitzMax, but it has a neat little trick that BlitzMax did not. Whereas BlitzMax was cross platform, allowing me to compile to Mac, Windows and Linux, Monkey goes even further. With a single source project, I can create games for, not only the desktop operating systems, but also for Android and iOS. Monkey also supports XNA, but I'm not too interested in publishing to that platform right now. So the upshot is, the games I am working on will also be available to mobile user, firstly Android, but hopefully iOS by the end of the year.
I'm still using RealStudio (now called Xojo) for in house tools, but not much in the way of commercial applications. Once my new web site is up and running, I will be making some, if not all, of these tools available for free download.
Well, that's it for now, so just watch this space for details of new games and stuff.

Wednesday, 28 November 2012

Image files in Virtual Volumes

In  a recent Real Studio project, I realised that I needed to save image files with a Virtual Volume. At first, I didn't give this any thought, I proceeded with my normal way of saving and loading the images. Little did I know at that time, but images cannot be saved in this way when using a Virtual Volume, so I needed to come up with a new method.
The best way I discovered to accomplish this is using a MemoryBlock as an intermediary class. Fortunately, the Picture class has a method called GetData and a shared method called FromData that allow us to transfer the image to and from a MemoryBlock.
So armed with this information, I first created a new save routine. I decided to extend the Picture class to help keep things neat:

Sub SaveToVirtualVolume(Extends MyPicture As Picture, file as FolderItem, format As String="public.png", quality As Integer=Picture.QualityDefault)

  'Create a new memory block with the data from the Picture class

  Dim m As MemoryBlock=MyPicture.GetData(format,quality)

  'Open a binary stream to the file, overwriting it if the file already exists
  Dim s As BinaryStream=BinaryStream.Create(file,True)
 
  'If the binary stream has successfully been opened, write out each 

  'byte from the memory block to the binary stream
 if s<>Nil then
    Dim Index As Integer=0
    while Index<m.Size
      s.WriteByte(m.Byte(Index))
      Index=Index+1
    wend
    s.Close
  end if
End Sub


As I normally use the PNG file type for images, I created this method to default to PNG should I not specify a format.
To read the image back from the Virtual Volume, I created a stand alone function, so that if the load failed, it would return a Nil object:

Function LoadImageFromVirtualVolume(file As FolderItem) As Picture
  'Create a new picture object to receive the image file

  Dim MyPicture As Picture

  'If there is a problem with the file passed to the
  'function, we should not attempt to load the image, 
  'and just return a Nil object
  if file<>Nil and file.Exists and not file.Directory then


    'Open the file as a binary stream and load it into a 
    'memory block that we create to hold the contents of the file
    Dim s As BinaryStream=BinaryStream.Open(file)
    if s<>Nil then

      'Create the new memory block with a size that matches the files contents
      Dim m As MemoryBlock=New MemoryBlock(s.Length)
      Dim Index As Integer=0
      while not s.EOF
        m.byte(Index)=s.ReadByte()
        Index=Index+1
      wend
      s.Close


      'Now simply use the FromData shared method to create 
      'the Picture object from the memoryblock contents
      MyPicture=Picture.FromData(m)
    end if
  end if


  'Return the object that is now either nil or the loaded image
  Return MyPicture

End Function

This is a very rough and ready way to accomplish what I am after, but now, when I have an image I need to save in a Virtual Volume, I simply use:

   MyImage.SaveToVirtualVolume(file)

or if I wish to save a JPEG, I could use:
   MyImage.SaveToVirtualVolume(file,Picture.FormatJPEG,Picture.QualityHigh)

To load an image back in from a Virtual Volume, I would use:

  MyImage=LoadImageFromVirtualVolume(file)

If the load was successful, then the variable MyImage would now contain the picture loaded, otherwise it would contain Nil.

Hope this is of some help to anyone who also encounters this minor oddity.

Tuesday, 15 May 2012

Debugging tips - continued

After my post about the excellent tutorial by Thomas Tempelmann (previous post), I decided to play around with a simple profiling class. I have commented the source, so it should be fairly self explanatory, but I will explain how to use it after the source code:


Class Profiler

    Sub Constructor(name as String)
  
        ' This should only be executed in debug mode
        #if DebugBuild

            ' First create the indent string, this will save time later on
            mIndent=""
  
            Dim Index As Integer=0
            While Index<mDepth
                mIndent=mIndent+"    "
                Index=Index+1
            Wend
  
            ' Store the name of the method
            mName = name
  
            ' Increase the indent depth for the next instance
            mDepth=mDepth+1
  
            ' Display the 'Entered" method
            System.DebugLog mIndent + "<"+name+"> Entered"
  
            ' Store off the time the constructor finished creation.
            ' We do this at the end of the constructor so that the rest of the 
            ' constructor has minimal impact on the time calculations
            mStart=Microseconds

        #EndIf

    End Sub

    Sub Destructor()
        
        ' This should only be executed in debug mode
        #if DebugBuild

            'Calculate the time the methhod took to execute
            'This is done straight away for a more accurate value
            Dim ExecTime As Double=Microseconds-mStart
  
            'Display the "Exited" message and the execution time of the method
            System.DebugLog mIndent + "<"+mName+"> Exited"
            System.DebugLog mIndent + "<"+mName+"> Execution Time = " + Str(ExecTime) + " Micro Seconds"
  
            'Reduce the indent depth for the next instance
            mDepth=mDepth-1
        
        #Endif

    End Sub

    Private mIndent As String
    Private mName As String
    Private mStart As Double

    Private Shared mDepth As Integer

End Class


To use this class to see how well your methods perform, all you need to do is place the following line at the beginning of the method you wish to test:

Dim p As New Profiler(MethodName)

Replace MethodName with the name of your method.

As the instance of the class is destroyed when it goes out of scope, there is not need to call manually call a destructor.

Now, whenever the method is executed, it will send entries to the system log.
On OS X, these can be viewed in the Console and should look something like this:


15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452] <BevelButton Action> Entered 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Entered 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Exited 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Execution Time = 12 Micro Seconds 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Entered 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Exited 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452]     <Test> Execution Time = 11 Micro Seconds 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452] <BevelButton Action> Exited 
15/05/2012 17:58:05 [0x0-0x91091].My Application.debug[4452] <BevelButton Action> Execution Time = 141 Micro Seconds 

Note, the method Test was called from within BevelButton Action, therefore, the log is indented automatically for readability.

As a little side note, I have used conditional compilation, so that the log entries are only generated if the application is executed from within the Real Studio IDE, this means that it would be safe to leave the calls in when deploying the application, however, it would be better if they were removed before release.

If you wish to download this class, I have made it available here.

Monday, 14 May 2012

Project Templates

A number of my Real Studio projects have required me to add things such as a Windows menu, for the open windows in a project, and a "Open Recent" menu.
Now while it isn't a bother to create these for each project, I began to think that there must be a better way to spend my time, rather than coding the same thing over and over.
Fortunately, Real Studio allows the use of project templates. In fact, any Real Studio user has already seen the project templates when they start up Real Studio. But what may not be apparent is that you can also add your own templates. It is a very simple process:


  1. Create your skeleton project
  2. Save it in the Project Templates folder within the Real Studio folder


And that is it.

What I have now done, is created some extra projects templates for some common scenarios I come across. I would also be possible to add things such as About windows, or even a skeleton Settings window. If you find yourself using the same custom controls repeatedly (like I do with my own NumberEdit control), then simply create a default project containing the controls and save it in the Templates folder.
I would, however, recommend not changing the existing projects. There may be a time when you need the bare bones that Real Studio offers you, but that is not a problem. As far as I can tell, the IDE will allow as many project templates as you would like.

Here is a quick shot of the Real Studio New Project window on my Mac to demonstrate this. I have highlighted my custom project templates: