void Font::buildAtlas(ResourceData data) { if(FT_New_Memory_Face(sLibrary, data.ptr.get(), data.length, 0, &face)) { LOG(LogError) << "Error creating font face!"; return; } //FT_Set_Char_Size(face, 0, size * 64, getDpiX(), getDpiY()); FT_Set_Pixel_Sizes(face, 0, mSize); //find the size we should use FT_GlyphSlot g = face->glyph; int w = 0; int h = 0; /*for(int i = 32; i < 128; i++) { if(FT_Load_Char(face, i, FT_LOAD_RENDER)) { fprintf(stderr, "Loading character %c failed!\n", i); continue; } w += g->bitmap.width; h = std::max(h, g->bitmap.rows); }*/ //the max size (GL_MAX_TEXTURE_SIZE) is like 3300 w = 2048; h = 512; textureWidth = w; textureHeight = h; //create the texture glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL); //copy the glyphs into the texture int x = 0; int y = 0; int maxHeight = 0; for(int i = 32; i < 128; i++) { if(FT_Load_Char(face, i, FT_LOAD_RENDER)) continue; //prints rendered texture to the console /*std::cout << "uploading at x: " << x << ", w: " << g->bitmap.width << " h: " << g->bitmap.rows << "\n"; for(int k = 0; k < g->bitmap.rows; k++) { for(int j = 0; j < g->bitmap.width; j++) { if(g->bitmap.buffer[g->bitmap.width * k + j]) std::cout << "."; else std::cout << " "; } std::cout << "\n"; }*/ if(x + g->bitmap.width >= textureWidth) { x = 0; y += maxHeight + 1; //leave one pixel of space between glyphs maxHeight = 0; } if(g->bitmap.rows > maxHeight) maxHeight = g->bitmap.rows; glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, g->bitmap.width, g->bitmap.rows, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer); charData[i].texX = x; charData[i].texY = y; charData[i].texW = g->bitmap.width; charData[i].texH = g->bitmap.rows; charData[i].advX = (float)g->metrics.horiAdvance / 64.0f; charData[i].advY = (float)g->metrics.vertAdvance / 64.0f; charData[i].bearingX = (float)g->metrics.horiBearingX / 64.0f; charData[i].bearingY = (float)g->metrics.horiBearingY / 64.0f; if(charData[i].texH > mMaxGlyphHeight) mMaxGlyphHeight = charData[i].texH; x += g->bitmap.width + 1; //leave one pixel of space between glyphs } glBindTexture(GL_TEXTURE_2D, 0); FT_Done_Face(face); if((y + maxHeight) >= textureHeight) { //failed to create a proper font texture LOG(LogWarning) << "Font \"" << mPath << "\" with size " << mSize << " exceeded max texture size! Trying again..."; //try a 3/4th smaller size and redo initialization fontScale *= 1.25f; mSize = (int)(mSize * (1.0f / fontScale)); deinit(); init(data); }else{ LOG(LogInfo) << "Created font \"" << mPath << "\" with size " << mSize << ". textureID: " << textureID; } }
int main(void) { init(); app_event_loop(); deinit(); }
ServiceRepository::~ServiceRepository() { LOG4CPLUS_TRACE_METHOD(mLogger, __PRETTY_FUNCTION__ ); deinit(); }
PersistentStore::~PersistentStore() { deinit(); }
// -------- begin of function Music::init ---------// // note : call Music::init after audio.init void Music::init() { deinit(); init_flag = audio.init_flag; }
GPGWrapper::~GPGWrapper() { deinit(); }
//------- Begin of function SpyArray::~SpyArray ----------// // SpyArray::~SpyArray() { deinit(); }
CShader::~CShader() { printf("[%i] Deleting shader object\n", program_ref); fragment_ref = vertex_ref = program_ref = -1; deinit(); }
// --------- Begin of function Projectile::~Projectile --------// Projectile::~Projectile() { deinit(); }
bool REACConnection::initWithInterface(IOWorkLoop *workLoop_, ifnet_t interface_, REACMode mode_, reac_connection_callback_t connectionCallback_, reac_samples_callback_t samplesCallback_, reac_get_samples_callback_t getSamplesCallback_, void *cookieA_, void *cookieB_, UInt8 inChannels_, UInt8 outChannels_) { dataStream = NULL; deviceInfo = NULL; filterCommandGate = NULL; workLoop = NULL; timerEventSource = NULL; interface = NULL; if (NULL == workLoop_) { goto Fail; } workLoop = workLoop_; workLoop->retain(); // Add the command gate to the workloop filterCommandGate = IOCommandGate::commandGate(this, (IOCommandGate::Action)filterCommandGateMsg); if (NULL == filterCommandGate || (workLoop->addEventSource(filterCommandGate) != kIOReturnSuccess) ) { IOLog("REACConnection::initWithInterface() - Error: Can't create or add commandGate\n"); goto Fail; } // Add the timer event source to the workloop connectionCounter = 0; lastSeenConnectionCounter = 0; timerEventSource = IOTimerEventSource::timerEventSource(this, (IOTimerEventSource::Action)&REACConnection::timerFired); if (NULL == timerEventSource) { IOLog("REACConnection::initWithInterface() - Error: Failed to create timer event source.\n"); goto Fail; } // Hack: Pretend to be connected immediately deviceInfo = (REACDeviceInfo*) IOMalloc(sizeof(REACDeviceInfo)); if (NULL == deviceInfo) { IOLog("REACConnection::initWithInterface() - Error: Failed to allocate device info object.\n"); goto Fail; } deviceInfo->addr[0] = 0x00; deviceInfo->addr[1] = 0x40; deviceInfo->addr[2] = 0xab; deviceInfo->addr[3] = 0xc4; deviceInfo->addr[4] = 0x80; deviceInfo->addr[5] = 0xf6; deviceInfo->in_channels = 16; deviceInfo->out_channels = 8; started = false; connected = false; lastCounter = 0; lastSeenConnectionCounter = 0; lastSentAnnouncementCounter = 0; splitAnnouncementCounter = 0; connectionCallback = connectionCallback_; samplesCallback = samplesCallback_; getSamplesCallback = getSamplesCallback_; cookieA = cookieA_; cookieB = cookieB_; mode = mode_; inChannels = inChannels_; outChannels = outChannels_; dataStream = REACDataStream::withConnection(this); // mode has to be set before this is called. if (NULL == dataStream) { goto Fail; } ifnet_reference(interface_); interface = interface_; if (kIOReturnSuccess != REACConnection::getInterfaceMacAddress(interface, interfaceAddr, sizeof(interfaceAddr))) { IOLog("REACConnection::initWithInterface() - Error: Failed to get interface address.\n"); goto Fail; } // TODO This is a hack. It seems to be needless though. //static const UInt8 counterfeitMac[] = { // 0x00, 0x40, 0xab, 0xc4, 0xb7, 0x58 //}; //memcpy(interfaceAddr, counterfeitMac, sizeof(interfaceAddr)); // Calculate our timeout in nanosecs, taking care to keep 64bits if (REAC_MASTER == mode_) { timeoutNS = 1000000000; timeoutNS /= REAC_PACKETS_PER_SECOND; } else { timeoutNS = REAC_CONNECTION_CHECK_TIMEOUT_MS; timeoutNS *= 1000000; } // Hack: Announce connect if (REAC_MASTER == mode) { if (NULL != connectionCallback) { connectionCallback(this, &cookieA, &cookieB, deviceInfo); } } return true; Fail: deinit(); return false; }
GameOfLife::~GameOfLife(){ // be sure to free up the memory we took deinit(); }
void REACConnection::free() { deinit(); super::free(); }
ScriptManager::~ScriptManager() { try { deinit(); } catch (...) { } }
/* * periodic update to handle vehicle timeouts and trigger collision detection */ void AP_ADSB::update(void) { // update _my_loc if (!_ahrs.get_position(_my_loc)) { _my_loc.zero(); } if (!_enabled) { if (in_state.vehicle_list != nullptr) { deinit(); } // nothing to do return; } else if (in_state.vehicle_list == nullptr) { init(); return; } else if (in_state.list_size != in_state.list_size_param) { deinit(); return; } uint32_t now = AP_HAL::millis(); // check current list for vehicles that time out uint16_t index = 0; while (index < in_state.vehicle_count) { // check list and drop stale vehicles. When disabled, the list will get flushed if (now - in_state.vehicle_list[index].last_update_ms > VEHICLE_TIMEOUT_MS) { // don't increment index, we want to check this same index again because the contents changed // also, if we're disabled then clear the list delete_vehicle(index); } else { index++; } } if (_my_loc.is_zero()) { // if we don't have a GPS lock then there's nothing else to do return; } if (out_state.chan < 0) { // if there's no transceiver detected then do not set ICAO and do not service the transceiver return; } // ensure it's positive 24bit but allow -1 if (out_state.cfg.ICAO_id_param <= -1 || out_state.cfg.ICAO_id_param > 0x00FFFFFF) { // icao param of -1 means static information is not sent, transceiver is assumed pre-programmed. // reset timer constantly so it never reaches 10s so it never sends out_state.last_config_ms = now; } else if (out_state.cfg.ICAO_id == 0 || out_state.cfg.ICAO_id_param_prev != out_state.cfg.ICAO_id_param) { // if param changed then regenerate. This allows the param to be changed back to zero to trigger a re-generate if (out_state.cfg.ICAO_id_param == 0) { out_state.cfg.ICAO_id = genICAO(_my_loc); } else { out_state.cfg.ICAO_id = out_state.cfg.ICAO_id_param; } out_state.cfg.ICAO_id_param_prev = out_state.cfg.ICAO_id_param; set_callsign("PING", true); GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_INFO, "ADSB: Using ICAO_id %d and Callsign %s", out_state.cfg.ICAO_id, out_state.cfg.callsign); out_state.last_config_ms = 0; // send now } // send static configuration data to transceiver, every 10s if (out_state.chan_last_ms > 0 && now - out_state.chan_last_ms > ADSB_CHAN_TIMEOUT_MS) { // haven't gotten a heartbeat health status packet in a while, assume hardware failure // TODO: reset out_state.chan out_state.chan = -1; GCS_MAVLINK::send_statustext_all(MAV_SEVERITY_ERROR, "ADSB: Transceiver heartbeat timed out"); } else if (out_state.chan < MAVLINK_COMM_NUM_BUFFERS) { mavlink_channel_t chan = (mavlink_channel_t)(MAVLINK_COMM_0 + out_state.chan); if (now - out_state.last_config_ms >= 5000 && HAVE_PAYLOAD_SPACE(chan, UAVIONIX_ADSB_OUT_CFG)) { out_state.last_config_ms = now; send_configure(chan); } // last_config_ms // send dynamic data to transceiver at 5Hz if (now - out_state.last_report_ms >= 200 && HAVE_PAYLOAD_SPACE(chan, UAVIONIX_ADSB_OUT_DYNAMIC)) { out_state.last_report_ms = now; send_dynamic_out(chan); } // last_report_ms } // chan_last_ms }
Font::~Font() { LOG(LogInfo) << "Destroying font \"" << mPath << "\" with size " << mSize << "."; deinit(); }
void manager::update_font_path() const { deinit(); init(); }
void Font::unload(const ResourceManager& rm) { deinit(); }
AudioManager::~AudioManager() { deinit(); }
void JNL_HTTPGet::connect(char *url) { deinit(); m_http_url=(char*)malloc(strlen(url)+1); strcpy(m_http_url,url); do_parse_url(m_http_url,&m_http_host,&m_http_port,&m_http_request, &m_http_lpinfo); strcpy(m_http_url,url); if (!m_http_host || !m_http_host[0] || !m_http_port) { m_http_state=-1; seterrstr("invalid URL"); return; } int sendbufferlen=0; if (!m_http_proxyhost || !m_http_proxyhost[0]) { sendbufferlen += 4 /* GET */ + strlen(m_http_request) + 9 /* HTTP/1.0 */ + 2; } else { sendbufferlen += 4 /* GET */ + strlen(m_http_url) + 9 /* HTTP/1.0 */ + 2; if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) { sendbufferlen+=58+strlen(m_http_proxylpinfo)*2; // being safe here } } sendbufferlen += 5 /* Host: */ + strlen(m_http_host) + 2; if (m_http_lpinfo&&m_http_lpinfo[0]) { sendbufferlen+=46+strlen(m_http_lpinfo)*2; // being safe here } if (m_sendheaders) sendbufferlen+=strlen(m_sendheaders); char *str=(char*)malloc(sendbufferlen+1024); if (!str) { seterrstr("error allocating memory"); m_http_state=-1; } if (!m_http_proxyhost || !m_http_proxyhost[0]) { wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_request); } else { wsprintf(str,"GET %s HTTP/1.0\r\n",m_http_url); } wsprintf(str+strlen(str),"Host: %s\r\n",m_http_host); if (m_http_lpinfo&&m_http_lpinfo[0]) { strcat(str,"Authorization: Basic "); do_encode_mimestr(m_http_lpinfo,str+strlen(str)); strcat(str,"\r\n"); } if (m_http_proxylpinfo&&m_http_proxylpinfo[0]) { strcat(str,"Proxy-Authorization: Basic "); do_encode_mimestr(m_http_proxylpinfo,str+strlen(str)); strcat(str,"\r\n"); } if (m_sendheaders) strcat(str,m_sendheaders); strcat(str,"\r\n"); int a=m_recvbufsize; if (a < 4096) a=4096; m_con=new JNL_Connection(m_dns,strlen(str)+4,a); if (m_con) { if (!m_http_proxyhost || !m_http_proxyhost[0]) { m_con->connect(m_http_host,m_http_port); } else { m_con->connect(m_http_proxyhost,m_http_proxyport); } m_con->send_string(str); } else { m_http_state=-1; seterrstr("could not create connection object"); } free(str); }
DynArray::~DynArray() { deinit(); }
int main() { int exit = 0; MAP* map = load_map("zaza.wad"); VEC2F vp = vec2f(-6.f, -232.f); float ang = 1.6, move_speed = 200.f, rot_speed = 2.5f; init(); int i; for(i = 0; i < RANDOM_COLOR_NUM; ++i) random_colors[i] = makecol(rand() % 156 + 100, rand() % 156 + 100, rand() % 156 + 100); clock_t last_clock = clock(); int baz = 0; while(!exit) { clock_t now = clock(); float dt = (float)(now - last_clock) / CLOCKS_PER_SEC; last_clock = now; VEC2F view_dir = vec2f(cos(ang), sin(ang)); VEC2F view_dir_norm = vec2f(-view_dir.y, view_dir.x); if(key[KEY_ESC]) exit = 1; if(key[KEY_S]) vp = vec2f_sum(vp, vec2f_uscale(view_dir, -move_speed * dt)); if(key[KEY_W]) vp = vec2f_sum(vp, vec2f_uscale(view_dir, move_speed * dt)); if(key[KEY_A]) vp = vec2f_sum(vp, vec2f_uscale(view_dir_norm, -move_speed * dt)); if(key[KEY_D]) vp = vec2f_sum(vp, vec2f_uscale(view_dir_norm, move_speed * dt)); if(key[KEY_LEFT]) ang -= rot_speed * dt; if(key[KEY_RIGHT]) ang += rot_speed * dt; //printf("(%f, %f) %f | %d\n", vp.x, vp.y, ang, mouse_x / 2); clear_to_color(buffer, makecol(64, 64, 64)); SECTOR* s = find_sector(map, map->node_num - 1, vp); float h = s->floor_height - 45; int i = 0; for(i = 0; i < H_RES; ++i) { float t = i - H_RES / 2; float u = FOCAL_DIST; VEC2F ray_dir = vec2f_sum(vec2f_uscale(view_dir, u), vec2f_uscale(view_dir_norm, t)); //vec2f(view_dir.x * FOCAL_DIST + view_dir_norm.x * t, view_dir.y * FOCAL_DIST + view_dir_norm.y * t); float ray_len = sqrt(ray_dir.x * ray_dir.x + ray_dir.y * ray_dir.y); ray_dir.x /= ray_len; ray_dir.y /= ray_len; int minh = 0; int maxh = SCREEN_H; render_col(buffer, map, map->node_num - 1, vp, h, ray_dir, i, &minh, &maxh); printf("\n"); //line(buffer, SCREEN_W / 2, SCREEN_H / 2, SCREEN_W / 2 + ray_dir.x * 200, SCREEN_H / 2 + ray_dir.y * 200, makecol(255, 255, 255)); } if(key[KEY_TAB]) for(i = 0; i < map->seg_num; ++i) { VERTEX v1t = map->vertexes[map->segs[i].v1_idx]; VERTEX v2t = map->vertexes[map->segs[i].v2_idx]; VEC2F v1 = vec2f(v1t.x, v1t.y); VEC2F v2 = vec2f(v2t.x, v2t.y); VEC2F mid = vec2f((v1.x + v2.x) / 2, (v1.y + v2.y) / 2); VEC2F n = normalized_normal(vec2f_diff(v2, v1)); float scl = 1.f / 2.f; line(buffer, v1.x*scl + SCREEN_W / 2, v1.y*scl + SCREEN_H / 2, v2.x*scl + SCREEN_W / 2, v2.y*scl + SCREEN_H / 2, makecol(255, 255, 255)); circlefill(buffer, (int)vp.x*scl + SCREEN_W/2, (int)vp.y*scl +SCREEN_H/2, 3, makecol(255, 255, 255)); line(buffer, SCREEN_W/2+ mid.x*scl, SCREEN_H/2 + mid.y*scl, SCREEN_W/2+ (mid.x + n.x * 10)*scl, SCREEN_H/2+ (mid.y + n.y * 10)*scl, makecol(255, 255, 255)); line(buffer, SCREEN_W/2+vp.x*scl, SCREEN_H/2+vp.y*scl, SCREEN_W/2+(vp.x+view_dir.x*100)*scl, SCREEN_H/2+(vp.y+view_dir.y*100)*scl, makecol(255, 255, 255)); } // draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); } destroy_map(map); deinit(); return 0; }END_OF_MAIN()
MakeCurrentPerfCase::~MakeCurrentPerfCase (void) { deinit(); }
// -------- begin of function Music::~Music ---------// Music::~Music() { deinit(); }
//-------- Begin of function LargeText::~LargeText ---// //! LargeText::~LargeText() { deinit(); }
inline ~Buffer() { deinit(); }
void sigint (int signum) { printf ("开户服务:即将停止。\n"); deinit (g_sockfd); exit (0); }
int main() { init(); install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,0); install_mouse(); show_mouse(screen); int x,y,j=0,i=0; BITMAP *welcome=NULL; welcome=load_bitmap("welcome.bmp",NULL); masked_blit(welcome,screen,0,0,50,0,500,500); rest (2000); while (!key[KEY_ESC]) { BITMAP *god=NULL; BITMAP *aarti=NULL; BITMAP *flower=NULL; BITMAP *exit1=NULL; BITMAP *exit2=NULL; flower=load_bitmap("flower.bmp",NULL); aarti=load_bitmap("aarti.bmp",NULL); exit1=load_bitmap("exit1.bmp",NULL); exit2=load_bitmap("exit2.bmp",NULL); god=load_bitmap("god.bmp",NULL); blit(god,screen,0,0,75,0,750,750); if((mouse_x<=150 && mouse_x>=0)&&(mouse_y<=500 && mouse_y>=400)&& (mouse_b &0x1)) { for(i=0;i<2;i++) { for(x=70;x<=450;x=x+10) { masked_blit(aarti,screen,0,0,x,200,100,100); rest(50); blit(god,screen,0,0,75,0,750,750); } for(x=450;x>=70;x=x-10) { masked_blit(aarti,screen,0,0,x,200,100,100); rest(50); blit(god,screen,0,0,75,0,750,750); }} } if((mouse_x<=300 && mouse_x>=150)&&(mouse_y<=500 && mouse_y>=400)&& (mouse_b &0x1)) { SAMPLE *bhajan; bhajan=load_sample("bhajan.wav"); play_sample(bhajan,255,127,1000,0); } if((mouse_x<=450 && mouse_x>=300)&&(mouse_y<=500 && mouse_y>=400)&& (mouse_b &0x1)) { for(i=0;i<4;i++) { y=50; for(x=100;x<=300;x=x+10) { masked_blit(flower,screen,0,0,x,y,100,100); masked_blit(flower,screen,0,0,600-x,y,100,100); masked_blit(flower,screen,0,0,100,50,100,100); masked_blit(flower,screen,0,0,500,50,100,100); int z=0; for(j=0;j<i;j++) { masked_blit(flower,screen,0,0,300+z,350+z,100,100); z=z+10; } y=y+15; rest(100); blit(god,screen,0,0,75,0,750,750); } } } if((mouse_x<=600 && mouse_x>=450)&&(mouse_y<=500 && mouse_y>=400)&& (mouse_b &0x1)) { for(x=0;x<=350;x++) { masked_blit(exit1,screen,0,0,x,0,300,700); masked_blit(exit2,screen,0,0,500-x,0,300,700); rest(1); } rest(999999); } } deinit(); return 0; }
MemoryManagerMemMap::~MemoryManagerMemMap() { deinit(); }