2010年5月22日 星期六

[IPhone] CloudBox


To the IPhone game development, I created my own game engine.
To the engine, I study design patterns, OOAD, IPhone SDK, cocos2d, CCGameBox and very much iphone sample.
This engine named CloudBox. I will use it to created my first IPhone game.
Reference my article for the Xcode template.
I created a template in Xcode project template, and a file template (See this pictures).
So at the next time, I can use CloudBox to
reduce the development effort.
Although the game is not yet complete, but the harvest was quite large.

2010年5月20日 星期四

[XCode] How to create a Xcode project template



Xcode project templates

From IPhone Dev FAQ

(Redirected from Xcode Project Template)
Jump to: navigation, search

To make your own Xcode Project Template for iPhone development follow these steps:

  1. Open a new finder window and navigate to ~/Library/Application Support/Developer/Shared/Xcode/ (note the ~)
  2. Create a new directory in here called Project Templates/
  3. Go into the newly created Project Templates/ directory and create a directory for the group your templates will appear in within the new project dialog in Xcode. In this example we will use MyApplication.
  4. Open a new finder window and navigate to /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/Application
  5. Copy one of the project templates (the one that best meets your needs) from here to the MyApplication directory we just created.
  6. Rename the copied project template directory to the name you want your template to be called.
  7. Go into this directory and you'll find an Xcode project called ___PROJECTNAME___.xcodeproj - Open this project like any normal project and edit it to how you want your newly created projects made from this template to be. You can use ___PROJECTNAME___ in files and directory names and in code and it will be replaced with the project name. ___PROJECTNAMEASIDENTIFIER___ can be used for code where you don't want spaces or other characters.
  8. After setting up your project template how you like, make sure it builds and then go and delete the build directory from the template directory because you don't want it to create that in new projects. Inside the ___PROJECTNAME___.xcodeproj directory you should also delete the username.* files (where username is your username), these contain things like window state and open files information from the last time you edited the project. If you ever edit your template later on, you'll need to delete these files again.
  9. Finally, change the description of your template in the ___PROJECTNAME___.xcodeproj/TemplateInfo.plist file and optionally change the icons file ___PROJECTNAME___.xcodeproj/TemplateIcon.icns. Search the web for how to edit .icns files, that's not covered here.

You can even add your project template to SVN and Xcode won't copy the .svn directories when it creates a new project. This can make it easy to merge useful changes from projects back into your template.

reference from http://www.iphonedevfaq.com/index.php?title=Xcode_Project_Template

I try to create my project template for my game develop toolkit CloudBox.

This is a very interesting experience.

In my experience,if file name set to ___PROJECTNAMEASIDENTIFIER___ , we must set file property is Relative to Project.

If file is our toolkit, we must set file property is Relative to Enclosing Group.


2010年5月4日 星期二

[.NETCF] How to declare memory-mapped file API with C# in WinCE

public class WinCEConst
{
public const UInt32 STANDARD_RIGHTS_REQUIRED = 0x000F0000;
public const UInt32 SECTION_QUERY = 0x0001;
public const UInt32 SECTION_MAP_WRITE = 0x0002;
public const UInt32 SECTION_MAP_READ = 0x0004;
public const UInt32 SECTION_MAP_EXECUTE = 0x0008;
public const UInt32 SECTION_EXTEND_SIZE = 0x0010;
public const UInt32 SECTION_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED SECTION_QUERY|
SECTION_MAP_WRITE|
SECTION_MAP_READ|
SECTION_MAP_EXECUTE|
SECTION_EXTEND_SIZE);
public const UInt32 FILE_MAP_ALL_ACCESS = SECTION_ALL_ACCESS;

public static IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);

public const int PAGE_READWRITE = 0x04;
public const int PAGE_READONLY = 0x02;
public const int FILE_MAP_READ = 0x0004;
public const int FILE_MAP_WRITE = 0x0002;
}

public class WinCE
{
// * WinCE using coredll.dll
// * Windows using keneral32.dll

[DllImport("Coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr CreateFileMapping(
IntPtr hFile,
object lpFileMappingAttributes,
uint flProtect,
uint dwMaximumSizeHigh,
uint dwMaximumSizeLow,
string lpName);

public static IntPtr OpenFileMapping(uint dwDesiredAccess, bool bInheritHandle, string lpName)
{
IntPtr t_pHandle = CreateFileMapping(new IntPtr(-1), null,
WinCEConst.PAGE_READWRITE, 0, 0, lpName);
return t_pHandle;
}

[DllImport("Coredll.dll", SetLastError = true)]
public static extern bool CloseHandle(IntPtr hObject);

[DllImport("Coredll.dll", SetLastError = true)]
public static extern IntPtr MapViewOfFile(
IntPtr hFileMappingObject,
uint dwDesiredAccess,
uint dwFileOffsetHigh,
uint dwFileOffsetLow,
uint dwNumberOfBytesToMap);

[DllImport("Coredll.dll", SetLastError = true)]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
}


If we want to communicate information at different process , we can use memory-mapped file.

If we want to use memory-mapped file in C#, we must use DllImport to declare API.

Memory-mapped files (MMFs) offer a unique memory management feature that allows applications to access files on disk in the same way they access dynamic memory—through pointers. With this capability you can map a view of all or part of a file on disk to a specific range of addresses within your process's address space. And once that is done, accessing the content of a memory-mapped file is as simple as dereferencing a pointer in the designated range of addresses.

You can see the reference for Win32 on MSDN.

2010年5月3日 星期一

[.NET] Transform single color background to transparent background



In order to develop IPhone game, I wnat to try Game Sprite function.
But IPhone UIImageView was not support transparent background function.
My picture is BMP type and had a single color background,previously can use DirectX SDK to reach transparent background.
So I develop a function to transform BMP to PNG file to reach transparent background.

[.NET]How to get file version with .NET

If you want to get file version in AssemblyInfo file.
You must use this code.

string version =
FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion.ToString();

this code must using these namespace.

using System.Reflection;
using System.Diagnostics;

2010年5月2日 星期日

[.NETCF]GetCurrentDirectory with C# in WinCE

In windows applcation we can use

String path = Directory.GetCurrentDirectory();



to get current directory.

but in WinCE .NET CF2.0 is not support GetCurrentDirectory

so we can do it.

String path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

[IPhone]How to develop iphone with C++

Introduction
When I got a game project for IPhone from TS, I will study how to develop IPhone game.
But I have no experience for the Object-C, so I try to use C++ to implement IPhone game.
I found Xcode can compile C++ with IPhone SDK, the solution is change the source code's extend file name.

Solution

If you have Test.h and Test.m file. Rename Test.m to Test.mm to implement C++.

[.NETCF]How to setting Send/Receive buffer with .NET Socket

Introduction
When implement a TCP/IP program with socket, generally we need to send some long data,
but design a message format is miscellaneous behavior.
So I try to modify Send/Receive buffer size to solve it.

Background
When I implement socket program with M$ .NET Framework, I found that only need to modify Socket property to solve it.
But in my job, I will implement this function in WinCE system with .NET Compact Framework.
And the .NETCF socket has not Send/Receive buffer size property, so I need anthoer solution to implement it.

Solution
In Windows .Net, we can use propery to set.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
s.SendBufferSize = 102400;
s.ReceiveBufferSize = 102400;
(Default value is 8192)

but .NET CF2.0 has not SendBufferSize/ReceiveBufferSize property.
so we can do this

s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReceiveBuffer, 102400);
s.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.SendBuffer, 102400);