本文整理汇总了C++中LOG类的典型用法代码示例。如果您正苦于以下问题:C++ LOG类的具体用法?C++ LOG怎么用?C++ LOG使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LOG类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: entity
void settler_ranged_attack_system::on_message(const settler_ranged_attack_message &msg) {
auto attacker = entity(msg.attacker);
auto defender = entity(msg.victim);
if (!attacker || !defender) return;
auto attacker_stats = attacker->component<game_stats_t>();
auto attacker_pos = attacker->component<position_t>();
auto defender_pos = defender->component<position_t>();
civ_dislike_attacker(defender);
std::size_t weapon_id, ammo_id;
std::tie(weapon_id, ammo_id) = get_ranged_and_ammo_id(msg.attacker);
std::string weapon_name = "fists";
int weapon_n = 1;
int weapon_d = 4;
int weapon_mod = 0;
if (weapon_id != 0) {
auto weapon_component = entity(weapon_id)->component<item_t>();
if (weapon_component) {
auto weapon_finder = item_defs.find(weapon_component->item_tag);
if (weapon_finder != item_defs.end()) {
weapon_name = weapon_finder->second.name;
}
}
}
if (ammo_id != 0) {
auto ammo_component = entity(ammo_id)->component<item_t>();
if (ammo_component) {
auto ammo_finder = item_defs.find(ammo_component->item_tag);
if (ammo_finder != item_defs.end()) {
weapon_n = ammo_finder->second.damage_n;
weapon_d = ammo_finder->second.damage_d + get_material(ammo_component->material)->damage_bonus;
weapon_mod = ammo_finder->second.damage_mod;
}
--ammo_component->stack_size;
if (ammo_component->stack_size < 1) delete_entity(ammo_id);
}
emit(emit_particles_message{3, attacker_pos->x, attacker_pos->y, attacker_pos->z,
defender_pos->x, defender_pos->y, defender_pos->z});
}
LOG ss;
ss.settler_name(msg.attacker)->text(" attacks ")->other_name(msg.victim)->text(" with their ")->col(rltk::colors::YELLOW)->text(weapon_name+std::string(". "))->col(rltk::colors::WHITE);
const int skill_modifier = get_skill_modifier(*attacker_stats, "Ranged Attacks");
const int die_roll = rng.roll_dice(1, 20) + stat_modifier(attacker_stats->dexterity + skill_modifier);
const int armor_class = calculate_armor_class(*defender);
if (die_roll > armor_class) {
const int damage = std::max(1, rng.roll_dice(weapon_n, weapon_d) + weapon_mod + stat_modifier(attacker_stats->strength) + skill_modifier);
ss.text("The attack hits for "+std::to_string(damage)+" points of damage.");
emit(inflict_damage_message{ msg.victim, damage, weapon_name });
gain_skill_from_success(msg.attacker, *attacker_stats, "Ranged Attacks", armor_class, rng);
} else {
ss.text("The attack misses.");
}
emit_deferred(log_message{ss.chars});
}
示例2: while
static void *thread(void *arg)
{
while(1)
{
LOG *log = (LOG *)arg;
sem_wait(&log->sem);
printf("log->write()\n");
log->write();
}
}
示例3: LoadVertices
///////////////////BSP::LoadVertices////////
////////////////////////////////////////////
bool BSP::LoadVertices(FILE * file)
{
//calculate number of vertices
numVertices=header.directoryEntries[bspVertices].length/sizeof(BSP_LOAD_VERTEX);
//Create space for this many BSP_LOAD_VERTICES
BSP_LOAD_VERTEX * loadVertices=new BSP_LOAD_VERTEX[numVertices];
if(!loadVertices)
{
errorLog.OutputError("Unable to allocate memory for %d BSP_LOAD_VERTEXes", numVertices);
return false;
}
//go to vertices in file
fseek(file, header.directoryEntries[bspVertices].offset, SEEK_SET);
//read in the vertices
fread(loadVertices, header.directoryEntries[bspVertices].length, 1, file);
//Convert to BSP_VERTEXes
vertices=new BSP_VERTEX[numVertices];
if(!vertices)
{
errorLog.OutputError("Unable to allocate memory for vertices");
return false;
}
for(int i=0; i<numVertices; ++i)
{
//swap y and z and negate z
vertices[i].position.x=loadVertices[i].position.x;
vertices[i].position.y=loadVertices[i].position.z;
vertices[i].position.z=-loadVertices[i].position.y;
//scale down
vertices[i].position/=64;
//Transfer texture coordinates (Invert t)
vertices[i].decalS=loadVertices[i].decalS;
vertices[i].decalT=-loadVertices[i].decalT;
//Transfer lightmap coordinates
vertices[i].lightmapS=loadVertices[i].lightmapS;
vertices[i].lightmapT=loadVertices[i].lightmapT;
}
if(loadVertices)
delete [] loadVertices;
loadVertices=NULL;
return true;
}
示例4: Load
//Load - load a texture from a file
bool IMAGE::Load(char * filename)
{
//Clear the data if already used
if(data)
delete [] data;
data=NULL;
bpp=0;
width=0;
height=0;
format=0;
int filenameLength=strlen(filename);
if( strncmp((filename+filenameLength-3), "BMP", 3)==0 ||
strncmp((filename+filenameLength-3), "bmp", 3)==0)
return LoadBMP(filename);
if( strncmp((filename+filenameLength-3), "PCX", 3)==0 ||
strncmp((filename+filenameLength-3), "pcx", 3)==0)
return LoadPCX(filename);
if( strncmp((filename+filenameLength-3), "TGA", 3)==0 ||
strncmp((filename+filenameLength-3), "tga", 3)==0)
return LoadTGA(filename);
errorLog.OutputError("%s does not end in \".tga\", \".bmp\" or \"pcx\"", filename);
return false;
}
示例5: DemoInit
//Set up variables
bool DemoInit()
{
if(!window.Init("Project Template", 640, 480, 32, 24, 8, WINDOWED_SCREEN))
return 0; //quit if not created
SetUpARB_multitexture();
SetUpEXT_texture3D();
SetUpEXT_texture_edge_clamp();
SetUpNV_register_combiners();
SetUpNV_texture_shader();
SetUpNV_vertex_program();
if( !EXT_texture_edge_clamp_supported || !ARB_multitexture_supported ||
!NV_vertex_program_supported || !NV_register_combiners_supported)
return false;
//Check we have at least 3 texture units
GLint maxTextureUnitsARB;
glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnitsARB);
if(maxTextureUnitsARB<3)
{
errorLog.OutputError("I require at least 3 texture units");
return false;
}
//Set light colors
lightColors[0].Set(1.0f, 1.0f, 1.0f, 1.0f);
lightColors[1].Set((float)47/255, (float)206/255, (float)240/255, 1.0f);
lightColors[2].Set((float)254/255, (float)48/255, (float)18/255, 1.0f);
lightColors[3].Set((float)83/255, (float)243/255, (float)29/255, 1.0f);
//Load textures
//Decal image
decalImage.Load("decal.tga");
glGenTextures(1, &decalTexture);
glBindTexture(GL_TEXTURE_2D, decalTexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, decalImage.width, decalImage.height,
0, decalImage.format, GL_UNSIGNED_BYTE, decalImage.data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//Create light textures
if(!InitLightTextures( atten1DTexture, atten2DTexture, atten3DTexture,
gaussian1DTexture, gaussian2DTexture))
return false;
camera.Init(VECTOR3D(0.0f, 0.0f, 3.5f));
//reset timer for start
timer.Reset();
return true;
}
示例6: LoadNV_vertex_program
bool LoadNV_vertex_program(char * filename, GLuint programID)
{
//load from file
std::ifstream vpFile(filename, std::ios::in | std::ios::binary);
if(vpFile.fail())
{
printf("Unable to open vertex program\n");
return false;
}
//calculate the size of the file
vpFile.seekg(0, std::ios::end);
int vpSize=vpFile.tellg();
vpFile.seekg(0, std::ios::beg);
//allocate memory
unsigned char * vpText=new unsigned char[vpSize];
if(!vpText)
{
printf("Unable to allocate space for vertex program text\n");
return false;
}
//read file
vpFile.read(reinterpret_cast<char *>(vpText), vpSize);
vpFile.close();
//load program
glLoadProgramNV(GL_VERTEX_PROGRAM_NV, programID, vpSize, vpText);
if(vpText)
delete [] vpText;
vpText=NULL;
//Output if there was an error
int errorPos;
glGetIntegerv(GL_PROGRAM_ERROR_POSITION_NV, &errorPos);
if(errorPos!=-1)
{
errorLog.OutputError("Program error at position %d in %s\n", errorPos, filename);
return false;
}
else
errorLog.OutputSuccess("%s loaded correctly", filename);
return true;
}
示例7: MakeCurrent
bool PBUFFER::MakeCurrent()
{
if(!wglMakeCurrent(hDC, hRC))
{
errorLog.OutputError("Unable to change current context");
return false;
}
return true;
}
示例8: SetUpEXT_texture_edge_clamp
bool SetUpEXT_texture_edge_clamp()
{
//Check for support
char * extensionString=(char *)glGetString(GL_EXTENSIONS);
char * extensionName="GL_EXT_texture_edge_clamp";
char * endOfString; //store pointer to end of string
unsigned int distanceToSpace; //distance to next space
endOfString=extensionString+strlen(extensionString);
//loop through string
while(extensionString<endOfString)
{
//find distance to next space
distanceToSpace=strcspn(extensionString, " ");
//see if we have found extensionName
if((strlen(extensionName)==distanceToSpace) &&
(strncmp(extensionName, extensionString, distanceToSpace)==0))
{
EXT_texture_edge_clamp_supported=true;
}
//if not, move on
extensionString+=distanceToSpace+1;
}
if(!EXT_texture_edge_clamp_supported)
{
errorLog.OutputError("EXT_texture_edge_clamp unsupported!");
return false;
}
errorLog.OutputSuccess("EXT_texture_edge_clamp supported!");
//get function pointers
//none specified
return true;
}
示例9: LoadTGA
//Load a TGA texture
bool IMAGE::LoadTGA(char * filename)
{
unsigned char UncompressedTGAHeader[12]={0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char CompressedTGAHeader[12]={0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned char Uncompressed8BitTGAHeader[12]={0, 1, 1, 0, 0, 0, 1, 24, 0, 0, 0, 0};
unsigned char TGAcompare[12]; //Used to compare TGA header
FILE * file = fopen(filename, "rb"); //Open the TGA file
if( file==NULL ) //Does the file exist?
{
errorLog.OutputError("%s does not exist", filename);
return false;
}
//read the header
fread(TGAcompare, 1, sizeof(TGAcompare), file);
fclose(file);
if(memcmp(UncompressedTGAHeader, TGAcompare, sizeof(UncompressedTGAHeader))==0)
{
return LoadUncompressedTrueColorTGA(filename);
}
else if(memcmp(CompressedTGAHeader, TGAcompare, sizeof(CompressedTGAHeader))==0)
{
return LoadCompressedTrueColorTGA(filename);
}
else if(memcmp(Uncompressed8BitTGAHeader, TGAcompare, sizeof(Uncompressed8BitTGAHeader))==0)
{
return LoadUncompressed8BitTGA(filename);
}
else
{
errorLog.OutputError("%s is not a recognised type of TGA", filename);
return false;
}
return false;
}
示例10: LoadBMP
bool IMAGE::LoadBMP(char * filename)
{
FILE * file; //the texture file
BITMAPFILEHEADER fileHeader; //bitmap file header
BITMAPINFOHEADER infoHeader; //bitmap info header
//open file for reading
file=fopen(filename, "rb");
if(file==NULL)
{
errorLog.OutputError("Unable to open %s", filename);
return false;
}
//read the file header
fread(&fileHeader, sizeof(BITMAPFILEHEADER), 1, file);
//check it's a bitmap
if(fileHeader.bfType != BITMAP_ID)
{
fclose(file);
errorLog.OutputError("%s is not a legal .BMP", filename);
return false;
}
//read in the information header
fread(&infoHeader, sizeof(BITMAPINFOHEADER), 1, file);
//close the file
fclose(file);
//discover the bpp
if(infoHeader.biBitCount==24)
return Load24BitBMP(filename);
if(infoHeader.biBitCount==8)
return Load8BitBMP(filename);
errorLog.OutputError("%s has an unknown bpp", filename);
return false;
}
示例11: Shutdown
void PBUFFER::Shutdown(void)
{
if(hRC) //have a rendering context?
{
if(!wglDeleteContext(hRC)) //try to delete RC
{
errorLog.OutputError("Release of Pbuffer Rendering Context Failed.");
}
hRC=NULL; //set RC to NULL
}
if(hDC && !wglReleasePbufferDCARB(hBuffer, hDC)) //Are we able to release DC?
{
errorLog.OutputError("Release of Pbuffer Device Context Failed.");
hDC=NULL;
}
if(!wglDestroyPbufferARB(hBuffer))
{
errorLog.OutputError("Unable to destroy pbuffer");
}
}
示例12: FlipVertically
void IMAGE::FlipVertically()
{
//dont flip zero or 1 height images
if(height==0 || height==1)
return;
int rowsToSwap=0;
//see how many rows to swap
if(height%2==1)
rowsToSwap=(height-1)/2;
else
rowsToSwap=height/2;
//create space for a temporary row
GLubyte * tempRow=new GLubyte[width*bpp/8];
if(!tempRow)
{
errorLog.OutputError("Unable to flip image, unable to create space for temporary row");
return;
}
//loop through rows to swap
for(int i=0; i<rowsToSwap; ++i)
{
//copy row i into temp
memcpy(tempRow, &data[i*width*bpp/8], width*bpp/8);
//copy row height-i-1 to row i
memcpy(&data[i*width*bpp/8], &data[(height-i-1)*width*bpp/8], width*bpp/8);
//copy temp into row height-i-1
memcpy(&data[(height-i-1)*width*bpp/8], tempRow, width*bpp/8);
}
//free tempRow
if(tempRow)
delete [] tempRow;
tempRow=NULL;
}
示例13: WinMain
//ENTRY POINT FOR APPLICATION
//CALL WINDOW CREATION ROUTINE, DEAL WITH MESSAGES, WATCH FOR INTERACTION
int WINAPI WinMain( HINSTANCE hInstance, //instance
HINSTANCE hPrevInstance, //Previous Instance
LPSTR lpCmdLine, //command line parameters
int nCmdShow) //Window show state
{
//Initiation
errorLog.Init("Error Log.txt");
//init variables etc, then GL
if(!DemoInit())
{
errorLog.OutputError("Demo Initiation failed");
return 0;
}
else
errorLog.OutputSuccess("Demo Initiation Successful");
if(!GLInit())
{
errorLog.OutputError("OpenGL Initiation failed");
return 0;
}
else
errorLog.OutputSuccess("OpenGL Initiation Successful");
//Main Loop
for(;;)
{
if(!(window.HandleMessages())) break;//handle windows messages, quit if returns false
UpdateFrame();
RenderFrame();
}
DemoShutdown();
errorLog.OutputSuccess("Exiting...");
return (window.msg.wParam); //Exit The Program
}
示例14: Init
bool PBUFFER::Init( int newWidth, int newHeight,
int newColorBits, int newDepthBits, int newStencilBits,
int numExtraIAttribs, int * extraIAttribList, int * flags)
{
//Check for pbuffer support
if( !WGL_ARB_extensions_string_supported ||
!WGL_ARB_pixel_format_supported ||
!WGL_ARB_pbuffer_supported)
{
errorLog.OutputError("Extension required for pbuffer unsupported");
return false;
}
//set class's member variables
width=newWidth;
height=newHeight;
colorBits=newColorBits;
depthBits=newDepthBits;
stencilBits=newStencilBits;
//Get the current device context
HDC hCurrentDC=wglGetCurrentDC();
if(!hCurrentDC)
{
errorLog.OutputError("Unable to get current Device Context");
return false;
}
//choose pixel format
GLint pixelFormat;
const int standardIAttribList[]={ WGL_DRAW_TO_PBUFFER_ARB, 1,
WGL_COLOR_BITS_ARB, colorBits,
WGL_ALPHA_BITS_ARB, colorBits==32 ? 8 : 0,
WGL_DEPTH_BITS_ARB, depthBits,
WGL_STENCIL_BITS_ARB, stencilBits};
const float fAttribList[]={
0};
//add the extraIAttribList to the standardIAttribList
int * iAttribList=new int[sizeof(standardIAttribList)/sizeof(int)+numExtraIAttribs*2+1];
if(!iAttribList)
{
errorLog.OutputError("Unable to allocate space for iAttribList");
return false;
}
memcpy( iAttribList, standardIAttribList, sizeof(standardIAttribList));
memcpy( iAttribList+sizeof(standardIAttribList)/sizeof(int),
extraIAttribList, numExtraIAttribs*2*sizeof(int)+sizeof(int));
//Choose pixel format
unsigned int numFormats;
if(!wglChoosePixelFormatARB(hCurrentDC, iAttribList, fAttribList, 1,
&pixelFormat, &numFormats))
{
errorLog.OutputError("Unable to find a pixel format for the pbuffer");
return false;
}
//Create the pbuffer
hBuffer=wglCreatePbufferARB(hCurrentDC, pixelFormat, width, height, flags);
if(!hBuffer)
{
errorLog.OutputError("Unable to create pbuffer");
return false;
}
//Get the pbuffer's device context
hDC=wglGetPbufferDCARB(hBuffer);
if(!hDC)
{
errorLog.OutputError("Unable to get pbuffer's device context");
return false;
}
//Create a rendering context for the pbuffer
hRC=wglCreateContext(hDC);
if(!hRC)
{
errorLog.OutputError("Unable to create pbuffer's rendering context");
return false;
}
//Set and output the actual pBuffer dimensions
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_WIDTH_ARB, &width);
wglQueryPbufferARB(hBuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
errorLog.OutputSuccess("Pbuffer Created: (%d x %d)", width, height);
return TRUE; //success!
}
示例15: LoadAlphaTGA
//load in an 8 bit greyscale TGA as an alpha channel
bool IMAGE::LoadAlphaTGA(char * filename)
{
unsigned char TGAHeader[12]={0, 1, 1, 0, 0, 0, 1, 24, 0, 0, 0, 0};
unsigned char TGAcompare[12]; //Used to compare TGA header
unsigned char header[6]; //First 6 useful bytes of the header
errorLog.OutputSuccess("Loading %s in LoadAlphaTGA()", filename);
if(!(format==GL_RGB || format==GL_RGBA))
{
errorLog.OutputError("Can only load an alpha channel to RGB / RGBA format images. %s caused error", filename);
return false;
}
FILE * file = fopen(filename, "rb"); //Open the TGA file
if(file == NULL) //Does the file exist?
{
errorLog.OutputError("%s does not exist.", filename);
return false;
}
if( fread(TGAcompare, 1, sizeof(TGAcompare), file)!=sizeof(TGAcompare)|| //Are there 12 bytes to read?
memcmp(TGAHeader, TGAcompare, sizeof(TGAHeader))!=0 || //Is the header correct?
fread(header, 1, sizeof(header), file)!=sizeof(header)) //Read next 6 bytes
{
fclose(file); //If anything else failed, close the file
errorLog.OutputError("Could not load %s correctly, general failure.", filename);
return false;
}
//save data into class member variables
unsigned int alphaWidth= header[1]*256+header[0]; //determine the image width
unsigned int alphaHeight= header[3]*256+header[2]; //determine image height
int alphaBpp= header[4];
if( alphaWidth<=0 || //if width <=0
alphaHeight<=0 || //or height<=0
alphaBpp!=8) //bpp not 8
{
fclose(file); //close the file
errorLog.OutputError("%s's height or width is less than zero, or the TGA is not 8 bpp.", filename);
return false;
}
//check it is the same size as the image
if(alphaWidth!=width || alphaHeight!=height)
{
errorLog.OutputError("%s is not the same size as the color texture", filename);
return false;
}
//make space for palette
unsigned char * palette=new unsigned char[256*3];
if(!palette)
{
errorLog.OutputError("Unable to allocate memory for palette");
return false;
}
//load the palette
fread(palette, 256*3, 1, file);
//we dont use the palette
delete [] palette;
palette=NULL;
//allocate space for alpha values
unsigned char * values=new unsigned char[width*height];
if(!values)
{
errorLog.OutputError("Unable to allocate memory for alpha values");
return false;
}
//load indices
fread(values, 1, alphaWidth*alphaHeight, file);
//close the file
fclose(file);
//now put in the alpha data
if(format==GL_RGBA)
{
for(unsigned int i=0; i<width*height; i++)
{
data[i*4+3]=values[i];
}
}
else if(format==GL_RGB)
{
unsigned char * tempData=new unsigned char[width*height*4];
if(!tempData)
{
errorLog.OutputError("Unable to allocate memory for Temporary Data");
return false;
}
for(unsigned int i=0; i<width*height; i++)
//.........这里部分代码省略.........