inline void smat_smat_mult(const MatrixA& a, const MatrixB& b, MatrixC& c, Assign, tag::row_major, // orientation a tag::col_major) // orientation b { // Copy B into a row-major matrix compressed2D<typename Collection<MatrixB>::value_type, matrix::parameters<> > b_copy(num_rows(b), num_cols(b)); b_copy= b; smat_smat_mult(a, b_copy, c, Assign(), tag::row_major(), tag::row_major()); }
void test_parallel_broadcasts(int p) { tbb::flow::broadcast_node<T> b; run_parallel_broadcasts(p, b); // test copy constructor tbb::flow::broadcast_node<T> b_copy(b); run_parallel_broadcasts(p, b_copy); }
void test1() { char a[] = "123alpha"; char b[] = "bravo123"; /* shift left */ b_copy(a, 5, a + 3); /* shift right */ b_copy(b + 3, 5, b); assert(b_diff(a, 8, "alphapha") == 0); assert(b_diff(b, 8, "brabravo") == 0); printf("[%s]\n", a); printf("[%s]\n", b); }
void loop_ctr(s4 &game_state) { ISceneNode* empty_node = irrlicht->smgr->addEmptySceneNode(); empty_node->setPosition(vector3df(0,0,0)); ICameraSceneNode* camera = irrlicht->smgr->addCameraSceneNode(); camera->setPosition({0,-250,-100}); camera->setUpVector({0,0,-1}); camera->setTarget({0,0,0}); camera->setParent(empty_node); camera->setFOV(70); irrlicht->device->getCursorControl()->setVisible(false); irrlicht->smgr->setAmbientLight(SColorf(1,1,1,1)); irrlicht->hud = irrlicht->smgr->createNewSceneManager(false); ICameraSceneNode* hud_camera = irrlicht->hud->addCameraSceneNode(); matrix4 ortho; ortho.buildProjectionMatrixOrthoLH( irrlicht->driver->getScreenSize().Width/ortho_scale, irrlicht->driver->getScreenSize().Height/ortho_scale,-1.0,1000.0); hud_camera->setProjectionMatrix(ortho); hud_camera->setPosition({0,0,-100}); hud_camera->setTarget({0,0,0}); // temp objects ---------------------------------- blist cmpnt_list, joint_list, tree_list; b_set(cmpnt_list,memory,sizeof(Component)); b_set(joint_list,memory,sizeof(Joint)); b_set(tree_list,memory,sizeof(CTree)); irr::core::map<ISceneNode*,Component*> node_cmpnt_map; ISceneNode* ctr_parent = irrlicht->smgr->addEmptySceneNode(); IMesh* cube_mesh = irrlicht->smgr->getGeometryCreator()->createCubeMesh(); auto add_object_to_world = [&] (vec3 pos, vec3 scale, s4 a, s4 r, s4 g, s4 b) -> Component* { const f4 floor_position = 10.0f; Component make_cmpnt; make_cmpnt.id = CMPNT_ID; CMPNT_ID++; make_cmpnt.node = irrlicht->smgr->addMeshSceneNode(cube_mesh,ctr_parent); make_cmpnt.node->setPosition(pos.irr()); make_cmpnt.node->setScale(scale.irr()); make_cmpnt.node->getMaterial(0).AmbientColor.set(a,r,g,b); make_cmpnt.shadow = irrlicht->smgr->addMeshSceneNode(cube_mesh,0); make_cmpnt.shadow->setScale({scale.x, scale.y, 0.1f}); make_cmpnt.shadow->setPosition({pos.x, pos.y,floor_position}); make_cmpnt.shadow->getMaterial(0).AmbientColor.set(GREY_BLUE_SHADOW); for (s4 i = 0; i < MAX_JOINTS; i++) make_cmpnt.joints[i] = 0; make_cmpnt.tree = 0; b_copy(cmpnt_list,&make_cmpnt); node_cmpnt_map.insert(make_cmpnt.node, (Component*)blast_address(cmpnt_list) ); return (Component*)blast_address(cmpnt_list); }; auto add_joint = [&] (Component* A, Component* B, vec3 posA, vec3 posB) { Joint C; C.A = A; C.posA = A->node->getTransformedBoundingBox().getExtent() * A->node->getScale(); C.posA *= (posA * 0.5f); C.B = B; C.posB = B->node->getTransformedBoundingBox().getExtent() * B->node->getScale(); C.posB *= (posB * 0.5f); C.type = Joint::SNAP; C.is_connected = false; b_copy(joint_list,&C); for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.A->joints[i] == 0) { C.A->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.A." << std::endl; } } for (s4 i = 0; i < MAX_JOINTS; i++) { if (C.B->joints[i] == 0) { C.B->joints[i] = (Joint*)blast_address(joint_list); break; } else if (i == MAX_JOINTS-1) { std::cout << "ERROR: Joint could not be added to C.B." << std::endl; } } }; { Component* A = add_object_to_world(vec3(0,30,-20),vec3(3,3,3),BLUE_LIGHT); Component* B = add_object_to_world(vec3(0,60,-20),vec3(9,3,2),BLACK); add_joint(A,B,vec3(0.0f,0.0f,1.0f),vec3(0.0f,0.0f,-1.0f)); Component* C = add_object_to_world(vec3(0,-90,-20),vec3(3,3,3),YELLOW_LIGHT); Component* D = add_object_to_world(vec3(0,-40,-20),vec3(8,10,4),GREEN_LIGHT); add_joint(C,D,vec3(0.0f,1.0f,0.0f),vec3(0.0f,-1.0f,0.0f)); add_joint(A,D,vec3(0.0f,0.0f,-1.0f),vec3(0.0f,0.0f,1.0f)); } // temp objects ---------------------------------- SimpleNodeEditor* sneditor = simple_node_editor_init(); sneditor->root_node = ctr_parent; f4 target_z_rotation = empty_node->getRotation().Z; p("---- Game loop start ----"); f4 dt = 0.0f; const f4 maxDelta = 1.0f/60.0f * 5.0f; const f4 tick_ms = 0.01666f; f4 render_dt = 0.0f; const f4 render_ms = 0.016667f; u4 time_physics_prev = btclock->getTimeMicroseconds(); while(irrlicht->device->run() && game_state == GAME_STATE_PLAY) { const u4 time_physics_curr = btclock->getTimeMicroseconds(); const f4 frameTime = ((f4)(time_physics_curr - time_physics_prev)) / 1000000.0; // todo: is this truncated correctly? time_physics_prev = time_physics_curr; f4 capped_dt = frameTime; if (capped_dt > maxDelta) { capped_dt = maxDelta; } render_dt += capped_dt; if ( render_dt >= render_ms ) { render_dt = 0.0f; f4 curr_rotation = empty_node->getRotation().Z; if (curr_rotation != target_z_rotation) { weighted_average(curr_rotation,target_z_rotation, 20.0f); if (curr_rotation >= 360.0f) { curr_rotation -= 360.0f; target_z_rotation -= 360.0f; } else if (curr_rotation < 0) { curr_rotation += 360.0f; target_z_rotation += 360.0f; } empty_node->setRotation({0,0,curr_rotation}); } if (sneditor->selected_node) { position2d<s32> screen_coord = irrlicht->colmgr->getScreenCoordinatesFrom3DPosition(sneditor->selected_node->getPosition(), camera); sneditor->hand_icon->setPosition({(screen_coord.X - (SCREEN_WIDTH/2)) / ortho_scale, (screen_coord.Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } else { sneditor->hand_icon->setPosition({(sneditor->cursor->getPosition().X - (SCREEN_WIDTH/2)) / ortho_scale, (sneditor->cursor->getPosition().Y - (SCREEN_HEIGHT/2)) / -ortho_scale,0}); } // Render irrlicht->driver->beginScene(true, true, SColor(GREY_BLUE)); irrlicht->smgr->drawAll(); irrlicht->driver->clearZBuffer(); irrlicht->hud->drawAll(); irrlicht->driver->endScene(); } dt += capped_dt; while( dt >= tick_ms ) { dt -= tick_ms; receiver->input(); if (receiver->a.state) target_z_rotation -= 90.0f; if (receiver->d.state) target_z_rotation += 90.0f; simple_node_editor_update( sneditor, receiver->mouse.left.state, receiver->mouse.left.released, receiver->mouse.right.state, false, receiver->tab.state, camera, &node_cmpnt_map); // TODO: Change this to: // - only test what the user is holding // - and only if the user is holding the smaller inserting part. // example: holding a screw in a large box bloop(joint_list, i) { Joint* c = (Joint*)b_get_mem_address(joint_list,i); if (c->A->tree != sneditor->selected_tree && c->B->tree != sneditor->selected_tree ) { continue; } if (!c->is_connected) { vec3 A = c->A->node->getPosition(); vec3 B = c->B->node->getPosition(); A += c->posA; B += c->posB; if (A.distance(B) < 13 /* && receiver->spacebar*/) { std::cout << "Comparing " << i << std::endl; c->is_connected = true; connect_joints(c,sneditor,camera,tree_list); } } } bloop(tree_list, i) { CTree* tree = (CTree*)b_get_mem_address(tree_list,i); if (tree->translation == vec3(0,0,0)) { continue; } for (s4 k = 0; k < tree->child_list.length;k++) { Component* cmpnt = (Component*)b_get_value(tree->child_list,k); cmpnt->node->setPosition(cmpnt->node->getPosition() + tree->translation.irr()); cmpnt->shadow->setPosition(cmpnt->node->getPosition() * vector3df(1,1,0) + vector3df(0,0,10)); } tree->translation = vec3(0,0,0); } if (receiver->restart.state) { game_state = GAME_STATE_RESET; } if (receiver->QUIT) { game_state = GAME_STATE_QUIT; } }