#include #include #include #include #include "StringHelper.h" #include "TextFileReader.h" HANDLE g_FileChangeNotification= NULL; void StopFileWatch() { if (g_FileChangeNotification != INVALID_HANDLE_VALUE && g_FileChangeNotification != NULL) { FindCloseChangeNotification(g_FileChangeNotification); } g_FileChangeNotification= NULL; } void StartFileWatch() { StopFileWatch(); std::string strPath= ".\\cfg\\"; g_FileChangeNotification= FindFirstChangeNotification( strPath.c_str(), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE ); } void ReadDataFromDisc(); bool CheckFileWatch() { if (g_FileChangeNotification == INVALID_HANDLE_VALUE || g_FileChangeNotification == NULL) { return false; } DWORD dwRet= WaitForSingleObject( g_FileChangeNotification, 1 ); if( WAIT_OBJECT_0 == dwRet ) { FindNextChangeNotification( g_FileChangeNotification ); ReadDataFromDisc(); return true; } return false; } void WriteHeader(); int g_iCurSpriptLength; int g_iCurSpriptParams; void ReadScriptTxt() { g_iCurSpriptLength= 0; g_iCurSpriptParams= 0; FrameWork::TextFileReader tfrScript; tfrScript.read( "cfg/script.txt" ); //#ifdef SCRIPTEDITOR for( int i= 0; i < (int)tfrScript.getFileLines().size(); ++i ) { std::string strAct= tfrScript.getFileLines()[ i ]; std::string strCommandFull; if( FrameWork::StringHelper::splitAt( strAct, "=", strCommandFull ) ) { } std::stringstream ss; ss << strAct; if( strCommandFull == "SKIP" ) { #ifdef SCRIPTEDITOR ss >> g_iSkipTicks; #endif } if( strCommandFull == "CLEAN" ) { g_iCurSpriptLength= 0; g_iCurSpriptParams= 0; } else if( strCommandFull == "CSPEED" ) { g_Script[ g_iCurSpriptLength++ ]= CSPEED; ss >> g_ScriptParamFloat[ g_iCurSpriptParams++ ]; } else if( strCommandFull == "OSPEED" ) { g_Script[ g_iCurSpriptLength++ ]= OSPEED; ss >> g_ScriptParamFloat[ g_iCurSpriptParams++ ]; } else if( strCommandFull == "CTIME" ) { g_Script[ g_iCurSpriptLength++ ]= CTIME; ss >> g_ScriptParamFloat[ g_iCurSpriptParams++ ]; } else if( strCommandFull == "OTIME" ) { g_Script[ g_iCurSpriptLength++ ]= OTIME; ss >> g_ScriptParamFloat[ g_iCurSpriptParams++ ]; } else if( strCommandFull == "CAM" ) { g_Script[ g_iCurSpriptLength++ ]= CAM; int iVal= 0; ss >> iVal; g_Script[ g_iCurSpriptLength++ ]= iVal; } else if( strCommandFull == "CAM" ) { g_Script[ g_iCurSpriptLength++ ]= CAM; int iVal= 0; ss >> iVal; g_Script[ g_iCurSpriptLength++ ]= iVal; } else if( strCommandFull == "OBJ" ) { g_Script[ g_iCurSpriptLength++ ]= OBJ; int iVal= 0; ss >> iVal; g_Script[ g_iCurSpriptLength++ ]= iVal; iVal= 0; ss >> iVal; g_Script[ g_iCurSpriptLength++ ]= iVal; } else if( strCommandFull == "TICK" ) { g_Script[ g_iCurSpriptLength++ ]= TICK; int iVal= 0; ss >> iVal; g_Script[ g_iCurSpriptLength++ ]= iVal; } else if( strCommandFull == "QUIT" ) { g_Script[ g_iCurSpriptLength++ ]= QUIT; } } //#endif } void ReadParamTxt() { FrameWork::TextFileReader tfrSong; tfrSong.read( "cfg/param.txt" ); tfrSong.append( "cfg/port.txt" ); tfrSong.append( "cfg/cam.txt" ); // tfrSong.append( "cfg/script.txt" ); for( int i= 0; i < (int)tfrSong.getFileLines().size(); ++i ) { std::string strAct= tfrSong.getFileLines()[ i ]; std::string strCommandFull; if( FrameWork::StringHelper::splitAt( strAct, "=", strCommandFull ) ) { } std::stringstream ss; ss << strAct; #ifdef SINGLEEDITMODE if( strCommandFull == "PCUR" ) { ss >> g_iCurrentPortrait; } else if( strCommandFull == "OCUR" ) { ss >> g_iCurrentObject; } else if( strCommandFull == "OCOUNT" ) { ss >> g_iCurrentObjectCount; } else if( strCommandFull == "CCUR" ) { ss >> g_iCurrentCamera; } #endif if( strCommandFull.size() < 4 ) { continue; } int iFunc= strCommandFull[ strCommandFull.size() - 1 ] - '0'; iFunc+= 10 * ( strCommandFull[ strCommandFull.size() - 2 ] - '0' ); iFunc+= 100 * ( strCommandFull[ strCommandFull.size() - 3 ] - '0' ); std::string strCommand; strCommand= strCommandFull.substr( 0, strCommandFull.size() - 3 ); if( strCommand == "BANK" ) { for( int j= 0; j < 4; ++j ) { float fVal= 0.0f; ss >> fVal; int iVal= (int)( fVal * 64.0f + 0.5f ); fVal= (float)( iVal ) / 64.0f; SetParamValue( iFunc, j, fVal ); } } else if( strCommand == "SIZE" ) { ss >> g_ObjectData[ iFunc ].m_iSizeX; ss >> g_ObjectData[ iFunc ].m_iSizeY; } else if( strCommand == "BASE" ) { ss >> g_ObjectData[ iFunc ].m_iBaseMeshType; ss >> g_ObjectData[ iFunc ].m_iBaseBank; } else if( strCommand == "OFFSET" ) { ss >> g_ObjectData[ iFunc ].m_iOffsetFunc; ss >> g_ObjectData[ iFunc ].m_iOffsetBank; } else if( strCommand == "HEIGHT" ) { ss >> g_ObjectData[ iFunc ].m_iHeightFunc; ss >> g_ObjectData[ iFunc ]. m_iHeightBank; } else if( strCommand == "MIX" ) { ss >> g_ObjectData[ iFunc ].m_iMixFunc; ss >> g_ObjectData[ iFunc ].m_iMixBank; } else if( strCommand == "TRANS" ) { ss >> g_ObjectData[ iFunc ].m_iTransformFunc; ss >> g_ObjectData[ iFunc ].m_iTransformBank; } else if( strCommand == "COLOR" ) { float fR; float fG; float fB; float fA; ss >> fR; ss >> fG; ss >> fB; ss >> fA; fR= min( 255.0f, fR ); fG= min( 255.0f, fG ); fB= min( 255.0f, fB ); fA= min( 255.0f, fA ); DWORD dwColor= ( (int)fR << 16 ) | ( (int)fG << 8 ) | ( (int)fB ); g_ObjectData[ iFunc ].m_dwColor= dwColor; } else if( strCommand == "PSCALE" ) { ss >> g_PortraitData[ iFunc ].m_iScale; } else if( strCommand == "PPOS" ) { ss >> g_PortraitData[ iFunc ].m_iPosX; ss >> g_PortraitData[ iFunc ].m_iPosY; ss >> g_PortraitData[ iFunc ].m_iTextPosX; ss >> g_PortraitData[ iFunc ].m_iTextPosY; } else if( strCommand == "PTEX" ) { ss >> g_PortraitData[ iFunc ].m_iTextureID; } else if( strCommand == "PWORD" ) { std::string strText( strAct ); FrameWork::StringHelper::searchAndRreplace( "
", "\n", strText ); strcpy_s( g_PortraitData[ iFunc ].m_pcText, strText.c_str() ); } else if( strCommand == "PTICK" ) { ss >> g_PortraitData[ iFunc ].m_iTicks; } else if( strCommand == "CTYPE" ) { ss >> g_CameraData[ iFunc ].m_iType; ss >> g_CameraData[ iFunc ].m_iBaseBank; ss >> g_CameraData[ iFunc ].m_fFov; } else if( strCommand == "CCOLOR" ) { float fR; float fG; float fB; float fA; ss >> fR; ss >> fG; ss >> fB; ss >> fA; fR= min( 255.0f, fR ); fG= min( 255.0f, fG ); fB= min( 255.0f, fB ); DWORD dwColor= ( (int)fR << 16 ) | ( (int)fG << 8 ) | ( (int)fB ); g_CameraData[ iFunc ].m_dwColor= dwColor; fA= max( 1.0f, fA ); g_CameraData[ iFunc ].m_fFog= 1.0f / fA; } #ifdef SINGLEFUNCEDITOR /*if( strCommand == "DRAW" ) { ss >> g_iCamFunc; ss >> g_iPaintFunc[ 0 ]; ss >> g_iPaintFunc[ 1 ]; } if( strCommand == "CAMREPEAT" ) { ss >> g_iCamRepeat; }*/ #endif } } void ReadDataFromDisc() { ReadParamTxt(); ReadScriptTxt(); static bool bWritten= false; if( bWritten ) { return; } WriteHeader(); } void WriteHeaderFunc() { std::ofstream ofs( "globaldata.h" ); ofs << "const float FloatParamBanks[ 4 * 512 ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < 4 * 512; ++i ) { char pcSpecial[ 1024 ]; sprintf_s( pcSpecial, 1024, "%1.9ff,\n", FloatParamBanks[ i ] ); ofs << pcSpecial; } ofs << "};" << "\n"; ofs << "\n"; { int iBytes= sizeof( g_CameraData ); ofs << "const unsigned char byteCameraData[ " << iBytes <<" ]=" << "\n"; ofs << "{" << "\n"; int iLine= 0; for( int i= 0; i < iBytes; ++i ) { ofs << (int)(((unsigned char*)g_CameraData)[ i ]) << ","; iLine++; if( iLine == 8 ) { ofs << "\n"; iLine= 0; } } ofs << "\n" << "};" << "\n"; ofs << "SCameraDescription* g_CameraData= (SCameraDescription*)byteCameraData;\n\n"; } { int iBytes= sizeof( g_ObjectData ); ofs << "const unsigned char byteObjectData[ " << iBytes <<" ]=" << "\n"; ofs << "{" << "\n"; int iLine= 0; for( int i= 0; i < iBytes; ++i ) { ofs << (int)(((unsigned char*)g_ObjectData)[ i ]) << ","; iLine++; if( iLine == 8 ) { ofs << "\n"; iLine= 0; } } ofs << "\n" << "};" << "\n"; ofs << "SObjectDescription* g_ObjectData= (SObjectDescription*)byteObjectData;\n\n"; } { int iBytes= sizeof( g_PortraitData ); ofs << "const unsigned char bytePortraitData[ " << iBytes <<" ]=" << "\n"; ofs << "{" << "\n"; int iLine= 0; for( int i= 0; i < iBytes; ++i ) { ofs << (int)(((unsigned char*)g_PortraitData)[ i ]) << ","; iLine++; if( iLine == 8 ) { ofs << "\n"; iLine= 0; } } ofs << "\n" << "};" << "\n"; ofs << "SPortraitDescription* g_PortraitData= (SPortraitDescription*)bytePortraitData;\n\n"; } /* ofs << "const int g_iFuncCount= " << g_iFuncCountWrite << ";\n"; ofs << "const int g_iFuncType[ g_iFuncCount ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < g_iFuncCountWrite; ++i ) { ofs << g_iFuncType[ i ] << "," << "\n"; } ofs << "};" << "\n"; ofs << "\n"; ofs << "const DWORD g_dwFuncColor[ 32 ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < 32; ++i ) { ofs << g_dwFuncColor[ i ] << "," << "\n"; } ofs << "};" << "\n"; ofs << "\n"; ofs << "const int g_iRanges[ 32 ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < 32; ++i ) { ofs << g_iRanges[ i ] << "," << "\n"; } ofs << "};" << "\n"; ofs << "\n"; ofs << "const int g_iDrawObj[ 16 ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < 16; ++i ) { ofs << g_iDrawObj[ i ] << "," << "\n"; } ofs << "};" << "\n"; ofs << "\n"; ofs << "const float g_fParameter[ g_iParamCount * g_iFuncCount ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < g_iParamCount; ++i ) { for( int j= 0; j < g_iFuncCountWrite; ++j ) { char pcSpecial[ 1024 ]; sprintf_s( pcSpecial, 1024, "%1.9ff,\n", g_fParameter[ j + g_iFuncCount * i] ); ofs << pcSpecial; } } ofs << "};" << "\n"; ofs << "\n"; */ } void WriteHeaderScript() { std::ofstream ofs( "scriptdata.h" ); ofs << "const int g_iScriptLength= " << g_iCurSpriptLength << ";\n"; ofs << "const unsigned char g_Script[ g_iScriptLength ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < g_iCurSpriptLength; ++i ) { ofs << (int)g_Script[ i ] << ",\n"; } ofs << "};" << "\n"; ofs << "const float g_ScriptParamFloat[ " << g_iCurSpriptParams << " ]=" << "\n"; ofs << "{" << "\n"; for( int i= 0; i < g_iCurSpriptParams; ++i ) { char pcSpecial[ 1024 ]; sprintf_s( pcSpecial, 1024, "%1.9ff,\n", g_ScriptParamFloat[ i ] ); ofs << pcSpecial; } ofs << "};" << "\n"; ofs << "\n"; ofs << "\n"; } void WriteHeader() { //#ifdef SINGLEEDITMODE WriteHeaderFunc(); //#endif //#ifdef SCRIPTEDITOR WriteHeaderScript(); //#endif }