void addr_is_invalid(string s1) { auto fun1 = [=]() { auto a1 = c_haship_addr(c_haship_addr::tag_constr_by_addr_dot(), s1); _UNUSED(a1); }; EXPECT_THROW( fun1() , std::invalid_argument); }
// Fired after all test activities have ended. void TestsEnvReseter::OnTestProgramEnd(const ::testing::UnitTest& unit_test) { _UNUSED(unit_test); g_dbg_level_set(40, "Show again some debug after the tests"); auto skipped = instance().m_count_tests_skipped; if (skipped>0) { std::cout << banner_skip() << " Tests skipped: " << skipped << "." << std::endl; _warn("Skipped some tests."); } else std::cout << "(No tests were skipped, this is good)" << std::endl; std::cout << std::endl; }
/* * call-seq: * Redleaf::Graph.model_types -> hash * * Return a hash describing all model types supported by the underlying Redland * library. * */ static VALUE rleaf_redleaf_graph_s_model_types( VALUE klass ) { const char *name, *label; unsigned int counter = 0; VALUE rhash = rb_hash_new(); _UNUSED( klass ); rleaf_log( "debug", "Enumerating graphs." ); while( (librdf_model_enumerate(rleaf_rdf_world, counter, &name, &label)) == 0 ) { rleaf_log( "debug", " graph [%d]: name = '%s', label = '%s'", counter, name, label ); rb_hash_aset( rhash, rb_str_new2(name), rb_str_new2(label) ); counter++; } rleaf_log( "debug", " got stuff for %d graphs.", counter ); return rhash; }
void c_peering_udp::send_data_RAW_udp(const char * data, size_t data_size, int udp_socket) { _UNUSED(udp_socket); _info("UDP send to peer RAW. To IP: " << m_peering_addr << ", RAW-DATA: " << to_debug_b(std::string(data,data_size)) ); //#ifdef __linux__ switch (m_peering_addr.get_ip_type()) { case c_ip46_addr::t_tag::tag_ipv4 : { m_udp_wrapper.get().send_data(m_peering_addr, data, data_size); } break; case c_ip46_addr::t_tag::tag_ipv6 : { m_udp_wrapper.get().send_data(m_peering_addr, data, data_size); } break; default: { std::ostringstream oss; oss << m_peering_addr; // TODO _throw_error( std::runtime_error(string("Invalid IP type (when trying to send RAW udp): ") + oss.str()) ); } } //#endif }
void c_node::draw_allegro (c_drawtarget &drawtarget, c_layer &layer_any) { auto layer = dynamic_cast<c_layer_allegro&>(layer_any); BITMAP *frame = layer.m_frame; const auto & gui = * drawtarget.m_gui; const int vx = gui.view_x(m_x), vy = gui.view_y(m_y); // position in viewport - because camera position c_osi2_switch::draw_allegro (drawtarget, layer_any); auto color = makecol(0,0,64); // TODO is this ok? _UNUSED(color); //////////////////////////////////////////////////////////////////// if (layer.m_layer_nr == e_layer_nr_object) { //BITMAP *fg1; //const char *file1; //file1 = "dat/server_48x48.png"; //set_color_conversion(COLORCONV_NONE); //fg1 = load_png(file1, NULL); // TODO: optmize/cache and share across objects set_alpha_blender(); draw_trans_sprite(frame, c_bitmaps::get_instance().m_node, vx - c_bitmaps::get_instance().m_node->w / 2, vy - c_bitmaps::get_instance().m_node->h / 2); } //////////////////////////////////////////////////////////////////// }
/* * call-seq: * Redleaf::Graph.serializers -> hash * * The serializers supported by the underlying Redland library. * Returns the hash describing the supported serializers, keyed by name. * * Redleaf::Graph.serializers * # => { * # "html"=> { * # :mime_types=> [ * # {:q=>10, :name=>"application/xhtml+xml"}, * # {:q=>10, :name=>"text/html"}, * # ], * # :uris=>["http://www.w3.org/1999/xhtml"], * # :aliases=>[], * # :flags=>0, * # }, * # "nquads"=> { * # :mime_types=>[{:q=>10, :name=>"text/x-nquads"}], * # :uris=>["http://sw.deri.org/2008/07/n-quads/#n-quads"], * # :aliases=>[], * # :flags=>0, * # }, * # ... * # } */ static VALUE rleaf_redleaf_graph_s_serializers( VALUE klass ) { const raptor_syntax_description *desc; unsigned int counter = 0, name = 0; VALUE rhash = rb_hash_new(); VALUE deschash = Qnil; _UNUSED( klass ); rleaf_log( "debug", "Enumerating serializers." ); while ( (desc = librdf_serializer_get_description(rleaf_rdf_world, counter)) != NULL ) { deschash = rb_hash_new(); rleaf_log( "debug", " serializer [%d]: name = '%s', desc = '%s'", counter, desc->names[0], desc->label ); deschash = rleaf_raptor_syntax_desc_to_hash( desc ); rb_hash_aset( rhash, rb_str_new2(desc->names[0]), deschash ); counter++; } rleaf_log( "debug", " got %d serializers.", counter ); return rhash; }
c_udp_wrapper_empty::c_udp_wrapper_empty(const int listen_port) { _UNUSED(listen_port); }
size_t c_tun_device_empty::write_to_tun(const void *buf, size_t count) { _UNUSED(buf); _UNUSED(count); return 0; }
size_t c_tun_device_empty::read_from_tun(void *buf, size_t count) { _UNUSED(buf); _UNUSED(count); return 0; }
void c_tun_device_empty::set_mtu(uint32_t mtu) { _warn("Called set_mtu on empty device"); _UNUSED(mtu); }
void c_tun_device_empty::set_ipv6_address(const std::array<uint8_t, 16> &binary_address, int prefixLen) { _UNUSED(binary_address); _UNUSED(prefixLen); }
void __hlt_memory_nullbuffer_add(__hlt_memory_nullbuffer* nbuf, const hlt_type_info* ti, void* obj, hlt_execution_context* ctx) { int64_t nbpos = _nullbuffer_index(nbuf, obj); if ( nbuf->flush_pos >= 0 ) { // We're flushing. if ( nbpos == nbuf->flush_pos ) // Deleting this right now. return; if ( nbpos > nbuf->flush_pos ) // In the buffer, and still getting there. return; // Either not yet in the buffer, or we passed it already. Delete // directly, we must not further modify the nullbuffer while flushing. #ifdef DEBUG __hlt_gchdr* hdr = (__hlt_gchdr*)obj; assert(hdr->ref_cnt <= 0); _UNUSED(hdr); #endif if ( ti->obj_dtor ) (*(ti->obj_dtor))(ti, obj, ctx); if ( nbpos >= 0 ) // Just to be safe. nbuf->objs[nbpos].obj = 0; __hlt_free(obj, ti->tag, "nullbuffer_add (during flush)"); return; } if ( nbpos >= 0 ) // Already in the buffer. return; #ifdef DEBUG __hlt_gchdr* hdr = (__hlt_gchdr*)obj; _dbg_mem_gc("nullbuffer_add", ti, hdr, "", 0, ctx); #endif if ( nbuf->used >= nbuf->allocated ) { size_t nsize = (nbuf->allocated * 2); nbuf->objs = (struct __obj_with_rtti*)hlt_realloc(nbuf->objs, sizeof(struct __obj_with_rtti) * nsize, sizeof(struct __obj_with_rtti) * nbuf->allocated); nbuf->allocated = nsize; } struct __obj_with_rtti x; x.ti = ti; x.obj = obj; nbuf->objs[nbuf->used++] = x; #ifdef DEBUG ++__hlt_globals()->num_nullbuffer; if ( nbuf->used > __hlt_globals()->max_nullbuffer ) // Not thread-safe, but doesn't matter. __hlt_globals()->max_nullbuffer = nbuf->used; #endif }
size_t c_udp_wrapper_empty::receive_data(void *data_buf, const size_t data_buf_size, c_ip46_addr &from_address) { _UNUSED(data_buf); _UNUSED(data_buf_size); _UNUSED(from_address); return 0; }
void c_udp_wrapper_empty::send_data(const c_ip46_addr &dst_address, const void *data, size_t size_of_data) { _UNUSED(dst_address); _UNUSED(data); _UNUSED(size_of_data); }
void c_entity::draw_allegro(c_drawtarget &drawtarget, c_layer &layer_any) { auto layer = dynamic_cast<c_layer_allegro &>(layer_any); BITMAP *frame = layer.m_frame; const auto & gui = * drawtarget.m_gui; const int vx = gui.view_x(m_x), vy = gui.view_y(m_y); // position in viewport - because camera position if (layer.m_layer_nr == e_layer_nr_gui_bgr) { auto selected_object = gui.m_selected_object; // iterator _UNUSED(selected_object); if (m_selected) { // if I am the selected object circle(frame, vx, vy, 50 - 5, makecol(255, 128, 32)); } // if (target_object) { // if I am the target object // circle(frame, vx, vy, 50 - 15, makecol(104, 71, 79)); // } // if (source_object) { // circle(frame, vx, vy, 50 - 15, makecol(246, 83, 86)); // } if (m_target) { // if I am the target object circle(frame, vx, vy, 50 - 15, makecol(104, 71, 79)); } if (m_source) { circle(frame, vx, vy, 50 - 15, makecol(246, 83, 86)); } // if (this == source_object.get()) { // circle(frame, vx, vy, 50 - 15, makecol(246, 83, 86)); // } } if (layer.m_layer_nr == e_layer_nr_gui) { //auto selected_object = gui.m_selected_object; if (m_selected) { // if I am the selected object //_dbg3("draw select"); const int r1 = 50 - 8, r2 = 50; const auto col1 = makecol(192, 192, 192), col2 = makecol(255, 128, 32); int nr = 0; for (double angle = 0; angle < M_PI * 2; angle += (M_PI * 2) / 16) { ++nr; line(frame, vx + sin(angle) * r1, vy + cos(angle) * r1, vx + sin(angle) * r2, vy + cos(angle) * r2, (nr % 2 ? col1 : col2)); } } } int color = makecol(255,128,0); // color1 if (layer.m_layer_nr == e_layer_nr_object) { line(frame, vx - 2, vy - 2, vx + 2, vy + 2, color); line(frame, vx - 2, vy + 2, vx + 2, vy - 2, color); circle(frame, vx, vy, 10, color); } if (layer.m_layer_nr == e_layer_nr_object_extra) { textout_ex(frame, font, m_name.c_str(), vx - 20, vy - 35, color, -1); } }
// Called before a test starts. void TestsEnvReseter::OnTestStart(const ::testing::TestInfo& test_info) { _UNUSED(test_info); g_dbg_level_set(100, "Be quiet during tests"); // test_info.test_case_name(), test_info.name()); }
void c_cable_shm_obj::send_to(const c_cable_base_addr &dest, const unsigned char *data, size_t size) { _UNUSED(dest); _UNUSED(data); _UNUSED(size); }
TEST(stdplus_misc, function_enum_to_int__enumclass) { g_dbg_level_set(150, "reduce warnings spam from tests (int_to_enum etc)"); EXPECT_NO_THROW( { auto color = int_to_enum<t_color_components>(0); _UNUSED(color); } );
int main(){ SysTick_Config(SystemCoreClock / 2000); // 0.5ms // NEED OF KEY AND LED RCC_ClockSecuritySystemCmd(ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); // Init LCD LCD_Cmd_InitFSMC(); LCD_Cmd_Init(); LCD_Cmd_InitBacklight(); // Put some background // LCD_FillRectangle_RGB565(0, 0, 240, 320, C_RGB565(0x80, 0x80, 0x80)); Painter_PutImage(res_img_res_lp_jpg,0,0,0xff); // Painter_SetupContextBitmask(240, 320, 0); // benchmark(2); // A circle to overlay long shadow LCD_FillCircle_RGB4444(120, 120, 100+18, 0x88fa); // now you can see it long_shadow(); // an alternative shadow // LCD_FillCircle(120+1, 120+1, 100+2, 0x8886, 0); // LCD_FillCircle(120, 120, 100+2, 0x8886, 0); // LCD_FillCircle(120, 120, 100+1, 0x8886, 0); // Put my clock panel on screen LCD_FillCircle_RGB565(120, 120, 100, C_RGB565(0, 0, 0)); LCD_FillCircle_RGB565(120, 120, 90, C_RGB565(0xff, 0xff, 0xff)); // Clock frame need some shadow! Painter_SetupContextBitmask(210, 210, 0); u16 x, y, i; u32 t; for (x=0;x<200;x++) for (y=0;y<200;y++){ t = (x-100)*(x-100)+(y-100)*(y-100); if ((t>=91*91)&&(t<100*100)) LCD_SetBitMask(_d_dl_ctx.bm, x, y, 210); } // Draw ticks and numbers const s8 TICK_XI[] = { 0, 42, 73, 85, 73, 42, 0, -42, -73, -85, -73, -42}; const s8 TICK_YI[] = {-85, -73, -42, 0, 42, 73, 85, 73, 42, 0, -42, -73}; const s8 TICK_XO[] = { 0, 44, 77, 90, 77, 45, 0, -44, -77, -90, -77, -45}; const s8 TICK_YO[] = {-90, -77, -45, 0, 44, 77, 90, 77, 45, 0, -44, -77}; const u16 *text[] = {res_string_0/*_FSTR_0*/, res_string_1/*_FSTR_1*/, res_string_2/*_FSTR_2*/, res_string_3/*_FSTR_3*/, res_string_4/*_FSTR_4*/, res_string_5/*_FSTR_5*/, res_string_6/*_FSTR_6*/, res_string_7/*_FSTR_7*/, res_string_8/*_FSTR_8*/, res_string_9/*_FSTR_9*/, res_string_11/*_FSTR_10*/, res_string_12/*_FSTR_11*/, res_string_13/*_FSTR_12*/ }; const u16 *col = res_string_14/*_FSTR_:*/; const u16 *space = res_string_15/*_FSTR_ */; u16 time[20]; for (i=0;i<12;i++){ Painter_LocateContextBitmask(100+TICK_XO[i], 100+TICK_YO[i]); Painter_DrawLine(120+TICK_XO[i], 120+TICK_YO[i], 120+TICK_XI[i], 120+TICK_YI[i], 0x000f, 5, PAINTER_DRAW_BM_HOLD); Painter_PutString(text[i?i:12], 14, 0x000f, 0 , 120+TICK_XI[i]-(TICK_XO[i]-TICK_XI[i])*2-5, 120+TICK_YI[i]-(TICK_YO[i]-TICK_YI[i])*2-8 , 20, 20, PAINTER_STR_SHADOW*2); } // Bravo! Painter_Fill_BitMaskShadow(30, 30, 230, 230, 0L, 10, 10, 210, 0x0008, 4, 4, 15); // LET IT RUN! u8 m, s; // so-called second and minute bitmask bm; _UNUSED(bm); s = 0; m = 0; Painter_SetupContextBitmask(200, 200, 0); // new context for new shadow Painter_LocateContextBitmask(100, 100); // start from center u8 shadow_on; u16 bg[200*60]; // grab screen region, saving for later repaint LCD_SetWindow(20, 240, 200, 60); LCD_GetImage_RGB565(bg, 200*60); while (1){ // PUSH BUTTON TO RUN REALLY FAST, WITHOUT SHADOW! shadow_on = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)?PAINTER_STR_SHADOW*2:0; LCD_FillCircle_RGB565(120, 120, 65, 0xffff); // Clear clock hands, sucks aha~ // Dont forget bitmasks for (x=30;x<170;x++) for (y=30;y<170;y++){ LCD_ResetBitMask(_d_dl_ctx.bm, x, y, 200); } // second hand u16 sh_x[] = {120, 120+(TICK_XI[_mod(s+11,12)]+3)/5, 120+TICK_XI[s]-(TICK_XO[s]-TICK_XI[s])*6, 120+(TICK_XI[_mod(s+1,12)]+3)/5 }; u16 sh_y[] = {120, 120+(TICK_YI[_mod(s+11,12)]+3)/5, 120+TICK_YI[s]-(TICK_YO[s]-TICK_YI[s])*6, 120+(TICK_YI[_mod(s+1,12)]+3)/5 }; // Center circle makes it cute~ Painter_DrawCircle(120, 120, 4, 0x6a2f, 12, PAINTER_DRAW_BM_HOLD); Painter_DrawPoly(sh_x, sh_y, 4, 0x6a2f, 3, PAINTER_DRAW_BM_HOLD | PAINTER_DRAW_POLY_CLOSE); // Painter_DrawLine(120, 120 // , 120+TICK_XI[s]-(TICK_XO[s]-TICK_XI[s])*6 // , 120+TICK_YI[s]-(TICK_YO[s]-TICK_YI[s])*6, // 0x6a2f, 5, PAINTER_DRAW_BM_HOLD); // Painter_DrawLine(120, 120 // , 120-(TICK_XI[s]+4)/8 // , 120-(TICK_YI[s]+4)/8, // 0x6a2f, 5, PAINTER_DRAW_BM_HOLD); // GET MY SHADOW! if (shadow_on) Painter_Fill_BitMaskShadow(50, 50, 190, 190, 0L, 30, 30, 200, 0x0008, 4, 4, 12); for (x=30;x<170;x++) for (y=30;y<170;y++){ LCD_ResetBitMask(_d_dl_ctx.bm, x, y, 200); } u32 mm = m % 12; // minute hand Painter_DrawLine(120, 120 , 120+TICK_XI[mm]-(TICK_XO[mm]-TICK_XI[mm])*10 , 120+TICK_YI[mm]-(TICK_YO[mm]-TICK_YI[mm])*10, 0xa22f, 5, PAINTER_DRAW_BM_HOLD); Painter_DrawLine(120, 120 , 120-(TICK_XI[mm]+4)/8 , 120-(TICK_YI[mm]+4)/8, 0xa22f, 5, PAINTER_DRAW_BM_HOLD); // Center circle makes it cute~ Painter_DrawCircle(120, 120, 3, 0xa22f, 5, PAINTER_DRAW_BM_HOLD); // GET MY SHADOW! if (shadow_on) Painter_Fill_BitMaskShadow(50, 50, 190, 190, 0L, 30, 30, 200, 0x0008, 4, 4, 12); // show time in text u16 *p = time, *q; // need some space *p++ = space[0]; mm = m?m:1; while (mm<10000) { *p++ = space[0]; mm *= 10; } //put minute digits p = itoa(m, p); *p++ = col[0]; //put second text directly q = (u16 *)(text)[s]; while (*q) *p++ = *q++; *p++ = 0; // repaint the background LCD_SetWindow(20, 240, 200, 60); LCD_PutImage_RGB565(bg, 200*60); // GET MY TIME! Painter_PutString((const u16*)time, 48, 0xffff, 0xf5b9 , 20, 240, 200, 60, shadow_on | PAINTER_STR_SFLUSH); put_fps(1); // PUSH A TO DASH! if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)) DUMMY; // TICK TOCK~ s++; if (s == 12) { m++; s = 0; } } return 0; }
void c_simulation::main_loop () { // PALETTE palette; //BITMAP *img_bgr = load_bitmap("dat/bgr-bright.tga", NULL); // TODO: s_font_allegl.reset (allegro_gl_convert_allegro_font(font,AGL_FONT_TYPE_TEXTURED,500.0), [](FONT *f){allegro_gl_destroy_font(f);}); for(auto &obj : m_world->m_objects) { obj->set_font(s_font_allegl); } int viewport_x = 0, viewport_y = 0; //show_mouse(m_screen); set_close_button_callback(c_close_button_handler); bool print_connect_line = false; bool start_simulation = false; bool simulation_pause = true; shared_ptr<c_cjddev> connect_node; std::chrono::steady_clock::time_point last_click_time = std::chrono::steady_clock::now() - std::chrono::milliseconds(1000); m_gui = make_shared<c_gui>(); // prepare drawtarget surface to draw to switch (m_drawtarget_type) { case e_drawtarget_type_allegro: m_drawtarget = make_shared<c_drawtarget_allegro>(m_frame); break; case e_drawtarget_type_opengl: m_drawtarget = make_shared<c_drawtarget_opengl>(); break; default: _erro("Warning: unsupported drawtarget"); } m_drawtarget->m_gui = m_gui; // bool allegro_keys_any_was=false; // is any key pressed right now (for key press/release) long loop_miliseconds = 0; long unsigned int frame_checkpoint = 0; /// needed for speed control (without world_draw manipulate in spacetime!) _UNUSED(frame_checkpoint); bool use_input_allegro = true; // always for now. input from Allegro bool use_draw_allegro = m_drawtarget_type == e_drawtarget_type_allegro; // draw in allegro bool use_draw_opengl = m_drawtarget_type == e_drawtarget_type_opengl; // draw in opengl _note("Entering main simulation loop"); // The main drawing is done inside this loop. ///@see rendering.txt/[[drawing_main]] float view_angle = 0.0; //float camera_offset = 1.0; float zoom = 1.0; float camera_step_z=-11.0; // === main loop === while (!m_goodbye && !close_button_pressed) { auto start_time = std::chrono::high_resolution_clock::now(); // --- process the keyboard/inputs --- if (use_input_allegro) { // TODO move this code here, but leave the variables in higher scope } poll_keyboard(); auto allegro_keys = key; auto allegro_shifts = key_shifts; // bool allegro_keys_any_is=false; // for (size_t i=0; i<sizeof(allegro_keys)/sizeof(allegro_keys[0]); ++i) allegro_keys_any_is=true; // the direct raw position const int allegro_mouse_x = mouse_x; const int allegro_mouse_y = mouse_y; const int allegro_mouse_b = mouse_b; // buttons // the position in display port GUI const int gui_mouse_x = allegro_mouse_x; const int gui_mouse_y = allegro_mouse_y; const int gui_mouse_b = allegro_mouse_b; // buttons // the position in the world coordinates const int gui_cursor_x = m_gui->view_x_rev(gui_mouse_x); const int gui_cursor_y = m_gui->view_y_rev(gui_mouse_y); const int gui_cursor_z = 0; // m_gui->view_z_rev(gui_mouse_z); _UNUSED(gui_mouse_b); _UNUSED(gui_cursor_x); _UNUSED(gui_cursor_y); _UNUSED(gui_cursor_z); //_dbg1("mouse_x mouse_y: " << gui_mouse_x << " " << gui_mouse_y); int allegro_char = 0; if (keypressed()) { allegro_char = readkey(); } // end of input // draw background of frame if (use_draw_allegro) { clear_to_color(m_frame, makecol(0, 128, 0)); blit(c_bitmaps::get_instance().m_background, m_frame, 0, 0, viewport_x, viewport_y, c_bitmaps::get_instance().m_background->w, c_bitmaps::get_instance().m_background->h); } if (use_draw_opengl) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //glDisable(GL_DEPTH_TEST); // ??? Enables Depth Testing //glEnable(GL_DEPTH_TEST); //glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //glLoadIdentity(); // glTranslatef(m_gui->camera_x, m_gui->camera_y,camera_offset); // minimum and maximum value for zoom in/out and rotate the scene // if (camera_offset >= 10.0) camera_offset = 10.0; // if (camera_offset <= 0.5) camera_offset = 0.5; if (view_angle >= 70) view_angle = 70; if(view_angle <= 0) view_angle = 0; if( zoom <= 0.1 ) zoom = 0.1; //because of glFrustum -> when left=right, or bottom=top there's error GL_INVALID_VALUE, so we can't multiply e.g left,right by 0 glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1.0*zoom, 1.0*zoom, -1.0*zoom, 1.0*zoom, 1.0,60.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glTranslatef(0.0f,0.0f,-11.0); glTranslatef(0.0f,0.0f,camera_step_z); glRotatef(-view_angle, 1,0,0); glScalef(10,10,10); // drawing backgound glPushMatrix(); //glScalef(1,1,1); glBindTexture(GL_TEXTURE_2D,c_bitmaps::get_instance().m_background_opengl); glEnable(GL_BLEND); //float q=1.0/zoom; float q=1.0; glBegin(GL_QUADS); glTexCoord2f(0,q); glVertex3f(-1.0f,1.0f, 0.0f); glTexCoord2f(q,q); glVertex3f(1.0f,1.0f, 0.0f); glTexCoord2f(q,0); glVertex3f(1.0f,-1.0f,0.0f); glTexCoord2f(0,0); glVertex3f(-1.0f,-1.0f,0.0f); glEnd(); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, 0); // texture glPopMatrix(); } // clear additional things if (use_draw_allegro) { clear_to_color(smallWindow, makecol(128, 128, 128)); } // main controll keys if (allegro_keys[KEY_ESC]) { _note("User exits the simulation from user interface"); m_goodbye = true; } if ((allegro_char & 0xff) == 'n' && !start_simulation) { std::cout << "ADD " << std::endl; _warn("THIS CODE IS NOT IMPLEMENTED NOW"); /* m_world->m_objects.push_back( make_shared<c_cjddev>( cjddev_detail_random_name(), // gui_mouse_x, gui_mouse_y, gui_cursor_x, gui_cursor_y, cjddev_detail_random_addr())); */ } if(allegro_keys[KEY_F1]){ //auto ptr = get_move_object(gui_mouse_x,gui_mouse_y); // TODO -in allegro? -not entire screen? /* try{ if(ptr != NULL){ int col_num =0; textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1); if(c_cjddev* tmp = dynamic_cast<c_cjddev *>(ptr.get()) ){ char* addr =(char *) malloc(45); sprintf(addr,"address: %ld",tmp->get_address()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); sprintf(addr,"neighbors: %d",(int)tmp->get_neighbors().size()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); sprintf(addr,"waitng: %d",(int)tmp->num_of_wating()); textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1); // textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1);{ free (addr); } if (use_draw_allegro) { // draw the information window blit (smallWindow,m_frame,0,0,m_frame->w-200,m_frame->h-200,screen->w/8, screen->h/4); } } } catch(...) {} */ // std::cout<<ptr->get_name().c_str()<<std::endl; } if(allegro_keys[KEY_F2]){ // BITMAP* screen = gui_get_screen(); int m_x =0; int m_y =0; static unsigned int num =0; if(num>=m_world->m_objects.size()){ num=0; } try{ // auto obj = m_world->m_objects.at(0); // m_x = m_world->m_objects.at(num)->get_x() - (screen->w/2); // m_y = m_world->m_objects.at(num)->get_y() - (screen->h/2); m_x = m_world->m_objects.at(num)->get_x()*m_gui->camera_zoom - (allegro_mouse_x); m_y = m_world->m_objects.at(num)->get_y()*m_gui->camera_zoom - (allegro_mouse_y); // std::cout<< screen->w<<" "<<screen->h<<" "<<screen->x_ofs<<" "<<screen->y_ofs<<std::endl; m_gui->camera_x = m_x ; m_gui->camera_y = m_y; std::this_thread::sleep_for(std::chrono::milliseconds(100)); num++; }catch(...) { } } // animation & tick if (m_frame_number % g_max_anim_frame == 0 && !simulation_pause) { frame_checkpoint = m_frame_number; m_world->tick(); // <=== } // === main user interface === // the mode typedef enum { e_mode_node, e_mode_camera } t_mode; t_mode mode; mode = e_mode_node; // by default we will move/edit etc the node (or entityt) if (allegro_shifts & KB_SHIFT_FLAG) mode = e_mode_camera; // with key SHIFT we move camera instea // mode: camera movement etc if (mode == e_mode_camera) { if (allegro_keys[KEY_LEFT]) m_gui->camera_x -= 10; if (allegro_keys[KEY_RIGHT]) m_gui->camera_x += 10; if (allegro_keys[KEY_UP]) m_gui->camera_y -= 10; if (allegro_keys[KEY_DOWN]) m_gui->camera_y += 10; const double zoom_speed = 1.1; if (allegro_keys[KEY_PGUP]) m_gui->camera_zoom *= zoom_speed; if (allegro_keys[KEY_PGDN]) m_gui->camera_zoom /= zoom_speed; } // rotate and zoom in/out the scene if(allegro_keys[KEY_Z]) { //camera_offset+=0.1; zoom+=0.1; _dbg1("zoom: " << zoom); } if(allegro_keys[KEY_X]) { //camera_offset-=0.1; zoom-=0.1; _dbg1("zoom: " << zoom); } if(allegro_keys[KEY_C]) { view_angle+=1.0; //farVal+=10; _dbg1("view_angle: " << view_angle); } if(allegro_keys[KEY_V]) { view_angle-=1.0; _dbg1("view_angle: " << view_angle); } if(allegro_keys[KEY_Q]) { camera_step_z+=0.1; } if(allegro_keys[KEY_W]) { camera_step_z -= 0.1; if(camera_step_z <= -11.0) camera_step_z=-11.0; } // === text debug on screen === string mouse_pos_str = std::to_string(gui_mouse_x) + " " + std::to_string(gui_mouse_y); string fps_str = "fps ???"; if (loop_miliseconds != 0) { fps_str = "fps: " + std::to_string(1000 / loop_miliseconds); } const int txt_h = 12; // line height (separation between lines) int txt_x = 10, txt_y = 10; // starting position of text if (use_draw_allegro) { string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame); textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, fps_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, ("Frame nr.: " + std::to_string(m_frame_number)).c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); textout_ex(m_frame, font, pck_speed_str.c_str(), 100, 10, makecol(0, 0, 255), -1); if(allegro_keys[KEY_H]) { int tex_y = 10; int lineh = 10; textout_ex(m_frame, font, "s - start", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "p - pause", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "f - send FTP", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "t - select target", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "r - select source", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "d - remove node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "n - add node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "enter/esc - exit", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "Arrows: move selected node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "SHIFT-Arrows: move the camera", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "SHIFT-PageUp/Down: zimm in/out", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "F1: info about node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); textout_ex(m_frame, font, "F2: next node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1); } else{ textout_ex(m_frame, font, "h - help", 1140, 30, makecol(0, 0, 255), -1); } } if (use_draw_opengl) { // TODO @opengl //textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1); float offset = 0.03; float tex_y = 0.9; float tex_x = 0.7; string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame); glColor4f(0.0,0.0,1.0,0.0); //glScalef(0.2f,0.2f,0.2f); //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y, 0.0, mouse_pos_str.c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, fps_str.c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, ("Frame nr.: " + std::to_string(m_frame_number)).c_str()); allegro_gl_printf_ex(s_font_allegl.get(), -0.7, 0.97, 0.0, pck_speed_str.c_str()); glDisable(GL_BLEND); glPopMatrix(); if(allegro_keys[KEY_H]) { _dbg1("KEY_H - opengl"); //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"s - start"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"p - pause"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"f - send FTP"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"t - select target"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"r - select source"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"d - remove node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"n - add node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"enter/esc - exit"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"Arrows: move selected node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-Arrows: move the camera"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-PageUp/Down: zoom in/out"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F1: info about node"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F2: next node"); glDisable(GL_BLEND); glPopMatrix(); } else { //glLoadIdentity(); glPushMatrix(); glEnable(GL_BLEND); //allegro_gl_printf(s_font_allegl.get(), 0.8, 0.9, 0.0,0xFF0000,"h - help"); allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"h - help"); //glBlendFunc(GL_ONE, GL_ZERO); glDisable(GL_BLEND); glPopMatrix(); } } //_dbg3("m_world->m_objects.size(): " << m_world->m_objects.size()); //_dbg3("get_move_object ret: " << get_move_object(gui_mouse_x, gui_mouse_y)); int move_object_index = get_move_object(gui_mouse_x, gui_mouse_y); ///< -1 if 'empty' if (move_object_index != -1) { // working with selected object m_gui->m_selected_object = m_world->m_objects.begin(); std::advance(m_gui->m_selected_object, move_object_index); auto selected_object = m_gui->m_selected_object; (*selected_object)->m_selected = true; c_entity *selected_object_raw = dynamic_cast<c_entity *>((*selected_object).get()); c_osi2_switch *selected_switch = dynamic_cast<c_osi2_switch *>((*selected_object).get()); // selected_switch->send_hello_to_neighbors(); // TODO //shared_ptr<c_cjddev> selected_device = std::dynamic_pointer_cast<c_cjddev>(selected_object); if (selected_object != m_world->m_objects.end()) { // editing the selected object // TODO: add connect /*if (gui_mouse_b == 1 && !print_connect_line) { print_connect_line = true; connect_node = std::dynamic_pointer_cast<c_cjddev>(selected_object); last_click_time = std::chrono::steady_clock::now(); } if (gui_mouse_b == 1 && print_connect_line && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(500)) { // assert( connect_node && selected_object ); connect_node->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(selected_object)); (std::dynamic_pointer_cast<c_cjddev>(selected_object))->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(connect_node)); print_connect_line = false; }*/ if (mode == e_mode_node) { // working with selected object - moving if (!print_connect_line) { int speed = 5; if (allegro_keys[KEY_LEFT]) selected_object_raw->m_x += -speed; if (allegro_keys[KEY_RIGHT]) selected_object_raw->m_x += speed; if (allegro_keys[KEY_DOWN]) selected_object_raw->m_y += speed; if (allegro_keys[KEY_UP]) selected_object_raw->m_y += -speed; } } // moving selected object } /* if ((allegro_char & 0xff) == 's' && !start_simulation) { if (!m_gui->m_source || !m_gui->m_target) { std::cout << "please choose target and source node\n"; } else { m_gui->m_source->buy_net(m_gui->m_target->get_address()); start_simulation = true; simulation_pause = false; } } if ((allegro_char & 0xff) == 'd' && selected_device && !start_simulation) { for (shared_ptr<c_cjddev> &it : selected_device->get_neighbors()) { selected_device->remove_neighbor(it); it->remove_neighbor(selected_device); } for (auto it = m_world->m_objects.begin(); it != m_world->m_objects.end(); ++it) { if (it->get() == selected_device.get()) { m_world->m_objects.erase(it); break; } } } if ((allegro_char & 0xff) == 't' && selected_device && !start_simulation) { m_gui->m_target = selected_device; } if ((allegro_char & 0xff) == 'r' && selected_device && !start_simulation) { m_gui->m_source = selected_device; } if ((allegro_char & 0xff) == 'f') { if (!m_gui->m_source || !m_gui->m_target) std::cout << "please choose target and source node\n"; else { m_gui->m_source->send_ftp_packet(m_gui->m_target->get_address(), "FTP data"); last_click_time = std::chrono::steady_clock::now(); } } */ // === animation clock controll === if ((allegro_char & 0xff) == 'p') { simulation_pause = !simulation_pause; last_click_time = std::chrono::steady_clock::now(); } if (allegro_keys[KEY_MINUS_PAD] && g_max_anim_frame < 400 && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) { //std::cout << m_frame_number-frame_checkpoint << " - " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame << std::endl; g_max_anim_frame += 1; last_click_time = std::chrono::steady_clock::now(); } if (allegro_keys[KEY_PLUS_PAD] && g_max_anim_frame > 10 && std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) { //std::cout << m_frame_number-frame_checkpoint << " + " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame << std::endl; g_max_anim_frame -= 1; last_click_time = std::chrono::steady_clock::now(); } } // === animation clock operations === m_world->draw(*m_drawtarget.get()); // <===== DRAW THE WORLD /* if ((m_frame_number - frame_checkpoint) < g_max_anim_frame) { m_world->draw(*m_drawtarget.get(), (m_frame_number - frame_checkpoint) % g_max_anim_frame); // <== } else { m_world->draw(*m_drawtarget.get(), g_max_anim_frame); } */ if (print_connect_line) { // the line the creates new connections if (use_draw_allegro) { line(m_frame, connect_node->m_x, connect_node->m_y, allegro_mouse_x, allegro_mouse_y, makecol(0, 255, 255)); } // TODO @opengl if (use_draw_opengl) { glColor3f(0.0f,1.0f,1.0f); glLineWidth(1.0); glScalef(1.0f,1.0f,1.0f); const int vx = m_gui->view_x(connect_node->m_x), vy = m_gui->view_y(connect_node->m_y); // position in viewport - because camera position //float start_line_x = ((connect_node->m_x)-0.5*SCREEN_W)/(0.5*SCREEN_W); //float start_line_y = -((connect_node->m_y)-0.5*SCREEN_H)/(0.5*SCREEN_H); float start_line_x = (vx-0.5*SCREEN_W)/(0.5*SCREEN_W); float start_line_y = -(vy-0.5*SCREEN_H)/(0.5*SCREEN_H); float end_line_x = (allegro_mouse_x-0.5*SCREEN_W)/(0.5*SCREEN_W); float end_line_y = -(allegro_mouse_y-0.5*SCREEN_H)/(0.5*SCREEN_H); //_dbg1("connect_node: " << connect_node->m_x << " " << connect_node->m_y); //_dbg1("allegro_mouse: " << allegro_mouse_x << " " << allegro_mouse_y); //_dbg1("start_line: " << start_line_x << " " << start_line_y); //_dbg1("end_line: " << end_line_x << " " << end_line_y); //glLoadIdentity(); glPushMatrix(); glBegin(GL_LINES); glVertex3f(start_line_x,start_line_y,0.0f); glVertex3f(end_line_x,end_line_y,0.0f); glEnd(); glPopMatrix(); } } if (allegro_mouse_b == 2) { // end/stop the line that creates new connections print_connect_line = false; } { auto x = allegro_mouse_x, y = allegro_mouse_y; int r = 5, rr = 4; if (use_draw_allegro) { line(m_frame, x - rr, y, x + rr, y, makecol(0, 0, 0)); line(m_frame, x, y - rr, x, y + rr, makecol(0, 0, 0)); circle(m_frame, x, y, r, makecol(255, 255, 255)); } // TODO @opengl if(use_draw_opengl) { float opengl_mouse_x = (x-SCREEN_W*0.5)/(0.5*SCREEN_W); float opengl_mouse_y = -(y-SCREEN_H*0.5)/(0.5*SCREEN_H); float cursor_size=0.01; //_dbg1("mouse_x mouse_y: " << mouse_x << " " << mouse_y); //_dbg1("screenW screenH: " << SCREEN_W << " " << SCREEN_H); //glLoadIdentity(); //glScalef(1/camera_offset, 1/camera_offset, 1.0); //glScalef(1.0*zoom, 1.0*zoom, 1.0*zoom); glPushMatrix(); glScalef(1.0f,1.0f,1.0f); glTranslatef(opengl_mouse_x,opengl_mouse_y,0.0f); //glTranslatef(m_gui->view_x_rev(mouse_x),m_gui->view_y_rev(mouse_y),0.0f); glColor3f(0.0, 0.0, 0.0); // draw cursor glBegin(GL_LINES); glVertex2f(-1.0f*cursor_size,0.0f); glVertex2f(1.0f*cursor_size,0.0f); glVertex2f(0.0f,-1.0f*cursor_size); glVertex2f(0.0f,1.0f*cursor_size); glEnd(); glPopMatrix(); } } // === show frame === if (use_draw_allegro) { //_dbg1("Allegro: frame done. fps = " << fps_str); scare_mouse(); blit(m_frame, m_screen, 0, 0, 0, 0, m_frame->w, m_frame->h); unscare_mouse(); if (!simulation_pause) { ++m_frame_number; } } if (use_draw_opengl) { //_dbg1("OpenGL: frame flip. fps = " << fps_str); allegro_gl_flip(); } for (auto &object : m_world->m_objects) { object->m_selected = false; } // std::this_thread::sleep_for(std::chrono::milliseconds(10)); auto stop_time = std::chrono::high_resolution_clock::now(); auto diff = stop_time - start_time; loop_miliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count(); } std::ofstream out_file("../layout/current/out.map.txt"); out_file << *m_world << std::endl; }