Posts

Showing posts with the label programming

How to setup RustDT

Image
RustDT is the IDE for Rust. If you are a guy like me who need a IDE for learning language and developing efficiently, you must have a try on RustDT( https://github.com/RustDT/RustDT/blob/latest/documentation/UserGuide.md#user-guide ) Enable code complete. Here you go!

Designing a Component-based Architecture in Lua for Game Apps

http://www.raywenderlich.com/24878/introduction-to-component-based-architecture-in-games http://www.tomseysdavies.com/2011/01/23/entity-systems/ http://flohofwoe.blogspot.tw/2013/07/entity-component-system-revisited.html

Direct3D Drawing in WPF

In Windows8, you can use SurfaceImageSource, VirtualSurfaceImageSource, SwapChainBackgroundPanel to let DirectX content into a XAML app. Visual Studio 2010 has removed Microsoft.DirectX support, so if we wanna use D3D in WPF, we need to leverage SlimDX or SharpDX. However, when you use older Windows version, ex: Win7, WinXP, you only can adopt D3DImage. D3DImage Lock, unLock image, and copy backbuffer to this image. Direct3D to WPF from Ellis Mu You can download the sample code here: https://github.com/DaoshengMu/WPFd3dImageCpp http://www.gamedev.net/topic/619534-wpf-directx-11-via-d3dimage/ http://www.notesonsoftware.com/directx/initializing-directx-9-drawing-in-wpf/ http://code4k.blogspot.tw/2011/03/benchmarking-cnet-direct3d-11-apis-vs.html http://www.codeproject.com/Articles/28526/Introduction-to-D3DImage http://social.msdn.microsoft.com/forums/en-US/wpf/thread/22a83db9-e903-49a5-815b-0647f157bda6 http://www.codeproject.com/Articles/351939/SurfaceI...

Friend fumction in C++ class

// in the header file void changeVar(); // define it. class testFriend { friend void changeVar(); // declare it private: int m_i; } // in the cpp file void changeVar( testFriend&i ) // implement it { i.m_i++; } // in the main file int main() { testFriend test; changeVar(test); }

Local static variable destruction

Local static variable dead time can't be confirmed. So we should avoid to use other local static variable at the destructor. Static variables are allocated at stack and follow FILO rule. If you generate static A before static B, and A use B's attribute in A's destructor, finally A will crash in the deconstruction time, because B has dreaded... Remember!! Stack is FILO.

c++ error: operator []: overloads have similar conversions

template <class Type> class Array {     Type&       operator[] ( unsigned int index ); } Array <int> a1; a1.pushback(10); a1.pushback(20); int g = a1[1]; c++ error: operator []:  3 overloads have similar conversions Because the compiler can't determine "1" is int, const int, or unsigned int in the implicit conversion rule. We need to cast it to unsigned int, let the compiler knows what we like to do. sol:      int g = a1[static_cast<unsigned int> (1)]; Reference: http://stackoverflow.com/questions/1726740/c-error-operator-2-overloads-have-similar-conversions

The relative order of initialization of non-local static objects

Refer to Effective C++ 3rd item 4. The Relative order of initialization of non-local static objects defined in different translation units is undefined. main.cpp -------------------------- testVar var; int _tmain(int argc, _TCHAR* argv[]) {      int t[16];         memcpy( t, var.getVar(), 16 * sizeof(int) );     return 0; } The t will be set [ 0, 0, 0,...... ]. It is wrong, I have set the t to g_identity. I must occur the relative order problem.  Below is the original source code. testVar.h -------------------------- template class testVar { private:     Type var[16];     static const testVar g_identity; }; testVar.inl ----------------------- template const testVar testVar ::g_identity( 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 ); template testVar ::testVar() {     setIdentity(); } template void testVar ::setIdentity() {  ...

Java Calendar.Month return month

Java... Calendar.Month. Today is in May, but It return 4. I found it defined one year is 0~11... so I need to plus 1...

Concern about _itoa()

char *c1; int lens = 8; c1 = (char *)malloc( lens * sizeof(char) ); for ( int i = 0; i < lens; i++ ) {     _itoa( i, &c1[i], 10 ); } free( c1 ); Above things perhaps  is right. Howerver, it will crash at free( c1 ). It says there is a heap overflow problem. Because _itoa at the same time set ASCII at index item and set the index+1 item to '\0', it will access the c1[lens] item....Therefore, that occurs crash.

Rotate Point Around Vector

void RotatePointAroundVector(x#,y#,z#,u#,v#,w#,a#) { ux#=u*x uy#=u*y uz#=u*z vx#=v*x vy#=v*y vz#=v*z wx#=w*x wy#=w*y wz#=w*z sa#=Sin(a) ca#=Cos(a) x#=u*(ux+vy+wz)+(x*(v*v+w*w)-u*(vy+wz))*ca+(-wy+vz)*sa y#=v*(ux+vy+wz)+(y*(u*u+w*w)-v*(ux+wz))*ca+(wx-uz)*sa z#=w*(ux+vy+wz)+(z*(u*u+v*v)-w*(ux+vy))*ca+(-vx+uy)*sa } http://www.blitzbasic.com/Community/posts.php?topic=57616

Texture transform matrix

Texture matrix can be used to implement UV animation, we use the two vectors to transform the uv coordinate.  Finally, u' =  u dp2 uvTexMatRow[0,1] + uvTexMatRow[2];                                      v' =  v dp2 uvTexMatRow[4,5] + uvTexMatRow[6]; var halfRotRad:Number = MathExt.DegreeToRadian( rotUV * 0.5 );                         var Rz:Number = Math.sin( halfRotRad );             var Rw:Number = Math.cos( halfRotRad );                         var RwRz2:Number = 2 * Rw * Rz;             var RzRz2:Number = 2 * Rz * Rz;                 ...

Android Socket create

Today, I wrote a demo program to test Android connect with PC.  theSocket = new Socket("192.168.0.1", 4444); 1. IP address must use this server's IP which is connected to the network, can't use 127.0.0.1 2. Attention! You must add uses-permission on the AndroidManifest.xml, the type of permission is " android.permission.INTERNET"

Titanium iOS/Android cross platform memo

As possible as you can choose non-dependent interface on specific platform.  Be careful the include *.js path.  Localization file at the string.xml file. When you find some item name displayed have problem, you need to check the file first.

JavaScript language advanced Tips & Tricks

http://code.google.com/p/jslibs/wiki/JavascriptTips#Singleton_pattern Java script singleton: http://www.hardcode.nl/subcategory_1/article_526-singleton-examples-in-javascript.htm var Setting =(function(){     var instantiated;     function init (){         // all singleton code goes here         return {             publicWhatever:function(){                 alert('whatever')             },             userID:null,                        setUserID:function( id ) {                 userID = id;             ...

Write data to file in Titanium

var configDir = Titanium.Filesystem.getFile( Titanium.Filesystem.applicationDataDirectory, "dirPath" );             if ( configDir.exists() ) {          configDir.createDirectory();      } var config = Titanium.Filesystem.getFile( configDir.resolve(), "fileName" );             if ( config.write( writeSettingToConfig( userID ) ) == false )     {         // handle write error         var error;     }     config = null;     configDir = null;

Using Quaternion to Perform 3D rotations

Using Quaternion to Perform 3D rotations: http://www.cprogramming.com/tutorial/3d/quaternions.html

Adobe AIR on mobile platform

Today I port my Flash Player version 3D engine to Adobe AIR, in order to support Android/iOS platform. Because my engine has been done on the PC/Web, so we can't aware performance penalty easily, now I forward to mobile platform, they have limit resource. We need to more optimize our engine. Because iOS version has been convert AS3 to native code, so I believe and found game loop and render loop are not the critical part. The GPU processing part is the issue. We have done several things, I list them on the bottom: ( improving the fps from 4 to 26 ) Resize our texture size, smaller is better. Reduce redundant shader instruction, especially pixel part. We remove the fog and alpha-test part ( for supporting alpha-test, we use 'kil' - it's very evil ) Disable lighting and shadow map. Currently, event-listener is not the issue. Continuing we want to try disable mipmap, it may help us improve current performance. OpenGL ES Programming Guide for iOS: http://developer...

Some articles about AS3 optimization

http://jacksondunstan.com/articles/270 http://jacksondunstan.com/articles/433

Macros for Build Commands and Properties in MVS

http://msdn.microsoft.com/en-us/library/c02as0cs%28v=VS.90%29.aspx

JNI keyboard hook

    If you want your JNI program process with your native dll's keyboard I/O, you must implement keyboard hook function.     http://www.jotschi.de/?p=90     http://www.codingforums.com/showthread.php?t=147913