void FontBuilder::CacheSymbol(wchar_t s) { CacheData* data = wcache[curSize][curFace][s]; if (!data) { FT_UInt glyphIndex = FT_Get_Char_Index(curFace, s); FT_Error error = FT_Load_Glyph(curFace, glyphIndex, 0); if (error) out_error() << L"Error occured while loading a glyph" << std::endl; if (curFace->glyph->format != FT_GLYPH_FORMAT_BITMAP) { error = FT_Render_Glyph(curFace->glyph, FT_RENDER_MODE_NORMAL); if (error) out_error() << L"Error occured while rendering a glyph" << std::endl; } FT_GlyphSlot slot = curFace->glyph; data = new CacheData; data->width = slot->bitmap.width; data->height = slot->bitmap.rows; if (data->width*data->height > 0) { data->buffer = new unsigned char[data->width*data->height]; memcpy(data->buffer, slot->bitmap.buffer, data->width*data->height); } data->x_offset = slot->bitmap_left; data->y_offset = slot->bitmap_top; data->x_advance = slot->advance.x >> 6; data->y_advance = slot->advance.y >> 6; wcache[curSize][curFace][s] = data; }
void EventManager::Process() { // MonitorScope lock(monitor); // while (events.empty()) // monitor.Wait(); try { while (!events.empty()) { Event* event = events.front(); for (std::vector<Handler>::iterator i = eventHandlers[event->eventCode].begin(); i != eventHandlers[event->eventCode].end(); ++i) { (*i)(event); } events.pop(); delete event; } } catch (System::PunkException& err) { out_error() << err.ToString() << std::endl; throw; } catch (...) { out_error() << L"Defenetly unexpected error in main loop" << std::endl; throw; } }
bool CalculateNativeAxis(const float* points, int count, unsigned vertex_size, vec3& r, vec3& s, vec3& t) { // find covariance matrix mat3 c = CreateCovarianceMatrix(points, count, vertex_size); // find eigen values of the covariance matrix Math::vec3 eigen_values; if (!EigenValues(c, eigen_values)) return (out_error() << "Can't find eigen values for matrix " << c.ToString() << std::endl, false); // find eigen vectors of the covariance matrix Math::vec3 eigen_vectors[3]; if (!EigenVectors(c, eigen_values, eigen_vectors)) return (out_error() << "Can't find eigen values for matrix " << c.ToString() << " with eigen values " << eigen_values.ToString() << std::endl, false); r = eigen_vectors[0]; s = eigen_vectors[1]; t = eigen_vectors[2]; mat3 a; a.SetColumn(0, r); a.SetColumn(1, s); a.SetColumn(2, t); out_message() << "Matrix a: " << a.ToString() << std::endl; mat3 tt = a.Transposed() * c * a; out_message() << "Matrix tt: " << tt.ToString() << std::endl; return true; }
main() #endif { int iret; tree_t * restrict ptree; #if defined(TLP) ptree = tlp_atree_work; #else ptree = &tree; #endif #if defined(CSASHOGI) && defined(_WIN32) if ( argc != 2 || strcmp( argv[1], "csa_shogi" ) ) { MessageBox( NULL, "The executable image is not intended\x0d" "as an independent program file.\x0d" "Execute CSA.EXE instead.", str_myname, MB_OK | MB_ICONINFORMATION ); return EXIT_FAILURE; } #endif #if defined(USI) if ( argc == 2 && ! strcmp( argv[1], "usi" ) ) { usi_mode = usi_on; } else { usi_mode = usi_off; } #endif if ( ini( ptree ) < 0 ) { out_error( "%s", str_error ); return EXIT_SUCCESS; } for ( ;; ) { iret = main_child( ptree ); if ( iret == -1 ) { out_error( "%s", str_error ); ShutdownAll(); break; } else if ( iret == -2 ) { out_warning( "%s", str_error ); ShutdownAll(); continue; } else if ( iret == -3 ) { break; } } if ( fin() < 0 ) { out_error( "%s", str_error ); } return EXIT_SUCCESS; }
/*------------------------------------------------------------------------- * Function: parse_range * * Purpose: Tries to parse a range expression of the form `I1:I2' * where I1 and I2 are integer constants. * * Return: Success: A range object. * * Failure: &ErrorCell * * Programmer: Robb Matzke * [email protected] * Jan 3 1997 * * Modifications: * *------------------------------------------------------------------------- */ static obj_t parse_range (lex_t *f, int skipnl) { obj_t lt=NIL, rt=NIL, retval=NIL; int lo, hi; lt = parse_term (f, skipnl); if (&ErrorCell==lt) return &ErrorCell; if (TOK_COLON==lex_token (f, NULL, skipnl)) { lex_consume (f); rt = parse_term (f, skipnl); if (&ErrorCell==rt) { obj_dest (rt); return &ErrorCell; } /* * Both arguments must be integer constants. */ if (!num_isint(lt)) { out_error ("Range: left limit is not an integer constant: ", lt); obj_dest (lt); obj_dest (rt); return &ErrorCell; } if (!num_isint(rt)) { out_error ("Range: right limit is not an integer constant: ", rt); obj_dest (lt); obj_dest (rt); return &ErrorCell; } /* * The constants must be in a reasonable order. */ lo = num_int (lt); hi = num_int (rt); if (hi<lo) { out_errorn ("Range: inverted range %d:%d changed to %d:%d", lo, hi, hi, lo); lo = num_int (rt); hi = num_int (lt); } /* * Create the range object. */ lt = obj_dest (lt); rt = obj_dest (rt); retval = obj_new (C_RANGE, lo, hi); } else { retval = lt; } return retval; }
bool TerrainCell::Save(std::ostream& stream) const { stream.write((char*)&m_core, sizeof(m_core)); if (!m_name.Save(stream)) return (out_error() << "Can't save cell name" << std::endl, false); if (!m_source.Save(stream)) return (out_error() << "Can't save cell raw file name" << std::endl, false); return true; }
bool TerrainCell::Load(std::istream& stream) { stream.read((char*)&m_core, sizeof(m_core)); if (!m_name.Load(stream)) return (out_error() << "Can't load cell name" << std::endl, false); if (!m_source.Load(stream)) return (out_error() << "Can't load cell raw file name" << std::endl, false); return true; }
int main() { Virtual::Cameras::FirstPersonCameraOptions options; g_camera.reset(new Virtual::Cameras::FirstPersonCamera(options)); g_camera->SetPositionAndTarget(Math::vec3(0, 5, 5), Math::vec3(0,0,0), Math::vec3(0,1,0)); System::Window::Instance()->SetTitle(L"OpenGL Init test"); System::Mouse::Instance()->LockInWindow(false); OpenGL::Driver::Instance()->Start(); System::EventManager::Instance()->SubscribeHandler(System::EVENT_IDLE, System::EventHandler(Idle)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_DOWN, System::EventHandler(OnMouseLeftButtonDown)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_UP, System::EventHandler(OnMouseLeftButtonUp)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_MOVE, System::EventHandler(OnMouseMove)); m_quad.reset(new OpenGL::QuadObject); m_quad->Cook(2,2); rc.reset(new OpenGL::RenderContextSolid3D); OpenGL::RenderTargetBackBuffer::RenderTargetBackBufferProperties p; rt = OpenGL::Driver::Instance()->CreateRenderTarget(&p); rt->SetClearColor(0, 0, 0, 1); if (!rt) { out_error() << "Render target was not created" << std::endl; return 0; } System::Window::Instance()->Loop(); System::MegaDestroyer::Destroy(); return 0; }
void FontBuilder::SetCharSize(int width, int height) { curSize = width * 1000 + height; FT_Error error = FT_Set_Char_Size(curFace, width*64, height*64, 96, 96); if (error) out_error() << L"Can't set new char size" << std::endl; }
int main() { System::Window::Instance()->SetTitle(L"OpenGL Init test"); System::Mouse::Instance()->LockInWindow(false); OpenGL::Driver::Instance()->Start(); System::EventManager::Instance()->SubscribeHandler(System::EVENT_IDLE, System::EventHandler(Idle)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_DOWN, System::EventHandler(OnMouseLeftButtonDown)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_LBUTTON_UP, System::EventHandler(OnMouseLeftButtonUp)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_MOVE, System::EventHandler(OnMouseMove)); System::EventManager::Instance()->SubscribeHandler(System::EVENT_MOUSE_WHEEL, System::EventHandler(OnMouseWheelScroll)); OpenGL::RenderTargetBackBuffer::RenderTargetBackBufferProperties p; rt = OpenGL::Driver::Instance()->CreateRenderTarget(&p); rt->SetClearColor(0.6, 0.6, 0.6, 1); if (!rt) { out_error() << "Render target was not created" << std::endl; return 0; } CreateWorld(); System::Window::Instance()->Loop(); System::MegaDestroyer::Destroy(); return 0; }
int main(int argc, char *argv[]) { struct mer_rule *mrule; mer_rule_new(mrule); switch (parse_args(argc, argv, mrule)) { /* Error */ case -1: out_error(); break; /* Output help */ case 0: out_help(); break; /* Add rule */ case 1: return handle_cmd(CMD_ADD, mrule); /* Delete rule */ case 2: return handle_cmd(CMD_DEL, mrule); /* List rules */ case 3: out_list(); break; /* List rules */ case 4: return handle_cmd(CMD_FLUSH, mrule); default: fprintf(stderr, "Unknown parse_args() return value.\n"); return -1; } return 0; }
bool SkinMeshNode::Load(std::istream& stream) { if (!GeometryNode::Load(stream)) return (out_error() << "Can't load portal node" << std::endl, false); return true; }
HRESULT BuildPreviewGraph(ICaptureGraphBuilder2* pBuilder, IBaseFilter* pCap) { HRESULT hr = pBuilder->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pCap, nullptr, nullptr); if (FAILED(hr)) { out_error() << "Can't build preview graph" << std::endl; } return hr; }
bool LightNode::Save(std::ostream& stream) const { if (!Node::Save(stream)) return (out_error() << "Can't save light node" << std::endl, false); //if (!System::GetFactory()->SaveToStream(stream, m_light_set)) // return (out_error() << "Can't save light node" << std::endl, false); return true; }
/* * out_err -- output an error message */ void out_err(const char *file, int line, const char *func, const char *fmt, ...) { va_list ap; va_start(ap, fmt); out_error(file, line, func, "\n", fmt, ap); va_end(ap); }
bool Test() { System::Proxy<Scene::SceneGraph> scene = System::GetFactory()->CreateFromTextFile(System::Environment::Instance()->GetModelFolder() + L"skin_test3.pmd"); if (!scene.IsValid()) return (out_error() << "Unable to create world from file" << std::endl, false); Scene::DefaultVisitor v; scene->GetRootNode()->Apply(&v); return true; }
bool LightNode::Load(std::istream& stream) { if (!Node::Load(stream)) return (out_error() << "Can't load light node" << std::endl, false); //m_light_set = System::GetFactory()->LoadFromStream(stream); //if (!m_light_set.IsValid()) // return (out_error() << "Can't load light node" << std::endl, false); return true; }
int regmatch(regex_t *regex, char *call, char *pattern, char *buf, size_t buflen) { int ret = reginit(regex, pattern, buf, buflen); if (ret) { out_error("GCC plugin: failed to compile regexp: %s", buf); return ret; } return regexec(regex, call, 0, NULL, 0); }
HRESULT CreateFilter(IGraphBuilder* pGraph, IMoniker* pMoniker, IBaseFilter** pCap) { *pCap = NULL; HRESULT hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&pCap); if (SUCCEEDED(hr)) { hr = pGraph->AddFilter(*pCap, L"Capture Filter"); if (FAILED(hr)) { out_error() << "Can't add filter to graph builder" << std::endl; } } return hr; }
void CreateWorld() { Virtual::Cameras::FirstPersonCameraOptions options; g_camera.reset(new Virtual::Cameras::FirstPersonCamera(options)); g_camera->SetPositionAndTarget(Math::vec3(0, 5, 5), Math::vec3(0,0,0), Math::vec3(0,1,0)); Utility::WorldDesc world_desc; if (!Utility::Parser::LoadWorld(System::Environment::Instance()->GetModelFolder() + L"navi_mesh_test.pmd", world_desc)) { out_error() << "Can't load world descriptor from file" << std::endl; exit(-1); } g_world.reset(new Virtual::World(world_desc)); }
static int get_node_type( Node_p node_ptr, int tr ) {/* Init get_node_type */ int ret_value = UNKNOWN; int pl = GET_PLACE_INDEX(node_ptr); if(IS_NEUTRAL(pl)) {/* Posto neutro */ ret_value = PROJECTION; }/* Posto neutro */ else {/* Posto colorato */ Coeff_p c_ptr = NULL; for(c_ptr = node_ptr->arcfun; c_ptr != NULL ; c_ptr = c_ptr->next) {/* Per ogni tupla della C.L. */ if(c_ptr->guard != NULL) {/* Funzione con predicati */ ret_value = GUARDED; goto ret; }/* Funzione con predicati */ }/* Per ogni tupla della C.L. */ if(node_ptr->arcfun->next != NULL) {/* Normale C.L */ ret_value = COMPLEX; }/* Normale C.L */ else {/* Una sola tupla di funzioni */ ret_value = get_tuple_type(node_ptr->arcfun,tr,pl); }/* Una sola tupla di funzioni */ }/* Posto colorato */ ret: switch(ret_value) {/* Tipo di funzione */ #ifdef FLUSH_FUNCTION case FLUSH_TYPE : #endif case ONLY_S : case PROJECTION : case COMPLEX : case GUARDED : break; default : out_error(ERROR_UNKNOWN_FUNCTION_TYPE,pl,tr,0,0,NULL,NULL); }/* Tipo di funzione */ return(ret_value); }/* End get_node_type */
void out_ip_pcap_file(const uint8_t *pkt, size_t caplen, size_t len, const struct timeval *tv) { /* From pcap-int.h, which is not present on some systems, * and written in the stone of uncounted saved pcap files. */ struct { struct { int32_t tv_sec; int32_t tv_usec; } ts; /* time stamp */ bpf_u_int32 caplen; /* length of portion present */ bpf_u_int32 len; /* length this packet (off wire) */ } sf_hdr; if (caplen > sizeof(out_buf) - sizeof(sf_hdr) - out_buf_len || out_buf_base != 0) { out_flush(); if (caplen > sizeof(out_buf) - sizeof(sf_hdr) - out_buf_len) { out_error("forwarding output stalled; dropping"); return; } } /* Use the official version of struct pcap_sf_pkthdr and hope * even the "experts" with "patched" versions can handle the * standard form. */ sf_hdr.ts.tv_sec = tv->tv_sec; sf_hdr.ts.tv_usec = tv->tv_usec; sf_hdr.caplen = caplen; sf_hdr.len = len; memcpy(&out_buf[out_buf_len], &sf_hdr, sizeof(sf_hdr)); out_buf_len += sizeof(sf_hdr); memcpy(&out_buf[out_buf_len], pkt, caplen); out_buf_len += caplen; if (time_out_flush.tv_sec == 0) gettimeofday(&time_out_flush, NULL); }
MYSQL_RES *quiry(char *sql) { MYSQL *conn; MYSQL_RES *res; // char *db_str = "4A0ED31A14743F2AD9AC39F7E09AD9EF"; char *db_str = "9A7767579A6435E1216E7F852C8FCFD7"; char *db_pawd; // char *ip = "192.168.56.101"; char *ip = "10.10.3.207"; int port = 3306; db_pawd = aes_dec(db_str, 0); conn = mysql_init(NULL); if (!(mysql_real_connect(conn, ip, "root", db_pawd, "web_check", port, NULL, 0))) { if (mysql_error(conn)) fprintf(stderr, "connection error %d : %s\n", mysql_errno(conn), mysql_error(conn)); out_error("Fail to connect mysql, ip:%s\tport:%d\n", ip, port); } // 查询数据库 if (mysql_query(conn,sql)) { fprintf(stderr, "查询失败\n"); return NULL; } // 生成结果集 if (!(res=mysql_store_result(conn))) { fprintf(stderr, "结果集生成失败\n"); return NULL; } mysql_close(conn); return res; }
void Test::Run() { m_result = true; try { TestApp* app = new TestApp; Punk::Config cfg; cfg.gpu_config.view_width = 800; cfg.gpu_config.view_height = 600; app->Init(cfg); System::Mouse::Instance()->LockInWindow(false); app->Run(); delete app; } catch(System::PunkException& e) { out_error() << e.ToString() << std::endl; m_result = false; } catch(...) { m_result = false; } }
/* forward watch hits as NMSG messages */ bool out_whit_nmsg(axa_p_whit_t *whit, size_t whit_len) { nmsg_message_t msg; struct timespec ts; static const union { uint e; uint8_t c[0]; } pkt_enum = { .e = NMSG__BASE__PACKET_TYPE__IP }; size_t len; struct timeval now; nmsg_res res; bool result; switch ((axa_p_whit_enum_t)whit->hdr.type) { case AXA_P_WHIT_NMSG: /* pass NMSG messages along */ if (whit2nmsg(&msg, whit, whit_len) == AXA_W2N_RES_FRAGMENT) { if (axa_debug != 0) printf("ignoring NMSG fragment from " AXA_OP_CH_PREFIX"%d", AXA_P2H_CH(whit->hdr.ch)); return (false); } if (msg == NULL) return (false); break; case AXA_P_WHIT_IP: /* Convert raw IP packets to nmsg BASE_PACKET */ len = whit_len - sizeof(whit->ip.hdr); if (AXA_P2H32(whit->ip.hdr.ip_len) != len) return (false); /* Ignore incomplete packets. */ if (!out_nmsg_mod_checked) { out_nmsg_mod_checked = true; out_nmsg_mod = nmsg_msgmod_lookup(NMSG_VENDOR_BASE_ID, NMSG_VENDOR_BASE_PACKET_ID); if (out_nmsg_mod == NULL) { out_error("cannot get BASE_PACKET module"); return (false); } res = nmsg_msgmod_init(out_nmsg_mod, &out_nmsg_clos); if (res != nmsg_res_success) { out_error("cannot init BASE_PACKET module"); out_nmsg_mod = NULL; return (false); } } if (out_nmsg_mod == NULL) { out_error("cannot forward IP as NMSG messages" " without PACKET nmsg_msgmod"); return (false); } msg = nmsg_message_init(out_nmsg_mod); AXA_ASSERT(msg != NULL); res = nmsg_message_set_field(msg, "payload_type", 0, pkt_enum.c, sizeof(pkt_enum)); AXA_ASSERT(res == nmsg_res_success); res = nmsg_message_set_field(msg, "payload", 0, whit->ip.b, len); AXA_ASSERT(res == nmsg_res_success); ts.tv_sec = AXA_P2H32(whit->ip.hdr.tv.tv_sec); ts.tv_nsec = AXA_P2H32(whit->ip.hdr.tv.tv_usec) * 1000; nmsg_message_set_time(msg, &ts); break; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunreachable-code" default: out_error("cannot forward SRA #%d messages as NMSG messages", whit->hdr.type); return (false); #pragma clang diagnostic pop } res = nmsg_output_write(out_nmsg_output, msg); if (res == nmsg_res_success) { result = true; } else { result = false; gettimeofday(&now, NULL); if (out_sock_type != SOCK_DGRAM || res != nmsg_res_errno || !AXA_IGNORED_UDP_ERRNO(errno)) { /* Stop on non-UDP errors. */ clear_prompt(); error_msg("nmsg_output_write(): %s", nmsg_res_lookup(res)); out_close(false); disconnect(true); } else if (output_errno != errno || 60*1000 <= axa_elapsed_ms(&now, &output_errno_time) || axa_debug >= AXA_DEBUG_TRACE) { /* Report occasional identical UDP errors. */ output_errno = errno; gettimeofday(&output_errno_time, NULL); clear_prompt(); error_msg("nmsg_output_write(): %s", strerror(output_errno)); } } nmsg_message_destroy(&msg); if (time_out_flush.tv_sec == 0) gettimeofday(&time_out_flush, NULL); return (result); }
bool TerrainRawDataSource::Load(std::istream& stream) { if (!m_raw_file.Load(stream)) return (out_error() << "Can't load terrain raw data source" << std::endl, false); return true; }
bool SkinMeshNode::Save(std::ostream& stream) const { if (!GeometryNode::Save(stream)) return (out_error() << "Can't save portal node" << std::endl, false); return true; }
void Test::Run() { m_result = true; try { System::string string("Hello this world"); std::wcout << string << std::endl; System::string s2(L" bad Hello bad world bad "); std::wcout << s2 << std::endl; s2 = s2.Replace("bad", "AmazIng"); std::wcout << s2 << std::endl; s2 = s2.Trim(" "); std::wcout << s2 << std::endl; if (s2 != s2) throw; std::wcout << s2.ToLower() << std::endl; System::string s3(L"Vitaju Šanoŭnaje spadarstva!"); std::wcout << s3 << std::endl; std::wcout << s3.ToLower() << std::endl; std::wcout << System::string::Convert(24) << std::endl; std::wcout << System::string::Convert(true) << std::endl; std::wcout << System::string::Convert(L'Q') << std::endl; long double ld = 1.45; std::wcout << System::string::Convert(ld) << std::endl; std::wcout << System::string::Convert((double)ld) << std::endl; std::wcout << System::string::Convert((float)ld) << std::endl; std::wcout << System::string::Convert((uint16_t)0xeaff) << std::endl; std::wcout << s2 + s3 << std::endl; std::wcout << "Split: " << s2 << std::endl; auto v = s2.Split(" "); for (auto e : v) { std::wcout << e << std::endl; } std::wcout << "s2 size: " << s2.Size() << std::endl; std::wcout << "s2 length: " << s2.Length() << std::endl; { System::string s("The value is {0} and {1}"); int8_t p = 13; std::wcout << s.arg(p).arg(p/2) << std::endl; } { System::string s = L"Hełło world šæźžćđš¶ŧŋ"; std::ofstream stream("test.string"); //s.Save(stream); } { std::ifstream stream("test.string"); System::string s; //s.Load(stream); std::wcout << s << std::endl; } } catch(System::PunkException& e) { out_error() << e.ToString() << std::endl; m_result = false; } catch(...) { m_result = false; } }
bool TerrainRawDataSource::Save(std::ostream& stream) const { if (!m_raw_file.Save(stream)) return (out_error() << "Can't save terrain raw data source" << std::endl, false); return true; }
/* * === FUNCTION ====================================================================== * Name: error * Description: * ===================================================================================== */ void error () { out_error("Invalid function", EXIT_FAILURE); } /* ----- end of function error ----- */