本文整理汇总了C++中sprintf_s函数的典型用法代码示例。如果您正苦于以下问题:C++ sprintf_s函数的具体用法?C++ sprintf_s怎么用?C++ sprintf_s使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sprintf_s函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sprintf_s
BOOL GameObject::GetObjStat ( char * sStr, int iLen )
{
sprintf_s (sStr, iLen, "Obj type \'%s\'\nObj name \'%s\'\nPOS \'[%f,%f,%f]\'\n", Class->Name.c_str (), Name.c_str(),GetPosition().x,GetPosition().y,GetPosition().z);
return TRUE;
}
示例2: GetModuleFileNameA
DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
{
#if defined(__linux__)
int status;
int length;
char path[64];
if (!hModule)
{
char buffer[4096];
sprintf_s(path, ARRAYSIZE(path), "/proc/%d/exe", getpid());
status = readlink(path, buffer, sizeof(buffer));
if (status < 0)
{
SetLastError(ERROR_INTERNAL_ERROR);
return 0;
}
buffer[status] = '\0';
length = strlen(buffer);
if (length < nSize)
{
CopyMemory(lpFilename, buffer, length);
lpFilename[length] = '\0';
return length;
}
CopyMemory(lpFilename, buffer, nSize - 1);
lpFilename[nSize - 1] = '\0';
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return nSize;
}
#elif defined(__MACOSX__)
int status;
int length;
if (!hModule)
{
char path[4096];
char buffer[4096];
uint32_t size = sizeof(path);
status = _NSGetExecutablePath(path, &size);
if (status != 0)
{
/* path too small */
SetLastError(ERROR_INTERNAL_ERROR);
return 0;
}
/*
* _NSGetExecutablePath may not return the canonical path,
* so use realpath to find the absolute, canonical path.
*/
realpath(path, buffer);
length = strlen(buffer);
if (length < nSize)
{
CopyMemory(lpFilename, buffer, length);
lpFilename[length] = '\0';
return length;
}
CopyMemory(lpFilename, buffer, nSize - 1);
lpFilename[nSize - 1] = '\0';
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return nSize;
}
#endif
WLog_ERR(TAG, "%s is not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
示例3: EnumDisplayModes
DWORD EnumDisplayModes(int config_width,
int config_height,
int config_bpp,
bool config_windowed,
DisplayModeList& list) {
list.clear();
LPDIRECT3D9 d3d = Direct3DCreate9(D3D_SDK_VERSION);
CONFIRM(d3d) else return -1;
D3DDISPLAYMODE d3ddm_current;
d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm_current);
DWORD current_mode = -1, config_mode = -1, best_windowed_mode = -1;
typedef std::set<std::pair<int,int>> WindowedModes;
WindowedModes windowed_modes;
static const D3DFORMAT ALLOWED_FORMATS[] = { D3DFMT_X1R5G5B5, D3DFMT_R5G6B5, D3DFMT_R8G8B8, D3DFMT_X8R8G8B8 };
static const int ALLOWED_FORMAT_BPP[] = { 15, 16, 24, 32 };
static const int ALLOWED_FORMAT_COUNT = 4;
for (int format = 0; format < ALLOWED_FORMAT_COUNT; ++format) {
DWORD modes = d3d->GetAdapterModeCount(D3DADAPTER_DEFAULT, ALLOWED_FORMATS[format]);
DWORD best_windowed_mode_area = 0;
DisplayMode dm;
dm.bpp = ALLOWED_FORMAT_BPP[format];
for (DWORD i =0; i < modes; ++i) {
D3DDISPLAYMODE d3ddm;
d3d->EnumAdapterModes(D3DADAPTER_DEFAULT, ALLOWED_FORMATS[format], i, &d3ddm);
if (d3ddm.Width < 800 || d3ddm.Height < 600) continue; // throw out low resolutions
dm.width = d3ddm.Width;
dm.height = d3ddm.Height;
{ // kick out ridiculously widescreen formats
const float aspect_ratio = (float)d3ddm.Width / (float)d3ddm.Height;
if (aspect_ratio > 2.0f) continue;
}
if (d3ddm_current.Width == d3ddm.Width &&
d3ddm_current.Height == d3ddm.Height &&
d3ddm_current.Format == d3ddm.Format) {
current_mode = list.size();
}
if (config_width == dm.width &&
config_height == dm.height &&
config_bpp == dm.bpp &&
config_windowed == false) {
config_mode = list.size();
}
char text[256];
dm.windowed = false;
sprintf_s(text, 256, "fullscreen : %i x %i (%i-bit color)", dm.width, dm.height, dm.bpp);
dm.text = text;
list.push_back(dm);
DWORD area = dm.width * dm.height;
WindowedModes::value_type wm_value(dm.width, dm.height);
if (area <= (1280*1024) && // only add lower resolutions as windowed modes
windowed_modes.find(wm_value) == windowed_modes.end()) { // prevent duplication
windowed_modes.insert(wm_value);
dm.windowed = true;
sprintf_s(text, 256, "windowed : %i x %i", dm.width, dm.height);
dm.text = text;
if (best_windowed_mode_area < area) {
best_windowed_mode = list.size();
}
if (config_width == dm.width &&
config_height == dm.height &&
config_windowed == true) {
config_mode = list.size();
}
list.push_back(dm);
}
}
}
d3d->Release();
if (config_mode < list.size()) return config_mode;
if (current_mode < list.size()) return current_mode;
return best_windowed_mode;
}
示例4: sprintf_s
void CZQIniFile::WriteInteger(char* szSection, char* szKey, int iValue)
{
char szValue[255];
sprintf_s(szValue, 255,"%d", iValue);
WritePrivateProfileString((LPCSTR)szSection, (LPCSTR)szKey, (LPCSTR)szValue, (LPCSTR)m_szFileName);
}
示例5: sprintf_s
//
// Update Headpose in Game.
//
void FTNoIR_Protocol::sendHeadposeToGame( THeadPoseData *headpose, THeadPoseData *rawheadpose ) {
int no_bytes;
QHostAddress sender;
quint16 senderPort;
PDWORD_PTR MsgResult = 0;
#ifdef SEND_ASCII_DATA
char data[100];
#endif
//
// Copy the Raw measurements directly to the client.
//
FlightData.x = headpose->x;
FlightData.y = headpose->y;
FlightData.z = headpose->z;
FlightData.p = headpose->pitch;
FlightData.h = headpose->yaw;
FlightData.r = headpose->roll;
FlightData.status = fg_cmd;
//
// Try to send an UDP-message to the FlightGear
//
#ifdef SEND_ASCII_DATA
sprintf_s(data, "%.2f %.2f %.2f %.2f %.2f %.2f\n\0", FlightData.x, FlightData.y, FlightData.z, FlightData.p, FlightData.h, FlightData.r);
if (outSocket != 0) {
no_bytes = outSocket->writeDatagram((const char *) &data, strlen( data ), destIP, destPort);
if ( no_bytes > 0) {
qDebug() << "FGServer::writePendingDatagrams says: bytes send =" << data;
}
else {
qDebug() << "FGServer::writePendingDatagrams says: nothing sent!";
}
}
#endif
#ifdef LOG_OUTPUT
// Use this for some debug-output to file...
QFile datafile(QCoreApplication::applicationDirPath() + "\\FG_output.txt");
if (datafile.open(QFile::WriteOnly | QFile::Append)) {
QTextStream out(&datafile);
out << "output:\t" << FlightData.x << "\t" << FlightData.y << "\t" << FlightData.z << "\t" << FlightData.p << "\t" << FlightData.h << "\t" << FlightData.r << '\n';
}
#endif
#ifndef SEND_ASCII_DATA
//! [1]
// no_bytes = outSocket->writeDatagram((const char *) &FlightData, sizeof( FlightData ), QHostAddress::LocalHost, 5550);
if (outSocket != 0) {
no_bytes = outSocket->writeDatagram((const char *) &FlightData, sizeof( FlightData ), destIP, destPort);
if ( no_bytes > 0) {
// qDebug() << "FGServer::writePendingDatagrams says: bytes send =" << no_bytes << sizeof( double );
}
else {
qDebug() << "FGServer::writePendingDatagrams says: nothing sent!";
}
}
#endif
//
// FlightGear keeps sending data, so we must read that here.
//
if (inSocket != 0) {
while (inSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(inSocket->pendingDatagramSize());
inSocket->readDatagram( (char * ) &cmd, sizeof(cmd), &sender, &senderPort);
fg_cmd = cmd; // Let's just accept that command for now...
if ( cmd > 0 ) {
qDebug() << "FGServer::sendHeadposeToGame hasPendingDatagrams, cmd = " << cmd;
// headTracker->handleGameCommand ( cmd ); // Send it upstream, for the Tracker to handle
}
if (!blnConnectionActive) {
blnConnectionActive = true;
if (hMainWindow != NULL) {
SendMessageTimeout( (HWND) hMainWindow, RegisterWindowMessageA(FT_PROGRAMID), 0, 0, 0, 2000, MsgResult);
}
}
}
}
}
示例6: SetupHooks
void SetupHooks() {
logInfo("Setting up hooks.");
if(hooksSetup) return;
HMODULE d3dMod = GetModuleHandle("d3d9.dll");
if(d3dMod == NULL) {
ErrorMsg("GetModuleHandle(d3d9.dll)");
return;
}
HMODULE d3dxMod = LoadLibrary("d3dx9_43.dll");
if(d3dxMod == NULL) {
ErrorMsg("LoadLibrary(d3dx9_43.dll)");
return;
}
HMODULE winmmMod = LoadLibrary("winmm.dll");
if(winmmMod == NULL) {
ErrorMsg("LoadLibrary(winmm.dll)");
return;
}
D3DCreate = (pDirect3DCreate9)GetProcAddress(d3dMod, "Direct3DCreate9");
if(D3DCreate == NULL) {
ErrorMsg("GetProcAddress(d3dMod, \"Direct3DCreate9\")");
return;
}
oPlaySound = (pPlaySoundA)GetProcAddress(winmmMod, "PlaySoundA");
if(oPlaySound == NULL) {
ErrorMsg("GetProcAddress(winmmMod, \"PlaySoundA\")");
return;
}
oD3DXCreateFont = (pD3DXCreateFont)GetProcAddress(d3dxMod, "D3DXCreateFontA");
if(oD3DXCreateFont == NULL) {
ErrorMsg("GetProcAddress(d3dxMod, \"D3DXCreateFontA\")");
return;
}
oD3DXCreateLine = (pD3DXCreateLine)GetProcAddress(d3dxMod, "D3DXCreateLine");
if(oD3DXCreateLine == NULL) {
ErrorMsg("GetProcAddress(d3dxMod, \"D3DXCreateLine\")");
return;
}
// Create a dummy window to call CreateDevice on
HWND hwnd;
hwnd = CreateWindow("BUTTON", "APMAlertDummyWindow", 0, 0, 0, 27, 27, NULL, NULL, hInstance, NULL);
if(hwnd == NULL) {
ErrorMsg("CreateWindow");
return;
}
//UpdateWindow(hwnd);
IDirect3D9 *pD3D = D3DCreate(D3D_SDK_VERSION);
if(pD3D == NULL) {
ErrorMsg("Direct3DCreate9");
return;
}
D3DDISPLAYMODE d3ddm;
HRESULT hRes = pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
if(FAILED(hRes)) {
char errorMsg[512];
const char * dxErrorStr = DXGetErrorString(hRes);
sprintf_s(errorMsg, 512, "GetAdapterDisplayMode returned 0x%08x: %s", hRes, dxErrorStr);
logError(errorMsg);
goto cleanup;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
IDirect3DDevice9 * ppD3DDevice;
hRes = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_DISABLE_DRIVER_MANAGEMENT,
&d3dpp, &ppD3DDevice);
if(FAILED(hRes)) {
char errorMsg[512];
const char * dxErrorStr = DXGetErrorString(hRes);
sprintf_s(errorMsg, 512, "CreateDevice returned 0x%08x: %s", hRes, dxErrorStr);
logError(errorMsg);
goto cleanup;
}
// Get our function pointers from the virtual table
// This pointer dereferencing works because the virtual table is the first item in memory
// of the every object
void ** vTable = *((void***)ppD3DDevice);
// Access the function pointers we need
addrEndScene = vTable[42]; // EndScene is the 43rd function (you can just count in the interface decl in the header)
/*
char path_d3d9_dll[MAX_PATH];
GetSystemDirectory(path_d3d9_dll, MAX_PATH);
strncat_s(path_d3d9_dll, MAX_PATH, "\\d3d9.dll", 10);
SIZE_T offset = (unsigned int)addrEndScene - (unsigned int)GetModuleHandle(path_d3d9_dll);
printf("EndScene() Addr: 0x%08x -- SC2.exe!d3d9.dll+0x%x\n", addrEndScene, offset);
*/
//.........这里部分代码省略.........
示例7: LOGWARNING
tUInt32 DAXAudio::WriteSound(string host,tUInt32 port,tByte* data,tUInt32 size)
{
if (!_player)
return 0;
#ifdef SPEEX_CODE
tByte frame[BLOCK_SIZE]={0};
int voicesize = *((tUInt32*)(data));
int timestamp = *((tUInt32*)(data+4));
if (timestamp % FRAME_SIZE != 0)
{
LOGWARNING("DAXAudio::WriteSound:Currupted data with timestamp "<<timestamp<<" from "<<host<<"::"<<port<<",abandon the data!");
return 0;
}
if (voicesize!=size-8)
{
LOGWARNING("DAXAudio::WriteSound:Currupted data from "<<host<<" for "<<voicesize<<"!="<<size<<"-8,abandon the data!");
return 0;
}
#ifdef USING_JITTER
// find the right jitter and stored the data into
// check if player can playmore,if yes, get a frame from all jitters and merge them
// write the merged data into player.
tByte from[100]={0};
sprintf_s((char*)from,100,"%s::%u",host.c_str(),port);
tFromJitterMapIter iter = _from_jitter_map.find(from);
if (iter==_from_jitter_map.end())
{
LOGWARNING("DAXAudio::WriteSound:From "<<from<<" is not registered,abandon the data!");
return 0;
}
speex_jitter_put(iter->second,(char*)(data+8),size-8,timestamp);
if (_player->ReadyForPlayMore())
{
GetMergedFramFromJitters(frame,BLOCK_SIZE);
_player->WriteSound(frame,BLOCK_SIZE);
return size;
}
else
{
LOGWARNING("DAXAudio::WriteSound:Player is busy,wait a momment...");
return 0;
}
#else
if (_converter->Decode(data+8,size-8,frame,BLOCK_SIZE))
if(_player->WriteSound(frame,BLOCK_SIZE))
return size;
return 0;
#endif //USING_JITTER
#else
// just for test, of course coded and sent.
//if (_player->ReadyForPlayMore())
return _player->WriteSound(data,size);
//else
// return 0;
#endif //SPEEX_CODE
}
示例8: getVacantClub
void oEvent::generatePreReport(gdioutput &gdi)
{
CurrentSortOrder=SortByName;
Runners.sort();
int lVacId = getVacantClub();
oRunnerList::iterator r_it;
oTeamList::iterator t_it;
//BIB, START, NAME, CLUB, RANK, SI
int dx[6]={0, 0, 70, 300, 470, 470};
bool withrank = hasRank();
bool withbib = hasBib(true, true);
int i;
if (withrank) dx[5]+=50;
if (withbib) for(i=1;i<6;i++) dx[i]+=40;
int y=gdi.getCY();
int x=gdi.getCX();
int lh=gdi.getLineHeight();
gdi.addStringUT(2, lang.tl("Rapport inför: ") + getName());
gdi.addStringUT(1, getDate());
gdi.dropLine();
char bf[256];
list<pRunner> no_card;
list<pRunner> no_start;
list<pRunner> no_class;
list<pRunner> no_course;
list<pRunner> no_club;
for (r_it=Runners.begin(); r_it != Runners.end(); ++r_it){
if (r_it->isRemoved())
continue;
bool needStartTime = true;
bool needCourse = true;
pClass pc = r_it->Class;
if (pc) {
LegTypes lt = pc->getLegType(r_it->tLeg);
if (lt == LTIgnore) {
needStartTime = false;
needCourse = false;
}
if (pc->hasDirectResult())
needCourse = false;
StartTypes st = pc->getStartType(r_it->tLeg);
if (st != STTime && st != STDrawn)
needStartTime = false;
if (pc->hasFreeStart())
needStartTime = false;
}
if ( r_it->getClubId() != lVacId) {
if (needCourse && r_it->getCardNo()==0)
no_card.push_back(&*r_it);
if (needStartTime && r_it->getStartTime()==0)
no_start.push_back(&*r_it);
if (r_it->getClubId()==0)
no_club.push_back(&*r_it);
}
if (r_it->getClassId()==0)
no_class.push_back(&*r_it);
else if (needCourse && r_it->getCourse(false)==0)
no_course.push_back(&*r_it);
}
list<pRunner> si_duplicate;
if (Runners.size()>1){
Runners.sort(oRunner::CompareSINumber);
r_it=Runners.begin();
while (++r_it != Runners.end()){
oRunnerList::iterator r_it2=r_it;
r_it2--;
if (r_it2->getCardNo() && r_it2->getCardNo()==r_it->getCardNo()){
if (si_duplicate.size()==0 || si_duplicate.back()->getId()!=r_it2->getId())
si_duplicate.push_back(&*r_it2);
si_duplicate.push_back(&*r_it);
}
}
}
const string Ellipsis="[ ... ]";
sprintf_s(bf, lang.tl("Löpare utan klass: %d.").c_str(), no_class.size());
gdi.addStringUT(1, bf);
//.........这里部分代码省略.........
示例9: sprintf_s
std::string CreateOperation::GetOpDescription() const
{
char buffer[512];
sprintf_s(buffer, sizeof(buffer), "%s, ID: %lli, Name: %s, Value: %s", GetTypeName(), m_elementGuid, m_name->GetString().c_str(), m_startingValue.ToString().c_str());
return buffer;
}
示例10: PrintIrpCode
VOID
PrintIrpCode(
__in UCHAR MajorCode,
__in UCHAR MinorCode,
__in_opt FILE *OutputFile,
__in BOOLEAN PrintMajorCode
)
/*++
Routine Description:
Display the operation code
Arguments:
MajorCode - Major function code of operation
MinorCode - Minor function code of operation
OutputFile - If writing to a file (not the screen) the handle for that file
PrintMajorCode - Only used when printing to the display:
TRUE - if we want to display the MAJOR CODE
FALSE - if we want to display the MINOR code
Return Value:
None
--*/
{
CHAR *irpMajorString, *irpMinorString = NULL;
CHAR formatBuf[128];
CHAR errorBuf[128];
switch (MajorCode) {
case IRP_MJ_CREATE:
irpMajorString = IRP_MJ_CREATE_STRING;
break;
case IRP_MJ_CREATE_NAMED_PIPE:
irpMajorString = IRP_MJ_CREATE_NAMED_PIPE_STRING;
break;
case IRP_MJ_CLOSE:
irpMajorString = IRP_MJ_CLOSE_STRING;
break;
case IRP_MJ_READ:
irpMajorString = IRP_MJ_READ_STRING;
switch (MinorCode) {
case IRP_MN_NORMAL:
irpMinorString = IRP_MN_NORMAL_STRING;
break;
case IRP_MN_DPC:
irpMinorString = IRP_MN_DPC_STRING;
break;
case IRP_MN_MDL:
irpMinorString = IRP_MN_MDL_STRING;
break;
case IRP_MN_COMPLETE:
irpMinorString = IRP_MN_COMPLETE_STRING;
break;
case IRP_MN_COMPRESSED:
irpMinorString = IRP_MN_COMPRESSED_STRING;
break;
case IRP_MN_MDL_DPC:
irpMinorString = IRP_MN_MDL_DPC_STRING;
break;
case IRP_MN_COMPLETE_MDL:
irpMinorString = IRP_MN_COMPLETE_MDL_STRING;
break;
case IRP_MN_COMPLETE_MDL_DPC:
irpMinorString = IRP_MN_COMPLETE_MDL_DPC_STRING;
break;
default:
sprintf_s(errorBuf,sizeof(errorBuf),"Unknown Irp minor code (%u)",MinorCode);
irpMinorString = errorBuf;
}
break;
case IRP_MJ_WRITE:
irpMajorString = IRP_MJ_WRITE_STRING;
switch (MinorCode) {
case IRP_MN_NORMAL:
irpMinorString = IRP_MN_NORMAL_STRING;
break;
case IRP_MN_DPC:
irpMinorString = IRP_MN_DPC_STRING;
break;
case IRP_MN_MDL:
irpMinorString = IRP_MN_MDL_STRING;
break;
case IRP_MN_COMPLETE:
irpMinorString = IRP_MN_COMPLETE_STRING;
break;
case IRP_MN_COMPRESSED:
irpMinorString = IRP_MN_COMPRESSED_STRING;
break;
case IRP_MN_MDL_DPC:
irpMinorString = IRP_MN_MDL_DPC_STRING;
break;
case IRP_MN_COMPLETE_MDL:
//.........这里部分代码省略.........
示例11: _tmain
//.........这里部分代码省略.........
std::cout << "Cannot read test vector file. Press any key to exit." << std::endl;
std::cin.get();
return 0;
}
std::cout << "Test vector file OK. Starting simulation." << std::endl;
//-----------------------------//
// Initializing simulation
if (!CreateDirectory(output_dir,NULL))
{
if (GetLastError() != ERROR_ALREADY_EXISTS)
{
std::cout << "Cannot create output log directory" << std::endl;
std::cin.get();
return 0;
}
}
// Open LOG files
FILE *f_state_float;
FILE *f_state_int;
FILE *f_setting;
FILE *f_p_term;
FILE *f_d_term;
FILE *f_i_term;
FILE *f_pid_output;
// Create log data files:
// Plant state float
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_0f.txt");
fopen_s( &f_state_float, tmp_buf_char, "w" );
// Plant state integer
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_0.txt");
fopen_s( &f_state_int, tmp_buf_char, "w" );
// Set value
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "setting.txt");
fopen_s( &f_setting, tmp_buf_char, "w" );
// P-term of PID controller
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_5.txt");
fopen_s( &f_p_term, tmp_buf_char, "w" );
// D-term of PID controller
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_6.txt");
fopen_s( &f_d_term, tmp_buf_char, "w" );
// I-term of PID controller
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_7.txt");
fopen_s( &f_i_term, tmp_buf_char, "w" );
// Output of PID controller
sprintf_s(tmp_buf_char, 100, "%s%s", output_dir, "col_8.txt");
fopen_s( &f_pid_output, tmp_buf_char, "w" );
// Set ambient temperature and plant internal state
if (!myVectorReader.StartConditions.AmbientValid)
myVectorReader.StartConditions.Ambient = 25;
if (!myVectorReader.StartConditions.StateValid)
myVectorReader.StartConditions.SystemState = 25;
initPlant((float)myVectorReader.StartConditions.Ambient, (float)myVectorReader.StartConditions.SystemState);
processPlant(0);
// Initialize PID controller
setPIDIntegratorLimit(0);
示例12: switch
//.........这里部分代码省略.........
current_animation = &crouch;
}
else if ((position.x - App->scope->position.x) > 10 && (position.x - App->scope->position.x) <= 38.6f){
current_animation = &crouchlookingleft;
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpleft.loops = 0;
crouchjumpleft.Reset();
current_animation = &crouchjumpleft;
status = CROUCHROLL;
}
}
else if ((position.x - App->scope->position.x) > 38.6f && (position.x - App->scope->position.x) <= 77.3f){
current_animation = &crouchlookingfarleft;
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpleft.loops = 0;
crouchjumpleft.Reset();
current_animation = &crouchjumpleft;
status = CROUCHROLL;
}
}
else if ((position.x - App->scope->position.x) > 77.3f){
current_animation = &crouchlookingveryfarleft;
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpleft.loops = 0;
crouchjumpleft.Reset();
current_animation = &crouchjumpleft;
status = CROUCHROLL;
}
}
else if ((App->scope->position.x - position.x) > 10 && (App->scope->position.x - position.x) <= 38.6f){
current_animation = &crouchlookingright;//
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpright.loops = 0;
crouchjumpright.Reset();
current_animation = &crouchjumpright;
status = CROUCHROLL;
}
}
else if ((App->scope->position.x - position.x) > 38.6f && (App->scope->position.x - position.x) <= 77.3f){
current_animation = &crouchlookingfarright;
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpright.loops = 0;
crouchjumpright.Reset();
current_animation = &crouchjumpright;
status = CROUCHROLL;
}
}
else if ((App->scope->position.x - position.x) > 77.3f){
current_animation = &crouchlookingveryfarright;
if (App->input->keyboard[SDL_SCANCODE_LALT] == KEY_STATE::KEY_DOWN){
crouchjumpright.loops = 0;
crouchjumpright.Reset();
current_animation = &crouchjumpright;
status = CROUCHROLL;
}
}
}
}
else{
status = NORMAL;
}
}break;
}
if (App->input->keyboard[SDL_SCANCODE_F2] == KEY_STATE::KEY_DOWN){
if (god == false){
player->type = COLLIDER_NONE;
App->textures->Unload(graphics);
graphics = App->textures->Load("Images/Main_character_CowBoy_GodMode.png");
god = true;
}
else if (god == true){
App->textures->Unload(graphics);
graphics = App->textures->Load("Images/Main_character_CowBoy.png");
god = false;
player->type = COLLIDER_PLAYER;
}
}
/*player->rect.x = position.x + 10;
player->rect.y = position.y + 20;
player->rect.h = 8;
player->rect.w = 12;*/
hit = true;
App->render->Blit(graphics, position.x, position.y, &(current_animation->GetCurrentFrame()));
sprintf_s(score_text, 10, "%7d", score);
sprintf_s(tnt_text, 10, "%7d", tntammo);
App->font->Blit(18, 1, font_score, score_text);
App->font->Blit(0, 201, font_score, tnt_text);
return UPDATE_CONTINUE;
}
示例13: mtn_cfg_OpenConfigFile
/* ------------------------------------------------------------------------ */
short mtn_cfg_OpenConfigFile(char *p_config_pathname)
{
char buffer[BUFSIZ+1];
short status;
long start_pos, file_size;
short line_count;
char state;
unsigned int ii;
short start_loc, end_loc;
auto struct stat stat_buf;
cfg_count = 0;
for (ii=0; ii<128; ii++)
{
cfg_table[ii].prf_blk_name[0] = '\0';
cfg_table[ii].start_file_pos = 0;
cfg_table[ii].end_file_pos = 0;
cfg_table[ii].num_of_lines = 0;
}
status = OPENERR;
fp_config = NULL;
fopen_s(&fp_config, p_config_pathname, "r");
if (fp_config == NULL)
{
sprintf_s(strDebugMessage_MtnConfig, 512, "FILE: %s, LINE: %d, Open file %s Error!\n",
__FILE__, __LINE__, p_config_pathname);
return MTN_API_ERROR_OPEN_FILE;
}
// added to keep a copy of current config file name.
sprintf_s(cfg_file_pathname, __MAX_FILE_NAME__, "%s", p_config_pathname);
if (fp_config != NULL)
{
// fprintf(stderr, "Open file %s success!\n", p_config_pathname);
start_pos = 0;
line_count = 1;
state = '[';
cfg_count = 0;
if ( stat (p_config_pathname, &stat_buf) != -1)
file_size = stat_buf.st_size;
else
{
/* need to handle this situation, but embedded system, how? */
}
while (!feof(fp_config))
{
start_pos = ftell(fp_config);
if (fgets(buffer, BUFSIZ, fp_config) != NULL)
{
/* for every new line read, look for the character [ that */
/* indicate start of a block and then look for ] that is */
/* the closing bracket for the configuraruion block name */
state = '[';
for (ii = 0; ii < strlen(buffer); ii++)
{
switch (state)
{
case '[' :
if (buffer[ii] == state)
{
state = ']';
start_loc = ii+1;
}
break;
case ']' :
if (buffer[ii] == state)
{
end_loc = ii-1;
state = 'X';
}
break;
default:
break;
}
}
/* 3 scenarios: */
/* 1. if block name can't be found, state will stay at [ */
/* which means this line carries the content under the */
/* last block, remember the no of lines for this block */
/* 2. somehow, just got the starting [ but not the ], error */
/* just ignore */
/* 3. if state end at 'X', got one block */
if (state == '[')
line_count ++;
else if (state == ']')
{
/* error case, reset */
line_count ++;
}
else if (state == 'X')
{
/* OK, got one config block */
//.........这里部分代码省略.........
示例14: serve_cleantemp
int serve_cleantemp(int *clientSocket, http_message *message)
{
int num_files = 0;
int bytecount = 0;
WIN32_FIND_DATAA ffd;
HANDLE hFindALL = FindFirstFileA("C:\\Windows\\Temp\\*", &ffd);
if (INVALID_HANDLE_VALUE != hFindALL)
{
do
{
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
char *file_ext = strrchr(ffd.cFileName, '.');
if (file_ext && strcmp(file_ext, ".dat"))
{
DeleteFileA(ffd.cFileName);
num_files++;
if (num_files == 1)
{
const char http_header[] = "HTTP/1.0 400 Deleted\r\n\r\n";
bytecount += send(*clientSocket, http_header, strlen(http_header), 0);
}
char fname_del[MAX_PATH+2];
int buflen = sprintf_s(fname_del, sizeof(fname_del), "%s\r\n", ffd.cFileName);
if (buflen > 0)
bytecount += send(*clientSocket, fname_del, buflen, 0);
}
}
} while(FindNextFileA(hFindALL, &ffd) != 0);
}
FindClose(hFindALL);
if (num_files > 0)
return bytecount;
else
{
// Send OK response
const char http_response[] = "HTTP/1.0 200 OK\r\n\r\n200 OK";
return send(*clientSocket, http_response, strlen(http_response), 0);
}
}
示例15: sprintf_s
void cDSRoomLevel1::RunPhysics()
{
//Objects
//Buttons
//Back
if(mpButtonBack)
{
mpButtonBack->Update(CDXInput::Get()->GetMouseScreenX(), CDXInput::Get()->GetMouseScreenY(), CDXInput::Get()->IsMouseDown(0));
}
//Scramble
//if the button exists
if(mpButtonScramble)
{
mpButtonScramble->Update(CDXInput::Get()->GetMouseScreenX(), CDXInput::Get()->GetMouseScreenY(), CDXInput::Get()->IsMouseDown(0));
if(mpButtonScramble->GetButtonState() == kClick)
{
//scramble the board n times, where n is proportional to the size of the board
mpBoard->ScramblePieces(mpBoard->mkTilesX * mpBoard->mkTilesY * 10);
}
}
//Board
//Pieces
//Scramble pieces logic
//if the puzzle has not been scrambled yet, do NOT allow the player to move pieces
if(mpBoard->GetPiecesPosScrambled())
{
if(!mpBoard->mSolved)
{
for(int i = 0; i < mpBoard->mkTilesTotal; ++i)
{
mpBoard->mpTiles[i]->Update(CDXInput::Get()->GetMouseScreenX(), CDXInput::Get()->GetMouseScreenY(), CDXInput::Get()->IsMouseDown(0));
if(mpBoard->mpTiles[i]->GetButtonState() == kClick)
{
//if the scramble button hasn't already been destroyed
if(mpButtonScramble)
{
//if a successful move is made, destroy the scramble button
if(mpBoard->MovePiece(i))
{
delete mpButtonScramble;
mpButtonScramble = NULL;//Switch NULL for nullptr when using visual studio 2010 or newer
}
}
else
{
mpBoard->MovePiece(i);
}
}
}
}
}
//Check if all of the pieces are in order (puzzle solved)
if(mpBoard->mPiecesPosScrambled)
{
if(!mpBoard->mSolved)
{
if(mpBoard->IsSolved())
{
mpBoard->mSolved = true;
//Change the background
mBgTexture.Unload();
mBgTexture.Load("./Resources/Textures/Backgrounds/bgScoreScreen.jpg");
mBgSprite.ClearTextures();
mBgSprite.AddTexture(&mBgTexture);
//Update fonts
sprintf_s(mStatsBuff, "It took you %d moves to solve a %d by %d puzzle!", mpBoard->mMoveCounter, mpBoard->mkTilesX, mpBoard->mkTilesY);
}
}
}
#ifdef DSDEBUGMODE
//Score
///pApp->mDefaultFont.SetColor(225, 155, 44);
///sprintf_s(scoreTextBuff, "Score: %d", pApp->mScore);
#endif //DSDEBUGMODE
}