void Engine::init_scene() { Node* scene = nodes["scene"] = new Node(NULL); // shaders // // "simple_shader" shaders["simple_shader"] = make_shader("shaders/p_v.glsl", "shaders/unicolor_f.glsl"); // "light1" { Shader* shader = shaders["light1"] = make_shader("shaders/pn_v.glsl", "shaders/light1_f.glsl"); // TODO put uniforms in "material"-class or something? set_uniform(shader, "mycolor", glm::vec4(1.f)); set_uniform(shader, "ambient_intensity", glm::vec4(.1f,.1f,.1f,1.f)); set_uniform(shader, "diffuse_color", glm::vec4(.5f,.5f,.5f,1.f)); set_uniform(shader, "specular_color", glm::vec4(1.f,1.f,1.f,1.f)); set_uniform(shader, "atten_k", .04f); set_uniform(shader, "gauss_k", .1f); } // objects // // grid { Shader* shader = shaders["simple_shader"]; Node* node = nodes["grid"] = new Node(scene); int no = 5; glm::vec3 scale = glm::vec3(20.f); VAO* vao = create_grid(no, scale); std::vector<Uniform*> material; glm::vec4 white = glm::vec4(1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", white); material.push_back(mycolor); renderables.push_back( new BasicRenderObject(shader, node, vao, material)); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // redcube { Shader* shader = shaders["light1"]; Node* node = nodes["redcube"] = new Node(scene); node->position = glm::vec3(.5f,.5f,-1.7f); glm::vec3 scale = glm::vec3(.05f); VAO* vao = create_cube_with_normals(scale); std::vector<Uniform*> material; glm::vec4 red = glm::vec4(1.f,0.f,.5f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", red); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // physics btCollisionShape* cube_shape = new btBoxShape(from_vec3(scale/2.f)); float mass = 0.f; redcube_rb = create_rigid_body(mass, node, cube_shape); physics->add_rigid_body(redcube_rb); // mem vaos.push_back(vao); uniforms.push_back(mycolor); collision_shapes.push_back(cube_shape); } make_litcube("cyancube", glm::vec4(0.f, 1.f, 1.f, 1.f), glm::vec3(0.05f)); nodes["cyancube"]->orientation = glm::angleAxis(glm::radians(45.f), glm::normalize(glm::vec3(-1.f, 1.f, 1.f))); make_litcube("yellowcube", glm::vec4(1.f, 1.f, 0.f, 1.f), glm::vec3(0.05f)); nodes["yellowcube"]->orientation = nodes["cyancube"]->orientation; make_litcube("bluecube", glm::vec4(0.f, 0.f, 1.f, 1.f), glm::vec3(1.f), 30.f, glm::vec3(0.f, 1.5f, -5.f)); // lightcube { Shader* shader = shaders["simple_shader"]; Node* node = nodes["lightcube"] = new Node(scene); node->position = glm::vec3(0.f, 1.f, 0.f); glm::vec3 scale = glm::vec3(.3f,.3f,.3f); VAO* vao = create_cube(scale); std::vector<Uniform*> material; glm::vec4 white = glm::vec4(1.f,1.f,1.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", white); material.push_back(mycolor); renderables.push_back( new BasicRenderObject(shader, node, vao, material)); // sync point light with position PointLight light0(node, glm::vec4(.7f,.7f,.7f,1.f)); set_uniform(shaders["light1"], "light.position", glm::vec3(light0.get_position())); set_uniform(shaders["light1"], "light.intensity", light0.get_intensity()); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // plane { Shader* shader = shaders["light1"]; Node* node = nodes["plane"] = new Node(scene); node->position = glm::vec3(0.f, -.5f, 0.f); glm::vec3 scale = glm::vec3(20.f, 1.f, 20.f); VAO* vao = create_cube_with_normals(scale); std::vector<Uniform*> material; glm::vec4 goldish = glm::vec4(1.f,1.f,0.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", goldish); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // physics btCollisionShape* shape = new btBoxShape(from_vec3(scale/2.f)); float mass = 0.f; btRigidBody* rigid_body = create_rigid_body(mass, node, shape); physics->add_rigid_body(rigid_body); // mem uniforms.push_back(mycolor); vaos.push_back(vao); collision_shapes.push_back(shape); } // bound { Shader* shader = shaders["light1"]; Node* node = nodes["bound"] = new Node(scene); glm::vec3 scale = glm::vec3(20.f); bool face_inward = true; VAO* vao = create_cube_with_normals(scale, face_inward); std::vector<Uniform*> material; glm::vec4 greenblueish = glm::vec4(0.f,1.f,1.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", greenblueish); material.push_back(mycolor); renderables.push_back( new LitRenderObject(shader, node, vao, material)); // mem vaos.push_back(vao); uniforms.push_back(mycolor); } // roboarm { nodes["roboarm0"] = new Node(scene); nodes["roboarm1"] = new Node(scene); nodes["roboarm2"] = new Node(scene); nodes["roboarm3"] = new Node(scene); glm::vec3 scale = glm::vec3(0.1f, 0.4f, 0.1f); nodes["roboarm0"]->position = glm::vec3(0.f, 1.f, -2.f); //nodes["roboarm0"]->orientation = // glm::angleAxis(glm::radians(180.f), glm::vec3(1.f, 0.f, 0.f)); nodes["roboarm1"]->position = nodes["roboarm0"]->position + nodes["roboarm0"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm1"]->orientation = nodes["roboarm0"]->orientation; nodes["roboarm2"]->position = nodes["roboarm1"]->position + nodes["roboarm1"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm2"]->orientation = nodes["roboarm1"]->orientation; nodes["roboarm3"]->position = nodes["roboarm2"]->position + nodes["roboarm2"]->orientation * glm::vec3(0.f, scale.y, 0.f); nodes["roboarm3"]->orientation = nodes["roboarm2"]->orientation; // render { Shader* shader = shaders["light1"]; glm::vec4 black = glm::vec4(0.f,0.f,0.f,1.f); StoredUniform<glm::vec4>* mycolor = new StoredUniform<glm::vec4>(shader, "mycolor", black); std::vector<Uniform*> material; material.push_back(mycolor); // TODO use rounder shapes... VAO* vao = create_cube_with_normals(scale); auto make_renderable = [&shader, &material, &vao] (Node* node) { return new LitRenderObject(shader, node, vao, material); }; renderables.insert(renderables.end(), { make_renderable(nodes["roboarm0"]), make_renderable(nodes["roboarm1"]), make_renderable(nodes["roboarm2"]), make_renderable(nodes["roboarm3"]), } ); // mem uniforms.push_back(mycolor); vaos.push_back(vao); } btCollisionShape *shape = new btBoxShape(from_vec3(scale/2.f)); float density = 1000.f, volume = scale.x * scale.y * scale.z, mass = density * volume; // mem collision_shapes.push_back(shape); btRigidBody *rb0 = create_rigid_body(0.f, nodes["roboarm0"], shape), *rb1 = create_rigid_body(mass, nodes["roboarm1"], shape), *rb2 = create_rigid_body(mass, nodes["roboarm2"], shape), *rb3 = create_rigid_body(mass, nodes["roboarm3"], shape); rb1->setActivationState(DISABLE_DEACTIVATION); rb2->setActivationState(DISABLE_DEACTIVATION); rb3->setActivationState(DISABLE_DEACTIVATION); physics->add_rigid_body(rb0); physics->add_rigid_body(rb1); physics->add_rigid_body(rb2); physics->add_rigid_body(rb3); btMatrix3x3 rot; rot.setIdentity(); btTransform trans_up(rot, btVector3(0.f, scale.y/2, 0.f)), trans_down(rot, btVector3(0.f, -scale.y/2, 0.f)); rc1 = new btHingeConstraint(*rb0, *rb1, trans_up, trans_down); rc2 = new btHingeConstraint(*rb1, *rb2, trans_up, trans_down); rc3 = new btHingeConstraint(*rb2, *rb3, trans_up, trans_down); float pi = glm::pi<float>(); rc1->setLimit(-pi/2, pi/2); rc2->setLimit(-pi/2, pi/2); rc3->setLimit(-pi/2, pi/2); bool intercollision = false; physics->add_constraint(rc1, intercollision); physics->add_constraint(rc2, intercollision); physics->add_constraint(rc3, intercollision); roboarm0 = new KinematicChain(nullptr, rb0, nullptr); roboarm1 = new KinematicChain(roboarm0, rb1, rc1); roboarm2 = new KinematicChain(roboarm1, rb2, rc2); roboarm3 = new KinematicChain(roboarm2, rb3, rc3); } }
static int wlan_trans_thread(void *data) { int i, vif_id, ret, done, retry, sem_count, send_pkt, index, wake_flag, gpio_status; rxfifo_t *rx_fifo; txfifo_t *tx_fifo; wlan_vif_t *vif; sdio_chn_t *tx_chn; sdio_chn_t *rx_chn; unsigned short status; wlan_thread_t *thread; u32 rx_gpio; thread = &(g_wlan.wlan_trans); sdiodev_readchn_init(8, (void *)wlan_rx_chn_isr, 1); sdiodev_readchn_init(9, (void *)wlan_rx_chn_isr, 1); rx_chn = &(g_wlan.hw.sdio_rx_chn); tx_chn = &(g_wlan.hw.sdio_tx_chn); rx_fifo = &(g_wlan.rxfifo); rx_gpio = g_wlan.hw.rx_gpio; up(&(g_wlan.sync.sem)); printke("%s enter\n", __func__); thread->null_run = 0; thread->max_null_run = 100; thread->idle_sleep = 400; thread->prio = 90; wake_flag = 0; thread_sched_policy(thread); trans_down(); do { thread_sleep_policy(thread); send_pkt = retry = done = 0; sem_count = g_wlan.wlan_trans.sem.count; /* if (0 == wake_flag) { wake_lock(&g_wlan.hw.wlan_lock); wake_flag = 1; } */ RX: gpio_status = gpio_get_value(rx_gpio); if (!gpio_status) { if (true == rx_chn->gpio_high) { rx_chn->gpio_high = false; rx_chn->timeout_flag = false; } goto TX; } else { if (false == rx_chn->gpio_high) { rx_chn->gpio_high = true; } } wlan_wakeup(); ret = set_marlin_wakeup(0, 1); #if 0 if (0 != ret) { printke("rx call set_marlin_wakeup error:%d\n", ret); if (ret != -ETIMEDOUT) msleep(200); goto TX; } #endif if (0 != ret) { if( (ITM_NONE_MODE != g_wlan.netif[0].mode) || (ITM_NONE_MODE != g_wlan.netif[1].mode) ) { if(-2 != ret) { printke("rx call set_marlin_wakeup return:%d:%d\n", ret); msleep(200); goto TX; } } else { printke("rx retry open wlan\n", ret); msleep(200); goto TX; } } ret = sdio_chn_status(rx_chn->bit_map, &status); if (0 != ret) { printke("rx call sdio_chn_status error:%d\n", ret); goto RX_SLEEP; } index = check_valid_chn(1, status, rx_chn); if (index < 0) { RX_SLEEP: if (false == rx_chn->timeout_flag) { rx_chn->timeout_flag = true; rx_chn->timeout = jiffies + msecs_to_jiffies(rx_chn->timeout_time); } else { if (time_after(jiffies, rx_chn->timeout)) { printke ("[SDIO_RX_CHN][TIMEOUT][%lu] jiffies:%lu\n", rx_chn->timeout_time, jiffies); msleep(300); rx_chn->timeout_flag = false; } } goto TX; } if (true == rx_chn->timeout_flag) { rx_chn->timeout_flag = false; } if (14 == index) { mdbg_sdio_read(); goto TX; } if (11 == index) { mdbg_at_cmd_read(); goto TX; } if (15 == index) { mdbg_loopcheck_read(); goto TX; } ret = rx_fifo_in(index, rx_fifo, hw_rx); if (OK != ret) { if (HW_READ_ERROR == ret) msleep(100); retry++; goto TX; } g_wlan.wlan_core.need_rx++; core_up(); TX: for (vif_id = NETIF_0_ID; vif_id < WLAN_MAX_ID; vif_id++) { vif = &(g_wlan.netif[vif_id]); tx_fifo = &(vif->txfifo); ret = tx_fifo_used(tx_fifo); if (0 == ret) continue; wlan_wakeup(); ret = set_marlin_wakeup(0, 1); #if 0 if (0 != ret) { printke("tx call set_marlin_wakeup error:%d\n", ret); if (ret != -ETIMEDOUT) msleep(200); retry++; continue; } #endif if (0 != ret) { if( (ITM_NONE_MODE != g_wlan.netif[0].mode) || (ITM_NONE_MODE != g_wlan.netif[1].mode) ) { // -2: means bt ack high if(-2 != ret){ printke("tx call set_marlin_wakeup return:%d\n", ret); msleep(200); retry++; continue; } }else{ printke("tx retry open wlan\n"); msleep(300); retry++; continue; } } ret = sdio_chn_status(tx_chn->bit_map, &status); if (ret) { printke("tx call sdio_chn_status error:%d\n", ret); goto TX_SLEEP; } index = check_valid_chn(0, status, tx_chn); if (index < 0) { TX_SLEEP: if (false == tx_chn->timeout_flag) { tx_chn->timeout_flag = true; tx_chn->timeout = jiffies + msecs_to_jiffies(tx_chn-> timeout_time); } else { if (time_after (jiffies, tx_chn->timeout)) { printke ("[SDIO_TX_CHN][TIMEOUT][%lu] jiffies:%lu\n", tx_chn->timeout_time, jiffies); msleep(300); tx_chn->timeout_flag = false; } } retry++; continue; } if (true == tx_chn->timeout_flag) { tx_chn->timeout_flag = false; } ret = tx_fifo_out(vif_id, index, tx_fifo, hw_tx, &send_pkt); if (OK != ret) { if (HW_WRITE_ERROR == ret) { msleep(100); retry++; } continue; } done = done + send_pkt; core_try_up(); } if (g_wlan.sync.exit) { /* if(1 == wake_flag) { wake_unlock(&g_wlan.hw.wlan_lock); wake_flag = 0; } */ break; } gpio_status = gpio_get_value(rx_gpio); if (gpio_status) { if (g_wlan.wlan_trans.sem.count - done <= 1) { done = (g_wlan.wlan_trans.sem.count > 0) ? (g_wlan.wlan_trans.sem.count - 1) : (0); } } else { if ((0 == done) && (0 == retry)) done = ((0 == sem_count) ? (1) : (sem_count)); } if (done > 0) thread->null_run = 0; else thread->null_run++; wlan_sleep(); /* if ((done >= g_wlan.wlan_trans.sem.count) && (wake_flag = 1) &&(!gpio_status) ) { wake_unlock(&g_wlan.hw.wlan_lock); wake_flag = 0; } */ for (i = 0; i < done; i++) { trans_down(); } } while (!kthread_should_stop()); sdiodev_readchn_uninit(8); sdiodev_readchn_uninit(9); mdbg_sdio_read(); del_timer_sync(&(g_wlan.hw.wakeup_timer)); printke("%s exit\n", __func__); up(&(g_wlan.sync.sem)); core_up(); return OK; }