bool CScriptEngine::LoadScriptString(const char* code, const char* moduleName, const char* sectionName) { assert(code && *code); asIScriptModule *mod = m_vm->GetModule(moduleName, asGM_ALWAYS_CREATE); int r = mod->AddScriptSection(sectionName, code); if( r < 0 ) { CON(MSG_ERR, _W("AddScriptSection() failed!") ); return false; } // Compile the script. If there are any compiler messages they will // be written to the message stream that we set right after creating the // script engine. If there are no errors, and no warnings, nothing will // be written to the stream. r = mod->Build(); if( r < 0 ) { CON(MSG_ERR, _W("Script build failed!") ); return false; } CDebugBinStream bs( _W("compiled_script.txt"), true ); mod->SaveByteCode( &bs ); return true; }
uint8_t command_handle (const char *input, char *expandedtext, uint8_t show_ambiguous, uint8_t show_complete, uint8_t execute_command, void *context) { int32_t matches; if (expandedtext) { *expandedtext = '\0'; } /* * Check for ambiguous commands. */ matches = command_matches(input, expandedtext, false, false, execute_command, context); if (matches == 0) { CON("> %%%%fg=red$Unknown command: \"%s\"%%%%fg=reset$", input); return (false); } if (matches > 1) { if (show_ambiguous) { CON("> %%%%fg=red$Incomplete command, " "\"%s\"%%%%fg=reset$. Try:", input); } command_matches(input, expandedtext, show_ambiguous, show_complete, execute_command, context); if (!show_ambiguous) { if (expandedtext) { if (!strcasecmp(input, expandedtext)) { CON("> %%%%fg=red$Incomplete command, " "\"%s\"%%%%fg=reset$. Try:", input); command_matches(input, expandedtext, true, show_complete, execute_command, context); } } else { command_matches(input, expandedtext, true, show_complete, execute_command, context); } } return (false); } if (!execute_command && (matches == 1)) { CON("> %%%%fg=red$Incomplete command, " "\"%s\"%%%%fg=reset$. Try:", input); command_matches(input, expandedtext, true, show_complete, execute_command, context); } return (true); }
//--------------------------------------------------------------------------- bool CFS_Sqlite::Initialize(void* pEngine) { int ret=0; CON(MSG_INFO, _W("Database filesystem sqlite %s:"), _A2W(sqlite3_version) ); if (!sqlite3_threadsafe()) { CON(MSG_ERR, _W("... not compiled thread-safe - will not be used!")); return false; } CON(MSG_INFO, _W("... setting multithread configuration")); sqlite3_config(SQLITE_CONFIG_MULTITHREAD); ret = sqlite3_initialize(); if (ret == SQLITE_OK) CON(MSG_INFO, _W("... successfuly initialized")); else { CON(MSG_ERR, _W("... error code %d returned - will not be used!"), ret); return false; } return true; }
bool CScriptEngine::LoadScript( const wchar * path ) { IFileSystem* fs = CEngine::instance()->mFilesystem(); CON(MSG_INFO, _W("ScriptEngine: Loading script file %s"), path); // load using FS BYTE* pData=NULL; unsigned long fSize=0; FSFILE* fp = fs->Load(path, pData, fSize, true); if (!fp) { CON(MSG_ERR, _W("Faile to open script file %s!"), path); return false; } if (!LoadScriptString( (const char*)pData, 0, _W2A(path) )) { CON(MSG_ERR, _W("Error loading %s script!"), path ); fs->UnLoad(fp, pData); return false; } fs->UnLoad(fp, pData); return true; }
bool CScriptEngine::Initialize() { // register custom memory management //asSetGlobalMemoryFunctions() m_vm = asCreateScriptEngine(ANGELSCRIPT_VERSION); m_vm->SetEngineProperty(asEP_USE_CHARACTER_LITERALS, true); // treat 'a' as character literal of type uint8 if( m_vm == 0 ) { CON( MSG_ERR, _W("Failed to create script engine!") ); return false; } // set compiler message callback m_vm->SetMessageCallback(asFUNCTION(ScriptMessageCallback), 0, asCALL_CDECL); // write version info CON( MSG_INFO, _W(" AngelScript version %s successfuly initialized."), _A2W( asGetLibraryVersion() ) ); CON( MSG_INFO, _W(" Build flags: %s"), _A2W( asGetLibraryOptions() ) ); // register basic types RegisterBasicTypesToScript(m_vm); // Script UnitTest LoadScriptString(\ "void UnitTest()\n"\ "{\n"\ "Log(\"--- Script engine unit test ---\");\n"\ "\n"\ "Log( \"String comparison: \" + ( (\"str\"==\"str\") ? \"OK\" : \"ERROR\" ) );\n"\ "\n"\ "String float2str = 0.123f;\n"\ "Log(\"Float-to-String: \" + float2str);\n"\ "String strTrue = true; String strFalse = false;\n"\ "Log(\"Bool-to-String: \" + ( (strTrue == \"True\") && (strFalse == \"False\") ? \"OK\" : \"ERROR\" ) );\n"\ "Log(\"String index operator: \" + ( (\"str\"[2]=='r') ? \"OK\" : \"ERROR\") );\n"\ "Log(\"String length(): \" + ( (\"str\".length()==3) ? \"OK\" : \"ERROR\") );\n"\ "\n"\ "float f = 0.123f;\n"\ "float f2 = sin(f);\n"\ "Log(\"sin(\" + f + \") = \" + f2 );\n"\ "\n"\ "Log(\"rand(0.1f, 0.7f) = \" + rand(0.1f, 0.7f) );\n"\ "}\n"\ ,0,"UnitTestSection"); ExecuteString("UnitTest();"); return true; }
int main() { int i,n,j,a[CON(SIZE)+1]={0}; n=(int)ceil(sqrt(SIZE));n=CON(n); for(i=0;i<n;i++) { if(a[i]==0) for(j=CON2(i);j<CON(SIZE);j+=ICON(i)) a[j]=1; } j=0; for(i=0;i<=CON(SIZE);i++) if(a[i]==0) { prime[j]=ICON(i); j++; } int t,m,f; scanf("%d",&t); while(t--) { int b[100010]={0},s=0; scanf("%d%d",&m,&n); if(m<=2)printf("2\n"),m=3; if(m%2==0)m++; if(n%2==0)n--; f=(int)sqrt(n); for(i=0;i<3401;i++) { if(prime[i]>f)break; int start; if(m>=prime[i]) { start=m+prime[i]-m%prime[i]; if(start%2==0)start+=prime[i]; start-=m; if(m%prime[i]==0 &&m!=prime[i])start=0; } else start=prime[i]*prime[i]-m; for(j=CONN(start);j<=(n-m)/2;j+=prime[i]) b[j]=1; } for(i=0;i<=(n-m)/2;i++) if(b[i]==0) // s++; printf("%d\n",ICON2(i)+m); // printf("%d\n",s); printf("\n"); } return 0; }
bool DGLE_API CRender::_s_ConListFeatures(void *pParameter, const char *pcParam) { if (strlen(pcParam) != 0) { CON(CRender, "No parameters expected."); return false; } else { CON(CRender, PTHIS(CRender)->_strFeturesList.c_str()); CON(CRender, PTHIS(CRender)->_strMetricsList.c_str()); return true; } }
bool CDeviceWrapper::Create(unsigned int width, unsigned int height, bool fullscreen, void* handle) { CON(MSG_INFO, " ...creating DirectX device with backbuffer of %d x %d %s", width, height, fullscreen?"fullscreen":"windowed"); m_pD3d = Direct3DCreate9(D3D_SDK_VERSION); if(!m_pD3d) return false; m_pD3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &m_sMode); if(!fullscreen) { if(SUCCEEDED(m_pD3d->CheckDeviceType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_sMode.Format, m_sMode.Format, true))) { m_sD3dpp.Windowed = TRUE; m_sD3dpp.BackBufferFormat = m_sMode.Format; } else return false; } m_sD3dpp.SwapEffect = fullscreen ? D3DSWAPEFFECT_DISCARD : D3DSWAPEFFECT_COPY; m_sD3dpp.hDeviceWindow = (HWND)handle; m_sD3dpp.BackBufferWidth = width; m_sD3dpp.BackBufferHeight = height; m_sD3dpp.EnableAutoDepthStencil = TRUE; m_sD3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; m_sD3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_sD3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //maximum fps D3DCAPS9 caps; m_pD3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); DWORD vp; if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //TODO: pure device support m_pD3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, (HWND)handle, vp, &m_sD3dpp, &m_pD3ddev); if(!m_pD3ddev) return false; //TODO: multisampling support m_pD3ddev->CreateDepthStencilSurface(width, height, D3DFMT_D24S8, D3DMULTISAMPLE_NONE, 0, TRUE, &m_pZbuffer, NULL); if(!m_pZbuffer) return false; CON(MSG_INFO, " ...device sucessfuly created"); SetupD3D(); g_pD3ddev = m_pD3ddev; return true; }
// ---------------------------------------------------------------------- BaseObject* CObjectManager::CreateObject(const wchar* objectName) { EngineObjectReg* optr=g_first_obj; while(optr) { if ( !wstricmp(objectName, optr->ObjName) ) { optr->InstNum++; CON(MSG_INFO, _W("ObjectManager: Creating %s object (%d)."), objectName, optr->InstNum ); return (BaseObject*)optr->CreateFn(); } optr = optr->Next; } CON(MSG_ERR, _W("ObjectManager: Failed to create %s object! Object not found."), objectName ); return NULL; }
void DGLE2_API CHookedWindow::_s_ConsoleQuit(void *pParametr, const char *pcParam) { if (strlen(pcParam)!=0) CON(CHookedWindow, "No parametrs expected."); else ::SendMessage(PTHIS(CHookedWindow)->_hRootHWnd, WM_CLOSE, NULL, NULL); }
bool CP3DPhysCharacter::CreateCharacter(float fHeight, float fRadius, float fEyeOffset) { m_fHeight = fHeight; m_fRadius = fRadius; m_fEyeOffset = fEyeOffset; bLoaded = false; NxCapsuleControllerDesc desc; desc.height = m_fHeight - 2*m_fRadius - 15.0f; // - step offset desc.radius = m_fRadius; desc.slopeLimit = 0.7f; // asi v rad desc.stepOffset = 35.0f; desc.upDirection = NX_Y; desc.callback = &g_ControllerHitReport; m_pChar = (NxCapsuleController*)g_pCtrlMgr->createController(g_pScene, desc); int nmbShp = m_pChar->getActor()->getNbShapes(); NxShape *const * pShp = m_pChar->getActor()->getShapes(); for (int i=0;i<nmbShp;i++) pShp[i]->setGroup(PHYSGROUP_PLAYER); if(!m_pChar) { CON(MSG_CON_ERR, "Can't create capsule character controller!"); return false; } bLoaded = true; return true; }
// ----------------------------------------------------- bool CGraphicsRenderer::Initialize() { sTextureDesc desc; desc.ArraySize = 1; desc.AutoGenerateMips = false; desc.BindFlag = P3D_TEXBINDFLAG_RENDER_TARGET; desc.CPUAccess = P3D_CPUACCESS_NONE; desc.MipLevels = 1; desc.ResourceUsage = P3D_RESOURCEUSAGE_DEFAULT; //desc.Width = 1024; //desc.Height = 576; // TODO: sizes desc.Width = 400; desc.Height = 300; // Initialize Diffuse Render Target desc.Format = P3D_FORMAT_X8R8G8B8_UNORM; m_mrt_diffuse = CRenderer::cGraphicsManager()->CreateTexture(desc, NULL, 0); if (!m_mrt_diffuse) { CON(MSG_ERR_FATAL, _W("Failed to create diffuse RT!") ); return false; } // Initialize Normal Render Target desc.Format = P3D_FORMAT_R16G16_SNORM; m_mrt_normal = CRenderer::cGraphicsManager()->CreateTexture(desc, NULL, 0); if (!m_mrt_diffuse) { CON(MSG_ERR_FATAL, _W("Failed to create normal RT!") ); return false; } // Initialize Depth Render Target desc.Format = P3D_FORMAT_R32_FLOAT; m_mrt_depth = CRenderer::cGraphicsManager()->CreateTexture(desc, NULL, 0); if (!m_mrt_diffuse) { CON(MSG_ERR_FATAL, _W("Failed to create depth RT!") ); return false; } return true; }
// TODO: if clicking on error message is not working within VisualStudio, // make second version using #ifdef _DEBUG && MSVC with OutputDebugString // or remove : from the begining of line void ScriptMessageCallback(const asSMessageInfo *msg, void *param) { const wchar *type = _W("ERR "); if( msg->type == asMSGTYPE_WARNING ) type = _W("WARN"); else if( msg->type == asMSGTYPE_INFORMATION ) type = _W("INFO"); CON(MSG_INFO, _W(": %s (%d, %d) : %s : %s\n"), _A2W(msg->section), msg->row, msg->col, type, _A2W(msg->message) ); }
bool CShaderBufferHLSL::Create(const sShaderBufferDesc &desc, const void *data) { D3D10_BUFFER_DESC cbDesc; cbDesc.ByteWidth = desc.BufferSize; cbDesc.BindFlags = D3D10_BIND_CONSTANT_BUFFER; cbDesc.MiscFlags = 0; if(desc.ResourceUsage == P3D_RESOURCEUSAGE_IMMUTABLE) cbDesc.Usage = D3D10_USAGE_IMMUTABLE; else if(desc.ResourceUsage == P3D_RESOURCEUSAGE_DEFAULT)cbDesc.Usage = D3D10_USAGE_DEFAULT; else if(desc.ResourceUsage == P3D_RESOURCEUSAGE_DYNAMIC) { if(desc.CPUAccess != P3D_CPUACCESS_READ) cbDesc.Usage = D3D10_USAGE_DYNAMIC; else cbDesc.Usage = D3D10_USAGE_STAGING; } else { CON(MSG_ERR, _W("Shader buffer creation failed. No apropriate ResourceUsage given.")); return false; } if(desc.CPUAccess == P3D_CPUACCESS_NONE) cbDesc.CPUAccessFlags = 0; else if(desc.CPUAccess == P3D_CPUACCESS_READ) cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; else if(desc.CPUAccess == P3D_CPUACCESS_WRITE) cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; else if(desc.CPUAccess == P3D_CPUACCESS_READ_WRITE) cbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ || D3D10_CPU_ACCESS_WRITE; else { CON(MSG_ERR, _W("Shader buffer creation failed. No apropriate CPUAccess given.")); return false; } D3D10_SUBRESOURCE_DATA initData; initData.pSysMem = data; if(!CheckHRResult( g_pD3ddev->CreateBuffer( &cbDesc, data ? &initData : NULL, &m_pBuffer ) )) { CON(MSG_ERR, _W("Shader buffer creation failed.")); return false; } m_desc = desc; return true; }
bool CheckHRResult(HRESULT hr) { switch(hr) { case S_OK: return true; break; case D3D10_ERROR_FILE_NOT_FOUND: CON(MSG_ERR, _W("HRESULT: The file was not found.")); return false; break; case D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS: CON(MSG_ERR, _W("HRESULT: There are too many unique instances of a particular type of state object.")); return false; break; case D3DERR_INVALIDCALL: CON(MSG_ERR, _W("HRESULT: The method call is invalid. For example, a method's parameter may not be a valid pointer.")); return false; break; case D3DERR_WASSTILLDRAWING: CON(MSG_ERR, _W("HRESULT: The previous blit operation that is transferring information to or from this surface is incomplete.")); return false; break; case E_FAIL: CON(MSG_ERR, _W("HRESULT: Attempted to create a device with the debug layer enabled and the layer is not installed.")); return false; break; case E_INVALIDARG: CON(MSG_ERR, _W("HRESULT: An invalid parameter was passed to the returning function.")); return false; break; case E_OUTOFMEMORY: CON(MSG_ERR, _W("HRESULT: Direct3D could not allocate sufficient memory to complete the call.")); return false; break; case S_FALSE: CON(MSG_ERR, _W("HRESULT: Alternate success value, indicating a successful but nonstandard completion (the precise meaning depends on context).")); return true; break; default: CON(MSG_ERR, _W("HRESULT: Unknown HRESULT value.")); return false; } }
bool CSoundManager::Create(COALExtProvider* exts) { m_pListener = new CSoundListener(); m_extensions = exts; if(!m_pListener) { CON(MSG_ERR_FATAL, _W("Can't create listener instance!")); return false; } return m_pListener->Create(Vec3(),Vec3(0,0,-1)); }
bool DGLE_API CHookedWindow::_s_ConsoleQuit(void *pParameter, const char *pcParam) { if (strlen(pcParam) != 0) { CON(CHookedWindow, "No parameters expected."); return false; } else { ::SendMessage(PTHIS(CHookedWindow)->_hRootHWnd, WM_CLOSE, NULL, NULL); return true; } }
CSoundManager::~CSoundManager() { ClearAll(); if(m_pListener) { delete m_pListener; m_pListener = 0; CON(MSG_DBG, _W("Listener deleted...")); } m_extensions = 0; }
bool CShaderBufferCg::Create(const sShaderBufferDesc &desc, const void *data) { CGbufferusage usage; bool dynamic = false; if(desc.CPUAccess == P3D_CPUACCESS_NONE || desc.CPUAccess == P3D_CPUACCESS_WRITE) { if(desc.ResourceUsage == P3D_RESOURCEUSAGE_DYNAMIC) usage = CG_BUFFER_USAGE_DYNAMIC_DRAW; else usage = CG_BUFFER_USAGE_STATIC_DRAW; } else if(desc.CPUAccess == P3D_CPUACCESS_READ) { if(desc.ResourceUsage == P3D_RESOURCEUSAGE_DYNAMIC) usage = CG_BUFFER_USAGE_DYNAMIC_READ; else usage = CG_BUFFER_USAGE_STATIC_READ; } else if(desc.CPUAccess == P3D_CPUACCESS_READ_WRITE) { if(desc.ResourceUsage == P3D_RESOURCEUSAGE_DYNAMIC) usage = CG_BUFFER_USAGE_DYNAMIC_COPY; else usage = CG_BUFFER_USAGE_STATIC_COPY; } else { CON(MSG_ERR, _W("Shader buffer creation failed. No apropriate ResourceUsage given.")); return false; } m_buffer = cgCreateBuffer(*g_pcgcontext, desc.BufferSize, data, usage); if(!m_buffer) { CON(MSG_ERR, _W("Shader buffer creation failed.")); return false; } m_desc = desc; return true; }
/* * User has entered a command, run it */ static uint8_t server_players_show (tokens_t *tokens, void *context) { CON("Name Remote IP Local IP Quality"); CON("---- --------------- --------------- -------"); uint32_t pi; pi = 0; gsocketp s; TREE_WALK(sockets, s) { aplayer *p = socket_get_player(s); if (!p) { continue; } if (!p->stats_from_client.pname[0]) { continue; } char *tmp = iptodynstr(p->local_ip); char *tmp2 = iptodynstr(p->remote_ip); pi++; CON("[%d] %-10s %-15s %-15s %d", pi, p->stats_from_client.pname, tmp, tmp2, socket_get_quality(s)); myfree(tmp2); myfree(tmp); }
caddr_t exp_PrpcTPInvoke(SQLHDBC hdbc,long op) { future_t* f; caddr_t res; CON(dbc,hdbc); f = PrpcFuture (dbc->con_session, &s_sql_tp_transact, op, NULL); if () { } res = PrpcFutureNextResult (f); PrpcFutureFree(f); return res; }
void CSoundManager::ClearAll() { unsigned int i,s; s = m_sources.size(); for(i = 0; i < s; i++) delete m_sources[i]; //Delete any survivors m_sources.clear(); s = m_buffers.size(); for(i = 0; i < s; i++) delete m_buffers[i]; //Delete any survivors m_buffers.clear(); CON(MSG_DBG, _W("All the remaining sound sources deleted...")); }
bool CShaderBufferHLSL::Map(void **data, bool discard) { D3D10_MAP maptype; if(discard) { if(m_desc.CPUAccess == P3D_CPUACCESS_WRITE) maptype = D3D10_MAP_WRITE_DISCARD; else CON(MSG_ERR, _W("VertexBuffer: CPU access is not set P3D_CPUACCESS_WRITE, discard impossible.")); } else { if(m_desc.CPUAccess == P3D_CPUACCESS_READ) maptype = D3D10_MAP_READ; else if(m_desc.CPUAccess == P3D_CPUACCESS_READ_WRITE) maptype = D3D10_MAP_READ_WRITE; else if(m_desc.CPUAccess == P3D_CPUACCESS_WRITE) maptype = D3D10_MAP_WRITE; } return CheckHRResult(m_pBuffer->Map(maptype, 0, data)); }
SQLRETURN SQL_API SQLErrorW ( SQLHENV henv, SQLHDBC hdbc, SQLHSTMT hstmt, SQLWCHAR * wszSqlState, SQLINTEGER * pfNativeError, SQLWCHAR * wszErrorMsg, SQLSMALLINT cbErrorMsg, SQLSMALLINT * pcbErrorMsg) { STMT (stmt, hstmt); CON (con, hdbc); /*ENV (env, henv); */ wcharset_t *charset = con ? con->con_charset : (stmt ? stmt->stmt_connection->con_charset : NULL); SQLCHAR szSqlState[6]; SQLRETURN rc; if (con || stmt) { cli_connection_t *conn = con ? con : stmt->stmt_connection; DEFINE_OUTPUT_CHAR_NARROW (ErrorMsg, conn, SQLSMALLINT); MAKE_OUTPUT_CHAR_NARROW (ErrorMsg, conn); rc = virtodbc__SQLError (henv, hdbc, hstmt, szSqlState, pfNativeError, szErrorMsg, _cbErrorMsg, _pcbErrorMsg, 1); SET_AND_FREE_OUTPUT_CHAR_NARROW (ErrorMsg, conn); } else { DEFINE_OUTPUT_CHAR_NARROW_N (ErrorMsg, SQLSMALLINT); MAKE_OUTPUT_CHAR_NARROW_N (ErrorMsg); rc = virtodbc__SQLError (henv, hdbc, hstmt, szSqlState, pfNativeError, szErrorMsg, _cbErrorMsg, pcbErrorMsg, 1); SET_AND_FREE_OUTPUT_CHAR_NARROW_N (ErrorMsg); } if (wszSqlState) cli_narrow_to_wide (charset, 0, szSqlState, 6, WCHAR_CAST wszSqlState, 6); return rc; }
SQLRETURN SQL_API SQLConnect (SQLHDBC hdbc, SQLTCHAR * szDSN, SQLSMALLINT cbDSN, SQLTCHAR * szUID, SQLSMALLINT cbUID, SQLTCHAR * szPWD, SQLSMALLINT cbPWD) { #ifndef DSN_TRANSLATION return internal_sql_connect (hdbc, szDSN, cbDSN, szUID, cbUID, szPWD, cbPWD); #else CON (con, hdbc); TCHAR cmd[200]; TCHAR *dsn; TCHAR *uid; TCHAR *pwd; TCHAR *pcmd = &(cmd[0]); StrCopyInW (&dsn, (TCHAR *) szDSN, cbDSN); StrCopyInW (&uid, (TCHAR *) szUID, cbUID); StrCopyInW (&pwd, (TCHAR *) szPWD, cbPWD); if ((cbDSN < 0 && cbDSN != SQL_NTS) || (cbUID < 0 && cbUID != SQL_NTS) || (cbPWD < 0 && cbPWD != SQL_NTS)) { set_error (&con->con_error, "S1090", "CL062", "Invalid string or buffer length"); return SQL_ERROR; } pcmd = stpcpyw (pcmd, _T ("DSN=")); pcmd = stpcpyw (pcmd, dsn); pcmd = stpcpyw (pcmd, _T (";UID=")); pcmd = stpcpyw (pcmd, uid); pcmd = stpcpyw (pcmd, _T (";PWD=")); pcmd = stpcpyw (pcmd, pwd); free (dsn); free (uid); free (pwd); return virtodbc__SQLDriverConnect (hdbc, NULL, (SQLTCHAR *) cmd, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT); #endif }
bool CSoundEngine::Initialize(void *pEngine) { if (m_bInit) return false; m_bInit = true; s_pEngine = (IEngine*)pEngine; // memory leaks detection #if defined(_DEBUG) && defined(_MSC_VER) && _MSC_VER >= 800 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); //_CrtSetBreakAlloc(76); #endif CON(MSG_INFO, _W("= Sound Device initialization =")); m_device = alcOpenDevice(NULL); if(!m_device) { CON(MSG_ERR_FATAL, _W(" Can't initialize OpenAL! Please try to reinstall OpenAL libraries...")); return false; } m_extensions = new COALExtProvider(); if(m_extensions == NULL) { CON(MSG_INFO, _W(" Can't create OpenAL Extension provider instance!")); m_context = alcCreateContext(m_device, NULL); if(m_context != NULL) alcMakeContextCurrent(m_context); } else m_extensions->Create(m_device, m_context); if(m_context == NULL) { CON(MSG_ERR_FATAL, _W(" Can't create OpenAL context!")); return false; } if (!cSoundManager()->Create(m_extensions)) CON(MSG_ERR_FATAL, _W(" Can't create Sound Manager!")); CON(MSG_INFO, _W(" ...using OpenAL version %s"), _A2W(alGetString(AL_VERSION)) ); return true; }
bool CheckGLErrors(const wchar *info) { GLenum error; while(true) { error = glGetError(); if(error == GL_NO_ERROR) { //CON(MSG_INFO, " ...no errors"); return false; //You're lucky } if(error == GL_INVALID_ENUM) CON(MSG_ERR, _W("%s: The enum argument is out of range!"), info); else if(error == GL_INVALID_VALUE) CON(MSG_ERR, _W("%s: The numeric argument is out of range!"), info); else if(error == GL_INVALID_OPERATION) CON(MSG_ERR, _W("%s: The operation is illegal in its current state!"), info); else if(error == GL_STACK_OVERFLOW) CON(MSG_ERR, _W("%s: The command would cause a stack overflow!"), info); else if(error == GL_STACK_UNDERFLOW) CON(MSG_ERR, _W("%s: The command would cause a stack underflow!"), info); else if(error == GL_OUT_OF_MEMORY) CON(MSG_ERR, _W("%s: Not enough memory is left to execute the command!"), info); else if(error == GL_TABLE_TOO_LARGE) CON(MSG_ERR, _W("%s: The specified table is too large!"), info); return true; } }
bool CMeshLoader::Load(const wchar* path, bool ignore_animation_data/*=false*/) { if (m_bLoaded) { Unload(); m_bLoaded = false; } IFileSystem* pFS = CEngine::instance()->mFilesystem(); unsigned int ltim = GetTickCount(); // open file wchar fspath[P3DMAX_PATH]; wsprintf(fspath, P3DMAX_PATH-1, _W("models/%s.rmesh"), path); FSFILE* fp = pFS->Open(fspath, _W("rb")); if (!fp) { CON(MSG_ERR, _W("MeshLoader: Can't find mesh file '%s'!"), fspath); return false; } if (fp->nLen<sizeof(sRMHeader)) { CON(MSG_ERR, _W("MeshLoader: Mesh file '%s' is corrupted!"), fspath); pFS->Close(fp); return false; } // load and check header m_rhead = new sRMHeader(); pFS->Read(m_rhead, sizeof(sRMHeader), 1, fp); if (m_rhead->magic[0]!='R' || m_rhead->magic[1]!='M') { CON(MSG_ERR, _W("MeshLoader: File '%s' is not valid RMesh!"), fspath); pFS->Close(fp); return false; } if (m_rhead->major!=RM_MAJOR) { CON(MSG_ERR, _W("MeshLoader: Mesh '%s' is version %d, but engine can load only %d!"), fspath, m_rhead->major, RM_MAJOR); pFS->Close(fp); return false; } if (m_rhead->minor!=RM_MINOR) { CON(MSG_DBG, _W("MeshLoader: Minor version warning. Mesh '%s' is minor version %d, engine can load %d."), fspath, m_rhead->minor, RM_MINOR); } m_bLoaded=true; // LOAD INFO --------------------------------------------------- m_rinfo = new sRMInfo(); pFS->Seek(fp, m_rhead->contents[RM_FILE_INFO].offset, SEEK_SET); pFS->Read(m_rinfo, sizeof(sRMInfo), 1, fp); // LOAD SUBSETS --------------------------------------------------- m_nSubsets = m_rhead->contents[RM_SUBSETS].length/sizeof(sRMSubset); m_rsubsets = new sRMSubset[m_nSubsets]; pFS->Seek(fp, m_rhead->contents[RM_SUBSETS].offset, SEEK_SET); pFS->Read(m_rsubsets, sizeof(sRMSubset), m_nSubsets, fp); // LOAD VERTICES --------------------------------------------------- m_nVerts = m_rhead->contents[RM_VERTICES].length/sizeof(sRMVertex); m_rverts = new sRMVertex[m_nVerts]; pFS->Seek(fp, m_rhead->contents[RM_VERTICES].offset, SEEK_SET); pFS->Read(m_rverts, sizeof(sRMVertex), m_nVerts, fp); // LOAD INDICES --------------------------------------------------- m_nInds = m_rhead->contents[RM_INDICES].length/sizeof(sRMIndex); m_rinds = new sRMIndex[m_nInds]; pFS->Seek(fp, m_rhead->contents[RM_INDICES].offset, SEEK_SET); pFS->Read(m_rinds, sizeof(sRMIndex), m_nInds, fp); // MAKE FACE GROUPS ----------------------------------------------- m_faceGroups = new unsigned int[m_nInds/3]; memset(m_faceGroups, 0, sizeof(unsigned int)*m_nInds/3); for (unsigned int s=0; s<m_nSubsets; s++) { // find faces which belongs to this subset unsigned int beginFace = m_rsubsets[s].firstindex/3; unsigned int endFace = (m_rsubsets[s].firstindex+m_rsubsets[s].numindices)/3; // assign face groups to this subset for (unsigned int f=beginFace; f<endFace; f++) m_faceGroups[f]=s; } // IF THIS FILE HAS ANIMATION AND IT IS LAODED MAKE SURE TO SET m_bAnimated TO TRUE m_bAnimated = false; if (!m_rinfo->idontimportanim) { // check if file contain animated content // TODO: } // close file pFS->Close(fp); ltim = GetTickCount() - ltim; if (ltim<1000) CON(MSG_INFO, _W("MeshLoader: Mesh '%s' loaded. Loading took %d miliseconds."), path, ltim); else CON(MSG_INFO, _W("MeshLoader: Mesh '%s' loaded. Loading took %d seconds."), path, ltim/1000); return true; }
bool CShaderHLSL::Create(P3D::sShaderDesc &desc) { const char *pData; ULONG fsize; IFileSystem* pFS = CRenderer::mEngine()->mFilesystem(); wchar path[P3DMAX_PATH]; wsprintf(path, P3DMAX_PATH-1, _W("shaders/%s.rshader"), desc.ShaderFile.Get()); FSFILE *fp = pFS->Load(path, (BYTE *&)pData, fsize, true); if (!fp) { CON(MSG_ERR, _W("Can't open %s.hlsl shader file from data/shaders directory!"), desc.ShaderFile.Get()); return false; } ID3D10Blob *pShaderBlob = NULL; ID3D10Blob *pErrors = NULL; UINT flags = D3D10_SHADER_DEBUG; //D3D10_SHADER_OPTIMIZATION_LEVEL3 char profile[128]; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: strcpy(profile, D3D10GetVertexShaderProfile(g_pD3ddev)); break; case SHADERTYPE_GEOMETRY_SHADER: strcpy(profile, D3D10GetGeometryShaderProfile(g_pD3ddev)); break; case SHADERTYPE_PIXEL_SHADER: strcpy(profile, D3D10GetPixelShaderProfile(g_pD3ddev)); break; default: CON(MSG_ERR, _W("Chader creation failed. No apropriate ShaderType given.")); return false; } CIncludeHandler includeHandler; D3D10_SHADER_MACRO Shader_Macros[] = { { "DX10", NULL }, { "SM4", NULL }, NULL }; if(!CheckHRResult(D3DX10CompileFromMemory( pData, fsize, NULL, Shader_Macros, &includeHandler, _W2A(desc.EntryFunction.Get()), profile, flags, 0, NULL, &pShaderBlob, &pErrors, NULL ))) { if(pErrors) CON(MSG_ERR, _W("%s"), _A2W((char*)pErrors->GetBufferPointer())); else CON(MSG_ERR, _W("Error description not given")); CON(MSG_ERR, _W("Shader %s could not be compiled"), desc.ShaderFile.Get()); SAFE_RELEASE(pErrors); return false; } pFS->UnLoad(fp, (BYTE *)pData); //save to cache fp = pFS->Open(_W("cache/shaders/hlsl"), _W("wb")); const char* cs = (const char*)pShaderBlob->GetBufferPointer(); pFS->Write(cs, 1, pShaderBlob->GetBufferSize(), fp); pFS->Close(fp); bool shaderCreated = false; switch(desc.ShaderType) { case SHADERTYPE_VERTEX_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreateVertexShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pVS)); break; case SHADERTYPE_GEOMETRY_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreateGeometryShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pGS)); break; case SHADERTYPE_PIXEL_SHADER: shaderCreated = CheckHRResult(g_pD3ddev->CreatePixelShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pPS)); break; } if(!shaderCreated) { CON(MSG_ERR, _W("Shader creation error")); return false; } //if(!CheckHRResult(D3DReflect((DWORD*)pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), __uuidof(ID3D10ShaderReflection), &m_pReflection))) if(!CheckHRResult(D3D10ReflectShader(pShaderBlob->GetBufferPointer(), pShaderBlob->GetBufferSize(), &m_pReflection))) { CON(MSG_ERR, _W("Could not create a Shader reflection")); return false; } //HRESULT D3DReflect(LPCVOID pSrcData, SIZE_T SrcDataSize, REFIID pInterface, void **ppReflector); D3D10_SHADER_DESC shDesc; m_pReflection->GetDesc(&shDesc); m_numResources = shDesc.BoundResources; //not sure about this if(desc.ShaderType == SHADERTYPE_VERTEX_SHADER) m_pVertDecl = new CVertexDeclaration(CRenderer::cGraphicsManager()->GetVertexDescByID(desc.VertexDescID), pShaderBlob); SAFE_RELEASE(pShaderBlob); m_desc = desc; CON(MSG_INFO, _W("Shader '%s' created"), desc.ShaderFile); return true; }
static SQLRETURN SQL_API virtodbc__SQLDriverConnect (SQLHDBC hdbc, HWND hwnd, SQLTCHAR * szConnStrIn, SQLSMALLINT cbConnStrIn, SQLTCHAR * szConnStrOut, SQLSMALLINT cbConnStrOutMax, SQLSMALLINT * pcbConnStrOutMax, SQLUSMALLINT fDriverCompletion) { char tempHostName[1024]; TCHAR cmd[2500]; short fPrompt; TCHAR *connStr; TCHAR *DSN; char *UID; char *PWD; char *HOST; char *szHost; char *CHARSET; char *DATABASE; TCHAR *UIDW; TCHAR *PWDW; TCHAR *HOSTW; TCHAR *CHARSETW; TCHAR *ENCRYPTW; TCHAR *SERVERCERTW; TCHAR *FORCE_DMBS_NAMEW; TCHAR *DAYLIGHTW; TCHAR *ROUNDROBINW; #ifdef _SSL TCHAR *PWDCLEARW; #endif TCHAR *DATABASEW; SQLRETURN rc; CON (con, hdbc); CfgData cfgdata[sizeof (attrs) / sizeof (CfgRecord)]; cli_dbg_printf (("DriverConnect(%p, ..., %d) called.\n", hdbc, fDriverCompletion)); memset (cfgdata, 0, sizeof (cfgdata)); mutex_enter (con->con_environment->env_mtx); if ((szConnStrIn == NULL) || (!cbConnStrIn) || ((cbConnStrIn == SQL_NTS) && (!szConnStrIn[0]))) { connStr = _tcsdup (_T ("")); } else StrCopyInW (&connStr, (TCHAR *) szConnStrIn, cbConnStrIn); ParseOptions (cfgdata, NULL, 1); PutConnectionOptions (cfgdata, con); ParseOptions (cfgdata, connStr, 0); #ifdef DEBUG DumpOpts (connStr, cfgdata); #endif fPrompt = FALSE; if (fDriverCompletion == SQL_DRIVER_COMPLETE || fDriverCompletion == SQL_DRIVER_COMPLETE_REQUIRED) { if (!cfgdata[oUID].data || !cfgdata[oUID].data[0] || cfgdata[oUID].data[0] == ' ' || !cfgdata[oPWD].data || !cfgdata[oPWD].data[0] || cfgdata[oPWD].data[0] == ' ' || !cfgdata[oHOST].data || !cfgdata[oHOST].data[0] || cfgdata[oHOST].data[0] == ' ') fPrompt = TRUE; } else if (fDriverCompletion == SQL_DRIVER_PROMPT) { fPrompt = TRUE; } if (fPrompt) { if ((rc = DriverConnectDialog ((void *) hwnd)) != SQL_SUCCESS) { ParseOptions (cfgdata, NULL, 1); mutex_leave (con->con_environment->env_mtx); return rc; } } #ifdef _SSL if (con->con_encrypt) { dk_free_box (con->con_encrypt); } ENCRYPTW = cfgdata[oENCRYPT].data && _tcslen (cfgdata[oENCRYPT].data) ? (cfgdata[oENCRYPT].data) : NULL; con->con_encrypt = virt_wide_to_ansi (ENCRYPTW); PWDCLEARW = cfgdata[oPWDCLEAR].data && _tcslen (cfgdata[oPWDCLEAR].data) ? (cfgdata[oPWDCLEAR].data) : NULL; con->con_pwd_cleartext = PWDCLEARW ? _ttoi (PWDCLEARW) : 0; SERVERCERTW = cfgdata[oSERVERCERT].data && _tcslen (cfgdata[oSERVERCERT].data) ? (cfgdata[oSERVERCERT].data) : NULL; con->con_ca_list = virt_wide_to_ansi (SERVERCERTW); #else con->con_encrypt = NULL; ENCRYPTW = NULL; con->con_pwd_cleartext = 0; SERVERCERTW = NULL; con->con_ca_list = NULL; con->con_pwd_cleartext = 0; #endif if (cfgdata[oROUNDROBIN].data && _tcslen (cfgdata[oROUNDROBIN].data)) { char *nst, nst1; nst = virt_wide_to_ansi (cfgdata[oROUNDROBIN].data); nst1 = toupper (*nst); con->con_round_robin = OPTION_TRUE (nst1) ? 1 : 0; free_wide_buffer (nst); } if (cfgdata[oWideUTF16].data && _tcslen (cfgdata[oWideUTF16].data)) { char *nst, nst1; nst = virt_wide_to_ansi (cfgdata[oWideUTF16].data); nst1 = toupper (*nst); con->con_wide_as_utf16 = OPTION_TRUE (nst1) ? 1 : 0; free_wide_buffer (nst); } FORCE_DMBS_NAMEW = cfgdata[oFORCE_DBMS_NAME].data && _tcslen (cfgdata[oFORCE_DBMS_NAME].data) ? cfgdata[oFORCE_DBMS_NAME].data : NULL; if (FORCE_DMBS_NAMEW) { char *force_dbms_name = virt_wide_to_ansi (FORCE_DMBS_NAMEW); strncpy (__virtodbc_dbms_name, force_dbms_name, sizeof (__virtodbc_dbms_name)); __virtodbc_dbms_name[sizeof (__virtodbc_dbms_name) - 1] = 0; free_wide_buffer (force_dbms_name); } else strcpy_ck (__virtodbc_dbms_name, PRODUCT_DBMS); DSN = cfgdata[oDSN].data; UIDW = cfgdata[oUID].data ? cfgdata[oUID].data : (TCHAR *) _T (""); UID = virt_wide_to_ansi (UIDW); PWDW = cfgdata[oPWD].data ? cfgdata[oPWD].data : (TCHAR *) _T (""); PWD = virt_wide_to_ansi (PWDW); HOSTW = cfgdata[oHOST].data ? cfgdata[oHOST].data : attrs[oHOST].defVal; HOST = virt_wide_to_ansi (HOSTW); DATABASEW = cfgdata[oDATABASE].data; DATABASE = virt_wide_to_ansi (DATABASEW); if (cfgdata[oCHARSET].data && _tcslen (cfgdata[oCHARSET].data)) { char * cs = virt_wide_to_ansi (cfgdata[oCHARSET].data); if (!strcmp (cs, "UTF-8")) { free (cfgdata[oCHARSET].data); cfgdata[oCHARSET].data = NULL; cfgdata[oCHARSET].supplied = FALSE; con->con_string_is_utf8 = 1; } } CHARSETW = (cfgdata[oCHARSET].data && _tcslen (cfgdata[oCHARSET].data)) ? cfgdata[oCHARSET].data : NULL; CHARSET = con->con_charset_name = virt_wide_to_ansi (CHARSETW); if (strchr (HOST, ':') == NULL && strchr(HOST,',') == NULL) { snprintf (tempHostName, sizeof (tempHostName), "%s:1111", HOST); szHost = tempHostName; } else szHost = HOST; DAYLIGHTW = cfgdata[oDAYLIGHT].data && _tcslen (cfgdata[oDAYLIGHT].data) ? cfgdata[oDAYLIGHT].data : NULL; if (DAYLIGHTW) { char *daylight = virt_wide_to_ansi (DAYLIGHTW); isdts_mode = (toupper (*daylight) == 'Y'); free_wide_buffer (daylight); } if (cfgdata[oNoSystemTables].data && _tcslen (cfgdata[oNoSystemTables].data)) { char *nst, nst1; nst = virt_wide_to_ansi (cfgdata[oNoSystemTables].data); nst1 = toupper (*nst); con->con_no_system_tables = OPTION_TRUE (nst1) ? 1 : 0; free_wide_buffer (nst); } if (cfgdata[oTreatViewsAsTables].data && _tcslen (cfgdata[oTreatViewsAsTables].data)) { char *nst, nst1; nst = virt_wide_to_ansi (cfgdata[oTreatViewsAsTables].data); nst1 = toupper (*nst); con->con_treat_views_as_tables = OPTION_TRUE (nst1) ? 1 : 0; free_wide_buffer (nst); } #ifdef DEBUG DumpOpts (connStr, cfgdata); printf (_T ("CONNECT(%s,%s,%s)\n"), szHost, UID, PWD); #endif rc = internal_sql_connect (hdbc, (SQLCHAR *) szHost, SQL_NTS, (SQLCHAR *) UID, SQL_NTS, (SQLCHAR *) PWD, SQL_NTS); if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { if (DATABASEW && _tcslen (DATABASEW) && _tcscmp (DATABASEW, DEFAULT_DATABASE_PER_USER)) rc = virtodbc__SQLSetConnectAttr (hdbc, SQL_CURRENT_QUALIFIER, DATABASE, SQL_NTS); else DATABASEW = NULL; } if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { if (cfgdata[oIsolationLevel].data && _tcslen (cfgdata[oIsolationLevel].data)) { TCHAR *szValue = cfgdata[oIsolationLevel].data; if (!_tcsicmp (szValue, _T ("Read Uncommitted"))) con->con_isolation = SQL_TXN_READ_UNCOMMITTED; else if (!_tcsicmp (szValue, _T ("Read Committed"))) con->con_isolation = SQL_TXN_READ_COMMITTED; else if (!_tcsicmp (szValue, _T ("Repeatable Read"))) con->con_isolation = SQL_TXN_REPEATABLE_READ; else if (!_tcsicmp (szValue, _T ("Serializable"))) con->con_isolation = SQL_TXN_SERIALIZABLE; } } if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) { TCHAR *p = cmd; if (cfgdata[oDRIVER].supplied && cfgdata[oDRIVER].data) { p = stpcpyw (p, _T ("DRIVER=")); p = stpcpyw (p, cfgdata[oDRIVER].data); p = stpcpyw (p, _T (";SERVER=OpenLink")); } else if (DSN) { p = stpcpyw (p, _T ("DSN=")); p = stpcpyw (p, DSN); } else p = stpcpyw (p, _T ("DSN=default")); if (DATABASEW) { p = stpcpyw (p, _T (";DATABASE=")); p = stpcpyw (p, DATABASEW); } if (FORCE_DMBS_NAMEW) { p = stpcpyw (p, _T (";FORCE_DBMS_NAME=")); p = stpcpyw (p, FORCE_DMBS_NAMEW); } if (CHARSET) { p = stpcpyw (p, _T (";CHARSET=")); p = stpcpyw (p, CHARSETW); } #ifdef _SSL if (con->con_encrypt) { p = stpcpyw (p, _T (";ENCRYPT=")); p = stpcpyw (p, ENCRYPTW); } if (con->con_ca_list) { p = stpcpyw (p, _T (";SERVERCERT=")); p = stpcpyw (p, SERVERCERTW); } if (con->con_pwd_cleartext) { p = stpcpyw (p, _T (";PWDCLEAR=")); p = stpcpyw (p, PWDCLEARW); } #endif if (DAYLIGHTW) { p = stpcpyw (p, isdts_mode ? _T (";DAYLIGHT=Y") : _T (";DAYLIGHT=N")); } p = stpcpyw (p, _T (";UID=")); p = stpcpyw (p, UIDW); p = stpcpyw (p, _T (";PWD=")); p = stpcpyw (p, PWDW); p = stpcpyw (p, _T (";HOST=")); p = stpcpyw (p, HOSTW); if (-1 == StrCopyOut (cmd, szConnStrOut, cbConnStrOutMax, (u_short *) pcbConnStrOutMax)) { rc = SQL_SUCCESS_WITH_INFO; set_success_info (&con->con_error, "01004", "CLW01", "String data, right truncated", 0); } } free_wide_buffer (HOST); free_wide_buffer (UID); free_wide_buffer (PWD); free_wide_buffer (CHARSET); free_wide_buffer (DATABASE); /* Cleanup */ ParseOptions (cfgdata, NULL, 1); if (connStr) free (connStr); mutex_leave (con->con_environment->env_mtx); return rc; }