D:/Programming/GUI Editor (Source)/stdafx.cpp
00001
00002
00003
00004
00005 #include "stdafx.h"
00006 #include <direct.h>
00007
00008 static int rgiState[2+55];
00009
00010 int Random()
00011 {
00012 int *piState;
00013 int iState1;
00014 int iState2;
00015 int iRand;
00016 piState = &rgiState[2];
00017 iState1 = piState[-2];
00018 iState2 = piState[-1];
00019 iRand = ( piState[iState1] + piState[iState2] )
00020 & ( ( 1 << 30 ) - 1 );
00021 piState[iState1] = iRand;
00022
00023 if ( ++iState1 == 55 )
00024 iState1 = 0;
00025
00026 if ( ++iState2 == 55 )
00027 iState2 = 0;
00028
00029 piState[-2] = iState1;
00030 piState[-1] = iState2;
00031
00032 return iRand >> 6;
00033 }
00034
00035
00036
00037 int Random(int from, int to)
00038 {
00039 seed();
00040 int power;
00041 int number;
00042
00043 if ( ( to = to - from + 1 ) <= 1 )
00044 return from;
00045
00046 for ( power = 2; power < to; power <<= 1 )
00047 ;
00048 while ( ( number = Random( ) & ( power - 1 ) ) >= to )
00049 ;
00050 return from + number;
00051 }
00052
00053
00054
00055
00056
00057 void seed()
00058 {
00059 int *piState;
00060 int iState;
00061 piState = &rgiState[2];
00062 piState[-2] = 55 - 55;
00063 piState[-1] = 55 - 24;
00064 piState[0] = ( (int) time( NULL ) ) & ( ( 1 << 30 ) - 1 );
00065 piState[1] = 1;
00066 for ( iState = 2; iState < 55; iState++ )
00067 {
00068 piState[iState] = ( piState[iState-1] + piState[iState-2] )
00069 & ( ( 1 << 30 ) - 1 );
00070 }
00071 return;
00072 }
00073
00074 CString GetAppPath()
00075 {
00076 char Buf[512];
00077 ::GetModuleFileName(0, Buf, 512);
00078
00079 CString AppPath = CString(Buf);
00080 AppPath.Replace("\\", "/");
00081
00082 AppPath.MakeLower();
00083
00084 #ifdef _DEBUG
00085 AppPath.Replace("/debug", "");
00086 #endif
00087
00088 #ifdef _RELEASE
00089 AppPath.Replace("/release", "");
00090 #endif
00091
00092 CString ExeName;
00093 ExeName.Format("%s%s%s", "/", AfxGetApp()->m_pszExeName, ".exe");
00094 AppPath.Replace(ExeName.MakeLower(), "/");
00095
00096 return AppPath;
00097 }
00098
00099 CString GetFullPath(CString PathRel)
00100 {
00101 CString AppPath = GetAppPath();
00102
00103 AppPath.MakeLower();
00104 PathRel.MakeLower();
00105
00106 PathRel.Replace("\\", "/");
00107 int iRetValue = PathRel.Find(AppPath);
00108
00109 if(iRetValue == 0)
00110 return PathRel;
00111 else
00112 return CString(AppPath + PathRel);
00113 }
00114
00115 CString GetRelPath(CString FullPath)
00116 {
00117 FullPath.Replace("\\", "/");
00118 FullPath.MakeLower();
00119
00120 CString AppPath = GetAppPath();
00121 AppPath.MakeLower();
00122
00123 FullPath.Replace(AppPath, "");
00124
00125 return FullPath;
00126 }
Generated on Sun Jul 17 21:34:28 2005 for OpenGL GUI by
1.3.8