entity * insert_entity(oct_node oc, vec3 pos, vec3 size, i32 id){ oc = oct_find_fitting_node(oc, &pos, &size); entity e = {OBJECT, oct_node_empty, id, pos, size}; entity * e2 = clone(&e, sizeof(entity)); add_entity(oc, (entity_header *) e2); return e2; }
tile * insert_tile(oct_node oc, vec3i pos, i32 id){ oc = oct_get_relative(oc, pos); tile t = {TILE, oct_node_empty, id}; tile * t2 = clone(&t, sizeof(t)); add_entity(oc, (entity_header *) t2); return t2; }
static void add_exnref (Exception exn, struct buffer_s *data, list referenced) { print0ToBuffer (data, "(exn "); if (exn->corba_rep_id != NULL) { print0ToBuffer(data, "(id "); add_quoted_string(exn->corba_rep_id, data); print0ToBuffer(data, ")"); } else { printmToBuffer (data, "(ref %s %s)", interface_name(exception_interface(exn)), exception_name(exn)); add_entity (ExceptionE, exn, referenced); } printmToBuffer (data, ")"); }
void on_push(std::shared_ptr<Game> game) { auto scene = std::make_shared<Scene>(); auto player = std::make_shared<Entity>(); player->attach_component<PositionComponent>(); player->attach_component<VelocityComponent>(); player->attach_component<PlayerDrawableComponent>(); scene->add_entity(player); auto circle_drawable = std::make_shared<CircleDrawableSystem>(); scene->add_system(circle_drawable); game->make_active_scene(scene); }
static bool sig_done(jose_io_t *io) { io_t *i = containerof(io, io_t, io); size_t len = 0; if (EVP_DigestSignFinal(i->emc, NULL, &len) <= 0) return false; uint8_t buf[len]; if (EVP_DigestSignFinal(i->emc, buf, &len) <= 0) return false; if (json_object_set_new(i->sig, "signature", jose_b64_enc(buf, len)) < 0) return false; return add_entity(i->obj, i->sig, "signatures", "signature", "protected", "header", NULL); }
i64 get_hash(oct_node n, oct_node bn, game_data * gd){ { // Get hash quick bool ok = false; i64 hash = _get_hash(n, &ok); if(ok){ logd("Found: %p\n", hash); return hash; } } { //Hash node not found, build hash tree. bool _ok = false; i64 hash2 = _get_hash(bn, &_ok); logd("init hash: %p\n", hash2); ASSERT(_ok); bool changed = false; while(oct_has_super(bn)){ bn = oct_get_super(bn); hash2 = iron_hash(&hash2, sizeof(hash2)); logd("next hash: %p\n", hash2); changed = true; } ASSERT(changed); hash_node * new_node = alloc0(sizeof(hash_node)); new_node->type = HASH64; new_node->hash = hash2; add_entity(bn, (entity_header *) new_node); gd->hashed_node = bn; } { //now it should be possible to find a hash for n bool ok = false; i64 hash = _get_hash(n, &ok); logd("Final: %p\n", hash); ASSERT(ok); return hash; } }
int adp_discovery_state_machine::state_avail(const uint8_t *frame, size_t frame_len) { struct jdksavdecc_adpdu_common_control_header adp_hdr; uint64_t entity_entity_id; uint32_t entity_index; entity_entity_id = jdksavdecc_uint64_get(frame, ETHER_HDR_SIZE + PROTOCOL_HDR_SIZE); jdksavdecc_adpdu_common_control_header_read(&adp_hdr, frame, ETHER_HDR_SIZE, frame_len); if(have_entity(entity_entity_id, &entity_index)) { update_entity_timeout(entity_index, adp_hdr.valid_time * 2 * 1000); // Valid time period is between 2 and 62 seconds } else { struct entities entity; entity.entity_id = entity_entity_id; entity.inflight_timer.start(adp_hdr.valid_time * 2 * 1000); // Valid time period is between 2 and 62 seconds add_entity(entity); notification_imp_ref->post_notification_msg(END_STATION_CONNECTED, entity_entity_id, 0, 0, 0, 0, 0); } return 0; }
std::shared_ptr<Entity> GameEngine::create_entity(std::string name) { std::shared_ptr<Entity> e = std::make_shared<Entity>(name); add_entity(e); return e; }
static bool alg_wrap_wrp(const jose_hook_alg_t *alg, jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, json_t *cek) { openssl_auto(EVP_PKEY_CTX) *epc = NULL; openssl_auto(EVP_PKEY) *key = NULL; const EVP_MD *md = NULL; const RSA *rsa = NULL; uint8_t *pt = NULL; uint8_t *ct = NULL; bool ret = false; size_t ptl = 0; size_t ctl = 0; int tmp = 0; int pad = 0; if (!json_object_get(cek, "k") && !jose_jwk_gen(cfg, cek)) return false; switch (str2enum(alg->name, NAMES, NULL)) { case 0: pad = RSA_PKCS1_PADDING; tmp = 11; md = EVP_sha1(); break; case 1: pad = RSA_PKCS1_OAEP_PADDING; tmp = 41; md = EVP_sha1(); break; case 2: pad = RSA_PKCS1_OAEP_PADDING; tmp = 41; md = EVP_sha256(); break; default: return false; } key = jose_openssl_jwk_to_EVP_PKEY(cfg, jwk); if (!key || EVP_PKEY_base_id(key) != EVP_PKEY_RSA) return false; ptl = jose_b64_dec(json_object_get(cek, "k"), NULL, 0); if (ptl == SIZE_MAX) return false; rsa = EVP_PKEY_get0_RSA(key); if (!rsa) return false; if ((int) ptl >= RSA_size(rsa) - tmp) return false; epc = EVP_PKEY_CTX_new(key, NULL); if (!epc) return false; if (EVP_PKEY_encrypt_init(epc) <= 0) return false; if (EVP_PKEY_CTX_set_rsa_padding(epc, pad) <= 0) return false; if (pad == RSA_PKCS1_OAEP_PADDING) { if (EVP_PKEY_CTX_set_rsa_oaep_md(epc, md) <= 0) return false; if (EVP_PKEY_CTX_set_rsa_mgf1_md(epc, md) <= 0) return false; } pt = malloc(ptl); if (!pt) return false; if (jose_b64_dec(json_object_get(cek, "k"), pt, ptl) != ptl) goto egress; if (EVP_PKEY_encrypt(epc, NULL, &ctl, pt, ptl) <= 0) goto egress; ct = malloc(ctl); if (!ct) goto egress; if (EVP_PKEY_encrypt(epc, ct, &ctl, pt, ptl) <= 0) goto egress; if (json_object_set_new(rcp, "encrypted_key", jose_b64_enc(ct, ctl)) < 0) goto egress; ret = add_entity(jwe, rcp, "recipients", "header", "encrypted_key", NULL); egress: if (pt) { OPENSSL_cleanse(pt, ptl); free(pt); } free(ct); return ret; }
static bool alg_wrap_wrp(const jose_hook_alg_t *alg, jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, json_t *cek) { const jose_hook_alg_t *ecdh = NULL; json_auto_t *exc = NULL; json_auto_t *hdr = NULL; json_auto_t *epk = NULL; json_auto_t *der = NULL; const char *wrap = NULL; json_t *h = NULL; if (json_object_get(cek, "k")) { if (strcmp(alg->name, "ECDH-ES") == 0) return false; } else if (!jose_jwk_gen(cfg, cek)) { return false; } hdr = jose_jwe_hdr(jwe, rcp); if (!hdr) return false; h = json_object_get(rcp, "header"); if (!h && json_object_set_new(rcp, "header", h = json_object()) == -1) return false; epk = json_pack("{s:s,s:O}", "kty", "EC", "crv", json_object_get(jwk, "crv")); if (!epk) return false; if (!jose_jwk_gen(cfg, epk)) return false; ecdh = jose_hook_alg_find(JOSE_HOOK_ALG_KIND_EXCH, "ECDH"); if (!ecdh) return false; exc = ecdh->exch.exc(ecdh, cfg, epk, jwk); if (!exc) return false; if (!jose_jwk_pub(cfg, epk)) return false; if (json_object_set(h, "epk", epk) == -1) return false; der = derive(alg, cfg, hdr, cek, exc); if (!der) return false; wrap = strchr(alg->name, '+'); if (wrap) { const jose_hook_alg_t *kw = NULL; kw = jose_hook_alg_find(JOSE_HOOK_ALG_KIND_WRAP, &wrap[1]); if (!kw) return false; return kw->wrap.wrp(kw, cfg, jwe, rcp, der, cek); } if (json_object_update(cek, der) < 0) return false; return add_entity(jwe, rcp, "recipients", "header", "encrypted_key", NULL); }
static void draw_screen() { static double last_frame_time; static int frame_index; static float frame_rates[FRAME_INDEX_MAX]; static float frame_times[FRAME_INDEX_MAX]; double start_time = time_now_double(); glClearColor(0.0, 0.0, 0.0, 0.0); graph_dev_start_frame(); sng_set_foreground(WHITE); sng_abs_xy_draw_string("F1 FOR HELP", NANO_FONT, SCREEN_WIDTH - 100, 10); static struct entity_context *cx; if (!cx) cx = entity_context_new(50, 50); if (wireframe != oldwireframe) { oldwireframe = wireframe; if (wireframe) set_renderer(cx, WIREFRAME_RENDERER | BLACK_TRIS); else set_renderer(cx, FLATSHADING_RENDERER); } float r = target_mesh->radius / tan(FOV / 3.0); /* 50% size for middle zoom */ float r_cam = r * lobby_zoom / 255.0; camera_set_parameters(cx, 0.1f, r * 2.2, SCREEN_WIDTH, SCREEN_HEIGHT, FOV); camera_set_pos(cx, r_cam, 0, 0); camera_look_at(cx, 0, 0, 0); camera_assign_up_direction(cx, 0, 1, 0); union vec3 light_pos = { { 1.01 * r, 0, 0 } }; quat_rot_vec_self(&light_pos, &light_orientation); set_lighting(cx, light_pos.v.x, light_pos.v.y, light_pos.v.z); calculate_camera_transform(cx); struct entity *e = add_entity(cx, target_mesh, 0, 0, 0, WHITE); struct entity *ae = NULL; if (planet_mode) { update_entity_material(e, &planet_material); if (draw_atmosphere) { ae = add_entity(cx, atmosphere_mesh, 0, 0, 0, WHITE); update_entity_scale(ae, 1.03); update_entity_material(ae, &atmosphere_material); } } update_entity_orientation(e, &lobby_orientation); if (isDraggingLight) { union vec3 light_dir = { { 10.75 * r_cam, 0, 0 } }; quat_rot_vec_self(&light_dir, &light_orientation); sng_set_foreground(WHITE); render_line(cx, light_dir.v.x, light_dir.v.y, light_dir.v.z, 0, 0, 0); e = add_entity(cx, light_mesh, light_dir.v.x, light_dir.v.y, light_dir.v.z, WHITE); } else { e = add_entity(cx, light_mesh, light_pos.v.x, light_pos.v.y, light_pos.v.z, WHITE); } render_entities(cx); remove_all_entity(cx); if (helpmode) draw_help_screen(0); if (display_frame_stats > 0) { float avg_frame_rate = 0; float avg_frame_time = 0; int i; for (i = 0; i < FRAME_INDEX_MAX; i++) { avg_frame_rate += frame_rates[i]; avg_frame_time += frame_times[i]; } avg_frame_rate /= (float)FRAME_INDEX_MAX; avg_frame_time /= (float)FRAME_INDEX_MAX; sng_set_foreground(WHITE); char stat_buffer[30]; sprintf(stat_buffer, "fps %5.2f", 1.0/avg_frame_rate); sng_abs_xy_draw_string(stat_buffer, NANO_FONT, 2, 10); sprintf(stat_buffer, "t %0.2f ms", avg_frame_time * 1000.0); sng_abs_xy_draw_string(stat_buffer, NANO_FONT, 92, 10); } if (display_frame_stats > 1) graph_dev_display_debug_menu_show(); graph_dev_end_frame(); glFinish(); /* * Swap the buffers. This this tells the driver to * render the next frame from the contents of the * back-buffer, and to set all rendering operations * to occur on what was the front-buffer. * * Double buffering prevents nasty visual tearing * from the application drawing on areas of the * screen that are being updated at the same time. */ SDL_GL_SwapBuffers(); if (display_frame_stats > 0) { double end_time = time_now_double(); frame_rates[frame_index] = start_time - last_frame_time; frame_times[frame_index] = end_time - start_time; frame_index = (frame_index + 1) % FRAME_INDEX_MAX; last_frame_time = start_time; } }
static bool alg_wrap_wrp(const jose_hook_alg_t *alg, jose_cfg_t *cfg, json_t *jwe, json_t *rcp, const json_t *jwk, json_t *cek) { const EVP_CIPHER *cph = NULL; EVP_CIPHER_CTX *ecc = NULL; bool ret = false; size_t ptl = 0; size_t ctl = 0; int len = 0; if (!json_object_get(cek, "k") && !jose_jwk_gen(cfg, cek)) return false; switch (str2enum(alg->name, NAMES, NULL)) { case 0: cph = EVP_aes_128_wrap(); break; case 1: cph = EVP_aes_192_wrap(); break; case 2: cph = EVP_aes_256_wrap(); break; default: return false; } uint8_t ky[EVP_CIPHER_key_length(cph)]; uint8_t iv[EVP_CIPHER_iv_length(cph)]; uint8_t pt[KEYMAX]; uint8_t ct[sizeof(pt) + EVP_CIPHER_block_size(cph) * 2]; memset(iv, 0xA6, EVP_CIPHER_iv_length(cph)); if (jose_b64_dec(json_object_get(jwk, "k"), NULL, 0) != sizeof(ky)) goto egress; if (jose_b64_dec(json_object_get(jwk, "k"), ky, sizeof(ky)) != sizeof(ky)) goto egress; ptl = jose_b64_dec(json_object_get(cek, "k"), NULL, 0); if (ptl > sizeof(pt)) goto egress; if (jose_b64_dec(json_object_get(cek, "k"), pt, ptl) != ptl) goto egress; ecc = EVP_CIPHER_CTX_new(); if (!ecc) goto egress; EVP_CIPHER_CTX_set_flags(ecc, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW); if (EVP_EncryptInit_ex(ecc, cph, NULL, ky, iv) <= 0) goto egress; if (EVP_EncryptUpdate(ecc, ct, &len, pt, ptl) <= 0) goto egress; ctl = len; if (EVP_EncryptFinal(ecc, &ct[len], &len) <= 0) goto egress; ctl += len; if (json_object_set_new(rcp, "encrypted_key", jose_b64_enc(ct, ctl)) < 0) goto egress; ret = add_entity(jwe, rcp, "recipients", "header", "encrypted_key", NULL); egress: OPENSSL_cleanse(ky, sizeof(ky)); OPENSSL_cleanse(pt, sizeof(pt)); EVP_CIPHER_CTX_free(ecc); return ret; }
std::shared_ptr<gx::scene> universe_bootstrap( gx::render_context* render_context, d3d11::system_context context, std::shared_ptr<fnd::universe> universe ) { auto scene = std::make_shared<gx::scene>(); auto entities = std::make_shared<gx::entity_world> (); auto dynamic_entities = std::make_shared<fnd::typed_world> (); //add two worlds //1. with entities, created or loaded //2. dynamic entities which change depending on time //3. add a spatial structure for representing these entities universe->add_world(entities); universe->add_world(dynamic_entities); universe->add_world(scene); //room std::ifstream f("giroom.am", std::ios_base::in | std::ios_base::binary); std::future< std::shared_ptr<room_entity> > future_room = std::async( std::launch::async, [&]() { return create_room_entity(context.m_device.get(), render_context->get_shader_database(), f); }); //auto room_entity = create_room_entity(context.m_device.get(), render_context->get_shader_database(), f); //floor auto floor_entity = create_floor_entity( context.m_device.get(), render_context->get_shader_database(), 20, 20, 30 ); //directional light std::vector<directional_light> directional_lights; directional_lights.reserve(8); math::float4 light_position = math::set( 5.0f, 1.0f, 5.0f, 1.0f ); directional_lights.push_back( directional_light( gx::color::white(), math::sub(light_position, math::set(0.0f, 0.0f, 0.0f, 1.0f) ) )); //should be quad auto directional_entity = create_directional_lights_entity( context.m_device.get(), render_context->m_screen_space_render_data.m_screen_space_vertex_buffer, &directional_lights[0], &directional_lights[0] + directional_lights.size() ); //create point light entity and insert it into two worlds (for update and render) auto point_lights = create_point_lights_entity( context.m_device.get() ); auto light_updater = create_light_entity_updater(); dynamic_entities->add_type( 0, light_updater ); point_light light1 ( math::set(0.3f, 0.2f, 0.0f, 0.0f), light_position, 1.0f, 0.5f); point_lights->add_light(light1); auto it = scene->begin(); auto it_end = scene->end(); auto pi_div_two = 1.570796327f; //auto m_1 = math::rotation_x(-pi_div_two); //auto m_2 = math::translation(-1.0f, 0.0f, 0.0f); auto m_4 = math::translation(0.0f, 0.0f, 0.0f); auto root = scene->get_root(); //auto entity_1 = gxu::create_lat_lon_sphere_entity<gx::lambert_shift_invairant_material_factory>( render_context, 1.0f, 20, gx::color::blue() ); auto sphere_1 = gxu::create_lat_lon_sphere_entity<gx::blinn_phong_shift_invairant_material_factory>( render_context->get_device(), render_context->get_shader_database(), 1.0f, 20 , gx::color::green() , math::set(0.05f, 0.05f, 0.05f, gx::encode_specular_power(2 * 25.0f) ) ); auto sphere_2 = gxu::create_lat_lon_sphere_entity<gx::blinn_phong_shift_invairant_material_factory>( render_context->get_device(), render_context->get_shader_database(), 1.0f, 20 , gx::color::green() , math::set(0.05f, 0.05f, 0.05f, gx::encode_specular_power(2 * 50.0f) ) ); auto sphere_3 = gxu::create_lat_lon_sphere_entity<gx::blinn_phong_shift_invairant_material_factory>( render_context->get_device(), render_context->get_shader_database(), 1.0f, 20 , gx::color::green() , math::set(0.05f, 0.05f, 0.05f, gx::encode_specular_power(2 * 75.0f) ) ); auto sphere_4 = gxu::create_lat_lon_sphere_entity<gx::blinn_phong_shift_invairant_material_factory>( render_context->get_device(), render_context->get_shader_database(), 1.0f, 20 , gx::color::green() , math::set(0.05f, 0.05f, 0.05f, gx::encode_specular_power(2 * 100.0f) ) ); auto node_1 = std::make_shared<gx::scene::node> ( m_4, sphere_1.get() ); auto node_2 = std::make_shared<gx::scene::node> ( m_4, point_lights.get() ); auto node_3 = std::make_shared<gx::scene::node> ( m_4, directional_entity.get() ); auto node_4 = std::make_shared<gx::scene::node> ( math::translation(0.0f, -2.0f, 0.0f) , floor_entity.get() ); auto room_entity = future_room.get(); auto node_5 = std::make_shared<gx::scene::node> ( math::translation(0.0f, -2.0f, 0.0f), room_entity.get() ); auto node_6 = std::make_shared<gx::scene::node> ( math::translation(2.0f, 0.0f, 0.0f), sphere_2.get() ); auto node_7 = std::make_shared<gx::scene::node> ( math::translation(4.0f, 0.0f, 0.0f), sphere_3.get() ); auto node_8 = std::make_shared<gx::scene::node> ( math::translation(6.0f, 0.0f, 0.0f), sphere_4.get() ); //1. add to graphic world gx::add_node(root, node_1); gx::add_node(root, node_2); gx::add_node(root, node_3); gx::add_node(root, node_4); gx::add_node(root, node_5); gx::add_node(root, node_6); gx::add_node(root, node_7); gx::add_node(root, node_8); //2. add to entities world entities->add_entity( point_lights); entities->add_entity( directional_entity ); entities->add_entity( floor_entity ); entities->add_entity( room_entity ); entities->add_entity( sphere_1); entities->add_entity( sphere_2); entities->add_entity( sphere_3); entities->add_entity( sphere_4); scene->rebuild(); //3. add lights for updating light_updater->add_item(point_lights); return scene; }
void update_entity(entity * e){ oct_node oc = e->node; remove_entity((entity_header *) e); oc = oct_find_fitting_node(oc, &e->offset, &e->size); add_entity(oc, (entity_header *) e); }
static void add_typeref (Type t, struct buffer_s *data, list referenced) { if ((t->uid != NIL) && t->explicit_uid) { } else if (type_kind(t) == alias_Type) { add_typeref (t->supertype, data, referenced); } else { switch (type_kind(t)) { case byte_Type: print0ToBuffer (data, "byte"); break; case shortcardinal_Type: print0ToBuffer (data, "shortcardinal"); break; case cardinal_Type: print0ToBuffer (data, "cardinal"); break; case longcardinal_Type: print0ToBuffer (data, "longcardinal"); break; case shortinteger_Type: print0ToBuffer (data, "shortinteger"); break; case integer_Type: print0ToBuffer (data, "integer"); break; case longinteger_Type: print0ToBuffer (data, "longinteger"); break; case shortreal_Type: print0ToBuffer (data, "shortreal"); break; case real_Type: print0ToBuffer (data, "real"); break; case longreal_Type: print0ToBuffer (data, "longreal"); break; case shortcharacter_Type: print0ToBuffer (data, "shortcharacter"); break; case character_Type: print0ToBuffer (data, "character"); break; #if 0 case longcharacter_Type: #endif case boolean_Type: print0ToBuffer (data, "boolean"); break; case pickle_Type: print0ToBuffer (data, "pickle"); break; case void_Type: print0ToBuffer (data, "void"); break; case object_Type: case fixedpoint_Type: case string_Type: case union_Type: case sequence_Type: case record_Type: case array_Type: case enumeration_Type: case optional_Type: case reference_Type: printmToBuffer (data, "(ref %s %s)", interface_name(type_interface(t)), type_name(t)); add_entity (InterfaceE, type_interface(t), referenced); add_entity (TypeE, t, referenced); break; default: fprintf (stderr, "Invalid type kind %d for built-in type %s\n", type_basic_type(t), full_type_name(t)); exit(1); } } }